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

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

* empty log message *

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