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

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

desktop + misc fixes

File size: 110.8 KB
Line 
1/* $Id: win32wbase.cpp,v 1.95 1999-11-25 19:22:02 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994 Alexandre Julliard
11 *
12 * TODO: Not thread/process safe
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17#include <os2win.h>
18#include <win.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdarg.h>
22#include <assert.h>
23#include <misc.h>
24#include <heapstring.h>
25#include <win32wbase.h>
26#include <winres.h>
27#include "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 FillRect( (HDC)wParam, &rect, windowClass->getBackgroundBrush());
1651
1652 return 1;
1653 }
1654 case WM_GETDLGCODE:
1655 return 0;
1656
1657 case WM_NCLBUTTONDOWN:
1658 case WM_NCLBUTTONUP:
1659 case WM_NCLBUTTONDBLCLK:
1660 case WM_NCRBUTTONUP:
1661 case WM_NCRBUTTONDOWN:
1662 case WM_NCRBUTTONDBLCLK:
1663 case WM_NCMBUTTONDOWN:
1664 case WM_NCMBUTTONUP:
1665 case WM_NCMBUTTONDBLCLK:
1666 return 0; //TODO: Send WM_SYSCOMMAND if required
1667
1668 case WM_NCHITTEST: //TODO: Calculate position of
1669 return HTCLIENT;
1670
1671 case WM_SYSCOMMAND:
1672 {
1673 POINT point;
1674
1675 point.x = LOWORD(lParam);
1676 point.y = HIWORD(lParam);
1677 return HandleSysCommand(wParam, &point);
1678 }
1679
1680 case WM_SYSKEYDOWN:
1681 if(wParam == VK_F4) /* try to close the window */
1682 {
1683 Win32BaseWindow *window = GetTopParent();
1684 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1685 window->PostMessageA(WM_SYSCOMMAND, SC_CLOSE, 0);
1686 }
1687
1688 Win32BaseWindow *siblingWindow;
1689 HWND sibling;
1690 char nameBuffer [40], mnemonic;
1691 int nameLength;
1692
1693 GetWindowTextA (nameBuffer, 40);
1694
1695 // search all sibling to see it this key is their mnemonic
1696 sibling = GetWindow (GW_HWNDFIRST);
1697 while (sibling != 0) {
1698 siblingWindow = GetWindowFromHandle (sibling);
1699 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1700
1701 // find the siblings mnemonic
1702 mnemonic = '\0';
1703 for (int i=0 ; i<nameLength ; i++) {
1704 if (nameBuffer [i] == '&') {
1705 mnemonic = nameBuffer [i+1];
1706 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1707 mnemonic -= 32; // make it uppercase
1708 break; // stop searching
1709 }
1710 }
1711
1712 // key matches siblings mnemonic, send mouseclick
1713 if (mnemonic == (char) wParam) {
1714 siblingWindow->SendMessageA (BM_CLICK, 0, 0);
1715 }
1716
1717 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1718 }
1719
1720 return 0;
1721
1722 case WM_QUERYOPEN:
1723 case WM_QUERYENDSESSION:
1724 return 1;
1725
1726 case WM_NOTIFYFORMAT:
1727 if (IsUnicode()) return NFR_UNICODE;
1728 else return NFR_ANSI;
1729
1730 case WM_SETICON:
1731 case WM_GETICON:
1732 {
1733 LRESULT result = 0;
1734 if (!windowClass) return result;
1735 int index = GCL_HICON;
1736
1737 if (wParam == ICON_SMALL)
1738 index = GCL_HICONSM;
1739
1740 result = windowClass->getClassLongA(index);
1741
1742 if (Msg == WM_SETICON)
1743 windowClass->setClassLongA(index, lParam);
1744
1745 return result;
1746 }
1747 case WM_NOTIFY:
1748 return 0; //comctl32 controls expect this
1749
1750 default:
1751 if(Msg > WM_USER) {
1752 return 0;
1753 }
1754 return 1;
1755 }
1756}
1757//******************************************************************************
1758//******************************************************************************
1759LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1760{
1761 switch(Msg)
1762 {
1763 case WM_GETTEXTLENGTH:
1764 return wndNameLength;
1765
1766 case WM_GETTEXT:
1767 if (!lParam || !wParam) return 0;
1768 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1769 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1770 return min(wndNameLength,wParam);
1771
1772 case WM_SETTEXT:
1773 {
1774 LPWSTR lpsz = (LPWSTR)lParam;
1775
1776 if(windowNameA) free(windowNameA);
1777 if(windowNameW) free(windowNameW);
1778
1779 if (lParam)
1780 {
1781 wndNameLength = lstrlenW(lpsz);
1782 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1783 lstrcpyWtoA(windowNameA,lpsz);
1784 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1785 lstrcpyW(windowNameW,lpsz);
1786 } else
1787 {
1788 windowNameA = NULL;
1789 windowNameW = NULL;
1790 wndNameLength = 0;
1791 }
1792
1793 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1794 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1795
1796 return TRUE;
1797 }
1798
1799 default:
1800 return DefWindowProcA(Msg, wParam, lParam);
1801 }
1802}
1803//******************************************************************************
1804//******************************************************************************
1805LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1806{
1807 LRESULT rc;
1808 BOOL fInternalMsgBackup = fInternalMsg;
1809
1810 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1811 // receive those before they get their WM_CREATE message
1812 //NOTE: May need to refuse more messages
1813 if(fCreated == FALSE && Msg == WM_COMMAND) {
1814 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1815 return 0;
1816 }
1817
1818 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, FALSE);
1819
1820 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1821 return(0);
1822 }
1823 fInternalMsg = FALSE;
1824 switch(Msg)
1825 {
1826 case WM_CREATE:
1827 {
1828 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1829 dprintf(("WM_CREATE returned -1\n"));
1830 rc = -1; //don't create window
1831 break;
1832 }
1833 NotifyParent(Msg, wParam, lParam);
1834
1835 rc = 0;
1836 break;
1837 }
1838 case WM_SETTEXT:
1839 rc = CallWindowProcA(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1840 break;
1841
1842 case WM_LBUTTONDOWN:
1843 case WM_MBUTTONDOWN:
1844 case WM_RBUTTONDOWN:
1845 NotifyParent(Msg, wParam, lParam);
1846 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1847 break;
1848
1849 case WM_DESTROY:
1850 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1851 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1852 break;
1853
1854 default:
1855 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1856 break;
1857 }
1858 fInternalMsg = fInternalMsgBackup;
1859 return rc;
1860}
1861//******************************************************************************
1862//******************************************************************************
1863LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1864{
1865 LRESULT rc;
1866 BOOL fInternalMsgBackup = fInternalMsg;
1867
1868 //SvL: Some Wine controls send WM_COMMAND messages when they receive the focus -> apps don't like to
1869 // receive those before they get their WM_CREATE message
1870 //NOTE: May need to refuse more messages
1871 if(fCreated == FALSE && Msg == WM_COMMAND) {
1872 dprintf(("SendMessageA BEFORE creation! %s for %x %x %x", GetMsgText(Msg), getWindowHandle(), wParam, lParam));
1873 return 0;
1874 }
1875
1876 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, FALSE);
1877
1878 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1879 return(0);
1880 }
1881 fInternalMsg = FALSE;
1882 switch(Msg)
1883 {
1884 case WM_CREATE:
1885 {
1886 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1887 dprintf(("WM_CREATE returned -1\n"));
1888 rc = -1; //don't create window
1889 break;
1890 }
1891 NotifyParent(Msg, wParam, lParam);
1892
1893 rc = 0;
1894 break;
1895 }
1896 case WM_SETTEXT:
1897 rc = CallWindowProcW(win32wndproc, getWindowHandle(), WM_SETTEXT, wParam, lParam);
1898 break;
1899
1900 case WM_LBUTTONDOWN:
1901 case WM_MBUTTONDOWN:
1902 case WM_RBUTTONDOWN:
1903 NotifyParent(Msg, wParam, lParam);
1904 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1905 break;
1906
1907 case WM_DESTROY:
1908 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1909 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1910 break;
1911
1912 default:
1913 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1914 break;
1915 }
1916 fInternalMsg = fInternalMsgBackup;
1917 return rc;
1918}
1919//******************************************************************************
1920//Called as a result of an OS/2 message
1921//******************************************************************************
1922LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1923{
1924 LRESULT rc;
1925 BOOL fInternalMsgBackup = fInternalMsg;
1926
1927 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
1928
1929 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1930 return(0);
1931 }
1932 fInternalMsg = TRUE;
1933 switch(Msg)
1934 {
1935 case WM_CREATE:
1936 {
1937 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1938 dprintf(("WM_CREATE returned -1\n"));
1939 rc = -1; //don't create window
1940 break;
1941 }
1942 NotifyParent(Msg, wParam, lParam);
1943 rc = 0;
1944 break;
1945 }
1946 case WM_LBUTTONDOWN:
1947 case WM_MBUTTONDOWN:
1948 case WM_RBUTTONDOWN:
1949 NotifyParent(Msg, wParam, lParam);
1950 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1951 break;
1952
1953 case WM_DESTROY:
1954 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
1955 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
1956 break;
1957
1958 default:
1959 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
1960 break;
1961 }
1962 fInternalMsg = fInternalMsgBackup;
1963 return rc;
1964}
1965//******************************************************************************
1966//Called as a result of an OS/2 message
1967//todo, unicode msgs (WM_SETTEXT etc)
1968//******************************************************************************
1969LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1970{
1971 LRESULT rc;
1972 BOOL fInternalMsgBackup = fInternalMsg;
1973
1974 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
1975
1976 if(HkCBT::OS2HkCBTProc(getWindowHandle(), Msg, wParam, lParam) == TRUE) {//hook swallowed msg
1977 return(0);
1978 }
1979 fInternalMsg = TRUE;
1980 switch(Msg)
1981 {
1982 case WM_CREATE:
1983 {
1984 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
1985 dprintf(("WM_CREATE returned -1\n"));
1986 rc = -1; //don't create window
1987 break;
1988 }
1989 NotifyParent(Msg, wParam, lParam);
1990 rc = 0;
1991 break;
1992 }
1993 case WM_LBUTTONDOWN:
1994 case WM_MBUTTONDOWN:
1995 case WM_RBUTTONDOWN:
1996 NotifyParent(Msg, wParam, lParam);
1997 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
1998 break;
1999
2000 case WM_DESTROY:
2001 win32wndproc(getWindowHandle(), WM_NCDESTROY, 0, 0);
2002 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2003 break;
2004 default:
2005 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2006 break;
2007 }
2008 fInternalMsg = fInternalMsgBackup;
2009 return rc;
2010}
2011//******************************************************************************
2012//******************************************************************************
2013BOOL Win32BaseWindow::PostMessageA(ULONG msg, WPARAM wParam, LPARAM lParam)
2014{
2015 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2016
2017 packet->Msg = msg;
2018 packet->wParam = wParam;
2019 packet->lParam = lParam;
2020 packet->fUnicode = FALSE;
2021 return OSLibPostMessage(OS2Hwnd, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2022}
2023//******************************************************************************
2024//******************************************************************************
2025BOOL Win32BaseWindow::PostMessageW(ULONG msg, WPARAM wParam, LPARAM lParam)
2026{
2027 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2028
2029 packet->Msg = msg;
2030 packet->wParam = wParam;
2031 packet->lParam = lParam;
2032 packet->fUnicode = TRUE;
2033 return OSLibPostMessage(OS2Hwnd, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2034}
2035//******************************************************************************
2036//******************************************************************************
2037BOOL Win32BaseWindow::PostThreadMessageA(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam)
2038{
2039 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2040
2041 packet->Msg = msg;
2042 packet->wParam = wParam;
2043 packet->lParam = lParam;
2044 packet->fUnicode = FALSE;
2045 return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2046}
2047//******************************************************************************
2048//******************************************************************************
2049BOOL Win32BaseWindow::PostThreadMessageW(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam)
2050{
2051 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2052
2053 packet->Msg = msg;
2054 packet->wParam = wParam;
2055 packet->lParam = lParam;
2056 packet->fUnicode = TRUE;
2057 return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2058}
2059//******************************************************************************
2060//******************************************************************************
2061void Win32BaseWindow::PostMessage(POSTMSG_PACKET *packet)
2062{
2063 if(packet == NULL)
2064 return;
2065
2066 if(packet->fUnicode) {
2067 SendMessageW(packet->Msg, packet->wParam, packet->lParam);
2068 }
2069 else SendMessageA(packet->Msg, packet->wParam, packet->lParam);
2070
2071 free(packet);
2072}
2073//******************************************************************************
2074//Send message to window of another process
2075//******************************************************************************
2076LRESULT Win32BaseWindow::SendMessageToProcess(UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2077{
2078 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
2079
2080 dprintf(("SendMessageToProcess %x %x %x %x", getOS2WindowHandle(), msg, wParam, lParam));
2081 packet->Msg = msg;
2082 packet->wParam = wParam;
2083 packet->lParam = lParam;
2084 packet->fUnicode = fUnicode;
2085 return OSLibSendMessage(getOS2WindowHandle(), WIN32APP_POSTMSG, WIN32PM_MAGIC, (DWORD)packet);
2086}
2087//******************************************************************************
2088//TODO: Do this more efficiently
2089//******************************************************************************
2090LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2091{
2092 Win32BaseWindow *window;
2093 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2094 DWORD processid, myprocessid;
2095
2096 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2097 myprocessid = GetCurrentProcessId();
2098
2099 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2100 window = GetWindowFromHandle(hwnd++);
2101 if(window) {
2102 if (window->getStyle() & WS_POPUP || (window->getStyle() & WS_CAPTION) == WS_CAPTION)
2103 {
2104
2105 if(type == BROADCAST_SEND) {
2106 GetWindowThreadProcessId(hwnd, &processid);
2107 if(processid == myprocessid) {
2108 window->SendMessageA(msg, wParam, lParam);
2109 }
2110 else {
2111 window->SendMessageToProcess(msg, wParam, lParam, FALSE);
2112 }
2113 }
2114 else window->PostMessageA(msg, wParam, lParam);
2115 }
2116 }
2117 }
2118 return 0;
2119}
2120//******************************************************************************
2121//TODO: Do this more efficiently
2122//******************************************************************************
2123LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2124{
2125 Win32BaseWindow *window;
2126 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2127 DWORD processid, myprocessid;
2128
2129
2130 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2131 myprocessid = GetCurrentProcessId();
2132
2133 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2134 window = GetWindowFromHandle(hwnd++);
2135 if(window) {
2136 if (window->getStyle() & WS_POPUP || (window->getStyle() & WS_CAPTION) == WS_CAPTION)
2137 {
2138
2139 if(type == BROADCAST_SEND) {
2140 GetWindowThreadProcessId(hwnd, &processid);
2141 if(processid == myprocessid) {
2142 window->SendMessageW(msg, wParam, lParam);
2143 }
2144 else {
2145 window->SendMessageToProcess(msg, wParam, lParam, TRUE);
2146 }
2147 }
2148 else window->PostMessageW(msg, wParam, lParam);
2149 }
2150 }
2151 }
2152 return 0;
2153}
2154//******************************************************************************
2155//TODO: do we need to inform the parent of the parent (etc) of the child window?
2156//******************************************************************************
2157void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2158{
2159 Win32BaseWindow *window = this;
2160 Win32BaseWindow *parentwindow;
2161
2162 while(window)
2163 {
2164 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2165 {
2166 /* Notify the parent window only */
2167 parentwindow = window->getParent();
2168 if(parentwindow) {
2169 if(Msg == WM_CREATE || Msg == WM_DESTROY) {
2170 parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), (LPARAM)window->getWindowHandle());
2171 }
2172 else parentwindow->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, window->getWindowId()), lParam );
2173 }
2174 }
2175 else break;
2176
2177 window = parentwindow;
2178 }
2179}
2180//******************************************************************************
2181//******************************************************************************
2182BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
2183{
2184
2185 dprintf(("SetMenu %x", hMenu));
2186 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
2187 if(OS2HwndMenu == 0) {
2188 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
2189 return FALSE;
2190 }
2191 return TRUE;
2192}
2193//******************************************************************************
2194//******************************************************************************
2195BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
2196{
2197 Win32Resource *winres = (Win32Resource *)hAccel;
2198 HANDLE accelhandle;
2199
2200 if(HIWORD(hAccel) == 0) {
2201 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
2202 SetLastError(ERROR_INVALID_PARAMETER);
2203 return FALSE;
2204 }
2205 acceltableResource = winres;
2206 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
2207 winres->setOS2Handle(accelhandle);
2208 return(accelhandle != 0);
2209}
2210//******************************************************************************
2211//******************************************************************************
2212BOOL Win32BaseWindow::SetIcon(HICON hIcon)
2213{
2214 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
2215 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
2216//TODO: Wine does't send these. Correct?
2217// SendMessageA(WM_SETICON, ICON_BIG, hIcon);
2218 return TRUE;
2219 }
2220 return FALSE;
2221}
2222//******************************************************************************
2223//******************************************************************************
2224BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2225{
2226 ULONG showstate = 0;
2227 HWND hWinAfter;
2228
2229 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2230#if 1
2231 if (flags & WIN_NEED_SIZE)
2232 {
2233 /* should happen only in CreateWindowEx() */
2234 int wParam = SIZE_RESTORED;
2235
2236 flags &= ~WIN_NEED_SIZE;
2237 if (dwStyle & WS_MAXIMIZE)
2238 wParam = SIZE_MAXIMIZED;
2239 else
2240 if (dwStyle & WS_MINIMIZE)
2241 wParam = SIZE_MINIMIZED;
2242
2243 SendMessageA(WM_SIZE, wParam,
2244 MAKELONG(rectClient.right-rectClient.left,
2245 rectClient.bottom-rectClient.top));
2246 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2247 }
2248#else
2249 if(fFirstShow) {
2250 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
2251 SendMessageA(WM_SIZE, SIZE_RESTORED,
2252 MAKELONG(rectClient.right-rectClient.left,
2253 rectClient.bottom-rectClient.top));
2254 SendMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2255
2256 }
2257 fFirstShow = FALSE;
2258 }
2259#endif
2260 switch(nCmdShow)
2261 {
2262 case SW_SHOW:
2263 case SW_SHOWDEFAULT: //todo
2264 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2265 break;
2266 case SW_HIDE:
2267 showstate = SWPOS_HIDE;
2268 break;
2269 case SW_RESTORE:
2270 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2271 break;
2272 case SW_MINIMIZE:
2273 showstate = SWPOS_MINIMIZE;
2274 break;
2275 case SW_SHOWMAXIMIZED:
2276 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2277 break;
2278 case SW_SHOWMINIMIZED:
2279 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2280 break;
2281 case SW_SHOWMINNOACTIVE:
2282 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2283 break;
2284 case SW_SHOWNA:
2285 showstate = SWPOS_SHOW;
2286 break;
2287 case SW_SHOWNOACTIVATE:
2288 showstate = SWPOS_SHOW;
2289 break;
2290 case SW_SHOWNORMAL:
2291 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2292 break;
2293 }
2294
2295 /* We can't activate a child window (WINE) */
2296 if(getStyle() & WS_CHILD)
2297 showstate &= ~SWPOS_ACTIVATE;
2298
2299 if(showstate & SWPOS_SHOW) {
2300 setStyle(getStyle() | WS_VISIBLE);
2301 }
2302 else setStyle(getStyle() & ~WS_VISIBLE);
2303
2304 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2305 return rc;
2306}
2307//******************************************************************************
2308//******************************************************************************
2309BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2310{
2311 BOOL rc = FALSE;
2312 Win32BaseWindow *window;
2313 HWND hParent = 0;
2314
2315 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2316
2317 if (fuFlags &
2318 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2319 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2320 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2321 SWP_NOOWNERZORDER))
2322 {
2323 return FALSE;
2324 }
2325
2326 WINDOWPOS wpos;
2327 SWP swp, swpOld;
2328
2329 wpos.flags = fuFlags;
2330 wpos.cy = cy;
2331 wpos.cx = cx;
2332 wpos.x = x;
2333 wpos.y = y;
2334 wpos.hwndInsertAfter = hwndInsertAfter;
2335 wpos.hwnd = getWindowHandle();
2336
2337 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2338 {
2339 if (isChild())
2340 {
2341 hParent = getParent()->getOS2WindowHandle();
2342 }
2343 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2344 }
2345
2346 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2347 if (swp.fl == 0)
2348 return TRUE;
2349
2350// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2351 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2352 {
2353 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2354 if(wndBehind) {
2355 swp.hwndInsertBehind = wndBehind->getOS2WindowHandle();
2356 }
2357 else {
2358 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2359 swp.hwndInsertBehind = 0;
2360 }
2361 }
2362#if 0
2363 if (isFrameWindow())
2364 {
2365 if (!isChild())
2366 {
2367 POINT maxSize, maxPos, minTrack, maxTrack;
2368
2369 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2370
2371 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2372 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2373 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2374 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2375 }
2376 swp.hwnd = OS2HwndFrame;
2377 }
2378 else
2379#endif
2380 swp.hwnd = OS2HwndFrame;
2381
2382 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2383
2384 rc = OSLibWinSetMultWindowPos(&swp, 1);
2385
2386 if (rc == FALSE)
2387 {
2388 dprintf(("OSLibWinSetMultWindowPos failed!"));
2389 }
2390 else
2391 {
2392 if (fuFlags & SWP_FRAMECHANGED_W)
2393 OSLibSendMessage (OS2HwndFrame, 0x42 /*WM_UPDATEFRAME*/, -1, 0);
2394 }
2395
2396 return (rc);
2397}
2398//******************************************************************************
2399//TODO: WPF_RESTOREMAXIMIZED
2400//******************************************************************************
2401BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2402{
2403 if(isFrameWindow())
2404 {
2405 // Set the minimized position
2406 if (winpos->flags & WPF_SETMINPOSITION)
2407 {
2408 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2409 }
2410
2411 //TODO: Max position
2412
2413 // Set the new restore position.
2414 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2415 }
2416
2417 return ShowWindow(winpos->showCmd);
2418}
2419//******************************************************************************
2420//Also destroys all the child windows (destroy parent, destroy children)
2421//******************************************************************************
2422BOOL Win32BaseWindow::DestroyWindow()
2423{
2424 return OSLibWinDestroyWindow(OS2HwndFrame);
2425}
2426//******************************************************************************
2427//******************************************************************************
2428HWND Win32BaseWindow::GetParent()
2429{
2430 if(getParent()) {
2431 return getParent()->getWindowHandle();
2432 }
2433 else return 0;
2434}
2435//******************************************************************************
2436//******************************************************************************
2437HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2438{
2439 HWND oldhwnd;
2440 Win32BaseWindow *newparent;
2441
2442 if(getParent()) {
2443 oldhwnd = getParent()->getWindowHandle();
2444 getParent()->RemoveChild(this);
2445 }
2446 else oldhwnd = 0;
2447
2448 newparent = GetWindowFromHandle(hwndNewParent);
2449 if(newparent)
2450 {
2451 setParent(newparent);
2452 getParent()->AddChild(this);
2453 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2454 return oldhwnd;
2455 }
2456 else {
2457 setParent(windowDesktop);
2458 getParent()->AddChild(this);
2459 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2460 return oldhwnd;
2461 }
2462}
2463//******************************************************************************
2464//******************************************************************************
2465BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2466{
2467 if(getParent()) {
2468 return getParent()->getWindowHandle() == hwndParent;
2469 }
2470 else return 0;
2471}
2472//******************************************************************************
2473//******************************************************************************
2474HWND Win32BaseWindow::GetTopWindow()
2475{
2476 return GetWindow(GW_CHILD);
2477}
2478//******************************************************************************
2479// Get the top-level parent for a child window.
2480//******************************************************************************
2481Win32BaseWindow *Win32BaseWindow::GetTopParent()
2482{
2483 Win32BaseWindow *window = this;
2484
2485 while(window && (window->getStyle() & WS_CHILD))
2486 {
2487 window = window->getParent();
2488 }
2489 return window;
2490}
2491//******************************************************************************
2492//Don't call WinUpdateWindow as that one also updates the child windows
2493//Also need to send WM_PAINT directly to the window procedure, which doesn't
2494//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2495//******************************************************************************
2496BOOL Win32BaseWindow::UpdateWindow()
2497{
2498 RECT rect;
2499
2500 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2501 {//update region not empty
2502 HDC hdc;
2503
2504 hdc = O32_GetDC(OS2Hwnd);
2505 if (isIcon)
2506 {
2507 SendMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2508 SendMessageA(WM_PAINTICON, 0, 0);
2509 } else
2510 {
2511 SendMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2512 SendMessageA(WM_PAINT, 0, 0);
2513 }
2514 O32_ReleaseDC(OS2Hwnd, hdc);
2515 }
2516 return TRUE;
2517}
2518//******************************************************************************
2519//******************************************************************************
2520BOOL Win32BaseWindow::IsIconic()
2521{
2522 return OSLibWinIsIconic(OS2Hwnd);
2523}
2524//******************************************************************************
2525//TODO: Should not enumerate children that are created during the enumeration!
2526//******************************************************************************
2527BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2528{
2529 BOOL rc = TRUE;
2530 HWND hwnd;
2531 Win32BaseWindow *prevchild = 0, *child = 0;
2532
2533 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2534 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2535 {
2536 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2537 hwnd = child->getWindowHandle();
2538 if(lpfn(hwnd, lParam) == FALSE)
2539 {
2540 rc = FALSE;
2541 break;
2542 }
2543 //check if the window still exists
2544 if(!::IsWindow(hwnd))
2545 {
2546 child = prevchild;
2547 continue;
2548 }
2549 if(child->getFirstChild() != NULL)
2550 {
2551 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2552 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2553 {
2554 rc = FALSE;
2555 break;
2556 }
2557 }
2558 prevchild = child;
2559 }
2560 return rc;
2561}
2562//******************************************************************************
2563//******************************************************************************
2564Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2565{
2566 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2567 {
2568 if (child->getWindowId() == id)
2569 {
2570 return child;
2571 }
2572 }
2573 return 0;
2574}
2575//******************************************************************************
2576//TODO:
2577//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2578//the current process owns them.
2579//******************************************************************************
2580HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2581 BOOL fUnicode)
2582{
2583 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2584 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2585
2586 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2587 (hwndChildAfter != 0 && !child) ||
2588 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2589 {
2590 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2591 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2592 return 0;
2593 }
2594 if(hwndParent != OSLIB_HWND_DESKTOP)
2595 {//if the current process owns the window, just do a quick search
2596 child = (Win32BaseWindow *)parent->getFirstChild();
2597 if(hwndChildAfter != 0)
2598 {
2599 while(child)
2600 {
2601 if(child->getWindowHandle() == hwndChildAfter)
2602 {
2603 child = (Win32BaseWindow *)child->getNextChild();
2604 break;
2605 }
2606 child = (Win32BaseWindow *)child->getNextChild();
2607 }
2608 }
2609 while(child)
2610 {
2611 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2612 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2613 {
2614 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2615 return child->getWindowHandle();
2616 }
2617 child = (Win32BaseWindow *)child->getNextChild();
2618 }
2619 }
2620 else {
2621 Win32BaseWindow *wnd;
2622 HWND henum, hwnd;
2623
2624 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2625 hwnd = OSLibWinGetNextWindow(henum);
2626
2627 while(hwnd)
2628 {
2629 wnd = GetWindowFromOS2Handle(hwnd);
2630 if(wnd == NULL) {
2631 hwnd = OSLibWinQueryClientWindow(hwnd);
2632 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2633 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2634 }
2635
2636 if(wnd) {
2637 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2638 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2639 {
2640 OSLibWinEndEnumWindows(henum);
2641 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2642 return wnd->getWindowHandle();
2643 }
2644 }
2645 hwnd = OSLibWinGetNextWindow(henum);
2646 }
2647 OSLibWinEndEnumWindows(henum);
2648 }
2649 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2650 return 0;
2651}
2652//******************************************************************************
2653//******************************************************************************
2654HWND Win32BaseWindow::GetWindow(UINT uCmd)
2655{
2656 HWND hwndRelated = 0;
2657 Win32BaseWindow *window;
2658
2659 switch(uCmd)
2660 {
2661 case GW_HWNDFIRST:
2662 if(getParent()) {
2663 window = (Win32BaseWindow *)getParent()->getFirstChild();
2664 hwndRelated = window->getWindowHandle();
2665 }
2666 break;
2667
2668 case GW_HWNDLAST:
2669 if(getParent())
2670 {
2671 goto end;
2672 }
2673
2674 window = this;
2675 while(window)
2676 {
2677 window = (Win32BaseWindow *)window->getNextChild();
2678 }
2679 hwndRelated = window->getWindowHandle();
2680 break;
2681
2682 case GW_HWNDNEXT:
2683 window = (Win32BaseWindow *)getNextChild();
2684 if(window) {
2685 hwndRelated = window->getWindowHandle();
2686 }
2687 break;
2688
2689 case GW_HWNDPREV:
2690 if(!getParent())
2691 {
2692 goto end;
2693 }
2694 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2695 if(window == this)
2696 {
2697 hwndRelated = 0; /* First in list */
2698 goto end;
2699 }
2700 while(window->getNextChild())
2701 {
2702 if (window->getNextChild() == this)
2703 {
2704 hwndRelated = window->getWindowHandle();
2705 goto end;
2706 }
2707 window = (Win32BaseWindow *)window->getNextChild();
2708 }
2709 break;
2710
2711 case GW_OWNER:
2712 if(getOwner()) {
2713 hwndRelated = getOwner()->getWindowHandle();
2714 }
2715 break;
2716
2717 case GW_CHILD:
2718 if(getFirstChild()) {
2719 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2720 }
2721 break;
2722 }
2723end:
2724 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2725 return hwndRelated;
2726}
2727//******************************************************************************
2728//******************************************************************************
2729HWND Win32BaseWindow::SetActiveWindow()
2730{
2731 return OSLibWinSetActiveWindow(OS2HwndFrame);
2732}
2733//******************************************************************************
2734//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2735//******************************************************************************
2736BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2737{
2738 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2739}
2740//******************************************************************************
2741//******************************************************************************
2742BOOL Win32BaseWindow::CloseWindow()
2743{
2744 return OSLibWinMinimizeWindow(OS2HwndFrame);
2745}
2746//******************************************************************************
2747//******************************************************************************
2748HWND Win32BaseWindow::GetActiveWindow()
2749{
2750 HWND hwndActive;
2751 Win32BaseWindow *win32wnd;
2752 ULONG magic;
2753
2754 hwndActive = OSLibWinQueryActiveWindow();
2755
2756 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2757 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2758 if(CheckMagicDword(magic) && win32wnd)
2759 {
2760 return win32wnd->getWindowHandle();
2761 }
2762 return hwndActive;
2763}
2764//******************************************************************************
2765//******************************************************************************
2766BOOL Win32BaseWindow::IsWindowEnabled()
2767{
2768 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2769}
2770//******************************************************************************
2771//******************************************************************************
2772BOOL Win32BaseWindow::IsWindowVisible()
2773{
2774#if 1
2775 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2776#else
2777 return OSLibWinIsWindowVisible(OS2HwndFrame);
2778#endif
2779}
2780//******************************************************************************
2781//******************************************************************************
2782BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2783{
2784 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2785}
2786//******************************************************************************
2787//******************************************************************************
2788BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2789{
2790 if(wndname == NULL)
2791 return FALSE;
2792
2793 if(fUnicode) {
2794 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2795 }
2796 else return (strcmp(windowNameA, wndname) == 0);
2797}
2798//******************************************************************************
2799//******************************************************************************
2800int Win32BaseWindow::GetWindowTextLength()
2801{
2802 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2803}
2804//******************************************************************************
2805//******************************************************************************
2806int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2807{
2808 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2809}
2810//******************************************************************************
2811//******************************************************************************
2812int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2813{
2814 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2815}
2816//******************************************************************************
2817//******************************************************************************
2818BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2819{
2820 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2821}
2822//******************************************************************************
2823//******************************************************************************
2824BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2825{
2826 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2827}
2828//******************************************************************************
2829//******************************************************************************
2830VOID Win32BaseWindow::updateWindowStyle(DWORD oldExStyle,DWORD oldStyle)
2831{
2832 if(IsWindowDestroyed()) return;
2833
2834/*
2835 if (isChild())
2836 {
2837 DWORD dwOSWinStyle,dwOSFrameStyle,newBorderWidth,newBorderHeight;
2838
2839 OSLibWinConvertStyle(dwStyle,&dwExStyle,&dwOSWinStyle,&dwOSFrameStyle,&newBorderWidth,&newBorderHeight);
2840 if (newBorderWidth != borderWidth || newBorderHeight != borderHeight)
2841 {
2842 borderWidth = newBorderWidth;
2843 borderHeight = newBorderHeight;
2844 FrameSetBorderSize(this,TRUE);
2845 }
2846 }
2847*/
2848
2849 if (dwStyle != oldStyle) OSLibSetWindowStyle(OS2HwndFrame,dwStyle);
2850}
2851//******************************************************************************
2852//******************************************************************************
2853LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value)
2854{
2855 LONG oldval;
2856
2857 dprintf2(("SetWindowLongA %x %d %x", getWindowHandle(), index, value));
2858 switch(index) {
2859 case GWL_EXSTYLE:
2860 {
2861 STYLESTRUCT ss;
2862
2863 if(dwExStyle == value)
2864 return value;
2865
2866 ss.styleOld = dwExStyle;
2867 ss.styleNew = value;
2868 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2869 SendMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2870 setExStyle(ss.styleNew);
2871 updateWindowStyle(ss.styleOld,getStyle());
2872 SendMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2873 return ss.styleOld;
2874 }
2875 case GWL_STYLE:
2876 {
2877 STYLESTRUCT ss;
2878
2879 if(dwStyle == value)
2880 return value;
2881
2882 value &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way (WINE) */
2883 ss.styleOld = getStyle();
2884 ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
2885 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), getStyle(), value));
2886 SendMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2887 setStyle(ss.styleNew);
2888 updateWindowStyle(dwExStyle,ss.styleOld);
2889 SendMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2890#ifdef DEBUG
2891 PrintWindowStyle(ss.styleNew, 0);
2892#endif
2893 return ss.styleOld;
2894 }
2895 case GWL_WNDPROC:
2896 oldval = (LONG)getWindowProc();
2897 setWindowProc((WNDPROC)value);
2898 return oldval;
2899 case GWL_HINSTANCE:
2900 oldval = hInstance;
2901 hInstance = value;
2902 return oldval;
2903 case GWL_HWNDPARENT:
2904 return SetParent((HWND)value);
2905 case GWL_ID:
2906 oldval = getWindowId();
2907 setWindowId(value);
2908 return oldval;
2909 case GWL_USERDATA:
2910 oldval = userData;
2911 userData = value;
2912 return oldval;
2913 default:
2914 if(index >= 0 && index/4 < nrUserWindowLong)
2915 {
2916 oldval = userWindowLong[index/4];
2917 userWindowLong[index/4] = value;
2918 return oldval;
2919 }
2920 SetLastError(ERROR_INVALID_PARAMETER);
2921 return 0;
2922 }
2923}
2924//******************************************************************************
2925//******************************************************************************
2926ULONG Win32BaseWindow::GetWindowLongA(int index)
2927{
2928 ULONG value;
2929
2930 switch(index) {
2931 case GWL_EXSTYLE:
2932 value = dwExStyle;
2933 break;
2934 case GWL_STYLE:
2935 value = dwStyle;
2936 break;
2937 case GWL_WNDPROC:
2938 value = (ULONG)getWindowProc();
2939 break;
2940 case GWL_HINSTANCE:
2941 value = hInstance;
2942 break;
2943 case GWL_HWNDPARENT:
2944 if(getParent()) {
2945 value = getParent()->getWindowHandle();
2946 }
2947 else value = 0;
2948 break;
2949 case GWL_ID:
2950 value = getWindowId();
2951 break;
2952 case GWL_USERDATA:
2953 value = userData;
2954 break;
2955 default:
2956 if(index >= 0 && index/4 < nrUserWindowLong)
2957 {
2958 value = userWindowLong[index/4];
2959 break;
2960 }
2961 SetLastError(ERROR_INVALID_PARAMETER);
2962 return 0;
2963 }
2964 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
2965 return value;
2966}
2967//******************************************************************************
2968//******************************************************************************
2969WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
2970{
2971 WORD oldval;
2972
2973 if(index >= 0 && index/4 < nrUserWindowLong)
2974 {
2975 oldval = ((WORD *)userWindowLong)[index/2];
2976 ((WORD *)userWindowLong)[index/2] = value;
2977 return oldval;
2978 }
2979 SetLastError(ERROR_INVALID_PARAMETER);
2980 return 0;
2981}
2982//******************************************************************************
2983//******************************************************************************
2984WORD Win32BaseWindow::GetWindowWord(int index)
2985{
2986 if(index >= 0 && index/4 < nrUserWindowLong)
2987 {
2988 return ((WORD *)userWindowLong)[index/2];
2989 }
2990 SetLastError(ERROR_INVALID_PARAMETER);
2991 return 0;
2992}
2993//******************************************************************************
2994//******************************************************************************
2995void Win32BaseWindow::setWindowId(DWORD id)
2996{
2997 windowId = id;
2998 dprintf(("Set window ID to %x", id));
2999 OSLibSetWindowID(OS2HwndFrame, id);
3000}
3001//******************************************************************************
3002//******************************************************************************
3003Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3004{
3005 Win32BaseWindow *window;
3006
3007 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3008 return window;
3009 }
3010 else return NULL;
3011}
3012//******************************************************************************
3013//******************************************************************************
3014Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3015{
3016 Win32BaseWindow *win32wnd;
3017 DWORD magic;
3018
3019 if(hwnd == OSLIB_HWND_DESKTOP)
3020 {
3021 return windowDesktop;
3022 }
3023
3024 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3025 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3026
3027 if(win32wnd && CheckMagicDword(magic)) {
3028 return win32wnd;
3029 }
3030 return 0;
3031}
3032//******************************************************************************
3033//******************************************************************************
3034Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3035{
3036 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3037}
3038//******************************************************************************
3039//******************************************************************************
3040HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3041{
3042 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3043
3044 if(window) {
3045 return window->getOS2WindowHandle();
3046 }
3047 else return hwnd;
3048}
3049//******************************************************************************
3050//******************************************************************************
3051HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
3052{
3053 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3054
3055 if(window) {
3056 return window->getOS2FrameWindowHandle();
3057 }
3058 else return hwnd;
3059}
3060//******************************************************************************
3061//******************************************************************************
3062HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3063{
3064 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3065
3066 if(window) {
3067 return window->getWindowHandle();
3068 }
3069 window = GetWindowFromOS2FrameHandle(hwnd);
3070 if(window) {
3071 return window->getWindowHandle();
3072 }
3073 else return 0;
3074// else return hwnd; //OS/2 window handle
3075}
3076//******************************************************************************
3077// GetNextDlgTabItem32 (USER32.276)
3078//******************************************************************************
3079HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3080{
3081 Win32BaseWindow *child, *nextchild, *lastchild;
3082 HWND retvalue;
3083
3084 if (hwndCtrl)
3085 {
3086 child = GetWindowFromHandle(hwndCtrl);
3087 if (!child)
3088 {
3089 retvalue = 0;
3090 goto END;
3091 }
3092 /* Make sure hwndCtrl is a top-level child */
3093 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3094 {
3095 child = child->getParent();
3096 if(child == NULL) break;
3097 }
3098
3099 if (!child || child->getParent() != this)
3100 {
3101 retvalue = 0;
3102 goto END;
3103 }
3104 }
3105 else
3106 {
3107 /* No ctrl specified -> start from the beginning */
3108 child = (Win32BaseWindow *)getFirstChild();
3109 if (!child)
3110 {
3111 retvalue = 0;
3112 goto END;
3113 }
3114
3115 if (!fPrevious)
3116 {
3117 while (child->getNextChild())
3118 {
3119 child = (Win32BaseWindow *)child->getNextChild();
3120 }
3121 }
3122 }
3123
3124 lastchild = child;
3125 nextchild = (Win32BaseWindow *)child->getNextChild();
3126 while (TRUE)
3127 {
3128 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3129
3130 if (child == nextchild) break;
3131
3132 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3133 !(nextchild->getStyle() & WS_DISABLED))
3134 {
3135 lastchild = nextchild;
3136 if (!fPrevious) break;
3137 }
3138 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3139 }
3140 retvalue = lastchild->getWindowHandle();
3141
3142END:
3143 return retvalue;
3144}
3145//******************************************************************************
3146//******************************************************************************
3147HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3148{
3149 Win32BaseWindow *child, *nextchild, *lastchild;
3150 HWND retvalue;
3151
3152 if (hwndCtrl)
3153 {
3154 child = GetWindowFromHandle(hwndCtrl);
3155 if (!child)
3156 {
3157 retvalue = 0;
3158 goto END;
3159 }
3160 /* Make sure hwndCtrl is a top-level child */
3161 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3162 {
3163 child = child->getParent();
3164 if(child == NULL) break;
3165 }
3166
3167 if (!child || child->getParent() != this)
3168 {
3169 retvalue = 0;
3170 goto END;
3171 }
3172 }
3173 else
3174 {
3175 /* No ctrl specified -> start from the beginning */
3176 child = (Win32BaseWindow *)getFirstChild();
3177 if (!child)
3178 {
3179 retvalue = 0;
3180 goto END;
3181 }
3182
3183 if (fPrevious)
3184 {
3185 while (child->getNextChild())
3186 {
3187 child = (Win32BaseWindow *)child->getNextChild();
3188 }
3189 }
3190 }
3191
3192 lastchild = child;
3193 nextchild = (Win32BaseWindow *)child->getNextChild();
3194 while (TRUE)
3195 {
3196 if (!nextchild || nextchild->getStyle() & WS_GROUP)
3197 {
3198 /* Wrap-around to the beginning of the group */
3199 Win32BaseWindow *pWndTemp;
3200
3201 nextchild = (Win32BaseWindow *)getFirstChild();
3202
3203 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3204 {
3205 if (pWndTemp->getStyle() & WS_GROUP)
3206 nextchild = pWndTemp;
3207
3208 if (pWndTemp == child)
3209 break;
3210 }
3211
3212 }
3213 if (nextchild == child)
3214 break;
3215
3216 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3217 {
3218 lastchild = nextchild;
3219
3220 if (!fPrevious)
3221 break;
3222 }
3223
3224 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3225 }
3226 retvalue = lastchild->getWindowHandle();
3227END:
3228 return retvalue;
3229}
3230//******************************************************************************
3231//******************************************************************************
3232#ifdef DEBUG
3233void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3234{
3235 char style[256] = "";
3236 char exstyle[256] = "";
3237
3238 /* Window styles */
3239 if(dwStyle & WS_CHILD)
3240 strcat(style, "WS_CHILD ");
3241 if(dwStyle & WS_POPUP)
3242 strcat(style, "WS_POPUP ");
3243 if(dwStyle & WS_VISIBLE)
3244 strcat(style, "WS_VISIBLE ");
3245 if(dwStyle & WS_DISABLED)
3246 strcat(style, "WS_DISABLED ");
3247 if(dwStyle & WS_CLIPSIBLINGS)
3248 strcat(style, "WS_CLIPSIBLINGS ");
3249 if(dwStyle & WS_CLIPCHILDREN)
3250 strcat(style, "WS_CLIPCHILDREN ");
3251 if(dwStyle & WS_MAXIMIZE)
3252 strcat(style, "WS_MAXIMIZE ");
3253 if(dwStyle & WS_MINIMIZE)
3254 strcat(style, "WS_MINIMIZE ");
3255 if(dwStyle & WS_GROUP)
3256 strcat(style, "WS_GROUP ");
3257 if(dwStyle & WS_TABSTOP)
3258 strcat(style, "WS_TABSTOP ");
3259
3260 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3261 strcat(style, "WS_CAPTION ");
3262 if(dwStyle & WS_DLGFRAME)
3263 strcat(style, "WS_DLGFRAME ");
3264 if(dwStyle & WS_BORDER)
3265 strcat(style, "WS_BORDER ");
3266
3267 if(dwStyle & WS_VSCROLL)
3268 strcat(style, "WS_VSCROLL ");
3269 if(dwStyle & WS_HSCROLL)
3270 strcat(style, "WS_HSCROLL ");
3271 if(dwStyle & WS_SYSMENU)
3272 strcat(style, "WS_SYSMENU ");
3273 if(dwStyle & WS_THICKFRAME)
3274 strcat(style, "WS_THICKFRAME ");
3275 if(dwStyle & WS_MINIMIZEBOX)
3276 strcat(style, "WS_MINIMIZEBOX ");
3277 if(dwStyle & WS_MAXIMIZEBOX)
3278 strcat(style, "WS_MAXIMIZEBOX ");
3279
3280 if(dwExStyle & WS_EX_DLGMODALFRAME)
3281 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3282 if(dwExStyle & WS_EX_ACCEPTFILES)
3283 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3284 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3285 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3286 if(dwExStyle & WS_EX_TOPMOST)
3287 strcat(exstyle, "WS_EX_TOPMOST ");
3288 if(dwExStyle & WS_EX_TRANSPARENT)
3289 strcat(exstyle, "WS_EX_TRANSPARENT ");
3290
3291 if(dwExStyle & WS_EX_MDICHILD)
3292 strcat(exstyle, "WS_EX_MDICHILD ");
3293 if(dwExStyle & WS_EX_TOOLWINDOW)
3294 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3295 if(dwExStyle & WS_EX_WINDOWEDGE)
3296 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3297 if(dwExStyle & WS_EX_CLIENTEDGE)
3298 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3299 if(dwExStyle & WS_EX_CONTEXTHELP)
3300 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3301 if(dwExStyle & WS_EX_RIGHT)
3302 strcat(exstyle, "WS_EX_RIGHT ");
3303 if(dwExStyle & WS_EX_LEFT)
3304 strcat(exstyle, "WS_EX_LEFT ");
3305 if(dwExStyle & WS_EX_RTLREADING)
3306 strcat(exstyle, "WS_EX_RTLREADING ");
3307 if(dwExStyle & WS_EX_LTRREADING)
3308 strcat(exstyle, "WS_EX_LTRREADING ");
3309 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3310 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3311 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3312 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3313 if(dwExStyle & WS_EX_CONTROLPARENT)
3314 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3315 if(dwExStyle & WS_EX_STATICEDGE)
3316 strcat(exstyle, "WS_EX_STATICEDGE ");
3317 if(dwExStyle & WS_EX_APPWINDOW)
3318 strcat(exstyle, "WS_EX_APPWINDOW ");
3319
3320 dprintf(("Window style: %x %s", dwStyle, style));
3321 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3322}
3323#endif
3324//******************************************************************************
3325//******************************************************************************
3326
3327GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.