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

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

Accelerator support (not working) + bugfixes

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