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

Last change on this file since 5655 was 5646, checked in by sandervl, 24 years ago

YD: SendNCCalcSize bugfix

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