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

Last change on this file since 728 was 728, checked in by dengert, 26 years ago

reposition child windows when parent height is changed

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