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

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

WS_DISABLED fix + removed frame + poschanged bugfixes

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