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

Last change on this file since 9590 was 9590, checked in by sandervl, 23 years ago

corrected regressions caused by previous setfocus fix; make sure owner isn't disabled when specifying SWP_DEACTIVATE

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