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

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

Fix for crash during destruction of window with children

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