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

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

PF: Correctly finish PM restore procedure from minimized state; Use Stock brush for minimized icon fill when it is not allocated

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