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

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

Merge branch gcc-kmk to trunk.

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