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

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

Tool windows don't have minimize or maximize buttons; always draw tool windows in win32 style as they are not compatible with PM frame controls

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