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

Last change on this file since 3611 was 3610, checked in by sandervl, 25 years ago

Tasklist fixes

File size: 109.3 KB
Line 
1/* $Id: win32wbase.cpp,v 1.195 2000-05-26 18:43:34 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-2000 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: Client rectangle always relative to frame window; window rectangle in screen coordinates
18 *
19 * Project Odin Software License can be found in LICENSE.TXT
20 *
21 */
22#include <os2win.h>
23#include <win.h>
24#include <stdlib.h>
25#include <string.h>
26#include <stdarg.h>
27#include <assert.h>
28#include <misc.h>
29#include <heapstring.h>
30#include <win32wbase.h>
31#include <winres.h>
32#include "wndmsg.h"
33#include "oslibwin.h"
34#include "oslibmsg.h"
35#include "oslibutil.h"
36#include "oslibgdi.h"
37#include "oslibres.h"
38#include "oslibdos.h"
39#include "syscolor.h"
40#include "win32wndhandle.h"
41#include "dc.h"
42#include "pmframe.h"
43#include "win32wdesktop.h"
44#include "pmwindow.h"
45#include "controls.h"
46#include <wprocess.h>
47#include <win\hook.h>
48#include <menu.h>
49#define INCL_TIMERWIN32
50#include "timer.h"
51
52#define DBG_LOCALLOG DBG_win32wbase
53#include "dbglocal.h"
54
55/* bits in the dwKeyData */
56#define KEYDATA_ALT 0x2000
57#define KEYDATA_PREVSTATE 0x4000
58
59void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
60
61static fDestroyAll = FALSE;
62//For quick lookup of current process id
63static ULONG currentProcessId = -1;
64
65//******************************************************************************
66//******************************************************************************
67Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
68{
69 Init();
70}
71//******************************************************************************
72//******************************************************************************
73Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
74 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
75{
76 Init();
77 this->isUnicode = isUnicode;
78 CreateWindowExA(lpCreateStructA, classAtom);
79}
80//******************************************************************************
81//******************************************************************************
82void Win32BaseWindow::Init()
83{
84 isUnicode = FALSE;
85 fFirstShow = TRUE;
86 fIsDialog = FALSE;
87 fIsModalDialogOwner = FALSE;
88 OS2HwndModalDialog = 0;
89 fInternalMsg = FALSE;
90 fNoSizeMsg = FALSE;
91 fIsDestroyed = FALSE;
92 fDestroyWindowCalled = FALSE;
93 fCreated = FALSE;
94 fTaskList = FALSE;
95 fParentDC = FALSE;
96 fComingToTop = FALSE;
97
98 windowNameA = NULL;
99 windowNameW = NULL;
100 wndNameLength = 0;
101
102 userWindowLong = NULL;;
103 nrUserWindowLong = 0;
104
105 magic = WIN32PM_MAGIC;
106 OS2Hwnd = 0;
107 OS2HwndFrame = 0;
108 hSysMenu = 0;
109 Win32Hwnd = 0;
110
111 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
112 {
113 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
114 DebugInt3();
115 }
116
117 posx = posy = 0;
118 width = height = 0;
119
120 dwExStyle = 0;
121 dwStyle = 0;
122 win32wndproc = 0;
123 hInstance = 0;
124 dwIDMenu = 0; //0xFFFFFFFF; //default -1
125 userData = 0;
126 contextHelpId = 0;
127 hotkey = 0;
128
129 pOldFrameProc = NULL;
130
131 hwndLinkAfter = HWND_BOTTOM;
132 flags = 0;
133 lastHitTestVal = HTOS_NORMAL;
134 owner = NULL;
135 windowClass = 0;
136
137 hIcon = 0;
138 hIconSm = 0;
139
140 EraseBkgndFlag = TRUE;
141
142 horzScrollInfo = NULL;
143 vertScrollInfo = NULL;
144
145 propertyList = NULL;
146
147 ownDC = 0;
148 hWindowRegion = 0;
149 hClipRegion = 0;
150
151 hTaskList = 0;
152
153 if(currentProcessId == -1)
154 {
155 currentProcessId = GetCurrentProcessId();
156 }
157 dwThreadId = GetCurrentThreadId();
158 dwProcessId = currentProcessId;
159}
160//******************************************************************************
161//todo get rid of resources (menu, icon etc)
162//******************************************************************************
163Win32BaseWindow::~Win32BaseWindow()
164{
165 if(hTaskList) {
166 OSLibWinRemoveFromTasklist(hTaskList);
167 }
168
169 OSLibWinSetVisibleRegionNotify(OS2HwndFrame, FALSE);
170 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
171 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
172
173 if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
174 {
175 //if we're the last child that's being destroyed and our
176 //parent window was also destroyed, then we delete the parent object
177 if(getParent()->IsWindowDestroyed())
178 {
179 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
180 delete getParent();
181 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
182 }
183 }
184 else
185 if(fDestroyAll) {
186 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
187 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
188 }
189
190 if(isOwnDC())
191 releaseOwnDC(ownDC);
192
193 if(Win32Hwnd)
194 HwFreeWindowHandle(Win32Hwnd);
195
196 if(userWindowLong)
197 free(userWindowLong);
198
199 if(windowNameA) {
200 free(windowNameA);
201 windowNameA = NULL;
202 }
203 if(windowNameW) {
204 free(windowNameW);
205 windowNameW = NULL;
206 }
207 if(vertScrollInfo) {
208 free(vertScrollInfo);
209 vertScrollInfo = NULL;
210 }
211 if(horzScrollInfo) {
212 free(horzScrollInfo);
213 horzScrollInfo = NULL;
214 }
215 if(propertyList) {
216 removeWindowProps();
217 }
218}
219//******************************************************************************
220//******************************************************************************
221void Win32BaseWindow::DestroyAll()
222{
223 fDestroyAll = TRUE;
224 GenericObject::DestroyAll(windows);
225}
226//******************************************************************************
227//******************************************************************************
228BOOL Win32BaseWindow::isChild()
229{
230 return ((dwStyle & WS_CHILD) != 0);
231}
232//******************************************************************************
233//******************************************************************************
234BOOL Win32BaseWindow::IsWindowUnicode()
235{
236 dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
237 return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
238}
239//******************************************************************************
240//******************************************************************************
241BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
242{
243 char buffer[256];
244
245#ifdef DEBUG
246 PrintWindowStyle(cs->style, cs->dwExStyle);
247#endif
248
249 //If window has no owner/parent window, then it will be added to the tasklist
250 //(depending on visibility state)
251 if (!cs->hwndParent) fTaskList = TRUE;
252
253 sw = SW_SHOW;
254 SetLastError(0);
255
256 /* Find the parent window */
257 if (cs->hwndParent)
258 {
259 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
260 if(!window) {
261 dprintf(("Bad parent %04x\n", cs->hwndParent ));
262 SetLastError(ERROR_INVALID_PARAMETER);
263 return FALSE;
264 }
265 /* Make sure parent is valid */
266 if (!window->IsWindow() )
267 {
268 dprintf(("Bad parent %04x\n", cs->hwndParent ));
269 SetLastError(ERROR_INVALID_PARAMETER);
270 return FALSE;
271 }
272 /* Windows does this for overlapped windows
273 * (I don't know about other styles.) */
274 if (cs->hwndParent == GetDesktopWindow() && (!(cs->style & WS_CHILD) || (cs->style & WS_POPUP)))
275 {
276 cs->hwndParent = 0;
277 }
278 }
279 else
280 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
281 dprintf(("No parent for child window\n" ));
282 SetLastError(ERROR_INVALID_PARAMETER);
283 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
284 }
285
286 /* Find the window class */
287 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
288 if (!windowClass)
289 {
290 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
291 dprintf(("Bad class '%s'\n", buffer ));
292 SetLastError(ERROR_INVALID_PARAMETER);
293 return 0;
294 }
295#ifdef DEBUG
296 if(HIWORD(cs->lpszClass))
297 {
298 char *astring;
299
300 if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
301 else astring = (char *)cs->lpszClass;
302
303 dprintf(("Window class %s", astring));
304 if(isUnicode) FreeAsciiString(astring);
305 }
306 else dprintf(("Window class %x", cs->lpszClass));
307#endif
308
309 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
310 * with an atom as the class name, put some programs expect to have a *REAL* string in
311 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
312 */
313 if (!HIWORD(cs->lpszClass) ) {
314 if (isUnicode) {
315 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
316 }
317 else {
318 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
319 }
320 cs->lpszClass = buffer;
321 }
322
323 /* Fix the coordinates */
324 fXDefault = FALSE;
325 fCXDefault = FALSE;
326 if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16))
327 {
328 /* Never believe Microsoft's documentation... CreateWindowEx doc says
329 * that if an overlapped window is created with WS_VISIBLE style bit
330 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
331 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
332 * reveals that
333 *
334 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
335 * 2) it does not ignore the y parameter as the docs claim; instead, it
336 * uses it as second parameter to ShowWindow() unless y is either
337 * CW_USEDEFAULT or CW_USEDEFAULT16.
338 *
339 * The fact that we didn't do 2) caused bogus windows pop up when wine
340 * was running apps that were using this obscure feature. Example -
341 * calc.exe that comes with Win98 (only Win98, it's different from
342 * the one that comes with Win95 and NT)
343 */
344 if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y;
345
346 /* We have saved cs->y, now we can trash it */
347 cs->x = 0;
348 cs->y = 0;
349 fXDefault = TRUE;
350 }
351 if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16))
352 {
353 cs->cx = 600; /* FIXME */
354 cs->cy = 400;
355 fCXDefault = TRUE;
356 }
357 if (cs->style & (WS_POPUP | WS_CHILD))
358 {
359 fXDefault = FALSE;
360 if (fCXDefault)
361 {
362 fCXDefault = FALSE;
363 cs->cx = cs->cy = 0;
364 }
365 }
366 if (fXDefault && !fCXDefault) fXDefault = FALSE; //CB: only x positioning doesn't work (calc.exe,cdrlabel.exe)
367
368 if (cs->x < 0) cs->x = 0;
369 if (cs->y < 0) cs->y = 0;
370
371 //Allocate window words
372 nrUserWindowLong = windowClass->getExtraWndWords();
373 if(nrUserWindowLong) {
374 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
375 memset(userWindowLong, 0, nrUserWindowLong);
376 }
377
378 if ((cs->style & WS_CHILD) && cs->hwndParent)
379 {
380 SetParent(cs->hwndParent);
381 owner = GetWindowFromHandle(cs->hwndParent);
382 if(owner == NULL)
383 {
384 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
385 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
386 return FALSE;
387 }
388 //SvL: Shell positioning shouldn't be done for child windows! (breaks Notes)
389 fXDefault = fCXDefault = FALSE;
390 }
391 else
392 {
393 SetParent(0);
394 if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) {
395 owner = NULL;
396 }
397 else
398 {
399 owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
400 if(owner == NULL)
401 {
402 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
403 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
404 return FALSE;
405 }
406 }
407 }
408
409 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
410 hInstance = cs->hInstance;
411 dwStyle = cs->style & ~WS_VISIBLE;
412 dwExStyle = cs->dwExStyle;
413
414 hwndLinkAfter = HWND_TOP;
415 if(CONTROLS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX))
416 {
417 hwndLinkAfter = HWND_BOTTOM;
418 dwStyle |= WS_CLIPSIBLINGS;
419 }
420 else
421 if(CONTROLS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) {
422 dwStyle |= WS_CLIPSIBLINGS;
423 }
424
425 /* Increment class window counter */
426 windowClass->IncreaseWindowCount();
427
428 if (HOOK_IsHooked( WH_CBT ))
429 {
430 CBT_CREATEWNDA cbtc;
431 LRESULT ret;
432
433 cbtc.lpcs = cs;
434 cbtc.hwndInsertAfter = hwndLinkAfter;
435 ret = HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
436 if(ret)
437 {
438 dprintf(("CBT-hook returned 0!!"));
439 SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
440 return FALSE;
441 }
442 }
443
444 /* Correct the window style */
445 if (!(cs->style & WS_CHILD))
446 {
447 dwStyle |= WS_CLIPSIBLINGS;
448 if (!(cs->style & WS_POPUP))
449 {
450 dwStyle |= WS_CAPTION;
451 flags |= WIN_NEED_SIZE;
452 }
453 }
454 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
455
456 if (cs->style & WS_HSCROLL)
457 {
458 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
459 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
460 horzScrollInfo->MaxVal = 100;
461 horzScrollInfo->flags = ESB_ENABLE_BOTH;
462 }
463
464 if (cs->style & WS_VSCROLL)
465 {
466 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
467 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
468 vertScrollInfo->MaxVal = 100;
469 vertScrollInfo->flags = ESB_ENABLE_BOTH;
470 }
471
472 if(HIWORD(cs->lpszName))
473 {
474 if (!isUnicode)
475 {
476 wndNameLength = strlen(cs->lpszName);
477 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
478 strcpy(windowNameA,cs->lpszName);
479 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
480 lstrcpyAtoW(windowNameW,windowNameA);
481 windowNameA[wndNameLength] = 0;
482 windowNameW[wndNameLength] = 0;
483 }
484 else
485 {
486 wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
487 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
488 lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
489 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
490 lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
491 windowNameA[wndNameLength] = 0;
492 windowNameW[wndNameLength] = 0;
493 }
494 }
495
496 //copy pointer of CREATESTRUCT for usage in MsgCreate method
497 tmpcs = cs;
498
499 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
500 THDB *thdb = GetThreadTHDB();
501
502 if(thdb == NULL) {
503 dprintf(("Window creation failed - thdb == NULL")); //this is VERY bad
504 ExitProcess(666);
505 return FALSE;
506 }
507
508 thdb->newWindow = (ULONG)this;
509
510 DWORD dwOSWinStyle;
511
512 OSLibWinConvertStyle(dwStyle,dwExStyle,&dwOSWinStyle);
513
514 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
515 dwOSWinStyle,(char *)windowNameA,
516 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
517 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
518 &OS2HwndFrame, 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle() & CS_SAVEBITS);
519 if(OS2Hwnd == 0) {
520 dprintf(("Window creation failed!!"));
521 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
522 return FALSE;
523 }
524 OSLibWinSetVisibleRegionNotify(OS2HwndFrame, TRUE);
525 SetLastError(0);
526 return TRUE;
527}
528//******************************************************************************
529//******************************************************************************
530BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
531{
532 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
533 POINT maxSize, maxPos, minTrack, maxTrack;
534
535 OS2Hwnd = hwndClient;
536 OS2HwndFrame = hwndFrame;
537
538 fNoSizeMsg = TRUE;
539
540 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
541 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
542 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
543 return FALSE;
544 }
545 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
546 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
547 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
548 return FALSE;
549 }
550
551//SvL: This completely messes up MS Word 97 (no button bar, no menu)
552#if 0
553 //adjust CW_USEDEFAULT position
554 if (fXDefault | fCXDefault)
555 {
556 RECT rect;
557
558 //SvL: Returns invalid rectangle (not the expected shell default size)
559 OSLibWinQueryWindowRect(OS2HwndFrame,&rect,RELATIVE_TO_SCREEN);
560 if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
561 if (fXDefault)
562 {
563 cs->x = rect.left;
564 cs->y = rect.top;
565 if (!fCXDefault)
566 {
567 //CB: todo: adjust pos to screen rect
568 }
569 }
570 if (fCXDefault)
571 {
572 cs->cx = rect.right-rect.left;
573 cs->cy = rect.bottom-rect.top;
574 }
575 }
576#endif
577
578 OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
579
580 fakeWinBase.hwndThis = OS2Hwnd;
581 fakeWinBase.pWindowClass = windowClass;
582
583 //Set icon from window or class
584 if (hIcon)
585 OSLibWinSetIcon(OS2HwndFrame,hIcon);
586 else if (windowClass->getIcon())
587 OSLibWinSetIcon(OS2HwndFrame,windowClass->getIcon());
588
589 /* Get class or window DC if needed */
590 if(windowClass->getStyle() & CS_OWNDC) {
591 dprintf(("Class with CS_OWNDC style"));
592 ownDC = GetDC(getWindowHandle()); //TODO: or GetWindowDC???
593 }
594 else
595 if (windowClass->getStyle() & CS_PARENTDC) {
596 dprintf(("WARNING: Class with CS_PARENTDC style!"));
597 fParentDC = TRUE;
598 ownDC = 0;
599 }
600 else
601 if (windowClass->getStyle() & CS_CLASSDC) {
602 dprintf(("WARNING: Class with CS_CLASSDC style!"));
603 ownDC = 0;
604 }
605 /* Set the window menu */
606 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
607 {
608 if (cs->hMenu) {
609 ::SetMenu(getWindowHandle(), cs->hMenu);
610 }
611 else {
612 if (windowClass->getMenuNameA()) {
613 cs->hMenu = LoadMenuA(windowClass->getInstance(),windowClass->getMenuNameA());
614#if 0 //CB: hack for treeview test cases bug
615if (!cs->hMenu) cs->hMenu = LoadMenuA(windowClass->getInstance(),"MYAPP");
616#endif
617 if (cs->hMenu) ::SetMenu(getWindowHandle(), cs->hMenu );
618 }
619 }
620 }
621 else
622 {
623 setWindowId((DWORD)cs->hMenu);
624 }
625 hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0;
626
627 // Subclass frame
628 pOldFrameProc = FrameSubclassFrameWindow(this);
629
630 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
631 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
632 {
633 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
634 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
635 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
636 if (cs->cx < minTrack.x) cs->cx = minTrack.x;
637 if (cs->cy < minTrack.y) cs->cy = minTrack.y;
638 }
639
640 if(cs->style & WS_CHILD)
641 {
642 if(cs->cx < 0) cs->cx = 0;
643 if(cs->cy < 0) cs->cy = 0;
644 }
645 else
646 {
647 if (cs->cx <= 0) cs->cx = 1;
648 if (cs->cy <= 0) cs->cy = 1;
649 }
650
651 //preset rects
652 rectWindow.left = cs->x;
653 rectWindow.right = cs->x+cs->cx;
654 rectWindow.top = cs->y;
655 rectWindow.bottom = cs->y+cs->cy;
656 rectClient = rectWindow; //dummy client rect
657 OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
658
659 if (getParent()) mapWin32Rect(getParent()->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,&rectWindow);
660 /* Send the WM_CREATE message
661 * Perhaps we shouldn't allow width/height changes as well.
662 * See p327 in "Internals".
663 */
664 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
665
666 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
667 fCreated = TRUE;
668
669 if(fTaskList) {
670 hTaskList = OSLibWinAddToTaskList(OS2HwndFrame, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
671 }
672
673 if (SendInternalMessageA(WM_NCCREATE,0,(LPARAM)cs))
674 {
675 RECT tmpRect;
676
677 //CB: recheck flags
678 if (cs->style & (WS_POPUP | WS_CHILD))
679 {
680 fXDefault = FALSE;
681 if (fCXDefault)
682 {
683 fCXDefault = FALSE;
684 cs->cx = cs->cy = 0;
685 }
686 }
687 //update rect
688 rectWindow.left = cs->x;
689 rectWindow.right = cs->x+cs->cx;
690 rectWindow.top = cs->y;
691 rectWindow.bottom = cs->y+cs->cy;
692 tmpRect = rectWindow;
693 if (getParent()) mapWin32Rect(getParent()->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,&rectWindow);
694 OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
695
696 rectClient = rectWindow;
697 OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
698
699 //set the window size and update the client
700 SetWindowPos(hwndLinkAfter, tmpRect.left, tmpRect.top, tmpRect.right-tmpRect.left, tmpRect.bottom-tmpRect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED);
701 fNoSizeMsg = FALSE;
702 if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE
703 if( (SendInternalMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
704 {
705 if(!(flags & WIN_NEED_SIZE))
706 {
707 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
708 MAKELONG(rectClient.right-rectClient.left,
709 rectClient.bottom-rectClient.top));
710
711 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
712 }
713
714 if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
715 {
716 /* Notify the parent window only */
717 SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
718 if(!::IsWindow(getWindowHandle()))
719 {
720 dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
721 goto end;
722 }
723 }
724
725 if (cs->style & WS_VISIBLE) ShowWindow(sw);
726
727 /* Call WH_SHELL hook */
728 if (!(getStyle() & WS_CHILD) && !owner)
729 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0 );
730
731 SetLastError(0);
732 return TRUE;
733 }
734 }
735 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
736 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
737end:
738 return FALSE;
739}
740//******************************************************************************
741//******************************************************************************
742ULONG Win32BaseWindow::MsgQuit()
743{
744 return SendInternalMessageA(WM_QUIT, 0, 0);
745}
746//******************************************************************************
747//******************************************************************************
748ULONG Win32BaseWindow::MsgClose()
749{
750 return SendInternalMessageA(WM_CLOSE,0,0);
751}
752//******************************************************************************
753//******************************************************************************
754ULONG Win32BaseWindow::MsgDestroy()
755{
756 ULONG rc;
757 Win32BaseWindow *child;
758 HWND hwnd = getWindowHandle();
759
760 fIsDestroyed = TRUE;
761
762 if(fDestroyWindowCalled == FALSE)
763 {//this window was destroyed because DestroyWindow was called for it's parent
764 //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
765 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
766 {
767 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
768 {
769 /* Notify the parent window only */
770 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
771 }
772//// else DebugInt3();
773 }
774 }
775 SendInternalMessageA(WM_DESTROY, 0, 0);
776 if(::IsWindow(hwnd) == FALSE) {
777 //object already destroyed, so return immediately
778 return 1;
779 }
780 SendInternalMessageA(WM_NCDESTROY, 0, 0);
781
782 TIMER_KillTimerFromWindow(OS2Hwnd);
783
784 if(getFirstChild() == NULL) {
785 delete this;
786 }
787 return 1;
788}
789//******************************************************************************
790//******************************************************************************
791ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
792{
793 if(fEnable) {
794 dwStyle &= ~WS_DISABLED;
795 }
796 else dwStyle |= WS_DISABLED;
797
798 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
799}
800//******************************************************************************
801//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
802//******************************************************************************
803ULONG Win32BaseWindow::MsgShow(BOOL fShow)
804{
805 if(fNoSizeMsg || fDestroyWindowCalled) {
806 return 1;
807 }
808
809 if(fShow) {
810 setStyle(getStyle() | WS_VISIBLE);
811 }
812 else setStyle(getStyle() & ~WS_VISIBLE);
813
814 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
815}
816//******************************************************************************
817//******************************************************************************
818ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
819{
820 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
821 // a WM_WINDOWPOSCHANGED msg -> crash)
822 if(fNoSizeMsg || fDestroyWindowCalled)
823 return 0;
824
825 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
826}
827//******************************************************************************
828//******************************************************************************
829ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
830{
831 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
832 // a WM_WINDOWPOSCHANGED msg -> crash)
833 if(fNoSizeMsg || fDestroyWindowCalled)
834 return 1;
835
836 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
837}
838//******************************************************************************
839//******************************************************************************
840#if 0
841ULONG Win32BaseWindow::MsgMinMax()
842{
843
844}
845#endif
846//******************************************************************************
847//******************************************************************************
848ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
849{
850 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
851 //window scrollbars send these messages
852 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
853}
854//******************************************************************************
855//******************************************************************************
856ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
857{
858 lastHitTestVal = DispatchMessageA(msg);
859
860 dprintf2(("MsgHitTest %x (%d,%d) (%d,%d) (%d,%d) returned %x", getWindowHandle(), LOWORD(msg->lParam), HIWORD(msg->lParam), rectWindow.left, rectWindow.right, rectWindow.top, rectWindow.bottom, lastHitTestVal));
861
862 if (lastHitTestVal == HTTRANSPARENT)
863 return HTOS_TRANSPARENT;
864 else
865 return HTOS_NORMAL;
866}
867//******************************************************************************
868//******************************************************************************
869ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win)
870{
871 ULONG rc, procidhwnd = -1, threadidhwnd = 0;
872
873 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
874 if(fDestroyWindowCalled) {
875 return 0;
876 }
877
878 //According to SDK docs, if app returns FALSE & window is being deactivated,
879 //default processing is cancelled
880 //TODO: According to Wine we should proceed anyway if window is sysmodal
881#if 0
882 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
883 {
884 return 0;
885 }
886#endif
887 /* child windows get WM_CHILDACTIVATE message */
888 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
889 {
890 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
891 return 0;
892 }
893
894 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
895
896 if(hwndOS2Win) {
897 threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd);
898 }
899
900 if(fActivate) {
901 SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId); //activate; specify window thread id
902 }
903 else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd); //deactivate; specify thread id of other process
904 return rc;
905}
906//******************************************************************************
907//******************************************************************************
908ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
909{
910 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
911}
912//******************************************************************************
913//******************************************************************************
914ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
915{
916 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
917}
918//******************************************************************************
919//******************************************************************************
920ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
921{
922 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
923 if(fDestroyWindowCalled) {
924 return 0;
925 }
926
927 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
928}
929//******************************************************************************
930//******************************************************************************
931ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
932{
933 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
934 if(fDestroyWindowCalled) {
935 return 0;
936 }
937 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
938}
939//******************************************************************************
940//******************************************************************************
941ULONG Win32BaseWindow::MsgButton(MSG *msg)
942{
943 BOOL fClick = FALSE;
944
945// dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
946 switch(msg->message) {
947 case WM_LBUTTONDBLCLK:
948 case WM_RBUTTONDBLCLK:
949 case WM_MBUTTONDBLCLK:
950 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
951 {
952 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
953 MsgButton(msg);
954 msg->message++; //button-up
955 return MsgButton(msg);
956 }
957 break;
958 case WM_NCLBUTTONDBLCLK:
959 case WM_NCRBUTTONDBLCLK:
960 case WM_NCMBUTTONDBLCLK:
961 //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
962 fClick = TRUE;
963 break;
964
965 case WM_LBUTTONDOWN:
966 case WM_RBUTTONDOWN:
967 case WM_MBUTTONDOWN:
968 case WM_NCLBUTTONDOWN:
969 case WM_NCRBUTTONDOWN:
970 case WM_NCMBUTTONDOWN:
971 fClick = TRUE;
972 break;
973 }
974
975 if(fClick)
976 {
977 HWND hwndTop;
978
979 /* Activate the window if needed */
980 hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
981
982 HWND hwndActive = GetActiveWindow();
983 if (hwndTop && (getWindowHandle() != hwndActive))
984 {
985 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
986 MAKELONG( lastHitTestVal, msg->message) );
987
988#if 0
989 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
990 eatMsg = TRUE;
991#endif
992 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
993 && (hwndTop != GetForegroundWindow()) )
994 {
995 Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
996
997 //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
998 if (win32top) OSLibWinSetFocus(win32top->getOS2FrameWindowHandle());
999 }
1000 }
1001 }
1002
1003 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1004
1005 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1006}
1007//******************************************************************************
1008//******************************************************************************
1009ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1010{
1011 if (select && IsWindowIconic())
1012 return SendInternalMessageA(WM_PAINTICON, 1, 0);
1013 else
1014 return SendInternalMessageA(WM_PAINT, 0, 0);
1015}
1016//******************************************************************************
1017//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1018// (or are we simply erasing too much here)
1019//******************************************************************************
1020ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1021{
1022 ULONG rc;
1023 HDC hdcErase = hdc;
1024
1025 if (hdcErase == 0)
1026 hdcErase = O32_GetDC(OS2Hwnd);
1027
1028 if(IsWindowIconic())
1029 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1030 else
1031 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1032 if (hdc == 0)
1033 O32_ReleaseDC(OS2Hwnd, hdcErase);
1034 return (rc);
1035}
1036//******************************************************************************
1037//******************************************************************************
1038ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1039{
1040 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1041 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1042
1043 //translated message == WM_(NC)MOUSEMOVE
1044 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1045}
1046//******************************************************************************
1047//******************************************************************************
1048ULONG Win32BaseWindow::MsgChar(MSG *msg)
1049{
1050 return DispatchMsgA(msg);
1051}
1052//******************************************************************************
1053//******************************************************************************
1054ULONG Win32BaseWindow::MsgNCPaint()
1055{
1056 RECT rect;
1057
1058 if (GetOS2UpdateRect(OS2HwndFrame,&rect))
1059 {
1060 HRGN hrgn;
1061 ULONG rc;
1062 RECT client = rectClient;
1063
1064 if ((rect.left >= client.left) && (rect.left < client.right) &&
1065 (rect.right >= client.left) && (rect.right < client.right) &&
1066 (rect.top >= client.top) && (rect.top < client.bottom) &&
1067 (rect.bottom >= client.top) && (rect.bottom < client.bottom))
1068 {
1069 return 0;
1070 }
1071
1072 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", rect.left, rect.top, rect.right, rect.bottom));
1073 hrgn = CreateRectRgnIndirect(&rect);
1074 if (!hrgn) return 0;
1075
1076 rc = SendInternalMessageA(WM_NCPAINT,hrgn,0);
1077
1078 DeleteObject(hrgn);
1079
1080 return rc;
1081 }
1082 else return 0;
1083}
1084//******************************************************************************
1085//Called when either the frame's size or position has changed (lpWndPos != NULL)
1086//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1087//******************************************************************************
1088ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1089{
1090 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1091 WINDOWPOS wndPos;
1092 ULONG rc;
1093
1094 if(lpWndPos)
1095 {
1096 POINT point;
1097
1098 //set new window rectangle
1099 point.x = lpWndPos->x;
1100 point.y = lpWndPos->y;
1101 if (getParent()) ClientToScreen(getParent()->getWindowHandle(),&point);
1102
1103 setWindowRect(point.x,point.y,point.x+lpWndPos->cx,point.y+lpWndPos->cy);
1104 newWindowRect = rectWindow;
1105 }
1106 else {
1107 wndPos.hwnd = getWindowHandle();
1108 wndPos.hwndInsertAfter = 0;
1109 newWindowRect= rectWindow;
1110 if (getParent()) {
1111 mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&newWindowRect);
1112 }
1113 wndPos.x = newWindowRect.left;
1114 wndPos.y = newWindowRect.top;
1115 wndPos.cx = newWindowRect.right - newWindowRect.left;
1116 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1117 wndPos.flags = SWP_FRAMECHANGED;
1118 lpWndPos = &wndPos;
1119
1120 if (getParent()) {
1121 newWindowRect= rectWindow; //reset; was modified
1122 }
1123 }
1124
1125 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &rectClient);
1126
1127 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));
1128 return rc;
1129}
1130//******************************************************************************
1131//******************************************************************************
1132ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1133{
1134 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1135}
1136//******************************************************************************
1137//******************************************************************************
1138ULONG Win32BaseWindow::MsgGetTextLength()
1139{
1140 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1141}
1142//******************************************************************************
1143//******************************************************************************
1144void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1145{
1146 SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
1147}
1148//******************************************************************************
1149//******************************************************************************
1150LONG Win32BaseWindow::sendHitTest(ULONG lParam)
1151{
1152 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, lParam);
1153 return lastHitTestVal;
1154}
1155//******************************************************************************
1156//******************************************************************************
1157BOOL Win32BaseWindow::isMDIClient()
1158{
1159 return FALSE;
1160}
1161//******************************************************************************
1162//******************************************************************************
1163BOOL Win32BaseWindow::isMDIChild()
1164{
1165 return FALSE;
1166}
1167//******************************************************************************
1168//TODO: Not complete
1169//******************************************************************************
1170BOOL Win32BaseWindow::isFrameWindow()
1171{
1172// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1173 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1174 return TRUE;
1175
1176 return FALSE;
1177}
1178//******************************************************************************
1179//******************************************************************************
1180BOOL Win32BaseWindow::IsWindowIconic()
1181{
1182 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1183}
1184//******************************************************************************
1185//******************************************************************************
1186SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1187{
1188 switch(nBar)
1189 {
1190 case SB_HORZ:
1191 if (!horzScrollInfo)
1192 {
1193 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1194 if (!horzScrollInfo) break;
1195 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1196 horzScrollInfo->MaxVal = 100;
1197 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1198 }
1199 return horzScrollInfo;
1200
1201 case SB_VERT:
1202 if (!vertScrollInfo)
1203 {
1204 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1205 if (!vertScrollInfo) break;
1206 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1207 vertScrollInfo->MaxVal = 100;
1208 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1209 }
1210 return vertScrollInfo;
1211 }
1212
1213 return NULL;
1214}
1215//******************************************************************************
1216//******************************************************************************
1217LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1218{
1219 //SvL: Set background color to default button color (not window (white))
1220 if(ctlType == CTLCOLOR_BTN)
1221 {
1222 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1223 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1224 return GetSysColorBrush(COLOR_BTNFACE);
1225 }
1226 //SvL: Set background color to default dialog color if window is dialog
1227 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1228 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1229 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1230 return GetSysColorBrush(COLOR_BTNFACE);
1231 }
1232
1233 if( ctlType == CTLCOLOR_SCROLLBAR)
1234 {
1235 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1236 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1237 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1238 SetBkColor( hdc, bk);
1239
1240 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1241 * we better use 0x55aa bitmap brush to make scrollbar's background
1242 * look different from the window background.
1243 */
1244 if (bk == GetSysColor(COLOR_WINDOW)) {
1245 return GetPattern55AABrush();
1246 }
1247
1248 UnrealizeObject( hb );
1249 return (LRESULT)hb;
1250 }
1251
1252 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1253
1254 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1255 {
1256 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1257 }
1258 else
1259 {
1260 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1261 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1262 }
1263 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1264}
1265//******************************************************************************
1266//******************************************************************************
1267LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1268{
1269 /*
1270 * Visibility flag.
1271 */
1272 if ( (uFlags & PRF_CHECKVISIBLE) &&
1273 !IsWindowVisible() )
1274 return 0;
1275
1276 /*
1277 * Unimplemented flags.
1278 */
1279 if ( (uFlags & PRF_CHILDREN) ||
1280 (uFlags & PRF_OWNED) ||
1281 (uFlags & PRF_NONCLIENT) )
1282 {
1283 dprintf(("WM_PRINT message with unsupported flags\n"));
1284 }
1285
1286 /*
1287 * Background
1288 */
1289 if ( uFlags & PRF_ERASEBKGND)
1290 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1291
1292 /*
1293 * Client area
1294 */
1295 if ( uFlags & PRF_CLIENT)
1296 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1297
1298
1299 return 0;
1300}
1301//******************************************************************************
1302//******************************************************************************
1303LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1304{
1305 switch(Msg)
1306 {
1307 case WM_CLOSE:
1308 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1309 DestroyWindow();
1310 return 0;
1311
1312 case WM_GETTEXTLENGTH:
1313 return wndNameLength;
1314
1315 case WM_GETTEXT:
1316 if (!lParam || !wParam) return 0;
1317 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1318 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1319 return min(wndNameLength, wParam);
1320
1321 case WM_SETTEXT:
1322 {
1323 LPCSTR lpsz = (LPCSTR)lParam;
1324
1325 if(windowNameA) free(windowNameA);
1326 if(windowNameW) free(windowNameW);
1327 if (lParam)
1328 {
1329 wndNameLength = strlen(lpsz);
1330 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1331 strcpy(windowNameA, lpsz);
1332 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1333 lstrcpyAtoW(windowNameW, windowNameA);
1334 }
1335 else
1336 {
1337 windowNameA = NULL;
1338 windowNameW = NULL;
1339 wndNameLength = 0;
1340 }
1341 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1342 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1343 {
1344 HandleNCPaint((HRGN)1);
1345 if(hTaskList) {
1346 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1347 }
1348 }
1349
1350 return TRUE;
1351 }
1352
1353 case WM_SETREDRAW:
1354 {
1355 if (wParam)
1356 {
1357 setStyle(getStyle() | WS_VISIBLE);
1358 OSLibWinEnableWindowUpdate(OS2HwndFrame,TRUE);
1359 }
1360 else
1361 {
1362 if (getStyle() & WS_VISIBLE)
1363 {
1364 setStyle(getStyle() & ~WS_VISIBLE);
1365 OSLibWinEnableWindowUpdate(OS2HwndFrame,FALSE);
1366 }
1367 }
1368 return 0;
1369 }
1370
1371 case WM_CTLCOLORMSGBOX:
1372 case WM_CTLCOLOREDIT:
1373 case WM_CTLCOLORLISTBOX:
1374 case WM_CTLCOLORBTN:
1375 case WM_CTLCOLORDLG:
1376 case WM_CTLCOLORSTATIC:
1377 case WM_CTLCOLORSCROLLBAR:
1378 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1379
1380 case WM_CTLCOLOR:
1381 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1382
1383 case WM_VKEYTOITEM:
1384 case WM_CHARTOITEM:
1385 return -1;
1386
1387 case WM_PARENTNOTIFY:
1388 return 0;
1389
1390 case WM_MOUSEACTIVATE:
1391 {
1392 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1393 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1394 {
1395 if(getParent()) {
1396 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1397 if(rc) return rc;
1398 }
1399 }
1400 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1401 }
1402
1403 case WM_ACTIVATE:
1404 /* The default action in Windows is to set the keyboard focus to
1405 * the window, if it's being activated and not minimized */
1406 if (LOWORD(wParam) != WA_INACTIVE) {
1407 if(!(getStyle() & WS_MINIMIZE))
1408 SetFocus(getWindowHandle());
1409 }
1410 return 0;
1411
1412 case WM_SETCURSOR:
1413 {
1414 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1415 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
1416 {
1417 if(getParent()) {
1418 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1419 if(rc) return rc;
1420 }
1421 }
1422 if (wParam == Win32Hwnd)
1423 {
1424 HCURSOR hCursor;
1425
1426 switch(LOWORD(lParam))
1427 {
1428 case HTCLIENT:
1429 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1430 break;
1431
1432 case HTLEFT:
1433 case HTRIGHT:
1434 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1435 break;
1436
1437 case HTTOP:
1438 case HTBOTTOM:
1439 hCursor = LoadCursorA(0,IDC_SIZENSA);
1440 break;
1441
1442 case HTTOPLEFT:
1443 case HTBOTTOMRIGHT:
1444 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1445 break;
1446
1447 case HTTOPRIGHT:
1448 case HTBOTTOMLEFT:
1449 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1450 break;
1451
1452 default:
1453 hCursor = LoadCursorA(0,IDC_ARROWA);
1454 break;
1455 }
1456
1457 if (hCursor)
1458 {
1459 SetCursor(hCursor);
1460 return 1;
1461 }
1462 else return 0;
1463 }
1464 else return 0;
1465 }
1466
1467 case WM_MOUSEMOVE:
1468 return 0;
1469
1470 case WM_WINDOWPOSCHANGED:
1471 {
1472 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1473 WPARAM wp = SIZE_RESTORED;
1474
1475 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1476 {
1477 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1478 }
1479 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1480 {
1481 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1482 else
1483 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1484
1485 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1486 rectClient.bottom - rectClient.top));
1487 }
1488 return 0;
1489 }
1490 case WM_WINDOWPOSCHANGING:
1491 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1492
1493 case WM_ERASEBKGND:
1494 case WM_ICONERASEBKGND:
1495 {
1496 RECT rect;
1497 int rc;
1498
1499 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1500
1501 rc = GetClipBox( (HDC)wParam, &rect );
1502 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1503 {
1504 HBRUSH hBrush = windowClass->getBackgroundBrush();
1505
1506 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1507 hBrush = GetSysColorBrush(hBrush-1);
1508
1509 FillRect( (HDC)wParam, &rect, hBrush);
1510 }
1511 return 1;
1512 }
1513
1514 case WM_PRINT:
1515 return DefWndPrint(wParam,lParam);
1516
1517 case WM_PAINTICON:
1518 case WM_PAINT:
1519 {
1520 PAINTSTRUCT ps;
1521 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1522 if( hdc )
1523 {
1524 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() && hIcon))
1525 {
1526 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1527 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1528 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1529 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1530 }
1531 EndPaint(getWindowHandle(), &ps );
1532 }
1533 return 0;
1534 }
1535
1536 case WM_GETDLGCODE:
1537 return 0;
1538
1539 case WM_NCPAINT:
1540 return HandleNCPaint((HRGN)wParam);
1541
1542 case WM_NCACTIVATE:
1543 return HandleNCActivate(wParam);
1544
1545 case WM_NCCREATE:
1546 return(TRUE);
1547
1548 case WM_NCDESTROY:
1549 return 0;
1550
1551 case WM_NCCALCSIZE:
1552 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1553
1554 case WM_NCLBUTTONDOWN:
1555 return HandleNCLButtonDown(wParam,lParam);
1556
1557 case WM_LBUTTONDBLCLK:
1558 case WM_NCLBUTTONDBLCLK:
1559 return HandleNCLButtonDblClk(wParam,lParam);
1560
1561 case WM_NCRBUTTONDOWN:
1562 case WM_NCRBUTTONDBLCLK:
1563 case WM_NCMBUTTONDOWN:
1564 case WM_NCMBUTTONDBLCLK:
1565 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1566 return 0;
1567
1568 case WM_NCRBUTTONUP:
1569 return HandleNCRButtonUp(wParam,lParam);
1570
1571 case WM_NCMBUTTONUP:
1572 return 0;
1573
1574 case WM_NCHITTEST:
1575 {
1576 POINT point;
1577 LRESULT retvalue;
1578
1579 point.x = (SHORT)LOWORD(lParam);
1580 point.y = (SHORT)HIWORD(lParam);
1581
1582 retvalue = HandleNCHitTest(point);
1583#if 0 //CB: let the Corel people fix the bugs first
1584 if(retvalue == HTMENU)
1585 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1586 else
1587 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1588#endif
1589 return retvalue;
1590 }
1591
1592 case WM_SYSCOMMAND:
1593 {
1594 POINT point;
1595
1596 point.x = LOWORD(lParam);
1597 point.y = HIWORD(lParam);
1598 return HandleSysCommand(wParam,&point);
1599 }
1600
1601 case WM_SYSKEYDOWN:
1602 if(wParam == VK_F4) /* try to close the window */
1603 {
1604 Win32BaseWindow *window = GetTopParent();
1605 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1606 PostMessageA(getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1607 }
1608
1609 Win32BaseWindow *siblingWindow;
1610 HWND sibling;
1611 char nameBuffer [40], mnemonic;
1612 int nameLength;
1613
1614 GetWindowTextA (nameBuffer, 40);
1615
1616 // search all sibling to see it this key is their mnemonic
1617 sibling = GetWindow (GW_HWNDFIRST);
1618 while (sibling != 0) {
1619 siblingWindow = GetWindowFromHandle (sibling);
1620 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1621
1622 // find the siblings mnemonic
1623 mnemonic = '\0';
1624 for (int i=0 ; i<nameLength ; i++) {
1625 if (nameBuffer [i] == '&') {
1626 mnemonic = nameBuffer [i+1];
1627 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1628 mnemonic -= 32; // make it uppercase
1629 break; // stop searching
1630 }
1631 }
1632
1633 // key matches siblings mnemonic, send mouseclick
1634 if (mnemonic == (char) wParam) {
1635 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1636 }
1637
1638 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1639 }
1640
1641 return 0;
1642
1643#if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
1644 case WM_KEYDOWN:
1645 case WM_KEYUP:
1646 case WM_SYSKEYDOWN:
1647 case WM_SYSKEYUP:
1648#endif
1649
1650 case WM_SYSCHAR:
1651 {
1652 int iMenuSysKey = 0;
1653 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1654 {
1655 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1656 (WPARAM)SC_RESTORE, 0L );
1657 break;
1658 }
1659 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1660 {
1661 if (wParam == VK_TAB || wParam == VK_ESCAPE)
1662 break;
1663 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1664 getParent()->SendMessageA(Msg, wParam, lParam );
1665 }
1666 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1667 }
1668 else /* check for Ctrl-Esc */
1669 if (wParam != VK_ESCAPE) MessageBeep(0);
1670 break;
1671 }
1672
1673 case WM_SETHOTKEY:
1674 hotkey = wParam;
1675 return 1; //CB: always successful
1676
1677 case WM_GETHOTKEY:
1678 return hotkey;
1679
1680 case WM_CONTEXTMENU:
1681 if ((dwStyle & WS_CHILD) && getParent())
1682 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1683 return 0;
1684
1685 case WM_SHOWWINDOW:
1686 if (!lParam) return 0; /* sent from ShowWindow */
1687 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1688 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1689 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1690 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1691 return 0;
1692
1693 case WM_CANCELMODE:
1694 if (getParent() == windowDesktop) EndMenu();
1695 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1696 return 0;
1697
1698 case WM_DROPOBJECT:
1699 return DRAG_FILE;
1700
1701 case WM_QUERYDROPOBJECT:
1702 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1703
1704 case WM_QUERYDRAGICON:
1705 {
1706 HICON hDragIcon = windowClass->getCursor();
1707 UINT len;
1708
1709 if(hDragIcon) return (LRESULT)hDragIcon;
1710 for(len = 1; len < 64; len++)
1711 {
1712 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1713 if(hDragIcon)
1714 return (LRESULT)hDragIcon;
1715 }
1716 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1717 }
1718
1719 case WM_QUERYOPEN:
1720 case WM_QUERYENDSESSION:
1721 return 1;
1722
1723 case WM_NOTIFYFORMAT:
1724 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1725
1726 case WM_SETICON:
1727 case WM_GETICON:
1728 {
1729 LRESULT result = 0;
1730
1731 /* Set the appropriate icon members in the window structure. */
1732 if (wParam == ICON_SMALL)
1733 {
1734 result = hIconSm;
1735 if (Msg == WM_SETICON)
1736 hIconSm = (HICON)lParam;
1737 }
1738 else
1739 {
1740 result = hIcon;
1741 if (Msg == WM_SETICON)
1742 {
1743 hIcon = (HICON)lParam;
1744 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1745 OSLibWinSetIcon(OS2HwndFrame,hIcon);
1746 }
1747 }
1748 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1749 HandleNCPaint((HRGN)1);
1750
1751 return result;
1752 }
1753
1754 case WM_HELP:
1755 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1756 break;
1757
1758 case WM_NOTIFY:
1759 return 0; //comctl32 controls expect this
1760
1761 default:
1762 return 0;
1763 }
1764 return 0;
1765}
1766//******************************************************************************
1767//******************************************************************************
1768LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1769{
1770 switch(Msg)
1771 {
1772 case WM_GETTEXTLENGTH:
1773 return wndNameLength;
1774
1775 case WM_GETTEXT:
1776 if (!lParam || !wParam) return 0;
1777 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1778 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1779 return min(wndNameLength,wParam);
1780
1781 case WM_SETTEXT:
1782 {
1783 LPWSTR lpsz = (LPWSTR)lParam;
1784
1785 if(windowNameA) free(windowNameA);
1786 if(windowNameW) free(windowNameW);
1787 if (lParam)
1788 {
1789 wndNameLength = lstrlenW(lpsz);
1790 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1791 lstrcpyWtoA(windowNameA,lpsz);
1792 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1793 lstrcpyW(windowNameW,lpsz);
1794 }
1795 else
1796 {
1797 windowNameA = NULL;
1798 windowNameW = NULL;
1799 wndNameLength = 0;
1800 }
1801 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
1802 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1803 {
1804 HandleNCPaint((HRGN)1);
1805 if(hTaskList) {
1806 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1807 }
1808 }
1809
1810 return TRUE;
1811 }
1812
1813 default:
1814 return DefWindowProcA(Msg, wParam, lParam);
1815 }
1816}
1817//******************************************************************************
1818//******************************************************************************
1819LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1820{
1821 //if the destination window is created by this process & thread, call window proc directly
1822 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1823 return SendInternalMessageA(Msg, wParam, lParam);
1824 }
1825 //otherwise use WinSendMsg to send it to the right process/thread
1826 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1827 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1828}
1829//******************************************************************************
1830//******************************************************************************
1831LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1832{
1833 //if the destination window is created by this process & thread, call window proc directly
1834 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1835 return SendInternalMessageW(Msg, wParam, lParam);
1836 }
1837 //otherwise use WinSendMsg to send it to the right process/thread
1838 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1839}
1840//******************************************************************************
1841//Called as a result of an OS/2 message or called from a class method
1842//******************************************************************************
1843LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1844{
1845 LRESULT rc;
1846 BOOL fInternalMsgBackup = fInternalMsg;
1847
1848 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1849
1850 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
1851
1852 fInternalMsg = TRUE;
1853 switch(Msg)
1854 {
1855 case WM_CREATE:
1856 {
1857 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1858 dprintf(("WM_CREATE returned -1\n"));
1859 rc = -1; //don't create window
1860 break;
1861 }
1862 rc = 0;
1863 break;
1864 }
1865 case WM_LBUTTONDOWN:
1866 case WM_MBUTTONDOWN:
1867 case WM_RBUTTONDOWN:
1868 {
1869 if (getParent())
1870 {
1871 POINTS pt = MAKEPOINTS(lParam);
1872 POINT point;
1873
1874 point.x = pt.x;
1875 point.y = pt.y;
1876 mapWin32Point(OS2Hwnd,getParent()->getOS2WindowHandle(),(OSLIBPOINT*)&point);
1877 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
1878 }
1879 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1880 break;
1881 }
1882
1883 case WM_DESTROY:
1884 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1885 break;
1886
1887 default:
1888 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1889 break;
1890 }
1891 fInternalMsg = fInternalMsgBackup;
1892 return rc;
1893}
1894//******************************************************************************
1895//Called as a result of an OS/2 message or called from a class method
1896//******************************************************************************
1897LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1898{
1899 LRESULT rc;
1900 BOOL fInternalMsgBackup = fInternalMsg;
1901
1902 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1903
1904 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
1905
1906 fInternalMsg = TRUE;
1907 switch(Msg)
1908 {
1909 case WM_CREATE:
1910 {
1911 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1912 dprintf(("WM_CREATE returned -1\n"));
1913 rc = -1; //don't create window
1914 break;
1915 }
1916 rc = 0;
1917 break;
1918 }
1919 case WM_LBUTTONDOWN:
1920 case WM_MBUTTONDOWN:
1921 case WM_RBUTTONDOWN:
1922 NotifyParent(Msg, wParam, lParam);
1923 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1924 break;
1925
1926 case WM_DESTROY:
1927 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1928 break;
1929 default:
1930 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1931 break;
1932 }
1933 fInternalMsg = fInternalMsgBackup;
1934 return rc;
1935}
1936//******************************************************************************
1937//******************************************************************************
1938void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
1939{
1940 CWPSTRUCT cwp;
1941
1942 cwp.lParam = lParam;
1943 cwp.wParam = wParam;
1944 cwp.message = Msg;
1945 cwp.hwnd = getWindowHandle();
1946
1947 switch(hooktype) {
1948 case WH_CALLWNDPROC:
1949 if(fUnicode) {
1950 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1951 }
1952 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1953 break;
1954 }
1955}
1956//******************************************************************************
1957//TODO: Do this more efficiently
1958//******************************************************************************
1959LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
1960{
1961 Win32BaseWindow *window;
1962 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
1963
1964 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
1965
1966 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
1967 window = GetWindowFromHandle(hwnd++);
1968 if(window) {
1969 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
1970 {
1971
1972 if(type == BROADCAST_SEND) {
1973 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
1974 }
1975 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
1976 }
1977 }
1978 }
1979 return 0;
1980}
1981//******************************************************************************
1982//TODO: Do this more efficiently
1983//******************************************************************************
1984LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
1985{
1986 Win32BaseWindow *window;
1987 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
1988
1989 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
1990
1991 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
1992 window = GetWindowFromHandle(hwnd++);
1993 if(window) {
1994 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
1995 {
1996
1997 if(type == BROADCAST_SEND) {
1998 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
1999 }
2000 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2001 }
2002 }
2003 }
2004 return 0;
2005}
2006//******************************************************************************
2007//******************************************************************************
2008void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2009{
2010 Win32BaseWindow *window = this;
2011 Win32BaseWindow *parentwindow;
2012
2013 while(window)
2014 {
2015 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2016 {
2017 /* Notify the parent window only */
2018 parentwindow = window->getParent();
2019 if(parentwindow) {
2020 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2021 }
2022 }
2023 else break;
2024
2025 window = parentwindow;
2026 }
2027}
2028//******************************************************************************
2029// Returns the big or small icon for the window, falling back to the
2030// class as windows does.
2031//******************************************************************************
2032HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2033{
2034 HICON hWndIcon;
2035
2036 if (fType == ICON_BIG)
2037 {
2038 if (hIcon) hWndIcon = hIcon;
2039 else if (windowClass && windowClass->getIcon()) hWndIcon = windowClass->getIcon();
2040 else if (!(dwStyle & DS_MODALFRAME))
2041 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2042 else hWndIcon = 0;
2043 } else
2044 {
2045 if (hIconSm) hWndIcon = hIconSm;
2046 else if (hIcon) hWndIcon = hIcon;
2047 else if (windowClass && windowClass->getIconSm()) hWndIcon = windowClass->getIconSm();
2048 else if (windowClass && windowClass->getIcon()) hWndIcon = windowClass->getIcon();
2049 else if (!(dwStyle & DS_MODALFRAME))
2050 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2051 else hWndIcon = 0;
2052 }
2053
2054 return hWndIcon;
2055}
2056//******************************************************************************
2057//******************************************************************************
2058BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2059{
2060 ULONG showstate = 0;
2061 HWND hWinAfter;
2062 BOOL rc,wasVisible,showFlag;
2063
2064 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2065
2066 switch(nCmdShow)
2067 {
2068 case SW_SHOW:
2069 case SW_SHOWDEFAULT: //todo
2070 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2071 break;
2072 case SW_HIDE:
2073 if (!wasVisible) return wasVisible;
2074 if(GetCapture() == getWindowHandle() || IsChild(GetCapture()))
2075 ReleaseCapture();
2076
2077 showstate = SWPOS_HIDE;
2078 break;
2079 case SW_RESTORE:
2080 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2081 break;
2082 case SW_MINIMIZE:
2083 showstate = SWPOS_MINIMIZE;
2084 break;
2085 case SW_SHOWMAXIMIZED:
2086 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2087 break;
2088 case SW_SHOWMINIMIZED:
2089 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2090 break;
2091 case SW_SHOWMINNOACTIVE:
2092 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2093 break;
2094 case SW_SHOWNA:
2095 showstate = SWPOS_SHOW;
2096 break;
2097 case SW_SHOWNOACTIVATE:
2098 showstate = SWPOS_SHOW;
2099 break;
2100 case SW_SHOWNORMAL:
2101 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2102 break;
2103 }
2104
2105 /* We can't activate a child window (WINE) */
2106 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2107 showstate &= ~SWPOS_ACTIVATE;
2108
2109 if(showstate & SWPOS_SHOW) {
2110 setStyle(getStyle() | WS_VISIBLE);
2111 if(hTaskList) {
2112 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2113 }
2114 }
2115 else {
2116 if(hTaskList) {
2117 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2118 }
2119 setStyle(getStyle() & ~WS_VISIBLE);
2120 }
2121 showFlag = (nCmdShow != SW_HIDE);
2122
2123 rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2124 OSLibWinShowWindow(OS2Hwnd, showstate);
2125
2126 SendInternalMessageA(WM_SHOWWINDOW, (showstate & SWPOS_SHOW) ? 1 : 0, 0);
2127
2128 //CB: PMFrame: WM_MINMAXFRAME SWP_* handling isn't always successful!
2129 if ((showstate & SWPOS_MAXIMIZE) == SWPOS_MAXIMIZE)
2130 setStyle((getStyle() & ~WS_MINIMIZE) | WS_MAXIMIZE);
2131 else if ((showstate & SWPOS_MINIMIZE) == SWPOS_MINIMIZE)
2132 setStyle((getStyle() & ~WS_MAXIMIZE) | WS_MINIMIZE);
2133 else if ((showstate & SWPOS_RESTORE) == SWPOS_RESTORE)
2134 setStyle(getStyle() & ~(WS_MINIMIZE | WS_MAXIMIZE));
2135
2136 if (flags & WIN_NEED_SIZE)
2137 {
2138 /* should happen only in CreateWindowEx() */
2139 int wParam = SIZE_RESTORED;
2140
2141 flags &= ~WIN_NEED_SIZE;
2142 if (dwStyle & WS_MAXIMIZE)
2143 wParam = SIZE_MAXIMIZED;
2144 else
2145 if (dwStyle & WS_MINIMIZE)
2146 wParam = SIZE_MINIMIZED;
2147
2148 SendInternalMessageA(WM_SIZE, wParam,
2149 MAKELONG(rectClient.right-rectClient.left,
2150 rectClient.bottom-rectClient.top));
2151 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2152 }
2153
2154 return rc;
2155}
2156//******************************************************************************
2157//******************************************************************************
2158BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2159{
2160 BOOL rc = FALSE;
2161 Win32BaseWindow *window;
2162 HWND hParent = 0;
2163
2164 if (fuFlags &
2165 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2166 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2167 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2168 SWP_NOOWNERZORDER))
2169 {
2170 return FALSE;
2171 }
2172
2173 if(IsWindowDestroyed()) {
2174 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2175 dprintf(("SetWindowPos; window already destroyed"));
2176 return TRUE;
2177 }
2178#if 0
2179 /* Fix redundant flags */
2180 if(getStyle() & WS_VISIBLE) {
2181 fuFlags &= ~SWP_SHOWWINDOW;
2182 }
2183 else
2184 {
2185 if (!(fuFlags & SWP_SHOWWINDOW))
2186 fuFlags |= SWP_NOREDRAW;
2187 fuFlags &= ~SWP_HIDEWINDOW;
2188 }
2189
2190 if(cx < 0) cx = 0;
2191 if(cy < 0) cy = 0;
2192
2193 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2194 fuFlags |= SWP_NOSIZE; /* Already the right size */
2195 }
2196
2197 if((rectWindow.left == x) && (rectWindow.top == y)) {
2198 fuFlags |= SWP_NOMOVE; /* Already the right position */
2199 }
2200
2201 if(getWindowHandle() == GetActiveWindow()) {
2202 fuFlags |= SWP_NOACTIVATE; /* Already active */
2203 }
2204 else
2205 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2206 {
2207 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2208 {
2209 fuFlags &= ~SWP_NOZORDER;
2210 hwndInsertAfter = HWND_TOP;
2211 }
2212 }
2213#endif
2214
2215 WINDOWPOS wpos;
2216 SWP swp, swpOld;
2217 wpos.flags = fuFlags;
2218 wpos.cy = cy;
2219 wpos.cx = cx;
2220 wpos.x = x;
2221 wpos.y = y;
2222 wpos.hwndInsertAfter = hwndInsertAfter;
2223 wpos.hwnd = getWindowHandle();
2224
2225 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2226 {
2227 if (isChild())
2228 {
2229 Win32BaseWindow *windowParent = getParent();
2230 if(windowParent) {
2231 hParent = getParent()->getOS2WindowHandle();
2232 }
2233 else dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2234 }
2235 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2236 }
2237
2238 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2239 if (swp.fl == 0) {
2240 if (fuFlags & SWP_FRAMECHANGED)
2241 {
2242 FrameUpdateClient(this);
2243 }
2244 return TRUE;
2245 }
2246
2247// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2248 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2249 {
2250 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2251 if(wndBehind) {
2252 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2253 }
2254 else {
2255 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2256 swp.hwndInsertBehind = 0;
2257 }
2258 }
2259 swp.hwnd = OS2HwndFrame;
2260
2261 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2262
2263 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible()) {
2264 setStyle(getStyle() | WS_VISIBLE);
2265 //SvL: TODO: Send WM_SHOWWINDOW??
2266 OSLibWinShowWindow(OS2Hwnd, SWPOS_SHOW);
2267 if(hTaskList) {
2268 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2269 }
2270 }
2271 else
2272 if(fuFlags & SWP_HIDEWINDOW && IsWindowVisible()) {
2273 setStyle(getStyle() & ~WS_VISIBLE);
2274 //SvL: TODO: Send WM_SHOWWINDOW??
2275 OSLibWinShowWindow(OS2Hwnd, SWPOS_HIDE);
2276 if(hTaskList) {
2277 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2278 }
2279 }
2280 rc = OSLibWinSetMultWindowPos(&swp, 1);
2281
2282 if(rc == FALSE)
2283 {
2284 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2285 return 0;
2286 }
2287
2288 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2289 {
2290 FrameUpdateClient(this);
2291 }
2292 return (rc);
2293}
2294//******************************************************************************
2295//TODO: WPF_RESTOREMAXIMIZED
2296//******************************************************************************
2297BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2298{
2299 if(isFrameWindow())
2300 {
2301 // Set the minimized position
2302 if (winpos->flags & WPF_SETMINPOSITION)
2303 {
2304 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2305 }
2306
2307 //TODO: Max position
2308
2309 // Set the new restore position.
2310 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2311 }
2312
2313 return ShowWindow(winpos->showCmd);
2314}
2315//******************************************************************************
2316//Also destroys all the child windows (destroy children first, parent last)
2317//******************************************************************************
2318BOOL Win32BaseWindow::DestroyWindow()
2319{
2320 HWND hwnd = getWindowHandle();
2321
2322 dprintf(("DestroyWindow %x", hwnd));
2323
2324 /* Call hooks */
2325 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2326 {
2327 return FALSE;
2328 }
2329
2330 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2331 {
2332 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2333 /* FIXME: clean up palette - see "Internals" p.352 */
2334 }
2335
2336 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2337 {
2338 if(getParent())
2339 {
2340 /* Notify the parent window only */
2341 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2342 if(!::IsWindow(hwnd) )
2343 {
2344 return TRUE;
2345 }
2346 }
2347 else DebugInt3();
2348 }
2349
2350 /* Hide the window */
2351 if(IsWindowVisible())
2352 {
2353 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2354 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2355 if(!::IsWindow(hwnd))
2356 {
2357 return TRUE;
2358 }
2359 }
2360 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2361
2362 fDestroyWindowCalled = TRUE;
2363 return OSLibWinDestroyWindow(OS2HwndFrame);
2364}
2365//******************************************************************************
2366//******************************************************************************
2367Win32BaseWindow *Win32BaseWindow::getParent()
2368{
2369 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::GetParent();
2370 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2371}
2372//******************************************************************************
2373//******************************************************************************
2374HWND Win32BaseWindow::GetParent()
2375{
2376 Win32BaseWindow *wndparent;
2377
2378 if ((!(getStyle() & (WS_POPUP|WS_CHILD))))
2379 {
2380 return 0;
2381 }
2382 wndparent = ((getStyle() & WS_CHILD) ? getParent() : getOwner());
2383
2384 return (wndparent) ? wndparent->getWindowHandle() : 0;
2385}
2386//******************************************************************************
2387//******************************************************************************
2388HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2389{
2390 HWND oldhwnd;
2391 Win32BaseWindow *newparent;
2392 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::GetParent();
2393
2394 if(oldparent) {
2395 oldhwnd = oldparent->getWindowHandle();
2396 oldparent->RemoveChild(this);
2397 }
2398 else oldhwnd = 0;
2399
2400 newparent = GetWindowFromHandle(hwndNewParent);
2401 if(newparent)
2402 {
2403 setParent(newparent);
2404 getParent()->AddChild(this);
2405 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2406 return oldhwnd;
2407 }
2408 else {
2409 setParent(windowDesktop);
2410 windowDesktop->AddChild(this);
2411 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2412 return oldhwnd;
2413 }
2414}
2415//******************************************************************************
2416//******************************************************************************
2417BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2418{
2419 if(getParent()) {
2420 return getParent()->getWindowHandle() == hwndParent;
2421 }
2422 else return 0;
2423}
2424//******************************************************************************
2425//******************************************************************************
2426HWND Win32BaseWindow::GetTopWindow()
2427{
2428 return GetWindow(GW_CHILD);
2429}
2430//******************************************************************************
2431// Get the top-level parent for a child window.
2432//******************************************************************************
2433Win32BaseWindow *Win32BaseWindow::GetTopParent()
2434{
2435 Win32BaseWindow *window = this;
2436
2437 while(window && (window->getStyle() & WS_CHILD))
2438 {
2439 window = window->getParent();
2440 }
2441 return window;
2442}
2443//******************************************************************************
2444//TODO: Should not enumerate children that are created during the enumeration!
2445//******************************************************************************
2446BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2447{
2448 BOOL rc = TRUE;
2449 HWND hwnd;
2450 Win32BaseWindow *prevchild = 0, *child = 0;
2451
2452 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2453 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2454 {
2455 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2456 hwnd = child->getWindowHandle();
2457 if(child->getOwner()) {
2458 continue; //shouldn't have an owner (Wine)
2459 }
2460 if(lpfn(hwnd, lParam) == FALSE)
2461 {
2462 rc = FALSE;
2463 break;
2464 }
2465 //check if the window still exists
2466 if(!::IsWindow(hwnd))
2467 {
2468 child = prevchild;
2469 continue;
2470 }
2471 if(child->getFirstChild() != NULL)
2472 {
2473 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2474 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2475 {
2476 rc = FALSE;
2477 break;
2478 }
2479 }
2480 prevchild = child;
2481 }
2482 return rc;
2483}
2484//******************************************************************************
2485//Enumerate first-level children only and check thread id
2486//******************************************************************************
2487BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2488{
2489 Win32BaseWindow *child = 0;
2490 ULONG tid, pid;
2491 BOOL rc;
2492 HWND hwnd;
2493
2494 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2495
2496 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2497 {
2498 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2499
2500 if(dwThreadId == tid) {
2501 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2502 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2503 break;
2504 }
2505 }
2506 }
2507 return TRUE;
2508}
2509//******************************************************************************
2510//Enumerate first-level children only
2511//******************************************************************************
2512BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2513{
2514 Win32BaseWindow *child = 0;
2515 BOOL rc;
2516 HWND hwnd;
2517
2518 dprintf(("EnumWindows %x %x", lpfn, lParam));
2519
2520 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2521 {
2522 hwnd = child->getWindowHandle();
2523
2524 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2525 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2526 break;
2527 }
2528 }
2529 return TRUE;
2530}
2531//******************************************************************************
2532//******************************************************************************
2533Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2534{
2535 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2536 {
2537 if (child->getWindowId() == id)
2538 {
2539 return child;
2540 }
2541 }
2542 return 0;
2543}
2544//******************************************************************************
2545//TODO:
2546//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2547//the current process owns them.
2548//******************************************************************************
2549HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
2550{
2551 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2552 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2553
2554 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
2555 if((hwndParent != 0 && !parent) ||
2556 (hwndChildAfter != 0 && !child) ||
2557 (hwndParent == 0 && hwndChildAfter != 0))
2558 {
2559 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2560 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2561 return 0;
2562 }
2563 SetLastError(0);
2564 if(hwndParent != 0)
2565 {//if the current process owns the window, just do a quick search
2566 child = (Win32BaseWindow *)parent->getFirstChild();
2567 if(hwndChildAfter != 0)
2568 {
2569 while(child)
2570 {
2571 if(child->getWindowHandle() == hwndChildAfter)
2572 {
2573 child = (Win32BaseWindow *)child->getNextChild();
2574 break;
2575 }
2576 child = (Win32BaseWindow *)child->getNextChild();
2577 }
2578 }
2579 while(child)
2580 {
2581 //According to Wine, the class doesn't need to be specified
2582 if((!atom || child->getWindowClass()->getAtom() == atom) &&
2583 (!lpszWindow || child->hasWindowName(lpszWindow)))
2584 {
2585 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2586 return child->getWindowHandle();
2587 }
2588 child = (Win32BaseWindow *)child->getNextChild();
2589 }
2590 }
2591 else {
2592 Win32BaseWindow *wnd;
2593 HWND henum, hwnd;
2594
2595 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2596 hwnd = OSLibWinGetNextWindow(henum);
2597
2598 while(hwnd)
2599 {
2600 wnd = GetWindowFromOS2Handle(hwnd);
2601 if(wnd == NULL) {
2602 hwnd = OSLibWinQueryClientWindow(hwnd);
2603 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2604 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2605 }
2606
2607 if(wnd) {
2608 //According to Wine, the class doesn't need to be specified
2609 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
2610 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
2611 {
2612 OSLibWinEndEnumWindows(henum);
2613 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2614 return wnd->getWindowHandle();
2615 }
2616 }
2617 hwnd = OSLibWinGetNextWindow(henum);
2618 }
2619 OSLibWinEndEnumWindows(henum);
2620 }
2621 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2622 return 0;
2623}
2624//******************************************************************************
2625//******************************************************************************
2626HWND Win32BaseWindow::GetWindow(UINT uCmd)
2627{
2628 HWND hwndRelated = 0;
2629 Win32BaseWindow *window;
2630
2631 switch(uCmd)
2632 {
2633 case GW_HWNDFIRST:
2634 if(getParent()) {
2635 window = (Win32BaseWindow *)getParent()->getFirstChild();
2636 hwndRelated = window->getWindowHandle();
2637 }
2638 break;
2639
2640 case GW_HWNDLAST:
2641 if(!getParent())
2642 {
2643 goto end;
2644 }
2645
2646 window = this;
2647 while(window->getNextChild())
2648 {
2649 window = (Win32BaseWindow *)window->getNextChild();
2650 }
2651 hwndRelated = window->getWindowHandle();
2652 break;
2653
2654 case GW_HWNDNEXT:
2655 window = (Win32BaseWindow *)getNextChild();
2656 if(window) {
2657 hwndRelated = window->getWindowHandle();
2658 }
2659 break;
2660
2661 case GW_HWNDPREV:
2662 if(!getParent())
2663 {
2664 goto end;
2665 }
2666 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2667 if(window == this)
2668 {
2669 hwndRelated = 0; /* First in list */
2670 goto end;
2671 }
2672 while(window->getNextChild())
2673 {
2674 if (window->getNextChild() == this)
2675 {
2676 hwndRelated = window->getWindowHandle();
2677 goto end;
2678 }
2679 window = (Win32BaseWindow *)window->getNextChild();
2680 }
2681 break;
2682
2683 case GW_OWNER:
2684 if(getOwner()) {
2685 hwndRelated = getOwner()->getWindowHandle();
2686 }
2687 break;
2688
2689 case GW_CHILD:
2690 if(getFirstChild()) {
2691 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2692 }
2693 break;
2694 }
2695end:
2696 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2697 return hwndRelated;
2698}
2699//******************************************************************************
2700//******************************************************************************
2701HWND Win32BaseWindow::SetActiveWindow()
2702{
2703 HWND hwndActive;
2704
2705 dprintf(("SetActiveWindow %x", getWindowHandle()));
2706 if(OSLibWinSetActiveWindow(OS2HwndFrame) == FALSE) {
2707 dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2HwndFrame));
2708 }
2709 hwndActive = GetActiveWindow();
2710 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
2711}
2712//******************************************************************************
2713//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2714//******************************************************************************
2715BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2716{
2717 BOOL rc;
2718
2719 //return true if previous state was disabled, else false (sdk docs)
2720 rc = (getStyle() & WS_DISABLED) != 0;
2721 if(rc && !fEnable) {
2722 SendMessageA(WM_CANCELMODE, 0, 0);
2723 }
2724 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2725 if(fEnable == FALSE) {
2726 //SvL: No need to clear focus as PM already does this
2727 if(getWindowHandle() == GetCapture()) {
2728 ReleaseCapture(); /* A disabled window can't capture the mouse */
2729 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
2730 }
2731 }
2732 return rc;
2733}
2734//******************************************************************************
2735//******************************************************************************
2736BOOL Win32BaseWindow::CloseWindow()
2737{
2738 return OSLibWinMinimizeWindow(OS2HwndFrame);
2739}
2740//******************************************************************************
2741//TODO: Not be 100% correct; should return active window of current thread
2742// or NULL when there is none -> WinQueryActiveWindow just returns
2743// the current active window
2744//******************************************************************************
2745HWND Win32BaseWindow::GetActiveWindow()
2746{
2747 HWND hwndActive;
2748 Win32BaseWindow *win32wnd;
2749 ULONG magic;
2750
2751 hwndActive = OSLibWinQueryActiveWindow();
2752
2753 return OS2ToWin32Handle(hwndActive);
2754}
2755//******************************************************************************
2756//******************************************************************************
2757BOOL Win32BaseWindow::IsWindowEnabled()
2758{
2759 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2760}
2761//******************************************************************************
2762//******************************************************************************
2763BOOL Win32BaseWindow::IsWindowVisible()
2764{
2765#if 1
2766 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2767#else
2768 return OSLibWinIsWindowVisible(OS2HwndFrame);
2769#endif
2770}
2771//******************************************************************************
2772//******************************************************************************
2773BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2774{
2775 INT len = GetWindowTextLength();
2776 BOOL res;
2777
2778 if (wndname == NULL)
2779 return (len == 0);
2780
2781 len++;
2782 if (fUnicode)
2783 {
2784 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
2785
2786 GetWindowTextW(text,len);
2787 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
2788 free(text);
2789 } else
2790 {
2791 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
2792
2793 GetWindowTextA(text,len);
2794 res = (strcmp(text,wndname) == 0);
2795 free(text);
2796 }
2797
2798 return res;
2799}
2800//******************************************************************************
2801//******************************************************************************
2802CHAR *Win32BaseWindow::getWindowNamePtrA()
2803{
2804 INT len = GetWindowTextLength();
2805 CHAR *text;
2806
2807 if (len == 0) return NULL;
2808 len++;
2809 text = (CHAR*)malloc(len*sizeof(CHAR));
2810 GetWindowTextA(text,len);
2811
2812 return text;
2813}
2814//******************************************************************************
2815//******************************************************************************
2816WCHAR *Win32BaseWindow::getWindowNamePtrW()
2817{
2818 INT len = GetWindowTextLength();
2819 WCHAR *text;
2820
2821 if (len == 0) return NULL;
2822 len++;
2823 text = (WCHAR*)malloc(len*sizeof(WCHAR));
2824 GetWindowTextW(text,len);
2825
2826 return text;
2827}
2828//******************************************************************************
2829//******************************************************************************
2830VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
2831{
2832 if (namePtr) free(namePtr);
2833}
2834//******************************************************************************
2835//******************************************************************************
2836int Win32BaseWindow::GetWindowTextLength()
2837{
2838 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2839}
2840//******************************************************************************
2841//******************************************************************************
2842int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2843{
2844 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2845}
2846//******************************************************************************
2847//******************************************************************************
2848int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2849{
2850 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2851}
2852//******************************************************************************
2853//******************************************************************************
2854BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2855{
2856 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2857}
2858//******************************************************************************
2859//******************************************************************************
2860BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2861{
2862 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2863}
2864//******************************************************************************
2865//******************************************************************************
2866LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
2867{
2868 LONG oldval;
2869
2870 dprintf2(("SetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
2871 switch(index) {
2872 case GWL_EXSTYLE:
2873 {
2874 STYLESTRUCT ss;
2875
2876 if(dwExStyle == value)
2877 return value;
2878
2879 ss.styleOld = dwExStyle;
2880 ss.styleNew = value;
2881 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2882 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2883 setExStyle(ss.styleNew);
2884 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2885 return ss.styleOld;
2886 }
2887 case GWL_STYLE:
2888 {
2889 STYLESTRUCT ss;
2890
2891 //SvL: TODO: Can you change minimize or maximize status here too?
2892
2893 if(dwStyle == value)
2894 return value;
2895
2896 value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
2897 ss.styleOld = getStyle();
2898 ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
2899 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
2900 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2901 setStyle(ss.styleNew);
2902 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2903//// OSLibSetWindowStyle(getOS2FrameWindowHandle(), getStyle(), getExStyle(),
2904//// windowClass->getStyle() & CS_SAVEBITS);
2905#ifdef DEBUG
2906 PrintWindowStyle(ss.styleNew, 0);
2907#endif
2908 return ss.styleOld;
2909 }
2910 case GWL_WNDPROC:
2911 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
2912 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
2913 return oldval;
2914
2915 case GWL_HINSTANCE:
2916 oldval = hInstance;
2917 hInstance = value;
2918 return oldval;
2919
2920 case GWL_HWNDPARENT:
2921 return SetParent((HWND)value);
2922
2923 case GWL_ID:
2924 oldval = getWindowId();
2925 setWindowId(value);
2926 return oldval;
2927
2928 case GWL_USERDATA:
2929 oldval = userData;
2930 userData = value;
2931 return oldval;
2932
2933 default:
2934 if(index >= 0 && index/4 < nrUserWindowLong)
2935 {
2936 oldval = userWindowLong[index/4];
2937 userWindowLong[index/4] = value;
2938 return oldval;
2939 }
2940 SetLastError(ERROR_INVALID_PARAMETER);
2941 return 0;
2942 }
2943}
2944//******************************************************************************
2945//******************************************************************************
2946ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
2947{
2948 ULONG value;
2949
2950 switch(index) {
2951 case GWL_EXSTYLE:
2952 value = dwExStyle;
2953 break;
2954 case GWL_STYLE:
2955 value = dwStyle;
2956 break;
2957 case GWL_WNDPROC:
2958 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
2959 break;
2960 case GWL_HINSTANCE:
2961 value = hInstance;
2962 break;
2963 case GWL_HWNDPARENT:
2964 if(getParent()) {
2965 value = getParent()->getWindowHandle();
2966 }
2967 else value = 0;
2968 break;
2969 case GWL_ID:
2970 value = getWindowId();
2971 break;
2972 case GWL_USERDATA:
2973 value = userData;
2974 break;
2975 default:
2976 if(index >= 0 && index/4 < nrUserWindowLong)
2977 {
2978 value = userWindowLong[index/4];
2979 break;
2980 }
2981 SetLastError(ERROR_INVALID_PARAMETER);
2982 return 0;
2983 }
2984 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
2985 return value;
2986}
2987//******************************************************************************
2988//******************************************************************************
2989WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2990{
2991 WORD oldval;
2992
2993 if(index >= 0 && index/4 < nrUserWindowLong)
2994 {
2995 oldval = ((WORD *)userWindowLong)[index/2];
2996 ((WORD *)userWindowLong)[index/2] = value;
2997 return oldval;
2998 }
2999 SetLastError(ERROR_INVALID_PARAMETER);
3000 return 0;
3001}
3002//******************************************************************************
3003//******************************************************************************
3004WORD Win32BaseWindow::GetWindowWord(int index)
3005{
3006 if(index >= 0 && index/4 < nrUserWindowLong)
3007 {
3008 return ((WORD *)userWindowLong)[index/2];
3009 }
3010 SetLastError(ERROR_INVALID_PARAMETER);
3011 return 0;
3012}
3013//******************************************************************************
3014//******************************************************************************
3015void Win32BaseWindow::setWindowId(DWORD id)
3016{
3017 dwIDMenu = id;
3018}
3019//******************************************************************************
3020//******************************************************************************
3021Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3022{
3023 Win32BaseWindow *window;
3024
3025 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3026 return window;
3027 }
3028// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3029 return NULL;
3030}
3031//******************************************************************************
3032//Note: Should return NULL if window is frame window! (IsOS2FrameWindowHandle depends on this
3033// behaviour)
3034//******************************************************************************
3035Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3036{
3037 Win32BaseWindow *win32wnd;
3038 DWORD magic;
3039
3040 if(hwnd == OSLIB_HWND_DESKTOP)
3041 {
3042 return windowDesktop;
3043 }
3044
3045 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3046 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3047
3048 if(win32wnd && CheckMagicDword(magic)) {
3049 return win32wnd;
3050 }
3051// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3052 return 0;
3053}
3054//******************************************************************************
3055//******************************************************************************
3056Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3057{
3058 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3059}
3060//******************************************************************************
3061//******************************************************************************
3062HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3063{
3064 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3065
3066 if(window) {
3067 return window->getOS2WindowHandle();
3068 }
3069// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3070 return hwnd;
3071}
3072//******************************************************************************
3073//******************************************************************************
3074HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
3075{
3076 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3077
3078 if(window) {
3079 return window->getOS2FrameWindowHandle();
3080 }
3081// dprintf2(("Win32BaseWindow::Win32ToOS2FrameHandle: not a win32 window %x", hwnd));
3082 return hwnd;
3083}
3084//******************************************************************************
3085//******************************************************************************
3086HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3087{
3088 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3089
3090 if(window) {
3091 return window->getWindowHandle();
3092 }
3093 window = GetWindowFromOS2FrameHandle(hwnd);
3094 if(window) {
3095 return window->getWindowHandle();
3096 }
3097// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3098 return 0;
3099// else return hwnd; //OS/2 window handle
3100}
3101//******************************************************************************
3102//******************************************************************************
3103BOOL Win32BaseWindow::IsOS2FrameWindowHandle(HWND hwndWin32, HWND hwndOS2)
3104{
3105 Win32BaseWindow *window = GetWindowFromHandle(hwndWin32);
3106
3107 if(window->getOS2FrameWindowHandle() == hwndOS2) {
3108 return TRUE;
3109 }
3110 return FALSE;
3111}
3112//******************************************************************************
3113// GetNextDlgTabItem32 (USER32.276)
3114//******************************************************************************
3115HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3116{
3117 Win32BaseWindow *child, *nextchild, *lastchild;
3118 HWND retvalue;
3119
3120 if (hwndCtrl)
3121 {
3122 child = GetWindowFromHandle(hwndCtrl);
3123 if (!child)
3124 {
3125 retvalue = 0;
3126 goto END;
3127 }
3128 /* Make sure hwndCtrl is a top-level child */
3129 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3130 {
3131 child = child->getParent();
3132 if(child == NULL) break;
3133 }
3134
3135 if (!child || (child->getParent() != this))
3136 {
3137 retvalue = 0;
3138 goto END;
3139 }
3140 }
3141 else
3142 {
3143 /* No ctrl specified -> start from the beginning */
3144 child = (Win32BaseWindow *)getFirstChild();
3145 if (!child)
3146 {
3147 retvalue = 0;
3148 goto END;
3149 }
3150
3151 if (!fPrevious)
3152 {
3153 while (child->getNextChild())
3154 {
3155 child = (Win32BaseWindow *)child->getNextChild();
3156 }
3157 }
3158 }
3159
3160 lastchild = child;
3161 nextchild = (Win32BaseWindow *)child->getNextChild();
3162 while (TRUE)
3163 {
3164 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3165
3166 if (child == nextchild) break;
3167
3168 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3169 !(nextchild->getStyle() & WS_DISABLED))
3170 {
3171 lastchild = nextchild;
3172 if (!fPrevious) break;
3173 }
3174 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3175 }
3176 retvalue = lastchild->getWindowHandle();
3177
3178END:
3179 return retvalue;
3180}
3181//******************************************************************************
3182//******************************************************************************
3183HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3184{
3185 Win32BaseWindow *child, *nextchild, *lastchild;
3186 HWND retvalue;
3187
3188 if (hwndCtrl)
3189 {
3190 child = GetWindowFromHandle(hwndCtrl);
3191 if (!child)
3192 {
3193 retvalue = 0;
3194 goto END;
3195 }
3196 /* Make sure hwndCtrl is a top-level child */
3197 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3198 {
3199 child = child->getParent();
3200 if(child == NULL) break;
3201 }
3202
3203 if (!child || (child->getParent() != this))
3204 {
3205 retvalue = 0;
3206 goto END;
3207 }
3208 }
3209 else
3210 {
3211 /* No ctrl specified -> start from the beginning */
3212 child = (Win32BaseWindow *)getFirstChild();
3213 if (!child)
3214 {
3215 retvalue = 0;
3216 goto END;
3217 }
3218
3219 if (fPrevious)
3220 {
3221 while (child->getNextChild())
3222 {
3223 child = (Win32BaseWindow *)child->getNextChild();
3224 }
3225 }
3226 }
3227
3228 lastchild = child;
3229 nextchild = (Win32BaseWindow *)child->getNextChild();
3230 while (TRUE)
3231 {
3232 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3233 {
3234 /* Wrap-around to the beginning of the group */
3235 Win32BaseWindow *pWndTemp;
3236
3237 nextchild = (Win32BaseWindow *)getFirstChild();
3238
3239 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3240 {
3241 if (pWndTemp->getStyle() & WS_GROUP)
3242 nextchild = pWndTemp;
3243
3244 if (pWndTemp == child)
3245 break;
3246 }
3247
3248 }
3249 if (nextchild == child)
3250 break;
3251
3252 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3253 {
3254 lastchild = nextchild;
3255
3256 if (!fPrevious)
3257 break;
3258 }
3259
3260 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3261 }
3262 retvalue = lastchild->getWindowHandle();
3263END:
3264 return retvalue;
3265}
3266//******************************************************************************
3267//******************************************************************************
3268#ifdef DEBUG
3269void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3270{
3271 char style[256] = "";
3272 char exstyle[256] = "";
3273
3274 /* Window styles */
3275 if(dwStyle & WS_CHILD)
3276 strcat(style, "WS_CHILD ");
3277 if(dwStyle & WS_POPUP)
3278 strcat(style, "WS_POPUP ");
3279 if(dwStyle & WS_VISIBLE)
3280 strcat(style, "WS_VISIBLE ");
3281 if(dwStyle & WS_DISABLED)
3282 strcat(style, "WS_DISABLED ");
3283 if(dwStyle & WS_CLIPSIBLINGS)
3284 strcat(style, "WS_CLIPSIBLINGS ");
3285 if(dwStyle & WS_CLIPCHILDREN)
3286 strcat(style, "WS_CLIPCHILDREN ");
3287 if(dwStyle & WS_MAXIMIZE)
3288 strcat(style, "WS_MAXIMIZE ");
3289 if(dwStyle & WS_MINIMIZE)
3290 strcat(style, "WS_MINIMIZE ");
3291 if(dwStyle & WS_GROUP)
3292 strcat(style, "WS_GROUP ");
3293 if(dwStyle & WS_TABSTOP)
3294 strcat(style, "WS_TABSTOP ");
3295
3296 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3297 strcat(style, "WS_CAPTION ");
3298 if(dwStyle & WS_DLGFRAME)
3299 strcat(style, "WS_DLGFRAME ");
3300 if(dwStyle & WS_BORDER)
3301 strcat(style, "WS_BORDER ");
3302
3303 if(dwStyle & WS_VSCROLL)
3304 strcat(style, "WS_VSCROLL ");
3305 if(dwStyle & WS_HSCROLL)
3306 strcat(style, "WS_HSCROLL ");
3307 if(dwStyle & WS_SYSMENU)
3308 strcat(style, "WS_SYSMENU ");
3309 if(dwStyle & WS_THICKFRAME)
3310 strcat(style, "WS_THICKFRAME ");
3311 if(dwStyle & WS_MINIMIZEBOX)
3312 strcat(style, "WS_MINIMIZEBOX ");
3313 if(dwStyle & WS_MAXIMIZEBOX)
3314 strcat(style, "WS_MAXIMIZEBOX ");
3315
3316 if(dwExStyle & WS_EX_DLGMODALFRAME)
3317 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3318 if(dwExStyle & WS_EX_ACCEPTFILES)
3319 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3320 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3321 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3322 if(dwExStyle & WS_EX_TOPMOST)
3323 strcat(exstyle, "WS_EX_TOPMOST ");
3324 if(dwExStyle & WS_EX_TRANSPARENT)
3325 strcat(exstyle, "WS_EX_TRANSPARENT ");
3326
3327 if(dwExStyle & WS_EX_MDICHILD)
3328 strcat(exstyle, "WS_EX_MDICHILD ");
3329 if(dwExStyle & WS_EX_TOOLWINDOW)
3330 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3331 if(dwExStyle & WS_EX_WINDOWEDGE)
3332 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3333 if(dwExStyle & WS_EX_CLIENTEDGE)
3334 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3335 if(dwExStyle & WS_EX_CONTEXTHELP)
3336 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3337 if(dwExStyle & WS_EX_RIGHT)
3338 strcat(exstyle, "WS_EX_RIGHT ");
3339 if(dwExStyle & WS_EX_LEFT)
3340 strcat(exstyle, "WS_EX_LEFT ");
3341 if(dwExStyle & WS_EX_RTLREADING)
3342 strcat(exstyle, "WS_EX_RTLREADING ");
3343 if(dwExStyle & WS_EX_LTRREADING)
3344 strcat(exstyle, "WS_EX_LTRREADING ");
3345 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3346 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3347 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3348 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3349 if(dwExStyle & WS_EX_CONTROLPARENT)
3350 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3351 if(dwExStyle & WS_EX_STATICEDGE)
3352 strcat(exstyle, "WS_EX_STATICEDGE ");
3353 if(dwExStyle & WS_EX_APPWINDOW)
3354 strcat(exstyle, "WS_EX_APPWINDOW ");
3355
3356 dprintf(("Window style: %x %s", dwStyle, style));
3357 dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
3358}
3359#endif
3360//******************************************************************************
3361//******************************************************************************
3362
3363GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.