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

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

lots of fixes + changes (see ChangeLog)

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