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

Last change on this file since 2099 was 2099, checked in by cbratschi, 26 years ago

MDI cascade/tile, WM_PARENTNOTIFY cursor pos mapping, free timers after WM_DESTROY

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