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

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

Added MDI class + ChildWindowFromPointEx by Rene Pronk

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