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

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

EB's unicode changes + seticon + mdi fixes

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