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

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