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

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

EB's SetWindowPos fix

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