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

Last change on this file since 1511 was 1511, checked in by cbratschi, 26 years ago

scrollbar updates

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