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

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

* empty log message *

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