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

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

dprintf2 addition + Rene Pronk's mnemonics changes

File size: 102.1 KB
Line 
1/* $Id: win32wbase.cpp,v 1.78 1999-11-09 19:23:17 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(wParam == VK_F4) /* try to close the window */
1568 {
1569 Win32BaseWindow *window = GetTopParent();
1570 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1571 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1572 }
1573
1574 Win32BaseWindow *siblingWindow;
1575 HWND sibling;
1576 char nameBuffer [40], mnemonic;
1577 int nameLength;
1578
1579 GetWindowTextA (nameBuffer, 40);
1580
1581 // search all sibling to see it this key is their mnemonic
1582 sibling = GetWindow (GW_HWNDFIRST);
1583 while (sibling != 0) {
1584 siblingWindow = GetWindowFromHandle (sibling);
1585 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1586
1587 // find the siblings mnemonic
1588 mnemonic = '\0';
1589 for (int i=0 ; i<nameLength ; i++) {
1590 if (nameBuffer [i] == '&') {
1591 mnemonic = nameBuffer [i+1];
1592 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1593 mnemonic -= 32; // make it uppercase
1594 break; // stop searching
1595 }
1596 }
1597
1598 // key matches siblings mnemonic, send mouseclick
1599 if (mnemonic == (char) wParam) {
1600 siblingWindow->SendMessageA (BM_CLICK, 0, 0);
1601 }
1602
1603 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1604 }
1605
1606 return 0;
1607
1608 case WM_QUERYOPEN:
1609 case WM_QUERYENDSESSION:
1610 return 1;
1611
1612 case WM_NOTIFYFORMAT:
1613 if (IsUnicode()) return NFR_UNICODE;
1614 else return NFR_ANSI;
1615
1616 case WM_SETICON:
1617 case WM_GETICON:
1618 {
1619 LRESULT result = 0;
1620 if (!windowClass) return result;
1621 int index = GCL_HICON;
1622
1623 if (wParam == ICON_SMALL)
1624 index = GCL_HICONSM;
1625
1626 result = windowClass->getClassLongA(index);
1627
1628 if (Msg == WM_SETICON)
1629 windowClass->setClassLongA(index, lParam);
1630
1631 return result;
1632 }
1633 case WM_NOTIFY:
1634 return 0; //comctl32 controls expect this
1635
1636 default:
1637 if(Msg > WM_USER) {
1638 return 0;
1639 }
1640 return 1;
1641 }
1642}
1643//******************************************************************************
1644//******************************************************************************
1645LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1646{
1647 switch(Msg)
1648 {
1649 case WM_GETTEXTLENGTH:
1650 return wndNameLength;
1651
1652 case WM_GETTEXT: //TODO: SS_ICON controls
1653 {
1654 LRESULT result;
1655 char *str = (char *) malloc(wParam + 1);
1656 result = DefWindowProcA(Msg, wParam, (LPARAM)str );
1657 lstrcpynAtoW( (LPWSTR)lParam, str, wParam );
1658 free(str);
1659 return result;
1660 }
1661
1662 case WM_SETTEXT:
1663 {
1664 if(!fInternalMsg)
1665 {
1666 LRESULT result;
1667 char *aText = (char *) malloc((lstrlenW((LPWSTR)lParam)+1)*sizeof(WCHAR));
1668 *aText = 0;
1669 lstrcpyWtoA(aText, (LPWSTR) lParam);
1670 result = SetWindowTextA(aText);
1671 free(aText);
1672 return result;
1673 }
1674 else return 0;
1675 }
1676
1677 default:
1678 return DefWindowProcA(Msg, wParam, lParam);
1679 }
1680}
1681//******************************************************************************
1682//******************************************************************************
1683LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1684{
1685 LRESULT rc;
1686 BOOL fInternalMsgBackup = fInternalMsg;
1687
1688 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1689 // receive those before they get their WM_CREATE message
1690 //NOTE: May need to refuse more messages
1691 if(fCreated == FALSE && Msg == WM_COMMAND) {
1692 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1693 return 0;
1694 }
1695
1696 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
1697
1698 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1699 return(0);
1700 }
1701 fInternalMsg = FALSE;
1702 switch(Msg)
1703 {
1704 case WM_CREATE:
1705 {
1706 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1707 dprintf(("WM_CREATE returned -1\n"));
1708 rc = -1; //don't create window
1709 break;
1710 }
1711 NotifyParent(Msg, wParam, lParam);
1712
1713 rc = 0;
1714 break;
1715 }
1716 case WM_SETTEXT:
1717 rc = CallWindowProcA(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1718 break;
1719
1720 case WM_LBUTTONDOWN:
1721 case WM_MBUTTONDOWN:
1722 case WM_RBUTTONDOWN:
1723 NotifyParent(Msg, wParam, lParam);
1724 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1725 break;
1726
1727 case WM_DESTROY:
1728 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1729 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1730 break;
1731
1732 default:
1733 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1734 break;
1735 }
1736 fInternalMsg = fInternalMsgBackup;
1737 return rc;
1738}
1739//******************************************************************************
1740//******************************************************************************
1741LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1742{
1743 LRESULT rc;
1744 BOOL fInternalMsgBackup = fInternalMsg;
1745
1746 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1747 // receive those before they get their WM_CREATE message
1748 //NOTE: May need to refuse more messages
1749 if(fCreated == FALSE && Msg == WM_COMMAND) {
1750 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1751 return 0;
1752 }
1753
1754 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
1755
1756 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1757 return(0);
1758 }
1759 fInternalMsg = FALSE;
1760 switch(Msg)
1761 {
1762 case WM_CREATE:
1763 {
1764 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1765 dprintf(("WM_CREATE returned -1\n"));
1766 rc = -1; //don't create window
1767 break;
1768 }
1769 NotifyParent(Msg, wParam, lParam);
1770
1771 rc = 0;
1772 break;
1773 }
1774 case WM_SETTEXT:
1775 rc = CallWindowProcW(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1776 break;
1777
1778 case WM_LBUTTONDOWN:
1779 case WM_MBUTTONDOWN:
1780 case WM_RBUTTONDOWN:
1781 NotifyParent(Msg, wParam, lParam);
1782 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1783 break;
1784
1785 case WM_DESTROY:
1786 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1787 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1788 break;
1789
1790 default:
1791 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1792 break;
1793 }
1794 fInternalMsg = fInternalMsgBackup;
1795 return rc;
1796}
1797//******************************************************************************
1798//Called as a result of an OS/2 message
1799//******************************************************************************
1800LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1801{
1802 LRESULT rc;
1803 BOOL fInternalMsgBackup = fInternalMsg;
1804
1805 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1806
1807 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1808 return(0);
1809 }
1810 fInternalMsg = TRUE;
1811 switch(Msg)
1812 {
1813 case WM_CREATE:
1814 {
1815 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1816 dprintf(("WM_CREATE returned -1\n"));
1817 rc = -1; //don't create window
1818 break;
1819 }
1820 NotifyParent(Msg, wParam, lParam);
1821 rc = 0;
1822 break;
1823 }
1824 case WM_LBUTTONDOWN:
1825 case WM_MBUTTONDOWN:
1826 case WM_RBUTTONDOWN:
1827 NotifyParent(Msg, wParam, lParam);
1828 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1829 break;
1830
1831 case WM_DESTROY:
1832 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1833 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1834 break;
1835 default:
1836 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1837 break;
1838 }
1839 fInternalMsg = fInternalMsgBackup;
1840 return rc;
1841}
1842//******************************************************************************
1843//Called as a result of an OS/2 message
1844//todo, unicode msgs (WM_SETTEXT etc)
1845//******************************************************************************
1846LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1847{
1848 LRESULT rc;
1849 BOOL fInternalMsgBackup = fInternalMsg;
1850
1851 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1852
1853 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1854 return(0);
1855 }
1856 fInternalMsg = TRUE;
1857 switch(Msg)
1858 {
1859 case WM_CREATE:
1860 {
1861 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1862 dprintf(("WM_CREATE returned -1\n"));
1863 rc = -1; //don't create window
1864 break;
1865 }
1866 NotifyParent(Msg, wParam, lParam);
1867 rc = 0;
1868 break;
1869 }
1870 case WM_LBUTTONDOWN:
1871 case WM_MBUTTONDOWN:
1872 case WM_RBUTTONDOWN:
1873 NotifyParent(Msg, wParam, lParam);
1874 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1875 break;
1876
1877 case WM_DESTROY:
1878 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1879 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1880 break;
1881 default:
1882 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1883 break;
1884 }
1885 fInternalMsg = fInternalMsgBackup;
1886 return rc;
1887}
1888//******************************************************************************
1889//******************************************************************************
1890BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1891{
1892 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1893}
1894//******************************************************************************
1895//******************************************************************************
1896BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1897{
1898 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1899}
1900//******************************************************************************
1901//TODO: do we need to inform the parent of the parent (etc) of the child window?
1902//******************************************************************************
1903void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1904{
1905 Win32BaseWindow *window = this;
1906 Win32BaseWindow *parentwindow;
1907
1908 while(window)
1909 {
1910 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1911 {
1912 /* Notify the parent window only */
1913 parentwindow = window->getParent();
1914 if(parentwindow) {
1915 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1916 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1917 }
1918 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1919 }
1920 }
1921 else break;
1922
1923 window = parentwindow;
1924 }
1925}
1926//******************************************************************************
1927//******************************************************************************
1928BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1929{
1930
1931 dprintf(("SetMenu %x", hMenu));
1932 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1933 if(OS2HwndMenu == 0) {
1934 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1935 return FALSE;
1936 }
1937 return TRUE;
1938}
1939//******************************************************************************
1940//******************************************************************************
1941BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1942{
1943 Win32Resource *winres = (Win32Resource *)hAccel;
1944 HANDLE accelhandle;
1945
1946 if(HIWORD(hAccel) == 0) {
1947 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1948 SetLastError(ERROR_INVALID_PARAMETER);
1949 return FALSE;
1950 }
1951 acceltableResource = winres;
1952 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1953 winres->setOS2Handle(accelhandle);
1954 return(accelhandle != 0);
1955}
1956//******************************************************************************
1957//******************************************************************************
1958BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1959{
1960 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1961 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1962//TODO: Wine does't send these. Correct?
1963// SendMessageA(WM_SETICON, ICON_BIG, hIcon);
1964 return TRUE;
1965 }
1966 return FALSE;
1967}
1968//******************************************************************************
1969//******************************************************************************
1970BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1971{
1972 ULONG showstate = 0;
1973 HWND hWinAfter;
1974
1975 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
1976#if 1
1977 if (flags & WIN_NEED_SIZE)
1978 {
1979 /* should happen only in CreateWindowEx() */
1980 int wParam = SIZE_RESTORED;
1981
1982 flags &= ~WIN_NEED_SIZE;
1983 if (dwStyle & WS_MAXIMIZE)
1984 wParam = SIZE_MAXIMIZED;
1985 else
1986 if (dwStyle & WS_MINIMIZE)
1987 wParam = SIZE_MINIMIZED;
1988
1989 SendMessageA(WM_SIZE, wParam,
1990 MAKELONG(rectClient.right-rectClient.left,
1991 rectClient.bottom-rectClient.top));
1992 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1993 }
1994#else
1995 if(fFirstShow) {
1996 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
1997 SendMessageA(WM_SIZE, SIZE_RESTORED,
1998 MAKELONG(rectClient.right-rectClient.left,
1999 rectClient.bottom-rectClient.top));
2000 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2001
2002 }
2003 fFirstShow = FALSE;
2004 }
2005#endif
2006 switch(nCmdShow)
2007 {
2008 case SW_SHOW:
2009 case SW_SHOWDEFAULT: //todo
2010 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2011 break;
2012 case SW_HIDE:
2013 showstate = SWPOS_HIDE;
2014 break;
2015 case SW_RESTORE:
2016 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2017 break;
2018 case SW_MINIMIZE:
2019 showstate = SWPOS_MINIMIZE;
2020 break;
2021 case SW_SHOWMAXIMIZED:
2022 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2023 break;
2024 case SW_SHOWMINIMIZED:
2025 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2026 break;
2027 case SW_SHOWMINNOACTIVE:
2028 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2029 break;
2030 case SW_SHOWNA:
2031 showstate = SWPOS_SHOW;
2032 break;
2033 case SW_SHOWNOACTIVATE:
2034 showstate = SWPOS_SHOW;
2035 break;
2036 case SW_SHOWNORMAL:
2037 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2038 break;
2039 }
2040
2041 /* We can't activate a child window (WINE) */
2042 if(getStyle() & WS_CHILD)
2043 showstate &= ~SWPOS_ACTIVATE;
2044
2045 if(showstate & SWPOS_SHOW) {
2046 setStyle(getStyle() | WS_VISIBLE);
2047 }
2048 else setStyle(getStyle() & ~WS_VISIBLE);
2049
2050 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2051 return rc;
2052}
2053//******************************************************************************
2054//******************************************************************************
2055BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2056{
2057 BOOL rc = FALSE;
2058 Win32BaseWindow *window;
2059 HWND hParent = 0;
2060
2061 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2062
2063 if (fuFlags &
2064 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2065 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2066 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2067 SWP_NOOWNERZORDER))
2068 {
2069 return FALSE;
2070 }
2071
2072 WINDOWPOS wpos;
2073 SWP swp, swpOld;
2074
2075 wpos.flags = fuFlags;
2076 wpos.cy = cy;
2077 wpos.cx = cx;
2078 wpos.x = x;
2079 wpos.y = y;
2080 wpos.hwndInsertAfter = hwndInsertAfter;
2081 wpos.hwnd = getWindowHandle();
2082
2083 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2084 {
2085 if (isChild())
2086 {
2087 hParent = getParent()->getOS2WindowHandle();
2088 }
2089 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2090 }
2091
2092 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2093 if (swp.fl == 0)
2094 return TRUE;
2095
2096// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2097 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2098 {
2099 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2100 if(wndBehind) {
2101 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2102 }
2103 else {
2104 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2105 swp.hwndInsertBehind = 0;
2106 }
2107 }
2108#if 0
2109 if (isFrameWindow())
2110 {
2111 if (!isChild())
2112 {
2113 POINT maxSize, maxPos, minTrack, maxTrack;
2114
2115 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2116
2117 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2118 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2119 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2120 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2121 }
2122 swp.hwnd = OS2HwndFrame;
2123 }
2124 else
2125#endif
2126 swp.hwnd = OS2HwndFrame;
2127
2128 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2129
2130 rc = OSLibWinSetMultWindowPos(&swp, 1);
2131
2132 if (rc == FALSE)
2133 {
2134 dprintf(("OSLibWinSetMultWindowPos failed!"));
2135 }
2136 else
2137 {
2138 if (fuFlags & SWP_FRAMECHANGED_W)
2139 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2140 }
2141
2142 return (rc);
2143}
2144//******************************************************************************
2145//TODO: WPF_RESTOREMAXIMIZED
2146//******************************************************************************
2147BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2148{
2149 if(isFrameWindow())
2150 {
2151 // Set the minimized position
2152 if (winpos->flags & WPF_SETMINPOSITION)
2153 {
2154 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2155 }
2156
2157 //TODO: Max position
2158
2159 // Set the new restore position.
2160 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2161 }
2162
2163 return ShowWindow(winpos->showCmd);
2164}
2165//******************************************************************************
2166//Also destroys all the child windows (destroy parent, destroy children)
2167//******************************************************************************
2168BOOL Win32BaseWindow::DestroyWindow()
2169{
2170 return OSLibWinDestroyWindow(OS2HwndFrame);
2171}
2172//******************************************************************************
2173//******************************************************************************
2174HWND Win32BaseWindow::GetParent()
2175{
2176 if(getParent()) {
2177 return getParent()->getWindowHandle();
2178 }
2179 else return 0;
2180}
2181//******************************************************************************
2182//******************************************************************************
2183HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2184{
2185 HWND oldhwnd;
2186 Win32BaseWindow *newparent;
2187
2188 if(getParent()) {
2189 oldhwnd = getParent()->getWindowHandle();
2190 getParent()->RemoveChild(this);
2191 }
2192 else oldhwnd = 0;
2193
2194 newparent = GetWindowFromHandle(hwndNewParent);
2195 if(newparent)
2196 {
2197 setParent(newparent);
2198 getParent()->AddChild(this);
2199 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2200 return oldhwnd;
2201 }
2202 SetLastError(ERROR_INVALID_PARAMETER);
2203 return 0;
2204}
2205//******************************************************************************
2206//******************************************************************************
2207BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2208{
2209 if(getParent()) {
2210 return getParent()->getWindowHandle() == hwndParent;
2211 }
2212 else return 0;
2213}
2214//******************************************************************************
2215//******************************************************************************
2216HWND Win32BaseWindow::GetTopWindow()
2217{
2218 return GetWindow(GW_CHILD);
2219}
2220//******************************************************************************
2221// Get the top-level parent for a child window.
2222//******************************************************************************
2223Win32BaseWindow *Win32BaseWindow::GetTopParent()
2224{
2225 Win32BaseWindow *window = this;
2226
2227 while(window && (window->getStyle() & WS_CHILD))
2228 {
2229 window = window->getParent();
2230 }
2231 return window;
2232}
2233//******************************************************************************
2234//Don't call WinUpdateWindow as that one also updates the child windows
2235//Also need to send WM_PAINT directly to the window procedure, which doesn't
2236//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2237//******************************************************************************
2238BOOL Win32BaseWindow::UpdateWindow()
2239{
2240 RECT rect;
2241
2242 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2243 {//update region not empty
2244 HDC hdc;
2245
2246 hdc = O32_GetDC(OS2Hwnd);
2247 if (isIcon)
2248 {
2249 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2250 SendMessageA(WM_PAINTICON, 0, 0);
2251 } else
2252 {
2253 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2254 SendMessageA(WM_PAINT, 0, 0);
2255 }
2256 O32_ReleaseDC(OS2Hwnd, hdc);
2257 }
2258 return TRUE;
2259}
2260//******************************************************************************
2261//******************************************************************************
2262BOOL Win32BaseWindow::IsIconic()
2263{
2264 return OSLibWinIsIconic(OS2Hwnd);
2265}
2266//******************************************************************************
2267//TODO: Should not enumerate children that are created during the enumeration!
2268//******************************************************************************
2269BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2270{
2271 BOOL rc = TRUE;
2272 HWND hwnd;
2273 Win32BaseWindow *prevchild = 0, *child = 0;
2274
2275 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2276 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2277 {
2278 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2279 hwnd = child->getWindowHandle();
2280 if(lpfn(hwnd, lParam) == FALSE)
2281 {
2282 rc = FALSE;
2283 break;
2284 }
2285 //check if the window still exists
2286 if(!::IsWindow(hwnd))
2287 {
2288 child = prevchild;
2289 continue;
2290 }
2291 if(child->getFirstChild() != NULL)
2292 {
2293 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2294 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2295 {
2296 rc = FALSE;
2297 break;
2298 }
2299 }
2300 prevchild = child;
2301 }
2302 return rc;
2303}
2304//******************************************************************************
2305//******************************************************************************
2306Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2307{
2308 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2309 {
2310 if (child->getWindowId() == id)
2311 {
2312 return child;
2313 }
2314 }
2315 return 0;
2316}
2317//******************************************************************************
2318//TODO:
2319//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2320//the current process owns them.
2321//******************************************************************************
2322HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2323 BOOL fUnicode)
2324{
2325 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2326 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2327
2328 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2329 (hwndChildAfter != 0 && !child) ||
2330 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2331 {
2332 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2333 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2334 return 0;
2335 }
2336 if(hwndParent != OSLIB_HWND_DESKTOP)
2337 {//if the current process owns the window, just do a quick search
2338 child = (Win32BaseWindow *)parent->getFirstChild();
2339 if(hwndChildAfter != 0)
2340 {
2341 while(child)
2342 {
2343 if(child->getWindowHandle() == hwndChildAfter)
2344 {
2345 child = (Win32BaseWindow *)child->getNextChild();
2346 break;
2347 }
2348 child = (Win32BaseWindow *)child->getNextChild();
2349 }
2350 }
2351 while(child)
2352 {
2353 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2354 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2355 {
2356 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2357 return child->getWindowHandle();
2358 }
2359 child = (Win32BaseWindow *)child->getNextChild();
2360 }
2361 }
2362 else {
2363 Win32BaseWindow *wnd;
2364 HWND henum, hwnd;
2365
2366 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2367 hwnd = OSLibWinGetNextWindow(henum);
2368
2369 while(hwnd)
2370 {
2371 wnd = GetWindowFromOS2Handle(hwnd);
2372 if(wnd == NULL) {
2373 hwnd = OSLibWinQueryClientWindow(hwnd);
2374 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2375 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2376 }
2377
2378 if(wnd) {
2379 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2380 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2381 {
2382 OSLibWinEndEnumWindows(henum);
2383 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2384 return wnd->getWindowHandle();
2385 }
2386 }
2387 hwnd = OSLibWinGetNextWindow(henum);
2388 }
2389 OSLibWinEndEnumWindows(henum);
2390 }
2391 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2392 return 0;
2393}
2394//******************************************************************************
2395//******************************************************************************
2396HWND Win32BaseWindow::GetWindow(UINT uCmd)
2397{
2398 HWND hwndRelated = 0;
2399 Win32BaseWindow *window;
2400
2401 switch(uCmd)
2402 {
2403 case GW_HWNDFIRST:
2404 if(getParent()) {
2405 window = (Win32BaseWindow *)getParent()->getFirstChild();
2406 hwndRelated = window->getWindowHandle();
2407 }
2408 break;
2409
2410 case GW_HWNDLAST:
2411 if(getParent())
2412 {
2413 goto end;
2414 }
2415
2416 window = this;
2417 while(window)
2418 {
2419 window = (Win32BaseWindow *)window->getNextChild();
2420 }
2421 hwndRelated = window->getWindowHandle();
2422 break;
2423
2424 case GW_HWNDNEXT:
2425 window = (Win32BaseWindow *)getNextChild();
2426 if(window) {
2427 hwndRelated = window->getWindowHandle();
2428 }
2429 break;
2430
2431 case GW_HWNDPREV:
2432 if(!getParent())
2433 {
2434 goto end;
2435 }
2436 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2437 if(window == this)
2438 {
2439 hwndRelated = 0; /* First in list */
2440 goto end;
2441 }
2442 while(window->getNextChild())
2443 {
2444 if (window->getNextChild() == this)
2445 {
2446 hwndRelated = window->getWindowHandle();
2447 goto end;
2448 }
2449 window = (Win32BaseWindow *)window->getNextChild();
2450 }
2451 break;
2452
2453 case GW_OWNER:
2454 if(getOwner()) {
2455 hwndRelated = getOwner()->getWindowHandle();
2456 }
2457 break;
2458
2459 case GW_CHILD:
2460 if(getFirstChild()) {
2461 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2462 }
2463 break;
2464 }
2465end:
2466 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2467 return hwndRelated;
2468}
2469//******************************************************************************
2470//******************************************************************************
2471HWND Win32BaseWindow::SetActiveWindow()
2472{
2473 return OSLibWinSetActiveWindow(OS2HwndFrame);
2474}
2475//******************************************************************************
2476//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2477//******************************************************************************
2478BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2479{
2480 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2481}
2482//******************************************************************************
2483//******************************************************************************
2484BOOL Win32BaseWindow::CloseWindow()
2485{
2486 return OSLibWinMinimizeWindow(OS2HwndFrame);
2487}
2488//******************************************************************************
2489//******************************************************************************
2490HWND Win32BaseWindow::GetActiveWindow()
2491{
2492 HWND hwndActive;
2493 Win32BaseWindow *win32wnd;
2494 ULONG magic;
2495
2496 hwndActive = OSLibWinQueryActiveWindow();
2497
2498 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2499 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2500 if(CheckMagicDword(magic) && win32wnd)
2501 {
2502 return win32wnd->getWindowHandle();
2503 }
2504 return hwndActive;
2505}
2506//******************************************************************************
2507//******************************************************************************
2508BOOL Win32BaseWindow::IsWindowEnabled()
2509{
2510 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2511}
2512//******************************************************************************
2513//******************************************************************************
2514BOOL Win32BaseWindow::IsWindowVisible()
2515{
2516#if 1
2517 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2518#else
2519 return OSLibWinIsWindowVisible(OS2HwndFrame);
2520#endif
2521}
2522//******************************************************************************
2523//******************************************************************************
2524BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2525{
2526 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2527}
2528//******************************************************************************
2529//******************************************************************************
2530BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2531{
2532 if(wndname == NULL)
2533 return FALSE;
2534
2535 if(fUnicode) {
2536 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2537 }
2538 else return (strcmp(windowNameA, wndname) == 0);
2539}
2540//******************************************************************************
2541//******************************************************************************
2542int Win32BaseWindow::GetWindowTextLength()
2543{
2544 return wndNameLength;
2545}
2546//******************************************************************************
2547//******************************************************************************
2548int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2549{
2550 if(windowNameA == NULL) {
2551 *lpsz = 0;
2552 return 0;
2553 }
2554 strncpy(lpsz, windowNameA, cch);
2555 return wndNameLength;
2556}
2557//******************************************************************************
2558//******************************************************************************
2559int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2560{
2561 if(windowNameW == NULL) {
2562 *lpsz = 0;
2563 return 0;
2564 }
2565 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2566 return wndNameLength;
2567}
2568//******************************************************************************
2569//******************************************************************************
2570BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2571{
2572 if(lpsz == NULL)
2573 return FALSE;
2574
2575 if(windowNameA) free(windowNameA);
2576 if(windowNameW) free(windowNameW);
2577
2578 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2579 strcpy(windowNameA, lpsz);
2580 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2581 lstrcpyAtoW(windowNameW, windowNameA);
2582 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2583
2584 if(OS2HwndFrame)
2585 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2586
2587 return TRUE;
2588}
2589//******************************************************************************
2590//******************************************************************************
2591BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2592{
2593 if(lpsz == NULL)
2594 return FALSE;
2595
2596 if(windowNameA) free(windowNameA);
2597 if(windowNameW) free(windowNameW);
2598
2599 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2600 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2601 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2602 lstrcpyWtoA(windowNameA, windowNameW);
2603 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2604
2605 if(OS2HwndFrame)
2606 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2607
2608 return TRUE;
2609}
2610//******************************************************************************
2611//******************************************************************************
2612LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2613{
2614 LONG oldval;
2615
2616 switch(index) {
2617 case GWL_EXSTYLE:
2618 {
2619 STYLESTRUCT ss;
2620
2621 if(dwExStyle == value)
2622 return value;
2623
2624 ss.styleOld = dwExStyle;
2625 ss.styleNew = value;
2626 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2627 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2628 setExStyle(ss.styleNew);
2629 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2630 return ss.styleOld;
2631 }
2632 case GWL_STYLE:
2633 {
2634 STYLESTRUCT ss;
2635
2636 if(dwStyle == value)
2637 return value;
2638
2639 ss.styleOld = dwStyle;
2640 ss.styleNew = value;
2641 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), dwStyle, value));
2642 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2643 setStyle(ss.styleNew);
2644 if(!IsWindowDestroyed())
2645 OSLibSetWindowStyle(OS2HwndFrame, ss.styleNew);
2646 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2647 return ss.styleOld;
2648 }
2649 case GWL_WNDPROC:
2650 oldval = (LONG)getWindowProc();
2651 setWindowProc((WNDPROC)value);
2652 return oldval;
2653 case GWL_HINSTANCE:
2654 oldval = hInstance;
2655 hInstance = value;
2656 return oldval;
2657 case GWL_HWNDPARENT:
2658 return SetParent((HWND)value);
2659 case GWL_ID:
2660 oldval = getWindowId();
2661 setWindowId(value);
2662 return oldval;
2663 case GWL_USERDATA:
2664 oldval = userData;
2665 userData = value;
2666 return oldval;
2667 default:
2668 if(index >= 0 && index/4 < nrUserWindowLong)
2669 {
2670 oldval = userWindowLong[index/4];
2671 userWindowLong[index/4] = value;
2672 return oldval;
2673 }
2674 SetLastError(ERROR_INVALID_PARAMETER);
2675 return 0;
2676 }
2677}
2678//******************************************************************************
2679//******************************************************************************
2680ULONG Win32BaseWindow::GetWindowLongA(int index)
2681{
2682 switch(index) {
2683 case GWL_EXSTYLE:
2684 return dwExStyle;
2685 case GWL_STYLE:
2686 return dwStyle;
2687 case GWL_WNDPROC:
2688 return (ULONG)getWindowProc();
2689 case GWL_HINSTANCE:
2690 return hInstance;
2691 case GWL_HWNDPARENT:
2692 if(getParent()) {
2693 return getParent()->getWindowHandle();
2694 }
2695 else return 0;
2696 case GWL_ID:
2697 return getWindowId();
2698 case GWL_USERDATA:
2699 return userData;
2700 default:
2701 if(index >= 0 && index/4 < nrUserWindowLong)
2702 {
2703 return userWindowLong[index/4];
2704 }
2705 SetLastError(ERROR_INVALID_PARAMETER);
2706 return 0;
2707 }
2708}
2709//******************************************************************************
2710//******************************************************************************
2711WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2712{
2713 WORD oldval;
2714
2715 if(index >= 0 && index/4 < nrUserWindowLong)
2716 {
2717 oldval = ((WORD *)userWindowLong)[index/2];
2718 ((WORD *)userWindowLong)[index/2] = value;
2719 return oldval;
2720 }
2721 SetLastError(ERROR_INVALID_PARAMETER);
2722 return 0;
2723}
2724//******************************************************************************
2725//******************************************************************************
2726WORD Win32BaseWindow::GetWindowWord(int index)
2727{
2728 if(index >= 0 && index/4 < nrUserWindowLong)
2729 {
2730 return ((WORD *)userWindowLong)[index/2];
2731 }
2732 SetLastError(ERROR_INVALID_PARAMETER);
2733 return 0;
2734}
2735//******************************************************************************
2736//******************************************************************************
2737void Win32BaseWindow::setWindowId(DWORD id)
2738{
2739 windowId = id;
2740 OSLibSetWindowID(OS2HwndFrame, id);
2741}
2742//******************************************************************************
2743//******************************************************************************
2744Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2745{
2746 Win32BaseWindow *window;
2747
2748 if(hwnd == NULL && windowDesktop)
2749 return windowDesktop;
2750
2751 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2752 return window;
2753 }
2754 else return NULL;
2755}
2756//******************************************************************************
2757//******************************************************************************
2758Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2759{
2760 Win32BaseWindow *win32wnd;
2761 DWORD magic;
2762
2763 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2764 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2765
2766 if(win32wnd && CheckMagicDword(magic)) {
2767 return win32wnd;
2768 }
2769 return 0;
2770}
2771//******************************************************************************
2772//******************************************************************************
2773Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
2774{
2775 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
2776}
2777//******************************************************************************
2778//******************************************************************************
2779HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2780{
2781 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2782
2783 if(window) {
2784 return window->getOS2WindowHandle();
2785 }
2786 else return hwnd;
2787}
2788//******************************************************************************
2789//******************************************************************************
2790HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
2791{
2792 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2793
2794 if(window) {
2795 return window->getOS2FrameWindowHandle();
2796 }
2797 else return hwnd;
2798}
2799//******************************************************************************
2800//******************************************************************************
2801HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2802{
2803 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2804
2805 if(window) {
2806 return window->getWindowHandle();
2807 }
2808 window = GetWindowFromOS2FrameHandle(hwnd);
2809 if(window) {
2810 return window->getWindowHandle();
2811 }
2812 else return 0;
2813// else return hwnd; //OS/2 window handle
2814}
2815//******************************************************************************
2816// GetNextDlgTabItem32 (USER32.276)
2817//******************************************************************************
2818HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
2819{
2820 Win32BaseWindow *child, *nextchild, *lastchild;
2821 HWND retvalue;
2822
2823 if (hwndCtrl)
2824 {
2825 child = GetWindowFromHandle(hwndCtrl);
2826 if (!child)
2827 {
2828 retvalue = 0;
2829 goto END;
2830 }
2831 /* Make sure hwndCtrl is a top-level child */
2832 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
2833 {
2834 child = child->getParent();
2835 if(child == NULL) break;
2836 }
2837
2838 if (!child || child->getParent() != this)
2839 {
2840 retvalue = 0;
2841 goto END;
2842 }
2843 }
2844 else
2845 {
2846 /* No ctrl specified -> start from the beginning */
2847 child = (Win32BaseWindow *)getFirstChild();
2848 if (!child)
2849 {
2850 retvalue = 0;
2851 goto END;
2852 }
2853
2854 if (!fPrevious)
2855 {
2856 while (child->getNextChild())
2857 {
2858 child = (Win32BaseWindow *)child->getNextChild();
2859 }
2860 }
2861 }
2862
2863 lastchild = child;
2864 nextchild = (Win32BaseWindow *)child->getNextChild();
2865 while (TRUE)
2866 {
2867 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
2868
2869 if (child == nextchild) break;
2870
2871 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
2872 !(nextchild->getStyle() & WS_DISABLED))
2873 {
2874 lastchild = nextchild;
2875 if (!fPrevious) break;
2876 }
2877 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
2878 }
2879 retvalue = lastchild->getWindowHandle();
2880
2881END:
2882 return retvalue;
2883}
2884//******************************************************************************
2885//******************************************************************************
2886HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
2887{
2888 Win32BaseWindow *child, *nextchild, *lastchild;
2889 HWND retvalue;
2890
2891 if (hwndCtrl)
2892 {
2893 child = GetWindowFromHandle(hwndCtrl);
2894 if (!child)
2895 {
2896 retvalue = 0;
2897 goto END;
2898 }
2899 /* Make sure hwndCtrl is a top-level child */
2900 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
2901 {
2902 child = child->getParent();
2903 if(child == NULL) break;
2904 }
2905
2906 if (!child || child->getParent() != this)
2907 {
2908 retvalue = 0;
2909 goto END;
2910 }
2911 }
2912 else
2913 {
2914 /* No ctrl specified -> start from the beginning */
2915 child = (Win32BaseWindow *)getFirstChild();
2916 if (!child)
2917 {
2918 retvalue = 0;
2919 goto END;
2920 }
2921
2922 if (fPrevious)
2923 {
2924 while (child->getNextChild())
2925 {
2926 child = (Win32BaseWindow *)child->getNextChild();
2927 }
2928 }
2929 }
2930
2931 lastchild = child;
2932 nextchild = (Win32BaseWindow *)child->getNextChild();
2933 while (TRUE)
2934 {
2935 if (!nextchild || nextchild->getStyle() & WS_GROUP)
2936 {
2937 /* Wrap-around to the beginning of the group */
2938 Win32BaseWindow *pWndTemp;
2939
2940 nextchild = (Win32BaseWindow *)getFirstChild();
2941
2942 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
2943 {
2944 if (pWndTemp->getStyle() & WS_GROUP)
2945 nextchild = pWndTemp;
2946
2947 if (pWndTemp == child)
2948 break;
2949 }
2950
2951 }
2952 if (nextchild == child)
2953 break;
2954
2955 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
2956 {
2957 lastchild = nextchild;
2958
2959 if (!fPrevious)
2960 break;
2961 }
2962
2963 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
2964 }
2965 retvalue = lastchild->getWindowHandle();
2966END:
2967 return retvalue;
2968}
2969//******************************************************************************
2970//******************************************************************************
2971#ifdef DEBUG
2972void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
2973{
2974 char style[256] = "";
2975 char exstyle[256] = "";
2976
2977 /* Window styles */
2978 if(dwStyle & WS_CHILD)
2979 strcat(style, "WS_CHILD ");
2980 if(dwStyle & WS_POPUP)
2981 strcat(style, "WS_POPUP ");
2982 if(dwStyle & WS_VISIBLE)
2983 strcat(style, "WS_VISIBLE ");
2984 if(dwStyle & WS_DISABLED)
2985 strcat(style, "WS_DISABLED ");
2986 if(dwStyle & WS_CLIPSIBLINGS)
2987 strcat(style, "WS_CLIPSIBLINGS ");
2988 if(dwStyle & WS_CLIPCHILDREN)
2989 strcat(style, "WS_CLIPCHILDREN ");
2990 if(dwStyle & WS_MAXIMIZE)
2991 strcat(style, "WS_MAXIMIZE ");
2992 if(dwStyle & WS_MINIMIZE)
2993 strcat(style, "WS_MINIMIZE ");
2994 if(dwStyle & WS_GROUP)
2995 strcat(style, "WS_GROUP ");
2996 if(dwStyle & WS_TABSTOP)
2997 strcat(style, "WS_TABSTOP ");
2998
2999 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3000 strcat(style, "WS_CAPTION ");
3001 if(dwStyle & WS_DLGFRAME)
3002 strcat(style, "WS_DLGFRAME ");
3003 if(dwStyle & WS_BORDER)
3004 strcat(style, "WS_BORDER ");
3005
3006 if(dwStyle & WS_VSCROLL)
3007 strcat(style, "WS_VSCROLL ");
3008 if(dwStyle & WS_HSCROLL)
3009 strcat(style, "WS_HSCROLL ");
3010 if(dwStyle & WS_SYSMENU)
3011 strcat(style, "WS_SYSMENU ");
3012 if(dwStyle & WS_THICKFRAME)
3013 strcat(style, "WS_THICKFRAME ");
3014 if(dwStyle & WS_MINIMIZEBOX)
3015 strcat(style, "WS_MINIMIZEBOX ");
3016 if(dwStyle & WS_MAXIMIZEBOX)
3017 strcat(style, "WS_MAXIMIZEBOX ");
3018
3019 if(dwExStyle & WS_EX_DLGMODALFRAME)
3020 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3021 if(dwExStyle & WS_EX_ACCEPTFILES)
3022 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3023 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3024 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3025 if(dwExStyle & WS_EX_TOPMOST)
3026 strcat(exstyle, "WS_EX_TOPMOST ");
3027 if(dwExStyle & WS_EX_TRANSPARENT)
3028 strcat(exstyle, "WS_EX_TRANSPARENT ");
3029
3030 if(dwExStyle & WS_EX_MDICHILD)
3031 strcat(exstyle, "WS_EX_MDICHILD ");
3032 if(dwExStyle & WS_EX_TOOLWINDOW)
3033 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3034 if(dwExStyle & WS_EX_WINDOWEDGE)
3035 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3036 if(dwExStyle & WS_EX_CLIENTEDGE)
3037 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3038 if(dwExStyle & WS_EX_CONTEXTHELP)
3039 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3040 if(dwExStyle & WS_EX_RIGHT)
3041 strcat(exstyle, "WS_EX_RIGHT ");
3042 if(dwExStyle & WS_EX_LEFT)
3043 strcat(exstyle, "WS_EX_LEFT ");
3044 if(dwExStyle & WS_EX_RTLREADING)
3045 strcat(exstyle, "WS_EX_RTLREADING ");
3046 if(dwExStyle & WS_EX_LTRREADING)
3047 strcat(exstyle, "WS_EX_LTRREADING ");
3048 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3049 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3050 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3051 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3052 if(dwExStyle & WS_EX_CONTROLPARENT)
3053 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3054 if(dwExStyle & WS_EX_STATICEDGE)
3055 strcat(exstyle, "WS_EX_STATICEDGE ");
3056 if(dwExStyle & WS_EX_APPWINDOW)
3057 strcat(exstyle, "WS_EX_APPWINDOW ");
3058
3059 dprintf(("Window style: %x %s", dwStyle, style));
3060 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3061}
3062#endif
3063//******************************************************************************
3064//******************************************************************************
3065
3066GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.