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

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

Update

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