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

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

window property fixes/changes

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