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

Last change on this file since 2384 was 2384, checked in by sandervl, 26 years ago

win32 look update

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