1 | /* $Id: win32wbase.cpp,v 1.261 2001-06-10 09:19:58 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Window Base Class for OS/2
|
---|
4 | *
|
---|
5 | * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
6 | * Copyright 1999 Daniela Engert (dani@ngrt.de)
|
---|
7 | * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
|
---|
8 | *
|
---|
9 | * Parts based on Wine Windows code (windows\win.c)
|
---|
10 | * Corel version: corel20000212
|
---|
11 | *
|
---|
12 | * Copyright 1993, 1994, 1996 Alexandre Julliard
|
---|
13 | * 1995 Alex Korobka
|
---|
14 | *
|
---|
15 | * TODO: Not thread/process safe
|
---|
16 | *
|
---|
17 | * NOTE: To access a window object, you must call GetWindowFromOS2Handle or
|
---|
18 | * GetWindowFromHandle. Both these methods increase the reference count
|
---|
19 | * of the object. When you're done with the object, you MUST call
|
---|
20 | * the release method!
|
---|
21 | * This mechanism prevents premature destruction of objects when there
|
---|
22 | * are still clients using it.
|
---|
23 | *
|
---|
24 | * NOTE: Client rectangle always relative to frame window
|
---|
25 | * Window rectangle in parent coordinates (relative to parent's client window)
|
---|
26 | * (screen coord. if no parent)
|
---|
27 | *
|
---|
28 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
29 | *
|
---|
30 | */
|
---|
31 | #include <os2win.h>
|
---|
32 | #include <win.h>
|
---|
33 | #include <stdlib.h>
|
---|
34 | #include <string.h>
|
---|
35 | #include <stdarg.h>
|
---|
36 | #include <assert.h>
|
---|
37 | #include <misc.h>
|
---|
38 | #include <heapstring.h>
|
---|
39 | #include <winuser32.h>
|
---|
40 | #include "win32wbase.h"
|
---|
41 | #include "wndmsg.h"
|
---|
42 | #include "oslibwin.h"
|
---|
43 | #include "oslibmsg.h"
|
---|
44 | #include "oslibutil.h"
|
---|
45 | #include "oslibgdi.h"
|
---|
46 | #include "oslibres.h"
|
---|
47 | #include "oslibdos.h"
|
---|
48 | #include "syscolor.h"
|
---|
49 | #include "win32wndhandle.h"
|
---|
50 | #include "dc.h"
|
---|
51 | #include "win32wdesktop.h"
|
---|
52 | #include "pmwindow.h"
|
---|
53 | #include "controls.h"
|
---|
54 | #include <wprocess.h>
|
---|
55 | #include <win\hook.h>
|
---|
56 | #include <menu.h>
|
---|
57 | #define INCL_TIMERWIN32
|
---|
58 | #include "timer.h"
|
---|
59 |
|
---|
60 | #define DBG_LOCALLOG DBG_win32wbase
|
---|
61 | #include "dbglocal.h"
|
---|
62 |
|
---|
63 | /* bits in the dwKeyData */
|
---|
64 | #define KEYDATA_ALT 0x2000
|
---|
65 | #define KEYDATA_PREVSTATE 0x4000
|
---|
66 |
|
---|
67 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
|
---|
68 |
|
---|
69 | static fDestroyAll = FALSE;
|
---|
70 | //For quick lookup of current process id
|
---|
71 | static ULONG currentProcessId = -1;
|
---|
72 |
|
---|
73 | //******************************************************************************
|
---|
74 | //******************************************************************************
|
---|
75 | Win32BaseWindow::Win32BaseWindow()
|
---|
76 | : GenericObject(&windows, &critsect), ChildWindow(&critsect)
|
---|
77 | {
|
---|
78 | Init();
|
---|
79 | }
|
---|
80 | //******************************************************************************
|
---|
81 | //******************************************************************************
|
---|
82 | Win32BaseWindow::Win32BaseWindow(HWND hwndOS2, ULONG reserved)
|
---|
83 | : GenericObject(&windows, &critsect), ChildWindow(&critsect)
|
---|
84 | {
|
---|
85 | Init();
|
---|
86 | OS2Hwnd = hwndOS2;
|
---|
87 | }
|
---|
88 | //******************************************************************************
|
---|
89 | //******************************************************************************
|
---|
90 | Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
|
---|
91 | : GenericObject(&windows, &critsect), ChildWindow(&critsect)
|
---|
92 | {
|
---|
93 | Init();
|
---|
94 | this->isUnicode = isUnicode;
|
---|
95 | CreateWindowExA(lpCreateStructA, classAtom);
|
---|
96 | }
|
---|
97 | //******************************************************************************
|
---|
98 | //******************************************************************************
|
---|
99 | void Win32BaseWindow::Init()
|
---|
100 | {
|
---|
101 | isUnicode = FALSE;
|
---|
102 | fFirstShow = TRUE;
|
---|
103 | fIsDialog = FALSE;
|
---|
104 | fIsModalDialogOwner = FALSE;
|
---|
105 | OS2HwndModalDialog = 0;
|
---|
106 | fInternalMsg = FALSE;
|
---|
107 | fNoSizeMsg = FALSE;
|
---|
108 | fIsDestroyed = FALSE;
|
---|
109 | fDestroyWindowCalled = FALSE;
|
---|
110 | fCreated = FALSE;
|
---|
111 | fTaskList = FALSE;
|
---|
112 | fParentDC = FALSE;
|
---|
113 | fComingToTop = FALSE;
|
---|
114 | fCreateSetWindowPos = FALSE;
|
---|
115 | fCreationFinished= FALSE;
|
---|
116 | fMinMaxChange = FALSE;
|
---|
117 | fVisibleRegionChanged = FALSE;
|
---|
118 | fEraseBkgndFlag = TRUE;
|
---|
119 |
|
---|
120 | windowNameA = NULL;
|
---|
121 | windowNameW = NULL;
|
---|
122 |
|
---|
123 | userWindowBytes = NULL;;
|
---|
124 | nrUserWindowBytes= 0;
|
---|
125 |
|
---|
126 | OS2Hwnd = 0;
|
---|
127 | OS2HwndFrame = 0;
|
---|
128 | hSysMenu = 0;
|
---|
129 | Win32Hwnd = 0;
|
---|
130 |
|
---|
131 | if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
|
---|
132 | {
|
---|
133 | dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
|
---|
134 | DebugInt3();
|
---|
135 | }
|
---|
136 |
|
---|
137 | posx = posy = 0;
|
---|
138 | width = height = 0;
|
---|
139 |
|
---|
140 | dwExStyle = 0;
|
---|
141 | dwStyle = 0;
|
---|
142 | win32wndproc = 0;
|
---|
143 | hInstance = 0;
|
---|
144 | dwIDMenu = 0; //0xFFFFFFFF; //default -1
|
---|
145 | userData = 0;
|
---|
146 | contextHelpId = 0;
|
---|
147 | hotkey = 0;
|
---|
148 |
|
---|
149 |
|
---|
150 | hwndLinkAfter = HWND_BOTTOM;
|
---|
151 | flags = 0;
|
---|
152 | lastHitTestVal = HTOS_NORMAL;
|
---|
153 | owner = NULL;
|
---|
154 | windowClass = 0;
|
---|
155 |
|
---|
156 | hIcon = 0;
|
---|
157 | hIconSm = 0;
|
---|
158 |
|
---|
159 | horzScrollInfo = NULL;
|
---|
160 | vertScrollInfo = NULL;
|
---|
161 |
|
---|
162 | propertyList = NULL;
|
---|
163 |
|
---|
164 | ownDC = 0;
|
---|
165 | hWindowRegion = 0;
|
---|
166 | hClipRegion = 0;
|
---|
167 |
|
---|
168 | hTaskList = 0;
|
---|
169 |
|
---|
170 | if(currentProcessId == -1)
|
---|
171 | {
|
---|
172 | currentProcessId = GetCurrentProcessId();
|
---|
173 | }
|
---|
174 | dwThreadId = GetCurrentThreadId();
|
---|
175 | dwProcessId = currentProcessId;
|
---|
176 |
|
---|
177 | memset(&windowpos, 0, sizeof(windowpos));
|
---|
178 | //min and max position are initially -1 (verified in NT4, SP6)
|
---|
179 | windowpos.ptMinPosition.x = -1;
|
---|
180 | windowpos.ptMinPosition.y = -1;
|
---|
181 | windowpos.ptMaxPosition.x = -1;
|
---|
182 | windowpos.ptMaxPosition.y = -1;
|
---|
183 | }
|
---|
184 | //******************************************************************************
|
---|
185 | //todo get rid of resources (menu, icon etc)
|
---|
186 | //******************************************************************************
|
---|
187 | Win32BaseWindow::~Win32BaseWindow()
|
---|
188 | {
|
---|
189 | if(getRefCount() < 0) {
|
---|
190 | DebugInt3();
|
---|
191 | }
|
---|
192 |
|
---|
193 | if(hTaskList) {
|
---|
194 | OSLibWinRemoveFromTasklist(hTaskList);
|
---|
195 | }
|
---|
196 |
|
---|
197 | OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE);
|
---|
198 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
---|
199 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
---|
200 |
|
---|
201 | if(fDestroyAll) {
|
---|
202 | dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
|
---|
203 | setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
|
---|
204 | }
|
---|
205 |
|
---|
206 | /* Decrement class window counter */
|
---|
207 | if(windowClass) {
|
---|
208 | RELEASE_CLASSOBJ(windowClass);
|
---|
209 | }
|
---|
210 |
|
---|
211 | if(isOwnDC())
|
---|
212 | releaseOwnDC(ownDC);
|
---|
213 |
|
---|
214 | if(Win32Hwnd)
|
---|
215 | HwFreeWindowHandle(Win32Hwnd);
|
---|
216 |
|
---|
217 | if(userWindowBytes)
|
---|
218 | free(userWindowBytes);
|
---|
219 |
|
---|
220 | if(windowNameA) {
|
---|
221 | free(windowNameA);
|
---|
222 | windowNameA = NULL;
|
---|
223 | }
|
---|
224 | if(windowNameW) {
|
---|
225 | free(windowNameW);
|
---|
226 | windowNameW = NULL;
|
---|
227 | }
|
---|
228 | if(vertScrollInfo) {
|
---|
229 | free(vertScrollInfo);
|
---|
230 | vertScrollInfo = NULL;
|
---|
231 | }
|
---|
232 | if(horzScrollInfo) {
|
---|
233 | free(horzScrollInfo);
|
---|
234 | horzScrollInfo = NULL;
|
---|
235 | }
|
---|
236 | if(propertyList) {
|
---|
237 | removeWindowProps();
|
---|
238 | }
|
---|
239 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
---|
240 | if(wndparent) {
|
---|
241 | RELEASE_WNDOBJ(wndparent);
|
---|
242 | }
|
---|
243 | if(owner) {
|
---|
244 | RELEASE_WNDOBJ(owner);
|
---|
245 | }
|
---|
246 | if(windowClass) {
|
---|
247 | RELEASE_CLASSOBJ(windowClass);
|
---|
248 | }
|
---|
249 | }
|
---|
250 | //******************************************************************************
|
---|
251 | //******************************************************************************
|
---|
252 | void Win32BaseWindow::DestroyAll()
|
---|
253 | {
|
---|
254 | fDestroyAll = TRUE;
|
---|
255 | GenericObject::DestroyAll(windows);
|
---|
256 | }
|
---|
257 | //******************************************************************************
|
---|
258 | //******************************************************************************
|
---|
259 | BOOL Win32BaseWindow::isChild()
|
---|
260 | {
|
---|
261 | return ((dwStyle & WS_CHILD) != 0);
|
---|
262 | }
|
---|
263 | //******************************************************************************
|
---|
264 | //******************************************************************************
|
---|
265 | BOOL Win32BaseWindow::IsWindowUnicode()
|
---|
266 | {
|
---|
267 | dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
|
---|
268 | return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
|
---|
269 | }
|
---|
270 | //******************************************************************************
|
---|
271 | //******************************************************************************
|
---|
272 | BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
|
---|
273 | {
|
---|
274 | char buffer[256];
|
---|
275 |
|
---|
276 | #ifdef DEBUG
|
---|
277 | PrintWindowStyle(cs->style, cs->dwExStyle);
|
---|
278 | #endif
|
---|
279 |
|
---|
280 | //If window has no owner/parent window, then it will be added to the tasklist
|
---|
281 | //(depending on visibility state)
|
---|
282 | if (!cs->hwndParent) fTaskList = TRUE;
|
---|
283 |
|
---|
284 | sw = SW_SHOW;
|
---|
285 | SetLastError(0);
|
---|
286 |
|
---|
287 | /* Find the parent window */
|
---|
288 | if (cs->hwndParent)
|
---|
289 | {
|
---|
290 | Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
|
---|
291 | if(!window) {
|
---|
292 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
293 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
294 | return FALSE;
|
---|
295 | }
|
---|
296 | /* Make sure parent is valid */
|
---|
297 | if (!window->IsWindow() )
|
---|
298 | {
|
---|
299 | RELEASE_WNDOBJ(window);
|
---|
300 | dprintf(("Bad parent %04x\n", cs->hwndParent ));
|
---|
301 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
302 | return FALSE;
|
---|
303 | }
|
---|
304 | RELEASE_WNDOBJ(window);
|
---|
305 | /* Windows does this for overlapped windows
|
---|
306 | * (I don't know about other styles.) */
|
---|
307 | if (cs->hwndParent == GetDesktopWindow() && (!(cs->style & WS_CHILD) || (cs->style & WS_POPUP)))
|
---|
308 | {
|
---|
309 | cs->hwndParent = 0;
|
---|
310 | }
|
---|
311 | }
|
---|
312 | else
|
---|
313 | if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
|
---|
314 | dprintf(("No parent for child window" ));
|
---|
315 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
316 | return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
|
---|
317 | }
|
---|
318 |
|
---|
319 | /* Find the window class */
|
---|
320 | windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
|
---|
321 | if (!windowClass)
|
---|
322 | {
|
---|
323 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
324 | dprintf(("Bad class '%s'", buffer ));
|
---|
325 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
326 | return 0;
|
---|
327 | }
|
---|
328 |
|
---|
329 | #ifdef DEBUG
|
---|
330 | if(HIWORD(cs->lpszClass))
|
---|
331 | {
|
---|
332 | if(isUnicode) dprintf(("Window class %ls", cs->lpszClass));
|
---|
333 | else dprintf(("Window class %s", cs->lpszClass));
|
---|
334 | }
|
---|
335 | else dprintf(("Window class %x", cs->lpszClass));
|
---|
336 | #endif
|
---|
337 |
|
---|
338 | /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
|
---|
339 | * with an atom as the class name, put some programs expect to have a *REAL* string in
|
---|
340 | * lpszClass when the CREATESTRUCT is sent with WM_CREATE
|
---|
341 | */
|
---|
342 | if (!HIWORD(cs->lpszClass) ) {
|
---|
343 | if (isUnicode) {
|
---|
344 | GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
|
---|
345 | }
|
---|
346 | else {
|
---|
347 | GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
|
---|
348 | }
|
---|
349 | cs->lpszClass = buffer;
|
---|
350 | }
|
---|
351 |
|
---|
352 | /* Fix the coordinates */
|
---|
353 | fXDefault = FALSE;
|
---|
354 | fCXDefault = FALSE;
|
---|
355 | if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16))
|
---|
356 | {
|
---|
357 | /* Never believe Microsoft's documentation... CreateWindowEx doc says
|
---|
358 | * that if an overlapped window is created with WS_VISIBLE style bit
|
---|
359 | * set and the x parameter is set to CW_USEDEFAULT, the system ignores
|
---|
360 | * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
|
---|
361 | * reveals that
|
---|
362 | *
|
---|
363 | * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
|
---|
364 | * 2) it does not ignore the y parameter as the docs claim; instead, it
|
---|
365 | * uses it as second parameter to ShowWindow() unless y is either
|
---|
366 | * CW_USEDEFAULT or CW_USEDEFAULT16.
|
---|
367 | *
|
---|
368 | * The fact that we didn't do 2) caused bogus windows pop up when wine
|
---|
369 | * was running apps that were using this obscure feature. Example -
|
---|
370 | * calc.exe that comes with Win98 (only Win98, it's different from
|
---|
371 | * the one that comes with Win95 and NT)
|
---|
372 | */
|
---|
373 | if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y;
|
---|
374 |
|
---|
375 | /* We have saved cs->y, now we can trash it */
|
---|
376 | cs->x = 0;
|
---|
377 | cs->y = 0;
|
---|
378 | fXDefault = TRUE;
|
---|
379 | }
|
---|
380 | if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16))
|
---|
381 | {
|
---|
382 | cs->cx = 600; /* FIXME */
|
---|
383 | cs->cy = 400;
|
---|
384 | fCXDefault = TRUE;
|
---|
385 | }
|
---|
386 | if (cs->style & (WS_POPUP | WS_CHILD))
|
---|
387 | {
|
---|
388 | fXDefault = FALSE;
|
---|
389 | if (fCXDefault)
|
---|
390 | {
|
---|
391 | fCXDefault = FALSE;
|
---|
392 | cs->cx = cs->cy = 0;
|
---|
393 | }
|
---|
394 | }
|
---|
395 | if (fXDefault && !fCXDefault) fXDefault = FALSE; //CB: only x positioning doesn't work (calc.exe,cdrlabel.exe)
|
---|
396 |
|
---|
397 | if (cs->x < 0) cs->x = 0;
|
---|
398 | if (cs->y < 0) cs->y = 0;
|
---|
399 |
|
---|
400 | //Allocate window words
|
---|
401 | nrUserWindowBytes = windowClass->getExtraWndBytes();
|
---|
402 | if(nrUserWindowBytes) {
|
---|
403 | userWindowBytes = (char *)_smalloc(nrUserWindowBytes);
|
---|
404 | memset(userWindowBytes, 0, nrUserWindowBytes);
|
---|
405 | }
|
---|
406 |
|
---|
407 | if ((cs->style & WS_CHILD) && cs->hwndParent)
|
---|
408 | {
|
---|
409 | SetParent(cs->hwndParent);
|
---|
410 | // owner = GetWindowFromHandle(cs->hwndParent);
|
---|
411 | owner = 0;
|
---|
412 | /* if(owner == NULL)
|
---|
413 | {
|
---|
414 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
---|
415 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
416 | return FALSE;
|
---|
417 | }*/
|
---|
418 | //SvL: Shell positioning shouldn't be done for child windows! (breaks Notes)
|
---|
419 | fXDefault = fCXDefault = FALSE;
|
---|
420 | }
|
---|
421 | else
|
---|
422 | {
|
---|
423 | SetParent(0);
|
---|
424 | if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) {
|
---|
425 | owner = NULL;
|
---|
426 | }
|
---|
427 | else
|
---|
428 | {
|
---|
429 | owner = GetWindowFromHandle(GetWindowFromHandle(cs->hwndParent)->GetTopParent());
|
---|
430 | if(owner == NULL)
|
---|
431 | {
|
---|
432 | dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
|
---|
433 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
434 | return FALSE;
|
---|
435 | }
|
---|
436 | }
|
---|
437 | }
|
---|
438 |
|
---|
439 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
|
---|
440 | hInstance = cs->hInstance;
|
---|
441 | dwStyle = cs->style & ~WS_VISIBLE;
|
---|
442 | dwExStyle = cs->dwExStyle;
|
---|
443 |
|
---|
444 | hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
|
---|
445 |
|
---|
446 | /* Correct the window style */
|
---|
447 | if (!(cs->style & WS_CHILD))
|
---|
448 | {
|
---|
449 | dwStyle |= WS_CLIPSIBLINGS;
|
---|
450 | if (!(cs->style & WS_POPUP))
|
---|
451 | {
|
---|
452 | dwStyle |= WS_CAPTION;
|
---|
453 | flags |= WIN_NEED_SIZE;
|
---|
454 | }
|
---|
455 | }
|
---|
456 | if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
|
---|
457 |
|
---|
458 | //copy pointer of CREATESTRUCT for usage in MsgCreate method
|
---|
459 | tmpcs = cs;
|
---|
460 |
|
---|
461 | //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
|
---|
462 | TEB *teb = GetThreadTEB();
|
---|
463 | if(teb == NULL) {
|
---|
464 | dprintf(("Window creation failed - teb == NULL")); //this is VERY bad
|
---|
465 | ExitProcess(666);
|
---|
466 | return FALSE;
|
---|
467 | }
|
---|
468 |
|
---|
469 | teb->o.odin.newWindow = (ULONG)this;
|
---|
470 |
|
---|
471 | DWORD dwOSWinStyle;
|
---|
472 |
|
---|
473 | OSLibWinConvertStyle(dwStyle,dwExStyle,&dwOSWinStyle);
|
---|
474 |
|
---|
475 | OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
|
---|
476 | dwOSWinStyle,(char *)windowNameA,
|
---|
477 | (owner) ? owner->getOS2WindowHandle() : ((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP),
|
---|
478 | (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
|
---|
479 | 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle(), &OS2HwndFrame);
|
---|
480 | if(OS2Hwnd == 0) {
|
---|
481 | dprintf(("Window creation failed!! OS LastError %0x", OSLibWinGetLastError()));
|
---|
482 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
483 | return FALSE;
|
---|
484 | }
|
---|
485 | OSLibWinSetVisibleRegionNotify(OS2Hwnd, TRUE);
|
---|
486 | fCreationFinished = TRUE; //creation done with success
|
---|
487 | SetLastError(0);
|
---|
488 | return TRUE;
|
---|
489 | }
|
---|
490 | //******************************************************************************
|
---|
491 | //******************************************************************************
|
---|
492 | BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2)
|
---|
493 | {
|
---|
494 | CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
|
---|
495 | POINT maxSize, maxPos, minTrack, maxTrack;
|
---|
496 | HWND hwnd = getWindowHandle();
|
---|
497 | LRESULT (* CALLBACK localSend32)(HWND, UINT, WPARAM, LPARAM);
|
---|
498 |
|
---|
499 | OS2Hwnd = hwndOS2;
|
---|
500 |
|
---|
501 | fNoSizeMsg = TRUE;
|
---|
502 |
|
---|
503 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, getWindowHandle()) == FALSE) {
|
---|
504 | dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
|
---|
505 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
506 | return FALSE;
|
---|
507 | }
|
---|
508 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
|
---|
509 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
510 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
511 | return FALSE;
|
---|
512 | }
|
---|
513 | if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32FLAGS, 0) == FALSE) {
|
---|
514 | dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
|
---|
515 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
516 | return FALSE;
|
---|
517 | }
|
---|
518 |
|
---|
519 | if (HOOK_IsHooked( WH_CBT ))
|
---|
520 | {
|
---|
521 | CBT_CREATEWNDA cbtc;
|
---|
522 | LRESULT ret;
|
---|
523 |
|
---|
524 | cbtc.lpcs = cs;
|
---|
525 | cbtc.hwndInsertAfter = hwndLinkAfter;
|
---|
526 | ret = (isUnicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc)
|
---|
527 | : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
|
---|
528 | if(ret)
|
---|
529 | {
|
---|
530 | dprintf(("CBT-hook returned 0!!"));
|
---|
531 | SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
|
---|
532 | return FALSE;
|
---|
533 | }
|
---|
534 | //todo: if hook changes parent, we need to do so too!!!!!!!!!!
|
---|
535 | }
|
---|
536 |
|
---|
537 | if (cs->style & WS_HSCROLL)
|
---|
538 | {
|
---|
539 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
540 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
|
---|
541 | horzScrollInfo->MaxVal = 100;
|
---|
542 | horzScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
543 | }
|
---|
544 |
|
---|
545 | if (cs->style & WS_VSCROLL)
|
---|
546 | {
|
---|
547 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
548 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
|
---|
549 | vertScrollInfo->MaxVal = 100;
|
---|
550 | vertScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
551 | }
|
---|
552 |
|
---|
553 | if(HIWORD(cs->lpszName))
|
---|
554 | {
|
---|
555 | if (!isUnicode)
|
---|
556 | {
|
---|
557 | int wndNameLength = strlen(cs->lpszName);
|
---|
558 | windowNameA = (LPSTR)_smalloc(wndNameLength+1);
|
---|
559 | strcpy(windowNameA,cs->lpszName);
|
---|
560 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
561 | lstrcpyAtoW(windowNameW,windowNameA);
|
---|
562 | windowNameA[wndNameLength] = 0;
|
---|
563 | windowNameW[wndNameLength] = 0;
|
---|
564 | }
|
---|
565 | else
|
---|
566 | {
|
---|
567 | // Wide
|
---|
568 | int wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
|
---|
569 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
570 | lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
|
---|
571 | windowNameW[lstrlenW((LPWSTR)cs->lpszName)] = 0; // need ?
|
---|
572 | // Ascii
|
---|
573 | LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR)cs->lpszName);
|
---|
574 | if(tmp) {
|
---|
575 | long tmpLength = strlen( tmp );
|
---|
576 | windowNameA = (LPSTR)_smalloc(tmpLength+1);
|
---|
577 | strcpy(windowNameA,tmp);
|
---|
578 | windowNameA[tmpLength] = 0; // need ?
|
---|
579 | HEAP_free(tmp);
|
---|
580 | } else {
|
---|
581 | windowNameA = (LPSTR)_smalloc(1);
|
---|
582 | windowNameA[0] = 0;
|
---|
583 | }
|
---|
584 | }
|
---|
585 | }
|
---|
586 |
|
---|
587 | //SvL: This completely messes up MS Word 97 (no button bar, no menu)
|
---|
588 | #if 0
|
---|
589 | //adjust CW_USEDEFAULT position
|
---|
590 | if (fXDefault | fCXDefault)
|
---|
591 | {
|
---|
592 | RECT rect;
|
---|
593 |
|
---|
594 | //SvL: Returns invalid rectangle (not the expected shell default size)
|
---|
595 | OSLibWinQueryWindowRect(OS2Hwnd,&rect,RELATIVE_TO_SCREEN);
|
---|
596 | if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
|
---|
597 | if (fXDefault)
|
---|
598 | {
|
---|
599 | cs->x = rect.left;
|
---|
600 | cs->y = rect.top;
|
---|
601 | if (!fCXDefault)
|
---|
602 | {
|
---|
603 | //CB: todo: adjust pos to screen rect
|
---|
604 | }
|
---|
605 | }
|
---|
606 | if (fCXDefault)
|
---|
607 | {
|
---|
608 | cs->cx = rect.right-rect.left;
|
---|
609 | cs->cy = rect.bottom-rect.top;
|
---|
610 | }
|
---|
611 | }
|
---|
612 | #endif
|
---|
613 |
|
---|
614 | fakeWinBase.hwndThis = OS2Hwnd;
|
---|
615 | fakeWinBase.pWindowClass = windowClass;
|
---|
616 |
|
---|
617 | //Set icon from window or class
|
---|
618 | if (hIcon)
|
---|
619 | OSLibWinSetIcon(OS2Hwnd,hIcon);
|
---|
620 | else
|
---|
621 | if (windowClass->getIcon())
|
---|
622 | OSLibWinSetIcon(OS2Hwnd,windowClass->getIcon());
|
---|
623 |
|
---|
624 | /* Get class or window DC if needed */
|
---|
625 | if(windowClass->getStyle() & CS_OWNDC) {
|
---|
626 | dprintf(("Class with CS_OWNDC style"));
|
---|
627 | ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE);
|
---|
628 | }
|
---|
629 | else
|
---|
630 | if (windowClass->getStyle() & CS_PARENTDC) {
|
---|
631 | fParentDC = TRUE;
|
---|
632 | ownDC = 0;
|
---|
633 | }
|
---|
634 | else
|
---|
635 | if (windowClass->getStyle() & CS_CLASSDC) {
|
---|
636 | dprintf(("WARNING: Class with CS_CLASSDC style!"));
|
---|
637 | ownDC = 0;
|
---|
638 | }
|
---|
639 | /* Set the window menu */
|
---|
640 | if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
|
---|
641 | {
|
---|
642 | if (cs->hMenu) {
|
---|
643 | ::SetMenu(getWindowHandle(), cs->hMenu);
|
---|
644 | }
|
---|
645 | else {
|
---|
646 | if (windowClass->getMenuNameA()) {
|
---|
647 | cs->hMenu = LoadMenuA(windowClass->getInstance(),windowClass->getMenuNameA());
|
---|
648 | #if 0 //CB: hack for treeview test cases bug
|
---|
649 | if (!cs->hMenu) cs->hMenu = LoadMenuA(windowClass->getInstance(),"MYAPP");
|
---|
650 | #endif
|
---|
651 | if (cs->hMenu) ::SetMenu(getWindowHandle(), cs->hMenu );
|
---|
652 | }
|
---|
653 | }
|
---|
654 | }
|
---|
655 | else
|
---|
656 | {
|
---|
657 | setWindowId((DWORD)cs->hMenu);
|
---|
658 | }
|
---|
659 | hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0;
|
---|
660 |
|
---|
661 | /* Send the WM_GETMINMAXINFO message and fix the size if needed */
|
---|
662 | if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
|
---|
663 | {
|
---|
664 | GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
|
---|
665 | if (maxSize.x < cs->cx) cs->cx = maxSize.x;
|
---|
666 | if (maxSize.y < cs->cy) cs->cy = maxSize.y;
|
---|
667 | if (cs->cx < minTrack.x) cs->cx = minTrack.x;
|
---|
668 | if (cs->cy < minTrack.y) cs->cy = minTrack.y;
|
---|
669 | }
|
---|
670 |
|
---|
671 | if(cs->style & WS_CHILD)
|
---|
672 | {
|
---|
673 | if(cs->cx < 0) cs->cx = 0;
|
---|
674 | if(cs->cy < 0) cs->cy = 0;
|
---|
675 | }
|
---|
676 | else
|
---|
677 | {
|
---|
678 | if (cs->cx <= 0) cs->cx = 1;
|
---|
679 | if (cs->cy <= 0) cs->cy = 1;
|
---|
680 | }
|
---|
681 |
|
---|
682 | //set client & window rectangles from CreateWindowEx CREATESTRUCT
|
---|
683 | rectWindow.left = cs->x;
|
---|
684 | rectWindow.right = cs->x+cs->cx;
|
---|
685 | rectWindow.top = cs->y;
|
---|
686 | rectWindow.bottom = cs->y+cs->cy;
|
---|
687 | rectClient = rectWindow;
|
---|
688 | OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
|
---|
689 |
|
---|
690 | /* Send the WM_CREATE message
|
---|
691 | * Perhaps we shouldn't allow width/height changes as well.
|
---|
692 | * See p327 in "Internals".
|
---|
693 | */
|
---|
694 | maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
|
---|
695 |
|
---|
696 | //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
|
---|
697 | fCreated = TRUE;
|
---|
698 |
|
---|
699 | if(fTaskList) {
|
---|
700 | hTaskList = OSLibWinAddToTaskList(OS2HwndFrame, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
|
---|
701 | }
|
---|
702 |
|
---|
703 | localSend32 = (isUnicode) ? ::SendMessageW : ::SendMessageA;
|
---|
704 |
|
---|
705 | if(localSend32(getWindowHandle(), WM_NCCREATE,0,(LPARAM)cs))
|
---|
706 | {
|
---|
707 | RECT tmpRect;
|
---|
708 |
|
---|
709 | //CB: recheck flags
|
---|
710 | if (cs->style & (WS_POPUP | WS_CHILD))
|
---|
711 | {
|
---|
712 | fXDefault = FALSE;
|
---|
713 | if (fCXDefault)
|
---|
714 | {
|
---|
715 | fCXDefault = FALSE;
|
---|
716 | cs->cx = cs->cy = 0;
|
---|
717 | rectWindow.right = rectWindow.left;
|
---|
718 | rectWindow.bottom = rectWindow.top;
|
---|
719 | }
|
---|
720 | }
|
---|
721 | tmpRect = rectWindow;
|
---|
722 |
|
---|
723 | fCreateSetWindowPos = TRUE;
|
---|
724 |
|
---|
725 | //set the window size and update the client
|
---|
726 | SetWindowPos(hwndLinkAfter, tmpRect.left, tmpRect.top, tmpRect.right-tmpRect.left, tmpRect.bottom-tmpRect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED);
|
---|
727 | fNoSizeMsg = FALSE;
|
---|
728 | if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE
|
---|
729 | if( (localSend32(getWindowHandle(), WM_CREATE, 0, (LPARAM)cs )) != -1 )
|
---|
730 | {
|
---|
731 | if(!(flags & WIN_NEED_SIZE))
|
---|
732 | {
|
---|
733 | SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
|
---|
734 | MAKELONG(rectClient.right-rectClient.left,
|
---|
735 | rectClient.bottom-rectClient.top));
|
---|
736 |
|
---|
737 | if(!::IsWindow(hwnd))
|
---|
738 | {
|
---|
739 | dprintf(("Createwindow: WM_SIZE destroyed window"));
|
---|
740 | goto end;
|
---|
741 | }
|
---|
742 | SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
|
---|
743 | if(!::IsWindow(hwnd))
|
---|
744 | {
|
---|
745 | dprintf(("Createwindow: WM_MOVE destroyed window"));
|
---|
746 | goto end;
|
---|
747 | }
|
---|
748 | }
|
---|
749 | if (getStyle() & (WS_MINIMIZE | WS_MAXIMIZE))
|
---|
750 | {
|
---|
751 | RECT newPos;
|
---|
752 | UINT swFlag = (getStyle() & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
|
---|
753 | setStyle(getStyle() & ~(WS_MAXIMIZE | WS_MINIMIZE));
|
---|
754 | MinMaximize(swFlag, &newPos);
|
---|
755 | swFlag = ((getStyle() & WS_CHILD) || GetActiveWindow()) ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
|
---|
756 | : SWP_NOZORDER | SWP_FRAMECHANGED;
|
---|
757 | SetWindowPos(0, newPos.left, newPos.top, newPos.right, newPos.bottom, swFlag);
|
---|
758 | if(!::IsWindow(hwnd))
|
---|
759 | {
|
---|
760 | dprintf(("Createwindow: min/max destroyed window"));
|
---|
761 | goto end;
|
---|
762 | }
|
---|
763 | }
|
---|
764 |
|
---|
765 | if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
766 | {
|
---|
767 | /* Notify the parent window only */
|
---|
768 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
|
---|
769 | {
|
---|
770 | getParent()->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
|
---|
771 | }
|
---|
772 | if(!::IsWindow(hwnd))
|
---|
773 | {
|
---|
774 | dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
|
---|
775 | goto end;
|
---|
776 | }
|
---|
777 | }
|
---|
778 |
|
---|
779 | if(cs->style & WS_VISIBLE) {
|
---|
780 | dwStyle &= ~WS_VISIBLE;
|
---|
781 | ShowWindow(sw);
|
---|
782 | }
|
---|
783 |
|
---|
784 | /* Call WH_SHELL hook */
|
---|
785 | if (!(getStyle() & WS_CHILD) && !owner)
|
---|
786 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0);
|
---|
787 |
|
---|
788 | SetLastError(0);
|
---|
789 | return TRUE;
|
---|
790 | }
|
---|
791 | }
|
---|
792 | dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
|
---|
793 | SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
|
---|
794 | end:
|
---|
795 | return FALSE;
|
---|
796 | }
|
---|
797 | //******************************************************************************
|
---|
798 | //******************************************************************************
|
---|
799 | ULONG Win32BaseWindow::MsgQuit()
|
---|
800 | {
|
---|
801 | return SendInternalMessageA(WM_QUIT, 0, 0);
|
---|
802 | }
|
---|
803 | //******************************************************************************
|
---|
804 | //******************************************************************************
|
---|
805 | ULONG Win32BaseWindow::MsgClose()
|
---|
806 | {
|
---|
807 | return SendInternalMessageA(WM_CLOSE,0,0);
|
---|
808 | }
|
---|
809 | //******************************************************************************
|
---|
810 | //******************************************************************************
|
---|
811 | ULONG Win32BaseWindow::MsgDestroy()
|
---|
812 | {
|
---|
813 | ULONG rc;
|
---|
814 | Win32BaseWindow *child;
|
---|
815 | HWND hwnd = getWindowHandle();
|
---|
816 |
|
---|
817 | fIsDestroyed = TRUE;
|
---|
818 |
|
---|
819 | if(fDestroyWindowCalled == FALSE)
|
---|
820 | {//this window was destroyed because DestroyWindow was called for it's parent
|
---|
821 | //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
|
---|
822 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
|
---|
823 | {
|
---|
824 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
|
---|
825 | {
|
---|
826 | /* Notify the parent window only */
|
---|
827 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
|
---|
828 | }
|
---|
829 | //// else DebugInt3();
|
---|
830 | }
|
---|
831 | }
|
---|
832 | SendInternalMessageA(WM_DESTROY, 0, 0);
|
---|
833 | if(::IsWindow(hwnd) == FALSE) {
|
---|
834 | //object already destroyed, so return immediately
|
---|
835 | return 1;
|
---|
836 | }
|
---|
837 | SendInternalMessageA(WM_NCDESTROY, 0, 0);
|
---|
838 |
|
---|
839 | TIMER_KillTimerFromWindow(getWindowHandle());
|
---|
840 |
|
---|
841 | if(getRefCount() == 0 && getFirstChild() == NULL && fCreationFinished) {
|
---|
842 | delete this;
|
---|
843 | }
|
---|
844 | else {
|
---|
845 | //make sure no message can ever arrive for this window again (PM or from other win32 windows)
|
---|
846 | dprintf(("Mark window %x (%x) as deleted", getWindowHandle(), this));
|
---|
847 | markDeleted();
|
---|
848 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
|
---|
849 | OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
|
---|
850 | if(Win32Hwnd) {
|
---|
851 | HwFreeWindowHandle(Win32Hwnd);
|
---|
852 | Win32Hwnd = 0;
|
---|
853 | }
|
---|
854 | }
|
---|
855 | return 1;
|
---|
856 | }
|
---|
857 | //******************************************************************************
|
---|
858 | //******************************************************************************
|
---|
859 | ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
|
---|
860 | {
|
---|
861 | if(fEnable) {
|
---|
862 | dwStyle &= ~WS_DISABLED;
|
---|
863 | }
|
---|
864 | else dwStyle |= WS_DISABLED;
|
---|
865 |
|
---|
866 | return SendInternalMessageA(WM_ENABLE, fEnable, 0);
|
---|
867 | }
|
---|
868 | //******************************************************************************
|
---|
869 | //TODO: SW_PARENTCLOSING/OPENING flag (lParam)
|
---|
870 | //******************************************************************************
|
---|
871 | ULONG Win32BaseWindow::MsgShow(BOOL fShow)
|
---|
872 | {
|
---|
873 | if(fNoSizeMsg || fDestroyWindowCalled) {
|
---|
874 | return 1;
|
---|
875 | }
|
---|
876 |
|
---|
877 | if(fShow) {
|
---|
878 | setStyle(getStyle() | WS_VISIBLE);
|
---|
879 | if(getStyle() & WS_MINIMIZE) {
|
---|
880 | return ShowWindow(SW_RESTORE);
|
---|
881 | }
|
---|
882 | }
|
---|
883 | else setStyle(getStyle() & ~WS_VISIBLE);
|
---|
884 |
|
---|
885 | //already sent from ShowWindow
|
---|
886 | //// return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
|
---|
887 | return 0;
|
---|
888 | }
|
---|
889 | //******************************************************************************
|
---|
890 | //******************************************************************************
|
---|
891 | ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
|
---|
892 | {
|
---|
893 | //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
|
---|
894 | // a WM_WINDOWPOSCHANGED msg -> crash)
|
---|
895 | if(fNoSizeMsg || fDestroyWindowCalled)
|
---|
896 | return 0;
|
---|
897 |
|
---|
898 | return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
|
---|
899 | }
|
---|
900 | //******************************************************************************
|
---|
901 | //******************************************************************************
|
---|
902 | ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
|
---|
903 | {
|
---|
904 | //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
|
---|
905 | // a WM_WINDOWPOSCHANGED msg -> crash)
|
---|
906 | if(fNoSizeMsg || fDestroyWindowCalled)
|
---|
907 | return 1;
|
---|
908 |
|
---|
909 | return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
|
---|
910 | }
|
---|
911 | //******************************************************************************
|
---|
912 | //******************************************************************************
|
---|
913 | ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
|
---|
914 | {
|
---|
915 | //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
|
---|
916 | //window scrollbars send these messages
|
---|
917 | return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
|
---|
918 | }
|
---|
919 | //******************************************************************************
|
---|
920 | //******************************************************************************
|
---|
921 | ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win)
|
---|
922 | {
|
---|
923 | ULONG rc, procidhwnd = -1, threadidhwnd = 0;
|
---|
924 |
|
---|
925 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
|
---|
926 | if(fDestroyWindowCalled) {
|
---|
927 | return 0;
|
---|
928 | }
|
---|
929 |
|
---|
930 | //According to SDK docs, if app returns FALSE & window is being deactivated,
|
---|
931 | //default processing is cancelled
|
---|
932 | //TODO: According to Wine we should proceed anyway if window is sysmodal
|
---|
933 | if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
|
---|
934 | {
|
---|
935 | dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
|
---|
936 | return 0;
|
---|
937 | }
|
---|
938 | /* child windows get a WM_CHILDACTIVATE message */
|
---|
939 | if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
|
---|
940 | {
|
---|
941 | if(fActivate) {//WM_CHILDACTIVE is for activation only
|
---|
942 | SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
|
---|
943 | }
|
---|
944 | return 0;
|
---|
945 | }
|
---|
946 |
|
---|
947 | rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
|
---|
948 |
|
---|
949 | if(hwndOS2Win) {
|
---|
950 | threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd);
|
---|
951 | }
|
---|
952 | //Warning: temporary hack to force focus to newly created window
|
---|
953 | //RealPlayer 8 does not pass WM_ACTIVATE to defwindowproc and doesn't call
|
---|
954 | //setfocus -> keyboard focus not set
|
---|
955 | //TODO: Find real cause!!
|
---|
956 | if(GetFocus() == 0 && fActivate) {
|
---|
957 | if(!(getStyle() & WS_MINIMIZE))
|
---|
958 | SetFocus(getWindowHandle());
|
---|
959 | }
|
---|
960 | //Warning: temporary hack to force focus to newly created window
|
---|
961 |
|
---|
962 | if(fActivate) {
|
---|
963 | SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId); //activate; specify window thread id
|
---|
964 | }
|
---|
965 | else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd); //deactivate; specify thread id of other process
|
---|
966 | return rc;
|
---|
967 | }
|
---|
968 | //******************************************************************************
|
---|
969 | //******************************************************************************
|
---|
970 | ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
|
---|
971 | {
|
---|
972 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
973 | }
|
---|
974 | //******************************************************************************
|
---|
975 | //******************************************************************************
|
---|
976 | ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
|
---|
977 | {
|
---|
978 | return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
|
---|
979 | }
|
---|
980 | //******************************************************************************
|
---|
981 | //******************************************************************************
|
---|
982 | ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
|
---|
983 | {
|
---|
984 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
|
---|
985 | if(fDestroyWindowCalled) {
|
---|
986 | return 0;
|
---|
987 | }
|
---|
988 |
|
---|
989 | return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
|
---|
990 | }
|
---|
991 | //******************************************************************************
|
---|
992 | //******************************************************************************
|
---|
993 | ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
|
---|
994 | {
|
---|
995 | //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
|
---|
996 | if(fDestroyWindowCalled) {
|
---|
997 | return 0;
|
---|
998 | }
|
---|
999 | return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
|
---|
1000 | }
|
---|
1001 | //******************************************************************************
|
---|
1002 | //******************************************************************************
|
---|
1003 | ULONG Win32BaseWindow::MsgButton(MSG *msg)
|
---|
1004 | {
|
---|
1005 | BOOL fClick = FALSE;
|
---|
1006 |
|
---|
1007 | // dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
|
---|
1008 | switch(msg->message) {
|
---|
1009 | case WM_LBUTTONDBLCLK:
|
---|
1010 | case WM_RBUTTONDBLCLK:
|
---|
1011 | case WM_MBUTTONDBLCLK:
|
---|
1012 | if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
|
---|
1013 | {
|
---|
1014 | msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
|
---|
1015 | MsgButton(msg);
|
---|
1016 | msg->message++; //button-up
|
---|
1017 | return MsgButton(msg);
|
---|
1018 | }
|
---|
1019 | break;
|
---|
1020 | case WM_NCLBUTTONDBLCLK:
|
---|
1021 | case WM_NCRBUTTONDBLCLK:
|
---|
1022 | case WM_NCMBUTTONDBLCLK:
|
---|
1023 | //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
|
---|
1024 | fClick = TRUE;
|
---|
1025 | break;
|
---|
1026 |
|
---|
1027 | case WM_LBUTTONDOWN:
|
---|
1028 | case WM_RBUTTONDOWN:
|
---|
1029 | case WM_MBUTTONDOWN:
|
---|
1030 | case WM_NCLBUTTONDOWN:
|
---|
1031 | case WM_NCRBUTTONDOWN:
|
---|
1032 | case WM_NCMBUTTONDOWN:
|
---|
1033 | fClick = TRUE;
|
---|
1034 | break;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | if(fClick)
|
---|
1038 | {
|
---|
1039 | HWND hwndTop;
|
---|
1040 |
|
---|
1041 | /* Activate the window if needed */
|
---|
1042 | hwndTop = GetTopParent();
|
---|
1043 |
|
---|
1044 | HWND hwndActive = GetActiveWindow();
|
---|
1045 | if (hwndTop && (getWindowHandle() != hwndActive))
|
---|
1046 | {
|
---|
1047 | LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
|
---|
1048 | MAKELONG( lastHitTestVal, msg->message) );
|
---|
1049 |
|
---|
1050 | #if 0
|
---|
1051 | if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
|
---|
1052 | eatMsg = TRUE;
|
---|
1053 | #endif
|
---|
1054 | if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
|
---|
1055 | && (hwndTop != GetForegroundWindow()) )
|
---|
1056 | {
|
---|
1057 | Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
|
---|
1058 |
|
---|
1059 | //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
|
---|
1060 | if (win32top) {
|
---|
1061 | OSLibWinSetFocus(win32top->getOS2FrameWindowHandle());
|
---|
1062 | RELEASE_WNDOBJ(win32top);
|
---|
1063 | }
|
---|
1064 | }
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
|
---|
1069 |
|
---|
1070 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
1071 | }
|
---|
1072 | //******************************************************************************
|
---|
1073 | //******************************************************************************
|
---|
1074 | ULONG Win32BaseWindow::MsgPaint(ULONG tmp, ULONG select)
|
---|
1075 | {
|
---|
1076 | if (select && IsWindowIconic())
|
---|
1077 | return SendInternalMessageA(WM_PAINTICON, 1, 0);
|
---|
1078 | else
|
---|
1079 | return SendInternalMessageA(WM_PAINT, 0, 0);
|
---|
1080 | }
|
---|
1081 | //******************************************************************************
|
---|
1082 | //TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
|
---|
1083 | // (or are we simply erasing too much here)
|
---|
1084 | //******************************************************************************
|
---|
1085 | ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
|
---|
1086 | {
|
---|
1087 | ULONG rc;
|
---|
1088 | HDC hdcErase = hdc;
|
---|
1089 |
|
---|
1090 | if (hdcErase == 0)
|
---|
1091 | hdcErase = GetDC(getWindowHandle());
|
---|
1092 |
|
---|
1093 | if(IsWindowIconic())
|
---|
1094 | rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
|
---|
1095 | else
|
---|
1096 | rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
|
---|
1097 | if (hdc == 0)
|
---|
1098 | ReleaseDC(getWindowHandle(), hdcErase);
|
---|
1099 | return (rc);
|
---|
1100 | }
|
---|
1101 | //******************************************************************************
|
---|
1102 | //******************************************************************************
|
---|
1103 | ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
|
---|
1104 | {
|
---|
1105 | //TODO: hiword should be 0 if window enters menu mode (SDK docs)
|
---|
1106 | SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
|
---|
1107 |
|
---|
1108 | //translated message == WM_(NC)MOUSEMOVE
|
---|
1109 | return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
|
---|
1110 | }
|
---|
1111 | //******************************************************************************
|
---|
1112 | //******************************************************************************
|
---|
1113 | ULONG Win32BaseWindow::MsgChar(MSG *msg)
|
---|
1114 | {
|
---|
1115 | return DispatchMsgA(msg);
|
---|
1116 | }
|
---|
1117 | //******************************************************************************
|
---|
1118 | //TODO: Should use update region, not rectangle
|
---|
1119 | //******************************************************************************
|
---|
1120 | ULONG Win32BaseWindow::MsgNCPaint(PRECT pUpdateRect)
|
---|
1121 | {
|
---|
1122 | HRGN hrgn;
|
---|
1123 | ULONG rc;
|
---|
1124 | RECT client = rectClient;
|
---|
1125 |
|
---|
1126 | if ((pUpdateRect->left >= client.left) && (pUpdateRect->left < client.right) &&
|
---|
1127 | (pUpdateRect->right >= client.left) && (pUpdateRect->right < client.right) &&
|
---|
1128 | (pUpdateRect->top >= client.top) && (pUpdateRect->top < client.bottom) &&
|
---|
1129 | (pUpdateRect->bottom >= client.top) && (pUpdateRect->bottom < client.bottom))
|
---|
1130 | {
|
---|
1131 | return 0;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | dprintf(("MsgNCPaint (%d,%d)(%d,%d)", pUpdateRect->left, pUpdateRect->top, pUpdateRect->right, pUpdateRect->bottom));
|
---|
1135 | hrgn = CreateRectRgnIndirect(pUpdateRect);
|
---|
1136 |
|
---|
1137 | rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
|
---|
1138 |
|
---|
1139 | DeleteObject(hrgn);
|
---|
1140 |
|
---|
1141 | return rc;
|
---|
1142 | }
|
---|
1143 | //******************************************************************************
|
---|
1144 | //Called when either the frame's size or position has changed (lpWndPos != NULL)
|
---|
1145 | //or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
|
---|
1146 | //******************************************************************************
|
---|
1147 | ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
|
---|
1148 | {
|
---|
1149 | RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
|
---|
1150 | RECT newClientRect;
|
---|
1151 | WINDOWPOS wndPos;
|
---|
1152 | ULONG rc;
|
---|
1153 |
|
---|
1154 | if(lpWndPos)
|
---|
1155 | {
|
---|
1156 | //set new window rectangle
|
---|
1157 | setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
|
---|
1158 | lpWndPos->y+lpWndPos->cy);
|
---|
1159 | newWindowRect = rectWindow;
|
---|
1160 | }
|
---|
1161 | else {
|
---|
1162 | wndPos.hwnd = getWindowHandle();
|
---|
1163 | wndPos.hwndInsertAfter = 0;
|
---|
1164 | newWindowRect= rectWindow;
|
---|
1165 | wndPos.x = newWindowRect.left;
|
---|
1166 | wndPos.y = newWindowRect.top;
|
---|
1167 | wndPos.cx = newWindowRect.right - newWindowRect.left;
|
---|
1168 | wndPos.cy = newWindowRect.bottom - newWindowRect.top;
|
---|
1169 | wndPos.flags = SWP_FRAMECHANGED;
|
---|
1170 | lpWndPos = &wndPos;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | newClientRect = rectClient;
|
---|
1174 | rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &newClientRect);
|
---|
1175 | rectClient = newClientRect; //must update rectClient here
|
---|
1176 |
|
---|
1177 | dprintf(("MsgFormatFrame: old client rect (%d,%d)(%d,%d), new client (%d,%d)(%d,%d)", client.left, client.top, client.right, client.bottom, rectClient.left, rectClient.top, rectClient.right, rectClient.bottom));
|
---|
1178 | dprintf(("MsgFormatFrame: old window rect (%d,%d)(%d,%d), new window (%d,%d)(%d,%d)", oldWindowRect.left, oldWindowRect.top, oldWindowRect.right, oldWindowRect.bottom, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
|
---|
1179 |
|
---|
1180 | if(fNoSizeMsg || !EqualRect(&client, &rectClient)) {
|
---|
1181 | OSLibWinSetClientPos(getOS2WindowHandle(), rectClient.left, rectClient.top, getClientWidth(), getClientHeight(), getWindowHeight());
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | #if 1
|
---|
1185 | //this doesn't always work
|
---|
1186 | // if(!fNoSizeMsg && (client.left != rectClient.left || client.top != rectClient.top))
|
---|
1187 | if(!fNoSizeMsg && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
|
---|
1188 | || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
|
---|
1189 | (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
|
---|
1190 | {
|
---|
1191 | Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
|
---|
1192 |
|
---|
1193 | //client rectangle has moved -> inform children
|
---|
1194 | dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
|
---|
1195 | while(child) {
|
---|
1196 | ::SetWindowPos(child->getWindowHandle(),
|
---|
1197 | HWND_TOP, child->getWindowRect()->left,
|
---|
1198 | child->getWindowRect()->top, 0, 0,
|
---|
1199 | SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
|
---|
1200 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
1201 | }
|
---|
1202 | }
|
---|
1203 | #endif
|
---|
1204 | return rc;
|
---|
1205 | }
|
---|
1206 | //******************************************************************************
|
---|
1207 | //******************************************************************************
|
---|
1208 | ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
|
---|
1209 | {
|
---|
1210 | return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
|
---|
1211 | }
|
---|
1212 | //******************************************************************************
|
---|
1213 | //******************************************************************************
|
---|
1214 | ULONG Win32BaseWindow::MsgGetTextLength()
|
---|
1215 | {
|
---|
1216 | return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
|
---|
1217 | }
|
---|
1218 | //******************************************************************************
|
---|
1219 | //******************************************************************************
|
---|
1220 | void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
|
---|
1221 | {
|
---|
1222 | SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
|
---|
1223 | }
|
---|
1224 | //******************************************************************************
|
---|
1225 | //******************************************************************************
|
---|
1226 | BOOL Win32BaseWindow::isMDIClient()
|
---|
1227 | {
|
---|
1228 | return FALSE;
|
---|
1229 | }
|
---|
1230 | //******************************************************************************
|
---|
1231 | //******************************************************************************
|
---|
1232 | BOOL Win32BaseWindow::isMDIChild()
|
---|
1233 | {
|
---|
1234 | return FALSE;
|
---|
1235 | }
|
---|
1236 | //******************************************************************************
|
---|
1237 | //TODO: Not complete
|
---|
1238 | //******************************************************************************
|
---|
1239 | BOOL Win32BaseWindow::isFrameWindow()
|
---|
1240 | {
|
---|
1241 | if(getParent() == NULL)
|
---|
1242 | return TRUE;
|
---|
1243 |
|
---|
1244 | return FALSE;
|
---|
1245 | }
|
---|
1246 | //******************************************************************************
|
---|
1247 | //******************************************************************************
|
---|
1248 | BOOL Win32BaseWindow::isDesktopWindow()
|
---|
1249 | {
|
---|
1250 | return FALSE;
|
---|
1251 | }
|
---|
1252 | //******************************************************************************
|
---|
1253 | //******************************************************************************
|
---|
1254 | BOOL Win32BaseWindow::IsWindowIconic()
|
---|
1255 | {
|
---|
1256 | return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
|
---|
1257 | }
|
---|
1258 | //******************************************************************************
|
---|
1259 | //******************************************************************************
|
---|
1260 | SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
|
---|
1261 | {
|
---|
1262 | switch(nBar)
|
---|
1263 | {
|
---|
1264 | case SB_HORZ:
|
---|
1265 | if (!horzScrollInfo)
|
---|
1266 | {
|
---|
1267 | horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
1268 | if (!horzScrollInfo) break;
|
---|
1269 | horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
|
---|
1270 | horzScrollInfo->MaxVal = 100;
|
---|
1271 | horzScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
1272 | }
|
---|
1273 | return horzScrollInfo;
|
---|
1274 |
|
---|
1275 | case SB_VERT:
|
---|
1276 | if (!vertScrollInfo)
|
---|
1277 | {
|
---|
1278 | vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
|
---|
1279 | if (!vertScrollInfo) break;
|
---|
1280 | vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
|
---|
1281 | vertScrollInfo->MaxVal = 100;
|
---|
1282 | vertScrollInfo->flags = ESB_ENABLE_BOTH;
|
---|
1283 | }
|
---|
1284 | return vertScrollInfo;
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | return NULL;
|
---|
1288 | }
|
---|
1289 | //******************************************************************************
|
---|
1290 | //******************************************************************************
|
---|
1291 | LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
|
---|
1292 | {
|
---|
1293 | //SvL: Set background color to default button color (not window (white))
|
---|
1294 | if(ctlType == CTLCOLOR_BTN)
|
---|
1295 | {
|
---|
1296 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
|
---|
1297 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
1298 | return GetSysColorBrush(COLOR_BTNFACE);
|
---|
1299 | }
|
---|
1300 | //SvL: Set background color to default dialog color if window is dialog
|
---|
1301 | if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
|
---|
1302 | SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
|
---|
1303 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
1304 | return GetSysColorBrush(COLOR_BTNFACE);
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | if( ctlType == CTLCOLOR_SCROLLBAR)
|
---|
1308 | {
|
---|
1309 | HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
|
---|
1310 | COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
|
---|
1311 | SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
|
---|
1312 | SetBkColor( hdc, bk);
|
---|
1313 |
|
---|
1314 | /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
|
---|
1315 | * we better use 0x55aa bitmap brush to make scrollbar's background
|
---|
1316 | * look different from the window background.
|
---|
1317 | */
|
---|
1318 | if (bk == GetSysColor(COLOR_WINDOW)) {
|
---|
1319 | return GetPattern55AABrush();
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 | UnrealizeObject( hb );
|
---|
1323 | return (LRESULT)hb;
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
1327 |
|
---|
1328 | if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
|
---|
1329 | {
|
---|
1330 | SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
|
---|
1331 | }
|
---|
1332 | else
|
---|
1333 | {
|
---|
1334 | SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
|
---|
1335 | return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
|
---|
1336 | }
|
---|
1337 | return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
|
---|
1338 | }
|
---|
1339 | //******************************************************************************
|
---|
1340 | //******************************************************************************
|
---|
1341 | LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
|
---|
1342 | {
|
---|
1343 | /*
|
---|
1344 | * Visibility flag.
|
---|
1345 | */
|
---|
1346 | if ( (uFlags & PRF_CHECKVISIBLE) &&
|
---|
1347 | !IsWindowVisible(getWindowHandle()) )
|
---|
1348 | return 0;
|
---|
1349 |
|
---|
1350 | /*
|
---|
1351 | * Unimplemented flags.
|
---|
1352 | */
|
---|
1353 | if ( (uFlags & PRF_CHILDREN) ||
|
---|
1354 | (uFlags & PRF_OWNED) ||
|
---|
1355 | (uFlags & PRF_NONCLIENT) )
|
---|
1356 | {
|
---|
1357 | dprintf(("WM_PRINT message with unsupported flags\n"));
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | /*
|
---|
1361 | * Background
|
---|
1362 | */
|
---|
1363 | if ( uFlags & PRF_ERASEBKGND)
|
---|
1364 | SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
|
---|
1365 |
|
---|
1366 | /*
|
---|
1367 | * Client area
|
---|
1368 | */
|
---|
1369 | if ( uFlags & PRF_CLIENT)
|
---|
1370 | SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
|
---|
1371 |
|
---|
1372 |
|
---|
1373 | return 0;
|
---|
1374 | }
|
---|
1375 | //******************************************************************************
|
---|
1376 | //******************************************************************************
|
---|
1377 | LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
1378 | {
|
---|
1379 | switch(Msg)
|
---|
1380 | {
|
---|
1381 | case WM_CLOSE:
|
---|
1382 | dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
|
---|
1383 | DestroyWindow();
|
---|
1384 | return 0;
|
---|
1385 |
|
---|
1386 | case WM_GETTEXTLENGTH:
|
---|
1387 | if(windowNameA) {
|
---|
1388 | return strlen(windowNameA);
|
---|
1389 | }
|
---|
1390 | else {
|
---|
1391 | return 0;
|
---|
1392 | }
|
---|
1393 |
|
---|
1394 | case WM_GETTEXT:
|
---|
1395 | if (!lParam || !wParam) return 0;
|
---|
1396 | if (!windowNameA) ((LPSTR)lParam)[0] = 0;
|
---|
1397 | else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
|
---|
1398 | return min((windowNameA ? strlen(windowNameA) : 0), wParam);
|
---|
1399 |
|
---|
1400 | case WM_SETTEXT:
|
---|
1401 | {
|
---|
1402 | LPCSTR lpsz = (LPCSTR)lParam;
|
---|
1403 |
|
---|
1404 | if(windowNameA) free(windowNameA);
|
---|
1405 | if(windowNameW) free(windowNameW);
|
---|
1406 | if (lParam)
|
---|
1407 | {
|
---|
1408 | int wndNameLength = strlen(lpsz);
|
---|
1409 | windowNameA = (LPSTR)_smalloc(wndNameLength+1);
|
---|
1410 | strcpy(windowNameA, lpsz);
|
---|
1411 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
1412 | lstrcpyAtoW(windowNameW, windowNameA);
|
---|
1413 | }
|
---|
1414 | else
|
---|
1415 | {
|
---|
1416 | windowNameA = NULL;
|
---|
1417 | windowNameW = NULL;
|
---|
1418 | }
|
---|
1419 | dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
|
---|
1420 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
1421 | {
|
---|
1422 | HandleNCPaint((HRGN)1);
|
---|
1423 | if(hTaskList) {
|
---|
1424 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
|
---|
1425 | }
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 | return TRUE;
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | case WM_SETREDRAW:
|
---|
1432 | {
|
---|
1433 | if (wParam)
|
---|
1434 | {
|
---|
1435 | setStyle(getStyle() | WS_VISIBLE);
|
---|
1436 | dprintf(("Enable window update for %x", getWindowHandle()));
|
---|
1437 | OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
|
---|
1438 | }
|
---|
1439 | else
|
---|
1440 | {
|
---|
1441 | if (getStyle() & WS_VISIBLE)
|
---|
1442 | {
|
---|
1443 | setStyle(getStyle() & ~WS_VISIBLE);
|
---|
1444 | dprintf(("Disable window update for %x", getWindowHandle()));
|
---|
1445 | OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
|
---|
1446 | }
|
---|
1447 | }
|
---|
1448 | return 0;
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | case WM_CTLCOLORMSGBOX:
|
---|
1452 | case WM_CTLCOLOREDIT:
|
---|
1453 | case WM_CTLCOLORLISTBOX:
|
---|
1454 | case WM_CTLCOLORBTN:
|
---|
1455 | case WM_CTLCOLORDLG:
|
---|
1456 | case WM_CTLCOLORSTATIC:
|
---|
1457 | case WM_CTLCOLORSCROLLBAR:
|
---|
1458 | return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
|
---|
1459 |
|
---|
1460 | case WM_CTLCOLOR:
|
---|
1461 | return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
|
---|
1462 |
|
---|
1463 | case WM_VKEYTOITEM:
|
---|
1464 | case WM_CHARTOITEM:
|
---|
1465 | return -1;
|
---|
1466 |
|
---|
1467 | case WM_PARENTNOTIFY:
|
---|
1468 | return 0;
|
---|
1469 |
|
---|
1470 | case WM_MOUSEACTIVATE:
|
---|
1471 | {
|
---|
1472 | dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
---|
1473 | if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
1474 | {
|
---|
1475 | if(getParent()) {
|
---|
1476 | LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
|
---|
1477 | if(rc) return rc;
|
---|
1478 | }
|
---|
1479 | }
|
---|
1480 | return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | case WM_ACTIVATE:
|
---|
1484 | /* The default action in Windows is to set the keyboard focus to
|
---|
1485 | * the window, if it's being activated and not minimized */
|
---|
1486 | if (LOWORD(wParam) != WA_INACTIVE) {
|
---|
1487 | if(!(getStyle() & WS_MINIMIZE))
|
---|
1488 | SetFocus(getWindowHandle());
|
---|
1489 | }
|
---|
1490 | return 0;
|
---|
1491 |
|
---|
1492 | case WM_SETCURSOR:
|
---|
1493 | {
|
---|
1494 | dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
|
---|
1495 | if((getStyle() & WS_CHILD))
|
---|
1496 | {
|
---|
1497 | if(getParent()) {
|
---|
1498 | LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
|
---|
1499 | if(rc) return rc;
|
---|
1500 | }
|
---|
1501 | }
|
---|
1502 | if (wParam == getWindowHandle())
|
---|
1503 | {
|
---|
1504 | HCURSOR hCursor;
|
---|
1505 |
|
---|
1506 | switch(LOWORD(lParam))
|
---|
1507 | {
|
---|
1508 | case HTCLIENT:
|
---|
1509 | hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
|
---|
1510 | break;
|
---|
1511 |
|
---|
1512 | case HTLEFT:
|
---|
1513 | case HTRIGHT:
|
---|
1514 | hCursor = LoadCursorA(0,IDC_SIZEWEA);
|
---|
1515 | break;
|
---|
1516 |
|
---|
1517 | case HTTOP:
|
---|
1518 | case HTBOTTOM:
|
---|
1519 | hCursor = LoadCursorA(0,IDC_SIZENSA);
|
---|
1520 | break;
|
---|
1521 |
|
---|
1522 | case HTTOPLEFT:
|
---|
1523 | case HTBOTTOMRIGHT:
|
---|
1524 | hCursor = LoadCursorA(0,IDC_SIZENWSEA);
|
---|
1525 | break;
|
---|
1526 |
|
---|
1527 | case HTTOPRIGHT:
|
---|
1528 | case HTBOTTOMLEFT:
|
---|
1529 | hCursor = LoadCursorA(0,IDC_SIZENESWA);
|
---|
1530 | break;
|
---|
1531 |
|
---|
1532 | default:
|
---|
1533 | hCursor = LoadCursorA(0,IDC_ARROWA);
|
---|
1534 | break;
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | if (hCursor)
|
---|
1538 | {
|
---|
1539 | SetCursor(hCursor);
|
---|
1540 | return 1;
|
---|
1541 | }
|
---|
1542 | else return 0;
|
---|
1543 | }
|
---|
1544 | else return 0;
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | case WM_MOUSEMOVE:
|
---|
1548 | return 0;
|
---|
1549 |
|
---|
1550 | case WM_WINDOWPOSCHANGED:
|
---|
1551 | {
|
---|
1552 | PWINDOWPOS wpos = (PWINDOWPOS)lParam;
|
---|
1553 | WPARAM wp = SIZE_RESTORED;
|
---|
1554 |
|
---|
1555 | if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
|
---|
1556 | {
|
---|
1557 | SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
|
---|
1558 | }
|
---|
1559 | if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
|
---|
1560 | {
|
---|
1561 | if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
|
---|
1562 | else
|
---|
1563 | if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
|
---|
1564 |
|
---|
1565 | SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
|
---|
1566 | rectClient.bottom - rectClient.top));
|
---|
1567 | }
|
---|
1568 | return 0;
|
---|
1569 | }
|
---|
1570 | case WM_WINDOWPOSCHANGING:
|
---|
1571 | return HandleWindowPosChanging((WINDOWPOS *)lParam);
|
---|
1572 |
|
---|
1573 | case WM_ERASEBKGND:
|
---|
1574 | case WM_ICONERASEBKGND:
|
---|
1575 | {
|
---|
1576 | RECT rect;
|
---|
1577 | int rc;
|
---|
1578 |
|
---|
1579 | if(getWindowHandle() == 0x68000044) {
|
---|
1580 | rc = GetClipBox( (HDC)wParam, &rect );
|
---|
1581 | FillRect( (HDC)wParam, &rect, GetSysColorBrush(COLOR_WINDOWTEXT));
|
---|
1582 | return 1;
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
|
---|
1586 |
|
---|
1587 | rc = GetClipBox( (HDC)wParam, &rect );
|
---|
1588 | if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
|
---|
1589 | {
|
---|
1590 | HBRUSH hBrush = windowClass->getBackgroundBrush();
|
---|
1591 |
|
---|
1592 | if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
|
---|
1593 | hBrush = GetSysColorBrush(hBrush-1);
|
---|
1594 |
|
---|
1595 | FillRect( (HDC)wParam, &rect, hBrush);
|
---|
1596 | }
|
---|
1597 | return 1;
|
---|
1598 | }
|
---|
1599 |
|
---|
1600 | case WM_PRINT:
|
---|
1601 | return DefWndPrint(wParam,lParam);
|
---|
1602 |
|
---|
1603 | case WM_PAINTICON:
|
---|
1604 | case WM_PAINT:
|
---|
1605 | {
|
---|
1606 | PAINTSTRUCT ps;
|
---|
1607 | HDC hdc = BeginPaint(getWindowHandle(), &ps );
|
---|
1608 | if( hdc )
|
---|
1609 | {
|
---|
1610 | if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
|
---|
1611 | {
|
---|
1612 | int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
|
---|
1613 | int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
|
---|
1614 | dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
|
---|
1615 | DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
|
---|
1616 | }
|
---|
1617 | EndPaint(getWindowHandle(), &ps );
|
---|
1618 | }
|
---|
1619 | return 0;
|
---|
1620 | }
|
---|
1621 |
|
---|
1622 | case WM_GETDLGCODE:
|
---|
1623 | return 0;
|
---|
1624 |
|
---|
1625 | case WM_NCPAINT:
|
---|
1626 | return HandleNCPaint((HRGN)wParam);
|
---|
1627 |
|
---|
1628 | case WM_NCACTIVATE:
|
---|
1629 | return HandleNCActivate(wParam);
|
---|
1630 |
|
---|
1631 | case WM_NCCREATE:
|
---|
1632 | return(TRUE);
|
---|
1633 |
|
---|
1634 | case WM_NCDESTROY:
|
---|
1635 | return 0;
|
---|
1636 |
|
---|
1637 | case WM_NCCALCSIZE:
|
---|
1638 | return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
|
---|
1639 |
|
---|
1640 | case WM_NCLBUTTONDOWN:
|
---|
1641 | return HandleNCLButtonDown(wParam,lParam);
|
---|
1642 |
|
---|
1643 | case WM_LBUTTONDBLCLK:
|
---|
1644 | case WM_NCLBUTTONDBLCLK:
|
---|
1645 | return HandleNCLButtonDblClk(wParam,lParam);
|
---|
1646 |
|
---|
1647 | case WM_NCRBUTTONDOWN:
|
---|
1648 | case WM_NCRBUTTONDBLCLK:
|
---|
1649 | case WM_NCMBUTTONDOWN:
|
---|
1650 | case WM_NCMBUTTONDBLCLK:
|
---|
1651 | if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
|
---|
1652 | return 0;
|
---|
1653 |
|
---|
1654 | case WM_NCRBUTTONUP:
|
---|
1655 | return HandleNCRButtonUp(wParam,lParam);
|
---|
1656 |
|
---|
1657 | case WM_NCMBUTTONUP:
|
---|
1658 | return 0;
|
---|
1659 |
|
---|
1660 | case WM_NCHITTEST:
|
---|
1661 | {
|
---|
1662 | POINT point;
|
---|
1663 | LRESULT retvalue;
|
---|
1664 |
|
---|
1665 | point.x = (SHORT)LOWORD(lParam);
|
---|
1666 | point.y = (SHORT)HIWORD(lParam);
|
---|
1667 |
|
---|
1668 | retvalue = HandleNCHitTest(point);
|
---|
1669 | #if 0 //CB: let the Corel people fix the bugs first
|
---|
1670 | if(retvalue == HTMENU)
|
---|
1671 | MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
|
---|
1672 | else
|
---|
1673 | MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
|
---|
1674 | #endif
|
---|
1675 | return retvalue;
|
---|
1676 | }
|
---|
1677 |
|
---|
1678 | case WM_SYSCOMMAND:
|
---|
1679 | {
|
---|
1680 | POINT point;
|
---|
1681 |
|
---|
1682 | point.x = LOWORD(lParam);
|
---|
1683 | point.y = HIWORD(lParam);
|
---|
1684 | return HandleSysCommand(wParam,&point);
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 | case WM_SYSKEYDOWN:
|
---|
1688 | if(wParam == VK_F4) /* try to close the window */
|
---|
1689 | {
|
---|
1690 | Win32BaseWindow *window = GetWindowFromHandle(GetTopParent());
|
---|
1691 | if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
|
---|
1692 | PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
|
---|
1693 | if(window) RELEASE_WNDOBJ(window);
|
---|
1694 | return 0;
|
---|
1695 | }
|
---|
1696 |
|
---|
1697 | Win32BaseWindow *siblingWindow;
|
---|
1698 | HWND sibling;
|
---|
1699 | char nameBuffer [40], mnemonic;
|
---|
1700 | int nameLength;
|
---|
1701 |
|
---|
1702 | GetWindowTextA (nameBuffer, 40);
|
---|
1703 |
|
---|
1704 | // search all sibling to see it this key is their mnemonic
|
---|
1705 | sibling = GetWindow (GW_HWNDFIRST);
|
---|
1706 | while (sibling != 0) {
|
---|
1707 | siblingWindow = GetWindowFromHandle (sibling);
|
---|
1708 | nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
|
---|
1709 |
|
---|
1710 | // find the siblings mnemonic
|
---|
1711 | mnemonic = '\0';
|
---|
1712 | for (int i=0 ; i<nameLength ; i++) {
|
---|
1713 | if (IsDBCSLeadByte(nameBuffer[i])) {
|
---|
1714 | // Skip DBCS
|
---|
1715 | continue;
|
---|
1716 | }
|
---|
1717 | if (nameBuffer [i] == '&') {
|
---|
1718 | mnemonic = nameBuffer [i+1];
|
---|
1719 | if ((mnemonic >= 'a') && (mnemonic <= 'z'))
|
---|
1720 | mnemonic -= 32; // make it uppercase
|
---|
1721 | break; // stop searching
|
---|
1722 | }
|
---|
1723 | }
|
---|
1724 |
|
---|
1725 | // key matches siblings mnemonic, send mouseclick
|
---|
1726 | if (mnemonic == (char) wParam) {
|
---|
1727 | siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
|
---|
1728 | }
|
---|
1729 | sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
|
---|
1730 | RELEASE_WNDOBJ(siblingWindow);
|
---|
1731 | }
|
---|
1732 |
|
---|
1733 | return 0;
|
---|
1734 |
|
---|
1735 | #if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
|
---|
1736 | case WM_KEYDOWN:
|
---|
1737 | case WM_KEYUP:
|
---|
1738 | case WM_SYSKEYDOWN:
|
---|
1739 | case WM_SYSKEYUP:
|
---|
1740 | #endif
|
---|
1741 |
|
---|
1742 | case WM_SYSCHAR:
|
---|
1743 | {
|
---|
1744 | int iMenuSysKey = 0;
|
---|
1745 | if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
|
---|
1746 | {
|
---|
1747 | PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
|
---|
1748 | (WPARAM)SC_RESTORE, 0L );
|
---|
1749 | break;
|
---|
1750 | }
|
---|
1751 | if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
|
---|
1752 | {
|
---|
1753 | if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
|
---|
1754 | break;
|
---|
1755 | if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
|
---|
1756 | getParent()->SendMessageA(Msg, wParam, lParam );
|
---|
1757 | }
|
---|
1758 | else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
|
---|
1759 | }
|
---|
1760 | #if 0
|
---|
1761 | else /* check for Ctrl-Esc */
|
---|
1762 | if (wParam != VK_ESCAPE) MessageBeep(0);
|
---|
1763 | break;
|
---|
1764 | #endif
|
---|
1765 | }
|
---|
1766 |
|
---|
1767 | case WM_SETHOTKEY:
|
---|
1768 | hotkey = wParam;
|
---|
1769 | return 1; //CB: always successful
|
---|
1770 |
|
---|
1771 | case WM_GETHOTKEY:
|
---|
1772 | return hotkey;
|
---|
1773 |
|
---|
1774 | case WM_CONTEXTMENU:
|
---|
1775 | if ((dwStyle & WS_CHILD) && getParent())
|
---|
1776 | getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
|
---|
1777 | return 0;
|
---|
1778 |
|
---|
1779 | case WM_SHOWWINDOW:
|
---|
1780 | if (!lParam) return 0; /* sent from ShowWindow */
|
---|
1781 | if (!(dwStyle & WS_POPUP) || !owner) return 0;
|
---|
1782 | if ((dwStyle & WS_VISIBLE) && wParam) return 0;
|
---|
1783 | else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
|
---|
1784 | ShowWindow(wParam ? SW_SHOW:SW_HIDE);
|
---|
1785 | return 0;
|
---|
1786 |
|
---|
1787 | case WM_CANCELMODE:
|
---|
1788 | if (getParent() == windowDesktop) EndMenu();
|
---|
1789 | if (GetCapture() == Win32Hwnd) ReleaseCapture();
|
---|
1790 | return 0;
|
---|
1791 |
|
---|
1792 | case WM_DROPOBJECT:
|
---|
1793 | return DRAG_FILE;
|
---|
1794 |
|
---|
1795 | case WM_QUERYDROPOBJECT:
|
---|
1796 | return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
|
---|
1797 |
|
---|
1798 | case WM_QUERYDRAGICON:
|
---|
1799 | {
|
---|
1800 | HICON hDragIcon = windowClass->getCursor();
|
---|
1801 | UINT len;
|
---|
1802 |
|
---|
1803 | if(hDragIcon) return (LRESULT)hDragIcon;
|
---|
1804 | for(len = 1; len < 64; len++)
|
---|
1805 | {
|
---|
1806 | hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
|
---|
1807 | if(hDragIcon)
|
---|
1808 | return (LRESULT)hDragIcon;
|
---|
1809 | }
|
---|
1810 | return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | case WM_QUERYOPEN:
|
---|
1814 | case WM_QUERYENDSESSION:
|
---|
1815 | return 1;
|
---|
1816 |
|
---|
1817 | case WM_NOTIFYFORMAT:
|
---|
1818 | return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
|
---|
1819 |
|
---|
1820 | case WM_SETICON:
|
---|
1821 | case WM_GETICON:
|
---|
1822 | {
|
---|
1823 | LRESULT result = 0;
|
---|
1824 |
|
---|
1825 | /* Set the appropriate icon members in the window structure. */
|
---|
1826 | if (wParam == ICON_SMALL)
|
---|
1827 | {
|
---|
1828 | result = hIconSm;
|
---|
1829 | if (Msg == WM_SETICON)
|
---|
1830 | hIconSm = (HICON)lParam;
|
---|
1831 | }
|
---|
1832 | else
|
---|
1833 | {
|
---|
1834 | result = hIcon;
|
---|
1835 | if (Msg == WM_SETICON)
|
---|
1836 | {
|
---|
1837 | hIcon = (HICON)lParam;
|
---|
1838 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
1839 | OSLibWinSetIcon(OS2Hwnd,hIcon);
|
---|
1840 | }
|
---|
1841 | }
|
---|
1842 | if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
|
---|
1843 | HandleNCPaint((HRGN)1);
|
---|
1844 |
|
---|
1845 | return result;
|
---|
1846 | }
|
---|
1847 |
|
---|
1848 | case WM_HELP:
|
---|
1849 | if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
|
---|
1850 | break;
|
---|
1851 |
|
---|
1852 | case WM_NOTIFY:
|
---|
1853 | return 0; //comctl32 controls expect this
|
---|
1854 |
|
---|
1855 | default:
|
---|
1856 | return 0;
|
---|
1857 | }
|
---|
1858 | return 0;
|
---|
1859 | }
|
---|
1860 | //******************************************************************************
|
---|
1861 | //******************************************************************************
|
---|
1862 | LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
1863 | {
|
---|
1864 | switch(Msg)
|
---|
1865 | {
|
---|
1866 | case WM_GETTEXTLENGTH:
|
---|
1867 | if(windowNameW) {
|
---|
1868 | return lstrlenW(windowNameW);
|
---|
1869 | }
|
---|
1870 | else return 0;
|
---|
1871 |
|
---|
1872 | case WM_GETTEXT:
|
---|
1873 | if (!lParam || !wParam) return 0;
|
---|
1874 | if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
|
---|
1875 | else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
|
---|
1876 | return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam);
|
---|
1877 |
|
---|
1878 | case WM_SETTEXT:
|
---|
1879 | {
|
---|
1880 | LPWSTR lpsz = (LPWSTR)lParam;
|
---|
1881 |
|
---|
1882 | if(windowNameA) free(windowNameA);
|
---|
1883 | if(windowNameW) free(windowNameW);
|
---|
1884 | if (lParam)
|
---|
1885 | {
|
---|
1886 | // Wide
|
---|
1887 | int wndNameLength = lstrlenW(lpsz);
|
---|
1888 | windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
|
---|
1889 | lstrcpyW(windowNameW,lpsz);
|
---|
1890 | // Ascii
|
---|
1891 | LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz);
|
---|
1892 | if(tmp) {
|
---|
1893 | long tmpLength = strlen( tmp );
|
---|
1894 | windowNameA = (LPSTR)_smalloc(tmpLength+1);
|
---|
1895 | strcpy(windowNameA,tmp);
|
---|
1896 | windowNameA[tmpLength] = 0; // need ?
|
---|
1897 | HEAP_free(tmp);
|
---|
1898 | }
|
---|
1899 | else {
|
---|
1900 | windowNameA = (LPSTR)_smalloc(1);
|
---|
1901 | windowNameA[0] = 0;
|
---|
1902 | }
|
---|
1903 | }
|
---|
1904 | else
|
---|
1905 | {
|
---|
1906 | windowNameA = NULL;
|
---|
1907 | windowNameW = NULL;
|
---|
1908 | }
|
---|
1909 | dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
|
---|
1910 | if ((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
1911 | {
|
---|
1912 | HandleNCPaint((HRGN)1);
|
---|
1913 | if(hTaskList) {
|
---|
1914 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
|
---|
1915 | }
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | return TRUE;
|
---|
1919 | }
|
---|
1920 |
|
---|
1921 | default:
|
---|
1922 | return DefWindowProcA(Msg, wParam, lParam);
|
---|
1923 | }
|
---|
1924 | }
|
---|
1925 | //******************************************************************************
|
---|
1926 | //******************************************************************************
|
---|
1927 | LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1928 | {
|
---|
1929 | //if the destination window is created by this process & thread, call window proc directly
|
---|
1930 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
|
---|
1931 | return SendInternalMessageA(Msg, wParam, lParam);
|
---|
1932 | }
|
---|
1933 | //otherwise use WinSendMsg to send it to the right process/thread
|
---|
1934 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
|
---|
1935 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
---|
1936 | }
|
---|
1937 | //******************************************************************************
|
---|
1938 | //******************************************************************************
|
---|
1939 | LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1940 | {
|
---|
1941 | //if the destination window is created by this process & thread, call window proc directly
|
---|
1942 | if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
|
---|
1943 | return SendInternalMessageW(Msg, wParam, lParam);
|
---|
1944 | }
|
---|
1945 | //otherwise use WinSendMsg to send it to the right process/thread
|
---|
1946 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
|
---|
1947 | }
|
---|
1948 | //******************************************************************************
|
---|
1949 | //Called as a result of an OS/2 message or called from a class method
|
---|
1950 | //******************************************************************************
|
---|
1951 | LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
1952 | {
|
---|
1953 | LRESULT rc;
|
---|
1954 | HWND hwnd = getWindowHandle();
|
---|
1955 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
1956 |
|
---|
1957 | //if the destination window was created by this process & thread, call window proc directly
|
---|
1958 | if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
|
---|
1959 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
|
---|
1960 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
---|
1961 | }
|
---|
1962 |
|
---|
1963 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
|
---|
1964 |
|
---|
1965 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
|
---|
1966 |
|
---|
1967 | fInternalMsg = TRUE;
|
---|
1968 | switch(Msg)
|
---|
1969 | {
|
---|
1970 | case WM_CREATE:
|
---|
1971 | {
|
---|
1972 | if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
1973 | dprintf(("WM_CREATE returned -1\n"));
|
---|
1974 | rc = -1; //don't create window
|
---|
1975 | break;
|
---|
1976 | }
|
---|
1977 | rc = 0;
|
---|
1978 | break;
|
---|
1979 | }
|
---|
1980 | case WM_LBUTTONDOWN:
|
---|
1981 | case WM_MBUTTONDOWN:
|
---|
1982 | case WM_RBUTTONDOWN:
|
---|
1983 | {
|
---|
1984 | if (getParent())
|
---|
1985 | {
|
---|
1986 | POINTS pt = MAKEPOINTS(lParam);
|
---|
1987 | POINT point;
|
---|
1988 |
|
---|
1989 | point.x = pt.x;
|
---|
1990 | point.y = pt.y;
|
---|
1991 | MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
|
---|
1992 | NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
|
---|
1993 | }
|
---|
1994 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
1995 | break;
|
---|
1996 | }
|
---|
1997 | case WM_NCHITTEST:
|
---|
1998 | rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
|
---|
1999 | break;
|
---|
2000 |
|
---|
2001 | case WM_DESTROY:
|
---|
2002 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
2003 | break;
|
---|
2004 |
|
---|
2005 | default:
|
---|
2006 | rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
|
---|
2007 | break;
|
---|
2008 | }
|
---|
2009 | if(!::IsWindow(hwnd)) {
|
---|
2010 | //window might have been destroyed by now. (this pointer invalid)
|
---|
2011 | //we must return immediately
|
---|
2012 | //(MS Visual C++ install heap corruption)
|
---|
2013 | //TODO: could happen in several places here!!!!
|
---|
2014 | return rc;
|
---|
2015 | }
|
---|
2016 | fInternalMsg = fInternalMsgBackup;
|
---|
2017 | dprintf2(("SendMessageA %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
|
---|
2018 | return rc;
|
---|
2019 | }
|
---|
2020 | //******************************************************************************
|
---|
2021 | //Called as a result of an OS/2 message or called from a class method
|
---|
2022 | //******************************************************************************
|
---|
2023 | LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
|
---|
2024 | {
|
---|
2025 | LRESULT rc;
|
---|
2026 | HWND hwnd = getWindowHandle();
|
---|
2027 | BOOL fInternalMsgBackup = fInternalMsg;
|
---|
2028 |
|
---|
2029 | //if the destination window was created by this process & thread, call window proc directly
|
---|
2030 | if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
|
---|
2031 | dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
|
---|
2032 | return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
|
---|
2033 | }
|
---|
2034 |
|
---|
2035 | DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
|
---|
2036 |
|
---|
2037 | CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
|
---|
2038 |
|
---|
2039 | fInternalMsg = TRUE;
|
---|
2040 | switch(Msg)
|
---|
2041 | {
|
---|
2042 | case WM_CREATE:
|
---|
2043 | {
|
---|
2044 | if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
|
---|
2045 | dprintf(("WM_CREATE returned -1\n"));
|
---|
2046 | rc = -1; //don't create window
|
---|
2047 | break;
|
---|
2048 | }
|
---|
2049 | rc = 0;
|
---|
2050 | break;
|
---|
2051 | }
|
---|
2052 | case WM_LBUTTONDOWN:
|
---|
2053 | case WM_MBUTTONDOWN:
|
---|
2054 | case WM_RBUTTONDOWN:
|
---|
2055 | NotifyParent(Msg, wParam, lParam);
|
---|
2056 | rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
|
---|
2057 | break;
|
---|
2058 |
|
---|
2059 | case WM_NCHITTEST:
|
---|
2060 | rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
|
---|
2061 | break;
|
---|
2062 |
|
---|
2063 | case WM_DESTROY:
|
---|
2064 | rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
|
---|
2065 | break;
|
---|
2066 | default:
|
---|
2067 | rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
|
---|
2068 | break;
|
---|
2069 | }
|
---|
2070 | if(!::IsWindow(hwnd)) {
|
---|
2071 | //window might have been destroyed by now. (this pointer invalid)
|
---|
2072 | //we must return immediately
|
---|
2073 | //(MS Visual C++ install heap corruption)
|
---|
2074 | //TODO: could happen in several places here!!!!
|
---|
2075 | return rc;
|
---|
2076 | }
|
---|
2077 | fInternalMsg = fInternalMsgBackup;
|
---|
2078 | dprintf2(("SendMessageW %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
|
---|
2079 | return rc;
|
---|
2080 | }
|
---|
2081 | //******************************************************************************
|
---|
2082 | //******************************************************************************
|
---|
2083 | void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
|
---|
2084 | {
|
---|
2085 | CWPSTRUCT cwp;
|
---|
2086 |
|
---|
2087 | cwp.lParam = lParam;
|
---|
2088 | cwp.wParam = wParam;
|
---|
2089 | cwp.message = Msg;
|
---|
2090 | cwp.hwnd = getWindowHandle();
|
---|
2091 |
|
---|
2092 | switch(hooktype) {
|
---|
2093 | case WH_CALLWNDPROC:
|
---|
2094 | if(fUnicode) {
|
---|
2095 | HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
|
---|
2096 | }
|
---|
2097 | else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
|
---|
2098 | break;
|
---|
2099 | }
|
---|
2100 | }
|
---|
2101 | //******************************************************************************
|
---|
2102 | //TODO: Do this more efficiently
|
---|
2103 | //******************************************************************************
|
---|
2104 | LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
2105 | {
|
---|
2106 | Win32BaseWindow *window;
|
---|
2107 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
|
---|
2108 |
|
---|
2109 | dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
|
---|
2110 |
|
---|
2111 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
|
---|
2112 | window = GetWindowFromHandle(hwnd++);
|
---|
2113 | if(window) {
|
---|
2114 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
|
---|
2115 | {
|
---|
2116 | if(type == BROADCAST_SEND) {
|
---|
2117 | ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
|
---|
2118 | }
|
---|
2119 | else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
|
---|
2120 | }
|
---|
2121 | RELEASE_WNDOBJ(window);
|
---|
2122 | }
|
---|
2123 | }
|
---|
2124 | return 0;
|
---|
2125 | }
|
---|
2126 | //******************************************************************************
|
---|
2127 | //TODO: Do this more efficiently
|
---|
2128 | //******************************************************************************
|
---|
2129 | LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
2130 | {
|
---|
2131 | Win32BaseWindow *window;
|
---|
2132 | HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
|
---|
2133 |
|
---|
2134 | dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
|
---|
2135 |
|
---|
2136 | for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
|
---|
2137 | window = GetWindowFromHandle(hwnd++);
|
---|
2138 | if(window) {
|
---|
2139 | if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
|
---|
2140 | {
|
---|
2141 | if(type == BROADCAST_SEND) {
|
---|
2142 | ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
|
---|
2143 | }
|
---|
2144 | else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
|
---|
2145 | }
|
---|
2146 | RELEASE_WNDOBJ(window);
|
---|
2147 | }
|
---|
2148 | }
|
---|
2149 | return 0;
|
---|
2150 | }
|
---|
2151 | //******************************************************************************
|
---|
2152 | //******************************************************************************
|
---|
2153 | void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
|
---|
2154 | {
|
---|
2155 | Win32BaseWindow *window = this;
|
---|
2156 | Win32BaseWindow *parentwindow;
|
---|
2157 |
|
---|
2158 | while(window)
|
---|
2159 | {
|
---|
2160 | if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
|
---|
2161 | {
|
---|
2162 | /* Notify the parent window only */
|
---|
2163 | parentwindow = window->getParent();
|
---|
2164 | if(parentwindow) {
|
---|
2165 | parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
|
---|
2166 | }
|
---|
2167 | }
|
---|
2168 | else break;
|
---|
2169 |
|
---|
2170 | window = parentwindow;
|
---|
2171 | }
|
---|
2172 | }
|
---|
2173 | //******************************************************************************
|
---|
2174 | // Returns the big or small icon for the window, falling back to the
|
---|
2175 | // class as windows does.
|
---|
2176 | //******************************************************************************
|
---|
2177 | HICON Win32BaseWindow::IconForWindow(WPARAM fType)
|
---|
2178 | {
|
---|
2179 | HICON hWndIcon;
|
---|
2180 |
|
---|
2181 | if (fType == ICON_BIG)
|
---|
2182 | {
|
---|
2183 | if (hIcon)
|
---|
2184 | hWndIcon = hIcon;
|
---|
2185 | else
|
---|
2186 | if (windowClass && windowClass->getIcon())
|
---|
2187 | hWndIcon = windowClass->getIcon();
|
---|
2188 | else
|
---|
2189 | if (!(dwStyle & DS_MODALFRAME))
|
---|
2190 | hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
|
---|
2191 | else hWndIcon = 0;
|
---|
2192 | }
|
---|
2193 | else
|
---|
2194 | {
|
---|
2195 | if (hIconSm)
|
---|
2196 | hWndIcon = hIconSm;
|
---|
2197 | else
|
---|
2198 | if (hIcon)
|
---|
2199 | hWndIcon = hIcon;
|
---|
2200 | else
|
---|
2201 | if (windowClass && windowClass->getIconSm())
|
---|
2202 | hWndIcon = windowClass->getIconSm();
|
---|
2203 | else
|
---|
2204 | if (windowClass && windowClass->getIcon())
|
---|
2205 | hWndIcon = windowClass->getIcon();
|
---|
2206 | else
|
---|
2207 | if (!(dwStyle & DS_MODALFRAME))
|
---|
2208 | hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
|
---|
2209 | else hWndIcon = 0;
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 | return hWndIcon;
|
---|
2213 | }
|
---|
2214 | //******************************************************************************
|
---|
2215 | //******************************************************************************
|
---|
2216 | BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
|
---|
2217 | {
|
---|
2218 | ULONG swp = 0;
|
---|
2219 | HWND hWinAfter;
|
---|
2220 | BOOL rc,wasVisible,showFlag;
|
---|
2221 | RECT newPos = {0, 0, 0, 0};
|
---|
2222 |
|
---|
2223 | dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
|
---|
2224 | wasVisible = (getStyle() & WS_VISIBLE) != 0;
|
---|
2225 |
|
---|
2226 | switch(nCmdShow)
|
---|
2227 | {
|
---|
2228 | case SW_HIDE:
|
---|
2229 | if (!wasVisible) goto END;
|
---|
2230 |
|
---|
2231 | swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
|
---|
2232 | break;
|
---|
2233 |
|
---|
2234 | case SW_SHOWMINNOACTIVE:
|
---|
2235 | swp |= SWP_NOACTIVATE | SWP_NOZORDER;
|
---|
2236 | /* fall through */
|
---|
2237 | case SW_SHOWMINIMIZED:
|
---|
2238 | swp |= SWP_SHOWWINDOW;
|
---|
2239 | /* fall through */
|
---|
2240 | case SW_MINIMIZE:
|
---|
2241 | swp |= SWP_FRAMECHANGED;
|
---|
2242 | if( !(getStyle() & WS_MINIMIZE) ) {
|
---|
2243 | swp |= MinMaximize(SW_MINIMIZE, &newPos );
|
---|
2244 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
|
---|
2245 | }
|
---|
2246 | else swp |= SWP_NOSIZE | SWP_NOMOVE;
|
---|
2247 | break;
|
---|
2248 |
|
---|
2249 | case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
|
---|
2250 | swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
|
---|
2251 | if( !(getStyle() & WS_MAXIMIZE) ) {
|
---|
2252 | swp |= MinMaximize(SW_MAXIMIZE, &newPos );
|
---|
2253 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
|
---|
2254 | }
|
---|
2255 | else swp |= SWP_NOSIZE | SWP_NOMOVE;
|
---|
2256 | break;
|
---|
2257 |
|
---|
2258 | case SW_SHOWNA:
|
---|
2259 | swp |= SWP_NOACTIVATE | SWP_NOZORDER;
|
---|
2260 | /* fall through */
|
---|
2261 | case SW_SHOW:
|
---|
2262 | swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
|
---|
2263 |
|
---|
2264 | /*
|
---|
2265 | * ShowWindow has a little peculiar behavior that if the
|
---|
2266 | * window is already the topmost window, it will not
|
---|
2267 | * activate it.
|
---|
2268 | */
|
---|
2269 | if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
|
---|
2270 | swp |= SWP_NOACTIVATE;
|
---|
2271 |
|
---|
2272 | break;
|
---|
2273 |
|
---|
2274 | case SW_SHOWNOACTIVATE:
|
---|
2275 | swp |= SWP_NOZORDER;
|
---|
2276 | if (GetActiveWindow())
|
---|
2277 | swp |= SWP_NOACTIVATE;
|
---|
2278 | /* fall through */
|
---|
2279 | case SW_SHOWNORMAL: /* same as SW_NORMAL: */
|
---|
2280 | case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
|
---|
2281 | case SW_RESTORE:
|
---|
2282 | //TODO: WIN_RESTORE_MAX flag!!!!!!!!!!!!!!
|
---|
2283 | swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
|
---|
2284 |
|
---|
2285 | if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
|
---|
2286 | swp |= MinMaximize(SW_RESTORE, &newPos );
|
---|
2287 | fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
|
---|
2288 | }
|
---|
2289 | else swp |= SWP_NOSIZE | SWP_NOMOVE;
|
---|
2290 | break;
|
---|
2291 | }
|
---|
2292 |
|
---|
2293 | showFlag = (nCmdShow != SW_HIDE);
|
---|
2294 | if (showFlag != wasVisible)
|
---|
2295 | {
|
---|
2296 | SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
|
---|
2297 | if (!::IsWindow( getWindowHandle() )) goto END;
|
---|
2298 | }
|
---|
2299 |
|
---|
2300 | /* We can't activate a child window */
|
---|
2301 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
|
---|
2302 | swp |= SWP_NOACTIVATE | SWP_NOZORDER;
|
---|
2303 |
|
---|
2304 | SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
|
---|
2305 |
|
---|
2306 | if(!(swp & SWP_NOACTIVATE)) {
|
---|
2307 | OSLibWinSetActiveWindow(OS2HwndFrame);
|
---|
2308 | }
|
---|
2309 |
|
---|
2310 | if (flags & WIN_NEED_SIZE)
|
---|
2311 | {
|
---|
2312 | /* should happen only in CreateWindowEx() */
|
---|
2313 | int wParam = SIZE_RESTORED;
|
---|
2314 |
|
---|
2315 | flags &= ~WIN_NEED_SIZE;
|
---|
2316 | if (dwStyle & WS_MAXIMIZE)
|
---|
2317 | wParam = SIZE_MAXIMIZED;
|
---|
2318 | else
|
---|
2319 | if (dwStyle & WS_MINIMIZE)
|
---|
2320 | wParam = SIZE_MINIMIZED;
|
---|
2321 |
|
---|
2322 | SendInternalMessageA(WM_SIZE, wParam,
|
---|
2323 | MAKELONG(rectClient.right-rectClient.left,
|
---|
2324 | rectClient.bottom-rectClient.top));
|
---|
2325 | SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
|
---|
2326 | }
|
---|
2327 | //testestest
|
---|
2328 | //temporary workaround for file dialogs with template dialog child
|
---|
2329 | //they don't redraw when switching directories
|
---|
2330 | //For some reason the new child's (syslistview32) update rectangle stays
|
---|
2331 | //empty after its parent is made visible with ShowWindow
|
---|
2332 | //TODO: find real cause
|
---|
2333 | if(!wasVisible) {
|
---|
2334 | InvalidateRect(getWindowHandle(), NULL, TRUE);
|
---|
2335 | }
|
---|
2336 | //testestest
|
---|
2337 | END:
|
---|
2338 | fMinMaxChange = FALSE;
|
---|
2339 | return wasVisible;
|
---|
2340 | }
|
---|
2341 | //******************************************************************************
|
---|
2342 | //******************************************************************************
|
---|
2343 | BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
|
---|
2344 | {
|
---|
2345 | BOOL rc = FALSE;
|
---|
2346 | Win32BaseWindow *window;
|
---|
2347 | HWND hParent = 0;
|
---|
2348 | RECT oldClientRect = rectClient;
|
---|
2349 |
|
---|
2350 | if (fuFlags &
|
---|
2351 | ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
|
---|
2352 | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
|
---|
2353 | SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
|
---|
2354 | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
|
---|
2355 | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
|
---|
2356 | {
|
---|
2357 | dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
|
---|
2358 | return FALSE;
|
---|
2359 | }
|
---|
2360 |
|
---|
2361 | if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
|
---|
2362 | dprintf(("WARNING: SetWindowPos; unsupported flag"));
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 | if(IsWindowDestroyed()) {
|
---|
2366 | //changing the position of a window that's being destroyed can cause crashes in PMMERGE
|
---|
2367 | dprintf(("SetWindowPos; window already destroyed"));
|
---|
2368 | return TRUE;
|
---|
2369 | }
|
---|
2370 | #if 0
|
---|
2371 | /* Fix redundant flags */
|
---|
2372 | if(getStyle() & WS_VISIBLE) {
|
---|
2373 | fuFlags &= ~SWP_SHOWWINDOW;
|
---|
2374 | }
|
---|
2375 | else
|
---|
2376 | {
|
---|
2377 | if (!(fuFlags & SWP_SHOWWINDOW))
|
---|
2378 | fuFlags |= SWP_NOREDRAW;
|
---|
2379 | fuFlags &= ~SWP_HIDEWINDOW;
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 | if(cx < 0) cx = 0;
|
---|
2383 | if(cy < 0) cy = 0;
|
---|
2384 |
|
---|
2385 | if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
|
---|
2386 | fuFlags |= SWP_NOSIZE; /* Already the right size */
|
---|
2387 | }
|
---|
2388 |
|
---|
2389 | if((rectWindow.left == x) && (rectWindow.top == y)) {
|
---|
2390 | fuFlags |= SWP_NOMOVE; /* Already the right position */
|
---|
2391 | }
|
---|
2392 |
|
---|
2393 | if(getWindowHandle() == GetActiveWindow()) {
|
---|
2394 | fuFlags |= SWP_NOACTIVATE; /* Already active */
|
---|
2395 | }
|
---|
2396 | else
|
---|
2397 | if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
|
---|
2398 | {
|
---|
2399 | if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
|
---|
2400 | {
|
---|
2401 | fuFlags &= ~SWP_NOZORDER;
|
---|
2402 | hwndInsertAfter = HWND_TOP;
|
---|
2403 | }
|
---|
2404 | }
|
---|
2405 | #endif
|
---|
2406 |
|
---|
2407 | if(!fCreateSetWindowPos)
|
---|
2408 | {//don't change size; modify internal structures only
|
---|
2409 | //TODO: not 100% correct yet (activate)
|
---|
2410 | if(!(fuFlags & SWP_NOZORDER)) {
|
---|
2411 | hwndLinkAfter = hwndInsertAfter;
|
---|
2412 | }
|
---|
2413 | if(!(fuFlags & SWP_NOMOVE)) {
|
---|
2414 | rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
|
---|
2415 | rectWindow.top = y;
|
---|
2416 | rectWindow.right = (rectWindow.right - rectWindow.left) + x;
|
---|
2417 | rectWindow.left = x;
|
---|
2418 | }
|
---|
2419 | if(!(fuFlags & SWP_NOSIZE)) {
|
---|
2420 | rectWindow.bottom = rectWindow.top + cy;
|
---|
2421 | rectWindow.right = rectWindow.left + cx;
|
---|
2422 | }
|
---|
2423 | return TRUE;
|
---|
2424 | }
|
---|
2425 |
|
---|
2426 | WINDOWPOS wpos;
|
---|
2427 | SWP swp, swpOld;
|
---|
2428 | wpos.flags = fuFlags;
|
---|
2429 | wpos.cy = cy;
|
---|
2430 | wpos.cx = cx;
|
---|
2431 | wpos.x = x;
|
---|
2432 | wpos.y = y;
|
---|
2433 | wpos.hwndInsertAfter = hwndInsertAfter;
|
---|
2434 | wpos.hwnd = getWindowHandle();
|
---|
2435 |
|
---|
2436 | if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
|
---|
2437 | {
|
---|
2438 | if (isChild())
|
---|
2439 | {
|
---|
2440 | if(!getParent()) {
|
---|
2441 | dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
|
---|
2442 | }
|
---|
2443 | }
|
---|
2444 | OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
|
---|
2445 | }
|
---|
2446 |
|
---|
2447 | if(getParent()) {
|
---|
2448 | OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
|
---|
2449 | OS2HwndFrame);
|
---|
2450 | }
|
---|
2451 | else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
|
---|
2452 |
|
---|
2453 | if (swp.fl == 0) {
|
---|
2454 | if(fuFlags & SWP_FRAMECHANGED)
|
---|
2455 | {
|
---|
2456 | NotifyFrameChanged(&wpos, &oldClientRect);
|
---|
2457 | }
|
---|
2458 | return TRUE;
|
---|
2459 | }
|
---|
2460 |
|
---|
2461 | // if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
---|
2462 | if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
|
---|
2463 | {
|
---|
2464 | Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
|
---|
2465 | if(wndBehind) {
|
---|
2466 | swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
|
---|
2467 | RELEASE_WNDOBJ(wndBehind);
|
---|
2468 | }
|
---|
2469 | else {
|
---|
2470 | dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
|
---|
2471 | swp.hwndInsertBehind = 0;
|
---|
2472 | }
|
---|
2473 | }
|
---|
2474 | swp.hwnd = OS2HwndFrame;
|
---|
2475 |
|
---|
2476 | if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
|
---|
2477 | setStyle(getStyle() | WS_VISIBLE);
|
---|
2478 | if(hTaskList) {
|
---|
2479 | dprintf(("Adding window %x to tasklist", getWindowHandle()));
|
---|
2480 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
|
---|
2481 | }
|
---|
2482 | }
|
---|
2483 | else
|
---|
2484 | if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
|
---|
2485 | setStyle(getStyle() & ~WS_VISIBLE);
|
---|
2486 | if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
|
---|
2487 | dprintf(("Removing window %x from tasklist", getWindowHandle()));
|
---|
2488 | OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
|
---|
2489 | }
|
---|
2490 | }
|
---|
2491 | dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
|
---|
2492 | rc = OSLibWinSetMultWindowPos(&swp, 1);
|
---|
2493 |
|
---|
2494 | if(rc == FALSE)
|
---|
2495 | {
|
---|
2496 | dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
|
---|
2497 | return 0;
|
---|
2498 | }
|
---|
2499 |
|
---|
2500 | if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
|
---|
2501 | {
|
---|
2502 | NotifyFrameChanged(&wpos, &oldClientRect);
|
---|
2503 | }
|
---|
2504 | return (rc);
|
---|
2505 | }
|
---|
2506 | //******************************************************************************
|
---|
2507 | //Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
|
---|
2508 | //******************************************************************************
|
---|
2509 | BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
|
---|
2510 | {
|
---|
2511 | rectWindow.left += dx;
|
---|
2512 | rectWindow.right += dx;
|
---|
2513 | rectWindow.top += dy;
|
---|
2514 | rectWindow.bottom += dy;
|
---|
2515 | SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
|
---|
2516 | return TRUE;
|
---|
2517 | }
|
---|
2518 | //******************************************************************************
|
---|
2519 | //******************************************************************************
|
---|
2520 | void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
|
---|
2521 | {
|
---|
2522 | HRGN hrgn, hrgnClient;
|
---|
2523 | RECT rect;
|
---|
2524 |
|
---|
2525 | MsgFormatFrame(NULL);
|
---|
2526 |
|
---|
2527 | if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
|
---|
2528 | RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
|
---|
2529 | {
|
---|
2530 | wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
|
---|
2531 | wpos->cx = RECT_WIDTH(rectWindow);
|
---|
2532 | wpos->cy = RECT_HEIGHT(rectWindow);
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 | if(rectClient.left != oldClientRect->left ||
|
---|
2536 | rectClient.top != oldClientRect->top)
|
---|
2537 | {
|
---|
2538 | wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
|
---|
2539 | wpos->x = rectWindow.left;
|
---|
2540 | wpos->y = rectWindow.top;
|
---|
2541 | }
|
---|
2542 |
|
---|
2543 | WINDOWPOS wpOld = *wpos;
|
---|
2544 | SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
|
---|
2545 |
|
---|
2546 | if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
|
---|
2547 | (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
|
---|
2548 | {
|
---|
2549 | dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
|
---|
2550 | SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
|
---|
2551 | }
|
---|
2552 | else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
|
---|
2553 |
|
---|
2554 | //Calculate invalid areas
|
---|
2555 | rect = rectWindow;
|
---|
2556 | OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
|
---|
2557 | hrgn = CreateRectRgnIndirect(&rect);
|
---|
2558 | if (!hrgn) {
|
---|
2559 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
|
---|
2560 | return;
|
---|
2561 | }
|
---|
2562 | rect = rectClient;
|
---|
2563 | hrgnClient = CreateRectRgnIndirect(&rect);
|
---|
2564 | if (!hrgn) {
|
---|
2565 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
|
---|
2566 | return;
|
---|
2567 | }
|
---|
2568 | CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
|
---|
2569 | DeleteObject(hrgnClient);
|
---|
2570 |
|
---|
2571 | if(!EqualRect(oldClientRect, &rectClient)) {
|
---|
2572 | UnionRect(oldClientRect, oldClientRect, &rectClient);
|
---|
2573 | hrgnClient = CreateRectRgnIndirect(oldClientRect);
|
---|
2574 | if (!hrgn) {
|
---|
2575 | dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
|
---|
2576 | return;
|
---|
2577 | }
|
---|
2578 | CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
|
---|
2579 | DeleteObject(hrgnClient);
|
---|
2580 | }
|
---|
2581 | RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
|
---|
2582 | RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
|
---|
2583 | DeleteObject(hrgn);
|
---|
2584 | }
|
---|
2585 | //******************************************************************************
|
---|
2586 | //TODO: Check how this api really works in NT
|
---|
2587 | //******************************************************************************
|
---|
2588 | BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
|
---|
2589 | {
|
---|
2590 | dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
|
---|
2591 | dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
|
---|
2592 | dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
|
---|
2593 | windowpos.ptMinPosition = wndpl->ptMinPosition;
|
---|
2594 | windowpos.ptMaxPosition = wndpl->ptMaxPosition;
|
---|
2595 | windowpos.rcNormalPosition = wndpl->rcNormalPosition;
|
---|
2596 |
|
---|
2597 | if(getStyle() & WS_MINIMIZE )
|
---|
2598 | {
|
---|
2599 | //TODO: Why can't this be (0,0)?
|
---|
2600 | if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
|
---|
2601 | SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
|
---|
2602 | 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
---|
2603 | }
|
---|
2604 | }
|
---|
2605 | else
|
---|
2606 | if(getStyle() & WS_MAXIMIZE )
|
---|
2607 | {
|
---|
2608 | //TODO: Why can't this be (0,0)?
|
---|
2609 | if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
|
---|
2610 | SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
|
---|
2611 | 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
---|
2612 | }
|
---|
2613 | else {
|
---|
2614 | SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
|
---|
2615 | windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
|
---|
2616 | windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
|
---|
2617 | SWP_NOZORDER | SWP_NOACTIVATE );
|
---|
2618 | }
|
---|
2619 | ShowWindow(wndpl->showCmd);
|
---|
2620 | if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
|
---|
2621 | {
|
---|
2622 | /* SDK: ...valid only the next time... */
|
---|
2623 | if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
|
---|
2624 | setFlags(getFlags() | WIN_RESTORE_MAX);
|
---|
2625 | }
|
---|
2626 | return TRUE;
|
---|
2627 | }
|
---|
2628 | //******************************************************************************
|
---|
2629 | //******************************************************************************
|
---|
2630 | BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
|
---|
2631 | {
|
---|
2632 | wndpl->length = sizeof(*wndpl);
|
---|
2633 | if(getStyle() & WS_MINIMIZE )
|
---|
2634 | wndpl->showCmd = SW_SHOWMINIMIZED;
|
---|
2635 | else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
|
---|
2636 |
|
---|
2637 | //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
|
---|
2638 | if(getFlags() & WIN_RESTORE_MAX )
|
---|
2639 | wndpl->flags = WPF_RESTORETOMAXIMIZED;
|
---|
2640 | else wndpl->flags = 0;
|
---|
2641 |
|
---|
2642 | wndpl->ptMinPosition = windowpos.ptMinPosition;
|
---|
2643 | wndpl->ptMaxPosition = windowpos.ptMaxPosition;
|
---|
2644 | //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
|
---|
2645 | wndpl->rcNormalPosition = rectWindow;
|
---|
2646 |
|
---|
2647 | return TRUE;
|
---|
2648 | }
|
---|
2649 | //******************************************************************************
|
---|
2650 | //Also destroys all the child windows (destroy children first, parent last)
|
---|
2651 | //******************************************************************************
|
---|
2652 | BOOL Win32BaseWindow::DestroyWindow()
|
---|
2653 | {
|
---|
2654 | HWND hwnd = getWindowHandle();
|
---|
2655 |
|
---|
2656 | dprintf(("DestroyWindow %x", hwnd));
|
---|
2657 |
|
---|
2658 | /* Call hooks */
|
---|
2659 | if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
|
---|
2660 | {
|
---|
2661 | return FALSE;
|
---|
2662 | }
|
---|
2663 |
|
---|
2664 | if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
|
---|
2665 | {
|
---|
2666 | HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
|
---|
2667 | /* FIXME: clean up palette - see "Internals" p.352 */
|
---|
2668 | }
|
---|
2669 |
|
---|
2670 | if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
|
---|
2671 | {
|
---|
2672 | if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
|
---|
2673 | {
|
---|
2674 | /* Notify the parent window only */
|
---|
2675 | getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
|
---|
2676 | if(!::IsWindow(hwnd) )
|
---|
2677 | {
|
---|
2678 | return TRUE;
|
---|
2679 | }
|
---|
2680 | }
|
---|
2681 | //// else DebugInt3();
|
---|
2682 | }
|
---|
2683 | /* Hide the window */
|
---|
2684 | if(IsWindowVisible(getWindowHandle()))
|
---|
2685 | {
|
---|
2686 | SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
|
---|
2687 | SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
|
---|
2688 | if(!::IsWindow(hwnd))
|
---|
2689 | {
|
---|
2690 | return TRUE;
|
---|
2691 | }
|
---|
2692 | }
|
---|
2693 | dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
|
---|
2694 |
|
---|
2695 | fDestroyWindowCalled = TRUE;
|
---|
2696 | return OSLibWinDestroyWindow(OS2HwndFrame);
|
---|
2697 | }
|
---|
2698 | //******************************************************************************
|
---|
2699 | //******************************************************************************
|
---|
2700 | Win32BaseWindow *Win32BaseWindow::getParent()
|
---|
2701 | {
|
---|
2702 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
---|
2703 | return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
|
---|
2704 | }
|
---|
2705 | //******************************************************************************
|
---|
2706 | //Note: does not set last error if no parent (verified in NT4, SP6)
|
---|
2707 | //******************************************************************************
|
---|
2708 | HWND Win32BaseWindow::GetParent()
|
---|
2709 | {
|
---|
2710 | if((!(getStyle() & (WS_POPUP|WS_CHILD)))) {
|
---|
2711 | return 0;
|
---|
2712 | }
|
---|
2713 |
|
---|
2714 | Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
---|
2715 |
|
---|
2716 | if(getStyle() & WS_CHILD) {
|
---|
2717 | if(wndparent) {
|
---|
2718 | return wndparent->getWindowHandle();
|
---|
2719 | }
|
---|
2720 | dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
|
---|
2721 | DebugInt3();
|
---|
2722 | return 0;
|
---|
2723 | }
|
---|
2724 | else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
|
---|
2725 | }
|
---|
2726 | //******************************************************************************
|
---|
2727 | //******************************************************************************
|
---|
2728 | HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
|
---|
2729 | {
|
---|
2730 | HWND oldhwnd;
|
---|
2731 | Win32BaseWindow *newparent;
|
---|
2732 | Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
|
---|
2733 | BOOL fShow = FALSE;
|
---|
2734 |
|
---|
2735 | if(oldparent) {
|
---|
2736 | oldhwnd = oldparent->getWindowHandle();
|
---|
2737 | oldparent->removeChild(this);
|
---|
2738 | }
|
---|
2739 | else oldhwnd = 0;
|
---|
2740 |
|
---|
2741 | /* Windows hides the window first, then shows it again
|
---|
2742 | * including the WM_SHOWWINDOW messages and all */
|
---|
2743 | if(fCreated && (getStyle() & WS_VISIBLE)) {
|
---|
2744 | ShowWindow(SW_HIDE);
|
---|
2745 | fShow = TRUE;
|
---|
2746 | }
|
---|
2747 | if(oldparent) {
|
---|
2748 | RELEASE_WNDOBJ(oldparent);
|
---|
2749 | }
|
---|
2750 | newparent = GetWindowFromHandle(hwndNewParent);
|
---|
2751 | if(newparent && !newparent->isDesktopWindow())
|
---|
2752 | {
|
---|
2753 | setParent(newparent);
|
---|
2754 | getParent()->addChild(this);
|
---|
2755 | OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
|
---|
2756 | if(!(getStyle() & WS_CHILD))
|
---|
2757 | {
|
---|
2758 | //TODO: Send WM_STYLECHANGED msg?
|
---|
2759 | setStyle(getStyle() | WS_CHILD);
|
---|
2760 | if(getWindowId())
|
---|
2761 | {
|
---|
2762 | DestroyMenu( (HMENU) getWindowId() );
|
---|
2763 | setWindowId(0);
|
---|
2764 | }
|
---|
2765 | }
|
---|
2766 | }
|
---|
2767 | else {
|
---|
2768 | setParent(windowDesktop);
|
---|
2769 | windowDesktop->addChild(this);
|
---|
2770 | OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
|
---|
2771 |
|
---|
2772 | //TODO: Send WM_STYLECHANGED msg?
|
---|
2773 | setStyle(getStyle() & ~WS_CHILD);
|
---|
2774 | setWindowId(0);
|
---|
2775 | }
|
---|
2776 | /* SetParent additionally needs to make hwndChild the topmost window
|
---|
2777 | in the x-order and send the expected WM_WINDOWPOSCHANGING and
|
---|
2778 | WM_WINDOWPOSCHANGED notification messages.
|
---|
2779 | */
|
---|
2780 | if(fCreated) {
|
---|
2781 | SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
|
---|
2782 | SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
|
---|
2783 |
|
---|
2784 | /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
|
---|
2785 | * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
|
---|
2786 | }
|
---|
2787 | return oldhwnd;
|
---|
2788 | }
|
---|
2789 | //******************************************************************************
|
---|
2790 | //******************************************************************************
|
---|
2791 | BOOL Win32BaseWindow::IsChild(HWND hwndParent)
|
---|
2792 | {
|
---|
2793 | if(getParent()) {
|
---|
2794 | if(getParent()->getWindowHandle() == hwndParent)
|
---|
2795 | return TRUE;
|
---|
2796 |
|
---|
2797 | return getParent()->IsChild(hwndParent);
|
---|
2798 | }
|
---|
2799 | else return 0;
|
---|
2800 | }
|
---|
2801 | //******************************************************************************
|
---|
2802 | //******************************************************************************
|
---|
2803 | HWND Win32BaseWindow::GetTopWindow()
|
---|
2804 | {
|
---|
2805 | HWND hwndTop;
|
---|
2806 | Win32BaseWindow *topwindow;
|
---|
2807 |
|
---|
2808 | hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
|
---|
2809 | if(!isDesktopWindow())
|
---|
2810 | {
|
---|
2811 | topwindow = GetWindowFromOS2FrameHandle(hwndTop);
|
---|
2812 | if(topwindow) {
|
---|
2813 | hwndTop = topwindow->getWindowHandle();
|
---|
2814 | RELEASE_WNDOBJ(topwindow);
|
---|
2815 | return hwndTop;
|
---|
2816 | }
|
---|
2817 | return 0;
|
---|
2818 | }
|
---|
2819 | while(hwndTop) {
|
---|
2820 | topwindow = GetWindowFromOS2FrameHandle(hwndTop);
|
---|
2821 | if(topwindow) {
|
---|
2822 | hwndTop = topwindow->getWindowHandle();
|
---|
2823 | RELEASE_WNDOBJ(topwindow);
|
---|
2824 | return hwndTop;
|
---|
2825 | }
|
---|
2826 | hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
|
---|
2827 | }
|
---|
2828 |
|
---|
2829 | return 0;
|
---|
2830 | }
|
---|
2831 | //******************************************************************************
|
---|
2832 | // Get the top-level parent for a child window.
|
---|
2833 | //******************************************************************************
|
---|
2834 | HWND Win32BaseWindow::GetTopParent()
|
---|
2835 | {
|
---|
2836 | Win32BaseWindow *window = this;
|
---|
2837 | HWND hwndTopParent = 0;
|
---|
2838 |
|
---|
2839 | lock();
|
---|
2840 | while(window && (window->getStyle() & WS_CHILD))
|
---|
2841 | {
|
---|
2842 | window = window->getParent();
|
---|
2843 | }
|
---|
2844 | if(window) {
|
---|
2845 | hwndTopParent = window->getWindowHandle();
|
---|
2846 | }
|
---|
2847 | unlock();
|
---|
2848 | return hwndTopParent;
|
---|
2849 | }
|
---|
2850 | //******************************************************************************
|
---|
2851 | //TODO: Should not enumerate children that are created during the enumeration!
|
---|
2852 | //******************************************************************************
|
---|
2853 | BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
---|
2854 | {
|
---|
2855 | BOOL rc = TRUE;
|
---|
2856 | HWND hwnd;
|
---|
2857 | Win32BaseWindow *prevchild = 0, *child = 0;
|
---|
2858 |
|
---|
2859 | dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
|
---|
2860 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
2861 | {
|
---|
2862 | dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
|
---|
2863 | hwnd = child->getWindowHandle();
|
---|
2864 | if(child->getOwner()) {
|
---|
2865 | continue; //shouldn't have an owner (Wine)
|
---|
2866 | }
|
---|
2867 | if(lpfn(hwnd, lParam) == FALSE)
|
---|
2868 | {
|
---|
2869 | rc = FALSE;
|
---|
2870 | break;
|
---|
2871 | }
|
---|
2872 | //check if the window still exists
|
---|
2873 | if(!::IsWindow(hwnd))
|
---|
2874 | {
|
---|
2875 | child = prevchild;
|
---|
2876 | continue;
|
---|
2877 | }
|
---|
2878 | if(child->getFirstChild() != NULL)
|
---|
2879 | {
|
---|
2880 | dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
|
---|
2881 | if(child->EnumChildWindows(lpfn, lParam) == FALSE)
|
---|
2882 | {
|
---|
2883 | rc = FALSE;
|
---|
2884 | break;
|
---|
2885 | }
|
---|
2886 | }
|
---|
2887 | prevchild = child;
|
---|
2888 | }
|
---|
2889 | return rc;
|
---|
2890 | }
|
---|
2891 | //******************************************************************************
|
---|
2892 | //Enumerate first-level children only and check thread id
|
---|
2893 | //******************************************************************************
|
---|
2894 | BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
|
---|
2895 | {
|
---|
2896 | Win32BaseWindow *child = 0;
|
---|
2897 | ULONG tid, pid;
|
---|
2898 | BOOL rc;
|
---|
2899 | HWND hwnd;
|
---|
2900 |
|
---|
2901 | dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
|
---|
2902 |
|
---|
2903 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
2904 | {
|
---|
2905 | OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
|
---|
2906 |
|
---|
2907 | if(dwThreadId == tid) {
|
---|
2908 | dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
|
---|
2909 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
|
---|
2910 | break;
|
---|
2911 | }
|
---|
2912 | }
|
---|
2913 | }
|
---|
2914 | return TRUE;
|
---|
2915 | }
|
---|
2916 | //******************************************************************************
|
---|
2917 | //Enumerate first-level children only
|
---|
2918 | //******************************************************************************
|
---|
2919 | BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
|
---|
2920 | {
|
---|
2921 | Win32BaseWindow *child = 0;
|
---|
2922 | BOOL rc;
|
---|
2923 | HWND hwnd;
|
---|
2924 |
|
---|
2925 | dprintf(("EnumWindows %x %x", lpfn, lParam));
|
---|
2926 |
|
---|
2927 | for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
2928 | {
|
---|
2929 | hwnd = child->getWindowHandle();
|
---|
2930 |
|
---|
2931 | dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
|
---|
2932 | if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
|
---|
2933 | break;
|
---|
2934 | }
|
---|
2935 | }
|
---|
2936 | return TRUE;
|
---|
2937 | }
|
---|
2938 | //******************************************************************************
|
---|
2939 | //******************************************************************************
|
---|
2940 | HWND Win32BaseWindow::FindWindowById(int id)
|
---|
2941 | {
|
---|
2942 | lock();
|
---|
2943 | for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
|
---|
2944 | {
|
---|
2945 | if (child->getWindowId() == id)
|
---|
2946 | {
|
---|
2947 | unlock();
|
---|
2948 | return child->getWindowHandle();
|
---|
2949 | }
|
---|
2950 | }
|
---|
2951 | unlock();
|
---|
2952 | return 0;
|
---|
2953 | }
|
---|
2954 | //******************************************************************************
|
---|
2955 | //TODO:
|
---|
2956 | //We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
|
---|
2957 | //the current process owns them.
|
---|
2958 | //******************************************************************************
|
---|
2959 | HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
|
---|
2960 | {
|
---|
2961 | Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
|
---|
2962 | Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
|
---|
2963 | Win32BaseWindow *firstchild = child;
|
---|
2964 |
|
---|
2965 | dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
|
---|
2966 | if((hwndParent != 0 && !parent) ||
|
---|
2967 | (hwndChildAfter != 0 && !child) ||
|
---|
2968 | (hwndParent == 0 && hwndChildAfter != 0))
|
---|
2969 | {
|
---|
2970 | if(parent) RELEASE_WNDOBJ(parent);
|
---|
2971 | if(firstchild) RELEASE_WNDOBJ(firstchild);
|
---|
2972 | dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
|
---|
2973 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
2974 | return 0;
|
---|
2975 | }
|
---|
2976 | SetLastError(0);
|
---|
2977 | if(hwndParent != 0)
|
---|
2978 | {//if the current process owns the window, just do a quick search
|
---|
2979 | lock(&critsect);
|
---|
2980 | child = (Win32BaseWindow *)parent->getFirstChild();
|
---|
2981 | if(hwndChildAfter != 0)
|
---|
2982 | {
|
---|
2983 | while(child)
|
---|
2984 | {
|
---|
2985 | if(child->getWindowHandle() == hwndChildAfter)
|
---|
2986 | {
|
---|
2987 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
2988 | break;
|
---|
2989 | }
|
---|
2990 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
2991 | }
|
---|
2992 | }
|
---|
2993 | while(child)
|
---|
2994 | {
|
---|
2995 | //According to Wine, the class doesn't need to be specified
|
---|
2996 | if((!atom || child->getWindowClass()->getAtom() == atom) &&
|
---|
2997 | (!lpszWindow || child->hasWindowName(lpszWindow)))
|
---|
2998 | {
|
---|
2999 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
|
---|
3000 | HWND hwndChild = child->getWindowHandle();
|
---|
3001 | unlock(&critsect);
|
---|
3002 | if(parent) RELEASE_WNDOBJ(parent);
|
---|
3003 | if(firstchild) RELEASE_WNDOBJ(firstchild);
|
---|
3004 | dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
|
---|
3005 | return hwndChild;
|
---|
3006 | }
|
---|
3007 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
3008 | }
|
---|
3009 | unlock(&critsect);
|
---|
3010 | if(parent) RELEASE_WNDOBJ(parent);
|
---|
3011 | if(firstchild) RELEASE_WNDOBJ(firstchild);
|
---|
3012 | }
|
---|
3013 | else {
|
---|
3014 | Win32BaseWindow *wnd;
|
---|
3015 | HWND henum, hwnd;
|
---|
3016 |
|
---|
3017 | henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
|
---|
3018 | hwnd = OSLibWinGetNextWindow(henum);
|
---|
3019 |
|
---|
3020 | while(hwnd)
|
---|
3021 | {
|
---|
3022 | wnd = GetWindowFromOS2FrameHandle(hwnd);
|
---|
3023 | if(wnd == NULL) {
|
---|
3024 | hwnd = OSLibWinQueryClientWindow(hwnd);
|
---|
3025 | if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
|
---|
3026 | }
|
---|
3027 |
|
---|
3028 | if(wnd) {
|
---|
3029 | //According to Wine, the class doesn't need to be specified
|
---|
3030 | if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
|
---|
3031 | (!lpszWindow || wnd->hasWindowName(lpszWindow)))
|
---|
3032 | {
|
---|
3033 | OSLibWinEndEnumWindows(henum);
|
---|
3034 | dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
|
---|
3035 | HWND hwndret = wnd->getWindowHandle();
|
---|
3036 | RELEASE_WNDOBJ(wnd);
|
---|
3037 | return hwndret;
|
---|
3038 | }
|
---|
3039 | RELEASE_WNDOBJ(wnd);
|
---|
3040 | }
|
---|
3041 | hwnd = OSLibWinGetNextWindow(henum);
|
---|
3042 | }
|
---|
3043 | OSLibWinEndEnumWindows(henum);
|
---|
3044 | if(parent) RELEASE_WNDOBJ(parent);
|
---|
3045 | if(firstchild) RELEASE_WNDOBJ(firstchild);
|
---|
3046 | }
|
---|
3047 | SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
|
---|
3048 | return 0;
|
---|
3049 | }
|
---|
3050 | //******************************************************************************
|
---|
3051 | //******************************************************************************
|
---|
3052 | HWND Win32BaseWindow::GetWindow(UINT uCmd)
|
---|
3053 | {
|
---|
3054 | HWND hwndRelated = 0;
|
---|
3055 | Win32BaseWindow *window;
|
---|
3056 |
|
---|
3057 | switch(uCmd)
|
---|
3058 | {
|
---|
3059 | case GW_HWNDFIRST:
|
---|
3060 | if(getParent())
|
---|
3061 | {
|
---|
3062 | window = (Win32BaseWindow *)getParent();
|
---|
3063 | hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
|
---|
3064 | window = GetWindowFromOS2FrameHandle(hwndRelated);
|
---|
3065 | if(window) {
|
---|
3066 | hwndRelated = window->getWindowHandle();
|
---|
3067 | RELEASE_WNDOBJ(window);
|
---|
3068 | }
|
---|
3069 | else hwndRelated = 0;
|
---|
3070 | }
|
---|
3071 | else {
|
---|
3072 | dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
|
---|
3073 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
|
---|
3074 | }
|
---|
3075 | break;
|
---|
3076 |
|
---|
3077 | case GW_HWNDLAST:
|
---|
3078 | if(getParent()) {
|
---|
3079 | window = (Win32BaseWindow *)getParent();
|
---|
3080 | hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
|
---|
3081 | dprintf(("os2 handle %x", hwndRelated));
|
---|
3082 | window = GetWindowFromOS2FrameHandle(hwndRelated);
|
---|
3083 | if(window) {
|
---|
3084 | hwndRelated = window->getWindowHandle();
|
---|
3085 | RELEASE_WNDOBJ(window);
|
---|
3086 | }
|
---|
3087 | else hwndRelated = 0;
|
---|
3088 | }
|
---|
3089 | else {
|
---|
3090 | dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
|
---|
3091 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
|
---|
3092 | }
|
---|
3093 | break;
|
---|
3094 |
|
---|
3095 | case GW_HWNDNEXT:
|
---|
3096 | if(getParent()) {
|
---|
3097 | hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
|
---|
3098 | window = GetWindowFromOS2FrameHandle(hwndRelated);
|
---|
3099 | if(window) {
|
---|
3100 | hwndRelated = window->getWindowHandle();
|
---|
3101 | RELEASE_WNDOBJ(window);
|
---|
3102 | }
|
---|
3103 | else hwndRelated = 0;
|
---|
3104 | }
|
---|
3105 | else {
|
---|
3106 | dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
|
---|
3107 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
|
---|
3108 | }
|
---|
3109 | break;
|
---|
3110 |
|
---|
3111 | case GW_HWNDPREV:
|
---|
3112 | if(getParent()) {
|
---|
3113 | hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
|
---|
3114 | window = GetWindowFromOS2FrameHandle(hwndRelated);
|
---|
3115 | if(window) {
|
---|
3116 | hwndRelated = window->getWindowHandle();
|
---|
3117 | RELEASE_WNDOBJ(window);
|
---|
3118 | }
|
---|
3119 | else hwndRelated = 0;
|
---|
3120 | }
|
---|
3121 | else {
|
---|
3122 | dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
|
---|
3123 | hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
|
---|
3124 | }
|
---|
3125 | break;
|
---|
3126 |
|
---|
3127 | case GW_OWNER:
|
---|
3128 | if(getOwner()) {
|
---|
3129 | hwndRelated = getOwner()->getWindowHandle();
|
---|
3130 | }
|
---|
3131 | break;
|
---|
3132 |
|
---|
3133 | case GW_CHILD:
|
---|
3134 | hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
|
---|
3135 | window = GetWindowFromOS2FrameHandle(hwndRelated);
|
---|
3136 | if(window) {
|
---|
3137 | hwndRelated = window->getWindowHandle();
|
---|
3138 | RELEASE_WNDOBJ(window);
|
---|
3139 | }
|
---|
3140 | else hwndRelated = 0;
|
---|
3141 | break;
|
---|
3142 | }
|
---|
3143 | end:
|
---|
3144 | dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
|
---|
3145 | return hwndRelated;
|
---|
3146 | }
|
---|
3147 | //******************************************************************************
|
---|
3148 | //******************************************************************************
|
---|
3149 | HWND Win32BaseWindow::SetActiveWindow()
|
---|
3150 | {
|
---|
3151 | HWND hwndActive;
|
---|
3152 |
|
---|
3153 | dprintf(("SetActiveWindow %x", getWindowHandle()));
|
---|
3154 | if(GetActiveWindow() == getWindowHandle()) {
|
---|
3155 | dprintf(("Window already active"));
|
---|
3156 | return getWindowHandle();
|
---|
3157 | }
|
---|
3158 | if (HOOK_IsHooked( WH_CBT ))
|
---|
3159 | {
|
---|
3160 | CBTACTIVATESTRUCT cbta;
|
---|
3161 | LRESULT ret;
|
---|
3162 |
|
---|
3163 | cbta.fMouse = FALSE;
|
---|
3164 | cbta.hWndActive = GetActiveWindow();
|
---|
3165 | ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
|
---|
3166 | if(ret)
|
---|
3167 | {
|
---|
3168 | dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
|
---|
3169 | return cbta.hWndActive;
|
---|
3170 | }
|
---|
3171 | }
|
---|
3172 | SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
|
---|
3173 |
|
---|
3174 | // if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
|
---|
3175 | // dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
|
---|
3176 | // }
|
---|
3177 | hwndActive = GetActiveWindow();
|
---|
3178 | return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
|
---|
3179 | }
|
---|
3180 | //******************************************************************************
|
---|
3181 | //Used to change active status of an mdi window
|
---|
3182 | //******************************************************************************
|
---|
3183 | BOOL Win32BaseWindow::DeactivateChildWindow()
|
---|
3184 | {
|
---|
3185 | /* child windows get a WM_CHILDACTIVATE message */
|
---|
3186 | if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
|
---|
3187 | {
|
---|
3188 | ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
|
---|
3189 | OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
|
---|
3190 | return TRUE;
|
---|
3191 | }
|
---|
3192 | DebugInt3(); //should not be called for non-child window
|
---|
3193 | return FALSE;
|
---|
3194 | }
|
---|
3195 | //******************************************************************************
|
---|
3196 | //WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
|
---|
3197 | //******************************************************************************
|
---|
3198 | BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
|
---|
3199 | {
|
---|
3200 | BOOL rc;
|
---|
3201 |
|
---|
3202 | dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
|
---|
3203 | //return true if previous state was disabled, else false (sdk docs)
|
---|
3204 | rc = (getStyle() & WS_DISABLED) != 0;
|
---|
3205 | if(rc && !fEnable) {
|
---|
3206 | SendMessageA(WM_CANCELMODE, 0, 0);
|
---|
3207 | }
|
---|
3208 | OSLibWinEnableWindow(OS2HwndFrame, fEnable);
|
---|
3209 | if(fEnable == FALSE) {
|
---|
3210 | //SvL: No need to clear focus as PM already does this
|
---|
3211 | if(getWindowHandle() == GetCapture()) {
|
---|
3212 | ReleaseCapture(); /* A disabled window can't capture the mouse */
|
---|
3213 | dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
|
---|
3214 | }
|
---|
3215 | }
|
---|
3216 | return rc;
|
---|
3217 | }
|
---|
3218 | //******************************************************************************
|
---|
3219 | //******************************************************************************
|
---|
3220 | BOOL Win32BaseWindow::CloseWindow()
|
---|
3221 | {
|
---|
3222 | return OSLibWinMinimizeWindow(OS2Hwnd);
|
---|
3223 | }
|
---|
3224 | //******************************************************************************
|
---|
3225 | //TODO: Not be 100% correct; should return active window of current thread
|
---|
3226 | // or NULL when there is none -> WinQueryActiveWindow just returns
|
---|
3227 | // the current active window
|
---|
3228 | //******************************************************************************
|
---|
3229 | HWND Win32BaseWindow::GetActiveWindow()
|
---|
3230 | {
|
---|
3231 | HWND hwndActive;
|
---|
3232 |
|
---|
3233 | hwndActive = OSLibWinQueryActiveWindow();
|
---|
3234 |
|
---|
3235 | return OS2ToWin32Handle(hwndActive);
|
---|
3236 | }
|
---|
3237 | //******************************************************************************
|
---|
3238 | //******************************************************************************
|
---|
3239 | BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
|
---|
3240 | {
|
---|
3241 | INT len = GetWindowTextLength(fUnicode);
|
---|
3242 | BOOL res;
|
---|
3243 |
|
---|
3244 | if (wndname == NULL)
|
---|
3245 | return (len == 0);
|
---|
3246 |
|
---|
3247 | len++;
|
---|
3248 | if (fUnicode)
|
---|
3249 | {
|
---|
3250 | WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
|
---|
3251 |
|
---|
3252 | GetWindowTextW(text,len);
|
---|
3253 | res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
|
---|
3254 | free(text);
|
---|
3255 | }
|
---|
3256 | else
|
---|
3257 | {
|
---|
3258 | CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
|
---|
3259 |
|
---|
3260 | GetWindowTextA(text,len);
|
---|
3261 | res = (strcmp(text,wndname) == 0);
|
---|
3262 | free(text);
|
---|
3263 | }
|
---|
3264 |
|
---|
3265 | return res;
|
---|
3266 | }
|
---|
3267 | //******************************************************************************
|
---|
3268 | //******************************************************************************
|
---|
3269 | CHAR *Win32BaseWindow::getWindowNamePtrA()
|
---|
3270 | {
|
---|
3271 | INT len = GetWindowTextLength(FALSE);
|
---|
3272 | CHAR *text;
|
---|
3273 |
|
---|
3274 | if (len == 0) return NULL;
|
---|
3275 | len++;
|
---|
3276 | text = (CHAR*)malloc(len*sizeof(CHAR));
|
---|
3277 | GetWindowTextA(text,len);
|
---|
3278 |
|
---|
3279 | return text;
|
---|
3280 | }
|
---|
3281 | //******************************************************************************
|
---|
3282 | //******************************************************************************
|
---|
3283 | WCHAR *Win32BaseWindow::getWindowNamePtrW()
|
---|
3284 | {
|
---|
3285 | INT len = GetWindowTextLength(TRUE);
|
---|
3286 | WCHAR *text;
|
---|
3287 |
|
---|
3288 | if (len == 0) return NULL;
|
---|
3289 | len++;
|
---|
3290 | text = (WCHAR*)malloc(len*sizeof(WCHAR));
|
---|
3291 | GetWindowTextW(text,len);
|
---|
3292 |
|
---|
3293 | return text;
|
---|
3294 | }
|
---|
3295 | //******************************************************************************
|
---|
3296 | //******************************************************************************
|
---|
3297 | VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
|
---|
3298 | {
|
---|
3299 | if (namePtr) free(namePtr);
|
---|
3300 | }
|
---|
3301 | //******************************************************************************
|
---|
3302 | //When using this API for a window that was created by a different process, NT
|
---|
3303 | //does NOT send WM_GETTEXTLENGTH.
|
---|
3304 | //******************************************************************************
|
---|
3305 | int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
|
---|
3306 | {
|
---|
3307 | //if the destination window is created by this process, send message
|
---|
3308 | if(dwProcessId == currentProcessId) {
|
---|
3309 | if(fUnicode) {
|
---|
3310 | return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
|
---|
3311 | }
|
---|
3312 | else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
|
---|
3313 | }
|
---|
3314 | //else get data directory from window structure
|
---|
3315 | //TODO: must lock window structure.... (TODO)
|
---|
3316 | if(fUnicode) {
|
---|
3317 | if(windowNameW) {
|
---|
3318 | return strlenW(windowNameW);
|
---|
3319 | }
|
---|
3320 | else return 0;
|
---|
3321 | }
|
---|
3322 | else {
|
---|
3323 | if(windowNameA) {
|
---|
3324 | return strlen(windowNameA);
|
---|
3325 | }
|
---|
3326 | else return 0;
|
---|
3327 | }
|
---|
3328 | }
|
---|
3329 | //******************************************************************************
|
---|
3330 | //When using this API for a window that was created by a different process, NT
|
---|
3331 | //does NOT send WM_GETTEXT.
|
---|
3332 | //******************************************************************************
|
---|
3333 | int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
|
---|
3334 | {
|
---|
3335 | //if the destination window is created by this process, send message
|
---|
3336 | if(dwProcessId == currentProcessId) {
|
---|
3337 | return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
|
---|
3338 | }
|
---|
3339 | //else get data directory from window structure
|
---|
3340 | if (!lpsz || !cch) return 0;
|
---|
3341 | if (!windowNameA) lpsz[0] = 0;
|
---|
3342 | else lstrcpynA(lpsz, windowNameA, cch);
|
---|
3343 | return min((windowNameA ? strlen(windowNameA) : 0), cch);
|
---|
3344 | }
|
---|
3345 | //******************************************************************************
|
---|
3346 | //When using this API for a window that was created by a different process, NT
|
---|
3347 | //does NOT send WM_GETTEXT.
|
---|
3348 | //******************************************************************************
|
---|
3349 | int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
|
---|
3350 | {
|
---|
3351 | //if the destination window is created by this process, send message
|
---|
3352 | if(dwProcessId == currentProcessId) {
|
---|
3353 | return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
|
---|
3354 | }
|
---|
3355 | //else get data directory from window structure
|
---|
3356 | if (!lpsz || !cch) return 0;
|
---|
3357 | if (!windowNameW) lpsz[0] = 0;
|
---|
3358 | else lstrcpynW(lpsz, windowNameW, cch);
|
---|
3359 | return min((windowNameW ? strlenW(windowNameW) : 0), cch);
|
---|
3360 | }
|
---|
3361 | //******************************************************************************
|
---|
3362 | //TODO: How does this work when the target window belongs to a different process???
|
---|
3363 | //******************************************************************************
|
---|
3364 | BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
|
---|
3365 | {
|
---|
3366 | return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
|
---|
3367 | }
|
---|
3368 | //******************************************************************************
|
---|
3369 | //******************************************************************************
|
---|
3370 | BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
|
---|
3371 | {
|
---|
3372 | return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
|
---|
3373 | }
|
---|
3374 | //******************************************************************************
|
---|
3375 | //******************************************************************************
|
---|
3376 | LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
|
---|
3377 | {
|
---|
3378 | LONG oldval;
|
---|
3379 |
|
---|
3380 | switch(index) {
|
---|
3381 | case GWL_EXSTYLE:
|
---|
3382 | {
|
---|
3383 | STYLESTRUCT ss;
|
---|
3384 |
|
---|
3385 | if(dwExStyle == value) {
|
---|
3386 | oldval = value;
|
---|
3387 | break;
|
---|
3388 | }
|
---|
3389 | ss.styleOld = dwExStyle;
|
---|
3390 | ss.styleNew = value;
|
---|
3391 | dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
|
---|
3392 | SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
|
---|
3393 | setExStyle(ss.styleNew);
|
---|
3394 | SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
|
---|
3395 | oldval = ss.styleOld;
|
---|
3396 | break;
|
---|
3397 | }
|
---|
3398 | case GWL_STYLE:
|
---|
3399 | {
|
---|
3400 | STYLESTRUCT ss;
|
---|
3401 |
|
---|
3402 | //SvL: TODO: Can you change minimize or maximize status here too?
|
---|
3403 |
|
---|
3404 | if(dwStyle == value) {
|
---|
3405 | oldval = value;
|
---|
3406 | break;
|
---|
3407 | }
|
---|
3408 | value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
|
---|
3409 | ss.styleOld = getStyle();
|
---|
3410 | ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
|
---|
3411 | dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
|
---|
3412 | SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
|
---|
3413 | setStyle(ss.styleNew);
|
---|
3414 | SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
|
---|
3415 | OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
|
---|
3416 | #ifdef DEBUG
|
---|
3417 | PrintWindowStyle(ss.styleNew, 0);
|
---|
3418 | #endif
|
---|
3419 | oldval = ss.styleOld;
|
---|
3420 | break;
|
---|
3421 | }
|
---|
3422 | case GWL_WNDPROC:
|
---|
3423 | {
|
---|
3424 | //Note: Type of SetWindowLong determines new window proc type
|
---|
3425 | // UNLESS the new window proc has already been registered
|
---|
3426 | // (use the old type in that case)
|
---|
3427 | // (VERIFIED in NT 4, SP6)
|
---|
3428 | WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
|
---|
3429 | if(type == WIN_PROC_INVALID) {
|
---|
3430 | type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
|
---|
3431 | }
|
---|
3432 | oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
|
---|
3433 | dprintf(("SetWindowLong GWL_WNDPROC %x old %x new style %x", getWindowHandle(), oldval, value));
|
---|
3434 | WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
|
---|
3435 | break;
|
---|
3436 | }
|
---|
3437 | case GWL_HINSTANCE:
|
---|
3438 | oldval = hInstance;
|
---|
3439 | hInstance = value;
|
---|
3440 | break;
|
---|
3441 |
|
---|
3442 | case GWL_HWNDPARENT:
|
---|
3443 | oldval = SetParent((HWND)value);
|
---|
3444 | break;
|
---|
3445 |
|
---|
3446 | case GWL_ID:
|
---|
3447 | oldval = getWindowId();
|
---|
3448 | setWindowId(value);
|
---|
3449 | break;
|
---|
3450 |
|
---|
3451 | case GWL_USERDATA:
|
---|
3452 | oldval = userData;
|
---|
3453 | userData = value;
|
---|
3454 | break;
|
---|
3455 |
|
---|
3456 | default:
|
---|
3457 | if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
|
---|
3458 | {
|
---|
3459 | oldval = *(ULONG *)(userWindowBytes + index);
|
---|
3460 | *(ULONG *)(userWindowBytes + index) = value;
|
---|
3461 | break;
|
---|
3462 | }
|
---|
3463 | dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
---|
3464 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
---|
3465 | return 0;
|
---|
3466 | }
|
---|
3467 | //Note: NT4, SP6 does not set the last error to 0
|
---|
3468 | SetLastError(ERROR_SUCCESS);
|
---|
3469 | dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
|
---|
3470 | return oldval;
|
---|
3471 | }
|
---|
3472 | //******************************************************************************
|
---|
3473 | //******************************************************************************
|
---|
3474 | ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
|
---|
3475 | {
|
---|
3476 | ULONG value;
|
---|
3477 |
|
---|
3478 | switch(index) {
|
---|
3479 | case GWL_EXSTYLE:
|
---|
3480 | value = dwExStyle;
|
---|
3481 | break;
|
---|
3482 | case GWL_STYLE:
|
---|
3483 | value = dwStyle;
|
---|
3484 | break;
|
---|
3485 | case GWL_WNDPROC:
|
---|
3486 | value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
|
---|
3487 | break;
|
---|
3488 | case GWL_HINSTANCE:
|
---|
3489 | value = hInstance;
|
---|
3490 | break;
|
---|
3491 | case GWL_HWNDPARENT:
|
---|
3492 | value = GetParent();
|
---|
3493 | break;
|
---|
3494 | case GWL_ID:
|
---|
3495 | value = getWindowId();
|
---|
3496 | break;
|
---|
3497 | case GWL_USERDATA:
|
---|
3498 | value = userData;
|
---|
3499 | break;
|
---|
3500 | default:
|
---|
3501 | if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
|
---|
3502 | {
|
---|
3503 | value = *(ULONG *)(userWindowBytes + index);
|
---|
3504 | break;
|
---|
3505 | }
|
---|
3506 | dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
---|
3507 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
---|
3508 | return 0;
|
---|
3509 | }
|
---|
3510 | dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
|
---|
3511 | //Note: NT4, SP6 does not set the last error to 0
|
---|
3512 | SetLastError(ERROR_SUCCESS);
|
---|
3513 | return value;
|
---|
3514 | }
|
---|
3515 | //******************************************************************************
|
---|
3516 | //******************************************************************************
|
---|
3517 | WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
|
---|
3518 | {
|
---|
3519 | WORD oldval;
|
---|
3520 |
|
---|
3521 | if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
|
---|
3522 | {
|
---|
3523 | oldval = *(WORD *)(userWindowBytes + index);
|
---|
3524 | *(WORD *)(userWindowBytes + index) = value;
|
---|
3525 | //Note: NT4, SP6 does not set the last error to 0
|
---|
3526 | dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
|
---|
3527 | SetLastError(ERROR_SUCCESS);
|
---|
3528 | return oldval;
|
---|
3529 | }
|
---|
3530 | dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
|
---|
3531 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
---|
3532 | return 0;
|
---|
3533 | }
|
---|
3534 | //******************************************************************************
|
---|
3535 | //******************************************************************************
|
---|
3536 | WORD Win32BaseWindow::GetWindowWord(int index)
|
---|
3537 | {
|
---|
3538 | if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
|
---|
3539 | {
|
---|
3540 | //Note: NT4, SP6 does not set the last error to 0
|
---|
3541 | SetLastError(ERROR_SUCCESS);
|
---|
3542 | dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
|
---|
3543 | return *(WORD *)(userWindowBytes + index);
|
---|
3544 | }
|
---|
3545 | dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
|
---|
3546 | SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
|
---|
3547 | return 0;
|
---|
3548 | }
|
---|
3549 | //******************************************************************************
|
---|
3550 | //******************************************************************************
|
---|
3551 | void Win32BaseWindow::setWindowId(DWORD id)
|
---|
3552 | {
|
---|
3553 | dwIDMenu = id;
|
---|
3554 | }
|
---|
3555 | //******************************************************************************
|
---|
3556 | //******************************************************************************
|
---|
3557 | HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
|
---|
3558 | {
|
---|
3559 | Win32BaseWindow *firstchild = NULL, *child, *nextchild, *lastchild;
|
---|
3560 | HWND retvalue;
|
---|
3561 |
|
---|
3562 | lock();
|
---|
3563 | if (hwndCtrl)
|
---|
3564 | {
|
---|
3565 | firstchild = child = GetWindowFromHandle(hwndCtrl);
|
---|
3566 | if (!child)
|
---|
3567 | {
|
---|
3568 | retvalue = 0;
|
---|
3569 | goto END;
|
---|
3570 | }
|
---|
3571 | /* Make sure hwndCtrl is a top-level child */
|
---|
3572 | while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
|
---|
3573 | {
|
---|
3574 | child = child->getParent();
|
---|
3575 | if(child == NULL) break;
|
---|
3576 | }
|
---|
3577 | if (!child || (child->getParent() != this))
|
---|
3578 | {
|
---|
3579 | retvalue = 0;
|
---|
3580 | goto END;
|
---|
3581 | }
|
---|
3582 | }
|
---|
3583 | else
|
---|
3584 | {
|
---|
3585 | /* No ctrl specified -> start from the beginning */
|
---|
3586 | child = (Win32BaseWindow *)getFirstChild();
|
---|
3587 | if (!child)
|
---|
3588 | {
|
---|
3589 | retvalue = 0;
|
---|
3590 | goto END;
|
---|
3591 | }
|
---|
3592 |
|
---|
3593 | if (fPrevious)
|
---|
3594 | {
|
---|
3595 | while (child->getNextChild())
|
---|
3596 | {
|
---|
3597 | child = (Win32BaseWindow *)child->getNextChild();
|
---|
3598 | }
|
---|
3599 | }
|
---|
3600 | }
|
---|
3601 |
|
---|
3602 | lastchild = child;
|
---|
3603 | nextchild = (Win32BaseWindow *)child->getNextChild();
|
---|
3604 | while (TRUE)
|
---|
3605 | {
|
---|
3606 | if (!nextchild || (nextchild->getStyle() & WS_GROUP))
|
---|
3607 | {
|
---|
3608 | /* Wrap-around to the beginning of the group */
|
---|
3609 | Win32BaseWindow *pWndTemp;
|
---|
3610 |
|
---|
3611 | nextchild = (Win32BaseWindow *)getFirstChild();
|
---|
3612 |
|
---|
3613 | for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
|
---|
3614 | {
|
---|
3615 | if (pWndTemp->getStyle() & WS_GROUP)
|
---|
3616 | nextchild = pWndTemp;
|
---|
3617 |
|
---|
3618 | if (pWndTemp == child)
|
---|
3619 | break;
|
---|
3620 | }
|
---|
3621 |
|
---|
3622 | }
|
---|
3623 | if (nextchild == child)
|
---|
3624 | break;
|
---|
3625 |
|
---|
3626 | if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
|
---|
3627 | {
|
---|
3628 | lastchild = nextchild;
|
---|
3629 |
|
---|
3630 | if (!fPrevious)
|
---|
3631 | break;
|
---|
3632 | }
|
---|
3633 |
|
---|
3634 | nextchild = (Win32BaseWindow *)nextchild->getNextChild();
|
---|
3635 | }
|
---|
3636 | retvalue = lastchild->getWindowHandle();
|
---|
3637 | END:
|
---|
3638 | unlock();
|
---|
3639 | if(firstchild) RELEASE_WNDOBJ(firstchild);
|
---|
3640 | return retvalue;
|
---|
3641 | }
|
---|
3642 | //******************************************************************************
|
---|
3643 | //Locates window in linked list and increases reference count (if found)
|
---|
3644 | //Window object must be unreferenced after usage
|
---|
3645 | //******************************************************************************
|
---|
3646 | Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
|
---|
3647 | {
|
---|
3648 | Win32BaseWindow *window;
|
---|
3649 |
|
---|
3650 | lock(&critsect);
|
---|
3651 | if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
|
---|
3652 | if(window) {
|
---|
3653 | dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
|
---|
3654 | window->addRef();
|
---|
3655 | }
|
---|
3656 | unlock(&critsect);
|
---|
3657 | return window;
|
---|
3658 | }
|
---|
3659 | unlock(&critsect);
|
---|
3660 | // dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
|
---|
3661 | return NULL;
|
---|
3662 | }
|
---|
3663 | //******************************************************************************
|
---|
3664 | //Locates window in linked list and increases reference count (if found)
|
---|
3665 | //Window object must be unreferenced after usage
|
---|
3666 | //******************************************************************************
|
---|
3667 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
|
---|
3668 | {
|
---|
3669 | DWORD magic;
|
---|
3670 | HWND hwnd;
|
---|
3671 |
|
---|
3672 | if(hwndOS2 == OSLIB_HWND_DESKTOP)
|
---|
3673 | {
|
---|
3674 | windowDesktop->addRef();
|
---|
3675 | return windowDesktop;
|
---|
3676 | }
|
---|
3677 |
|
---|
3678 | hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
|
---|
3679 | magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
|
---|
3680 |
|
---|
3681 | if(hwnd && CheckMagicDword(magic)) {
|
---|
3682 | return GetWindowFromHandle(hwnd);
|
---|
3683 | }
|
---|
3684 | // dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
|
---|
3685 | return 0;
|
---|
3686 | }
|
---|
3687 | //******************************************************************************
|
---|
3688 | //Locates window in linked list and increases reference count (if found)
|
---|
3689 | //Window object must be unreferenced after usage
|
---|
3690 | //******************************************************************************
|
---|
3691 | Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
|
---|
3692 | {
|
---|
3693 | return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
|
---|
3694 | }
|
---|
3695 | //******************************************************************************
|
---|
3696 | //******************************************************************************
|
---|
3697 | HWND WIN32API Win32ToOS2Handle(HWND hwnd)
|
---|
3698 | {
|
---|
3699 | HWND hwndOS2;
|
---|
3700 |
|
---|
3701 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
3702 |
|
---|
3703 | if(window) {
|
---|
3704 | hwndOS2 = window->getOS2WindowHandle();
|
---|
3705 | RELEASE_WNDOBJ(window);
|
---|
3706 | return hwndOS2;
|
---|
3707 | }
|
---|
3708 | // dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
|
---|
3709 | return hwnd;
|
---|
3710 | }
|
---|
3711 | //******************************************************************************
|
---|
3712 | //******************************************************************************
|
---|
3713 | HWND WIN32API OS2ToWin32Handle(HWND hwnd)
|
---|
3714 | {
|
---|
3715 | Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
|
---|
3716 | HWND hwndWin32;
|
---|
3717 |
|
---|
3718 | if(window) {
|
---|
3719 | hwndWin32 = window->getWindowHandle();
|
---|
3720 | RELEASE_WNDOBJ(window);
|
---|
3721 | return hwndWin32;
|
---|
3722 | }
|
---|
3723 | window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
|
---|
3724 | if(window) {
|
---|
3725 | hwndWin32 = window->getWindowHandle();
|
---|
3726 | RELEASE_WNDOBJ(window);
|
---|
3727 | return hwndWin32;
|
---|
3728 | }
|
---|
3729 |
|
---|
3730 | // dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
|
---|
3731 | return 0;
|
---|
3732 | // else return hwnd; //OS/2 window handle
|
---|
3733 | }
|
---|
3734 | //******************************************************************************
|
---|
3735 | //******************************************************************************
|
---|
3736 | GenericObject *Win32BaseWindow::windows = NULL;
|
---|
3737 | CRITICAL_SECTION Win32BaseWindow::critsect = {0};
|
---|
3738 |
|
---|
3739 | //******************************************************************************
|
---|
3740 | //******************************************************************************
|
---|
3741 | #ifdef DEBUG
|
---|
3742 | void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
|
---|
3743 | {
|
---|
3744 | char style[256] = "";
|
---|
3745 | char exstyle[256] = "";
|
---|
3746 |
|
---|
3747 | /* Window styles */
|
---|
3748 | if(dwStyle & WS_CHILD)
|
---|
3749 | strcat(style, "WS_CHILD ");
|
---|
3750 | if(dwStyle & WS_POPUP)
|
---|
3751 | strcat(style, "WS_POPUP ");
|
---|
3752 | if(dwStyle & WS_VISIBLE)
|
---|
3753 | strcat(style, "WS_VISIBLE ");
|
---|
3754 | if(dwStyle & WS_DISABLED)
|
---|
3755 | strcat(style, "WS_DISABLED ");
|
---|
3756 | if(dwStyle & WS_CLIPSIBLINGS)
|
---|
3757 | strcat(style, "WS_CLIPSIBLINGS ");
|
---|
3758 | if(dwStyle & WS_CLIPCHILDREN)
|
---|
3759 | strcat(style, "WS_CLIPCHILDREN ");
|
---|
3760 | if(dwStyle & WS_MAXIMIZE)
|
---|
3761 | strcat(style, "WS_MAXIMIZE ");
|
---|
3762 | if(dwStyle & WS_MINIMIZE)
|
---|
3763 | strcat(style, "WS_MINIMIZE ");
|
---|
3764 | if(dwStyle & WS_GROUP)
|
---|
3765 | strcat(style, "WS_GROUP ");
|
---|
3766 | if(dwStyle & WS_TABSTOP)
|
---|
3767 | strcat(style, "WS_TABSTOP ");
|
---|
3768 |
|
---|
3769 | if((dwStyle & WS_CAPTION) == WS_CAPTION)
|
---|
3770 | strcat(style, "WS_CAPTION ");
|
---|
3771 | if(dwStyle & WS_DLGFRAME)
|
---|
3772 | strcat(style, "WS_DLGFRAME ");
|
---|
3773 | if(dwStyle & WS_BORDER)
|
---|
3774 | strcat(style, "WS_BORDER ");
|
---|
3775 |
|
---|
3776 | if(dwStyle & WS_VSCROLL)
|
---|
3777 | strcat(style, "WS_VSCROLL ");
|
---|
3778 | if(dwStyle & WS_HSCROLL)
|
---|
3779 | strcat(style, "WS_HSCROLL ");
|
---|
3780 | if(dwStyle & WS_SYSMENU)
|
---|
3781 | strcat(style, "WS_SYSMENU ");
|
---|
3782 | if(dwStyle & WS_THICKFRAME)
|
---|
3783 | strcat(style, "WS_THICKFRAME ");
|
---|
3784 | if(dwStyle & WS_MINIMIZEBOX)
|
---|
3785 | strcat(style, "WS_MINIMIZEBOX ");
|
---|
3786 | if(dwStyle & WS_MAXIMIZEBOX)
|
---|
3787 | strcat(style, "WS_MAXIMIZEBOX ");
|
---|
3788 |
|
---|
3789 | if(dwExStyle & WS_EX_DLGMODALFRAME)
|
---|
3790 | strcat(exstyle, "WS_EX_DLGMODALFRAME ");
|
---|
3791 | if(dwExStyle & WS_EX_ACCEPTFILES)
|
---|
3792 | strcat(exstyle, "WS_EX_ACCEPTFILES ");
|
---|
3793 | if(dwExStyle & WS_EX_NOPARENTNOTIFY)
|
---|
3794 | strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
|
---|
3795 | if(dwExStyle & WS_EX_TOPMOST)
|
---|
3796 | strcat(exstyle, "WS_EX_TOPMOST ");
|
---|
3797 | if(dwExStyle & WS_EX_TRANSPARENT)
|
---|
3798 | strcat(exstyle, "WS_EX_TRANSPARENT ");
|
---|
3799 |
|
---|
3800 | if(dwExStyle & WS_EX_MDICHILD)
|
---|
3801 | strcat(exstyle, "WS_EX_MDICHILD ");
|
---|
3802 | if(dwExStyle & WS_EX_TOOLWINDOW)
|
---|
3803 | strcat(exstyle, "WS_EX_TOOLWINDOW ");
|
---|
3804 | if(dwExStyle & WS_EX_WINDOWEDGE)
|
---|
3805 | strcat(exstyle, "WS_EX_WINDOWEDGE ");
|
---|
3806 | if(dwExStyle & WS_EX_CLIENTEDGE)
|
---|
3807 | strcat(exstyle, "WS_EX_CLIENTEDGE ");
|
---|
3808 | if(dwExStyle & WS_EX_CONTEXTHELP)
|
---|
3809 | strcat(exstyle, "WS_EX_CONTEXTHELP ");
|
---|
3810 | if(dwExStyle & WS_EX_RIGHT)
|
---|
3811 | strcat(exstyle, "WS_EX_RIGHT ");
|
---|
3812 | if(dwExStyle & WS_EX_LEFT)
|
---|
3813 | strcat(exstyle, "WS_EX_LEFT ");
|
---|
3814 | if(dwExStyle & WS_EX_RTLREADING)
|
---|
3815 | strcat(exstyle, "WS_EX_RTLREADING ");
|
---|
3816 | if(dwExStyle & WS_EX_LTRREADING)
|
---|
3817 | strcat(exstyle, "WS_EX_LTRREADING ");
|
---|
3818 | if(dwExStyle & WS_EX_LEFTSCROLLBAR)
|
---|
3819 | strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
|
---|
3820 | if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
|
---|
3821 | strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
|
---|
3822 | if(dwExStyle & WS_EX_CONTROLPARENT)
|
---|
3823 | strcat(exstyle, "WS_EX_CONTROLPARENT ");
|
---|
3824 | if(dwExStyle & WS_EX_STATICEDGE)
|
---|
3825 | strcat(exstyle, "WS_EX_STATICEDGE ");
|
---|
3826 | if(dwExStyle & WS_EX_APPWINDOW)
|
---|
3827 | strcat(exstyle, "WS_EX_APPWINDOW ");
|
---|
3828 |
|
---|
3829 | dprintf(("Window style: %x %s", dwStyle, style));
|
---|
3830 | dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
|
---|
3831 | }
|
---|
3832 | #endif
|
---|
3833 | //******************************************************************************
|
---|
3834 | //******************************************************************************
|
---|