source: branches/gcc-kmk/src/user32/win32wbase.cpp@ 21808

Last change on this file since 21808 was 21808, checked in by dmik, 14 years ago

Port USER32.DLL (continued).

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