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

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

heap corruption bugfix

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