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

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

Visible & Clip region changes

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