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

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

mdi fix + ShowOwnedPopups implemented

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