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

Last change on this file since 21372 was 21372, checked in by vladest, 15 years ago

Fixed notification parameter for parent

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