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

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

Point/Rectangle bug fixes

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