source: trunk/src/user32/new/win32wbase.cpp@ 819

Last change on this file since 819 was 819, checked in by dengert, 26 years ago

begin DAXifying windows

File size: 72.1 KB
Line 
1/* $Id: win32wbase.cpp,v 1.6 1999-09-04 17:56:41 dengert Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include <spy.h>
28#include "wndmsg.h"
29#include "hooks.h"
30#include "oslibwin.h"
31#include "oslibutil.h"
32#include "oslibgdi.h"
33#include "oslibres.h"
34#include "oslibmenu.h"
35#include "oslibdos.h"
36#include "syscolor.h"
37#include "win32wndhandle.h"
38#include "heapshared.h"
39
40
41#define HAS_DLGFRAME(style,exStyle) \
42 (((exStyle) & WS_EX_DLGMODALFRAME) || \
43 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
44
45#define HAS_THICKFRAME(style) \
46 (((style) & WS_THICKFRAME) && \
47 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
48
49#define HAS_BORDER(style, exStyle) \
50 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
51
52#define IS_OVERLAPPED(style) \
53 !(style & (WS_CHILD | WS_POPUP))
54
55//******************************************************************************
56//******************************************************************************
57Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
58{
59 Init();
60}
61//******************************************************************************
62//******************************************************************************
63Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
64 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
65{
66 Init();
67 this->isUnicode = isUnicode;
68 CreateWindowExA(lpCreateStructA, classAtom);
69}
70//******************************************************************************
71//******************************************************************************
72void Win32BaseWindow::Init()
73{
74 isUnicode = FALSE;
75 fCreated = FALSE;
76 fFirstShow = TRUE;
77
78 windowNameA = NULL;
79 windowNameW = NULL;
80 wndNameLength = 0;
81
82 userWindowLong = NULL;;
83 nrUserWindowLong = 0;
84
85 magic = WIN32PM_MAGIC;
86 OS2Hwnd = 0;
87 OS2HwndFrame = 0;
88 OS2HwndMenu = 0;
89 Win32Hwnd = 0;
90
91 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
92 {
93 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
94 DebugInt3();
95 }
96
97 posx = posy = 0;
98 width = height = 0;
99
100 dwExStyle = 0;
101 dwStyle = 0;
102 win32wndproc = 0;
103 hInstance = 0;
104 windowId = 0xFFFFFFFF; //default = -1
105 userData = 0;
106
107 hwndLinkAfter = HWND_BOTTOM;
108 flags = 0;
109 isIcon = FALSE;
110 lastHitTestVal = 0;
111 owner = NULL;
112 windowClass = 0;
113
114 acceltableResource = NULL;
115 menuResource = NULL;
116 iconResource = NULL;
117}
118//******************************************************************************
119//todo get rid of resources (menu, accel, icon etc)
120//******************************************************************************
121Win32BaseWindow::~Win32BaseWindow()
122{
123 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
124 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
125
126 if(Win32Hwnd)
127 HwFreeWindowHandle(Win32Hwnd);
128
129 if(userWindowLong)
130 free(userWindowLong);
131 if(windowNameA) {
132 free(windowNameA);
133 windowNameA = NULL;
134 }
135 if(windowNameW) {
136 free(windowNameW);
137 windowNameW = NULL;
138 }
139}
140//******************************************************************************
141//******************************************************************************
142BOOL Win32BaseWindow::isChild()
143{
144 return (dwStyle & WS_CHILD) != 0;
145}
146//******************************************************************************
147//******************************************************************************
148BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
149{
150 char buffer[256];
151 INT sw = SW_SHOW;
152 POINT maxSize, maxPos, minTrack, maxTrack;
153
154 SetLastError(0);
155
156 /* Find the parent window */
157 if (cs->hwndParent)
158 {
159 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
160 if(!window) {
161 dprintf(("Bad parent %04x\n", cs->hwndParent ));
162 SetLastError(ERROR_INVALID_PARAMETER);
163 return FALSE;
164 }
165 /* Make sure parent is valid */
166 if (!window->IsWindow() )
167 {
168 dprintf(("Bad parent %04x\n", cs->hwndParent ));
169 SetLastError(ERROR_INVALID_PARAMETER);
170 return FALSE;
171 }
172 }
173 else
174 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
175 dprintf(("No parent for child window\n" ));
176 SetLastError(ERROR_INVALID_PARAMETER);
177 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
178 }
179
180 /* Find the window class */
181 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
182 if (!windowClass)
183 {
184 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
185 dprintf(("Bad class '%s'\n", buffer ));
186 return 0;
187 }
188
189 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
190 * with an atom as the class name, put some programs expect to have a *REAL* string in
191 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
192 */
193 if (!HIWORD(cs->lpszClass) ) {
194 if (isUnicode) {
195 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
196 }
197 else {
198 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
199 }
200 cs->lpszClass = buffer;
201 }
202
203 /* Fix the coordinates */
204 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
205 {
206// PDB *pdb = PROCESS_Current();
207
208 /* Never believe Microsoft's documentation... CreateWindowEx doc says
209 * that if an overlapped window is created with WS_VISIBLE style bit
210 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
211 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
212 * reveals that
213 *
214 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
215 * 2) it does not ignore the y parameter as the docs claim; instead, it
216 * uses it as second parameter to ShowWindow() unless y is either
217 * CW_USEDEFAULT or CW_USEDEFAULT16.
218 *
219 * The fact that we didn't do 2) caused bogus windows pop up when wine
220 * was running apps that were using this obscure feature. Example -
221 * calc.exe that comes with Win98 (only Win98, it's different from
222 * the one that comes with Win95 and NT)
223 */
224 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
225
226 /* We have saved cs->y, now we can trash it */
227#if 0
228 if ( !(cs->style & (WS_CHILD | WS_POPUP))
229 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
230 {
231 cs->x = pdb->env_db->startup_info->dwX;
232 cs->y = pdb->env_db->startup_info->dwY;
233 }
234#endif
235 cs->x = 0;
236 cs->y = 0;
237// }
238 }
239 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
240 {
241#if 0
242 PDB *pdb = PROCESS_Current();
243 if ( !(cs->style & (WS_CHILD | WS_POPUP))
244 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
245 {
246 cs->cx = pdb->env_db->startup_info->dwXSize;
247 cs->cy = pdb->env_db->startup_info->dwYSize;
248 }
249 else
250 {
251#endif
252 cs->cx = 600; /* FIXME */
253 cs->cy = 400;
254// }
255 }
256
257 if (cs->x < 0) cs->x = 0;
258 if (cs->y < 0) cs->y = 0;
259
260 //Allocate window words
261 nrUserWindowLong = windowClass->getExtraWndWords();
262 if(nrUserWindowLong) {
263 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
264 memset(userWindowLong, 0, nrUserWindowLong);
265 }
266
267 if ((cs->style & WS_CHILD) && cs->hwndParent)
268 {
269 SetParent(cs->hwndParent);
270 owner = GetWindowFromHandle(cs->hwndParent);
271 if(owner == NULL)
272 {
273 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
274 return FALSE;
275 }
276 }
277 else
278 {
279 if (!cs->hwndParent) {
280 owner = NULL;
281 }
282 else
283 {
284 owner = GetWindowFromHandle(cs->hwndParent);
285 if(owner == NULL)
286 {
287 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
288 return FALSE;
289 }
290 }
291 }
292
293 setWindowProc(windowClass->getWindowProc());
294 hInstance = cs->hInstance;
295 dwStyle = cs->style & ~WS_VISIBLE;
296 dwExStyle = cs->dwExStyle;
297
298 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
299 ? HWND_BOTTOM : HWND_TOP;
300
301#if 0
302//TODO
303 /* Call the WH_CBT hook */
304
305 if (HOOK_IsHooked( WH_CBT ))
306 {
307 CBT_CREATEWNDA cbtc;
308 LRESULT ret;
309
310 cbtc.lpcs = cs;
311 cbtc.hwndInsertAfter = hwndLinkAfter;
312 ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
313 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
314 if (ret)
315 {
316 TRACE_(win)("CBT-hook returned 0\n");
317 wndPtr->pDriver->pFinalize(wndPtr);
318 retvalue = 0;
319 goto end;
320 }
321 }
322#endif
323
324 /* Increment class window counter */
325 windowClass->IncreaseWindowCount();
326
327 /* Correct the window style */
328 if (!(cs->style & WS_CHILD))
329 {
330 dwStyle |= WS_CLIPSIBLINGS;
331 if (!(cs->style & WS_POPUP))
332 {
333 dwStyle |= WS_CAPTION;
334 flags |= WIN_NEED_SIZE;
335 }
336 }
337 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
338
339 //TODO?
340#if 0
341 /* Get class or window DC if needed */
342 if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
343 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
344 else wndPtr->dce = NULL;
345#endif
346
347 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
348 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
349 {
350 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
351 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
352 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
353 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
354 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
355 }
356
357 if(cs->style & WS_CHILD)
358 {
359 if(cs->cx < 0) cs->cx = 0;
360 if(cs->cy < 0) cs->cy = 0;
361 }
362 else
363 {
364 if (cs->cx <= 0) cs->cx = 1;
365 if (cs->cy <= 0) cs->cy = 1;
366 }
367
368 rectWindow.left = cs->x;
369 rectWindow.top = cs->y;
370 rectWindow.right = cs->x + cs->cx;
371 rectWindow.bottom = cs->y + cs->cy;
372 rectClient = rectWindow;
373
374 DWORD dwOSWinStyle, dwOSFrameStyle;
375
376 OSLibWinConvertStyle(cs->style, cs->dwExStyle, &dwOSWinStyle, &dwOSFrameStyle);
377
378 //TODO: Test
379#if 1
380 if(cs->style & WS_CHILD) {
381 dwOSFrameStyle = 0;
382 }
383#endif
384
385 if(cs->lpszName)
386 SetWindowText((LPSTR)cs->lpszName);
387
388 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
389 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
390 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
391 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
392 &OS2HwndFrame);
393
394 if(OS2Hwnd == 0) {
395 dprintf(("Window creation failed!!"));
396 return FALSE;
397 }
398
399 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
400 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
401 return FALSE;
402 }
403 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
404 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
405 return FALSE;
406 }
407 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
408 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
409 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
410 return FALSE;
411 }
412#if 0
413 if(OS2Hwnd != OS2HwndFrame) {
414 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
415 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
416 return FALSE;
417 }
418 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
419 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
420 return FALSE;
421 }
422 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
423 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
424 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
425 return FALSE;
426 }
427 }
428#endif
429
430 fakeWinBase.hwndThisObject = OS2Hwnd;
431 fakeWinBase.pWindowClass = windowClass;
432 *(PULONG)&fakeWinBase -= 0x90 - 8;
433// SetFakeOpen32();
434
435 /* Set the window menu */
436 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
437 {
438 if (cs->hMenu) SetMenu(cs->hMenu);
439 else
440 {
441 if (windowClass->getMenuNameA()) {
442 cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
443 if (cs->hMenu) SetMenu(cs->hMenu );
444 }
445 }
446 }
447 else windowId = (UINT)cs->hMenu;
448
449 //Set icon from class
450 if(windowClass->getIcon())
451 SetIcon(windowClass->getIcon());
452
453 if(getParent()) {
454 SetWindowPos(getParent()->getWindowHandle(), rectClient.left, rectClient.top,
455 rectClient.right-rectClient.left,
456 rectClient.bottom-rectClient.top,
457 SWP_NOACTIVATE | SWP_NOZORDER);
458 }
459 else {
460 SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
461 rectClient.right-rectClient.left,
462 rectClient.bottom-rectClient.top,
463 SWP_NOACTIVATE);
464 }
465 //Get the client window rectangle
466 GetClientRect(Win32Hwnd, &rectClient);
467
468 /* Send the WM_CREATE message
469 * Perhaps we shouldn't allow width/height changes as well.
470 * See p327 in "Internals".
471 */
472 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
473
474 fCreated = TRUE; //Allow WM_SIZE messages now
475 if(SendInternalMessage(WM_NCCREATE, 0, (LPARAM)cs) )
476 {
477 //doesn't work right, messes up client rectangle
478#if 0
479 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
480#endif
481 OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
482 dprintf(("Sending WM_CREATE"));
483 if( (SendInternalMessage(WM_CREATE, 0, (LPARAM)cs )) != -1 )
484 {
485 if(!(flags & WIN_NEED_SIZE)) {
486 SendMessageA(WM_SIZE, SIZE_RESTORED,
487 MAKELONG(rectClient.right-rectClient.left,
488 rectClient.bottom-rectClient.top));
489 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
490 }
491 if (cs->style & WS_VISIBLE) ShowWindow( sw );
492
493#if 0
494 /* Call WH_SHELL hook */
495
496 if (!(dwStyle & WS_CHILD) && !owner)
497 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
498#endif
499 SetLastError(0);
500 return TRUE;
501 }
502 }
503 fCreated = FALSE;
504 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
505 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
506 DestroyWindow();
507 return FALSE;
508}
509#if 0
510/***********************************************************************
511 * WINPOS_MinMaximize
512 *
513 * Fill in lpRect and return additional flags to be used with SetWindowPos().
514 * This function assumes that 'cmd' is different from the current window
515 * state.
516 */
517UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect )
518{
519 UINT swpFlags = 0;
520 POINT pt, size;
521 LPINTERNALPOS lpPos;
522
523 size.x = rectWindow.left; size.y = rectWindow.top;
524 lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
525
526 if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
527 {
528 if( dwStyle & WS_MINIMIZE )
529 {
530 if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
531 return (SWP_NOSIZE | SWP_NOMOVE);
532 swpFlags |= SWP_NOCOPYBITS;
533 }
534 switch( cmd )
535 {
536 case SW_MINIMIZE:
537 if( dwStyle & WS_MAXIMIZE)
538 {
539 flags |= WIN_RESTORE_MAX;
540 dwStyle &= ~WS_MAXIMIZE;
541 }
542 else
543 flags &= ~WIN_RESTORE_MAX;
544 dwStyle |= WS_MINIMIZE;
545
546#if 0
547 if( flags & WIN_NATIVE )
548 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
549 swpFlags |= MINMAX_NOSWP;
550#endif
551
552 lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
553
554 SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
555 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
556 swpFlags |= SWP_NOCOPYBITS;
557 break;
558
559 case SW_MAXIMIZE:
560 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
561
562 if( dwStyle & WS_MINIMIZE )
563 {
564 if( flags & WIN_NATIVE )
565 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
566 swpFlags |= MINMAX_NOSWP;
567
568 WINPOS_ShowIconTitle( wndPtr, FALSE );
569 dwStyle &= ~WS_MINIMIZE;
570 }
571 dwStyle |= WS_MAXIMIZE;
572
573 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
574 size.x, size.y );
575 break;
576
577 case SW_RESTORE:
578 if( dwStyle & WS_MINIMIZE )
579 {
580 if( flags & WIN_NATIVE )
581 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
582 swpFlags |= MINMAX_NOSWP;
583
584 dwStyle &= ~WS_MINIMIZE;
585 WINPOS_ShowIconTitle( wndPtr, FALSE );
586
587 if( flags & WIN_RESTORE_MAX)
588 {
589 /* Restore to maximized position */
590 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
591 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
592 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
593 dwStyle |= WS_MAXIMIZE;
594 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
595 break;
596 }
597 }
598 else
599 if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
600 else dwStyle &= ~WS_MAXIMIZE;
601
602 /* Restore to normal position */
603
604 *lpRect = lpPos->rectNormal;
605 lpRect->right -= lpRect->left;
606 lpRect->bottom -= lpRect->top;
607
608 break;
609 }
610 } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
611 return swpFlags;
612}
613#endif
614/*******************************************************************
615 * GetMinMaxInfo
616 *
617 * Get the minimized and maximized information for a window.
618 */
619void Win32BaseWindow::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
620 POINT *minTrack, POINT *maxTrack )
621{
622 MINMAXINFO MinMax;
623 INT xinc, yinc;
624
625 /* Compute default values */
626
627 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
628 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
629 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
630 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
631 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
632 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
633
634 if (flags & WIN_MANAGED) xinc = yinc = 0;
635 else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
636 {
637 xinc = GetSystemMetrics(SM_CXDLGFRAME);
638 yinc = GetSystemMetrics(SM_CYDLGFRAME);
639 }
640 else
641 {
642 xinc = yinc = 0;
643 if (HAS_THICKFRAME(dwStyle))
644 {
645 xinc += GetSystemMetrics(SM_CXFRAME);
646 yinc += GetSystemMetrics(SM_CYFRAME);
647 }
648 if (dwStyle & WS_BORDER)
649 {
650 xinc += GetSystemMetrics(SM_CXBORDER);
651 yinc += GetSystemMetrics(SM_CYBORDER);
652 }
653 }
654 MinMax.ptMaxSize.x += 2 * xinc;
655 MinMax.ptMaxSize.y += 2 * yinc;
656
657#if 0
658 lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
659 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
660 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
661 else
662 {
663#endif
664 MinMax.ptMaxPosition.x = -xinc;
665 MinMax.ptMaxPosition.y = -yinc;
666// }
667
668 SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
669
670 /* Some sanity checks */
671
672 dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
673 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
674 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
675 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
676 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
677 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
678 MinMax.ptMinTrackSize.x );
679 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
680 MinMax.ptMinTrackSize.y );
681
682 if (maxSize) *maxSize = MinMax.ptMaxSize;
683 if (maxPos) *maxPos = MinMax.ptMaxPosition;
684 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
685 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
686}
687/***********************************************************************
688 * WINPOS_SendNCCalcSize
689 *
690 * Send a WM_NCCALCSIZE message to a window.
691 * All parameters are read-only except newClientRect.
692 * oldWindowRect, oldClientRect and winpos must be non-NULL only
693 * when calcValidRect is TRUE.
694 */
695LONG Win32BaseWindow::SendNCCalcSize(BOOL calcValidRect, RECT *newWindowRect, RECT *oldWindowRect,
696 RECT *oldClientRect, WINDOWPOS *winpos,
697 RECT *newClientRect )
698{
699 NCCALCSIZE_PARAMS params;
700 WINDOWPOS winposCopy;
701 LONG result;
702
703 params.rgrc[0] = *newWindowRect;
704 if (calcValidRect)
705 {
706 winposCopy = *winpos;
707 params.rgrc[1] = *oldWindowRect;
708 params.rgrc[2] = *oldClientRect;
709 params.lppos = &winposCopy;
710 }
711 result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
712 (LPARAM)&params );
713 *newClientRect = params.rgrc[0];
714 return result;
715}
716//******************************************************************************
717//******************************************************************************
718ULONG Win32BaseWindow::MsgCreate(HWND hwndOS2, ULONG initParam)
719{
720 OS2Hwnd = hwndOS2;
721 return SendInternalMessageA(WM_CREATE, 0, initParam);
722}
723//******************************************************************************
724//******************************************************************************
725ULONG Win32BaseWindow::MsgQuit()
726{
727 return SendInternalMessageA(WM_QUIT, 0, 0);
728}
729//******************************************************************************
730//******************************************************************************
731ULONG Win32BaseWindow::MsgClose()
732{
733 if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
734 return 0; //app handles this message
735 }
736 delete this;
737 return 1;
738}
739//******************************************************************************
740//******************************************************************************
741ULONG Win32BaseWindow::MsgDestroy()
742{
743 ULONG rc;
744
745 rc = SendInternalMessageA(WM_DESTROY, 0, 0);
746 delete this;
747 return rc;
748}
749//******************************************************************************
750//******************************************************************************
751ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
752{
753 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
754}
755//******************************************************************************
756//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
757//******************************************************************************
758ULONG Win32BaseWindow::MsgShow(BOOL fShow)
759{
760 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
761}
762//******************************************************************************
763//******************************************************************************
764ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
765{
766 dprintf(("MsgPosChanging"));
767#if 1
768 if(fCreated == FALSE) {
769 return 1;
770 }
771#endif
772 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
773}
774//******************************************************************************
775//******************************************************************************
776ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
777{
778 dprintf(("MsgPosChanged"));
779#if 1
780 if(fCreated == FALSE) {
781 return 1;
782 }
783#endif
784 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
785}
786//******************************************************************************
787//******************************************************************************
788ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
789{
790 dprintf(("MsgMove to (%d,%d)", x, y));
791 if(fCreated == FALSE) {
792 return 1;
793 }
794
795 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
796}
797//******************************************************************************
798//******************************************************************************
799ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
800{
801 switch(cmd) {
802 case CMD_MENU:
803 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
804 case CMD_CONTROL:
805 return 0; //todo
806 case CMD_ACCELERATOR:
807 dprintf(("accelerator command"));
808 return 0; //todo
809 }
810 return 0;
811}
812//******************************************************************************
813//******************************************************************************
814ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
815{
816 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
817 return 1; //TODO: May need to change this
818}
819//******************************************************************************
820//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
821//******************************************************************************
822ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
823{
824 WORD fwSizeType = 0;
825
826 if(fCreated == FALSE) {//Solitaire crashes if it receives a WM_SIZE during CreateWindowEx (normal or our fault?)
827 return 1;
828 }
829
830 if(fMinimize) {
831 fwSizeType = SIZE_MINIMIZED;
832 }
833 else
834 if(fMaximize) {
835 fwSizeType = SIZE_MAXIMIZED;
836 }
837 else fwSizeType = SIZE_RESTORED;
838
839 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
840}
841//******************************************************************************
842//******************************************************************************
843ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, HWND hwnd)
844{
845 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE)
846 {
847 if(!fActivate) {
848 return 1;
849 }
850 }
851 return SendInternalMessageA(WM_ACTIVATE, (fActivate) ? WA_ACTIVE : WA_INACTIVE, hwnd);
852}
853//******************************************************************************
854//******************************************************************************
855ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
856{
857 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
858}
859//******************************************************************************
860//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
861//******************************************************************************
862ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
863{
864 ULONG lParam = 0;
865
866 lParam = repeatcnt;
867 lParam |= (scancode << 16);
868 if(keyflags & KEY_ALTDOWN)
869 lParam |= (1<<29);
870 if(keyflags & KEY_PREVDOWN)
871 lParam |= (1<<30);
872 if(keyflags & KEY_UP)
873 lParam |= (1<<31);
874 if(keyflags & KEY_DEADKEY) {
875 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
876 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
877 }
878 else {
879 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
880 return SendInternalMessageA(WM_CHAR, cmd, lParam);
881 }
882}
883//******************************************************************************
884//******************************************************************************
885ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
886{
887 if(hwnd == 0) {
888 //other app lost focus
889 SendInternalMessageA(WM_ACTIVATEAPP, TRUE, 0); //TODO: Need thread id from hwnd app
890 }
891 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
892}
893//******************************************************************************
894//******************************************************************************
895ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
896{
897 if(hwnd == 0) {
898 //other app lost focus
899 SendInternalMessageA(WM_ACTIVATEAPP, FALSE, 0); //TODO: Need thread id from hwnd app
900 }
901 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
902}
903//******************************************************************************
904//******************************************************************************
905ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
906{
907 ULONG win32msg;
908 ULONG win32ncmsg;
909
910 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
911 switch(msg) {
912 case BUTTON_LEFTDOWN:
913 win32msg = WM_LBUTTONDOWN;
914 win32ncmsg = WM_NCLBUTTONDOWN;
915 break;
916 case BUTTON_LEFTUP:
917 win32msg = WM_LBUTTONUP;
918 win32ncmsg = WM_NCLBUTTONUP;
919 break;
920 case BUTTON_LEFTDBLCLICK:
921 win32msg = WM_LBUTTONDBLCLK;
922 win32ncmsg = WM_NCLBUTTONDBLCLK;
923 break;
924 case BUTTON_RIGHTUP:
925 win32msg = WM_RBUTTONUP;
926 win32ncmsg = WM_NCRBUTTONUP;
927 break;
928 case BUTTON_RIGHTDOWN:
929 win32msg = WM_RBUTTONDOWN;
930 win32ncmsg = WM_NCRBUTTONDOWN;
931 break;
932 case BUTTON_RIGHTDBLCLICK:
933 win32msg = WM_RBUTTONDBLCLK;
934 win32ncmsg = WM_NCRBUTTONDBLCLK;
935 break;
936 case BUTTON_MIDDLEUP:
937 win32msg = WM_MBUTTONUP;
938 win32ncmsg = WM_NCMBUTTONUP;
939 break;
940 case BUTTON_MIDDLEDOWN:
941 win32msg = WM_MBUTTONDOWN;
942 win32ncmsg = WM_NCMBUTTONDOWN;
943 break;
944 case BUTTON_MIDDLEDBLCLICK:
945 win32msg = WM_MBUTTONDBLCLK;
946 win32ncmsg = WM_NCMBUTTONDBLCLK;
947 break;
948 default:
949 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
950 return 1;
951 }
952 if(win32msg == WM_MBUTTONDBLCLK || win32msg == WM_RBUTTONDBLCLK || win32msg == WM_LBUTTONDBLCLK) {
953 if(!(windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)) {
954 return 1;
955 }
956 }
957 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
958
959 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
960 if(lastHitTestVal != HTCLIENT) {
961 SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
962 }
963 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
964}
965//******************************************************************************
966//******************************************************************************
967ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
968{
969 ULONG winstate = 0;
970 ULONG setcursormsg = WM_MOUSEMOVE;
971
972 if(keystate & WMMOVE_LBUTTON)
973 winstate |= MK_LBUTTON;
974 if(keystate & WMMOVE_RBUTTON)
975 winstate |= MK_RBUTTON;
976 if(keystate & WMMOVE_MBUTTON)
977 winstate |= MK_MBUTTON;
978 if(keystate & WMMOVE_SHIFT)
979 winstate |= MK_SHIFT;
980 if(keystate & WMMOVE_CTRL)
981 winstate |= MK_CONTROL;
982
983 if(lastHitTestVal != HTCLIENT) {
984 setcursormsg = WM_NCMOUSEMOVE;
985 }
986 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
987 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
988
989 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
990 if(lastHitTestVal != HTCLIENT) {
991 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
992 }
993 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
994}
995//******************************************************************************
996//******************************************************************************
997ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, ULONG tmp2)
998{
999 return SendInternalMessageA(WM_PAINT, 0, 0);
1000}
1001//******************************************************************************
1002//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1003// (or are we simply erasing too much here)
1004//******************************************************************************
1005ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1006{
1007 ULONG rc;
1008 HDC hdcErase = hdc;
1009
1010 if (hdcErase == 0)
1011 hdcErase = O32_GetDC(OS2Hwnd);
1012
1013 if(isIcon)
1014 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1015 else
1016 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1017 if (hdc == 0)
1018 O32_ReleaseDC(OS2Hwnd, hdcErase);
1019 return (rc);
1020}
1021//******************************************************************************
1022//******************************************************************************
1023ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1024{
1025 if(isUnicode) {
1026 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1027 }
1028 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1029}
1030//******************************************************************************
1031//TODO: in- or excluding terminating 0?
1032//******************************************************************************
1033ULONG Win32BaseWindow::MsgGetTextLength()
1034{
1035 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1036}
1037//******************************************************************************
1038//******************************************************************************
1039char *Win32BaseWindow::MsgGetText()
1040{
1041 if(isUnicode) {
1042 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1043 }
1044 else {
1045 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1046 }
1047 return windowNameA;
1048}
1049//******************************************************************************
1050//******************************************************************************
1051LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1052{
1053 switch(Msg)
1054 {
1055 case WM_GETTEXTLENGTH:
1056 return wndNameLength;
1057
1058 case WM_GETTEXT: //TODO: SS_ICON controls
1059 strncpy((LPSTR)lParam, windowNameA, wParam);
1060 return min(wndNameLength, wParam);
1061
1062 case WM_SETTEXT:
1063 return 0;
1064
1065 case WM_SETREDRAW:
1066 if(wParam)
1067 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1068 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1069
1070 return 0; //TODO
1071
1072 case WM_NCCREATE:
1073 return(TRUE);
1074
1075 case WM_CTLCOLORMSGBOX:
1076 case WM_CTLCOLOREDIT:
1077 case WM_CTLCOLORLISTBOX:
1078 case WM_CTLCOLORBTN:
1079 case WM_CTLCOLORDLG:
1080 case WM_CTLCOLORSTATIC:
1081 case WM_CTLCOLORSCROLLBAR:
1082 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1083 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1084 return GetSysColorBrush(COLOR_BTNFACE);
1085
1086 case WM_PARENTNOTIFY:
1087 return 0;
1088
1089 case WM_MOUSEACTIVATE:
1090 {
1091 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1092 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1093 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1094 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1095 {
1096 if(getParent()) {
1097 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1098 if(rc) return rc;
1099 }
1100 }
1101 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1102 }
1103 case WM_SETCURSOR:
1104 {
1105 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1106 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1107 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1108 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1109 {
1110 if(getParent()) {
1111 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1112 if(rc) return rc;
1113 }
1114 }
1115 return 1;
1116 }
1117 case WM_MOUSEMOVE:
1118 return 0;
1119
1120 case WM_WINDOWPOSCHANGED:
1121 {
1122
1123/* undocumented SWP flags - from SDK 3.1 */
1124#define SWP_NOCLIENTSIZE 0x0800
1125#define SWP_NOCLIENTMOVE 0x1000
1126
1127 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1128 WPARAM wp = SIZE_RESTORED;
1129
1130 if (!(wpos->flags & SWP_NOCLIENTMOVE))
1131 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1132
1133 if (!(wpos->flags & SWP_NOCLIENTSIZE))
1134 {
1135 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1136 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1137
1138 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1139 rectClient.bottom - rectClient.top));
1140 }
1141 return 0;
1142 }
1143 case WM_ERASEBKGND:
1144 case WM_ICONERASEBKGND:
1145 {
1146 RECT rect;
1147 int rc;
1148
1149 if (!windowClass->getBackgroundBrush()) return 0;
1150
1151 /* Since WM_ERASEBKGND may receive either a window dc or a */
1152 /* client dc, the area to be erased has to be retrieved from */
1153 /* the device context. */
1154 rc = GetClipBox( (HDC)wParam, &rect );
1155 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1156 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1157
1158 return 1;
1159 }
1160
1161 case WM_NCLBUTTONDOWN:
1162 case WM_NCLBUTTONUP:
1163 case WM_NCLBUTTONDBLCLK:
1164 case WM_NCRBUTTONUP:
1165 case WM_NCRBUTTONDOWN:
1166 case WM_NCRBUTTONDBLCLK:
1167 case WM_NCMBUTTONDOWN:
1168 case WM_NCMBUTTONUP:
1169 case WM_NCMBUTTONDBLCLK:
1170 return 0; //TODO: Send WM_SYSCOMMAND if required
1171
1172 case WM_NCHITTEST: //TODO: Calculate position of
1173 return HTCLIENT;
1174
1175 default:
1176 return 1;
1177 }
1178}
1179//******************************************************************************
1180//******************************************************************************
1181LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1182{
1183 switch(Msg)
1184 {
1185 case WM_GETTEXTLENGTH:
1186 return wndNameLength;
1187
1188 case WM_GETTEXT: //TODO: SS_ICON controls
1189 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1190 return min(wndNameLength, wParam);
1191
1192 default:
1193 return DefWindowProcA(Msg, wParam, lParam);
1194 }
1195}
1196//******************************************************************************
1197//******************************************************************************
1198LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1199{
1200 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1201 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1202
1203 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1204 return(0);
1205 }
1206 switch(Msg)
1207 {
1208 case WM_CREATE:
1209 {
1210 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1211 dprintf(("WM_NCCREATE returned FALSE\n"));
1212 return(-1); //don't create window
1213 }
1214 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1215 dprintf(("WM_CREATE returned -1\n"));
1216 return(-1); //don't create window
1217 }
1218 NotifyParent(Msg, wParam, lParam);
1219
1220 return(0);
1221 }
1222 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1223 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1224
1225 case WM_LBUTTONDOWN:
1226 case WM_MBUTTONDOWN:
1227 case WM_RBUTTONDOWN:
1228 NotifyParent(Msg, wParam, lParam);
1229 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1230
1231 case WM_DESTROY:
1232 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1233 NotifyParent(Msg, wParam, lParam);
1234 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1235 default:
1236 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1237 }
1238}
1239//******************************************************************************
1240//******************************************************************************
1241LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1242{
1243 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1244 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1245
1246 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1247 return(0);
1248 }
1249 switch(Msg)
1250 {
1251 case WM_CREATE:
1252 {
1253 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1254 dprintf(("WM_NCCREATE returned FALSE\n"));
1255 return(0); //don't create window
1256 }
1257 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1258 dprintf(("WM_CREATE returned FALSE\n"));
1259 return(0); //don't create window
1260 }
1261 NotifyParent(Msg, wParam, lParam);
1262
1263 return(1);
1264 }
1265 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1266 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1267
1268 case WM_LBUTTONDOWN:
1269 case WM_MBUTTONDOWN:
1270 case WM_RBUTTONDOWN:
1271 NotifyParent(Msg, wParam, lParam);
1272 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1273
1274 case WM_DESTROY:
1275 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1276 NotifyParent(Msg, wParam, lParam);
1277 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1278
1279 default:
1280 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1281 }
1282}
1283//******************************************************************************
1284//Called as a result of an OS/2 message
1285//******************************************************************************
1286LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1287{
1288 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1289 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1290
1291 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1292 return(0);
1293 }
1294 switch(Msg)
1295 {
1296 case WM_CREATE:
1297 {
1298 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1299 dprintf(("WM_NCCREATE returned FALSE\n"));
1300 return(0); //don't create window
1301 }
1302 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1303 dprintf(("WM_CREATE returned FALSE\n"));
1304 return(0); //don't create window
1305 }
1306 NotifyParent(Msg, wParam, lParam);
1307
1308 return(1);
1309 }
1310 case WM_LBUTTONDOWN:
1311 case WM_MBUTTONDOWN:
1312 case WM_RBUTTONDOWN:
1313 NotifyParent(Msg, wParam, lParam);
1314 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1315
1316 case WM_DESTROY:
1317 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1318 NotifyParent(Msg, wParam, lParam);
1319 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1320 default:
1321 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1322 }
1323}
1324//******************************************************************************
1325//Called as a result of an OS/2 message
1326//todo, unicode msgs (WM_SETTEXT etc)
1327//******************************************************************************
1328LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1329{
1330 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1331 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1332
1333 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1334 return(0);
1335 }
1336 switch(Msg)
1337 {
1338 case WM_CREATE:
1339 {
1340 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1341 dprintf(("WM_NCCREATE returned FALSE\n"));
1342 return(0); //don't create window
1343 }
1344 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1345 dprintf(("WM_CREATE returned FALSE\n"));
1346 return(0); //don't create window
1347 }
1348 NotifyParent(Msg, wParam, lParam);
1349
1350 return(1);
1351 }
1352 case WM_LBUTTONDOWN:
1353 case WM_MBUTTONDOWN:
1354 case WM_RBUTTONDOWN:
1355 NotifyParent(Msg, wParam, lParam);
1356 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1357
1358 case WM_DESTROY:
1359 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1360 NotifyParent(Msg, wParam, lParam);
1361 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1362 default:
1363 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1364 }
1365}
1366//******************************************************************************
1367//******************************************************************************
1368BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1369{
1370 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1371}
1372//******************************************************************************
1373//******************************************************************************
1374BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1375{
1376 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1377}
1378//******************************************************************************
1379//TODO: do we need to inform the parent of the parent (etc) of the child window?
1380//******************************************************************************
1381void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1382{
1383 Win32BaseWindow *window = this;
1384 Win32BaseWindow *parentwindow;
1385
1386 while(window)
1387 {
1388 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1389 {
1390 /* Notify the parent window only */
1391 parentwindow = window->getParent();
1392 if(parentwindow) {
1393 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1394 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1395 }
1396 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1397 }
1398 }
1399 else break;
1400
1401 window = parentwindow;
1402 }
1403}
1404//******************************************************************************
1405//******************************************************************************
1406BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1407{
1408 PVOID menutemplate;
1409 Win32Resource *winres = (Win32Resource *)hMenu;
1410
1411 dprintf(("SetMenu %x", hMenu));
1412 if(HIWORD(winres) == 0) {
1413 dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
1414 SetLastError(ERROR_INVALID_PARAMETER);
1415 return FALSE;
1416 }
1417 menutemplate = winres->lockOS2Resource();
1418 if(menutemplate == NULL)
1419 {
1420 dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
1421 return FALSE;
1422 }
1423 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1424 if(OS2HwndMenu == 0) {
1425 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1426 return FALSE;
1427 }
1428 winres->setOS2Handle(OS2HwndMenu);
1429 menuResource = winres;
1430 return TRUE;
1431}
1432//******************************************************************************
1433//******************************************************************************
1434BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1435{
1436 Win32Resource *winres = (Win32Resource *)hAccel;
1437 HANDLE accelhandle;
1438
1439 if(HIWORD(hAccel) == 0) {
1440 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1441 SetLastError(ERROR_INVALID_PARAMETER);
1442 return FALSE;
1443 }
1444 acceltableResource = winres;
1445 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1446 winres->setOS2Handle(accelhandle);
1447 return(accelhandle != 0);
1448}
1449//******************************************************************************
1450//******************************************************************************
1451BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1452{
1453 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1454 return OSLibWinSetIcon(OS2HwndFrame, hIcon);
1455}
1456//******************************************************************************
1457//******************************************************************************
1458BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1459{
1460 ULONG showstate = 0;
1461
1462 dprintf(("ShowWindow %x", nCmdShow));
1463 if(fFirstShow) {
1464 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1465 SendMessageA(WM_SIZE, SIZE_RESTORED,
1466 MAKELONG(rectClient.right-rectClient.left,
1467 rectClient.bottom-rectClient.top));
1468 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1469
1470 }
1471 fFirstShow = FALSE;
1472 }
1473 switch(nCmdShow)
1474 {
1475 case SW_SHOW:
1476 case SW_SHOWDEFAULT: //todo
1477 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1478 break;
1479 case SW_HIDE:
1480 showstate = SWPOS_HIDE;
1481 break;
1482 case SW_RESTORE:
1483 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1484 break;
1485 case SW_MINIMIZE:
1486 showstate = SWPOS_MINIMIZE;
1487 break;
1488 case SW_SHOWMAXIMIZED:
1489 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1490 break;
1491 case SW_SHOWMINIMIZED:
1492 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1493 break;
1494 case SW_SHOWMINNOACTIVE:
1495 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1496 break;
1497 case SW_SHOWNA:
1498 showstate = SWPOS_SHOW;
1499 break;
1500 case SW_SHOWNOACTIVATE:
1501 showstate = SWPOS_SHOW;
1502 break;
1503 case SW_SHOWNORMAL:
1504 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1505 break;
1506 }
1507 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1508}
1509//******************************************************************************
1510//******************************************************************************
1511BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1512{
1513 BOOL rc = FALSE;
1514 Win32BaseWindow *window;
1515 HWND hParent = 0;
1516
1517 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1518
1519 /* Validate the flags passed in ... */
1520 if ( fuFlags &
1521 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1522 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1523 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1524 SWP_NOOWNERZORDER) )
1525 {
1526 return FALSE;
1527 }
1528
1529 WINDOWPOS wpos;
1530 SWP swp, swpOld;
1531
1532 //****************************
1533 // Set up with Windows values.
1534 //****************************
1535 wpos.flags = fuFlags;
1536 wpos.cy = cy;
1537 wpos.cx = cx;
1538 wpos.x = x;
1539 wpos.y = y;
1540 wpos.hwndInsertAfter = hwndInsertAfter;
1541 wpos.hwnd = getWindowHandle();
1542
1543 //**********************************************
1544 // Convert from Windows to PM coords and flags.
1545 //**********************************************
1546 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1547 if (isChild())
1548 {
1549 hParent = getParent()->getOS2WindowHandle();
1550 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1551 } else
1552 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1553 }
1554 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1555
1556 /* MapSWP can clear the SWP_MOVE and SWP_SIZE flags if the window is not
1557 * being moved or sized. If these were the only operations to be done
1558 * and they have been cleared, return now.
1559 */
1560 if (swp.fl == 0)
1561 return TRUE;
1562
1563 //*********************************************************************
1564 //On Windows, a WM_GETMINMAXINFO is made to the app from within this API.
1565 //We'll send a WM_QUERYTRACKINFO which is translated into a WM_GETMINMAXINFO
1566 //and passed on to the app. Compare the values returned with the SWP cx and
1567 //cy values. They cannot be bigger than the max nor smaller than the min.
1568 //*********************************************************************
1569
1570 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1571 {
1572 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1573 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1574 }
1575 if (isFrameWindow())
1576 {
1577 POINT maxSize, maxPos, minTrack, maxTrack;
1578
1579 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1580
1581 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1582 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1583 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1584 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1585 swp.hwnd = OS2HwndFrame;
1586 } else
1587 swp.hwnd = OS2Hwnd;
1588 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1589
1590 //*****************************************************************************
1591 // Squibble the window. (WinSetMultWindowPos is faster than WinSetWindowPos.)
1592 //*****************************************************************************
1593 rc = OSLibWinSetMultWindowPos(&swp, 1);
1594
1595 if (rc == FALSE)
1596 {
1597// SET_ERROR_LAST();
1598 }
1599 else
1600 {
1601 /* To implement support for SWP_FRAMECHANGED_W correctly, we would need
1602 ** to send a WM_NCCALCSIZE message. This means DAX would have to support
1603 ** the WM_NCCALCSIZE message. I don't think DAX can support this
1604 ** message because it is tightly bound with the architecture of
1605 ** overlapped windows (the "just one window" architecture). However,
1606 ** we *can* support the SWP_FRAMECHANGED flag by sending the window
1607 ** a WM_UPDATEFRAME, which will provide the behavior of WM_NCCALCSIZE.
1608 */
1609// if (fuFlags & SWP_FRAMECHANGED_W)
1610// WinSendMsg(hWindow, WM_UPDATEFRAME, (MPARAM)-1, 0);
1611 }
1612
1613 return (rc);
1614}
1615//******************************************************************************
1616//Also destroys all the child windows (destroy parent, destroy children)
1617//******************************************************************************
1618BOOL Win32BaseWindow::DestroyWindow()
1619{
1620 return OSLibWinDestroyWindow(OS2HwndFrame);
1621}
1622//******************************************************************************
1623//******************************************************************************
1624HWND Win32BaseWindow::GetParent()
1625{
1626 if(getParent()) {
1627 return getParent()->getWindowHandle();
1628 }
1629 else return 0;
1630}
1631//******************************************************************************
1632//******************************************************************************
1633HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1634{
1635 HWND oldhwnd;
1636 Win32BaseWindow *newparent;
1637
1638 if(getParent()) {
1639 oldhwnd = getParent()->getWindowHandle();
1640 }
1641 else oldhwnd = 0;
1642
1643 if(hwndNewParent == 0) {//desktop window = parent
1644 setParent(NULL);
1645 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1646 return oldhwnd;
1647 }
1648 newparent = GetWindowFromHandle(hwndNewParent);
1649 if(newparent)
1650 {
1651 setParent(newparent);
1652 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1653 return oldhwnd;
1654 }
1655 SetLastError(ERROR_INVALID_PARAMETER);
1656 return 0;
1657}
1658//******************************************************************************
1659//******************************************************************************
1660BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1661{
1662 if(getParent()) {
1663 return getParent()->getWindowHandle() == hwndParent;
1664 }
1665 else return 0;
1666}
1667//******************************************************************************
1668//******************************************************************************
1669HWND Win32BaseWindow::GetTopWindow()
1670{
1671 return GetWindow(GW_CHILD);
1672}
1673//******************************************************************************
1674//Don't call WinUpdateWindow as that one also updates the child windows
1675//Also need to send WM_PAINT directly to the window procedure, which doesn't
1676//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1677//******************************************************************************
1678BOOL Win32BaseWindow::UpdateWindow()
1679{
1680 RECT rect;
1681
1682 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1683 {//update region not empty
1684 HDC hdc;
1685
1686 hdc = O32_GetDC(OS2Hwnd);
1687 if (isIcon)
1688 {
1689 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1690 SendInternalMessageA(WM_PAINTICON, 0, 0);
1691 } else
1692 {
1693 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1694 SendInternalMessageA(WM_PAINT, 0, 0);
1695 }
1696 O32_ReleaseDC(OS2Hwnd, hdc);
1697 }
1698 return TRUE;
1699}
1700//******************************************************************************
1701//******************************************************************************
1702BOOL Win32BaseWindow::IsIconic()
1703{
1704 return OSLibWinIsIconic(OS2Hwnd);
1705}
1706//******************************************************************************
1707//TODO:
1708//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1709//the current process owns them.
1710//******************************************************************************
1711HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1712 BOOL fUnicode)
1713{
1714 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1715 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1716
1717 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1718 (hwndChildAfter != 0 && !child) ||
1719 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1720 {
1721 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1722 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1723 return 0;
1724 }
1725 if(hwndParent != OSLIB_HWND_DESKTOP)
1726 {//if the current process owns the window, just do a quick search
1727 child = (Win32BaseWindow *)parent->getFirstChild();
1728 if(hwndChildAfter != 0)
1729 {
1730 while(child)
1731 {
1732 if(child->getWindowHandle() == hwndChildAfter)
1733 {
1734 child = (Win32BaseWindow *)child->getNextChild();
1735 break;
1736 }
1737 child = (Win32BaseWindow *)child->getNextChild();
1738 }
1739 }
1740 while(child)
1741 {
1742 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1743 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1744 {
1745 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1746 return child->getWindowHandle();
1747 }
1748 child = (Win32BaseWindow *)child->getNextChild();
1749 }
1750 }
1751 else {
1752 Win32BaseWindow *wnd;
1753 HWND henum, hwnd;
1754
1755 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1756 hwnd = OSLibWinGetNextWindow(henum);
1757
1758 while(hwnd)
1759 {
1760 wnd = GetWindowFromOS2Handle(hwnd);
1761 if(wnd == NULL) {
1762 hwnd = OSLibWinQueryClientWindow(hwnd);
1763 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1764 }
1765
1766 if(wnd) {
1767 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1768
1769 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1770 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1771 break;
1772 }
1773 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1774 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1775 {
1776 OSLibWinEndEnumWindows(henum);
1777 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1778 return wnd->getWindowHandle();
1779 }
1780 }
1781 hwnd = OSLibWinGetNextWindow(henum);
1782 }
1783 OSLibWinEndEnumWindows(henum);
1784 }
1785 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1786 return 0;
1787}
1788//******************************************************************************
1789//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1790//******************************************************************************
1791HWND Win32BaseWindow::GetWindow(UINT uCmd)
1792{
1793 Win32BaseWindow *win32wnd;
1794 ULONG magic;
1795 ULONG getcmd = 0;
1796 HWND hwndRelated;
1797
1798 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1799 switch(uCmd)
1800 {
1801 case GW_CHILD:
1802 getcmd = QWOS_TOP;
1803 break;
1804 case GW_HWNDFIRST:
1805 if(getParent()) {
1806 getcmd = QWOS_TOP; //top of child windows
1807 }
1808 else getcmd = QWOS_TOP; //TODO
1809 break;
1810 case GW_HWNDLAST:
1811 if(getParent()) {
1812 getcmd = QWOS_BOTTOM; //bottom of child windows
1813 }
1814 else getcmd = QWOS_BOTTOM; //TODO
1815 break;
1816 case GW_HWNDNEXT:
1817 getcmd = QWOS_NEXT;
1818 break;
1819 case GW_HWNDPREV:
1820 getcmd = QWOS_PREV;
1821 break;
1822 case GW_OWNER:
1823 if(owner) {
1824 return owner->getWindowHandle();
1825 }
1826 else return 0;
1827 }
1828 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1829 if(hwndRelated)
1830 {
1831 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1832 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1833 if(CheckMagicDword(magic) && win32wnd)
1834 {
1835 return win32wnd->getWindowHandle();
1836 }
1837 }
1838 return 0;
1839}
1840//******************************************************************************
1841//******************************************************************************
1842HWND Win32BaseWindow::SetActiveWindow()
1843{
1844 return OSLibWinSetActiveWindow(OS2Hwnd);
1845}
1846//******************************************************************************
1847//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1848//******************************************************************************
1849BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
1850{
1851 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1852}
1853//******************************************************************************
1854//******************************************************************************
1855BOOL Win32BaseWindow::CloseWindow()
1856{
1857 return OSLibWinMinimizeWindow(OS2Hwnd);
1858}
1859//******************************************************************************
1860//******************************************************************************
1861HWND Win32BaseWindow::GetActiveWindow()
1862{
1863 HWND hwndActive;
1864 Win32BaseWindow *win32wnd;
1865 ULONG magic;
1866
1867 hwndActive = OSLibWinQueryActiveWindow();
1868
1869 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1870 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1871 if(CheckMagicDword(magic) && win32wnd)
1872 {
1873 return win32wnd->getWindowHandle();
1874 }
1875 return hwndActive;
1876}
1877//******************************************************************************
1878//******************************************************************************
1879BOOL Win32BaseWindow::IsWindow()
1880{
1881 return TRUE;
1882}
1883//******************************************************************************
1884//******************************************************************************
1885BOOL Win32BaseWindow::IsWindowEnabled()
1886{
1887 return OSLibWinIsWindowEnabled(OS2Hwnd);
1888}
1889//******************************************************************************
1890//******************************************************************************
1891BOOL Win32BaseWindow::IsWindowVisible()
1892{
1893 return OSLibWinIsWindowVisible(OS2Hwnd);
1894}
1895//******************************************************************************
1896//******************************************************************************
1897BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
1898{
1899 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1900}
1901//******************************************************************************
1902//******************************************************************************
1903BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
1904{
1905 if(fUnicode) {
1906 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
1907 }
1908 else return (strcmp(windowNameA, wndname) == 0);
1909}
1910//******************************************************************************
1911//******************************************************************************
1912int Win32BaseWindow::GetWindowTextLengthA()
1913{
1914 return OSLibWinQueryWindowTextLength(OS2Hwnd);
1915}
1916//******************************************************************************
1917//******************************************************************************
1918int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
1919{
1920 return OSLibWinQueryWindowText(OS2Hwnd, cch, lpsz);
1921}
1922//******************************************************************************
1923//******************************************************************************
1924BOOL Win32BaseWindow::SetWindowText(LPSTR lpsz)
1925{
1926 if(lpsz == NULL)
1927 return FALSE;
1928
1929 if(isUnicode == FALSE) {
1930 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
1931 strcpy(windowNameA, lpsz);
1932 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
1933 lstrcpyAtoW(windowNameW, windowNameA);
1934 }
1935 else {
1936 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
1937 lstrcpyW(windowNameW, (LPWSTR)lpsz);
1938 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
1939 lstrcpyWtoA(windowNameA, windowNameW);
1940 }
1941 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1942
1943 if(OS2Hwnd)
1944 return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)windowNameA);
1945
1946 return TRUE;
1947}
1948//******************************************************************************
1949//******************************************************************************
1950LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
1951{
1952 LONG oldval;
1953
1954 switch(index) {
1955 case GWL_EXSTYLE:
1956 oldval = dwExStyle;
1957 setExStyle(value);
1958 return oldval;
1959 case GWL_STYLE:
1960 oldval = dwStyle;
1961 setStyle(value);
1962 return oldval;
1963 case GWL_WNDPROC:
1964 oldval = (LONG)getWindowProc();
1965 setWindowProc((WNDPROC)value);
1966 return oldval;
1967 case GWL_HINSTANCE:
1968 oldval = hInstance;
1969 hInstance = value;
1970 return oldval;
1971 case GWL_HWNDPARENT:
1972 return SetParent((HWND)value);
1973
1974 case GWL_ID:
1975 oldval = getWindowId();
1976 setWindowId(value);
1977 return oldval;
1978 case GWL_USERDATA:
1979 oldval = userData;
1980 userData = value;
1981 return oldval;
1982 default:
1983 if(index >= 0 && index/4 < nrUserWindowLong)
1984 {
1985 oldval = userWindowLong[index/4];
1986 userWindowLong[index/4] = value;
1987 return oldval;
1988 }
1989 SetLastError(ERROR_INVALID_PARAMETER);
1990 return 0;
1991 }
1992}
1993//******************************************************************************
1994//******************************************************************************
1995ULONG Win32BaseWindow::GetWindowLongA(int index)
1996{
1997 switch(index) {
1998 case GWL_EXSTYLE:
1999 return dwExStyle;
2000 case GWL_STYLE:
2001 return dwStyle;
2002 case GWL_WNDPROC:
2003 return (ULONG)getWindowProc();
2004 case GWL_HINSTANCE:
2005 return hInstance;
2006 case GWL_HWNDPARENT:
2007 if(getParent()) {
2008 return getParent()->getWindowHandle();
2009 }
2010 else return 0;
2011 case GWL_ID:
2012 return getWindowId();
2013 case GWL_USERDATA:
2014 return userData;
2015 default:
2016 if(index >= 0 && index/4 < nrUserWindowLong)
2017 {
2018 return userWindowLong[index/4];
2019 }
2020 SetLastError(ERROR_INVALID_PARAMETER);
2021 return 0;
2022 }
2023}
2024//******************************************************************************
2025//******************************************************************************
2026WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2027{
2028 WORD oldval;
2029
2030 if(index >= 0 && index/4 < nrUserWindowLong)
2031 {
2032 oldval = ((WORD *)userWindowLong)[index/2];
2033 ((WORD *)userWindowLong)[index/2] = value;
2034 return oldval;
2035 }
2036 SetLastError(ERROR_INVALID_PARAMETER);
2037 return 0;
2038}
2039//******************************************************************************
2040//******************************************************************************
2041WORD Win32BaseWindow::GetWindowWord(int index)
2042{
2043 if(index >= 0 && index/4 < nrUserWindowLong)
2044 {
2045 return ((WORD *)userWindowLong)[index/2];
2046 }
2047 SetLastError(ERROR_INVALID_PARAMETER);
2048 return 0;
2049}
2050//******************************************************************************
2051//******************************************************************************
2052Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2053{
2054 Win32BaseWindow *window;
2055
2056 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2057 return window;
2058 }
2059 else return NULL;
2060}
2061//******************************************************************************
2062//******************************************************************************
2063Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2064{
2065 Win32BaseWindow *win32wnd;
2066 DWORD magic;
2067
2068 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2069 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2070
2071 if(win32wnd && CheckMagicDword(magic)) {
2072 return win32wnd;
2073 }
2074 return 0;
2075}
2076//******************************************************************************
2077//******************************************************************************
2078GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.