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

Last change on this file since 21357 was 21356, checked in by rlwalsh, 16 years ago

eliminate VACPP warning & info msgs - see Ticket #1

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