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

Last change on this file since 327 was 327, checked in by cbratschi, 26 years ago

API Open32 -> PM

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