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

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

Menus are displayed now

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