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

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

Rewrote EnumThreadWindows/EnumWindows, Fixed GetParent

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