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

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

WM_ACTIVATE(APP) changes

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