source: trunk/src/user32/new/win32wnd.cpp@ 345

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

Accelerator + icon changes

File size: 53.4 KB
Line 
1/* $Id: win32wnd.cpp,v 1.18 1999-07-20 15:46:54 sandervl Exp $ */
2/*
3 * Win32 Window Code for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16#include <os2win.h>
17#include <win.h>
18#include <stdlib.h>
19#include <string.h>
20#include <stdarg.h>
21#include <assert.h>
22#include <misc.h>
23#include <handlemanager.h>
24#include <win32wnd.h>
25#include <spy.h>
26#include "wndmsg.h"
27#include "hooks.h"
28#include <oslibwin.h>
29#include <oslibutil.h>
30#include <oslibgdi.h>
31#include <oslibres.h>
32#include <winres.h>
33
34#define HAS_DLGFRAME(style,exStyle) \
35 (((exStyle) & WS_EX_DLGMODALFRAME) || \
36 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
37
38#define HAS_THICKFRAME(style) \
39 (((style) & WS_THICKFRAME) && \
40 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
41
42//******************************************************************************
43//******************************************************************************
44Win32Window::Win32Window(DWORD objType) : GenericObject(&windows, objType)
45{
46 Init();
47}
48//******************************************************************************
49//******************************************************************************
50Win32Window::Win32Window(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
51 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
52{
53 Init();
54 this->isUnicode = isUnicode;
55 CreateWindowExA(lpCreateStructA, classAtom);
56}
57//******************************************************************************
58//******************************************************************************
59void Win32Window::Init()
60{
61 isUnicode = FALSE;
62
63 windowName = NULL;
64 wndNameLength = 0;
65
66 windowText = NULL;;
67 wndTextLength = 0;
68
69 userWindowLong = NULL;;
70 nrUserWindowLong = 0;
71
72 magic = WIN32PM_MAGIC;
73 OS2Hwnd = 0;
74 OS2HwndFrame = 0;
75 OS2HwndMenu = 0;
76 Win32Hwnd = 0;
77
78 if(HMHandleAllocate(&Win32Hwnd, (ULONG)this) != 0)
79 {
80 dprintf(("Win32Window::Init HMHandleAllocate failed!!"));
81 DebugInt3();
82 }
83 Win32Hwnd &= 0xFFFF;
84 Win32Hwnd |= 0x68000000;
85
86 posx = posy = 0;
87 width = height = 0;
88
89 dwExStyle = 0;
90 dwStyle = 0;
91 win32wndproc = 0;
92 hInstance = 0;
93 windowId = 0xFFFFFFFF; //default = -1
94 userData = 0;
95
96 hwndLinkAfter = HWND_BOTTOM;
97 flags = 0;
98 isIcon = FALSE;
99 lastHitTestVal = 0;
100 owner = NULL;
101 windowClass = 0;
102
103 acceltableResource = NULL;
104 menuResource = NULL;
105 iconResource = NULL;
106}
107//******************************************************************************
108//todo get rid of resources (menu, accel, icon etc)
109//******************************************************************************
110Win32Window::~Win32Window()
111{
112 if(Win32Hwnd)
113 HMHandleFree(Win32Hwnd);
114 if(windowName)
115 free(windowName);
116 if(windowText)
117 free(windowText);
118 if(userWindowLong)
119 free(userWindowLong);
120}
121//******************************************************************************
122//******************************************************************************
123BOOL Win32Window::isChild()
124{
125 return (dwStyle & WS_CHILD) != 0;
126}
127//******************************************************************************
128//******************************************************************************
129BOOL Win32Window::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
130{
131 char buffer[256];
132 INT sw = SW_SHOW;
133 POINT maxSize, maxPos, minTrack, maxTrack;
134
135 SetLastError(0);
136
137 /* Find the parent window */
138 if (cs->hwndParent)
139 {
140 Win32Window *window = GetWindowFromHandle(cs->hwndParent);
141 if(!window) {
142 dprintf(("Bad parent %04x\n", cs->hwndParent ));
143 SetLastError(ERROR_INVALID_PARAMETER);
144 return FALSE;
145 }
146 /* Make sure parent is valid */
147 if (!window->IsWindow() )
148 {
149 dprintf(("Bad parent %04x\n", cs->hwndParent ));
150 SetLastError(ERROR_INVALID_PARAMETER);
151 return FALSE;
152 }
153 }
154 else
155 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
156 dprintf(("No parent for child window\n" ));
157 SetLastError(ERROR_INVALID_PARAMETER);
158 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
159 }
160
161 /* Find the window class */
162 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
163 if (!windowClass)
164 {
165 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
166 dprintf(("Bad class '%s'\n", buffer ));
167 return 0;
168 }
169
170 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
171 * with an atom as the class name, put some programs expect to have a *REAL* string in
172 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
173 */
174 if (!HIWORD(cs->lpszClass) ) {
175 if (isUnicode) {
176 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
177 }
178 else {
179 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
180 }
181 cs->lpszClass = buffer;
182 }
183
184 /* Fix the coordinates */
185 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
186 {
187// PDB *pdb = PROCESS_Current();
188
189 /* Never believe Microsoft's documentation... CreateWindowEx doc says
190 * that if an overlapped window is created with WS_VISIBLE style bit
191 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
192 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
193 * reveals that
194 *
195 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
196 * 2) it does not ignore the y parameter as the docs claim; instead, it
197 * uses it as second parameter to ShowWindow() unless y is either
198 * CW_USEDEFAULT or CW_USEDEFAULT16.
199 *
200 * The fact that we didn't do 2) caused bogus windows pop up when wine
201 * was running apps that were using this obscure feature. Example -
202 * calc.exe that comes with Win98 (only Win98, it's different from
203 * the one that comes with Win95 and NT)
204 */
205 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
206
207 /* We have saved cs->y, now we can trash it */
208#if 0
209 if ( !(cs->style & (WS_CHILD | WS_POPUP))
210 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
211 {
212 cs->x = pdb->env_db->startup_info->dwX;
213 cs->y = pdb->env_db->startup_info->dwY;
214 }
215#endif
216 cs->x = 0;
217 cs->y = 0;
218// }
219 }
220 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
221 {
222#if 0
223 PDB *pdb = PROCESS_Current();
224 if ( !(cs->style & (WS_CHILD | WS_POPUP))
225 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
226 {
227 cs->cx = pdb->env_db->startup_info->dwXSize;
228 cs->cy = pdb->env_db->startup_info->dwYSize;
229 }
230 else
231 {
232#endif
233 cs->cx = 600; /* FIXME */
234 cs->cy = 400;
235// }
236 }
237
238 //Allocate window words
239 nrUserWindowLong = windowClass->getExtraWndWords();
240 if(nrUserWindowLong) {
241 userWindowLong = (ULONG *)malloc(nrUserWindowLong);
242 memset(userWindowLong, 0, nrUserWindowLong);
243 }
244
245 if ((cs->style & WS_CHILD) && cs->hwndParent)
246 {
247 SetParent(cs->hwndParent);
248 }
249 else
250 {
251 if (!cs->hwndParent) {
252 owner = NULL;
253 }
254 else
255 {
256 owner = GetWindowFromHandle(cs->hwndParent);
257 if(owner == NULL)
258 {
259 dprintf(("HMHandleTranslateToOS2 couldn't find owner window %x!!!", cs->hwndParent));
260 return FALSE;
261 }
262 }
263 }
264
265 setWindowProc(windowClass->getWindowProc());
266 hInstance = cs->hInstance;
267 dwStyle = cs->style & ~WS_VISIBLE;
268 dwExStyle = cs->dwExStyle;
269
270 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
271 ? HWND_BOTTOM : HWND_TOP;
272
273#if 0
274//TODO
275 /* Call the WH_CBT hook */
276
277 if (HOOK_IsHooked( WH_CBT ))
278 {
279 CBT_CREATEWNDA cbtc;
280 LRESULT ret;
281
282 cbtc.lpcs = cs;
283 cbtc.hwndInsertAfter = hwndLinkAfter;
284 ret = unicode ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc)
285 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, Win32Hwnd, (LPARAM)&cbtc);
286 if (ret)
287 {
288 TRACE_(win)("CBT-hook returned 0\n");
289 wndPtr->pDriver->pFinalize(wndPtr);
290 retvalue = 0;
291 goto end;
292 }
293 }
294#endif
295
296 /* Increment class window counter */
297 windowClass->IncreaseWindowCount();
298
299 /* Correct the window style */
300 if (!(cs->style & WS_CHILD))
301 {
302 dwStyle |= WS_CLIPSIBLINGS;
303 if (!(cs->style & WS_POPUP))
304 {
305 dwStyle |= WS_CAPTION;
306 flags |= WIN_NEED_SIZE;
307 }
308 }
309 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
310
311 //TODO?
312#if 0
313 /* Get class or window DC if needed */
314 if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
315 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
316 else wndPtr->dce = NULL;
317#endif
318
319 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
320 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
321 {
322 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
323 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
324 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
325 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
326 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
327 }
328
329 if(cs->style & WS_CHILD)
330 {
331 if(cs->cx < 0) cs->cx = 0;
332 if(cs->cy < 0) cs->cy = 0;
333 }
334 else
335 {
336 if (cs->cx <= 0) cs->cx = 1;
337 if (cs->cy <= 0) cs->cy = 1;
338 }
339
340 rectWindow.left = cs->x;
341 rectWindow.top = cs->y;
342 rectWindow.right = cs->x + cs->cx;
343 rectWindow.bottom = cs->y + cs->cy;
344 rectClient = rectWindow;
345
346 DWORD dwOSWinStyle, dwOSFrameStyle;
347
348 OSLibWinConvertStyle(cs->style, &dwOSWinStyle, &dwOSFrameStyle);
349
350 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : 0,
351 dwOSWinStyle, dwOSFrameStyle, (char *)cs->lpszName,
352 (owner) ? owner->getOS2WindowHandle() : 0,
353 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
354 &OS2HwndFrame);
355
356 if(OS2Hwnd == 0) {
357 dprintf(("Window creation failed!!"));
358 return FALSE;
359 }
360 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
361 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
362 return FALSE;
363 }
364 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
365 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
366 return FALSE;
367 }
368#if 0
369 if(OS2Hwnd != OS2HwndFrame) {
370 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
371 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
372 return FALSE;
373 }
374 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
375 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
376 return FALSE;
377 }
378 }
379#endif
380 /* Set the window menu */
381 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
382 {
383 if (cs->hMenu) SetMenu(cs->hMenu);
384 else
385 {
386 if (windowClass->getMenuNameA()) {
387 cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
388 if (cs->hMenu) SetMenu(cs->hMenu );
389 }
390 }
391 }
392 else windowId = (UINT)cs->hMenu;
393
394 //Set icon from class
395 if(windowClass->getIcon())
396 SetIcon(windowClass->getIcon());
397
398 /* Send the WM_CREATE message
399 * Perhaps we shouldn't allow width/height changes as well.
400 * See p327 in "Internals".
401 */
402 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
403
404 if(SendInternalMessage(WM_NCCREATE, 0, (LPARAM)cs) )
405 {
406 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
407 OffsetRect(&rectWindow, maxPos.x - rectWindow.left,
408 maxPos.y - rectWindow.top);
409 dprintf(("Sending WM_CREATE"));
410 if( (SendInternalMessage(WM_CREATE, 0, (LPARAM)cs )) != -1 )
411 {
412 SetWindowPos(HWND_TOP, rectClient.left, rectClient.top,
413 rectClient.right-rectClient.left,
414 rectClient.bottom-rectClient.top,
415 SWP_NOACTIVATE);
416
417 if (cs->style & WS_VISIBLE) ShowWindow( sw );
418
419#if 0
420 /* Call WH_SHELL hook */
421
422 if (!(dwStyle & WS_CHILD) && !owner)
423 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
424#endif
425 SetLastError(0);
426 return TRUE;
427 }
428 }
429 return FALSE;
430}
431#if 0
432/***********************************************************************
433 * WINPOS_MinMaximize
434 *
435 * Fill in lpRect and return additional flags to be used with SetWindowPos().
436 * This function assumes that 'cmd' is different from the current window
437 * state.
438 */
439UINT Win32Window::MinMaximize(UINT16 cmd, LPRECT16 lpRect )
440{
441 UINT swpFlags = 0;
442 POINT pt, size;
443 LPINTERNALPOS lpPos;
444
445 size.x = rectWindow.left; size.y = rectWindow.top;
446 lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
447
448 if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
449 {
450 if( dwStyle & WS_MINIMIZE )
451 {
452 if( !SendInternalMessageA(WM_QUERYOPEN, 0, 0L ) )
453 return (SWP_NOSIZE | SWP_NOMOVE);
454 swpFlags |= SWP_NOCOPYBITS;
455 }
456 switch( cmd )
457 {
458 case SW_MINIMIZE:
459 if( dwStyle & WS_MAXIMIZE)
460 {
461 flags |= WIN_RESTORE_MAX;
462 dwStyle &= ~WS_MAXIMIZE;
463 }
464 else
465 flags &= ~WIN_RESTORE_MAX;
466 dwStyle |= WS_MINIMIZE;
467
468#if 0
469 if( flags & WIN_NATIVE )
470 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
471 swpFlags |= MINMAX_NOSWP;
472#endif
473
474 lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
475
476 SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
477 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
478 swpFlags |= SWP_NOCOPYBITS;
479 break;
480
481 case SW_MAXIMIZE:
482 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
483 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
484 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
485
486 if( dwStyle & WS_MINIMIZE )
487 {
488 if( flags & WIN_NATIVE )
489 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
490 swpFlags |= MINMAX_NOSWP;
491
492 WINPOS_ShowIconTitle( wndPtr, FALSE );
493 dwStyle &= ~WS_MINIMIZE;
494 }
495 dwStyle |= WS_MAXIMIZE;
496
497 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
498 size.x, size.y );
499 break;
500
501 case SW_RESTORE:
502 if( dwStyle & WS_MINIMIZE )
503 {
504 if( flags & WIN_NATIVE )
505 if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
506 swpFlags |= MINMAX_NOSWP;
507
508 dwStyle &= ~WS_MINIMIZE;
509 WINPOS_ShowIconTitle( wndPtr, FALSE );
510
511 if( flags & WIN_RESTORE_MAX)
512 {
513 /* Restore to maximized position */
514 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
515 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
516 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
517 dwStyle |= WS_MAXIMIZE;
518 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
519 break;
520 }
521 }
522 else
523 if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
524 else dwStyle &= ~WS_MAXIMIZE;
525
526 /* Restore to normal position */
527
528 *lpRect = lpPos->rectNormal;
529 lpRect->right -= lpRect->left;
530 lpRect->bottom -= lpRect->top;
531
532 break;
533 }
534 } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
535 return swpFlags;
536}
537#endif
538/*******************************************************************
539 * GetMinMaxInfo
540 *
541 * Get the minimized and maximized information for a window.
542 */
543void Win32Window::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
544 POINT *minTrack, POINT *maxTrack )
545{
546 MINMAXINFO MinMax;
547 INT xinc, yinc;
548
549 /* Compute default values */
550
551 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
552 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
553 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
554 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
555 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
556 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
557
558 if (flags & WIN_MANAGED) xinc = yinc = 0;
559 else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
560 {
561 xinc = GetSystemMetrics(SM_CXDLGFRAME);
562 yinc = GetSystemMetrics(SM_CYDLGFRAME);
563 }
564 else
565 {
566 xinc = yinc = 0;
567 if (HAS_THICKFRAME(dwStyle))
568 {
569 xinc += GetSystemMetrics(SM_CXFRAME);
570 yinc += GetSystemMetrics(SM_CYFRAME);
571 }
572 if (dwStyle & WS_BORDER)
573 {
574 xinc += GetSystemMetrics(SM_CXBORDER);
575 yinc += GetSystemMetrics(SM_CYBORDER);
576 }
577 }
578 MinMax.ptMaxSize.x += 2 * xinc;
579 MinMax.ptMaxSize.y += 2 * yinc;
580
581#if 0
582 lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
583 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
584 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
585 else
586 {
587#endif
588 MinMax.ptMaxPosition.x = -xinc;
589 MinMax.ptMaxPosition.y = -yinc;
590// }
591
592 SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
593
594 /* Some sanity checks */
595
596 dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
597 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
598 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
599 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
600 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
601 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
602 MinMax.ptMinTrackSize.x );
603 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
604 MinMax.ptMinTrackSize.y );
605
606 if (maxSize) *maxSize = MinMax.ptMaxSize;
607 if (maxPos) *maxPos = MinMax.ptMaxPosition;
608 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
609 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
610}
611/***********************************************************************
612 * WINPOS_SendNCCalcSize
613 *
614 * Send a WM_NCCALCSIZE message to a window.
615 * All parameters are read-only except newClientRect.
616 * oldWindowRect, oldClientRect and winpos must be non-NULL only
617 * when calcValidRect is TRUE.
618 */
619LONG Win32Window::SendNCCalcSize(BOOL calcValidRect,
620 RECT *newWindowRect, RECT *oldWindowRect,
621 RECT *oldClientRect, WINDOWPOS *winpos,
622 RECT *newClientRect )
623{
624 NCCALCSIZE_PARAMS params;
625 WINDOWPOS winposCopy;
626 LONG result;
627
628 params.rgrc[0] = *newWindowRect;
629 if (calcValidRect)
630 {
631 winposCopy = *winpos;
632 params.rgrc[1] = *oldWindowRect;
633 params.rgrc[2] = *oldClientRect;
634 params.lppos = &winposCopy;
635 }
636 result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect,
637 (LPARAM)&params );
638 *newClientRect = params.rgrc[0];
639 return result;
640}
641//******************************************************************************
642//******************************************************************************
643ULONG Win32Window::MsgCreate(HWND hwndOS2, ULONG initParam)
644{
645 OS2Hwnd = hwndOS2;
646 return SendInternalMessageA(WM_CREATE, 0, initParam);
647}
648//******************************************************************************
649//******************************************************************************
650ULONG Win32Window::MsgQuit()
651{
652 return SendInternalMessageA(WM_QUIT, 0, 0);
653}
654//******************************************************************************
655//******************************************************************************
656ULONG Win32Window::MsgClose()
657{
658 return SendInternalMessageA(WM_CLOSE, 0, 0);
659}
660//******************************************************************************
661//******************************************************************************
662ULONG Win32Window::MsgDestroy()
663{
664 ULONG rc;
665
666 rc = SendInternalMessageA(WM_DESTROY, 0, 0);
667 delete this;
668 return rc;
669}
670//******************************************************************************
671//******************************************************************************
672ULONG Win32Window::MsgEnable(BOOL fEnable)
673{
674 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
675}
676//******************************************************************************
677//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
678//******************************************************************************
679ULONG Win32Window::MsgShow(BOOL fShow)
680{
681 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
682}
683//******************************************************************************
684//******************************************************************************
685ULONG Win32Window::MsgMove(ULONG x, ULONG y)
686{
687 dprintf(("MsgMove to (%d,%d)", x, y));
688 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
689}
690//******************************************************************************
691//******************************************************************************
692ULONG Win32Window::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
693{
694 switch(cmd) {
695 case CMD_MENU:
696 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
697 case CMD_CONTROL:
698 return 0; //todo
699 case CMD_ACCELERATOR:
700 dprintf(("accelerator command"));
701 return 0; //todo
702 }
703}
704//******************************************************************************
705//******************************************************************************
706ULONG Win32Window::MsgHitTest(ULONG x, ULONG y)
707{
708 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
709 return 1; //TODO: May need to change this
710}
711//******************************************************************************
712//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
713//******************************************************************************
714ULONG Win32Window::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
715{
716 WORD fwSizeType = 0;
717
718 if(fMinimize) {
719 fwSizeType = SIZE_MINIMIZED;
720 }
721 else
722 if(fMaximize) {
723 fwSizeType = SIZE_MAXIMIZED;
724 }
725 else fwSizeType = SIZE_RESTORED;
726
727 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
728}
729//******************************************************************************
730//******************************************************************************
731ULONG Win32Window::MsgActivate(BOOL fActivate, HWND hwnd)
732{
733 return SendInternalMessageA(WM_ACTIVATE, (fActivate) ? WA_ACTIVE : WA_INACTIVE, hwnd);
734}
735//******************************************************************************
736//******************************************************************************
737ULONG Win32Window::MsgSetFocus(HWND hwnd)
738{
739 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
740}
741//******************************************************************************
742//******************************************************************************
743ULONG Win32Window::MsgKillFocus(HWND hwnd)
744{
745 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
746}
747//******************************************************************************
748//******************************************************************************
749ULONG Win32Window::MsgButton(ULONG msg, ULONG x, ULONG y)
750{
751 ULONG win32msg;
752 ULONG win32ncmsg;
753
754 dprintf(("MsgButton to (%d,%d)", x, y));
755 switch(msg) {
756 case BUTTON_LEFTDOWN:
757 win32msg = WM_LBUTTONDOWN;
758 win32ncmsg = WM_NCLBUTTONDOWN;
759 break;
760 case BUTTON_LEFTUP:
761 win32msg = WM_LBUTTONUP;
762 win32ncmsg = WM_NCLBUTTONUP;
763 break;
764 case BUTTON_LEFTDBLCLICK:
765 win32msg = WM_LBUTTONDBLCLK;
766 win32ncmsg = WM_NCLBUTTONDBLCLK;
767 break;
768 case BUTTON_RIGHTUP:
769 win32msg = WM_RBUTTONUP;
770 win32ncmsg = WM_NCRBUTTONUP;
771 break;
772 case BUTTON_RIGHTDOWN:
773 win32msg = WM_RBUTTONDOWN;
774 win32ncmsg = WM_NCRBUTTONDOWN;
775 break;
776 case BUTTON_RIGHTDBLCLICK:
777 win32msg = WM_RBUTTONDBLCLK;
778 win32ncmsg = WM_NCRBUTTONDBLCLK;
779 break;
780 case BUTTON_MIDDLEUP:
781 win32msg = WM_MBUTTONUP;
782 win32ncmsg = WM_NCMBUTTONUP;
783 break;
784 case BUTTON_MIDDLEDOWN:
785 win32msg = WM_MBUTTONDOWN;
786 win32ncmsg = WM_NCMBUTTONDOWN;
787 break;
788 case BUTTON_MIDDLEDBLCLICK:
789 win32msg = WM_MBUTTONDBLCLK;
790 win32ncmsg = WM_NCMBUTTONDBLCLK;
791 break;
792 default:
793 dprintf(("Win32Window::Button: invalid msg!!!!"));
794 return 1;
795 }
796 SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(x, y)); //TODO:
797 return SendInternalMessageA(win32msg, 0, MAKELONG(x, y));
798}
799//******************************************************************************
800//******************************************************************************
801ULONG Win32Window::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
802{
803ULONG winstate = 0;
804
805 if(keystate & WMMOVE_LBUTTON)
806 winstate |= MK_LBUTTON;
807 if(keystate & WMMOVE_RBUTTON)
808 winstate |= MK_RBUTTON;
809 if(keystate & WMMOVE_MBUTTON)
810 winstate |= MK_MBUTTON;
811 if(keystate & WMMOVE_SHIFT)
812 winstate |= MK_SHIFT;
813 if(keystate & WMMOVE_CTRL)
814 winstate |= MK_CONTROL;
815
816 return SendInternalMessageA(WM_MOUSEMOVE, keystate, MAKELONG(x, y));
817}
818//******************************************************************************
819//******************************************************************************
820ULONG Win32Window::MsgPaint(ULONG tmp1, ULONG tmp2)
821{
822 return SendInternalMessageA(WM_PAINT, 0, 0);
823}
824//******************************************************************************
825//******************************************************************************
826ULONG Win32Window::MsgEraseBackGround(ULONG hps)
827{
828 if(isIcon) {
829 return SendInternalMessageA(WM_ICONERASEBKGND, hps, 0);
830 }
831 else return SendInternalMessageA(WM_ERASEBKGND, hps, 0);
832}
833//******************************************************************************
834//******************************************************************************
835ULONG Win32Window::MsgSetText(LPSTR lpsz, LONG cch)
836{
837 if(isUnicode) {
838 return SendInternalMessageW(WM_SETTEXT, 0, (LPARAM)lpsz);
839 }
840 else return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
841}
842//******************************************************************************
843//******************************************************************************
844LRESULT Win32Window::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
845{
846 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
847 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
848
849 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
850 return(0);
851 }
852 switch(Msg)
853 {
854 case WM_CREATE:
855 {
856 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
857 dprintf(("WM_NCCREATE returned FALSE\n"));
858 return(-1); //don't create window
859 }
860 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
861 dprintf(("WM_CREATE returned -1\n"));
862 return(-1); //don't create window
863 }
864 NotifyParent(Msg, wParam, lParam);
865
866 return(0);
867 }
868 case WM_LBUTTONDOWN:
869 case WM_MBUTTONDOWN:
870 case WM_RBUTTONDOWN:
871 NotifyParent(Msg, wParam, lParam);
872 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
873
874 case WM_DESTROY:
875 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
876 NotifyParent(Msg, wParam, lParam);
877 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
878 default:
879 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
880 }
881}
882//******************************************************************************
883//******************************************************************************
884LRESULT Win32Window::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
885{
886 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
887 dprintf(("SendMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
888
889 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
890 return(0);
891 }
892 switch(Msg)
893 {
894 case WM_CREATE:
895 {
896 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
897 dprintf(("WM_NCCREATE returned FALSE\n"));
898 return(0); //don't create window
899 }
900 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
901 dprintf(("WM_CREATE returned FALSE\n"));
902 return(0); //don't create window
903 }
904 NotifyParent(Msg, wParam, lParam);
905
906 return(1);
907 }
908 case WM_LBUTTONDOWN:
909 case WM_MBUTTONDOWN:
910 case WM_RBUTTONDOWN:
911 NotifyParent(Msg, wParam, lParam);
912 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
913
914 case WM_DESTROY:
915 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
916 NotifyParent(Msg, wParam, lParam);
917 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
918
919 default:
920 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
921 }
922}
923//******************************************************************************
924//Called as a result of an OS/2 message
925//******************************************************************************
926LRESULT Win32Window::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
927{
928 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
929 dprintf(("SendInternalMessageA %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
930
931 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
932 return(0);
933 }
934 switch(Msg)
935 {
936 case WM_CREATE:
937 {
938 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
939 dprintf(("WM_NCCREATE returned FALSE\n"));
940 return(0); //don't create window
941 }
942 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
943 dprintf(("WM_CREATE returned FALSE\n"));
944 return(0); //don't create window
945 }
946 NotifyParent(Msg, wParam, lParam);
947
948 return(1);
949 }
950 case WM_LBUTTONDOWN:
951 case WM_MBUTTONDOWN:
952 case WM_RBUTTONDOWN:
953 NotifyParent(Msg, wParam, lParam);
954 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
955
956 case WM_DESTROY:
957 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
958 NotifyParent(Msg, wParam, lParam);
959 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
960 default:
961 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
962 }
963}
964//******************************************************************************
965//Called as a result of an OS/2 message
966//todo, unicode msgs (WM_SETTEXT etc)
967//******************************************************************************
968LRESULT Win32Window::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
969{
970 if(PostSpyMessage(getWindowHandle(), Msg, wParam, lParam) == FALSE)
971 dprintf(("SendInternalMessageW %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
972
973 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
974 return(0);
975 }
976 switch(Msg)
977 {
978 case WM_CREATE:
979 {
980 if(win32wndproc(getWindowHandle(), WM_NCCREATE, 0, lParam) == 0) {
981 dprintf(("WM_NCCREATE returned FALSE\n"));
982 return(0); //don't create window
983 }
984 if(win32wndproc(getWindowHandle(), WM_CREATE, 0, lParam) == 0) {
985 dprintf(("WM_CREATE returned FALSE\n"));
986 return(0); //don't create window
987 }
988 NotifyParent(Msg, wParam, lParam);
989
990 return(1);
991 }
992 case WM_LBUTTONDOWN:
993 case WM_MBUTTONDOWN:
994 case WM_RBUTTONDOWN:
995 NotifyParent(Msg, wParam, lParam);
996 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
997
998 case WM_DESTROY:
999 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1000 NotifyParent(Msg, wParam, lParam);
1001 return win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1002 default:
1003 return win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1004 }
1005}
1006//******************************************************************************
1007//******************************************************************************
1008BOOL Win32Window::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
1009{
1010 POSTMSG_PACKET *postmsg;
1011
1012 postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
1013 if(postmsg == NULL) {
1014 dprintf(("Win32Window::PostMessageA: malloc returned NULL!!"));
1015 return 0;
1016 }
1017 postmsg->Msg = msg;
1018 postmsg->wParam = wParam;
1019 postmsg->lParam = lParam;
1020 return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEA, (ULONG)postmsg, 0);
1021}
1022//******************************************************************************
1023//******************************************************************************
1024BOOL Win32Window::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
1025{
1026 POSTMSG_PACKET *postmsg;
1027
1028 postmsg = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
1029 if(postmsg == NULL) {
1030 dprintf(("Win32Window::PostMessageW: malloc returned NULL!!"));
1031 return 0;
1032 }
1033 postmsg->Msg = msg;
1034 postmsg->wParam = wParam;
1035 postmsg->lParam = lParam;
1036 return OSLibPostMessage(OS2Hwnd, WM_WIN32_POSTMESSAGEW, (ULONG)postmsg, 0);
1037}
1038//******************************************************************************
1039//TODO: do we need to inform the parent of the parent (etc) of the child window?
1040//******************************************************************************
1041void Win32Window::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
1042{
1043 Win32Window *window = this;
1044 Win32Window *parentwindow;
1045
1046 while(window)
1047 {
1048 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
1049 {
1050 /* Notify the parent window only */
1051 parentwindow = window->getParent();
1052 if(parentwindow) {
1053 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
1054 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
1055 }
1056 else parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
1057 }
1058 }
1059 else break;
1060
1061 window = parentwindow;
1062 }
1063}
1064//******************************************************************************
1065//******************************************************************************
1066BOOL Win32Window::SetMenu(HMENU hMenu)
1067{
1068 PVOID menutemplate;
1069 Win32Resource *winres = (Win32Resource *)hMenu;
1070
1071 if(HIWORD(winres) == 0) {
1072 dprintf(("Win32Window:: Win32Resource *winres == 0"));
1073 SetLastError(ERROR_INVALID_PARAMETER);
1074 return FALSE;
1075 }
1076 menutemplate = winres->lockOS2Resource();
1077 if(menutemplate == NULL)
1078 {
1079 dprintf(("Win32Window::SetMenu menutemplate == 0"));
1080 return FALSE;
1081 }
1082 OS2HwndMenu = OSLibWinCreateMenu(OS2HwndFrame, menutemplate);
1083 if(OS2HwndMenu == 0) {
1084 dprintf(("Win32Window::SetMenu OS2HwndMenu == 0"));
1085 return FALSE;
1086 }
1087 menuResource = winres;
1088 return TRUE;
1089}
1090//******************************************************************************
1091//******************************************************************************
1092BOOL Win32Window::SetAccelTable(HACCEL hAccel)
1093{
1094 Win32Resource *winres = (Win32Resource *)hAccel;
1095 HANDLE accelhandle;
1096
1097 if(HIWORD(hAccel) == 0) {
1098 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
1099 SetLastError(ERROR_INVALID_PARAMETER);
1100 return FALSE;
1101 }
1102 acceltableResource = winres;
1103 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1104 winres->setOS2Handle(accelhandle);
1105 return(accelhandle != 0);
1106}
1107//******************************************************************************
1108//******************************************************************************
1109BOOL Win32Window::SetIcon(HICON hIcon)
1110{
1111 Win32Resource *winres = (Win32Resource *)hIcon;
1112 HANDLE iconhandle;
1113
1114 if(HIWORD(hIcon) == 0) {
1115 dprintf(("SetIcon: hIcon %x invalid", hIcon));
1116 SetLastError(ERROR_INVALID_PARAMETER);
1117 return FALSE;
1118 }
1119 dprintf(("Win32Window::SetIcon %x", hIcon));
1120 iconResource = winres;
1121 iconhandle = OSLibWinSetIcon(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
1122 winres->setOS2Handle(iconhandle);
1123 return(iconhandle != 0);
1124}
1125//******************************************************************************
1126//******************************************************************************
1127BOOL Win32Window::ShowWindow(ULONG nCmdShow)
1128{
1129 ULONG showstate = 0;
1130
1131 dprintf(("ShowWindow %x", nCmdShow));
1132 switch(nCmdShow)
1133 {
1134 case SW_SHOW:
1135 case SW_SHOWDEFAULT: //todo
1136 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
1137 break;
1138 case SW_HIDE:
1139 showstate = SWPOS_HIDE;
1140 break;
1141 case SW_RESTORE:
1142 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
1143 break;
1144 case SW_MINIMIZE:
1145 showstate = SWPOS_MINIMIZE;
1146 break;
1147 case SW_SHOWMAXIMIZED:
1148 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1149 break;
1150 case SW_SHOWMINIMIZED:
1151 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
1152 break;
1153 case SW_SHOWMINNOACTIVE:
1154 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
1155 break;
1156 case SW_SHOWNA:
1157 showstate = SWPOS_SHOW;
1158 break;
1159 case SW_SHOWNOACTIVATE:
1160 showstate = SWPOS_SHOW;
1161 break;
1162 case SW_SHOWNORMAL:
1163 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
1164 break;
1165 }
1166 return OSLibWinShowWindow(OS2HwndFrame, showstate);
1167}
1168//******************************************************************************
1169//******************************************************************************
1170BOOL Win32Window::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
1171{
1172 Win32Window *window;
1173 ULONG setstate = 0;
1174
1175 switch(hwndInsertAfter) {
1176 case HWND_BOTTOM:
1177 hwndInsertAfter = HWNDOS_BOTTOM;
1178 break;
1179 case HWND_TOPMOST: //TODO:
1180 case HWND_NOTOPMOST: //TODO:
1181 case HWND_TOP:
1182 hwndInsertAfter = HWNDOS_TOP;
1183 break;
1184 default:
1185 window = GetWindowFromHandle(hwndInsertAfter);
1186 if(window) {
1187 hwndInsertAfter = window->getOS2WindowHandle();
1188 }
1189 else {
1190 dprintf(("Win32Window::SetWindowPos, unknown hwndInsertAfter %x", hwndInsertAfter));
1191 hwndInsertAfter = 0;
1192 }
1193 break;
1194
1195 }
1196 setstate = SWPOS_MOVE | SWPOS_SIZE | SWPOS_ACTIVATE | SWPOS_ZORDER;
1197 if(fuFlags & SWP_DRAWFRAME)
1198 setstate |= 0; //TODO
1199 if(fuFlags & SWP_FRAMECHANGED)
1200 setstate |= 0; //TODO
1201 if(fuFlags & SWP_HIDEWINDOW)
1202 setstate &= ~SWPOS_ZORDER;
1203 if(fuFlags & SWP_NOACTIVATE)
1204 setstate &= ~SWPOS_ACTIVATE;
1205 if(fuFlags & SWP_NOCOPYBITS)
1206 setstate |= 0; //TODO
1207 if(fuFlags & SWP_NOMOVE)
1208 setstate &= ~SWPOS_MOVE;
1209 if(fuFlags & SWP_NOSIZE)
1210 setstate &= ~SWPOS_SIZE;
1211 if(fuFlags & SWP_NOREDRAW)
1212 setstate |= SWPOS_NOREDRAW;
1213 if(fuFlags & SWP_NOZORDER)
1214 setstate &= ~SWPOS_ZORDER;
1215 if(fuFlags & SWP_SHOWWINDOW)
1216 setstate |= SWPOS_SHOW;
1217
1218 return OSLibWinSetWindowPos(OS2HwndFrame, hwndInsertAfter, x, y, cx, cy, setstate);
1219}
1220//******************************************************************************
1221//Also destroys all the child windows (destroy parent, destroy children)
1222//******************************************************************************
1223BOOL Win32Window::DestroyWindow()
1224{
1225 return OSLibWinDestroyWindow(OS2HwndFrame);
1226}
1227//******************************************************************************
1228//******************************************************************************
1229HWND Win32Window::GetParent()
1230{
1231 if(getParent()) {
1232 return getParent()->getWindowHandle();
1233 }
1234 else return 0;
1235}
1236//******************************************************************************
1237//******************************************************************************
1238HWND Win32Window::SetParent(HWND hwndNewParent)
1239{
1240 HWND oldhwnd;
1241 Win32Window *newparent;
1242
1243 if(getParent()) {
1244 oldhwnd = getParent()->getWindowHandle();
1245 }
1246 else oldhwnd = 0;
1247
1248 if(hwndNewParent == 0) {//desktop window = parent
1249 setParent(NULL);
1250 OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
1251 return oldhwnd;
1252 }
1253 newparent = GetWindowFromHandle(hwndNewParent);
1254 if(newparent)
1255 {
1256 setParent(newparent);
1257 OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
1258 return oldhwnd;
1259 }
1260 SetLastError(ERROR_INVALID_PARAMETER);
1261 return 0;
1262}
1263//******************************************************************************
1264//******************************************************************************
1265BOOL Win32Window::IsChild(HWND hwndParent)
1266{
1267 if(getParent()) {
1268 return getParent()->getWindowHandle() == hwndParent;
1269 }
1270 else return 0;
1271}
1272//******************************************************************************
1273//******************************************************************************
1274HWND Win32Window::GetTopWindow()
1275{
1276 return GetWindow(GW_CHILD);
1277}
1278//******************************************************************************
1279//Don't call WinUpdateWindow as that one also updates the child windows
1280//Also need to send WM_PAINT directly to the window procedure, which doesn't
1281//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
1282//******************************************************************************
1283BOOL Win32Window::UpdateWindow()
1284{
1285 RECT rect;
1286
1287 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
1288 {//update region not empty
1289 SendInternalMessageA((isIcon) ? WM_PAINTICON : WM_PAINT, 0, 0);
1290 }
1291 return TRUE;
1292}
1293//******************************************************************************
1294//******************************************************************************
1295BOOL Win32Window::IsIconic()
1296{
1297 return OSLibWinIsIconic(OS2Hwnd);
1298}
1299//******************************************************************************
1300//TODO: not complete nor correct (distinction between top-level, top-most & child windows)
1301//******************************************************************************
1302HWND Win32Window::GetWindow(UINT uCmd)
1303{
1304 Win32Window *win32wnd;
1305 ULONG magic;
1306 ULONG getcmd = 0;
1307 HWND hwndRelated;
1308
1309 dprintf(("GetWindow %x %d NOT COMPLETE", getWindowHandle(), uCmd));
1310 switch(uCmd)
1311 {
1312 case GW_CHILD:
1313 getcmd = QWOS_TOP;
1314 break;
1315 case GW_HWNDFIRST:
1316 if(getParent()) {
1317 getcmd = QWOS_TOP; //top of child windows
1318 }
1319 else getcmd = QWOS_TOP; //TODO
1320 break;
1321 case GW_HWNDLAST:
1322 if(getParent()) {
1323 getcmd = QWOS_BOTTOM; //bottom of child windows
1324 }
1325 else getcmd = QWOS_BOTTOM; //TODO
1326 break;
1327 case GW_HWNDNEXT:
1328 getcmd = QWOS_NEXT;
1329 break;
1330 case GW_HWNDPREV:
1331 getcmd = QWOS_PREV;
1332 break;
1333 case GW_OWNER:
1334 if(owner) {
1335 return owner->getWindowHandle();
1336 }
1337 else return 0;
1338 }
1339 hwndRelated = OSLibWinQueryWindow(OS2Hwnd, getcmd);
1340 if(hwndRelated)
1341 {
1342 win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32WNDPTR);
1343 magic = OSLibWinGetWindowULong(hwndRelated, OFFSET_WIN32PM_MAGIC);
1344 if(CheckMagicDword(magic) && win32wnd)
1345 {
1346 return win32wnd->getWindowHandle();
1347 }
1348 }
1349 return 0;
1350}
1351//******************************************************************************
1352//******************************************************************************
1353HWND Win32Window::SetActiveWindow()
1354{
1355 return OSLibWinSetActiveWindow(OS2Hwnd);
1356}
1357//******************************************************************************
1358//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
1359//******************************************************************************
1360BOOL Win32Window::EnableWindow(BOOL fEnable)
1361{
1362 return OSLibWinEnableWindow(OS2Hwnd, fEnable);
1363}
1364//******************************************************************************
1365//******************************************************************************
1366BOOL Win32Window::CloseWindow()
1367{
1368 return OSLibWinMinimizeWindow(OS2Hwnd);
1369}
1370//******************************************************************************
1371//******************************************************************************
1372BOOL Win32Window::BringWindowToTop()
1373{
1374 return SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
1375}
1376//******************************************************************************
1377//******************************************************************************
1378HWND Win32Window::GetActiveWindow()
1379{
1380 HWND hwndActive;
1381 Win32Window *win32wnd;
1382 ULONG magic;
1383
1384 hwndActive = OSLibWinQueryActiveWindow();
1385
1386 win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
1387 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
1388 if(CheckMagicDword(magic) && win32wnd)
1389 {
1390 return win32wnd->getWindowHandle();
1391 }
1392 return hwndActive;
1393}
1394//******************************************************************************
1395//******************************************************************************
1396BOOL Win32Window::IsWindow()
1397{
1398 return TRUE;
1399}
1400//******************************************************************************
1401//******************************************************************************
1402BOOL Win32Window::IsWindowEnabled()
1403{
1404 return OSLibWinIsWindowEnabled(OS2Hwnd);
1405}
1406//******************************************************************************
1407//******************************************************************************
1408BOOL Win32Window::IsWindowVisible()
1409{
1410 return OSLibWinIsWindowVisible(OS2Hwnd);
1411}
1412//******************************************************************************
1413//******************************************************************************
1414BOOL Win32Window::GetWindowRect(PRECT pRect)
1415{
1416// return OSLibWinIsWindowVisible(OS2Hwnd);
1417}
1418//******************************************************************************
1419//******************************************************************************
1420int Win32Window::GetWindowTextLengthA()
1421{
1422 return OSLibWinQueryWindowTextLength(OS2Hwnd);
1423}
1424//******************************************************************************
1425//******************************************************************************
1426int Win32Window::GetWindowTextA(LPSTR lpsz, int cch)
1427{
1428 return OSLibWinQueryWindowText(OS2Hwnd, cch, lpsz);
1429}
1430//******************************************************************************
1431//******************************************************************************
1432BOOL Win32Window::SetWindowTextA(LPCSTR lpsz)
1433{
1434 return OSLibWinSetWindowText(OS2Hwnd, (LPSTR)lpsz);
1435}
1436//******************************************************************************
1437//******************************************************************************
1438LONG Win32Window::SetWindowLongA(int index, ULONG value)
1439{
1440 LONG oldval;
1441
1442 switch(index) {
1443 case GWL_EXSTYLE:
1444 oldval = dwExStyle;
1445 dwExStyle = value;
1446 return oldval;
1447 case GWL_STYLE:
1448 oldval = dwStyle;
1449 dwStyle = value;
1450 return oldval;
1451 case GWL_WNDPROC:
1452 oldval = (LONG)getWindowProc();
1453 setWindowProc((WNDPROC)value);
1454 return oldval;
1455 case GWL_HINSTANCE:
1456 oldval = hInstance;
1457 hInstance = value;
1458 return oldval;
1459 case GWL_HWNDPARENT:
1460 return SetParent((HWND)value);
1461
1462 case GWL_ID:
1463 oldval = getWindowId();
1464 setWindowId(value);
1465 return oldval;
1466 case GWL_USERDATA:
1467 oldval = userData;
1468 userData = value;
1469 return oldval;
1470 default:
1471 if(index >= 0 && index/4 < nrUserWindowLong)
1472 {
1473 oldval = userWindowLong[index/4];
1474 userWindowLong[index/4] = value;
1475 return oldval;
1476 }
1477 SetLastError(ERROR_INVALID_PARAMETER);
1478 return 0;
1479 }
1480}
1481//******************************************************************************
1482//******************************************************************************
1483ULONG Win32Window::GetWindowLongA(int index)
1484{
1485 switch(index) {
1486 case GWL_EXSTYLE:
1487 return dwExStyle;
1488 case GWL_STYLE:
1489 return dwStyle;
1490 case GWL_WNDPROC:
1491 return (ULONG)getWindowProc();
1492 case GWL_HINSTANCE:
1493 return hInstance;
1494 case GWL_HWNDPARENT:
1495 if(getParent()) {
1496 return getParent()->getWindowHandle();
1497 }
1498 else return 0;
1499 case GWL_ID:
1500 return getWindowId();
1501 case GWL_USERDATA:
1502 return userData;
1503 default:
1504 if(index >= 0 && index/4 < nrUserWindowLong)
1505 {
1506 return userWindowLong[index/4];
1507 }
1508 SetLastError(ERROR_INVALID_PARAMETER);
1509 return 0;
1510 }
1511}
1512//******************************************************************************
1513//******************************************************************************
1514WORD Win32Window::SetWindowWord(int index, WORD value)
1515{
1516 WORD oldval;
1517
1518 if(index >= 0 && index/4 < nrUserWindowLong)
1519 {
1520 oldval = ((WORD *)userWindowLong)[index/2];
1521 ((WORD *)userWindowLong)[index/2] = value;
1522 return oldval;
1523 }
1524 SetLastError(ERROR_INVALID_PARAMETER);
1525 return 0;
1526}
1527//******************************************************************************
1528//******************************************************************************
1529WORD Win32Window::GetWindowWord(int index)
1530{
1531 if(index >= 0 && index/4 < nrUserWindowLong)
1532 {
1533 return ((WORD *)userWindowLong)[index/2];
1534 }
1535 SetLastError(ERROR_INVALID_PARAMETER);
1536 return 0;
1537}
1538//******************************************************************************
1539//******************************************************************************
1540Win32Window *Win32Window::GetWindowFromHandle(HWND hwnd)
1541{
1542 Win32Window *window;
1543
1544 if(HIWORD(hwnd) != 0x6800) {
1545 return NULL;
1546 }
1547
1548 if(HMHandleTranslateToOS2(LOWORD(hwnd), (PULONG)&window) == NO_ERROR) {
1549 return window;
1550 }
1551 else return NULL;
1552}
1553//******************************************************************************
1554//******************************************************************************
1555Win32Window *Win32Window::GetWindowFromOS2Handle(HWND hwnd)
1556{
1557 Win32Window *win32wnd;
1558 DWORD magic;
1559
1560 win32wnd = (Win32Window *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
1561 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
1562
1563 if(win32wnd && CheckMagicDword(magic)) {
1564 return win32wnd;
1565 }
1566 return 0;
1567}
1568//******************************************************************************
1569//******************************************************************************
1570GenericObject *Win32Window::windows = NULL;
Note: See TracBrowser for help on using the repository browser.