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

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

Filter out some very frequent messages (dprintf)

File size: 72.3 KB
Line 
1/* $Id: win32wbase.cpp,v 1.12 1999-09-05 17:14:03 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 <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 fIsDialog = FALSE;
78
79 windowNameA = NULL;
80 windowNameW = NULL;
81 wndNameLength = 0;
82
83 userWindowLong = NULL;;
84 nrUserWindowLong = 0;
85
86 magic = WIN32PM_MAGIC;
87 OS2Hwnd = 0;
88 OS2HwndFrame = 0;
89 OS2HwndMenu = 0;
90 Win32Hwnd = 0;
91
92 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
93 {
94 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
95 DebugInt3();
96 }
97
98 posx = posy = 0;
99 width = height = 0;
100
101 dwExStyle = 0;
102 dwStyle = 0;
103 win32wndproc = 0;
104 hInstance = 0;
105 windowId = 0xFFFFFFFF; //default = -1
106 userData = 0;
107
108 hwndLinkAfter = HWND_BOTTOM;
109 flags = 0;
110 isIcon = FALSE;
111 lastHitTestVal = 0;
112 owner = NULL;
113 windowClass = 0;
114
115 acceltableResource = NULL;
116 menuResource = NULL;
117 iconResource = NULL;
118}
119//******************************************************************************
120//todo get rid of resources (menu, accel, icon etc)
121//******************************************************************************
122Win32BaseWindow::~Win32BaseWindow()
123{
124 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
125 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
126
127 if(Win32Hwnd)
128 HwFreeWindowHandle(Win32Hwnd);
129
130 if(userWindowLong)
131 free(userWindowLong);
132 if(windowNameA) {
133 free(windowNameA);
134 windowNameA = NULL;
135 }
136 if(windowNameW) {
137 free(windowNameW);
138 windowNameW = NULL;
139 }
140}
141//******************************************************************************
142//******************************************************************************
143BOOL Win32BaseWindow::isChild()
144{
145 return (dwStyle & WS_CHILD) != 0;
146}
147//******************************************************************************
148//******************************************************************************
149BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
150{
151 char buffer[256];
152 INT sw = SW_SHOW;
153 POINT maxSize, maxPos, minTrack, maxTrack;
154
155 SetLastError(0);
156
157 /* Find the parent window */
158 if (cs->hwndParent)
159 {
160 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
161 if(!window) {
162 dprintf(("Bad parent %04x\n", cs->hwndParent ));
163 SetLastError(ERROR_INVALID_PARAMETER);
164 return FALSE;
165 }
166 /* Make sure parent is valid */
167 if (!window->IsWindow() )
168 {
169 dprintf(("Bad parent %04x\n", cs->hwndParent ));
170 SetLastError(ERROR_INVALID_PARAMETER);
171 return FALSE;
172 }
173 }
174 else
175 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
176 dprintf(("No parent for child window\n" ));
177 SetLastError(ERROR_INVALID_PARAMETER);
178 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
179 }
180
181 /* Find the window class */
182 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
183 if (!windowClass)
184 {
185 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
186 dprintf(("Bad class '%s'\n", buffer ));
187 return 0;
188 }
189
190 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
191 * with an atom as the class name, put some programs expect to have a *REAL* string in
192 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
193 */
194 if (!HIWORD(cs->lpszClass) ) {
195 if (isUnicode) {
196 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
197 }
198 else {
199 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
200 }
201 cs->lpszClass = buffer;
202 }
203
204 /* Fix the coordinates */
205 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
206 {
207// PDB *pdb = PROCESS_Current();
208
209 /* Never believe Microsoft's documentation... CreateWindowEx doc says
210 * that if an overlapped window is created with WS_VISIBLE style bit
211 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
212 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
213 * reveals that
214 *
215 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
216 * 2) it does not ignore the y parameter as the docs claim; instead, it
217 * uses it as second parameter to ShowWindow() unless y is either
218 * CW_USEDEFAULT or CW_USEDEFAULT16.
219 *
220 * The fact that we didn't do 2) caused bogus windows pop up when wine
221 * was running apps that were using this obscure feature. Example -
222 * calc.exe that comes with Win98 (only Win98, it's different from
223 * the one that comes with Win95 and NT)
224 */
225 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
226
227 /* We have saved cs->y, now we can trash it */
228#if 0
229 if ( !(cs->style & (WS_CHILD | WS_POPUP))
230 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
231 {
232 cs->x = pdb->env_db->startup_info->dwX;
233 cs->y = pdb->env_db->startup_info->dwY;
234 }
235#endif
236 cs->x = 0;
237 cs->y = 0;
238// }
239 }
240 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
241 {
242#if 0
243 PDB *pdb = PROCESS_Current();
244 if ( !(cs->style & (WS_CHILD | WS_POPUP))
245 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
246 {
247 cs->cx = pdb->env_db->startup_info->dwXSize;
248 cs->cy = pdb->env_db->startup_info->dwYSize;
249 }
250 else
251 {
252#endif
253 cs->cx = 600; /* FIXME */
254 cs->cy = 400;
255// }
256 }
257
258 if (cs->x < 0) cs->x = 0;
259 if (cs->y < 0) cs->y = 0;
260
261 //Allocate window words
262 nrUserWindowLong = windowClass->getExtraWndWords();
263 if(nrUserWindowLong) {
264 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
265 memset(userWindowLong, 0, nrUserWindowLong);
266 }
267
268 if ((cs->style & WS_CHILD) && cs->hwndParent)
269 {
270 SetParent(cs->hwndParent);
271 owner = GetWindowFromHandle(cs->hwndParent);
272 if(owner == NULL)
273 {
274 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
275 return FALSE;
276 }
277 }
278 else
279 {
280 if (!cs->hwndParent) {
281 owner = NULL;
282 }
283 else
284 {
285 owner = GetWindowFromHandle(cs->hwndParent);
286 if(owner == NULL)
287 {
288 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
289 return FALSE;
290 }
291 }
292 }
293
294 setWindowProc(windowClass->getWindowProc());
295 hInstance = cs->hInstance;
296 dwStyle = cs->style & ~WS_VISIBLE;
297 dwExStyle = cs->dwExStyle;
298
299 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
300 ? HWND_BOTTOM : HWND_TOP;
301
302#if 0
303//TODO
304 /* Call the WH_CBT hook */
305
306 if (HOOK_IsHooked( WH_CBT ))
307 {
308 CBT_CREATEWNDA cbtc;
309 LRESULT ret;
310
311 cbtc.lpcs = cs;
312 cbtc.hwndInsertAfter = hwndLinkAfter;
313 ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
314 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
315 if (ret)
316 {
317 TRACE_(win)("CBT-hook returned 0\n");
318 wndPtr->pDriver->pFinalize(wndPtr);
319 retvalue = 0;
320 goto end;
321 }
322 }
323#endif
324
325 /* Increment class window counter */
326 windowClass->IncreaseWindowCount();
327
328 /* Correct the window style */
329 if (!(cs->style & WS_CHILD))
330 {
331 dwStyle |= WS_CLIPSIBLINGS;
332 if (!(cs->style & WS_POPUP))
333 {
334 dwStyle |= WS_CAPTION;
335 flags |= WIN_NEED_SIZE;
336 }
337 }
338 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
339
340 //TODO?
341#if 0
342 /* Get class or window DC if needed */
343 if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
344 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
345 else wndPtr->dce = NULL;
346#endif
347
348 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
349 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
350 {
351 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
352 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
353 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
354 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
355 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
356 }
357
358 if(cs->style & WS_CHILD)
359 {
360 if(cs->cx < 0) cs->cx = 0;
361 if(cs->cy < 0) cs->cy = 0;
362 }
363 else
364 {
365 if (cs->cx <= 0) cs->cx = 1;
366 if (cs->cy <= 0) cs->cy = 1;
367 }
368
369 rectWindow.left = cs->x;
370 rectWindow.top = cs->y;
371 rectWindow.right = cs->x + cs->cx;
372 rectWindow.bottom = cs->y + cs->cy;
373 rectClient = rectWindow;
374
375 DWORD dwOSWinStyle, dwOSFrameStyle;
376
377 OSLibWinConvertStyle(cs->style, cs->dwExStyle, &dwOSWinStyle, &dwOSFrameStyle);
378
379 //TODO: Test
380#if 1
381 if(cs->style & WS_CHILD) {
382 dwOSFrameStyle = 0;
383 }
384#endif
385
386 if(cs->lpszName)
387 SetWindowTextA((LPSTR)cs->lpszName);
388
389 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
390 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
391 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
392 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
393 &OS2HwndFrame);
394
395 if(OS2Hwnd == 0) {
396 dprintf(("Window creation failed!!"));
397 return FALSE;
398 }
399
400 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
401 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
402 return FALSE;
403 }
404 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
405 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
406 return FALSE;
407 }
408 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
409 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
410 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
411 return FALSE;
412 }
413#if 0
414 if(OS2Hwnd != OS2HwndFrame) {
415 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
416 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
417 return FALSE;
418 }
419 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
420 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
421 return FALSE;
422 }
423 //SvL: Need to store the shared memory base, or else other apps can map it into their memory space
424 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_SHAREDMEM, HeapGetSharedMemBase()) == FALSE) {
425 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
426 return FALSE;
427 }
428 }
429#endif
430
431 fakeWinBase.hwndThis = OS2Hwnd;
432 fakeWinBase.pWindowClass = windowClass;
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 case WM_GETDLGCODE:
1161 return 0;
1162
1163 case WM_NCLBUTTONDOWN:
1164 case WM_NCLBUTTONUP:
1165 case WM_NCLBUTTONDBLCLK:
1166 case WM_NCRBUTTONUP:
1167 case WM_NCRBUTTONDOWN:
1168 case WM_NCRBUTTONDBLCLK:
1169 case WM_NCMBUTTONDOWN:
1170 case WM_NCMBUTTONUP:
1171 case WM_NCMBUTTONDBLCLK:
1172 return 0; //TODO: Send WM_SYSCOMMAND if required
1173
1174 case WM_NCHITTEST: //TODO: Calculate position of
1175 return HTCLIENT;
1176
1177 default:
1178 return 1;
1179 }
1180}
1181//******************************************************************************
1182//******************************************************************************
1183LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1184{
1185 switch(Msg)
1186 {
1187 case WM_GETTEXTLENGTH:
1188 return wndNameLength;
1189
1190 case WM_GETTEXT: //TODO: SS_ICON controls
1191 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1192 return min(wndNameLength, wParam);
1193
1194 default:
1195 return DefWindowProcA(Msg, wParam, lParam);
1196 }
1197}
1198//******************************************************************************
1199//******************************************************************************
1200LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1201{
1202 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1203 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1204 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1205 }
1206
1207 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1208 return(0);
1209 }
1210 switch(Msg)
1211 {
1212 case WM_CREATE:
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(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1244 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1245 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1246 }
1247
1248 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1249 return(0);
1250 }
1251 switch(Msg)
1252 {
1253 case WM_CREATE:
1254 {
1255 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1256 dprintf(("WM_CREATE returned FALSE\n"));
1257 return(0); //don't create window
1258 }
1259 NotifyParent(Msg, wParam, lParam);
1260
1261 return(1);
1262 }
1263 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1264 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1265
1266 case WM_LBUTTONDOWN:
1267 case WM_MBUTTONDOWN:
1268 case WM_RBUTTONDOWN:
1269 NotifyParent(Msg, wParam, lParam);
1270 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1271
1272 case WM_DESTROY:
1273 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1274 NotifyParent(Msg, wParam, lParam);
1275 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1276
1277 default:
1278 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1279 }
1280}
1281//******************************************************************************
1282//Called as a result of an OS/2 message
1283//******************************************************************************
1284LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1285{
1286 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1287 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1288
1289 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1290 return(0);
1291 }
1292 switch(Msg)
1293 {
1294 case WM_CREATE:
1295 {
1296 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1297 dprintf(("WM_CREATE returned FALSE\n"));
1298 return(0); //don't create window
1299 }
1300 NotifyParent(Msg, wParam, lParam);
1301
1302 return(1);
1303 }
1304 case WM_LBUTTONDOWN:
1305 case WM_MBUTTONDOWN:
1306 case WM_RBUTTONDOWN:
1307 NotifyParent(Msg, wParam, lParam);
1308 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1309
1310 case WM_DESTROY:
1311 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1312 NotifyParent(Msg, wParam, lParam);
1313 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1314 default:
1315 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1316 }
1317}
1318//******************************************************************************
1319//Called as a result of an OS/2 message
1320//todo, unicode msgs (WM_SETTEXT etc)
1321//******************************************************************************
1322LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1323{
1324 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1325 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1326
1327 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1328 return(0);
1329 }
1330 switch(Msg)
1331 {
1332 case WM_CREATE:
1333 {
1334 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1335 dprintf(("WM_CREATE returned FALSE\n"));
1336 return(0); //don't create window
1337 }
1338 NotifyParent(Msg, wParam, lParam);
1339
1340 return(1);
1341 }
1342 case WM_LBUTTONDOWN:
1343 case WM_MBUTTONDOWN:
1344 case WM_RBUTTONDOWN:
1345 NotifyParent(Msg, wParam, lParam);
1346 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1347
1348 case WM_DESTROY:
1349 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1350 NotifyParent(Msg, wParam, lParam);
1351 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1352 default:
1353 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1354 }
1355}
1356//******************************************************************************
1357//******************************************************************************
1358BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1359{
1360 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1361}
1362//******************************************************************************
1363//******************************************************************************
1364BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1365{
1366 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1367}
1368//******************************************************************************
1369//TODO: do we need to inform the parent of the parent (etc) of the child window?
1370//******************************************************************************
1371void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1372{
1373 Win32BaseWindow *window = this;
1374 Win32BaseWindow *parentwindow;
1375
1376 while(window)
1377 {
1378 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1379 {
1380 /* Notify the parent window only */
1381 parentwindow = window->getParent();
1382 if(parentwindow) {
1383 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1384 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1385 }
1386 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1387 }
1388 }
1389 else break;
1390
1391 window = parentwindow;
1392 }
1393}
1394//******************************************************************************
1395//******************************************************************************
1396Win32BaseWindow *Win32BaseWindow::getTopParent()
1397{
1398 Win32BaseWindow *tmpWnd = this;
1399
1400 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1401 {
1402 tmpWnd = tmpWnd->getParent();
1403 }
1404 return tmpWnd;
1405}
1406//******************************************************************************
1407//******************************************************************************
1408BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1409{
1410 PVOID menutemplate;
1411 Win32Resource *winres = (Win32Resource *)hMenu;
1412
1413 dprintf(("SetMenu %x", hMenu));
1414 if(HIWORD(winres) == 0) {
1415 dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
1416 SetLastError(ERROR_INVALID_PARAMETER);
1417 return FALSE;
1418 }
1419 menutemplate = winres->lockOS2Resource();
1420 if(menutemplate == NULL)
1421 {
1422 dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
1423 return FALSE;
1424 }
1425 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1426 if(OS2HwndMenu == 0) {
1427 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1428 return FALSE;
1429 }
1430 winres->setOS2Handle(OS2HwndMenu);
1431 menuResource = winres;
1432 return TRUE;
1433}
1434//******************************************************************************
1435//******************************************************************************
1436BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1437{
1438 Win32Resource *winres = (Win32Resource *)hAccel;
1439 HANDLE accelhandle;
1440
1441 if(HIWORD(hAccel) == 0) {
1442 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1443 SetLastError(ERROR_INVALID_PARAMETER);
1444 return FALSE;
1445 }
1446 acceltableResource = winres;
1447 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1448 winres->setOS2Handle(accelhandle);
1449 return(accelhandle != 0);
1450}
1451//******************************************************************************
1452//******************************************************************************
1453BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1454{
1455 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1456 return OSLibWinSetIcon(OS2HwndFrame, hIcon);
1457}
1458//******************************************************************************
1459//******************************************************************************
1460BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1461{
1462 ULONG showstate = 0;
1463
1464 dprintf(("ShowWindow %x", nCmdShow));
1465 if(fFirstShow) {
1466 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1467 SendMessageA(WM_SIZE, SIZE_RESTORED,
1468 MAKELONG(rectClient.right-rectClient.left,
1469 rectClient.bottom-rectClient.top));
1470 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1471
1472 }
1473 fFirstShow = FALSE;
1474 }
1475 switch(nCmdShow)
1476 {
1477 case SW_SHOW:
1478 case SW_SHOWDEFAULT: //todo
1479 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1480 break;
1481 case SW_HIDE:
1482 showstate = SWPOS_HIDE;
1483 break;
1484 case SW_RESTORE:
1485 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1486 break;
1487 case SW_MINIMIZE:
1488 showstate = SWPOS_MINIMIZE;
1489 break;
1490 case SW_SHOWMAXIMIZED:
1491 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1492 break;
1493 case SW_SHOWMINIMIZED:
1494 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1495 break;
1496 case SW_SHOWMINNOACTIVE:
1497 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1498 break;
1499 case SW_SHOWNA:
1500 showstate = SWPOS_SHOW;
1501 break;
1502 case SW_SHOWNOACTIVATE:
1503 showstate = SWPOS_SHOW;
1504 break;
1505 case SW_SHOWNORMAL:
1506 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1507 break;
1508 }
1509 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1510}
1511//******************************************************************************
1512//******************************************************************************
1513BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1514{
1515 BOOL rc = FALSE;
1516 Win32BaseWindow *window;
1517 HWND hParent = 0;
1518
1519 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1520
1521 /* Validate the flags passed in ... */
1522 if ( fuFlags &
1523 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1524 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1525 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1526 SWP_NOOWNERZORDER) )
1527 {
1528 return FALSE;
1529 }
1530
1531 WINDOWPOS wpos;
1532 SWP swp, swpOld;
1533
1534 //****************************
1535 // Set up with Windows values.
1536 //****************************
1537 wpos.flags = fuFlags;
1538 wpos.cy = cy;
1539 wpos.cx = cx;
1540 wpos.x = x;
1541 wpos.y = y;
1542 wpos.hwndInsertAfter = hwndInsertAfter;
1543 wpos.hwnd = getWindowHandle();
1544
1545 //**********************************************
1546 // Convert from Windows to PM coords and flags.
1547 //**********************************************
1548 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1549 if (isChild())
1550 {
1551 hParent = getParent()->getOS2WindowHandle();
1552 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1553 } else
1554 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1555 }
1556 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1557
1558 /* MapSWP can clear the SWP_MOVE and SWP_SIZE flags if the window is not
1559 * being moved or sized. If these were the only operations to be done
1560 * and they have been cleared, return now.
1561 */
1562 if (swp.fl == 0)
1563 return TRUE;
1564
1565 //*********************************************************************
1566 //On Windows, a WM_GETMINMAXINFO is made to the app from within this API.
1567 //We'll send a WM_QUERYTRACKINFO which is translated into a WM_GETMINMAXINFO
1568 //and passed on to the app. Compare the values returned with the SWP cx and
1569 //cy values. They cannot be bigger than the max nor smaller than the min.
1570 //*********************************************************************
1571
1572 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1573 {
1574 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1575 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1576 }
1577 if (isFrameWindow())
1578 {
1579 POINT maxSize, maxPos, minTrack, maxTrack;
1580
1581 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1582
1583 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1584 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1585 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1586 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1587 swp.hwnd = OS2HwndFrame;
1588 } else
1589 swp.hwnd = OS2Hwnd;
1590 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1591
1592 //*****************************************************************************
1593 // Squibble the window. (WinSetMultWindowPos is faster than WinSetWindowPos.)
1594 //*****************************************************************************
1595 rc = OSLibWinSetMultWindowPos(&swp, 1);
1596
1597 if (rc == FALSE)
1598 {
1599// SET_ERROR_LAST();
1600 }
1601 else
1602 {
1603 /* To implement support for SWP_FRAMECHANGED_W correctly, we would need
1604 ** to send a WM_NCCALCSIZE message. This means DAX would have to support
1605 ** the WM_NCCALCSIZE message. I don't think DAX can support this
1606 ** message because it is tightly bound with the architecture of
1607 ** overlapped windows (the "just one window" architecture). However,
1608 ** we *can* support the SWP_FRAMECHANGED flag by sending the window
1609 ** a WM_UPDATEFRAME, which will provide the behavior of WM_NCCALCSIZE.
1610 */
1611// if (fuFlags & SWP_FRAMECHANGED_W)
1612// WinSendMsg(hWindow, WM_UPDATEFRAME, (MPARAM)-1, 0);
1613 }
1614
1615 return (rc);
1616}
1617//******************************************************************************
1618//Also destroys all the child windows (destroy parent, destroy children)
1619//******************************************************************************
1620BOOL Win32BaseWindow::DestroyWindow()
1621{
1622 return OSLibWinDestroyWindow(OS2HwndFrame);
1623}
1624//******************************************************************************
1625//******************************************************************************
1626HWND Win32BaseWindow::GetParent()
1627{
1628 if(getParent()) {
1629 return getParent()->getWindowHandle();
1630 }
1631 else return 0;
1632}
1633//******************************************************************************
1634//******************************************************************************
1635HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1636{
1637 HWND oldhwnd;
1638 Win32BaseWindow *newparent;
1639
1640 if(getParent()) {
1641 oldhwnd = getParent()->getWindowHandle();
1642 }
1643 else oldhwnd = 0;
1644
1645 if(hwndNewParent == 0) {//desktop window = parent
1646 setParent(NULL);
1647 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1648 return oldhwnd;
1649 }
1650 newparent = GetWindowFromHandle(hwndNewParent);
1651 if(newparent)
1652 {
1653 setParent(newparent);
1654 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1655 return oldhwnd;
1656 }
1657 SetLastError(ERROR_INVALID_PARAMETER);
1658 return 0;
1659}
1660//******************************************************************************
1661//******************************************************************************
1662BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1663{
1664 if(getParent()) {
1665 return getParent()->getWindowHandle() == hwndParent;
1666 }
1667 else return 0;
1668}
1669//******************************************************************************
1670//******************************************************************************
1671HWND Win32BaseWindow::GetTopWindow()
1672{
1673 return GetWindow(GW_CHILD);
1674}
1675//******************************************************************************
1676//Don't call WinUpdateWindow as that one also updates the child windows
1677//Also need to send WM_PAINT directly to the window procedure, which doesn't
1678//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1679//******************************************************************************
1680BOOL Win32BaseWindow::UpdateWindow()
1681{
1682 RECT rect;
1683
1684 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1685 {//update region not empty
1686 HDC hdc;
1687
1688 hdc = O32_GetDC(OS2Hwnd);
1689 if (isIcon)
1690 {
1691 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1692 SendInternalMessageA(WM_PAINTICON, 0, 0);
1693 } else
1694 {
1695 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1696 SendInternalMessageA(WM_PAINT, 0, 0);
1697 }
1698 O32_ReleaseDC(OS2Hwnd, hdc);
1699 }
1700 return TRUE;
1701}
1702//******************************************************************************
1703//******************************************************************************
1704BOOL Win32BaseWindow::IsIconic()
1705{
1706 return OSLibWinIsIconic(OS2Hwnd);
1707}
1708//******************************************************************************
1709//TODO:
1710//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1711//the current process owns them.
1712//******************************************************************************
1713HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1714 BOOL fUnicode)
1715{
1716 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1717 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1718
1719 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1720 (hwndChildAfter != 0 && !child) ||
1721 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1722 {
1723 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1724 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1725 return 0;
1726 }
1727 if(hwndParent != OSLIB_HWND_DESKTOP)
1728 {//if the current process owns the window, just do a quick search
1729 child = (Win32BaseWindow *)parent->getFirstChild();
1730 if(hwndChildAfter != 0)
1731 {
1732 while(child)
1733 {
1734 if(child->getWindowHandle() == hwndChildAfter)
1735 {
1736 child = (Win32BaseWindow *)child->getNextChild();
1737 break;
1738 }
1739 child = (Win32BaseWindow *)child->getNextChild();
1740 }
1741 }
1742 while(child)
1743 {
1744 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1745 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1746 {
1747 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1748 return child->getWindowHandle();
1749 }
1750 child = (Win32BaseWindow *)child->getNextChild();
1751 }
1752 }
1753 else {
1754 Win32BaseWindow *wnd;
1755 HWND henum, hwnd;
1756
1757 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1758 hwnd = OSLibWinGetNextWindow(henum);
1759
1760 while(hwnd)
1761 {
1762 wnd = GetWindowFromOS2Handle(hwnd);
1763 if(wnd == NULL) {
1764 hwnd = OSLibWinQueryClientWindow(hwnd);
1765 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1766 }
1767
1768 if(wnd) {
1769 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1770
1771 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1772 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1773 break;
1774 }
1775 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1776 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1777 {
1778 OSLibWinEndEnumWindows(henum);
1779 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1780 return wnd->getWindowHandle();
1781 }
1782 }
1783 hwnd = OSLibWinGetNextWindow(henum);
1784 }
1785 OSLibWinEndEnumWindows(henum);
1786 }
1787 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1788 return 0;
1789}
1790//******************************************************************************
1791//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1792//******************************************************************************
1793HWND Win32BaseWindow::GetWindow(UINT uCmd)
1794{
1795 Win32BaseWindow *win32wnd;
1796 ULONG magic;
1797 ULONG getcmd = 0;
1798 HWND hwndRelated;
1799
1800 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1801 switch(uCmd)
1802 {
1803 case GW_CHILD:
1804 getcmd = QWOS_TOP;
1805 break;
1806 case GW_HWNDFIRST:
1807 if(getParent()) {
1808 getcmd = QWOS_TOP; //top of child windows
1809 }
1810 else getcmd = QWOS_TOP; //TODO
1811 break;
1812 case GW_HWNDLAST:
1813 if(getParent()) {
1814 getcmd = QWOS_BOTTOM; //bottom of child windows
1815 }
1816 else getcmd = QWOS_BOTTOM; //TODO
1817 break;
1818 case GW_HWNDNEXT:
1819 getcmd = QWOS_NEXT;
1820 break;
1821 case GW_HWNDPREV:
1822 getcmd = QWOS_PREV;
1823 break;
1824 case GW_OWNER:
1825 if(owner) {
1826 return owner->getWindowHandle();
1827 }
1828 else return 0;
1829 }
1830 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1831 if(hwndRelated)
1832 {
1833 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1834 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1835 if(CheckMagicDword(magic) && win32wnd)
1836 {
1837 return win32wnd->getWindowHandle();
1838 }
1839 }
1840 return 0;
1841}
1842//******************************************************************************
1843//******************************************************************************
1844HWND Win32BaseWindow::SetActiveWindow()
1845{
1846 return OSLibWinSetActiveWindow(OS2Hwnd);
1847}
1848//******************************************************************************
1849//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1850//******************************************************************************
1851BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
1852{
1853 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1854}
1855//******************************************************************************
1856//******************************************************************************
1857BOOL Win32BaseWindow::CloseWindow()
1858{
1859 return OSLibWinMinimizeWindow(OS2Hwnd);
1860}
1861//******************************************************************************
1862//******************************************************************************
1863HWND Win32BaseWindow::GetActiveWindow()
1864{
1865 HWND hwndActive;
1866 Win32BaseWindow *win32wnd;
1867 ULONG magic;
1868
1869 hwndActive = OSLibWinQueryActiveWindow();
1870
1871 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1872 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1873 if(CheckMagicDword(magic) && win32wnd)
1874 {
1875 return win32wnd->getWindowHandle();
1876 }
1877 return hwndActive;
1878}
1879//******************************************************************************
1880//******************************************************************************
1881BOOL Win32BaseWindow::IsWindowEnabled()
1882{
1883 return OSLibWinIsWindowEnabled(OS2Hwnd);
1884}
1885//******************************************************************************
1886//******************************************************************************
1887BOOL Win32BaseWindow::IsWindowVisible()
1888{
1889 return OSLibWinIsWindowVisible(OS2Hwnd);
1890}
1891//******************************************************************************
1892//******************************************************************************
1893BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
1894{
1895 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1896}
1897//******************************************************************************
1898//******************************************************************************
1899BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
1900{
1901 if(fUnicode) {
1902 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
1903 }
1904 else return (strcmp(windowNameA, wndname) == 0);
1905}
1906//******************************************************************************
1907//******************************************************************************
1908int Win32BaseWindow::GetWindowTextLength()
1909{
1910 return wndNameLength;
1911}
1912//******************************************************************************
1913//******************************************************************************
1914int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
1915{
1916 strncpy(lpsz, windowNameA, cch);
1917 return wndNameLength;
1918}
1919//******************************************************************************
1920//******************************************************************************
1921int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
1922{
1923 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
1924 return wndNameLength;
1925}
1926//******************************************************************************
1927//******************************************************************************
1928BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
1929{
1930 if(lpsz == NULL)
1931 return FALSE;
1932
1933 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
1934 strcpy(windowNameA, lpsz);
1935 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
1936 lstrcpyAtoW(windowNameW, windowNameA);
1937 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1938
1939 if(OS2HwndFrame)
1940 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1941
1942 return TRUE;
1943}
1944//******************************************************************************
1945//******************************************************************************
1946BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
1947{
1948 if(lpsz == NULL)
1949 return FALSE;
1950
1951 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
1952 lstrcpyW(windowNameW, (LPWSTR)lpsz);
1953 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
1954 lstrcpyWtoA(windowNameA, windowNameW);
1955 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1956
1957 if(OS2HwndFrame)
1958 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1959
1960 return TRUE;
1961}
1962//******************************************************************************
1963//******************************************************************************
1964LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
1965{
1966 LONG oldval;
1967
1968 switch(index) {
1969 case GWL_EXSTYLE:
1970 oldval = dwExStyle;
1971 setExStyle(value);
1972 return oldval;
1973 case GWL_STYLE:
1974 oldval = dwStyle;
1975 setStyle(value);
1976 return oldval;
1977 case GWL_WNDPROC:
1978 oldval = (LONG)getWindowProc();
1979 setWindowProc((WNDPROC)value);
1980 return oldval;
1981 case GWL_HINSTANCE:
1982 oldval = hInstance;
1983 hInstance = value;
1984 return oldval;
1985 case GWL_HWNDPARENT:
1986 return SetParent((HWND)value);
1987
1988 case GWL_ID:
1989 oldval = getWindowId();
1990 setWindowId(value);
1991 return oldval;
1992 case GWL_USERDATA:
1993 oldval = userData;
1994 userData = value;
1995 return oldval;
1996 default:
1997 if(index >= 0 && index/4 < nrUserWindowLong)
1998 {
1999 oldval = userWindowLong[index/4];
2000 userWindowLong[index/4] = value;
2001 return oldval;
2002 }
2003 SetLastError(ERROR_INVALID_PARAMETER);
2004 return 0;
2005 }
2006}
2007//******************************************************************************
2008//******************************************************************************
2009ULONG Win32BaseWindow::GetWindowLongA(int index)
2010{
2011 switch(index) {
2012 case GWL_EXSTYLE:
2013 return dwExStyle;
2014 case GWL_STYLE:
2015 return dwStyle;
2016 case GWL_WNDPROC:
2017 return (ULONG)getWindowProc();
2018 case GWL_HINSTANCE:
2019 return hInstance;
2020 case GWL_HWNDPARENT:
2021 if(getParent()) {
2022 return getParent()->getWindowHandle();
2023 }
2024 else return 0;
2025 case GWL_ID:
2026 return getWindowId();
2027 case GWL_USERDATA:
2028 return userData;
2029 default:
2030 if(index >= 0 && index/4 < nrUserWindowLong)
2031 {
2032 return userWindowLong[index/4];
2033 }
2034 SetLastError(ERROR_INVALID_PARAMETER);
2035 return 0;
2036 }
2037}
2038//******************************************************************************
2039//******************************************************************************
2040WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2041{
2042 WORD oldval;
2043
2044 if(index >= 0 && index/4 < nrUserWindowLong)
2045 {
2046 oldval = ((WORD *)userWindowLong)[index/2];
2047 ((WORD *)userWindowLong)[index/2] = value;
2048 return oldval;
2049 }
2050 SetLastError(ERROR_INVALID_PARAMETER);
2051 return 0;
2052}
2053//******************************************************************************
2054//******************************************************************************
2055WORD Win32BaseWindow::GetWindowWord(int index)
2056{
2057 if(index >= 0 && index/4 < nrUserWindowLong)
2058 {
2059 return ((WORD *)userWindowLong)[index/2];
2060 }
2061 SetLastError(ERROR_INVALID_PARAMETER);
2062 return 0;
2063}
2064//******************************************************************************
2065//******************************************************************************
2066Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2067{
2068 Win32BaseWindow *window;
2069
2070 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2071 return window;
2072 }
2073 else return NULL;
2074}
2075//******************************************************************************
2076//******************************************************************************
2077Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2078{
2079 Win32BaseWindow *win32wnd;
2080 DWORD magic;
2081
2082 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2083 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2084
2085 if(win32wnd && CheckMagicDword(magic)) {
2086 return win32wnd;
2087 }
2088 return 0;
2089}
2090//******************************************************************************
2091//******************************************************************************
2092GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.