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

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

experimental WM_NCHITTEST generation (disabled) + MDI fixes

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