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

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

Dialog update

File size: 72.6 KB
Line 
1/* $Id: win32wbase.cpp,v 1.9 1999-09-05 12:03:33 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 SetWindowTextA((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 case WM_GETDLGCODE:
1162 return 0;
1163
1164 case WM_NCLBUTTONDOWN:
1165 case WM_NCLBUTTONUP:
1166 case WM_NCLBUTTONDBLCLK:
1167 case WM_NCRBUTTONUP:
1168 case WM_NCRBUTTONDOWN:
1169 case WM_NCRBUTTONDBLCLK:
1170 case WM_NCMBUTTONDOWN:
1171 case WM_NCMBUTTONUP:
1172 case WM_NCMBUTTONDBLCLK:
1173 return 0; //TODO: Send WM_SYSCOMMAND if required
1174
1175 case WM_NCHITTEST: //TODO: Calculate position of
1176 return HTCLIENT;
1177
1178 default:
1179 return 1;
1180 }
1181}
1182//******************************************************************************
1183//******************************************************************************
1184LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1185{
1186 switch(Msg)
1187 {
1188 case WM_GETTEXTLENGTH:
1189 return wndNameLength;
1190
1191 case WM_GETTEXT: //TODO: SS_ICON controls
1192 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1193 return min(wndNameLength, wParam);
1194
1195 default:
1196 return DefWindowProcA(Msg, wParam, lParam);
1197 }
1198}
1199//******************************************************************************
1200//******************************************************************************
1201LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1202{
1203 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1204 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1205
1206 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1207 return(0);
1208 }
1209 switch(Msg)
1210 {
1211 case WM_CREATE:
1212 {
1213 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1214 dprintf(("WM_NCCREATE returned FALSE\n"));
1215 return(-1); //don't create window
1216 }
1217 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1218 dprintf(("WM_CREATE returned -1\n"));
1219 return(-1); //don't create window
1220 }
1221 NotifyParent(Msg, wParam, lParam);
1222
1223 return(0);
1224 }
1225 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1226 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1227
1228 case WM_LBUTTONDOWN:
1229 case WM_MBUTTONDOWN:
1230 case WM_RBUTTONDOWN:
1231 NotifyParent(Msg, wParam, lParam);
1232 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1233
1234 case WM_DESTROY:
1235 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1236 NotifyParent(Msg, wParam, lParam);
1237 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1238 default:
1239 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1240 }
1241}
1242//******************************************************************************
1243//******************************************************************************
1244LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1245{
1246 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1247 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1248
1249 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1250 return(0);
1251 }
1252 switch(Msg)
1253 {
1254 case WM_CREATE:
1255 {
1256 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1257 dprintf(("WM_NCCREATE returned FALSE\n"));
1258 return(0); //don't create window
1259 }
1260 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1261 dprintf(("WM_CREATE returned FALSE\n"));
1262 return(0); //don't create window
1263 }
1264 NotifyParent(Msg, wParam, lParam);
1265
1266 return(1);
1267 }
1268 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1269 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1270
1271 case WM_LBUTTONDOWN:
1272 case WM_MBUTTONDOWN:
1273 case WM_RBUTTONDOWN:
1274 NotifyParent(Msg, wParam, lParam);
1275 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1276
1277 case WM_DESTROY:
1278 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1279 NotifyParent(Msg, wParam, lParam);
1280 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1281
1282 default:
1283 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1284 }
1285}
1286//******************************************************************************
1287//Called as a result of an OS/2 message
1288//******************************************************************************
1289LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1290{
1291 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1292 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1293
1294 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1295 return(0);
1296 }
1297 switch(Msg)
1298 {
1299 case WM_CREATE:
1300 {
1301 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1302 dprintf(("WM_NCCREATE returned FALSE\n"));
1303 return(0); //don't create window
1304 }
1305 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1306 dprintf(("WM_CREATE returned FALSE\n"));
1307 return(0); //don't create window
1308 }
1309 NotifyParent(Msg, wParam, lParam);
1310
1311 return(1);
1312 }
1313 case WM_LBUTTONDOWN:
1314 case WM_MBUTTONDOWN:
1315 case WM_RBUTTONDOWN:
1316 NotifyParent(Msg, wParam, lParam);
1317 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1318
1319 case WM_DESTROY:
1320 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1321 NotifyParent(Msg, wParam, lParam);
1322 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1323 default:
1324 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1325 }
1326}
1327//******************************************************************************
1328//Called as a result of an OS/2 message
1329//todo, unicode msgs (WM_SETTEXT etc)
1330//******************************************************************************
1331LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1332{
1333 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1334 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1335
1336 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1337 return(0);
1338 }
1339 switch(Msg)
1340 {
1341 case WM_CREATE:
1342 {
1343 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
1344 dprintf(("WM_NCCREATE returned FALSE\n"));
1345 return(0); //don't create window
1346 }
1347 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1348 dprintf(("WM_CREATE returned FALSE\n"));
1349 return(0); //don't create window
1350 }
1351 NotifyParent(Msg, wParam, lParam);
1352
1353 return(1);
1354 }
1355 case WM_LBUTTONDOWN:
1356 case WM_MBUTTONDOWN:
1357 case WM_RBUTTONDOWN:
1358 NotifyParent(Msg, wParam, lParam);
1359 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1360
1361 case WM_DESTROY:
1362 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1363 NotifyParent(Msg, wParam, lParam);
1364 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1365 default:
1366 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1367 }
1368}
1369//******************************************************************************
1370//******************************************************************************
1371BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1372{
1373 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1374}
1375//******************************************************************************
1376//******************************************************************************
1377BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1378{
1379 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1380}
1381//******************************************************************************
1382//TODO: do we need to inform the parent of the parent (etc) of the child window?
1383//******************************************************************************
1384void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1385{
1386 Win32BaseWindow *window = this;
1387 Win32BaseWindow *parentwindow;
1388
1389 while(window)
1390 {
1391 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1392 {
1393 /* Notify the parent window only */
1394 parentwindow = window->getParent();
1395 if(parentwindow) {
1396 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1397 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1398 }
1399 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1400 }
1401 }
1402 else break;
1403
1404 window = parentwindow;
1405 }
1406}
1407//******************************************************************************
1408//******************************************************************************
1409BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1410{
1411 PVOID menutemplate;
1412 Win32Resource *winres = (Win32Resource *)hMenu;
1413
1414 dprintf(("SetMenu %x", hMenu));
1415 if(HIWORD(winres) == 0) {
1416 dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
1417 SetLastError(ERROR_INVALID_PARAMETER);
1418 return FALSE;
1419 }
1420 menutemplate = winres->lockOS2Resource();
1421 if(menutemplate == NULL)
1422 {
1423 dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
1424 return FALSE;
1425 }
1426 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1427 if(OS2HwndMenu == 0) {
1428 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1429 return FALSE;
1430 }
1431 winres->setOS2Handle(OS2HwndMenu);
1432 menuResource = winres;
1433 return TRUE;
1434}
1435//******************************************************************************
1436//******************************************************************************
1437BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1438{
1439 Win32Resource *winres = (Win32Resource *)hAccel;
1440 HANDLE accelhandle;
1441
1442 if(HIWORD(hAccel) == 0) {
1443 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1444 SetLastError(ERROR_INVALID_PARAMETER);
1445 return FALSE;
1446 }
1447 acceltableResource = winres;
1448 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1449 winres->setOS2Handle(accelhandle);
1450 return(accelhandle != 0);
1451}
1452//******************************************************************************
1453//******************************************************************************
1454BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1455{
1456 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1457 return OSLibWinSetIcon(OS2HwndFrame, hIcon);
1458}
1459//******************************************************************************
1460//******************************************************************************
1461BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1462{
1463 ULONG showstate = 0;
1464
1465 dprintf(("ShowWindow %x", nCmdShow));
1466 if(fFirstShow) {
1467 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1468 SendMessageA(WM_SIZE, SIZE_RESTORED,
1469 MAKELONG(rectClient.right-rectClient.left,
1470 rectClient.bottom-rectClient.top));
1471 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1472
1473 }
1474 fFirstShow = FALSE;
1475 }
1476 switch(nCmdShow)
1477 {
1478 case SW_SHOW:
1479 case SW_SHOWDEFAULT: //todo
1480 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1481 break;
1482 case SW_HIDE:
1483 showstate = SWPOS_HIDE;
1484 break;
1485 case SW_RESTORE:
1486 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1487 break;
1488 case SW_MINIMIZE:
1489 showstate = SWPOS_MINIMIZE;
1490 break;
1491 case SW_SHOWMAXIMIZED:
1492 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1493 break;
1494 case SW_SHOWMINIMIZED:
1495 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1496 break;
1497 case SW_SHOWMINNOACTIVE:
1498 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1499 break;
1500 case SW_SHOWNA:
1501 showstate = SWPOS_SHOW;
1502 break;
1503 case SW_SHOWNOACTIVATE:
1504 showstate = SWPOS_SHOW;
1505 break;
1506 case SW_SHOWNORMAL:
1507 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1508 break;
1509 }
1510 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1511}
1512//******************************************************************************
1513//******************************************************************************
1514BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1515{
1516 BOOL rc = FALSE;
1517 Win32BaseWindow *window;
1518 HWND hParent = 0;
1519
1520 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1521
1522 /* Validate the flags passed in ... */
1523 if ( fuFlags &
1524 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1525 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1526 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1527 SWP_NOOWNERZORDER) )
1528 {
1529 return FALSE;
1530 }
1531
1532 WINDOWPOS wpos;
1533 SWP swp, swpOld;
1534
1535 //****************************
1536 // Set up with Windows values.
1537 //****************************
1538 wpos.flags = fuFlags;
1539 wpos.cy = cy;
1540 wpos.cx = cx;
1541 wpos.x = x;
1542 wpos.y = y;
1543 wpos.hwndInsertAfter = hwndInsertAfter;
1544 wpos.hwnd = getWindowHandle();
1545
1546 //**********************************************
1547 // Convert from Windows to PM coords and flags.
1548 //**********************************************
1549 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1550 if (isChild())
1551 {
1552 hParent = getParent()->getOS2WindowHandle();
1553 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1554 } else
1555 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1556 }
1557 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1558
1559 /* MapSWP can clear the SWP_MOVE and SWP_SIZE flags if the window is not
1560 * being moved or sized. If these were the only operations to be done
1561 * and they have been cleared, return now.
1562 */
1563 if (swp.fl == 0)
1564 return TRUE;
1565
1566 //*********************************************************************
1567 //On Windows, a WM_GETMINMAXINFO is made to the app from within this API.
1568 //We'll send a WM_QUERYTRACKINFO which is translated into a WM_GETMINMAXINFO
1569 //and passed on to the app. Compare the values returned with the SWP cx and
1570 //cy values. They cannot be bigger than the max nor smaller than the min.
1571 //*********************************************************************
1572
1573 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1574 {
1575 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1576 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1577 }
1578 if (isFrameWindow())
1579 {
1580 POINT maxSize, maxPos, minTrack, maxTrack;
1581
1582 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1583
1584 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1585 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1586 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1587 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1588 swp.hwnd = OS2HwndFrame;
1589 } else
1590 swp.hwnd = OS2Hwnd;
1591 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1592
1593 //*****************************************************************************
1594 // Squibble the window. (WinSetMultWindowPos is faster than WinSetWindowPos.)
1595 //*****************************************************************************
1596 rc = OSLibWinSetMultWindowPos(&swp, 1);
1597
1598 if (rc == FALSE)
1599 {
1600// SET_ERROR_LAST();
1601 }
1602 else
1603 {
1604 /* To implement support for SWP_FRAMECHANGED_W correctly, we would need
1605 ** to send a WM_NCCALCSIZE message. This means DAX would have to support
1606 ** the WM_NCCALCSIZE message. I don't think DAX can support this
1607 ** message because it is tightly bound with the architecture of
1608 ** overlapped windows (the "just one window" architecture). However,
1609 ** we *can* support the SWP_FRAMECHANGED flag by sending the window
1610 ** a WM_UPDATEFRAME, which will provide the behavior of WM_NCCALCSIZE.
1611 */
1612// if (fuFlags & SWP_FRAMECHANGED_W)
1613// WinSendMsg(hWindow, WM_UPDATEFRAME, (MPARAM)-1, 0);
1614 }
1615
1616 return (rc);
1617}
1618//******************************************************************************
1619//Also destroys all the child windows (destroy parent, destroy children)
1620//******************************************************************************
1621BOOL Win32BaseWindow::DestroyWindow()
1622{
1623 return OSLibWinDestroyWindow(OS2HwndFrame);
1624}
1625//******************************************************************************
1626//******************************************************************************
1627HWND Win32BaseWindow::GetParent()
1628{
1629 if(getParent()) {
1630 return getParent()->getWindowHandle();
1631 }
1632 else return 0;
1633}
1634//******************************************************************************
1635//******************************************************************************
1636HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1637{
1638 HWND oldhwnd;
1639 Win32BaseWindow *newparent;
1640
1641 if(getParent()) {
1642 oldhwnd = getParent()->getWindowHandle();
1643 }
1644 else oldhwnd = 0;
1645
1646 if(hwndNewParent == 0) {//desktop window = parent
1647 setParent(NULL);
1648 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1649 return oldhwnd;
1650 }
1651 newparent = GetWindowFromHandle(hwndNewParent);
1652 if(newparent)
1653 {
1654 setParent(newparent);
1655 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1656 return oldhwnd;
1657 }
1658 SetLastError(ERROR_INVALID_PARAMETER);
1659 return 0;
1660}
1661//******************************************************************************
1662//******************************************************************************
1663BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1664{
1665 if(getParent()) {
1666 return getParent()->getWindowHandle() == hwndParent;
1667 }
1668 else return 0;
1669}
1670//******************************************************************************
1671//******************************************************************************
1672HWND Win32BaseWindow::GetTopWindow()
1673{
1674 return GetWindow(GW_CHILD);
1675}
1676//******************************************************************************
1677//Don't call WinUpdateWindow as that one also updates the child windows
1678//Also need to send WM_PAINT directly to the window procedure, which doesn't
1679//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1680//******************************************************************************
1681BOOL Win32BaseWindow::UpdateWindow()
1682{
1683 RECT rect;
1684
1685 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1686 {//update region not empty
1687 HDC hdc;
1688
1689 hdc = O32_GetDC(OS2Hwnd);
1690 if (isIcon)
1691 {
1692 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1693 SendInternalMessageA(WM_PAINTICON, 0, 0);
1694 } else
1695 {
1696 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1697 SendInternalMessageA(WM_PAINT, 0, 0);
1698 }
1699 O32_ReleaseDC(OS2Hwnd, hdc);
1700 }
1701 return TRUE;
1702}
1703//******************************************************************************
1704//******************************************************************************
1705BOOL Win32BaseWindow::IsIconic()
1706{
1707 return OSLibWinIsIconic(OS2Hwnd);
1708}
1709//******************************************************************************
1710//TODO:
1711//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1712//the current process owns them.
1713//******************************************************************************
1714HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1715 BOOL fUnicode)
1716{
1717 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1718 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1719
1720 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1721 (hwndChildAfter != 0 && !child) ||
1722 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1723 {
1724 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1725 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1726 return 0;
1727 }
1728 if(hwndParent != OSLIB_HWND_DESKTOP)
1729 {//if the current process owns the window, just do a quick search
1730 child = (Win32BaseWindow *)parent->getFirstChild();
1731 if(hwndChildAfter != 0)
1732 {
1733 while(child)
1734 {
1735 if(child->getWindowHandle() == hwndChildAfter)
1736 {
1737 child = (Win32BaseWindow *)child->getNextChild();
1738 break;
1739 }
1740 child = (Win32BaseWindow *)child->getNextChild();
1741 }
1742 }
1743 while(child)
1744 {
1745 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1746 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1747 {
1748 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1749 return child->getWindowHandle();
1750 }
1751 child = (Win32BaseWindow *)child->getNextChild();
1752 }
1753 }
1754 else {
1755 Win32BaseWindow *wnd;
1756 HWND henum, hwnd;
1757
1758 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1759 hwnd = OSLibWinGetNextWindow(henum);
1760
1761 while(hwnd)
1762 {
1763 wnd = GetWindowFromOS2Handle(hwnd);
1764 if(wnd == NULL) {
1765 hwnd = OSLibWinQueryClientWindow(hwnd);
1766 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1767 }
1768
1769 if(wnd) {
1770 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1771
1772 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1773 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1774 break;
1775 }
1776 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1777 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1778 {
1779 OSLibWinEndEnumWindows(henum);
1780 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1781 return wnd->getWindowHandle();
1782 }
1783 }
1784 hwnd = OSLibWinGetNextWindow(henum);
1785 }
1786 OSLibWinEndEnumWindows(henum);
1787 }
1788 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1789 return 0;
1790}
1791//******************************************************************************
1792//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1793//******************************************************************************
1794HWND Win32BaseWindow::GetWindow(UINT uCmd)
1795{
1796 Win32BaseWindow *win32wnd;
1797 ULONG magic;
1798 ULONG getcmd = 0;
1799 HWND hwndRelated;
1800
1801 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1802 switch(uCmd)
1803 {
1804 case GW_CHILD:
1805 getcmd = QWOS_TOP;
1806 break;
1807 case GW_HWNDFIRST:
1808 if(getParent()) {
1809 getcmd = QWOS_TOP; //top of child windows
1810 }
1811 else getcmd = QWOS_TOP; //TODO
1812 break;
1813 case GW_HWNDLAST:
1814 if(getParent()) {
1815 getcmd = QWOS_BOTTOM; //bottom of child windows
1816 }
1817 else getcmd = QWOS_BOTTOM; //TODO
1818 break;
1819 case GW_HWNDNEXT:
1820 getcmd = QWOS_NEXT;
1821 break;
1822 case GW_HWNDPREV:
1823 getcmd = QWOS_PREV;
1824 break;
1825 case GW_OWNER:
1826 if(owner) {
1827 return owner->getWindowHandle();
1828 }
1829 else return 0;
1830 }
1831 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1832 if(hwndRelated)
1833 {
1834 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1835 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1836 if(CheckMagicDword(magic) && win32wnd)
1837 {
1838 return win32wnd->getWindowHandle();
1839 }
1840 }
1841 return 0;
1842}
1843//******************************************************************************
1844//******************************************************************************
1845HWND Win32BaseWindow::SetActiveWindow()
1846{
1847 return OSLibWinSetActiveWindow(OS2Hwnd);
1848}
1849//******************************************************************************
1850//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1851//******************************************************************************
1852BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
1853{
1854 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1855}
1856//******************************************************************************
1857//******************************************************************************
1858BOOL Win32BaseWindow::CloseWindow()
1859{
1860 return OSLibWinMinimizeWindow(OS2Hwnd);
1861}
1862//******************************************************************************
1863//******************************************************************************
1864HWND Win32BaseWindow::GetActiveWindow()
1865{
1866 HWND hwndActive;
1867 Win32BaseWindow *win32wnd;
1868 ULONG magic;
1869
1870 hwndActive = OSLibWinQueryActiveWindow();
1871
1872 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1873 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1874 if(CheckMagicDword(magic) && win32wnd)
1875 {
1876 return win32wnd->getWindowHandle();
1877 }
1878 return hwndActive;
1879}
1880//******************************************************************************
1881//******************************************************************************
1882BOOL Win32BaseWindow::IsWindowEnabled()
1883{
1884 return OSLibWinIsWindowEnabled(OS2Hwnd);
1885}
1886//******************************************************************************
1887//******************************************************************************
1888BOOL Win32BaseWindow::IsWindowVisible()
1889{
1890 return OSLibWinIsWindowVisible(OS2Hwnd);
1891}
1892//******************************************************************************
1893//******************************************************************************
1894BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
1895{
1896 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1897}
1898//******************************************************************************
1899//******************************************************************************
1900BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
1901{
1902 if(fUnicode) {
1903 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
1904 }
1905 else return (strcmp(windowNameA, wndname) == 0);
1906}
1907//******************************************************************************
1908//******************************************************************************
1909int Win32BaseWindow::GetWindowTextLength()
1910{
1911 return wndNameLength;
1912}
1913//******************************************************************************
1914//******************************************************************************
1915int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
1916{
1917 strncpy(lpsz, windowNameA, cch);
1918 return wndNameLength;
1919}
1920//******************************************************************************
1921//******************************************************************************
1922int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
1923{
1924 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
1925 return wndNameLength;
1926}
1927//******************************************************************************
1928//******************************************************************************
1929BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
1930{
1931 if(lpsz == NULL)
1932 return FALSE;
1933
1934 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
1935 strcpy(windowNameA, lpsz);
1936 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
1937 lstrcpyAtoW(windowNameW, windowNameA);
1938 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1939
1940 if(OS2HwndFrame)
1941 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1942
1943 return TRUE;
1944}
1945//******************************************************************************
1946//******************************************************************************
1947BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
1948{
1949 if(lpsz == NULL)
1950 return FALSE;
1951
1952 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
1953 lstrcpyW(windowNameW, (LPWSTR)lpsz);
1954 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
1955 lstrcpyWtoA(windowNameA, windowNameW);
1956 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1957
1958 if(OS2HwndFrame)
1959 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1960
1961 return TRUE;
1962}
1963//******************************************************************************
1964//******************************************************************************
1965LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
1966{
1967 LONG oldval;
1968
1969 switch(index) {
1970 case GWL_EXSTYLE:
1971 oldval = dwExStyle;
1972 setExStyle(value);
1973 return oldval;
1974 case GWL_STYLE:
1975 oldval = dwStyle;
1976 setStyle(value);
1977 return oldval;
1978 case GWL_WNDPROC:
1979 oldval = (LONG)getWindowProc();
1980 setWindowProc((WNDPROC)value);
1981 return oldval;
1982 case GWL_HINSTANCE:
1983 oldval = hInstance;
1984 hInstance = value;
1985 return oldval;
1986 case GWL_HWNDPARENT:
1987 return SetParent((HWND)value);
1988
1989 case GWL_ID:
1990 oldval = getWindowId();
1991 setWindowId(value);
1992 return oldval;
1993 case GWL_USERDATA:
1994 oldval = userData;
1995 userData = value;
1996 return oldval;
1997 default:
1998 if(index >= 0 && index/4 < nrUserWindowLong)
1999 {
2000 oldval = userWindowLong[index/4];
2001 userWindowLong[index/4] = value;
2002 return oldval;
2003 }
2004 SetLastError(ERROR_INVALID_PARAMETER);
2005 return 0;
2006 }
2007}
2008//******************************************************************************
2009//******************************************************************************
2010ULONG Win32BaseWindow::GetWindowLongA(int index)
2011{
2012 switch(index) {
2013 case GWL_EXSTYLE:
2014 return dwExStyle;
2015 case GWL_STYLE:
2016 return dwStyle;
2017 case GWL_WNDPROC:
2018 return (ULONG)getWindowProc();
2019 case GWL_HINSTANCE:
2020 return hInstance;
2021 case GWL_HWNDPARENT:
2022 if(getParent()) {
2023 return getParent()->getWindowHandle();
2024 }
2025 else return 0;
2026 case GWL_ID:
2027 return getWindowId();
2028 case GWL_USERDATA:
2029 return userData;
2030 default:
2031 if(index >= 0 && index/4 < nrUserWindowLong)
2032 {
2033 return userWindowLong[index/4];
2034 }
2035 SetLastError(ERROR_INVALID_PARAMETER);
2036 return 0;
2037 }
2038}
2039//******************************************************************************
2040//******************************************************************************
2041WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2042{
2043 WORD oldval;
2044
2045 if(index >= 0 && index/4 < nrUserWindowLong)
2046 {
2047 oldval = ((WORD *)userWindowLong)[index/2];
2048 ((WORD *)userWindowLong)[index/2] = value;
2049 return oldval;
2050 }
2051 SetLastError(ERROR_INVALID_PARAMETER);
2052 return 0;
2053}
2054//******************************************************************************
2055//******************************************************************************
2056WORD Win32BaseWindow::GetWindowWord(int index)
2057{
2058 if(index >= 0 && index/4 < nrUserWindowLong)
2059 {
2060 return ((WORD *)userWindowLong)[index/2];
2061 }
2062 SetLastError(ERROR_INVALID_PARAMETER);
2063 return 0;
2064}
2065//******************************************************************************
2066//******************************************************************************
2067Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2068{
2069 Win32BaseWindow *window;
2070
2071 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2072 return window;
2073 }
2074 else return NULL;
2075}
2076//******************************************************************************
2077//******************************************************************************
2078Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2079{
2080 Win32BaseWindow *win32wnd;
2081 DWORD magic;
2082
2083 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2084 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2085
2086 if(win32wnd && CheckMagicDword(magic)) {
2087 return win32wnd;
2088 }
2089 return 0;
2090}
2091//******************************************************************************
2092//******************************************************************************
2093GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.