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

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

Focus + dialog fixes

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