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

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

EndDialog: Enable owner window regardless of whether it was enabled before dialog creation & check for fake windows in GetWindowFromOS2Handle

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