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

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

MDI changes + WM_INITMENU support added + disabled experimental support for CS_PARENTDC style

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