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

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

Rene Pronk's WM_(SYS)KEYUP/DOWN changes + SvL's dialog changes

File size: 76.1 KB
Line 
1/* $Id: win32wbase.cpp,v 1.7 1999-09-22 08:58:35 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include <spy.h>
28#include "wndmsg.h"
29#include "hooks.h"
30#include "oslibwin.h"
31#include "oslibutil.h"
32#include "oslibgdi.h"
33#include "oslibres.h"
34#include "oslibmenu.h"
35#include "oslibdos.h"
36#include "syscolor.h"
37#include "win32wndhandle.h"
38#include "heapshared.h"
39#include "dc.h"
40
41#define HAS_DLGFRAME(style,exStyle) \
42 (((exStyle) & WS_EX_DLGMODALFRAME) || \
43 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
44
45#define HAS_THICKFRAME(style) \
46 (((style) & WS_THICKFRAME) && \
47 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
48
49#define HAS_BORDER(style, exStyle) \
50 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
51
52#define IS_OVERLAPPED(style) \
53 !(style & (WS_CHILD | WS_POPUP))
54
55//******************************************************************************
56//******************************************************************************
57Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
58{
59 Init();
60}
61//******************************************************************************
62//******************************************************************************
63Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
64 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
65{
66 Init();
67 this->isUnicode = isUnicode;
68 CreateWindowExA(lpCreateStructA, classAtom);
69}
70//******************************************************************************
71//******************************************************************************
72void Win32BaseWindow::Init()
73{
74 isUnicode = FALSE;
75 fCreated = FALSE;
76 fFirstShow = TRUE;
77 fIsDialog = FALSE;
78
79 windowNameA = NULL;
80 windowNameW = NULL;
81 wndNameLength = 0;
82
83 userWindowLong = NULL;;
84 nrUserWindowLong = 0;
85
86 magic = WIN32PM_MAGIC;
87 OS2Hwnd = 0;
88 OS2HwndFrame = 0;
89 OS2HwndMenu = 0;
90 Win32Hwnd = 0;
91
92 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
93 {
94 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
95 DebugInt3();
96 }
97
98 posx = posy = 0;
99 width = height = 0;
100
101 dwExStyle = 0;
102 dwStyle = 0;
103 win32wndproc = 0;
104 hInstance = 0;
105 windowId = 0xFFFFFFFF; //default = -1
106 userData = 0;
107
108 hwndLinkAfter = HWND_BOTTOM;
109 flags = 0;
110 isIcon = FALSE;
111 lastHitTestVal = 0;
112 owner = NULL;
113 windowClass = 0;
114
115 acceltableResource = NULL;
116 menuResource = NULL;
117 iconResource = NULL;
118
119 EraseBkgndFlag = TRUE;
120 PSEraseFlag = FALSE;
121 SupressEraseFlag = FALSE;
122}
123//******************************************************************************
124//todo get rid of resources (menu, accel, icon etc)
125//******************************************************************************
126Win32BaseWindow::~Win32BaseWindow()
127{
128 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
129 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
130
131 if (isOwnDC())
132 releaseOwnDC (ownDC);
133
134 if(Win32Hwnd)
135 HwFreeWindowHandle(Win32Hwnd);
136
137 if(userWindowLong)
138 free(userWindowLong);
139 if(windowNameA) {
140 free(windowNameA);
141 windowNameA = NULL;
142 }
143 if(windowNameW) {
144 free(windowNameW);
145 windowNameW = NULL;
146 }
147}
148//******************************************************************************
149//******************************************************************************
150BOOL Win32BaseWindow::isChild()
151{
152 return (dwStyle & WS_CHILD) != 0;
153}
154//******************************************************************************
155//******************************************************************************
156BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
157{
158 char buffer[256];
159 INT sw = SW_SHOW;
160 POINT maxSize, maxPos, minTrack, maxTrack;
161
162 SetLastError(0);
163
164 /* Find the parent window */
165 if (cs->hwndParent)
166 {
167 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
168 if(!window) {
169 dprintf(("Bad parent %04x\n", cs->hwndParent ));
170 SetLastError(ERROR_INVALID_PARAMETER);
171 return FALSE;
172 }
173 /* Make sure parent is valid */
174 if (!window->IsWindow() )
175 {
176 dprintf(("Bad parent %04x\n", cs->hwndParent ));
177 SetLastError(ERROR_INVALID_PARAMETER);
178 return FALSE;
179 }
180 }
181 else
182 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
183 dprintf(("No parent for child window\n" ));
184 SetLastError(ERROR_INVALID_PARAMETER);
185 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
186 }
187
188 /* Find the window class */
189 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
190 if (!windowClass)
191 {
192 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
193 dprintf(("Bad class '%s'\n", buffer ));
194 return 0;
195 }
196
197 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
198 * with an atom as the class name, put some programs expect to have a *REAL* string in
199 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
200 */
201 if (!HIWORD(cs->lpszClass) ) {
202 if (isUnicode) {
203 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
204 }
205 else {
206 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
207 }
208 cs->lpszClass = buffer;
209 }
210
211 /* Fix the coordinates */
212 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
213 {
214// PDB *pdb = PROCESS_Current();
215
216 /* Never believe Microsoft's documentation... CreateWindowEx doc says
217 * that if an overlapped window is created with WS_VISIBLE style bit
218 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
219 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
220 * reveals that
221 *
222 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
223 * 2) it does not ignore the y parameter as the docs claim; instead, it
224 * uses it as second parameter to ShowWindow() unless y is either
225 * CW_USEDEFAULT or CW_USEDEFAULT16.
226 *
227 * The fact that we didn't do 2) caused bogus windows pop up when wine
228 * was running apps that were using this obscure feature. Example -
229 * calc.exe that comes with Win98 (only Win98, it's different from
230 * the one that comes with Win95 and NT)
231 */
232 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
233
234 /* We have saved cs->y, now we can trash it */
235#if 0
236 if ( !(cs->style & (WS_CHILD | WS_POPUP))
237 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
238 {
239 cs->x = pdb->env_db->startup_info->dwX;
240 cs->y = pdb->env_db->startup_info->dwY;
241 }
242#endif
243 cs->x = 0;
244 cs->y = 0;
245// }
246 }
247 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
248 {
249#if 0
250 PDB *pdb = PROCESS_Current();
251 if ( !(cs->style & (WS_CHILD | WS_POPUP))
252 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
253 {
254 cs->cx = pdb->env_db->startup_info->dwXSize;
255 cs->cy = pdb->env_db->startup_info->dwYSize;
256 }
257 else
258 {
259#endif
260 cs->cx = 600; /* FIXME */
261 cs->cy = 400;
262// }
263 }
264
265 if (cs->x < 0) cs->x = 0;
266 if (cs->y < 0) cs->y = 0;
267
268 //Allocate window words
269 nrUserWindowLong = windowClass->getExtraWndWords();
270 if(nrUserWindowLong) {
271 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
272 memset(userWindowLong, 0, nrUserWindowLong);
273 }
274
275 if ((cs->style & WS_CHILD) && cs->hwndParent)
276 {
277 SetParent(cs->hwndParent);
278 owner = GetWindowFromHandle(cs->hwndParent);
279 if(owner == NULL)
280 {
281 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
282 return FALSE;
283 }
284 }
285 else
286 {
287 if (!cs->hwndParent) {
288 owner = NULL;
289 }
290 else
291 {
292 owner = GetWindowFromHandle(cs->hwndParent);
293 if(owner == NULL)
294 {
295 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
296 return FALSE;
297 }
298 }
299 }
300
301 setWindowProc(windowClass->getWindowProc());
302 hInstance = cs->hInstance;
303 dwStyle = cs->style & ~WS_VISIBLE;
304 dwExStyle = cs->dwExStyle;
305
306 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
307 ? HWND_BOTTOM : HWND_TOP;
308
309#if 0
310//TODO
311 /* Call the WH_CBT hook */
312
313 if (HOOK_IsHooked( WH_CBT ))
314 {
315 CBT_CREATEWNDA cbtc;
316 LRESULT ret;
317
318 cbtc.lpcs = cs;
319 cbtc.hwndInsertAfter = hwndLinkAfter;
320 ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
321 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
322 if (ret)
323 {
324 TRACE_(win)("CBT-hook returned 0\n");
325 wndPtr->pDriver->pFinalize(wndPtr);
326 retvalue = 0;
327 goto end;
328 }
329 }
330#endif
331
332 /* Increment class window counter */
333 windowClass->IncreaseWindowCount();
334
335 /* Correct the window style */
336 if (!(cs->style & WS_CHILD))
337 {
338 dwStyle |= WS_CLIPSIBLINGS;
339 if (!(cs->style & WS_POPUP))
340 {
341 dwStyle |= WS_CAPTION;
342 flags |= WIN_NEED_SIZE;
343 }
344 }
345 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
346
347 //TODO?
348#if 0
349 /* Get class or window DC if needed */
350 if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
351 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
352 else wndPtr->dce = NULL;
353#endif
354
355 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
356 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
357 {
358 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
359 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
360 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
361 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
362 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
363 }
364
365 if(cs->style & WS_CHILD)
366 {
367 if(cs->cx < 0) cs->cx = 0;
368 if(cs->cy < 0) cs->cy = 0;
369 }
370 else
371 {
372 if (cs->cx <= 0) cs->cx = 1;
373 if (cs->cy <= 0) cs->cy = 1;
374 }
375
376 rectWindow.left = cs->x;
377 rectWindow.top = cs->y;
378 rectWindow.right = cs->x + cs->cx;
379 rectWindow.bottom = cs->y + cs->cy;
380 rectClient = rectWindow;
381
382 DWORD dwOSWinStyle, dwOSFrameStyle;
383
384 OSLibWinConvertStyle(cs->style, cs->dwExStyle, &dwOSWinStyle, &dwOSFrameStyle);
385
386 //TODO: Test
387#if 1
388 if(cs->style & WS_CHILD) {
389 dwOSFrameStyle = 0;
390 }
391#endif
392
393 if(cs->lpszName)
394 {
395 if(isUnicode)
396 SetWindowTextW((LPWSTR)cs->lpszName);
397 else SetWindowTextA((LPSTR)cs->lpszName);
398 }
399
400 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
401 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
402 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
403 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
404 &OS2HwndFrame);
405
406 if(OS2Hwnd == 0) {
407 dprintf(("Window creation failed!!"));
408 return FALSE;
409 }
410
411 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
412 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
413 return FALSE;
414 }
415 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
416 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
417 return FALSE;
418 }
419 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
420 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
421 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
422 return FALSE;
423 }
424#if 0
425 if(OS2Hwnd != OS2HwndFrame) {
426 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
427 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
428 return FALSE;
429 }
430 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
431 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
432 return FALSE;
433 }
434 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
435 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
436 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
437 return FALSE;
438 }
439 }
440#endif
441
442 fakeWinBase.hwndThis = OS2Hwnd;
443 fakeWinBase.pWindowClass = windowClass;
444// SetFakeOpen32();
445
446 /* Set the window menu */
447 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
448 {
449 if (cs->hMenu) SetMenu(cs->hMenu);
450 else
451 {
452 if (windowClass->getMenuNameA()) {
453 cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
454 if (cs->hMenu) SetMenu(cs->hMenu );
455 }
456 }
457 }
458 else windowId = (UINT)cs->hMenu;
459
460 //Set icon from class
461 if(windowClass->getIcon())
462 SetIcon(windowClass->getIcon());
463
464 if(getParent()) {
465 SetWindowPos(getParent()->getWindowHandle(), rectClient.left, rectClient.top,
466 rectClient.right-rectClient.left,
467 rectClient.bottom-rectClient.top,
468 SWP_NOACTIVATE | SWP_NOZORDER);
469 }
470 else {
471 SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
472 rectClient.right-rectClient.left,
473 rectClient.bottom-rectClient.top,
474 SWP_NOACTIVATE);
475 }
476 //Get the client window rectangle
477 GetClientRect(Win32Hwnd, &rectClient);
478
479 /* Send the WM_CREATE message
480 * Perhaps we shouldn't allow width/height changes as well.
481 * See p327 in "Internals".
482 */
483 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
484
485 fCreated = TRUE; //Allow WM_SIZE messages now
486 if(SendInternalMessage(WM_NCCREATE, 0, (LPARAM)cs) )
487 {
488 //doesn't work right, messes up client rectangle
489#if 0
490 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
491#endif
492 OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
493 dprintf(("Sending WM_CREATE"));
494 if( (SendInternalMessage(WM_CREATE, 0, (LPARAM)cs )) != -1 )
495 {
496 if(!(flags & WIN_NEED_SIZE)) {
497 SendMessageA(WM_SIZE, SIZE_RESTORED,
498 MAKELONG(rectClient.right-rectClient.left,
499 rectClient.bottom-rectClient.top));
500 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
501 }
502 if (cs->style & WS_VISIBLE) ShowWindow( sw );
503
504#if 0
505 /* Call WH_SHELL hook */
506
507 if (!(dwStyle & WS_CHILD) && !owner)
508 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
509#endif
510 SetLastError(0);
511 return TRUE;
512 }
513 }
514 fCreated = FALSE;
515 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
516 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
517 DestroyWindow();
518 return FALSE;
519}
520#if 0
521/***********************************************************************
522 * WINPOS_MinMaximize
523 *
524 * Fill in lpRect and return additional flags to be used with SetWindowPos().
525 * This function assumes that 'cmd' is different from the current window
526 * state.
527 */
528UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect )
529{
530 UINT swpFlags = 0;
531 POINT pt, size;
532 LPINTERNALPOS lpPos;
533
534 size.x = rectWindow.left; size.y = rectWindow.top;
535 lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
536
537 if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
538 {
539 if( dwStyle & WS_MINIMIZE )
540 {
541 if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
542 return (SWP_NOSIZE | SWP_NOMOVE);
543 swpFlags |= SWP_NOCOPYBITS;
544 }
545 switch( cmd )
546 {
547 case SW_MINIMIZE:
548 if( dwStyle & WS_MAXIMIZE)
549 {
550 flags |= WIN_RESTORE_MAX;
551 dwStyle &= ~WS_MAXIMIZE;
552 }
553 else
554 flags &= ~WIN_RESTORE_MAX;
555 dwStyle |= WS_MINIMIZE;
556
557#if 0
558 if( flags & WIN_NATIVE )
559 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
560 swpFlags |= MINMAX_NOSWP;
561#endif
562
563 lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
564
565 SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
566 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
567 swpFlags |= SWP_NOCOPYBITS;
568 break;
569
570 case SW_MAXIMIZE:
571 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
572
573 if( dwStyle & WS_MINIMIZE )
574 {
575 if( flags & WIN_NATIVE )
576 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
577 swpFlags |= MINMAX_NOSWP;
578
579 WINPOS_ShowIconTitle( wndPtr, FALSE );
580 dwStyle &= ~WS_MINIMIZE;
581 }
582 dwStyle |= WS_MAXIMIZE;
583
584 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
585 size.x, size.y );
586 break;
587
588 case SW_RESTORE:
589 if( dwStyle & WS_MINIMIZE )
590 {
591 if( flags & WIN_NATIVE )
592 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
593 swpFlags |= MINMAX_NOSWP;
594
595 dwStyle &= ~WS_MINIMIZE;
596 WINPOS_ShowIconTitle( wndPtr, FALSE );
597
598 if( flags & WIN_RESTORE_MAX)
599 {
600 /* Restore to maximized position */
601 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
602 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
603 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
604 dwStyle |= WS_MAXIMIZE;
605 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
606 break;
607 }
608 }
609 else
610 if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
611 else dwStyle &= ~WS_MAXIMIZE;
612
613 /* Restore to normal position */
614
615 *lpRect = lpPos->rectNormal;
616 lpRect->right -= lpRect->left;
617 lpRect->bottom -= lpRect->top;
618
619 break;
620 }
621 } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
622 return swpFlags;
623}
624#endif
625/*******************************************************************
626 * GetMinMaxInfo
627 *
628 * Get the minimized and maximized information for a window.
629 */
630void Win32BaseWindow::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
631 POINT *minTrack, POINT *maxTrack )
632{
633 MINMAXINFO MinMax;
634 INT xinc, yinc;
635
636 /* Compute default values */
637
638 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
639 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
640 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
641 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
642 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
643 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
644
645 if (flags & WIN_MANAGED) xinc = yinc = 0;
646 else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
647 {
648 xinc = GetSystemMetrics(SM_CXDLGFRAME);
649 yinc = GetSystemMetrics(SM_CYDLGFRAME);
650 }
651 else
652 {
653 xinc = yinc = 0;
654 if (HAS_THICKFRAME(dwStyle))
655 {
656 xinc += GetSystemMetrics(SM_CXFRAME);
657 yinc += GetSystemMetrics(SM_CYFRAME);
658 }
659 if (dwStyle & WS_BORDER)
660 {
661 xinc += GetSystemMetrics(SM_CXBORDER);
662 yinc += GetSystemMetrics(SM_CYBORDER);
663 }
664 }
665 MinMax.ptMaxSize.x += 2 * xinc;
666 MinMax.ptMaxSize.y += 2 * yinc;
667
668#if 0
669 lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
670 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
671 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
672 else
673 {
674#endif
675 MinMax.ptMaxPosition.x = -xinc;
676 MinMax.ptMaxPosition.y = -yinc;
677// }
678
679 SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
680
681 /* Some sanity checks */
682
683 dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
684 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
685 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
686 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
687 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
688 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
689 MinMax.ptMinTrackSize.x );
690 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
691 MinMax.ptMinTrackSize.y );
692
693 if (maxSize) *maxSize = MinMax.ptMaxSize;
694 if (maxPos) *maxPos = MinMax.ptMaxPosition;
695 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
696 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
697}
698/***********************************************************************
699 * WINPOS_SendNCCalcSize
700 *
701 * Send a WM_NCCALCSIZE message to a window.
702 * All parameters are read-only except newClientRect.
703 * oldWindowRect, oldClientRect and winpos must be non-NULL only
704 * when calcValidRect is TRUE.
705 */
706LONG Win32BaseWindow::SendNCCalcSize(BOOL calcValidRect, RECT *newWindowRect, RECT *oldWindowRect,
707 RECT *oldClientRect, WINDOWPOS *winpos,
708 RECT *newClientRect )
709{
710 NCCALCSIZE_PARAMS params;
711 WINDOWPOS winposCopy;
712 LONG result;
713
714 params.rgrc[0] = *newWindowRect;
715 if (calcValidRect)
716 {
717 winposCopy = *winpos;
718 params.rgrc[1] = *oldWindowRect;
719 params.rgrc[2] = *oldClientRect;
720 params.lppos = &winposCopy;
721 }
722 result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
723 (LPARAM)&params );
724 *newClientRect = params.rgrc[0];
725 return result;
726}
727//******************************************************************************
728//******************************************************************************
729ULONG Win32BaseWindow::MsgCreate(HWND hwndOS2, ULONG initParam)
730{
731 OS2Hwnd = hwndOS2;
732 return SendInternalMessageA(WM_CREATE, 0, initParam);
733}
734//******************************************************************************
735//******************************************************************************
736ULONG Win32BaseWindow::MsgQuit()
737{
738 return SendInternalMessageA(WM_QUIT, 0, 0);
739}
740//******************************************************************************
741//******************************************************************************
742ULONG Win32BaseWindow::MsgClose()
743{
744 if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
745 return 0; //app handles this message
746 }
747 delete this;
748 return 1;
749}
750//******************************************************************************
751//******************************************************************************
752ULONG Win32BaseWindow::MsgDestroy()
753{
754 ULONG rc;
755
756 rc = SendInternalMessageA(WM_DESTROY, 0, 0);
757 delete this;
758 return rc;
759}
760//******************************************************************************
761//******************************************************************************
762ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
763{
764 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
765}
766//******************************************************************************
767//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
768//******************************************************************************
769ULONG Win32BaseWindow::MsgShow(BOOL fShow)
770{
771 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
772}
773//******************************************************************************
774//******************************************************************************
775ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
776{
777 dprintf(("MsgPosChanging"));
778#if 1
779 if(fCreated == FALSE) {
780 return 1;
781 }
782#endif
783 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
784}
785//******************************************************************************
786//******************************************************************************
787ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
788{
789 dprintf(("MsgPosChanged"));
790#if 1
791 if(fCreated == FALSE) {
792 return 1;
793 }
794#endif
795 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
796}
797//******************************************************************************
798//******************************************************************************
799ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
800{
801 dprintf(("MsgMove to (%d,%d)", x, y));
802 if(fCreated == FALSE) {
803 return 1;
804 }
805
806 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
807}
808//******************************************************************************
809//******************************************************************************
810ULONG Win32BaseWindow::MsgTimer(ULONG TimerID)
811{
812 // TODO: call TIMERPROC if not NULL
813 return SendInternalMessageA(WM_TIMER, TimerID, 0);
814}
815//******************************************************************************
816//******************************************************************************
817ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
818{
819 switch(cmd) {
820 case CMD_MENU:
821 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
822 case CMD_CONTROL:
823 return 0; //todo
824 case CMD_ACCELERATOR:
825 dprintf(("accelerator command"));
826 return 0; //todo
827 }
828 return 0;
829}
830//******************************************************************************
831//******************************************************************************
832ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
833{
834 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
835 return 1; //TODO: May need to change this
836}
837//******************************************************************************
838//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
839//******************************************************************************
840ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
841{
842 WORD fwSizeType = 0;
843
844 if(fCreated == FALSE) {//Solitaire crashes if it receives a WM_SIZE during CreateWindowEx (normal or our fault?)
845 return 1;
846 }
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, HWND hwnd)
862{
863 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE)
864 {
865 if(!fActivate) {
866 return 1;
867 }
868 }
869 return SendInternalMessageA(WM_ACTIVATE, (fActivate) ? WA_ACTIVE : WA_INACTIVE, hwnd);
870}
871//******************************************************************************
872//******************************************************************************
873ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
874{
875 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
876}
877//******************************************************************************
878//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
879//******************************************************************************
880ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
881{
882 ULONG lParam = 0;
883
884 lParam = repeatcnt;
885 lParam |= (scancode << 16);
886 if(keyflags & KEY_ALTDOWN)
887 lParam |= (1<<29);
888 if(keyflags & KEY_PREVDOWN)
889 lParam |= (1<<30);
890 if(keyflags & KEY_UP)
891 lParam |= (1<<31);
892 if(keyflags & KEY_DEADKEY) {
893 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
894 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
895 }
896 else {
897 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
898 return SendInternalMessageA(WM_CHAR, cmd, lParam);
899 }
900}
901//******************************************************************************
902//******************************************************************************
903ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
904{
905 ULONG lParam=0;
906
907 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
908 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
909 // bit 24, 1=extended key
910 // bit 25-28, reserved
911 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
912 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
913 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
914
915 dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
916
917 return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
918}
919//******************************************************************************
920//******************************************************************************
921ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
922{
923 ULONG lParam=0;
924
925 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
926 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
927 // bit 24, 1=extended key
928 // bit 25-28, reserved
929 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
930 if (keyWasPressed)
931 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
932 // bit 31, transition state, always 0 for WM_KEYDOWN
933
934 dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
935
936 return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
937}
938//******************************************************************************
939//******************************************************************************
940ULONG Win32BaseWindow::MsgSysKeyUp (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_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
953
954 return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
955}
956//******************************************************************************
957//******************************************************************************
958ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
959{
960 ULONG lParam=0;
961
962 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
963 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
964 // bit 24, 1=extended key
965 // bit 25-28, reserved
966 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
967 if (keyWasPressed)
968 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
969 // bit 31, transition state, always 0 for WM_KEYDOWN
970
971 dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
972
973 return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
974}
975//******************************************************************************
976//******************************************************************************
977ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
978{
979 if(hwnd == 0) {
980 //other app lost focus
981 SendInternalMessageA(WM_ACTIVATEAPP, TRUE, 0); //TODO: Need thread id from hwnd app
982 }
983 return SendInternalMessageA(WM_SETFOCUS, OS2ToWin32Handle (hwnd), 0);
984}
985//******************************************************************************
986//******************************************************************************
987ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
988{
989 if(hwnd == 0) {
990 //other app lost focus
991 SendInternalMessageA(WM_ACTIVATEAPP, FALSE, 0); //TODO: Need thread id from hwnd app
992 }
993 return SendInternalMessageA(WM_KILLFOCUS, OS2ToWin32Handle (hwnd), 0);
994}
995//******************************************************************************
996//******************************************************************************
997//******************************************************************************
998ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
999{
1000 ULONG win32msg;
1001 ULONG win32ncmsg;
1002
1003 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1004 switch(msg) {
1005 case BUTTON_LEFTDOWN:
1006 win32msg = WM_LBUTTONDOWN;
1007 win32ncmsg = WM_NCLBUTTONDOWN;
1008 break;
1009 case BUTTON_LEFTUP:
1010 win32msg = WM_LBUTTONUP;
1011 win32ncmsg = WM_NCLBUTTONUP;
1012 break;
1013 case BUTTON_LEFTDBLCLICK:
1014 win32msg = WM_LBUTTONDBLCLK;
1015 win32ncmsg = WM_NCLBUTTONDBLCLK;
1016 break;
1017 case BUTTON_RIGHTUP:
1018 win32msg = WM_RBUTTONUP;
1019 win32ncmsg = WM_NCRBUTTONUP;
1020 break;
1021 case BUTTON_RIGHTDOWN:
1022 win32msg = WM_RBUTTONDOWN;
1023 win32ncmsg = WM_NCRBUTTONDOWN;
1024 break;
1025 case BUTTON_RIGHTDBLCLICK:
1026 win32msg = WM_RBUTTONDBLCLK;
1027 win32ncmsg = WM_NCRBUTTONDBLCLK;
1028 break;
1029 case BUTTON_MIDDLEUP:
1030 win32msg = WM_MBUTTONUP;
1031 win32ncmsg = WM_NCMBUTTONUP;
1032 break;
1033 case BUTTON_MIDDLEDOWN:
1034 win32msg = WM_MBUTTONDOWN;
1035 win32ncmsg = WM_NCMBUTTONDOWN;
1036 break;
1037 case BUTTON_MIDDLEDBLCLICK:
1038 win32msg = WM_MBUTTONDBLCLK;
1039 win32ncmsg = WM_NCMBUTTONDBLCLK;
1040 break;
1041 default:
1042 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1043 return 1;
1044 }
1045 if(win32msg == WM_MBUTTONDBLCLK || win32msg == WM_RBUTTONDBLCLK || win32msg == WM_LBUTTONDBLCLK) {
1046 if(!(windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)) {
1047 return 1;
1048 }
1049 }
1050 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1051
1052 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1053 if(lastHitTestVal != HTCLIENT) {
1054 SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1055 }
1056 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1057}
1058//******************************************************************************
1059//******************************************************************************
1060ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1061{
1062 ULONG winstate = 0;
1063 ULONG setcursormsg = WM_MOUSEMOVE;
1064
1065 if(keystate & WMMOVE_LBUTTON)
1066 winstate |= MK_LBUTTON;
1067 if(keystate & WMMOVE_RBUTTON)
1068 winstate |= MK_RBUTTON;
1069 if(keystate & WMMOVE_MBUTTON)
1070 winstate |= MK_MBUTTON;
1071 if(keystate & WMMOVE_SHIFT)
1072 winstate |= MK_SHIFT;
1073 if(keystate & WMMOVE_CTRL)
1074 winstate |= MK_CONTROL;
1075
1076 if(lastHitTestVal != HTCLIENT) {
1077 setcursormsg = WM_NCMOUSEMOVE;
1078 }
1079 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1080 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1081
1082 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1083 if(lastHitTestVal != HTCLIENT) {
1084 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1085 }
1086 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1087}
1088//******************************************************************************
1089//******************************************************************************
1090ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1091{
1092 if (select && isIcon)
1093 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1094 else
1095 return SendInternalMessageA(WM_PAINT, 0, 0);
1096}
1097//******************************************************************************
1098//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1099// (or are we simply erasing too much here)
1100//******************************************************************************
1101ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1102{
1103 ULONG rc;
1104 HDC hdcErase = hdc;
1105
1106 if (hdcErase == 0)
1107 hdcErase = O32_GetDC(OS2Hwnd);
1108
1109 if(isIcon)
1110 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1111 else
1112 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1113 if (hdc == 0)
1114 O32_ReleaseDC(OS2Hwnd, hdcErase);
1115 return (rc);
1116}
1117//******************************************************************************
1118//******************************************************************************
1119ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1120{
1121 if(isUnicode) {
1122 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1123 }
1124 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1125}
1126//******************************************************************************
1127//TODO: in- or excluding terminating 0?
1128//******************************************************************************
1129ULONG Win32BaseWindow::MsgGetTextLength()
1130{
1131 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1132}
1133//******************************************************************************
1134//******************************************************************************
1135char *Win32BaseWindow::MsgGetText()
1136{
1137 if(isUnicode) {
1138 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1139 }
1140 else {
1141 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1142 }
1143 return windowNameA;
1144}
1145//******************************************************************************
1146//******************************************************************************
1147LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1148{
1149 switch(Msg)
1150 {
1151 case WM_GETTEXTLENGTH:
1152 return wndNameLength;
1153
1154 case WM_GETTEXT: //TODO: SS_ICON controls
1155 strncpy((LPSTR)lParam, windowNameA, wParam);
1156 return min(wndNameLength, wParam);
1157
1158 case WM_SETTEXT:
1159 return 0;
1160
1161 case WM_SETREDRAW:
1162 if(wParam)
1163 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1164 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1165
1166 return 0; //TODO
1167
1168 case WM_NCCREATE:
1169 return(TRUE);
1170
1171 //SvL: Set background color to default button color (not window (white))
1172 case WM_CTLCOLORBTN:
1173 SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
1174 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1175 return GetSysColorBrush(COLOR_BTNFACE);
1176
1177 //SvL: Set background color to default dialog color if window is dialog
1178 case WM_CTLCOLORDLG:
1179 case WM_CTLCOLORSTATIC:
1180 if(IsDialog()) {
1181 SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
1182 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1183 return GetSysColorBrush(COLOR_BTNFACE);
1184 }
1185 //no break
1186
1187 case WM_CTLCOLORMSGBOX:
1188 case WM_CTLCOLOREDIT:
1189 case WM_CTLCOLORLISTBOX:
1190 case WM_CTLCOLORSCROLLBAR:
1191 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1192 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1193 return GetSysColorBrush(COLOR_BTNFACE);
1194
1195 case WM_PARENTNOTIFY:
1196 return 0;
1197
1198 case WM_MOUSEACTIVATE:
1199 {
1200 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1201 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1202 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1203 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1204 {
1205 if(getParent()) {
1206 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1207 if(rc) return rc;
1208 }
1209 }
1210 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1211 }
1212 case WM_SETCURSOR:
1213 {
1214 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1215 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1216 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1217 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1218 {
1219 if(getParent()) {
1220 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1221 if(rc) return rc;
1222 }
1223 }
1224 return 1;
1225 }
1226 case WM_MOUSEMOVE:
1227 return 0;
1228
1229 case WM_WINDOWPOSCHANGED:
1230 {
1231
1232/* undocumented SWP flags - from SDK 3.1 */
1233#define SWP_NOCLIENTSIZE 0x0800
1234#define SWP_NOCLIENTMOVE 0x1000
1235
1236 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1237 WPARAM wp = SIZE_RESTORED;
1238
1239 if (!(wpos->flags & SWP_NOCLIENTMOVE))
1240 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1241
1242 if (!(wpos->flags & SWP_NOCLIENTSIZE))
1243 {
1244 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1245 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1246
1247 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1248 rectClient.bottom - rectClient.top));
1249 }
1250 return 0;
1251 }
1252 case WM_ERASEBKGND:
1253 case WM_ICONERASEBKGND:
1254 {
1255 RECT rect;
1256 int rc;
1257
1258 if (!windowClass->getBackgroundBrush()) return 0;
1259
1260 rc = GetClipBox( (HDC)wParam, &rect );
1261 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1262 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1263
1264 return 1;
1265 }
1266 case WM_GETDLGCODE:
1267 return 0;
1268
1269 case WM_NCLBUTTONDOWN:
1270 case WM_NCLBUTTONUP:
1271 case WM_NCLBUTTONDBLCLK:
1272 case WM_NCRBUTTONUP:
1273 case WM_NCRBUTTONDOWN:
1274 case WM_NCRBUTTONDBLCLK:
1275 case WM_NCMBUTTONDOWN:
1276 case WM_NCMBUTTONUP:
1277 case WM_NCMBUTTONDBLCLK:
1278 return 0; //TODO: Send WM_SYSCOMMAND if required
1279
1280 case WM_NCHITTEST: //TODO: Calculate position of
1281 return HTCLIENT;
1282
1283 default:
1284 return 1;
1285 }
1286}
1287//******************************************************************************
1288//******************************************************************************
1289LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1290{
1291 switch(Msg)
1292 {
1293 case WM_GETTEXTLENGTH:
1294 return wndNameLength;
1295
1296 case WM_GETTEXT: //TODO: SS_ICON controls
1297 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1298 return min(wndNameLength, wParam);
1299
1300 default:
1301 return DefWindowProcA(Msg, wParam, lParam);
1302 }
1303}
1304//******************************************************************************
1305//******************************************************************************
1306LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1307{
1308 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1309 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1310 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1311 }
1312
1313 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1314 return(0);
1315 }
1316 switch(Msg)
1317 {
1318 case WM_CREATE:
1319 {
1320 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1321 dprintf(("WM_CREATE returned -1\n"));
1322 return(-1); //don't create window
1323 }
1324 NotifyParent(Msg, wParam, lParam);
1325
1326 return(0);
1327 }
1328 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1329 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1330
1331 case WM_LBUTTONDOWN:
1332 case WM_MBUTTONDOWN:
1333 case WM_RBUTTONDOWN:
1334 NotifyParent(Msg, wParam, lParam);
1335 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1336
1337 case WM_DESTROY:
1338 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1339 NotifyParent(Msg, wParam, lParam);
1340 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1341 default:
1342 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1343 }
1344}
1345//******************************************************************************
1346//******************************************************************************
1347LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1348{
1349 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1350 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1351 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1352 }
1353
1354 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1355 return(0);
1356 }
1357 switch(Msg)
1358 {
1359 case WM_CREATE:
1360 {
1361 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1362 dprintf(("WM_CREATE returned FALSE\n"));
1363 return(0); //don't create window
1364 }
1365 NotifyParent(Msg, wParam, lParam);
1366
1367 return(1);
1368 }
1369 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1370 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1371
1372 case WM_LBUTTONDOWN:
1373 case WM_MBUTTONDOWN:
1374 case WM_RBUTTONDOWN:
1375 NotifyParent(Msg, wParam, lParam);
1376 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1377
1378 case WM_DESTROY:
1379 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1380 NotifyParent(Msg, wParam, lParam);
1381 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1382
1383 default:
1384 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1385 }
1386}
1387//******************************************************************************
1388//Called as a result of an OS/2 message
1389//******************************************************************************
1390LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1391{
1392 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1393 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1394
1395 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1396 return(0);
1397 }
1398 switch(Msg)
1399 {
1400 case WM_CREATE:
1401 {
1402 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1403 dprintf(("WM_CREATE returned FALSE\n"));
1404 return(0); //don't create window
1405 }
1406 NotifyParent(Msg, wParam, lParam);
1407
1408 return(1);
1409 }
1410 case WM_LBUTTONDOWN:
1411 case WM_MBUTTONDOWN:
1412 case WM_RBUTTONDOWN:
1413 NotifyParent(Msg, wParam, lParam);
1414 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1415
1416 case WM_DESTROY:
1417 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1418 NotifyParent(Msg, wParam, lParam);
1419 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1420 default:
1421 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1422 }
1423}
1424//******************************************************************************
1425//Called as a result of an OS/2 message
1426//todo, unicode msgs (WM_SETTEXT etc)
1427//******************************************************************************
1428LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1429{
1430 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1431 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1432
1433 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1434 return(0);
1435 }
1436 switch(Msg)
1437 {
1438 case WM_CREATE:
1439 {
1440 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1441 dprintf(("WM_CREATE returned FALSE\n"));
1442 return(0); //don't create window
1443 }
1444 NotifyParent(Msg, wParam, lParam);
1445
1446 return(1);
1447 }
1448 case WM_LBUTTONDOWN:
1449 case WM_MBUTTONDOWN:
1450 case WM_RBUTTONDOWN:
1451 NotifyParent(Msg, wParam, lParam);
1452 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1453
1454 case WM_DESTROY:
1455 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1456 NotifyParent(Msg, wParam, lParam);
1457 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1458 default:
1459 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1460 }
1461}
1462//******************************************************************************
1463//******************************************************************************
1464BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1465{
1466 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1467}
1468//******************************************************************************
1469//******************************************************************************
1470BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1471{
1472 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1473}
1474//******************************************************************************
1475//TODO: do we need to inform the parent of the parent (etc) of the child window?
1476//******************************************************************************
1477void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1478{
1479 Win32BaseWindow *window = this;
1480 Win32BaseWindow *parentwindow;
1481
1482 while(window)
1483 {
1484 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1485 {
1486 /* Notify the parent window only */
1487 parentwindow = window->getParent();
1488 if(parentwindow) {
1489 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1490 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1491 }
1492 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1493 }
1494 }
1495 else break;
1496
1497 window = parentwindow;
1498 }
1499}
1500//******************************************************************************
1501//******************************************************************************
1502Win32BaseWindow *Win32BaseWindow::getTopParent()
1503{
1504 Win32BaseWindow *tmpWnd = this;
1505
1506 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1507 {
1508 tmpWnd = tmpWnd->getParent();
1509 }
1510 return tmpWnd;
1511}
1512//******************************************************************************
1513//******************************************************************************
1514BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1515{
1516 PVOID menutemplate;
1517 Win32Resource *winres = (Win32Resource *)hMenu;
1518
1519 dprintf(("SetMenu %x", hMenu));
1520 if(HIWORD(winres) == 0) {
1521 dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
1522 SetLastError(ERROR_INVALID_PARAMETER);
1523 return FALSE;
1524 }
1525 menutemplate = winres->lockOS2Resource();
1526 if(menutemplate == NULL)
1527 {
1528 dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
1529 return FALSE;
1530 }
1531 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1532 if(OS2HwndMenu == 0) {
1533 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1534 return FALSE;
1535 }
1536 winres->setOS2Handle(OS2HwndMenu);
1537 menuResource = winres;
1538 return TRUE;
1539}
1540//******************************************************************************
1541//******************************************************************************
1542BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1543{
1544 Win32Resource *winres = (Win32Resource *)hAccel;
1545 HANDLE accelhandle;
1546
1547 if(HIWORD(hAccel) == 0) {
1548 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1549 SetLastError(ERROR_INVALID_PARAMETER);
1550 return FALSE;
1551 }
1552 acceltableResource = winres;
1553 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1554 winres->setOS2Handle(accelhandle);
1555 return(accelhandle != 0);
1556}
1557//******************************************************************************
1558//******************************************************************************
1559BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1560{
1561 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1562 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1563 SendInternalMessageA(WM_SETICON, hIcon, 0);
1564 return TRUE;
1565 }
1566 return FALSE;
1567}
1568//******************************************************************************
1569//******************************************************************************
1570BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1571{
1572 ULONG showstate = 0;
1573
1574 dprintf(("ShowWindow %x", nCmdShow));
1575 if(fFirstShow) {
1576 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1577 SendMessageA(WM_SIZE, SIZE_RESTORED,
1578 MAKELONG(rectClient.right-rectClient.left,
1579 rectClient.bottom-rectClient.top));
1580 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1581
1582 }
1583 fFirstShow = FALSE;
1584 }
1585 switch(nCmdShow)
1586 {
1587 case SW_SHOW:
1588 case SW_SHOWDEFAULT: //todo
1589 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1590 break;
1591 case SW_HIDE:
1592 showstate = SWPOS_HIDE;
1593 break;
1594 case SW_RESTORE:
1595 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1596 break;
1597 case SW_MINIMIZE:
1598 showstate = SWPOS_MINIMIZE;
1599 break;
1600 case SW_SHOWMAXIMIZED:
1601 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1602 break;
1603 case SW_SHOWMINIMIZED:
1604 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1605 break;
1606 case SW_SHOWMINNOACTIVE:
1607 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1608 break;
1609 case SW_SHOWNA:
1610 showstate = SWPOS_SHOW;
1611 break;
1612 case SW_SHOWNOACTIVATE:
1613 showstate = SWPOS_SHOW;
1614 break;
1615 case SW_SHOWNORMAL:
1616 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1617 break;
1618 }
1619 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1620}
1621//******************************************************************************
1622//******************************************************************************
1623BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1624{
1625 BOOL rc = FALSE;
1626 Win32BaseWindow *window;
1627 HWND hParent = 0;
1628
1629 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1630
1631 if (fuFlags &
1632 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1633 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1634 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1635 SWP_NOOWNERZORDER))
1636 {
1637 return FALSE;
1638 }
1639
1640 WINDOWPOS wpos;
1641 SWP swp, swpOld;
1642
1643 wpos.flags = fuFlags;
1644 wpos.cy = cy;
1645 wpos.cx = cx;
1646 wpos.x = x;
1647 wpos.y = y;
1648 wpos.hwndInsertAfter = hwndInsertAfter;
1649 wpos.hwnd = getWindowHandle();
1650
1651 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1652 if (isChild())
1653 {
1654 hParent = getParent()->getOS2WindowHandle();
1655 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1656 } else
1657 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1658 }
1659
1660 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1661 if (swp.fl == 0)
1662 return TRUE;
1663
1664 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1665 {
1666 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1667 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1668 }
1669 if (isFrameWindow())
1670 {
1671 POINT maxSize, maxPos, minTrack, maxTrack;
1672
1673 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1674
1675 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1676 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1677 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1678 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1679 swp.hwnd = OS2HwndFrame;
1680 } else
1681 swp.hwnd = OS2Hwnd;
1682 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1683
1684 rc = OSLibWinSetMultWindowPos(&swp, 1);
1685
1686 if (rc == FALSE)
1687 {
1688// SET_ERROR_LAST();
1689 }
1690 else
1691 {
1692 if (fuFlags & SWP_FRAMECHANGED_W)
1693 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
1694 }
1695
1696 return (rc);
1697}
1698//******************************************************************************
1699//Also destroys all the child windows (destroy parent, destroy children)
1700//******************************************************************************
1701BOOL Win32BaseWindow::DestroyWindow()
1702{
1703 return OSLibWinDestroyWindow(OS2HwndFrame);
1704}
1705//******************************************************************************
1706//******************************************************************************
1707HWND Win32BaseWindow::GetParent()
1708{
1709 if(getParent()) {
1710 return getParent()->getWindowHandle();
1711 }
1712 else return 0;
1713}
1714//******************************************************************************
1715//******************************************************************************
1716HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1717{
1718 HWND oldhwnd;
1719 Win32BaseWindow *newparent;
1720
1721 if(getParent()) {
1722 oldhwnd = getParent()->getWindowHandle();
1723 getParent()->RemoveChild(this);
1724 }
1725 else oldhwnd = 0;
1726
1727 if(hwndNewParent == 0) {//desktop window = parent
1728 setParent(NULL);
1729 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1730 return oldhwnd;
1731 }
1732 newparent = GetWindowFromHandle(hwndNewParent);
1733 if(newparent)
1734 {
1735 setParent(newparent);
1736 getParent()->AddChild(this);
1737 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1738 return oldhwnd;
1739 }
1740 SetLastError(ERROR_INVALID_PARAMETER);
1741 return 0;
1742}
1743//******************************************************************************
1744//******************************************************************************
1745BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1746{
1747 if(getParent()) {
1748 return getParent()->getWindowHandle() == hwndParent;
1749 }
1750 else return 0;
1751}
1752//******************************************************************************
1753//******************************************************************************
1754HWND Win32BaseWindow::GetTopWindow()
1755{
1756 return GetWindow(GW_CHILD);
1757}
1758//******************************************************************************
1759//Don't call WinUpdateWindow as that one also updates the child windows
1760//Also need to send WM_PAINT directly to the window procedure, which doesn't
1761//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1762//******************************************************************************
1763BOOL Win32BaseWindow::UpdateWindow()
1764{
1765 RECT rect;
1766
1767 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1768 {//update region not empty
1769 HDC hdc;
1770
1771 hdc = O32_GetDC(OS2Hwnd);
1772 if (isIcon)
1773 {
1774 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1775 SendInternalMessageA(WM_PAINTICON, 0, 0);
1776 } else
1777 {
1778 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1779 SendInternalMessageA(WM_PAINT, 0, 0);
1780 }
1781 O32_ReleaseDC(OS2Hwnd, hdc);
1782 }
1783 return TRUE;
1784}
1785//******************************************************************************
1786//******************************************************************************
1787BOOL Win32BaseWindow::IsIconic()
1788{
1789 return OSLibWinIsIconic(OS2Hwnd);
1790}
1791//******************************************************************************
1792//TODO:
1793//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1794//the current process owns them.
1795//******************************************************************************
1796HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1797 BOOL fUnicode)
1798{
1799 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1800 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1801
1802 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1803 (hwndChildAfter != 0 && !child) ||
1804 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1805 {
1806 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1807 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1808 return 0;
1809 }
1810 if(hwndParent != OSLIB_HWND_DESKTOP)
1811 {//if the current process owns the window, just do a quick search
1812 child = (Win32BaseWindow *)parent->getFirstChild();
1813 if(hwndChildAfter != 0)
1814 {
1815 while(child)
1816 {
1817 if(child->getWindowHandle() == hwndChildAfter)
1818 {
1819 child = (Win32BaseWindow *)child->getNextChild();
1820 break;
1821 }
1822 child = (Win32BaseWindow *)child->getNextChild();
1823 }
1824 }
1825 while(child)
1826 {
1827 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1828 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1829 {
1830 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1831 return child->getWindowHandle();
1832 }
1833 child = (Win32BaseWindow *)child->getNextChild();
1834 }
1835 }
1836 else {
1837 Win32BaseWindow *wnd;
1838 HWND henum, hwnd;
1839
1840 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1841 hwnd = OSLibWinGetNextWindow(henum);
1842
1843 while(hwnd)
1844 {
1845 wnd = GetWindowFromOS2Handle(hwnd);
1846 if(wnd == NULL) {
1847 hwnd = OSLibWinQueryClientWindow(hwnd);
1848 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1849 }
1850
1851 if(wnd) {
1852 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1853
1854 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1855 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1856 break;
1857 }
1858 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1859 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1860 {
1861 OSLibWinEndEnumWindows(henum);
1862 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1863 return wnd->getWindowHandle();
1864 }
1865 }
1866 hwnd = OSLibWinGetNextWindow(henum);
1867 }
1868 OSLibWinEndEnumWindows(henum);
1869 }
1870 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1871 return 0;
1872}
1873//******************************************************************************
1874//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1875//******************************************************************************
1876HWND Win32BaseWindow::GetWindow(UINT uCmd)
1877{
1878 Win32BaseWindow *win32wnd;
1879 ULONG magic;
1880 ULONG getcmd = 0;
1881 HWND hwndRelated;
1882
1883 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1884 switch(uCmd)
1885 {
1886 case GW_CHILD:
1887 getcmd = QWOS_TOP;
1888 break;
1889 case GW_HWNDFIRST:
1890 if(getParent()) {
1891 getcmd = QWOS_TOP; //top of child windows
1892 }
1893 else getcmd = QWOS_TOP; //TODO
1894 break;
1895 case GW_HWNDLAST:
1896 if(getParent()) {
1897 getcmd = QWOS_BOTTOM; //bottom of child windows
1898 }
1899 else getcmd = QWOS_BOTTOM; //TODO
1900 break;
1901 case GW_HWNDNEXT:
1902 getcmd = QWOS_NEXT;
1903 break;
1904 case GW_HWNDPREV:
1905 getcmd = QWOS_PREV;
1906 break;
1907 case GW_OWNER:
1908 if(owner) {
1909 return owner->getWindowHandle();
1910 }
1911 else return 0;
1912 }
1913 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1914 if(hwndRelated)
1915 {
1916 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1917 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1918 if(CheckMagicDword(magic) && win32wnd)
1919 {
1920 return win32wnd->getWindowHandle();
1921 }
1922 }
1923 return 0;
1924}
1925//******************************************************************************
1926//******************************************************************************
1927HWND Win32BaseWindow::SetActiveWindow()
1928{
1929 return OSLibWinSetActiveWindow(OS2Hwnd);
1930}
1931//******************************************************************************
1932//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1933//******************************************************************************
1934BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
1935{
1936 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1937}
1938//******************************************************************************
1939//******************************************************************************
1940BOOL Win32BaseWindow::CloseWindow()
1941{
1942 return OSLibWinMinimizeWindow(OS2Hwnd);
1943}
1944//******************************************************************************
1945//******************************************************************************
1946HWND Win32BaseWindow::GetActiveWindow()
1947{
1948 HWND hwndActive;
1949 Win32BaseWindow *win32wnd;
1950 ULONG magic;
1951
1952 hwndActive = OSLibWinQueryActiveWindow();
1953
1954 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1955 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1956 if(CheckMagicDword(magic) && win32wnd)
1957 {
1958 return win32wnd->getWindowHandle();
1959 }
1960 return hwndActive;
1961}
1962//******************************************************************************
1963//******************************************************************************
1964BOOL Win32BaseWindow::IsWindowEnabled()
1965{
1966 return OSLibWinIsWindowEnabled(OS2Hwnd);
1967}
1968//******************************************************************************
1969//******************************************************************************
1970BOOL Win32BaseWindow::IsWindowVisible()
1971{
1972 return OSLibWinIsWindowVisible(OS2Hwnd);
1973}
1974//******************************************************************************
1975//******************************************************************************
1976BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
1977{
1978 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1979}
1980//******************************************************************************
1981//******************************************************************************
1982BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
1983{
1984 if(fUnicode) {
1985 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
1986 }
1987 else return (strcmp(windowNameA, wndname) == 0);
1988}
1989//******************************************************************************
1990//******************************************************************************
1991int Win32BaseWindow::GetWindowTextLength()
1992{
1993 return wndNameLength;
1994}
1995//******************************************************************************
1996//******************************************************************************
1997int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
1998{
1999 strncpy(lpsz, windowNameA, cch);
2000 return wndNameLength;
2001}
2002//******************************************************************************
2003//******************************************************************************
2004int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2005{
2006 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2007 return wndNameLength;
2008}
2009//******************************************************************************
2010//******************************************************************************
2011BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2012{
2013 if(lpsz == NULL)
2014 return FALSE;
2015
2016 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2017 strcpy(windowNameA, lpsz);
2018 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2019 lstrcpyAtoW(windowNameW, windowNameA);
2020 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2021
2022 if(OS2HwndFrame)
2023 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2024
2025 return TRUE;
2026}
2027//******************************************************************************
2028//******************************************************************************
2029BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2030{
2031 if(lpsz == NULL)
2032 return FALSE;
2033
2034 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2035 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2036 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2037 lstrcpyWtoA(windowNameA, windowNameW);
2038 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2039
2040 if(OS2HwndFrame)
2041 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2042
2043 return TRUE;
2044}
2045//******************************************************************************
2046//******************************************************************************
2047LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2048{
2049 LONG oldval;
2050
2051 switch(index) {
2052 case GWL_EXSTYLE:
2053 oldval = dwExStyle;
2054 setExStyle(value);
2055 return oldval;
2056 case GWL_STYLE:
2057 oldval = dwStyle;
2058 setStyle(value);
2059 return oldval;
2060 case GWL_WNDPROC:
2061 oldval = (LONG)getWindowProc();
2062 setWindowProc((WNDPROC)value);
2063 return oldval;
2064 case GWL_HINSTANCE:
2065 oldval = hInstance;
2066 hInstance = value;
2067 return oldval;
2068 case GWL_HWNDPARENT:
2069 return SetParent((HWND)value);
2070
2071 case GWL_ID:
2072 oldval = getWindowId();
2073 setWindowId(value);
2074 return oldval;
2075 case GWL_USERDATA:
2076 oldval = userData;
2077 userData = value;
2078 return oldval;
2079 default:
2080 if(index >= 0 && index/4 < nrUserWindowLong)
2081 {
2082 oldval = userWindowLong[index/4];
2083 userWindowLong[index/4] = value;
2084 return oldval;
2085 }
2086 SetLastError(ERROR_INVALID_PARAMETER);
2087 return 0;
2088 }
2089}
2090//******************************************************************************
2091//******************************************************************************
2092ULONG Win32BaseWindow::GetWindowLongA(int index)
2093{
2094 switch(index) {
2095 case GWL_EXSTYLE:
2096 return dwExStyle;
2097 case GWL_STYLE:
2098 return dwStyle;
2099 case GWL_WNDPROC:
2100 return (ULONG)getWindowProc();
2101 case GWL_HINSTANCE:
2102 return hInstance;
2103 case GWL_HWNDPARENT:
2104 if(getParent()) {
2105 return getParent()->getWindowHandle();
2106 }
2107 else return 0;
2108 case GWL_ID:
2109 return getWindowId();
2110 case GWL_USERDATA:
2111 return userData;
2112 default:
2113 if(index >= 0 && index/4 < nrUserWindowLong)
2114 {
2115 return userWindowLong[index/4];
2116 }
2117 SetLastError(ERROR_INVALID_PARAMETER);
2118 return 0;
2119 }
2120}
2121//******************************************************************************
2122//******************************************************************************
2123WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2124{
2125 WORD oldval;
2126
2127 if(index >= 0 && index/4 < nrUserWindowLong)
2128 {
2129 oldval = ((WORD *)userWindowLong)[index/2];
2130 ((WORD *)userWindowLong)[index/2] = value;
2131 return oldval;
2132 }
2133 SetLastError(ERROR_INVALID_PARAMETER);
2134 return 0;
2135}
2136//******************************************************************************
2137//******************************************************************************
2138WORD Win32BaseWindow::GetWindowWord(int index)
2139{
2140 if(index >= 0 && index/4 < nrUserWindowLong)
2141 {
2142 return ((WORD *)userWindowLong)[index/2];
2143 }
2144 SetLastError(ERROR_INVALID_PARAMETER);
2145 return 0;
2146}
2147//******************************************************************************
2148//******************************************************************************
2149Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2150{
2151 Win32BaseWindow *window;
2152
2153 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2154 return window;
2155 }
2156 else return NULL;
2157}
2158//******************************************************************************
2159//******************************************************************************
2160Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2161{
2162 Win32BaseWindow *win32wnd;
2163 DWORD magic;
2164
2165 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2166 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2167
2168 if(win32wnd && CheckMagicDword(magic)) {
2169 return win32wnd;
2170 }
2171 return 0;
2172}
2173//******************************************************************************
2174//******************************************************************************
2175GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.