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

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

Implemented Set/GetWindowRgn (not activated)

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