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

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

desktop + misc updates

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