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

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

resource and other fixes

File size: 88.2 KB
Line 
1/* $Id: win32wbase.cpp,v 1.28 1999-10-08 12:10:27 cbratschi Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include <spy.h>
28#include "wndmsg.h"
29#include "hooks.h"
30#include "oslibwin.h"
31#include "oslibutil.h"
32#include "oslibgdi.h"
33#include "oslibres.h"
34#include "oslibmenu.h"
35#include "oslibdos.h"
36#include "syscolor.h"
37#include "win32wndhandle.h"
38#include "heapshared.h"
39#include "dc.h"
40
41#define HAS_DLGFRAME(style,exStyle) \
42 (((exStyle) & WS_EX_DLGMODALFRAME) || \
43 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
44
45#define HAS_THICKFRAME(style) \
46 (((style) & WS_THICKFRAME) && \
47 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
48
49#define HAS_3DFRAME(exStyle) \
50 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
51
52#define HAS_BORDER(style, exStyle) \
53 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
54
55#define IS_OVERLAPPED(style) \
56 !(style & (WS_CHILD | WS_POPUP))
57
58//******************************************************************************
59//******************************************************************************
60Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
61{
62 Init();
63}
64//******************************************************************************
65//******************************************************************************
66Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
67 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
68{
69 Init();
70 this->isUnicode = isUnicode;
71 CreateWindowExA(lpCreateStructA, classAtom);
72}
73//******************************************************************************
74//******************************************************************************
75void Win32BaseWindow::Init()
76{
77 isUnicode = FALSE;
78 fCreated = FALSE;
79 fFirstShow = TRUE;
80 fIsDialog = FALSE;
81 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(SendInternalMessage(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( (SendInternalMessage(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( !SendInternalMessageA(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 SendInternalMessageA(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 = SendInternalMessageA(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 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
824}
825//******************************************************************************
826//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
827//******************************************************************************
828ULONG Win32BaseWindow::MsgShow(BOOL fShow)
829{
830 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
831}
832//******************************************************************************
833//******************************************************************************
834ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
835{
836 dprintf(("MsgPosChanging"));
837#if 1
838 if(fCreated == FALSE) {
839 return 1;
840 }
841#endif
842 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
843}
844//******************************************************************************
845//******************************************************************************
846ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
847{
848 dprintf(("MsgPosChanged"));
849#if 1
850 if(fCreated == FALSE) {
851 return 1;
852 }
853#endif
854 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
855}
856//******************************************************************************
857//******************************************************************************
858ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
859{
860 dprintf(("MsgMove to (%d,%d)", x, y));
861 if(fCreated == FALSE) {
862 return 1;
863 }
864
865 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
866}
867//******************************************************************************
868//******************************************************************************
869ULONG Win32BaseWindow::MsgTimer(ULONG TimerID)
870{
871 // TODO: call TIMERPROC if not NULL
872 return SendInternalMessageA(WM_TIMER, TimerID, 0);
873}
874//******************************************************************************
875//******************************************************************************
876ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
877{
878 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
879 //window scrollbars send these messages
880 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
881}
882//******************************************************************************
883//******************************************************************************
884ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
885{
886 switch(cmd) {
887 case CMD_MENU:
888 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
889 case CMD_CONTROL:
890 return 0; //todo
891 case CMD_ACCELERATOR:
892 dprintf(("accelerator command"));
893 return 0; //todo
894 }
895 return 0;
896}
897//******************************************************************************
898//******************************************************************************
899ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
900{
901 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
902 return 1; //TODO: May need to change this
903}
904//******************************************************************************
905//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
906//******************************************************************************
907ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
908{
909 WORD fwSizeType = 0;
910
911 if(fCreated == FALSE) {//Solitaire crashes if it receives a WM_SIZE during CreateWindowEx (normal or our fault?)
912 return 1;
913 }
914
915 if(fMinimize) {
916 fwSizeType = SIZE_MINIMIZED;
917 }
918 else
919 if(fMaximize) {
920 fwSizeType = SIZE_MAXIMIZED;
921 }
922 else fwSizeType = SIZE_RESTORED;
923
924 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
925}
926//******************************************************************************
927//******************************************************************************
928ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
929{
930 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
931
932 //According to SDK docs, if app returns FALSE & window is being deactivated,
933 //default processing is cancelled
934 //TODO: According to Wine we should proceed anyway if window is sysmodal
935 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
936 {
937 return 0;
938 }
939 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
940
941 curprocid = GetCurrentProcessId();
942 if(hwnd) {
943 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
944 }
945
946 if(curprocid != procidhwnd && fActivate) {
947 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
948 }
949 return rc;
950}
951//******************************************************************************
952//******************************************************************************
953ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
954{
955 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
956}
957//******************************************************************************
958//TODO: Is this correct and complete?
959//Add print screen, break & numlock
960//******************************************************************************
961void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
962{
963 switch(virtualkey) {
964 case VK_DOWN:
965 case VK_UP:
966 case VK_PRIOR:
967 case VK_NEXT:
968 case VK_END:
969 case VK_DIVIDE:
970 case VK_DELETE:
971 case VK_EXECUTE: //Numeric enter key?
972 case VK_HOME:
973 case VK_INSERT:
974 case VK_RCONTROL:
975 case VK_RMENU: //is this the right alt???
976 *lParam = *lParam | (1<<24);
977 }
978}
979//******************************************************************************
980//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
981//******************************************************************************
982ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
983{
984 ULONG lParam = 0;
985
986 lParam = repeatcnt;
987 lParam |= (scancode << 16);
988 setExtendedKey(vkey, &lParam);
989
990 if(keyflags & KEY_ALTDOWN)
991 lParam |= (1<<29);
992 if(keyflags & KEY_PREVDOWN)
993 lParam |= (1<<30);
994 if(keyflags & KEY_UP)
995 lParam |= (1<<31);
996 if(keyflags & KEY_DEADKEY) {
997 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
998 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
999 }
1000 else {
1001 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
1002 return SendInternalMessageA(WM_CHAR, cmd, lParam);
1003 }
1004}
1005//******************************************************************************
1006//******************************************************************************
1007ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
1008{
1009 ULONG lParam=0;
1010
1011 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1012 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1013 // bit 24, 1=extended key
1014 // bit 25-28, reserved
1015 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
1016 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
1017 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
1018
1019 dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
1020
1021 setExtendedKey(virtualKey, &lParam);
1022 return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
1023}
1024//******************************************************************************
1025//******************************************************************************
1026ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
1027{
1028 ULONG lParam=0;
1029
1030 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1031 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1032 // bit 24, 1=extended key
1033 // bit 25-28, reserved
1034 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
1035 if (keyWasPressed)
1036 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1037 // bit 31, transition state, always 0 for WM_KEYDOWN
1038
1039 setExtendedKey(virtualKey, &lParam);
1040
1041 dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1042
1043 return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
1044}
1045//******************************************************************************
1046//******************************************************************************
1047ULONG Win32BaseWindow::MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
1048{
1049 ULONG lParam=0;
1050
1051 lParam = repeatCount & 0x0FFFF; // bit 0-15,repeatcount
1052 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1053 // bit 24, 1=extended key
1054 // bit 25-28, reserved
1055 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
1056 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
1057 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
1058
1059 setExtendedKey(virtualKey, &lParam);
1060 dprintf(("WM_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
1061
1062 return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
1063}
1064//******************************************************************************
1065//******************************************************************************
1066ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
1067{
1068 ULONG lParam=0;
1069
1070 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
1071 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
1072 // bit 24, 1=extended key
1073 // bit 25-28, reserved
1074 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
1075 if (keyWasPressed)
1076 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1077 // bit 31, transition state, always 0 for WM_KEYDOWN
1078
1079 setExtendedKey(virtualKey, &lParam);
1080 dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1081
1082 return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
1083}
1084//******************************************************************************
1085//******************************************************************************
1086ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1087{
1088 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1089}
1090//******************************************************************************
1091//******************************************************************************
1092ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1093{
1094 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1095}
1096//******************************************************************************
1097//******************************************************************************
1098//******************************************************************************
1099ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
1100{
1101 ULONG win32msg;
1102 ULONG win32ncmsg;
1103
1104 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1105 switch(msg) {
1106 case BUTTON_LEFTDOWN:
1107 win32msg = WM_LBUTTONDOWN;
1108 win32ncmsg = WM_NCLBUTTONDOWN;
1109 break;
1110 case BUTTON_LEFTUP:
1111 win32msg = WM_LBUTTONUP;
1112 win32ncmsg = WM_NCLBUTTONUP;
1113 break;
1114 case BUTTON_LEFTDBLCLICK:
1115 if (windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1116 {
1117 win32msg = WM_LBUTTONDBLCLK;
1118 win32ncmsg = WM_NCLBUTTONDBLCLK;
1119 } else
1120 {
1121 MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
1122 return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
1123 }
1124 break;
1125 case BUTTON_RIGHTUP:
1126 win32msg = WM_RBUTTONUP;
1127 win32ncmsg = WM_NCRBUTTONUP;
1128 break;
1129 case BUTTON_RIGHTDOWN:
1130 win32msg = WM_RBUTTONDOWN;
1131 win32ncmsg = WM_NCRBUTTONDOWN;
1132 break;
1133 case BUTTON_RIGHTDBLCLICK:
1134 if (windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1135 {
1136 win32msg = WM_RBUTTONDBLCLK;
1137 win32ncmsg = WM_NCRBUTTONDBLCLK;
1138 } else
1139 {
1140 MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
1141 return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
1142 }
1143 break;
1144 case BUTTON_MIDDLEUP:
1145 win32msg = WM_MBUTTONUP;
1146 win32ncmsg = WM_NCMBUTTONUP;
1147 break;
1148 case BUTTON_MIDDLEDOWN:
1149 win32msg = WM_MBUTTONDOWN;
1150 win32ncmsg = WM_NCMBUTTONDOWN;
1151 break;
1152 case BUTTON_MIDDLEDBLCLICK:
1153 if (windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1154 {
1155 win32msg = WM_MBUTTONDBLCLK;
1156 win32ncmsg = WM_NCMBUTTONDBLCLK;
1157 } else
1158 {
1159 MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
1160 return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
1161 }
1162 break;
1163 default:
1164 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1165 return 1;
1166 }
1167
1168 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1169
1170 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1171 if(lastHitTestVal != HTCLIENT) {
1172 return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1173 }
1174 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1175}
1176//******************************************************************************
1177//******************************************************************************
1178ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1179{
1180 ULONG winstate = 0;
1181 ULONG setcursormsg = WM_MOUSEMOVE;
1182
1183 if(keystate & WMMOVE_LBUTTON)
1184 winstate |= MK_LBUTTON;
1185 if(keystate & WMMOVE_RBUTTON)
1186 winstate |= MK_RBUTTON;
1187 if(keystate & WMMOVE_MBUTTON)
1188 winstate |= MK_MBUTTON;
1189 if(keystate & WMMOVE_SHIFT)
1190 winstate |= MK_SHIFT;
1191 if(keystate & WMMOVE_CTRL)
1192 winstate |= MK_CONTROL;
1193
1194 if(lastHitTestVal != HTCLIENT) {
1195 setcursormsg = WM_NCMOUSEMOVE;
1196 }
1197 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1198 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1199
1200 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1201 if(lastHitTestVal != HTCLIENT) {
1202 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1203 }
1204 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
1205}
1206//******************************************************************************
1207//******************************************************************************
1208ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1209{
1210 if (select && isIcon)
1211 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1212 else
1213 return SendInternalMessageA(WM_PAINT, 0, 0);
1214}
1215//******************************************************************************
1216//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1217// (or are we simply erasing too much here)
1218//******************************************************************************
1219ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1220{
1221 ULONG rc;
1222 HDC hdcErase = hdc;
1223
1224 if (hdcErase == 0)
1225 hdcErase = O32_GetDC(OS2Hwnd);
1226
1227 if(isIcon)
1228 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1229 else
1230 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1231 if (hdc == 0)
1232 O32_ReleaseDC(OS2Hwnd, hdcErase);
1233 return (rc);
1234}
1235//******************************************************************************
1236//******************************************************************************
1237ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1238{
1239 if(isUnicode) {
1240 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
1241 }
1242 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1243}
1244//******************************************************************************
1245//TODO: in- or excluding terminating 0?
1246//******************************************************************************
1247ULONG Win32BaseWindow::MsgGetTextLength()
1248{
1249 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1250}
1251//******************************************************************************
1252//******************************************************************************
1253char *Win32BaseWindow::MsgGetText()
1254{
1255 if(isUnicode) {
1256 SendInternalMessageW(WM_GETTEXT, wndNameLength, (LPARAM)windowNameW);
1257 }
1258 else {
1259 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1260 }
1261 return windowNameA;
1262}
1263//******************************************************************************
1264//******************************************************************************
1265BOOL Win32BaseWindow::isMDIClient()
1266{
1267 return FALSE;
1268}
1269//******************************************************************************
1270//TODO: Not complete (flags)
1271//******************************************************************************
1272SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1273{
1274 switch(nBar) {
1275 case SB_HORZ:
1276 if(horzScrollInfo) {
1277 horzScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndHorzScroll);
1278 return horzScrollInfo;
1279 }
1280 break;
1281 case SB_VERT:
1282 if(vertScrollInfo) {
1283 vertScrollInfo->CurVal = OSLibWinGetScrollPos(OS2HwndFrame, hwndVertScroll);
1284 return vertScrollInfo;
1285 }
1286 break;
1287 }
1288 return NULL;
1289}
1290//******************************************************************************
1291//TODO: Not complete
1292//******************************************************************************
1293LONG Win32BaseWindow::setScrollInfo(int nBar, SCROLLINFO *info, int fRedraw)
1294{
1295 SCROLLBAR_INFO *infoPtr;
1296 HWND hwndScroll;
1297 ULONG scrollType;
1298 int new_flags;
1299
1300 switch(nBar) {
1301 case SB_HORZ:
1302 if(!horzScrollInfo) {
1303 return 0;
1304 }
1305 infoPtr = horzScrollInfo;
1306 hwndScroll = hwndHorzScroll;
1307 scrollType = OSLIB_HSCROLL;
1308 break;
1309 case SB_VERT:
1310 if(!vertScrollInfo) {
1311 return 0;
1312 }
1313 infoPtr = vertScrollInfo;
1314 hwndScroll = hwndVertScroll;
1315 scrollType = OSLIB_VSCROLL;
1316 break;
1317 default:
1318 return 0;
1319 }
1320
1321 if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0;
1322 if ((info->cbSize != sizeof(*info)) &&
1323 (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0;
1324
1325 /* Set the page size */
1326 if (info->fMask & SIF_PAGE)
1327 {
1328 if( infoPtr->Page != info->nPage )
1329 {
1330 infoPtr->Page = info->nPage;
1331 OSLibWinSetScrollPageSize(OS2HwndFrame, hwndScroll, info->nPage, infoPtr->MaxVal, fRedraw);
1332 }
1333 }
1334
1335 /* Set the scroll pos */
1336 if (info->fMask & SIF_POS)
1337 {
1338 if( infoPtr->CurVal != info->nPos )
1339 {
1340 infoPtr->CurVal = info->nPos;
1341 OSLibWinSetScrollPos(OS2HwndFrame, hwndScroll, info->nPos, fRedraw);
1342 }
1343 }
1344
1345 /* Set the scroll range */
1346 if (info->fMask & SIF_RANGE)
1347 {
1348 /* Invalid range -> range is set to (0,0) */
1349 if ((info->nMin > info->nMax) ||
1350 ((UINT)(info->nMax - info->nMin) >= 0x80000000))
1351 {
1352 infoPtr->MinVal = 0;
1353 infoPtr->MaxVal = 0;
1354 }
1355 else
1356 {
1357 if( infoPtr->MinVal != info->nMin ||
1358 infoPtr->MaxVal != info->nMax )
1359 {
1360 infoPtr->MinVal = info->nMin;
1361 infoPtr->MaxVal = info->nMax;
1362
1363 OSLibWinSetScrollRange(OS2HwndFrame, hwndScroll, info->nMin, info->nMax, fRedraw);
1364 }
1365 }
1366 }
1367
1368 /* Make sure the page size is valid */
1369 if (infoPtr->Page < 0) infoPtr->Page = 0;
1370 else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 )
1371 infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1;
1372
1373 /* Make sure the pos is inside the range */
1374 if (infoPtr->CurVal < infoPtr->MinVal)
1375 infoPtr->CurVal = infoPtr->MinVal;
1376 else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
1377 infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 );
1378
1379 /* Check if the scrollbar should be hidden or disabled */
1380 if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL))
1381 {
1382 new_flags = infoPtr->flags;
1383 if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ))
1384 {
1385 /* Hide or disable scroll-bar */
1386 if (info->fMask & SIF_DISABLENOSCROLL)
1387 {
1388 new_flags = ESB_DISABLE_BOTH;
1389 //TODO:
1390 }
1391 else if (nBar != SB_CTL)
1392 {
1393 //TODO
1394 goto done;
1395 }
1396 }
1397 else /* Show and enable scroll-bar */
1398 {
1399 //TODO
1400 new_flags = 0;
1401 }
1402
1403 if (infoPtr->flags != new_flags) /* check arrow flags */
1404 {
1405 infoPtr->flags = new_flags;
1406 }
1407 }
1408
1409done:
1410 /* Return current position */
1411
1412 return infoPtr->CurVal;
1413}
1414//******************************************************************************
1415//******************************************************************************
1416LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1417{
1418 switch(Msg)
1419 {
1420 case WM_CLOSE:
1421 DestroyWindow();
1422 return 0;
1423
1424 case WM_GETTEXTLENGTH:
1425 return wndNameLength;
1426
1427 case WM_GETTEXT: //TODO: SS_ICON controls
1428 strncpy((LPSTR)lParam, windowNameA, wParam);
1429 return min(wndNameLength, wParam);
1430
1431 case WM_SETTEXT:
1432 if(!fInternalMsg) {
1433 return SetWindowTextA((LPSTR)lParam);
1434 }
1435 else return 0;
1436
1437 case WM_SETREDRAW:
1438 if(wParam)
1439 SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) | WS_VISIBLE);
1440 else SetWindowLongA (GWL_STYLE, GetWindowLongA (GWL_STYLE) & ~WS_VISIBLE);
1441
1442 return 0; //TODO
1443
1444 case WM_NCCREATE:
1445 return(TRUE);
1446
1447 //SvL: Set background color to default button color (not window (white))
1448 case WM_CTLCOLORBTN:
1449 SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
1450 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1451 return GetSysColorBrush(COLOR_BTNFACE);
1452
1453 //SvL: Set background color to default dialog color if window is dialog
1454 case WM_CTLCOLORDLG:
1455 case WM_CTLCOLORSTATIC:
1456 if(IsDialog()) {
1457 SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
1458 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1459 return GetSysColorBrush(COLOR_BTNFACE);
1460 }
1461 //no break
1462
1463 case WM_CTLCOLORMSGBOX:
1464 case WM_CTLCOLOREDIT:
1465 case WM_CTLCOLORLISTBOX:
1466 case WM_CTLCOLORSCROLLBAR:
1467 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1468 SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT));
1469 return GetSysColorBrush(COLOR_BTNFACE);
1470
1471 case WM_PARENTNOTIFY:
1472 return 0;
1473
1474 case WM_MOUSEACTIVATE:
1475 {
1476 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1477 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1478 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1479 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1480 {
1481 if(getParent()) {
1482 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1483 if(rc) return rc;
1484 }
1485 }
1486 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1487 }
1488 case WM_SETCURSOR:
1489 {
1490 DWORD dwStyle = GetWindowLongA(GWL_STYLE);
1491 DWORD dwExStyle = GetWindowLongA(GWL_EXSTYLE);
1492 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1493 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
1494 {
1495 if(getParent()) {
1496 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1497 if(rc) return rc;
1498 }
1499 }
1500 return 1;
1501 }
1502 case WM_MOUSEMOVE:
1503 return 0;
1504
1505 case WM_WINDOWPOSCHANGED:
1506 {
1507
1508/* undocumented SWP flags - from SDK 3.1 */
1509#define SWP_NOCLIENTSIZE 0x0800
1510#define SWP_NOCLIENTMOVE 0x1000
1511
1512 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1513 WPARAM wp = SIZE_RESTORED;
1514
1515 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1516 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1517
1518 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1519 {
1520 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1521 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1522
1523 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1524 rectClient.bottom - rectClient.top));
1525 }
1526 return 0;
1527 }
1528 case WM_ERASEBKGND:
1529 case WM_ICONERASEBKGND:
1530 {
1531 RECT rect;
1532 int rc;
1533
1534 if (!windowClass->getBackgroundBrush()) return 0;
1535
1536 rc = GetClipBox( (HDC)wParam, &rect );
1537 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1538 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1539
1540 return 1;
1541 }
1542 case WM_GETDLGCODE:
1543 return 0;
1544
1545 case WM_NCLBUTTONDOWN:
1546 case WM_NCLBUTTONUP:
1547 case WM_NCLBUTTONDBLCLK:
1548 case WM_NCRBUTTONUP:
1549 case WM_NCRBUTTONDOWN:
1550 case WM_NCRBUTTONDBLCLK:
1551 case WM_NCMBUTTONDOWN:
1552 case WM_NCMBUTTONUP:
1553 case WM_NCMBUTTONDBLCLK:
1554 return 0; //TODO: Send WM_SYSCOMMAND if required
1555
1556 case WM_NCHITTEST: //TODO: Calculate position of
1557 return HTCLIENT;
1558
1559#if 0
1560 case WM_SYSKEYDOWN:
1561 if(HIWORD(lParam) & KEYDATA_ALT)
1562 {
1563 if(wParam == VK_F4) /* try to close the window */
1564 {
1565 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
1566 wndPtr = WIN_FindWndPtr( hWnd );
1567 if( wndPtr && !(getClass()->getStyle() & CS_NOCLOSE) )
1568 PostMessage(WM_SYSCOMMAND, SC_CLOSE, 0);
1569 }
1570 }
1571 return 0;
1572#endif
1573
1574 default:
1575 return 1;
1576 }
1577}
1578//******************************************************************************
1579//******************************************************************************
1580LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1581{
1582 switch(Msg)
1583 {
1584 case WM_GETTEXTLENGTH:
1585 return wndNameLength;
1586
1587 case WM_GETTEXT: //TODO: SS_ICON controls
1588 lstrcpynW((LPWSTR)lParam, windowNameW, wParam);
1589 return min(wndNameLength, wParam);
1590
1591 case WM_SETTEXT:
1592 if(!fInternalMsg) {
1593 return SetWindowTextW((LPWSTR)lParam);
1594 }
1595 else return 0;
1596
1597 default:
1598 return DefWindowProcA(Msg, wParam, lParam);
1599 }
1600}
1601//******************************************************************************
1602//******************************************************************************
1603LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1604{
1605 LRESULT rc;
1606 BOOL fInternalMsgBackup = fInternalMsg;
1607
1608 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1609 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1610 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1611 }
1612
1613 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1614 return(0);
1615 }
1616 fInternalMsg = FALSE;
1617 switch(Msg)
1618 {
1619 case WM_CREATE:
1620 {
1621 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1622 dprintf(("WM_CREATE returned -1\n"));
1623 rc = -1; //don't create window
1624 break;
1625 }
1626 NotifyParent(Msg, wParam, lParam);
1627
1628 rc = 0;
1629 break;
1630 }
1631 case WM_SETTEXT:
1632 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1633 break;
1634
1635 case WM_LBUTTONDOWN:
1636 case WM_MBUTTONDOWN:
1637 case WM_RBUTTONDOWN:
1638 NotifyParent(Msg, wParam, lParam);
1639 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1640 break;
1641
1642 case WM_DESTROY:
1643 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1644 break;
1645
1646 default:
1647 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1648 break;
1649 }
1650 fInternalMsg = fInternalMsgBackup;
1651 return rc;
1652}
1653//******************************************************************************
1654//******************************************************************************
1655LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1656{
1657 LRESULT rc;
1658 BOOL fInternalMsgBackup = fInternalMsg;
1659
1660 if(Msg != WM_GETDLGCODE && Msg != WM_ENTERIDLE) {//sent *very* often
1661 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1662 dprintf(("SendMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1663 }
1664
1665 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1666 return(0);
1667 }
1668 fInternalMsg = FALSE;
1669 switch(Msg)
1670 {
1671 case WM_CREATE:
1672 {
1673 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1674 dprintf(("WM_CREATE returned -1\n"));
1675 rc = -1; //don't create window
1676 break;
1677 }
1678 NotifyParent(Msg, wParam, lParam);
1679
1680 rc = 0;
1681 break;
1682 }
1683 case WM_SETTEXT:
1684 rc = win32wndproc(getWindowHandle(), WM_SETTEXT, wParam, lParam);
1685 break;
1686
1687 case WM_LBUTTONDOWN:
1688 case WM_MBUTTONDOWN:
1689 case WM_RBUTTONDOWN:
1690 NotifyParent(Msg, wParam, lParam);
1691 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1692 break;
1693
1694 case WM_DESTROY:
1695 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1696 NotifyParent(Msg, wParam, lParam);
1697 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1698 break;
1699
1700 default:
1701 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1702 break;
1703 }
1704 fInternalMsg = fInternalMsgBackup;
1705 return rc;
1706}
1707//******************************************************************************
1708//Called as a result of an OS/2 message
1709//******************************************************************************
1710LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1711{
1712 LRESULT rc;
1713 BOOL fInternalMsgBackup = fInternalMsg;
1714
1715 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1716 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1717
1718 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1719 return(0);
1720 }
1721 fInternalMsg = TRUE;
1722 switch(Msg)
1723 {
1724 case WM_CREATE:
1725 {
1726 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1727 dprintf(("WM_CREATE returned -1\n"));
1728 rc = -1; //don't create window
1729 break;
1730 }
1731 NotifyParent(Msg, wParam, lParam);
1732 rc = 0;
1733 break;
1734 }
1735 case WM_LBUTTONDOWN:
1736 case WM_MBUTTONDOWN:
1737 case WM_RBUTTONDOWN:
1738 NotifyParent(Msg, wParam, lParam);
1739 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1740 break;
1741
1742 case WM_DESTROY:
1743 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1744 NotifyParent(Msg, wParam, lParam);
1745 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1746 break;
1747 default:
1748 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1749 break;
1750 }
1751 fInternalMsg = fInternalMsgBackup;
1752 return rc;
1753}
1754//******************************************************************************
1755//Called as a result of an OS/2 message
1756//todo, unicode msgs (WM_SETTEXT etc)
1757//******************************************************************************
1758LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1759{
1760 LRESULT rc;
1761 BOOL fInternalMsgBackup = fInternalMsg;
1762
1763 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
1764 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1765
1766 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1767 return(0);
1768 }
1769 fInternalMsg = TRUE;
1770 switch(Msg)
1771 {
1772 case WM_CREATE:
1773 {
1774 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1775 dprintf(("WM_CREATE returned -1\n"));
1776 rc = -1; //don't create window
1777 break;
1778 }
1779 NotifyParent(Msg, wParam, lParam);
1780 rc = 0;
1781 break;
1782 }
1783 case WM_LBUTTONDOWN:
1784 case WM_MBUTTONDOWN:
1785 case WM_RBUTTONDOWN:
1786 NotifyParent(Msg, wParam, lParam);
1787 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1788 break;
1789
1790 case WM_DESTROY:
1791 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1792 NotifyParent(Msg, wParam, lParam);
1793 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1794 break;
1795 default:
1796 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1797 break;
1798 }
1799 fInternalMsg = fInternalMsgBackup;
1800 return rc;
1801}
1802//******************************************************************************
1803//******************************************************************************
1804BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1805{
1806 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1807}
1808//******************************************************************************
1809//******************************************************************************
1810BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1811{
1812 return OSLibPostMessage(OS2Hwnd, WIN32APP_USERMSGBASE+msg, wParam, lParam);
1813}
1814//******************************************************************************
1815//TODO: do we need to inform the parent of the parent (etc) of the child window?
1816//******************************************************************************
1817void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1818{
1819 Win32BaseWindow *window = this;
1820 Win32BaseWindow *parentwindow;
1821
1822 while(window)
1823 {
1824 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1825 {
1826 /* Notify the parent window only */
1827 parentwindow = window->getParent();
1828 if(parentwindow) {
1829 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1830 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1831 }
1832 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1833 }
1834 }
1835 else break;
1836
1837 window = parentwindow;
1838 }
1839}
1840//******************************************************************************
1841//******************************************************************************
1842Win32BaseWindow *Win32BaseWindow::getTopParent()
1843{
1844 Win32BaseWindow *tmpWnd = this;
1845
1846 while( tmpWnd && (tmpWnd->getStyle() & WS_CHILD))
1847 {
1848 tmpWnd = tmpWnd->getParent();
1849 }
1850 return tmpWnd;
1851}
1852//******************************************************************************
1853//******************************************************************************
1854BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
1855{
1856
1857 dprintf(("SetMenu %x", hMenu));
1858 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
1859 if(OS2HwndMenu == 0) {
1860 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
1861 return FALSE;
1862 }
1863 return TRUE;
1864}
1865//******************************************************************************
1866//******************************************************************************
1867BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
1868{
1869 Win32Resource *winres = (Win32Resource *)hAccel;
1870 HANDLE accelhandle;
1871
1872 if(HIWORD(hAccel) == 0) {
1873 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1874 SetLastError(ERROR_INVALID_PARAMETER);
1875 return FALSE;
1876 }
1877 acceltableResource = winres;
1878 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1879 winres->setOS2Handle(accelhandle);
1880 return(accelhandle != 0);
1881}
1882//******************************************************************************
1883//******************************************************************************
1884BOOL Win32BaseWindow::SetIcon(HICON hIcon)
1885{
1886 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
1887 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
1888 SendInternalMessageA(WM_SETICON, hIcon, 0);
1889 return TRUE;
1890 }
1891 return FALSE;
1892}
1893//******************************************************************************
1894//******************************************************************************
1895BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
1896{
1897 ULONG showstate = 0;
1898
1899 dprintf(("ShowWindow %x", nCmdShow));
1900 if(fFirstShow) {
1901 if(isFrameWindow() && IS_OVERLAPPED(getStyle())) {
1902 SendMessageA(WM_SIZE, SIZE_RESTORED,
1903 MAKELONG(rectClient.right-rectClient.left,
1904 rectClient.bottom-rectClient.top));
1905 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
1906
1907 }
1908 fFirstShow = FALSE;
1909 }
1910 switch(nCmdShow)
1911 {
1912 case SW_SHOW:
1913 case SW_SHOWDEFAULT: //todo
1914 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1915 break;
1916 case SW_HIDE:
1917 showstate = SWPOS_HIDE;
1918 break;
1919 case SW_RESTORE:
1920 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1921 break;
1922 case SW_MINIMIZE:
1923 showstate = SWPOS_MINIMIZE;
1924 break;
1925 case SW_SHOWMAXIMIZED:
1926 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1927 break;
1928 case SW_SHOWMINIMIZED:
1929 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1930 break;
1931 case SW_SHOWMINNOACTIVE:
1932 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1933 break;
1934 case SW_SHOWNA:
1935 showstate = SWPOS_SHOW;
1936 break;
1937 case SW_SHOWNOACTIVATE:
1938 showstate = SWPOS_SHOW;
1939 break;
1940 case SW_SHOWNORMAL:
1941 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1942 break;
1943 }
1944 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
1945 return rc;
1946}
1947//******************************************************************************
1948//******************************************************************************
1949BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1950{
1951 BOOL rc = FALSE;
1952 Win32BaseWindow *window;
1953 HWND hParent = 0;
1954
1955 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
1956
1957 if (fuFlags &
1958 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
1959 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
1960 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
1961 SWP_NOOWNERZORDER))
1962 {
1963 return FALSE;
1964 }
1965
1966 WINDOWPOS wpos;
1967 SWP swp, swpOld;
1968
1969 wpos.flags = fuFlags;
1970 wpos.cy = cy;
1971 wpos.cx = cx;
1972 wpos.x = x;
1973 wpos.y = y;
1974 wpos.hwndInsertAfter = hwndInsertAfter;
1975 wpos.hwnd = getWindowHandle();
1976
1977 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE)) {
1978 if (isChild())
1979 {
1980 hParent = getParent()->getOS2WindowHandle();
1981 OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
1982 } else
1983 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
1984 }
1985
1986 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
1987 if (swp.fl == 0)
1988 return TRUE;
1989
1990 if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
1991 {
1992 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
1993 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
1994 }
1995 if (isFrameWindow())
1996 {
1997 POINT maxSize, maxPos, minTrack, maxTrack;
1998
1999 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2000
2001 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2002 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2003 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2004 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2005
2006 RECTLOS2 rectFrame;
2007
2008 //Calculate correct frame rectangle from client rectangle
2009 //NOTE: xLeft & yBottom can become too big
2010 //Some programs use GetSystemMetrics 32/33 to determine offsets
2011 rectFrame.xLeft = swp.x;
2012 rectFrame.yBottom = swp.y;
2013 rectFrame.xRight = swp.x + swp.cx;
2014 rectFrame.yTop = swp.y + swp.cy;
2015
2016 OSLibWinCalcFrameRect(OS2HwndFrame, &rectFrame, FALSE);
2017 swp.x = rectFrame.xLeft;
2018 swp.y = rectFrame.yBottom;
2019 swp.cx = rectFrame.xRight - rectFrame.xLeft;
2020 swp.cy = rectFrame.yTop - rectFrame.yBottom;
2021 if(swp.x < 0) {
2022 swp.cx += -swp.x;
2023 swp.x = 0;
2024 }
2025 if(swp.y + swp.cy > ScreenHeight) {
2026 swp.y = ScreenHeight - swp.cy;
2027 }
2028 swp.hwnd = OS2HwndFrame;
2029 } else
2030 swp.hwnd = OS2Hwnd;
2031 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2032
2033 rc = OSLibWinSetMultWindowPos(&swp, 1);
2034
2035 if (rc == FALSE)
2036 {
2037// SET_ERROR_LAST();
2038 }
2039 else
2040 {
2041 if (fuFlags & SWP_FRAMECHANGED_W)
2042 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2043 }
2044
2045 return (rc);
2046}
2047//******************************************************************************
2048//Also destroys all the child windows (destroy parent, destroy children)
2049//******************************************************************************
2050BOOL Win32BaseWindow::DestroyWindow()
2051{
2052 return OSLibWinDestroyWindow(OS2HwndFrame);
2053}
2054//******************************************************************************
2055//******************************************************************************
2056HWND Win32BaseWindow::GetParent()
2057{
2058 if(getParent()) {
2059 return getParent()->getWindowHandle();
2060 }
2061 else return 0;
2062}
2063//******************************************************************************
2064//******************************************************************************
2065HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2066{
2067 HWND oldhwnd;
2068 Win32BaseWindow *newparent;
2069
2070 if(getParent()) {
2071 oldhwnd = getParent()->getWindowHandle();
2072 getParent()->RemoveChild(this);
2073 }
2074 else oldhwnd = 0;
2075
2076 if(hwndNewParent == 0) {//desktop window = parent
2077 setParent(NULL);
2078 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
2079 return oldhwnd;
2080 }
2081 newparent = GetWindowFromHandle(hwndNewParent);
2082 if(newparent)
2083 {
2084 setParent(newparent);
2085 getParent()->AddChild(this);
2086 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
2087 return oldhwnd;
2088 }
2089 SetLastError(ERROR_INVALID_PARAMETER);
2090 return 0;
2091}
2092//******************************************************************************
2093//******************************************************************************
2094BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2095{
2096 if(getParent()) {
2097 return getParent()->getWindowHandle() == hwndParent;
2098 }
2099 else return 0;
2100}
2101//******************************************************************************
2102//******************************************************************************
2103HWND Win32BaseWindow::GetTopWindow()
2104{
2105 return GetWindow(GW_CHILD);
2106}
2107//******************************************************************************
2108//Don't call WinUpdateWindow as that one also updates the child windows
2109//Also need to send WM_PAINT directly to the window procedure, which doesn't
2110//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2111//******************************************************************************
2112BOOL Win32BaseWindow::UpdateWindow()
2113{
2114 RECT rect;
2115
2116 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2117 {//update region not empty
2118 HDC hdc;
2119
2120 hdc = O32_GetDC(OS2Hwnd);
2121 if (isIcon)
2122 {
2123 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2124 SendInternalMessageA(WM_PAINTICON, 0, 0);
2125 } else
2126 {
2127 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2128 SendInternalMessageA(WM_PAINT, 0, 0);
2129 }
2130 O32_ReleaseDC(OS2Hwnd, hdc);
2131 }
2132 return TRUE;
2133}
2134//******************************************************************************
2135//******************************************************************************
2136BOOL Win32BaseWindow::IsIconic()
2137{
2138 return OSLibWinIsIconic(OS2Hwnd);
2139}
2140//******************************************************************************
2141//TODO:
2142//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2143//the current process owns them.
2144//******************************************************************************
2145HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2146 BOOL fUnicode)
2147{
2148 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2149 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2150
2151 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2152 (hwndChildAfter != 0 && !child) ||
2153 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2154 {
2155 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2156 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2157 return 0;
2158 }
2159 if(hwndParent != OSLIB_HWND_DESKTOP)
2160 {//if the current process owns the window, just do a quick search
2161 child = (Win32BaseWindow *)parent->getFirstChild();
2162 if(hwndChildAfter != 0)
2163 {
2164 while(child)
2165 {
2166 if(child->getWindowHandle() == hwndChildAfter)
2167 {
2168 child = (Win32BaseWindow *)child->getNextChild();
2169 break;
2170 }
2171 child = (Win32BaseWindow *)child->getNextChild();
2172 }
2173 }
2174 while(child)
2175 {
2176 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2177 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2178 {
2179 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2180 return child->getWindowHandle();
2181 }
2182 child = (Win32BaseWindow *)child->getNextChild();
2183 }
2184 }
2185 else {
2186 Win32BaseWindow *wnd;
2187 HWND henum, hwnd;
2188
2189 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2190 hwnd = OSLibWinGetNextWindow(henum);
2191
2192 while(hwnd)
2193 {
2194 wnd = GetWindowFromOS2Handle(hwnd);
2195 if(wnd == NULL) {
2196 hwnd = OSLibWinQueryClientWindow(hwnd);
2197 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2198 }
2199
2200 if(wnd) {
2201 LPVOID sharedmembase = (LPVOID)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_SHAREDMEM);
2202
2203 if(OSLibDosGetSharedMem(sharedmembase, MAX_HEAPSIZE, OSLIB_PAG_READ) != 0) {
2204 dprintf(("OSLibDosGetSharedMem returned error for %x", wnd));
2205 break;
2206 }
2207 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2208 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2209 {
2210 OSLibWinEndEnumWindows(henum);
2211 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2212 return wnd->getWindowHandle();
2213 }
2214 }
2215 hwnd = OSLibWinGetNextWindow(henum);
2216 }
2217 OSLibWinEndEnumWindows(henum);
2218 }
2219 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2220 return 0;
2221}
2222//******************************************************************************
2223//TODO: not complete nor correct (distinction be tween top-level, top-most & child windows)
2224//******************************************************************************
2225HWND Win32BaseWindow::GetWindow(UINT uCmd)
2226{
2227 Win32BaseWindow *win32wnd;
2228 ULONG magic;
2229 ULONG getcmd = 0;
2230 HWND hwndRelated;
2231
2232 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
2233 switch(uCmd)
2234 {
2235 case GW_CHILD:
2236 getcmd = QWOS_TOP;
2237 break;
2238 case GW_HWNDFIRST:
2239 if(getParent()) {
2240 getcmd = QWOS_TOP; //top of child windows
2241 }
2242 else getcmd = QWOS_TOP; //TODO
2243 break;
2244 case GW_HWNDLAST:
2245 if(getParent()) {
2246 getcmd = QWOS_BOTTOM; //bottom of child windows
2247 }
2248 else getcmd = QWOS_BOTTOM; //TODO
2249 break;
2250 case GW_HWNDNEXT:
2251 getcmd = QWOS_NEXT;
2252 break;
2253 case GW_HWNDPREV:
2254 getcmd = QWOS_PREV;
2255 break;
2256 case GW_OWNER:
2257 if(owner) {
2258 return owner->getWindowHandle();
2259 }
2260 else return 0;
2261 }
2262 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
2263 if(hwndRelated)
2264 {
2265 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
2266 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
2267 if(CheckMagicDword(magic) && win32wnd)
2268 {
2269 return win32wnd->getWindowHandle();
2270 }
2271 }
2272 return 0;
2273}
2274//******************************************************************************
2275//******************************************************************************
2276HWND Win32BaseWindow::SetActiveWindow()
2277{
2278 return OSLibWinSetActiveWindow(OS2Hwnd);
2279}
2280//******************************************************************************
2281//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2282//******************************************************************************
2283BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2284{
2285 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
2286}
2287//******************************************************************************
2288//******************************************************************************
2289BOOL Win32BaseWindow::CloseWindow()
2290{
2291 return OSLibWinMinimizeWindow(OS2Hwnd);
2292}
2293//******************************************************************************
2294//******************************************************************************
2295HWND Win32BaseWindow::GetActiveWindow()
2296{
2297 HWND hwndActive;
2298 Win32BaseWindow *win32wnd;
2299 ULONG magic;
2300
2301 hwndActive = OSLibWinQueryActiveWindow();
2302
2303 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2304 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2305 if(CheckMagicDword(magic) && win32wnd)
2306 {
2307 return win32wnd->getWindowHandle();
2308 }
2309 return hwndActive;
2310}
2311//******************************************************************************
2312//******************************************************************************
2313BOOL Win32BaseWindow::IsWindowEnabled()
2314{
2315 return OSLibWinIsWindowEnabled(OS2Hwnd);
2316}
2317//******************************************************************************
2318//******************************************************************************
2319BOOL Win32BaseWindow::IsWindowVisible()
2320{
2321 return OSLibWinIsWindowVisible(OS2Hwnd);
2322}
2323//******************************************************************************
2324//******************************************************************************
2325BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2326{
2327 return OSLibWinQueryWindowRect(OS2Hwnd, pRect, RELATIVE_TO_SCREEN);
2328}
2329//******************************************************************************
2330//******************************************************************************
2331BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2332{
2333 if(fUnicode) {
2334 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2335 }
2336 else return (strcmp(windowNameA, wndname) == 0);
2337}
2338//******************************************************************************
2339//******************************************************************************
2340int Win32BaseWindow::GetWindowTextLength()
2341{
2342 return wndNameLength;
2343}
2344//******************************************************************************
2345//******************************************************************************
2346int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2347{
2348 strncpy(lpsz, windowNameA, cch);
2349 return wndNameLength;
2350}
2351//******************************************************************************
2352//******************************************************************************
2353int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2354{
2355 lstrcpynW((LPWSTR)lpsz, windowNameW, cch);
2356 return wndNameLength;
2357}
2358//******************************************************************************
2359//******************************************************************************
2360BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2361{
2362 if(lpsz == NULL)
2363 return FALSE;
2364
2365 if(windowNameA) free(windowNameA);
2366 if(windowNameW) free(windowNameW);
2367
2368 windowNameA = (LPSTR)_smalloc(strlen(lpsz)+1);
2369 strcpy(windowNameA, lpsz);
2370 windowNameW = (LPWSTR)_smalloc((strlen(lpsz)+1)*sizeof(WCHAR));
2371 lstrcpyAtoW(windowNameW, windowNameA);
2372 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2373
2374 if(OS2HwndFrame)
2375 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2376
2377 return TRUE;
2378}
2379//******************************************************************************
2380//******************************************************************************
2381BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2382{
2383 if(lpsz == NULL)
2384 return FALSE;
2385
2386 if(windowNameA) free(windowNameA);
2387 if(windowNameW) free(windowNameW);
2388
2389 windowNameW = (LPWSTR)_smalloc((lstrlenW((LPWSTR)lpsz)+1)*sizeof(WCHAR));
2390 lstrcpyW(windowNameW, (LPWSTR)lpsz);
2391 windowNameA = (LPSTR)_smalloc(lstrlenW((LPWSTR)lpsz)+1);
2392 lstrcpyWtoA(windowNameA, windowNameW);
2393 wndNameLength = strlen(windowNameA)+1; //including 0 terminator
2394
2395 if(OS2HwndFrame)
2396 return OSLibWinSetWindowText(OS2HwndFrame, (LPSTR)windowNameA);
2397
2398 return TRUE;
2399}
2400//******************************************************************************
2401//******************************************************************************
2402LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2403{
2404 LONG oldval;
2405
2406 switch(index) {
2407 case GWL_EXSTYLE:
2408 {
2409 STYLESTRUCT ss;
2410
2411 ss.styleOld = dwExStyle;
2412 ss.styleNew = value;
2413 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2414 oldval = dwExStyle;
2415 setExStyle(value);
2416 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2417 return oldval;
2418 }
2419 case GWL_STYLE:
2420 {
2421 STYLESTRUCT ss;
2422
2423 ss.styleOld = dwStyle;
2424 ss.styleNew = value;
2425 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2426 oldval = dwStyle;
2427 setStyle(value);
2428 OSLibSetWindowStyle(OS2HwndFrame, dwStyle);
2429 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2430 return oldval;
2431 }
2432 case GWL_WNDPROC:
2433 oldval = (LONG)getWindowProc();
2434 setWindowProc((WNDPROC)value);
2435 return oldval;
2436 case GWL_HINSTANCE:
2437 oldval = hInstance;
2438 hInstance = value;
2439 return oldval;
2440 case GWL_HWNDPARENT:
2441 return SetParent((HWND)value);
2442 case GWL_ID:
2443 oldval = getWindowId();
2444 setWindowId(value);
2445 return oldval;
2446 case GWL_USERDATA:
2447 oldval = userData;
2448 userData = value;
2449 return oldval;
2450 default:
2451 if(index >= 0 && index/4 < nrUserWindowLong)
2452 {
2453 oldval = userWindowLong[index/4];
2454 userWindowLong[index/4] = value;
2455 return oldval;
2456 }
2457 SetLastError(ERROR_INVALID_PARAMETER);
2458 return 0;
2459 }
2460}
2461//******************************************************************************
2462//******************************************************************************
2463ULONG Win32BaseWindow::GetWindowLongA(int index)
2464{
2465 switch(index) {
2466 case GWL_EXSTYLE:
2467 return dwExStyle;
2468 case GWL_STYLE:
2469 return dwStyle;
2470 case GWL_WNDPROC:
2471 return (ULONG)getWindowProc();
2472 case GWL_HINSTANCE:
2473 return hInstance;
2474 case GWL_HWNDPARENT:
2475 if(getParent()) {
2476 return getParent()->getWindowHandle();
2477 }
2478 else return 0;
2479 case GWL_ID:
2480 return getWindowId();
2481 case GWL_USERDATA:
2482 return userData;
2483 default:
2484 if(index >= 0 && index/4 < nrUserWindowLong)
2485 {
2486 return userWindowLong[index/4];
2487 }
2488 SetLastError(ERROR_INVALID_PARAMETER);
2489 return 0;
2490 }
2491}
2492//******************************************************************************
2493//******************************************************************************
2494WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2495{
2496 WORD oldval;
2497
2498 if(index >= 0 && index/4 < nrUserWindowLong)
2499 {
2500 oldval = ((WORD *)userWindowLong)[index/2];
2501 ((WORD *)userWindowLong)[index/2] = value;
2502 return oldval;
2503 }
2504 SetLastError(ERROR_INVALID_PARAMETER);
2505 return 0;
2506}
2507//******************************************************************************
2508//******************************************************************************
2509WORD Win32BaseWindow::GetWindowWord(int index)
2510{
2511 if(index >= 0 && index/4 < nrUserWindowLong)
2512 {
2513 return ((WORD *)userWindowLong)[index/2];
2514 }
2515 SetLastError(ERROR_INVALID_PARAMETER);
2516 return 0;
2517}
2518//******************************************************************************
2519//******************************************************************************
2520void Win32BaseWindow::setWindowId(DWORD id)
2521{
2522 windowId = id;
2523 OSLibSetWindowID(OS2HwndFrame, id);
2524}
2525//******************************************************************************
2526//******************************************************************************
2527Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
2528{
2529 Win32BaseWindow *window;
2530
2531 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
2532 return window;
2533 }
2534 else return NULL;
2535}
2536//******************************************************************************
2537//******************************************************************************
2538Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
2539{
2540 Win32BaseWindow *win32wnd;
2541 DWORD magic;
2542
2543 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
2544 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
2545
2546 if(win32wnd && CheckMagicDword(magic)) {
2547 return win32wnd;
2548 }
2549 return 0;
2550}
2551//******************************************************************************
2552//******************************************************************************
2553HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
2554{
2555 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
2556
2557 if(window) {
2558 return window->getOS2WindowHandle();
2559 }
2560 else return hwnd; //OS/2 window handle
2561}
2562//******************************************************************************
2563//******************************************************************************
2564HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
2565{
2566 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
2567
2568 if(window) {
2569 return window->getWindowHandle();
2570 }
2571 else return hwnd; //OS/2 window handle
2572}
2573//******************************************************************************
2574//******************************************************************************
2575GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.