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

Last change on this file since 21303 was 21303, checked in by ydario, 16 years ago

User32 updates.

File size: 150.9 KB
Line 
1/* $Id: win32wbase.cpp,v 1.390 2004-05-24 09:02:00 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-2002 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c)
10 * Corel version: corel20000212
11 *
12 * Copyright 1993, 1994, 1996 Alexandre Julliard
13 * 1995 Alex Korobka
14 *
15 * TODO: Not thread/process safe
16 *
17 * NOTE: To access a window object, you must call GetWindowFromOS2Handle or
18 * GetWindowFromHandle. Both these methods increase the reference count
19 * of the object. When you're done with the object, you MUST call
20 * the release method!
21 * This mechanism prevents premature destruction of objects when there
22 * are still clients using it.
23 *
24 * NOTE: Client rectangle always relative to frame window
25 * Window rectangle in parent coordinates (relative to parent's client window)
26 * (screen coord. if no parent)
27 *
28 * NOTE: Status of window:
29 * Before a window has processed WM_NCCREATE:
30 * - GetTopWindow can't return that window handle
31 * - GetWindow(parent, GW_CHILD) can't return that window handle
32 * - IsChild works
33 * TODO: Does this affect more functions?? (other GetWindow ops)
34 * (verified in NT4, SP6)
35 *
36 * Project Odin Software License can be found in LICENSE.TXT
37 *
38 */
39#include <os2win.h>
40#include <win.h>
41#include <stdlib.h>
42#include <string.h>
43#include <stdarg.h>
44#include <assert.h>
45#include <misc.h>
46#include <heapstring.h>
47#include <winuser32.h>
48#include <custombuild.h>
49#include "win32wbase.h"
50#include "win32wfake.h"
51#include "wndmsg.h"
52#include "oslibwin.h"
53#include "oslibmsg.h"
54#include "oslibutil.h"
55#include "oslibgdi.h"
56#include "oslibres.h"
57#include "oslibdos.h"
58#include "syscolor.h"
59#include "win32wndhandle.h"
60#include "dc.h"
61#include "win32wdesktop.h"
62#include "pmwindow.h"
63#include "controls.h"
64#include <wprocess.h>
65#include <win\hook.h>
66#include <menu.h>
67#define INCL_TIMERWIN32
68#include "timer.h"
69#include "user32api.h"
70#include "callwrap.h"
71
72#define DBG_LOCALLOG DBG_win32wbase
73#include "dbglocal.h"
74
75/* bits in the dwKeyData */
76#define KEYDATA_ALT 0x2000
77#define KEYDATA_PREVSTATE 0x4000
78
79void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
80
81static fDestroyAll = FALSE;
82//For quick lookup of current process id
83static ULONG currentProcessId = -1;
84static int iF10Key = 0;
85static int iMenuSysKey = 0;
86
87//******************************************************************************
88//******************************************************************************
89Win32BaseWindow::Win32BaseWindow()
90 : GenericObject(&windows, &critsect), ChildWindow(&critsect)
91{
92 Init();
93}
94//******************************************************************************
95//******************************************************************************
96Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
97 : GenericObject(&windows, &critsect), ChildWindow(&critsect)
98{
99 Init();
100 this->isUnicode = isUnicode;
101 // call member function
102 CreateWindowExA(lpCreateStructA, classAtom);
103}
104//******************************************************************************
105//******************************************************************************
106void Win32BaseWindow::Init()
107{
108 isUnicode = FALSE;
109 fFirstShow = TRUE;
110 fIsDialog = FALSE;
111 fIsModalDialogOwner = FALSE;
112 OS2HwndModalDialog = 0;
113 fParentChange = FALSE;
114 fDestroyWindowCalled = FALSE;
115 fChildDestructionInProgress = FALSE;
116 fTaskList = FALSE;
117 fParentDC = FALSE;
118 fComingToTop = FALSE;
119 fMinMaxChange = FALSE;
120 fPMUpdateRegionChanged = FALSE;
121 fEraseBkgndFlag = TRUE;
122 fIsDragDropActive= FALSE;
123 fDirtyUpdateRegion = FALSE;
124 fWindowLocked = FALSE;
125
126 state = STATE_INIT;
127 windowNameA = NULL;
128 windowNameW = NULL;
129 windowNameLengthA = 0;
130 windowNameLengthW = 0;
131
132 userWindowBytes = NULL;;
133 nrUserWindowBytes= 0;
134
135 OS2Hwnd = 0;
136 OS2HwndFrame = 0;
137 hSysMenu = 0;
138 Win32Hwnd = 0;
139
140 // allocate a Win32 HWND, return it in Win32Hwnd and associate object
141 // pointer with it
142 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
143 {
144 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
145 DebugInt3();
146 }
147 Win32HwndOrg = Win32Hwnd;
148
149 posx = posy = 0;
150 width = height = 0;
151
152 dwExStyle = 0;
153 dwStyle = 0;
154 dwOldStyle = 0;
155 win32wndproc = 0;
156 hInstance = 0;
157 dwIDMenu = 0; //0xFFFFFFFF; //default -1
158 userData = 0;
159 contextHelpId = 0;
160 hotkey = 0;
161
162 hwndLinkAfter = HWND_BOTTOM;
163 flags = 0;
164 lastHitTestVal = HTCLIENT;
165 owner = NULL;
166 windowClass = 0;
167
168 hIcon = 0;
169 hIconSm = 0;
170
171 horzScrollInfo = NULL;
172 vertScrollInfo = NULL;
173
174 propertyList = NULL;
175
176 cbExtra = 0;
177 pExtra = NULL;
178
179 ownDC = 0;
180 hWindowRegion = 0;
181 hClipRegion = 0;
182 hVisRegion = 0;
183 hUpdateRegion = 0;
184
185 hTaskList = 0;
186
187 if(currentProcessId == -1)
188 {
189 currentProcessId = GetCurrentProcessId();
190 }
191 dwThreadId = GetCurrentThreadId();
192 dwProcessId = currentProcessId;
193
194 memset(&windowpos, 0, sizeof(windowpos));
195 //min and max position are initially -1 (verified in NT4, SP6)
196 windowpos.ptMinPosition.x = -1;
197 windowpos.ptMinPosition.y = -1;
198 windowpos.ptMaxPosition.x = -1;
199 windowpos.ptMaxPosition.y = -1;
200
201 lpVisRgnNotifyProc = NULL;
202 dwVisRgnNotifyParam = NULL;
203
204 pfnOldPMWndProc = NULL;
205
206 memset(hdcWindow, 0, sizeof(hdcWindow));
207 nrOpenDCs = 0;
208}
209//******************************************************************************
210//todo get rid of resources (menu, icon etc)
211//******************************************************************************
212Win32BaseWindow::~Win32BaseWindow()
213{
214 if(getRefCount() < 0) {
215 DebugInt3();
216 }
217
218 if(hTaskList) {
219 OSLibWinRemoveFromTasklist(hTaskList);
220 }
221
222 OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE);
223 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
224 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
225
226 if(fDestroyAll) {
227 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
228 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
229 }
230 else
231 if(getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
232 {
233 //if we're the last child that's being destroyed and our
234 //parent window was also destroyed, then we
235 if(getParent()->IsWindowDestroyed())
236 {
237 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
238 RELEASE_WNDOBJ(wndparent);
239 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
240 }
241 }
242 else
243 {
244 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
245 if(wndparent && !fDestroyAll) {
246 RELEASE_WNDOBJ(wndparent);
247 }
248 }
249 if(owner && !fDestroyAll) {
250 RELEASE_WNDOBJ(owner);
251 }
252
253 // Decrement class window counter
254 // NOTE: Must be done before ReleaseDC call for ownDC!
255 if(windowClass) {
256 RELEASE_CLASSOBJ(windowClass);
257 }
258
259 if(ownDC)
260 ReleaseDC(Win32HwndOrg, ownDC);
261
262 if(Win32Hwnd)
263 HwFreeWindowHandle(Win32Hwnd);
264
265 if(userWindowBytes)
266 free(userWindowBytes);
267
268 if(windowNameA) {
269 free(windowNameA);
270 windowNameA = NULL;
271 }
272 if(windowNameW) {
273 free(windowNameW);
274 windowNameW = NULL;
275 }
276 if(vertScrollInfo) {
277 free(vertScrollInfo);
278 vertScrollInfo = NULL;
279 }
280 if(horzScrollInfo) {
281 free(horzScrollInfo);
282 horzScrollInfo = NULL;
283 }
284 if(propertyList) {
285 removeWindowProps();
286 }
287 if(hUpdateRegion) {
288 DeleteObject(hUpdateRegion);
289 hUpdateRegion = NULL;
290 }
291}
292//******************************************************************************
293//******************************************************************************
294void Win32BaseWindow::DestroyAll()
295{
296 fDestroyAll = TRUE;
297 GenericObject::DestroyAll(windows);
298}
299//******************************************************************************
300//******************************************************************************
301BOOL Win32BaseWindow::isChild()
302{
303 return ((dwStyle & WS_CHILD) != 0);
304}
305//******************************************************************************
306//******************************************************************************
307BOOL Win32BaseWindow::IsWindowUnicode()
308{
309 dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
310 return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
311}
312//******************************************************************************
313//******************************************************************************
314BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
315{
316 char buffer[256];
317
318#ifdef DEBUG
319 PrintWindowStyle(cs->style, cs->dwExStyle);
320#endif
321
322 //If window has no owner/parent window, then it will be added to the tasklist
323 //(depending on visibility state)
324 if (!cs->hwndParent) fTaskList = TRUE;
325
326 sw = SW_SHOW;
327 SetLastError(0);
328
329 /* Find the parent window */
330 if (cs->hwndParent)
331 {
332 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
333 if(!window) {
334 dprintf(("Bad parent %04x\n", cs->hwndParent ));
335 SetLastError(ERROR_INVALID_PARAMETER);
336 return FALSE;
337 }
338 /* Make sure parent is valid */
339 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 = 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
1561 dprintf(("DefWndProc: winmsg: %x for %x Msg %s", Msg, Win32Hwnd, GetMsgText(HIWORD(lParam))));
1562
1563 switch(Msg)
1564 {
1565 case WM_CLOSE:
1566 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1567 DestroyWindow();
1568 return 0;
1569
1570 case WM_GETTEXTLENGTH:
1571 return windowNameLengthA;
1572
1573 case WM_GETTEXT:
1574 if (!lParam || !wParam)
1575 return 0;
1576 if (!windowNameA)
1577 ((LPSTR)lParam)[0] = 0;
1578 else
1579 lstrcpynA(( LPSTR )lParam, windowNameA, wParam );
1580 return strlen(( LPSTR )lParam );
1581
1582 case WM_SETTEXT:
1583 {
1584 LPCSTR lpsz = (LPCSTR)lParam;
1585
1586 // reallocate if new buffer is larger
1587 if (!lParam)
1588 {
1589 free(windowNameA);
1590 free(windowNameW);
1591 windowNameLengthA = 0;
1592 windowNameLengthW = 0;
1593 windowNameA = NULL;
1594 windowNameW = NULL;
1595 }
1596 else
1597 {
1598 if (windowNameA)
1599 {
1600 free(windowNameA);
1601 windowNameA = NULL;
1602 }
1603
1604 if (windowNameW)
1605 {
1606 free(windowNameW);
1607 windowNameW = NULL;
1608 }
1609
1610 windowNameLengthA = strlen( lpsz );
1611 windowNameA = (LPSTR)_smalloc(windowNameLengthA+1);
1612 strcpy(windowNameA, lpsz);
1613 windowNameLengthW = lstrlenAtoW( lpsz, -1 );
1614 windowNameW = (LPWSTR)_smalloc(( windowNameLengthW + 1 )*sizeof(WCHAR));
1615 lstrcpyAtoW( windowNameW, windowNameA );
1616 }
1617
1618 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1619 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1620 {
1621 HandleNCPaint((HRGN)1);
1622 if(hTaskList) {
1623 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1624 }
1625 if(fOS2Look) {
1626 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1627 }
1628 }
1629
1630 return TRUE;
1631 }
1632
1633 case WM_SETREDRAW:
1634 {
1635 if (wParam)
1636 {
1637 setStyle(getStyle() | WS_VISIBLE);
1638 dprintf(("Enable window update for %x", getWindowHandle()));
1639 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
1640 }
1641 else
1642 {
1643 if (getStyle() & WS_VISIBLE)
1644 {
1645 setStyle(getStyle() & ~WS_VISIBLE);
1646 dprintf(("Disable window update for %x", getWindowHandle()));
1647 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
1648 }
1649 }
1650 return 0;
1651 }
1652
1653 case WM_CTLCOLORMSGBOX:
1654 case WM_CTLCOLOREDIT:
1655 case WM_CTLCOLORLISTBOX:
1656 case WM_CTLCOLORBTN:
1657 case WM_CTLCOLORDLG:
1658 case WM_CTLCOLORSTATIC:
1659 case WM_CTLCOLORSCROLLBAR:
1660 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1661
1662 case WM_CTLCOLOR:
1663 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1664
1665 case WM_VKEYTOITEM:
1666 case WM_CHARTOITEM:
1667 return -1;
1668
1669 case WM_PARENTNOTIFY:
1670 return 0;
1671
1672 case WM_MOUSEACTIVATE:
1673 {
1674 HWND hwnd = getWindowHandle();
1675
1676 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1677 if (::GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
1678 {
1679 LONG ret = ::SendMessageW( ::GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
1680 if (ret) return ret;
1681 }
1682
1683 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
1684 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
1685 }
1686
1687 case WM_ACTIVATE:
1688 /* The default action in Windows is to set the keyboard focus to
1689 * the window, if it's being activated and not minimized */
1690 if (LOWORD(wParam) != WA_INACTIVE) {
1691 if(!(getStyle() & WS_MINIMIZE))
1692 SetFocus(getWindowHandle());
1693 }
1694 return 0;
1695
1696 case WM_SETCURSOR:
1697 {
1698 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1699 if((getStyle() & WS_CHILD))
1700 {
1701 if(getParent()) {
1702 LRESULT rc = SendMessageA(getParent()->getWindowHandle(), WM_SETCURSOR, wParam, lParam);
1703 if(rc) return rc;
1704 }
1705 }
1706 if (wParam == getWindowHandle())
1707 {
1708 HCURSOR hCursor;
1709
1710 switch(LOWORD(lParam))
1711 {
1712 case HTCLIENT:
1713 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1714 break;
1715
1716 case HTLEFT:
1717 case HTRIGHT:
1718 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1719 break;
1720
1721 case HTTOP:
1722 case HTBOTTOM:
1723 hCursor = LoadCursorA(0,IDC_SIZENSA);
1724 break;
1725
1726 case HTTOPLEFT:
1727 case HTBOTTOMRIGHT:
1728 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1729 break;
1730
1731 case HTTOPRIGHT:
1732 case HTBOTTOMLEFT:
1733 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1734 break;
1735
1736 default:
1737 hCursor = LoadCursorA(0,IDC_ARROWA);
1738 break;
1739 }
1740
1741 if (hCursor)
1742 {
1743 SetCursor(hCursor);
1744 return 1;
1745 }
1746 else return 0;
1747 }
1748 else return 0;
1749 }
1750
1751 case WM_MOUSEMOVE:
1752 return 0;
1753
1754 case WM_MOUSEWHEEL:
1755 if (::GetWindowLongA( getWindowHandle(), GWL_STYLE ) & WS_CHILD)
1756 return ::SendMessageA( ::GetParent(getWindowHandle()), WM_MOUSEWHEEL, wParam, lParam );
1757 break;
1758
1759 case WM_WINDOWPOSCHANGED:
1760 {
1761 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1762 WPARAM wp = SIZE_RESTORED;
1763
1764 //According to Wine these are always sent, but experiments in Windows NT4, SP6
1765 //show otherwise
1766 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1767 {
1768 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1769 }
1770 //According to Wine these are always sent, but experiments in Windows NT4, SP6
1771 //show otherwise
1772 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1773 {
1774 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1775 else
1776 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1777
1778 SendMessageA(getWindowHandle(),WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1779 rectClient.bottom - rectClient.top));
1780 }
1781 return 0;
1782 }
1783 case WM_WINDOWPOSCHANGING:
1784 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1785
1786 case WM_ERASEBKGND:
1787 case WM_ICONERASEBKGND:
1788 {
1789 HBRUSH hBrush;
1790 RECT rect;
1791 int rc;
1792
1793 if (!windowClass || (!windowClass->getBackgroundBrush()
1794 && !(getStyle() & WS_MINIMIZE))) return 0;
1795
1796 //PF For PM desktop/MDI icons allocate brush as well to avoid
1797 //garbage in icons
1798
1799 if (!windowClass->getBackgroundBrush())
1800 hBrush = GetStockObject(GRAY_BRUSH);
1801 else
1802 {
1803 hBrush = windowClass->getBackgroundBrush();
1804 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1805 hBrush = GetSysColorBrush(hBrush-1);
1806 }
1807
1808
1809 rc = GetClipBox( (HDC)wParam, &rect );
1810 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1811 FillRect( (HDC)wParam, &rect, hBrush);
1812
1813 return 1;
1814 }
1815
1816 case WM_PRINT:
1817 return DefWndPrint(wParam,lParam);
1818
1819 case WM_SYNCPAINT:
1820 RedrawWindow(getWindowHandle(), NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN);
1821 return 0;
1822
1823 case WM_PAINTICON:
1824 case WM_PAINT:
1825 {
1826 PAINTSTRUCT ps;
1827 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1828 if( hdc )
1829 {
1830 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1831 {
1832 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1833 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1834 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1835 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1836 }
1837 EndPaint(getWindowHandle(), &ps );
1838 }
1839 return 0;
1840 }
1841
1842 case WM_GETDLGCODE:
1843 return 0;
1844
1845 case WM_NCPAINT:
1846 return HandleNCPaint((HRGN)wParam);
1847
1848 case WM_NCACTIVATE:
1849 return HandleNCActivate(wParam);
1850
1851 case WM_NCCREATE:
1852 return(TRUE);
1853
1854 case WM_NCDESTROY:
1855 return 0;
1856
1857 case WM_NCCALCSIZE:
1858 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1859
1860 case WM_NCLBUTTONDOWN:
1861 return HandleNCLButtonDown(wParam,lParam);
1862
1863 case WM_LBUTTONDBLCLK:
1864 case WM_NCLBUTTONDBLCLK:
1865 return HandleNCLButtonDblClk(wParam,lParam);
1866
1867 case WM_NCRBUTTONDOWN:
1868 case WM_NCRBUTTONDBLCLK:
1869 case WM_NCMBUTTONDOWN:
1870 case WM_NCMBUTTONDBLCLK:
1871 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1872 return 0;
1873
1874 case WM_NCRBUTTONUP:
1875 return HandleNCRButtonUp(wParam,lParam);
1876
1877 case WM_NCMBUTTONUP:
1878 return 0;
1879
1880 case WM_NCHITTEST:
1881 {
1882 POINT point;
1883 LRESULT retvalue;
1884
1885 point.x = (SHORT)LOWORD(lParam);
1886 point.y = (SHORT)HIWORD(lParam);
1887
1888 retvalue = HandleNCHitTest(point);
1889#if 0 //CB: let the Corel people fix the bugs first
1890 if(retvalue == HTMENU)
1891 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1892 else
1893 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1894#endif
1895 return retvalue;
1896 }
1897
1898 case WM_SYSCOMMAND:
1899 {
1900 POINT point;
1901
1902 point.x = LOWORD(lParam);
1903 point.y = HIWORD(lParam);
1904 return HandleSysCommand(wParam,&point);
1905 }
1906
1907 case WM_KEYDOWN:
1908 if(wParam == VK_F10) iF10Key = VK_F10;
1909 break;
1910
1911 case WM_SYSKEYDOWN:
1912 {
1913 if( HIWORD(lParam) & KEYDATA_ALT )
1914 {
1915 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
1916 if( wParam == VK_MENU && !iMenuSysKey )
1917 iMenuSysKey = 1;
1918 else
1919 iMenuSysKey = 0;
1920
1921 iF10Key = 0;
1922
1923 if( wParam == VK_F4 ) /* try to close the window */
1924 {
1925 HWND top = GetTopParent();
1926 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
1927 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
1928 }
1929
1930 //Default OS/2 app behaviour for system keys
1931 if(fOS2Look)
1932 {
1933 if( wParam == VK_F5 ) /* try to restore the window */
1934 {
1935 HWND top = GetTopParent();
1936 /* No checks needed SC_RESTORE handler does them */
1937 PostMessageW( top, WM_SYSCOMMAND, SC_RESTORE, 0 );
1938 }
1939
1940 if( wParam == VK_F7 ) /* size the window */
1941 {
1942 HWND top = GetTopParent();
1943 PostMessageW( top, WM_SYSCOMMAND, SC_MOVE, 0 );
1944 }
1945
1946 if( wParam == VK_F8 ) /* move the window */
1947 {
1948 HWND top = GetTopParent();
1949 if ( GetWindowLongA(top, GWL_STYLE) & WS_SIZEBOX)
1950 PostMessageW( top, WM_SYSCOMMAND, SC_SIZE, 0 );
1951 }
1952
1953 if( wParam == VK_F9 ) /* try to minimize the window */
1954 {
1955 HWND top = GetTopParent();
1956 if ( GetWindowLongA(top, GWL_STYLE) & WS_MINIMIZEBOX)
1957 PostMessageW( top, WM_SYSCOMMAND, SC_MINIMIZE, 0 );
1958 }
1959
1960 if( wParam == VK_F10 ) /* try to maximize the window */
1961 {
1962 HWND top = GetTopParent();
1963 if ( GetWindowLongA(top, GWL_STYLE) & WS_MAXIMIZEBOX)
1964 PostMessageW( top, WM_SYSCOMMAND, SC_MAXIMIZE, 0 );
1965 }
1966 }
1967
1968 }
1969 else if( wParam == VK_F10 )
1970 iF10Key = 1;
1971 else
1972 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
1973 SendMessageW(getWindowHandle(), WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
1974 return 0;
1975 }
1976
1977 case WM_KEYUP:
1978 //Single Alt down + up always generates WM_SYSKEYUP
1979 iMenuSysKey = 0;
1980 // no break;
1981 case WM_SYSKEYUP:
1982 /* Press and release F10 or ALT */
1983 if (((wParam == VK_MENU) && iMenuSysKey) ||
1984 ((wParam == VK_F10) && iF10Key))
1985 ::SendMessageW( GetTopParent(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
1986 iMenuSysKey = iF10Key = 0;
1987 break;
1988
1989 case WM_SYSCHAR:
1990 {
1991 iMenuSysKey = 0;
1992 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1993 {
1994 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1995 (WPARAM)SC_RESTORE, 0L );
1996 break;
1997 }
1998 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1999 {
2000 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
2001 break;
2002 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
2003 ::SendMessageW(GetParent(), Msg, wParam, lParam );
2004 }
2005 else ::SendMessageA(getWindowHandle(), WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
2006 }
2007#if 0
2008 else /* check for Ctrl-Esc */
2009 if (wParam != VK_ESCAPE) MessageBeep(0);
2010 break;
2011#endif
2012 }
2013
2014 case WM_SETHOTKEY:
2015 hotkey = wParam;
2016 return 1; //CB: always successful
2017
2018 case WM_GETHOTKEY:
2019 return hotkey;
2020
2021 case WM_RBUTTONUP:
2022 {
2023 POINT pt;
2024 pt.x = SLOWORD(lParam);
2025 pt.y = SHIWORD(lParam);
2026 ClientToScreen(getWindowHandle(), &pt);
2027 SendMessageA( getWindowHandle(), WM_CONTEXTMENU, getWindowHandle(),MAKELPARAM(pt.x, pt.y) );
2028 }
2029 break;
2030
2031 case WM_CONTEXTMENU:
2032 if ((dwStyle & WS_CHILD) && getParent())
2033 SendMessageA(getParent()->getWindowHandle(), WM_CONTEXTMENU,wParam,lParam);
2034 else
2035 {
2036 LONG hitcode;
2037 POINT pt;
2038 if (!GetSysMenu()) return 0;
2039 pt.x = SLOWORD(lParam);
2040 pt.y = SHIWORD(lParam);
2041 hitcode = HandleNCHitTest(pt);
2042
2043 /* Track system popup if click was in the caption area. */
2044 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
2045 TrackPopupMenu(GetSysMenu(),
2046 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
2047 pt.x, pt.y, 0, getWindowHandle(), NULL);
2048 }
2049 return 0;
2050
2051 case WM_SHOWWINDOW:
2052 if (!lParam) return 0; /* sent from ShowWindow */
2053 if (!(dwStyle & WS_POPUP) || !owner) return 0;
2054 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
2055 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
2056 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
2057 return 0;
2058
2059 case WM_CANCELMODE:
2060 if (getParent() == windowDesktop) EndMenu();
2061 if (GetCapture() == Win32Hwnd) ReleaseCapture();
2062 return 0;
2063
2064 case WM_DROPOBJECT:
2065 return DRAG_FILE;
2066
2067 case WM_QUERYDROPOBJECT:
2068 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
2069
2070 case WM_QUERYDRAGICON:
2071 {
2072 HICON hDragIcon = windowClass->getCursor();
2073 UINT len;
2074
2075 if(hDragIcon) return (LRESULT)hDragIcon;
2076 for(len = 1; len < 64; len++)
2077 {
2078 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
2079 if(hDragIcon)
2080 return (LRESULT)hDragIcon;
2081 }
2082 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
2083 }
2084
2085 case WM_QUERYOPEN:
2086 case WM_QUERYENDSESSION:
2087 return 1;
2088
2089 case WM_NOTIFYFORMAT:
2090 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
2091
2092 case WM_SETICON:
2093 case WM_GETICON:
2094 {
2095 LRESULT result = 0;
2096
2097 /* Set the appropriate icon members in the window structure. */
2098 if (wParam == ICON_SMALL)
2099 {
2100 result = hIconSm;
2101 if (Msg == WM_SETICON)
2102 hIconSm = (HICON)lParam;
2103 }
2104 else
2105 {
2106 result = hIcon;
2107 if (Msg == WM_SETICON)
2108 {
2109 hIcon = (HICON)lParam;
2110 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2111 OSLibWinSetIcon(OS2HwndFrame,hIcon);
2112 }
2113 }
2114 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
2115 HandleNCPaint((HRGN)1);
2116
2117 return result;
2118 }
2119
2120 case WM_HELP:
2121 if (getParent()) SendMessageA(getParent()->getWindowHandle(), Msg,wParam,lParam);
2122 break;
2123
2124 case WM_NOTIFY:
2125 return 0; //comctl32 controls expect this
2126
2127 case WM_IME_CHAR:
2128 if( wParam & 0xFF00 ) // DBCS ?
2129 SendMessageA( getWindowHandle(), WM_CHAR, ( WPARAM )( BYTE )( wParam >> 8 ), lParam );
2130 SendMessageA( getWindowHandle(), WM_CHAR, ( WPARAM )( BYTE )( wParam & 0xFF ), lParam );
2131 break;
2132
2133 default:
2134 return 0;
2135 }
2136 return 0;
2137}
2138//******************************************************************************
2139//******************************************************************************
2140LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
2141{
2142 switch(Msg)
2143 {
2144 case WM_GETTEXTLENGTH:
2145 return windowNameLengthW;
2146
2147 case WM_GETTEXT:
2148 if (!lParam || !wParam)
2149 return 0;
2150 if (!windowNameW)
2151 ((LPWSTR)lParam)[0] = 0;
2152 else
2153 lstrcpynW(( LPWSTR )lParam, windowNameW, wParam );
2154
2155 return strlenW(( LPWSTR )lParam );
2156
2157 case WM_SETTEXT:
2158 {
2159 LPWSTR lpsz = (LPWSTR)lParam;
2160
2161 // reallocate if new buffer is larger
2162 if (!lParam)
2163 {
2164 free(windowNameA);
2165 free(windowNameW);
2166 windowNameLengthA = 0;
2167 windowNameLengthW = 0;
2168 windowNameA = NULL;
2169 windowNameW = NULL;
2170 }
2171 else
2172 {
2173 if (windowNameA)
2174 {
2175 free(windowNameA);
2176 windowNameA = NULL;
2177 }
2178
2179 if (windowNameW)
2180 {
2181 free(windowNameW);
2182 windowNameW = NULL;
2183 }
2184
2185 windowNameLengthW = lstrlenW( lpsz );
2186 windowNameW = (LPWSTR)_smalloc((windowNameLengthW+1)*sizeof(WCHAR));
2187 strcpyW(windowNameW, lpsz);
2188 windowNameLengthA = lstrlenWtoA( lpsz, -1 );
2189 windowNameA = (LPSTR)_smalloc( windowNameLengthA + 1 );
2190 lstrcpyWtoA( windowNameA, windowNameW );
2191 }
2192
2193 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, windowNameA));
2194 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2195 {
2196 HandleNCPaint((HRGN)1);
2197 if(hTaskList) {
2198 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2199 }
2200 if(fOS2Look) {
2201 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
2202 }
2203 }
2204
2205 return TRUE;
2206 }
2207
2208 case WM_IME_CHAR:
2209 SendMessageW( getWindowHandle(), WM_CHAR, wParam, lParam );
2210 return 0;
2211
2212 default:
2213 return DefWindowProcA(Msg, wParam, lParam);
2214 }
2215}
2216//******************************************************************************
2217//******************************************************************************
2218void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2219{
2220 Win32BaseWindow *window = this;
2221 Win32BaseWindow *parentwindow;
2222
2223 while(window)
2224 {
2225 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2226 {
2227 /* Notify the parent window only */
2228 parentwindow = window->getParent();
2229 if(parentwindow) {
2230 /* PF We should map points for each window accordingly! */
2231 if (Msg == WM_LBUTTONDOWN || Msg == WM_MBUTTONDOWN || Msg == WM_RBUTTONDOWN)
2232 {
2233 POINTS pt = MAKEPOINTS(lParam);
2234 POINT point;
2235
2236 point.x = pt.x;
2237 point.y = pt.y;
2238
2239 MapWindowPoints(getWindowHandle(),parentwindow->getWindowHandle(), &point, 1);
2240 lParam = MAKELPARAM(point.x, point.y);
2241 }
2242 SendMessageA(parentwindow->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2243 }
2244
2245 }
2246 else break;
2247
2248 window = parentwindow;
2249 }
2250}
2251//******************************************************************************
2252// Returns the big or small icon for the window, falling back to the
2253// class as windows does.
2254//******************************************************************************
2255HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2256{
2257 HICON hWndIcon;
2258
2259 if (fType == ICON_BIG)
2260 {
2261 if (hIcon)
2262 hWndIcon = hIcon;
2263 else
2264 if (windowClass && windowClass->getIcon())
2265 hWndIcon = windowClass->getIcon();
2266 else
2267 if (!(dwStyle & DS_MODALFRAME))
2268 {//SvL: load it as shared or else we'll leak icons
2269 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
2270 }
2271 else hWndIcon = 0;
2272 }
2273 else
2274 {
2275 if (hIconSm)
2276 hWndIcon = hIconSm;
2277 else
2278 if (hIcon)
2279 hWndIcon = hIcon;
2280 else
2281 if (windowClass && windowClass->getIconSm())
2282 hWndIcon = windowClass->getIconSm();
2283 else
2284 if (windowClass && windowClass->getIcon())
2285 hWndIcon = windowClass->getIcon();
2286 else
2287 if (!(dwStyle & DS_MODALFRAME))
2288 {//SvL: load it as shared or else we'll leak icons
2289 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR|LR_SHARED);
2290 }
2291 else hWndIcon = 0;
2292 }
2293
2294 return hWndIcon;
2295}
2296//******************************************************************************
2297//******************************************************************************
2298BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2299{
2300 ULONG swp = 0;
2301 HWND hWinAfter;
2302 BOOL rc,wasVisible,showFlag;
2303 RECT newPos = {0, 0, 0, 0};
2304
2305 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2306 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2307
2308 dwOldStyle = getStyle();
2309
2310 /*
2311 * SW_SHOWDEFAULT is an reference to the startup info wShowWindow member.
2312 */
2313 if (nCmdShow == SW_SHOWDEFAULT)
2314 {
2315 nCmdShow = GetProcessDword(0, GPD_STARTF_SHOWWINDOW);
2316 dprintf(("ShowWindow: GetProcessDword(0, GPD_STARTF_SHOWWINDOW) -> %x", nCmdShow));
2317 }
2318
2319
2320 switch(nCmdShow)
2321 {
2322 case SW_HIDE:
2323 if (!wasVisible) goto END;
2324
2325 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2326 break;
2327
2328 case SW_SHOWMINNOACTIVE:
2329 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2330 /* fall through */
2331 case SW_SHOWMINIMIZED:
2332 swp |= SWP_SHOWWINDOW;
2333 /* fall through */
2334 case SW_MINIMIZE:
2335 swp |= SWP_FRAMECHANGED;
2336 if( !(getStyle() & WS_MINIMIZE) ) {
2337 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2338 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2339 }
2340 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2341 break;
2342
2343 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2344 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2345 if( !(getStyle() & WS_MAXIMIZE) ) {
2346 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2347 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2348 }
2349 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2350 break;
2351
2352 case SW_SHOWNA:
2353 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2354 /* fall through */
2355 case SW_SHOW:
2356 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2357
2358 /*
2359 * ShowWindow has a little peculiar behavior that if the
2360 * window is already the topmost window, it will not
2361 * activate it.
2362 */
2363 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2364 swp |= SWP_NOACTIVATE;
2365
2366 break;
2367
2368 case SW_SHOWNOACTIVATE:
2369 swp |= SWP_NOZORDER | SWP_NOACTIVATE;
2370 /* fall through */
2371 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2372 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2373 case SW_RESTORE:
2374 dprintf(("ShowWindow:restoring window"));
2375
2376 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2377 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2378 swp |= MinMaximize(SW_RESTORE, &newPos );
2379 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2380 }
2381 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2382 break;
2383 }
2384
2385 showFlag = (nCmdShow != SW_HIDE);
2386 if (showFlag != wasVisible)
2387 {
2388 SendMessageA(getWindowHandle(),WM_SHOWWINDOW, showFlag, 0 );
2389 if (!::IsWindow( getWindowHandle() )) goto END;
2390 }
2391
2392 /* We can't activate a child window */
2393 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2394 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2395
2396 if (!(getStyle() & WS_MINIMIZE)) {
2397 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp), TRUE);
2398 }
2399 else OSLibWinMinimizeWindow(getOS2FrameWindowHandle());
2400
2401 if(!(swp & SWP_NOACTIVATE) && (!(getStyle() & WS_MINIMIZE))) {
2402 OSLibWinSetActiveWindow(OS2HwndFrame);
2403 }
2404
2405 if (flags & WIN_NEED_SIZE)
2406 {
2407 /* should happen only in CreateWindowEx() */
2408 int wParam = SIZE_RESTORED;
2409
2410 flags &= ~WIN_NEED_SIZE;
2411 if (dwStyle & WS_MAXIMIZE)
2412 wParam = SIZE_MAXIMIZED;
2413 else
2414 if (dwStyle & WS_MINIMIZE)
2415 wParam = SIZE_MINIMIZED;
2416
2417 SendMessageA(getWindowHandle(),WM_SIZE, wParam,
2418 MAKELONG(rectClient.right-rectClient.left,
2419 rectClient.bottom-rectClient.top));
2420 SendMessageA(getWindowHandle(),WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2421 }
2422//testestest
2423 //temporary workaround for file dialogs with template dialog child
2424 //they don't redraw when switching directories
2425 //For some reason the new child's (syslistview32) update rectangle stays
2426 //empty after its parent is made visible with ShowWindow
2427 //TODO: find real cause
2428 if(!wasVisible) {
2429 InvalidateRect(getWindowHandle(), NULL, TRUE);
2430 }
2431//testestest
2432
2433END:
2434 fMinMaxChange = FALSE;
2435 return wasVisible;
2436}
2437//******************************************************************************
2438//******************************************************************************
2439BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
2440 int cy, UINT fuFlags, BOOL fShowWindow)
2441{
2442 BOOL rc = FALSE;
2443 Win32BaseWindow *window;
2444 HWND hParent = 0;
2445 RECT oldClientRect = rectClient;
2446
2447 if (fuFlags &
2448 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2449 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2450 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2451 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2452 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS))
2453 {
2454 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2455 return FALSE;
2456 }
2457
2458 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS)) {
2459 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2460 }
2461
2462 if(IsWindowDestroyed()) {
2463 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2464 dprintf(("SetWindowPos; window already destroyed"));
2465 return TRUE;
2466 }
2467
2468 if(state >= STATE_CREATED) {
2469 /* Fix redundant flags */
2470 if(getStyle() & WS_VISIBLE) {
2471 fuFlags &= ~SWP_SHOWWINDOW;
2472 }
2473 else
2474 {
2475 if (!(fuFlags & SWP_SHOWWINDOW))
2476 fuFlags |= SWP_NOREDRAW;
2477 fuFlags &= ~SWP_HIDEWINDOW;
2478 }
2479 //SvL: These checks are causing problems in Lotus Notes 6
2480 // It's not entirely clear why, but child windows are not placed
2481 // correctly when enabling them.
2482#if 0
2483 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2484 fuFlags |= SWP_NOSIZE; /* Already the right size */
2485 }
2486
2487 if((rectWindow.left == x) && (rectWindow.top == y)) {
2488 fuFlags |= SWP_NOMOVE; /* Already the right position */
2489 }
2490#endif
2491
2492 if(getWindowHandle() == GetActiveWindow()) {
2493 fuFlags |= SWP_NOACTIVATE; /* Already active */
2494 }
2495 else
2496 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2497 {
2498 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2499 {
2500 fuFlags &= ~SWP_NOZORDER;
2501 hwndInsertAfter = HWND_TOP;
2502 }
2503 }
2504 }
2505
2506 /* TODO: Check hwndInsertAfter */
2507
2508 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2509 if(state < STATE_POST_WMNCCREATE)
2510 {//don't change size; modify internal structures only
2511 //TODO: not 100% correct yet (activate)
2512 dprintf2(("state < STATE_POST_WMNCCREATE"));
2513 if(!(fuFlags & SWP_NOZORDER)) {
2514 hwndLinkAfter = hwndInsertAfter;
2515 }
2516 if(!(fuFlags & SWP_NOMOVE)) {
2517 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2518 rectWindow.top = y;
2519 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2520 rectWindow.left = x;
2521 }
2522 if(!(fuFlags & SWP_NOSIZE)) {
2523 rectWindow.bottom = rectWindow.top + cy;
2524 rectWindow.right = rectWindow.left + cx;
2525 }
2526 return TRUE;
2527 }
2528
2529 WINDOWPOS wpos;
2530 SWP swp, swpOld;
2531 wpos.flags = fuFlags;
2532 wpos.cy = cy;
2533 wpos.cx = cx;
2534 wpos.x = x;
2535 wpos.y = y;
2536 wpos.hwndInsertAfter = hwndInsertAfter;
2537 wpos.hwnd = getWindowHandle();
2538
2539 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2540 {
2541 if (isChild())
2542 {
2543 if(!getParent()) {
2544 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2545 }
2546 }
2547 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2548 }
2549 if((dwOldStyle & WS_MINIMIZE) && (getStyle() & WS_MINIMIZE))
2550 {//don't allow size changes if the window is minimized
2551 //we will update the restore position at the end of this method
2552 if(!(wpos.flags & SWP_NOSIZE)) {
2553 //TODO: updating the window rectangle doesn't look right
2554 wpos.flags |= SWP_NOSIZE;
2555 rectWindow.right = rectWindow.left + wpos.cx;
2556 rectWindow.bottom = rectWindow.top + wpos.cy;
2557 dprintf(("WARNING: Don't allow size change for minimized window; only save new restore position"));
2558 dprintf(("new window rectangle (%d,%d)(%d,%d)", rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2559 }
2560 }
2561
2562 // Hack alert: This makes sure the tooltips windows in OpenOffice don't
2563 // activate the owner windows too.
2564 // First condition takes care of SetWindowPos during window
2565 // creation. The 2nd one for calls made by OpenOffice
2566 if(((getStyle() & WS_POPUP) && (getExStyle() & WS_EX_TOPMOST)) || (fuFlags & SWP_NOOWNERZORDER))
2567 {
2568 //SWP_NOOWNERZORDER means only the z-order of this window changes; it
2569 //should not affect the owner
2570 //PM doesn't support this feature, so this hack might work
2571 wpos.flags |= SWP_NOZORDER;
2572 }
2573
2574 if(getParent()) {
2575 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2576 OS2HwndFrame);
2577 }
2578 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2579
2580 if (swp.fl == 0) {
2581 dprintf2(("swp.fl == 0"));
2582 if(fuFlags & SWP_FRAMECHANGED)
2583 {
2584 NotifyFrameChanged(&wpos, &oldClientRect);
2585 }
2586 if(!fShowWindow && !(getStyle() & (WS_MINIMIZE|WS_MAXIMIZE)) && !(fuFlags & (SWP_NOSIZE | SWP_NOMOVE)))
2587 {
2588 //Restore position always changes when the window position is changed
2589 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2590 windowpos.rcNormalPosition = rectWindow;
2591 }
2592 return TRUE;
2593 }
2594
2595// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2596 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2597 {
2598 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2599 if(wndBehind) {
2600 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2601 RELEASE_WNDOBJ(wndBehind);
2602 }
2603 else {
2604 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2605 swp.hwndInsertBehind = 0;
2606 }
2607 }
2608 swp.hwnd = OS2HwndFrame;
2609
2610 //SvL: Must also deactivate the window when hiding it or else focus won't
2611 // change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
2612 if((swp.fl & (SWPOS_HIDE|SWPOS_DEACTIVATE)) == (SWPOS_HIDE|SWPOS_DEACTIVATE))
2613 {
2614 //we must make sure the owner is not disabled or else the focus will
2615 //be switched to the wrong window
2616 Win32BaseWindow *topOwner;
2617
2618 if(getOwner() == NULL) {
2619 windowDesktop->addRef();
2620 topOwner = windowDesktop;
2621 }
2622 else topOwner = GetWindowFromHandle(getOwner()->GetTopParent());
2623
2624 if(topOwner != NULL) {
2625 DWORD dwStyle = topOwner->GetWindowLong(GWL_STYLE, FALSE);
2626 if(dwStyle & WS_DISABLED) {
2627 swp.fl &= ~SWPOS_DEACTIVATE;
2628 }
2629 }
2630 else DebugInt3();
2631 }
2632
2633 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2634 setStyle(getStyle() | WS_VISIBLE);
2635 if(hTaskList) {
2636 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2637 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2638 }
2639 }
2640 else
2641 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2642 setStyle(getStyle() & ~WS_VISIBLE);
2643 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2644 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2645 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2646 }
2647 }
2648 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2649
2650 rc = OSLibWinSetMultWindowPos(&swp, 1);
2651 if(rc == FALSE)
2652 {
2653 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2654 return 0;
2655 }
2656
2657 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2658 {
2659 NotifyFrameChanged(&wpos, &oldClientRect);
2660 }
2661 if(!fShowWindow && !(getStyle() & (WS_MINIMIZE|WS_MAXIMIZE)))
2662 {
2663 //Restore position always changes when the window position is changed
2664 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2665 windowpos.rcNormalPosition = rectWindow;
2666 }
2667 //MSDN says the entire client area will be invalidated when SWP_NOCOPYBITS
2668 //is specified (fixes repaint issues when window is made smaller)
2669 if((fuFlags & (SWP_NOCOPYBITS|SWP_NOREDRAW)) == SWP_NOCOPYBITS) {
2670 InvalidateRect(getWindowHandle(), NULL, TRUE);
2671 }
2672
2673 if(!(fuFlags & SWP_NOSIZE))
2674 {
2675 // We must call this function or open DC will get out of sync
2676 // (PM will not always send us a WM_VRNENABLED message)
2677 RecalcVisibleRegion(this);
2678 }
2679 return (rc);
2680}
2681//******************************************************************************
2682//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2683//******************************************************************************
2684BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2685{
2686 rectWindow.left += dx;
2687 rectWindow.right += dx;
2688 rectWindow.top += dy;
2689 rectWindow.bottom += dy;
2690 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2691 return TRUE;
2692}
2693//******************************************************************************
2694//******************************************************************************
2695void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2696{
2697 HRGN hrgn, hrgnClient;
2698 RECT rect;
2699
2700 MsgFormatFrame(NULL);
2701
2702 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2703 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2704 {
2705 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2706 wpos->cx = RECT_WIDTH(rectWindow);
2707 wpos->cy = RECT_HEIGHT(rectWindow);
2708 }
2709
2710 if(rectClient.left != oldClientRect->left ||
2711 rectClient.top != oldClientRect->top)
2712 {
2713 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2714 wpos->x = rectWindow.left;
2715 wpos->y = rectWindow.top;
2716 }
2717
2718 WINDOWPOS wpOld = *wpos;
2719 if(!(wpos->flags & SWP_NOSENDCHANGING))
2720 SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2721
2722 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2723 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2724 {
2725 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2726 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2727 }
2728 else SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2729
2730 //Calculate invalid areas
2731 rect = rectWindow;
2732 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2733 hrgn = CreateRectRgnIndirect(&rect);
2734 if (!hrgn) {
2735 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2736 return;
2737 }
2738 rect = rectClient;
2739 hrgnClient = CreateRectRgnIndirect(&rect);
2740 if (!hrgn) {
2741 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2742 return;
2743 }
2744 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2745 DeleteObject(hrgnClient);
2746
2747 if(!EqualRect(oldClientRect, &rectClient)) {
2748 UnionRect(oldClientRect, oldClientRect, &rectClient);
2749 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2750 if (!hrgn) {
2751 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2752 return;
2753 }
2754 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2755 DeleteObject(hrgnClient);
2756 }
2757 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2758 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2759 DeleteObject(hrgn);
2760}
2761//******************************************************************************
2762//TODO: Check how this api really works in NT
2763//******************************************************************************
2764BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2765{
2766 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2767 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2768 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2769 windowpos.ptMinPosition = wndpl->ptMinPosition;
2770 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2771 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2772
2773 if(getStyle() & WS_MINIMIZE )
2774 {
2775 //TODO: Why can't this be (0,0)?
2776 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2777 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2778 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2779 }
2780 }
2781 else
2782 if(getStyle() & WS_MAXIMIZE )
2783 {
2784 //TODO: Why can't this be (0,0)?
2785 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2786 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2787 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2788 }
2789 else {
2790 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2791 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2792 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2793 SWP_NOZORDER | SWP_NOACTIVATE );
2794 }
2795 ShowWindow(wndpl->showCmd);
2796 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2797 {
2798 /* SDK: ...valid only the next time... */
2799 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2800 setFlags(getFlags() | WIN_RESTORE_MAX);
2801 }
2802 return TRUE;
2803}
2804//******************************************************************************
2805//******************************************************************************
2806BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2807{
2808 wndpl->length = sizeof(*wndpl);
2809 if(getStyle() & WS_MINIMIZE )
2810 wndpl->showCmd = SW_SHOWMINIMIZED;
2811 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2812
2813 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2814 if(getFlags() & WIN_RESTORE_MAX )
2815 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2816 else wndpl->flags = 0;
2817
2818 wndpl->ptMinPosition = windowpos.ptMinPosition;
2819 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2820 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2821 wndpl->rcNormalPosition = windowpos.rcNormalPosition;
2822
2823 return TRUE;
2824}
2825//******************************************************************************
2826//Also destroys all the child windows (destroy children first, parent last)
2827//TODO: Don't rely on PM to do the right thing. Send WM_(NC)DESTROY &
2828// destroy children ourselves (see Wine)
2829//******************************************************************************
2830BOOL Win32BaseWindow::DestroyWindow()
2831{
2832 HWND hwnd = getWindowHandle();
2833
2834 dprintf(("DestroyWindow %x", hwnd));
2835
2836#if 0
2837 /* Look whether the focus is within the tree of windows we will
2838 * be destroying.
2839 */
2840 HWND hwndFocus = GetFocus();
2841 if (hwndFocus == hwnd || ::IsChild( hwnd, hwndFocus ))
2842 {
2843 HWND parent = GetAncestor( hwnd, GA_PARENT );
2844 if (parent == GetDesktopWindow()) parent = 0;
2845 SetFocus( parent );
2846 }
2847#endif
2848 /* Call hooks */
2849 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2850 {
2851 return FALSE;
2852 }
2853
2854 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2855 {
2856 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2857 /* FIXME: clean up palette - see "Internals" p.352 */
2858 }
2859
2860 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2861 {
2862 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2863 {
2864 /* Notify the parent window only */
2865 SendMessageA(getParent()->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2866 if(!::IsWindow(hwnd) )
2867 {
2868 return TRUE;
2869 }
2870 }
2871//// else DebugInt3();
2872 }
2873 //Must remove the switch entry here to avoid problems with XWorkPlace
2874 if(hTaskList) {
2875 OSLibWinRemoveFromTasklist(hTaskList);
2876 hTaskList = 0;
2877 }
2878
2879 /* Hide the window */
2880 if(IsWindowVisible(getWindowHandle()))
2881 {
2882 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2883 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2884 if(!::IsWindow(hwnd))
2885 {
2886 return TRUE;
2887 }
2888 }
2889 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2890
2891 // check the handle for the last active popup window
2892 Win32BaseWindow* owner = getOwner();
2893 if (NULL != owner)
2894 {
2895 if (owner->getLastActive() == hwnd)
2896 owner->setLastActive( owner->getWindowHandle() );
2897
2898 //SvL: Not sure this is correct, but it solves the problem of reassigning
2899 // activation. A disabled window will never be activated ->
2900 // possible that the wrong window is chosen by PM.
2901 // PM chooses another window to be activated before WM_DESTROY is
2902 // sent. VPC enables the owner when it receives that message,
2903 // but by then it's too late.
2904 // (MFC created modeless dialog)
2905 //TODO: This might be the wrong place to do it. EndDialog is called,
2906 // so perhaps it should be done there. (although Wine only
2907 // enables the owner if the dialog is modal)
2908 ::EnableWindow(owner->getWindowHandle(), 1);
2909 }
2910
2911 fDestroyWindowCalled = TRUE;
2912
2913//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2914// handler; must postpone it
2915 if(fChildDestructionInProgress) {
2916 dprintf(("Postponing parent destruction because of dying child"));
2917 OSLibPostMessageDirect(OS2HwndFrame, WIN32APP_POSTPONEDESTROY, 0, 0);
2918 return TRUE;
2919 }
2920
2921 BOOL fOldChildDestructionInProgress = FALSE;
2922 if(GetParent()) {
2923 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2924 if(window) {
2925 fOldChildDestructionInProgress = window->IsChildDestructionInProgress();
2926 window->SetChildDestructionInProgress(TRUE);
2927 RELEASE_WNDOBJ(window);
2928 }
2929 }
2930//hack end
2931
2932 BOOL ret = OSLibWinDestroyWindow(OS2HwndFrame);
2933
2934//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2935// handler; must postpone it
2936 if(GetParent()) {
2937 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2938 if(window) {
2939 window->SetChildDestructionInProgress(fOldChildDestructionInProgress);
2940 RELEASE_WNDOBJ(window);
2941 }
2942 }
2943//hack end
2944 return ret;
2945}
2946//******************************************************************************
2947//******************************************************************************
2948Win32BaseWindow *Win32BaseWindow::getParent()
2949{
2950 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2951 //experiment
2952#if 0
2953 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2954#else
2955 return wndparent;
2956#endif
2957}
2958//******************************************************************************
2959// Win32BaseWindow::GetParent
2960//
2961// If the window is a child window, then return the parent window handle.
2962// If it's a popup window, then return the owner
2963//
2964// Returns window handle of parent or owner window
2965//
2966// Note: does not set last error if no parent (verified in NT4, SP6)
2967//******************************************************************************
2968HWND Win32BaseWindow::GetParent()
2969{
2970 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2971
2972 if(getStyle() & WS_CHILD)
2973 {
2974 if(wndparent) {
2975 return wndparent->getWindowHandle();
2976 }
2977 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2978 DebugInt3();
2979 return 0;
2980 }
2981 else
2982 if(getStyle() & WS_POPUP)
2983 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2984 else return 0;
2985}
2986//******************************************************************************
2987//******************************************************************************
2988HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2989{
2990 HWND oldhwnd;
2991 Win32BaseWindow *newparent;
2992 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2993 BOOL fShow = FALSE;
2994
2995 if(oldparent) {
2996 oldhwnd = oldparent->getWindowHandle();
2997 oldparent->removeChild(this);
2998 }
2999 else oldhwnd = 0;
3000
3001 /* Windows hides the window first, then shows it again
3002 * including the WM_SHOWWINDOW messages and all */
3003 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
3004 ShowWindow(SW_HIDE);
3005 fShow = TRUE;
3006 }
3007 if(oldparent) {
3008 //release parent here (increased refcount during creation)
3009 RELEASE_WNDOBJ(oldparent);
3010 }
3011 newparent = GetWindowFromHandle(hwndNewParent);
3012 if(newparent && !newparent->isDesktopWindow())
3013 {
3014 setParent(newparent);
3015 getParent()->addChild(this);
3016 fParentChange = TRUE;
3017 // in case we haven't finished creating the window whose parent we're
3018 // setting here, the OS/2 HWND might not exist yet and we call the PM
3019 // API with a NULLHANDLE - no problem
3020 // when we create the OS/2 window lateron, we will create it with the
3021 // right parent anyway.
3022 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
3023 if(!(getStyle() & WS_CHILD))
3024 {
3025 if(getWindowId())
3026 {
3027 DestroyMenu( (HMENU) getWindowId() );
3028 setWindowId(0);
3029 }
3030 }
3031 //SvL: Even though the win32 coordinates might not change, the PM
3032 // coordinates can. We must make sure the control stays at the
3033 // same position (y) relative to the (new) parent.
3034 // TODO: shouldn't we check the state of the window and not do it in INIT state?
3035 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
3036 SWP_NOACTIVATE|SWP_NOSIZE);
3037 fParentChange = FALSE;
3038 }
3039 else {
3040 if(newparent) RELEASE_WNDOBJ(newparent);
3041
3042 setParent(windowDesktop);
3043 windowDesktop->addRef();
3044 windowDesktop->addChild(this);
3045 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
3046
3047 //Do not change the window id!
3048//// setWindowId(0);
3049 }
3050 /* SetParent additionally needs to make hwndChild the topmost window
3051 in the x-order and send the expected WM_WINDOWPOSCHANGING and
3052 WM_WINDOWPOSCHANGED notification messages.
3053 */
3054 if(state >= STATE_PRE_WMNCCREATE) {
3055 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
3056 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
3057
3058 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
3059 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
3060 }
3061 return oldhwnd;
3062}
3063//******************************************************************************
3064//******************************************************************************
3065BOOL Win32BaseWindow::IsChild(HWND hwndParent)
3066{
3067 // PH: Optimizer won't unroll calls to getParent() even
3068 // in release build.
3069 Win32BaseWindow *_parent = getParent();
3070
3071 if(_parent)
3072 {
3073 if(_parent->getWindowHandle() == hwndParent)
3074 return TRUE;
3075
3076 return _parent->IsChild(hwndParent);
3077 }
3078 else
3079 return 0;
3080}
3081//******************************************************************************
3082//******************************************************************************
3083HWND Win32BaseWindow::GetTopWindow()
3084{
3085 HWND hwndTop;
3086 Win32BaseWindow *topwindow;
3087
3088 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3089 if(!isDesktopWindow())
3090 {
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 return 0;
3104 }
3105 while(hwndTop) {
3106 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3107 //Note: GetTopWindow can't return a window that hasn't processed
3108 // WM_NCCREATE yet (verified in NT4, SP6)
3109 if(topwindow) {
3110 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3111 hwndTop = topwindow->getWindowHandle();
3112 }
3113 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3114 RELEASE_WNDOBJ(topwindow);
3115 return hwndTop;
3116 }
3117 if(topwindow) RELEASE_WNDOBJ(topwindow);
3118 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
3119 }
3120
3121 return 0;
3122}
3123//******************************************************************************
3124// Get the top-level parent for a child window.
3125//******************************************************************************
3126HWND Win32BaseWindow::GetTopParent()
3127{
3128 Win32BaseWindow *window = this;
3129 HWND hwndTopParent = 0;
3130
3131 lock();
3132 while(window && (window->getStyle() & WS_CHILD))
3133 {
3134 window = window->getParent();
3135 }
3136 if(window) {
3137 hwndTopParent = window->getWindowHandle();
3138 }
3139 unlock();
3140 return hwndTopParent;
3141}
3142//******************************************************************************
3143//TODO: Should not enumerate children that are created during the enumeration!
3144//TODO: Do this more efficiently
3145//******************************************************************************
3146BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
3147{
3148 BOOL rc = TRUE;
3149 HWND hwnd;
3150 Win32BaseWindow *prevchild = 0, *child = 0;
3151
3152 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3153 lock();
3154 for (child = (Win32BaseWindow *)getFirstChild(); child != NULL; child = (Win32BaseWindow *)child->getNextChild())
3155 {
3156 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3157 hwnd = child->getWindowHandle();
3158 if(child->IsWindowDestroyed() || child->getOwner()) {
3159 continue; //shouldn't have an owner (Wine)
3160 }
3161 child->addRef();
3162 unlock();
3163 if(WrapCallback2((WNDPROC)lpfn, hwnd, lParam) == FALSE)
3164 {
3165 child->release();
3166 return FALSE;
3167 }
3168 child->release();
3169 lock();
3170 //check if the window still exists
3171 if(!::IsWindow(hwnd))
3172 {
3173 child = prevchild;
3174 if(child == NULL) break;
3175 continue;
3176 }
3177 if(child->getFirstChild() != NULL)
3178 {
3179 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3180 child->addRef();
3181 unlock();
3182 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3183 {
3184 child->release();
3185 return FALSE;
3186 }
3187 child->release();
3188 lock();
3189 }
3190 prevchild = child;
3191 }
3192 unlock();
3193 return rc;
3194}
3195//******************************************************************************
3196//Enumerate first-level children only and check thread id
3197//NOTE: NT4 returns first-level children in Z-order!
3198//******************************************************************************
3199BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3200{
3201 Win32BaseWindow *wnd = NULL;
3202 HWND henum, hwnd, hwndWin32;
3203 ULONG tid, pid;
3204 BOOL rc;
3205
3206 //Enumerate all top-level windows and check the process and thread ids
3207 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3208 hwnd = OSLibWinGetNextWindow(henum);
3209
3210 while(hwnd)
3211 {
3212 wnd = GetWindowFromOS2FrameHandle(hwnd);
3213 if(wnd) {
3214 hwndWin32 = wnd->getWindowHandle();
3215 }
3216 else hwndWin32 = 0;
3217
3218 if(wnd) RELEASE_WNDOBJ(wnd);
3219
3220 if(hwndWin32) {
3221 OSLibWinQueryWindowProcess(hwnd, &pid, &tid);
3222
3223 if(dwThreadId == tid) {
3224 dprintf(("EnumThreadWindows: Found Window %x", hwndWin32));
3225 if((rc = WrapCallback2((WNDPROC)lpfn, hwndWin32, lParam)) == FALSE) {
3226 break;
3227 }
3228 }
3229 }
3230 hwnd = OSLibWinGetNextWindow(henum);
3231 }
3232 OSLibWinEndEnumWindows(henum);
3233 return TRUE;
3234}
3235//******************************************************************************
3236//Enumerate first-level children only
3237//******************************************************************************
3238BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3239{
3240 Win32BaseWindow *window;
3241 BOOL rc;
3242 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
3243 DWORD dwStyle;
3244
3245 dprintf(("EnumWindows %x %x", lpfn, lParam));
3246
3247 for(int i=0;i<MAX_WINDOW_HANDLES;i++)
3248 {
3249 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3250 if(window) {
3251 if(window->getWindowHandle() != hwnd) {
3252 dprintf(("CORRUPT WINDOW %x %x", window, hwnd));
3253 }
3254 RELEASE_WNDOBJ(window);
3255 dwStyle = ::GetWindowLongA(hwnd, GWL_STYLE);
3256 if ((dwStyle & WS_POPUP) || ((dwStyle & WS_CAPTION) == WS_CAPTION))
3257 {
3258 dprintf2(("EnumWindows: Found Window %x", hwnd));
3259 if((rc = WrapCallback2((WNDPROC)lpfn, hwnd, lParam)) == FALSE) {
3260 break;
3261 }
3262 }
3263 }
3264 hwnd++;
3265 }
3266 return TRUE;
3267}
3268//******************************************************************************
3269//******************************************************************************
3270HWND Win32BaseWindow::FindWindowById(int id)
3271{
3272 HWND hwnd;
3273
3274 lock();
3275 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3276 {
3277 if (child->getWindowId() == id)
3278 {
3279 hwnd = child->getWindowHandle();
3280 unlock();
3281 return hwnd;
3282 }
3283 }
3284 unlock();
3285 return 0;
3286}
3287//******************************************************************************
3288//TODO:
3289//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3290//the current process owns them.
3291//******************************************************************************
3292HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3293{
3294 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3295 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3296 Win32BaseWindow *firstchild = child;
3297
3298 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3299 if((hwndParent != 0 && !parent) ||
3300 (hwndChildAfter != 0 && !child) ||
3301 (hwndParent == 0 && hwndChildAfter != 0))
3302 {
3303 if(parent) RELEASE_WNDOBJ(parent);
3304 if(firstchild) RELEASE_WNDOBJ(firstchild);
3305 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3306 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3307 return 0;
3308 }
3309 SetLastError(0);
3310 if(hwndParent != 0)
3311 {//if the current process owns the window, just do a quick search
3312 lock(&critsect);
3313 child = (Win32BaseWindow *)parent->getFirstChild();
3314 if(hwndChildAfter != 0)
3315 {
3316 while(child)
3317 {
3318 if(child->getWindowHandle() == hwndChildAfter)
3319 {
3320 child = (Win32BaseWindow *)child->getNextChild();
3321 break;
3322 }
3323 child = (Win32BaseWindow *)child->getNextChild();
3324 }
3325 }
3326 while(child)
3327 {
3328 //According to Wine, the class doesn't need to be specified
3329 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3330 (!lpszWindow || child->hasWindowName(lpszWindow)))
3331 {
3332 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3333 HWND hwndChild = child->getWindowHandle();
3334 unlock(&critsect);
3335 if(parent) RELEASE_WNDOBJ(parent);
3336 if(firstchild) RELEASE_WNDOBJ(firstchild);
3337 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3338 return hwndChild;
3339 }
3340 child = (Win32BaseWindow *)child->getNextChild();
3341 }
3342 unlock(&critsect);
3343 if(parent) RELEASE_WNDOBJ(parent);
3344 if(firstchild) RELEASE_WNDOBJ(firstchild);
3345 }
3346 else {
3347 Win32BaseWindow *wnd;
3348 HWND henum, hwnd;
3349
3350 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3351 hwnd = OSLibWinGetNextWindow(henum);
3352
3353 while(hwnd)
3354 {
3355 wnd = GetWindowFromOS2FrameHandle(hwnd);
3356 if(wnd) {
3357 //According to Wine, the class doesn't need to be specified
3358 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3359 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3360 {
3361 OSLibWinEndEnumWindows(henum);
3362 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3363 HWND hwndret = wnd->getWindowHandle();
3364 RELEASE_WNDOBJ(wnd);
3365 return hwndret;
3366 }
3367 RELEASE_WNDOBJ(wnd);
3368 }
3369 hwnd = OSLibWinGetNextWindow(henum);
3370 }
3371 OSLibWinEndEnumWindows(henum);
3372 if(parent) RELEASE_WNDOBJ(parent);
3373 if(firstchild) RELEASE_WNDOBJ(firstchild);
3374 }
3375 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3376 return 0;
3377}
3378//******************************************************************************
3379//******************************************************************************
3380HWND Win32BaseWindow::GetWindow(UINT uCmd)
3381{
3382 HWND hwndRelated = 0;
3383 Win32BaseWindow *window;
3384
3385 switch(uCmd)
3386 {
3387 case GW_HWNDFIRST:
3388 window = (Win32BaseWindow *)getParent();
3389 if(window)
3390 {
3391 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3392 window = GetWindowFromOS2FrameHandle(hwndRelated);
3393 if(window) {
3394 hwndRelated = window->getWindowHandle();
3395 RELEASE_WNDOBJ(window);
3396 }
3397 else hwndRelated = 0;
3398 }
3399 else {
3400 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3401 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3402 }
3403 break;
3404
3405 case GW_HWNDLAST:
3406 window = (Win32BaseWindow *)getParent();
3407 if(window) {
3408 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3409 dprintf(("os2 handle %x", hwndRelated));
3410 window = GetWindowFromOS2FrameHandle(hwndRelated);
3411 if(window) {
3412 hwndRelated = window->getWindowHandle();
3413 RELEASE_WNDOBJ(window);
3414 }
3415 else hwndRelated = 0;
3416 }
3417 else {
3418 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3419 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3420 }
3421 break;
3422
3423 case GW_HWNDNEXT:
3424 if(getParent()) {
3425 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3426 window = GetWindowFromOS2FrameHandle(hwndRelated);
3427 if(window) {
3428 hwndRelated = window->getWindowHandle();
3429 RELEASE_WNDOBJ(window);
3430 }
3431 else hwndRelated = 0;
3432 }
3433 else {
3434 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3435 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3436 }
3437 break;
3438
3439 case GW_HWNDPREV:
3440 if(getParent()) {
3441 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3442 window = GetWindowFromOS2FrameHandle(hwndRelated);
3443 if(window) {
3444 hwndRelated = window->getWindowHandle();
3445 RELEASE_WNDOBJ(window);
3446 }
3447 else hwndRelated = 0;
3448 }
3449 else {
3450 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3451 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3452 }
3453 break;
3454
3455 case GW_OWNER:
3456 {
3457 Win32BaseWindow *owner = getOwner();
3458 if(owner) {
3459 hwndRelated = owner->getWindowHandle();
3460 }
3461 break;
3462 }
3463
3464 case GW_CHILD:
3465 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3466 window = GetWindowFromOS2FrameHandle(hwndRelated);
3467
3468 //Before a window has processed WM_NCCREATE:
3469 //- GetWindow(parent, GW_CHILD) can't return that window handle
3470 //(verified in NT4, SP6)
3471 if(window) {
3472 if(window->state >= STATE_POST_WMNCCREATE) {
3473 hwndRelated = window->getWindowHandle();
3474 RELEASE_WNDOBJ(window);
3475 }
3476 else {
3477 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3478 RELEASE_WNDOBJ(window);
3479 }
3480 }
3481 else hwndRelated = 0;
3482
3483 break;
3484
3485 //for internal use only
3486 case GW_HWNDNEXTCHILD:
3487 lock();
3488 window = (Win32BaseWindow *)getNextChild();
3489 if(window) {
3490 hwndRelated = window->getWindowHandle();
3491 }
3492 else hwndRelated = 0;
3493 unlock();
3494 break;
3495
3496 case GW_HWNDPREVCHILD:
3497 DebugInt3();
3498 break;
3499
3500 case GW_HWNDFIRSTCHILD:
3501 lock();
3502 window = (Win32BaseWindow *)getFirstChild();
3503 if(window) {
3504 hwndRelated = window->getWindowHandle();
3505 }
3506 else hwndRelated = 0;
3507 unlock();
3508 break;
3509
3510 case GW_HWNDLASTCHILD:
3511 lock();
3512 window = (Win32BaseWindow *)getFirstChild();
3513 if(window) {
3514 while (window->getNextChild())
3515 {
3516 window = (Win32BaseWindow *)window->getNextChild();
3517 }
3518 hwndRelated = window->getWindowHandle();
3519 }
3520 else hwndRelated = 0;
3521 unlock();
3522 break;
3523 }
3524end:
3525 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3526 return hwndRelated;
3527}
3528//******************************************************************************
3529//******************************************************************************
3530PRECT Win32BaseWindow::getWindowRect()
3531{
3532 return &rectWindow;
3533}
3534//******************************************************************************
3535//******************************************************************************
3536HWND Win32BaseWindow::SetActiveWindow()
3537{
3538 HWND hwndActive;
3539
3540 dprintf(("SetActiveWindow %x", getWindowHandle()));
3541 if(getStyle() & WS_CHILD) {
3542// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3543 dprintf(("WARNING: Window is a child or disabled"));
3544 return 0;
3545 }
3546
3547 if(GetActiveWindow() == getWindowHandle()) {
3548 dprintf(("Window already active"));
3549 return getWindowHandle();
3550 }
3551 if (HOOK_IsHooked( WH_CBT ))
3552 {
3553 CBTACTIVATESTRUCT cbta;
3554 LRESULT ret;
3555
3556 cbta.fMouse = FALSE;
3557 cbta.hWndActive = GetActiveWindow();
3558 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3559 if(ret)
3560 {
3561 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3562 return cbta.hWndActive;
3563 }
3564 }
3565 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3566
3567// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3568// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3569// }
3570 hwndActive = GetActiveWindow();
3571 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3572}
3573//******************************************************************************
3574//Used to change active status of an mdi window
3575//******************************************************************************
3576BOOL Win32BaseWindow::DeactivateChildWindow()
3577{
3578 /* child windows get a WM_CHILDACTIVATE message */
3579 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3580 {
3581 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3582 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3583 return TRUE;
3584 }
3585 DebugInt3(); //should not be called for non-child window
3586 return FALSE;
3587}
3588//******************************************************************************
3589//WM_ENABLE is sent to hwnd, but not to its children (as it should be)
3590//******************************************************************************
3591BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3592{
3593 BOOL rc;
3594
3595 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3596 //return true if previous state was disabled, else false (sdk docs)
3597 rc = (getStyle() & WS_DISABLED) != 0;
3598 if(rc && !fEnable) {
3599 SendMessageA(getWindowHandle(), WM_CANCELMODE, 0, 0);
3600 }
3601 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3602 if(fEnable == FALSE) {
3603 //SvL: No need to clear focus as PM already does this
3604 if(getWindowHandle() == GetCapture()) {
3605 ReleaseCapture(); /* A disabled window can't capture the mouse */
3606 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3607 }
3608 }
3609 return rc;
3610}
3611//******************************************************************************
3612//******************************************************************************
3613BOOL Win32BaseWindow::CloseWindow()
3614{
3615 if (::GetWindowLongW( getWindowHandle() , GWL_STYLE ) & WS_CHILD) return FALSE;
3616 ShowWindow( SW_MINIMIZE );
3617 return TRUE;
3618}
3619//******************************************************************************
3620//TODO: Not be 100% correct; should return active window of current thread
3621// or NULL when there is none -> WinQueryActiveWindow just returns
3622// the current active window
3623//******************************************************************************
3624HWND Win32BaseWindow::GetActiveWindow()
3625{
3626 HWND hwndActive;
3627
3628 hwndActive = OSLibWinQueryActiveWindow();
3629 return OS2ToWin32Handle(hwndActive);
3630}
3631//******************************************************************************
3632//******************************************************************************
3633BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3634{
3635 INT len = GetWindowTextLength(fUnicode);
3636 BOOL res;
3637
3638 if (wndname == NULL)
3639 return (len == 0);
3640
3641 len++;
3642 if (fUnicode)
3643 {
3644 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3645
3646 GetWindowTextW(text,len);
3647 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3648 free(text);
3649 }
3650 else
3651 {
3652 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3653
3654 GetWindowTextA(text,len);
3655 res = (strcmp(text,wndname) == 0);
3656 free(text);
3657 }
3658
3659 return res;
3660}
3661//******************************************************************************
3662//******************************************************************************
3663CHAR *Win32BaseWindow::getWindowNamePtrA()
3664{
3665 INT len = GetWindowTextLength(FALSE);
3666 CHAR *text;
3667
3668 if (len == 0) return NULL;
3669 len++;
3670 text = (CHAR*)malloc(len*sizeof(CHAR));
3671 GetWindowTextA(text,len);
3672
3673 return text;
3674}
3675//******************************************************************************
3676//******************************************************************************
3677WCHAR *Win32BaseWindow::getWindowNamePtrW()
3678{
3679 INT len = GetWindowTextLength(TRUE);
3680 WCHAR *text;
3681
3682 if (len == 0) return NULL;
3683 len++;
3684 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3685 GetWindowTextW(text,len);
3686
3687 return text;
3688}
3689//******************************************************************************
3690//******************************************************************************
3691VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3692{
3693 if (namePtr) free(namePtr);
3694}
3695//******************************************************************************
3696//When using this API for a window that was created by a different process, NT
3697//does NOT send WM_GETTEXTLENGTH.
3698//******************************************************************************
3699int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3700{
3701 //if the destination window is created by this process, send message
3702 if(dwProcessId == currentProcessId)
3703 {
3704 if(fUnicode) {
3705 return SendMessageW(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3706 }
3707 else return SendMessageA(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3708 }
3709 //else get data directory from window structure
3710 //TODO: must lock window structure.... (TODO)
3711 return fUnicode ? windowNameLengthW : windowNameLengthA;
3712}
3713//******************************************************************************
3714//When using this API for a window that was created by a different process, NT
3715//does NOT send WM_GETTEXT.
3716//******************************************************************************
3717int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3718{
3719 //if the destination window is created by this process, send message
3720 if(dwProcessId == currentProcessId) {
3721 return SendMessageA(getWindowHandle(),WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3722 }
3723
3724 //else get data directory from window structure
3725 if (!lpsz || !cch) return 0;
3726 if (!windowNameA) lpsz[0] = 0;
3727 else lstrcpynA( lpsz, windowNameA, cch );
3728 return strlen( lpsz );
3729}
3730//******************************************************************************
3731//When using this API for a window that was created by a different process, NT
3732//does NOT send WM_GETTEXT.
3733//******************************************************************************
3734int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3735{
3736 //if the destination window is created by this process, send message
3737 if(dwProcessId == currentProcessId) {
3738 return ::SendMessageW(getWindowHandle(), WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3739 }
3740 //else get data directory from window structure
3741 if (!lpsz || !cch)
3742 return 0;
3743 if (!windowNameW)
3744 lpsz[0] = 0;
3745 else
3746 lstrcpynW( lpsz, windowNameW, cch );
3747
3748 return strlenW( lpsz );
3749}
3750//******************************************************************************
3751//TODO: How does this work when the target window belongs to a different process???
3752//******************************************************************************
3753BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3754{
3755 return SendMessageA(getWindowHandle(),WM_SETTEXT,0,(LPARAM)lpsz);
3756}
3757//******************************************************************************
3758//******************************************************************************
3759BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3760{
3761 return SendMessageW(getWindowHandle(), WM_SETTEXT,0,(LPARAM)lpsz);
3762}
3763//******************************************************************************
3764//******************************************************************************
3765LONG Win32BaseWindow::SetWindowLong(int index, ULONG value, BOOL fUnicode)
3766{
3767 LONG oldval;
3768
3769 switch(index) {
3770 case GWL_EXSTYLE:
3771 {
3772 STYLESTRUCT ss;
3773
3774 if(dwExStyle == value) {
3775 oldval = value;
3776 break;
3777 }
3778 ss.styleOld = dwExStyle;
3779 ss.styleNew = value;
3780 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3781 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3782 setExStyle(ss.styleNew);
3783 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3784
3785 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3786 getStyle(), getExStyle(),ss.styleOld);
3787
3788 oldval = ss.styleOld;
3789 break;
3790 }
3791 case GWL_STYLE:
3792 {
3793 STYLESTRUCT ss;
3794
3795 //SvL: TODO: Can you change minimize or maximize status here too?
3796
3797 if(dwStyle == value) {
3798 oldval = value;
3799 break;
3800 }
3801 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3802
3803 //Changing WS_CHILD style is allowed
3804 ss.styleOld = getStyle();
3805 ss.styleNew = value;
3806 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3807 setStyle(ss.styleNew);
3808 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3809
3810 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3811 getStyle(), getExStyle(),ss.styleOld);
3812
3813 //TODO: Might not be correct to use ShowWindow here
3814 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3815 if(ss.styleNew & WS_VISIBLE)
3816 ShowWindow(SW_SHOWNOACTIVATE);
3817 else ShowWindow(SW_HIDE);
3818 }
3819
3820#ifdef DEBUG
3821 PrintWindowStyle(ss.styleNew, 0);
3822#endif
3823 oldval = ss.styleOld;
3824 break;
3825 }
3826 case GWL_WNDPROC:
3827 {
3828 //Note: Type of SetWindowLong determines new window proc type
3829 // UNLESS the new window proc has already been registered
3830 // (use the old type in that case)
3831 // (VERIFIED in NT 4, SP6)
3832 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3833 if(type == WIN_PROC_INVALID) {
3834 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3835 }
3836 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3837 dprintf(("SetWindowLong%c GWL_WNDPROC %x old %x new wndproc %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), oldval, value));
3838 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3839 break;
3840 }
3841 case GWL_HINSTANCE:
3842 oldval = hInstance;
3843 hInstance = value;
3844 break;
3845
3846 case GWL_HWNDPARENT:
3847 dprintf(("GWL_ID GWL_HWNDPARENT %x, new %x", GetParent(), value));
3848 oldval = SetParent((HWND)value);
3849 break;
3850
3851 case GWL_ID:
3852 dprintf(("GWL_ID old %x, new %x", getWindowId(), value));
3853 oldval = getWindowId();
3854 setWindowId(value);
3855 break;
3856
3857 case GWL_USERDATA:
3858 oldval = userData;
3859 userData = value;
3860 break;
3861
3862 default:
3863 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3864 {
3865 oldval = *(ULONG *)(userWindowBytes + index);
3866 *(ULONG *)(userWindowBytes + index) = value;
3867 break;
3868 }
3869 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3870 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3871 return 0;
3872 }
3873 //Note: NT4, SP6 does not set the last error to 0
3874 SetLastError(ERROR_SUCCESS);
3875 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3876 return oldval;
3877}
3878//******************************************************************************
3879//******************************************************************************
3880ULONG Win32BaseWindow::GetWindowLong(int index, BOOL fUnicode)
3881{
3882 ULONG value;
3883
3884 switch(index) {
3885 case GWL_EXSTYLE:
3886 value = dwExStyle;
3887 break;
3888 case GWL_STYLE:
3889 value = dwStyle;
3890 break;
3891 case GWL_WNDPROC:
3892 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3893 break;
3894 case GWL_HINSTANCE:
3895 value = hInstance;
3896 break;
3897 case GWL_HWNDPARENT:
3898 value = GetParent();
3899 break;
3900 case GWL_ID:
3901 value = getWindowId();
3902 break;
3903 case GWL_USERDATA:
3904 value = userData;
3905 break;
3906 default:
3907 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3908 {
3909 value = *(ULONG *)(userWindowBytes + index);
3910 break;
3911 }
3912 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3913 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3914 return 0;
3915 }
3916 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3917 //Note: NT4, SP6 does not set the last error to 0
3918 SetLastError(ERROR_SUCCESS);
3919 return value;
3920}
3921//******************************************************************************
3922//******************************************************************************
3923WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3924{
3925 WORD oldval;
3926
3927 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3928 {
3929 oldval = *(WORD *)(userWindowBytes + index);
3930 *(WORD *)(userWindowBytes + index) = value;
3931 //Note: NT4, SP6 does not set the last error to 0
3932 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3933 SetLastError(ERROR_SUCCESS);
3934 return oldval;
3935 }
3936 switch(index)
3937 {
3938 case GWW_HINSTANCE:
3939 oldval = hInstance;
3940 hInstance = value;
3941 break;
3942
3943 case GWW_HWNDPARENT:
3944 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3945 break;
3946
3947 case GWW_ID:
3948 oldval = getWindowId();
3949 setWindowId(value);
3950 break;
3951
3952 default:
3953 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3954 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3955 return 0;
3956 }
3957 //Note: NT4, SP6 does not set the last error to 0
3958 SetLastError(ERROR_SUCCESS);
3959 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3960 return oldval;
3961}
3962//******************************************************************************
3963//******************************************************************************
3964WORD Win32BaseWindow::GetWindowWord(int index)
3965{
3966 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3967 {
3968 //Note: NT4, SP6 does not set the last error to 0
3969 SetLastError(ERROR_SUCCESS);
3970 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3971 return *(WORD *)(userWindowBytes + index);
3972 }
3973 switch(index)
3974 {
3975 case GWW_ID:
3976 if(HIWORD(getWindowId()))
3977 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3978 return (WORD)getWindowId();
3979
3980 case GWW_HWNDPARENT:
3981 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3982 return (WORD) GetParent();
3983
3984 case GWW_HINSTANCE:
3985 if (HIWORD(hInstance))
3986 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3987 return (WORD)hInstance;
3988 }
3989
3990 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3991 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3992 return 0;
3993}
3994//******************************************************************************
3995// Win32BaseWindow::setVisibleRgnNotifyProc
3996//
3997// Sets the visible region change notification handler. Called when
3998// the window receives a WM_VRNDISABLED or WM_VRNENABLED message (PM).
3999//
4000// Parameters:
4001// VISRGN_NOTIFY_PROC lpNotifyProc - notification handler
4002// DWORD dwUserData - caller supplied parameter for handler invocations
4003//
4004// Returns:
4005// TRUE - Success
4006// FALSE - Failure
4007//
4008//******************************************************************************
4009BOOL Win32BaseWindow::setVisibleRgnNotifyProc(VISRGN_NOTIFY_PROC lpNotifyProc, DWORD dwUserData)
4010{
4011 lpVisRgnNotifyProc = lpNotifyProc;
4012 dwVisRgnNotifyParam = dwUserData;
4013 return TRUE;
4014}
4015//******************************************************************************
4016// Win32BaseWindow::callVisibleRgnNotifyProc
4017//
4018// Call the visible region change notification handler. Called when
4019// the window receives a WM_VRNDISABLED or WM_VRNENABLED message (PM).
4020//
4021// Parameters:
4022// BOOL fDrawingAllowed - drawing is allowed or not
4023//
4024// Returns:
4025// TRUE - Success
4026// FALSE - Failure
4027//
4028//******************************************************************************
4029void Win32BaseWindow::callVisibleRgnNotifyProc(BOOL fDrawingAllowed)
4030{
4031 if(fDrawingAllowed) {
4032 fWindowLocked = TRUE;
4033 }
4034 else {
4035 fWindowLocked = FALSE;
4036 }
4037 if(lpVisRgnNotifyProc) {
4038 lpVisRgnNotifyProc(getWindowHandle(), fDrawingAllowed, dwVisRgnNotifyParam);
4039 }
4040}
4041//******************************************************************************
4042// Win32BaseWindow::queryOpenDCs
4043//
4044// Return the DCs that are currently open for this window
4045//
4046// Parameters:
4047// HDC *phdcWindow - pointer to HDC array (IN)
4048// int chdcWindow - size of HDC array (IN)
4049// int *pnrdcs - number of HDCs returned (OUT)
4050//
4051// Returns:
4052// TRUE - Success
4053// FALSE - Failure
4054//
4055//******************************************************************************
4056BOOL Win32BaseWindow::queryOpenDCs(HDC *phdcWindow, int chdcWindow, int *pnrdcs)
4057{
4058 if(nrOpenDCs == 0) return FALSE;
4059
4060 if(chdcWindow < nrOpenDCs) {
4061 DebugInt3();
4062 return FALSE;
4063 }
4064
4065 lock(&critsect);
4066 int j = 0;
4067 for(int i=0;i<MAX_OPENDCS && j<nrOpenDCs;i++) {
4068 if(hdcWindow[i] != 0) {
4069 phdcWindow[j] = hdcWindow[i];
4070 j++;
4071 }
4072 }
4073 unlock(&critsect);
4074 *pnrdcs = nrOpenDCs;
4075 return TRUE;
4076}
4077//******************************************************************************
4078// Win32BaseWindow::addOpenDC
4079//
4080// Add DC to list of open DCS
4081//
4082// Parameters:
4083// HDC hdc - HDC to be added to our list of open DCs
4084//
4085// Returns:
4086//
4087//******************************************************************************
4088void Win32BaseWindow::addOpenDC(HDC hdc)
4089{
4090 lock(&critsect);
4091 for(int i=0;i<MAX_OPENDCS;i++) {
4092 if(hdcWindow[i] == 0) {
4093 hdcWindow[i] = hdc;
4094 break;
4095 }
4096 }
4097 unlock(&critsect);
4098 if(i == MAX_OPENDCS) {
4099 dprintf(("Open DCs:"));
4100 for(int i=0;i<MAX_OPENDCS;i++) {
4101 dprintf(("Window %x DC %x", WindowFromDC(hdcWindow[i]), hdcWindow[i]));
4102 }
4103 DebugInt3(); //no room!
4104 return;
4105 }
4106
4107 dprintf2(("Win32BaseWindow::addOpenDC %x %x %d", getWindowHandle(), hdc, nrOpenDCs+1));
4108 nrOpenDCs++;
4109}
4110//******************************************************************************
4111// Win32BaseWindow::removeOpenDC
4112//
4113// Remove DC from list of open DCS
4114//
4115// Parameters:
4116// HDC hdc - HDC to be removed from our list of open DCs
4117//
4118// Returns:
4119//
4120//******************************************************************************
4121void Win32BaseWindow::removeOpenDC(HDC hdc)
4122{
4123 if(nrOpenDCs == 0) {
4124 dprintf(("Win32BaseWindow::removeOpenDC %x hdc %x not found!! (1)", getWindowHandle(), hdc));
4125 //Some applications call ReleaseDC before EndPaint
4126// DebugInt3();
4127 return;
4128 }
4129 lock(&critsect);
4130 for(int i=0;i<MAX_OPENDCS;i++) {
4131 if(hdcWindow[i] == hdc) {
4132 hdcWindow[i] = 0;
4133 break;
4134 }
4135 }
4136 unlock(&critsect);
4137 if(i == MAX_OPENDCS) {
4138 dprintf(("Win32BaseWindow::removeOpenDC hdc %x not found!!", hdc));
4139 DebugInt3(); //not found
4140 return;
4141 }
4142 dprintf2(("Win32BaseWindow::removeOpenDC %x %x", getWindowHandle(), hdc, nrOpenDCs-1));
4143 nrOpenDCs--;
4144}
4145//******************************************************************************
4146//Locates window in linked list and increases reference count (if found)
4147//Window object must be unreferenced after usage
4148//******************************************************************************
4149Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
4150{
4151 Win32BaseWindow *window;
4152
4153////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
4154//// while browsing
4155//// Not thread safe now!
4156//// lock(&critsect);
4157 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
4158 if(window) {
4159//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
4160 window->addRef();
4161 }
4162//// unlock(&critsect);
4163 return window;
4164 }
4165//// unlock(&critsect);
4166// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
4167 return NULL;
4168}
4169//******************************************************************************
4170//Locates window in linked list and increases reference count (if found)
4171//Window object must be unreferenced after usage
4172//******************************************************************************
4173Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
4174{
4175 DWORD magic;
4176 HWND hwnd;
4177
4178 if(hwndOS2 == OSLIB_HWND_DESKTOP)
4179 {
4180 windowDesktop->addRef();
4181 return windowDesktop;
4182 }
4183
4184 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
4185 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
4186
4187 if(hwnd && CheckMagicDword(magic)) {
4188 return GetWindowFromHandle(hwnd);
4189 }
4190// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
4191
4192 //Now check if it's a fake window
4193 Win32FakeWindow *window = Win32FakeWindow::GetWindowFromOS2Handle(hwndOS2);
4194 if(window) {
4195 return window;
4196 }
4197 return 0;
4198}
4199//******************************************************************************
4200//Locates window in linked list and increases reference count (if found)
4201//Window object must be unreferenced after usage
4202//******************************************************************************
4203Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
4204{
4205 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
4206}
4207//******************************************************************************
4208//******************************************************************************
4209HWND WIN32API Win32ToOS2Handle(HWND hwnd)
4210{
4211 HWND hwndOS2;
4212
4213 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4214
4215 if(window) {
4216 hwndOS2 = window->getOS2WindowHandle();
4217 RELEASE_WNDOBJ(window);
4218 return hwndOS2;
4219 }
4220// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4221 return hwnd;
4222}
4223//******************************************************************************
4224//******************************************************************************
4225HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
4226{
4227 HWND hwndOS2;
4228
4229 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4230
4231 if(window) {
4232 hwndOS2 = window->getOS2FrameWindowHandle();
4233 RELEASE_WNDOBJ(window);
4234 return hwndOS2;
4235 }
4236// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4237 return hwnd;
4238}
4239//******************************************************************************
4240//******************************************************************************
4241HWND WIN32API OS2ToWin32Handle(HWND hwnd)
4242{
4243 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
4244 HWND hwndWin32;
4245
4246 if(window) {
4247 hwndWin32 = window->getWindowHandle();
4248 RELEASE_WNDOBJ(window);
4249 return hwndWin32;
4250 }
4251 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
4252 if(window) {
4253 hwndWin32 = window->getWindowHandle();
4254 RELEASE_WNDOBJ(window);
4255 return hwndWin32;
4256 }
4257
4258// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
4259 return 0;
4260// else return hwnd; //OS/2 window handle
4261}
4262#ifdef DEBUG
4263LONG Win32BaseWindow::addRef()
4264{
4265// dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
4266 return GenericObject::addRef();
4267}
4268//******************************************************************************
4269//******************************************************************************
4270LONG Win32BaseWindow::release(char *function, int line)
4271{
4272// dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
4273 return GenericObject::release();
4274}
4275#endif
4276//******************************************************************************
4277//******************************************************************************
4278GenericObject *Win32BaseWindow::windows = NULL;
4279VMutex Win32BaseWindow::critsect;
4280
4281//******************************************************************************
4282//******************************************************************************
4283#ifdef DEBUG
4284void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
4285{
4286 char style[256] = "";
4287 char exstyle[256] = "";
4288
4289 /* Window styles */
4290 if(dwStyle & WS_CHILD)
4291 strcat(style, "WS_CHILD ");
4292 if(dwStyle & WS_POPUP)
4293 strcat(style, "WS_POPUP ");
4294 if(dwStyle & WS_VISIBLE)
4295 strcat(style, "WS_VISIBLE ");
4296 if(dwStyle & WS_DISABLED)
4297 strcat(style, "WS_DISABLED ");
4298 if(dwStyle & WS_CLIPSIBLINGS)
4299 strcat(style, "WS_CLIPSIBLINGS ");
4300 if(dwStyle & WS_CLIPCHILDREN)
4301 strcat(style, "WS_CLIPCHILDREN ");
4302 if(dwStyle & WS_MAXIMIZE)
4303 strcat(style, "WS_MAXIMIZE ");
4304 if(dwStyle & WS_MINIMIZE)
4305 strcat(style, "WS_MINIMIZE ");
4306 if(dwStyle & WS_GROUP)
4307 strcat(style, "WS_GROUP ");
4308 if(dwStyle & WS_TABSTOP)
4309 strcat(style, "WS_TABSTOP ");
4310
4311 if((dwStyle & WS_CAPTION) == WS_CAPTION)
4312 strcat(style, "WS_CAPTION ");
4313 if(dwStyle & WS_DLGFRAME)
4314 strcat(style, "WS_DLGFRAME ");
4315 if(dwStyle & WS_BORDER)
4316 strcat(style, "WS_BORDER ");
4317
4318 if(dwStyle & WS_VSCROLL)
4319 strcat(style, "WS_VSCROLL ");
4320 if(dwStyle & WS_HSCROLL)
4321 strcat(style, "WS_HSCROLL ");
4322 if(dwStyle & WS_SYSMENU)
4323 strcat(style, "WS_SYSMENU ");
4324 if(dwStyle & WS_THICKFRAME)
4325 strcat(style, "WS_THICKFRAME ");
4326 if(dwStyle & WS_MINIMIZEBOX)
4327 strcat(style, "WS_MINIMIZEBOX ");
4328 if(dwStyle & WS_MAXIMIZEBOX)
4329 strcat(style, "WS_MAXIMIZEBOX ");
4330
4331 if(dwExStyle & WS_EX_DLGMODALFRAME)
4332 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4333 if(dwExStyle & WS_EX_ACCEPTFILES)
4334 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4335 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4336 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4337 if(dwExStyle & WS_EX_TOPMOST)
4338 strcat(exstyle, "WS_EX_TOPMOST ");
4339 if(dwExStyle & WS_EX_TRANSPARENT)
4340 strcat(exstyle, "WS_EX_TRANSPARENT ");
4341
4342 if(dwExStyle & WS_EX_MDICHILD)
4343 strcat(exstyle, "WS_EX_MDICHILD ");
4344 if(dwExStyle & WS_EX_TOOLWINDOW)
4345 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4346 if(dwExStyle & WS_EX_WINDOWEDGE)
4347 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4348 if(dwExStyle & WS_EX_CLIENTEDGE)
4349 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4350 if(dwExStyle & WS_EX_CONTEXTHELP)
4351 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4352 if(dwExStyle & WS_EX_RIGHT)
4353 strcat(exstyle, "WS_EX_RIGHT ");
4354 if(dwExStyle & WS_EX_LEFT)
4355 strcat(exstyle, "WS_EX_LEFT ");
4356 if(dwExStyle & WS_EX_RTLREADING)
4357 strcat(exstyle, "WS_EX_RTLREADING ");
4358 if(dwExStyle & WS_EX_LTRREADING)
4359 strcat(exstyle, "WS_EX_LTRREADING ");
4360 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4361 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4362 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4363 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4364 if(dwExStyle & WS_EX_CONTROLPARENT)
4365 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4366 if(dwExStyle & WS_EX_STATICEDGE)
4367 strcat(exstyle, "WS_EX_STATICEDGE ");
4368 if(dwExStyle & WS_EX_APPWINDOW)
4369 strcat(exstyle, "WS_EX_APPWINDOW ");
4370
4371 dprintf(("Window style: %x %s", dwStyle, style));
4372 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4373}
4374#endif
4375//******************************************************************************
4376//******************************************************************************
Note: See TracBrowser for help on using the repository browser.