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

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

release private window DC

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