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

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

Put back pos change messages in pmwindow.cpp, changed message logging

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