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

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

* empty log message *

File size: 54.6 KB
Line 
1/* $Id: win32wnd.cpp,v 1.21 1999-07-25 09:19:22 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, maxPos.y - rectWindow.top);
411 dprintf(("Sending WM_CREATE"));
412 if( (SendInternalMessage(WM_CREATE, 0, (LPARAM)cs )) != -1 )
413 {
414 SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
415 rectClient.right-rectClient.left,
416 rectClient.bottom-rectClient.top,
417 SWP_NOACTIVATE);
418
419 if (cs->style & WS_VISIBLE) ShowWindow( sw );
420
421#if 0
422 /* Call WH_SHELL hook */
423
424 if (!(dwStyle & WS_CHILD) && !owner)
425 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
426#endif
427 SetLastError(0);
428 return TRUE;
429 }
430 }
431 return FALSE;
432}
433#if 0
434/***********************************************************************
435 * WINPOS_MinMaximize
436 *
437 * Fill in lpRect and return additional flags to be used with SetWindowPos().
438 * This function assumes that 'cmd' is different from the current window
439 * state.
440 */
441UINT Win32Window::MinMaximize(UINT16 cmd, LPRECT16 lpRect )
442{
443 UINT swpFlags = 0;
444 POINT pt, size;
445 LPINTERNALPOS lpPos;
446
447 size.x = rectWindow.left; size.y = rectWindow.top;
448 lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
449
450 if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
451 {
452 if( dwStyle & WS_MINIMIZE )
453 {
454 if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
455 return (SWP_NOSIZE | SWP_NOMOVE);
456 swpFlags |= SWP_NOCOPYBITS;
457 }
458 switch( cmd )
459 {
460 case SW_MINIMIZE:
461 if( dwStyle & WS_MAXIMIZE)
462 {
463 flags |= WIN_RESTORE_MAX;
464 dwStyle &= ~WS_MAXIMIZE;
465 }
466 else
467 flags &= ~WIN_RESTORE_MAX;
468 dwStyle |= WS_MINIMIZE;
469
470#if 0
471 if( flags & WIN_NATIVE )
472 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
473 swpFlags |= MINMAX_NOSWP;
474#endif
475
476 lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
477
478 SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
479 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
480 swpFlags |= SWP_NOCOPYBITS;
481 break;
482
483 case SW_MAXIMIZE:
484 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
485 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
486 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
487
488 if( dwStyle & WS_MINIMIZE )
489 {
490 if( flags & WIN_NATIVE )
491 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
492 swpFlags |= MINMAX_NOSWP;
493
494 WINPOS_ShowIconTitle( wndPtr, FALSE );
495 dwStyle &= ~WS_MINIMIZE;
496 }
497 dwStyle |= WS_MAXIMIZE;
498
499 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
500 size.x, size.y );
501 break;
502
503 case SW_RESTORE:
504 if( dwStyle & WS_MINIMIZE )
505 {
506 if( flags & WIN_NATIVE )
507 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
508 swpFlags |= MINMAX_NOSWP;
509
510 dwStyle &= ~WS_MINIMIZE;
511 WINPOS_ShowIconTitle( wndPtr, FALSE );
512
513 if( flags & WIN_RESTORE_MAX)
514 {
515 /* Restore to maximized position */
516 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
517 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
518 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
519 dwStyle |= WS_MAXIMIZE;
520 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
521 break;
522 }
523 }
524 else
525 if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
526 else dwStyle &= ~WS_MAXIMIZE;
527
528 /* Restore to normal position */
529
530 *lpRect = lpPos->rectNormal;
531 lpRect->right -= lpRect->left;
532 lpRect->bottom -= lpRect->top;
533
534 break;
535 }
536 } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
537 return swpFlags;
538}
539#endif
540/*******************************************************************
541 * GetMinMaxInfo
542 *
543 * Get the minimized and maximized information for a window.
544 */
545void Win32Window::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
546 POINT *minTrack, POINT *maxTrack )
547{
548 MINMAXINFO MinMax;
549 INT xinc, yinc;
550
551 /* Compute default values */
552
553 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
554 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
555 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
556 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
557 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
558 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
559
560 if (flags & WIN_MANAGED) xinc = yinc = 0;
561 else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
562 {
563 xinc = GetSystemMetrics(SM_CXDLGFRAME);
564 yinc = GetSystemMetrics(SM_CYDLGFRAME);
565 }
566 else
567 {
568 xinc = yinc = 0;
569 if (HAS_THICKFRAME(dwStyle))
570 {
571 xinc += GetSystemMetrics(SM_CXFRAME);
572 yinc += GetSystemMetrics(SM_CYFRAME);
573 }
574 if (dwStyle & WS_BORDER)
575 {
576 xinc += GetSystemMetrics(SM_CXBORDER);
577 yinc += GetSystemMetrics(SM_CYBORDER);
578 }
579 }
580 MinMax.ptMaxSize.x += 2 * xinc;
581 MinMax.ptMaxSize.y += 2 * yinc;
582
583#if 0
584 lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
585 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
586 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
587 else
588 {
589#endif
590 MinMax.ptMaxPosition.x = -xinc;
591 MinMax.ptMaxPosition.y = -yinc;
592// }
593
594 SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
595
596 /* Some sanity checks */
597
598 dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
599 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
600 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
601 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
602 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
603 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
604 MinMax.ptMinTrackSize.x );
605 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
606 MinMax.ptMinTrackSize.y );
607
608 if (maxSize) *maxSize = MinMax.ptMaxSize;
609 if (maxPos) *maxPos = MinMax.ptMaxPosition;
610 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
611 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
612}
613/***********************************************************************
614 * WINPOS_SendNCCalcSize
615 *
616 * Send a WM_NCCALCSIZE message to a window.
617 * All parameters are read-only except newClientRect.
618 * oldWindowRect, oldClientRect and winpos must be non-NULL only
619 * when calcValidRect is TRUE.
620 */
621LONG Win32Window::SendNCCalcSize(BOOL calcValidRect,
622 RECT *newWindowRect, RECT *oldWindowRect,
623 RECT *oldClientRect, WINDOWPOS *winpos,
624 RECT *newClientRect )
625{
626 NCCALCSIZE_PARAMS params;
627 WINDOWPOS winposCopy;
628 LONG result;
629
630 params.rgrc[0] = *newWindowRect;
631 if (calcValidRect)
632 {
633 winposCopy = *winpos;
634 params.rgrc[1] = *oldWindowRect;
635 params.rgrc[2] = *oldClientRect;
636 params.lppos = &winposCopy;
637 }
638 result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
639 (LPARAM)&params );
640 *newClientRect = params.rgrc[0];
641 return result;
642}
643//******************************************************************************
644//******************************************************************************
645ULONG Win32Window::MsgCreate(HWND hwndOS2, ULONG initParam)
646{
647 OS2Hwnd = hwndOS2;
648 return SendInternalMessageA(WM_CREATE, 0, initParam);
649}
650//******************************************************************************
651//******************************************************************************
652ULONG Win32Window::MsgQuit()
653{
654 return SendInternalMessageA(WM_QUIT, 0, 0);
655}
656//******************************************************************************
657//******************************************************************************
658ULONG Win32Window::MsgClose()
659{
660 if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
661 return 0; //app handles this message
662 }
663 delete this;
664 return 1;
665}
666//******************************************************************************
667//******************************************************************************
668ULONG Win32Window::MsgDestroy()
669{
670 ULONG rc;
671
672 rc = SendInternalMessageA(WM_DESTROY, 0, 0);
673 delete this;
674 return rc;
675}
676//******************************************************************************
677//******************************************************************************
678ULONG Win32Window::MsgEnable(BOOL fEnable)
679{
680 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
681}
682//******************************************************************************
683//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
684//******************************************************************************
685ULONG Win32Window::MsgShow(BOOL fShow)
686{
687 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
688}
689//******************************************************************************
690//******************************************************************************
691ULONG Win32Window::MsgMove(ULONG x, ULONG y)
692{
693 dprintf(("MsgMove to (%d,%d)", x, y));
694 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
695}
696//******************************************************************************
697//******************************************************************************
698ULONG Win32Window::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
699{
700 switch(cmd) {
701 case CMD_MENU:
702 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
703 case CMD_CONTROL:
704 return 0; //todo
705 case CMD_ACCELERATOR:
706 dprintf(("accelerator command"));
707 return 0; //todo
708 }
709 return 0;
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::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
745{
746 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
747}
748//******************************************************************************
749//TODO: virtual key translation & extended keyboard bit
750//******************************************************************************
751ULONG Win32Window::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
752{
753 ULONG lParam = 0;
754
755 lParam = repeatcnt;
756 lParam |= (scancode << 16);
757 if(keyflags & KEY_ALTDOWN)
758 lParam |= (1<<29);
759 if(keyflags & KEY_PREVDOWN)
760 lParam |= (1<<30);
761 if(keyflags & KEY_UP)
762 lParam |= (1<<31);
763 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
764 return SendInternalMessageA(WM_CHAR, cmd, lParam);
765}
766//******************************************************************************
767//******************************************************************************
768ULONG Win32Window::MsgSetFocus(HWND hwnd)
769{
770 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
771}
772//******************************************************************************
773//******************************************************************************
774ULONG Win32Window::MsgKillFocus(HWND hwnd)
775{
776 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
777}
778//******************************************************************************
779//******************************************************************************
780ULONG Win32Window::MsgButton(ULONG msg, ULONG x, ULONG y)
781{
782 ULONG win32msg;
783 ULONG win32ncmsg;
784
785 dprintf(("MsgButton to (%d,%d)", x, y));
786 switch(msg) {
787 case BUTTON_LEFTDOWN:
788 win32msg = WM_LBUTTONDOWN;
789 win32ncmsg = WM_NCLBUTTONDOWN;
790 break;
791 case BUTTON_LEFTUP:
792 win32msg = WM_LBUTTONUP;
793 win32ncmsg = WM_NCLBUTTONUP;
794 break;
795 case BUTTON_LEFTDBLCLICK:
796 win32msg = WM_LBUTTONDBLCLK;
797 win32ncmsg = WM_NCLBUTTONDBLCLK;
798 break;
799 case BUTTON_RIGHTUP:
800 win32msg = WM_RBUTTONUP;
801 win32ncmsg = WM_NCRBUTTONUP;
802 break;
803 case BUTTON_RIGHTDOWN:
804 win32msg = WM_RBUTTONDOWN;
805 win32ncmsg = WM_NCRBUTTONDOWN;
806 break;
807 case BUTTON_RIGHTDBLCLICK:
808 win32msg = WM_RBUTTONDBLCLK;
809 win32ncmsg = WM_NCRBUTTONDBLCLK;
810 break;
811 case BUTTON_MIDDLEUP:
812 win32msg = WM_MBUTTONUP;
813 win32ncmsg = WM_NCMBUTTONUP;
814 break;
815 case BUTTON_MIDDLEDOWN:
816 win32msg = WM_MBUTTONDOWN;
817 win32ncmsg = WM_NCMBUTTONDOWN;
818 break;
819 case BUTTON_MIDDLEDBLCLICK:
820 win32msg = WM_MBUTTONDBLCLK;
821 win32ncmsg = WM_NCMBUTTONDBLCLK;
822 break;
823 default:
824 dprintf(("Win32Window::Button: invalid msg!!!!"));
825 return 1;
826 }
827 SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(x, y)); //TODO:
828 return SendInternalMessageA(win32msg, 0, MAKELONG(x, y));
829}
830//******************************************************************************
831//******************************************************************************
832ULONG Win32Window::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
833{
834ULONG winstate = 0;
835
836 if(keystate & WMMOVE_LBUTTON)
837 winstate |= MK_LBUTTON;
838 if(keystate & WMMOVE_RBUTTON)
839 winstate |= MK_RBUTTON;
840 if(keystate & WMMOVE_MBUTTON)
841 winstate |= MK_MBUTTON;
842 if(keystate & WMMOVE_SHIFT)
843 winstate |= MK_SHIFT;
844 if(keystate & WMMOVE_CTRL)
845 winstate |= MK_CONTROL;
846
847 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
848}
849//******************************************************************************
850//******************************************************************************
851ULONG Win32Window::MsgPaint(ULONG tmp1, ULONG tmp2)
852{
853 return SendInternalMessageA(WM_PAINT, 0, 0);
854}
855//******************************************************************************
856//******************************************************************************
857ULONG Win32Window::MsgEraseBackGround(ULONG hps)
858{
859 if(isIcon) {
860 return SendInternalMessageA(WM_ICONERASEBKGND, hps, 0);
861 }
862 else return SendInternalMessageA(WM_ERASEBKGND, hps, 0);
863}
864//******************************************************************************
865//******************************************************************************
866ULONG Win32Window::MsgSetText(LPSTR lpsz, LONG cch)
867{
868 if(isUnicode) {
869 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
870 }
871 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
872}
873//******************************************************************************
874//******************************************************************************
875LRESULT Win32Window::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
876{
877 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
878 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
879
880 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
881 return(0);
882 }
883 switch(Msg)
884 {
885 case WM_CREATE:
886 {
887 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
888 dprintf(("WM_NCCREATE returned FALSE\n"));
889 return(-1); //don't create window
890 }
891 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
892 dprintf(("WM_CREATE returned -1\n"));
893 return(-1); //don't create window
894 }
895 NotifyParent(Msg, wParam, lParam);
896
897 return(0);
898 }
899 case WM_LBUTTONDOWN:
900 case WM_MBUTTONDOWN:
901 case WM_RBUTTONDOWN:
902 NotifyParent(Msg, wParam, lParam);
903 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
904
905 case WM_DESTROY:
906 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
907 NotifyParent(Msg, wParam, lParam);
908 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
909 default:
910 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
911 }
912}
913//******************************************************************************
914//******************************************************************************
915LRESULT Win32Window::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
916{
917 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
918 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
919
920 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
921 return(0);
922 }
923 switch(Msg)
924 {
925 case WM_CREATE:
926 {
927 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
928 dprintf(("WM_NCCREATE returned FALSE\n"));
929 return(0); //don't create window
930 }
931 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
932 dprintf(("WM_CREATE returned FALSE\n"));
933 return(0); //don't create window
934 }
935 NotifyParent(Msg, wParam, lParam);
936
937 return(1);
938 }
939 case WM_LBUTTONDOWN:
940 case WM_MBUTTONDOWN:
941 case WM_RBUTTONDOWN:
942 NotifyParent(Msg, wParam, lParam);
943 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
944
945 case WM_DESTROY:
946 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
947 NotifyParent(Msg, wParam, lParam);
948 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
949
950 default:
951 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
952 }
953}
954//******************************************************************************
955//Called as a result of an OS/2 message
956//******************************************************************************
957LRESULT Win32Window::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
958{
959 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
960 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
961
962 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
963 return(0);
964 }
965 switch(Msg)
966 {
967 case WM_CREATE:
968 {
969 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
970 dprintf(("WM_NCCREATE returned FALSE\n"));
971 return(0); //don't create window
972 }
973 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
974 dprintf(("WM_CREATE returned FALSE\n"));
975 return(0); //don't create window
976 }
977 NotifyParent(Msg, wParam, lParam);
978
979 return(1);
980 }
981 case WM_LBUTTONDOWN:
982 case WM_MBUTTONDOWN:
983 case WM_RBUTTONDOWN:
984 NotifyParent(Msg, wParam, lParam);
985 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
986
987 case WM_DESTROY:
988 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
989 NotifyParent(Msg, wParam, lParam);
990 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
991 default:
992 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
993 }
994}
995//******************************************************************************
996//Called as a result of an OS/2 message
997//todo, unicode msgs (WM_SETTEXT etc)
998//******************************************************************************
999LRESULT Win32Window::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1000{
1001 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1002 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1003
1004 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1005 return(0);
1006 }
1007 switch(Msg)
1008 {
1009 case WM_CREATE:
1010 {
1011 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1012 dprintf(("WM_NCCREATE returned FALSE\n"));
1013 return(0); //don't create window
1014 }
1015 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1016 dprintf(("WM_CREATE returned FALSE\n"));
1017 return(0); //don't create window
1018 }
1019 NotifyParent(Msg, wParam, lParam);
1020
1021 return(1);
1022 }
1023 case WM_LBUTTONDOWN:
1024 case WM_MBUTTONDOWN:
1025 case WM_RBUTTONDOWN:
1026 NotifyParent(Msg, wParam, lParam);
1027 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1028
1029 case WM_DESTROY:
1030 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1031 NotifyParent(Msg, wParam, lParam);
1032 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1033 default:
1034 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1035 }
1036}
1037//******************************************************************************
1038//******************************************************************************
1039BOOL Win32Window::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1040{
1041 POSTMSG_PACKET *postmsg;
1042
1043 postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
1044 if(postmsg == NULL) {
1045 dprintf(("Win32Window::PostMessageA: malloc returned NULL!!"));
1046 return 0;
1047 }
1048 postmsg->Msg = msg;
1049 postmsg->wParam = wParam;
1050 postmsg->lParam = lParam;
1051 return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEA, (ULONG)postmsg, 0);
1052}
1053//******************************************************************************
1054//******************************************************************************
1055BOOL Win32Window::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1056{
1057 POSTMSG_PACKET *postmsg;
1058
1059 postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
1060 if(postmsg == NULL) {
1061 dprintf(("Win32Window::PostMessageW: malloc returned NULL!!"));
1062 return 0;
1063 }
1064 postmsg->Msg = msg;
1065 postmsg->wParam = wParam;
1066 postmsg->lParam = lParam;
1067 return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEW, (ULONG)postmsg, 0);
1068}
1069//******************************************************************************
1070//TODO: do we need to inform the parent of the parent (etc) of the child window?
1071//******************************************************************************
1072void Win32Window::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1073{
1074 Win32Window *window = this;
1075 Win32Window *parentwindow;
1076
1077 while(window)
1078 {
1079 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1080 {
1081 /* Notify the parent window only */
1082 parentwindow = window->getParent();
1083 if(parentwindow) {
1084 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1085 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1086 }
1087 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1088 }
1089 }
1090 else break;
1091
1092 window = parentwindow;
1093 }
1094}
1095//******************************************************************************
1096//******************************************************************************
1097BOOL Win32Window::SetMenu(HMENU hMenu)
1098{
1099 PVOID menutemplate;
1100 Win32Resource *winres = (Win32Resource *)hMenu;
1101
1102 if(HIWORD(winres) == 0) {
1103 dprintf(("Win32Window:: Win32Resource *winres == 0"));
1104 SetLastError(ERROR_INVALID_PARAMETER);
1105 return FALSE;
1106 }
1107 menutemplate = winres->lockOS2Resource();
1108 if(menutemplate == NULL)
1109 {
1110 dprintf(("Win32Window::SetMenu menutemplate == 0"));
1111 return FALSE;
1112 }
1113 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1114 if(OS2HwndMenu == 0) {
1115 dprintf(("Win32Window::SetMenu OS2HwndMenu == 0"));
1116 return FALSE;
1117 }
1118 menuResource = winres;
1119 return TRUE;
1120}
1121//******************************************************************************
1122//******************************************************************************
1123BOOL Win32Window::SetAccelTable(HACCEL hAccel)
1124{
1125 Win32Resource *winres = (Win32Resource *)hAccel;
1126 HANDLE accelhandle;
1127
1128 if(HIWORD(hAccel) == 0) {
1129 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1130 SetLastError(ERROR_INVALID_PARAMETER);
1131 return FALSE;
1132 }
1133 acceltableResource = winres;
1134 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1135 winres->setOS2Handle(accelhandle);
1136 return(accelhandle != 0);
1137}
1138//******************************************************************************
1139//******************************************************************************
1140BOOL Win32Window::SetIcon(HICON hIcon)
1141{
1142 Win32Resource *winres = (Win32Resource *)hIcon;
1143 HANDLE iconhandle;
1144
1145 if(HIWORD(hIcon) == 0) {
1146 dprintf(("SetIcon: hIcon %x invalid", hIcon));
1147 SetLastError(ERROR_INVALID_PARAMETER);
1148 return FALSE;
1149 }
1150 dprintf(("Win32Window::SetIcon %x", hIcon));
1151 iconResource = winres;
1152 iconhandle = OSLibWinSetIcon(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1153 winres->setOS2Handle(iconhandle);
1154 return(iconhandle != 0);
1155}
1156//******************************************************************************
1157//******************************************************************************
1158BOOL Win32Window::ShowWindow(ULONG nCmdShow)
1159{
1160 ULONG showstate = 0;
1161
1162 dprintf(("ShowWindow %x", nCmdShow));
1163 switch(nCmdShow)
1164 {
1165 case SW_SHOW:
1166 case SW_SHOWDEFAULT: //todo
1167 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1168 break;
1169 case SW_HIDE:
1170 showstate = SWPOS_HIDE;
1171 break;
1172 case SW_RESTORE:
1173 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1174 break;
1175 case SW_MINIMIZE:
1176 showstate = SWPOS_MINIMIZE;
1177 break;
1178 case SW_SHOWMAXIMIZED:
1179 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1180 break;
1181 case SW_SHOWMINIMIZED:
1182 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1183 break;
1184 case SW_SHOWMINNOACTIVE:
1185 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1186 break;
1187 case SW_SHOWNA:
1188 showstate = SWPOS_SHOW;
1189 break;
1190 case SW_SHOWNOACTIVATE:
1191 showstate = SWPOS_SHOW;
1192 break;
1193 case SW_SHOWNORMAL:
1194 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1195 break;
1196 }
1197 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1198}
1199//******************************************************************************
1200//******************************************************************************
1201BOOL Win32Window::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1202{
1203 Win32Window *window;
1204 ULONG setstate = 0;
1205
1206 switch(hwndInsertAfter) {
1207 case HWND_BOTTOM:
1208 hwndInsertAfter = HWNDOS_BOTTOM;
1209 break;
1210 case HWND_TOPMOST: //TODO:
1211 case HWND_NOTOPMOST: //TODO:
1212 case HWND_TOP:
1213 hwndInsertAfter = HWNDOS_TOP;
1214 break;
1215 default:
1216 window = GetWindowFromHandle(hwndInsertAfter);
1217 if(window) {
1218 hwndInsertAfter = window->getOS2WindowHandle();
1219 }
1220 else {
1221 dprintf(("Win32Window::SetWindowPos, unknown hwndInsertAfter %x", hwndInsertAfter));
1222 hwndInsertAfter = 0;
1223 }
1224 break;
1225
1226 }
1227 setstate = SWPOS_MOVE | SWPOS_SIZE | SWPOS_ACTIVATE | SWPOS_ZORDER;
1228 if(fuFlags & SWP_DRAWFRAME)
1229 setstate |= 0; //TODO
1230 if(fuFlags & SWP_FRAMECHANGED)
1231 setstate |= 0; //TODO
1232 if(fuFlags & SWP_HIDEWINDOW)
1233 setstate &= ~SWPOS_ZORDER;
1234 if(fuFlags & SWP_NOACTIVATE)
1235 setstate &= ~SWPOS_ACTIVATE;
1236 if(fuFlags & SWP_NOCOPYBITS)
1237 setstate |= 0; //TODO
1238 if(fuFlags & SWP_NOMOVE)
1239 setstate &= ~SWPOS_MOVE;
1240 if(fuFlags & SWP_NOSIZE)
1241 setstate &= ~SWPOS_SIZE;
1242 if(fuFlags & SWP_NOREDRAW)
1243 setstate |= SWPOS_NOREDRAW;
1244 if(fuFlags & SWP_NOZORDER)
1245 setstate &= ~SWPOS_ZORDER;
1246 if(fuFlags & SWP_SHOWWINDOW)
1247 setstate |= SWPOS_SHOW;
1248
1249 return OSLibWinSetWindowPos(OS2HwndFrame, hwndInsertAfter, x, y, cx, cy, setstate);
1250}
1251//******************************************************************************
1252//Also destroys all the child windows (destroy parent, destroy children)
1253//******************************************************************************
1254BOOL Win32Window::DestroyWindow()
1255{
1256 return OSLibWinDestroyWindow(OS2HwndFrame);
1257}
1258//******************************************************************************
1259//******************************************************************************
1260HWND Win32Window::GetParent()
1261{
1262 if(getParent()) {
1263 return getParent()->getWindowHandle();
1264 }
1265 else return 0;
1266}
1267//******************************************************************************
1268//******************************************************************************
1269HWND Win32Window::SetParent(HWND hwndNewParent)
1270{
1271 HWND oldhwnd;
1272 Win32Window *newparent;
1273
1274 if(getParent()) {
1275 oldhwnd = getParent()->getWindowHandle();
1276 }
1277 else oldhwnd = 0;
1278
1279 if(hwndNewParent == 0) {//desktop window = parent
1280 setParent(NULL);
1281 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1282 return oldhwnd;
1283 }
1284 newparent = GetWindowFromHandle(hwndNewParent);
1285 if(newparent)
1286 {
1287 setParent(newparent);
1288 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1289 return oldhwnd;
1290 }
1291 SetLastError(ERROR_INVALID_PARAMETER);
1292 return 0;
1293}
1294//******************************************************************************
1295//******************************************************************************
1296BOOL Win32Window::IsChild(HWND hwndParent)
1297{
1298 if(getParent()) {
1299 return getParent()->getWindowHandle() == hwndParent;
1300 }
1301 else return 0;
1302}
1303//******************************************************************************
1304//******************************************************************************
1305HWND Win32Window::GetTopWindow()
1306{
1307 return GetWindow(GW_CHILD);
1308}
1309//******************************************************************************
1310//Don't call WinUpdateWindow as that one also updates the child windows
1311//Also need to send WM_PAINT directly to the window procedure, which doesn't
1312//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1313//******************************************************************************
1314BOOL Win32Window::UpdateWindow()
1315{
1316 RECT rect;
1317
1318 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1319 {//update region not empty
1320 SendInternalMessageA((isIcon) ? WM_PAINTICON : WM_PAINT, 0, 0);
1321 }
1322 return TRUE;
1323}
1324//******************************************************************************
1325//******************************************************************************
1326BOOL Win32Window::IsIconic()
1327{
1328 return OSLibWinIsIconic(OS2Hwnd);
1329}
1330//******************************************************************************
1331//TODO: not complete nor correct (distinction between top-level, top-most & child windows)
1332//******************************************************************************
1333HWND Win32Window::GetWindow(UINT uCmd)
1334{
1335 Win32Window *win32wnd;
1336 ULONG magic;
1337 ULONG getcmd = 0;
1338 HWND hwndRelated;
1339
1340 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1341 switch(uCmd)
1342 {
1343 case GW_CHILD:
1344 getcmd = QWOS_TOP;
1345 break;
1346 case GW_HWNDFIRST:
1347 if(getParent()) {
1348 getcmd = QWOS_TOP; //top of child windows
1349 }
1350 else getcmd = QWOS_TOP; //TODO
1351 break;
1352 case GW_HWNDLAST:
1353 if(getParent()) {
1354 getcmd = QWOS_BOTTOM; //bottom of child windows
1355 }
1356 else getcmd = QWOS_BOTTOM; //TODO
1357 break;
1358 case GW_HWNDNEXT:
1359 getcmd = QWOS_NEXT;
1360 break;
1361 case GW_HWNDPREV:
1362 getcmd = QWOS_PREV;
1363 break;
1364 case GW_OWNER:
1365 if(owner) {
1366 return owner->getWindowHandle();
1367 }
1368 else return 0;
1369 }
1370 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1371 if(hwndRelated)
1372 {
1373 win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1374 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1375 if(CheckMagicDword(magic) && win32wnd)
1376 {
1377 return win32wnd->getWindowHandle();
1378 }
1379 }
1380 return 0;
1381}
1382//******************************************************************************
1383//******************************************************************************
1384HWND Win32Window::SetActiveWindow()
1385{
1386 return OSLibWinSetActiveWindow(OS2Hwnd);
1387}
1388//******************************************************************************
1389//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1390//******************************************************************************
1391BOOL Win32Window::EnableWindow(BOOL fEnable)
1392{
1393 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1394}
1395//******************************************************************************
1396//******************************************************************************
1397BOOL Win32Window::CloseWindow()
1398{
1399 return OSLibWinMinimizeWindow(OS2Hwnd);
1400}
1401//******************************************************************************
1402//******************************************************************************
1403BOOL Win32Window::BringWindowToTop()
1404{
1405 return SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
1406}
1407//******************************************************************************
1408//******************************************************************************
1409HWND Win32Window::GetActiveWindow()
1410{
1411 HWND hwndActive;
1412 Win32Window *win32wnd;
1413 ULONG magic;
1414
1415 hwndActive = OSLibWinQueryActiveWindow();
1416
1417 win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1418 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1419 if(CheckMagicDword(magic) && win32wnd)
1420 {
1421 return win32wnd->getWindowHandle();
1422 }
1423 return hwndActive;
1424}
1425//******************************************************************************
1426//******************************************************************************
1427BOOL Win32Window::IsWindow()
1428{
1429 return TRUE;
1430}
1431//******************************************************************************
1432//******************************************************************************
1433BOOL Win32Window::IsWindowEnabled()
1434{
1435 return OSLibWinIsWindowEnabled(OS2Hwnd);
1436}
1437//******************************************************************************
1438//******************************************************************************
1439BOOL Win32Window::IsWindowVisible()
1440{
1441 return OSLibWinIsWindowVisible(OS2Hwnd);
1442}
1443//******************************************************************************
1444//******************************************************************************
1445BOOL Win32Window::GetWindowRect(PRECT pRect)
1446{
1447 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1448}
1449//******************************************************************************
1450//******************************************************************************
1451int Win32Window::GetWindowTextLengthA()
1452{
1453 return OSLibWinQueryWindowTextLength(OS2Hwnd);
1454}
1455//******************************************************************************
1456//******************************************************************************
1457int Win32Window::GetWindowTextA(LPSTR lpsz, int cch)
1458{
1459 return OSLibWinQueryWindowText(OS2Hwnd, cch, lpsz);
1460}
1461//******************************************************************************
1462//******************************************************************************
1463BOOL Win32Window::SetWindowTextA(LPCSTR lpsz)
1464{
1465 return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)lpsz);
1466}
1467//******************************************************************************
1468//******************************************************************************
1469LONG Win32Window::SetWindowLongA(int index, ULONG value)
1470{
1471 LONG oldval;
1472
1473 switch(index) {
1474 case GWL_EXSTYLE:
1475 oldval = dwExStyle;
1476 dwExStyle = value;
1477 return oldval;
1478 case GWL_STYLE:
1479 oldval = dwStyle;
1480 dwStyle = value;
1481 return oldval;
1482 case GWL_WNDPROC:
1483 oldval = (LONG)getWindowProc();
1484 setWindowProc((WNDPROC)value);
1485 return oldval;
1486 case GWL_HINSTANCE:
1487 oldval = hInstance;
1488 hInstance = value;
1489 return oldval;
1490 case GWL_HWNDPARENT:
1491 return SetParent((HWND)value);
1492
1493 case GWL_ID:
1494 oldval = getWindowId();
1495 setWindowId(value);
1496 return oldval;
1497 case GWL_USERDATA:
1498 oldval = userData;
1499 userData = value;
1500 return oldval;
1501 default:
1502 if(index >= 0 && index/4 < nrUserWindowLong)
1503 {
1504 oldval = userWindowLong[index/4];
1505 userWindowLong[index/4] = value;
1506 return oldval;
1507 }
1508 SetLastError(ERROR_INVALID_PARAMETER);
1509 return 0;
1510 }
1511}
1512//******************************************************************************
1513//******************************************************************************
1514ULONG Win32Window::GetWindowLongA(int index)
1515{
1516 switch(index) {
1517 case GWL_EXSTYLE:
1518 return dwExStyle;
1519 case GWL_STYLE:
1520 return dwStyle;
1521 case GWL_WNDPROC:
1522 return (ULONG)getWindowProc();
1523 case GWL_HINSTANCE:
1524 return hInstance;
1525 case GWL_HWNDPARENT:
1526 if(getParent()) {
1527 return getParent()->getWindowHandle();
1528 }
1529 else return 0;
1530 case GWL_ID:
1531 return getWindowId();
1532 case GWL_USERDATA:
1533 return userData;
1534 default:
1535 if(index >= 0 && index/4 < nrUserWindowLong)
1536 {
1537 return userWindowLong[index/4];
1538 }
1539 SetLastError(ERROR_INVALID_PARAMETER);
1540 return 0;
1541 }
1542}
1543//******************************************************************************
1544//******************************************************************************
1545WORD Win32Window::SetWindowWord(int index, WORD value)
1546{
1547 WORD oldval;
1548
1549 if(index >= 0 && index/4 < nrUserWindowLong)
1550 {
1551 oldval = ((WORD *)userWindowLong)[index/2];
1552 ((WORD *)userWindowLong)[index/2] = value;
1553 return oldval;
1554 }
1555 SetLastError(ERROR_INVALID_PARAMETER);
1556 return 0;
1557}
1558//******************************************************************************
1559//******************************************************************************
1560WORD Win32Window::GetWindowWord(int index)
1561{
1562 if(index >= 0 && index/4 < nrUserWindowLong)
1563 {
1564 return ((WORD *)userWindowLong)[index/2];
1565 }
1566 SetLastError(ERROR_INVALID_PARAMETER);
1567 return 0;
1568}
1569//******************************************************************************
1570//******************************************************************************
1571Win32Window *Win32Window::GetWindowFromHandle(HWND hwnd)
1572{
1573 Win32Window *window;
1574
1575 if(HIWORD(hwnd) != 0x6800) {
1576 return NULL;
1577 }
1578
1579 if(HMHandleTranslateToOS2(LOWORD(hwnd), (PULONG)&window) == NO_ERROR) {
1580 return window;
1581 }
1582 else return NULL;
1583}
1584//******************************************************************************
1585//******************************************************************************
1586Win32Window *Win32Window::GetWindowFromOS2Handle(HWND hwnd)
1587{
1588 Win32Window *win32wnd;
1589 DWORD magic;
1590
1591 win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
1592 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
1593
1594 if(win32wnd && CheckMagicDword(magic)) {
1595 return win32wnd;
1596 }
1597 return 0;
1598}
1599//******************************************************************************
1600//******************************************************************************
1601GenericObject *Win32Window::windows = NULL;
Note: See TracBrowser for help on using the repository browser.