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

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

Set/GetParent changes/fixes

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