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

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

RDW_FRAME support for GetDCEx; added wine dialog change; added extra logging

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