source: trunk/src/user32/new/win32wnd.cpp@ 397

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

* empty log message *

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