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

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

Set text + dialog bugfixes

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