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

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

Edgar Buerkle's fixes for GetDesktopWindow, icons + WM_TIMER support

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