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

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

Destroy switch entry before hiding window in DestroyWindow.

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