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

Last change on this file since 1333 was 1333, checked in by cbratschi, 26 years ago

added WINE scrollbars to frame, fixed pmframe, WM_ENTERIDLE

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