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

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

modal dialog fixes

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