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

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

MDI fix + desktop as parent for main windows

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