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

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

minimize updates + update region fix in NotifyFrameChanged

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