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

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

WM_NCHITTEST changes; no longer rely on PM

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