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

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

map rect, WM_ERASEBKGND and other fixes

File size: 111.0 KB
Line 
1/* $Id: win32wbase.cpp,v 1.97 1999-11-26 17:06:09 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 "wndmsg.h"
28#include "hooks.h"
29#include "oslibwin.h"
30#include "oslibutil.h"
31#include "oslibgdi.h"
32#include "oslibres.h"
33#include "oslibmenu.h"
34#include "oslibdos.h"
35#include "syscolor.h"
36#include "win32wndhandle.h"
37#include "dc.h"
38#include "pmframe.h"
39#include "win32wdesktop.h"
40#include "pmwindow.h"
41#include "controls.h"
42#include <wprocess.h>
43#include "winmouse.h"
44
45#define HAS_DLGFRAME(style,exStyle) \
46 (((exStyle) & WS_EX_DLGMODALFRAME) || \
47 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
48
49#define HAS_THICKFRAME(style,exStyle) \
50 (((style) & WS_THICKFRAME) && \
51 !((exStyle) & WS_EX_DLGMODALFRAME))
52
53#define HAS_THINFRAME(style) \
54 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
55
56#define HAS_BIGFRAME(style,exStyle) \
57 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
58 ((exStyle) & WS_EX_DLGMODALFRAME))
59
60#define HAS_ANYFRAME(style,exStyle) \
61 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
62 ((exStyle) & WS_EX_DLGMODALFRAME) || \
63 !((style) & (WS_CHILD | WS_POPUP)))
64
65#define HAS_3DFRAME(exStyle) \
66 ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
67
68#define HAS_BORDER(style, exStyle) \
69 ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
70
71#define IS_OVERLAPPED(style) \
72 !(style & (WS_CHILD | WS_POPUP))
73
74/* bits in the dwKeyData */
75#define KEYDATA_ALT 0x2000
76#define KEYDATA_PREVSTATE 0x4000
77
78void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
79
80static fDestroyAll = FALSE;
81
82//******************************************************************************
83//******************************************************************************
84Win32BaseWindow::Win32BaseWindow(DWORD objType) : GenericObject(&windows, objType)
85{
86 Init();
87}
88//******************************************************************************
89//******************************************************************************
90Win32BaseWindow::Win32BaseWindow(HWND os2Handle,VOID* win32WndProc) : GenericObject(&windows,OBJTYPE_WINDOW)
91{
92 Init();
93 OS2Hwnd = OS2HwndFrame = os2Handle;
94 dwStyle = WS_VISIBLE;
95 setWindowProc((WNDPROC)win32WndProc);
96 fIsSubclassedOS2Wnd = TRUE;
97 fFirstShow = FALSE;
98
99 SetLastError(0);
100
101 //CB: replace by a secure method
102
103 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
104 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
105 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
106 return;
107 }
108 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
109 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
110 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
111 return;
112 }
113
114 OSLibWinQueryWindowRect(OS2Hwnd,&rectWindow);
115 rectClient = rectWindow;
116 rectClient.bottom -= rectClient.top;
117 rectClient.top = 0;
118 rectClient.right -= rectClient.left;
119 rectClient.left = 0;
120
121 setOldWndProc(SubclassWithDefHandler(OS2Hwnd));
122}
123//******************************************************************************
124//******************************************************************************
125Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
126 : GenericObject(&windows, OBJTYPE_WINDOW), ChildWindow()
127{
128 Init();
129 this->isUnicode = isUnicode;
130 CreateWindowExA(lpCreateStructA, classAtom);
131}
132//******************************************************************************
133//******************************************************************************
134void Win32BaseWindow::Init()
135{
136 isUnicode = FALSE;
137 fIsSubclassedOS2Wnd = FALSE;
138 fFirstShow = TRUE;
139 fIsDialog = FALSE;
140 fIsModalDialogOwner = FALSE;
141 OS2HwndModalDialog = 0;
142 fInternalMsg = FALSE;
143 fNoSizeMsg = FALSE;
144 fIsDestroyed = FALSE;
145 fCreated = FALSE;
146
147 windowNameA = NULL;
148 windowNameW = NULL;
149 wndNameLength = 0;
150
151 userWindowLong = NULL;;
152 nrUserWindowLong = 0;
153
154 magic = WIN32PM_MAGIC;
155 OS2Hwnd = 0;
156 OS2HwndFrame = 0;
157 OS2HwndMenu = 0;
158 Win32Hwnd = 0;
159
160 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
161 {
162 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
163 DebugInt3();
164 }
165
166 posx = posy = 0;
167 width = height = 0;
168
169 dwExStyle = 0;
170 dwStyle = 0;
171 win32wndproc = 0;
172 hInstance = 0;
173 windowId = 0xFFFFFFFF; //default = -1
174 userData = 0;
175 contextHelpId = 0;
176
177 pOldFrameProc = NULL;
178 borderWidth = 0;
179 borderHeight = 0;
180
181 hwndLinkAfter = HWND_BOTTOM;
182 flags = 0;
183 isIcon = FALSE;
184 lastHitTestVal = 0;
185 owner = NULL;
186 windowClass = 0;
187
188 acceltableResource = NULL;
189 iconResource = NULL;
190
191 EraseBkgndFlag = TRUE;
192 PSEraseFlag = FALSE;
193 SupressEraseFlag = FALSE;
194
195 horzScrollInfo = NULL;
196 vertScrollInfo = NULL;
197 hwndHorzScroll = 0;
198 hwndVertScroll = 0;
199
200 ownDC = 0;
201}
202//******************************************************************************
203//todo get rid of resources (menu, accel, icon etc)
204//******************************************************************************
205Win32BaseWindow::~Win32BaseWindow()
206{
207 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
208 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
209
210 if(!fDestroyAll && getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
211 {
212 //if we're the last child that's being destroyed and our
213 //parent window was also destroyed, then we delete the parent object
214 if(getParent()->IsWindowDestroyed())
215 {
216 dprintf(("Last Child (%x) destroyed, get rid of our parent window (%x)", getWindowHandle(), getParent()->getWindowHandle()));
217 delete getParent();
218 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
219 }
220 }
221 else
222 if(fDestroyAll) {
223 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
224 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
225 }
226
227 if (isOwnDC())
228 releaseOwnDC (ownDC);
229
230 if(Win32Hwnd)
231 HwFreeWindowHandle(Win32Hwnd);
232
233 if(userWindowLong)
234 free(userWindowLong);
235 if(windowNameA) {
236 free(windowNameA);
237 windowNameA = NULL;
238 }
239 if(windowNameW) {
240 free(windowNameW);
241 windowNameW = NULL;
242 }
243 if(vertScrollInfo) {
244 free(vertScrollInfo);
245 vertScrollInfo = NULL;
246 }
247 if(horzScrollInfo) {
248 free(horzScrollInfo);
249 horzScrollInfo = NULL;
250 }
251}
252//******************************************************************************
253//******************************************************************************
254void Win32BaseWindow::DestroyAll()
255{
256 fDestroyAll = TRUE;
257 GenericObject::DestroyAll(windows);
258}
259//******************************************************************************
260//******************************************************************************
261BOOL Win32BaseWindow::isChild()
262{
263 return ((dwStyle & WS_CHILD) != 0);
264}
265//******************************************************************************
266//******************************************************************************
267BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
268{
269 char buffer[256];
270 POINT maxSize, maxPos, minTrack, maxTrack;
271
272#ifdef DEBUG
273 PrintWindowStyle(cs->style, cs->dwExStyle);
274#endif
275
276 sw = SW_SHOW;
277 SetLastError(0);
278
279 /* Find the parent window */
280 if (cs->hwndParent)
281 {
282 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
283 if(!window) {
284 dprintf(("Bad parent %04x\n", cs->hwndParent ));
285 SetLastError(ERROR_INVALID_PARAMETER);
286 return FALSE;
287 }
288 /* Make sure parent is valid */
289 if (!window->IsWindow() )
290 {
291 dprintf(("Bad parent %04x\n", cs->hwndParent ));
292 SetLastError(ERROR_INVALID_PARAMETER);
293 return FALSE;
294 }
295 }
296 else
297 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
298 dprintf(("No parent for child window\n" ));
299 SetLastError(ERROR_INVALID_PARAMETER);
300 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
301 }
302
303 /* Find the window class */
304 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
305 if (!windowClass)
306 {
307 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
308 dprintf(("Bad class '%s'\n", buffer ));
309 SetLastError(ERROR_INVALID_PARAMETER);
310 return 0;
311 }
312#ifdef DEBUG
313 if(HIWORD(cs->lpszClass))
314 {
315 char *astring;
316
317 if(isUnicode) astring = UnicodeToAsciiString((LPWSTR)cs->lpszClass);
318 else astring = (char *)cs->lpszClass;
319
320 dprintf(("Window class %s", astring));
321 if(isUnicode) FreeAsciiString(astring);
322 }
323 else dprintf(("Window class %x", cs->lpszClass));
324#endif
325
326 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
327 * with an atom as the class name, put some programs expect to have a *REAL* string in
328 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
329 */
330 if (!HIWORD(cs->lpszClass) ) {
331 if (isUnicode) {
332 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
333 }
334 else {
335 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
336 }
337 cs->lpszClass = buffer;
338 }
339
340 /* Fix the coordinates */
341 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
342 {
343// PDB *pdb = PROCESS_Current();
344
345 /* Never believe Microsoft's documentation... CreateWindowEx doc says
346 * that if an overlapped window is created with WS_VISIBLE style bit
347 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
348 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
349 * reveals that
350 *
351 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
352 * 2) it does not ignore the y parameter as the docs claim; instead, it
353 * uses it as second parameter to ShowWindow() unless y is either
354 * CW_USEDEFAULT or CW_USEDEFAULT16.
355 *
356 * The fact that we didn't do 2) caused bogus windows pop up when wine
357 * was running apps that were using this obscure feature. Example -
358 * calc.exe that comes with Win98 (only Win98, it's different from
359 * the one that comes with Win95 and NT)
360 */
361 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) sw = cs->y;
362
363 /* We have saved cs->y, now we can trash it */
364#if 0
365 if ( !(cs->style & (WS_CHILD | WS_POPUP))
366 && (pdb->env_db->startup_info->dwFlags & STARTF_USEPOSITION) )
367 {
368 cs->x = pdb->env_db->startup_info->dwX;
369 cs->y = pdb->env_db->startup_info->dwY;
370 }
371#endif
372 cs->x = 0;
373 cs->y = 0;
374// }
375 }
376 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
377 {
378#if 0
379 PDB *pdb = PROCESS_Current();
380 if ( !(cs->style & (WS_CHILD | WS_POPUP))
381 && (pdb->env_db->startup_info->dwFlags & STARTF_USESIZE) )
382 {
383 cs->cx = pdb->env_db->startup_info->dwXSize;
384 cs->cy = pdb->env_db->startup_info->dwYSize;
385 }
386 else
387 {
388#endif
389 cs->cx = 600; /* FIXME */
390 cs->cy = 400;
391// }
392 }
393
394 if (cs->x < 0) cs->x = 0;
395 if (cs->y < 0) cs->y = 0;
396
397 //Allocate window words
398 nrUserWindowLong = windowClass->getExtraWndWords();
399 if(nrUserWindowLong) {
400 userWindowLong = (ULONG *)_smalloc(nrUserWindowLong);
401 memset(userWindowLong, 0, nrUserWindowLong);
402 }
403
404 if ((cs->style & WS_CHILD) && cs->hwndParent)
405 {
406 SetParent(cs->hwndParent);
407 owner = GetWindowFromHandle(cs->hwndParent);
408 if(owner == NULL)
409 {
410 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
411 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
412 return FALSE;
413 }
414 }
415 else
416 {
417 if (!cs->hwndParent || cs->hwndParent == windowDesktop->getWindowHandle()) {
418 owner = NULL;
419 }
420 else
421 {
422 owner = GetWindowFromHandle(cs->hwndParent)->GetTopParent();
423 if(owner == NULL)
424 {
425 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
426 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
427 return FALSE;
428 }
429 }
430 }
431
432 setWindowProc(windowClass->getWindowProc());
433 hInstance = cs->hInstance;
434 dwStyle = cs->style & ~WS_VISIBLE;
435 dwExStyle = cs->dwExStyle;
436
437 hwndLinkAfter = HWND_TOP;
438 if(WIDGETS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX))
439 {
440 hwndLinkAfter = HWND_BOTTOM;
441 dwStyle |= WS_CLIPSIBLINGS;
442 }
443 else
444 if(WIDGETS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) {
445 dwStyle |= WS_CLIPSIBLINGS;
446 }
447
448 /* Increment class window counter */
449 windowClass->IncreaseWindowCount();
450
451 /* Correct the window style */
452 if (!(cs->style & WS_CHILD))
453 {
454 dwStyle |= WS_CLIPSIBLINGS;
455 if (!(cs->style & WS_POPUP))
456 {
457 dwStyle |= WS_CAPTION;
458 flags |= WIN_NEED_SIZE;
459 }
460 }
461 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
462
463 //TODO?
464#if 0
465 /* Get class or window DC if needed */
466 if (classPtr->style & CS_OWNDC) dce = DCE_AllocDCE(hwnd,DCE_WINDOW_DC);
467 else if (classPtr->style & CS_CLASSDC) wndPtr->dce = classPtr->dce;
468 else wndPtr->dce = NULL;
469#endif
470
471 if (cs->style & WS_HSCROLL)
472 {
473 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
474 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
475 horzScrollInfo->MaxVal = 100;
476 horzScrollInfo->flags = ESB_ENABLE_BOTH;
477 }
478
479 if (cs->style & WS_VSCROLL)
480 {
481 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
482 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
483 vertScrollInfo->MaxVal = 100;
484 vertScrollInfo->flags = ESB_ENABLE_BOTH;
485 }
486
487 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
488 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
489 {
490 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
491 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
492 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
493 if (cs->cx < minTrack.x ) cs->cx = minTrack.x;
494 if (cs->cy < minTrack.y ) cs->cy = minTrack.y;
495 }
496
497 if(cs->style & WS_CHILD)
498 {
499 if(cs->cx < 0) cs->cx = 0;
500 if(cs->cy < 0) cs->cy = 0;
501 }
502 else
503 {
504 if (cs->cx <= 0) cs->cx = 1;
505 if (cs->cy <= 0) cs->cy = 1;
506 }
507
508 DWORD dwOSWinStyle, dwOSFrameStyle;
509
510 OSLibWinConvertStyle(dwStyle, &dwExStyle, &dwOSWinStyle, &dwOSFrameStyle, &borderWidth, &borderHeight);
511
512 rectWindow.left = cs->x;
513 rectWindow.top = cs->y;
514 rectWindow.right = cs->x + cs->cx;
515 rectWindow.bottom = cs->y + cs->cy;
516 rectClient = rectWindow;
517
518 if(HIWORD(cs->lpszName))
519 {
520 if (!isUnicode)
521 {
522 wndNameLength = strlen(cs->lpszName);
523 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
524 strcpy(windowNameA,cs->lpszName);
525 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
526 lstrcpyAtoW(windowNameW,windowNameA);
527 } else
528 {
529 wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
530 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
531 lstrcpyWtoA(windowNameA,(LPWSTR)cs->lpszName);
532 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
533 lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
534 }
535 }
536
537 //copy pointer of CREATESTRUCT for usage in MsgCreate method
538 tmpcs = cs;
539
540 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
541 THDB *thdb = GetThreadTHDB();
542
543 if(thdb == NULL) {
544 dprintf(("Window creation failed - thdb == NULL")); //this is VERY bad
545 ExitProcess(666);
546 return FALSE;
547 }
548
549 thdb->newWindow = (ULONG)this;
550
551 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
552 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
553 (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
554 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
555 &OS2HwndFrame, 0);
556
557 if(OS2Hwnd == 0) {
558 dprintf(("Window creation failed!!"));
559 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
560 return FALSE;
561 }
562
563 SetLastError(0);
564 return TRUE;
565}
566//******************************************************************************
567//******************************************************************************
568BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
569{
570 POINT maxPos;
571 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
572 RECT rectWndTmp, rectClientTmp;
573
574 OS2Hwnd = hwndClient;
575 OS2HwndFrame = hwndFrame;
576
577 //make backup copy of rectangles (some calls below result in WM_WINDOWPOSCHANGED with weird values since we haven't
578 //set our window size just yet)
579 rectWndTmp = rectWindow;
580 rectClientTmp = rectClient;
581
582 fNoSizeMsg = TRUE;
583
584 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
585 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
586 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
587 return FALSE;
588 }
589 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
590 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
591 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
592 return FALSE;
593 }
594#if 0
595 if(OS2Hwnd != OS2HwndFrame) {
596 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32WNDPTR, (ULONG)this) == FALSE) {
597 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2HwndFrame));
598 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
599 return FALSE;
600 }
601 if(OSLibWinSetWindowULong(OS2HwndFrame, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
602 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2HwndFrame));
603 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
604 return FALSE;
605 }
606 }
607#endif
608
609 OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
610
611 FrameGetScrollBarHandles(this,dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
612 subclassScrollBars(dwStyle & WS_HSCROLL,dwStyle & WS_VSCROLL);
613
614 fakeWinBase.hwndThis = OS2Hwnd;
615 fakeWinBase.pWindowClass = windowClass;
616
617 //Set icon from class
618 if(windowClass->getIcon())
619 SetIcon(windowClass->getIcon());
620
621 /* Set the window menu */
622 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
623 {
624 if (cs->hMenu) {
625 SetMenu(cs->hMenu);
626 }
627 else {
628 if (windowClass->getMenuNameA()) {
629 cs->hMenu = LoadMenuA(cs->hInstance, windowClass->getMenuNameA());
630 if (cs->hMenu) SetMenu(cs->hMenu );
631 }
632 }
633 }
634 else
635 {
636 setWindowId((DWORD)cs->hMenu);
637 }
638
639 // Subclass frame
640 pOldFrameProc = FrameSubclassFrameWindow(this);
641 if (isChild()) FrameSetBorderSize(this,TRUE);
642
643 //restore rectangles (some calls below result in WM_WINDOWPOSCHANGED with weird values since we haven't
644 //set our window size just yet)
645 rectWindow = rectWndTmp;
646 rectClient = rectClientTmp;
647
648 /* Send the WM_CREATE message
649 * Perhaps we shouldn't allow width/height changes as well.
650 * See p327 in "Internals".
651 */
652 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
653
654 if(getParent()) {
655 SetWindowPos(hwndLinkAfter, rectClient.left, rectClient.top,
656 rectClient.right-rectClient.left,
657 rectClient.bottom-rectClient.top,
658 SWP_NOACTIVATE | SWP_NOREDRAW);
659 }
660 else {
661 SetWindowPos(hwndLinkAfter, rectClient.left, rectClient.top,
662 rectClient.right-rectClient.left,
663 rectClient.bottom-rectClient.top,
664 SWP_NOACTIVATE | SWP_NOREDRAW);
665 }
666 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
667 fNoSizeMsg = FALSE;
668
669 if(SendMessageA(WM_NCCREATE, 0, (LPARAM)cs) )
670 {
671 fCreated = TRUE;
672
673 SendNCCalcSize(FALSE, &rectWindow, NULL, NULL, 0, &rectClient );
674
675// OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
676 if( (SendMessageA(WM_CREATE, 0, (LPARAM)cs )) != -1 )
677 {
678 if(!(flags & WIN_NEED_SIZE)) {
679 SendMessageA(WM_SIZE, SIZE_RESTORED,
680 MAKELONG(rectClient.right-rectClient.left,
681 rectClient.bottom-rectClient.top));
682 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
683 }
684
685 if (cs->style & WS_VISIBLE) ShowWindow( sw );
686
687#if 0
688 /* Call WH_SHELL hook */
689
690 if (!(dwStyle & WS_CHILD) && !owner)
691 HOOK_CallHooks16( WH_SHELL, HSHELL_WINDOWCREATED, hwnd, 0 );
692#endif
693 SetLastError(0);
694 return TRUE;
695 }
696 }
697 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
698 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
699 return FALSE;
700}
701//******************************************************************************
702//******************************************************************************
703ULONG Win32BaseWindow::MsgQuit()
704{
705 return SendInternalMessageA(WM_QUIT, 0, 0);
706}
707//******************************************************************************
708//******************************************************************************
709ULONG Win32BaseWindow::MsgClose()
710{
711 if(SendInternalMessageA(WM_CLOSE, 0, 0) == 0) {
712 return 0; //app handles this message
713 }
714 return 1;
715}
716//******************************************************************************
717//******************************************************************************
718ULONG Win32BaseWindow::MsgDestroy()
719{
720 ULONG rc;
721 Win32BaseWindow *child;
722
723 if (isSubclassedOS2Wnd) OSLibWinSubclassWindow(OS2Hwnd,pOldWndProc);
724
725 fIsDestroyed = TRUE;
726 //According to the SDK, WM_PARENTNOTIFY messages are sent to the parent (this window)
727 //before any window destruction has begun
728 child = (Win32BaseWindow *)getFirstChild();
729 while(child) {
730 child->NotifyParent(WM_DESTROY, 0, 0);
731
732 child = (Win32BaseWindow *)child->getNextChild();
733 }
734 SendInternalMessageA(WM_DESTROY, 0, 0);
735
736 if (hwndHorzScroll && OSLibWinQueryWindow(hwndHorzScroll,QWOS_PARENT) == OSLibWinQueryObjectWindow()) OSLibWinDestroyWindow(hwndHorzScroll);
737 if (hwndVertScroll && OSLibWinQueryWindow(hwndVertScroll,QWOS_PARENT) == OSLibWinQueryObjectWindow()) OSLibWinDestroyWindow(hwndVertScroll);
738
739 if(getFirstChild() == NULL) {
740 delete this;
741 }
742 return 1;
743}
744//******************************************************************************
745//******************************************************************************
746ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
747{
748 if(fEnable) {
749 dwStyle &= ~WS_DISABLED;
750 }
751 else dwStyle |= WS_DISABLED;
752
753 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
754}
755//******************************************************************************
756//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
757//******************************************************************************
758ULONG Win32BaseWindow::MsgShow(BOOL fShow)
759{
760 if(fNoSizeMsg) {
761 return 1;
762 }
763
764 if(fShow) {
765 setStyle(getStyle() | WS_VISIBLE);
766 }
767 else setStyle(getStyle() & ~WS_VISIBLE);
768
769 return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
770}
771//******************************************************************************
772//******************************************************************************
773ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
774{
775 if(fNoSizeMsg)
776 return 1;
777
778 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
779}
780//******************************************************************************
781//******************************************************************************
782ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
783{
784 if(fNoSizeMsg)
785 return 1;
786
787 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
788}
789//******************************************************************************
790//******************************************************************************
791ULONG Win32BaseWindow::MsgMove(ULONG x, ULONG y)
792{
793 dprintf(("MsgMove to (%d,%d)", x, y));
794 if(fNoSizeMsg)
795 return 1;
796
797 return SendInternalMessageA(WM_MOVE, 0, MAKELONG((USHORT)x, (USHORT)y));
798}
799//******************************************************************************
800//******************************************************************************
801ULONG Win32BaseWindow::MsgTimer(ULONG TimerID)
802{
803 // TODO: call TIMERPROC if not NULL
804 return SendInternalMessageA(WM_TIMER, TimerID, 0);
805}
806//******************************************************************************
807//******************************************************************************
808ULONG Win32BaseWindow::MsgSysTimer(ULONG TimerID)
809{
810 // TODO: call TIMERPROC if not NULL
811 return SendInternalMessageA(WM_SYSTIMER, TimerID, 0);
812}
813//******************************************************************************
814//******************************************************************************
815ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
816{
817 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
818 //window scrollbars send these messages
819 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
820}
821//******************************************************************************
822//******************************************************************************
823ULONG Win32BaseWindow::MsgCommand(ULONG cmd, ULONG Id, HWND hwnd)
824{
825 switch(cmd) {
826 case CMD_MENU:
827 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
828 case CMD_CONTROL:
829 return 0; //todo
830 case CMD_ACCELERATOR:
831 // this fit not really windows behavior.
832 // maybe TranslateAccelerator() is better
833 dprintf(("accelerator command"));
834 return SendInternalMessageA(WM_COMMAND, MAKELONG(Id, 0), 0);
835 }
836 return 0;
837}
838//******************************************************************************
839//******************************************************************************
840ULONG Win32BaseWindow::MsgHitTest(ULONG x, ULONG y)
841{
842 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)x, (USHORT)y));
843 dprintf(("MsgHitTest returned %x", lastHitTestVal));
844 return 1; //TODO: May need to change this
845}
846//******************************************************************************
847//TODO: Send WM_NCCALCSIZE message here and correct size if necessary
848//******************************************************************************
849ULONG Win32BaseWindow::MsgSize(ULONG width, ULONG height, BOOL fMinimize, BOOL fMaximize)
850{
851 WORD fwSizeType = 0;
852
853 dwStyle &= ~(WS_MINIMIZE|WS_MAXIMIZE);
854 if(fMinimize) {
855 fwSizeType = SIZE_MINIMIZED;
856 dwStyle |= WS_MINIMIZE;
857 }
858 else
859 if(fMaximize) {
860 fwSizeType = SIZE_MAXIMIZED;
861 dwStyle |= WS_MAXIMIZE;
862 }
863 else fwSizeType = SIZE_RESTORED;
864
865 return SendInternalMessageA(WM_SIZE, fwSizeType, MAKELONG((USHORT)width, (USHORT)height));
866}
867//******************************************************************************
868//******************************************************************************
869ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
870{
871 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
872
873 //According to SDK docs, if app returns FALSE & window is being deactivated,
874 //default processing is cancelled
875 //TODO: According to Wine we should proceed anyway if window is sysmodal
876 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
877 {
878 return 0;
879 }
880 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
881
882 curprocid = GetCurrentProcessId();
883 if(hwnd) {
884 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
885 }
886
887 if(curprocid != procidhwnd && fActivate) {
888 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
889 }
890 return rc;
891}
892//******************************************************************************
893//******************************************************************************
894ULONG Win32BaseWindow::MsgSysCommand(ULONG win32sc, ULONG x, ULONG y)
895{
896 return SendInternalMessageA(WM_SYSCOMMAND, win32sc, MAKELONG((USHORT)x, (USHORT)y));
897}
898//******************************************************************************
899//TODO: Is this correct and complete?
900//Add print screen, break & numlock
901//******************************************************************************
902void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
903{
904 switch(virtualkey) {
905 case VK_DOWN:
906 case VK_UP:
907 case VK_PRIOR:
908 case VK_NEXT:
909 case VK_END:
910 case VK_DIVIDE:
911 case VK_DELETE:
912 case VK_EXECUTE: //Numeric enter key?
913 case VK_HOME:
914 case VK_INSERT:
915 case VK_RCONTROL:
916 case VK_RMENU: //is this the right alt???
917 *lParam = *lParam | (1<<24);
918 }
919}
920//******************************************************************************
921//TODO: virtual key & (possibly) scancode translation, extended keyboard bit & Unicode
922//******************************************************************************
923ULONG Win32BaseWindow::MsgChar(ULONG cmd, ULONG repeatcnt, ULONG scancode, ULONG vkey, ULONG keyflags)
924{
925 ULONG lParam = 0;
926
927 lParam = repeatcnt;
928 lParam |= (scancode << 16);
929 setExtendedKey(vkey, &lParam);
930
931 if(keyflags & KEY_ALTDOWN)
932 lParam |= (1<<29);
933 if(keyflags & KEY_PREVDOWN)
934 lParam |= (1<<30);
935 if(keyflags & KEY_UP)
936 lParam |= (1<<31);
937 if(keyflags & KEY_DEADKEY) {
938 dprintf(("WM_DEADCHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
939 return SendInternalMessageA(WM_DEADCHAR, cmd, lParam);
940 }
941 else {
942 dprintf(("WM_CHAR: %x %x %08x", OS2Hwnd, cmd, lParam));
943 return SendInternalMessageA(WM_CHAR, cmd, lParam);
944 }
945}
946//******************************************************************************
947//******************************************************************************
948ULONG Win32BaseWindow::MsgKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
949{
950 ULONG lParam=0;
951
952 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
953 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
954 // bit 24, 1=extended key
955 // bit 25-28, reserved
956 lParam |= 0 << 29; // bit 29, key is released, always 0 for WM_KEYUP ?? <- conflict according to the MS docs
957 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
958 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
959
960 dprintf(("WM_KEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
961
962 setExtendedKey(virtualKey, &lParam);
963 return SendInternalMessageA (WM_KEYUP, virtualKey, lParam);
964}
965//******************************************************************************
966//******************************************************************************
967ULONG Win32BaseWindow::MsgKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
968{
969 ULONG lParam=0;
970
971 lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
972 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
973 // bit 24, 1=extended key
974 // bit 25-28, reserved
975 // bit 29, key is pressed, always 0 for WM_KEYDOWN ?? <- conflict according to the MS docs
976 if (keyWasPressed)
977 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
978 // bit 31, transition state, always 0 for WM_KEYDOWN
979
980 setExtendedKey(virtualKey, &lParam);
981
982 dprintf(("WM_KEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
983
984 return SendInternalMessageA (WM_KEYDOWN, virtualKey, lParam);
985}
986//******************************************************************************
987//******************************************************************************
988ULONG Win32BaseWindow::MsgSysKeyUp (ULONG repeatCount, ULONG scancode, ULONG virtualKey)
989{
990 ULONG lParam=0;
991
992 lParam = repeatCount & 0x0FFFF; // bit 0-15,repeatcount
993 lParam |= (scancode & 0x0FF) << 16; // bit 16-23, scancode
994 // bit 24, 1=extended key
995 // bit 25-28, reserved
996 lParam |= 0 << 29; // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
997 lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
998 lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
999
1000 setExtendedKey(virtualKey, &lParam);
1001 dprintf(("WM_SYSKEYUP: vkey:(%x) param:(%x)", virtualKey, lParam));
1002
1003 return SendInternalMessageA (WM_SYSKEYUP, virtualKey, lParam);
1004}
1005//******************************************************************************
1006//******************************************************************************
1007ULONG Win32BaseWindow::MsgSysKeyDown (ULONG repeatCount, ULONG scancode, ULONG virtualKey, BOOL keyWasPressed)
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 // bit 29, key is released, always 1 for WM_SYSKEYUP ?? <- conflict according to the MS docs
1016 if (keyWasPressed)
1017 lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
1018 // bit 31, transition state, always 0 for WM_KEYDOWN
1019
1020 setExtendedKey(virtualKey, &lParam);
1021 dprintf(("WM_SYSKEYDOWN: vkey:(%x) param:(%x)", virtualKey, lParam));
1022
1023 return SendInternalMessageA (WM_SYSKEYDOWN, virtualKey, lParam);
1024}
1025//******************************************************************************
1026//******************************************************************************
1027ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1028{
1029 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1030}
1031//******************************************************************************
1032//******************************************************************************
1033ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1034{
1035 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1036}
1037//******************************************************************************
1038//******************************************************************************
1039ULONG Win32BaseWindow::MsgButton(ULONG msg, ULONG ncx, ULONG ncy, ULONG clx, ULONG cly)
1040{
1041 ULONG win32msg;
1042 ULONG win32ncmsg;
1043 BOOL fClick = FALSE;
1044
1045 if(ISMOUSE_CAPTURED()) {
1046 if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_BUTTON, ncx, ncy, msg))
1047 return 0;
1048 }
1049
1050 dprintf(("MsgButton to (%d,%d)", ncx, ncy));
1051 switch(msg) {
1052 case BUTTON_LEFTDOWN:
1053 win32msg = WM_LBUTTONDOWN;
1054 win32ncmsg = WM_NCLBUTTONDOWN;
1055 fClick = TRUE;
1056 break;
1057 case BUTTON_LEFTUP:
1058 win32msg = WM_LBUTTONUP;
1059 win32ncmsg = WM_NCLBUTTONUP;
1060 break;
1061 case BUTTON_LEFTDBLCLICK:
1062 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1063 {
1064 win32msg = WM_LBUTTONDBLCLK;
1065 win32ncmsg = WM_NCLBUTTONDBLCLK;
1066 } else
1067 {
1068 MsgButton(BUTTON_LEFTDOWN,ncx,ncy,clx,cly);
1069 return MsgButton(BUTTON_LEFTUP,ncx,ncy,clx,cly);
1070 }
1071 break;
1072 case BUTTON_RIGHTUP:
1073 win32msg = WM_RBUTTONUP;
1074 win32ncmsg = WM_NCRBUTTONUP;
1075 break;
1076 case BUTTON_RIGHTDOWN:
1077 win32msg = WM_RBUTTONDOWN;
1078 win32ncmsg = WM_NCRBUTTONDOWN;
1079 fClick = TRUE;
1080 break;
1081 case BUTTON_RIGHTDBLCLICK:
1082 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1083 {
1084 win32msg = WM_RBUTTONDBLCLK;
1085 win32ncmsg = WM_NCRBUTTONDBLCLK;
1086 } else
1087 {
1088 MsgButton(BUTTON_RIGHTDOWN,ncx,ncy,clx,cly);
1089 return MsgButton(BUTTON_RIGHTUP,ncx,ncy,clx,cly);
1090 }
1091 break;
1092 case BUTTON_MIDDLEUP:
1093 win32msg = WM_MBUTTONUP;
1094 win32ncmsg = WM_NCMBUTTONUP;
1095 break;
1096 case BUTTON_MIDDLEDOWN:
1097 win32msg = WM_MBUTTONDOWN;
1098 win32ncmsg = WM_NCMBUTTONDOWN;
1099 fClick = TRUE;
1100 break;
1101 case BUTTON_MIDDLEDBLCLICK:
1102 if (windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS)
1103 {
1104 win32msg = WM_MBUTTONDBLCLK;
1105 win32ncmsg = WM_NCMBUTTONDBLCLK;
1106 } else
1107 {
1108 MsgButton(BUTTON_MIDDLEDOWN,ncx,ncy,clx,cly);
1109 return MsgButton(BUTTON_MIDDLEUP,ncx,ncy,clx,cly);
1110 }
1111 break;
1112 default:
1113 dprintf(("Win32BaseWindow::Button: invalid msg!!!!"));
1114 return 1;
1115 }
1116
1117 if(fClick)
1118 {
1119 HWND hwndTop;
1120
1121 /* Activate the window if needed */
1122 if(isSubclassedOS2Wnd()) {
1123 Win32BaseWindow *parentwnd = GetWindowFromOS2FrameHandle(OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT));
1124 if(parentwnd) {
1125 hwndTop = (parentwnd->GetTopParent()) ? parentwnd->GetTopParent()->getWindowHandle() : 0;
1126 }
1127 else hwndTop = 0;
1128 }
1129 else hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
1130
1131 if (hwndTop && getWindowHandle() != GetActiveWindow())
1132 {
1133 LONG ret = SendMessageA(WM_MOUSEACTIVATE, hwndTop,
1134 MAKELONG( HTCLIENT, win32msg ) );
1135
1136#if 0
1137 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1138 eatMsg = TRUE;
1139#endif
1140 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
1141 && hwndTop != GetForegroundWindow() )
1142 {
1143 ::SetActiveWindow(hwndTop);
1144 }
1145 }
1146 }
1147
1148 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, win32ncmsg));
1149
1150 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
1151 if(lastHitTestVal != HTCLIENT) {
1152 return SendInternalMessageA(win32ncmsg, lastHitTestVal, MAKELONG(ncx, ncy)); //TODO:
1153 }
1154 return SendInternalMessageA(win32msg, 0, MAKELONG(clx, cly));
1155}
1156//******************************************************************************
1157//******************************************************************************
1158ULONG Win32BaseWindow::MsgMouseMove(ULONG keystate, ULONG x, ULONG y)
1159{
1160 ULONG winstate = 0;
1161 ULONG setcursormsg = WM_MOUSEMOVE;
1162
1163 if(ISMOUSE_CAPTURED()) {
1164 POINT point = {x,y};
1165
1166 MapWindowPoints(getWindowHandle(), HWND_DESKTOP, &point, 1);
1167 if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_MOVE, point.x, point.y, keystate))
1168 return 0;
1169 }
1170
1171 if(keystate & WMMOVE_LBUTTON)
1172 winstate |= MK_LBUTTON;
1173 if(keystate & WMMOVE_RBUTTON)
1174 winstate |= MK_RBUTTON;
1175 if(keystate & WMMOVE_MBUTTON)
1176 winstate |= MK_MBUTTON;
1177 if(keystate & WMMOVE_SHIFT)
1178 winstate |= MK_SHIFT;
1179 if(keystate & WMMOVE_CTRL)
1180 winstate |= MK_CONTROL;
1181
1182 if(lastHitTestVal != HTCLIENT) {
1183 setcursormsg = WM_NCMOUSEMOVE;
1184 }
1185 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1186 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, setcursormsg));
1187
1188 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
1189 if(lastHitTestVal != HTCLIENT) {
1190 SendInternalMessageA(WM_NCMOUSEMOVE, lastHitTestVal, MAKELONG(x, y));
1191 }
1192 return SendInternalMessageA(WM_MOUSEMOVE, winstate, MAKELONG(x, y));
1193}
1194//******************************************************************************
1195//******************************************************************************
1196ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1197{
1198 if (select && isIcon)
1199 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1200 else
1201 return SendInternalMessageA(WM_PAINT, 0, 0);
1202}
1203//******************************************************************************
1204//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1205// (or are we simply erasing too much here)
1206//******************************************************************************
1207ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1208{
1209 ULONG rc;
1210 HDC hdcErase = hdc;
1211
1212 if (hdcErase == 0)
1213 hdcErase = O32_GetDC(OS2Hwnd);
1214
1215 if(isIcon)
1216 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1217 else
1218 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1219 if (hdc == 0)
1220 O32_ReleaseDC(OS2Hwnd, hdcErase);
1221 return (rc);
1222}
1223//******************************************************************************
1224//******************************************************************************
1225ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1226{
1227 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1228}
1229//******************************************************************************
1230//TODO: in- or excluding terminating 0?
1231//******************************************************************************
1232ULONG Win32BaseWindow::MsgGetTextLength()
1233{
1234 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1235}
1236//******************************************************************************
1237//******************************************************************************
1238char *Win32BaseWindow::MsgGetText()
1239{
1240 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1241 return windowNameA;
1242}
1243//******************************************************************************
1244//******************************************************************************
1245ULONG Win32BaseWindow::MsgContextMenu(ULONG x,ULONG y)
1246{
1247 return SendInternalMessageA(WM_CONTEXTMENU,Win32Hwnd,MAKELPARAM(x,y));
1248}
1249//******************************************************************************
1250//******************************************************************************
1251BOOL Win32BaseWindow::isMDIClient()
1252{
1253 return FALSE;
1254}
1255//******************************************************************************
1256//******************************************************************************
1257BOOL Win32BaseWindow::isMDIChild()
1258{
1259 return FALSE;
1260}
1261//******************************************************************************
1262//TODO: Not complete
1263//******************************************************************************
1264BOOL Win32BaseWindow::isFrameWindow()
1265{
1266// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1267 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1268 return TRUE;
1269
1270 return FALSE;
1271}
1272//******************************************************************************
1273//******************************************************************************
1274SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1275{
1276 switch(nBar)
1277 {
1278 case SB_HORZ:
1279 return horzScrollInfo;
1280
1281 case SB_VERT:
1282 return vertScrollInfo;
1283 }
1284
1285 return NULL;
1286}
1287//******************************************************************************
1288//******************************************************************************
1289VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1290{
1291 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1292}
1293//******************************************************************************
1294//******************************************************************************
1295BOOL Win32BaseWindow::showScrollBars(BOOL changeHorz,BOOL changeVert,BOOL fShow)
1296{
1297 BOOL rc = TRUE;
1298 DWORD flags = 0;
1299
1300 if (fShow)
1301 {
1302 BOOL createHorz = FALSE,createVert = FALSE;
1303 BOOL showHorz = FALSE,showVert = FALSE;
1304
1305 if (changeHorz)
1306 {
1307 if (!hwndHorzScroll)
1308 createHorz = TRUE;
1309 else
1310 showHorz = TRUE;
1311 }
1312
1313 if (changeVert)
1314 {
1315 if (!hwndVertScroll)
1316 createVert = TRUE;
1317 else
1318 showVert = TRUE;
1319 }
1320
1321 if (createHorz || createVert)
1322 {
1323 if (createHorz && !horzScrollInfo)
1324 {
1325 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1326 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1327 horzScrollInfo->MaxVal = 100;
1328 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1329 }
1330
1331 if (createVert && !vertScrollInfo)
1332 {
1333 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1334 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1335 vertScrollInfo->MaxVal = 100;
1336 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1337 }
1338
1339 rc = FrameCreateScrollBars(this,createHorz,createVert,FALSE,&flags);
1340
1341 if (!rc) return FALSE;
1342 if (createHorz) dwStyle |= WS_HSCROLL;
1343 if (createVert) dwStyle |= WS_VSCROLL;
1344 }
1345
1346 if (showVert || showHorz)
1347 {
1348 DWORD newFlags;
1349 rc = FrameShowScrollBars(this,showHorz,showVert,fShow,FALSE,&newFlags);
1350 flags |= newFlags;
1351 if (rc)
1352 {
1353 if (showHorz) dwStyle |= WS_HSCROLL;
1354 if (showVert) dwStyle |= WS_VSCROLL;
1355 }
1356 }
1357
1358 if (flags) FrameUpdateFrame(this,flags);
1359 } else
1360 {
1361 rc = FrameShowScrollBars(this,changeHorz && hwndHorzScroll,changeVert && hwndVertScroll,fShow,TRUE);
1362
1363 if (rc)
1364 {
1365 if (changeHorz) dwStyle &= ~WS_HSCROLL;
1366 if (changeVert) dwStyle &= ~WS_VSCROLL;
1367 }
1368 }
1369
1370 return rc;
1371}
1372/***********************************************************************
1373 * NC_HandleSysCommand
1374 *
1375 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1376 *
1377 * TODO: Not done (see #if 0)
1378 */
1379LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1380{
1381 UINT uCommand = wParam & 0xFFF0;
1382
1383 if (getStyle() & WS_CHILD && uCommand != SC_KEYMENU )
1384 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1385
1386 switch (uCommand)
1387 {
1388#if 0
1389 case SC_SIZE:
1390 case SC_MOVE:
1391 NC_DoSizeMove( hwnd, wParam );
1392 break;
1393#endif
1394
1395 case SC_MINIMIZE:
1396 ShowWindow(SW_MINIMIZE);
1397 break;
1398
1399 case SC_MAXIMIZE:
1400 ShowWindow(SW_MAXIMIZE);
1401 break;
1402
1403 case SC_RESTORE:
1404 ShowWindow(SW_RESTORE);
1405 break;
1406
1407 case SC_CLOSE:
1408 return SendMessageA(WM_CLOSE, 0, 0);
1409
1410#if 0
1411 case SC_VSCROLL:
1412 case SC_HSCROLL:
1413 NC_TrackScrollBar( hwnd, wParam, pt32 );
1414 break;
1415
1416 case SC_MOUSEMENU:
1417 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1418 break;
1419
1420 case SC_KEYMENU:
1421 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1422 break;
1423
1424 case SC_TASKLIST:
1425 WinExec( "taskman.exe", SW_SHOWNORMAL );
1426 break;
1427
1428 case SC_SCREENSAVE:
1429 if (wParam == SC_ABOUTWINE)
1430 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1431 else
1432 if (wParam == SC_PUTMARK)
1433 dprintf(("Mark requested by user\n"));
1434 break;
1435
1436 case SC_HOTKEY:
1437 case SC_ARRANGE:
1438 case SC_NEXTWINDOW:
1439 case SC_PREVWINDOW:
1440 break;
1441#endif
1442 }
1443 return 0;
1444}
1445//******************************************************************************
1446//******************************************************************************
1447LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1448{
1449 //SvL: Set background color to default button color (not window (white))
1450 if(ctlType == CTLCOLOR_BTN)
1451 {
1452 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1453 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1454 return GetSysColorBrush(COLOR_BTNFACE);
1455 }
1456 //SvL: Set background color to default dialog color if window is dialog
1457 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1458 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1459 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1460 return GetSysColorBrush(COLOR_BTNFACE);
1461 }
1462
1463 if( ctlType == CTLCOLOR_SCROLLBAR)
1464 {
1465 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1466 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1467 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1468 SetBkColor( hdc, bk);
1469
1470//TODO?
1471#if 0
1472 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1473 * we better use 0x55aa bitmap brush to make scrollbar's background
1474 * look different from the window background.
1475 */
1476 if (bk == GetSysColor(COLOR_WINDOW)) {
1477 return CACHE_GetPattern55AABrush();
1478 }
1479#endif
1480 UnrealizeObject( hb );
1481 return (LRESULT)hb;
1482 }
1483
1484 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1485
1486 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1487 {
1488 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1489 }
1490 else
1491 {
1492 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1493 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1494 }
1495 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1496}
1497//******************************************************************************
1498//******************************************************************************
1499LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1500{
1501 switch(Msg)
1502 {
1503 case WM_CLOSE:
1504 DestroyWindow();
1505 return 0;
1506
1507 case WM_GETTEXTLENGTH:
1508 return wndNameLength;
1509
1510 case WM_GETTEXT:
1511 if (!lParam || !wParam) return 0;
1512 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1513 else strncpy((LPSTR)lParam, windowNameA, wParam);
1514 return min(wndNameLength, wParam);
1515
1516 case WM_SETTEXT:
1517 {
1518 LPCSTR lpsz = (LPCSTR)lParam;
1519
1520 if(windowNameA) free(windowNameA);
1521 if(windowNameW) free(windowNameW);
1522
1523 if (lParam)
1524 {
1525 wndNameLength = strlen(lpsz);
1526 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1527 strcpy(windowNameA, lpsz);
1528 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1529 lstrcpyAtoW(windowNameW, windowNameA);
1530 } else
1531 {
1532 windowNameA = NULL;
1533 windowNameW = NULL;
1534 wndNameLength = 0;
1535 }
1536 dprintf(("WM_SETTEXT of %d to %s\n", Win32Hwnd, lParam));
1537
1538 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1539 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1540
1541 return TRUE;
1542 }
1543
1544 case WM_SETREDRAW:
1545 {
1546 DWORD oldStyle = getStyle();
1547
1548 if(wParam)
1549 setStyle(getStyle() | WS_VISIBLE);
1550 else setStyle(getStyle() & ~WS_VISIBLE);
1551
1552 updateWindowStyle(getExStyle(), oldStyle);
1553
1554 return 0; //TODO
1555 }
1556 case WM_NCCREATE:
1557 return(TRUE);
1558
1559 case WM_NCCALCSIZE:
1560 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1561
1562 case WM_CTLCOLORMSGBOX:
1563 case WM_CTLCOLOREDIT:
1564 case WM_CTLCOLORLISTBOX:
1565 case WM_CTLCOLORBTN:
1566 case WM_CTLCOLORDLG:
1567 case WM_CTLCOLORSTATIC:
1568 case WM_CTLCOLORSCROLLBAR:
1569 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1570
1571 case WM_CTLCOLOR:
1572 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1573
1574 case WM_VKEYTOITEM:
1575 case WM_CHARTOITEM:
1576 return -1;
1577
1578 case WM_PARENTNOTIFY:
1579 return 0;
1580
1581 case WM_MOUSEACTIVATE:
1582 {
1583 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1584 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1585 {
1586 if(getParent()) {
1587 LRESULT rc = getParent()->SendMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1588 if(rc) return rc;
1589 }
1590 }
1591 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1592 }
1593 case WM_SETCURSOR:
1594 {
1595 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1596 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1597 {
1598 if(getParent()) {
1599 LRESULT rc = getParent()->SendMessageA(WM_SETCURSOR, wParam, lParam);
1600 if(rc) return rc;
1601 }
1602 }
1603 if (wParam == Win32Hwnd)
1604 {
1605 HCURSOR hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1606
1607 if (hCursor) SetCursor(hCursor);
1608 return 1;
1609 } else return 0;
1610 }
1611 case WM_MOUSEMOVE:
1612 return 0; //we do our own cursor handling
1613
1614 case WM_WINDOWPOSCHANGED:
1615 {
1616
1617/* undocumented SWP flags - from SDK 3.1 */
1618#define SWP_NOCLIENTSIZE 0x0800
1619#define SWP_NOCLIENTMOVE 0x1000
1620
1621 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1622 WPARAM wp = SIZE_RESTORED;
1623
1624 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1625 SendMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1626
1627 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1628 {
1629 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1630 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1631
1632 SendMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1633 rectClient.bottom - rectClient.top));
1634 }
1635 return 0;
1636 }
1637 case WM_WINDOWPOSCHANGING:
1638 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1639
1640 case WM_ERASEBKGND:
1641 case WM_ICONERASEBKGND:
1642 {
1643 RECT rect;
1644 int rc;
1645
1646 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1647
1648 rc = GetClipBox( (HDC)wParam, &rect );
1649 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1650 {
1651 HBRUSH hBrush = windowClass->getBackgroundBrush();
1652
1653 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1)) hBrush = GetSysColorBrush(hBrush-1);
1654
1655 FillRect( (HDC)wParam, &rect, hBrush);
1656 }
1657
1658 return 1;
1659 }
1660 case WM_GETDLGCODE:
1661 return 0;
1662
1663 case WM_NCLBUTTONDOWN:
1664 case WM_NCLBUTTONUP:
1665 case WM_NCLBUTTONDBLCLK:
1666 case WM_NCRBUTTONUP:
1667 case WM_NCRBUTTONDOWN:
1668 case WM_NCRBUTTONDBLCLK:
1669 case WM_NCMBUTTONDOWN:
1670 case WM_NCMBUTTONUP:
1671 case WM_NCMBUTTONDBLCLK:
1672 return 0; //TODO: Send WM_SYSCOMMAND if required
1673
1674 case WM_NCHITTEST: //TODO: Calculate position of
1675 return HTCLIENT;
1676
1677 case WM_SYSCOMMAND:
1678 {
1679 POINT point;
1680
1681 point.x = LOWORD(lParam);
1682 point.y = HIWORD(lParam);
1683 return HandleSysCommand(wParam, &point);
1684 }
1685
1686 case WM_SYSKEYDOWN:
1687 if(wParam == VK_F4) /* try to close the window */
1688 {
1689 Win32BaseWindow *window = GetTopParent();
1690 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1691 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1692 }
1693
1694 Win32BaseWindow *siblingWindow;
1695 HWND sibling;
1696 char nameBuffer [40], mnemonic;
1697 int nameLength;
1698
1699 GetWindowTextA (nameBuffer, 40);
1700
1701 // search all sibling to see it this key is their mnemonic
1702 sibling = GetWindow (GW_HWNDFIRST);
1703 while (sibling != 0) {
1704 siblingWindow = GetWindowFromHandle (sibling);
1705 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1706
1707 // find the siblings mnemonic
1708 mnemonic = '\0';
1709 for (int i=0 ; i<nameLength ; i++) {
1710 if (nameBuffer [i] == '&') {
1711 mnemonic = nameBuffer [i+1];
1712 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1713 mnemonic -= 32; // make it uppercase
1714 break; // stop searching
1715 }
1716 }
1717
1718 // key matches siblings mnemonic, send mouseclick
1719 if (mnemonic == (char) wParam) {
1720 siblingWindow->SendMessageA (BM_CLICK, 0, 0);
1721 }
1722
1723 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1724 }
1725
1726 return 0;
1727
1728 case WM_QUERYOPEN:
1729 case WM_QUERYENDSESSION:
1730 return 1;
1731
1732 case WM_NOTIFYFORMAT:
1733 if (IsUnicode()) return NFR_UNICODE;
1734 else return NFR_ANSI;
1735
1736 case WM_SETICON:
1737 case WM_GETICON:
1738 {
1739 LRESULT result = 0;
1740 if (!windowClass) return result;
1741 int index = GCL_HICON;
1742
1743 if (wParam == ICON_SMALL)
1744 index = GCL_HICONSM;
1745
1746 result = windowClass->getClassLongA(index);
1747
1748 if (Msg == WM_SETICON)
1749 windowClass->setClassLongA(index, lParam);
1750
1751 return result;
1752 }
1753 case WM_NOTIFY:
1754 return 0; //comctl32 controls expect this
1755
1756 default:
1757 if(Msg > WM_USER) {
1758 return 0;
1759 }
1760 return 1;
1761 }
1762}
1763//******************************************************************************
1764//******************************************************************************
1765LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1766{
1767 switch(Msg)
1768 {
1769 case WM_GETTEXTLENGTH:
1770 return wndNameLength;
1771
1772 case WM_GETTEXT:
1773 if (!lParam || !wParam) return 0;
1774 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1775 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1776 return min(wndNameLength,wParam);
1777
1778 case WM_SETTEXT:
1779 {
1780 LPWSTR lpsz = (LPWSTR)lParam;
1781
1782 if(windowNameA) free(windowNameA);
1783 if(windowNameW) free(windowNameW);
1784
1785 if (lParam)
1786 {
1787 wndNameLength = lstrlenW(lpsz);
1788 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1789 lstrcpyWtoA(windowNameA,lpsz);
1790 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1791 lstrcpyW(windowNameW,lpsz);
1792 } else
1793 {
1794 windowNameA = NULL;
1795 windowNameW = NULL;
1796 wndNameLength = 0;
1797 }
1798
1799 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1800 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1801
1802 return TRUE;
1803 }
1804
1805 default:
1806 return DefWindowProcA(Msg, wParam, lParam);
1807 }
1808}
1809//******************************************************************************
1810//******************************************************************************
1811LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1812{
1813 LRESULT rc;
1814 BOOL fInternalMsgBackup = fInternalMsg;
1815
1816 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1817 // receive those before they get their WM_CREATE message
1818 //NOTE: May need to refuse more messages
1819 if(fCreated == FALSE && Msg == WM_COMMAND) {
1820 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1821 return 0;
1822 }
1823
1824 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
1825
1826 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1827 return(0);
1828 }
1829 fInternalMsg = FALSE;
1830 switch(Msg)
1831 {
1832 case WM_CREATE:
1833 {
1834 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1835 dprintf(("WM_CREATE returned -1\n"));
1836 rc = -1; //don't create window
1837 break;
1838 }
1839 NotifyParent(Msg, wParam, lParam);
1840
1841 rc = 0;
1842 break;
1843 }
1844 case WM_SETTEXT:
1845 rc = CallWindowProcA(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1846 break;
1847
1848 case WM_LBUTTONDOWN:
1849 case WM_MBUTTONDOWN:
1850 case WM_RBUTTONDOWN:
1851 NotifyParent(Msg, wParam, lParam);
1852 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1853 break;
1854
1855 case WM_DESTROY:
1856 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1857 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1858 break;
1859
1860 default:
1861 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1862 break;
1863 }
1864 fInternalMsg = fInternalMsgBackup;
1865 return rc;
1866}
1867//******************************************************************************
1868//******************************************************************************
1869LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1870{
1871 LRESULT rc;
1872 BOOL fInternalMsgBackup = fInternalMsg;
1873
1874 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1875 // receive those before they get their WM_CREATE message
1876 //NOTE: May need to refuse more messages
1877 if(fCreated == FALSE && Msg == WM_COMMAND) {
1878 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1879 return 0;
1880 }
1881
1882 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
1883
1884 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1885 return(0);
1886 }
1887 fInternalMsg = FALSE;
1888 switch(Msg)
1889 {
1890 case WM_CREATE:
1891 {
1892 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1893 dprintf(("WM_CREATE returned -1\n"));
1894 rc = -1; //don't create window
1895 break;
1896 }
1897 NotifyParent(Msg, wParam, lParam);
1898
1899 rc = 0;
1900 break;
1901 }
1902 case WM_SETTEXT:
1903 rc = CallWindowProcW(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1904 break;
1905
1906 case WM_LBUTTONDOWN:
1907 case WM_MBUTTONDOWN:
1908 case WM_RBUTTONDOWN:
1909 NotifyParent(Msg, wParam, lParam);
1910 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1911 break;
1912
1913 case WM_DESTROY:
1914 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1915 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1916 break;
1917
1918 default:
1919 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1920 break;
1921 }
1922 fInternalMsg = fInternalMsgBackup;
1923 return rc;
1924}
1925//******************************************************************************
1926//Called as a result of an OS/2 message
1927//******************************************************************************
1928LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1929{
1930 LRESULT rc;
1931 BOOL fInternalMsgBackup = fInternalMsg;
1932
1933 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1934
1935 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1936 return(0);
1937 }
1938 fInternalMsg = TRUE;
1939 switch(Msg)
1940 {
1941 case WM_CREATE:
1942 {
1943 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1944 dprintf(("WM_CREATE returned -1\n"));
1945 rc = -1; //don't create window
1946 break;
1947 }
1948 NotifyParent(Msg, wParam, lParam);
1949 rc = 0;
1950 break;
1951 }
1952 case WM_LBUTTONDOWN:
1953 case WM_MBUTTONDOWN:
1954 case WM_RBUTTONDOWN:
1955 NotifyParent(Msg, wParam, lParam);
1956 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1957 break;
1958
1959 case WM_DESTROY:
1960 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1961 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1962 break;
1963
1964 default:
1965 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1966 break;
1967 }
1968 fInternalMsg = fInternalMsgBackup;
1969 return rc;
1970}
1971//******************************************************************************
1972//Called as a result of an OS/2 message
1973//todo, unicode msgs (WM_SETTEXT etc)
1974//******************************************************************************
1975LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1976{
1977 LRESULT rc;
1978 BOOL fInternalMsgBackup = fInternalMsg;
1979
1980 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1981
1982 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1983 return(0);
1984 }
1985 fInternalMsg = TRUE;
1986 switch(Msg)
1987 {
1988 case WM_CREATE:
1989 {
1990 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1991 dprintf(("WM_CREATE returned -1\n"));
1992 rc = -1; //don't create window
1993 break;
1994 }
1995 NotifyParent(Msg, wParam, lParam);
1996 rc = 0;
1997 break;
1998 }
1999 case WM_LBUTTONDOWN:
2000 case WM_MBUTTONDOWN:
2001 case WM_RBUTTONDOWN:
2002 NotifyParent(Msg, wParam, lParam);
2003 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2004 break;
2005
2006 case WM_DESTROY:
2007 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
2008 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2009 break;
2010 default:
2011 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2012 break;
2013 }
2014 fInternalMsg = fInternalMsgBackup;
2015 return rc;
2016}
2017//******************************************************************************
2018//******************************************************************************
2019BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
2020{
2021 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2022
2023 packet->Msg = msg;
2024 packet->wParam = wParam;
2025 packet->lParam = lParam;
2026 packet->fUnicode = FALSE;
2027 return OSLibPostMessage(OS2Hwnd, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2028}
2029//******************************************************************************
2030//******************************************************************************
2031BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
2032{
2033 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2034
2035 packet->Msg = msg;
2036 packet->wParam = wParam;
2037 packet->lParam = lParam;
2038 packet->fUnicode = TRUE;
2039 return OSLibPostMessage(OS2Hwnd, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2040}
2041//******************************************************************************
2042//******************************************************************************
2043BOOL Win32BaseWindow::PostThreadMessageA(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam)
2044{
2045 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2046
2047 packet->Msg = msg;
2048 packet->wParam = wParam;
2049 packet->lParam = lParam;
2050 packet->fUnicode = FALSE;
2051 return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2052}
2053//******************************************************************************
2054//******************************************************************************
2055BOOL Win32BaseWindow::PostThreadMessageW(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam)
2056{
2057 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2058
2059 packet->Msg = msg;
2060 packet->wParam = wParam;
2061 packet->lParam = lParam;
2062 packet->fUnicode = TRUE;
2063 return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2064}
2065//******************************************************************************
2066//******************************************************************************
2067void Win32BaseWindow::PostMessage(POSTMSG_PACKET *packet)
2068{
2069 if(packet == NULL)
2070 return;
2071
2072 if(packet->fUnicode) {
2073 SendMessageW(packet->Msg, packet->wParam, packet->lParam);
2074 }
2075 else SendMessageA(packet->Msg, packet->wParam, packet->lParam);
2076
2077 free(packet);
2078}
2079//******************************************************************************
2080//Send message to window of another process
2081//******************************************************************************
2082LRESULT Win32BaseWindow::SendMessageToProcess(UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2083{
2084 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2085
2086 dprintf(("SendMessageToProcess %x %x %x %x", getOS2WindowHandle(), msg, wParam, lParam));
2087 packet->Msg = msg;
2088 packet->wParam = wParam;
2089 packet->lParam = lParam;
2090 packet->fUnicode = fUnicode;
2091 return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2092}
2093//******************************************************************************
2094//TODO: Do this more efficiently
2095//******************************************************************************
2096LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2097{
2098 Win32BaseWindow *window;
2099 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2100 DWORD processid, myprocessid;
2101
2102 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2103 myprocessid = GetCurrentProcessId();
2104
2105 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2106 window = GetWindowFromHandle(hwnd++);
2107 if(window) {
2108 if (window->getStyle() & WS_POPUP || (window->getStyle() & WS_CAPTION) == WS_CAPTION)
2109 {
2110
2111 if(type == BROADCAST_SEND) {
2112 GetWindowThreadProcessId(hwnd, &processid);
2113 if(processid == myprocessid) {
2114 window->SendMessageA(msg, wParam, lParam);
2115 }
2116 else {
2117 window->SendMessageToProcess(msg, wParam, lParam, FALSE);
2118 }
2119 }
2120 else window->PostMessageA(msg, wParam, lParam);
2121 }
2122 }
2123 }
2124 return 0;
2125}
2126//******************************************************************************
2127//TODO: Do this more efficiently
2128//******************************************************************************
2129LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2130{
2131 Win32BaseWindow *window;
2132 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2133 DWORD processid, myprocessid;
2134
2135
2136 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2137 myprocessid = GetCurrentProcessId();
2138
2139 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2140 window = GetWindowFromHandle(hwnd++);
2141 if(window) {
2142 if (window->getStyle() & WS_POPUP || (window->getStyle() & WS_CAPTION) == WS_CAPTION)
2143 {
2144
2145 if(type == BROADCAST_SEND) {
2146 GetWindowThreadProcessId(hwnd, &processid);
2147 if(processid == myprocessid) {
2148 window->SendMessageW(msg, wParam, lParam);
2149 }
2150 else {
2151 window->SendMessageToProcess(msg, wParam, lParam, TRUE);
2152 }
2153 }
2154 else window->PostMessageW(msg, wParam, lParam);
2155 }
2156 }
2157 }
2158 return 0;
2159}
2160//******************************************************************************
2161//TODO: do we need to inform the parent of the parent (etc) of the child window?
2162//******************************************************************************
2163void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2164{
2165 Win32BaseWindow *window = this;
2166 Win32BaseWindow *parentwindow;
2167
2168 while(window)
2169 {
2170 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2171 {
2172 /* Notify the parent window only */
2173 parentwindow = window->getParent();
2174 if(parentwindow) {
2175 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
2176 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
2177 }
2178 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
2179 }
2180 }
2181 else break;
2182
2183 window = parentwindow;
2184 }
2185}
2186//******************************************************************************
2187//******************************************************************************
2188BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
2189{
2190
2191 dprintf(("SetMenu %x", hMenu));
2192 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
2193 if(OS2HwndMenu == 0) {
2194 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
2195 return FALSE;
2196 }
2197 return TRUE;
2198}
2199//******************************************************************************
2200//******************************************************************************
2201BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
2202{
2203 Win32Resource *winres = (Win32Resource *)hAccel;
2204 HANDLE accelhandle;
2205
2206 if(HIWORD(hAccel) == 0) {
2207 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
2208 SetLastError(ERROR_INVALID_PARAMETER);
2209 return FALSE;
2210 }
2211 acceltableResource = winres;
2212 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
2213 winres->setOS2Handle(accelhandle);
2214 return(accelhandle != 0);
2215}
2216//******************************************************************************
2217//******************************************************************************
2218BOOL Win32BaseWindow::SetIcon(HICON hIcon)
2219{
2220 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
2221 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
2222//TODO: Wine does't send these. Correct?
2223// SendMessageA(WM_SETICON, ICON_BIG, hIcon);
2224 return TRUE;
2225 }
2226 return FALSE;
2227}
2228//******************************************************************************
2229//******************************************************************************
2230BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2231{
2232 ULONG showstate = 0;
2233 HWND hWinAfter;
2234
2235 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2236#if 1
2237 if (flags & WIN_NEED_SIZE)
2238 {
2239 /* should happen only in CreateWindowEx() */
2240 int wParam = SIZE_RESTORED;
2241
2242 flags &= ~WIN_NEED_SIZE;
2243 if (dwStyle & WS_MAXIMIZE)
2244 wParam = SIZE_MAXIMIZED;
2245 else
2246 if (dwStyle & WS_MINIMIZE)
2247 wParam = SIZE_MINIMIZED;
2248
2249 SendMessageA(WM_SIZE, wParam,
2250 MAKELONG(rectClient.right-rectClient.left,
2251 rectClient.bottom-rectClient.top));
2252 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2253 }
2254#else
2255 if(fFirstShow) {
2256 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
2257 SendMessageA(WM_SIZE, SIZE_RESTORED,
2258 MAKELONG(rectClient.right-rectClient.left,
2259 rectClient.bottom-rectClient.top));
2260 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2261
2262 }
2263 fFirstShow = FALSE;
2264 }
2265#endif
2266 switch(nCmdShow)
2267 {
2268 case SW_SHOW:
2269 case SW_SHOWDEFAULT: //todo
2270 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2271 break;
2272 case SW_HIDE:
2273 showstate = SWPOS_HIDE;
2274 break;
2275 case SW_RESTORE:
2276 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2277 break;
2278 case SW_MINIMIZE:
2279 showstate = SWPOS_MINIMIZE;
2280 break;
2281 case SW_SHOWMAXIMIZED:
2282 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2283 break;
2284 case SW_SHOWMINIMIZED:
2285 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2286 break;
2287 case SW_SHOWMINNOACTIVE:
2288 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2289 break;
2290 case SW_SHOWNA:
2291 showstate = SWPOS_SHOW;
2292 break;
2293 case SW_SHOWNOACTIVATE:
2294 showstate = SWPOS_SHOW;
2295 break;
2296 case SW_SHOWNORMAL:
2297 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2298 break;
2299 }
2300
2301 /* We can't activate a child window (WINE) */
2302 if(getStyle() & WS_CHILD)
2303 showstate &= ~SWPOS_ACTIVATE;
2304
2305 if(showstate & SWPOS_SHOW) {
2306 setStyle(getStyle() | WS_VISIBLE);
2307 }
2308 else setStyle(getStyle() & ~WS_VISIBLE);
2309
2310 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2311 return rc;
2312}
2313//******************************************************************************
2314//******************************************************************************
2315BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2316{
2317 BOOL rc = FALSE;
2318 Win32BaseWindow *window;
2319 HWND hParent = 0;
2320
2321 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2322
2323 if (fuFlags &
2324 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2325 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2326 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2327 SWP_NOOWNERZORDER))
2328 {
2329 return FALSE;
2330 }
2331
2332 WINDOWPOS wpos;
2333 SWP swp, swpOld;
2334
2335 wpos.flags = fuFlags;
2336 wpos.cy = cy;
2337 wpos.cx = cx;
2338 wpos.x = x;
2339 wpos.y = y;
2340 wpos.hwndInsertAfter = hwndInsertAfter;
2341 wpos.hwnd = getWindowHandle();
2342
2343 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2344 {
2345 if (isChild())
2346 {
2347 hParent = getParent()->getOS2WindowHandle();
2348 }
2349 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2350 }
2351
2352 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2353 if (swp.fl == 0)
2354 return TRUE;
2355
2356// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2357 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2358 {
2359 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2360 if(wndBehind) {
2361 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2362 }
2363 else {
2364 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2365 swp.hwndInsertBehind = 0;
2366 }
2367 }
2368#if 0
2369 if (isFrameWindow())
2370 {
2371 if (!isChild())
2372 {
2373 POINT maxSize, maxPos, minTrack, maxTrack;
2374
2375 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2376
2377 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2378 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2379 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2380 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2381 }
2382 swp.hwnd = OS2HwndFrame;
2383 }
2384 else
2385#endif
2386 swp.hwnd = OS2HwndFrame;
2387
2388 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2389
2390 rc = OSLibWinSetMultWindowPos(&swp, 1);
2391
2392 if (rc == FALSE)
2393 {
2394 dprintf(("OSLibWinSetMultWindowPos failed!"));
2395 }
2396 else
2397 {
2398 if (fuFlags & SWP_FRAMECHANGED_W)
2399 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2400 }
2401
2402 return (rc);
2403}
2404//******************************************************************************
2405//TODO: WPF_RESTOREMAXIMIZED
2406//******************************************************************************
2407BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2408{
2409 if(isFrameWindow())
2410 {
2411 // Set the minimized position
2412 if (winpos->flags & WPF_SETMINPOSITION)
2413 {
2414 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2415 }
2416
2417 //TODO: Max position
2418
2419 // Set the new restore position.
2420 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2421 }
2422
2423 return ShowWindow(winpos->showCmd);
2424}
2425//******************************************************************************
2426//Also destroys all the child windows (destroy parent, destroy children)
2427//******************************************************************************
2428BOOL Win32BaseWindow::DestroyWindow()
2429{
2430 return OSLibWinDestroyWindow(OS2HwndFrame);
2431}
2432//******************************************************************************
2433//******************************************************************************
2434HWND Win32BaseWindow::GetParent()
2435{
2436 if(getParent()) {
2437 return getParent()->getWindowHandle();
2438 }
2439 else return 0;
2440}
2441//******************************************************************************
2442//******************************************************************************
2443HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2444{
2445 HWND oldhwnd;
2446 Win32BaseWindow *newparent;
2447
2448 if(getParent()) {
2449 oldhwnd = getParent()->getWindowHandle();
2450 getParent()->RemoveChild(this);
2451 }
2452 else oldhwnd = 0;
2453
2454 newparent = GetWindowFromHandle(hwndNewParent);
2455 if(newparent)
2456 {
2457 setParent(newparent);
2458 getParent()->AddChild(this);
2459 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2460 return oldhwnd;
2461 }
2462 else {
2463 setParent(windowDesktop);
2464 getParent()->AddChild(this);
2465 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2466 return oldhwnd;
2467 }
2468}
2469//******************************************************************************
2470//******************************************************************************
2471BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2472{
2473 if(getParent()) {
2474 return getParent()->getWindowHandle() == hwndParent;
2475 }
2476 else return 0;
2477}
2478//******************************************************************************
2479//******************************************************************************
2480HWND Win32BaseWindow::GetTopWindow()
2481{
2482 return GetWindow(GW_CHILD);
2483}
2484//******************************************************************************
2485// Get the top-level parent for a child window.
2486//******************************************************************************
2487Win32BaseWindow *Win32BaseWindow::GetTopParent()
2488{
2489 Win32BaseWindow *window = this;
2490
2491 while(window && (window->getStyle() & WS_CHILD))
2492 {
2493 window = window->getParent();
2494 }
2495 return window;
2496}
2497//******************************************************************************
2498//Don't call WinUpdateWindow as that one also updates the child windows
2499//Also need to send WM_PAINT directly to the window procedure, which doesn't
2500//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2501//******************************************************************************
2502BOOL Win32BaseWindow::UpdateWindow()
2503{
2504 RECT rect;
2505
2506 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2507 {//update region not empty
2508 HDC hdc;
2509
2510 hdc = O32_GetDC(OS2Hwnd);
2511 if (isIcon)
2512 {
2513 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2514 SendMessageA(WM_PAINTICON, 0, 0);
2515 } else
2516 {
2517 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2518 SendMessageA(WM_PAINT, 0, 0);
2519 }
2520 O32_ReleaseDC(OS2Hwnd, hdc);
2521 }
2522 return TRUE;
2523}
2524//******************************************************************************
2525//******************************************************************************
2526BOOL Win32BaseWindow::IsIconic()
2527{
2528 return OSLibWinIsIconic(OS2Hwnd);
2529}
2530//******************************************************************************
2531//TODO: Should not enumerate children that are created during the enumeration!
2532//******************************************************************************
2533BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2534{
2535 BOOL rc = TRUE;
2536 HWND hwnd;
2537 Win32BaseWindow *prevchild = 0, *child = 0;
2538
2539 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2540 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2541 {
2542 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2543 hwnd = child->getWindowHandle();
2544 if(lpfn(hwnd, lParam) == FALSE)
2545 {
2546 rc = FALSE;
2547 break;
2548 }
2549 //check if the window still exists
2550 if(!::IsWindow(hwnd))
2551 {
2552 child = prevchild;
2553 continue;
2554 }
2555 if(child->getFirstChild() != NULL)
2556 {
2557 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2558 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2559 {
2560 rc = FALSE;
2561 break;
2562 }
2563 }
2564 prevchild = child;
2565 }
2566 return rc;
2567}
2568//******************************************************************************
2569//******************************************************************************
2570Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2571{
2572 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2573 {
2574 if (child->getWindowId() == id)
2575 {
2576 return child;
2577 }
2578 }
2579 return 0;
2580}
2581//******************************************************************************
2582//TODO:
2583//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2584//the current process owns them.
2585//******************************************************************************
2586HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2587 BOOL fUnicode)
2588{
2589 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2590 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2591
2592 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2593 (hwndChildAfter != 0 && !child) ||
2594 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2595 {
2596 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2597 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2598 return 0;
2599 }
2600 if(hwndParent != OSLIB_HWND_DESKTOP)
2601 {//if the current process owns the window, just do a quick search
2602 child = (Win32BaseWindow *)parent->getFirstChild();
2603 if(hwndChildAfter != 0)
2604 {
2605 while(child)
2606 {
2607 if(child->getWindowHandle() == hwndChildAfter)
2608 {
2609 child = (Win32BaseWindow *)child->getNextChild();
2610 break;
2611 }
2612 child = (Win32BaseWindow *)child->getNextChild();
2613 }
2614 }
2615 while(child)
2616 {
2617 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2618 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2619 {
2620 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2621 return child->getWindowHandle();
2622 }
2623 child = (Win32BaseWindow *)child->getNextChild();
2624 }
2625 }
2626 else {
2627 Win32BaseWindow *wnd;
2628 HWND henum, hwnd;
2629
2630 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2631 hwnd = OSLibWinGetNextWindow(henum);
2632
2633 while(hwnd)
2634 {
2635 wnd = GetWindowFromOS2Handle(hwnd);
2636 if(wnd == NULL) {
2637 hwnd = OSLibWinQueryClientWindow(hwnd);
2638 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2639 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2640 }
2641
2642 if(wnd) {
2643 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2644 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2645 {
2646 OSLibWinEndEnumWindows(henum);
2647 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2648 return wnd->getWindowHandle();
2649 }
2650 }
2651 hwnd = OSLibWinGetNextWindow(henum);
2652 }
2653 OSLibWinEndEnumWindows(henum);
2654 }
2655 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2656 return 0;
2657}
2658//******************************************************************************
2659//******************************************************************************
2660HWND Win32BaseWindow::GetWindow(UINT uCmd)
2661{
2662 HWND hwndRelated = 0;
2663 Win32BaseWindow *window;
2664
2665 switch(uCmd)
2666 {
2667 case GW_HWNDFIRST:
2668 if(getParent()) {
2669 window = (Win32BaseWindow *)getParent()->getFirstChild();
2670 hwndRelated = window->getWindowHandle();
2671 }
2672 break;
2673
2674 case GW_HWNDLAST:
2675 if(!getParent())
2676 {
2677 goto end;
2678 }
2679
2680 window = this;
2681 while(window->getNextChild())
2682 {
2683 window = (Win32BaseWindow *)window->getNextChild();
2684 }
2685 hwndRelated = window->getWindowHandle();
2686 break;
2687
2688 case GW_HWNDNEXT:
2689 window = (Win32BaseWindow *)getNextChild();
2690 if(window) {
2691 hwndRelated = window->getWindowHandle();
2692 }
2693 break;
2694
2695 case GW_HWNDPREV:
2696 if(!getParent())
2697 {
2698 goto end;
2699 }
2700 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2701 if(window == this)
2702 {
2703 hwndRelated = 0; /* First in list */
2704 goto end;
2705 }
2706 while(window->getNextChild())
2707 {
2708 if (window->getNextChild() == this)
2709 {
2710 hwndRelated = window->getWindowHandle();
2711 goto end;
2712 }
2713 window = (Win32BaseWindow *)window->getNextChild();
2714 }
2715 break;
2716
2717 case GW_OWNER:
2718 if(getOwner()) {
2719 hwndRelated = getOwner()->getWindowHandle();
2720 }
2721 break;
2722
2723 case GW_CHILD:
2724 if(getFirstChild()) {
2725 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2726 }
2727 break;
2728 }
2729end:
2730 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2731 return hwndRelated;
2732}
2733//******************************************************************************
2734//******************************************************************************
2735HWND Win32BaseWindow::SetActiveWindow()
2736{
2737 return OSLibWinSetActiveWindow(OS2HwndFrame);
2738}
2739//******************************************************************************
2740//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2741//******************************************************************************
2742BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2743{
2744 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2745}
2746//******************************************************************************
2747//******************************************************************************
2748BOOL Win32BaseWindow::CloseWindow()
2749{
2750 return OSLibWinMinimizeWindow(OS2HwndFrame);
2751}
2752//******************************************************************************
2753//******************************************************************************
2754HWND Win32BaseWindow::GetActiveWindow()
2755{
2756 HWND hwndActive;
2757 Win32BaseWindow *win32wnd;
2758 ULONG magic;
2759
2760 hwndActive = OSLibWinQueryActiveWindow();
2761
2762 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2763 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2764 if(CheckMagicDword(magic) && win32wnd)
2765 {
2766 return win32wnd->getWindowHandle();
2767 }
2768 return hwndActive;
2769}
2770//******************************************************************************
2771//******************************************************************************
2772BOOL Win32BaseWindow::IsWindowEnabled()
2773{
2774 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2775}
2776//******************************************************************************
2777//******************************************************************************
2778BOOL Win32BaseWindow::IsWindowVisible()
2779{
2780#if 1
2781 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2782#else
2783 return OSLibWinIsWindowVisible(OS2HwndFrame);
2784#endif
2785}
2786//******************************************************************************
2787//******************************************************************************
2788BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2789{
2790 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2791}
2792//******************************************************************************
2793//******************************************************************************
2794BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2795{
2796 if(wndname == NULL)
2797 return FALSE;
2798
2799 if(fUnicode) {
2800 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2801 }
2802 else return (strcmp(windowNameA, wndname) == 0);
2803}
2804//******************************************************************************
2805//******************************************************************************
2806int Win32BaseWindow::GetWindowTextLength()
2807{
2808 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2809}
2810//******************************************************************************
2811//******************************************************************************
2812int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2813{
2814 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2815}
2816//******************************************************************************
2817//******************************************************************************
2818int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2819{
2820 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2821}
2822//******************************************************************************
2823//******************************************************************************
2824BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2825{
2826 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2827}
2828//******************************************************************************
2829//******************************************************************************
2830BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2831{
2832 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2833}
2834//******************************************************************************
2835//******************************************************************************
2836VOID Win32BaseWindow::updateWindowStyle(DWORD oldExStyle,DWORD oldStyle)
2837{
2838 if(IsWindowDestroyed()) return;
2839
2840/*
2841 if (isChild())
2842 {
2843 DWORD dwOSWinStyle,dwOSFrameStyle,newBorderWidth,newBorderHeight;
2844
2845 OSLibWinConvertStyle(dwStyle,&dwExStyle,&dwOSWinStyle,&dwOSFrameStyle,&newBorderWidth,&newBorderHeight);
2846 if (newBorderWidth != borderWidth || newBorderHeight != borderHeight)
2847 {
2848 borderWidth = newBorderWidth;
2849 borderHeight = newBorderHeight;
2850 FrameSetBorderSize(this,TRUE);
2851 }
2852 }
2853*/
2854
2855 if (dwStyle != oldStyle) OSLibSetWindowStyle(OS2HwndFrame,dwStyle);
2856}
2857//******************************************************************************
2858//******************************************************************************
2859LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2860{
2861 LONG oldval;
2862
2863 dprintf2(("SetWindowLongA %x %d %x", getWindowHandle(), index, value));
2864 switch(index) {
2865 case GWL_EXSTYLE:
2866 {
2867 STYLESTRUCT ss;
2868
2869 if(dwExStyle == value)
2870 return value;
2871
2872 ss.styleOld = dwExStyle;
2873 ss.styleNew = value;
2874 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2875 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2876 setExStyle(ss.styleNew);
2877 updateWindowStyle(ss.styleOld,getStyle());
2878 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2879 return ss.styleOld;
2880 }
2881 case GWL_STYLE:
2882 {
2883 STYLESTRUCT ss;
2884
2885 if(dwStyle == value)
2886 return value;
2887
2888 value &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way (WINE) */
2889 ss.styleOld = getStyle();
2890 ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
2891 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), getStyle(), value));
2892 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2893 setStyle(ss.styleNew);
2894 updateWindowStyle(dwExStyle,ss.styleOld);
2895 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2896#ifdef DEBUG
2897 PrintWindowStyle(ss.styleNew, 0);
2898#endif
2899 return ss.styleOld;
2900 }
2901 case GWL_WNDPROC:
2902 oldval = (LONG)getWindowProc();
2903 setWindowProc((WNDPROC)value);
2904 return oldval;
2905 case GWL_HINSTANCE:
2906 oldval = hInstance;
2907 hInstance = value;
2908 return oldval;
2909 case GWL_HWNDPARENT:
2910 return SetParent((HWND)value);
2911 case GWL_ID:
2912 oldval = getWindowId();
2913 setWindowId(value);
2914 return oldval;
2915 case GWL_USERDATA:
2916 oldval = userData;
2917 userData = value;
2918 return oldval;
2919 default:
2920 if(index >= 0 && index/4 < nrUserWindowLong)
2921 {
2922 oldval = userWindowLong[index/4];
2923 userWindowLong[index/4] = value;
2924 return oldval;
2925 }
2926 SetLastError(ERROR_INVALID_PARAMETER);
2927 return 0;
2928 }
2929}
2930//******************************************************************************
2931//******************************************************************************
2932ULONG Win32BaseWindow::GetWindowLongA(int index)
2933{
2934 ULONG value;
2935
2936 switch(index) {
2937 case GWL_EXSTYLE:
2938 value = dwExStyle;
2939 break;
2940 case GWL_STYLE:
2941 value = dwStyle;
2942 break;
2943 case GWL_WNDPROC:
2944 value = (ULONG)getWindowProc();
2945 break;
2946 case GWL_HINSTANCE:
2947 value = hInstance;
2948 break;
2949 case GWL_HWNDPARENT:
2950 if(getParent()) {
2951 value = getParent()->getWindowHandle();
2952 }
2953 else value = 0;
2954 break;
2955 case GWL_ID:
2956 value = getWindowId();
2957 break;
2958 case GWL_USERDATA:
2959 value = userData;
2960 break;
2961 default:
2962 if(index >= 0 && index/4 < nrUserWindowLong)
2963 {
2964 value = userWindowLong[index/4];
2965 break;
2966 }
2967 SetLastError(ERROR_INVALID_PARAMETER);
2968 return 0;
2969 }
2970 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
2971 return value;
2972}
2973//******************************************************************************
2974//******************************************************************************
2975WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2976{
2977 WORD oldval;
2978
2979 if(index >= 0 && index/4 < nrUserWindowLong)
2980 {
2981 oldval = ((WORD *)userWindowLong)[index/2];
2982 ((WORD *)userWindowLong)[index/2] = value;
2983 return oldval;
2984 }
2985 SetLastError(ERROR_INVALID_PARAMETER);
2986 return 0;
2987}
2988//******************************************************************************
2989//******************************************************************************
2990WORD Win32BaseWindow::GetWindowWord(int index)
2991{
2992 if(index >= 0 && index/4 < nrUserWindowLong)
2993 {
2994 return ((WORD *)userWindowLong)[index/2];
2995 }
2996 SetLastError(ERROR_INVALID_PARAMETER);
2997 return 0;
2998}
2999//******************************************************************************
3000//******************************************************************************
3001void Win32BaseWindow::setWindowId(DWORD id)
3002{
3003 windowId = id;
3004 dprintf(("Set window ID to %x", id));
3005 OSLibSetWindowID(OS2HwndFrame, id);
3006}
3007//******************************************************************************
3008//******************************************************************************
3009Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3010{
3011 Win32BaseWindow *window;
3012
3013 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3014 return window;
3015 }
3016 else return NULL;
3017}
3018//******************************************************************************
3019//******************************************************************************
3020Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3021{
3022 Win32BaseWindow *win32wnd;
3023 DWORD magic;
3024
3025 if(hwnd == OSLIB_HWND_DESKTOP)
3026 {
3027 return windowDesktop;
3028 }
3029
3030 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3031 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3032
3033 if(win32wnd && CheckMagicDword(magic)) {
3034 return win32wnd;
3035 }
3036 return 0;
3037}
3038//******************************************************************************
3039//******************************************************************************
3040Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3041{
3042 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3043}
3044//******************************************************************************
3045//******************************************************************************
3046HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3047{
3048 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3049
3050 if(window) {
3051 return window->getOS2WindowHandle();
3052 }
3053 else return hwnd;
3054}
3055//******************************************************************************
3056//******************************************************************************
3057HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
3058{
3059 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3060
3061 if(window) {
3062 return window->getOS2FrameWindowHandle();
3063 }
3064 else return hwnd;
3065}
3066//******************************************************************************
3067//******************************************************************************
3068HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3069{
3070 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3071
3072 if(window) {
3073 return window->getWindowHandle();
3074 }
3075 window = GetWindowFromOS2FrameHandle(hwnd);
3076 if(window) {
3077 return window->getWindowHandle();
3078 }
3079 else return 0;
3080// else return hwnd; //OS/2 window handle
3081}
3082//******************************************************************************
3083// GetNextDlgTabItem32 (USER32.276)
3084//******************************************************************************
3085HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3086{
3087 Win32BaseWindow *child, *nextchild, *lastchild;
3088 HWND retvalue;
3089
3090 if (hwndCtrl)
3091 {
3092 child = GetWindowFromHandle(hwndCtrl);
3093 if (!child)
3094 {
3095 retvalue = 0;
3096 goto END;
3097 }
3098 /* Make sure hwndCtrl is a top-level child */
3099 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3100 {
3101 child = child->getParent();
3102 if(child == NULL) break;
3103 }
3104
3105 if (!child || child->getParent() != this)
3106 {
3107 retvalue = 0;
3108 goto END;
3109 }
3110 }
3111 else
3112 {
3113 /* No ctrl specified -> start from the beginning */
3114 child = (Win32BaseWindow *)getFirstChild();
3115 if (!child)
3116 {
3117 retvalue = 0;
3118 goto END;
3119 }
3120
3121 if (!fPrevious)
3122 {
3123 while (child->getNextChild())
3124 {
3125 child = (Win32BaseWindow *)child->getNextChild();
3126 }
3127 }
3128 }
3129
3130 lastchild = child;
3131 nextchild = (Win32BaseWindow *)child->getNextChild();
3132 while (TRUE)
3133 {
3134 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3135
3136 if (child == nextchild) break;
3137
3138 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3139 !(nextchild->getStyle() & WS_DISABLED))
3140 {
3141 lastchild = nextchild;
3142 if (!fPrevious) break;
3143 }
3144 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3145 }
3146 retvalue = lastchild->getWindowHandle();
3147
3148END:
3149 return retvalue;
3150}
3151//******************************************************************************
3152//******************************************************************************
3153HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3154{
3155 Win32BaseWindow *child, *nextchild, *lastchild;
3156 HWND retvalue;
3157
3158 if (hwndCtrl)
3159 {
3160 child = GetWindowFromHandle(hwndCtrl);
3161 if (!child)
3162 {
3163 retvalue = 0;
3164 goto END;
3165 }
3166 /* Make sure hwndCtrl is a top-level child */
3167 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3168 {
3169 child = child->getParent();
3170 if(child == NULL) break;
3171 }
3172
3173 if (!child || child->getParent() != this)
3174 {
3175 retvalue = 0;
3176 goto END;
3177 }
3178 }
3179 else
3180 {
3181 /* No ctrl specified -> start from the beginning */
3182 child = (Win32BaseWindow *)getFirstChild();
3183 if (!child)
3184 {
3185 retvalue = 0;
3186 goto END;
3187 }
3188
3189 if (fPrevious)
3190 {
3191 while (child->getNextChild())
3192 {
3193 child = (Win32BaseWindow *)child->getNextChild();
3194 }
3195 }
3196 }
3197
3198 lastchild = child;
3199 nextchild = (Win32BaseWindow *)child->getNextChild();
3200 while (TRUE)
3201 {
3202 if (!nextchild || nextchild->getStyle() & WS_GROUP)
3203 {
3204 /* Wrap-around to the beginning of the group */
3205 Win32BaseWindow *pWndTemp;
3206
3207 nextchild = (Win32BaseWindow *)getFirstChild();
3208
3209 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3210 {
3211 if (pWndTemp->getStyle() & WS_GROUP)
3212 nextchild = pWndTemp;
3213
3214 if (pWndTemp == child)
3215 break;
3216 }
3217
3218 }
3219 if (nextchild == child)
3220 break;
3221
3222 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3223 {
3224 lastchild = nextchild;
3225
3226 if (!fPrevious)
3227 break;
3228 }
3229
3230 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3231 }
3232 retvalue = lastchild->getWindowHandle();
3233END:
3234 return retvalue;
3235}
3236//******************************************************************************
3237//******************************************************************************
3238#ifdef DEBUG
3239void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3240{
3241 char style[256] = "";
3242 char exstyle[256] = "";
3243
3244 /* Window styles */
3245 if(dwStyle & WS_CHILD)
3246 strcat(style, "WS_CHILD ");
3247 if(dwStyle & WS_POPUP)
3248 strcat(style, "WS_POPUP ");
3249 if(dwStyle & WS_VISIBLE)
3250 strcat(style, "WS_VISIBLE ");
3251 if(dwStyle & WS_DISABLED)
3252 strcat(style, "WS_DISABLED ");
3253 if(dwStyle & WS_CLIPSIBLINGS)
3254 strcat(style, "WS_CLIPSIBLINGS ");
3255 if(dwStyle & WS_CLIPCHILDREN)
3256 strcat(style, "WS_CLIPCHILDREN ");
3257 if(dwStyle & WS_MAXIMIZE)
3258 strcat(style, "WS_MAXIMIZE ");
3259 if(dwStyle & WS_MINIMIZE)
3260 strcat(style, "WS_MINIMIZE ");
3261 if(dwStyle & WS_GROUP)
3262 strcat(style, "WS_GROUP ");
3263 if(dwStyle & WS_TABSTOP)
3264 strcat(style, "WS_TABSTOP ");
3265
3266 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3267 strcat(style, "WS_CAPTION ");
3268 if(dwStyle & WS_DLGFRAME)
3269 strcat(style, "WS_DLGFRAME ");
3270 if(dwStyle & WS_BORDER)
3271 strcat(style, "WS_BORDER ");
3272
3273 if(dwStyle & WS_VSCROLL)
3274 strcat(style, "WS_VSCROLL ");
3275 if(dwStyle & WS_HSCROLL)
3276 strcat(style, "WS_HSCROLL ");
3277 if(dwStyle & WS_SYSMENU)
3278 strcat(style, "WS_SYSMENU ");
3279 if(dwStyle & WS_THICKFRAME)
3280 strcat(style, "WS_THICKFRAME ");
3281 if(dwStyle & WS_MINIMIZEBOX)
3282 strcat(style, "WS_MINIMIZEBOX ");
3283 if(dwStyle & WS_MAXIMIZEBOX)
3284 strcat(style, "WS_MAXIMIZEBOX ");
3285
3286 if(dwExStyle & WS_EX_DLGMODALFRAME)
3287 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3288 if(dwExStyle & WS_EX_ACCEPTFILES)
3289 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3290 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3291 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3292 if(dwExStyle & WS_EX_TOPMOST)
3293 strcat(exstyle, "WS_EX_TOPMOST ");
3294 if(dwExStyle & WS_EX_TRANSPARENT)
3295 strcat(exstyle, "WS_EX_TRANSPARENT ");
3296
3297 if(dwExStyle & WS_EX_MDICHILD)
3298 strcat(exstyle, "WS_EX_MDICHILD ");
3299 if(dwExStyle & WS_EX_TOOLWINDOW)
3300 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3301 if(dwExStyle & WS_EX_WINDOWEDGE)
3302 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3303 if(dwExStyle & WS_EX_CLIENTEDGE)
3304 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3305 if(dwExStyle & WS_EX_CONTEXTHELP)
3306 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3307 if(dwExStyle & WS_EX_RIGHT)
3308 strcat(exstyle, "WS_EX_RIGHT ");
3309 if(dwExStyle & WS_EX_LEFT)
3310 strcat(exstyle, "WS_EX_LEFT ");
3311 if(dwExStyle & WS_EX_RTLREADING)
3312 strcat(exstyle, "WS_EX_RTLREADING ");
3313 if(dwExStyle & WS_EX_LTRREADING)
3314 strcat(exstyle, "WS_EX_LTRREADING ");
3315 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3316 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3317 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3318 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3319 if(dwExStyle & WS_EX_CONTROLPARENT)
3320 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3321 if(dwExStyle & WS_EX_STATICEDGE)
3322 strcat(exstyle, "WS_EX_STATICEDGE ");
3323 if(dwExStyle & WS_EX_APPWINDOW)
3324 strcat(exstyle, "WS_EX_APPWINDOW ");
3325
3326 dprintf(("Window style: %x %s", dwStyle, style));
3327 dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
3328}
3329#endif
3330//******************************************************************************
3331//******************************************************************************
3332
3333GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.