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

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

moving child window when old window smaller than client area & resized

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