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

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

Changes for applications that don't validate the update region of a window during WM_PAINT

File size: 146.6 KB
Line 
1/* $Id: win32wbase.cpp,v 1.363 2003-03-22 20:27:12 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) {
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::IsWindowIconic()
1469{
1470 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1471}
1472//******************************************************************************
1473//******************************************************************************
1474SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1475{
1476 switch(nBar)
1477 {
1478 case SB_HORZ:
1479 if (!horzScrollInfo)
1480 {
1481 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1482 if (!horzScrollInfo) break;
1483 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1484 horzScrollInfo->MaxVal = 100;
1485 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1486 }
1487 return horzScrollInfo;
1488
1489 case SB_VERT:
1490 if (!vertScrollInfo)
1491 {
1492 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1493 if (!vertScrollInfo) break;
1494 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1495 vertScrollInfo->MaxVal = 100;
1496 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1497 }
1498 return vertScrollInfo;
1499 }
1500
1501 return NULL;
1502}
1503//******************************************************************************
1504//******************************************************************************
1505LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1506{
1507 //SvL: Set background color to default button color (not window (white))
1508 if(ctlType == CTLCOLOR_BTN)
1509 {
1510 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1511 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1512 return GetSysColorBrush(COLOR_BTNFACE);
1513 }
1514 //SvL: Set background color to default dialog color if window is dialog
1515 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1516 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1517 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1518 return GetSysColorBrush(COLOR_BTNFACE);
1519 }
1520 if( ctlType == CTLCOLOR_SCROLLBAR)
1521 {
1522 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1523 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1524 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1525 SetBkColor( hdc, bk);
1526
1527 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1528 * we better use 0x55aa bitmap brush to make scrollbar's background
1529 * look different from the window background.
1530 */
1531 if (bk == GetSysColor(COLOR_WINDOW)) {
1532 return GetPattern55AABrush();
1533 }
1534
1535 UnrealizeObject( hb );
1536 return (LRESULT)hb;
1537 }
1538
1539 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1540
1541 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1542 {
1543 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1544 }
1545 else
1546 {
1547 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1548 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1549 }
1550 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1551}
1552//******************************************************************************
1553//******************************************************************************
1554LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1555{
1556 /*
1557 * Visibility flag.
1558 */
1559 if ( (uFlags & PRF_CHECKVISIBLE) &&
1560 !IsWindowVisible(getWindowHandle()) )
1561 return 0;
1562
1563 /*
1564 * Unimplemented flags.
1565 */
1566 if ( (uFlags & PRF_CHILDREN) ||
1567 (uFlags & PRF_OWNED) ||
1568 (uFlags & PRF_NONCLIENT) )
1569 {
1570 dprintf(("WM_PRINT message with unsupported flags\n"));
1571 }
1572
1573 /*
1574 * Background
1575 */
1576 if ( uFlags & PRF_ERASEBKGND)
1577 SendMessageA(getWindowHandle(),WM_ERASEBKGND, (WPARAM)hdc, 0);
1578
1579 /*
1580 * Client area
1581 */
1582 if ( uFlags & PRF_CLIENT)
1583 SendMessageA(getWindowHandle(),WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1584
1585
1586 return 0;
1587}
1588//******************************************************************************
1589//******************************************************************************
1590LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1591{
1592 switch(Msg)
1593 {
1594 case WM_CLOSE:
1595 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1596 DestroyWindow();
1597 return 0;
1598
1599 case WM_GETTEXTLENGTH:
1600 return windowNameLength;
1601
1602 case WM_GETTEXT:
1603 if (!lParam || !wParam)
1604 return 0;
1605 if (!windowNameA)
1606 ((LPSTR)lParam)[0] = 0;
1607 else
1608 memcpy((LPSTR)lParam, windowNameA, min(windowNameLength+1, wParam) );
1609 return min(windowNameLength, wParam);
1610
1611 case WM_SETTEXT:
1612 {
1613 LPCSTR lpsz = (LPCSTR)lParam;
1614
1615 // reallocate if new buffer is larger
1616 if (!lParam)
1617 {
1618 free(windowNameA);
1619 free(windowNameW);
1620 windowNameLength = 0;
1621 windowNameA = NULL;
1622 windowNameW = NULL;
1623 }
1624 else
1625 {
1626 // determine length of new text
1627 int iTextLength = strlen(lpsz);
1628
1629 if (windowNameLength < iTextLength)
1630 {
1631 if (windowNameA)
1632 {
1633 free(windowNameA);
1634 windowNameA = NULL;
1635 }
1636
1637 if (windowNameW)
1638 {
1639 free(windowNameW);
1640 windowNameW = NULL;
1641 }
1642 }
1643
1644 windowNameLength = iTextLength;
1645 if(!windowNameA)
1646 windowNameA = (LPSTR)_smalloc(windowNameLength+1);
1647 memcpy(windowNameA, lpsz, windowNameLength+1);
1648 if(!windowNameW)
1649 windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
1650 lstrcpynAtoW(windowNameW, windowNameA, windowNameLength+1);
1651 }
1652
1653 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1654 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1655 {
1656 HandleNCPaint((HRGN)1);
1657 if(hTaskList) {
1658 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1659 }
1660 if(fOS2Look) {
1661 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1662 }
1663 }
1664
1665 return TRUE;
1666 }
1667
1668 case WM_SETREDRAW:
1669 {
1670 if (wParam)
1671 {
1672 setStyle(getStyle() | WS_VISIBLE);
1673 dprintf(("Enable window update for %x", getWindowHandle()));
1674 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
1675 }
1676 else
1677 {
1678 if (getStyle() & WS_VISIBLE)
1679 {
1680 setStyle(getStyle() & ~WS_VISIBLE);
1681 dprintf(("Disable window update for %x", getWindowHandle()));
1682 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
1683 }
1684 }
1685 return 0;
1686 }
1687
1688 case WM_CTLCOLORMSGBOX:
1689 case WM_CTLCOLOREDIT:
1690 case WM_CTLCOLORLISTBOX:
1691 case WM_CTLCOLORBTN:
1692 case WM_CTLCOLORDLG:
1693 case WM_CTLCOLORSTATIC:
1694 case WM_CTLCOLORSCROLLBAR:
1695 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1696
1697 case WM_CTLCOLOR:
1698 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1699
1700 case WM_VKEYTOITEM:
1701 case WM_CHARTOITEM:
1702 return -1;
1703
1704 case WM_PARENTNOTIFY:
1705 return 0;
1706
1707 case WM_MOUSEACTIVATE:
1708 {
1709 HWND hwnd = getWindowHandle();
1710
1711 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1712 if (::GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
1713 {
1714 LONG ret = ::SendMessageW( ::GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
1715 if (ret) return ret;
1716 }
1717
1718 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
1719 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
1720 }
1721
1722 case WM_ACTIVATE:
1723 /* The default action in Windows is to set the keyboard focus to
1724 * the window, if it's being activated and not minimized */
1725 if (LOWORD(wParam) != WA_INACTIVE) {
1726 if(!(getStyle() & WS_MINIMIZE))
1727 SetFocus(getWindowHandle());
1728 }
1729 return 0;
1730
1731 case WM_SETCURSOR:
1732 {
1733 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1734 if((getStyle() & WS_CHILD))
1735 {
1736 if(getParent()) {
1737 LRESULT rc = SendMessageA(getParent()->getWindowHandle(), WM_SETCURSOR, wParam, lParam);
1738 if(rc) return rc;
1739 }
1740 }
1741 if (wParam == getWindowHandle())
1742 {
1743 HCURSOR hCursor;
1744
1745 switch(LOWORD(lParam))
1746 {
1747 case HTCLIENT:
1748 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1749 break;
1750
1751 case HTLEFT:
1752 case HTRIGHT:
1753 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1754 break;
1755
1756 case HTTOP:
1757 case HTBOTTOM:
1758 hCursor = LoadCursorA(0,IDC_SIZENSA);
1759 break;
1760
1761 case HTTOPLEFT:
1762 case HTBOTTOMRIGHT:
1763 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1764 break;
1765
1766 case HTTOPRIGHT:
1767 case HTBOTTOMLEFT:
1768 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1769 break;
1770
1771 default:
1772 hCursor = LoadCursorA(0,IDC_ARROWA);
1773 break;
1774 }
1775
1776 if (hCursor)
1777 {
1778 SetCursor(hCursor);
1779 return 1;
1780 }
1781 else return 0;
1782 }
1783 else return 0;
1784 }
1785
1786 case WM_MOUSEMOVE:
1787 return 0;
1788
1789 case WM_MOUSEWHEEL:
1790 if (::GetWindowLongA( getWindowHandle(), GWL_STYLE ) & WS_CHILD)
1791 return ::SendMessageA( ::GetParent(getWindowHandle()), WM_MOUSEWHEEL, wParam, lParam );
1792 break;
1793
1794 case WM_WINDOWPOSCHANGED:
1795 {
1796 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1797 WPARAM wp = SIZE_RESTORED;
1798
1799 //According to Wine these are always sent, but experiments in Windows NT4, SP6
1800 //show otherwise
1801 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1802 {
1803 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1804 }
1805 //According to Wine these are always sent, but experiments in Windows NT4, SP6
1806 //show otherwise
1807 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1808 {
1809 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1810 else
1811 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1812
1813 SendMessageA(getWindowHandle(),WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1814 rectClient.bottom - rectClient.top));
1815 }
1816 return 0;
1817 }
1818 case WM_WINDOWPOSCHANGING:
1819 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1820
1821 case WM_ERASEBKGND:
1822 case WM_ICONERASEBKGND:
1823 {
1824 RECT rect;
1825 int rc;
1826
1827 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1828
1829 rc = GetClipBox( (HDC)wParam, &rect );
1830 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1831 {
1832 HBRUSH hBrush = windowClass->getBackgroundBrush();
1833
1834 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1835 hBrush = GetSysColorBrush(hBrush-1);
1836
1837 FillRect( (HDC)wParam, &rect, hBrush);
1838 }
1839 return 1;
1840 }
1841
1842 case WM_PRINT:
1843 return DefWndPrint(wParam,lParam);
1844
1845 case WM_SYNCPAINT:
1846 RedrawWindow(getWindowHandle(), NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN);
1847 return 0;
1848
1849 case WM_PAINTICON:
1850 case WM_PAINT:
1851 {
1852 PAINTSTRUCT ps;
1853 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1854 if( hdc )
1855 {
1856 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1857 {
1858 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1859 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1860 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1861 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1862 }
1863 EndPaint(getWindowHandle(), &ps );
1864 }
1865 return 0;
1866 }
1867
1868 case WM_GETDLGCODE:
1869 return 0;
1870
1871 case WM_NCPAINT:
1872 return HandleNCPaint((HRGN)wParam);
1873
1874 case WM_NCACTIVATE:
1875 return HandleNCActivate(wParam);
1876
1877 case WM_NCCREATE:
1878 return(TRUE);
1879
1880 case WM_NCDESTROY:
1881 return 0;
1882
1883 case WM_NCCALCSIZE:
1884 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1885
1886 case WM_NCLBUTTONDOWN:
1887 return HandleNCLButtonDown(wParam,lParam);
1888
1889 case WM_LBUTTONDBLCLK:
1890 case WM_NCLBUTTONDBLCLK:
1891 return HandleNCLButtonDblClk(wParam,lParam);
1892
1893 case WM_NCRBUTTONDOWN:
1894 case WM_NCRBUTTONDBLCLK:
1895 case WM_NCMBUTTONDOWN:
1896 case WM_NCMBUTTONDBLCLK:
1897 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1898 return 0;
1899
1900 case WM_NCRBUTTONUP:
1901 return HandleNCRButtonUp(wParam,lParam);
1902
1903 case WM_NCMBUTTONUP:
1904 return 0;
1905
1906 case WM_NCHITTEST:
1907 {
1908 POINT point;
1909 LRESULT retvalue;
1910
1911 point.x = (SHORT)LOWORD(lParam);
1912 point.y = (SHORT)HIWORD(lParam);
1913
1914 retvalue = HandleNCHitTest(point);
1915#if 0 //CB: let the Corel people fix the bugs first
1916 if(retvalue == HTMENU)
1917 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1918 else
1919 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1920#endif
1921 return retvalue;
1922 }
1923
1924 case WM_SYSCOMMAND:
1925 {
1926 POINT point;
1927
1928 point.x = LOWORD(lParam);
1929 point.y = HIWORD(lParam);
1930 return HandleSysCommand(wParam,&point);
1931 }
1932
1933 case WM_KEYDOWN:
1934 if(wParam == VK_F10) iF10Key = VK_F10;
1935 break;
1936
1937 case WM_SYSKEYDOWN:
1938 {
1939 if( HIWORD(lParam) & KEYDATA_ALT )
1940 {
1941 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
1942 if( wParam == VK_MENU && !iMenuSysKey )
1943 iMenuSysKey = 1;
1944 else
1945 iMenuSysKey = 0;
1946
1947 iF10Key = 0;
1948
1949 if( wParam == VK_F4 ) /* try to close the window */
1950 {
1951 HWND top = GetTopParent();
1952 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
1953 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
1954 }
1955
1956 //Default OS/2 app behaviour for system keys
1957 if(fOS2Look)
1958 {
1959 if( wParam == VK_F5 ) /* try to restore the window */
1960 {
1961 HWND top = GetTopParent();
1962 /* No checks needed SC_RESTORE handler does them */
1963 PostMessageW( top, WM_SYSCOMMAND, SC_RESTORE, 0 );
1964 }
1965
1966 if( wParam == VK_F7 ) /* size the window */
1967 {
1968 HWND top = GetTopParent();
1969 PostMessageW( top, WM_SYSCOMMAND, SC_MOVE, 0 );
1970 }
1971
1972 if( wParam == VK_F8 ) /* move the window */
1973 {
1974 HWND top = GetTopParent();
1975 if ( GetWindowLongA(top, GWL_STYLE) & WS_SIZEBOX)
1976 PostMessageW( top, WM_SYSCOMMAND, SC_SIZE, 0 );
1977 }
1978
1979 if( wParam == VK_F9 ) /* try to minimize the window */
1980 {
1981 HWND top = GetTopParent();
1982 if ( GetWindowLongA(top, GWL_STYLE) & WS_MINIMIZEBOX)
1983 PostMessageW( top, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
1984 }
1985
1986 if( wParam == VK_F10 ) /* try to maximize the window */
1987 {
1988 HWND top = GetTopParent();
1989 if ( GetWindowLongA(top, GWL_STYLE) & WS_MAXIMIZEBOX)
1990 PostMessageW( top, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );
1991 }
1992 }
1993
1994 }
1995 else if( wParam == VK_F10 )
1996 iF10Key = 1;
1997 else
1998 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
1999 SendMessageW(getWindowHandle(), WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
2000
2001 Win32BaseWindow *siblingWindow;
2002 HWND sibling;
2003 char nameBuffer [40], mnemonic;
2004 int nameLength;
2005
2006 GetWindowTextA (nameBuffer, 40);
2007
2008 // search all sibling to see it this key is their mnemonic
2009 sibling = GetWindow (GW_HWNDFIRST);
2010 while (sibling != 0) {
2011 siblingWindow = GetWindowFromHandle (sibling);
2012 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
2013
2014 // find the siblings mnemonic
2015 mnemonic = '\0';
2016 for (int i=0 ; i<nameLength ; i++) {
2017 if (IsDBCSLeadByte(nameBuffer[i])) {
2018 // Skip DBCS
2019 continue;
2020 }
2021 if (nameBuffer [i] == '&') {
2022 mnemonic = nameBuffer [i+1];
2023 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
2024 mnemonic -= 32; // make it uppercase
2025 break; // stop searching
2026 }
2027 }
2028
2029 // key matches siblings mnemonic, send mouseclick
2030 if (mnemonic == (char) wParam) {
2031 ::SendMessageA(siblingWindow->getWindowHandle(), BM_CLICK, 0, 0);
2032 }
2033 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
2034 RELEASE_WNDOBJ(siblingWindow);
2035 }
2036
2037 return 0;
2038 }
2039
2040 case WM_KEYUP:
2041 //Single Alt down + up always generates WM_SYSKEYUP
2042 iMenuSysKey = 0;
2043 // no break;
2044 case WM_SYSKEYUP:
2045 /* Press and release F10 or ALT */
2046 if (((wParam == VK_MENU) && iMenuSysKey) ||
2047 ((wParam == VK_F10) && iF10Key))
2048 ::SendMessageW( GetTopParent(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
2049 iMenuSysKey = iF10Key = 0;
2050 break;
2051
2052 case WM_SYSCHAR:
2053 {
2054 iMenuSysKey = 0;
2055 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
2056 {
2057 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
2058 (WPARAM)SC_RESTORE, 0L );
2059 break;
2060 }
2061 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
2062 {
2063 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
2064 break;
2065 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
2066 ::SendMessageW(GetParent(), Msg, wParam, lParam );
2067 }
2068 else ::SendMessageA(getWindowHandle(), WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
2069 }
2070#if 0
2071 else /* check for Ctrl-Esc */
2072 if (wParam != VK_ESCAPE) MessageBeep(0);
2073 break;
2074#endif
2075 }
2076
2077 case WM_SETHOTKEY:
2078 hotkey = wParam;
2079 return 1; //CB: always successful
2080
2081 case WM_GETHOTKEY:
2082 return hotkey;
2083
2084 case WM_RBUTTONUP:
2085 {
2086 POINT pt;
2087 pt.x = SLOWORD(lParam);
2088 pt.y = SHIWORD(lParam);
2089 ClientToScreen(getWindowHandle(), &pt);
2090 SendMessageA( getWindowHandle(), WM_CONTEXTMENU, getWindowHandle(),MAKELPARAM(pt.x, pt.y) );
2091 }
2092 break;
2093
2094 case WM_CONTEXTMENU:
2095 if ((dwStyle & WS_CHILD) && getParent())
2096 SendMessageA(getParent()->getWindowHandle(), WM_CONTEXTMENU,wParam,lParam);
2097 else
2098 {
2099 LONG hitcode;
2100 POINT pt;
2101 if (!GetSysMenu()) return 0;
2102 pt.x = SLOWORD(lParam);
2103 pt.y = SHIWORD(lParam);
2104 hitcode = HandleNCHitTest(pt);
2105
2106 /* Track system popup if click was in the caption area. */
2107 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
2108 TrackPopupMenu(GetSysMenu(),
2109 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
2110 pt.x, pt.y, 0, getWindowHandle(), NULL);
2111 }
2112 return 0;
2113
2114 case WM_SHOWWINDOW:
2115 if (!lParam) return 0; /* sent from ShowWindow */
2116 if (!(dwStyle & WS_POPUP) || !owner) return 0;
2117 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
2118 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
2119 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
2120 return 0;
2121
2122 case WM_CANCELMODE:
2123 if (getParent() == windowDesktop) EndMenu();
2124 if (GetCapture() == Win32Hwnd) ReleaseCapture();
2125 return 0;
2126
2127 case WM_DROPOBJECT:
2128 return DRAG_FILE;
2129
2130 case WM_QUERYDROPOBJECT:
2131 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
2132
2133 case WM_QUERYDRAGICON:
2134 {
2135 HICON hDragIcon = windowClass->getCursor();
2136 UINT len;
2137
2138 if(hDragIcon) return (LRESULT)hDragIcon;
2139 for(len = 1; len < 64; len++)
2140 {
2141 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
2142 if(hDragIcon)
2143 return (LRESULT)hDragIcon;
2144 }
2145 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
2146 }
2147
2148 case WM_QUERYOPEN:
2149 case WM_QUERYENDSESSION:
2150 return 1;
2151
2152 case WM_NOTIFYFORMAT:
2153 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
2154
2155 case WM_SETICON:
2156 case WM_GETICON:
2157 {
2158 LRESULT result = 0;
2159
2160 /* Set the appropriate icon members in the window structure. */
2161 if (wParam == ICON_SMALL)
2162 {
2163 result = hIconSm;
2164 if (Msg == WM_SETICON)
2165 hIconSm = (HICON)lParam;
2166 }
2167 else
2168 {
2169 result = hIcon;
2170 if (Msg == WM_SETICON)
2171 {
2172 hIcon = (HICON)lParam;
2173 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2174 OSLibWinSetIcon(OS2HwndFrame,hIcon);
2175 }
2176 }
2177 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
2178 HandleNCPaint((HRGN)1);
2179
2180 return result;
2181 }
2182
2183 case WM_HELP:
2184 if (getParent()) SendMessageA(getParent()->getWindowHandle(), Msg,wParam,lParam);
2185 break;
2186
2187 case WM_NOTIFY:
2188 return 0; //comctl32 controls expect this
2189
2190 default:
2191 return 0;
2192 }
2193 return 0;
2194}
2195//******************************************************************************
2196//******************************************************************************
2197LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
2198{
2199 switch(Msg)
2200 {
2201 case WM_GETTEXTLENGTH:
2202 return windowNameLength;
2203
2204 case WM_GETTEXT:
2205 if (!lParam || !wParam)
2206 return 0;
2207 if (!windowNameW)
2208 ((LPWSTR)lParam)[0] = 0;
2209 else
2210 memcpy((LPSTR)lParam, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), wParam) );
2211 return min(windowNameLength, wParam);
2212
2213 case WM_SETTEXT:
2214 {
2215 LPWSTR lpsz = (LPWSTR)lParam;
2216
2217 // reallocate if new buffer is larger
2218 if (!lParam)
2219 {
2220 free(windowNameA);
2221 free(windowNameW);
2222 windowNameLength = 0;
2223 windowNameA = NULL;
2224 windowNameW = NULL;
2225 }
2226 else
2227 {
2228 // determine length of new text
2229 int iTextLength = lstrlenW(lpsz);
2230
2231 if (windowNameLength < iTextLength)
2232 {
2233 if (windowNameA)
2234 {
2235 free(windowNameA);
2236 windowNameA = NULL;
2237 }
2238
2239 if (windowNameW)
2240 {
2241 free(windowNameW);
2242 windowNameW = NULL;
2243 }
2244 }
2245
2246 windowNameLength = iTextLength;
2247 if(!windowNameW)
2248 windowNameW = (LPWSTR)_smalloc((windowNameLength+1)*sizeof(WCHAR));
2249 memcpy(windowNameW, lpsz, (windowNameLength+1) * sizeof(WCHAR));
2250 if(!windowNameA)
2251 windowNameA = (LPSTR)_smalloc(windowNameLength+1);
2252 lstrcpynWtoA(windowNameA, windowNameW, windowNameLength+1);
2253 }
2254
2255 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
2256 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2257 {
2258 HandleNCPaint((HRGN)1);
2259 if(hTaskList) {
2260 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2261 }
2262 if(fOS2Look) {
2263 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
2264 }
2265 }
2266
2267 return TRUE;
2268 }
2269
2270 default:
2271 return DefWindowProcA(Msg, wParam, lParam);
2272 }
2273}
2274//******************************************************************************
2275//******************************************************************************
2276void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2277{
2278 Win32BaseWindow *window = this;
2279 Win32BaseWindow *parentwindow;
2280
2281 while(window)
2282 {
2283 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2284 {
2285 /* Notify the parent window only */
2286 parentwindow = window->getParent();
2287 if(parentwindow) {
2288 SendMessageA(parentwindow->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2289 }
2290 }
2291 else break;
2292
2293 window = parentwindow;
2294 }
2295}
2296//******************************************************************************
2297// Returns the big or small icon for the window, falling back to the
2298// class as windows does.
2299//******************************************************************************
2300HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2301{
2302 HICON hWndIcon;
2303
2304 if (fType == ICON_BIG)
2305 {
2306 if (hIcon)
2307 hWndIcon = hIcon;
2308 else
2309 if (windowClass && windowClass->getIcon())
2310 hWndIcon = windowClass->getIcon();
2311 else
2312 if (!(dwStyle & DS_MODALFRAME))
2313 {//SvL: load it as shared or else we'll leak icons
2314 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
2315 }
2316 else hWndIcon = 0;
2317 }
2318 else
2319 {
2320 if (hIconSm)
2321 hWndIcon = hIconSm;
2322 else
2323 if (hIcon)
2324 hWndIcon = hIcon;
2325 else
2326 if (windowClass && windowClass->getIconSm())
2327 hWndIcon = windowClass->getIconSm();
2328 else
2329 if (windowClass && windowClass->getIcon())
2330 hWndIcon = windowClass->getIcon();
2331 else
2332 if (!(dwStyle & DS_MODALFRAME))
2333 {//SvL: load it as shared or else we'll leak icons
2334 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
2335 }
2336 else hWndIcon = 0;
2337 }
2338
2339 return hWndIcon;
2340}
2341//******************************************************************************
2342//******************************************************************************
2343BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2344{
2345 ULONG swp = 0;
2346 HWND hWinAfter;
2347 BOOL rc,wasVisible,showFlag;
2348 RECT newPos = {0, 0, 0, 0};
2349
2350 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2351 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2352
2353 dwOldStyle = getStyle();
2354
2355 switch(nCmdShow)
2356 {
2357 case SW_HIDE:
2358 if (!wasVisible) goto END;
2359
2360 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2361 break;
2362
2363 case SW_SHOWMINNOACTIVE:
2364 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2365 /* fall through */
2366 case SW_SHOWMINIMIZED:
2367 swp |= SWP_SHOWWINDOW;
2368 /* fall through */
2369 case SW_MINIMIZE:
2370 swp |= SWP_FRAMECHANGED;
2371 if( !(getStyle() & WS_MINIMIZE) ) {
2372 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2373 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2374 }
2375 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2376 break;
2377
2378 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2379 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2380 if( !(getStyle() & WS_MAXIMIZE) ) {
2381 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2382 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2383 }
2384 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2385 break;
2386
2387 case SW_SHOWNA:
2388 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2389 /* fall through */
2390 case SW_SHOW:
2391 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2392
2393 /*
2394 * ShowWindow has a little peculiar behavior that if the
2395 * window is already the topmost window, it will not
2396 * activate it.
2397 */
2398 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2399 swp |= SWP_NOACTIVATE;
2400
2401 break;
2402
2403 case SW_SHOWNOACTIVATE:
2404 swp |= SWP_NOZORDER;
2405 if (GetActiveWindow())
2406 swp |= SWP_NOACTIVATE;
2407 /* fall through */
2408 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2409 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2410 case SW_RESTORE:
2411 dprintf(("ShowWindow:restoring window"));
2412
2413 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2414 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2415 swp |= MinMaximize(SW_RESTORE, &newPos );
2416 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2417 }
2418 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2419 break;
2420 }
2421
2422 showFlag = (nCmdShow != SW_HIDE);
2423 if (showFlag != wasVisible)
2424 {
2425 SendMessageA(getWindowHandle(),WM_SHOWWINDOW, showFlag, 0 );
2426 if (!::IsWindow( getWindowHandle() )) goto END;
2427 }
2428
2429 /* We can't activate a child window */
2430 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2431 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2432
2433 if (!(getStyle() & WS_MINIMIZE)) {
2434 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp), TRUE);
2435 }
2436 else OSLibWinMinimizeWindow(getOS2FrameWindowHandle());
2437
2438 if(!(swp & SWP_NOACTIVATE) && (!(getStyle() & WS_MINIMIZE))) {
2439 OSLibWinSetActiveWindow(OS2HwndFrame);
2440 }
2441
2442 if (flags & WIN_NEED_SIZE)
2443 {
2444 /* should happen only in CreateWindowEx() */
2445 int wParam = SIZE_RESTORED;
2446
2447 flags &= ~WIN_NEED_SIZE;
2448 if (dwStyle & WS_MAXIMIZE)
2449 wParam = SIZE_MAXIMIZED;
2450 else
2451 if (dwStyle & WS_MINIMIZE)
2452 wParam = SIZE_MINIMIZED;
2453
2454 SendMessageA(getWindowHandle(),WM_SIZE, wParam,
2455 MAKELONG(rectClient.right-rectClient.left,
2456 rectClient.bottom-rectClient.top));
2457 SendMessageA(getWindowHandle(),WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2458 }
2459//testestest
2460 //temporary workaround for file dialogs with template dialog child
2461 //they don't redraw when switching directories
2462 //For some reason the new child's (syslistview32) update rectangle stays
2463 //empty after its parent is made visible with ShowWindow
2464 //TODO: find real cause
2465 if(!wasVisible) {
2466 InvalidateRect(getWindowHandle(), NULL, TRUE);
2467 }
2468//testestest
2469
2470END:
2471 fMinMaxChange = FALSE;
2472 return wasVisible;
2473}
2474//******************************************************************************
2475//******************************************************************************
2476BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
2477 int cy, UINT fuFlags, BOOL fShowWindow)
2478{
2479 BOOL rc = FALSE;
2480 Win32BaseWindow *window;
2481 HWND hParent = 0;
2482 RECT oldClientRect = rectClient;
2483
2484 if (fuFlags &
2485 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2486 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2487 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2488 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2489 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS))
2490 {
2491 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2492 return FALSE;
2493 }
2494
2495 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS)) {
2496 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2497 }
2498
2499 if(IsWindowDestroyed()) {
2500 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2501 dprintf(("SetWindowPos; window already destroyed"));
2502 return TRUE;
2503 }
2504
2505#if 0
2506 /* Fix redundant flags */
2507 if(getStyle() & WS_VISIBLE) {
2508 fuFlags &= ~SWP_SHOWWINDOW;
2509 }
2510 else
2511 {
2512 if (!(fuFlags & SWP_SHOWWINDOW))
2513 fuFlags |= SWP_NOREDRAW;
2514 fuFlags &= ~SWP_HIDEWINDOW;
2515 }
2516
2517//// if(cx < 0) cx = 0;
2518//// if(cy < 0) cy = 0;
2519
2520 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2521 fuFlags |= SWP_NOSIZE; /* Already the right size */
2522 }
2523
2524 if((rectWindow.left == x) && (rectWindow.top == y)) {
2525 fuFlags |= SWP_NOMOVE; /* Already the right position */
2526 }
2527
2528 if(getWindowHandle() == GetActiveWindow()) {
2529 fuFlags |= SWP_NOACTIVATE; /* Already active */
2530 }
2531 else
2532 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2533 {
2534 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2535 {
2536 fuFlags &= ~SWP_NOZORDER;
2537 hwndInsertAfter = HWND_TOP;
2538 }
2539 }
2540 /* TODO: Check hwndInsertAfter */
2541#endif
2542
2543 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2544 if(state < STATE_POST_WMNCCREATE)
2545 {//don't change size; modify internal structures only
2546 //TODO: not 100% correct yet (activate)
2547 dprintf2(("state < STATE_POST_WMNCCREATE"));
2548 if(!(fuFlags & SWP_NOZORDER)) {
2549 hwndLinkAfter = hwndInsertAfter;
2550 }
2551 if(!(fuFlags & SWP_NOMOVE)) {
2552 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2553 rectWindow.top = y;
2554 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2555 rectWindow.left = x;
2556 }
2557 if(!(fuFlags & SWP_NOSIZE)) {
2558 rectWindow.bottom = rectWindow.top + cy;
2559 rectWindow.right = rectWindow.left + cx;
2560 }
2561 return TRUE;
2562 }
2563
2564 WINDOWPOS wpos;
2565 SWP swp, swpOld;
2566 wpos.flags = fuFlags;
2567 wpos.cy = cy;
2568 wpos.cx = cx;
2569 wpos.x = x;
2570 wpos.y = y;
2571 wpos.hwndInsertAfter = hwndInsertAfter;
2572 wpos.hwnd = getWindowHandle();
2573
2574 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2575 {
2576 if (isChild())
2577 {
2578 if(!getParent()) {
2579 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2580 }
2581 }
2582 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2583 }
2584 if((dwOldStyle & WS_MINIMIZE) && (getStyle() & WS_MINIMIZE))
2585 {//don't allow size changes if the window is minimized
2586 //we will update the restore position at the end of this method
2587 if(!(wpos.flags & SWP_NOSIZE)) {
2588 //TODO: updating the window rectangle doesn't look right
2589 wpos.flags |= SWP_NOSIZE;
2590 rectWindow.right = rectWindow.left + wpos.cx;
2591 rectWindow.bottom = rectWindow.top + wpos.cy;
2592 dprintf(("WARNING: Don't allow size change for minimized window; only save new restore position"));
2593 dprintf(("new window rectangle (%d,%d)(%d,%d)", rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2594 }
2595 }
2596
2597 if(getParent()) {
2598 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2599 OS2HwndFrame);
2600 }
2601 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2602
2603 if (swp.fl == 0) {
2604 dprintf2(("swp.fl == 0"));
2605 if(fuFlags & SWP_FRAMECHANGED)
2606 {
2607 NotifyFrameChanged(&wpos, &oldClientRect);
2608 }
2609 if(!fShowWindow && !(getStyle() & WS_MINIMIZE) && !(fuFlags & (SWP_NOSIZE | SWP_NOMOVE)))
2610 {
2611 //Restore position always changes when the window position is changed
2612 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2613 windowpos.rcNormalPosition = rectWindow;
2614 }
2615 return TRUE;
2616 }
2617
2618// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2619 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2620 {
2621 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2622 if(wndBehind) {
2623 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2624 RELEASE_WNDOBJ(wndBehind);
2625 }
2626 else {
2627 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2628 swp.hwndInsertBehind = 0;
2629 }
2630 }
2631 swp.hwnd = OS2HwndFrame;
2632
2633 //SvL: Must also deactivate the window when hiding it or else focus won't
2634 // change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
2635 if((swp.fl & (SWPOS_HIDE|SWPOS_DEACTIVATE)) == (SWPOS_HIDE|SWPOS_DEACTIVATE))
2636 {
2637 //we must make sure the owner is not disabled or else the focus will
2638 //be switched to the wrong window
2639 Win32BaseWindow *topOwner;
2640
2641 if(getOwner() == NULL) {
2642 windowDesktop->addRef();
2643 topOwner = windowDesktop;
2644 }
2645 else topOwner = GetWindowFromHandle(getOwner()->GetTopParent());
2646
2647 if(topOwner != NULL) {
2648 DWORD dwStyle = topOwner->GetWindowLong(GWL_STYLE, FALSE);
2649 if(dwStyle & WS_DISABLED) {
2650 swp.fl &= ~SWPOS_DEACTIVATE;
2651 }
2652 }
2653 else DebugInt3();
2654 }
2655
2656 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2657 setStyle(getStyle() | WS_VISIBLE);
2658 if(hTaskList) {
2659 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2660 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2661 }
2662 }
2663 else
2664 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2665 setStyle(getStyle() & ~WS_VISIBLE);
2666 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2667 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2668 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2669 }
2670 }
2671 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2672
2673 rc = OSLibWinSetMultWindowPos(&swp, 1);
2674 if(rc == FALSE)
2675 {
2676 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2677 return 0;
2678 }
2679
2680 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2681 {
2682 NotifyFrameChanged(&wpos, &oldClientRect);
2683 }
2684 if(!fShowWindow && !(getStyle() & WS_MINIMIZE))
2685 {
2686 //Restore position always changes when the window position is changed
2687 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2688 windowpos.rcNormalPosition = rectWindow;
2689 }
2690 //MSDN says the entire client area will be invalidated when SWP_NOCOPYBITS
2691 //is specified (fixes repaint issues when window is made smaller)
2692 if((fuFlags & (SWP_NOCOPYBITS|SWP_NOREDRAW)) == SWP_NOCOPYBITS) {
2693 InvalidateRect(getWindowHandle(), NULL, TRUE);
2694 }
2695 return (rc);
2696}
2697//******************************************************************************
2698//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2699//******************************************************************************
2700BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2701{
2702 rectWindow.left += dx;
2703 rectWindow.right += dx;
2704 rectWindow.top += dy;
2705 rectWindow.bottom += dy;
2706 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2707 return TRUE;
2708}
2709//******************************************************************************
2710//******************************************************************************
2711void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2712{
2713 HRGN hrgn, hrgnClient;
2714 RECT rect;
2715
2716 MsgFormatFrame(NULL);
2717
2718 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2719 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2720 {
2721 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2722 wpos->cx = RECT_WIDTH(rectWindow);
2723 wpos->cy = RECT_HEIGHT(rectWindow);
2724 }
2725
2726 if(rectClient.left != oldClientRect->left ||
2727 rectClient.top != oldClientRect->top)
2728 {
2729 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2730 wpos->x = rectWindow.left;
2731 wpos->y = rectWindow.top;
2732 }
2733
2734 WINDOWPOS wpOld = *wpos;
2735 if(!(wpos->flags & SWP_NOSENDCHANGING))
2736 SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2737
2738 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2739 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2740 {
2741 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2742 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2743 }
2744 else SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2745
2746 //Calculate invalid areas
2747 rect = rectWindow;
2748 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2749 hrgn = CreateRectRgnIndirect(&rect);
2750 if (!hrgn) {
2751 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2752 return;
2753 }
2754 rect = rectClient;
2755 hrgnClient = CreateRectRgnIndirect(&rect);
2756 if (!hrgn) {
2757 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2758 return;
2759 }
2760 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2761 DeleteObject(hrgnClient);
2762
2763 if(!EqualRect(oldClientRect, &rectClient)) {
2764 UnionRect(oldClientRect, oldClientRect, &rectClient);
2765 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2766 if (!hrgn) {
2767 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2768 return;
2769 }
2770 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2771 DeleteObject(hrgnClient);
2772 }
2773 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2774 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2775 DeleteObject(hrgn);
2776}
2777//******************************************************************************
2778//TODO: Check how this api really works in NT
2779//******************************************************************************
2780BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2781{
2782 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2783 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2784 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2785 windowpos.ptMinPosition = wndpl->ptMinPosition;
2786 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2787 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2788
2789 if(getStyle() & WS_MINIMIZE )
2790 {
2791 //TODO: Why can't this be (0,0)?
2792 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2793 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2794 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2795 }
2796 }
2797 else
2798 if(getStyle() & WS_MAXIMIZE )
2799 {
2800 //TODO: Why can't this be (0,0)?
2801 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2802 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2803 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2804 }
2805 else {
2806 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2807 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2808 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2809 SWP_NOZORDER | SWP_NOACTIVATE );
2810 }
2811 ShowWindow(wndpl->showCmd);
2812 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2813 {
2814 /* SDK: ...valid only the next time... */
2815 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2816 setFlags(getFlags() | WIN_RESTORE_MAX);
2817 }
2818 return TRUE;
2819}
2820//******************************************************************************
2821//******************************************************************************
2822BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2823{
2824 wndpl->length = sizeof(*wndpl);
2825 if(getStyle() & WS_MINIMIZE )
2826 wndpl->showCmd = SW_SHOWMINIMIZED;
2827 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2828
2829 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2830 if(getFlags() & WIN_RESTORE_MAX )
2831 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2832 else wndpl->flags = 0;
2833
2834 wndpl->ptMinPosition = windowpos.ptMinPosition;
2835 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2836 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2837 wndpl->rcNormalPosition = windowpos.rcNormalPosition;
2838
2839 return TRUE;
2840}
2841//******************************************************************************
2842//Also destroys all the child windows (destroy children first, parent last)
2843//TODO: Don't rely on PM to do the right thing. Send WM_(NC)DESTROY &
2844// destroy children ourselves (see Wine)
2845//******************************************************************************
2846BOOL Win32BaseWindow::DestroyWindow()
2847{
2848 HWND hwnd = getWindowHandle();
2849
2850 dprintf(("DestroyWindow %x", hwnd));
2851
2852#if 0
2853 /* Look whether the focus is within the tree of windows we will
2854 * be destroying.
2855 */
2856 HWND hwndFocus = GetFocus();
2857 if (hwndFocus == hwnd || ::IsChild( hwnd, hwndFocus ))
2858 {
2859 HWND parent = GetAncestor( hwnd, GA_PARENT );
2860 if (parent == GetDesktopWindow()) parent = 0;
2861 SetFocus( parent );
2862 }
2863#endif
2864 /* Call hooks */
2865 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2866 {
2867 return FALSE;
2868 }
2869
2870 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2871 {
2872 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2873 /* FIXME: clean up palette - see "Internals" p.352 */
2874 }
2875
2876 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2877 {
2878 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2879 {
2880 /* Notify the parent window only */
2881 SendMessageA(getParent()->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2882 if(!::IsWindow(hwnd) )
2883 {
2884 return TRUE;
2885 }
2886 }
2887//// else DebugInt3();
2888 }
2889 /* Hide the window */
2890 if(IsWindowVisible(getWindowHandle()))
2891 {
2892 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2893 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2894 if(!::IsWindow(hwnd))
2895 {
2896 return TRUE;
2897 }
2898 }
2899 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2900
2901 // check the handle for the last active popup window
2902 Win32BaseWindow* owner = getOwner();
2903 if (NULL != owner)
2904 {
2905 if (owner->getLastActive() == hwnd)
2906 owner->setLastActive( owner->getWindowHandle() );
2907
2908 //SvL: Not sure this is correct, but it solves the problem of reassigning
2909 // activation. A disabled window will never be activated ->
2910 // possible that the wrong window is chosen by PM.
2911 // PM chooses another window to be activated before WM_DESTROY is
2912 // sent. VPC enables the owner when it receives that message,
2913 // but by then it's too late.
2914 // (MFC created modeless dialog)
2915 //TODO: This might be the wrong place to do it. EndDialog is called,
2916 // so perhaps it should be done there. (although Wine only
2917 // enables the owner if the dialog is modal)
2918 ::EnableWindow(owner->getWindowHandle(), 1);
2919 }
2920
2921 fDestroyWindowCalled = TRUE;
2922
2923//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2924// handler; must postpone it
2925 if(fChildDestructionInProgress) {
2926 dprintf(("Postponing parent destruction because of dying child"));
2927 OSLibPostMessageDirect(OS2HwndFrame, WIN32APP_POSTPONEDESTROY, 0, 0);
2928 return TRUE;
2929 }
2930
2931 BOOL fOldChildDestructionInProgress = FALSE;
2932 if(GetParent()) {
2933 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2934 if(window) {
2935 fOldChildDestructionInProgress = window->IsChildDestructionInProgress();
2936 window->SetChildDestructionInProgress(TRUE);
2937 RELEASE_WNDOBJ(window);
2938 }
2939 }
2940//hack end
2941
2942 BOOL ret = OSLibWinDestroyWindow(OS2HwndFrame);
2943
2944//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2945// handler; must postpone it
2946 if(GetParent()) {
2947 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2948 if(window) {
2949 window->SetChildDestructionInProgress(fOldChildDestructionInProgress);
2950 RELEASE_WNDOBJ(window);
2951 }
2952 }
2953//hack end
2954 return ret;
2955}
2956//******************************************************************************
2957//******************************************************************************
2958Win32BaseWindow *Win32BaseWindow::getParent()
2959{
2960 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2961 //experiment
2962#if 0
2963 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2964#else
2965 return wndparent;
2966#endif
2967}
2968//******************************************************************************
2969//Note: does not set last error if no parent (verified in NT4, SP6)
2970//******************************************************************************
2971HWND Win32BaseWindow::GetParent()
2972{
2973 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2974
2975 if(getStyle() & WS_CHILD)
2976 {
2977 if(wndparent) {
2978 return wndparent->getWindowHandle();
2979 }
2980 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2981 DebugInt3();
2982 return 0;
2983 }
2984 else
2985 if(getStyle() & WS_POPUP)
2986 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2987 else return 0;
2988}
2989//******************************************************************************
2990//******************************************************************************
2991HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2992{
2993 HWND oldhwnd;
2994 Win32BaseWindow *newparent;
2995 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2996 BOOL fShow = FALSE;
2997
2998 if(oldparent) {
2999 oldhwnd = oldparent->getWindowHandle();
3000 oldparent->removeChild(this);
3001 }
3002 else oldhwnd = 0;
3003
3004 /* Windows hides the window first, then shows it again
3005 * including the WM_SHOWWINDOW messages and all */
3006 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
3007 ShowWindow(SW_HIDE);
3008 fShow = TRUE;
3009 }
3010 if(oldparent) {
3011 //release parent here (increased refcount during creation)
3012 RELEASE_WNDOBJ(oldparent);
3013 }
3014 newparent = GetWindowFromHandle(hwndNewParent);
3015 if(newparent && !newparent->isDesktopWindow())
3016 {
3017 setParent(newparent);
3018 getParent()->addChild(this);
3019 fParentChange = TRUE;
3020 // in case we haven't finished creating the window whose parent we're
3021 // setting here, the OS/2 HWND might not exist yet and we call the PM
3022 // API with a NULLHANDLE - no problem
3023 // when we create the OS/2 window lateron, we will create it with the
3024 // right parent anyway.
3025 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
3026 if(!(getStyle() & WS_CHILD))
3027 {
3028 if(getWindowId())
3029 {
3030 DestroyMenu( (HMENU) getWindowId() );
3031 setWindowId(0);
3032 }
3033 }
3034 //SvL: Even though the win32 coordinates might not change, the PM
3035 // coordinates can. We must make sure the control stays at the
3036 // same position (y) relative to the (new) parent.
3037 // TODO: shouldn't we check the state of the window and not do it in INIT state?
3038 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
3039 SWP_NOACTIVATE|SWP_NOSIZE);
3040 fParentChange = FALSE;
3041 }
3042 else {
3043 if(newparent) RELEASE_WNDOBJ(newparent);
3044
3045 setParent(windowDesktop);
3046 windowDesktop->addRef();
3047 windowDesktop->addChild(this);
3048 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
3049
3050 //Do not change the window id!
3051//// setWindowId(0);
3052 }
3053 /* SetParent additionally needs to make hwndChild the topmost window
3054 in the x-order and send the expected WM_WINDOWPOSCHANGING and
3055 WM_WINDOWPOSCHANGED notification messages.
3056 */
3057 if(state >= STATE_PRE_WMNCCREATE) {
3058 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
3059 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
3060
3061 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
3062 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
3063 }
3064 return oldhwnd;
3065}
3066//******************************************************************************
3067//******************************************************************************
3068BOOL Win32BaseWindow::IsChild(HWND hwndParent)
3069{
3070 // PH: Optimizer won't unroll calls to getParent() even
3071 // in release build.
3072 Win32BaseWindow *_parent = getParent();
3073
3074 if(_parent)
3075 {
3076 if(_parent->getWindowHandle() == hwndParent)
3077 return TRUE;
3078
3079 return _parent->IsChild(hwndParent);
3080 }
3081 else
3082 return 0;
3083}
3084//******************************************************************************
3085//******************************************************************************
3086HWND Win32BaseWindow::GetTopWindow()
3087{
3088 HWND hwndTop;
3089 Win32BaseWindow *topwindow;
3090
3091 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3092 if(!isDesktopWindow())
3093 {
3094 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3095 //Note: GetTopWindow can't return a window that hasn't processed
3096 // WM_NCCREATE yet (verified in NT4, SP6)
3097 if(topwindow) {
3098 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3099 hwndTop = topwindow->getWindowHandle();
3100 }
3101 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3102 RELEASE_WNDOBJ(topwindow);
3103 return hwndTop;
3104 }
3105 if(topwindow) RELEASE_WNDOBJ(topwindow);
3106 return 0;
3107 }
3108 while(hwndTop) {
3109 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3110 //Note: GetTopWindow can't return a window that hasn't processed
3111 // WM_NCCREATE yet (verified in NT4, SP6)
3112 if(topwindow) {
3113 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3114 hwndTop = topwindow->getWindowHandle();
3115 }
3116 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3117 RELEASE_WNDOBJ(topwindow);
3118 return hwndTop;
3119 }
3120 if(topwindow) RELEASE_WNDOBJ(topwindow);
3121 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
3122 }
3123
3124 return 0;
3125}
3126//******************************************************************************
3127// Get the top-level parent for a child window.
3128//******************************************************************************
3129HWND Win32BaseWindow::GetTopParent()
3130{
3131 Win32BaseWindow *window = this;
3132 HWND hwndTopParent = 0;
3133
3134 lock();
3135 while(window && (window->getStyle() & WS_CHILD))
3136 {
3137 window = window->getParent();
3138 }
3139 if(window) {
3140 hwndTopParent = window->getWindowHandle();
3141 }
3142 unlock();
3143 return hwndTopParent;
3144}
3145//******************************************************************************
3146//TODO: Should not enumerate children that are created during the enumeration!
3147//TODO: Do this more efficiently
3148//******************************************************************************
3149BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
3150{
3151 BOOL rc = TRUE;
3152 HWND hwnd;
3153 Win32BaseWindow *prevchild = 0, *child = 0;
3154
3155 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3156 lock();
3157 for (child = (Win32BaseWindow *)getFirstChild(); child != NULL; child = (Win32BaseWindow *)child->getNextChild())
3158 {
3159 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3160 hwnd = child->getWindowHandle();
3161 if(child->IsWindowDestroyed() || child->getOwner()) {
3162 continue; //shouldn't have an owner (Wine)
3163 }
3164 child->addRef();
3165 unlock();
3166 if(lpfn(hwnd, lParam) == FALSE)
3167 {
3168 child->release();
3169 return FALSE;
3170 }
3171 child->release();
3172 lock();
3173 //check if the window still exists
3174 if(!::IsWindow(hwnd))
3175 {
3176 child = prevchild;
3177 if(child == NULL) break;
3178 continue;
3179 }
3180 if(child->getFirstChild() != NULL)
3181 {
3182 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3183 child->addRef();
3184 unlock();
3185 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3186 {
3187 child->release();
3188 return FALSE;
3189 }
3190 child->release();
3191 lock();
3192 }
3193 prevchild = child;
3194 }
3195 unlock();
3196 return rc;
3197}
3198//******************************************************************************
3199//Enumerate first-level children only and check thread id
3200//NOTE: NT4 returns first-level children in Z-order!
3201//******************************************************************************
3202BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3203{
3204 Win32BaseWindow *wnd = NULL;
3205 HWND henum, hwnd, hwndWin32;
3206 ULONG tid, pid;
3207 BOOL rc;
3208
3209 //Enumerate all top-level windows and check the process and thread ids
3210 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3211 hwnd = OSLibWinGetNextWindow(henum);
3212
3213 while(hwnd)
3214 {
3215 wnd = GetWindowFromOS2FrameHandle(hwnd);
3216 if(wnd == NULL) {
3217 hwnd = OSLibWinQueryClientWindow(hwnd);
3218 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3219 }
3220 if(wnd) {
3221 hwndWin32 = wnd->getWindowHandle();
3222 }
3223 else hwndWin32 = 0;
3224
3225 if(wnd) RELEASE_WNDOBJ(wnd);
3226
3227 if(hwndWin32) {
3228 OSLibWinQueryWindowProcess(hwnd, &pid, &tid);
3229
3230 if(dwThreadId == tid) {
3231 dprintf(("EnumThreadWindows: Found Window %x", hwndWin32));
3232 if((rc = lpfn(hwndWin32, lParam)) == FALSE) {
3233 break;
3234 }
3235 }
3236 }
3237 hwnd = OSLibWinGetNextWindow(henum);
3238 }
3239 OSLibWinEndEnumWindows(henum);
3240 return TRUE;
3241}
3242//******************************************************************************
3243//Enumerate first-level children only
3244//******************************************************************************
3245BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3246{
3247 Win32BaseWindow *window;
3248 BOOL rc;
3249 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
3250 DWORD dwStyle;
3251
3252 dprintf(("EnumWindows %x %x", lpfn, lParam));
3253
3254 for(int i=0;i<MAX_WINDOW_HANDLES;i++)
3255 {
3256 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3257 if(window) {
3258 if(window->getWindowHandle() != hwnd) {
3259 dprintf(("CORRUPT WINDOW %x %x", window, hwnd));
3260 }
3261 RELEASE_WNDOBJ(window);
3262 dwStyle = ::GetWindowLongA(hwnd, GWL_STYLE);
3263 if ((dwStyle & WS_POPUP) || ((dwStyle & WS_CAPTION) == WS_CAPTION))
3264 {
3265 dprintf2(("EnumWindows: Found Window %x", hwnd));
3266 if((rc = lpfn(hwnd, lParam)) == FALSE) {
3267 break;
3268 }
3269 }
3270 }
3271 hwnd++;
3272 }
3273 return TRUE;
3274}
3275//******************************************************************************
3276//******************************************************************************
3277HWND Win32BaseWindow::FindWindowById(int id)
3278{
3279 HWND hwnd;
3280
3281 lock();
3282 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3283 {
3284 if (child->getWindowId() == id)
3285 {
3286 hwnd = child->getWindowHandle();
3287 unlock();
3288 return hwnd;
3289 }
3290 }
3291 unlock();
3292 return 0;
3293}
3294//******************************************************************************
3295//TODO:
3296//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3297//the current process owns them.
3298//******************************************************************************
3299HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3300{
3301 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3302 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3303 Win32BaseWindow *firstchild = child;
3304
3305 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3306 if((hwndParent != 0 && !parent) ||
3307 (hwndChildAfter != 0 && !child) ||
3308 (hwndParent == 0 && hwndChildAfter != 0))
3309 {
3310 if(parent) RELEASE_WNDOBJ(parent);
3311 if(firstchild) RELEASE_WNDOBJ(firstchild);
3312 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3313 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3314 return 0;
3315 }
3316 SetLastError(0);
3317 if(hwndParent != 0)
3318 {//if the current process owns the window, just do a quick search
3319 lock(&critsect);
3320 child = (Win32BaseWindow *)parent->getFirstChild();
3321 if(hwndChildAfter != 0)
3322 {
3323 while(child)
3324 {
3325 if(child->getWindowHandle() == hwndChildAfter)
3326 {
3327 child = (Win32BaseWindow *)child->getNextChild();
3328 break;
3329 }
3330 child = (Win32BaseWindow *)child->getNextChild();
3331 }
3332 }
3333 while(child)
3334 {
3335 //According to Wine, the class doesn't need to be specified
3336 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3337 (!lpszWindow || child->hasWindowName(lpszWindow)))
3338 {
3339 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3340 HWND hwndChild = child->getWindowHandle();
3341 unlock(&critsect);
3342 if(parent) RELEASE_WNDOBJ(parent);
3343 if(firstchild) RELEASE_WNDOBJ(firstchild);
3344 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3345 return hwndChild;
3346 }
3347 child = (Win32BaseWindow *)child->getNextChild();
3348 }
3349 unlock(&critsect);
3350 if(parent) RELEASE_WNDOBJ(parent);
3351 if(firstchild) RELEASE_WNDOBJ(firstchild);
3352 }
3353 else {
3354 Win32BaseWindow *wnd;
3355 HWND henum, hwnd;
3356
3357 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3358 hwnd = OSLibWinGetNextWindow(henum);
3359
3360 while(hwnd)
3361 {
3362 wnd = GetWindowFromOS2FrameHandle(hwnd);
3363 if(wnd == NULL) {
3364 hwnd = OSLibWinQueryClientWindow(hwnd);
3365 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3366 }
3367
3368 if(wnd) {
3369 //According to Wine, the class doesn't need to be specified
3370 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3371 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3372 {
3373 OSLibWinEndEnumWindows(henum);
3374 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3375 HWND hwndret = wnd->getWindowHandle();
3376 RELEASE_WNDOBJ(wnd);
3377 return hwndret;
3378 }
3379 RELEASE_WNDOBJ(wnd);
3380 }
3381 hwnd = OSLibWinGetNextWindow(henum);
3382 }
3383 OSLibWinEndEnumWindows(henum);
3384 if(parent) RELEASE_WNDOBJ(parent);
3385 if(firstchild) RELEASE_WNDOBJ(firstchild);
3386 }
3387 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3388 return 0;
3389}
3390//******************************************************************************
3391//******************************************************************************
3392HWND Win32BaseWindow::GetWindow(UINT uCmd)
3393{
3394 HWND hwndRelated = 0;
3395 Win32BaseWindow *window;
3396
3397 switch(uCmd)
3398 {
3399 case GW_HWNDFIRST:
3400 window = (Win32BaseWindow *)getParent();
3401 if(window)
3402 {
3403 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3404 window = GetWindowFromOS2FrameHandle(hwndRelated);
3405 if(window) {
3406 hwndRelated = window->getWindowHandle();
3407 RELEASE_WNDOBJ(window);
3408 }
3409 else hwndRelated = 0;
3410 }
3411 else {
3412 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3413 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3414 }
3415 break;
3416
3417 case GW_HWNDLAST:
3418 window = (Win32BaseWindow *)getParent();
3419 if(window) {
3420 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3421 dprintf(("os2 handle %x", hwndRelated));
3422 window = GetWindowFromOS2FrameHandle(hwndRelated);
3423 if(window) {
3424 hwndRelated = window->getWindowHandle();
3425 RELEASE_WNDOBJ(window);
3426 }
3427 else hwndRelated = 0;
3428 }
3429 else {
3430 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3431 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3432 }
3433 break;
3434
3435 case GW_HWNDNEXT:
3436 if(getParent()) {
3437 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3438 window = GetWindowFromOS2FrameHandle(hwndRelated);
3439 if(window) {
3440 hwndRelated = window->getWindowHandle();
3441 RELEASE_WNDOBJ(window);
3442 }
3443 else hwndRelated = 0;
3444 }
3445 else {
3446 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3447 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3448 }
3449 break;
3450
3451 case GW_HWNDPREV:
3452 if(getParent()) {
3453 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3454 window = GetWindowFromOS2FrameHandle(hwndRelated);
3455 if(window) {
3456 hwndRelated = window->getWindowHandle();
3457 RELEASE_WNDOBJ(window);
3458 }
3459 else hwndRelated = 0;
3460 }
3461 else {
3462 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3463 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3464 }
3465 break;
3466
3467 case GW_OWNER:
3468 {
3469 Win32BaseWindow *owner = getOwner();
3470 if(owner) {
3471 hwndRelated = owner->getWindowHandle();
3472 }
3473 break;
3474 }
3475
3476 case GW_CHILD:
3477 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3478 window = GetWindowFromOS2FrameHandle(hwndRelated);
3479
3480 //Before a window has processed WM_NCCREATE:
3481 //- GetWindow(parent, GW_CHILD) can't return that window handle
3482 //(verified in NT4, SP6)
3483 if(window) {
3484 if(window->state >= STATE_POST_WMNCCREATE) {
3485 hwndRelated = window->getWindowHandle();
3486 RELEASE_WNDOBJ(window);
3487 }
3488 else {
3489 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3490 RELEASE_WNDOBJ(window);
3491 }
3492 }
3493 else hwndRelated = 0;
3494
3495 break;
3496
3497 //for internal use only
3498 case GW_HWNDNEXTCHILD:
3499 lock();
3500 window = (Win32BaseWindow *)getNextChild();
3501 if(window) {
3502 hwndRelated = window->getWindowHandle();
3503 }
3504 else hwndRelated = 0;
3505 unlock();
3506 break;
3507
3508 case GW_HWNDPREVCHILD:
3509 DebugInt3();
3510 break;
3511
3512 case GW_HWNDFIRSTCHILD:
3513 lock();
3514 window = (Win32BaseWindow *)getFirstChild();
3515 if(window) {
3516 hwndRelated = window->getWindowHandle();
3517 }
3518 else hwndRelated = 0;
3519 unlock();
3520 break;
3521
3522 case GW_HWNDLASTCHILD:
3523 lock();
3524 window = (Win32BaseWindow *)getFirstChild();
3525 if(window) {
3526 while (window->getNextChild())
3527 {
3528 window = (Win32BaseWindow *)window->getNextChild();
3529 }
3530 hwndRelated = window->getWindowHandle();
3531 }
3532 else hwndRelated = 0;
3533 unlock();
3534 break;
3535 }
3536end:
3537 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3538 return hwndRelated;
3539}
3540//******************************************************************************
3541//******************************************************************************
3542PRECT Win32BaseWindow::getWindowRect()
3543{
3544 return &rectWindow;
3545}
3546//******************************************************************************
3547//******************************************************************************
3548HWND Win32BaseWindow::SetActiveWindow()
3549{
3550 HWND hwndActive;
3551
3552 dprintf(("SetActiveWindow %x", getWindowHandle()));
3553 if(getStyle() & WS_CHILD) {
3554// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3555 dprintf(("WARNING: Window is a child or disabled"));
3556 return 0;
3557 }
3558
3559 if(GetActiveWindow() == getWindowHandle()) {
3560 dprintf(("Window already active"));
3561 return getWindowHandle();
3562 }
3563 if (HOOK_IsHooked( WH_CBT ))
3564 {
3565 CBTACTIVATESTRUCT cbta;
3566 LRESULT ret;
3567
3568 cbta.fMouse = FALSE;
3569 cbta.hWndActive = GetActiveWindow();
3570 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3571 if(ret)
3572 {
3573 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3574 return cbta.hWndActive;
3575 }
3576 }
3577 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3578
3579// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3580// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3581// }
3582 hwndActive = GetActiveWindow();
3583 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3584}
3585//******************************************************************************
3586//Used to change active status of an mdi window
3587//******************************************************************************
3588BOOL Win32BaseWindow::DeactivateChildWindow()
3589{
3590 /* child windows get a WM_CHILDACTIVATE message */
3591 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3592 {
3593 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3594 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3595 return TRUE;
3596 }
3597 DebugInt3(); //should not be called for non-child window
3598 return FALSE;
3599}
3600//******************************************************************************
3601//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3602//******************************************************************************
3603BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3604{
3605 BOOL rc;
3606
3607 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3608 //return true if previous state was disabled, else false (sdk docs)
3609 rc = (getStyle() & WS_DISABLED) != 0;
3610 if(rc && !fEnable) {
3611 SendMessageA(getWindowHandle(), WM_CANCELMODE, 0, 0);
3612 }
3613 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3614 if(fEnable == FALSE) {
3615 //SvL: No need to clear focus as PM already does this
3616 if(getWindowHandle() == GetCapture()) {
3617 ReleaseCapture(); /* A disabled window can't capture the mouse */
3618 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3619 }
3620 }
3621 return rc;
3622}
3623//******************************************************************************
3624//******************************************************************************
3625BOOL Win32BaseWindow::CloseWindow()
3626{
3627 if (::GetWindowLongW( getWindowHandle() , GWL_STYLE ) & WS_CHILD) return FALSE;
3628 ShowWindow( SW_MINIMIZE );
3629 return TRUE;
3630}
3631//******************************************************************************
3632//TODO: Not be 100% correct; should return active window of current thread
3633// or NULL when there is none -> WinQueryActiveWindow just returns
3634// the current active window
3635//******************************************************************************
3636HWND Win32BaseWindow::GetActiveWindow()
3637{
3638 HWND hwndActive;
3639
3640 hwndActive = OSLibWinQueryActiveWindow();
3641 return OS2ToWin32Handle(hwndActive);
3642}
3643//******************************************************************************
3644//******************************************************************************
3645BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3646{
3647 INT len = GetWindowTextLength(fUnicode);
3648 BOOL res;
3649
3650 if (wndname == NULL)
3651 return (len == 0);
3652
3653 len++;
3654 if (fUnicode)
3655 {
3656 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3657
3658 GetWindowTextW(text,len);
3659 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3660 free(text);
3661 }
3662 else
3663 {
3664 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3665
3666 GetWindowTextA(text,len);
3667 res = (strcmp(text,wndname) == 0);
3668 free(text);
3669 }
3670
3671 return res;
3672}
3673//******************************************************************************
3674//******************************************************************************
3675CHAR *Win32BaseWindow::getWindowNamePtrA()
3676{
3677 INT len = GetWindowTextLength(FALSE);
3678 CHAR *text;
3679
3680 if (len == 0) return NULL;
3681 len++;
3682 text = (CHAR*)malloc(len*sizeof(CHAR));
3683 GetWindowTextA(text,len);
3684
3685 return text;
3686}
3687//******************************************************************************
3688//******************************************************************************
3689WCHAR *Win32BaseWindow::getWindowNamePtrW()
3690{
3691 INT len = GetWindowTextLength(TRUE);
3692 WCHAR *text;
3693
3694 if (len == 0) return NULL;
3695 len++;
3696 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3697 GetWindowTextW(text,len);
3698
3699 return text;
3700}
3701//******************************************************************************
3702//******************************************************************************
3703VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3704{
3705 if (namePtr) free(namePtr);
3706}
3707//******************************************************************************
3708//When using this API for a window that was created by a different process, NT
3709//does NOT send WM_GETTEXTLENGTH.
3710//******************************************************************************
3711int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3712{
3713 //if the destination window is created by this process, send message
3714 if(dwProcessId == currentProcessId)
3715 {
3716 if(fUnicode) {
3717 return SendMessageW(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3718 }
3719 else return SendMessageA(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3720 }
3721 //else get data directory from window structure
3722 //TODO: must lock window structure.... (TODO)
3723 return windowNameLength;
3724}
3725//******************************************************************************
3726//When using this API for a window that was created by a different process, NT
3727//does NOT send WM_GETTEXT.
3728//******************************************************************************
3729int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3730{
3731 //if the destination window is created by this process, send message
3732 if(dwProcessId == currentProcessId) {
3733 return SendMessageA(getWindowHandle(),WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3734 }
3735
3736 //else get data directory from window structure
3737 if (!lpsz || !cch) return 0;
3738 if (!windowNameA) lpsz[0] = 0;
3739 else memcpy(lpsz, windowNameA, min(windowNameLength + 1, cch) );
3740 return min(windowNameLength, cch);
3741}
3742//******************************************************************************
3743//When using this API for a window that was created by a different process, NT
3744//does NOT send WM_GETTEXT.
3745//******************************************************************************
3746int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3747{
3748 //if the destination window is created by this process, send message
3749 if(dwProcessId == currentProcessId) {
3750 return ::SendMessageW(getWindowHandle(), WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3751 }
3752 //else get data directory from window structure
3753 if (!lpsz || !cch)
3754 return 0;
3755 if (!windowNameW)
3756 lpsz[0] = 0;
3757 else
3758 memcpy(lpsz, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), cch));
3759
3760 return min(windowNameLength, cch);
3761}
3762//******************************************************************************
3763//TODO: How does this work when the target window belongs to a different process???
3764//******************************************************************************
3765BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3766{
3767 return SendMessageA(getWindowHandle(),WM_SETTEXT,0,(LPARAM)lpsz);
3768}
3769//******************************************************************************
3770//******************************************************************************
3771BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3772{
3773 return SendMessageW(getWindowHandle(), WM_SETTEXT,0,(LPARAM)lpsz);
3774}
3775//******************************************************************************
3776//******************************************************************************
3777LONG Win32BaseWindow::SetWindowLong(int index, ULONG value, BOOL fUnicode)
3778{
3779 LONG oldval;
3780
3781 switch(index) {
3782 case GWL_EXSTYLE:
3783 {
3784 STYLESTRUCT ss;
3785
3786 if(dwExStyle == value) {
3787 oldval = value;
3788 break;
3789 }
3790 ss.styleOld = dwExStyle;
3791 ss.styleNew = value;
3792 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3793 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3794 setExStyle(ss.styleNew);
3795 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3796
3797 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3798 getStyle(), getExStyle(),ss.styleOld);
3799
3800 oldval = ss.styleOld;
3801 break;
3802 }
3803 case GWL_STYLE:
3804 {
3805 STYLESTRUCT ss;
3806
3807 //SvL: TODO: Can you change minimize or maximize status here too?
3808
3809 if(dwStyle == value) {
3810 oldval = value;
3811 break;
3812 }
3813 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3814
3815 //Changing WS_CHILD style is allowed
3816 ss.styleOld = getStyle();
3817 ss.styleNew = value;
3818 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3819 setStyle(ss.styleNew);
3820 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3821
3822 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3823 getStyle(), getExStyle(),ss.styleOld);
3824
3825 //TODO: Might not be correct to use ShowWindow here
3826 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3827 if(ss.styleNew & WS_VISIBLE)
3828 ShowWindow(SW_SHOWNOACTIVATE);
3829 else ShowWindow(SW_HIDE);
3830 }
3831
3832#ifdef DEBUG
3833 PrintWindowStyle(ss.styleNew, 0);
3834#endif
3835 oldval = ss.styleOld;
3836 break;
3837 }
3838 case GWL_WNDPROC:
3839 {
3840 //Note: Type of SetWindowLong determines new window proc type
3841 // UNLESS the new window proc has already been registered
3842 // (use the old type in that case)
3843 // (VERIFIED in NT 4, SP6)
3844 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3845 if(type == WIN_PROC_INVALID) {
3846 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3847 }
3848 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3849 dprintf(("SetWindowLong%c GWL_WNDPROC %x old %x new wndproc %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), oldval, value));
3850 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3851 break;
3852 }
3853 case GWL_HINSTANCE:
3854 oldval = hInstance;
3855 hInstance = value;
3856 break;
3857
3858 case GWL_HWNDPARENT:
3859 dprintf(("GWL_ID GWL_HWNDPARENT %x, new %x", GetParent(), value));
3860 oldval = SetParent((HWND)value);
3861 break;
3862
3863 case GWL_ID:
3864 dprintf(("GWL_ID old %x, new %x", getWindowId(), value));
3865 oldval = getWindowId();
3866 setWindowId(value);
3867 break;
3868
3869 case GWL_USERDATA:
3870 oldval = userData;
3871 userData = value;
3872 break;
3873
3874 default:
3875 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3876 {
3877 oldval = *(ULONG *)(userWindowBytes + index);
3878 *(ULONG *)(userWindowBytes + index) = value;
3879 break;
3880 }
3881 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3882 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3883 return 0;
3884 }
3885 //Note: NT4, SP6 does not set the last error to 0
3886 SetLastError(ERROR_SUCCESS);
3887 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3888 return oldval;
3889}
3890//******************************************************************************
3891//******************************************************************************
3892ULONG Win32BaseWindow::GetWindowLong(int index, BOOL fUnicode)
3893{
3894 ULONG value;
3895
3896 switch(index) {
3897 case GWL_EXSTYLE:
3898 value = dwExStyle;
3899 break;
3900 case GWL_STYLE:
3901 value = dwStyle;
3902 break;
3903 case GWL_WNDPROC:
3904 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3905 break;
3906 case GWL_HINSTANCE:
3907 value = hInstance;
3908 break;
3909 case GWL_HWNDPARENT:
3910 value = GetParent();
3911 break;
3912 case GWL_ID:
3913 value = getWindowId();
3914 break;
3915 case GWL_USERDATA:
3916 value = userData;
3917 break;
3918 default:
3919 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3920 {
3921 value = *(ULONG *)(userWindowBytes + index);
3922 break;
3923 }
3924 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3925 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3926 return 0;
3927 }
3928 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3929 //Note: NT4, SP6 does not set the last error to 0
3930 SetLastError(ERROR_SUCCESS);
3931 return value;
3932}
3933//******************************************************************************
3934//******************************************************************************
3935WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3936{
3937 WORD oldval;
3938
3939 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3940 {
3941 oldval = *(WORD *)(userWindowBytes + index);
3942 *(WORD *)(userWindowBytes + index) = value;
3943 //Note: NT4, SP6 does not set the last error to 0
3944 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3945 SetLastError(ERROR_SUCCESS);
3946 return oldval;
3947 }
3948 switch(index)
3949 {
3950 case GWW_HINSTANCE:
3951 oldval = hInstance;
3952 hInstance = value;
3953 break;
3954
3955 case GWW_HWNDPARENT:
3956 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3957 break;
3958
3959 case GWW_ID:
3960 oldval = getWindowId();
3961 setWindowId(value);
3962 break;
3963
3964 default:
3965 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3966 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3967 return 0;
3968 }
3969 //Note: NT4, SP6 does not set the last error to 0
3970 SetLastError(ERROR_SUCCESS);
3971 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3972 return oldval;
3973}
3974//******************************************************************************
3975//******************************************************************************
3976WORD Win32BaseWindow::GetWindowWord(int index)
3977{
3978 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3979 {
3980 //Note: NT4, SP6 does not set the last error to 0
3981 SetLastError(ERROR_SUCCESS);
3982 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3983 return *(WORD *)(userWindowBytes + index);
3984 }
3985 switch(index)
3986 {
3987 case GWW_ID:
3988 if(HIWORD(getWindowId()))
3989 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3990 return (WORD)getWindowId();
3991
3992 case GWW_HWNDPARENT:
3993 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3994 return (WORD) GetParent();
3995
3996 case GWW_HINSTANCE:
3997 if (HIWORD(hInstance))
3998 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3999 return (WORD)hInstance;
4000 }
4001
4002 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
4003 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
4004 return 0;
4005}
4006//******************************************************************************
4007//Locates window in linked list and increases reference count (if found)
4008//Window object must be unreferenced after usage
4009//******************************************************************************
4010Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
4011{
4012 Win32BaseWindow *window;
4013
4014////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
4015//// while browsing
4016//// Not thread safe now!
4017//// lock(&critsect);
4018 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
4019 if(window) {
4020//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
4021 window->addRef();
4022 }
4023//// unlock(&critsect);
4024 return window;
4025 }
4026//// unlock(&critsect);
4027// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
4028 return NULL;
4029}
4030//******************************************************************************
4031//Locates window in linked list and increases reference count (if found)
4032//Window object must be unreferenced after usage
4033//******************************************************************************
4034Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
4035{
4036 DWORD magic;
4037 HWND hwnd;
4038
4039 if(hwndOS2 == OSLIB_HWND_DESKTOP)
4040 {
4041 windowDesktop->addRef();
4042 return windowDesktop;
4043 }
4044
4045 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
4046 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
4047
4048 if(hwnd && CheckMagicDword(magic)) {
4049 return GetWindowFromHandle(hwnd);
4050 }
4051// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
4052 return 0;
4053}
4054//******************************************************************************
4055//Locates window in linked list and increases reference count (if found)
4056//Window object must be unreferenced after usage
4057//******************************************************************************
4058Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
4059{
4060 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
4061}
4062//******************************************************************************
4063//******************************************************************************
4064HWND WIN32API Win32ToOS2Handle(HWND hwnd)
4065{
4066 HWND hwndOS2;
4067
4068 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4069
4070 if(window) {
4071 hwndOS2 = window->getOS2WindowHandle();
4072 RELEASE_WNDOBJ(window);
4073 return hwndOS2;
4074 }
4075// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4076 return hwnd;
4077}
4078//******************************************************************************
4079//******************************************************************************
4080HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
4081{
4082 HWND hwndOS2;
4083
4084 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4085
4086 if(window) {
4087 hwndOS2 = window->getOS2FrameWindowHandle();
4088 RELEASE_WNDOBJ(window);
4089 return hwndOS2;
4090 }
4091// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4092 return hwnd;
4093}
4094//******************************************************************************
4095//******************************************************************************
4096HWND WIN32API OS2ToWin32Handle(HWND hwnd)
4097{
4098 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
4099 HWND hwndWin32;
4100
4101 if(window) {
4102 hwndWin32 = window->getWindowHandle();
4103 RELEASE_WNDOBJ(window);
4104 return hwndWin32;
4105 }
4106 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
4107 if(window) {
4108 hwndWin32 = window->getWindowHandle();
4109 RELEASE_WNDOBJ(window);
4110 return hwndWin32;
4111 }
4112
4113// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
4114 return 0;
4115// else return hwnd; //OS/2 window handle
4116}
4117#ifdef DEBUG
4118LONG Win32BaseWindow::addRef()
4119{
4120// dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
4121 return GenericObject::addRef();
4122}
4123//******************************************************************************
4124//******************************************************************************
4125LONG Win32BaseWindow::release(char *function, int line)
4126{
4127// dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
4128 return GenericObject::release();
4129}
4130#endif
4131//******************************************************************************
4132//******************************************************************************
4133GenericObject *Win32BaseWindow::windows = NULL;
4134CRITICAL_SECTION Win32BaseWindow::critsect = {0};
4135
4136//******************************************************************************
4137//******************************************************************************
4138#ifdef DEBUG
4139void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
4140{
4141 char style[256] = "";
4142 char exstyle[256] = "";
4143
4144 /* Window styles */
4145 if(dwStyle & WS_CHILD)
4146 strcat(style, "WS_CHILD ");
4147 if(dwStyle & WS_POPUP)
4148 strcat(style, "WS_POPUP ");
4149 if(dwStyle & WS_VISIBLE)
4150 strcat(style, "WS_VISIBLE ");
4151 if(dwStyle & WS_DISABLED)
4152 strcat(style, "WS_DISABLED ");
4153 if(dwStyle & WS_CLIPSIBLINGS)
4154 strcat(style, "WS_CLIPSIBLINGS ");
4155 if(dwStyle & WS_CLIPCHILDREN)
4156 strcat(style, "WS_CLIPCHILDREN ");
4157 if(dwStyle & WS_MAXIMIZE)
4158 strcat(style, "WS_MAXIMIZE ");
4159 if(dwStyle & WS_MINIMIZE)
4160 strcat(style, "WS_MINIMIZE ");
4161 if(dwStyle & WS_GROUP)
4162 strcat(style, "WS_GROUP ");
4163 if(dwStyle & WS_TABSTOP)
4164 strcat(style, "WS_TABSTOP ");
4165
4166 if((dwStyle & WS_CAPTION) == WS_CAPTION)
4167 strcat(style, "WS_CAPTION ");
4168 if(dwStyle & WS_DLGFRAME)
4169 strcat(style, "WS_DLGFRAME ");
4170 if(dwStyle & WS_BORDER)
4171 strcat(style, "WS_BORDER ");
4172
4173 if(dwStyle & WS_VSCROLL)
4174 strcat(style, "WS_VSCROLL ");
4175 if(dwStyle & WS_HSCROLL)
4176 strcat(style, "WS_HSCROLL ");
4177 if(dwStyle & WS_SYSMENU)
4178 strcat(style, "WS_SYSMENU ");
4179 if(dwStyle & WS_THICKFRAME)
4180 strcat(style, "WS_THICKFRAME ");
4181 if(dwStyle & WS_MINIMIZEBOX)
4182 strcat(style, "WS_MINIMIZEBOX ");
4183 if(dwStyle & WS_MAXIMIZEBOX)
4184 strcat(style, "WS_MAXIMIZEBOX ");
4185
4186 if(dwExStyle & WS_EX_DLGMODALFRAME)
4187 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4188 if(dwExStyle & WS_EX_ACCEPTFILES)
4189 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4190 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4191 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4192 if(dwExStyle & WS_EX_TOPMOST)
4193 strcat(exstyle, "WS_EX_TOPMOST ");
4194 if(dwExStyle & WS_EX_TRANSPARENT)
4195 strcat(exstyle, "WS_EX_TRANSPARENT ");
4196
4197 if(dwExStyle & WS_EX_MDICHILD)
4198 strcat(exstyle, "WS_EX_MDICHILD ");
4199 if(dwExStyle & WS_EX_TOOLWINDOW)
4200 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4201 if(dwExStyle & WS_EX_WINDOWEDGE)
4202 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4203 if(dwExStyle & WS_EX_CLIENTEDGE)
4204 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4205 if(dwExStyle & WS_EX_CONTEXTHELP)
4206 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4207 if(dwExStyle & WS_EX_RIGHT)
4208 strcat(exstyle, "WS_EX_RIGHT ");
4209 if(dwExStyle & WS_EX_LEFT)
4210 strcat(exstyle, "WS_EX_LEFT ");
4211 if(dwExStyle & WS_EX_RTLREADING)
4212 strcat(exstyle, "WS_EX_RTLREADING ");
4213 if(dwExStyle & WS_EX_LTRREADING)
4214 strcat(exstyle, "WS_EX_LTRREADING ");
4215 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4216 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4217 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4218 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4219 if(dwExStyle & WS_EX_CONTROLPARENT)
4220 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4221 if(dwExStyle & WS_EX_STATICEDGE)
4222 strcat(exstyle, "WS_EX_STATICEDGE ");
4223 if(dwExStyle & WS_EX_APPWINDOW)
4224 strcat(exstyle, "WS_EX_APPWINDOW ");
4225
4226 dprintf(("Window style: %x %s", dwStyle, style));
4227 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4228}
4229#endif
4230//******************************************************************************
4231//******************************************************************************
Note: See TracBrowser for help on using the repository browser.