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

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

Combobox + windowpos changes + fixes

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