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

Last change on this file since 1050 was 1050, checked in by cbratschi, 26 years ago

MsgButton() -> double click handling changed

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