source: trunk/src/user32/win32wbase.cpp@ 963

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

window focus management fixed

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