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

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

Some bugfixes

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