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

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

KSO: Properties allocated from shared memory & Fake window updates & SW_SHOWDEFAULT update

File size: 148.8 KB
Line 
1/* $Id: win32wbase.cpp,v 1.367 2003-04-23 18:00:59 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 /*
2364 * SW_SHOWDEFAULT is an reference to the startup info wShowWindow member.
2365 */
2366 if (nCmdShow == SW_SHOWDEFAULT)
2367 {
2368 nCmdShow = GetProcessDword(0, GPD_STARTF_SHOWWINDOW);
2369 dprintf(("ShowWindow: GetProcessDword(0, GPD_STARTF_SHOWWINDOW) -> %x", nCmdShow));
2370 }
2371
2372
2373 switch(nCmdShow)
2374 {
2375 case SW_HIDE:
2376 if (!wasVisible) goto END;
2377
2378 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2379 break;
2380
2381 case SW_SHOWMINNOACTIVE:
2382 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2383 /* fall through */
2384 case SW_SHOWMINIMIZED:
2385 swp |= SWP_SHOWWINDOW;
2386 /* fall through */
2387 case SW_MINIMIZE:
2388 swp |= SWP_FRAMECHANGED;
2389 if( !(getStyle() & WS_MINIMIZE) ) {
2390 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2391 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2392 }
2393 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2394 break;
2395
2396 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2397 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2398 if( !(getStyle() & WS_MAXIMIZE) ) {
2399 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2400 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2401 }
2402 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2403 break;
2404
2405 case SW_SHOWNA:
2406 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2407 /* fall through */
2408 case SW_SHOW:
2409 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2410
2411 /*
2412 * ShowWindow has a little peculiar behavior that if the
2413 * window is already the topmost window, it will not
2414 * activate it.
2415 */
2416 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2417 swp |= SWP_NOACTIVATE;
2418
2419 break;
2420
2421 case SW_SHOWNOACTIVATE:
2422 swp |= SWP_NOZORDER;
2423 if (GetActiveWindow())
2424 swp |= SWP_NOACTIVATE;
2425 /* fall through */
2426 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2427 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2428 case SW_RESTORE:
2429 dprintf(("ShowWindow:restoring window"));
2430
2431 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2432 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2433 swp |= MinMaximize(SW_RESTORE, &newPos );
2434 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2435 }
2436 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2437 break;
2438 }
2439
2440 showFlag = (nCmdShow != SW_HIDE);
2441 if (showFlag != wasVisible)
2442 {
2443 SendMessageA(getWindowHandle(),WM_SHOWWINDOW, showFlag, 0 );
2444 if (!::IsWindow( getWindowHandle() )) goto END;
2445 }
2446
2447 /* We can't activate a child window */
2448 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2449 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2450
2451 if (!(getStyle() & WS_MINIMIZE)) {
2452 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp), TRUE);
2453 }
2454 else OSLibWinMinimizeWindow(getOS2FrameWindowHandle());
2455
2456 if(!(swp & SWP_NOACTIVATE) && (!(getStyle() & WS_MINIMIZE))) {
2457 OSLibWinSetActiveWindow(OS2HwndFrame);
2458 }
2459
2460 if (flags & WIN_NEED_SIZE)
2461 {
2462 /* should happen only in CreateWindowEx() */
2463 int wParam = SIZE_RESTORED;
2464
2465 flags &= ~WIN_NEED_SIZE;
2466 if (dwStyle & WS_MAXIMIZE)
2467 wParam = SIZE_MAXIMIZED;
2468 else
2469 if (dwStyle & WS_MINIMIZE)
2470 wParam = SIZE_MINIMIZED;
2471
2472 SendMessageA(getWindowHandle(),WM_SIZE, wParam,
2473 MAKELONG(rectClient.right-rectClient.left,
2474 rectClient.bottom-rectClient.top));
2475 SendMessageA(getWindowHandle(),WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2476 }
2477//testestest
2478 //temporary workaround for file dialogs with template dialog child
2479 //they don't redraw when switching directories
2480 //For some reason the new child's (syslistview32) update rectangle stays
2481 //empty after its parent is made visible with ShowWindow
2482 //TODO: find real cause
2483 if(!wasVisible) {
2484 InvalidateRect(getWindowHandle(), NULL, TRUE);
2485 }
2486//testestest
2487
2488END:
2489 fMinMaxChange = FALSE;
2490 return wasVisible;
2491}
2492//******************************************************************************
2493//******************************************************************************
2494BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx,
2495 int cy, UINT fuFlags, BOOL fShowWindow)
2496{
2497 BOOL rc = FALSE;
2498 Win32BaseWindow *window;
2499 HWND hParent = 0;
2500 RECT oldClientRect = rectClient;
2501
2502 if (fuFlags &
2503 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2504 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2505 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2506 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2507 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS))
2508 {
2509 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2510 return FALSE;
2511 }
2512
2513 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_ASYNCWINDOWPOS)) {
2514 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2515 }
2516
2517 if(IsWindowDestroyed()) {
2518 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2519 dprintf(("SetWindowPos; window already destroyed"));
2520 return TRUE;
2521 }
2522
2523#if 0
2524 /* Fix redundant flags */
2525 if(getStyle() & WS_VISIBLE) {
2526 fuFlags &= ~SWP_SHOWWINDOW;
2527 }
2528 else
2529 {
2530 if (!(fuFlags & SWP_SHOWWINDOW))
2531 fuFlags |= SWP_NOREDRAW;
2532 fuFlags &= ~SWP_HIDEWINDOW;
2533 }
2534
2535//// if(cx < 0) cx = 0;
2536//// if(cy < 0) cy = 0;
2537
2538 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2539 fuFlags |= SWP_NOSIZE; /* Already the right size */
2540 }
2541
2542 if((rectWindow.left == x) && (rectWindow.top == y)) {
2543 fuFlags |= SWP_NOMOVE; /* Already the right position */
2544 }
2545
2546 if(getWindowHandle() == GetActiveWindow()) {
2547 fuFlags |= SWP_NOACTIVATE; /* Already active */
2548 }
2549 else
2550 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2551 {
2552 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2553 {
2554 fuFlags &= ~SWP_NOZORDER;
2555 hwndInsertAfter = HWND_TOP;
2556 }
2557 }
2558 /* TODO: Check hwndInsertAfter */
2559#endif
2560
2561 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2562 if(state < STATE_POST_WMNCCREATE)
2563 {//don't change size; modify internal structures only
2564 //TODO: not 100% correct yet (activate)
2565 dprintf2(("state < STATE_POST_WMNCCREATE"));
2566 if(!(fuFlags & SWP_NOZORDER)) {
2567 hwndLinkAfter = hwndInsertAfter;
2568 }
2569 if(!(fuFlags & SWP_NOMOVE)) {
2570 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2571 rectWindow.top = y;
2572 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2573 rectWindow.left = x;
2574 }
2575 if(!(fuFlags & SWP_NOSIZE)) {
2576 rectWindow.bottom = rectWindow.top + cy;
2577 rectWindow.right = rectWindow.left + cx;
2578 }
2579 return TRUE;
2580 }
2581
2582 WINDOWPOS wpos;
2583 SWP swp, swpOld;
2584 wpos.flags = fuFlags;
2585 wpos.cy = cy;
2586 wpos.cx = cx;
2587 wpos.x = x;
2588 wpos.y = y;
2589 wpos.hwndInsertAfter = hwndInsertAfter;
2590 wpos.hwnd = getWindowHandle();
2591
2592 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2593 {
2594 if (isChild())
2595 {
2596 if(!getParent()) {
2597 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2598 }
2599 }
2600 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2601 }
2602 if((dwOldStyle & WS_MINIMIZE) && (getStyle() & WS_MINIMIZE))
2603 {//don't allow size changes if the window is minimized
2604 //we will update the restore position at the end of this method
2605 if(!(wpos.flags & SWP_NOSIZE)) {
2606 //TODO: updating the window rectangle doesn't look right
2607 wpos.flags |= SWP_NOSIZE;
2608 rectWindow.right = rectWindow.left + wpos.cx;
2609 rectWindow.bottom = rectWindow.top + wpos.cy;
2610 dprintf(("WARNING: Don't allow size change for minimized window; only save new restore position"));
2611 dprintf(("new window rectangle (%d,%d)(%d,%d)", rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2612 }
2613 }
2614
2615 if(getParent()) {
2616 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2617 OS2HwndFrame);
2618 }
2619 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2620
2621 if (swp.fl == 0) {
2622 dprintf2(("swp.fl == 0"));
2623 if(fuFlags & SWP_FRAMECHANGED)
2624 {
2625 NotifyFrameChanged(&wpos, &oldClientRect);
2626 }
2627 if(!fShowWindow && !(getStyle() & WS_MINIMIZE) && !(fuFlags & (SWP_NOSIZE | SWP_NOMOVE)))
2628 {
2629 //Restore position always changes when the window position is changed
2630 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2631 windowpos.rcNormalPosition = rectWindow;
2632 }
2633 return TRUE;
2634 }
2635
2636// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2637 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2638 {
2639 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2640 if(wndBehind) {
2641 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2642 RELEASE_WNDOBJ(wndBehind);
2643 }
2644 else {
2645 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2646 swp.hwndInsertBehind = 0;
2647 }
2648 }
2649 swp.hwnd = OS2HwndFrame;
2650
2651 //SvL: Must also deactivate the window when hiding it or else focus won't
2652 // change. (NOTE: make sure this doesn't cause regressions (01-02-2003)
2653 if((swp.fl & (SWPOS_HIDE|SWPOS_DEACTIVATE)) == (SWPOS_HIDE|SWPOS_DEACTIVATE))
2654 {
2655 //we must make sure the owner is not disabled or else the focus will
2656 //be switched to the wrong window
2657 Win32BaseWindow *topOwner;
2658
2659 if(getOwner() == NULL) {
2660 windowDesktop->addRef();
2661 topOwner = windowDesktop;
2662 }
2663 else topOwner = GetWindowFromHandle(getOwner()->GetTopParent());
2664
2665 if(topOwner != NULL) {
2666 DWORD dwStyle = topOwner->GetWindowLong(GWL_STYLE, FALSE);
2667 if(dwStyle & WS_DISABLED) {
2668 swp.fl &= ~SWPOS_DEACTIVATE;
2669 }
2670 }
2671 else DebugInt3();
2672 }
2673
2674 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2675 setStyle(getStyle() | WS_VISIBLE);
2676 if(hTaskList) {
2677 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2678 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2679 }
2680 }
2681 else
2682 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2683 setStyle(getStyle() & ~WS_VISIBLE);
2684 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2685 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2686 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2687 }
2688 }
2689 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2690
2691 rc = OSLibWinSetMultWindowPos(&swp, 1);
2692 if(rc == FALSE)
2693 {
2694 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2695 return 0;
2696 }
2697
2698 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2699 {
2700 NotifyFrameChanged(&wpos, &oldClientRect);
2701 }
2702 if(!fShowWindow && !(getStyle() & WS_MINIMIZE))
2703 {
2704 //Restore position always changes when the window position is changed
2705 dprintf(("Save new restore position %x (%d,%d)(%d,%d)", getWindowHandle(), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
2706 windowpos.rcNormalPosition = rectWindow;
2707 }
2708 //MSDN says the entire client area will be invalidated when SWP_NOCOPYBITS
2709 //is specified (fixes repaint issues when window is made smaller)
2710 if((fuFlags & (SWP_NOCOPYBITS|SWP_NOREDRAW)) == SWP_NOCOPYBITS) {
2711 InvalidateRect(getWindowHandle(), NULL, TRUE);
2712 }
2713 return (rc);
2714}
2715//******************************************************************************
2716//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2717//******************************************************************************
2718BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2719{
2720 rectWindow.left += dx;
2721 rectWindow.right += dx;
2722 rectWindow.top += dy;
2723 rectWindow.bottom += dy;
2724 SendMessageA(getWindowHandle(),WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2725 return TRUE;
2726}
2727//******************************************************************************
2728//******************************************************************************
2729void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2730{
2731 HRGN hrgn, hrgnClient;
2732 RECT rect;
2733
2734 MsgFormatFrame(NULL);
2735
2736 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2737 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2738 {
2739 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2740 wpos->cx = RECT_WIDTH(rectWindow);
2741 wpos->cy = RECT_HEIGHT(rectWindow);
2742 }
2743
2744 if(rectClient.left != oldClientRect->left ||
2745 rectClient.top != oldClientRect->top)
2746 {
2747 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2748 wpos->x = rectWindow.left;
2749 wpos->y = rectWindow.top;
2750 }
2751
2752 WINDOWPOS wpOld = *wpos;
2753 if(!(wpos->flags & SWP_NOSENDCHANGING))
2754 SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2755
2756 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2757 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2758 {
2759 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2760 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2761 }
2762 else SendMessageA(getWindowHandle(),WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2763
2764 //Calculate invalid areas
2765 rect = rectWindow;
2766 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2767 hrgn = CreateRectRgnIndirect(&rect);
2768 if (!hrgn) {
2769 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2770 return;
2771 }
2772 rect = rectClient;
2773 hrgnClient = CreateRectRgnIndirect(&rect);
2774 if (!hrgn) {
2775 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2776 return;
2777 }
2778 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2779 DeleteObject(hrgnClient);
2780
2781 if(!EqualRect(oldClientRect, &rectClient)) {
2782 UnionRect(oldClientRect, oldClientRect, &rectClient);
2783 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2784 if (!hrgn) {
2785 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2786 return;
2787 }
2788 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2789 DeleteObject(hrgnClient);
2790 }
2791 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2792 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2793 DeleteObject(hrgn);
2794}
2795//******************************************************************************
2796//TODO: Check how this api really works in NT
2797//******************************************************************************
2798BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2799{
2800 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2801 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2802 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2803 windowpos.ptMinPosition = wndpl->ptMinPosition;
2804 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2805 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2806
2807 if(getStyle() & WS_MINIMIZE )
2808 {
2809 //TODO: Why can't this be (0,0)?
2810 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2811 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2812 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2813 }
2814 }
2815 else
2816 if(getStyle() & WS_MAXIMIZE )
2817 {
2818 //TODO: Why can't this be (0,0)?
2819 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2820 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2821 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2822 }
2823 else {
2824 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2825 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2826 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2827 SWP_NOZORDER | SWP_NOACTIVATE );
2828 }
2829 ShowWindow(wndpl->showCmd);
2830 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2831 {
2832 /* SDK: ...valid only the next time... */
2833 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2834 setFlags(getFlags() | WIN_RESTORE_MAX);
2835 }
2836 return TRUE;
2837}
2838//******************************************************************************
2839//******************************************************************************
2840BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2841{
2842 wndpl->length = sizeof(*wndpl);
2843 if(getStyle() & WS_MINIMIZE )
2844 wndpl->showCmd = SW_SHOWMINIMIZED;
2845 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2846
2847 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2848 if(getFlags() & WIN_RESTORE_MAX )
2849 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2850 else wndpl->flags = 0;
2851
2852 wndpl->ptMinPosition = windowpos.ptMinPosition;
2853 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2854 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2855 wndpl->rcNormalPosition = windowpos.rcNormalPosition;
2856
2857 return TRUE;
2858}
2859//******************************************************************************
2860//Also destroys all the child windows (destroy children first, parent last)
2861//TODO: Don't rely on PM to do the right thing. Send WM_(NC)DESTROY &
2862// destroy children ourselves (see Wine)
2863//******************************************************************************
2864BOOL Win32BaseWindow::DestroyWindow()
2865{
2866 HWND hwnd = getWindowHandle();
2867
2868 dprintf(("DestroyWindow %x", hwnd));
2869
2870#if 0
2871 /* Look whether the focus is within the tree of windows we will
2872 * be destroying.
2873 */
2874 HWND hwndFocus = GetFocus();
2875 if (hwndFocus == hwnd || ::IsChild( hwnd, hwndFocus ))
2876 {
2877 HWND parent = GetAncestor( hwnd, GA_PARENT );
2878 if (parent == GetDesktopWindow()) parent = 0;
2879 SetFocus( parent );
2880 }
2881#endif
2882 /* Call hooks */
2883 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2884 {
2885 return FALSE;
2886 }
2887
2888 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2889 {
2890 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2891 /* FIXME: clean up palette - see "Internals" p.352 */
2892 }
2893
2894 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2895 {
2896 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2897 {
2898 /* Notify the parent window only */
2899 SendMessageA(getParent()->getWindowHandle(), WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2900 if(!::IsWindow(hwnd) )
2901 {
2902 return TRUE;
2903 }
2904 }
2905//// else DebugInt3();
2906 }
2907 /* Hide the window */
2908 if(IsWindowVisible(getWindowHandle()))
2909 {
2910 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2911 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2912 if(!::IsWindow(hwnd))
2913 {
2914 return TRUE;
2915 }
2916 }
2917 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2918
2919 // check the handle for the last active popup window
2920 Win32BaseWindow* owner = getOwner();
2921 if (NULL != owner)
2922 {
2923 if (owner->getLastActive() == hwnd)
2924 owner->setLastActive( owner->getWindowHandle() );
2925
2926 //SvL: Not sure this is correct, but it solves the problem of reassigning
2927 // activation. A disabled window will never be activated ->
2928 // possible that the wrong window is chosen by PM.
2929 // PM chooses another window to be activated before WM_DESTROY is
2930 // sent. VPC enables the owner when it receives that message,
2931 // but by then it's too late.
2932 // (MFC created modeless dialog)
2933 //TODO: This might be the wrong place to do it. EndDialog is called,
2934 // so perhaps it should be done there. (although Wine only
2935 // enables the owner if the dialog is modal)
2936 ::EnableWindow(owner->getWindowHandle(), 1);
2937 }
2938
2939 fDestroyWindowCalled = TRUE;
2940
2941//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2942// handler; must postpone it
2943 if(fChildDestructionInProgress) {
2944 dprintf(("Postponing parent destruction because of dying child"));
2945 OSLibPostMessageDirect(OS2HwndFrame, WIN32APP_POSTPONEDESTROY, 0, 0);
2946 return TRUE;
2947 }
2948
2949 BOOL fOldChildDestructionInProgress = FALSE;
2950 if(GetParent()) {
2951 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2952 if(window) {
2953 fOldChildDestructionInProgress = window->IsChildDestructionInProgress();
2954 window->SetChildDestructionInProgress(TRUE);
2955 RELEASE_WNDOBJ(window);
2956 }
2957 }
2958//hack end
2959
2960 BOOL ret = OSLibWinDestroyWindow(OS2HwndFrame);
2961
2962//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
2963// handler; must postpone it
2964 if(GetParent()) {
2965 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(GetParent());
2966 if(window) {
2967 window->SetChildDestructionInProgress(fOldChildDestructionInProgress);
2968 RELEASE_WNDOBJ(window);
2969 }
2970 }
2971//hack end
2972 return ret;
2973}
2974//******************************************************************************
2975//******************************************************************************
2976Win32BaseWindow *Win32BaseWindow::getParent()
2977{
2978 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2979 //experiment
2980#if 0
2981 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2982#else
2983 return wndparent;
2984#endif
2985}
2986//******************************************************************************
2987//Note: does not set last error if no parent (verified in NT4, SP6)
2988//******************************************************************************
2989HWND Win32BaseWindow::GetParent()
2990{
2991 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2992
2993 if(getStyle() & WS_CHILD)
2994 {
2995 if(wndparent) {
2996 return wndparent->getWindowHandle();
2997 }
2998 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2999 DebugInt3();
3000 return 0;
3001 }
3002 else
3003 if(getStyle() & WS_POPUP)
3004 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
3005 else return 0;
3006}
3007//******************************************************************************
3008//******************************************************************************
3009HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
3010{
3011 HWND oldhwnd;
3012 Win32BaseWindow *newparent;
3013 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
3014 BOOL fShow = FALSE;
3015
3016 if(oldparent) {
3017 oldhwnd = oldparent->getWindowHandle();
3018 oldparent->removeChild(this);
3019 }
3020 else oldhwnd = 0;
3021
3022 /* Windows hides the window first, then shows it again
3023 * including the WM_SHOWWINDOW messages and all */
3024 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
3025 ShowWindow(SW_HIDE);
3026 fShow = TRUE;
3027 }
3028 if(oldparent) {
3029 //release parent here (increased refcount during creation)
3030 RELEASE_WNDOBJ(oldparent);
3031 }
3032 newparent = GetWindowFromHandle(hwndNewParent);
3033 if(newparent && !newparent->isDesktopWindow())
3034 {
3035 setParent(newparent);
3036 getParent()->addChild(this);
3037 fParentChange = TRUE;
3038 // in case we haven't finished creating the window whose parent we're
3039 // setting here, the OS/2 HWND might not exist yet and we call the PM
3040 // API with a NULLHANDLE - no problem
3041 // when we create the OS/2 window lateron, we will create it with the
3042 // right parent anyway.
3043 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
3044 if(!(getStyle() & WS_CHILD))
3045 {
3046 if(getWindowId())
3047 {
3048 DestroyMenu( (HMENU) getWindowId() );
3049 setWindowId(0);
3050 }
3051 }
3052 //SvL: Even though the win32 coordinates might not change, the PM
3053 // coordinates can. We must make sure the control stays at the
3054 // same position (y) relative to the (new) parent.
3055 // TODO: shouldn't we check the state of the window and not do it in INIT state?
3056 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
3057 SWP_NOACTIVATE|SWP_NOSIZE);
3058 fParentChange = FALSE;
3059 }
3060 else {
3061 if(newparent) RELEASE_WNDOBJ(newparent);
3062
3063 setParent(windowDesktop);
3064 windowDesktop->addRef();
3065 windowDesktop->addChild(this);
3066 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
3067
3068 //Do not change the window id!
3069//// setWindowId(0);
3070 }
3071 /* SetParent additionally needs to make hwndChild the topmost window
3072 in the x-order and send the expected WM_WINDOWPOSCHANGING and
3073 WM_WINDOWPOSCHANGED notification messages.
3074 */
3075 if(state >= STATE_PRE_WMNCCREATE) {
3076 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
3077 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
3078
3079 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
3080 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
3081 }
3082 return oldhwnd;
3083}
3084//******************************************************************************
3085//******************************************************************************
3086BOOL Win32BaseWindow::IsChild(HWND hwndParent)
3087{
3088 // PH: Optimizer won't unroll calls to getParent() even
3089 // in release build.
3090 Win32BaseWindow *_parent = getParent();
3091
3092 if(_parent)
3093 {
3094 if(_parent->getWindowHandle() == hwndParent)
3095 return TRUE;
3096
3097 return _parent->IsChild(hwndParent);
3098 }
3099 else
3100 return 0;
3101}
3102//******************************************************************************
3103//******************************************************************************
3104HWND Win32BaseWindow::GetTopWindow()
3105{
3106 HWND hwndTop;
3107 Win32BaseWindow *topwindow;
3108
3109 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3110 if(!isDesktopWindow())
3111 {
3112 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3113 //Note: GetTopWindow can't return a window that hasn't processed
3114 // WM_NCCREATE yet (verified in NT4, SP6)
3115 if(topwindow) {
3116 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3117 hwndTop = topwindow->getWindowHandle();
3118 }
3119 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3120 RELEASE_WNDOBJ(topwindow);
3121 return hwndTop;
3122 }
3123 if(topwindow) RELEASE_WNDOBJ(topwindow);
3124 return 0;
3125 }
3126 while(hwndTop) {
3127 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3128 //Note: GetTopWindow can't return a window that hasn't processed
3129 // WM_NCCREATE yet (verified in NT4, SP6)
3130 if(topwindow) {
3131 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3132 hwndTop = topwindow->getWindowHandle();
3133 }
3134 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3135 RELEASE_WNDOBJ(topwindow);
3136 return hwndTop;
3137 }
3138 if(topwindow) RELEASE_WNDOBJ(topwindow);
3139 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
3140 }
3141
3142 return 0;
3143}
3144//******************************************************************************
3145// Get the top-level parent for a child window.
3146//******************************************************************************
3147HWND Win32BaseWindow::GetTopParent()
3148{
3149 Win32BaseWindow *window = this;
3150 HWND hwndTopParent = 0;
3151
3152 lock();
3153 while(window && (window->getStyle() & WS_CHILD))
3154 {
3155 window = window->getParent();
3156 }
3157 if(window) {
3158 hwndTopParent = window->getWindowHandle();
3159 }
3160 unlock();
3161 return hwndTopParent;
3162}
3163//******************************************************************************
3164//TODO: Should not enumerate children that are created during the enumeration!
3165//TODO: Do this more efficiently
3166//******************************************************************************
3167BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
3168{
3169 BOOL rc = TRUE;
3170 HWND hwnd;
3171 Win32BaseWindow *prevchild = 0, *child = 0;
3172
3173 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3174 lock();
3175 for (child = (Win32BaseWindow *)getFirstChild(); child != NULL; child = (Win32BaseWindow *)child->getNextChild())
3176 {
3177 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3178 hwnd = child->getWindowHandle();
3179 if(child->IsWindowDestroyed() || child->getOwner()) {
3180 continue; //shouldn't have an owner (Wine)
3181 }
3182 child->addRef();
3183 unlock();
3184 if(lpfn(hwnd, lParam) == FALSE)
3185 {
3186 child->release();
3187 return FALSE;
3188 }
3189 child->release();
3190 lock();
3191 //check if the window still exists
3192 if(!::IsWindow(hwnd))
3193 {
3194 child = prevchild;
3195 if(child == NULL) break;
3196 continue;
3197 }
3198 if(child->getFirstChild() != NULL)
3199 {
3200 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3201 child->addRef();
3202 unlock();
3203 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3204 {
3205 child->release();
3206 return FALSE;
3207 }
3208 child->release();
3209 lock();
3210 }
3211 prevchild = child;
3212 }
3213 unlock();
3214 return rc;
3215}
3216//******************************************************************************
3217//Enumerate first-level children only and check thread id
3218//NOTE: NT4 returns first-level children in Z-order!
3219//******************************************************************************
3220BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3221{
3222 Win32BaseWindow *wnd = NULL;
3223 HWND henum, hwnd, hwndWin32;
3224 ULONG tid, pid;
3225 BOOL rc;
3226
3227 //Enumerate all top-level windows and check the process and thread ids
3228 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3229 hwnd = OSLibWinGetNextWindow(henum);
3230
3231 while(hwnd)
3232 {
3233 wnd = GetWindowFromOS2FrameHandle(hwnd);
3234 if(wnd == NULL) {
3235 hwnd = OSLibWinQueryClientWindow(hwnd);
3236 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3237 }
3238 if(wnd) {
3239 hwndWin32 = wnd->getWindowHandle();
3240 }
3241 else hwndWin32 = 0;
3242
3243 if(wnd) RELEASE_WNDOBJ(wnd);
3244
3245 if(hwndWin32) {
3246 OSLibWinQueryWindowProcess(hwnd, &pid, &tid);
3247
3248 if(dwThreadId == tid) {
3249 dprintf(("EnumThreadWindows: Found Window %x", hwndWin32));
3250 if((rc = lpfn(hwndWin32, lParam)) == FALSE) {
3251 break;
3252 }
3253 }
3254 }
3255 hwnd = OSLibWinGetNextWindow(henum);
3256 }
3257 OSLibWinEndEnumWindows(henum);
3258 return TRUE;
3259}
3260//******************************************************************************
3261//Enumerate first-level children only
3262//******************************************************************************
3263BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3264{
3265 Win32BaseWindow *window;
3266 BOOL rc;
3267 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
3268 DWORD dwStyle;
3269
3270 dprintf(("EnumWindows %x %x", lpfn, lParam));
3271
3272 for(int i=0;i<MAX_WINDOW_HANDLES;i++)
3273 {
3274 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3275 if(window) {
3276 if(window->getWindowHandle() != hwnd) {
3277 dprintf(("CORRUPT WINDOW %x %x", window, hwnd));
3278 }
3279 RELEASE_WNDOBJ(window);
3280 dwStyle = ::GetWindowLongA(hwnd, GWL_STYLE);
3281 if ((dwStyle & WS_POPUP) || ((dwStyle & WS_CAPTION) == WS_CAPTION))
3282 {
3283 dprintf2(("EnumWindows: Found Window %x", hwnd));
3284 if((rc = lpfn(hwnd, lParam)) == FALSE) {
3285 break;
3286 }
3287 }
3288 }
3289 hwnd++;
3290 }
3291 return TRUE;
3292}
3293//******************************************************************************
3294//******************************************************************************
3295HWND Win32BaseWindow::FindWindowById(int id)
3296{
3297 HWND hwnd;
3298
3299 lock();
3300 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3301 {
3302 if (child->getWindowId() == id)
3303 {
3304 hwnd = child->getWindowHandle();
3305 unlock();
3306 return hwnd;
3307 }
3308 }
3309 unlock();
3310 return 0;
3311}
3312//******************************************************************************
3313//TODO:
3314//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3315//the current process owns them.
3316//******************************************************************************
3317HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3318{
3319 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3320 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3321 Win32BaseWindow *firstchild = child;
3322
3323 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3324 if((hwndParent != 0 && !parent) ||
3325 (hwndChildAfter != 0 && !child) ||
3326 (hwndParent == 0 && hwndChildAfter != 0))
3327 {
3328 if(parent) RELEASE_WNDOBJ(parent);
3329 if(firstchild) RELEASE_WNDOBJ(firstchild);
3330 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3331 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3332 return 0;
3333 }
3334 SetLastError(0);
3335 if(hwndParent != 0)
3336 {//if the current process owns the window, just do a quick search
3337 lock(&critsect);
3338 child = (Win32BaseWindow *)parent->getFirstChild();
3339 if(hwndChildAfter != 0)
3340 {
3341 while(child)
3342 {
3343 if(child->getWindowHandle() == hwndChildAfter)
3344 {
3345 child = (Win32BaseWindow *)child->getNextChild();
3346 break;
3347 }
3348 child = (Win32BaseWindow *)child->getNextChild();
3349 }
3350 }
3351 while(child)
3352 {
3353 //According to Wine, the class doesn't need to be specified
3354 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3355 (!lpszWindow || child->hasWindowName(lpszWindow)))
3356 {
3357 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3358 HWND hwndChild = child->getWindowHandle();
3359 unlock(&critsect);
3360 if(parent) RELEASE_WNDOBJ(parent);
3361 if(firstchild) RELEASE_WNDOBJ(firstchild);
3362 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3363 return hwndChild;
3364 }
3365 child = (Win32BaseWindow *)child->getNextChild();
3366 }
3367 unlock(&critsect);
3368 if(parent) RELEASE_WNDOBJ(parent);
3369 if(firstchild) RELEASE_WNDOBJ(firstchild);
3370 }
3371 else {
3372 Win32BaseWindow *wnd;
3373 HWND henum, hwnd;
3374
3375 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3376 hwnd = OSLibWinGetNextWindow(henum);
3377
3378 while(hwnd)
3379 {
3380 wnd = GetWindowFromOS2FrameHandle(hwnd);
3381 if(wnd == NULL) {
3382 hwnd = OSLibWinQueryClientWindow(hwnd);
3383 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3384 }
3385
3386 if(wnd) {
3387 //According to Wine, the class doesn't need to be specified
3388 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3389 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3390 {
3391 OSLibWinEndEnumWindows(henum);
3392 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3393 HWND hwndret = wnd->getWindowHandle();
3394 RELEASE_WNDOBJ(wnd);
3395 return hwndret;
3396 }
3397 RELEASE_WNDOBJ(wnd);
3398 }
3399 hwnd = OSLibWinGetNextWindow(henum);
3400 }
3401 OSLibWinEndEnumWindows(henum);
3402 if(parent) RELEASE_WNDOBJ(parent);
3403 if(firstchild) RELEASE_WNDOBJ(firstchild);
3404 }
3405 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3406 return 0;
3407}
3408//******************************************************************************
3409//******************************************************************************
3410HWND Win32BaseWindow::GetWindow(UINT uCmd)
3411{
3412 HWND hwndRelated = 0;
3413 Win32BaseWindow *window;
3414
3415 switch(uCmd)
3416 {
3417 case GW_HWNDFIRST:
3418 window = (Win32BaseWindow *)getParent();
3419 if(window)
3420 {
3421 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3422 window = GetWindowFromOS2FrameHandle(hwndRelated);
3423 if(window) {
3424 hwndRelated = window->getWindowHandle();
3425 RELEASE_WNDOBJ(window);
3426 }
3427 else hwndRelated = 0;
3428 }
3429 else {
3430 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3431 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3432 }
3433 break;
3434
3435 case GW_HWNDLAST:
3436 window = (Win32BaseWindow *)getParent();
3437 if(window) {
3438 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3439 dprintf(("os2 handle %x", hwndRelated));
3440 window = GetWindowFromOS2FrameHandle(hwndRelated);
3441 if(window) {
3442 hwndRelated = window->getWindowHandle();
3443 RELEASE_WNDOBJ(window);
3444 }
3445 else hwndRelated = 0;
3446 }
3447 else {
3448 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3449 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3450 }
3451 break;
3452
3453 case GW_HWNDNEXT:
3454 if(getParent()) {
3455 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3456 window = GetWindowFromOS2FrameHandle(hwndRelated);
3457 if(window) {
3458 hwndRelated = window->getWindowHandle();
3459 RELEASE_WNDOBJ(window);
3460 }
3461 else hwndRelated = 0;
3462 }
3463 else {
3464 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3465 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3466 }
3467 break;
3468
3469 case GW_HWNDPREV:
3470 if(getParent()) {
3471 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3472 window = GetWindowFromOS2FrameHandle(hwndRelated);
3473 if(window) {
3474 hwndRelated = window->getWindowHandle();
3475 RELEASE_WNDOBJ(window);
3476 }
3477 else hwndRelated = 0;
3478 }
3479 else {
3480 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3481 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3482 }
3483 break;
3484
3485 case GW_OWNER:
3486 {
3487 Win32BaseWindow *owner = getOwner();
3488 if(owner) {
3489 hwndRelated = owner->getWindowHandle();
3490 }
3491 break;
3492 }
3493
3494 case GW_CHILD:
3495 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3496 window = GetWindowFromOS2FrameHandle(hwndRelated);
3497
3498 //Before a window has processed WM_NCCREATE:
3499 //- GetWindow(parent, GW_CHILD) can't return that window handle
3500 //(verified in NT4, SP6)
3501 if(window) {
3502 if(window->state >= STATE_POST_WMNCCREATE) {
3503 hwndRelated = window->getWindowHandle();
3504 RELEASE_WNDOBJ(window);
3505 }
3506 else {
3507 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3508 RELEASE_WNDOBJ(window);
3509 }
3510 }
3511 else hwndRelated = 0;
3512
3513 break;
3514
3515 //for internal use only
3516 case GW_HWNDNEXTCHILD:
3517 lock();
3518 window = (Win32BaseWindow *)getNextChild();
3519 if(window) {
3520 hwndRelated = window->getWindowHandle();
3521 }
3522 else hwndRelated = 0;
3523 unlock();
3524 break;
3525
3526 case GW_HWNDPREVCHILD:
3527 DebugInt3();
3528 break;
3529
3530 case GW_HWNDFIRSTCHILD:
3531 lock();
3532 window = (Win32BaseWindow *)getFirstChild();
3533 if(window) {
3534 hwndRelated = window->getWindowHandle();
3535 }
3536 else hwndRelated = 0;
3537 unlock();
3538 break;
3539
3540 case GW_HWNDLASTCHILD:
3541 lock();
3542 window = (Win32BaseWindow *)getFirstChild();
3543 if(window) {
3544 while (window->getNextChild())
3545 {
3546 window = (Win32BaseWindow *)window->getNextChild();
3547 }
3548 hwndRelated = window->getWindowHandle();
3549 }
3550 else hwndRelated = 0;
3551 unlock();
3552 break;
3553 }
3554end:
3555 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3556 return hwndRelated;
3557}
3558//******************************************************************************
3559//******************************************************************************
3560PRECT Win32BaseWindow::getWindowRect()
3561{
3562 return &rectWindow;
3563}
3564//******************************************************************************
3565//******************************************************************************
3566HWND Win32BaseWindow::SetActiveWindow()
3567{
3568 HWND hwndActive;
3569
3570 dprintf(("SetActiveWindow %x", getWindowHandle()));
3571 if(getStyle() & WS_CHILD) {
3572// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3573 dprintf(("WARNING: Window is a child or disabled"));
3574 return 0;
3575 }
3576
3577 if(GetActiveWindow() == getWindowHandle()) {
3578 dprintf(("Window already active"));
3579 return getWindowHandle();
3580 }
3581 if (HOOK_IsHooked( WH_CBT ))
3582 {
3583 CBTACTIVATESTRUCT cbta;
3584 LRESULT ret;
3585
3586 cbta.fMouse = FALSE;
3587 cbta.hWndActive = GetActiveWindow();
3588 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3589 if(ret)
3590 {
3591 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3592 return cbta.hWndActive;
3593 }
3594 }
3595 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3596
3597// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3598// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3599// }
3600 hwndActive = GetActiveWindow();
3601 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3602}
3603//******************************************************************************
3604//Used to change active status of an mdi window
3605//******************************************************************************
3606BOOL Win32BaseWindow::DeactivateChildWindow()
3607{
3608 /* child windows get a WM_CHILDACTIVATE message */
3609 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3610 {
3611 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3612 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3613 return TRUE;
3614 }
3615 DebugInt3(); //should not be called for non-child window
3616 return FALSE;
3617}
3618//******************************************************************************
3619//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3620//******************************************************************************
3621BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3622{
3623 BOOL rc;
3624
3625 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3626 //return true if previous state was disabled, else false (sdk docs)
3627 rc = (getStyle() & WS_DISABLED) != 0;
3628 if(rc && !fEnable) {
3629 SendMessageA(getWindowHandle(), WM_CANCELMODE, 0, 0);
3630 }
3631 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3632 if(fEnable == FALSE) {
3633 //SvL: No need to clear focus as PM already does this
3634 if(getWindowHandle() == GetCapture()) {
3635 ReleaseCapture(); /* A disabled window can't capture the mouse */
3636 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3637 }
3638 }
3639 return rc;
3640}
3641//******************************************************************************
3642//******************************************************************************
3643BOOL Win32BaseWindow::CloseWindow()
3644{
3645 if (::GetWindowLongW( getWindowHandle() , GWL_STYLE ) & WS_CHILD) return FALSE;
3646 ShowWindow( SW_MINIMIZE );
3647 return TRUE;
3648}
3649//******************************************************************************
3650//TODO: Not be 100% correct; should return active window of current thread
3651// or NULL when there is none -> WinQueryActiveWindow just returns
3652// the current active window
3653//******************************************************************************
3654HWND Win32BaseWindow::GetActiveWindow()
3655{
3656 HWND hwndActive;
3657
3658 hwndActive = OSLibWinQueryActiveWindow();
3659 return OS2ToWin32Handle(hwndActive);
3660}
3661//******************************************************************************
3662//******************************************************************************
3663BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3664{
3665 INT len = GetWindowTextLength(fUnicode);
3666 BOOL res;
3667
3668 if (wndname == NULL)
3669 return (len == 0);
3670
3671 len++;
3672 if (fUnicode)
3673 {
3674 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3675
3676 GetWindowTextW(text,len);
3677 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3678 free(text);
3679 }
3680 else
3681 {
3682 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3683
3684 GetWindowTextA(text,len);
3685 res = (strcmp(text,wndname) == 0);
3686 free(text);
3687 }
3688
3689 return res;
3690}
3691//******************************************************************************
3692//******************************************************************************
3693CHAR *Win32BaseWindow::getWindowNamePtrA()
3694{
3695 INT len = GetWindowTextLength(FALSE);
3696 CHAR *text;
3697
3698 if (len == 0) return NULL;
3699 len++;
3700 text = (CHAR*)malloc(len*sizeof(CHAR));
3701 GetWindowTextA(text,len);
3702
3703 return text;
3704}
3705//******************************************************************************
3706//******************************************************************************
3707WCHAR *Win32BaseWindow::getWindowNamePtrW()
3708{
3709 INT len = GetWindowTextLength(TRUE);
3710 WCHAR *text;
3711
3712 if (len == 0) return NULL;
3713 len++;
3714 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3715 GetWindowTextW(text,len);
3716
3717 return text;
3718}
3719//******************************************************************************
3720//******************************************************************************
3721VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3722{
3723 if (namePtr) free(namePtr);
3724}
3725//******************************************************************************
3726//When using this API for a window that was created by a different process, NT
3727//does NOT send WM_GETTEXTLENGTH.
3728//******************************************************************************
3729int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3730{
3731 //if the destination window is created by this process, send message
3732 if(dwProcessId == currentProcessId)
3733 {
3734 if(fUnicode) {
3735 return SendMessageW(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3736 }
3737 else return SendMessageA(getWindowHandle(), WM_GETTEXTLENGTH,0,0);
3738 }
3739 //else get data directory from window structure
3740 //TODO: must lock window structure.... (TODO)
3741 return windowNameLength;
3742}
3743//******************************************************************************
3744//When using this API for a window that was created by a different process, NT
3745//does NOT send WM_GETTEXT.
3746//******************************************************************************
3747int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3748{
3749 //if the destination window is created by this process, send message
3750 if(dwProcessId == currentProcessId) {
3751 return SendMessageA(getWindowHandle(),WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3752 }
3753
3754 //else get data directory from window structure
3755 if (!lpsz || !cch) return 0;
3756 if (!windowNameA) lpsz[0] = 0;
3757 else memcpy(lpsz, windowNameA, min(windowNameLength + 1, cch) );
3758 return min(windowNameLength, cch);
3759}
3760//******************************************************************************
3761//When using this API for a window that was created by a different process, NT
3762//does NOT send WM_GETTEXT.
3763//******************************************************************************
3764int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3765{
3766 //if the destination window is created by this process, send message
3767 if(dwProcessId == currentProcessId) {
3768 return ::SendMessageW(getWindowHandle(), WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3769 }
3770 //else get data directory from window structure
3771 if (!lpsz || !cch)
3772 return 0;
3773 if (!windowNameW)
3774 lpsz[0] = 0;
3775 else
3776 memcpy(lpsz, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), cch));
3777
3778 return min(windowNameLength, cch);
3779}
3780//******************************************************************************
3781//TODO: How does this work when the target window belongs to a different process???
3782//******************************************************************************
3783BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3784{
3785 return SendMessageA(getWindowHandle(),WM_SETTEXT,0,(LPARAM)lpsz);
3786}
3787//******************************************************************************
3788//******************************************************************************
3789BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3790{
3791 return SendMessageW(getWindowHandle(), WM_SETTEXT,0,(LPARAM)lpsz);
3792}
3793//******************************************************************************
3794//******************************************************************************
3795LONG Win32BaseWindow::SetWindowLong(int index, ULONG value, BOOL fUnicode)
3796{
3797 LONG oldval;
3798
3799 switch(index) {
3800 case GWL_EXSTYLE:
3801 {
3802 STYLESTRUCT ss;
3803
3804 if(dwExStyle == value) {
3805 oldval = value;
3806 break;
3807 }
3808 ss.styleOld = dwExStyle;
3809 ss.styleNew = value;
3810 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3811 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3812 setExStyle(ss.styleNew);
3813 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3814
3815 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3816 getStyle(), getExStyle(),ss.styleOld);
3817
3818 oldval = ss.styleOld;
3819 break;
3820 }
3821 case GWL_STYLE:
3822 {
3823 STYLESTRUCT ss;
3824
3825 //SvL: TODO: Can you change minimize or maximize status here too?
3826
3827 if(dwStyle == value) {
3828 oldval = value;
3829 break;
3830 }
3831 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3832
3833 //Changing WS_CHILD style is allowed
3834 ss.styleOld = getStyle();
3835 ss.styleNew = value;
3836 SendMessageA(getWindowHandle(),WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3837 setStyle(ss.styleNew);
3838 SendMessageA(getWindowHandle(),WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3839
3840 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(),
3841 getStyle(), getExStyle(),ss.styleOld);
3842
3843 //TODO: Might not be correct to use ShowWindow here
3844 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3845 if(ss.styleNew & WS_VISIBLE)
3846 ShowWindow(SW_SHOWNOACTIVATE);
3847 else ShowWindow(SW_HIDE);
3848 }
3849
3850#ifdef DEBUG
3851 PrintWindowStyle(ss.styleNew, 0);
3852#endif
3853 oldval = ss.styleOld;
3854 break;
3855 }
3856 case GWL_WNDPROC:
3857 {
3858 //Note: Type of SetWindowLong determines new window proc type
3859 // UNLESS the new window proc has already been registered
3860 // (use the old type in that case)
3861 // (VERIFIED in NT 4, SP6)
3862 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3863 if(type == WIN_PROC_INVALID) {
3864 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3865 }
3866 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3867 dprintf(("SetWindowLong%c GWL_WNDPROC %x old %x new wndproc %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), oldval, value));
3868 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3869 break;
3870 }
3871 case GWL_HINSTANCE:
3872 oldval = hInstance;
3873 hInstance = value;
3874 break;
3875
3876 case GWL_HWNDPARENT:
3877 dprintf(("GWL_ID GWL_HWNDPARENT %x, new %x", GetParent(), value));
3878 oldval = SetParent((HWND)value);
3879 break;
3880
3881 case GWL_ID:
3882 dprintf(("GWL_ID old %x, new %x", getWindowId(), value));
3883 oldval = getWindowId();
3884 setWindowId(value);
3885 break;
3886
3887 case GWL_USERDATA:
3888 oldval = userData;
3889 userData = value;
3890 break;
3891
3892 default:
3893 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3894 {
3895 oldval = *(ULONG *)(userWindowBytes + index);
3896 *(ULONG *)(userWindowBytes + index) = value;
3897 break;
3898 }
3899 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3900 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3901 return 0;
3902 }
3903 //Note: NT4, SP6 does not set the last error to 0
3904 SetLastError(ERROR_SUCCESS);
3905 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3906 return oldval;
3907}
3908//******************************************************************************
3909//******************************************************************************
3910ULONG Win32BaseWindow::GetWindowLong(int index, BOOL fUnicode)
3911{
3912 ULONG value;
3913
3914 switch(index) {
3915 case GWL_EXSTYLE:
3916 value = dwExStyle;
3917 break;
3918 case GWL_STYLE:
3919 value = dwStyle;
3920 break;
3921 case GWL_WNDPROC:
3922 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3923 break;
3924 case GWL_HINSTANCE:
3925 value = hInstance;
3926 break;
3927 case GWL_HWNDPARENT:
3928 value = GetParent();
3929 break;
3930 case GWL_ID:
3931 value = getWindowId();
3932 break;
3933 case GWL_USERDATA:
3934 value = userData;
3935 break;
3936 default:
3937 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3938 {
3939 value = *(ULONG *)(userWindowBytes + index);
3940 break;
3941 }
3942 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3943 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3944 return 0;
3945 }
3946 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3947 //Note: NT4, SP6 does not set the last error to 0
3948 SetLastError(ERROR_SUCCESS);
3949 return value;
3950}
3951//******************************************************************************
3952//******************************************************************************
3953WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3954{
3955 WORD oldval;
3956
3957 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3958 {
3959 oldval = *(WORD *)(userWindowBytes + index);
3960 *(WORD *)(userWindowBytes + index) = value;
3961 //Note: NT4, SP6 does not set the last error to 0
3962 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3963 SetLastError(ERROR_SUCCESS);
3964 return oldval;
3965 }
3966 switch(index)
3967 {
3968 case GWW_HINSTANCE:
3969 oldval = hInstance;
3970 hInstance = value;
3971 break;
3972
3973 case GWW_HWNDPARENT:
3974 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3975 break;
3976
3977 case GWW_ID:
3978 oldval = getWindowId();
3979 setWindowId(value);
3980 break;
3981
3982 default:
3983 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3984 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3985 return 0;
3986 }
3987 //Note: NT4, SP6 does not set the last error to 0
3988 SetLastError(ERROR_SUCCESS);
3989 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3990 return oldval;
3991}
3992//******************************************************************************
3993//******************************************************************************
3994WORD Win32BaseWindow::GetWindowWord(int index)
3995{
3996 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3997 {
3998 //Note: NT4, SP6 does not set the last error to 0
3999 SetLastError(ERROR_SUCCESS);
4000 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
4001 return *(WORD *)(userWindowBytes + index);
4002 }
4003 switch(index)
4004 {
4005 case GWW_ID:
4006 if(HIWORD(getWindowId()))
4007 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
4008 return (WORD)getWindowId();
4009
4010 case GWW_HWNDPARENT:
4011 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
4012 return (WORD) GetParent();
4013
4014 case GWW_HINSTANCE:
4015 if (HIWORD(hInstance))
4016 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
4017 return (WORD)hInstance;
4018 }
4019
4020 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
4021 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
4022 return 0;
4023}
4024//******************************************************************************
4025// Win32BaseWindow::setVisibleRgnNotifyProc
4026//
4027// Sets the visible region change notification handler. Called when
4028// the window receives a WM_VRNDISABLED or WM_VRNENABLED message (PM).
4029//
4030// Parameters:
4031// VISRGN_NOTIFY_PROC lpNotifyProc - notification handler
4032// DWORD dwUserData - caller supplied parameter for handler invocations
4033//
4034// Returns:
4035// TRUE - Success
4036// FALSE - Failure
4037//
4038//******************************************************************************
4039BOOL Win32BaseWindow::setVisibleRgnNotifyProc(VISRGN_NOTIFY_PROC lpNotifyProc, DWORD dwUserData)
4040{
4041 lpVisRgnNotifyProc = lpNotifyProc;
4042 dwVisRgnNotifyParam = dwUserData;
4043 return TRUE;
4044}
4045//******************************************************************************
4046// Win32BaseWindow::callVisibleRgnNotifyProc
4047//
4048// Call the visible region change notification handler. Called when
4049// the window receives a WM_VRNDISABLED or WM_VRNENABLED message (PM).
4050//
4051// Parameters:
4052// BOOL fDrawingAllowed - drawing is allowed or not
4053//
4054// Returns:
4055// TRUE - Success
4056// FALSE - Failure
4057//
4058//******************************************************************************
4059void Win32BaseWindow::callVisibleRgnNotifyProc(BOOL fDrawingAllowed)
4060{
4061 if(fDrawingAllowed) {
4062 fWindowLocked = TRUE;
4063 }
4064 else {
4065 fWindowLocked = FALSE;
4066 }
4067 if(lpVisRgnNotifyProc) {
4068 lpVisRgnNotifyProc(getWindowHandle(), fDrawingAllowed, dwVisRgnNotifyParam);
4069 }
4070}
4071//******************************************************************************
4072//Locates window in linked list and increases reference count (if found)
4073//Window object must be unreferenced after usage
4074//******************************************************************************
4075Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
4076{
4077 Win32BaseWindow *window;
4078
4079////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
4080//// while browsing
4081//// Not thread safe now!
4082//// lock(&critsect);
4083 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
4084 if(window) {
4085//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
4086 window->addRef();
4087 }
4088//// unlock(&critsect);
4089 return window;
4090 }
4091//// unlock(&critsect);
4092// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
4093 return NULL;
4094}
4095//******************************************************************************
4096//Locates window in linked list and increases reference count (if found)
4097//Window object must be unreferenced after usage
4098//******************************************************************************
4099Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
4100{
4101 DWORD magic;
4102 HWND hwnd;
4103
4104 if(hwndOS2 == OSLIB_HWND_DESKTOP)
4105 {
4106 windowDesktop->addRef();
4107 return windowDesktop;
4108 }
4109
4110 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
4111 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
4112
4113 if(hwnd && CheckMagicDword(magic)) {
4114 return GetWindowFromHandle(hwnd);
4115 }
4116// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
4117 return 0;
4118}
4119//******************************************************************************
4120//Locates window in linked list and increases reference count (if found)
4121//Window object must be unreferenced after usage
4122//******************************************************************************
4123Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
4124{
4125 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
4126}
4127//******************************************************************************
4128//******************************************************************************
4129HWND WIN32API Win32ToOS2Handle(HWND hwnd)
4130{
4131 HWND hwndOS2;
4132
4133 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4134
4135 if(window) {
4136 hwndOS2 = window->getOS2WindowHandle();
4137 RELEASE_WNDOBJ(window);
4138 return hwndOS2;
4139 }
4140// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4141 return hwnd;
4142}
4143//******************************************************************************
4144//******************************************************************************
4145HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
4146{
4147 HWND hwndOS2;
4148
4149 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
4150
4151 if(window) {
4152 hwndOS2 = window->getOS2FrameWindowHandle();
4153 RELEASE_WNDOBJ(window);
4154 return hwndOS2;
4155 }
4156// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
4157 return hwnd;
4158}
4159//******************************************************************************
4160//******************************************************************************
4161HWND WIN32API OS2ToWin32Handle(HWND hwnd)
4162{
4163 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
4164 HWND hwndWin32;
4165
4166 if(window) {
4167 hwndWin32 = window->getWindowHandle();
4168 RELEASE_WNDOBJ(window);
4169 return hwndWin32;
4170 }
4171 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
4172 if(window) {
4173 hwndWin32 = window->getWindowHandle();
4174 RELEASE_WNDOBJ(window);
4175 return hwndWin32;
4176 }
4177
4178// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
4179 return 0;
4180// else return hwnd; //OS/2 window handle
4181}
4182#ifdef DEBUG
4183LONG Win32BaseWindow::addRef()
4184{
4185// dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
4186 return GenericObject::addRef();
4187}
4188//******************************************************************************
4189//******************************************************************************
4190LONG Win32BaseWindow::release(char *function, int line)
4191{
4192// dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
4193 return GenericObject::release();
4194}
4195#endif
4196//******************************************************************************
4197//******************************************************************************
4198GenericObject *Win32BaseWindow::windows = NULL;
4199CRITICAL_SECTION Win32BaseWindow::critsect = {0};
4200
4201//******************************************************************************
4202//******************************************************************************
4203#ifdef DEBUG
4204void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
4205{
4206 char style[256] = "";
4207 char exstyle[256] = "";
4208
4209 /* Window styles */
4210 if(dwStyle & WS_CHILD)
4211 strcat(style, "WS_CHILD ");
4212 if(dwStyle & WS_POPUP)
4213 strcat(style, "WS_POPUP ");
4214 if(dwStyle & WS_VISIBLE)
4215 strcat(style, "WS_VISIBLE ");
4216 if(dwStyle & WS_DISABLED)
4217 strcat(style, "WS_DISABLED ");
4218 if(dwStyle & WS_CLIPSIBLINGS)
4219 strcat(style, "WS_CLIPSIBLINGS ");
4220 if(dwStyle & WS_CLIPCHILDREN)
4221 strcat(style, "WS_CLIPCHILDREN ");
4222 if(dwStyle & WS_MAXIMIZE)
4223 strcat(style, "WS_MAXIMIZE ");
4224 if(dwStyle & WS_MINIMIZE)
4225 strcat(style, "WS_MINIMIZE ");
4226 if(dwStyle & WS_GROUP)
4227 strcat(style, "WS_GROUP ");
4228 if(dwStyle & WS_TABSTOP)
4229 strcat(style, "WS_TABSTOP ");
4230
4231 if((dwStyle & WS_CAPTION) == WS_CAPTION)
4232 strcat(style, "WS_CAPTION ");
4233 if(dwStyle & WS_DLGFRAME)
4234 strcat(style, "WS_DLGFRAME ");
4235 if(dwStyle & WS_BORDER)
4236 strcat(style, "WS_BORDER ");
4237
4238 if(dwStyle & WS_VSCROLL)
4239 strcat(style, "WS_VSCROLL ");
4240 if(dwStyle & WS_HSCROLL)
4241 strcat(style, "WS_HSCROLL ");
4242 if(dwStyle & WS_SYSMENU)
4243 strcat(style, "WS_SYSMENU ");
4244 if(dwStyle & WS_THICKFRAME)
4245 strcat(style, "WS_THICKFRAME ");
4246 if(dwStyle & WS_MINIMIZEBOX)
4247 strcat(style, "WS_MINIMIZEBOX ");
4248 if(dwStyle & WS_MAXIMIZEBOX)
4249 strcat(style, "WS_MAXIMIZEBOX ");
4250
4251 if(dwExStyle & WS_EX_DLGMODALFRAME)
4252 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4253 if(dwExStyle & WS_EX_ACCEPTFILES)
4254 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4255 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4256 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4257 if(dwExStyle & WS_EX_TOPMOST)
4258 strcat(exstyle, "WS_EX_TOPMOST ");
4259 if(dwExStyle & WS_EX_TRANSPARENT)
4260 strcat(exstyle, "WS_EX_TRANSPARENT ");
4261
4262 if(dwExStyle & WS_EX_MDICHILD)
4263 strcat(exstyle, "WS_EX_MDICHILD ");
4264 if(dwExStyle & WS_EX_TOOLWINDOW)
4265 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4266 if(dwExStyle & WS_EX_WINDOWEDGE)
4267 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4268 if(dwExStyle & WS_EX_CLIENTEDGE)
4269 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4270 if(dwExStyle & WS_EX_CONTEXTHELP)
4271 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4272 if(dwExStyle & WS_EX_RIGHT)
4273 strcat(exstyle, "WS_EX_RIGHT ");
4274 if(dwExStyle & WS_EX_LEFT)
4275 strcat(exstyle, "WS_EX_LEFT ");
4276 if(dwExStyle & WS_EX_RTLREADING)
4277 strcat(exstyle, "WS_EX_RTLREADING ");
4278 if(dwExStyle & WS_EX_LTRREADING)
4279 strcat(exstyle, "WS_EX_LTRREADING ");
4280 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4281 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4282 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4283 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4284 if(dwExStyle & WS_EX_CONTROLPARENT)
4285 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4286 if(dwExStyle & WS_EX_STATICEDGE)
4287 strcat(exstyle, "WS_EX_STATICEDGE ");
4288 if(dwExStyle & WS_EX_APPWINDOW)
4289 strcat(exstyle, "WS_EX_APPWINDOW ");
4290
4291 dprintf(("Window style: %x %s", dwStyle, style));
4292 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4293}
4294#endif
4295//******************************************************************************
4296//******************************************************************************
Note: See TracBrowser for help on using the repository browser.