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

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

Dialog changes

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