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

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

* empty log message *

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