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

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

wm_adjustwindowpos & combobox fixes

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