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

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

Dinput additions + PostThreadMessageA/W fix

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