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

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

Window text + dialog fixes

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