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

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

More dialog update

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