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

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

create dialog controls with CreateWindowExW; use correct SendMessage during CreateWindow

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