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

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

Major rewrite: frame/client -> frame

File size: 109.8 KB
Line 
1/* $Id: win32wbase.cpp,v 1.198 2000-06-07 14:51:30 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::IsWindowIconic()
1161{
1162 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1163}
1164//******************************************************************************
1165//******************************************************************************
1166SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1167{
1168 switch(nBar)
1169 {
1170 case SB_HORZ:
1171 if (!horzScrollInfo)
1172 {
1173 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1174 if (!horzScrollInfo) break;
1175 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1176 horzScrollInfo->MaxVal = 100;
1177 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1178 }
1179 return horzScrollInfo;
1180
1181 case SB_VERT:
1182 if (!vertScrollInfo)
1183 {
1184 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1185 if (!vertScrollInfo) break;
1186 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1187 vertScrollInfo->MaxVal = 100;
1188 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1189 }
1190 return vertScrollInfo;
1191 }
1192
1193 return NULL;
1194}
1195//******************************************************************************
1196//******************************************************************************
1197LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1198{
1199 //SvL: Set background color to default button color (not window (white))
1200 if(ctlType == CTLCOLOR_BTN)
1201 {
1202 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1203 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1204 return GetSysColorBrush(COLOR_BTNFACE);
1205 }
1206 //SvL: Set background color to default dialog color if window is dialog
1207 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1208 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1209 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1210 return GetSysColorBrush(COLOR_BTNFACE);
1211 }
1212
1213 if( ctlType == CTLCOLOR_SCROLLBAR)
1214 {
1215 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1216 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1217 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1218 SetBkColor( hdc, bk);
1219
1220 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1221 * we better use 0x55aa bitmap brush to make scrollbar's background
1222 * look different from the window background.
1223 */
1224 if (bk == GetSysColor(COLOR_WINDOW)) {
1225 return GetPattern55AABrush();
1226 }
1227
1228 UnrealizeObject( hb );
1229 return (LRESULT)hb;
1230 }
1231
1232 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1233
1234 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1235 {
1236 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1237 }
1238 else
1239 {
1240 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1241 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1242 }
1243 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1244}
1245//******************************************************************************
1246//******************************************************************************
1247LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1248{
1249 /*
1250 * Visibility flag.
1251 */
1252 if ( (uFlags & PRF_CHECKVISIBLE) &&
1253 !IsWindowVisible() )
1254 return 0;
1255
1256 /*
1257 * Unimplemented flags.
1258 */
1259 if ( (uFlags & PRF_CHILDREN) ||
1260 (uFlags & PRF_OWNED) ||
1261 (uFlags & PRF_NONCLIENT) )
1262 {
1263 dprintf(("WM_PRINT message with unsupported flags\n"));
1264 }
1265
1266 /*
1267 * Background
1268 */
1269 if ( uFlags & PRF_ERASEBKGND)
1270 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1271
1272 /*
1273 * Client area
1274 */
1275 if ( uFlags & PRF_CLIENT)
1276 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1277
1278
1279 return 0;
1280}
1281//******************************************************************************
1282//******************************************************************************
1283LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1284{
1285 switch(Msg)
1286 {
1287 case WM_CLOSE:
1288 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1289 DestroyWindow();
1290 return 0;
1291
1292 case WM_GETTEXTLENGTH:
1293 return wndNameLength;
1294
1295 case WM_GETTEXT:
1296 if (!lParam || !wParam) return 0;
1297 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1298 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1299 return min(wndNameLength, wParam);
1300
1301 case WM_SETTEXT:
1302 {
1303 LPCSTR lpsz = (LPCSTR)lParam;
1304
1305 if(windowNameA) free(windowNameA);
1306 if(windowNameW) free(windowNameW);
1307 if (lParam)
1308 {
1309 wndNameLength = strlen(lpsz);
1310 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1311 strcpy(windowNameA, lpsz);
1312 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1313 lstrcpyAtoW(windowNameW, windowNameA);
1314 }
1315 else
1316 {
1317 windowNameA = NULL;
1318 windowNameW = NULL;
1319 wndNameLength = 0;
1320 }
1321 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1322 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1323 {
1324 HandleNCPaint((HRGN)1);
1325 if(hTaskList) {
1326 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1327 }
1328 }
1329
1330 return TRUE;
1331 }
1332
1333 case WM_SETREDRAW:
1334 {
1335 if (wParam)
1336 {
1337 setStyle(getStyle() | WS_VISIBLE);
1338 OSLibWinEnableWindowUpdate(OS2Hwnd,TRUE);
1339 }
1340 else
1341 {
1342 if (getStyle() & WS_VISIBLE)
1343 {
1344 setStyle(getStyle() & ~WS_VISIBLE);
1345 OSLibWinEnableWindowUpdate(OS2Hwnd,FALSE);
1346 }
1347 }
1348 return 0;
1349 }
1350
1351 case WM_CTLCOLORMSGBOX:
1352 case WM_CTLCOLOREDIT:
1353 case WM_CTLCOLORLISTBOX:
1354 case WM_CTLCOLORBTN:
1355 case WM_CTLCOLORDLG:
1356 case WM_CTLCOLORSTATIC:
1357 case WM_CTLCOLORSCROLLBAR:
1358 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1359
1360 case WM_CTLCOLOR:
1361 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1362
1363 case WM_VKEYTOITEM:
1364 case WM_CHARTOITEM:
1365 return -1;
1366
1367 case WM_PARENTNOTIFY:
1368 return 0;
1369
1370 case WM_MOUSEACTIVATE:
1371 {
1372 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1373 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1374 {
1375 if(getParent()) {
1376 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1377 if(rc) return rc;
1378 }
1379 }
1380 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1381 }
1382
1383 case WM_ACTIVATE:
1384 /* The default action in Windows is to set the keyboard focus to
1385 * the window, if it's being activated and not minimized */
1386 if (LOWORD(wParam) != WA_INACTIVE) {
1387 if(!(getStyle() & WS_MINIMIZE))
1388 SetFocus(getWindowHandle());
1389 }
1390 return 0;
1391
1392 case WM_SETCURSOR:
1393 {
1394 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1395 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
1396 {
1397 if(getParent()) {
1398 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1399 if(rc) return rc;
1400 }
1401 }
1402 if (wParam == Win32Hwnd)
1403 {
1404 HCURSOR hCursor;
1405
1406 switch(LOWORD(lParam))
1407 {
1408 case HTCLIENT:
1409 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1410 break;
1411
1412 case HTLEFT:
1413 case HTRIGHT:
1414 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1415 break;
1416
1417 case HTTOP:
1418 case HTBOTTOM:
1419 hCursor = LoadCursorA(0,IDC_SIZENSA);
1420 break;
1421
1422 case HTTOPLEFT:
1423 case HTBOTTOMRIGHT:
1424 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1425 break;
1426
1427 case HTTOPRIGHT:
1428 case HTBOTTOMLEFT:
1429 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1430 break;
1431
1432 default:
1433 hCursor = LoadCursorA(0,IDC_ARROWA);
1434 break;
1435 }
1436
1437 if (hCursor)
1438 {
1439 SetCursor(hCursor);
1440 return 1;
1441 }
1442 else return 0;
1443 }
1444 else return 0;
1445 }
1446
1447 case WM_MOUSEMOVE:
1448 return 0;
1449
1450 case WM_WINDOWPOSCHANGED:
1451 {
1452 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1453 WPARAM wp = SIZE_RESTORED;
1454
1455 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1456 {
1457 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1458 }
1459 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1460 {
1461 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1462 else
1463 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1464
1465 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1466 rectClient.bottom - rectClient.top));
1467 }
1468 return 0;
1469 }
1470 case WM_WINDOWPOSCHANGING:
1471 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1472
1473 case WM_ERASEBKGND:
1474 case WM_ICONERASEBKGND:
1475 {
1476 RECT rect;
1477 int rc;
1478
1479 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1480
1481 rc = GetClipBox( (HDC)wParam, &rect );
1482 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1483 {
1484 HBRUSH hBrush = windowClass->getBackgroundBrush();
1485
1486 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1487 hBrush = GetSysColorBrush(hBrush-1);
1488
1489 FillRect( (HDC)wParam, &rect, hBrush);
1490 }
1491 return 1;
1492 }
1493
1494 case WM_PRINT:
1495 return DefWndPrint(wParam,lParam);
1496
1497 case WM_PAINTICON:
1498 case WM_PAINT:
1499 {
1500 PAINTSTRUCT ps;
1501 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1502 if( hdc )
1503 {
1504 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() && hIcon))
1505 {
1506 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1507 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1508 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1509 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1510 }
1511 EndPaint(getWindowHandle(), &ps );
1512 }
1513 return 0;
1514 }
1515
1516 case WM_GETDLGCODE:
1517 return 0;
1518
1519 case WM_NCPAINT:
1520 return HandleNCPaint((HRGN)wParam);
1521
1522 case WM_NCACTIVATE:
1523 return HandleNCActivate(wParam);
1524
1525 case WM_NCCREATE:
1526 return(TRUE);
1527
1528 case WM_NCDESTROY:
1529 return 0;
1530
1531 case WM_NCCALCSIZE:
1532 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1533
1534 case WM_NCLBUTTONDOWN:
1535 return HandleNCLButtonDown(wParam,lParam);
1536
1537 case WM_LBUTTONDBLCLK:
1538 case WM_NCLBUTTONDBLCLK:
1539 return HandleNCLButtonDblClk(wParam,lParam);
1540
1541 case WM_NCRBUTTONDOWN:
1542 case WM_NCRBUTTONDBLCLK:
1543 case WM_NCMBUTTONDOWN:
1544 case WM_NCMBUTTONDBLCLK:
1545 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1546 return 0;
1547
1548 case WM_NCRBUTTONUP:
1549 return HandleNCRButtonUp(wParam,lParam);
1550
1551 case WM_NCMBUTTONUP:
1552 return 0;
1553
1554 case WM_NCHITTEST:
1555 {
1556 POINT point;
1557 LRESULT retvalue;
1558
1559 point.x = (SHORT)LOWORD(lParam);
1560 point.y = (SHORT)HIWORD(lParam);
1561
1562 retvalue = HandleNCHitTest(point);
1563#if 0 //CB: let the Corel people fix the bugs first
1564 if(retvalue == HTMENU)
1565 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1566 else
1567 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1568#endif
1569 return retvalue;
1570 }
1571
1572 case WM_SYSCOMMAND:
1573 {
1574 POINT point;
1575
1576 point.x = LOWORD(lParam);
1577 point.y = HIWORD(lParam);
1578 return HandleSysCommand(wParam,&point);
1579 }
1580
1581 case WM_SYSKEYDOWN:
1582 if(wParam == VK_F4) /* try to close the window */
1583 {
1584 Win32BaseWindow *window = GetTopParent();
1585 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1586 PostMessageA(getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1587 }
1588
1589 Win32BaseWindow *siblingWindow;
1590 HWND sibling;
1591 char nameBuffer [40], mnemonic;
1592 int nameLength;
1593
1594 GetWindowTextA (nameBuffer, 40);
1595
1596 // search all sibling to see it this key is their mnemonic
1597 sibling = GetWindow (GW_HWNDFIRST);
1598 while (sibling != 0) {
1599 siblingWindow = GetWindowFromHandle (sibling);
1600 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1601
1602 // find the siblings mnemonic
1603 mnemonic = '\0';
1604 for (int i=0 ; i<nameLength ; i++) {
1605 if (nameBuffer [i] == '&') {
1606 mnemonic = nameBuffer [i+1];
1607 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1608 mnemonic -= 32; // make it uppercase
1609 break; // stop searching
1610 }
1611 }
1612
1613 // key matches siblings mnemonic, send mouseclick
1614 if (mnemonic == (char) wParam) {
1615 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1616 }
1617
1618 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1619 }
1620
1621 return 0;
1622
1623#if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
1624 case WM_KEYDOWN:
1625 case WM_KEYUP:
1626 case WM_SYSKEYDOWN:
1627 case WM_SYSKEYUP:
1628#endif
1629
1630 case WM_SYSCHAR:
1631 {
1632 int iMenuSysKey = 0;
1633 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1634 {
1635 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1636 (WPARAM)SC_RESTORE, 0L );
1637 break;
1638 }
1639 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1640 {
1641 if (wParam == VK_TAB || wParam == VK_ESCAPE)
1642 break;
1643 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1644 getParent()->SendMessageA(Msg, wParam, lParam );
1645 }
1646 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1647 }
1648 else /* check for Ctrl-Esc */
1649 if (wParam != VK_ESCAPE) MessageBeep(0);
1650 break;
1651 }
1652
1653 case WM_SETHOTKEY:
1654 hotkey = wParam;
1655 return 1; //CB: always successful
1656
1657 case WM_GETHOTKEY:
1658 return hotkey;
1659
1660 case WM_CONTEXTMENU:
1661 if ((dwStyle & WS_CHILD) && getParent())
1662 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1663 return 0;
1664
1665 case WM_SHOWWINDOW:
1666 if (!lParam) return 0; /* sent from ShowWindow */
1667 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1668 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1669 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1670 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1671 return 0;
1672
1673 case WM_CANCELMODE:
1674 if (getParent() == windowDesktop) EndMenu();
1675 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1676 return 0;
1677
1678 case WM_DROPOBJECT:
1679 return DRAG_FILE;
1680
1681 case WM_QUERYDROPOBJECT:
1682 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1683
1684 case WM_QUERYDRAGICON:
1685 {
1686 HICON hDragIcon = windowClass->getCursor();
1687 UINT len;
1688
1689 if(hDragIcon) return (LRESULT)hDragIcon;
1690 for(len = 1; len < 64; len++)
1691 {
1692 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1693 if(hDragIcon)
1694 return (LRESULT)hDragIcon;
1695 }
1696 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1697 }
1698
1699 case WM_QUERYOPEN:
1700 case WM_QUERYENDSESSION:
1701 return 1;
1702
1703 case WM_NOTIFYFORMAT:
1704 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1705
1706 case WM_SETICON:
1707 case WM_GETICON:
1708 {
1709 LRESULT result = 0;
1710
1711 /* Set the appropriate icon members in the window structure. */
1712 if (wParam == ICON_SMALL)
1713 {
1714 result = hIconSm;
1715 if (Msg == WM_SETICON)
1716 hIconSm = (HICON)lParam;
1717 }
1718 else
1719 {
1720 result = hIcon;
1721 if (Msg == WM_SETICON)
1722 {
1723 hIcon = (HICON)lParam;
1724 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1725 OSLibWinSetIcon(OS2Hwnd,hIcon);
1726 }
1727 }
1728 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1729 HandleNCPaint((HRGN)1);
1730
1731 return result;
1732 }
1733
1734 case WM_HELP:
1735 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1736 break;
1737
1738 case WM_NOTIFY:
1739 return 0; //comctl32 controls expect this
1740
1741 default:
1742 return 0;
1743 }
1744 return 0;
1745}
1746//******************************************************************************
1747//******************************************************************************
1748LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1749{
1750 switch(Msg)
1751 {
1752 case WM_GETTEXTLENGTH:
1753 return wndNameLength;
1754
1755 case WM_GETTEXT:
1756 if (!lParam || !wParam) return 0;
1757 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1758 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1759 return min(wndNameLength,wParam);
1760
1761 case WM_SETTEXT:
1762 {
1763 LPWSTR lpsz = (LPWSTR)lParam;
1764
1765 if(windowNameA) free(windowNameA);
1766 if(windowNameW) free(windowNameW);
1767 if (lParam)
1768 {
1769 wndNameLength = lstrlenW(lpsz);
1770 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1771 lstrcpyWtoA(windowNameA,lpsz);
1772 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1773 lstrcpyW(windowNameW,lpsz);
1774 }
1775 else
1776 {
1777 windowNameA = NULL;
1778 windowNameW = NULL;
1779 wndNameLength = 0;
1780 }
1781 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
1782 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1783 {
1784 HandleNCPaint((HRGN)1);
1785 if(hTaskList) {
1786 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1787 }
1788 }
1789
1790 return TRUE;
1791 }
1792
1793 default:
1794 return DefWindowProcA(Msg, wParam, lParam);
1795 }
1796}
1797//******************************************************************************
1798//******************************************************************************
1799LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1800{
1801 //if the destination window is created by this process & thread, call window proc directly
1802 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1803 return SendInternalMessageA(Msg, wParam, lParam);
1804 }
1805 //otherwise use WinSendMsg to send it to the right process/thread
1806 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1807 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1808}
1809//******************************************************************************
1810//******************************************************************************
1811LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1812{
1813 //if the destination window is created by this process & thread, call window proc directly
1814 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1815 return SendInternalMessageW(Msg, wParam, lParam);
1816 }
1817 //otherwise use WinSendMsg to send it to the right process/thread
1818 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1819}
1820//******************************************************************************
1821//Called as a result of an OS/2 message or called from a class method
1822//******************************************************************************
1823LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1824{
1825 LRESULT rc;
1826 BOOL fInternalMsgBackup = fInternalMsg;
1827
1828 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1829
1830 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
1831
1832 fInternalMsg = TRUE;
1833 switch(Msg)
1834 {
1835 case WM_CREATE:
1836 {
1837 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1838 dprintf(("WM_CREATE returned -1\n"));
1839 rc = -1; //don't create window
1840 break;
1841 }
1842 rc = 0;
1843 break;
1844 }
1845 case WM_LBUTTONDOWN:
1846 case WM_MBUTTONDOWN:
1847 case WM_RBUTTONDOWN:
1848 {
1849 if (getParent())
1850 {
1851 POINTS pt = MAKEPOINTS(lParam);
1852 POINT point;
1853
1854 point.x = pt.x;
1855 point.y = pt.y;
1856 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
1857 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
1858 }
1859 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1860 break;
1861 }
1862
1863 case WM_DESTROY:
1864 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1865 break;
1866
1867 default:
1868 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1869 break;
1870 }
1871 fInternalMsg = fInternalMsgBackup;
1872 return rc;
1873}
1874//******************************************************************************
1875//Called as a result of an OS/2 message or called from a class method
1876//******************************************************************************
1877LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1878{
1879 LRESULT rc;
1880 BOOL fInternalMsgBackup = fInternalMsg;
1881
1882 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1883
1884 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
1885
1886 fInternalMsg = TRUE;
1887 switch(Msg)
1888 {
1889 case WM_CREATE:
1890 {
1891 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1892 dprintf(("WM_CREATE returned -1\n"));
1893 rc = -1; //don't create window
1894 break;
1895 }
1896 rc = 0;
1897 break;
1898 }
1899 case WM_LBUTTONDOWN:
1900 case WM_MBUTTONDOWN:
1901 case WM_RBUTTONDOWN:
1902 NotifyParent(Msg, wParam, lParam);
1903 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1904 break;
1905
1906 case WM_DESTROY:
1907 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1908 break;
1909 default:
1910 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1911 break;
1912 }
1913 fInternalMsg = fInternalMsgBackup;
1914 return rc;
1915}
1916//******************************************************************************
1917//******************************************************************************
1918void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
1919{
1920 CWPSTRUCT cwp;
1921
1922 cwp.lParam = lParam;
1923 cwp.wParam = wParam;
1924 cwp.message = Msg;
1925 cwp.hwnd = getWindowHandle();
1926
1927 switch(hooktype) {
1928 case WH_CALLWNDPROC:
1929 if(fUnicode) {
1930 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1931 }
1932 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1933 break;
1934 }
1935}
1936//******************************************************************************
1937//TODO: Do this more efficiently
1938//******************************************************************************
1939LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
1940{
1941 Win32BaseWindow *window;
1942 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
1943
1944 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
1945
1946 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
1947 window = GetWindowFromHandle(hwnd++);
1948 if(window) {
1949 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
1950 {
1951
1952 if(type == BROADCAST_SEND) {
1953 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
1954 }
1955 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
1956 }
1957 }
1958 }
1959 return 0;
1960}
1961//******************************************************************************
1962//TODO: Do this more efficiently
1963//******************************************************************************
1964LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
1965{
1966 Win32BaseWindow *window;
1967 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
1968
1969 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
1970
1971 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
1972 window = GetWindowFromHandle(hwnd++);
1973 if(window) {
1974 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
1975 {
1976
1977 if(type == BROADCAST_SEND) {
1978 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
1979 }
1980 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
1981 }
1982 }
1983 }
1984 return 0;
1985}
1986//******************************************************************************
1987//******************************************************************************
1988void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1989{
1990 Win32BaseWindow *window = this;
1991 Win32BaseWindow *parentwindow;
1992
1993 while(window)
1994 {
1995 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1996 {
1997 /* Notify the parent window only */
1998 parentwindow = window->getParent();
1999 if(parentwindow) {
2000 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2001 }
2002 }
2003 else break;
2004
2005 window = parentwindow;
2006 }
2007}
2008//******************************************************************************
2009// Returns the big or small icon for the window, falling back to the
2010// class as windows does.
2011//******************************************************************************
2012HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2013{
2014 HICON hWndIcon;
2015
2016 if (fType == ICON_BIG)
2017 {
2018 if (hIcon) hWndIcon = hIcon;
2019 else if (windowClass && windowClass->getIcon()) hWndIcon = windowClass->getIcon();
2020 else if (!(dwStyle & DS_MODALFRAME))
2021 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2022 else hWndIcon = 0;
2023 } else
2024 {
2025 if (hIconSm) hWndIcon = hIconSm;
2026 else if (hIcon) hWndIcon = hIcon;
2027 else if (windowClass && windowClass->getIconSm()) hWndIcon = windowClass->getIconSm();
2028 else if (windowClass && windowClass->getIcon()) hWndIcon = windowClass->getIcon();
2029 else if (!(dwStyle & DS_MODALFRAME))
2030 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2031 else hWndIcon = 0;
2032 }
2033
2034 return hWndIcon;
2035}
2036//******************************************************************************
2037//******************************************************************************
2038BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2039{
2040 ULONG swp = 0;
2041 HWND hWinAfter;
2042 BOOL rc,wasVisible,showFlag;
2043 RECT newPos = {0, 0, 0, 0};
2044
2045 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2046
2047 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2048
2049 switch(nCmdShow)
2050 {
2051 case SW_HIDE:
2052 if (!wasVisible) goto END;
2053 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
2054 SWP_NOACTIVATE | SWP_NOZORDER;
2055 break;
2056
2057 case SW_SHOWMINNOACTIVE:
2058 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2059 /* fall through */
2060 case SW_SHOWMINIMIZED:
2061 swp |= SWP_SHOWWINDOW;
2062 /* fall through */
2063 case SW_MINIMIZE:
2064 swp |= SWP_FRAMECHANGED;
2065 if( !(getStyle() & WS_MINIMIZE) )
2066 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2067 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2068 break;
2069
2070 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2071 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2072 if( !(getStyle() & WS_MAXIMIZE) )
2073 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2074 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2075 break;
2076
2077 case SW_SHOWNA:
2078 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2079 /* fall through */
2080 case SW_SHOW:
2081 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2082
2083 /*
2084 * ShowWindow has a little peculiar behavior that if the
2085 * window is already the topmost window, it will not
2086 * activate it.
2087 */
2088 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2089 swp |= SWP_NOACTIVATE;
2090
2091 break;
2092
2093 case SW_SHOWNOACTIVATE:
2094 swp |= SWP_NOZORDER;
2095 if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
2096 /* fall through */
2097 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2098 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2099 case SW_RESTORE:
2100 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2101
2102 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) )
2103 swp |= MinMaximize(SW_RESTORE, &newPos );
2104 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2105 break;
2106 }
2107
2108 showFlag = (nCmdShow != SW_HIDE);
2109 if (showFlag != wasVisible)
2110 {
2111 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2112 if (!::IsWindow( getWindowHandle() )) goto END;
2113 }
2114
2115 /* We can't activate a child window */
2116 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2117 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2118
2119 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2120
2121 if (flags & WIN_NEED_SIZE)
2122 {
2123 /* should happen only in CreateWindowEx() */
2124 int wParam = SIZE_RESTORED;
2125
2126 flags &= ~WIN_NEED_SIZE;
2127 if (dwStyle & WS_MAXIMIZE)
2128 wParam = SIZE_MAXIMIZED;
2129 else
2130 if (dwStyle & WS_MINIMIZE)
2131 wParam = SIZE_MINIMIZED;
2132
2133 SendInternalMessageA(WM_SIZE, wParam,
2134 MAKELONG(rectClient.right-rectClient.left,
2135 rectClient.bottom-rectClient.top));
2136 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2137 }
2138END:
2139 return wasVisible;
2140}
2141//******************************************************************************
2142//******************************************************************************
2143BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2144{
2145 BOOL rc = FALSE;
2146 Win32BaseWindow *window;
2147 HWND hParent = 0;
2148 RECT oldClientRect = rectClient;
2149
2150 if (fuFlags &
2151 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2152 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2153 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2154 SWP_NOOWNERZORDER))
2155 {
2156 return FALSE;
2157 }
2158
2159 if(IsWindowDestroyed()) {
2160 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2161 dprintf(("SetWindowPos; window already destroyed"));
2162 return TRUE;
2163 }
2164#if 0
2165 /* Fix redundant flags */
2166 if(getStyle() & WS_VISIBLE) {
2167 fuFlags &= ~SWP_SHOWWINDOW;
2168 }
2169 else
2170 {
2171 if (!(fuFlags & SWP_SHOWWINDOW))
2172 fuFlags |= SWP_NOREDRAW;
2173 fuFlags &= ~SWP_HIDEWINDOW;
2174 }
2175
2176 if(cx < 0) cx = 0;
2177 if(cy < 0) cy = 0;
2178
2179 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2180 fuFlags |= SWP_NOSIZE; /* Already the right size */
2181 }
2182
2183 if((rectWindow.left == x) && (rectWindow.top == y)) {
2184 fuFlags |= SWP_NOMOVE; /* Already the right position */
2185 }
2186
2187 if(getWindowHandle() == GetActiveWindow()) {
2188 fuFlags |= SWP_NOACTIVATE; /* Already active */
2189 }
2190 else
2191 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2192 {
2193 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2194 {
2195 fuFlags &= ~SWP_NOZORDER;
2196 hwndInsertAfter = HWND_TOP;
2197 }
2198 }
2199#endif
2200
2201 WINDOWPOS wpos;
2202 SWP swp, swpOld;
2203 wpos.flags = fuFlags;
2204 wpos.cy = cy;
2205 wpos.cx = cx;
2206 wpos.x = x;
2207 wpos.y = y;
2208 wpos.hwndInsertAfter = hwndInsertAfter;
2209 wpos.hwnd = getWindowHandle();
2210
2211 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2212 {
2213 if (isChild())
2214 {
2215 if(!getParent()) {
2216 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2217 }
2218 }
2219 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
2220 }
2221
2222 if(getParent()) {
2223 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getWindowHeight(),
2224 getParent()->getClientRectPtr()->left,
2225 getParent()->getClientRectPtr()->top,
2226 OS2Hwnd);
2227 }
2228 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), 0, 0, OS2Hwnd);
2229 if (swp.fl == 0) {
2230 if(fuFlags & SWP_FRAMECHANGED)
2231 {
2232 MsgFormatFrame(NULL);
2233 UnionRect(&oldClientRect, &oldClientRect, &rectClient);
2234 InvalidateRect(getWindowHandle(), &oldClientRect, TRUE);
2235//TODO: move child windows!!
2236 }
2237 return TRUE;
2238 }
2239
2240// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2241 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2242 {
2243 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2244 if(wndBehind) {
2245 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2246 }
2247 else {
2248 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2249 swp.hwndInsertBehind = 0;
2250 }
2251 }
2252 swp.hwnd = OS2Hwnd;
2253
2254 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2255 rc = OSLibWinSetMultWindowPos(&swp, 1);
2256
2257 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible()) {
2258 setStyle(getStyle() | WS_VISIBLE);
2259 if(hTaskList) {
2260 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2261 }
2262 }
2263 else
2264 if(fuFlags & SWP_HIDEWINDOW && IsWindowVisible()) {
2265 setStyle(getStyle() & ~WS_VISIBLE);
2266 if(hTaskList) {
2267 OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2268 }
2269 }
2270
2271 if(rc == FALSE)
2272 {
2273 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2274 return 0;
2275 }
2276
2277 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2278 {
2279 UnionRect(&oldClientRect, &oldClientRect, &rectClient);
2280 InvalidateRect(getWindowHandle(), &oldClientRect, TRUE);
2281//TODO: move child windows!!
2282 }
2283 return (rc);
2284}
2285//******************************************************************************
2286//******************************************************************************
2287BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2288{
2289 windowpos.ptMinPosition = wndpl->ptMinPosition;
2290 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2291 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2292
2293 if(getStyle() & WS_MINIMIZE )
2294 {
2295 //TODO: Why can't this be (0,0)?
2296 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2297 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2298 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2299 }
2300 }
2301 else
2302 if(getStyle() & WS_MAXIMIZE )
2303 {
2304 //TODO: Why can't this be (0,0)?
2305 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2306 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2307 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2308 }
2309 else {
2310 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2311 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2312 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2313 SWP_NOZORDER | SWP_NOACTIVATE );
2314 }
2315 ShowWindow(wndpl->showCmd);
2316 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2317 {
2318 /* SDK: ...valid only the next time... */
2319 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2320 setFlags(getFlags() | WIN_RESTORE_MAX);
2321 }
2322 return TRUE;
2323}
2324//******************************************************************************
2325//******************************************************************************
2326BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2327{
2328 wndpl->length = sizeof(*wndpl);
2329 if(getStyle() & WS_MINIMIZE )
2330 wndpl->showCmd = SW_SHOWMINIMIZED;
2331 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2332
2333 if(getFlags() & WIN_RESTORE_MAX )
2334 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2335 else wndpl->flags = 0;
2336
2337 wndpl->ptMinPosition = windowpos.ptMinPosition;
2338 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2339 wndpl->rcNormalPosition = windowpos.rcNormalPosition;
2340
2341 return TRUE;
2342}
2343//******************************************************************************
2344//Also destroys all the child windows (destroy children first, parent last)
2345//******************************************************************************
2346BOOL Win32BaseWindow::DestroyWindow()
2347{
2348 HWND hwnd = getWindowHandle();
2349
2350 dprintf(("DestroyWindow %x", hwnd));
2351
2352 /* Call hooks */
2353 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2354 {
2355 return FALSE;
2356 }
2357
2358 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2359 {
2360 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2361 /* FIXME: clean up palette - see "Internals" p.352 */
2362 }
2363
2364 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2365 {
2366 if(getParent())
2367 {
2368 /* Notify the parent window only */
2369 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2370 if(!::IsWindow(hwnd) )
2371 {
2372 return TRUE;
2373 }
2374 }
2375 else DebugInt3();
2376 }
2377
2378 /* Hide the window */
2379 if(IsWindowVisible())
2380 {
2381 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2382 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2383 if(!::IsWindow(hwnd))
2384 {
2385 return TRUE;
2386 }
2387 }
2388 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2389
2390 fDestroyWindowCalled = TRUE;
2391 return OSLibWinDestroyWindow(OS2Hwnd);
2392}
2393//******************************************************************************
2394//******************************************************************************
2395Win32BaseWindow *Win32BaseWindow::getParent()
2396{
2397 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::GetParent();
2398 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2399}
2400//******************************************************************************
2401//******************************************************************************
2402HWND Win32BaseWindow::GetParent()
2403{
2404 if(getStyle() & WS_CHILD) {
2405 if(getParent()) {
2406 return getParent()->getWindowHandle();
2407 }
2408 DebugInt3();
2409 return 0;
2410 }
2411 else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2412}
2413//******************************************************************************
2414//******************************************************************************
2415HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2416{
2417 HWND oldhwnd;
2418 Win32BaseWindow *newparent;
2419 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::GetParent();
2420 BOOL fShow = FALSE;
2421
2422 if(oldparent) {
2423 oldhwnd = oldparent->getWindowHandle();
2424 oldparent->RemoveChild(this);
2425 }
2426 else oldhwnd = 0;
2427
2428 /* Windows hides the window first, then shows it again
2429 * including the WM_SHOWWINDOW messages and all */
2430 if(fCreated && (getStyle() & WS_VISIBLE)) {
2431 ShowWindow(SW_HIDE);
2432 fShow = TRUE;
2433 }
2434
2435 newparent = GetWindowFromHandle(hwndNewParent);
2436 if(newparent)
2437 {
2438 setParent(newparent);
2439 getParent()->AddChild(this);
2440 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2441 }
2442 else {
2443 setParent(windowDesktop);
2444 windowDesktop->AddChild(this);
2445 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2446 }
2447 /* SetParent additionally needs to make hwndChild the topmost window
2448 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2449 WM_WINDOWPOSCHANGED notification messages.
2450 */
2451 if(fCreated) {
2452 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2453 SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2454
2455 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2456 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2457 }
2458 return oldhwnd;
2459}
2460//******************************************************************************
2461//******************************************************************************
2462BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2463{
2464 if(getParent()) {
2465 return getParent()->getWindowHandle() == hwndParent;
2466 }
2467 else return 0;
2468}
2469//******************************************************************************
2470//******************************************************************************
2471HWND Win32BaseWindow::GetTopWindow()
2472{
2473 return GetWindow(GW_CHILD);
2474}
2475//******************************************************************************
2476// Get the top-level parent for a child window.
2477//******************************************************************************
2478Win32BaseWindow *Win32BaseWindow::GetTopParent()
2479{
2480 Win32BaseWindow *window = this;
2481
2482 while(window && (window->getStyle() & WS_CHILD))
2483 {
2484 window = window->getParent();
2485 }
2486 return window;
2487}
2488//******************************************************************************
2489//TODO: Should not enumerate children that are created during the enumeration!
2490//******************************************************************************
2491BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2492{
2493 BOOL rc = TRUE;
2494 HWND hwnd;
2495 Win32BaseWindow *prevchild = 0, *child = 0;
2496
2497 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2498 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2499 {
2500 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2501 hwnd = child->getWindowHandle();
2502 if(child->getOwner()) {
2503 continue; //shouldn't have an owner (Wine)
2504 }
2505 if(lpfn(hwnd, lParam) == FALSE)
2506 {
2507 rc = FALSE;
2508 break;
2509 }
2510 //check if the window still exists
2511 if(!::IsWindow(hwnd))
2512 {
2513 child = prevchild;
2514 continue;
2515 }
2516 if(child->getFirstChild() != NULL)
2517 {
2518 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2519 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2520 {
2521 rc = FALSE;
2522 break;
2523 }
2524 }
2525 prevchild = child;
2526 }
2527 return rc;
2528}
2529//******************************************************************************
2530//Enumerate first-level children only and check thread id
2531//******************************************************************************
2532BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2533{
2534 Win32BaseWindow *child = 0;
2535 ULONG tid, pid;
2536 BOOL rc;
2537 HWND hwnd;
2538
2539 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2540
2541 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2542 {
2543 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2544
2545 if(dwThreadId == tid) {
2546 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2547 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2548 break;
2549 }
2550 }
2551 }
2552 return TRUE;
2553}
2554//******************************************************************************
2555//Enumerate first-level children only
2556//******************************************************************************
2557BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2558{
2559 Win32BaseWindow *child = 0;
2560 BOOL rc;
2561 HWND hwnd;
2562
2563 dprintf(("EnumWindows %x %x", lpfn, lParam));
2564
2565 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2566 {
2567 hwnd = child->getWindowHandle();
2568
2569 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2570 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2571 break;
2572 }
2573 }
2574 return TRUE;
2575}
2576//******************************************************************************
2577//******************************************************************************
2578Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2579{
2580 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2581 {
2582 if (child->getWindowId() == id)
2583 {
2584 return child;
2585 }
2586 }
2587 return 0;
2588}
2589//******************************************************************************
2590//TODO:
2591//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2592//the current process owns them.
2593//******************************************************************************
2594HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
2595{
2596 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2597 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2598
2599 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
2600 if((hwndParent != 0 && !parent) ||
2601 (hwndChildAfter != 0 && !child) ||
2602 (hwndParent == 0 && hwndChildAfter != 0))
2603 {
2604 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2605 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2606 return 0;
2607 }
2608 SetLastError(0);
2609 if(hwndParent != 0)
2610 {//if the current process owns the window, just do a quick search
2611 child = (Win32BaseWindow *)parent->getFirstChild();
2612 if(hwndChildAfter != 0)
2613 {
2614 while(child)
2615 {
2616 if(child->getWindowHandle() == hwndChildAfter)
2617 {
2618 child = (Win32BaseWindow *)child->getNextChild();
2619 break;
2620 }
2621 child = (Win32BaseWindow *)child->getNextChild();
2622 }
2623 }
2624 while(child)
2625 {
2626 //According to Wine, the class doesn't need to be specified
2627 if((!atom || child->getWindowClass()->getAtom() == atom) &&
2628 (!lpszWindow || child->hasWindowName(lpszWindow)))
2629 {
2630 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2631 return child->getWindowHandle();
2632 }
2633 child = (Win32BaseWindow *)child->getNextChild();
2634 }
2635 }
2636 else {
2637 Win32BaseWindow *wnd;
2638 HWND henum, hwnd;
2639
2640 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2641 hwnd = OSLibWinGetNextWindow(henum);
2642
2643 while(hwnd)
2644 {
2645 wnd = GetWindowFromOS2Handle(hwnd);
2646 if(wnd == NULL) {
2647 hwnd = OSLibWinQueryClientWindow(hwnd);
2648 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2649 }
2650
2651 if(wnd) {
2652 //According to Wine, the class doesn't need to be specified
2653 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
2654 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
2655 {
2656 OSLibWinEndEnumWindows(henum);
2657 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2658 return wnd->getWindowHandle();
2659 }
2660 }
2661 hwnd = OSLibWinGetNextWindow(henum);
2662 }
2663 OSLibWinEndEnumWindows(henum);
2664 }
2665 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2666 return 0;
2667}
2668//******************************************************************************
2669//******************************************************************************
2670HWND Win32BaseWindow::GetWindow(UINT uCmd)
2671{
2672 HWND hwndRelated = 0;
2673 Win32BaseWindow *window;
2674
2675 switch(uCmd)
2676 {
2677 case GW_HWNDFIRST:
2678 if(getParent()) {
2679 window = (Win32BaseWindow *)getParent()->getFirstChild();
2680 hwndRelated = window->getWindowHandle();
2681 }
2682 break;
2683
2684 case GW_HWNDLAST:
2685 if(!getParent())
2686 {
2687 goto end;
2688 }
2689
2690 window = this;
2691 while(window->getNextChild())
2692 {
2693 window = (Win32BaseWindow *)window->getNextChild();
2694 }
2695 hwndRelated = window->getWindowHandle();
2696 break;
2697
2698 case GW_HWNDNEXT:
2699 window = (Win32BaseWindow *)getNextChild();
2700 if(window) {
2701 hwndRelated = window->getWindowHandle();
2702 }
2703 break;
2704
2705 case GW_HWNDPREV:
2706 if(!getParent())
2707 {
2708 goto end;
2709 }
2710 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2711 if(window == this)
2712 {
2713 hwndRelated = 0; /* First in list */
2714 goto end;
2715 }
2716 while(window->getNextChild())
2717 {
2718 if (window->getNextChild() == this)
2719 {
2720 hwndRelated = window->getWindowHandle();
2721 goto end;
2722 }
2723 window = (Win32BaseWindow *)window->getNextChild();
2724 }
2725 break;
2726
2727 case GW_OWNER:
2728 if(getOwner()) {
2729 hwndRelated = getOwner()->getWindowHandle();
2730 }
2731 break;
2732
2733 case GW_CHILD:
2734 if(getFirstChild()) {
2735 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2736 }
2737 break;
2738 }
2739end:
2740 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2741 return hwndRelated;
2742}
2743//******************************************************************************
2744//******************************************************************************
2745HWND Win32BaseWindow::SetActiveWindow()
2746{
2747 HWND hwndActive;
2748
2749 dprintf(("SetActiveWindow %x", getWindowHandle()));
2750 if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
2751 dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
2752 }
2753 hwndActive = GetActiveWindow();
2754 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
2755}
2756//******************************************************************************
2757//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2758//******************************************************************************
2759BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2760{
2761 BOOL rc;
2762
2763 //return true if previous state was disabled, else false (sdk docs)
2764 rc = (getStyle() & WS_DISABLED) != 0;
2765 if(rc && !fEnable) {
2766 SendMessageA(WM_CANCELMODE, 0, 0);
2767 }
2768 OSLibWinEnableWindow(OS2Hwnd, fEnable);
2769 if(fEnable == FALSE) {
2770 //SvL: No need to clear focus as PM already does this
2771 if(getWindowHandle() == GetCapture()) {
2772 ReleaseCapture(); /* A disabled window can't capture the mouse */
2773 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
2774 }
2775 }
2776 return rc;
2777}
2778//******************************************************************************
2779//******************************************************************************
2780BOOL Win32BaseWindow::CloseWindow()
2781{
2782 return OSLibWinMinimizeWindow(OS2Hwnd);
2783}
2784//******************************************************************************
2785//TODO: Not be 100% correct; should return active window of current thread
2786// or NULL when there is none -> WinQueryActiveWindow just returns
2787// the current active window
2788//******************************************************************************
2789HWND Win32BaseWindow::GetActiveWindow()
2790{
2791 HWND hwndActive;
2792 Win32BaseWindow *win32wnd;
2793 ULONG magic;
2794
2795 hwndActive = OSLibWinQueryActiveWindow();
2796
2797 return OS2ToWin32Handle(hwndActive);
2798}
2799//******************************************************************************
2800//******************************************************************************
2801BOOL Win32BaseWindow::IsWindowEnabled()
2802{
2803 return OSLibWinIsWindowEnabled(OS2Hwnd);
2804}
2805//******************************************************************************
2806//******************************************************************************
2807BOOL Win32BaseWindow::IsWindowVisible()
2808{
2809 //TODO: Do we have to check the state of the parent window? (as Wine does)
2810#if 1
2811 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2812#else
2813 return OSLibWinIsWindowVisible(OS2Hwnd);
2814#endif
2815}
2816//******************************************************************************
2817//******************************************************************************
2818BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2819{
2820 INT len = GetWindowTextLength();
2821 BOOL res;
2822
2823 if (wndname == NULL)
2824 return (len == 0);
2825
2826 len++;
2827 if (fUnicode)
2828 {
2829 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
2830
2831 GetWindowTextW(text,len);
2832 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
2833 free(text);
2834 } else
2835 {
2836 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
2837
2838 GetWindowTextA(text,len);
2839 res = (strcmp(text,wndname) == 0);
2840 free(text);
2841 }
2842
2843 return res;
2844}
2845//******************************************************************************
2846//******************************************************************************
2847CHAR *Win32BaseWindow::getWindowNamePtrA()
2848{
2849 INT len = GetWindowTextLength();
2850 CHAR *text;
2851
2852 if (len == 0) return NULL;
2853 len++;
2854 text = (CHAR*)malloc(len*sizeof(CHAR));
2855 GetWindowTextA(text,len);
2856
2857 return text;
2858}
2859//******************************************************************************
2860//******************************************************************************
2861WCHAR *Win32BaseWindow::getWindowNamePtrW()
2862{
2863 INT len = GetWindowTextLength();
2864 WCHAR *text;
2865
2866 if (len == 0) return NULL;
2867 len++;
2868 text = (WCHAR*)malloc(len*sizeof(WCHAR));
2869 GetWindowTextW(text,len);
2870
2871 return text;
2872}
2873//******************************************************************************
2874//******************************************************************************
2875VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
2876{
2877 if (namePtr) free(namePtr);
2878}
2879//******************************************************************************
2880//******************************************************************************
2881int Win32BaseWindow::GetWindowTextLength()
2882{
2883 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2884}
2885//******************************************************************************
2886//******************************************************************************
2887int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2888{
2889 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2890}
2891//******************************************************************************
2892//******************************************************************************
2893int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2894{
2895 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2896}
2897//******************************************************************************
2898//******************************************************************************
2899BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2900{
2901 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2902}
2903//******************************************************************************
2904//******************************************************************************
2905BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2906{
2907 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2908}
2909//******************************************************************************
2910//******************************************************************************
2911LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
2912{
2913 LONG oldval;
2914
2915 dprintf2(("SetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
2916 switch(index) {
2917 case GWL_EXSTYLE:
2918 {
2919 STYLESTRUCT ss;
2920
2921 if(dwExStyle == value)
2922 return value;
2923
2924 ss.styleOld = dwExStyle;
2925 ss.styleNew = value;
2926 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2927 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2928 setExStyle(ss.styleNew);
2929 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2930 return ss.styleOld;
2931 }
2932 case GWL_STYLE:
2933 {
2934 STYLESTRUCT ss;
2935
2936 //SvL: TODO: Can you change minimize or maximize status here too?
2937
2938 if(dwStyle == value)
2939 return value;
2940
2941 value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
2942 ss.styleOld = getStyle();
2943 ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
2944 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
2945 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2946 setStyle(ss.styleNew);
2947 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2948//// OSLibSetWindowStyle(getOS2WindowHandle(), getStyle(), getExStyle(),
2949//// windowClass->getStyle() & CS_SAVEBITS);
2950#ifdef DEBUG
2951 PrintWindowStyle(ss.styleNew, 0);
2952#endif
2953 return ss.styleOld;
2954 }
2955 case GWL_WNDPROC:
2956 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
2957 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
2958 return oldval;
2959
2960 case GWL_HINSTANCE:
2961 oldval = hInstance;
2962 hInstance = value;
2963 return oldval;
2964
2965 case GWL_HWNDPARENT:
2966 return SetParent((HWND)value);
2967
2968 case GWL_ID:
2969 oldval = getWindowId();
2970 setWindowId(value);
2971 return oldval;
2972
2973 case GWL_USERDATA:
2974 oldval = userData;
2975 userData = value;
2976 return oldval;
2977
2978 default:
2979 if(index >= 0 && index/4 < nrUserWindowLong)
2980 {
2981 oldval = userWindowLong[index/4];
2982 userWindowLong[index/4] = value;
2983 return oldval;
2984 }
2985 SetLastError(ERROR_INVALID_PARAMETER);
2986 return 0;
2987 }
2988}
2989//******************************************************************************
2990//******************************************************************************
2991ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
2992{
2993 ULONG value;
2994
2995 switch(index) {
2996 case GWL_EXSTYLE:
2997 value = dwExStyle;
2998 break;
2999 case GWL_STYLE:
3000 value = dwStyle;
3001 break;
3002 case GWL_WNDPROC:
3003 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3004 break;
3005 case GWL_HINSTANCE:
3006 value = hInstance;
3007 break;
3008 case GWL_HWNDPARENT:
3009 value = GetParent();
3010 break;
3011 case GWL_ID:
3012 value = getWindowId();
3013 break;
3014 case GWL_USERDATA:
3015 value = userData;
3016 break;
3017 default:
3018 if(index >= 0 && index/4 < nrUserWindowLong)
3019 {
3020 value = userWindowLong[index/4];
3021 break;
3022 }
3023 SetLastError(ERROR_INVALID_PARAMETER);
3024 return 0;
3025 }
3026 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
3027 return value;
3028}
3029//******************************************************************************
3030//******************************************************************************
3031WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3032{
3033 WORD oldval;
3034
3035 if(index >= 0 && index/4 < nrUserWindowLong)
3036 {
3037 oldval = ((WORD *)userWindowLong)[index/2];
3038 ((WORD *)userWindowLong)[index/2] = value;
3039 return oldval;
3040 }
3041 SetLastError(ERROR_INVALID_PARAMETER);
3042 return 0;
3043}
3044//******************************************************************************
3045//******************************************************************************
3046WORD Win32BaseWindow::GetWindowWord(int index)
3047{
3048 if(index >= 0 && index/4 < nrUserWindowLong)
3049 {
3050 return ((WORD *)userWindowLong)[index/2];
3051 }
3052 SetLastError(ERROR_INVALID_PARAMETER);
3053 return 0;
3054}
3055//******************************************************************************
3056//******************************************************************************
3057void Win32BaseWindow::setWindowId(DWORD id)
3058{
3059 dwIDMenu = id;
3060}
3061//******************************************************************************
3062//******************************************************************************
3063Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3064{
3065 Win32BaseWindow *window;
3066
3067 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3068 return window;
3069 }
3070// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3071 return NULL;
3072}
3073//******************************************************************************
3074//******************************************************************************
3075Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3076{
3077 Win32BaseWindow *win32wnd;
3078 DWORD magic;
3079
3080 if(hwnd == OSLIB_HWND_DESKTOP)
3081 {
3082 return windowDesktop;
3083 }
3084
3085 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3086 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3087
3088 if(win32wnd && CheckMagicDword(magic)) {
3089 return win32wnd;
3090 }
3091// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3092 return 0;
3093}
3094//******************************************************************************
3095//******************************************************************************
3096HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3097{
3098 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3099
3100 if(window) {
3101 return window->getOS2WindowHandle();
3102 }
3103// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3104 return hwnd;
3105}
3106//******************************************************************************
3107//******************************************************************************
3108HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3109{
3110 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3111
3112 if(window) {
3113 return window->getWindowHandle();
3114 }
3115// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3116 return 0;
3117// else return hwnd; //OS/2 window handle
3118}
3119//******************************************************************************
3120//******************************************************************************
3121HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3122{
3123 Win32BaseWindow *child, *nextchild, *lastchild;
3124 HWND retvalue;
3125
3126 if (hwndCtrl)
3127 {
3128 child = GetWindowFromHandle(hwndCtrl);
3129 if (!child)
3130 {
3131 retvalue = 0;
3132 goto END;
3133 }
3134 /* Make sure hwndCtrl is a top-level child */
3135 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3136 {
3137 child = child->getParent();
3138 if(child == NULL) break;
3139 }
3140
3141 if (!child || (child->getParent() != this))
3142 {
3143 retvalue = 0;
3144 goto END;
3145 }
3146 }
3147 else
3148 {
3149 /* No ctrl specified -> start from the beginning */
3150 child = (Win32BaseWindow *)getFirstChild();
3151 if (!child)
3152 {
3153 retvalue = 0;
3154 goto END;
3155 }
3156
3157 if (!fPrevious)
3158 {
3159 while (child->getNextChild())
3160 {
3161 child = (Win32BaseWindow *)child->getNextChild();
3162 }
3163 }
3164 }
3165
3166 lastchild = child;
3167 nextchild = (Win32BaseWindow *)child->getNextChild();
3168 while (TRUE)
3169 {
3170 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3171
3172 if (child == nextchild) break;
3173
3174 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3175 !(nextchild->getStyle() & WS_DISABLED))
3176 {
3177 lastchild = nextchild;
3178 if (!fPrevious) break;
3179 }
3180 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3181 }
3182 retvalue = lastchild->getWindowHandle();
3183
3184END:
3185 return retvalue;
3186}
3187//******************************************************************************
3188//******************************************************************************
3189HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3190{
3191 Win32BaseWindow *child, *nextchild, *lastchild;
3192 HWND retvalue;
3193
3194 if (hwndCtrl)
3195 {
3196 child = GetWindowFromHandle(hwndCtrl);
3197 if (!child)
3198 {
3199 retvalue = 0;
3200 goto END;
3201 }
3202 /* Make sure hwndCtrl is a top-level child */
3203 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3204 {
3205 child = child->getParent();
3206 if(child == NULL) break;
3207 }
3208
3209 if (!child || (child->getParent() != this))
3210 {
3211 retvalue = 0;
3212 goto END;
3213 }
3214 }
3215 else
3216 {
3217 /* No ctrl specified -> start from the beginning */
3218 child = (Win32BaseWindow *)getFirstChild();
3219 if (!child)
3220 {
3221 retvalue = 0;
3222 goto END;
3223 }
3224
3225 if (fPrevious)
3226 {
3227 while (child->getNextChild())
3228 {
3229 child = (Win32BaseWindow *)child->getNextChild();
3230 }
3231 }
3232 }
3233
3234 lastchild = child;
3235 nextchild = (Win32BaseWindow *)child->getNextChild();
3236 while (TRUE)
3237 {
3238 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3239 {
3240 /* Wrap-around to the beginning of the group */
3241 Win32BaseWindow *pWndTemp;
3242
3243 nextchild = (Win32BaseWindow *)getFirstChild();
3244
3245 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3246 {
3247 if (pWndTemp->getStyle() & WS_GROUP)
3248 nextchild = pWndTemp;
3249
3250 if (pWndTemp == child)
3251 break;
3252 }
3253
3254 }
3255 if (nextchild == child)
3256 break;
3257
3258 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3259 {
3260 lastchild = nextchild;
3261
3262 if (!fPrevious)
3263 break;
3264 }
3265
3266 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3267 }
3268 retvalue = lastchild->getWindowHandle();
3269END:
3270 return retvalue;
3271}
3272//******************************************************************************
3273//******************************************************************************
3274#ifdef DEBUG
3275void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3276{
3277 char style[256] = "";
3278 char exstyle[256] = "";
3279
3280 /* Window styles */
3281 if(dwStyle & WS_CHILD)
3282 strcat(style, "WS_CHILD ");
3283 if(dwStyle & WS_POPUP)
3284 strcat(style, "WS_POPUP ");
3285 if(dwStyle & WS_VISIBLE)
3286 strcat(style, "WS_VISIBLE ");
3287 if(dwStyle & WS_DISABLED)
3288 strcat(style, "WS_DISABLED ");
3289 if(dwStyle & WS_CLIPSIBLINGS)
3290 strcat(style, "WS_CLIPSIBLINGS ");
3291 if(dwStyle & WS_CLIPCHILDREN)
3292 strcat(style, "WS_CLIPCHILDREN ");
3293 if(dwStyle & WS_MAXIMIZE)
3294 strcat(style, "WS_MAXIMIZE ");
3295 if(dwStyle & WS_MINIMIZE)
3296 strcat(style, "WS_MINIMIZE ");
3297 if(dwStyle & WS_GROUP)
3298 strcat(style, "WS_GROUP ");
3299 if(dwStyle & WS_TABSTOP)
3300 strcat(style, "WS_TABSTOP ");
3301
3302 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3303 strcat(style, "WS_CAPTION ");
3304 if(dwStyle & WS_DLGFRAME)
3305 strcat(style, "WS_DLGFRAME ");
3306 if(dwStyle & WS_BORDER)
3307 strcat(style, "WS_BORDER ");
3308
3309 if(dwStyle & WS_VSCROLL)
3310 strcat(style, "WS_VSCROLL ");
3311 if(dwStyle & WS_HSCROLL)
3312 strcat(style, "WS_HSCROLL ");
3313 if(dwStyle & WS_SYSMENU)
3314 strcat(style, "WS_SYSMENU ");
3315 if(dwStyle & WS_THICKFRAME)
3316 strcat(style, "WS_THICKFRAME ");
3317 if(dwStyle & WS_MINIMIZEBOX)
3318 strcat(style, "WS_MINIMIZEBOX ");
3319 if(dwStyle & WS_MAXIMIZEBOX)
3320 strcat(style, "WS_MAXIMIZEBOX ");
3321
3322 if(dwExStyle & WS_EX_DLGMODALFRAME)
3323 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3324 if(dwExStyle & WS_EX_ACCEPTFILES)
3325 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3326 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3327 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3328 if(dwExStyle & WS_EX_TOPMOST)
3329 strcat(exstyle, "WS_EX_TOPMOST ");
3330 if(dwExStyle & WS_EX_TRANSPARENT)
3331 strcat(exstyle, "WS_EX_TRANSPARENT ");
3332
3333 if(dwExStyle & WS_EX_MDICHILD)
3334 strcat(exstyle, "WS_EX_MDICHILD ");
3335 if(dwExStyle & WS_EX_TOOLWINDOW)
3336 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3337 if(dwExStyle & WS_EX_WINDOWEDGE)
3338 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3339 if(dwExStyle & WS_EX_CLIENTEDGE)
3340 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3341 if(dwExStyle & WS_EX_CONTEXTHELP)
3342 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3343 if(dwExStyle & WS_EX_RIGHT)
3344 strcat(exstyle, "WS_EX_RIGHT ");
3345 if(dwExStyle & WS_EX_LEFT)
3346 strcat(exstyle, "WS_EX_LEFT ");
3347 if(dwExStyle & WS_EX_RTLREADING)
3348 strcat(exstyle, "WS_EX_RTLREADING ");
3349 if(dwExStyle & WS_EX_LTRREADING)
3350 strcat(exstyle, "WS_EX_LTRREADING ");
3351 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3352 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3353 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3354 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3355 if(dwExStyle & WS_EX_CONTROLPARENT)
3356 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3357 if(dwExStyle & WS_EX_STATICEDGE)
3358 strcat(exstyle, "WS_EX_STATICEDGE ");
3359 if(dwExStyle & WS_EX_APPWINDOW)
3360 strcat(exstyle, "WS_EX_APPWINDOW ");
3361
3362 dprintf(("Window style: %x %s", dwStyle, style));
3363 dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
3364}
3365#endif
3366//******************************************************************************
3367//******************************************************************************
3368
3369GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.