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

Last change on this file since 22043 was 22043, checked in by dmik, 13 years ago

user32: Prevent debug assertion.

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