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

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

Don't change focus when processing mouse button message if the top parent is a fake window

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