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

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

frame bug fixes

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