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

Last change on this file since 780 was 780, checked in by phaller, 26 years ago

Fix: header file cleanup (win32type.h)

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