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

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

wsprintf fix, menu accelerator fix

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