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

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

Window creation: updated the coordinate fix code with the latest Rewind version

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