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

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

activation fixes

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