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

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

resource handling changes

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