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

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

Keyboard msg fixes

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