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

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

System menu commands now work

File size: 108.4 KB
Line 
1/* $Id: win32wbase.cpp,v 1.138 2000-01-09 17:57:48 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 dprintf2(("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 dprintf2(("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 if(OS2SysMenu) {
2011 OSLibWinSetSystemMenu(OS2SysMenu);
2012 }
2013 return OS2SysMenu;
2014 }
2015 else {//revert back to default system menu
2016 if(OS2SysMenu) {
2017 DestroyMenu(OS2SysMenu);
2018 OS2SysMenu = 0;
2019 }
2020 return 0;
2021 }
2022 }
2023 else return O32_GetSystemMenu(getOS2FrameWindowHandle(), fRevert);
2024}
2025//******************************************************************************
2026//******************************************************************************
2027BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
2028{
2029
2030 dprintf(("SetMenu %x", hMenu));
2031 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
2032 if(OS2HwndMenu == 0) {
2033 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
2034 return FALSE;
2035 }
2036 return TRUE;
2037}
2038//******************************************************************************
2039//******************************************************************************
2040BOOL Win32BaseWindow::SetIcon(HICON hIcon)
2041{
2042 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
2043 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
2044//TODO: Wine does't send these. Correct?
2045// SendInternalMessageA(WM_SETICON, ICON_BIG, hIcon);
2046 return TRUE;
2047 }
2048 return FALSE;
2049}
2050//******************************************************************************
2051//******************************************************************************
2052BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2053{
2054 ULONG showstate = 0;
2055 HWND hWinAfter;
2056
2057 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2058#if 1
2059 if (flags & WIN_NEED_SIZE)
2060 {
2061 /* should happen only in CreateWindowEx() */
2062 int wParam = SIZE_RESTORED;
2063
2064 flags &= ~WIN_NEED_SIZE;
2065 if (dwStyle & WS_MAXIMIZE)
2066 wParam = SIZE_MAXIMIZED;
2067 else
2068 if (dwStyle & WS_MINIMIZE)
2069 wParam = SIZE_MINIMIZED;
2070
2071 SendInternalMessageA(WM_SIZE, wParam,
2072 MAKELONG(rectClient.right-rectClient.left,
2073 rectClient.bottom-rectClient.top));
2074 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2075 }
2076#else
2077 if(fFirstShow) {
2078 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
2079 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
2080 MAKELONG(rectClient.right-rectClient.left,
2081 rectClient.bottom-rectClient.top));
2082 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2083
2084 }
2085 fFirstShow = FALSE;
2086 }
2087#endif
2088 switch(nCmdShow)
2089 {
2090 case SW_SHOW:
2091 case SW_SHOWDEFAULT: //todo
2092 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2093 break;
2094 case SW_HIDE:
2095 showstate = SWPOS_HIDE;
2096 break;
2097 case SW_RESTORE:
2098 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2099 break;
2100 case SW_MINIMIZE:
2101 showstate = SWPOS_MINIMIZE;
2102 break;
2103 case SW_SHOWMAXIMIZED:
2104 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2105 break;
2106 case SW_SHOWMINIMIZED:
2107 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2108 break;
2109 case SW_SHOWMINNOACTIVE:
2110 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2111 break;
2112 case SW_SHOWNA:
2113 showstate = SWPOS_SHOW;
2114 break;
2115 case SW_SHOWNOACTIVATE:
2116 showstate = SWPOS_SHOW;
2117 break;
2118 case SW_SHOWNORMAL:
2119 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2120 break;
2121 }
2122
2123 /* We can't activate a child window (WINE) */
2124 if(getStyle() & WS_CHILD)
2125 showstate &= ~SWPOS_ACTIVATE;
2126
2127 if(showstate & SWPOS_SHOW) {
2128 setStyle(getStyle() | WS_VISIBLE);
2129 }
2130 else setStyle(getStyle() & ~WS_VISIBLE);
2131
2132 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2133
2134 return rc;
2135}
2136//******************************************************************************
2137//When our parent window is moved, we aren't notified of the change (rectWindow is in
2138//screen coordinates, so it needs to be updated)
2139//Set the fWindowRectChanged flag and do the same for all the children
2140//Whenever getWindowRect is called and this flag is set, it refreshes the rectWindow structure
2141//******************************************************************************
2142void Win32BaseWindow::setWindowRectChanged()
2143{
2144 Win32BaseWindow *child;
2145
2146 fWindowRectChanged = TRUE;
2147
2148 child = (Win32BaseWindow *)getFirstChild();
2149 while(child)
2150 {
2151 child->setWindowRectChanged();
2152 child = (Win32BaseWindow *)child->getNextChild();
2153 }
2154}
2155//******************************************************************************
2156//******************************************************************************
2157PRECT Win32BaseWindow::getWindowRect()
2158{
2159 if(fWindowRectChanged) {
2160 OSLibWinQueryWindowRect(getOS2FrameWindowHandle(), &rectWindow, RELATIVE_TO_SCREEN);
2161 fWindowRectChanged = FALSE;
2162 }
2163 return &rectWindow;
2164}
2165//******************************************************************************
2166//******************************************************************************
2167void Win32BaseWindow::setWindowRect(LONG left, LONG top, LONG right, LONG bottom)
2168{
2169 fWindowRectChanged = FALSE;
2170
2171 rectWindow.left = left;
2172 rectWindow.top = top;
2173 rectWindow.right = right;
2174 rectWindow.bottom = bottom;
2175}
2176//******************************************************************************
2177//******************************************************************************
2178void Win32BaseWindow::setWindowRect(PRECT rect)
2179{
2180 fWindowRectChanged = FALSE;
2181
2182 rectWindow = *rect;
2183}
2184//******************************************************************************
2185//******************************************************************************
2186BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2187{
2188 BOOL rc = FALSE;
2189 Win32BaseWindow *window;
2190 HWND hParent = 0;
2191
2192 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2193
2194 if (fuFlags &
2195 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2196 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2197 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2198 SWP_NOOWNERZORDER))
2199 {
2200 return FALSE;
2201 }
2202
2203 WINDOWPOS wpos;
2204 SWP swp, swpOld;
2205
2206 wpos.flags = fuFlags;
2207 wpos.cy = cy;
2208 wpos.cx = cx;
2209 wpos.x = x;
2210 wpos.y = y;
2211 wpos.hwndInsertAfter = hwndInsertAfter;
2212 wpos.hwnd = getWindowHandle();
2213
2214 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2215 {
2216 if (isChild())
2217 {
2218 Win32BaseWindow *windowParent = getParent();
2219 if(windowParent) {
2220 hParent = getParent()->getOS2WindowHandle();
2221 }
2222 else dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2223 }
2224 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2225 }
2226
2227 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2228 if (swp.fl == 0)
2229 return TRUE;
2230
2231// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2232 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2233 {
2234 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2235 if(wndBehind) {
2236 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2237 }
2238 else {
2239 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2240 swp.hwndInsertBehind = 0;
2241 }
2242 }
2243#if 0
2244 if (isFrameWindow())
2245 {
2246 if (!isChild())
2247 {
2248 POINT maxSize, maxPos, minTrack, maxTrack;
2249
2250 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2251
2252 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2253 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2254 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2255 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2256 }
2257 swp.hwnd = OS2HwndFrame;
2258 }
2259 else
2260#endif
2261 swp.hwnd = OS2HwndFrame;
2262
2263 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2264
2265 rc = OSLibWinSetMultWindowPos(&swp, 1);
2266
2267 if (rc == FALSE)
2268 {
2269 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2270 }
2271
2272 //SWP_FRAMECHANGED is ignored, not necessary for OS/2
2273
2274 return (rc);
2275}
2276//******************************************************************************
2277//TODO: WPF_RESTOREMAXIMIZED
2278//******************************************************************************
2279BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2280{
2281 if(isFrameWindow())
2282 {
2283 // Set the minimized position
2284 if (winpos->flags & WPF_SETMINPOSITION)
2285 {
2286 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2287 }
2288
2289 //TODO: Max position
2290
2291 // Set the new restore position.
2292 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2293 }
2294
2295 return ShowWindow(winpos->showCmd);
2296}
2297//******************************************************************************
2298//Also destroys all the child windows (destroy children first, parent last)
2299//******************************************************************************
2300BOOL Win32BaseWindow::DestroyWindow()
2301{
2302 /* Call hooks */
2303 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2304 {
2305 return FALSE;
2306 }
2307
2308 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2309 {
2310 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2311 /* FIXME: clean up palette - see "Internals" p.352 */
2312 }
2313
2314 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2315 {
2316 if(getParent())
2317 {
2318 /* Notify the parent window only */
2319 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2320 if( !::IsWindow(getWindowHandle()) )
2321 {
2322 return TRUE;
2323 }
2324 }
2325 else DebugInt3();
2326 }
2327 fDestroyWindowCalled = TRUE;
2328 return OSLibWinDestroyWindow(OS2HwndFrame);
2329}
2330//******************************************************************************
2331//******************************************************************************
2332Win32BaseWindow *Win32BaseWindow::getParent()
2333{
2334 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::GetParent();
2335 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2336}
2337//******************************************************************************
2338//******************************************************************************
2339HWND Win32BaseWindow::GetParent()
2340{
2341 Win32BaseWindow *wndparent;
2342
2343 if ((!(getStyle() & (WS_POPUP|WS_CHILD))))
2344 {
2345 return 0;
2346 }
2347 wndparent = ((getStyle() & WS_CHILD) ? getParent() : getOwner());
2348
2349 return (wndparent) ? wndparent->getWindowHandle() : 0;
2350}
2351//******************************************************************************
2352//******************************************************************************
2353HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2354{
2355 HWND oldhwnd;
2356 Win32BaseWindow *newparent;
2357
2358 if(getParent()) {
2359 oldhwnd = getParent()->getWindowHandle();
2360 getParent()->RemoveChild(this);
2361 }
2362 else oldhwnd = 0;
2363
2364 newparent = GetWindowFromHandle(hwndNewParent);
2365 if(newparent)
2366 {
2367 setParent(newparent);
2368 getParent()->AddChild(this);
2369 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2370 return oldhwnd;
2371 }
2372 else {
2373 setParent(windowDesktop);
2374 windowDesktop->AddChild(this);
2375 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2376 return oldhwnd;
2377 }
2378}
2379//******************************************************************************
2380//******************************************************************************
2381BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2382{
2383 if(getParent()) {
2384 return getParent()->getWindowHandle() == hwndParent;
2385 }
2386 else return 0;
2387}
2388//******************************************************************************
2389//******************************************************************************
2390HWND Win32BaseWindow::GetTopWindow()
2391{
2392 return GetWindow(GW_CHILD);
2393}
2394//******************************************************************************
2395// Get the top-level parent for a child window.
2396//******************************************************************************
2397Win32BaseWindow *Win32BaseWindow::GetTopParent()
2398{
2399 Win32BaseWindow *window = this;
2400
2401 while(window && (window->getStyle() & WS_CHILD))
2402 {
2403 window = window->getParent();
2404 }
2405 return window;
2406}
2407//******************************************************************************
2408//Don't call WinUpdateWindow as that one also updates the child windows
2409//Also need to send WM_PAINT directly to the window procedure, which doesn't
2410//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2411//******************************************************************************
2412BOOL Win32BaseWindow::UpdateWindow()
2413{
2414 RECT rect;
2415
2416 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2417 {//update region not empty
2418 HDC hdc;
2419
2420 hdc = O32_GetDC(OS2Hwnd);
2421 if (isIcon)
2422 {
2423 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2424 SendInternalMessageA(WM_PAINTICON, 0, 0);
2425 }
2426 else
2427 {
2428 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2429 SendInternalMessageA(WM_PAINT, 0, 0);
2430 }
2431 O32_ReleaseDC(OS2Hwnd, hdc);
2432 }
2433 return TRUE;
2434}
2435//******************************************************************************
2436//******************************************************************************
2437BOOL Win32BaseWindow::IsIconic()
2438{
2439 return OSLibWinIsIconic(OS2Hwnd);
2440}
2441//******************************************************************************
2442//TODO: Should not enumerate children that are created during the enumeration!
2443//******************************************************************************
2444BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2445{
2446 BOOL rc = TRUE;
2447 HWND hwnd;
2448 Win32BaseWindow *prevchild = 0, *child = 0;
2449
2450 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2451 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2452 {
2453 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2454 hwnd = child->getWindowHandle();
2455 if(child->getOwner()) {
2456 continue; //shouldn't have an owner (Wine)
2457 }
2458 if(lpfn(hwnd, lParam) == FALSE)
2459 {
2460 rc = FALSE;
2461 break;
2462 }
2463 //check if the window still exists
2464 if(!::IsWindow(hwnd))
2465 {
2466 child = prevchild;
2467 continue;
2468 }
2469 if(child->getFirstChild() != NULL)
2470 {
2471 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2472 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2473 {
2474 rc = FALSE;
2475 break;
2476 }
2477 }
2478 prevchild = child;
2479 }
2480 return rc;
2481}
2482//******************************************************************************
2483//Enumerate first-level children only and check thread id
2484//******************************************************************************
2485BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2486{
2487 Win32BaseWindow *child = 0;
2488 ULONG tid, pid;
2489 BOOL rc;
2490 HWND hwnd;
2491
2492 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2493
2494 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2495 {
2496 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2497
2498 if(dwThreadId == tid) {
2499 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2500 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2501 break;
2502 }
2503 }
2504 }
2505 return TRUE;
2506}
2507//******************************************************************************
2508//Enumerate first-level children only
2509//******************************************************************************
2510BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2511{
2512 Win32BaseWindow *child = 0;
2513 BOOL rc;
2514 HWND hwnd;
2515
2516 dprintf(("EnumWindows %x %x", lpfn, lParam));
2517
2518 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2519 {
2520 hwnd = child->getWindowHandle();
2521
2522 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2523 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2524 break;
2525 }
2526 }
2527 return TRUE;
2528}
2529//******************************************************************************
2530//******************************************************************************
2531Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2532{
2533 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2534 {
2535 if (child->getWindowId() == id)
2536 {
2537 return child;
2538 }
2539 }
2540 return 0;
2541}
2542//******************************************************************************
2543//TODO:
2544//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2545//the current process owns them.
2546//******************************************************************************
2547HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2548 BOOL fUnicode)
2549{
2550 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2551 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2552
2553 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2554 (hwndChildAfter != 0 && !child) ||
2555 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2556 {
2557 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2558 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2559 return 0;
2560 }
2561 if(hwndParent != OSLIB_HWND_DESKTOP)
2562 {//if the current process owns the window, just do a quick search
2563 child = (Win32BaseWindow *)parent->getFirstChild();
2564 if(hwndChildAfter != 0)
2565 {
2566 while(child)
2567 {
2568 if(child->getWindowHandle() == hwndChildAfter)
2569 {
2570 child = (Win32BaseWindow *)child->getNextChild();
2571 break;
2572 }
2573 child = (Win32BaseWindow *)child->getNextChild();
2574 }
2575 }
2576 while(child)
2577 {
2578 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2579 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2580 {
2581 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2582 return child->getWindowHandle();
2583 }
2584 child = (Win32BaseWindow *)child->getNextChild();
2585 }
2586 }
2587 else {
2588 Win32BaseWindow *wnd;
2589 HWND henum, hwnd;
2590
2591 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2592 hwnd = OSLibWinGetNextWindow(henum);
2593
2594 while(hwnd)
2595 {
2596 wnd = GetWindowFromOS2Handle(hwnd);
2597 if(wnd == NULL) {
2598 hwnd = OSLibWinQueryClientWindow(hwnd);
2599 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2600 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2601 }
2602
2603 if(wnd) {
2604 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2605 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2606 {
2607 OSLibWinEndEnumWindows(henum);
2608 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2609 return wnd->getWindowHandle();
2610 }
2611 }
2612 hwnd = OSLibWinGetNextWindow(henum);
2613 }
2614 OSLibWinEndEnumWindows(henum);
2615 }
2616 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2617 return 0;
2618}
2619//******************************************************************************
2620//******************************************************************************
2621HWND Win32BaseWindow::GetWindow(UINT uCmd)
2622{
2623 HWND hwndRelated = 0;
2624 Win32BaseWindow *window;
2625
2626 switch(uCmd)
2627 {
2628 case GW_HWNDFIRST:
2629 if(getParent()) {
2630 window = (Win32BaseWindow *)getParent()->getFirstChild();
2631 hwndRelated = window->getWindowHandle();
2632 }
2633 break;
2634
2635 case GW_HWNDLAST:
2636 if(!getParent())
2637 {
2638 goto end;
2639 }
2640
2641 window = this;
2642 while(window->getNextChild())
2643 {
2644 window = (Win32BaseWindow *)window->getNextChild();
2645 }
2646 hwndRelated = window->getWindowHandle();
2647 break;
2648
2649 case GW_HWNDNEXT:
2650 window = (Win32BaseWindow *)getNextChild();
2651 if(window) {
2652 hwndRelated = window->getWindowHandle();
2653 }
2654 break;
2655
2656 case GW_HWNDPREV:
2657 if(!getParent())
2658 {
2659 goto end;
2660 }
2661 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2662 if(window == this)
2663 {
2664 hwndRelated = 0; /* First in list */
2665 goto end;
2666 }
2667 while(window->getNextChild())
2668 {
2669 if (window->getNextChild() == this)
2670 {
2671 hwndRelated = window->getWindowHandle();
2672 goto end;
2673 }
2674 window = (Win32BaseWindow *)window->getNextChild();
2675 }
2676 break;
2677
2678 case GW_OWNER:
2679 if(getOwner()) {
2680 hwndRelated = getOwner()->getWindowHandle();
2681 }
2682 break;
2683
2684 case GW_CHILD:
2685 if(getFirstChild()) {
2686 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2687 }
2688 break;
2689 }
2690end:
2691 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2692 return hwndRelated;
2693}
2694//******************************************************************************
2695//******************************************************************************
2696HWND Win32BaseWindow::SetActiveWindow()
2697{
2698 HWND hwndActive;
2699 Win32BaseWindow *win32wnd;
2700 ULONG magic;
2701
2702 hwndActive = OSLibWinSetActiveWindow(OS2HwndFrame);
2703 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2704 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2705 if(CheckMagicDword(magic) && win32wnd)
2706 {
2707 return win32wnd->getWindowHandle();
2708 }
2709 return 0;
2710}
2711//******************************************************************************
2712//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2713//******************************************************************************
2714BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2715{
2716 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2717}
2718//******************************************************************************
2719//******************************************************************************
2720BOOL Win32BaseWindow::CloseWindow()
2721{
2722 return OSLibWinMinimizeWindow(OS2HwndFrame);
2723}
2724//******************************************************************************
2725//******************************************************************************
2726HWND Win32BaseWindow::GetActiveWindow()
2727{
2728 HWND hwndActive;
2729 Win32BaseWindow *win32wnd;
2730 ULONG magic;
2731
2732 hwndActive = OSLibWinQueryActiveWindow();
2733
2734 return OS2ToWin32Handle(hwndActive);
2735}
2736//******************************************************************************
2737//******************************************************************************
2738BOOL Win32BaseWindow::IsWindowEnabled()
2739{
2740 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2741}
2742//******************************************************************************
2743//******************************************************************************
2744BOOL Win32BaseWindow::IsWindowVisible()
2745{
2746#if 1
2747 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2748#else
2749 return OSLibWinIsWindowVisible(OS2HwndFrame);
2750#endif
2751}
2752//******************************************************************************
2753//******************************************************************************
2754BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2755{
2756 INT len = GetWindowTextLength();
2757 BOOL res;
2758
2759 if (wndname == NULL)
2760 return (len == 0);
2761
2762 len++;
2763 if (fUnicode)
2764 {
2765 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
2766
2767 GetWindowTextW(text,len);
2768 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
2769 free(text);
2770 } else
2771 {
2772 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
2773
2774 GetWindowTextA(text,len);
2775 res = (strcmp(text,wndname) == 0);
2776 free(text);
2777 }
2778
2779 return res;
2780}
2781//******************************************************************************
2782//******************************************************************************
2783CHAR *Win32BaseWindow::getWindowNamePtrA()
2784{
2785 INT len = GetWindowTextLength();
2786 CHAR *text;
2787
2788 if (len == 0) return NULL;
2789 len++;
2790 text = (CHAR*)malloc(len*sizeof(CHAR));
2791 GetWindowTextA(text,len);
2792
2793 return text;
2794}
2795//******************************************************************************
2796//******************************************************************************
2797WCHAR *Win32BaseWindow::getWindowNamePtrW()
2798{
2799 INT len = GetWindowTextLength();
2800 WCHAR *text;
2801
2802 if (len == 0) return NULL;
2803 len++;
2804 text = (WCHAR*)malloc(len*sizeof(WCHAR));
2805 GetWindowTextW(text,len);
2806
2807 return text;
2808}
2809//******************************************************************************
2810//******************************************************************************
2811VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
2812{
2813 if (namePtr) free(namePtr);
2814}
2815//******************************************************************************
2816//******************************************************************************
2817int Win32BaseWindow::GetWindowTextLength()
2818{
2819 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2820}
2821//******************************************************************************
2822//******************************************************************************
2823int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2824{
2825 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2826}
2827//******************************************************************************
2828//******************************************************************************
2829int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2830{
2831 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2832}
2833//******************************************************************************
2834//******************************************************************************
2835BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2836{
2837 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2838}
2839//******************************************************************************
2840//******************************************************************************
2841BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2842{
2843 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2844}
2845//******************************************************************************
2846//******************************************************************************
2847VOID Win32BaseWindow::updateWindowStyle(DWORD oldExStyle,DWORD oldStyle)
2848{
2849 if(IsWindowDestroyed()) return;
2850
2851 //CB: todo: dwExStyle, creating new frame controls, destroy not used controls, WS_VISIBLE, WS_CHILD, ...
2852 // write test cases
2853 if ((dwStyle & 0xFFFF0000) != (oldStyle & 0xFFFF0000))
2854 {
2855 //dprintf(("updateWindowStyle: %x %x",oldStyle,dwStyle));
2856 OSLibSetWindowStyle(OS2HwndFrame, dwStyle, fTaskList);
2857 }
2858}
2859//******************************************************************************
2860//******************************************************************************
2861LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
2862{
2863 LONG oldval;
2864
2865 dprintf2(("SetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
2866 switch(index) {
2867 case GWL_EXSTYLE:
2868 {
2869 STYLESTRUCT ss;
2870
2871 if(dwExStyle == value)
2872 return value;
2873
2874 ss.styleOld = dwExStyle;
2875 ss.styleNew = value;
2876 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2877 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2878 setExStyle(ss.styleNew);
2879 updateWindowStyle(ss.styleOld,getStyle());
2880 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2881 return ss.styleOld;
2882 }
2883 case GWL_STYLE:
2884 {
2885 STYLESTRUCT ss;
2886
2887 if(dwStyle == value)
2888 return value;
2889
2890 value &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way (WINE) */
2891 ss.styleOld = getStyle();
2892 ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
2893 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
2894 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2895 setStyle(ss.styleNew);
2896 updateWindowStyle(dwExStyle,ss.styleOld);
2897 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2898#ifdef DEBUG
2899 PrintWindowStyle(ss.styleNew, 0);
2900#endif
2901 return ss.styleOld;
2902 }
2903 case GWL_WNDPROC:
2904 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
2905 //WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
2906 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
2907 return oldval;
2908 case GWL_HINSTANCE:
2909 oldval = hInstance;
2910 hInstance = value;
2911 return oldval;
2912 case GWL_HWNDPARENT:
2913 return SetParent((HWND)value);
2914 case GWL_ID:
2915 oldval = getWindowId();
2916 setWindowId(value);
2917 return oldval;
2918 case GWL_USERDATA:
2919 oldval = userData;
2920 userData = value;
2921 return oldval;
2922 default:
2923 if(index >= 0 && index/4 < nrUserWindowLong)
2924 {
2925 oldval = userWindowLong[index/4];
2926 userWindowLong[index/4] = value;
2927 return oldval;
2928 }
2929 SetLastError(ERROR_INVALID_PARAMETER);
2930 return 0;
2931 }
2932}
2933//******************************************************************************
2934//******************************************************************************
2935ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
2936{
2937 ULONG value;
2938
2939 switch(index) {
2940 case GWL_EXSTYLE:
2941 value = dwExStyle;
2942 break;
2943 case GWL_STYLE:
2944 value = dwStyle;
2945 break;
2946 case GWL_WNDPROC:
2947 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
2948 break;
2949 case GWL_HINSTANCE:
2950 value = hInstance;
2951 break;
2952 case GWL_HWNDPARENT:
2953 if(getParent()) {
2954 value = getParent()->getWindowHandle();
2955 }
2956 else value = 0;
2957 break;
2958 case GWL_ID:
2959 value = getWindowId();
2960 break;
2961 case GWL_USERDATA:
2962 value = userData;
2963 break;
2964 default:
2965 if(index >= 0 && index/4 < nrUserWindowLong)
2966 {
2967 value = userWindowLong[index/4];
2968 break;
2969 }
2970 SetLastError(ERROR_INVALID_PARAMETER);
2971 return 0;
2972 }
2973 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
2974 return value;
2975}
2976//******************************************************************************
2977//******************************************************************************
2978WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2979{
2980 WORD oldval;
2981
2982 if(index >= 0 && index/4 < nrUserWindowLong)
2983 {
2984 oldval = ((WORD *)userWindowLong)[index/2];
2985 ((WORD *)userWindowLong)[index/2] = value;
2986 return oldval;
2987 }
2988 SetLastError(ERROR_INVALID_PARAMETER);
2989 return 0;
2990}
2991//******************************************************************************
2992//******************************************************************************
2993WORD Win32BaseWindow::GetWindowWord(int index)
2994{
2995 if(index >= 0 && index/4 < nrUserWindowLong)
2996 {
2997 return ((WORD *)userWindowLong)[index/2];
2998 }
2999 SetLastError(ERROR_INVALID_PARAMETER);
3000 return 0;
3001}
3002//******************************************************************************
3003//******************************************************************************
3004void Win32BaseWindow::setWindowId(DWORD id)
3005{
3006 windowId = id;
3007 dprintf(("Set window ID to %x", id));
3008 OSLibSetWindowID(OS2HwndFrame, id);
3009}
3010//******************************************************************************
3011//******************************************************************************
3012Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3013{
3014 Win32BaseWindow *window;
3015
3016 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3017 return window;
3018 }
3019// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3020 return NULL;
3021}
3022//******************************************************************************
3023//******************************************************************************
3024Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3025{
3026 Win32BaseWindow *win32wnd;
3027 DWORD magic;
3028
3029 if(hwnd == OSLIB_HWND_DESKTOP)
3030 {
3031 return windowDesktop;
3032 }
3033
3034 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3035 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3036
3037 if(win32wnd && CheckMagicDword(magic)) {
3038 return win32wnd;
3039 }
3040// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3041 return 0;
3042}
3043//******************************************************************************
3044//******************************************************************************
3045Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3046{
3047 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3048}
3049//******************************************************************************
3050//******************************************************************************
3051HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3052{
3053 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3054
3055 if(window) {
3056 return window->getOS2WindowHandle();
3057 }
3058// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3059 return hwnd;
3060}
3061//******************************************************************************
3062//******************************************************************************
3063HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
3064{
3065 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3066
3067 if(window) {
3068 return window->getOS2FrameWindowHandle();
3069 }
3070// dprintf2(("Win32BaseWindow::Win32ToOS2FrameHandle: not a win32 window %x", hwnd));
3071 return hwnd;
3072}
3073//******************************************************************************
3074//******************************************************************************
3075HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3076{
3077 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3078
3079 if(window) {
3080 return window->getWindowHandle();
3081 }
3082 window = GetWindowFromOS2FrameHandle(hwnd);
3083 if(window) {
3084 return window->getWindowHandle();
3085 }
3086// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3087 return 0;
3088// else return hwnd; //OS/2 window handle
3089}
3090//******************************************************************************
3091// GetNextDlgTabItem32 (USER32.276)
3092//******************************************************************************
3093HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3094{
3095 Win32BaseWindow *child, *nextchild, *lastchild;
3096 HWND retvalue;
3097
3098 if (hwndCtrl)
3099 {
3100 child = GetWindowFromHandle(hwndCtrl);
3101 if (!child)
3102 {
3103 retvalue = 0;
3104 goto END;
3105 }
3106 /* Make sure hwndCtrl is a top-level child */
3107 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3108 {
3109 child = child->getParent();
3110 if(child == NULL) break;
3111 }
3112
3113 if (!child || (child->getParent() != this))
3114 {
3115 retvalue = 0;
3116 goto END;
3117 }
3118 }
3119 else
3120 {
3121 /* No ctrl specified -> start from the beginning */
3122 child = (Win32BaseWindow *)getFirstChild();
3123 if (!child)
3124 {
3125 retvalue = 0;
3126 goto END;
3127 }
3128
3129 if (!fPrevious)
3130 {
3131 while (child->getNextChild())
3132 {
3133 child = (Win32BaseWindow *)child->getNextChild();
3134 }
3135 }
3136 }
3137
3138 lastchild = child;
3139 nextchild = (Win32BaseWindow *)child->getNextChild();
3140 while (TRUE)
3141 {
3142 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3143
3144 if (child == nextchild) break;
3145
3146 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3147 !(nextchild->getStyle() & WS_DISABLED))
3148 {
3149 lastchild = nextchild;
3150 if (!fPrevious) break;
3151 }
3152 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3153 }
3154 retvalue = lastchild->getWindowHandle();
3155
3156END:
3157 return retvalue;
3158}
3159//******************************************************************************
3160//******************************************************************************
3161HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3162{
3163 Win32BaseWindow *child, *nextchild, *lastchild;
3164 HWND retvalue;
3165
3166 if (hwndCtrl)
3167 {
3168 child = GetWindowFromHandle(hwndCtrl);
3169 if (!child)
3170 {
3171 retvalue = 0;
3172 goto END;
3173 }
3174 /* Make sure hwndCtrl is a top-level child */
3175 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3176 {
3177 child = child->getParent();
3178 if(child == NULL) break;
3179 }
3180
3181 if (!child || (child->getParent() != this))
3182 {
3183 retvalue = 0;
3184 goto END;
3185 }
3186 }
3187 else
3188 {
3189 /* No ctrl specified -> start from the beginning */
3190 child = (Win32BaseWindow *)getFirstChild();
3191 if (!child)
3192 {
3193 retvalue = 0;
3194 goto END;
3195 }
3196
3197 if (fPrevious)
3198 {
3199 while (child->getNextChild())
3200 {
3201 child = (Win32BaseWindow *)child->getNextChild();
3202 }
3203 }
3204 }
3205
3206 lastchild = child;
3207 nextchild = (Win32BaseWindow *)child->getNextChild();
3208 while (TRUE)
3209 {
3210 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3211 {
3212 /* Wrap-around to the beginning of the group */
3213 Win32BaseWindow *pWndTemp;
3214
3215 nextchild = (Win32BaseWindow *)getFirstChild();
3216
3217 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3218 {
3219 if (pWndTemp->getStyle() & WS_GROUP)
3220 nextchild = pWndTemp;
3221
3222 if (pWndTemp == child)
3223 break;
3224 }
3225
3226 }
3227 if (nextchild == child)
3228 break;
3229
3230 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3231 {
3232 lastchild = nextchild;
3233
3234 if (!fPrevious)
3235 break;
3236 }
3237
3238 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3239 }
3240 retvalue = lastchild->getWindowHandle();
3241END:
3242 return retvalue;
3243}
3244//******************************************************************************
3245//******************************************************************************
3246#ifdef DEBUG
3247void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3248{
3249 char style[256] = "";
3250 char exstyle[256] = "";
3251
3252 /* Window styles */
3253 if(dwStyle & WS_CHILD)
3254 strcat(style, "WS_CHILD ");
3255 if(dwStyle & WS_POPUP)
3256 strcat(style, "WS_POPUP ");
3257 if(dwStyle & WS_VISIBLE)
3258 strcat(style, "WS_VISIBLE ");
3259 if(dwStyle & WS_DISABLED)
3260 strcat(style, "WS_DISABLED ");
3261 if(dwStyle & WS_CLIPSIBLINGS)
3262 strcat(style, "WS_CLIPSIBLINGS ");
3263 if(dwStyle & WS_CLIPCHILDREN)
3264 strcat(style, "WS_CLIPCHILDREN ");
3265 if(dwStyle & WS_MAXIMIZE)
3266 strcat(style, "WS_MAXIMIZE ");
3267 if(dwStyle & WS_MINIMIZE)
3268 strcat(style, "WS_MINIMIZE ");
3269 if(dwStyle & WS_GROUP)
3270 strcat(style, "WS_GROUP ");
3271 if(dwStyle & WS_TABSTOP)
3272 strcat(style, "WS_TABSTOP ");
3273
3274 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3275 strcat(style, "WS_CAPTION ");
3276 if(dwStyle & WS_DLGFRAME)
3277 strcat(style, "WS_DLGFRAME ");
3278 if(dwStyle & WS_BORDER)
3279 strcat(style, "WS_BORDER ");
3280
3281 if(dwStyle & WS_VSCROLL)
3282 strcat(style, "WS_VSCROLL ");
3283 if(dwStyle & WS_HSCROLL)
3284 strcat(style, "WS_HSCROLL ");
3285 if(dwStyle & WS_SYSMENU)
3286 strcat(style, "WS_SYSMENU ");
3287 if(dwStyle & WS_THICKFRAME)
3288 strcat(style, "WS_THICKFRAME ");
3289 if(dwStyle & WS_MINIMIZEBOX)
3290 strcat(style, "WS_MINIMIZEBOX ");
3291 if(dwStyle & WS_MAXIMIZEBOX)
3292 strcat(style, "WS_MAXIMIZEBOX ");
3293
3294 if(dwExStyle & WS_EX_DLGMODALFRAME)
3295 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3296 if(dwExStyle & WS_EX_ACCEPTFILES)
3297 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3298 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3299 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3300 if(dwExStyle & WS_EX_TOPMOST)
3301 strcat(exstyle, "WS_EX_TOPMOST ");
3302 if(dwExStyle & WS_EX_TRANSPARENT)
3303 strcat(exstyle, "WS_EX_TRANSPARENT ");
3304
3305 if(dwExStyle & WS_EX_MDICHILD)
3306 strcat(exstyle, "WS_EX_MDICHILD ");
3307 if(dwExStyle & WS_EX_TOOLWINDOW)
3308 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3309 if(dwExStyle & WS_EX_WINDOWEDGE)
3310 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3311 if(dwExStyle & WS_EX_CLIENTEDGE)
3312 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3313 if(dwExStyle & WS_EX_CONTEXTHELP)
3314 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3315 if(dwExStyle & WS_EX_RIGHT)
3316 strcat(exstyle, "WS_EX_RIGHT ");
3317 if(dwExStyle & WS_EX_LEFT)
3318 strcat(exstyle, "WS_EX_LEFT ");
3319 if(dwExStyle & WS_EX_RTLREADING)
3320 strcat(exstyle, "WS_EX_RTLREADING ");
3321 if(dwExStyle & WS_EX_LTRREADING)
3322 strcat(exstyle, "WS_EX_LTRREADING ");
3323 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3324 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3325 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3326 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3327 if(dwExStyle & WS_EX_CONTROLPARENT)
3328 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3329 if(dwExStyle & WS_EX_STATICEDGE)
3330 strcat(exstyle, "WS_EX_STATICEDGE ");
3331 if(dwExStyle & WS_EX_APPWINDOW)
3332 strcat(exstyle, "WS_EX_APPWINDOW ");
3333
3334 dprintf(("Window style: %x %s", dwStyle, style));
3335 dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
3336}
3337#endif
3338//******************************************************************************
3339//******************************************************************************
3340
3341GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.