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

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

Preparations for new RedrawWindow et.al.

File size: 72.6 KB
Line 
1/* $Id: win32wbase.cpp,v 1.16 1999-09-15 18:03:46 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, 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, hwnd, 0);
909}
910//******************************************************************************
911//******************************************************************************
912ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
913{
914 ULONG win32msg;
915 ULONG win32ncmsg;
916
917 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
918 switch(msg) {
919 case BUTTON_LEFTDOWN:
920 win32msg = WM_LBUTTONDOWN;
921 win32ncmsg = WM_NCLBUTTONDOWN;
922 break;
923 case BUTTON_LEFTUP:
924 win32msg = WM_LBUTTONUP;
925 win32ncmsg = WM_NCLBUTTONUP;
926 break;
927 case BUTTON_LEFTDBLCLICK:
928 win32msg = WM_LBUTTONDBLCLK;
929 win32ncmsg = WM_NCLBUTTONDBLCLK;
930 break;
931 case BUTTON_RIGHTUP:
932 win32msg = WM_RBUTTONUP;
933 win32ncmsg = WM_NCRBUTTONUP;
934 break;
935 case BUTTON_RIGHTDOWN:
936 win32msg = WM_RBUTTONDOWN;
937 win32ncmsg = WM_NCRBUTTONDOWN;
938 break;
939 case BUTTON_RIGHTDBLCLICK:
940 win32msg = WM_RBUTTONDBLCLK;
941 win32ncmsg = WM_NCRBUTTONDBLCLK;
942 break;
943 case BUTTON_MIDDLEUP:
944 win32msg = WM_MBUTTONUP;
945 win32ncmsg = WM_NCMBUTTONUP;
946 break;
947 case BUTTON_MIDDLEDOWN:
948 win32msg = WM_MBUTTONDOWN;
949 win32ncmsg = WM_NCMBUTTONDOWN;
950 break;
951 case BUTTON_MIDDLEDBLCLICK:
952 win32msg = WM_MBUTTONDBLCLK;
953 win32ncmsg = WM_NCMBUTTONDBLCLK;
954 break;
955 default:
956 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
957 return 1;
958 }
959 if(win32msg == WM_MBUTTONDBLCLK || win32msg == WM_RBUTTONDBLCLK || win32msg == WM_LBUTTONDBLCLK) {
960 if(!(windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)) {
961 return 1;
962 }
963 }
964 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
965
966 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
967 if(lastHitTestVal != HTCLIENT) {
968 SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
969 }
970 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
971}
972//******************************************************************************
973//******************************************************************************
974ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
975{
976 ULONG winstate = 0;
977 ULONG setcursormsg = WM_MOUSEMOVE;
978
979 if(keystate & WMMOVE_LBUTTON)
980 winstate |= MK_LBUTTON;
981 if(keystate & WMMOVE_RBUTTON)
982 winstate |= MK_RBUTTON;
983 if(keystate & WMMOVE_MBUTTON)
984 winstate |= MK_MBUTTON;
985 if(keystate & WMMOVE_SHIFT)
986 winstate |= MK_SHIFT;
987 if(keystate & WMMOVE_CTRL)
988 winstate |= MK_CONTROL;
989
990 if(lastHitTestVal != HTCLIENT) {
991 setcursormsg = WM_NCMOUSEMOVE;
992 }
993 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
994 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
995
996 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
997 if(lastHitTestVal != HTCLIENT) {
998 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
999 }
1000 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1001}
1002//******************************************************************************
1003//******************************************************************************
1004ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1005{
1006 if (select && isIcon)
1007 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1008 else
1009 return SendInternalMessageA(WM_PAINT, 0, 0);
1010}
1011//******************************************************************************
1012//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1013// (or are we simply erasing too much here)
1014//******************************************************************************
1015ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1016{
1017 ULONG rc;
1018 HDC hdcErase = hdc;
1019
1020 if (hdcErase == 0)
1021 hdcErase = O32_GetDC(OS2Hwnd);
1022
1023 if(isIcon)
1024 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1025 else
1026 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1027 if (hdc == 0)
1028 O32_ReleaseDC(OS2Hwnd, hdcErase);
1029 return (rc);
1030}
1031//******************************************************************************
1032//******************************************************************************
1033ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1034{
1035 if(isUnicode) {
1036 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1037 }
1038 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1039}
1040//******************************************************************************
1041//TODO: in- or excluding terminating 0?
1042//******************************************************************************
1043ULONG Win32BaseWindow::MsgGetTextLength()
1044{
1045 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1046}
1047//******************************************************************************
1048//******************************************************************************
1049char *Win32BaseWindow::MsgGetText()
1050{
1051 if(isUnicode) {
1052 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1053 }
1054 else {
1055 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1056 }
1057 return windowNameA;
1058}
1059//******************************************************************************
1060//******************************************************************************
1061LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1062{
1063 switch(Msg)
1064 {
1065 case WM_GETTEXTLENGTH:
1066 return wndNameLength;
1067
1068 case WM_GETTEXT: //TODO: SS_ICON controls
1069 strncpy((LPSTR)lParam, windowNameA, wParam);
1070 return min(wndNameLength, wParam);
1071
1072 case WM_SETTEXT:
1073 return 0;
1074
1075 case WM_SETREDRAW:
1076 if(wParam)
1077 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1078 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1079
1080 return 0; //TODO
1081
1082 case WM_NCCREATE:
1083 return(TRUE);
1084
1085 case WM_CTLCOLORMSGBOX:
1086 case WM_CTLCOLOREDIT:
1087 case WM_CTLCOLORLISTBOX:
1088 case WM_CTLCOLORBTN:
1089 case WM_CTLCOLORDLG:
1090 case WM_CTLCOLORSTATIC:
1091 case WM_CTLCOLORSCROLLBAR:
1092 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1093 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1094 return GetSysColorBrush(COLOR_BTNFACE);
1095
1096 case WM_PARENTNOTIFY:
1097 return 0;
1098
1099 case WM_MOUSEACTIVATE:
1100 {
1101 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1102 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1103 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1104 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1105 {
1106 if(getParent()) {
1107 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1108 if(rc) return rc;
1109 }
1110 }
1111 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1112 }
1113 case WM_SETCURSOR:
1114 {
1115 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1116 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1117 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1118 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1119 {
1120 if(getParent()) {
1121 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1122 if(rc) return rc;
1123 }
1124 }
1125 return 1;
1126 }
1127 case WM_MOUSEMOVE:
1128 return 0;
1129
1130 case WM_WINDOWPOSCHANGED:
1131 {
1132
1133/* undocumented SWP flags - from SDK 3.1 */
1134#define SWP_NOCLIENTSIZE 0x0800
1135#define SWP_NOCLIENTMOVE 0x1000
1136
1137 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1138 WPARAM wp = SIZE_RESTORED;
1139
1140 if (!(wpos->flags & SWP_NOCLIENTMOVE))
1141 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1142
1143 if (!(wpos->flags & SWP_NOCLIENTSIZE))
1144 {
1145 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1146 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1147
1148 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1149 rectClient.bottom - rectClient.top));
1150 }
1151 return 0;
1152 }
1153 case WM_ERASEBKGND:
1154 case WM_ICONERASEBKGND:
1155 {
1156 RECT rect;
1157 int rc;
1158
1159 if (!windowClass->getBackgroundBrush()) return 0;
1160
1161 /* Since WM_ERASEBKGND may receive either a window dc or a */
1162 /* client dc, the area to be erased has to be retrieved from */
1163 /* the device context. */
1164 rc = GetClipBox( (HDC)wParam, &rect );
1165 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1166 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1167
1168 return 1;
1169 }
1170 case WM_GETDLGCODE:
1171 return 0;
1172
1173 case WM_NCLBUTTONDOWN:
1174 case WM_NCLBUTTONUP:
1175 case WM_NCLBUTTONDBLCLK:
1176 case WM_NCRBUTTONUP:
1177 case WM_NCRBUTTONDOWN:
1178 case WM_NCRBUTTONDBLCLK:
1179 case WM_NCMBUTTONDOWN:
1180 case WM_NCMBUTTONUP:
1181 case WM_NCMBUTTONDBLCLK:
1182 return 0; //TODO: Send WM_SYSCOMMAND if required
1183
1184 case WM_NCHITTEST: //TODO: Calculate position of
1185 return HTCLIENT;
1186
1187 default:
1188 return 1;
1189 }
1190}
1191//******************************************************************************
1192//******************************************************************************
1193LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1194{
1195 switch(Msg)
1196 {
1197 case WM_GETTEXTLENGTH:
1198 return wndNameLength;
1199
1200 case WM_GETTEXT: //TODO: SS_ICON controls
1201 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1202 return min(wndNameLength, wParam);
1203
1204 default:
1205 return DefWindowProcA(Msg, wParam, lParam);
1206 }
1207}
1208//******************************************************************************
1209//******************************************************************************
1210LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1211{
1212 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1213 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1214 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1215 }
1216
1217 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1218 return(0);
1219 }
1220 switch(Msg)
1221 {
1222 case WM_CREATE:
1223 {
1224 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1225 dprintf(("WM_CREATE returned -1\n"));
1226 return(-1); //don't create window
1227 }
1228 NotifyParent(Msg, wParam, lParam);
1229
1230 return(0);
1231 }
1232 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1233 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1234
1235 case WM_LBUTTONDOWN:
1236 case WM_MBUTTONDOWN:
1237 case WM_RBUTTONDOWN:
1238 NotifyParent(Msg, wParam, lParam);
1239 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1240
1241 case WM_DESTROY:
1242 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1243 NotifyParent(Msg, wParam, lParam);
1244 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1245 default:
1246 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1247 }
1248}
1249//******************************************************************************
1250//******************************************************************************
1251LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1252{
1253 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1254 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1255 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1256 }
1257
1258 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1259 return(0);
1260 }
1261 switch(Msg)
1262 {
1263 case WM_CREATE:
1264 {
1265 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1266 dprintf(("WM_CREATE returned FALSE\n"));
1267 return(0); //don't create window
1268 }
1269 NotifyParent(Msg, wParam, lParam);
1270
1271 return(1);
1272 }
1273 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1274 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1275
1276 case WM_LBUTTONDOWN:
1277 case WM_MBUTTONDOWN:
1278 case WM_RBUTTONDOWN:
1279 NotifyParent(Msg, wParam, lParam);
1280 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1281
1282 case WM_DESTROY:
1283 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1284 NotifyParent(Msg, wParam, lParam);
1285 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1286
1287 default:
1288 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1289 }
1290}
1291//******************************************************************************
1292//Called as a result of an OS/2 message
1293//******************************************************************************
1294LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1295{
1296 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1297 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1298
1299 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1300 return(0);
1301 }
1302 switch(Msg)
1303 {
1304 case WM_CREATE:
1305 {
1306 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1307 dprintf(("WM_CREATE returned FALSE\n"));
1308 return(0); //don't create window
1309 }
1310 NotifyParent(Msg, wParam, lParam);
1311
1312 return(1);
1313 }
1314 case WM_LBUTTONDOWN:
1315 case WM_MBUTTONDOWN:
1316 case WM_RBUTTONDOWN:
1317 NotifyParent(Msg, wParam, lParam);
1318 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1319
1320 case WM_DESTROY:
1321 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1322 NotifyParent(Msg, wParam, lParam);
1323 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1324 default:
1325 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1326 }
1327}
1328//******************************************************************************
1329//Called as a result of an OS/2 message
1330//todo, unicode msgs (WM_SETTEXT etc)
1331//******************************************************************************
1332LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1333{
1334 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1335 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1336
1337 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1338 return(0);
1339 }
1340 switch(Msg)
1341 {
1342 case WM_CREATE:
1343 {
1344 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1345 dprintf(("WM_CREATE returned FALSE\n"));
1346 return(0); //don't create window
1347 }
1348 NotifyParent(Msg, wParam, lParam);
1349
1350 return(1);
1351 }
1352 case WM_LBUTTONDOWN:
1353 case WM_MBUTTONDOWN:
1354 case WM_RBUTTONDOWN:
1355 NotifyParent(Msg, wParam, lParam);
1356 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1357
1358 case WM_DESTROY:
1359 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1360 NotifyParent(Msg, wParam, lParam);
1361 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1362 default:
1363 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1364 }
1365}
1366//******************************************************************************
1367//******************************************************************************
1368BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1369{
1370 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1371}
1372//******************************************************************************
1373//******************************************************************************
1374BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1375{
1376 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1377}
1378//******************************************************************************
1379//TODO: do we need to inform the parent of the parent (etc) of the child window?
1380//******************************************************************************
1381void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1382{
1383 Win32BaseWindow *window = this;
1384 Win32BaseWindow *parentwindow;
1385
1386 while(window)
1387 {
1388 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1389 {
1390 /* Notify the parent window only */
1391 parentwindow = window->getParent();
1392 if(parentwindow) {
1393 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1394 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1395 }
1396 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1397 }
1398 }
1399 else break;
1400
1401 window = parentwindow;
1402 }
1403}
1404//******************************************************************************
1405//******************************************************************************
1406Win32BaseWindow *Win32BaseWindow::getTopParent()
1407{
1408 Win32BaseWindow *tmpWnd = this;
1409
1410 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1411 {
1412 tmpWnd = tmpWnd->getParent();
1413 }
1414 return tmpWnd;
1415}
1416//******************************************************************************
1417//******************************************************************************
1418BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1419{
1420 PVOID menutemplate;
1421 Win32Resource *winres = (Win32Resource *)hMenu;
1422
1423 dprintf(("SetMenu %x", hMenu));
1424 if(HIWORD(winres) == 0) {
1425 dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
1426 SetLastError(ERROR_INVALID_PARAMETER);
1427 return FALSE;
1428 }
1429 menutemplate = winres->lockOS2Resource();
1430 if(menutemplate == NULL)
1431 {
1432 dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
1433 return FALSE;
1434 }
1435 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1436 if(OS2HwndMenu == 0) {
1437 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1438 return FALSE;
1439 }
1440 winres->setOS2Handle(OS2HwndMenu);
1441 menuResource = winres;
1442 return TRUE;
1443}
1444//******************************************************************************
1445//******************************************************************************
1446BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1447{
1448 Win32Resource *winres = (Win32Resource *)hAccel;
1449 HANDLE accelhandle;
1450
1451 if(HIWORD(hAccel) == 0) {
1452 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1453 SetLastError(ERROR_INVALID_PARAMETER);
1454 return FALSE;
1455 }
1456 acceltableResource = winres;
1457 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1458 winres->setOS2Handle(accelhandle);
1459 return(accelhandle != 0);
1460}
1461//******************************************************************************
1462//******************************************************************************
1463BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1464{
1465 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1466 return OSLibWinSetIcon(OS2HwndFrame, hIcon);
1467}
1468//******************************************************************************
1469//******************************************************************************
1470BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1471{
1472 ULONG showstate = 0;
1473
1474 dprintf(("ShowWindow %x", nCmdShow));
1475 if(fFirstShow) {
1476 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1477 SendMessageA(WM_SIZE, SIZE_RESTORED,
1478 MAKELONG(rectClient.right-rectClient.left,
1479 rectClient.bottom-rectClient.top));
1480 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1481
1482 }
1483 fFirstShow = FALSE;
1484 }
1485 switch(nCmdShow)
1486 {
1487 case SW_SHOW:
1488 case SW_SHOWDEFAULT: //todo
1489 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1490 break;
1491 case SW_HIDE:
1492 showstate = SWPOS_HIDE;
1493 break;
1494 case SW_RESTORE:
1495 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1496 break;
1497 case SW_MINIMIZE:
1498 showstate = SWPOS_MINIMIZE;
1499 break;
1500 case SW_SHOWMAXIMIZED:
1501 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1502 break;
1503 case SW_SHOWMINIMIZED:
1504 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1505 break;
1506 case SW_SHOWMINNOACTIVE:
1507 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1508 break;
1509 case SW_SHOWNA:
1510 showstate = SWPOS_SHOW;
1511 break;
1512 case SW_SHOWNOACTIVATE:
1513 showstate = SWPOS_SHOW;
1514 break;
1515 case SW_SHOWNORMAL:
1516 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1517 break;
1518 }
1519 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1520}
1521//******************************************************************************
1522//******************************************************************************
1523BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1524{
1525 BOOL rc = FALSE;
1526 Win32BaseWindow *window;
1527 HWND hParent = 0;
1528
1529 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1530
1531 /* Validate the flags passed in ... */
1532 if ( fuFlags &
1533 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1534 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1535 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1536 SWP_NOOWNERZORDER) )
1537 {
1538 return FALSE;
1539 }
1540
1541 WINDOWPOS wpos;
1542 SWP swp, swpOld;
1543
1544 //****************************
1545 // Set up with Windows values.
1546 //****************************
1547 wpos.flags = fuFlags;
1548 wpos.cy = cy;
1549 wpos.cx = cx;
1550 wpos.x = x;
1551 wpos.y = y;
1552 wpos.hwndInsertAfter = hwndInsertAfter;
1553 wpos.hwnd = getWindowHandle();
1554
1555 //**********************************************
1556 // Convert from Windows to PM coords and flags.
1557 //**********************************************
1558 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1559 if (isChild())
1560 {
1561 hParent = getParent()->getOS2WindowHandle();
1562 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1563 } else
1564 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1565 }
1566 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1567
1568 /* MapSWP can clear the SWP_MOVE and SWP_SIZE flags if the window is not
1569 * being moved or sized. If these were the only operations to be done
1570 * and they have been cleared, return now.
1571 */
1572 if (swp.fl == 0)
1573 return TRUE;
1574
1575 //*********************************************************************
1576 //On Windows, a WM_GETMINMAXINFO is made to the app from within this API.
1577 //We'll send a WM_QUERYTRACKINFO which is translated into a WM_GETMINMAXINFO
1578 //and passed on to the app. Compare the values returned with the SWP cx and
1579 //cy values. They cannot be bigger than the max nor smaller than the min.
1580 //*********************************************************************
1581
1582 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1583 {
1584 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1585 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1586 }
1587 if (isFrameWindow())
1588 {
1589 POINT maxSize, maxPos, minTrack, maxTrack;
1590
1591 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1592
1593 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1594 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1595 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1596 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1597 swp.hwnd = OS2HwndFrame;
1598 } else
1599 swp.hwnd = OS2Hwnd;
1600 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1601
1602 //*****************************************************************************
1603 // Squibble the window. (WinSetMultWindowPos is faster than WinSetWindowPos.)
1604 //*****************************************************************************
1605 rc = OSLibWinSetMultWindowPos(&swp, 1);
1606
1607 if (rc == FALSE)
1608 {
1609// SET_ERROR_LAST();
1610 }
1611 else
1612 {
1613 /* To implement support for SWP_FRAMECHANGED_W correctly, we would need
1614 ** to send a WM_NCCALCSIZE message. This means DAX would have to support
1615 ** the WM_NCCALCSIZE message. I don't think DAX can support this
1616 ** message because it is tightly bound with the architecture of
1617 ** overlapped windows (the "just one window" architecture). However,
1618 ** we *can* support the SWP_FRAMECHANGED flag by sending the window
1619 ** a WM_UPDATEFRAME, which will provide the behavior of WM_NCCALCSIZE.
1620 */
1621// if (fuFlags & SWP_FRAMECHANGED_W)
1622// WinSendMsg(hWindow, WM_UPDATEFRAME, (MPARAM)-1, 0);
1623 }
1624
1625 return (rc);
1626}
1627//******************************************************************************
1628//Also destroys all the child windows (destroy parent, destroy children)
1629//******************************************************************************
1630BOOL Win32BaseWindow::DestroyWindow()
1631{
1632 return OSLibWinDestroyWindow(OS2HwndFrame);
1633}
1634//******************************************************************************
1635//******************************************************************************
1636HWND Win32BaseWindow::GetParent()
1637{
1638 if(getParent()) {
1639 return getParent()->getWindowHandle();
1640 }
1641 else return 0;
1642}
1643//******************************************************************************
1644//******************************************************************************
1645HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1646{
1647 HWND oldhwnd;
1648 Win32BaseWindow *newparent;
1649
1650 if(getParent()) {
1651 oldhwnd = getParent()->getWindowHandle();
1652 getParent()->RemoveChild(this);
1653 }
1654 else oldhwnd = 0;
1655
1656 if(hwndNewParent == 0) {//desktop window = parent
1657 setParent(NULL);
1658 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1659 return oldhwnd;
1660 }
1661 newparent = GetWindowFromHandle(hwndNewParent);
1662 if(newparent)
1663 {
1664 setParent(newparent);
1665 getParent()->AddChild(this);
1666 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1667 return oldhwnd;
1668 }
1669 SetLastError(ERROR_INVALID_PARAMETER);
1670 return 0;
1671}
1672//******************************************************************************
1673//******************************************************************************
1674BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1675{
1676 if(getParent()) {
1677 return getParent()->getWindowHandle() == hwndParent;
1678 }
1679 else return 0;
1680}
1681//******************************************************************************
1682//******************************************************************************
1683HWND Win32BaseWindow::GetTopWindow()
1684{
1685 return GetWindow(GW_CHILD);
1686}
1687//******************************************************************************
1688//Don't call WinUpdateWindow as that one also updates the child windows
1689//Also need to send WM_PAINT directly to the window procedure, which doesn't
1690//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1691//******************************************************************************
1692BOOL Win32BaseWindow::UpdateWindow()
1693{
1694 RECT rect;
1695
1696 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1697 {//update region not empty
1698 HDC hdc;
1699
1700 hdc = O32_GetDC(OS2Hwnd);
1701 if (isIcon)
1702 {
1703 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1704 SendInternalMessageA(WM_PAINTICON, 0, 0);
1705 } else
1706 {
1707 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1708 SendInternalMessageA(WM_PAINT, 0, 0);
1709 }
1710 O32_ReleaseDC(OS2Hwnd, hdc);
1711 }
1712 return TRUE;
1713}
1714//******************************************************************************
1715//******************************************************************************
1716BOOL Win32BaseWindow::IsIconic()
1717{
1718 return OSLibWinIsIconic(OS2Hwnd);
1719}
1720//******************************************************************************
1721//TODO:
1722//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1723//the current process owns them.
1724//******************************************************************************
1725HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1726 BOOL fUnicode)
1727{
1728 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1729 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1730
1731 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1732 (hwndChildAfter != 0 && !child) ||
1733 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1734 {
1735 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1736 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1737 return 0;
1738 }
1739 if(hwndParent != OSLIB_HWND_DESKTOP)
1740 {//if the current process owns the window, just do a quick search
1741 child = (Win32BaseWindow *)parent->getFirstChild();
1742 if(hwndChildAfter != 0)
1743 {
1744 while(child)
1745 {
1746 if(child->getWindowHandle() == hwndChildAfter)
1747 {
1748 child = (Win32BaseWindow *)child->getNextChild();
1749 break;
1750 }
1751 child = (Win32BaseWindow *)child->getNextChild();
1752 }
1753 }
1754 while(child)
1755 {
1756 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1757 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1758 {
1759 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1760 return child->getWindowHandle();
1761 }
1762 child = (Win32BaseWindow *)child->getNextChild();
1763 }
1764 }
1765 else {
1766 Win32BaseWindow *wnd;
1767 HWND henum, hwnd;
1768
1769 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1770 hwnd = OSLibWinGetNextWindow(henum);
1771
1772 while(hwnd)
1773 {
1774 wnd = GetWindowFromOS2Handle(hwnd);
1775 if(wnd == NULL) {
1776 hwnd = OSLibWinQueryClientWindow(hwnd);
1777 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1778 }
1779
1780 if(wnd) {
1781 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1782
1783 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1784 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1785 break;
1786 }
1787 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1788 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1789 {
1790 OSLibWinEndEnumWindows(henum);
1791 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1792 return wnd->getWindowHandle();
1793 }
1794 }
1795 hwnd = OSLibWinGetNextWindow(henum);
1796 }
1797 OSLibWinEndEnumWindows(henum);
1798 }
1799 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1800 return 0;
1801}
1802//******************************************************************************
1803//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1804//******************************************************************************
1805HWND Win32BaseWindow::GetWindow(UINT uCmd)
1806{
1807 Win32BaseWindow *win32wnd;
1808 ULONG magic;
1809 ULONG getcmd = 0;
1810 HWND hwndRelated;
1811
1812 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1813 switch(uCmd)
1814 {
1815 case GW_CHILD:
1816 getcmd = QWOS_TOP;
1817 break;
1818 case GW_HWNDFIRST:
1819 if(getParent()) {
1820 getcmd = QWOS_TOP; //top of child windows
1821 }
1822 else getcmd = QWOS_TOP; //TODO
1823 break;
1824 case GW_HWNDLAST:
1825 if(getParent()) {
1826 getcmd = QWOS_BOTTOM; //bottom of child windows
1827 }
1828 else getcmd = QWOS_BOTTOM; //TODO
1829 break;
1830 case GW_HWNDNEXT:
1831 getcmd = QWOS_NEXT;
1832 break;
1833 case GW_HWNDPREV:
1834 getcmd = QWOS_PREV;
1835 break;
1836 case GW_OWNER:
1837 if(owner) {
1838 return owner->getWindowHandle();
1839 }
1840 else return 0;
1841 }
1842 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1843 if(hwndRelated)
1844 {
1845 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1846 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1847 if(CheckMagicDword(magic) && win32wnd)
1848 {
1849 return win32wnd->getWindowHandle();
1850 }
1851 }
1852 return 0;
1853}
1854//******************************************************************************
1855//******************************************************************************
1856HWND Win32BaseWindow::SetActiveWindow()
1857{
1858 return OSLibWinSetActiveWindow(OS2Hwnd);
1859}
1860//******************************************************************************
1861//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1862//******************************************************************************
1863BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
1864{
1865 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1866}
1867//******************************************************************************
1868//******************************************************************************
1869BOOL Win32BaseWindow::CloseWindow()
1870{
1871 return OSLibWinMinimizeWindow(OS2Hwnd);
1872}
1873//******************************************************************************
1874//******************************************************************************
1875HWND Win32BaseWindow::GetActiveWindow()
1876{
1877 HWND hwndActive;
1878 Win32BaseWindow *win32wnd;
1879 ULONG magic;
1880
1881 hwndActive = OSLibWinQueryActiveWindow();
1882
1883 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1884 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1885 if(CheckMagicDword(magic) && win32wnd)
1886 {
1887 return win32wnd->getWindowHandle();
1888 }
1889 return hwndActive;
1890}
1891//******************************************************************************
1892//******************************************************************************
1893BOOL Win32BaseWindow::IsWindowEnabled()
1894{
1895 return OSLibWinIsWindowEnabled(OS2Hwnd);
1896}
1897//******************************************************************************
1898//******************************************************************************
1899BOOL Win32BaseWindow::IsWindowVisible()
1900{
1901 return OSLibWinIsWindowVisible(OS2Hwnd);
1902}
1903//******************************************************************************
1904//******************************************************************************
1905BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
1906{
1907 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1908}
1909//******************************************************************************
1910//******************************************************************************
1911BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
1912{
1913 if(fUnicode) {
1914 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
1915 }
1916 else return (strcmp(windowNameA, wndname) == 0);
1917}
1918//******************************************************************************
1919//******************************************************************************
1920int Win32BaseWindow::GetWindowTextLength()
1921{
1922 return wndNameLength;
1923}
1924//******************************************************************************
1925//******************************************************************************
1926int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
1927{
1928 strncpy(lpsz, windowNameA, cch);
1929 return wndNameLength;
1930}
1931//******************************************************************************
1932//******************************************************************************
1933int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
1934{
1935 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
1936 return wndNameLength;
1937}
1938//******************************************************************************
1939//******************************************************************************
1940BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
1941{
1942 if(lpsz == NULL)
1943 return FALSE;
1944
1945 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
1946 strcpy(windowNameA, lpsz);
1947 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
1948 lstrcpyAtoW(windowNameW, windowNameA);
1949 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1950
1951 if(OS2HwndFrame)
1952 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1953
1954 return TRUE;
1955}
1956//******************************************************************************
1957//******************************************************************************
1958BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
1959{
1960 if(lpsz == NULL)
1961 return FALSE;
1962
1963 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
1964 lstrcpyW(windowNameW, (LPWSTR)lpsz);
1965 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
1966 lstrcpyWtoA(windowNameA, windowNameW);
1967 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1968
1969 if(OS2HwndFrame)
1970 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1971
1972 return TRUE;
1973}
1974//******************************************************************************
1975//******************************************************************************
1976LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
1977{
1978 LONG oldval;
1979
1980 switch(index) {
1981 case GWL_EXSTYLE:
1982 oldval = dwExStyle;
1983 setExStyle(value);
1984 return oldval;
1985 case GWL_STYLE:
1986 oldval = dwStyle;
1987 setStyle(value);
1988 return oldval;
1989 case GWL_WNDPROC:
1990 oldval = (LONG)getWindowProc();
1991 setWindowProc((WNDPROC)value);
1992 return oldval;
1993 case GWL_HINSTANCE:
1994 oldval = hInstance;
1995 hInstance = value;
1996 return oldval;
1997 case GWL_HWNDPARENT:
1998 return SetParent((HWND)value);
1999
2000 case GWL_ID:
2001 oldval = getWindowId();
2002 setWindowId(value);
2003 return oldval;
2004 case GWL_USERDATA:
2005 oldval = userData;
2006 userData = value;
2007 return oldval;
2008 default:
2009 if(index >= 0 && index/4 < nrUserWindowLong)
2010 {
2011 oldval = userWindowLong[index/4];
2012 userWindowLong[index/4] = value;
2013 return oldval;
2014 }
2015 SetLastError(ERROR_INVALID_PARAMETER);
2016 return 0;
2017 }
2018}
2019//******************************************************************************
2020//******************************************************************************
2021ULONG Win32BaseWindow::GetWindowLongA(int index)
2022{
2023 switch(index) {
2024 case GWL_EXSTYLE:
2025 return dwExStyle;
2026 case GWL_STYLE:
2027 return dwStyle;
2028 case GWL_WNDPROC:
2029 return (ULONG)getWindowProc();
2030 case GWL_HINSTANCE:
2031 return hInstance;
2032 case GWL_HWNDPARENT:
2033 if(getParent()) {
2034 return getParent()->getWindowHandle();
2035 }
2036 else return 0;
2037 case GWL_ID:
2038 return getWindowId();
2039 case GWL_USERDATA:
2040 return userData;
2041 default:
2042 if(index >= 0 && index/4 < nrUserWindowLong)
2043 {
2044 return userWindowLong[index/4];
2045 }
2046 SetLastError(ERROR_INVALID_PARAMETER);
2047 return 0;
2048 }
2049}
2050//******************************************************************************
2051//******************************************************************************
2052WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2053{
2054 WORD oldval;
2055
2056 if(index >= 0 && index/4 < nrUserWindowLong)
2057 {
2058 oldval = ((WORD *)userWindowLong)[index/2];
2059 ((WORD *)userWindowLong)[index/2] = value;
2060 return oldval;
2061 }
2062 SetLastError(ERROR_INVALID_PARAMETER);
2063 return 0;
2064}
2065//******************************************************************************
2066//******************************************************************************
2067WORD Win32BaseWindow::GetWindowWord(int index)
2068{
2069 if(index >= 0 && index/4 < nrUserWindowLong)
2070 {
2071 return ((WORD *)userWindowLong)[index/2];
2072 }
2073 SetLastError(ERROR_INVALID_PARAMETER);
2074 return 0;
2075}
2076//******************************************************************************
2077//******************************************************************************
2078Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2079{
2080 Win32BaseWindow *window;
2081
2082 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2083 return window;
2084 }
2085 else return NULL;
2086}
2087//******************************************************************************
2088//******************************************************************************
2089Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2090{
2091 Win32BaseWindow *win32wnd;
2092 DWORD magic;
2093
2094 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2095 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2096
2097 if(win32wnd && CheckMagicDword(magic)) {
2098 return win32wnd;
2099 }
2100 return 0;
2101}
2102//******************************************************************************
2103//******************************************************************************
2104GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.