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

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

position change bugfixes

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