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

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

edit fixes, monitor API

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