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

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

WM_MINIMIZE/WS_MAXIMIZE support added to CreateWindow

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