source: trunk/src/user32/win32wbase.cpp@ 9871

Last change on this file since 9871 was 9871, checked in by sandervl, 22 years ago

PF: Wrong checks on restoration point remembering. Maximizing window from PM icon using keyboard or menu produced wrong controls

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