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

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

window style fixes

File size: 95.5 KB
Line 
1/* $Id: win32wbase.cpp,v 1.64 1999-10-28 15:20:25 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
1042 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1043 switch(msg) {
1044 case BUTTON_LEFTDOWN:
1045 win32msg = WM_LBUTTONDOWN;
1046 win32ncmsg = WM_NCLBUTTONDOWN;
1047 break;
1048 case BUTTON_LEFTUP:
1049 win32msg = WM_LBUTTONUP;
1050 win32ncmsg = WM_NCLBUTTONUP;
1051 break;
1052 case BUTTON_LEFTDBLCLICK:
1053 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1054 {
1055 win32msg = WM_LBUTTONDBLCLK;
1056 win32ncmsg = WM_NCLBUTTONDBLCLK;
1057 } else
1058 {
1059 MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
1060 return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
1061 }
1062 break;
1063 case BUTTON_RIGHTUP:
1064 win32msg = WM_RBUTTONUP;
1065 win32ncmsg = WM_NCRBUTTONUP;
1066 break;
1067 case BUTTON_RIGHTDOWN:
1068 win32msg = WM_RBUTTONDOWN;
1069 win32ncmsg = WM_NCRBUTTONDOWN;
1070 break;
1071 case BUTTON_RIGHTDBLCLICK:
1072 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1073 {
1074 win32msg = WM_RBUTTONDBLCLK;
1075 win32ncmsg = WM_NCRBUTTONDBLCLK;
1076 } else
1077 {
1078 MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
1079 return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
1080 }
1081 break;
1082 case BUTTON_MIDDLEUP:
1083 win32msg = WM_MBUTTONUP;
1084 win32ncmsg = WM_NCMBUTTONUP;
1085 break;
1086 case BUTTON_MIDDLEDOWN:
1087 win32msg = WM_MBUTTONDOWN;
1088 win32ncmsg = WM_NCMBUTTONDOWN;
1089 break;
1090 case BUTTON_MIDDLEDBLCLICK:
1091 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1092 {
1093 win32msg = WM_MBUTTONDBLCLK;
1094 win32ncmsg = WM_NCMBUTTONDBLCLK;
1095 } else
1096 {
1097 MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
1098 return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
1099 }
1100 break;
1101 default:
1102 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1103 return 1;
1104 }
1105
1106 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1107
1108 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1109 if(lastHitTestVal != HTCLIENT) {
1110 return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1111 }
1112 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1113}
1114//******************************************************************************
1115//******************************************************************************
1116ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1117{
1118 ULONG winstate = 0;
1119 ULONG setcursormsg = WM_MOUSEMOVE;
1120
1121 if(keystate & WMMOVE_LBUTTON)
1122 winstate |= MK_LBUTTON;
1123 if(keystate & WMMOVE_RBUTTON)
1124 winstate |= MK_RBUTTON;
1125 if(keystate & WMMOVE_MBUTTON)
1126 winstate |= MK_MBUTTON;
1127 if(keystate & WMMOVE_SHIFT)
1128 winstate |= MK_SHIFT;
1129 if(keystate & WMMOVE_CTRL)
1130 winstate |= MK_CONTROL;
1131
1132 if(lastHitTestVal != HTCLIENT) {
1133 setcursormsg = WM_NCMOUSEMOVE;
1134 }
1135 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1136 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1137
1138 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1139 if(lastHitTestVal != HTCLIENT) {
1140 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1141 }
1142 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1143}
1144//******************************************************************************
1145//******************************************************************************
1146ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1147{
1148 if (select && isIcon)
1149 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1150 else
1151 return SendInternalMessageA(WM_PAINT, 0, 0);
1152}
1153//******************************************************************************
1154//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1155// (or are we simply erasing too much here)
1156//******************************************************************************
1157ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1158{
1159 ULONG rc;
1160 HDC hdcErase = hdc;
1161
1162 if (hdcErase == 0)
1163 hdcErase = O32_GetDC(OS2Hwnd);
1164
1165 if(isIcon)
1166 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1167 else
1168 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1169 if (hdc == 0)
1170 O32_ReleaseDC(OS2Hwnd, hdcErase);
1171 return (rc);
1172}
1173//******************************************************************************
1174//******************************************************************************
1175ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1176{
1177 if(isUnicode) {
1178 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1179 }
1180 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1181}
1182//******************************************************************************
1183//TODO: in- or excluding terminating 0?
1184//******************************************************************************
1185ULONG Win32BaseWindow::MsgGetTextLength()
1186{
1187 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1188}
1189//******************************************************************************
1190//******************************************************************************
1191char *Win32BaseWindow::MsgGetText()
1192{
1193 if(isUnicode) {
1194 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1195 }
1196 else {
1197 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1198 }
1199 return windowNameA;
1200}
1201//******************************************************************************
1202//******************************************************************************
1203BOOL Win32BaseWindow::isMDIClient()
1204{
1205 return FALSE;
1206}
1207//******************************************************************************
1208//******************************************************************************
1209BOOL Win32BaseWindow::isMDIChild()
1210{
1211 return FALSE;
1212}
1213//******************************************************************************
1214//TODO: Not complete
1215//******************************************************************************
1216BOOL Win32BaseWindow::isFrameWindow()
1217{
1218// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1219 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1220 return TRUE;
1221
1222 return FALSE;
1223}
1224//******************************************************************************
1225//TODO: Not complete (flags)
1226//******************************************************************************
1227SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1228{
1229 switch(nBar) {
1230 case SB_HORZ:
1231 if(horzScrollInfo) {
1232 //CB:horzScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndHorzScroll);
1233 return horzScrollInfo;
1234 }
1235 break;
1236 case SB_VERT:
1237 if(vertScrollInfo) {
1238 //CB:vertScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndVertScroll);
1239 return vertScrollInfo;
1240 }
1241 break;
1242 }
1243 return NULL;
1244}
1245/***********************************************************************/
1246/***********************************************************************/
1247VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1248{
1249 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1250}
1251/***********************************************************************
1252 * NC_HandleSysCommand
1253 *
1254 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1255 *
1256 * TODO: Not done (see #if 0)
1257 */
1258LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1259{
1260 UINT uCommand = wParam & 0xFFF0;
1261
1262 if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
1263 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1264
1265 switch (uCommand)
1266 {
1267#if 0
1268 case SC_SIZE:
1269 case SC_MOVE:
1270 NC_DoSizeMove( hwnd, wParam );
1271 break;
1272#endif
1273
1274 case SC_MINIMIZE:
1275 ShowWindow(SW_MINIMIZE);
1276 break;
1277
1278 case SC_MAXIMIZE:
1279 ShowWindow(SW_MAXIMIZE);
1280 break;
1281
1282 case SC_RESTORE:
1283 ShowWindow(SW_RESTORE);
1284 break;
1285
1286 case SC_CLOSE:
1287 return SendMessageA(WM_CLOSE, 0, 0);
1288
1289#if 0
1290 case SC_VSCROLL:
1291 case SC_HSCROLL:
1292 NC_TrackScrollBar( hwnd, wParam, pt32 );
1293 break;
1294
1295 case SC_MOUSEMENU:
1296 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1297 break;
1298
1299 case SC_KEYMENU:
1300 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1301 break;
1302
1303 case SC_TASKLIST:
1304 WinExec( "taskman.exe", SW_SHOWNORMAL );
1305 break;
1306
1307 case SC_SCREENSAVE:
1308 if (wParam == SC_ABOUTWINE)
1309 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1310 else
1311 if (wParam == SC_PUTMARK)
1312 dprintf(("Mark requested by user\n"));
1313 break;
1314
1315 case SC_HOTKEY:
1316 case SC_ARRANGE:
1317 case SC_NEXTWINDOW:
1318 case SC_PREVWINDOW:
1319 break;
1320#endif
1321 }
1322 return 0;
1323}
1324//******************************************************************************
1325//******************************************************************************
1326LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1327{
1328 //SvL: Set background color to default button color (not window (white))
1329 if(ctlType == CTLCOLOR_BTN)
1330 {
1331 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1332 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1333 return GetSysColorBrush(COLOR_BTNFACE);
1334 }
1335 //SvL: Set background color to default dialog color if window is dialog
1336 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1337 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1338 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1339 return GetSysColorBrush(COLOR_BTNFACE);
1340 }
1341
1342 if( ctlType == CTLCOLOR_SCROLLBAR)
1343 {
1344 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1345 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1346 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1347 SetBkColor( hdc, bk);
1348
1349//TODO?
1350#if 0
1351 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1352 * we better use 0x55aa bitmap brush to make scrollbar's background
1353 * look different from the window background.
1354 */
1355 if (bk == GetSysColor(COLOR_WINDOW)) {
1356 return CACHE_GetPattern55AABrush();
1357 }
1358#endif
1359 UnrealizeObject( hb );
1360 return (LRESULT)hb;
1361 }
1362
1363 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1364
1365 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1366 {
1367 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1368 }
1369 else
1370 {
1371 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1372 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1373 }
1374 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1375}
1376//******************************************************************************
1377//******************************************************************************
1378LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1379{
1380 switch(Msg)
1381 {
1382 case WM_CLOSE:
1383 DestroyWindow();
1384 return 0;
1385
1386 case WM_GETTEXTLENGTH:
1387 return wndNameLength;
1388
1389 case WM_GETTEXT: //TODO: SS_ICON controls
1390 strncpy((LPSTR)lParam, windowNameA, wParam);
1391 return min(wndNameLength, wParam);
1392
1393 case WM_SETTEXT:
1394 if(!fInternalMsg) {
1395 return SetWindowTextA((LPSTR)lParam);
1396 }
1397 else return 0;
1398
1399 case WM_SETREDRAW:
1400 if(wParam)
1401 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1402 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1403
1404 return 0; //TODO
1405
1406 case WM_NCCREATE:
1407 return(TRUE);
1408
1409 case WM_NCCALCSIZE:
1410 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1411
1412 case WM_CTLCOLORMSGBOX:
1413 case WM_CTLCOLOREDIT:
1414 case WM_CTLCOLORLISTBOX:
1415 case WM_CTLCOLORBTN:
1416 case WM_CTLCOLORDLG:
1417 case WM_CTLCOLORSTATIC:
1418 case WM_CTLCOLORSCROLLBAR:
1419 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1420
1421 case WM_CTLCOLOR:
1422 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1423
1424 case WM_VKEYTOITEM:
1425 case WM_CHARTOITEM:
1426 return -1;
1427
1428 case WM_PARENTNOTIFY:
1429 return 0;
1430
1431 case WM_MOUSEACTIVATE:
1432 {
1433 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1434 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1435 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1436 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1437 {
1438 if(getParent()) {
1439 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1440 if(rc) return rc;
1441 }
1442 }
1443 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1444 }
1445 case WM_SETCURSOR:
1446 {
1447 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1448 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1449 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1450 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1451 {
1452 if(getParent()) {
1453 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1454 if(rc) return rc;
1455 }
1456 }
1457 return 1;
1458 }
1459 case WM_MOUSEMOVE:
1460 return 1; //Let OS/2 change the mouse cursor back to the default
1461
1462 case WM_WINDOWPOSCHANGED:
1463 {
1464
1465/* undocumented SWP flags - from SDK 3.1 */
1466#define SWP_NOCLIENTSIZE 0x0800
1467#define SWP_NOCLIENTMOVE 0x1000
1468
1469 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1470 WPARAM wp = SIZE_RESTORED;
1471
1472 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1473 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1474
1475 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1476 {
1477 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1478 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1479
1480 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1481 rectClient.bottom - rectClient.top));
1482 }
1483 return 0;
1484 }
1485 case WM_WINDOWPOSCHANGING:
1486 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1487
1488 case WM_ERASEBKGND:
1489 case WM_ICONERASEBKGND:
1490 {
1491 RECT rect;
1492 int rc;
1493
1494 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1495
1496 rc = GetClipBox( (HDC)wParam, &rect );
1497 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1498 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1499
1500 return 1;
1501 }
1502 case WM_GETDLGCODE:
1503 return 0;
1504
1505 case WM_NCLBUTTONDOWN:
1506 case WM_NCLBUTTONUP:
1507 case WM_NCLBUTTONDBLCLK:
1508 case WM_NCRBUTTONUP:
1509 case WM_NCRBUTTONDOWN:
1510 case WM_NCRBUTTONDBLCLK:
1511 case WM_NCMBUTTONDOWN:
1512 case WM_NCMBUTTONUP:
1513 case WM_NCMBUTTONDBLCLK:
1514 return 0; //TODO: Send WM_SYSCOMMAND if required
1515
1516 case WM_NCHITTEST: //TODO: Calculate position of
1517 return HTCLIENT;
1518
1519 case WM_SYSCOMMAND:
1520 {
1521 POINT point;
1522
1523 point.x = LOWORD(lParam);
1524 point.y = HIWORD(lParam);
1525 return HandleSysCommand(wParam, &point);
1526 }
1527
1528 case WM_SYSKEYDOWN:
1529 if(HIWORD(lParam) & KEYDATA_ALT)
1530 {
1531 if(wParam == VK_F4) /* try to close the window */
1532 {
1533 Win32BaseWindow *window = GetTopParent();
1534 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE) )
1535 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1536 }
1537 }
1538 return 0;
1539
1540 case WM_QUERYOPEN:
1541 case WM_QUERYENDSESSION:
1542 return 1;
1543
1544 case WM_NOTIFYFORMAT:
1545 if (IsUnicode()) return NFR_UNICODE;
1546 else return NFR_ANSI;
1547
1548 case WM_SETICON:
1549 case WM_GETICON:
1550 {
1551 LRESULT result = 0;
1552 if (!windowClass) return result;
1553 int index = GCL_HICON;
1554
1555 if (wParam == ICON_SMALL)
1556 index = GCL_HICONSM;
1557
1558 result = windowClass->getClassLongA(index);
1559
1560 if (Msg == WM_SETICON)
1561 windowClass->setClassLongA(index, lParam);
1562
1563 return result;
1564 }
1565 case WM_NOTIFY:
1566 return 0; //comctl32 controls expect this
1567
1568 default:
1569 if(Msg > WM_USER) {
1570 return 0;
1571 }
1572 return 1;
1573 }
1574}
1575//******************************************************************************
1576//******************************************************************************
1577LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1578{
1579 switch(Msg)
1580 {
1581 case WM_GETTEXTLENGTH:
1582 return wndNameLength;
1583
1584 case WM_GETTEXT: //TODO: SS_ICON controls
1585 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1586 return min(wndNameLength, wParam);
1587
1588 case WM_SETTEXT:
1589 if(!fInternalMsg) {
1590 return SetWindowTextW((LPWSTR)lParam);
1591 }
1592 else return 0;
1593
1594 default:
1595 return DefWindowProcA(Msg, wParam, lParam);
1596 }
1597}
1598//******************************************************************************
1599//******************************************************************************
1600LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1601{
1602 LRESULT rc;
1603 BOOL fInternalMsgBackup = fInternalMsg;
1604
1605 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1606 // receive those before they get their WM_CREATE message
1607 //NOTE: May need to refuse more messages
1608 if(fCreated == FALSE && Msg == WM_COMMAND) {
1609 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1610 return 0;
1611 }
1612
1613 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
1614
1615 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1616 return(0);
1617 }
1618 fInternalMsg = FALSE;
1619 switch(Msg)
1620 {
1621 case WM_CREATE:
1622 {
1623 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1624 dprintf(("WM_CREATE returned -1\n"));
1625 rc = -1; //don't create window
1626 break;
1627 }
1628 NotifyParent(Msg, wParam, lParam);
1629
1630 rc = 0;
1631 break;
1632 }
1633 case WM_SETTEXT:
1634 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1635 break;
1636
1637 case WM_LBUTTONDOWN:
1638 case WM_MBUTTONDOWN:
1639 case WM_RBUTTONDOWN:
1640 NotifyParent(Msg, wParam, lParam);
1641 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1642 break;
1643
1644 case WM_DESTROY:
1645 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1646 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1647 break;
1648
1649 default:
1650 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1651 break;
1652 }
1653 fInternalMsg = fInternalMsgBackup;
1654 return rc;
1655}
1656//******************************************************************************
1657//******************************************************************************
1658LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1659{
1660 LRESULT rc;
1661 BOOL fInternalMsgBackup = fInternalMsg;
1662
1663 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1664 // receive those before they get their WM_CREATE message
1665 //NOTE: May need to refuse more messages
1666 if(fCreated == FALSE && Msg == WM_COMMAND) {
1667 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1668 return 0;
1669 }
1670
1671 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
1672
1673 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1674 return(0);
1675 }
1676 fInternalMsg = FALSE;
1677 switch(Msg)
1678 {
1679 case WM_CREATE:
1680 {
1681 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1682 dprintf(("WM_CREATE returned -1\n"));
1683 rc = -1; //don't create window
1684 break;
1685 }
1686 NotifyParent(Msg, wParam, lParam);
1687
1688 rc = 0;
1689 break;
1690 }
1691 case WM_SETTEXT:
1692 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1693 break;
1694
1695 case WM_LBUTTONDOWN:
1696 case WM_MBUTTONDOWN:
1697 case WM_RBUTTONDOWN:
1698 NotifyParent(Msg, wParam, lParam);
1699 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1700 break;
1701
1702 case WM_DESTROY:
1703 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1704 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1705 break;
1706
1707 default:
1708 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1709 break;
1710 }
1711 fInternalMsg = fInternalMsgBackup;
1712 return rc;
1713}
1714//******************************************************************************
1715//Called as a result of an OS/2 message
1716//******************************************************************************
1717LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1718{
1719 LRESULT rc;
1720 BOOL fInternalMsgBackup = fInternalMsg;
1721
1722 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1723
1724 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1725 return(0);
1726 }
1727 fInternalMsg = TRUE;
1728 switch(Msg)
1729 {
1730 case WM_CREATE:
1731 {
1732 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1733 dprintf(("WM_CREATE returned -1\n"));
1734 rc = -1; //don't create window
1735 break;
1736 }
1737 NotifyParent(Msg, wParam, lParam);
1738 rc = 0;
1739 break;
1740 }
1741 case WM_LBUTTONDOWN:
1742 case WM_MBUTTONDOWN:
1743 case WM_RBUTTONDOWN:
1744 NotifyParent(Msg, wParam, lParam);
1745 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1746 break;
1747
1748 case WM_DESTROY:
1749 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1750 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1751 break;
1752 default:
1753 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1754 break;
1755 }
1756 fInternalMsg = fInternalMsgBackup;
1757 return rc;
1758}
1759//******************************************************************************
1760//Called as a result of an OS/2 message
1761//todo, unicode msgs (WM_SETTEXT etc)
1762//******************************************************************************
1763LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1764{
1765 LRESULT rc;
1766 BOOL fInternalMsgBackup = fInternalMsg;
1767
1768 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1769
1770 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1771 return(0);
1772 }
1773 fInternalMsg = TRUE;
1774 switch(Msg)
1775 {
1776 case WM_CREATE:
1777 {
1778 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1779 dprintf(("WM_CREATE returned -1\n"));
1780 rc = -1; //don't create window
1781 break;
1782 }
1783 NotifyParent(Msg, wParam, lParam);
1784 rc = 0;
1785 break;
1786 }
1787 case WM_LBUTTONDOWN:
1788 case WM_MBUTTONDOWN:
1789 case WM_RBUTTONDOWN:
1790 NotifyParent(Msg, wParam, lParam);
1791 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1792 break;
1793
1794 case WM_DESTROY:
1795 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1796 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1797 break;
1798 default:
1799 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1800 break;
1801 }
1802 fInternalMsg = fInternalMsgBackup;
1803 return rc;
1804}
1805//******************************************************************************
1806//******************************************************************************
1807BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1808{
1809 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1810}
1811//******************************************************************************
1812//******************************************************************************
1813BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1814{
1815 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1816}
1817//******************************************************************************
1818//TODO: do we need to inform the parent of the parent (etc) of the child window?
1819//******************************************************************************
1820void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1821{
1822 Win32BaseWindow *window = this;
1823 Win32BaseWindow *parentwindow;
1824
1825 while(window)
1826 {
1827 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1828 {
1829 /* Notify the parent window only */
1830 parentwindow = window->getParent();
1831 if(parentwindow) {
1832 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1833 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1834 }
1835 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1836 }
1837 }
1838 else break;
1839
1840 window = parentwindow;
1841 }
1842}
1843//******************************************************************************
1844//******************************************************************************
1845Win32BaseWindow *Win32BaseWindow::getTopParent()
1846{
1847 Win32BaseWindow *tmpWnd = this;
1848
1849 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1850 {
1851 tmpWnd = tmpWnd->getParent();
1852 }
1853 return tmpWnd;
1854}
1855//******************************************************************************
1856//******************************************************************************
1857BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1858{
1859
1860 dprintf(("SetMenu %x", hMenu));
1861 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1862 if(OS2HwndMenu == 0) {
1863 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1864 return FALSE;
1865 }
1866 return TRUE;
1867}
1868//******************************************************************************
1869//******************************************************************************
1870BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1871{
1872 Win32Resource *winres = (Win32Resource *)hAccel;
1873 HANDLE accelhandle;
1874
1875 if(HIWORD(hAccel) == 0) {
1876 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1877 SetLastError(ERROR_INVALID_PARAMETER);
1878 return FALSE;
1879 }
1880 acceltableResource = winres;
1881 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1882 winres->setOS2Handle(accelhandle);
1883 return(accelhandle != 0);
1884}
1885//******************************************************************************
1886//******************************************************************************
1887BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1888{
1889 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1890 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1891 SendMessageA(WM_SETICON, hIcon, 0);
1892 return TRUE;
1893 }
1894 return FALSE;
1895}
1896//******************************************************************************
1897//******************************************************************************
1898BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1899{
1900 ULONG showstate = 0;
1901
1902 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
1903#if 1
1904 if (flags & WIN_NEED_SIZE)
1905 {
1906 /* should happen only in CreateWindowEx() */
1907 int wParam = SIZE_RESTORED;
1908
1909 flags &= ~WIN_NEED_SIZE;
1910 if (dwStyle & WS_MAXIMIZE)
1911 wParam = SIZE_MAXIMIZED;
1912 else
1913 if (dwStyle & WS_MINIMIZE)
1914 wParam = SIZE_MINIMIZED;
1915
1916 SendMessageA(WM_SIZE, wParam,
1917 MAKELONG(rectClient.right-rectClient.left,
1918 rectClient.bottom-rectClient.top));
1919 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1920 }
1921#else
1922 if(fFirstShow) {
1923 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
1924 SendMessageA(WM_SIZE, SIZE_RESTORED,
1925 MAKELONG(rectClient.right-rectClient.left,
1926 rectClient.bottom-rectClient.top));
1927 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1928
1929 }
1930 fFirstShow = FALSE;
1931 }
1932#endif
1933 switch(nCmdShow)
1934 {
1935 case SW_SHOW:
1936 case SW_SHOWDEFAULT: //todo
1937 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1938 break;
1939 case SW_HIDE:
1940 showstate = SWPOS_HIDE;
1941 break;
1942 case SW_RESTORE:
1943 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1944 break;
1945 case SW_MINIMIZE:
1946 showstate = SWPOS_MINIMIZE;
1947 break;
1948 case SW_SHOWMAXIMIZED:
1949 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1950 break;
1951 case SW_SHOWMINIMIZED:
1952 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1953 break;
1954 case SW_SHOWMINNOACTIVE:
1955 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1956 break;
1957 case SW_SHOWNA:
1958 showstate = SWPOS_SHOW;
1959 break;
1960 case SW_SHOWNOACTIVATE:
1961 showstate = SWPOS_SHOW;
1962 break;
1963 case SW_SHOWNORMAL:
1964 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1965 break;
1966 }
1967
1968 if(showstate & SWPOS_SHOW) {
1969 setStyle(getStyle() | WS_VISIBLE);
1970 }
1971 else setStyle(getStyle() & ~WS_VISIBLE);
1972
1973 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
1974 return rc;
1975}
1976//******************************************************************************
1977//******************************************************************************
1978BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1979{
1980 BOOL rc = FALSE;
1981 Win32BaseWindow *window;
1982 HWND hParent = 0;
1983
1984 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1985
1986 if (fuFlags &
1987 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1988 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1989 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1990 SWP_NOOWNERZORDER))
1991 {
1992 return FALSE;
1993 }
1994
1995 WINDOWPOS wpos;
1996 SWP swp, swpOld;
1997
1998 wpos.flags = fuFlags;
1999 wpos.cy = cy;
2000 wpos.cx = cx;
2001 wpos.x = x;
2002 wpos.y = y;
2003 wpos.hwndInsertAfter = hwndInsertAfter;
2004 wpos.hwnd = getWindowHandle();
2005
2006 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2007 {
2008 if (isChild())
2009 {
2010 hParent = getParent()->getOS2WindowHandle();
2011 }
2012 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2013 }
2014
2015 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2016 if (swp.fl == 0)
2017 return TRUE;
2018
2019// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2020 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2021 {
2022 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2023 if(wndBehind) {
2024 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2025 }
2026 else {
2027 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2028 swp.hwndInsertBehind = 0;
2029 }
2030 }
2031#if 0
2032 if (isFrameWindow())
2033 {
2034 if (!isChild())
2035 {
2036 POINT maxSize, maxPos, minTrack, maxTrack;
2037
2038 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2039
2040 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2041 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2042 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2043 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2044 }
2045 swp.hwnd = OS2HwndFrame;
2046 }
2047 else
2048#endif
2049 swp.hwnd = OS2HwndFrame;
2050
2051 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2052
2053 rc = OSLibWinSetMultWindowPos(&swp, 1);
2054
2055 if (rc == FALSE)
2056 {
2057 dprintf(("OSLibWinSetMultWindowPos failed!"));
2058 }
2059 else
2060 {
2061 if (fuFlags & SWP_FRAMECHANGED_W)
2062 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2063 }
2064
2065 return (rc);
2066}
2067//******************************************************************************
2068//TODO: WPF_RESTOREMAXIMIZED
2069//******************************************************************************
2070BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2071{
2072 if(isFrameWindow())
2073 {
2074 // Set the minimized position
2075 if (winpos->flags & WPF_SETMINPOSITION)
2076 {
2077 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2078 }
2079
2080 //TODO: Max position
2081
2082 // Set the new restore position.
2083 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2084 }
2085
2086 return ShowWindow(winpos->showCmd);
2087}
2088//******************************************************************************
2089//Also destroys all the child windows (destroy parent, destroy children)
2090//******************************************************************************
2091BOOL Win32BaseWindow::DestroyWindow()
2092{
2093 return OSLibWinDestroyWindow(OS2HwndFrame);
2094}
2095//******************************************************************************
2096//******************************************************************************
2097HWND Win32BaseWindow::GetParent()
2098{
2099 if(getParent()) {
2100 return getParent()->getWindowHandle();
2101 }
2102 else return 0;
2103}
2104//******************************************************************************
2105//******************************************************************************
2106HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2107{
2108 HWND oldhwnd;
2109 Win32BaseWindow *newparent;
2110
2111 if(getParent()) {
2112 oldhwnd = getParent()->getWindowHandle();
2113 getParent()->RemoveChild(this);
2114 }
2115 else oldhwnd = 0;
2116
2117 newparent = GetWindowFromHandle(hwndNewParent);
2118 if(newparent)
2119 {
2120 setParent(newparent);
2121 getParent()->AddChild(this);
2122 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2123 return oldhwnd;
2124 }
2125 SetLastError(ERROR_INVALID_PARAMETER);
2126 return 0;
2127}
2128//******************************************************************************
2129//******************************************************************************
2130BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2131{
2132 if(getParent()) {
2133 return getParent()->getWindowHandle() == hwndParent;
2134 }
2135 else return 0;
2136}
2137//******************************************************************************
2138//******************************************************************************
2139HWND Win32BaseWindow::GetTopWindow()
2140{
2141 return GetWindow(GW_CHILD);
2142}
2143//******************************************************************************
2144// Get the top-level parent for a child window.
2145//******************************************************************************
2146Win32BaseWindow *Win32BaseWindow::GetTopParent()
2147{
2148 Win32BaseWindow *window = this;
2149
2150 while(window && (window->getStyle() & WS_CHILD))
2151 {
2152 window = window->getParent();
2153 }
2154 return window;
2155}
2156//******************************************************************************
2157//Don't call WinUpdateWindow as that one also updates the child windows
2158//Also need to send WM_PAINT directly to the window procedure, which doesn't
2159//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2160//******************************************************************************
2161BOOL Win32BaseWindow::UpdateWindow()
2162{
2163 RECT rect;
2164
2165 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2166 {//update region not empty
2167 HDC hdc;
2168
2169 hdc = O32_GetDC(OS2Hwnd);
2170 if (isIcon)
2171 {
2172 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2173 SendMessageA(WM_PAINTICON, 0, 0);
2174 } else
2175 {
2176 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2177 SendMessageA(WM_PAINT, 0, 0);
2178 }
2179 O32_ReleaseDC(OS2Hwnd, hdc);
2180 }
2181 return TRUE;
2182}
2183//******************************************************************************
2184//******************************************************************************
2185BOOL Win32BaseWindow::IsIconic()
2186{
2187 return OSLibWinIsIconic(OS2Hwnd);
2188}
2189//******************************************************************************
2190//TODO: Should not enumerate children that are created during the enumeration!
2191//******************************************************************************
2192BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2193{
2194 BOOL rc = TRUE;
2195 HWND hwnd;
2196 Win32BaseWindow *prevchild = 0, *child = 0;
2197
2198 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2199 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2200 {
2201 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2202 hwnd = child->getWindowHandle();
2203 if(lpfn(hwnd, lParam) == FALSE)
2204 {
2205 rc = FALSE;
2206 break;
2207 }
2208 //check if the window still exists
2209 if(!::IsWindow(hwnd))
2210 {
2211 child = prevchild;
2212 continue;
2213 }
2214 if(child->getFirstChild() != NULL)
2215 {
2216 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2217 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2218 {
2219 rc = FALSE;
2220 break;
2221 }
2222 }
2223 prevchild = child;
2224 }
2225 return rc;
2226}
2227//******************************************************************************
2228//******************************************************************************
2229Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2230{
2231 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2232 {
2233 if (child->getWindowId() == id)
2234 {
2235 return child;
2236 }
2237 }
2238 return 0;
2239}
2240//******************************************************************************
2241//TODO:
2242//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2243//the current process owns them.
2244//******************************************************************************
2245HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2246 BOOL fUnicode)
2247{
2248 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2249 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2250
2251 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2252 (hwndChildAfter != 0 && !child) ||
2253 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2254 {
2255 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2256 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2257 return 0;
2258 }
2259 if(hwndParent != OSLIB_HWND_DESKTOP)
2260 {//if the current process owns the window, just do a quick search
2261 child = (Win32BaseWindow *)parent->getFirstChild();
2262 if(hwndChildAfter != 0)
2263 {
2264 while(child)
2265 {
2266 if(child->getWindowHandle() == hwndChildAfter)
2267 {
2268 child = (Win32BaseWindow *)child->getNextChild();
2269 break;
2270 }
2271 child = (Win32BaseWindow *)child->getNextChild();
2272 }
2273 }
2274 while(child)
2275 {
2276 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2277 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2278 {
2279 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2280 return child->getWindowHandle();
2281 }
2282 child = (Win32BaseWindow *)child->getNextChild();
2283 }
2284 }
2285 else {
2286 Win32BaseWindow *wnd;
2287 HWND henum, hwnd;
2288
2289 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2290 hwnd = OSLibWinGetNextWindow(henum);
2291
2292 while(hwnd)
2293 {
2294 wnd = GetWindowFromOS2Handle(hwnd);
2295 if(wnd == NULL) {
2296 hwnd = OSLibWinQueryClientWindow(hwnd);
2297 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2298 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2299 }
2300
2301 if(wnd) {
2302 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2303 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2304 {
2305 OSLibWinEndEnumWindows(henum);
2306 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2307 return wnd->getWindowHandle();
2308 }
2309 }
2310 hwnd = OSLibWinGetNextWindow(henum);
2311 }
2312 OSLibWinEndEnumWindows(henum);
2313 }
2314 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2315 return 0;
2316}
2317//******************************************************************************
2318//******************************************************************************
2319HWND Win32BaseWindow::GetWindow(UINT uCmd)
2320{
2321 HWND hwndRelated = 0;
2322 Win32BaseWindow *window;
2323
2324 switch(uCmd)
2325 {
2326 case GW_HWNDFIRST:
2327 if(getParent()) {
2328 window = (Win32BaseWindow *)getParent()->getFirstChild();
2329 hwndRelated = window->getWindowHandle();
2330 }
2331 break;
2332
2333 case GW_HWNDLAST:
2334 if(getParent())
2335 {
2336 goto end;
2337 }
2338
2339 window = this;
2340 while(window)
2341 {
2342 window = (Win32BaseWindow *)window->getNextChild();
2343 }
2344 hwndRelated = window->getWindowHandle();
2345 break;
2346
2347 case GW_HWNDNEXT:
2348 window = (Win32BaseWindow *)getNextChild();
2349 if(window) {
2350 hwndRelated = window->getWindowHandle();
2351 }
2352 break;
2353
2354 case GW_HWNDPREV:
2355 if(!getParent())
2356 {
2357 goto end;
2358 }
2359 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2360 if(window == this)
2361 {
2362 hwndRelated = 0; /* First in list */
2363 goto end;
2364 }
2365 while(window->getNextChild())
2366 {
2367 if (window->getNextChild() == this)
2368 {
2369 hwndRelated = window->getWindowHandle();
2370 goto end;
2371 }
2372 window = (Win32BaseWindow *)window->getNextChild();
2373 }
2374 break;
2375
2376 case GW_OWNER:
2377 if(getOwner()) {
2378 hwndRelated = getOwner()->getWindowHandle();
2379 }
2380 break;
2381
2382 case GW_CHILD:
2383 if(getFirstChild()) {
2384 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2385 }
2386 break;
2387 }
2388end:
2389 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2390 return hwndRelated;
2391}
2392//******************************************************************************
2393//******************************************************************************
2394HWND Win32BaseWindow::SetActiveWindow()
2395{
2396 return OSLibWinSetActiveWindow(OS2Hwnd);
2397}
2398//******************************************************************************
2399//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2400//******************************************************************************
2401BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2402{
2403 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
2404}
2405//******************************************************************************
2406//******************************************************************************
2407BOOL Win32BaseWindow::CloseWindow()
2408{
2409 return OSLibWinMinimizeWindow(OS2Hwnd);
2410}
2411//******************************************************************************
2412//******************************************************************************
2413HWND Win32BaseWindow::GetActiveWindow()
2414{
2415 HWND hwndActive;
2416 Win32BaseWindow *win32wnd;
2417 ULONG magic;
2418
2419 hwndActive = OSLibWinQueryActiveWindow();
2420
2421 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2422 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2423 if(CheckMagicDword(magic) && win32wnd)
2424 {
2425 return win32wnd->getWindowHandle();
2426 }
2427 return hwndActive;
2428}
2429//******************************************************************************
2430//******************************************************************************
2431BOOL Win32BaseWindow::IsWindowEnabled()
2432{
2433 return OSLibWinIsWindowEnabled(OS2Hwnd);
2434}
2435//******************************************************************************
2436//******************************************************************************
2437BOOL Win32BaseWindow::IsWindowVisible()
2438{
2439#if 1
2440 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2441#else
2442 return OSLibWinIsWindowVisible(OS2Hwnd);
2443#endif
2444}
2445//******************************************************************************
2446//******************************************************************************
2447BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2448{
2449 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2450}
2451//******************************************************************************
2452//******************************************************************************
2453BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2454{
2455 if(fUnicode) {
2456 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2457 }
2458 else return (strcmp(windowNameA, wndname) == 0);
2459}
2460//******************************************************************************
2461//******************************************************************************
2462int Win32BaseWindow::GetWindowTextLength()
2463{
2464 return wndNameLength;
2465}
2466//******************************************************************************
2467//******************************************************************************
2468int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2469{
2470 if(windowNameA == NULL) {
2471 *lpsz = 0;
2472 return 0;
2473 }
2474 strncpy(lpsz, windowNameA, cch);
2475 return wndNameLength;
2476}
2477//******************************************************************************
2478//******************************************************************************
2479int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2480{
2481 if(windowNameW == NULL) {
2482 *lpsz = 0;
2483 return 0;
2484 }
2485 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2486 return wndNameLength;
2487}
2488//******************************************************************************
2489//******************************************************************************
2490BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2491{
2492 if(lpsz == NULL)
2493 return FALSE;
2494
2495 if(windowNameA) free(windowNameA);
2496 if(windowNameW) free(windowNameW);
2497
2498 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2499 strcpy(windowNameA, lpsz);
2500 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2501 lstrcpyAtoW(windowNameW, windowNameA);
2502 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2503
2504 if(OS2HwndFrame)
2505 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2506
2507 return TRUE;
2508}
2509//******************************************************************************
2510//******************************************************************************
2511BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2512{
2513 if(lpsz == NULL)
2514 return FALSE;
2515
2516 if(windowNameA) free(windowNameA);
2517 if(windowNameW) free(windowNameW);
2518
2519 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2520 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2521 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2522 lstrcpyWtoA(windowNameA, windowNameW);
2523 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2524
2525 if(OS2HwndFrame)
2526 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2527
2528 return TRUE;
2529}
2530//******************************************************************************
2531//******************************************************************************
2532LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2533{
2534 LONG oldval;
2535
2536 switch(index) {
2537 case GWL_EXSTYLE:
2538 {
2539 STYLESTRUCT ss;
2540
2541 if(dwExStyle == value)
2542 return value;
2543
2544 ss.styleOld = dwExStyle;
2545 ss.styleNew = value;
2546 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2547 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2548 setExStyle(ss.styleNew);
2549 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2550 return ss.styleOld;
2551 }
2552 case GWL_STYLE:
2553 {
2554 STYLESTRUCT ss;
2555
2556 if(dwStyle == value)
2557 return value;
2558
2559 ss.styleOld = dwStyle;
2560 ss.styleNew = value;
2561 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), dwStyle, value));
2562 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2563 setStyle(ss.styleNew);
2564 if(!IsWindowDestroyed())
2565 OSLibSetWindowStyle(OS2HwndFrame, ss.styleNew);
2566 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2567 return ss.styleOld;
2568 }
2569 case GWL_WNDPROC:
2570 oldval = (LONG)getWindowProc();
2571 setWindowProc((WNDPROC)value);
2572 return oldval;
2573 case GWL_HINSTANCE:
2574 oldval = hInstance;
2575 hInstance = value;
2576 return oldval;
2577 case GWL_HWNDPARENT:
2578 return SetParent((HWND)value);
2579 case GWL_ID:
2580 oldval = getWindowId();
2581 setWindowId(value);
2582 return oldval;
2583 case GWL_USERDATA:
2584 oldval = userData;
2585 userData = value;
2586 return oldval;
2587 default:
2588 if(index >= 0 && index/4 < nrUserWindowLong)
2589 {
2590 oldval = userWindowLong[index/4];
2591 userWindowLong[index/4] = value;
2592 return oldval;
2593 }
2594 SetLastError(ERROR_INVALID_PARAMETER);
2595 return 0;
2596 }
2597}
2598//******************************************************************************
2599//******************************************************************************
2600ULONG Win32BaseWindow::GetWindowLongA(int index)
2601{
2602 switch(index) {
2603 case GWL_EXSTYLE:
2604 return dwExStyle;
2605 case GWL_STYLE:
2606 return dwStyle;
2607 case GWL_WNDPROC:
2608 return (ULONG)getWindowProc();
2609 case GWL_HINSTANCE:
2610 return hInstance;
2611 case GWL_HWNDPARENT:
2612 if(getParent()) {
2613 return getParent()->getWindowHandle();
2614 }
2615 else return 0;
2616 case GWL_ID:
2617 return getWindowId();
2618 case GWL_USERDATA:
2619 return userData;
2620 default:
2621 if(index >= 0 && index/4 < nrUserWindowLong)
2622 {
2623 return userWindowLong[index/4];
2624 }
2625 SetLastError(ERROR_INVALID_PARAMETER);
2626 return 0;
2627 }
2628}
2629//******************************************************************************
2630//******************************************************************************
2631WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2632{
2633 WORD oldval;
2634
2635 if(index >= 0 && index/4 < nrUserWindowLong)
2636 {
2637 oldval = ((WORD *)userWindowLong)[index/2];
2638 ((WORD *)userWindowLong)[index/2] = value;
2639 return oldval;
2640 }
2641 SetLastError(ERROR_INVALID_PARAMETER);
2642 return 0;
2643}
2644//******************************************************************************
2645//******************************************************************************
2646WORD Win32BaseWindow::GetWindowWord(int index)
2647{
2648 if(index >= 0 && index/4 < nrUserWindowLong)
2649 {
2650 return ((WORD *)userWindowLong)[index/2];
2651 }
2652 SetLastError(ERROR_INVALID_PARAMETER);
2653 return 0;
2654}
2655//******************************************************************************
2656//******************************************************************************
2657void Win32BaseWindow::setWindowId(DWORD id)
2658{
2659 windowId = id;
2660 OSLibSetWindowID(OS2HwndFrame, id);
2661}
2662//******************************************************************************
2663//******************************************************************************
2664Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2665{
2666 Win32BaseWindow *window;
2667
2668 if(hwnd == NULL && windowDesktop)
2669 return windowDesktop;
2670
2671 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2672 return window;
2673 }
2674 else return NULL;
2675}
2676//******************************************************************************
2677//******************************************************************************
2678Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2679{
2680 Win32BaseWindow *win32wnd;
2681 DWORD magic;
2682
2683 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2684 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2685
2686 if(win32wnd && CheckMagicDword(magic)) {
2687 return win32wnd;
2688 }
2689 return 0;
2690}
2691//******************************************************************************
2692//******************************************************************************
2693Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
2694{
2695 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
2696}
2697//******************************************************************************
2698//******************************************************************************
2699HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2700{
2701 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2702
2703 if(window) {
2704 return window->getOS2WindowHandle();
2705 }
2706 else return hwnd;
2707}
2708//******************************************************************************
2709//******************************************************************************
2710HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
2711{
2712 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2713
2714 if(window) {
2715 return window->getOS2FrameWindowHandle();
2716 }
2717 else return hwnd;
2718}
2719//******************************************************************************
2720//******************************************************************************
2721HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2722{
2723 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2724
2725 if(window) {
2726 return window->getWindowHandle();
2727 }
2728 window = GetWindowFromOS2FrameHandle(hwnd);
2729 if(window) {
2730 return window->getWindowHandle();
2731 }
2732 else return 0;
2733// else return hwnd; //OS/2 window handle
2734}
2735//******************************************************************************
2736//******************************************************************************
2737#ifdef DEBUG
2738void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
2739{
2740 char style[256] = "";
2741 char exstyle[256] = "";
2742
2743 /* Window styles */
2744 if(dwStyle & WS_CHILD)
2745 strcat(style, "WS_CHILD ");
2746 if(dwStyle & WS_POPUP)
2747 strcat(style, "WS_POPUP ");
2748 if(dwStyle & WS_VISIBLE)
2749 strcat(style, "WS_VISIBLE ");
2750 if(dwStyle & WS_DISABLED)
2751 strcat(style, "WS_DISABLED ");
2752 if(dwStyle & WS_CLIPSIBLINGS)
2753 strcat(style, "WS_CLIPSIBLINGS ");
2754 if(dwStyle & WS_CLIPCHILDREN)
2755 strcat(style, "WS_CLIPCHILDREN ");
2756 if(dwStyle & WS_MAXIMIZE)
2757 strcat(style, "WS_MAXIMIZE ");
2758 if(dwStyle & WS_MINIMIZE)
2759 strcat(style, "WS_MINIMIZE ");
2760 if(dwStyle & WS_GROUP)
2761 strcat(style, "WS_GROUP ");
2762 if(dwStyle & WS_TABSTOP)
2763 strcat(style, "WS_TABSTOP ");
2764
2765 if((dwStyle & WS_CAPTION) == WS_CAPTION)
2766 strcat(style, "WS_CAPTION ");
2767 if(dwStyle & WS_DLGFRAME)
2768 strcat(style, "WS_DLGFRAME ");
2769 if(dwStyle & WS_BORDER)
2770 strcat(style, "WS_BORDER ");
2771
2772 if(dwStyle & WS_VSCROLL)
2773 strcat(style, "WS_VSCROLL ");
2774 if(dwStyle & WS_HSCROLL)
2775 strcat(style, "WS_HSCROLL ");
2776 if(dwStyle & WS_SYSMENU)
2777 strcat(style, "WS_SYSMENU ");
2778 if(dwStyle & WS_THICKFRAME)
2779 strcat(style, "WS_THICKFRAME ");
2780 if(dwStyle & WS_MINIMIZEBOX)
2781 strcat(style, "WS_MINIMIZEBOX ");
2782 if(dwStyle & WS_MAXIMIZEBOX)
2783 strcat(style, "WS_MAXIMIZEBOX ");
2784
2785 if(dwExStyle & WS_EX_DLGMODALFRAME)
2786 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
2787 if(dwExStyle & WS_EX_ACCEPTFILES)
2788 strcat(exstyle, "WS_EX_ACCEPTFILES ");
2789 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
2790 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
2791 if(dwExStyle & WS_EX_TOPMOST)
2792 strcat(exstyle, "WS_EX_TOPMOST ");
2793 if(dwExStyle & WS_EX_TRANSPARENT)
2794 strcat(exstyle, "WS_EX_TRANSPARENT ");
2795
2796 if(dwExStyle & WS_EX_MDICHILD)
2797 strcat(exstyle, "WS_EX_MDICHILD ");
2798 if(dwExStyle & WS_EX_TOOLWINDOW)
2799 strcat(exstyle, "WS_EX_TOOLWINDOW ");
2800 if(dwExStyle & WS_EX_WINDOWEDGE)
2801 strcat(exstyle, "WS_EX_WINDOWEDGE ");
2802 if(dwExStyle & WS_EX_CLIENTEDGE)
2803 strcat(exstyle, "WS_EX_CLIENTEDGE ");
2804 if(dwExStyle & WS_EX_CONTEXTHELP)
2805 strcat(exstyle, "WS_EX_CONTEXTHELP ");
2806 if(dwExStyle & WS_EX_RIGHT)
2807 strcat(exstyle, "WS_EX_RIGHT ");
2808 if(dwExStyle & WS_EX_LEFT)
2809 strcat(exstyle, "WS_EX_LEFT ");
2810 if(dwExStyle & WS_EX_RTLREADING)
2811 strcat(exstyle, "WS_EX_RTLREADING ");
2812 if(dwExStyle & WS_EX_LTRREADING)
2813 strcat(exstyle, "WS_EX_LTRREADING ");
2814 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
2815 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
2816 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
2817 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
2818 if(dwExStyle & WS_EX_CONTROLPARENT)
2819 strcat(exstyle, "WS_EX_CONTROLPARENT ");
2820 if(dwExStyle & WS_EX_STATICEDGE)
2821 strcat(exstyle, "WS_EX_STATICEDGE ");
2822 if(dwExStyle & WS_EX_APPWINDOW)
2823 strcat(exstyle, "WS_EX_APPWINDOW ");
2824
2825 dprintf(("Window style: %x %s", dwStyle, style));
2826 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
2827}
2828#endif
2829//******************************************************************************
2830//******************************************************************************
2831
2832GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.