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

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

some minor updates

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