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

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

Handle WM_SETTEXT + fInteralMsg flag for message handling

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