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

Last change on this file since 10593 was 10587, checked in by sandervl, 21 years ago

KSO: Update

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