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

Last change on this file since 9791 was 9791, checked in by sandervl, 23 years ago

Handle SetFocus(0) correctly: keystrokes are converted into WM_SYSKEYDOWN/(WM_SYSCHAR)/WM_SYSKEYUP messages

File size: 145.4 KB
Line 
1/* $Id: win32wbase.cpp,v 1.358 2003-02-13 10:12:25 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 case WM_SYSKEYUP:
2014 /* Press and release F10 or ALT */
2015 if (((wParam == VK_MENU) && iMenuSysKey) ||
2016 ((wParam == VK_F10) && iF10Key))
2017 ::SendMessageW( GetTopParent(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
2018 iMenuSysKey = iF10Key = 0;
2019 break;
2020
2021 case WM_SYSCHAR:
2022 {
2023 iMenuSysKey = 0;
2024 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
2025 {
2026 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
2027 (WPARAM)SC_RESTORE, 0L );
2028 break;
2029 }
2030 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
2031 {
2032 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
2033 break;
2034 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
2035 ::SendMessageW(GetParent(), Msg, wParam, lParam );
2036 }
2037 else ::SendMessageA(getWindowHandle(), WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
2038 }
2039#if 0
2040 else /* check for Ctrl-Esc */
2041 if (wParam != VK_ESCAPE) MessageBeep(0);
2042 break;
2043#endif
2044 }
2045
2046 case WM_SETHOTKEY:
2047 hotkey = wParam;
2048 return 1; //CB: always successful
2049
2050 case WM_GETHOTKEY:
2051 return hotkey;
2052
2053 case WM_RBUTTONUP:
2054 {
2055 POINT pt;
2056 pt.x = SLOWORD(lParam);
2057 pt.y = SHIWORD(lParam);
2058 ClientToScreen(getWindowHandle(), &pt);
2059 SendMessageA( getWindowHandle(), WM_CONTEXTMENU, getWindowHandle(),MAKELPARAM(pt.x, pt.y) );
2060 }
2061 break;
2062
2063 case WM_CONTEXTMENU:
2064 if ((dwStyle & WS_CHILD) && getParent())
2065 SendMessageA(getParent()->getWindowHandle(), WM_CONTEXTMENU,wParam,lParam);
2066 else
2067 {
2068 LONG hitcode;
2069 POINT pt;
2070 if (!GetSysMenu()) return 0;
2071 pt.x = SLOWORD(lParam);
2072 pt.y = SHIWORD(lParam);
2073 hitcode = HandleNCHitTest(pt);
2074
2075 /* Track system popup if click was in the caption area. */
2076 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
2077 TrackPopupMenu(GetSysMenu(),
2078 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
2079 pt.x, pt.y, 0, getWindowHandle(), NULL);
2080 }
2081 return 0;
2082
2083 case WM_SHOWWINDOW:
2084 if (!lParam) return 0; /* sent from ShowWindow */
2085 if (!(dwStyle & WS_POPUP) || !owner) return 0;
2086 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
2087 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
2088 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
2089 return 0;
2090
2091 case WM_CANCELMODE:
2092 if (getParent() == windowDesktop) EndMenu();
2093 if (GetCapture() == Win32Hwnd) ReleaseCapture();
2094 return 0;
2095
2096 case WM_DROPOBJECT:
2097 return DRAG_FILE;
2098
2099 case WM_QUERYDROPOBJECT:
2100 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
2101
2102 case WM_QUERYDRAGICON:
2103 {
2104 HICON hDragIcon = windowClass->getCursor();
2105 UINT len;
2106
2107 if(hDragIcon) return (LRESULT)hDragIcon;
2108 for(len = 1; len < 64; len++)
2109 {
2110 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
2111 if(hDragIcon)
2112 return (LRESULT)hDragIcon;
2113 }
2114 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
2115 }
2116
2117 case WM_QUERYOPEN:
2118 case WM_QUERYENDSESSION:
2119 return 1;
2120
2121 case WM_NOTIFYFORMAT:
2122 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
2123
2124 case WM_SETICON:
2125 case WM_GETICON:
2126 {
2127 LRESULT result = 0;
2128
2129 /* Set the appropriate icon members in the window structure. */
2130 if (wParam == ICON_SMALL)
2131 {
2132 result = hIconSm;
2133 if (Msg == WM_SETICON)
2134 hIconSm = (HICON)lParam;
2135 }
2136 else
2137 {
2138 result = hIcon;
2139 if (Msg == WM_SETICON)
2140 {
2141 hIcon = (HICON)lParam;
2142 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2143 OSLibWinSetIcon(OS2HwndFrame,hIcon);
2144 }
2145 }
2146 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
2147 HandleNCPaint((HRGN)1);
2148
2149 return result;
2150 }
2151
2152 case WM_HELP:
2153 if (getParent()) SendMessageA(getParent()->getWindowHandle(), Msg,wParam,lParam);
2154 break;
2155
2156 case WM_NOTIFY:
2157 return 0; //comctl32 controls expect this
2158
2159 default:
2160 return 0;
2161 }
2162 return 0;
2163}
2164//******************************************************************************
2165//******************************************************************************
2166LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
2167{
2168 switch(Msg)
2169 {
2170 case WM_GETTEXTLENGTH:
2171 return windowNameLength;
2172
2173 case WM_GETTEXT:
2174 if (!lParam || !wParam)
2175 return 0;
2176 if (!windowNameW)
2177 ((LPWSTR)lParam)[0] = 0;
2178 else
2179 memcpy((LPSTR)lParam, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), wParam) );
2180 return min(windowNameLength, wParam);
2181
2182 case WM_SETTEXT:
2183 {
2184 LPWSTR lpsz = (LPWSTR)lParam;
2185
2186 // reallocate if new buffer is larger
2187 if (!lParam)
2188 {
2189 free(windowNameA);
2190 free(windowNameW);
2191 windowNameLength = 0;
2192 windowNameA = NULL;
2193 windowNameW = NULL;
2194 }
2195 else
2196 {
2197 // determine length of new text
2198 int iTextLength = lstrlenW(lpsz);
2199
2200 if (windowNameLength < iTextLength)
2201 {
2202 if (windowNameA)
2203 {
2204 free(windowNameA);
2205 windowNameA = NULL;
2206 }
2207
2208 if (windowNameW)
2209 {
2210 free(windowNameW);
2211 windowNameW = NULL;
2212 }
2213 }
2214
2215 windowNameLength = iTextLength;
2216 if(!windowNameW)
2217 windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
2218 memcpy(windowNameW, lpsz, (windowNameLength+1) * sizeof(WCHAR));
2219 if(!windowNameA)
2220 windowNameA = (LPSTR)_smalloc(windowNameLength+1);
2221 lstrcpynWtoA(windowNameA, windowNameW, windowNameLength+1);
2222 }
2223
2224 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
2225 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2226 {
2227 HandleNCPaint((HRGN)1);
2228 if(hTaskList) {
2229 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2230 }
2231 if(fOS2Look) {
2232 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
2233 }
2234 }
2235
2236 return TRUE;
2237 }
2238
2239 default:
2240 return DefWindowProcA(Msg, wParam, lParam);
2241 }
2242}
2243//******************************************************************************
2244//******************************************************************************
2245void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2246{
2247 Win32BaseWindow *window = this;
2248 Win32BaseWindow *parentwindow;
2249
2250 while(window)
2251 {
2252 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2253 {
2254 /* Notify the parent window only */
2255 parentwindow = window->getParent();
2256 if(parentwindow) {
2257 SendMessageA(parentwindow->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2258 }
2259 }
2260 else break;
2261
2262 window = parentwindow;
2263 }
2264}
2265//******************************************************************************
2266// Returns the big or small icon for the window, falling back to the
2267// class as windows does.
2268//******************************************************************************
2269HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2270{
2271 HICON hWndIcon;
2272
2273 if (fType == ICON_BIG)
2274 {
2275 if (hIcon)
2276 hWndIcon = hIcon;
2277 else
2278 if (windowClass && windowClass->getIcon())
2279 hWndIcon = windowClass->getIcon();
2280 else
2281 if (!(dwStyle & DS_MODALFRAME))
2282 {//SvL: load it as shared or else we'll leak icons
2283 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
2284 }
2285 else hWndIcon = 0;
2286 }
2287 else
2288 {
2289 if (hIconSm)
2290 hWndIcon = hIconSm;
2291 else
2292 if (hIcon)
2293 hWndIcon = hIcon;
2294 else
2295 if (windowClass && windowClass->getIconSm())
2296 hWndIcon = windowClass->getIconSm();
2297 else
2298 if (windowClass && windowClass->getIcon())
2299 hWndIcon = windowClass->getIcon();
2300 else
2301 if (!(dwStyle & DS_MODALFRAME))
2302 {//SvL: load it as shared or else we'll leak icons
2303 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
2304 }
2305 else hWndIcon = 0;
2306 }
2307
2308 return hWndIcon;
2309}
2310//******************************************************************************
2311//******************************************************************************
2312BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2313{
2314 ULONG swp = 0;
2315 HWND hWinAfter;
2316 BOOL rc,wasVisible,showFlag;
2317 RECT newPos = {0, 0, 0, 0};
2318
2319 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2320 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2321
2322 dwOldStyle = getStyle();
2323
2324 switch(nCmdShow)
2325 {
2326 case SW_HIDE:
2327 if (!wasVisible) goto END;
2328
2329 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2330 break;
2331
2332 case SW_SHOWMINNOACTIVE:
2333 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2334 /* fall through */
2335 case SW_SHOWMINIMIZED:
2336 swp |= SWP_SHOWWINDOW;
2337 /* fall through */
2338 case SW_MINIMIZE:
2339 swp |= SWP_FRAMECHANGED;
2340 if( !(getStyle() & WS_MINIMIZE) ) {
2341 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2342 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2343 }
2344 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2345 break;
2346
2347 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2348 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2349 if( !(getStyle() & WS_MAXIMIZE) ) {
2350 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2351 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2352 }
2353 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2354 break;
2355
2356 case SW_SHOWNA:
2357 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2358 /* fall through */
2359 case SW_SHOW:
2360 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2361
2362 /*
2363 * ShowWindow has a little peculiar behavior that if the
2364 * window is already the topmost window, it will not
2365 * activate it.
2366 */
2367 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2368 swp |= SWP_NOACTIVATE;
2369
2370 break;
2371
2372 case SW_SHOWNOACTIVATE:
2373 swp |= SWP_NOZORDER;
2374 if (GetActiveWindow())
2375 swp |= SWP_NOACTIVATE;
2376 /* fall through */
2377 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2378 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2379 case SW_RESTORE:
2380 dprintf(("ShowWindow:restoring window"));
2381
2382 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2383 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2384 swp |= MinMaximize(SW_RESTORE, &newPos );
2385 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2386 }
2387 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2388 break;
2389 }
2390
2391 showFlag = (nCmdShow != SW_HIDE);
2392 if (showFlag != wasVisible)
2393 {
2394 SendMessageA(getWindowHandle(),WM_SHOWWINDOW, showFlag, 0 );
2395 if (!::IsWindow( getWindowHandle() )) goto END;
2396 }
2397
2398 /* We can't activate a child window */
2399 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2400 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2401
2402 if (!(getStyle() & WS_MINIMIZE)) {
2403 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp), TRUE);
2404 }
2405 else OSLibWinMinimizeWindow(getOS2FrameWindowHandle());
2406
2407 if(!(swp & SWP_NOACTIVATE) && (!(getStyle() & WS_MINIMIZE))) {
2408 OSLibWinSetActiveWindow(OS2HwndFrame);
2409 }
2410
2411 if (flags & WIN_NEED_SIZE)
2412 {
2413 /* should happen only in CreateWindowEx() */
2414 int wParam = SIZE_RESTORED;
2415
2416 flags &= ~WIN_NEED_SIZE;
2417 if (dwStyle & WS_MAXIMIZE)
2418 wParam = SIZE_MAXIMIZED;
2419 else
2420 if (dwStyle & WS_MINIMIZE)
2421 wParam = SIZE_MINIMIZED;
2422
2423 SendMessageA(getWindowHandle(),WM_SIZE, wParam,
2424 MAKELONG(rectClient.right-rectClient.left,
2425 rectClient.bottom-rectClient.top));
2426 SendMessageA(getWindowHandle(),WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2427 }
2428//testestest
2429 //temporary workaround for file dialogs with template dialog child
2430 //they don't redraw when switching directories
2431 //For some reason the new child's (syslistview32) update rectangle stays
2432 //empty after its parent is made visible with ShowWindow
2433 //TODO: find real cause
2434 if(!wasVisible) {
2435 InvalidateRect(getWindowHandle(), NULL, TRUE);
2436 }
2437//testestest
2438
2439END:
2440 fMinMaxChange = FALSE;
2441 return wasVisible;
2442}
2443//******************************************************************************
2444//******************************************************************************
2445BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
2446 int cy, UINT fuFlags, BOOL fShowWindow)
2447{
2448 BOOL rc = FALSE;
2449 Win32BaseWindow *window;
2450 HWND hParent = 0;
2451 RECT oldClientRect = rectClient;
2452
2453 if (fuFlags &
2454 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2455 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2456 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2457 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2458 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS))
2459 {
2460 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2461 return FALSE;
2462 }
2463
2464 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS)) {
2465 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2466 }
2467
2468 if(IsWindowDestroyed()) {
2469 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2470 dprintf(("SetWindowPos; window already destroyed"));
2471 return TRUE;
2472 }
2473
2474#if 0
2475 /* Fix redundant flags */
2476 if(getStyle() & WS_VISIBLE) {
2477 fuFlags &= ~SWP_SHOWWINDOW;
2478 }
2479 else
2480 {
2481 if (!(fuFlags & SWP_SHOWWINDOW))
2482 fuFlags |= SWP_NOREDRAW;
2483 fuFlags &= ~SWP_HIDEWINDOW;
2484 }
2485
2486//// if(cx < 0) cx = 0;
2487//// if(cy < 0) cy = 0;
2488
2489 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2490 fuFlags |= SWP_NOSIZE; /* Already the right size */
2491 }
2492
2493 if((rectWindow.left == x) && (rectWindow.top == y)) {
2494 fuFlags |= SWP_NOMOVE; /* Already the right position */
2495 }
2496
2497 if(getWindowHandle() == GetActiveWindow()) {
2498 fuFlags |= SWP_NOACTIVATE; /* Already active */
2499 }
2500 else
2501 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2502 {
2503 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2504 {
2505 fuFlags &= ~SWP_NOZORDER;
2506 hwndInsertAfter = HWND_TOP;
2507 }
2508 }
2509 /* TODO: Check hwndInsertAfter */
2510#endif
2511
2512 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2513 if(state < STATE_POST_WMNCCREATE)
2514 {//don't change size; modify internal structures only
2515 //TODO: not 100% correct yet (activate)
2516 dprintf2(("state < STATE_POST_WMNCCREATE"));
2517 if(!(fuFlags & SWP_NOZORDER)) {
2518 hwndLinkAfter = hwndInsertAfter;
2519 }
2520 if(!(fuFlags & SWP_NOMOVE)) {
2521 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2522 rectWindow.top = y;
2523 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2524 rectWindow.left = x;
2525 }
2526 if(!(fuFlags & SWP_NOSIZE)) {
2527 rectWindow.bottom = rectWindow.top + cy;
2528 rectWindow.right = rectWindow.left + cx;
2529 }
2530 return TRUE;
2531 }
2532
2533 WINDOWPOS wpos;
2534 SWP swp, swpOld;
2535 wpos.flags = fuFlags;
2536 wpos.cy = cy;
2537 wpos.cx = cx;
2538 wpos.x = x;
2539 wpos.y = y;
2540 wpos.hwndInsertAfter = hwndInsertAfter;
2541 wpos.hwnd = getWindowHandle();
2542
2543 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2544 {
2545 if (isChild())
2546 {
2547 if(!getParent()) {
2548 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2549 }
2550 }
2551 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2552 }
2553 if((dwOldStyle & WS_MINIMIZE) && (getStyle() & WS_MINIMIZE))
2554 {//don't allow size changes if the window is minimized
2555 //we will update the restore position at the end of this method
2556 if(!(wpos.flags & SWP_NOSIZE)) {
2557 //TODO: updating the window rectangle doesn't look right
2558 wpos.flags |= SWP_NOSIZE;
2559 rectWindow.right = rectWindow.left + wpos.cx;
2560 rectWindow.bottom = rectWindow.top + wpos.cy;
2561 dprintf(("WARNING: Don't allow size change for minimized window; only save new restore position"));
2562 dprintf(("new window rectangle (%d,%d)(%d,%d)", rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2563 }
2564 }
2565
2566 if(getParent()) {
2567 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2568 OS2HwndFrame);
2569 }
2570 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2571
2572 if (swp.fl == 0) {
2573 dprintf2(("swp.fl == 0"));
2574 if(fuFlags & SWP_FRAMECHANGED)
2575 {
2576 NotifyFrameChanged(&wpos, &oldClientRect);
2577 }
2578 if(!fShowWindow && !(getStyle() & WS_MINIMIZE))
2579 {
2580 //Restore position always changes when the window position is changed
2581 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2582 windowpos.rcNormalPosition = rectWindow;
2583 }
2584 return TRUE;
2585 }
2586
2587// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2588 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2589 {
2590 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2591 if(wndBehind) {
2592 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2593 RELEASE_WNDOBJ(wndBehind);
2594 }
2595 else {
2596 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2597 swp.hwndInsertBehind = 0;
2598 }
2599 }
2600 swp.hwnd = OS2HwndFrame;
2601
2602 //SvL: Must also deactivate the window when hiding it or else focus won't
2603 // change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
2604 if((swp.fl & (SWPOS_HIDE|SWPOS_DEACTIVATE)) == (SWPOS_HIDE|SWPOS_DEACTIVATE))
2605 {
2606 //we must make sure the owner is not disabled or else the focus will
2607 //be switched to the wrong window
2608 Win32BaseWindow *topOwner;
2609
2610 if(getOwner() == NULL) {
2611 windowDesktop->addRef();
2612 topOwner = windowDesktop;
2613 }
2614 else topOwner = GetWindowFromHandle(getOwner()->GetTopParent());
2615
2616 if(topOwner != NULL) {
2617 DWORD dwStyle = topOwner->GetWindowLong(GWL_STYLE, FALSE);
2618 if(dwStyle & WS_DISABLED) {
2619 swp.fl &= ~SWPOS_DEACTIVATE;
2620 }
2621 }
2622 else DebugInt3();
2623 }
2624
2625 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2626 setStyle(getStyle() | WS_VISIBLE);
2627 if(hTaskList) {
2628 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2629 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2630 }
2631 }
2632 else
2633 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2634 setStyle(getStyle() & ~WS_VISIBLE);
2635 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2636 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2637 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2638 }
2639 }
2640 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2641
2642 rc = OSLibWinSetMultWindowPos(&swp, 1);
2643 if(rc == FALSE)
2644 {
2645 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2646 return 0;
2647 }
2648
2649 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2650 {
2651 NotifyFrameChanged(&wpos, &oldClientRect);
2652 }
2653 if(!fShowWindow && !(getStyle() & WS_MINIMIZE))
2654 {
2655 //Restore position always changes when the window position is changed
2656 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2657 windowpos.rcNormalPosition = rectWindow;
2658 }
2659 //MSDN says the entire client area will be invalidated when SWP_NOCOPYBITS
2660 //is specified (fixes repaint issues when window is made smaller)
2661 if((fuFlags & (SWP_NOCOPYBITS|SWP_NOREDRAW)) == SWP_NOCOPYBITS) {
2662 InvalidateRect(getWindowHandle(), NULL, TRUE);
2663 }
2664 return (rc);
2665}
2666//******************************************************************************
2667//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2668//******************************************************************************
2669BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2670{
2671 rectWindow.left += dx;
2672 rectWindow.right += dx;
2673 rectWindow.top += dy;
2674 rectWindow.bottom += dy;
2675 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2676 return TRUE;
2677}
2678//******************************************************************************
2679//******************************************************************************
2680void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2681{
2682 HRGN hrgn, hrgnClient;
2683 RECT rect;
2684
2685 MsgFormatFrame(NULL);
2686
2687 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2688 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2689 {
2690 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2691 wpos->cx = RECT_WIDTH(rectWindow);
2692 wpos->cy = RECT_HEIGHT(rectWindow);
2693 }
2694
2695 if(rectClient.left != oldClientRect->left ||
2696 rectClient.top != oldClientRect->top)
2697 {
2698 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2699 wpos->x = rectWindow.left;
2700 wpos->y = rectWindow.top;
2701 }
2702
2703 WINDOWPOS wpOld = *wpos;
2704 if(!(wpos->flags & SWP_NOSENDCHANGING))
2705 SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2706
2707 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2708 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2709 {
2710 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2711 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2712 }
2713 else SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2714
2715 //Calculate invalid areas
2716 rect = rectWindow;
2717 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2718 hrgn = CreateRectRgnIndirect(&rect);
2719 if (!hrgn) {
2720 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2721 return;
2722 }
2723 rect = rectClient;
2724 hrgnClient = CreateRectRgnIndirect(&rect);
2725 if (!hrgn) {
2726 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2727 return;
2728 }
2729 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2730 DeleteObject(hrgnClient);
2731
2732 if(!EqualRect(oldClientRect, &rectClient)) {
2733 UnionRect(oldClientRect, oldClientRect, &rectClient);
2734 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2735 if (!hrgn) {
2736 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2737 return;
2738 }
2739 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2740 DeleteObject(hrgnClient);
2741 }
2742 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2743 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2744 DeleteObject(hrgn);
2745}
2746//******************************************************************************
2747//TODO: Check how this api really works in NT
2748//******************************************************************************
2749BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2750{
2751 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2752 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2753 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2754 windowpos.ptMinPosition = wndpl->ptMinPosition;
2755 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2756 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2757
2758 if(getStyle() & WS_MINIMIZE )
2759 {
2760 //TODO: Why can't this be (0,0)?
2761 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2762 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2763 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2764 }
2765 }
2766 else
2767 if(getStyle() & WS_MAXIMIZE )
2768 {
2769 //TODO: Why can't this be (0,0)?
2770 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2771 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2772 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2773 }
2774 else {
2775 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2776 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2777 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2778 SWP_NOZORDER | SWP_NOACTIVATE );
2779 }
2780 ShowWindow(wndpl->showCmd);
2781 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2782 {
2783 /* SDK: ...valid only the next time... */
2784 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2785 setFlags(getFlags() | WIN_RESTORE_MAX);
2786 }
2787 return TRUE;
2788}
2789//******************************************************************************
2790//******************************************************************************
2791BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2792{
2793 wndpl->length = sizeof(*wndpl);
2794 if(getStyle() & WS_MINIMIZE )
2795 wndpl->showCmd = SW_SHOWMINIMIZED;
2796 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2797
2798 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2799 if(getFlags() & WIN_RESTORE_MAX )
2800 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2801 else wndpl->flags = 0;
2802
2803 wndpl->ptMinPosition = windowpos.ptMinPosition;
2804 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2805 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2806 wndpl->rcNormalPosition = windowpos.rcNormalPosition;
2807
2808 return TRUE;
2809}
2810//******************************************************************************
2811//Also destroys all the child windows (destroy children first, parent last)
2812//TODO: Don't rely on PM to do the right thing. Send WM_(NC)DESTROY &
2813// destroy children ourselves (see Wine)
2814//******************************************************************************
2815BOOL Win32BaseWindow::DestroyWindow()
2816{
2817 HWND hwnd = getWindowHandle();
2818
2819 dprintf(("DestroyWindow %x", hwnd));
2820
2821#if 0
2822 /* Look whether the focus is within the tree of windows we will
2823 * be destroying.
2824 */
2825 HWND hwndFocus = GetFocus();
2826 if (hwndFocus == hwnd || ::IsChild( hwnd, hwndFocus ))
2827 {
2828 HWND parent = GetAncestor( hwnd, GA_PARENT );
2829 if (parent == GetDesktopWindow()) parent = 0;
2830 SetFocus( parent );
2831 }
2832#endif
2833 /* Call hooks */
2834 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2835 {
2836 return FALSE;
2837 }
2838
2839 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2840 {
2841 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2842 /* FIXME: clean up palette - see "Internals" p.352 */
2843 }
2844
2845 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2846 {
2847 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2848 {
2849 /* Notify the parent window only */
2850 SendMessageA(getParent()->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2851 if(!::IsWindow(hwnd) )
2852 {
2853 return TRUE;
2854 }
2855 }
2856//// else DebugInt3();
2857 }
2858 /* Hide the window */
2859 if(IsWindowVisible(getWindowHandle()))
2860 {
2861 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2862 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2863 if(!::IsWindow(hwnd))
2864 {
2865 return TRUE;
2866 }
2867 }
2868 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2869
2870 // check the handle for the last active popup window
2871 Win32BaseWindow* owner = getOwner();
2872 if (NULL != owner)
2873 {
2874 if (owner->getLastActive() == hwnd)
2875 owner->setLastActive( owner->getWindowHandle() );
2876
2877 //SvL: Not sure this is correct, but it solves the problem of reassigning
2878 // activation. A disabled window will never be activated ->
2879 // possible that the wrong window is chosen by PM.
2880 // PM chooses another window to be activated before WM_DESTROY is
2881 // sent. VPC enables the owner when it receives that message,
2882 // but by then it's too late.
2883 // (MFC created modeless dialog)
2884 //TODO: This might be the wrong place to do it. EndDialog is called,
2885 // so perhaps it should be done there. (although Wine only
2886 // enables the owner if the dialog is modal)
2887 ::EnableWindow(owner->getWindowHandle(), 1);
2888 }
2889
2890 fDestroyWindowCalled = TRUE;
2891
2892//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2893// handler; must postpone it
2894 if(fChildDestructionInProgress) {
2895 dprintf(("Postponing parent destruction because of dying child"));
2896 OSLibPostMessageDirect(OS2HwndFrame, WIN32APP_POSTPONEDESTROY, 0, 0);
2897 return TRUE;
2898 }
2899
2900 BOOL fOldChildDestructionInProgress = FALSE;
2901 if(GetParent()) {
2902 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2903 if(window) {
2904 fOldChildDestructionInProgress = window->IsChildDestructionInProgress();
2905 window->SetChildDestructionInProgress(TRUE);
2906 RELEASE_WNDOBJ(window);
2907 }
2908 }
2909//hack end
2910
2911 BOOL ret = OSLibWinDestroyWindow(OS2HwndFrame);
2912
2913//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2914// handler; must postpone it
2915 if(GetParent()) {
2916 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2917 if(window) {
2918 window->SetChildDestructionInProgress(fOldChildDestructionInProgress);
2919 RELEASE_WNDOBJ(window);
2920 }
2921 }
2922//hack end
2923 return ret;
2924}
2925//******************************************************************************
2926//******************************************************************************
2927Win32BaseWindow *Win32BaseWindow::getParent()
2928{
2929 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2930 //experiment
2931#if 0
2932 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2933#else
2934 return wndparent;
2935#endif
2936}
2937//******************************************************************************
2938//Note: does not set last error if no parent (verified in NT4, SP6)
2939//******************************************************************************
2940HWND Win32BaseWindow::GetParent()
2941{
2942 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2943
2944 if(getStyle() & WS_CHILD)
2945 {
2946 if(wndparent) {
2947 return wndparent->getWindowHandle();
2948 }
2949 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2950 DebugInt3();
2951 return 0;
2952 }
2953 else
2954 if(getStyle() & WS_POPUP)
2955 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2956 else return 0;
2957}
2958//******************************************************************************
2959//******************************************************************************
2960HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2961{
2962 HWND oldhwnd;
2963 Win32BaseWindow *newparent;
2964 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2965 BOOL fShow = FALSE;
2966
2967 if(oldparent) {
2968 oldhwnd = oldparent->getWindowHandle();
2969 oldparent->removeChild(this);
2970 }
2971 else oldhwnd = 0;
2972
2973 /* Windows hides the window first, then shows it again
2974 * including the WM_SHOWWINDOW messages and all */
2975 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
2976 ShowWindow(SW_HIDE);
2977 fShow = TRUE;
2978 }
2979 if(oldparent) {
2980 //release parent here (increased refcount during creation)
2981 RELEASE_WNDOBJ(oldparent);
2982 }
2983 newparent = GetWindowFromHandle(hwndNewParent);
2984 if(newparent && !newparent->isDesktopWindow())
2985 {
2986 setParent(newparent);
2987 getParent()->addChild(this);
2988 fParentChange = TRUE;
2989 // in case we haven't finished creating the window whose parent we're
2990 // setting here, the OS/2 HWND might not exist yet and we call the PM
2991 // API with a NULLHANDLE - no problem
2992 // when we create the OS/2 window lateron, we will create it with the
2993 // right parent anyway.
2994 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2995 if(!(getStyle() & WS_CHILD))
2996 {
2997 if(getWindowId())
2998 {
2999 DestroyMenu( (HMENU) getWindowId() );
3000 setWindowId(0);
3001 }
3002 }
3003 //SvL: Even though the win32 coordinates might not change, the PM
3004 // coordinates can. We must make sure the control stays at the
3005 // same position (y) relative to the (new) parent.
3006 // TODO: shouldn't we check the state of the window and not do it in INIT state?
3007 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
3008 SWP_NOACTIVATE|SWP_NOSIZE);
3009 fParentChange = FALSE;
3010 }
3011 else {
3012 if(newparent) RELEASE_WNDOBJ(newparent);
3013
3014 setParent(windowDesktop);
3015 windowDesktop->addRef();
3016 windowDesktop->addChild(this);
3017 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
3018
3019 //Do not change the window id!
3020//// setWindowId(0);
3021 }
3022 /* SetParent additionally needs to make hwndChild the topmost window
3023 in the x-order and send the expected WM_WINDOWPOSCHANGING and
3024 WM_WINDOWPOSCHANGED notification messages.
3025 */
3026 if(state >= STATE_PRE_WMNCCREATE) {
3027 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
3028 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
3029
3030 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
3031 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
3032 }
3033 return oldhwnd;
3034}
3035//******************************************************************************
3036//******************************************************************************
3037BOOL Win32BaseWindow::IsChild(HWND hwndParent)
3038{
3039 // PH: Optimizer won't unroll calls to getParent() even
3040 // in release build.
3041 Win32BaseWindow *_parent = getParent();
3042
3043 if(_parent)
3044 {
3045 if(_parent->getWindowHandle() == hwndParent)
3046 return TRUE;
3047
3048 return _parent->IsChild(hwndParent);
3049 }
3050 else
3051 return 0;
3052}
3053//******************************************************************************
3054//******************************************************************************
3055HWND Win32BaseWindow::GetTopWindow()
3056{
3057 HWND hwndTop;
3058 Win32BaseWindow *topwindow;
3059
3060 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3061 if(!isDesktopWindow())
3062 {
3063 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3064 //Note: GetTopWindow can't return a window that hasn't processed
3065 // WM_NCCREATE yet (verified in NT4, SP6)
3066 if(topwindow) {
3067 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3068 hwndTop = topwindow->getWindowHandle();
3069 }
3070 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3071 RELEASE_WNDOBJ(topwindow);
3072 return hwndTop;
3073 }
3074 if(topwindow) RELEASE_WNDOBJ(topwindow);
3075 return 0;
3076 }
3077 while(hwndTop) {
3078 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3079 //Note: GetTopWindow can't return a window that hasn't processed
3080 // WM_NCCREATE yet (verified in NT4, SP6)
3081 if(topwindow) {
3082 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3083 hwndTop = topwindow->getWindowHandle();
3084 }
3085 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3086 RELEASE_WNDOBJ(topwindow);
3087 return hwndTop;
3088 }
3089 if(topwindow) RELEASE_WNDOBJ(topwindow);
3090 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
3091 }
3092
3093 return 0;
3094}
3095//******************************************************************************
3096// Get the top-level parent for a child window.
3097//******************************************************************************
3098HWND Win32BaseWindow::GetTopParent()
3099{
3100 Win32BaseWindow *window = this;
3101 HWND hwndTopParent = 0;
3102
3103 lock();
3104 while(window && (window->getStyle() & WS_CHILD))
3105 {
3106 window = window->getParent();
3107 }
3108 if(window) {
3109 hwndTopParent = window->getWindowHandle();
3110 }
3111 unlock();
3112 return hwndTopParent;
3113}
3114//******************************************************************************
3115//TODO: Should not enumerate children that are created during the enumeration!
3116//TODO: Do this more efficiently
3117//******************************************************************************
3118BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
3119{
3120 BOOL rc = TRUE;
3121 HWND hwnd;
3122 Win32BaseWindow *prevchild = 0, *child = 0;
3123
3124 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3125 lock();
3126 for (child = (Win32BaseWindow *)getFirstChild(); child != NULL; child = (Win32BaseWindow *)child->getNextChild())
3127 {
3128 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3129 hwnd = child->getWindowHandle();
3130 if(child->IsWindowDestroyed() || child->getOwner()) {
3131 continue; //shouldn't have an owner (Wine)
3132 }
3133 child->addRef();
3134 unlock();
3135 if(lpfn(hwnd, lParam) == FALSE)
3136 {
3137 child->release();
3138 return FALSE;
3139 }
3140 child->release();
3141 lock();
3142 //check if the window still exists
3143 if(!::IsWindow(hwnd))
3144 {
3145 child = prevchild;
3146 if(child == NULL) break;
3147 continue;
3148 }
3149 if(child->getFirstChild() != NULL)
3150 {
3151 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3152 child->addRef();
3153 unlock();
3154 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3155 {
3156 child->release();
3157 return FALSE;
3158 }
3159 child->release();
3160 lock();
3161 }
3162 prevchild = child;
3163 }
3164 unlock();
3165 return rc;
3166}
3167//******************************************************************************
3168//Enumerate first-level children only and check thread id
3169//NOTE: NT4 returns first-level children in Z-order!
3170//******************************************************************************
3171BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3172{
3173 Win32BaseWindow *wnd = NULL;
3174 HWND henum, hwnd, hwndWin32;
3175 ULONG tid, pid;
3176 BOOL rc;
3177
3178 //Enumerate all top-level windows and check the process and thread ids
3179 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3180 hwnd = OSLibWinGetNextWindow(henum);
3181
3182 while(hwnd)
3183 {
3184 wnd = GetWindowFromOS2FrameHandle(hwnd);
3185 if(wnd == NULL) {
3186 hwnd = OSLibWinQueryClientWindow(hwnd);
3187 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3188 }
3189 if(wnd) {
3190 hwndWin32 = wnd->getWindowHandle();
3191 }
3192 else hwndWin32 = 0;
3193
3194 if(wnd) RELEASE_WNDOBJ(wnd);
3195
3196 if(hwndWin32) {
3197 OSLibWinQueryWindowProcess(hwnd, &pid, &tid);
3198
3199 if(dwThreadId == tid) {
3200 dprintf(("EnumThreadWindows: Found Window %x", hwndWin32));
3201 if((rc = lpfn(hwndWin32, lParam)) == FALSE) {
3202 break;
3203 }
3204 }
3205 }
3206 hwnd = OSLibWinGetNextWindow(henum);
3207 }
3208 OSLibWinEndEnumWindows(henum);
3209 return TRUE;
3210}
3211//******************************************************************************
3212//Enumerate first-level children only
3213//******************************************************************************
3214BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3215{
3216 Win32BaseWindow *window;
3217 BOOL rc;
3218 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
3219 DWORD dwStyle;
3220
3221 dprintf(("EnumWindows %x %x", lpfn, lParam));
3222
3223 for(int i=0;i<MAX_WINDOW_HANDLES;i++)
3224 {
3225 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3226 if(window) {
3227 if(window->getWindowHandle() != hwnd) {
3228 dprintf(("CORRUPT WINDOW %x %x", window, hwnd));
3229 }
3230 RELEASE_WNDOBJ(window);
3231 dwStyle = ::GetWindowLongA(hwnd, GWL_STYLE);
3232 if ((dwStyle & WS_POPUP) || ((dwStyle & WS_CAPTION) == WS_CAPTION))
3233 {
3234 dprintf2(("EnumWindows: Found Window %x", hwnd));
3235 if((rc = lpfn(hwnd, lParam)) == FALSE) {
3236 break;
3237 }
3238 }
3239 }
3240 hwnd++;
3241 }
3242 return TRUE;
3243}
3244//******************************************************************************
3245//******************************************************************************
3246HWND Win32BaseWindow::FindWindowById(int id)
3247{
3248 HWND hwnd;
3249
3250 lock();
3251 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3252 {
3253 if (child->getWindowId() == id)
3254 {
3255 hwnd = child->getWindowHandle();
3256 unlock();
3257 return hwnd;
3258 }
3259 }
3260 unlock();
3261 return 0;
3262}
3263//******************************************************************************
3264//TODO:
3265//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3266//the current process owns them.
3267//******************************************************************************
3268HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3269{
3270 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3271 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3272 Win32BaseWindow *firstchild = child;
3273
3274 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3275 if((hwndParent != 0 && !parent) ||
3276 (hwndChildAfter != 0 && !child) ||
3277 (hwndParent == 0 && hwndChildAfter != 0))
3278 {
3279 if(parent) RELEASE_WNDOBJ(parent);
3280 if(firstchild) RELEASE_WNDOBJ(firstchild);
3281 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3282 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3283 return 0;
3284 }
3285 SetLastError(0);
3286 if(hwndParent != 0)
3287 {//if the current process owns the window, just do a quick search
3288 lock(&critsect);
3289 child = (Win32BaseWindow *)parent->getFirstChild();
3290 if(hwndChildAfter != 0)
3291 {
3292 while(child)
3293 {
3294 if(child->getWindowHandle() == hwndChildAfter)
3295 {
3296 child = (Win32BaseWindow *)child->getNextChild();
3297 break;
3298 }
3299 child = (Win32BaseWindow *)child->getNextChild();
3300 }
3301 }
3302 while(child)
3303 {
3304 //According to Wine, the class doesn't need to be specified
3305 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3306 (!lpszWindow || child->hasWindowName(lpszWindow)))
3307 {
3308 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3309 HWND hwndChild = child->getWindowHandle();
3310 unlock(&critsect);
3311 if(parent) RELEASE_WNDOBJ(parent);
3312 if(firstchild) RELEASE_WNDOBJ(firstchild);
3313 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3314 return hwndChild;
3315 }
3316 child = (Win32BaseWindow *)child->getNextChild();
3317 }
3318 unlock(&critsect);
3319 if(parent) RELEASE_WNDOBJ(parent);
3320 if(firstchild) RELEASE_WNDOBJ(firstchild);
3321 }
3322 else {
3323 Win32BaseWindow *wnd;
3324 HWND henum, hwnd;
3325
3326 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3327 hwnd = OSLibWinGetNextWindow(henum);
3328
3329 while(hwnd)
3330 {
3331 wnd = GetWindowFromOS2FrameHandle(hwnd);
3332 if(wnd == NULL) {
3333 hwnd = OSLibWinQueryClientWindow(hwnd);
3334 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3335 }
3336
3337 if(wnd) {
3338 //According to Wine, the class doesn't need to be specified
3339 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3340 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3341 {
3342 OSLibWinEndEnumWindows(henum);
3343 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3344 HWND hwndret = wnd->getWindowHandle();
3345 RELEASE_WNDOBJ(wnd);
3346 return hwndret;
3347 }
3348 RELEASE_WNDOBJ(wnd);
3349 }
3350 hwnd = OSLibWinGetNextWindow(henum);
3351 }
3352 OSLibWinEndEnumWindows(henum);
3353 if(parent) RELEASE_WNDOBJ(parent);
3354 if(firstchild) RELEASE_WNDOBJ(firstchild);
3355 }
3356 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3357 return 0;
3358}
3359//******************************************************************************
3360//******************************************************************************
3361HWND Win32BaseWindow::GetWindow(UINT uCmd)
3362{
3363 HWND hwndRelated = 0;
3364 Win32BaseWindow *window;
3365
3366 switch(uCmd)
3367 {
3368 case GW_HWNDFIRST:
3369 window = (Win32BaseWindow *)getParent();
3370 if(window)
3371 {
3372 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3373 window = GetWindowFromOS2FrameHandle(hwndRelated);
3374 if(window) {
3375 hwndRelated = window->getWindowHandle();
3376 RELEASE_WNDOBJ(window);
3377 }
3378 else hwndRelated = 0;
3379 }
3380 else {
3381 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3382 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3383 }
3384 break;
3385
3386 case GW_HWNDLAST:
3387 window = (Win32BaseWindow *)getParent();
3388 if(window) {
3389 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3390 dprintf(("os2 handle %x", hwndRelated));
3391 window = GetWindowFromOS2FrameHandle(hwndRelated);
3392 if(window) {
3393 hwndRelated = window->getWindowHandle();
3394 RELEASE_WNDOBJ(window);
3395 }
3396 else hwndRelated = 0;
3397 }
3398 else {
3399 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3400 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3401 }
3402 break;
3403
3404 case GW_HWNDNEXT:
3405 if(getParent()) {
3406 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3407 window = GetWindowFromOS2FrameHandle(hwndRelated);
3408 if(window) {
3409 hwndRelated = window->getWindowHandle();
3410 RELEASE_WNDOBJ(window);
3411 }
3412 else hwndRelated = 0;
3413 }
3414 else {
3415 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3416 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3417 }
3418 break;
3419
3420 case GW_HWNDPREV:
3421 if(getParent()) {
3422 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3423 window = GetWindowFromOS2FrameHandle(hwndRelated);
3424 if(window) {
3425 hwndRelated = window->getWindowHandle();
3426 RELEASE_WNDOBJ(window);
3427 }
3428 else hwndRelated = 0;
3429 }
3430 else {
3431 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3432 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3433 }
3434 break;
3435
3436 case GW_OWNER:
3437 {
3438 Win32BaseWindow *owner = getOwner();
3439 if(owner) {
3440 hwndRelated = owner->getWindowHandle();
3441 }
3442 break;
3443 }
3444
3445 case GW_CHILD:
3446 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3447 window = GetWindowFromOS2FrameHandle(hwndRelated);
3448
3449 //Before a window has processed WM_NCCREATE:
3450 //- GetWindow(parent, GW_CHILD) can't return that window handle
3451 //(verified in NT4, SP6)
3452 if(window) {
3453 if(window->state >= STATE_POST_WMNCCREATE) {
3454 hwndRelated = window->getWindowHandle();
3455 RELEASE_WNDOBJ(window);
3456 }
3457 else {
3458 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3459 RELEASE_WNDOBJ(window);
3460 }
3461 }
3462 else hwndRelated = 0;
3463
3464 break;
3465
3466 //for internal use only
3467 case GW_HWNDNEXTCHILD:
3468 lock();
3469 window = (Win32BaseWindow *)getNextChild();
3470 if(window) {
3471 hwndRelated = window->getWindowHandle();
3472 }
3473 else hwndRelated = 0;
3474 unlock();
3475 break;
3476
3477 case GW_HWNDPREVCHILD:
3478 DebugInt3();
3479 break;
3480
3481 case GW_HWNDFIRSTCHILD:
3482 lock();
3483 window = (Win32BaseWindow *)getFirstChild();
3484 if(window) {
3485 hwndRelated = window->getWindowHandle();
3486 }
3487 else hwndRelated = 0;
3488 unlock();
3489 break;
3490
3491 case GW_HWNDLASTCHILD:
3492 lock();
3493 window = (Win32BaseWindow *)getFirstChild();
3494 if(window) {
3495 while (window->getNextChild())
3496 {
3497 window = (Win32BaseWindow *)window->getNextChild();
3498 }
3499 hwndRelated = window->getWindowHandle();
3500 }
3501 else hwndRelated = 0;
3502 unlock();
3503 break;
3504 }
3505end:
3506 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3507 return hwndRelated;
3508}
3509//******************************************************************************
3510//******************************************************************************
3511HWND Win32BaseWindow::SetActiveWindow()
3512{
3513 HWND hwndActive;
3514
3515 dprintf(("SetActiveWindow %x", getWindowHandle()));
3516 if(getStyle() & WS_CHILD) {
3517// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3518 dprintf(("WARNING: Window is a child or disabled"));
3519 return 0;
3520 }
3521
3522 if(GetActiveWindow() == getWindowHandle()) {
3523 dprintf(("Window already active"));
3524 return getWindowHandle();
3525 }
3526 if (HOOK_IsHooked( WH_CBT ))
3527 {
3528 CBTACTIVATESTRUCT cbta;
3529 LRESULT ret;
3530
3531 cbta.fMouse = FALSE;
3532 cbta.hWndActive = GetActiveWindow();
3533 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3534 if(ret)
3535 {
3536 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3537 return cbta.hWndActive;
3538 }
3539 }
3540 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3541
3542// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3543// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3544// }
3545 hwndActive = GetActiveWindow();
3546 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3547}
3548//******************************************************************************
3549//Used to change active status of an mdi window
3550//******************************************************************************
3551BOOL Win32BaseWindow::DeactivateChildWindow()
3552{
3553 /* child windows get a WM_CHILDACTIVATE message */
3554 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3555 {
3556 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3557 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3558 return TRUE;
3559 }
3560 DebugInt3(); //should not be called for non-child window
3561 return FALSE;
3562}
3563//******************************************************************************
3564//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3565//******************************************************************************
3566BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3567{
3568 BOOL rc;
3569
3570 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3571 //return true if previous state was disabled, else false (sdk docs)
3572 rc = (getStyle() & WS_DISABLED) != 0;
3573 if(rc && !fEnable) {
3574 SendMessageA(getWindowHandle(), WM_CANCELMODE, 0, 0);
3575 }
3576 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3577 if(fEnable == FALSE) {
3578 //SvL: No need to clear focus as PM already does this
3579 if(getWindowHandle() == GetCapture()) {
3580 ReleaseCapture(); /* A disabled window can't capture the mouse */
3581 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3582 }
3583 }
3584 return rc;
3585}
3586//******************************************************************************
3587//******************************************************************************
3588BOOL Win32BaseWindow::CloseWindow()
3589{
3590 if (::GetWindowLongW( getWindowHandle() , GWL_STYLE ) & WS_CHILD) return FALSE;
3591 ShowWindow( SW_MINIMIZE );
3592 return TRUE;
3593}
3594//******************************************************************************
3595//TODO: Not be 100% correct; should return active window of current thread
3596// or NULL when there is none -> WinQueryActiveWindow just returns
3597// the current active window
3598//******************************************************************************
3599HWND Win32BaseWindow::GetActiveWindow()
3600{
3601 HWND hwndActive;
3602
3603 hwndActive = OSLibWinQueryActiveWindow();
3604 return OS2ToWin32Handle(hwndActive);
3605}
3606//******************************************************************************
3607//******************************************************************************
3608BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3609{
3610 INT len = GetWindowTextLength(fUnicode);
3611 BOOL res;
3612
3613 if (wndname == NULL)
3614 return (len == 0);
3615
3616 len++;
3617 if (fUnicode)
3618 {
3619 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3620
3621 GetWindowTextW(text,len);
3622 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3623 free(text);
3624 }
3625 else
3626 {
3627 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3628
3629 GetWindowTextA(text,len);
3630 res = (strcmp(text,wndname) == 0);
3631 free(text);
3632 }
3633
3634 return res;
3635}
3636//******************************************************************************
3637//******************************************************************************
3638CHAR *Win32BaseWindow::getWindowNamePtrA()
3639{
3640 INT len = GetWindowTextLength(FALSE);
3641 CHAR *text;
3642
3643 if (len == 0) return NULL;
3644 len++;
3645 text = (CHAR*)malloc(len*sizeof(CHAR));
3646 GetWindowTextA(text,len);
3647
3648 return text;
3649}
3650//******************************************************************************
3651//******************************************************************************
3652WCHAR *Win32BaseWindow::getWindowNamePtrW()
3653{
3654 INT len = GetWindowTextLength(TRUE);
3655 WCHAR *text;
3656
3657 if (len == 0) return NULL;
3658 len++;
3659 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3660 GetWindowTextW(text,len);
3661
3662 return text;
3663}
3664//******************************************************************************
3665//******************************************************************************
3666VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3667{
3668 if (namePtr) free(namePtr);
3669}
3670//******************************************************************************
3671//When using this API for a window that was created by a different process, NT
3672//does NOT send WM_GETTEXTLENGTH.
3673//******************************************************************************
3674int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3675{
3676 //if the destination window is created by this process, send message
3677 if(dwProcessId == currentProcessId)
3678 {
3679 if(fUnicode) {
3680 return SendMessageW(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3681 }
3682 else return SendMessageA(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3683 }
3684 //else get data directory from window structure
3685 //TODO: must lock window structure.... (TODO)
3686 return windowNameLength;
3687}
3688//******************************************************************************
3689//When using this API for a window that was created by a different process, NT
3690//does NOT send WM_GETTEXT.
3691//******************************************************************************
3692int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3693{
3694 //if the destination window is created by this process, send message
3695 if(dwProcessId == currentProcessId) {
3696 return SendMessageA(getWindowHandle(),WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3697 }
3698
3699 //else get data directory from window structure
3700 if (!lpsz || !cch) return 0;
3701 if (!windowNameA) lpsz[0] = 0;
3702 else memcpy(lpsz, windowNameA, min(windowNameLength + 1, cch) );
3703 return min(windowNameLength, cch);
3704}
3705//******************************************************************************
3706//When using this API for a window that was created by a different process, NT
3707//does NOT send WM_GETTEXT.
3708//******************************************************************************
3709int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3710{
3711 //if the destination window is created by this process, send message
3712 if(dwProcessId == currentProcessId) {
3713 return ::SendMessageW(getWindowHandle(), WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3714 }
3715 //else get data directory from window structure
3716 if (!lpsz || !cch)
3717 return 0;
3718 if (!windowNameW)
3719 lpsz[0] = 0;
3720 else
3721 memcpy(lpsz, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), cch));
3722
3723 return min(windowNameLength, cch);
3724}
3725//******************************************************************************
3726//TODO: How does this work when the target window belongs to a different process???
3727//******************************************************************************
3728BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3729{
3730 return SendMessageA(getWindowHandle(),WM_SETTEXT,0,(LPARAM)lpsz);
3731}
3732//******************************************************************************
3733//******************************************************************************
3734BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3735{
3736 return SendMessageW(getWindowHandle(), WM_SETTEXT,0,(LPARAM)lpsz);
3737}
3738//******************************************************************************
3739//******************************************************************************
3740LONG Win32BaseWindow::SetWindowLong(int index, ULONG value, BOOL fUnicode)
3741{
3742 LONG oldval;
3743
3744 switch(index) {
3745 case GWL_EXSTYLE:
3746 {
3747 STYLESTRUCT ss;
3748
3749 if(dwExStyle == value) {
3750 oldval = value;
3751 break;
3752 }
3753 ss.styleOld = dwExStyle;
3754 ss.styleNew = value;
3755 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3756 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3757 setExStyle(ss.styleNew);
3758 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3759 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
3760 oldval = ss.styleOld;
3761 break;
3762 }
3763 case GWL_STYLE:
3764 {
3765 STYLESTRUCT ss;
3766
3767 //SvL: TODO: Can you change minimize or maximize status here too?
3768
3769 if(dwStyle == value) {
3770 oldval = value;
3771 break;
3772 }
3773 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3774
3775 //Changing WS_CHILD style is allowed
3776 ss.styleOld = getStyle();
3777 ss.styleNew = value;
3778 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3779 setStyle(ss.styleNew);
3780 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3781 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3782 getStyle(), getExStyle());
3783
3784 //TODO: Might not be correct to use ShowWindow here
3785 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3786 if(ss.styleNew & WS_VISIBLE)
3787 ShowWindow(SW_SHOWNOACTIVATE);
3788 else ShowWindow(SW_HIDE);
3789 }
3790
3791#ifdef DEBUG
3792 PrintWindowStyle(ss.styleNew, 0);
3793#endif
3794 oldval = ss.styleOld;
3795 break;
3796 }
3797 case GWL_WNDPROC:
3798 {
3799 //Note: Type of SetWindowLong determines new window proc type
3800 // UNLESS the new window proc has already been registered
3801 // (use the old type in that case)
3802 // (VERIFIED in NT 4, SP6)
3803 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3804 if(type == WIN_PROC_INVALID) {
3805 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3806 }
3807 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3808 dprintf(("SetWindowLong%c GWL_WNDPROC %x old %x new wndproc %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), oldval, value));
3809 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3810 break;
3811 }
3812 case GWL_HINSTANCE:
3813 oldval = hInstance;
3814 hInstance = value;
3815 break;
3816
3817 case GWL_HWNDPARENT:
3818 dprintf(("GWL_ID GWL_HWNDPARENT %x, new %x", GetParent(), value));
3819 oldval = SetParent((HWND)value);
3820 break;
3821
3822 case GWL_ID:
3823 dprintf(("GWL_ID old %x, new %x", getWindowId(), value));
3824 oldval = getWindowId();
3825 setWindowId(value);
3826 break;
3827
3828 case GWL_USERDATA:
3829 oldval = userData;
3830 userData = value;
3831 break;
3832
3833 default:
3834 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3835 {
3836 oldval = *(ULONG *)(userWindowBytes + index);
3837 *(ULONG *)(userWindowBytes + index) = value;
3838 break;
3839 }
3840 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3841 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3842 return 0;
3843 }
3844 //Note: NT4, SP6 does not set the last error to 0
3845 SetLastError(ERROR_SUCCESS);
3846 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3847 return oldval;
3848}
3849//******************************************************************************
3850//******************************************************************************
3851ULONG Win32BaseWindow::GetWindowLong(int index, BOOL fUnicode)
3852{
3853 ULONG value;
3854
3855 switch(index) {
3856 case GWL_EXSTYLE:
3857 value = dwExStyle;
3858 break;
3859 case GWL_STYLE:
3860 value = dwStyle;
3861 break;
3862 case GWL_WNDPROC:
3863 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3864 break;
3865 case GWL_HINSTANCE:
3866 value = hInstance;
3867 break;
3868 case GWL_HWNDPARENT:
3869 value = GetParent();
3870 break;
3871 case GWL_ID:
3872 value = getWindowId();
3873 break;
3874 case GWL_USERDATA:
3875 value = userData;
3876 break;
3877 default:
3878 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3879 {
3880 value = *(ULONG *)(userWindowBytes + index);
3881 break;
3882 }
3883 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3884 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3885 return 0;
3886 }
3887 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3888 //Note: NT4, SP6 does not set the last error to 0
3889 SetLastError(ERROR_SUCCESS);
3890 return value;
3891}
3892//******************************************************************************
3893//******************************************************************************
3894WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3895{
3896 WORD oldval;
3897
3898 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3899 {
3900 oldval = *(WORD *)(userWindowBytes + index);
3901 *(WORD *)(userWindowBytes + index) = value;
3902 //Note: NT4, SP6 does not set the last error to 0
3903 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3904 SetLastError(ERROR_SUCCESS);
3905 return oldval;
3906 }
3907 switch(index)
3908 {
3909 case GWW_HINSTANCE:
3910 oldval = hInstance;
3911 hInstance = value;
3912 break;
3913
3914 case GWW_HWNDPARENT:
3915 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3916 break;
3917
3918 case GWW_ID:
3919 oldval = getWindowId();
3920 setWindowId(value);
3921 break;
3922
3923 default:
3924 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3925 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3926 return 0;
3927 }
3928 //Note: NT4, SP6 does not set the last error to 0
3929 SetLastError(ERROR_SUCCESS);
3930 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3931 return oldval;
3932}
3933//******************************************************************************
3934//******************************************************************************
3935WORD Win32BaseWindow::GetWindowWord(int index)
3936{
3937 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3938 {
3939 //Note: NT4, SP6 does not set the last error to 0
3940 SetLastError(ERROR_SUCCESS);
3941 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3942 return *(WORD *)(userWindowBytes + index);
3943 }
3944 switch(index)
3945 {
3946 case GWW_ID:
3947 if(HIWORD(getWindowId()))
3948 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3949 return (WORD)getWindowId();
3950
3951 case GWW_HWNDPARENT:
3952 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3953 return (WORD) GetParent();
3954
3955 case GWW_HINSTANCE:
3956 if (HIWORD(hInstance))
3957 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3958 return (WORD)hInstance;
3959 }
3960
3961 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3962 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3963 return 0;
3964}
3965//******************************************************************************
3966//Locates window in linked list and increases reference count (if found)
3967//Window object must be unreferenced after usage
3968//******************************************************************************
3969Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3970{
3971 Win32BaseWindow *window;
3972
3973////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
3974//// while browsing
3975//// Not thread safe now!
3976//// lock(&critsect);
3977 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3978 if(window) {
3979//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
3980 window->addRef();
3981 }
3982//// unlock(&critsect);
3983 return window;
3984 }
3985//// unlock(&critsect);
3986// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3987 return NULL;
3988}
3989//******************************************************************************
3990//Locates window in linked list and increases reference count (if found)
3991//Window object must be unreferenced after usage
3992//******************************************************************************
3993Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
3994{
3995 DWORD magic;
3996 HWND hwnd;
3997
3998 if(hwndOS2 == OSLIB_HWND_DESKTOP)
3999 {
4000 windowDesktop->addRef();
4001 return windowDesktop;
4002 }
4003
4004 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
4005 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
4006
4007 if(hwnd && CheckMagicDword(magic)) {
4008 return GetWindowFromHandle(hwnd);
4009 }
4010// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
4011 return 0;
4012}
4013//******************************************************************************
4014//Locates window in linked list and increases reference count (if found)
4015//Window object must be unreferenced after usage
4016//******************************************************************************
4017Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
4018{
4019 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
4020}
4021//******************************************************************************
4022//******************************************************************************
4023HWND WIN32API Win32ToOS2Handle(HWND hwnd)
4024{
4025 HWND hwndOS2;
4026
4027 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4028
4029 if(window) {
4030 hwndOS2 = window->getOS2WindowHandle();
4031 RELEASE_WNDOBJ(window);
4032 return hwndOS2;
4033 }
4034// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4035 return hwnd;
4036}
4037//******************************************************************************
4038//******************************************************************************
4039HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
4040{
4041 HWND hwndOS2;
4042
4043 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4044
4045 if(window) {
4046 hwndOS2 = window->getOS2FrameWindowHandle();
4047 RELEASE_WNDOBJ(window);
4048 return hwndOS2;
4049 }
4050// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4051 return hwnd;
4052}
4053//******************************************************************************
4054//******************************************************************************
4055HWND WIN32API OS2ToWin32Handle(HWND hwnd)
4056{
4057 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
4058 HWND hwndWin32;
4059
4060 if(window) {
4061 hwndWin32 = window->getWindowHandle();
4062 RELEASE_WNDOBJ(window);
4063 return hwndWin32;
4064 }
4065 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
4066 if(window) {
4067 hwndWin32 = window->getWindowHandle();
4068 RELEASE_WNDOBJ(window);
4069 return hwndWin32;
4070 }
4071
4072// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
4073 return 0;
4074// else return hwnd; //OS/2 window handle
4075}
4076#ifdef DEBUG
4077LONG Win32BaseWindow::addRef()
4078{
4079// dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
4080 return GenericObject::addRef();
4081}
4082//******************************************************************************
4083//******************************************************************************
4084LONG Win32BaseWindow::release(char *function, int line)
4085{
4086// dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
4087 return GenericObject::release();
4088}
4089#endif
4090//******************************************************************************
4091//******************************************************************************
4092GenericObject *Win32BaseWindow::windows = NULL;
4093CRITICAL_SECTION Win32BaseWindow::critsect = {0};
4094
4095//******************************************************************************
4096//******************************************************************************
4097#ifdef DEBUG
4098void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
4099{
4100 char style[256] = "";
4101 char exstyle[256] = "";
4102
4103 /* Window styles */
4104 if(dwStyle & WS_CHILD)
4105 strcat(style, "WS_CHILD ");
4106 if(dwStyle & WS_POPUP)
4107 strcat(style, "WS_POPUP ");
4108 if(dwStyle & WS_VISIBLE)
4109 strcat(style, "WS_VISIBLE ");
4110 if(dwStyle & WS_DISABLED)
4111 strcat(style, "WS_DISABLED ");
4112 if(dwStyle & WS_CLIPSIBLINGS)
4113 strcat(style, "WS_CLIPSIBLINGS ");
4114 if(dwStyle & WS_CLIPCHILDREN)
4115 strcat(style, "WS_CLIPCHILDREN ");
4116 if(dwStyle & WS_MAXIMIZE)
4117 strcat(style, "WS_MAXIMIZE ");
4118 if(dwStyle & WS_MINIMIZE)
4119 strcat(style, "WS_MINIMIZE ");
4120 if(dwStyle & WS_GROUP)
4121 strcat(style, "WS_GROUP ");
4122 if(dwStyle & WS_TABSTOP)
4123 strcat(style, "WS_TABSTOP ");
4124
4125 if((dwStyle & WS_CAPTION) == WS_CAPTION)
4126 strcat(style, "WS_CAPTION ");
4127 if(dwStyle & WS_DLGFRAME)
4128 strcat(style, "WS_DLGFRAME ");
4129 if(dwStyle & WS_BORDER)
4130 strcat(style, "WS_BORDER ");
4131
4132 if(dwStyle & WS_VSCROLL)
4133 strcat(style, "WS_VSCROLL ");
4134 if(dwStyle & WS_HSCROLL)
4135 strcat(style, "WS_HSCROLL ");
4136 if(dwStyle & WS_SYSMENU)
4137 strcat(style, "WS_SYSMENU ");
4138 if(dwStyle & WS_THICKFRAME)
4139 strcat(style, "WS_THICKFRAME ");
4140 if(dwStyle & WS_MINIMIZEBOX)
4141 strcat(style, "WS_MINIMIZEBOX ");
4142 if(dwStyle & WS_MAXIMIZEBOX)
4143 strcat(style, "WS_MAXIMIZEBOX ");
4144
4145 if(dwExStyle & WS_EX_DLGMODALFRAME)
4146 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4147 if(dwExStyle & WS_EX_ACCEPTFILES)
4148 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4149 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4150 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4151 if(dwExStyle & WS_EX_TOPMOST)
4152 strcat(exstyle, "WS_EX_TOPMOST ");
4153 if(dwExStyle & WS_EX_TRANSPARENT)
4154 strcat(exstyle, "WS_EX_TRANSPARENT ");
4155
4156 if(dwExStyle & WS_EX_MDICHILD)
4157 strcat(exstyle, "WS_EX_MDICHILD ");
4158 if(dwExStyle & WS_EX_TOOLWINDOW)
4159 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4160 if(dwExStyle & WS_EX_WINDOWEDGE)
4161 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4162 if(dwExStyle & WS_EX_CLIENTEDGE)
4163 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4164 if(dwExStyle & WS_EX_CONTEXTHELP)
4165 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4166 if(dwExStyle & WS_EX_RIGHT)
4167 strcat(exstyle, "WS_EX_RIGHT ");
4168 if(dwExStyle & WS_EX_LEFT)
4169 strcat(exstyle, "WS_EX_LEFT ");
4170 if(dwExStyle & WS_EX_RTLREADING)
4171 strcat(exstyle, "WS_EX_RTLREADING ");
4172 if(dwExStyle & WS_EX_LTRREADING)
4173 strcat(exstyle, "WS_EX_LTRREADING ");
4174 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4175 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4176 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4177 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4178 if(dwExStyle & WS_EX_CONTROLPARENT)
4179 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4180 if(dwExStyle & WS_EX_STATICEDGE)
4181 strcat(exstyle, "WS_EX_STATICEDGE ");
4182 if(dwExStyle & WS_EX_APPWINDOW)
4183 strcat(exstyle, "WS_EX_APPWINDOW ");
4184
4185 dprintf(("Window style: %x %s", dwStyle, style));
4186 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4187}
4188#endif
4189//******************************************************************************
4190//******************************************************************************
Note: See TracBrowser for help on using the repository browser.