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

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

Changes for fake windows. Moved them into a seperate C++ class and overload some methods to correct the behaviour

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