source: trunk/src/user32/win32wbase.cpp@ 992

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

Fixes for incorrect background color for button, group & static text

File size: 73.3 KB
Line 
1/* $Id: win32wbase.cpp,v 1.4 1999-09-20 19:17:58 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#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, OS2ToWin32Handle (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, OS2ToWin32Handle (hwnd), 0);
909}
910//******************************************************************************
911//******************************************************************************
912//******************************************************************************
913ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
914{
915 ULONG win32msg;
916 ULONG win32ncmsg;
917
918 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
919 switch(msg) {
920 case BUTTON_LEFTDOWN:
921 win32msg = WM_LBUTTONDOWN;
922 win32ncmsg = WM_NCLBUTTONDOWN;
923 break;
924 case BUTTON_LEFTUP:
925 win32msg = WM_LBUTTONUP;
926 win32ncmsg = WM_NCLBUTTONUP;
927 break;
928 case BUTTON_LEFTDBLCLICK:
929 win32msg = WM_LBUTTONDBLCLK;
930 win32ncmsg = WM_NCLBUTTONDBLCLK;
931 break;
932 case BUTTON_RIGHTUP:
933 win32msg = WM_RBUTTONUP;
934 win32ncmsg = WM_NCRBUTTONUP;
935 break;
936 case BUTTON_RIGHTDOWN:
937 win32msg = WM_RBUTTONDOWN;
938 win32ncmsg = WM_NCRBUTTONDOWN;
939 break;
940 case BUTTON_RIGHTDBLCLICK:
941 win32msg = WM_RBUTTONDBLCLK;
942 win32ncmsg = WM_NCRBUTTONDBLCLK;
943 break;
944 case BUTTON_MIDDLEUP:
945 win32msg = WM_MBUTTONUP;
946 win32ncmsg = WM_NCMBUTTONUP;
947 break;
948 case BUTTON_MIDDLEDOWN:
949 win32msg = WM_MBUTTONDOWN;
950 win32ncmsg = WM_NCMBUTTONDOWN;
951 break;
952 case BUTTON_MIDDLEDBLCLICK:
953 win32msg = WM_MBUTTONDBLCLK;
954 win32ncmsg = WM_NCMBUTTONDBLCLK;
955 break;
956 default:
957 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
958 return 1;
959 }
960 if(win32msg == WM_MBUTTONDBLCLK || win32msg == WM_RBUTTONDBLCLK || win32msg == WM_LBUTTONDBLCLK) {
961 if(!(windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)) {
962 return 1;
963 }
964 }
965 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
966
967 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
968 if(lastHitTestVal != HTCLIENT) {
969 SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
970 }
971 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
972}
973//******************************************************************************
974//******************************************************************************
975ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
976{
977 ULONG winstate = 0;
978 ULONG setcursormsg = WM_MOUSEMOVE;
979
980 if(keystate & WMMOVE_LBUTTON)
981 winstate |= MK_LBUTTON;
982 if(keystate & WMMOVE_RBUTTON)
983 winstate |= MK_RBUTTON;
984 if(keystate & WMMOVE_MBUTTON)
985 winstate |= MK_MBUTTON;
986 if(keystate & WMMOVE_SHIFT)
987 winstate |= MK_SHIFT;
988 if(keystate & WMMOVE_CTRL)
989 winstate |= MK_CONTROL;
990
991 if(lastHitTestVal != HTCLIENT) {
992 setcursormsg = WM_NCMOUSEMOVE;
993 }
994 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
995 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
996
997 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
998 if(lastHitTestVal != HTCLIENT) {
999 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1000 }
1001 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1002}
1003//******************************************************************************
1004//******************************************************************************
1005ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1006{
1007 if (select && isIcon)
1008 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1009 else
1010 return SendInternalMessageA(WM_PAINT, 0, 0);
1011}
1012//******************************************************************************
1013//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1014// (or are we simply erasing too much here)
1015//******************************************************************************
1016ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1017{
1018 ULONG rc;
1019 HDC hdcErase = hdc;
1020
1021 if (hdcErase == 0)
1022 hdcErase = GetDC(Win32Hwnd);
1023
1024 if(isIcon)
1025 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1026 else
1027 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1028 if (hdc == 0)
1029 ReleaseDC(Win32Hwnd, hdcErase);
1030 return (rc);
1031}
1032//******************************************************************************
1033//******************************************************************************
1034ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1035{
1036 if(isUnicode) {
1037 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1038 }
1039 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1040}
1041//******************************************************************************
1042//TODO: in- or excluding terminating 0?
1043//******************************************************************************
1044ULONG Win32BaseWindow::MsgGetTextLength()
1045{
1046 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1047}
1048//******************************************************************************
1049//******************************************************************************
1050char *Win32BaseWindow::MsgGetText()
1051{
1052 if(isUnicode) {
1053 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1054 }
1055 else {
1056 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1057 }
1058 return windowNameA;
1059}
1060//******************************************************************************
1061//******************************************************************************
1062LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1063{
1064 switch(Msg)
1065 {
1066 case WM_GETTEXTLENGTH:
1067 return wndNameLength;
1068
1069 case WM_GETTEXT: //TODO: SS_ICON controls
1070 strncpy((LPSTR)lParam, windowNameA, wParam);
1071 return min(wndNameLength, wParam);
1072
1073 case WM_SETTEXT:
1074 return 0;
1075
1076 case WM_SETREDRAW:
1077 if(wParam)
1078 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1079 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1080
1081 return 0; //TODO
1082
1083 case WM_NCCREATE:
1084 return(TRUE);
1085
1086 //SvL: Set background color to default button color (not window (white))
1087 case WM_CTLCOLORBTN:
1088 SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
1089 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1090 return GetSysColorBrush(COLOR_BTNFACE);
1091
1092 //SvL: Set background color to default dialog color if window is dialog
1093 case WM_CTLCOLORDLG:
1094 case WM_CTLCOLORSTATIC:
1095 if(IsDialog()) {
1096 SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
1097 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1098 return GetSysColorBrush(COLOR_BTNFACE);
1099 }
1100 //no break
1101
1102 case WM_CTLCOLORMSGBOX:
1103 case WM_CTLCOLOREDIT:
1104 case WM_CTLCOLORLISTBOX:
1105 case WM_CTLCOLORSCROLLBAR:
1106 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1107 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1108 return GetSysColorBrush(COLOR_BTNFACE);
1109
1110 case WM_PARENTNOTIFY:
1111 return 0;
1112
1113 case WM_MOUSEACTIVATE:
1114 {
1115 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1116 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1117 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1118 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1119 {
1120 if(getParent()) {
1121 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1122 if(rc) return rc;
1123 }
1124 }
1125 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1126 }
1127 case WM_SETCURSOR:
1128 {
1129 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1130 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1131 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1132 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1133 {
1134 if(getParent()) {
1135 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1136 if(rc) return rc;
1137 }
1138 }
1139 return 1;
1140 }
1141 case WM_MOUSEMOVE:
1142 return 0;
1143
1144 case WM_WINDOWPOSCHANGED:
1145 {
1146
1147/* undocumented SWP flags - from SDK 3.1 */
1148#define SWP_NOCLIENTSIZE 0x0800
1149#define SWP_NOCLIENTMOVE 0x1000
1150
1151 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1152 WPARAM wp = SIZE_RESTORED;
1153
1154 if (!(wpos->flags & SWP_NOCLIENTMOVE))
1155 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1156
1157 if (!(wpos->flags & SWP_NOCLIENTSIZE))
1158 {
1159 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1160 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1161
1162 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1163 rectClient.bottom - rectClient.top));
1164 }
1165 return 0;
1166 }
1167 case WM_ERASEBKGND:
1168 case WM_ICONERASEBKGND:
1169 {
1170 RECT rect;
1171 int rc;
1172
1173 if (!windowClass->getBackgroundBrush()) return 0;
1174
1175 /* Since WM_ERASEBKGND may receive either a window dc or a */
1176 /* client dc, the area to be erased has to be retrieved from */
1177 /* the device context. */
1178 rc = GetClipBox( (HDC)wParam, &rect );
1179 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1180 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1181
1182 return 1;
1183 }
1184 case WM_GETDLGCODE:
1185 return 0;
1186
1187 case WM_NCLBUTTONDOWN:
1188 case WM_NCLBUTTONUP:
1189 case WM_NCLBUTTONDBLCLK:
1190 case WM_NCRBUTTONUP:
1191 case WM_NCRBUTTONDOWN:
1192 case WM_NCRBUTTONDBLCLK:
1193 case WM_NCMBUTTONDOWN:
1194 case WM_NCMBUTTONUP:
1195 case WM_NCMBUTTONDBLCLK:
1196 return 0; //TODO: Send WM_SYSCOMMAND if required
1197
1198 case WM_NCHITTEST: //TODO: Calculate position of
1199 return HTCLIENT;
1200
1201 default:
1202 return 1;
1203 }
1204}
1205//******************************************************************************
1206//******************************************************************************
1207LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1208{
1209 switch(Msg)
1210 {
1211 case WM_GETTEXTLENGTH:
1212 return wndNameLength;
1213
1214 case WM_GETTEXT: //TODO: SS_ICON controls
1215 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1216 return min(wndNameLength, wParam);
1217
1218 default:
1219 return DefWindowProcA(Msg, wParam, lParam);
1220 }
1221}
1222//******************************************************************************
1223//******************************************************************************
1224LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1225{
1226 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1227 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1228 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1229 }
1230
1231 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1232 return(0);
1233 }
1234 switch(Msg)
1235 {
1236 case WM_CREATE:
1237 {
1238 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1239 dprintf(("WM_CREATE returned -1\n"));
1240 return(-1); //don't create window
1241 }
1242 NotifyParent(Msg, wParam, lParam);
1243
1244 return(0);
1245 }
1246 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1247 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1248
1249 case WM_LBUTTONDOWN:
1250 case WM_MBUTTONDOWN:
1251 case WM_RBUTTONDOWN:
1252 NotifyParent(Msg, wParam, lParam);
1253 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1254
1255 case WM_DESTROY:
1256 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1257 NotifyParent(Msg, wParam, lParam);
1258 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1259 default:
1260 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1261 }
1262}
1263//******************************************************************************
1264//******************************************************************************
1265LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1266{
1267 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1268 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1269 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1270 }
1271
1272 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1273 return(0);
1274 }
1275 switch(Msg)
1276 {
1277 case WM_CREATE:
1278 {
1279 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1280 dprintf(("WM_CREATE returned FALSE\n"));
1281 return(0); //don't create window
1282 }
1283 NotifyParent(Msg, wParam, lParam);
1284
1285 return(1);
1286 }
1287 case WM_SETTEXT: //TODO: Nothing happens if passed to DefWindowProc
1288 return win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1289
1290 case WM_LBUTTONDOWN:
1291 case WM_MBUTTONDOWN:
1292 case WM_RBUTTONDOWN:
1293 NotifyParent(Msg, wParam, lParam);
1294 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1295
1296 case WM_DESTROY:
1297 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1298 NotifyParent(Msg, wParam, lParam);
1299 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1300
1301 default:
1302 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1303 }
1304}
1305//******************************************************************************
1306//Called as a result of an OS/2 message
1307//******************************************************************************
1308LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1309{
1310 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1311 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1312
1313 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1314 return(0);
1315 }
1316 switch(Msg)
1317 {
1318 case WM_CREATE:
1319 {
1320 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1321 dprintf(("WM_CREATE returned FALSE\n"));
1322 return(0); //don't create window
1323 }
1324 NotifyParent(Msg, wParam, lParam);
1325
1326 return(1);
1327 }
1328 case WM_LBUTTONDOWN:
1329 case WM_MBUTTONDOWN:
1330 case WM_RBUTTONDOWN:
1331 NotifyParent(Msg, wParam, lParam);
1332 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1333
1334 case WM_DESTROY:
1335 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1336 NotifyParent(Msg, wParam, lParam);
1337 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1338 default:
1339 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1340 }
1341}
1342//******************************************************************************
1343//Called as a result of an OS/2 message
1344//todo, unicode msgs (WM_SETTEXT etc)
1345//******************************************************************************
1346LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1347{
1348 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1349 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1350
1351 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1352 return(0);
1353 }
1354 switch(Msg)
1355 {
1356 case WM_CREATE:
1357 {
1358 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
1359 dprintf(("WM_CREATE returned FALSE\n"));
1360 return(0); //don't create window
1361 }
1362 NotifyParent(Msg, wParam, lParam);
1363
1364 return(1);
1365 }
1366 case WM_LBUTTONDOWN:
1367 case WM_MBUTTONDOWN:
1368 case WM_RBUTTONDOWN:
1369 NotifyParent(Msg, wParam, lParam);
1370 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1371
1372 case WM_DESTROY:
1373 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1374 NotifyParent(Msg, wParam, lParam);
1375 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1376 default:
1377 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1378 }
1379}
1380//******************************************************************************
1381//******************************************************************************
1382BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1383{
1384 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1385}
1386//******************************************************************************
1387//******************************************************************************
1388BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1389{
1390 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1391}
1392//******************************************************************************
1393//TODO: do we need to inform the parent of the parent (etc) of the child window?
1394//******************************************************************************
1395void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1396{
1397 Win32BaseWindow *window = this;
1398 Win32BaseWindow *parentwindow;
1399
1400 while(window)
1401 {
1402 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1403 {
1404 /* Notify the parent window only */
1405 parentwindow = window->getParent();
1406 if(parentwindow) {
1407 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1408 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1409 }
1410 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1411 }
1412 }
1413 else break;
1414
1415 window = parentwindow;
1416 }
1417}
1418//******************************************************************************
1419//******************************************************************************
1420Win32BaseWindow *Win32BaseWindow::getTopParent()
1421{
1422 Win32BaseWindow *tmpWnd = this;
1423
1424 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1425 {
1426 tmpWnd = tmpWnd->getParent();
1427 }
1428 return tmpWnd;
1429}
1430//******************************************************************************
1431//******************************************************************************
1432BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1433{
1434 PVOID menutemplate;
1435 Win32Resource *winres = (Win32Resource *)hMenu;
1436
1437 dprintf(("SetMenu %x", hMenu));
1438 if(HIWORD(winres) == 0) {
1439 dprintf(("Win32BaseWindow:: Win32Resource *winres == 0"));
1440 SetLastError(ERROR_INVALID_PARAMETER);
1441 return FALSE;
1442 }
1443 menutemplate = winres->lockOS2Resource();
1444 if(menutemplate == NULL)
1445 {
1446 dprintf(("Win32BaseWindow::SetMenu menutemplate == 0"));
1447 return FALSE;
1448 }
1449 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1450 if(OS2HwndMenu == 0) {
1451 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1452 return FALSE;
1453 }
1454 winres->setOS2Handle(OS2HwndMenu);
1455 menuResource = winres;
1456 return TRUE;
1457}
1458//******************************************************************************
1459//******************************************************************************
1460BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1461{
1462 Win32Resource *winres = (Win32Resource *)hAccel;
1463 HANDLE accelhandle;
1464
1465 if(HIWORD(hAccel) == 0) {
1466 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1467 SetLastError(ERROR_INVALID_PARAMETER);
1468 return FALSE;
1469 }
1470 acceltableResource = winres;
1471 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1472 winres->setOS2Handle(accelhandle);
1473 return(accelhandle != 0);
1474}
1475//******************************************************************************
1476//******************************************************************************
1477BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1478{
1479 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1480 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1481 SendInternalMessageA(WM_SETICON, hIcon, 0);
1482 return TRUE;
1483 }
1484 return FALSE;
1485}
1486//******************************************************************************
1487//******************************************************************************
1488BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1489{
1490 ULONG showstate = 0;
1491
1492 dprintf(("ShowWindow %x", nCmdShow));
1493 if(fFirstShow) {
1494 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1495 SendMessageA(WM_SIZE, SIZE_RESTORED,
1496 MAKELONG(rectClient.right-rectClient.left,
1497 rectClient.bottom-rectClient.top));
1498 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1499
1500 }
1501 fFirstShow = FALSE;
1502 }
1503 switch(nCmdShow)
1504 {
1505 case SW_SHOW:
1506 case SW_SHOWDEFAULT: //todo
1507 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1508 break;
1509 case SW_HIDE:
1510 showstate = SWPOS_HIDE;
1511 break;
1512 case SW_RESTORE:
1513 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1514 break;
1515 case SW_MINIMIZE:
1516 showstate = SWPOS_MINIMIZE;
1517 break;
1518 case SW_SHOWMAXIMIZED:
1519 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1520 break;
1521 case SW_SHOWMINIMIZED:
1522 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1523 break;
1524 case SW_SHOWMINNOACTIVE:
1525 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1526 break;
1527 case SW_SHOWNA:
1528 showstate = SWPOS_SHOW;
1529 break;
1530 case SW_SHOWNOACTIVATE:
1531 showstate = SWPOS_SHOW;
1532 break;
1533 case SW_SHOWNORMAL:
1534 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1535 break;
1536 }
1537 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1538}
1539//******************************************************************************
1540//******************************************************************************
1541BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1542{
1543 BOOL rc = FALSE;
1544 Win32BaseWindow *window;
1545 HWND hParent = 0;
1546
1547 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1548
1549 /* Validate the flags passed in ... */
1550 if ( fuFlags &
1551 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1552 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1553 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1554 SWP_NOOWNERZORDER) )
1555 {
1556 return FALSE;
1557 }
1558
1559 WINDOWPOS wpos;
1560 SWP swp, swpOld;
1561
1562 //****************************
1563 // Set up with Windows values.
1564 //****************************
1565 wpos.flags = fuFlags;
1566 wpos.cy = cy;
1567 wpos.cx = cx;
1568 wpos.x = x;
1569 wpos.y = y;
1570 wpos.hwndInsertAfter = hwndInsertAfter;
1571 wpos.hwnd = getWindowHandle();
1572
1573 //**********************************************
1574 // Convert from Windows to PM coords and flags.
1575 //**********************************************
1576 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1577 if (isChild())
1578 {
1579 hParent = getParent()->getOS2WindowHandle();
1580 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1581 } else
1582 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1583 }
1584 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1585
1586 /* MapSWP can clear the SWP_MOVE and SWP_SIZE flags if the window is not
1587 * being moved or sized. If these were the only operations to be done
1588 * and they have been cleared, return now.
1589 */
1590 if (swp.fl == 0)
1591 return TRUE;
1592
1593 //*********************************************************************
1594 //On Windows, a WM_GETMINMAXINFO is made to the app from within this API.
1595 //We'll send a WM_QUERYTRACKINFO which is translated into a WM_GETMINMAXINFO
1596 //and passed on to the app. Compare the values returned with the SWP cx and
1597 //cy values. They cannot be bigger than the max nor smaller than the min.
1598 //*********************************************************************
1599
1600 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1601 {
1602 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1603 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1604 }
1605 if (isFrameWindow())
1606 {
1607 POINT maxSize, maxPos, minTrack, maxTrack;
1608
1609 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
1610
1611 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
1612 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
1613 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
1614 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
1615 swp.hwnd = OS2HwndFrame;
1616 } else
1617 swp.hwnd = OS2Hwnd;
1618 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
1619
1620 //*****************************************************************************
1621 // Squibble the window. (WinSetMultWindowPos is faster than WinSetWindowPos.)
1622 //*****************************************************************************
1623 rc = OSLibWinSetMultWindowPos(&swp, 1);
1624
1625 if (rc == FALSE)
1626 {
1627// SET_ERROR_LAST();
1628 }
1629 else
1630 {
1631 /* To implement support for SWP_FRAMECHANGED_W correctly, we would need
1632 ** to send a WM_NCCALCSIZE message. This means DAX would have to support
1633 ** the WM_NCCALCSIZE message. I don't think DAX can support this
1634 ** message because it is tightly bound with the architecture of
1635 ** overlapped windows (the "just one window" architecture). However,
1636 ** we *can* support the SWP_FRAMECHANGED flag by sending the window
1637 ** a WM_UPDATEFRAME, which will provide the behavior of WM_NCCALCSIZE.
1638 */
1639// if (fuFlags & SWP_FRAMECHANGED_W)
1640// WinSendMsg(hWindow, WM_UPDATEFRAME, (MPARAM)-1, 0);
1641 }
1642
1643 return (rc);
1644}
1645//******************************************************************************
1646//Also destroys all the child windows (destroy parent, destroy children)
1647//******************************************************************************
1648BOOL Win32BaseWindow::DestroyWindow()
1649{
1650 return OSLibWinDestroyWindow(OS2HwndFrame);
1651}
1652//******************************************************************************
1653//******************************************************************************
1654HWND Win32BaseWindow::GetParent()
1655{
1656 if(getParent()) {
1657 return getParent()->getWindowHandle();
1658 }
1659 else return 0;
1660}
1661//******************************************************************************
1662//******************************************************************************
1663HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
1664{
1665 HWND oldhwnd;
1666 Win32BaseWindow *newparent;
1667
1668 if(getParent()) {
1669 oldhwnd = getParent()->getWindowHandle();
1670 getParent()->RemoveChild(this);
1671 }
1672 else oldhwnd = 0;
1673
1674 if(hwndNewParent == 0) {//desktop window = parent
1675 setParent(NULL);
1676 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1677 return oldhwnd;
1678 }
1679 newparent = GetWindowFromHandle(hwndNewParent);
1680 if(newparent)
1681 {
1682 setParent(newparent);
1683 getParent()->AddChild(this);
1684 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1685 return oldhwnd;
1686 }
1687 SetLastError(ERROR_INVALID_PARAMETER);
1688 return 0;
1689}
1690//******************************************************************************
1691//******************************************************************************
1692BOOL Win32BaseWindow::IsChild(HWND hwndParent)
1693{
1694 if(getParent()) {
1695 return getParent()->getWindowHandle() == hwndParent;
1696 }
1697 else return 0;
1698}
1699//******************************************************************************
1700//******************************************************************************
1701HWND Win32BaseWindow::GetTopWindow()
1702{
1703 return GetWindow(GW_CHILD);
1704}
1705//******************************************************************************
1706//Don't call WinUpdateWindow as that one also updates the child windows
1707//Also need to send WM_PAINT directly to the window procedure, which doesn't
1708//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1709//******************************************************************************
1710BOOL Win32BaseWindow::UpdateWindow()
1711{
1712 RECT rect;
1713
1714 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1715 {//update region not empty
1716 HDC hdc;
1717
1718 hdc = O32_GetDC(OS2Hwnd);
1719 if (isIcon)
1720 {
1721 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
1722 SendInternalMessageA(WM_PAINTICON, 0, 0);
1723 } else
1724 {
1725 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1726 SendInternalMessageA(WM_PAINT, 0, 0);
1727 }
1728 O32_ReleaseDC(OS2Hwnd, hdc);
1729 }
1730 return TRUE;
1731}
1732//******************************************************************************
1733//******************************************************************************
1734BOOL Win32BaseWindow::IsIconic()
1735{
1736 return OSLibWinIsIconic(OS2Hwnd);
1737}
1738//******************************************************************************
1739//TODO:
1740//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
1741//the current process owns them.
1742//******************************************************************************
1743HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
1744 BOOL fUnicode)
1745{
1746 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
1747 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
1748
1749 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
1750 (hwndChildAfter != 0 && !child) ||
1751 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
1752 {
1753 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
1754 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1755 return 0;
1756 }
1757 if(hwndParent != OSLIB_HWND_DESKTOP)
1758 {//if the current process owns the window, just do a quick search
1759 child = (Win32BaseWindow *)parent->getFirstChild();
1760 if(hwndChildAfter != 0)
1761 {
1762 while(child)
1763 {
1764 if(child->getWindowHandle() == hwndChildAfter)
1765 {
1766 child = (Win32BaseWindow *)child->getNextChild();
1767 break;
1768 }
1769 child = (Win32BaseWindow *)child->getNextChild();
1770 }
1771 }
1772 while(child)
1773 {
1774 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1775 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
1776 {
1777 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
1778 return child->getWindowHandle();
1779 }
1780 child = (Win32BaseWindow *)child->getNextChild();
1781 }
1782 }
1783 else {
1784 Win32BaseWindow *wnd;
1785 HWND henum, hwnd;
1786
1787 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
1788 hwnd = OSLibWinGetNextWindow(henum);
1789
1790 while(hwnd)
1791 {
1792 wnd = GetWindowFromOS2Handle(hwnd);
1793 if(wnd == NULL) {
1794 hwnd = OSLibWinQueryClientWindow(hwnd);
1795 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
1796 }
1797
1798 if(wnd) {
1799 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
1800
1801 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
1802 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
1803 break;
1804 }
1805 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
1806 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
1807 {
1808 OSLibWinEndEnumWindows(henum);
1809 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
1810 return wnd->getWindowHandle();
1811 }
1812 }
1813 hwnd = OSLibWinGetNextWindow(henum);
1814 }
1815 OSLibWinEndEnumWindows(henum);
1816 }
1817 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
1818 return 0;
1819}
1820//******************************************************************************
1821//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
1822//******************************************************************************
1823HWND Win32BaseWindow::GetWindow(UINT uCmd)
1824{
1825 Win32BaseWindow *win32wnd;
1826 ULONG magic;
1827 ULONG getcmd = 0;
1828 HWND hwndRelated;
1829
1830 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1831 switch(uCmd)
1832 {
1833 case GW_CHILD:
1834 getcmd = QWOS_TOP;
1835 break;
1836 case GW_HWNDFIRST:
1837 if(getParent()) {
1838 getcmd = QWOS_TOP; //top of child windows
1839 }
1840 else getcmd = QWOS_TOP; //TODO
1841 break;
1842 case GW_HWNDLAST:
1843 if(getParent()) {
1844 getcmd = QWOS_BOTTOM; //bottom of child windows
1845 }
1846 else getcmd = QWOS_BOTTOM; //TODO
1847 break;
1848 case GW_HWNDNEXT:
1849 getcmd = QWOS_NEXT;
1850 break;
1851 case GW_HWNDPREV:
1852 getcmd = QWOS_PREV;
1853 break;
1854 case GW_OWNER:
1855 if(owner) {
1856 return owner->getWindowHandle();
1857 }
1858 else return 0;
1859 }
1860 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1861 if(hwndRelated)
1862 {
1863 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1864 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1865 if(CheckMagicDword(magic) && win32wnd)
1866 {
1867 return win32wnd->getWindowHandle();
1868 }
1869 }
1870 return 0;
1871}
1872//******************************************************************************
1873//******************************************************************************
1874HWND Win32BaseWindow::SetActiveWindow()
1875{
1876 return OSLibWinSetActiveWindow(OS2Hwnd);
1877}
1878//******************************************************************************
1879//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1880//******************************************************************************
1881BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
1882{
1883 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1884}
1885//******************************************************************************
1886//******************************************************************************
1887BOOL Win32BaseWindow::CloseWindow()
1888{
1889 return OSLibWinMinimizeWindow(OS2Hwnd);
1890}
1891//******************************************************************************
1892//******************************************************************************
1893HWND Win32BaseWindow::GetActiveWindow()
1894{
1895 HWND hwndActive;
1896 Win32BaseWindow *win32wnd;
1897 ULONG magic;
1898
1899 hwndActive = OSLibWinQueryActiveWindow();
1900
1901 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1902 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1903 if(CheckMagicDword(magic) && win32wnd)
1904 {
1905 return win32wnd->getWindowHandle();
1906 }
1907 return hwndActive;
1908}
1909//******************************************************************************
1910//******************************************************************************
1911BOOL Win32BaseWindow::IsWindowEnabled()
1912{
1913 return OSLibWinIsWindowEnabled(OS2Hwnd);
1914}
1915//******************************************************************************
1916//******************************************************************************
1917BOOL Win32BaseWindow::IsWindowVisible()
1918{
1919 return OSLibWinIsWindowVisible(OS2Hwnd);
1920}
1921//******************************************************************************
1922//******************************************************************************
1923BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
1924{
1925 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
1926}
1927//******************************************************************************
1928//******************************************************************************
1929BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
1930{
1931 if(fUnicode) {
1932 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
1933 }
1934 else return (strcmp(windowNameA, wndname) == 0);
1935}
1936//******************************************************************************
1937//******************************************************************************
1938int Win32BaseWindow::GetWindowTextLength()
1939{
1940 return wndNameLength;
1941}
1942//******************************************************************************
1943//******************************************************************************
1944int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
1945{
1946 strncpy(lpsz, windowNameA, cch);
1947 return wndNameLength;
1948}
1949//******************************************************************************
1950//******************************************************************************
1951int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
1952{
1953 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
1954 return wndNameLength;
1955}
1956//******************************************************************************
1957//******************************************************************************
1958BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
1959{
1960 if(lpsz == NULL)
1961 return FALSE;
1962
1963 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
1964 strcpy(windowNameA, lpsz);
1965 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
1966 lstrcpyAtoW(windowNameW, windowNameA);
1967 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1968
1969 if(OS2HwndFrame)
1970 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1971
1972 return TRUE;
1973}
1974//******************************************************************************
1975//******************************************************************************
1976BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
1977{
1978 if(lpsz == NULL)
1979 return FALSE;
1980
1981 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
1982 lstrcpyW(windowNameW, (LPWSTR)lpsz);
1983 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
1984 lstrcpyWtoA(windowNameA, windowNameW);
1985 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
1986
1987 if(OS2HwndFrame)
1988 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
1989
1990 return TRUE;
1991}
1992//******************************************************************************
1993//******************************************************************************
1994LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
1995{
1996 LONG oldval;
1997
1998 switch(index) {
1999 case GWL_EXSTYLE:
2000 oldval = dwExStyle;
2001 setExStyle(value);
2002 return oldval;
2003 case GWL_STYLE:
2004 oldval = dwStyle;
2005 setStyle(value);
2006 return oldval;
2007 case GWL_WNDPROC:
2008 oldval = (LONG)getWindowProc();
2009 setWindowProc((WNDPROC)value);
2010 return oldval;
2011 case GWL_HINSTANCE:
2012 oldval = hInstance;
2013 hInstance = value;
2014 return oldval;
2015 case GWL_HWNDPARENT:
2016 return SetParent((HWND)value);
2017
2018 case GWL_ID:
2019 oldval = getWindowId();
2020 setWindowId(value);
2021 return oldval;
2022 case GWL_USERDATA:
2023 oldval = userData;
2024 userData = value;
2025 return oldval;
2026 default:
2027 if(index >= 0 && index/4 < nrUserWindowLong)
2028 {
2029 oldval = userWindowLong[index/4];
2030 userWindowLong[index/4] = value;
2031 return oldval;
2032 }
2033 SetLastError(ERROR_INVALID_PARAMETER);
2034 return 0;
2035 }
2036}
2037//******************************************************************************
2038//******************************************************************************
2039ULONG Win32BaseWindow::GetWindowLongA(int index)
2040{
2041 switch(index) {
2042 case GWL_EXSTYLE:
2043 return dwExStyle;
2044 case GWL_STYLE:
2045 return dwStyle;
2046 case GWL_WNDPROC:
2047 return (ULONG)getWindowProc();
2048 case GWL_HINSTANCE:
2049 return hInstance;
2050 case GWL_HWNDPARENT:
2051 if(getParent()) {
2052 return getParent()->getWindowHandle();
2053 }
2054 else return 0;
2055 case GWL_ID:
2056 return getWindowId();
2057 case GWL_USERDATA:
2058 return userData;
2059 default:
2060 if(index >= 0 && index/4 < nrUserWindowLong)
2061 {
2062 return userWindowLong[index/4];
2063 }
2064 SetLastError(ERROR_INVALID_PARAMETER);
2065 return 0;
2066 }
2067}
2068//******************************************************************************
2069//******************************************************************************
2070WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2071{
2072 WORD oldval;
2073
2074 if(index >= 0 && index/4 < nrUserWindowLong)
2075 {
2076 oldval = ((WORD *)userWindowLong)[index/2];
2077 ((WORD *)userWindowLong)[index/2] = value;
2078 return oldval;
2079 }
2080 SetLastError(ERROR_INVALID_PARAMETER);
2081 return 0;
2082}
2083//******************************************************************************
2084//******************************************************************************
2085WORD Win32BaseWindow::GetWindowWord(int index)
2086{
2087 if(index >= 0 && index/4 < nrUserWindowLong)
2088 {
2089 return ((WORD *)userWindowLong)[index/2];
2090 }
2091 SetLastError(ERROR_INVALID_PARAMETER);
2092 return 0;
2093}
2094//******************************************************************************
2095//******************************************************************************
2096Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2097{
2098 Win32BaseWindow *window;
2099
2100 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2101 return window;
2102 }
2103 else return NULL;
2104}
2105//******************************************************************************
2106//******************************************************************************
2107Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2108{
2109 Win32BaseWindow *win32wnd;
2110 DWORD magic;
2111
2112 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2113 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2114
2115 if(win32wnd && CheckMagicDword(magic)) {
2116 return win32wnd;
2117 }
2118 return 0;
2119}
2120//******************************************************************************
2121//******************************************************************************
2122GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.