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

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

some fixes

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