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

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

* empty log message *

File size: 79.3 KB
Line 
1/* $Id: win32wbase.cpp,v 1.17 1999-09-27 19:43:04 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#if 0
1350 case WM_SYSKEYDOWN:
1351 if(HIWORD(lParam) & KEYDATA_ALT)
1352 {
1353 if(wParam == VK_F4) /* try to close the window */
1354 {
1355 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
1356 wndPtr = WIN_FindWndPtr( hWnd );
1357 if( wndPtr && !(getClass()->getStyle() & CS_NOCLOSE) )
1358 PostMessage(WM_SYSCOMMAND, SC_CLOSE, 0);
1359 }
1360 }
1361 return 0;
1362#endif
1363
1364 default:
1365 return 1;
1366 }
1367}
1368//******************************************************************************
1369//******************************************************************************
1370LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1371{
1372 switch(Msg)
1373 {
1374 case WM_GETTEXTLENGTH:
1375 return wndNameLength;
1376
1377 case WM_GETTEXT: //TODO: SS_ICON controls
1378 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1379 return min(wndNameLength, wParam);
1380
1381 default:
1382 return DefWindowProcA(Msg, wParam, lParam);
1383 }
1384}
1385//******************************************************************************
1386//******************************************************************************
1387LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1388{
1389 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1390 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1391 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1392 }
1393
1394 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1395 return(0);
1396 }
1397 switch(Msg)
1398 {
1399 case WM_CREATE:
1400 {
1401 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1402 dprintf(("WM_CREATE returned -1\n"));
1403 return(-1); //don't create window
1404 }
1405 NotifyParent(Msg, wParam, lParam);
1406
1407 return(0);
1408 }
1409 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1410 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1411
1412 case WM_LBUTTONDOWN:
1413 case WM_MBUTTONDOWN:
1414 case WM_RBUTTONDOWN:
1415 NotifyParent(Msg, wParam, lParam);
1416 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1417
1418 case WM_DESTROY:
1419 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1420 NotifyParent(Msg, wParam, lParam);
1421 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1422 default:
1423 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1424 }
1425}
1426//******************************************************************************
1427//******************************************************************************
1428LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1429{
1430 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1431 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1432 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1433 }
1434
1435 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1436 return(0);
1437 }
1438 switch(Msg)
1439 {
1440 case WM_CREATE:
1441 {
1442 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1443 dprintf(("WM_CREATE returned -1\n"));
1444 return(-1); //don't create window
1445 }
1446 NotifyParent(Msg, wParam, lParam);
1447
1448 return(0);
1449 }
1450 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1451 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1452
1453 case WM_LBUTTONDOWN:
1454 case WM_MBUTTONDOWN:
1455 case WM_RBUTTONDOWN:
1456 NotifyParent(Msg, wParam, lParam);
1457 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1458
1459 case WM_DESTROY:
1460 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1461 NotifyParent(Msg, wParam, lParam);
1462 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1463
1464 default:
1465 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1466 }
1467}
1468//******************************************************************************
1469//Called as a result of an OS/2 message
1470//******************************************************************************
1471LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1472{
1473 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1474 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1475
1476 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1477 return(0);
1478 }
1479 switch(Msg)
1480 {
1481 case WM_CREATE:
1482 {
1483 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1484 dprintf(("WM_CREATE returned -1\n"));
1485 return(-1); //don't create window
1486 }
1487 NotifyParent(Msg, wParam, lParam);
1488
1489 return(0);
1490 }
1491 case WM_LBUTTONDOWN:
1492 case WM_MBUTTONDOWN:
1493 case WM_RBUTTONDOWN:
1494 NotifyParent(Msg, wParam, lParam);
1495 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1496
1497 case WM_DESTROY:
1498 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1499 NotifyParent(Msg, wParam, lParam);
1500 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1501 default:
1502 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1503 }
1504}
1505//******************************************************************************
1506//Called as a result of an OS/2 message
1507//todo, unicode msgs (WM_SETTEXT etc)
1508//******************************************************************************
1509LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1510{
1511 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1512 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1513
1514 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1515 return(0);
1516 }
1517 switch(Msg)
1518 {
1519 case WM_CREATE:
1520 {
1521 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1522 dprintf(("WM_CREATE returned -1\n"));
1523 return(-1); //don't create window
1524 }
1525 NotifyParent(Msg, wParam, lParam);
1526
1527 return(0);
1528 }
1529 case WM_LBUTTONDOWN:
1530 case WM_MBUTTONDOWN:
1531 case WM_RBUTTONDOWN:
1532 NotifyParent(Msg, wParam, lParam);
1533 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1534
1535 case WM_DESTROY:
1536 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1537 NotifyParent(Msg, wParam, lParam);
1538 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1539 default:
1540 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1541 }
1542}
1543//******************************************************************************
1544//******************************************************************************
1545BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1546{
1547 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1548}
1549//******************************************************************************
1550//******************************************************************************
1551BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1552{
1553 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1554}
1555//******************************************************************************
1556//TODO: do we need to inform the parent of the parent (etc) of the child window?
1557//******************************************************************************
1558void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1559{
1560 Win32BaseWindow *window = this;
1561 Win32BaseWindow *parentwindow;
1562
1563 while(window)
1564 {
1565 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1566 {
1567 /* Notify the parent window only */
1568 parentwindow = window->getParent();
1569 if(parentwindow) {
1570 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1571 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1572 }
1573 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1574 }
1575 }
1576 else break;
1577
1578 window = parentwindow;
1579 }
1580}
1581//******************************************************************************
1582//******************************************************************************
1583Win32BaseWindow *Win32BaseWindow::getTopParent()
1584{
1585 Win32BaseWindow *tmpWnd = this;
1586
1587 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1588 {
1589 tmpWnd = tmpWnd->getParent();
1590 }
1591 return tmpWnd;
1592}
1593//******************************************************************************
1594//******************************************************************************
1595BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1596{
1597
1598 dprintf(("SetMenu %x", hMenu));
1599 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1600 if(OS2HwndMenu == 0) {
1601 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1602 return FALSE;
1603 }
1604 return TRUE;
1605}
1606//******************************************************************************
1607//******************************************************************************
1608BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1609{
1610 Win32Resource *winres = (Win32Resource *)hAccel;
1611 HANDLE accelhandle;
1612
1613 if(HIWORD(hAccel) == 0) {
1614 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1615 SetLastError(ERROR_INVALID_PARAMETER);
1616 return FALSE;
1617 }
1618 acceltableResource = winres;
1619 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1620 winres->setOS2Handle(accelhandle);
1621 return(accelhandle != 0);
1622}
1623//******************************************************************************
1624//******************************************************************************
1625BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1626{
1627 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1628 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1629 SendInternalMessageA(WM_SETICON, hIcon, 0);
1630 return TRUE;
1631 }
1632 return FALSE;
1633}
1634//******************************************************************************
1635//******************************************************************************
1636BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1637{
1638 ULONG showstate = 0;
1639
1640 dprintf(("ShowWindow %x", nCmdShow));
1641 if(fFirstShow) {
1642 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1643 SendMessageA(WM_SIZE, SIZE_RESTORED,
1644 MAKELONG(rectClient.right-rectClient.left,
1645 rectClient.bottom-rectClient.top));
1646 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1647
1648 }
1649 fFirstShow = FALSE;
1650 }
1651 switch(nCmdShow)
1652 {
1653 case SW_SHOW:
1654 case SW_SHOWDEFAULT: //todo
1655 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1656 break;
1657 case SW_HIDE:
1658 showstate = SWPOS_HIDE;
1659 break;
1660 case SW_RESTORE:
1661 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1662 break;
1663 case SW_MINIMIZE:
1664 showstate = SWPOS_MINIMIZE;
1665 break;
1666 case SW_SHOWMAXIMIZED:
1667 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1668 break;
1669 case SW_SHOWMINIMIZED:
1670 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1671 break;
1672 case SW_SHOWMINNOACTIVE:
1673 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1674 break;
1675 case SW_SHOWNA:
1676 showstate = SWPOS_SHOW;
1677 break;
1678 case SW_SHOWNOACTIVATE:
1679 showstate = SWPOS_SHOW;
1680 break;
1681 case SW_SHOWNORMAL:
1682 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1683 break;
1684 }
1685 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1686}
1687//******************************************************************************
1688//******************************************************************************
1689BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1690{
1691 BOOL rc = FALSE;
1692 Win32BaseWindow *window;
1693 HWND hParent = 0;
1694
1695 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1696
1697 if (fuFlags &
1698 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1699 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1700 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1701 SWP_NOOWNERZORDER))
1702 {
1703 return FALSE;
1704 }
1705
1706 WINDOWPOS wpos;
1707 SWP swp, swpOld;
1708
1709 wpos.flags = fuFlags;
1710 wpos.cy = cy;
1711 wpos.cx = cx;
1712 wpos.x = x;
1713 wpos.y = y;
1714 wpos.hwndInsertAfter = hwndInsertAfter;
1715 wpos.hwnd = getWindowHandle();
1716
1717 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1718 if (isChild())
1719 {
1720 hParent = getParent()->getOS2WindowHandle();
1721 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1722 } else
1723 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1724 }
1725
1726 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1727 if (swp.fl == 0)
1728 return TRUE;
1729
1730 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1731 {
1732 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1733 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1734 }
1735 if (isFrameWindow())
1736 {
1737 POINT maxSize, maxPos, minTrack, maxTrack;
1738
1739 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1740
1741 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1742 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1743 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1744 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1745 swp.hwnd = OS2HwndFrame;
1746 } else
1747 swp.hwnd = OS2Hwnd;
1748 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1749
1750 rc = OSLibWinSetMultWindowPos(&swp, 1);
1751
1752 if (rc == FALSE)
1753 {
1754// SET_ERROR_LAST();
1755 }
1756 else
1757 {
1758 if (fuFlags & SWP_FRAMECHANGED_W)
1759 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
1760 }
1761
1762 return (rc);
1763}
1764//******************************************************************************
1765//Also destroys all the child windows (destroy parent, destroy children)
1766//******************************************************************************
1767BOOL Win32BaseWindow::DestroyWindow()
1768{
1769 return OSLibWinDestroyWindow(OS2HwndFrame);
1770}
1771//******************************************************************************
1772//******************************************************************************
1773HWND Win32BaseWindow::GetParent()
1774{
1775 if(getParent()) {
1776 return getParent()->getWindowHandle();
1777 }
1778 else return 0;
1779}
1780//******************************************************************************
1781//******************************************************************************
1782HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1783{
1784 HWND oldhwnd;
1785 Win32BaseWindow *newparent;
1786
1787 if(getParent()) {
1788 oldhwnd = getParent()->getWindowHandle();
1789 getParent()->RemoveChild(this);
1790 }
1791 else oldhwnd = 0;
1792
1793 if(hwndNewParent == 0) {//desktop window = parent
1794 setParent(NULL);
1795 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1796 return oldhwnd;
1797 }
1798 newparent = GetWindowFromHandle(hwndNewParent);
1799 if(newparent)
1800 {
1801 setParent(newparent);
1802 getParent()->AddChild(this);
1803 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1804 return oldhwnd;
1805 }
1806 SetLastError(ERROR_INVALID_PARAMETER);
1807 return 0;
1808}
1809//******************************************************************************
1810//******************************************************************************
1811BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1812{
1813 if(getParent()) {
1814 return getParent()->getWindowHandle() == hwndParent;
1815 }
1816 else return 0;
1817}
1818//******************************************************************************
1819//******************************************************************************
1820HWND Win32BaseWindow::GetTopWindow()
1821{
1822 return GetWindow(GW_CHILD);
1823}
1824//******************************************************************************
1825//Don't call WinUpdateWindow as that one also updates the child windows
1826//Also need to send WM_PAINT directly to the window procedure, which doesn't
1827//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1828//******************************************************************************
1829BOOL Win32BaseWindow::UpdateWindow()
1830{
1831 RECT rect;
1832
1833 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1834 {//update region not empty
1835 HDC hdc;
1836
1837 hdc = O32_GetDC(OS2Hwnd);
1838 if (isIcon)
1839 {
1840 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1841 SendInternalMessageA(WM_PAINTICON, 0, 0);
1842 } else
1843 {
1844 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1845 SendInternalMessageA(WM_PAINT, 0, 0);
1846 }
1847 O32_ReleaseDC(OS2Hwnd, hdc);
1848 }
1849 return TRUE;
1850}
1851//******************************************************************************
1852//******************************************************************************
1853BOOL Win32BaseWindow::IsIconic()
1854{
1855 return OSLibWinIsIconic(OS2Hwnd);
1856}
1857//******************************************************************************
1858//TODO:
1859//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1860//the current process owns them.
1861//******************************************************************************
1862HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1863 BOOL fUnicode)
1864{
1865 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1866 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1867
1868 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1869 (hwndChildAfter != 0 && !child) ||
1870 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1871 {
1872 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1873 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1874 return 0;
1875 }
1876 if(hwndParent != OSLIB_HWND_DESKTOP)
1877 {//if the current process owns the window, just do a quick search
1878 child = (Win32BaseWindow *)parent->getFirstChild();
1879 if(hwndChildAfter != 0)
1880 {
1881 while(child)
1882 {
1883 if(child->getWindowHandle() == hwndChildAfter)
1884 {
1885 child = (Win32BaseWindow *)child->getNextChild();
1886 break;
1887 }
1888 child = (Win32BaseWindow *)child->getNextChild();
1889 }
1890 }
1891 while(child)
1892 {
1893 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1894 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1895 {
1896 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1897 return child->getWindowHandle();
1898 }
1899 child = (Win32BaseWindow *)child->getNextChild();
1900 }
1901 }
1902 else {
1903 Win32BaseWindow *wnd;
1904 HWND henum, hwnd;
1905
1906 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1907 hwnd = OSLibWinGetNextWindow(henum);
1908
1909 while(hwnd)
1910 {
1911 wnd = GetWindowFromOS2Handle(hwnd);
1912 if(wnd == NULL) {
1913 hwnd = OSLibWinQueryClientWindow(hwnd);
1914 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1915 }
1916
1917 if(wnd) {
1918 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1919
1920 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1921 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1922 break;
1923 }
1924 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1925 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1926 {
1927 OSLibWinEndEnumWindows(henum);
1928 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1929 return wnd->getWindowHandle();
1930 }
1931 }
1932 hwnd = OSLibWinGetNextWindow(henum);
1933 }
1934 OSLibWinEndEnumWindows(henum);
1935 }
1936 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1937 return 0;
1938}
1939//******************************************************************************
1940//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1941//******************************************************************************
1942HWND Win32BaseWindow::GetWindow(UINT uCmd)
1943{
1944 Win32BaseWindow *win32wnd;
1945 ULONG magic;
1946 ULONG getcmd = 0;
1947 HWND hwndRelated;
1948
1949 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1950 switch(uCmd)
1951 {
1952 case GW_CHILD:
1953 getcmd = QWOS_TOP;
1954 break;
1955 case GW_HWNDFIRST:
1956 if(getParent()) {
1957 getcmd = QWOS_TOP; //top of child windows
1958 }
1959 else getcmd = QWOS_TOP; //TODO
1960 break;
1961 case GW_HWNDLAST:
1962 if(getParent()) {
1963 getcmd = QWOS_BOTTOM; //bottom of child windows
1964 }
1965 else getcmd = QWOS_BOTTOM; //TODO
1966 break;
1967 case GW_HWNDNEXT:
1968 getcmd = QWOS_NEXT;
1969 break;
1970 case GW_HWNDPREV:
1971 getcmd = QWOS_PREV;
1972 break;
1973 case GW_OWNER:
1974 if(owner) {
1975 return owner->getWindowHandle();
1976 }
1977 else return 0;
1978 }
1979 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1980 if(hwndRelated)
1981 {
1982 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1983 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1984 if(CheckMagicDword(magic) && win32wnd)
1985 {
1986 return win32wnd->getWindowHandle();
1987 }
1988 }
1989 return 0;
1990}
1991//******************************************************************************
1992//******************************************************************************
1993HWND Win32BaseWindow::SetActiveWindow()
1994{
1995 return OSLibWinSetActiveWindow(OS2Hwnd);
1996}
1997//******************************************************************************
1998//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1999//******************************************************************************
2000BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2001{
2002 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
2003}
2004//******************************************************************************
2005//******************************************************************************
2006BOOL Win32BaseWindow::CloseWindow()
2007{
2008 return OSLibWinMinimizeWindow(OS2Hwnd);
2009}
2010//******************************************************************************
2011//******************************************************************************
2012HWND Win32BaseWindow::GetActiveWindow()
2013{
2014 HWND hwndActive;
2015 Win32BaseWindow *win32wnd;
2016 ULONG magic;
2017
2018 hwndActive = OSLibWinQueryActiveWindow();
2019
2020 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2021 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2022 if(CheckMagicDword(magic) && win32wnd)
2023 {
2024 return win32wnd->getWindowHandle();
2025 }
2026 return hwndActive;
2027}
2028//******************************************************************************
2029//******************************************************************************
2030BOOL Win32BaseWindow::IsWindowEnabled()
2031{
2032 return OSLibWinIsWindowEnabled(OS2Hwnd);
2033}
2034//******************************************************************************
2035//******************************************************************************
2036BOOL Win32BaseWindow::IsWindowVisible()
2037{
2038 return OSLibWinIsWindowVisible(OS2Hwnd);
2039}
2040//******************************************************************************
2041//******************************************************************************
2042BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2043{
2044 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
2045}
2046//******************************************************************************
2047//******************************************************************************
2048BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2049{
2050 if(fUnicode) {
2051 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2052 }
2053 else return (strcmp(windowNameA, wndname) == 0);
2054}
2055//******************************************************************************
2056//******************************************************************************
2057int Win32BaseWindow::GetWindowTextLength()
2058{
2059 return wndNameLength;
2060}
2061//******************************************************************************
2062//******************************************************************************
2063int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2064{
2065 strncpy(lpsz, windowNameA, cch);
2066 return wndNameLength;
2067}
2068//******************************************************************************
2069//******************************************************************************
2070int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2071{
2072 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2073 return wndNameLength;
2074}
2075//******************************************************************************
2076//******************************************************************************
2077BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2078{
2079 if(lpsz == NULL)
2080 return FALSE;
2081
2082 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2083 strcpy(windowNameA, lpsz);
2084 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2085 lstrcpyAtoW(windowNameW, windowNameA);
2086 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2087
2088 if(OS2HwndFrame)
2089 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2090
2091 return TRUE;
2092}
2093//******************************************************************************
2094//******************************************************************************
2095BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2096{
2097 if(lpsz == NULL)
2098 return FALSE;
2099
2100 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2101 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2102 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2103 lstrcpyWtoA(windowNameA, windowNameW);
2104 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2105
2106 if(OS2HwndFrame)
2107 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2108
2109 return TRUE;
2110}
2111//******************************************************************************
2112//******************************************************************************
2113LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2114{
2115 LONG oldval;
2116
2117 switch(index) {
2118 case GWL_EXSTYLE:
2119 oldval = dwExStyle;
2120 setExStyle(value);
2121 return oldval;
2122 case GWL_STYLE:
2123 oldval = dwStyle;
2124 setStyle(value);
2125 return oldval;
2126 case GWL_WNDPROC:
2127 oldval = (LONG)getWindowProc();
2128 setWindowProc((WNDPROC)value);
2129 return oldval;
2130 case GWL_HINSTANCE:
2131 oldval = hInstance;
2132 hInstance = value;
2133 return oldval;
2134 case GWL_HWNDPARENT:
2135 return SetParent((HWND)value);
2136
2137 case GWL_ID:
2138 oldval = getWindowId();
2139 setWindowId(value);
2140 return oldval;
2141 case GWL_USERDATA:
2142 oldval = userData;
2143 userData = value;
2144 return oldval;
2145 default:
2146 if(index >= 0 && index/4 < nrUserWindowLong)
2147 {
2148 oldval = userWindowLong[index/4];
2149 userWindowLong[index/4] = value;
2150 return oldval;
2151 }
2152 SetLastError(ERROR_INVALID_PARAMETER);
2153 return 0;
2154 }
2155}
2156//******************************************************************************
2157//******************************************************************************
2158ULONG Win32BaseWindow::GetWindowLongA(int index)
2159{
2160 switch(index) {
2161 case GWL_EXSTYLE:
2162 return dwExStyle;
2163 case GWL_STYLE:
2164 return dwStyle;
2165 case GWL_WNDPROC:
2166 return (ULONG)getWindowProc();
2167 case GWL_HINSTANCE:
2168 return hInstance;
2169 case GWL_HWNDPARENT:
2170 if(getParent()) {
2171 return getParent()->getWindowHandle();
2172 }
2173 else return 0;
2174 case GWL_ID:
2175 return getWindowId();
2176 case GWL_USERDATA:
2177 return userData;
2178 default:
2179 if(index >= 0 && index/4 < nrUserWindowLong)
2180 {
2181 return userWindowLong[index/4];
2182 }
2183 SetLastError(ERROR_INVALID_PARAMETER);
2184 return 0;
2185 }
2186}
2187//******************************************************************************
2188//******************************************************************************
2189WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2190{
2191 WORD oldval;
2192
2193 if(index >= 0 && index/4 < nrUserWindowLong)
2194 {
2195 oldval = ((WORD *)userWindowLong)[index/2];
2196 ((WORD *)userWindowLong)[index/2] = value;
2197 return oldval;
2198 }
2199 SetLastError(ERROR_INVALID_PARAMETER);
2200 return 0;
2201}
2202//******************************************************************************
2203//******************************************************************************
2204WORD Win32BaseWindow::GetWindowWord(int index)
2205{
2206 if(index >= 0 && index/4 < nrUserWindowLong)
2207 {
2208 return ((WORD *)userWindowLong)[index/2];
2209 }
2210 SetLastError(ERROR_INVALID_PARAMETER);
2211 return 0;
2212}
2213//******************************************************************************
2214//******************************************************************************
2215Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2216{
2217 Win32BaseWindow *window;
2218
2219 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2220 return window;
2221 }
2222 else return NULL;
2223}
2224//******************************************************************************
2225//******************************************************************************
2226Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2227{
2228 Win32BaseWindow *win32wnd;
2229 DWORD magic;
2230
2231 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2232 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2233
2234 if(win32wnd && CheckMagicDword(magic)) {
2235 return win32wnd;
2236 }
2237 return 0;
2238}
2239//******************************************************************************
2240//******************************************************************************
2241HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2242{
2243 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2244
2245 if(window) {
2246 return window->getOS2WindowHandle();
2247 }
2248 else return hwnd; //OS/2 window handle
2249}
2250//******************************************************************************
2251//******************************************************************************
2252HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2253{
2254 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2255
2256 if(window) {
2257 return window->getWindowHandle();
2258 }
2259 else return hwnd; //OS/2 window handle
2260}
2261//******************************************************************************
2262//******************************************************************************
2263GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.