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

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

new mapping functions, fixed 1 pixel and window handle bugs

File size: 109.4 KB
Line 
1/* $Id: win32wbase.cpp,v 1.125 1999-12-29 22:54:02 cbratschi Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 * Parts based on Wine Windows code (windows\win.c)
9 *
10 * Copyright 1993, 1994, 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 acceltableResource = NULL;
195 iconResource = NULL;
196
197 EraseBkgndFlag = TRUE;
198 PSEraseFlag = FALSE;
199 SuppressEraseFlag = FALSE;
200
201 horzScrollInfo = NULL;
202 vertScrollInfo = NULL;
203 hwndHorzScroll = 0;
204 hwndVertScroll = 0;
205
206 ownDC = 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, accel, 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 if(fNoSizeMsg)
825 return 1;
826
827 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
828}
829//******************************************************************************
830//******************************************************************************
831ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
832{
833 if(fNoSizeMsg)
834 return 1;
835
836 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
837}
838//******************************************************************************
839//******************************************************************************
840#if 0
841ULONG Win32BaseWindow::MsgMinMax()
842{
843
844}
845#endif
846//******************************************************************************
847//******************************************************************************
848ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
849{
850 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
851 //window scrollbars send these messages
852 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
853}
854//******************************************************************************
855//******************************************************************************
856ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
857{
858 lastHitTestVal = SendInternalMessageA(WM_NCHITTEST, 0, MAKELONG((USHORT)msg->pt.x, (USHORT)msg->pt.y));
859 dprintf2(("MsgHitTest returned %x", lastHitTestVal));
860
861 if (lastHitTestVal == HTERROR)
862 return HTOS_ERROR;
863
864#if 0 //CB: problems with groupboxes, internal handling is better
865 if (lastHitTestVal == HTTRANSPARENT)
866 return HTOS_TRANSPARENT;
867#endif
868
869 return HTOS_NORMAL;
870}
871//******************************************************************************
872//******************************************************************************
873ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
874{
875 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
876
877
878 //According to SDK docs, if app returns FALSE & window is being deactivated,
879 //default processing is cancelled
880 //TODO: According to Wine we should proceed anyway if window is sysmodal
881 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
882 {
883 return 0;
884 }
885 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
886
887 curprocid = GetCurrentProcessId();
888 if(hwnd) {
889 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
890 }
891
892 if(curprocid != procidhwnd && fActivate) {
893 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
894 }
895 return rc;
896}
897//******************************************************************************
898//TODO: Is this correct and complete?
899//Add print screen, break & numlock
900//******************************************************************************
901void Win32BaseWindow::setExtendedKey(ULONG virtualkey, ULONG *lParam)
902{
903 switch(virtualkey) {
904 case VK_DOWN:
905 case VK_UP:
906 case VK_PRIOR:
907 case VK_NEXT:
908 case VK_END:
909 case VK_DIVIDE:
910 case VK_DELETE:
911 case VK_EXECUTE: //Numeric enter key?
912 case VK_HOME:
913 case VK_INSERT:
914 case VK_RCONTROL:
915 case VK_RMENU: //is this the right alt???
916 *lParam = *lParam | (1<<24);
917 }
918}
919//******************************************************************************
920//******************************************************************************
921ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
922{
923 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
924}
925//******************************************************************************
926//******************************************************************************
927ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
928{
929 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
930}
931//******************************************************************************
932//******************************************************************************
933ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
934{
935 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
936}
937//******************************************************************************
938//******************************************************************************
939ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
940{
941 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
942}
943//******************************************************************************
944//******************************************************************************
945ULONG Win32BaseWindow::MsgButton(MSG *msg)
946{
947 BOOL fClick = FALSE;
948
949 dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
950 switch(msg->message) {
951 case WM_LBUTTONDBLCLK:
952 case WM_RBUTTONDBLCLK:
953 case WM_MBUTTONDBLCLK:
954 case WM_NCLBUTTONDBLCLK:
955 case WM_NCRBUTTONDBLCLK:
956 case WM_NCMBUTTONDBLCLK:
957 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
958 {
959 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
960 MsgButton(msg);
961 msg->message++; //button-up
962 return MsgButton(msg);
963 }
964 break;
965 case WM_LBUTTONDOWN:
966 case WM_RBUTTONDOWN:
967 case WM_MBUTTONDOWN:
968 case WM_NCLBUTTONDOWN:
969 case WM_NCRBUTTONDOWN:
970 case WM_NCMBUTTONDOWN:
971 fClick = TRUE;
972 break;
973 }
974
975 if(ISMOUSE_CAPTURED())
976 {
977 if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_BUTTON, msg->pt.x, msg->pt.y))
978 return 0;
979 }
980
981 if(fClick)
982 {
983 HWND hwndTop;
984
985 /* Activate the window if needed */
986 if(isSubclassedOS2Wnd()) {
987 Win32BaseWindow *parentwnd = GetWindowFromOS2FrameHandle(OSLibWinQueryWindow(OS2Hwnd, QWOS_PARENT));
988 if(parentwnd) {
989 hwndTop = (parentwnd->GetTopParent()) ? parentwnd->GetTopParent()->getWindowHandle() : 0;
990 }
991 else hwndTop = 0;
992 }
993 else hwndTop = (GetTopParent()) ? GetTopParent()->getWindowHandle() : 0;
994
995 HWND hwndActive = GetActiveWindow();
996 if (hwndTop && (getWindowHandle() != hwndActive))
997 {
998 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
999 MAKELONG( lastHitTestVal, msg->message) );
1000
1001#if 0
1002 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1003 eatMsg = TRUE;
1004#endif
1005 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
1006 && hwndTop != GetForegroundWindow() )
1007 {
1008 ::SetActiveWindow(hwndTop);
1009 }
1010 }
1011 }
1012
1013 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1014
1015 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1016}
1017//******************************************************************************
1018//******************************************************************************
1019ULONG Win32BaseWindow::MsgPaint(ULONG tmp1, BOOL select)
1020{
1021 if (select && isIcon)
1022 return SendInternalMessageA(WM_PAINTICON, 0, 0);
1023 else
1024 return SendInternalMessageA(WM_PAINT, 0, 0);
1025}
1026//******************************************************************************
1027//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1028// (or are we simply erasing too much here)
1029//******************************************************************************
1030ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1031{
1032 ULONG rc;
1033 HDC hdcErase = hdc;
1034
1035 if (hdcErase == 0)
1036 hdcErase = O32_GetDC(OS2Hwnd);
1037
1038 if(isIcon)
1039 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1040 else
1041 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1042 if (hdc == 0)
1043 O32_ReleaseDC(OS2Hwnd, hdcErase);
1044 return (rc);
1045}
1046//******************************************************************************
1047//******************************************************************************
1048ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1049{
1050 if(ISMOUSE_CAPTURED()) {
1051 if(DInputMouseHandler(getWindowHandle(), MOUSEMSG_MOVE, msg->pt.x, msg->pt.y))
1052 return 0;
1053 }
1054
1055 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1056 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1057
1058 //translated message == WM_(NC)MOUSEMOVE
1059 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1060}
1061//******************************************************************************
1062//TODO: Depending on menu type, we should send WM_INITMENU or WM_INITPOPUPMENU
1063//TODO: PM sends it for each submenu that gets activated; Windows only for the first
1064// submenu; once the menu bar is active, moving the cursor doesn't generate other
1065// WM_INITMENU msgs. Not really a problem, but might need to fix this later on.
1066//******************************************************************************
1067ULONG Win32BaseWindow::MsgInitMenu(MSG *msg)
1068{
1069 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1070}
1071//******************************************************************************
1072//******************************************************************************
1073ULONG Win32BaseWindow::MsgNCPaint()
1074{
1075 return SendInternalMessageA(WM_PAINT, 0, 0);
1076}
1077//******************************************************************************
1078//******************************************************************************
1079ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1080{
1081 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1082}
1083//******************************************************************************
1084//******************************************************************************
1085ULONG Win32BaseWindow::MsgGetTextLength()
1086{
1087 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1088}
1089//******************************************************************************
1090//******************************************************************************
1091char *Win32BaseWindow::MsgGetText()
1092{
1093 SendInternalMessageA(WM_GETTEXT, wndNameLength, (LPARAM)windowNameA);
1094 return windowNameA;
1095}
1096//******************************************************************************
1097//******************************************************************************
1098ULONG Win32BaseWindow::MsgContextMenu(ULONG x,ULONG y)
1099{
1100 return SendInternalMessageA(WM_CONTEXTMENU,Win32Hwnd,MAKELPARAM(x,y));
1101}
1102//******************************************************************************
1103//******************************************************************************
1104BOOL Win32BaseWindow::isMDIClient()
1105{
1106 return FALSE;
1107}
1108//******************************************************************************
1109//******************************************************************************
1110BOOL Win32BaseWindow::isMDIChild()
1111{
1112 return FALSE;
1113}
1114//******************************************************************************
1115//TODO: Not complete
1116//******************************************************************************
1117BOOL Win32BaseWindow::isFrameWindow()
1118{
1119// if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1120 if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
1121 return TRUE;
1122
1123 return FALSE;
1124}
1125//******************************************************************************
1126//******************************************************************************
1127SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1128{
1129 switch(nBar)
1130 {
1131 case SB_HORZ:
1132 return horzScrollInfo;
1133
1134 case SB_VERT:
1135 return vertScrollInfo;
1136 }
1137
1138 return NULL;
1139}
1140//******************************************************************************
1141//******************************************************************************
1142VOID Win32BaseWindow::subclassScrollBars(BOOL subHorz,BOOL subVert)
1143{
1144 SCROLL_SubclassScrollBars(subHorz ? hwndHorzScroll:0,subVert ? hwndVertScroll:0);
1145}
1146//******************************************************************************
1147//******************************************************************************
1148BOOL Win32BaseWindow::showScrollBars(BOOL changeHorz,BOOL changeVert,BOOL fShow)
1149{
1150 BOOL rc = TRUE;
1151 DWORD flags = 0;
1152
1153 if (fShow)
1154 {
1155 BOOL createHorz = FALSE,createVert = FALSE;
1156 BOOL showHorz = FALSE,showVert = FALSE;
1157
1158 if (changeHorz)
1159 {
1160 if (!hwndHorzScroll)
1161 createHorz = TRUE;
1162 else
1163 showHorz = TRUE;
1164 }
1165
1166 if (changeVert)
1167 {
1168 if (!hwndVertScroll)
1169 createVert = TRUE;
1170 else
1171 showVert = TRUE;
1172 }
1173
1174 if (createHorz || createVert)
1175 {
1176 if (createHorz && !horzScrollInfo)
1177 {
1178 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1179 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1180 horzScrollInfo->MaxVal = 100;
1181 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1182 }
1183
1184 if (createVert && !vertScrollInfo)
1185 {
1186 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1187 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1188 vertScrollInfo->MaxVal = 100;
1189 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1190 }
1191
1192 rc = FrameCreateScrollBars(this,createHorz,createVert,FALSE,&flags);
1193
1194 if (!rc) return FALSE;
1195 if (createHorz) dwStyle |= WS_HSCROLL;
1196 if (createVert) dwStyle |= WS_VSCROLL;
1197 }
1198
1199 if (showVert || showHorz)
1200 {
1201 DWORD newFlags;
1202
1203 rc = FrameShowScrollBars(this,showHorz,showVert,fShow,FALSE,&newFlags);
1204 flags |= newFlags;
1205 if (rc)
1206 {
1207 if (showHorz) dwStyle |= WS_HSCROLL;
1208 if (showVert) dwStyle |= WS_VSCROLL;
1209 }
1210 }
1211
1212 if (flags) FrameUpdateFrame(this,flags);
1213 } else
1214 {
1215 rc = FrameShowScrollBars(this,changeHorz && hwndHorzScroll,changeVert && hwndVertScroll,fShow,TRUE);
1216
1217 if (rc)
1218 {
1219 if (changeHorz) dwStyle &= ~WS_HSCROLL;
1220 if (changeVert) dwStyle &= ~WS_VSCROLL;
1221 }
1222 }
1223
1224 return rc;
1225}
1226/***********************************************************************
1227 * NC_HandleNCLButtonDown
1228 *
1229 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1230 */
1231LONG Win32BaseWindow::HandleNCLButtonDown(WPARAM wParam,LPARAM lParam)
1232{
1233 switch(wParam) /* Hit test */
1234 {
1235 case HTCAPTION:
1236 SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
1237 break;
1238
1239 case HTSYSMENU:
1240 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU+HTSYSMENU,lParam);
1241 break;
1242
1243 case HTMENU:
1244 SendInternalMessageA(WM_SYSCOMMAND,SC_MOUSEMENU,lParam);
1245 break;
1246
1247 case HTHSCROLL:
1248 SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
1249 break;
1250
1251 case HTVSCROLL:
1252 SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
1253 break;
1254
1255 case HTLEFT:
1256 case HTRIGHT:
1257 case HTTOP:
1258 case HTTOPLEFT:
1259 case HTTOPRIGHT:
1260 case HTBOTTOM:
1261 case HTBOTTOMLEFT:
1262 case HTBOTTOMRIGHT:
1263 /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
1264 SendInternalMessageA(WM_SYSCOMMAND,SC_SIZE+wParam-2,lParam);
1265 break;
1266 case HTBORDER:
1267 break;
1268 }
1269
1270 return 0;
1271}
1272//******************************************************************************
1273//******************************************************************************
1274LONG Win32BaseWindow::HandleNCLButtonUp(WPARAM wParam,LPARAM lParam)
1275{
1276 switch(wParam) /* Hit test */
1277 {
1278 case HTMINBUTTON:
1279 SendInternalMessageA(WM_SYSCOMMAND,SC_MINIMIZE,lParam);
1280 break;
1281
1282 case HTMAXBUTTON:
1283 SendInternalMessageA(WM_SYSCOMMAND,SC_MAXIMIZE,lParam);
1284 break;
1285
1286 case HTCLOSE:
1287 SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
1288 break;
1289 }
1290
1291 return 0;
1292}
1293/***********************************************************************
1294 * NC_HandleNCLButtonDblClk
1295 *
1296 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1297 */
1298LONG Win32BaseWindow::HandleNCLButtonDblClk(WPARAM wParam,LPARAM lParam)
1299{
1300 /*
1301 * if this is an icon, send a restore since we are handling
1302 * a double click
1303 */
1304 if (dwStyle & WS_MINIMIZE)
1305 {
1306 SendInternalMessageA(WM_SYSCOMMAND,SC_RESTORE,lParam);
1307 return 0;
1308 }
1309
1310 switch(wParam) /* Hit test */
1311 {
1312 case HTCAPTION:
1313 /* stop processing if WS_MAXIMIZEBOX is missing */
1314 if (dwStyle & WS_MAXIMIZEBOX)
1315 SendInternalMessageA(WM_SYSCOMMAND,
1316 (dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1317 lParam);
1318 break;
1319
1320 case HTSYSMENU:
1321 if (!(GetClassWord(Win32Hwnd,GCW_STYLE) & CS_NOCLOSE))
1322 SendInternalMessageA(WM_SYSCOMMAND,SC_CLOSE,lParam);
1323 break;
1324
1325 case HTHSCROLL:
1326 SendInternalMessageA(WM_SYSCOMMAND,SC_HSCROLL+HTHSCROLL,lParam);
1327 break;
1328
1329 case HTVSCROLL:
1330 SendInternalMessageA(WM_SYSCOMMAND,SC_VSCROLL+HTVSCROLL,lParam);
1331 break;
1332 }
1333
1334 return 0;
1335}
1336/***********************************************************************
1337 * NC_HandleSysCommand
1338 *
1339 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1340 *
1341 * TODO: Not done (see #if 0)
1342 */
1343LONG Win32BaseWindow::HandleSysCommand(WPARAM wParam, POINT *pt32)
1344{
1345 UINT uCommand = wParam & 0xFFF0;
1346
1347 if ((getStyle() & WS_CHILD) && (uCommand != SC_KEYMENU))
1348 ScreenToClient(getParent()->getWindowHandle(), pt32 );
1349
1350 switch (uCommand)
1351 {
1352
1353 case SC_SIZE:
1354 {
1355 DWORD flags = 0;
1356
1357 switch ((wParam & 0xF)+2)
1358 {
1359 case HTLEFT:
1360 flags = TFOS_LEFT;
1361 break;
1362
1363 case HTRIGHT:
1364 flags = TFOS_RIGHT;
1365 break;
1366
1367 case HTTOP:
1368 flags = TFOS_TOP;
1369 break;
1370
1371 case HTTOPLEFT:
1372 flags = TFOS_TOP | TFOS_LEFT;
1373 break;
1374
1375 case HTTOPRIGHT:
1376 flags = TFOS_TOP | TFOS_RIGHT;
1377 break;
1378
1379 case HTBOTTOM:
1380 flags = TFOS_BOTTOM;
1381 break;
1382
1383 case HTBOTTOMLEFT:
1384 flags = TFOS_BOTTOM | TFOS_LEFT;
1385 break;
1386
1387 case HTBOTTOMRIGHT:
1388 flags = TFOS_BOTTOM | TFOS_RIGHT;
1389 break;
1390 }
1391 if (flags) FrameTrackFrame(this,flags);
1392 break;
1393 }
1394
1395 case SC_MOVE:
1396 FrameTrackFrame(this,TFOS_MOVE);
1397 break;
1398
1399 case SC_MINIMIZE:
1400 ShowWindow(SW_MINIMIZE);
1401 break;
1402
1403 case SC_MAXIMIZE:
1404 ShowWindow(SW_MAXIMIZE);
1405 break;
1406
1407 case SC_RESTORE:
1408 ShowWindow(SW_RESTORE);
1409 break;
1410
1411 case SC_CLOSE:
1412 return SendInternalMessageA(WM_CLOSE, 0, 0);
1413
1414#if 0
1415 case SC_VSCROLL:
1416 case SC_HSCROLL:
1417 NC_TrackScrollBar( hwnd, wParam, pt32 );
1418 break;
1419
1420 case SC_MOUSEMENU:
1421 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1422 break;
1423
1424 case SC_KEYMENU:
1425 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1426 break;
1427
1428 case SC_TASKLIST:
1429 WinExec( "taskman.exe", SW_SHOWNORMAL );
1430 break;
1431
1432 case SC_SCREENSAVE:
1433 if (wParam == SC_ABOUTWINE)
1434 ShellAboutA(hwnd, "Odin", WINE_RELEASE_INFO, 0);
1435 else
1436 if (wParam == SC_PUTMARK)
1437 dprintf(("Mark requested by user\n"));
1438 break;
1439
1440 case SC_HOTKEY:
1441 case SC_ARRANGE:
1442 case SC_NEXTWINDOW:
1443 case SC_PREVWINDOW:
1444 break;
1445#endif
1446 }
1447 return 0;
1448}
1449//******************************************************************************
1450//******************************************************************************
1451LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1452{
1453 //SvL: Set background color to default button color (not window (white))
1454 if(ctlType == CTLCOLOR_BTN)
1455 {
1456 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1457 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1458 return GetSysColorBrush(COLOR_BTNFACE);
1459 }
1460 //SvL: Set background color to default dialog color if window is dialog
1461 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1462 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1463 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1464 return GetSysColorBrush(COLOR_BTNFACE);
1465 }
1466
1467 if( ctlType == CTLCOLOR_SCROLLBAR)
1468 {
1469 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1470 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1471 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1472 SetBkColor( hdc, bk);
1473
1474//TODO?
1475#if 0
1476 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1477 * we better use 0x55aa bitmap brush to make scrollbar's background
1478 * look different from the window background.
1479 */
1480 if (bk == GetSysColor(COLOR_WINDOW)) {
1481 return CACHE_GetPattern55AABrush();
1482 }
1483#endif
1484 UnrealizeObject( hb );
1485 return (LRESULT)hb;
1486 }
1487
1488 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1489
1490 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1491 {
1492 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1493 }
1494 else
1495 {
1496 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1497 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1498 }
1499 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1500}
1501//******************************************************************************
1502//******************************************************************************
1503LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1504{
1505 /*
1506 * Visibility flag.
1507 */
1508 if ( (uFlags & PRF_CHECKVISIBLE) &&
1509 !IsWindowVisible() )
1510 return 0;
1511
1512 /*
1513 * Unimplemented flags.
1514 */
1515 if ( (uFlags & PRF_CHILDREN) ||
1516 (uFlags & PRF_OWNED) ||
1517 (uFlags & PRF_NONCLIENT) )
1518 {
1519 dprintf(("WM_PRINT message with unsupported flags\n"));
1520 }
1521
1522 /*
1523 * Background
1524 */
1525 if ( uFlags & PRF_ERASEBKGND)
1526 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1527
1528 /*
1529 * Client area
1530 */
1531 if ( uFlags & PRF_CLIENT)
1532 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1533
1534
1535 return 0;
1536}
1537//******************************************************************************
1538//******************************************************************************
1539LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1540{
1541 switch(Msg)
1542 {
1543 case WM_CLOSE:
1544 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1545 DestroyWindow();
1546 return 0;
1547
1548 case WM_GETTEXTLENGTH:
1549 return wndNameLength;
1550
1551 case WM_GETTEXT:
1552 if (!lParam || !wParam) return 0;
1553 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1554 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1555 return min(wndNameLength, wParam);
1556
1557 case WM_SETTEXT:
1558 {
1559 LPCSTR lpsz = (LPCSTR)lParam;
1560
1561 if(windowNameA) free(windowNameA);
1562 if(windowNameW) free(windowNameW);
1563
1564 if (lParam)
1565 {
1566 wndNameLength = strlen(lpsz);
1567 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1568 strcpy(windowNameA, lpsz);
1569 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1570 lstrcpyAtoW(windowNameW, windowNameA);
1571 }
1572 else
1573 {
1574 windowNameA = NULL;
1575 windowNameW = NULL;
1576 wndNameLength = 0;
1577 }
1578 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1579
1580 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1581 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1582
1583 return TRUE;
1584 }
1585
1586 case WM_SETREDRAW:
1587 {
1588 if (wParam)
1589 {
1590 setStyle(getStyle() | WS_VISIBLE);
1591 OSLibWinEnableWindowUpdate(OS2HwndFrame,TRUE);
1592 } else
1593 {
1594 if (getStyle() & WS_VISIBLE)
1595 {
1596 setStyle(getStyle() & ~WS_VISIBLE);
1597 OSLibWinEnableWindowUpdate(OS2HwndFrame,FALSE);
1598 }
1599 }
1600 return 0;
1601 }
1602
1603 case WM_NCPAINT:
1604 return 0;
1605
1606 case WM_NCACTIVATE:
1607 return TRUE;
1608
1609 case WM_NCCREATE:
1610 return(TRUE);
1611
1612 case WM_NCDESTROY:
1613 return 0;
1614
1615 case WM_NCCALCSIZE:
1616 return NCHandleCalcSize(wParam, (NCCALCSIZE_PARAMS *)lParam);
1617
1618 case WM_CTLCOLORMSGBOX:
1619 case WM_CTLCOLOREDIT:
1620 case WM_CTLCOLORLISTBOX:
1621 case WM_CTLCOLORBTN:
1622 case WM_CTLCOLORDLG:
1623 case WM_CTLCOLORSTATIC:
1624 case WM_CTLCOLORSCROLLBAR:
1625 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1626
1627 case WM_CTLCOLOR:
1628 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1629
1630 case WM_VKEYTOITEM:
1631 case WM_CHARTOITEM:
1632 return -1;
1633
1634 case WM_PARENTNOTIFY:
1635 return 0;
1636
1637 case WM_MOUSEACTIVATE:
1638 {
1639 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1640 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1641 {
1642 if(getParent()) {
1643 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1644 if(rc) return rc;
1645 }
1646 }
1647 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1648 }
1649
1650 case WM_ACTIVATE:
1651 //CB: todo
1652 return 0;
1653
1654 case WM_SETCURSOR:
1655 {
1656 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1657 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1658 {
1659 if(getParent()) {
1660 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1661 if(rc) return rc;
1662 }
1663 }
1664 if (wParam == Win32Hwnd)
1665 {
1666 HCURSOR hCursor;
1667
1668 switch(lastHitTestVal)
1669 {
1670 case HTLEFT:
1671 case HTRIGHT:
1672 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1673 break;
1674
1675 case HTTOP:
1676 case HTBOTTOM:
1677 hCursor = LoadCursorA(0,IDC_SIZENSA);
1678 break;
1679
1680 case HTTOPLEFT:
1681 case HTBOTTOMRIGHT:
1682 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1683 break;
1684
1685 case HTTOPRIGHT:
1686 case HTBOTTOMLEFT:
1687 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1688 break;
1689
1690 default:
1691 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1692 break;
1693 }
1694
1695 if (hCursor)
1696 {
1697 SetCursor(hCursor);
1698 return 1;
1699 } else return 0;
1700 } else return 0;
1701 }
1702
1703 case WM_MOUSEMOVE:
1704 return 0;
1705
1706 case WM_WINDOWPOSCHANGED:
1707 {
1708
1709/* undocumented SWP flags - from SDK 3.1 */
1710#define SWP_NOCLIENTSIZE 0x0800
1711#define SWP_NOCLIENTMOVE 0x1000
1712
1713 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1714 WPARAM wp = SIZE_RESTORED;
1715
1716 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1717 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
1718
1719 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1720 {
1721 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1722 else if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1723
1724 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1725 rectClient.bottom - rectClient.top));
1726 }
1727 return 0;
1728 }
1729 case WM_WINDOWPOSCHANGING:
1730 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1731
1732 case WM_ERASEBKGND:
1733 case WM_ICONERASEBKGND:
1734 {
1735 RECT rect;
1736 int rc;
1737
1738 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1739
1740 rc = GetClipBox( (HDC)wParam, &rect );
1741 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1742 {
1743 HBRUSH hBrush = windowClass->getBackgroundBrush();
1744
1745 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1)) hBrush = GetSysColorBrush(hBrush-1);
1746
1747 FillRect( (HDC)wParam, &rect, hBrush);
1748 }
1749
1750 return 1;
1751 }
1752
1753 case WM_PRINT:
1754 return DefWndPrint(wParam,lParam);
1755
1756 case WM_PAINTICON:
1757 case WM_PAINT:
1758 {
1759 PAINTSTRUCT ps;
1760 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1761 if( hdc )
1762 {
1763 if( (getStyle() & WS_MINIMIZE) && getWindowClass()->getIcon())
1764 {
1765 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1766 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1767 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1768 DrawIcon(hdc, x, y, getWindowClass()->getIcon() );
1769 }
1770 EndPaint(getWindowHandle(), &ps );
1771 }
1772 return 0;
1773 }
1774
1775 case WM_GETDLGCODE:
1776 return 0;
1777
1778 case WM_NCLBUTTONDOWN:
1779 return HandleNCLButtonDown(wParam,lParam);
1780
1781 case WM_NCLBUTTONUP:
1782 return HandleNCLButtonUp(wParam,lParam);
1783
1784 case WM_NCLBUTTONDBLCLK:
1785 return HandleNCLButtonDblClk(wParam,lParam);
1786
1787 case WM_NCRBUTTONDOWN:
1788 case WM_NCRBUTTONDBLCLK:
1789 case WM_NCMBUTTONDOWN:
1790 case WM_NCMBUTTONDBLCLK:
1791 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1792 return 0;
1793
1794 case WM_NCRBUTTONUP:
1795 case WM_NCMBUTTONUP:
1796 return 0;
1797
1798 case WM_NCHITTEST:
1799 {
1800 POINT point;
1801
1802 point.x = (SHORT)LOWORD(lParam);
1803 point.y = (SHORT)HIWORD(lParam);
1804
1805 return FrameHitTest(this,point.x,point.y);
1806 }
1807
1808 case WM_SYSCOMMAND:
1809 {
1810 POINT point;
1811
1812 point.x = LOWORD(lParam);
1813 point.y = HIWORD(lParam);
1814 return HandleSysCommand(wParam, &point);
1815 }
1816
1817 case WM_SYSKEYDOWN:
1818 if(wParam == VK_F4) /* try to close the window */
1819 {
1820 Win32BaseWindow *window = GetTopParent();
1821 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1822 PostMessageA(getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1823 }
1824
1825 Win32BaseWindow *siblingWindow;
1826 HWND sibling;
1827 char nameBuffer [40], mnemonic;
1828 int nameLength;
1829
1830 GetWindowTextA (nameBuffer, 40);
1831
1832 // search all sibling to see it this key is their mnemonic
1833 sibling = GetWindow (GW_HWNDFIRST);
1834 while (sibling != 0) {
1835 siblingWindow = GetWindowFromHandle (sibling);
1836 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1837
1838 // find the siblings mnemonic
1839 mnemonic = '\0';
1840 for (int i=0 ; i<nameLength ; i++) {
1841 if (nameBuffer [i] == '&') {
1842 mnemonic = nameBuffer [i+1];
1843 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1844 mnemonic -= 32; // make it uppercase
1845 break; // stop searching
1846 }
1847 }
1848
1849 // key matches siblings mnemonic, send mouseclick
1850 if (mnemonic == (char) wParam) {
1851 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1852 }
1853
1854 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1855 }
1856
1857 return 0;
1858
1859 case WM_SHOWWINDOW:
1860 if (!lParam) return 0; /* sent from ShowWindow */
1861 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1862 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1863 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1864 ShowWindow(wParam ? SW_SHOWNOACTIVATE : SW_HIDE);
1865 return 0;
1866
1867 case WM_CANCELMODE:
1868 //if (getParent() == windowDesktop) EndMenu();
1869 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1870 return 0;
1871
1872 case WM_DROPOBJECT:
1873 return DRAG_FILE;
1874
1875 case WM_QUERYDROPOBJECT:
1876 if (dwExStyle & WS_EX_ACCEPTFILES) return 1;
1877 return 0;
1878
1879 case WM_QUERYDRAGICON:
1880 {
1881 HICON hIcon = windowClass->getCursor();
1882 UINT len;
1883
1884 if(hIcon) return (LRESULT)hIcon;
1885 for(len = 1; len < 64; len++)
1886 {
1887 hIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1888 if(hIcon)
1889 return (LRESULT)hIcon;
1890 }
1891 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1892 }
1893
1894 case WM_QUERYOPEN:
1895 case WM_QUERYENDSESSION:
1896 return 1;
1897
1898 case WM_NOTIFYFORMAT:
1899 if (IsWindowUnicode()) return NFR_UNICODE;
1900 else return NFR_ANSI;
1901
1902 case WM_SETICON:
1903 case WM_GETICON:
1904 {
1905 LRESULT result = 0;
1906 if (!windowClass) return result;
1907 int index = GCL_HICON;
1908
1909 if (wParam == ICON_SMALL)
1910 index = GCL_HICONSM;
1911
1912 result = windowClass->getClassLongA(index);
1913
1914 if (Msg == WM_SETICON)
1915 windowClass->setClassLongA(index, lParam);
1916
1917 return result;
1918 }
1919
1920 case WM_NOTIFY:
1921 return 0; //comctl32 controls expect this
1922
1923 default:
1924 if(Msg > WM_USER) {
1925 return 0;
1926 }
1927 return 1; //CB: shouldn't this be 0?
1928 }
1929}
1930//******************************************************************************
1931//******************************************************************************
1932LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1933{
1934 switch(Msg)
1935 {
1936 case WM_GETTEXTLENGTH:
1937 return wndNameLength;
1938
1939 case WM_GETTEXT:
1940 if (!lParam || !wParam) return 0;
1941 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1942 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1943 return min(wndNameLength,wParam);
1944
1945 case WM_SETTEXT:
1946 {
1947 LPWSTR lpsz = (LPWSTR)lParam;
1948
1949 if(windowNameA) free(windowNameA);
1950 if(windowNameW) free(windowNameW);
1951
1952 if (lParam)
1953 {
1954 wndNameLength = lstrlenW(lpsz);
1955 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1956 lstrcpyWtoA(windowNameA,lpsz);
1957 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1958 lstrcpyW(windowNameW,lpsz);
1959 }
1960 else
1961 {
1962 windowNameA = NULL;
1963 windowNameW = NULL;
1964 wndNameLength = 0;
1965 }
1966
1967 if(OS2HwndFrame && (dwStyle & WS_CAPTION) == WS_CAPTION)
1968 return OSLibWinSetWindowText(OS2HwndFrame,(LPSTR)windowNameA);
1969
1970 return TRUE;
1971 }
1972
1973 default:
1974 return DefWindowProcA(Msg, wParam, lParam);
1975 }
1976}
1977//******************************************************************************
1978//******************************************************************************
1979LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1980{
1981 //if the destination window is created by this process & thread, call window proc directly
1982 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1983 return SendInternalMessageA(Msg, wParam, lParam);
1984 }
1985 //otherwise use WinSendMsg to send it to the right process/thread
1986 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1987}
1988//******************************************************************************
1989//******************************************************************************
1990LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1991{
1992 //if the destination window is created by this process & thread, call window proc directly
1993 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1994 return SendInternalMessageW(Msg, wParam, lParam);
1995 }
1996 //otherwise use WinSendMsg to send it to the right process/thread
1997 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1998}
1999//******************************************************************************
2000//Called as a result of an OS/2 message or called from a class method
2001//******************************************************************************
2002LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
2003{
2004 LRESULT rc;
2005 BOOL fInternalMsgBackup = fInternalMsg;
2006
2007 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
2008
2009 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
2010
2011 fInternalMsg = TRUE;
2012 switch(Msg)
2013 {
2014 case WM_CREATE:
2015 {
2016 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2017 dprintf(("WM_CREATE returned -1\n"));
2018 rc = -1; //don't create window
2019 break;
2020 }
2021 rc = 0;
2022 break;
2023 }
2024 case WM_LBUTTONDOWN:
2025 case WM_MBUTTONDOWN:
2026 case WM_RBUTTONDOWN:
2027 {
2028 if (getParent())
2029 {
2030 POINTS pt = MAKEPOINTS(lParam);
2031 POINT point;
2032
2033 point.x = pt.x;
2034 point.y = pt.y;
2035 MapWindowPoints(Win32Hwnd,getParent()->getWindowHandle(),&point,1);
2036 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
2037 }
2038 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2039 break;
2040 }
2041
2042 case WM_DESTROY:
2043 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2044 break;
2045
2046 default:
2047 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2048 break;
2049 }
2050 fInternalMsg = fInternalMsgBackup;
2051 return rc;
2052}
2053//******************************************************************************
2054//Called as a result of an OS/2 message or called from a class method
2055//******************************************************************************
2056LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
2057{
2058 LRESULT rc;
2059 BOOL fInternalMsgBackup = fInternalMsg;
2060
2061 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
2062
2063 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
2064
2065 fInternalMsg = TRUE;
2066 switch(Msg)
2067 {
2068 case WM_CREATE:
2069 {
2070 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2071 dprintf(("WM_CREATE returned -1\n"));
2072 rc = -1; //don't create window
2073 break;
2074 }
2075 rc = 0;
2076 break;
2077 }
2078 case WM_LBUTTONDOWN:
2079 case WM_MBUTTONDOWN:
2080 case WM_RBUTTONDOWN:
2081 NotifyParent(Msg, wParam, lParam);
2082 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2083 break;
2084
2085 case WM_DESTROY:
2086 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2087 break;
2088 default:
2089 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2090 break;
2091 }
2092 fInternalMsg = fInternalMsgBackup;
2093 return rc;
2094}
2095//******************************************************************************
2096//******************************************************************************
2097void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2098{
2099 CWPSTRUCT cwp;
2100
2101 cwp.lParam = lParam;
2102 cwp.wParam = wParam;
2103 cwp.message = Msg;
2104 cwp.hwnd = getWindowHandle();
2105
2106 switch(hooktype) {
2107 case WH_CALLWNDPROC:
2108 if(fUnicode) {
2109 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2110 }
2111 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2112 break;
2113 }
2114}
2115//******************************************************************************
2116//******************************************************************************
2117//******************************************************************************
2118//TODO: Do this more efficiently
2119//******************************************************************************
2120LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2121{
2122 Win32BaseWindow *window;
2123 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2124
2125 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2126
2127 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2128 window = GetWindowFromHandle(hwnd++);
2129 if(window) {
2130 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2131 {
2132
2133 if(type == BROADCAST_SEND) {
2134 window->SendInternalMessageA(msg, wParam, lParam);
2135 }
2136 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2137 }
2138 }
2139 }
2140 return 0;
2141}
2142//******************************************************************************
2143//TODO: Do this more efficiently
2144//******************************************************************************
2145LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2146{
2147 Win32BaseWindow *window;
2148 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2149
2150 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2151
2152 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2153 window = GetWindowFromHandle(hwnd++);
2154 if(window) {
2155 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2156 {
2157
2158 if(type == BROADCAST_SEND) {
2159 window->SendInternalMessageW(msg, wParam, lParam);
2160 }
2161 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2162 }
2163 }
2164 }
2165 return 0;
2166}
2167//******************************************************************************
2168//******************************************************************************
2169void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2170{
2171 Win32BaseWindow *window = this;
2172 Win32BaseWindow *parentwindow;
2173
2174 while(window)
2175 {
2176 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2177 {
2178 /* Notify the parent window only */
2179 parentwindow = window->getParent();
2180 if(parentwindow) {
2181 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2182 }
2183 }
2184 else break;
2185
2186 window = parentwindow;
2187 }
2188}
2189//******************************************************************************
2190//******************************************************************************
2191BOOL Win32BaseWindow::SetMenu(HMENU hMenu)
2192{
2193
2194 dprintf(("SetMenu %x", hMenu));
2195 OS2HwndMenu = OSLibWinSetMenu(OS2HwndFrame, hMenu);
2196 if(OS2HwndMenu == 0) {
2197 dprintf(("Win32BaseWindow::SetMenu OS2HwndMenu == 0"));
2198 return FALSE;
2199 }
2200 return TRUE;
2201}
2202//******************************************************************************
2203//******************************************************************************
2204BOOL Win32BaseWindow::SetAccelTable(HACCEL hAccel)
2205{
2206 Win32Resource *winres = (Win32Resource *)hAccel;
2207 HANDLE accelhandle;
2208
2209 if(HIWORD(hAccel) == 0) {
2210 dprintf(("SetAccelTable: hAccel %x invalid", hAccel));
2211 SetLastError(ERROR_INVALID_PARAMETER);
2212 return FALSE;
2213 }
2214 acceltableResource = winres;
2215 accelhandle = OSLibWinSetAccelTable(OS2HwndFrame, winres->getOS2Handle(), winres->lockOS2Resource());
2216 winres->setOS2Handle(accelhandle);
2217 return(accelhandle != 0);
2218}
2219//******************************************************************************
2220//******************************************************************************
2221BOOL Win32BaseWindow::SetIcon(HICON hIcon)
2222{
2223 dprintf(("Win32BaseWindow::SetIcon %x", hIcon));
2224 if(OSLibWinSetIcon(OS2HwndFrame, hIcon) == TRUE) {
2225//TODO: Wine does't send these. Correct?
2226// SendInternalMessageA(WM_SETICON, ICON_BIG, hIcon);
2227 return TRUE;
2228 }
2229 return FALSE;
2230}
2231//******************************************************************************
2232//******************************************************************************
2233BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2234{
2235 ULONG showstate = 0;
2236 HWND hWinAfter;
2237
2238 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2239#if 1
2240 if (flags & WIN_NEED_SIZE)
2241 {
2242 /* should happen only in CreateWindowEx() */
2243 int wParam = SIZE_RESTORED;
2244
2245 flags &= ~WIN_NEED_SIZE;
2246 if (dwStyle & WS_MAXIMIZE)
2247 wParam = SIZE_MAXIMIZED;
2248 else
2249 if (dwStyle & WS_MINIMIZE)
2250 wParam = SIZE_MINIMIZED;
2251
2252 SendInternalMessageA(WM_SIZE, wParam,
2253 MAKELONG(rectClient.right-rectClient.left,
2254 rectClient.bottom-rectClient.top));
2255 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2256 }
2257#else
2258 if(fFirstShow) {
2259 if(isFrameWindow() && IS_OVERLAPPED(getStyle()) && !isChild()) {
2260 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
2261 MAKELONG(rectClient.right-rectClient.left,
2262 rectClient.bottom-rectClient.top));
2263 SendInternalMessageA(WM_MOVE, 0, MAKELONG( rectClient.left, rectClient.top ) );
2264
2265 }
2266 fFirstShow = FALSE;
2267 }
2268#endif
2269 switch(nCmdShow)
2270 {
2271 case SW_SHOW:
2272 case SW_SHOWDEFAULT: //todo
2273 showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
2274 break;
2275 case SW_HIDE:
2276 showstate = SWPOS_HIDE;
2277 break;
2278 case SW_RESTORE:
2279 showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
2280 break;
2281 case SW_MINIMIZE:
2282 showstate = SWPOS_MINIMIZE;
2283 break;
2284 case SW_SHOWMAXIMIZED:
2285 showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2286 break;
2287 case SW_SHOWMINIMIZED:
2288 showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
2289 break;
2290 case SW_SHOWMINNOACTIVE:
2291 showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
2292 break;
2293 case SW_SHOWNA:
2294 showstate = SWPOS_SHOW;
2295 break;
2296 case SW_SHOWNOACTIVATE:
2297 showstate = SWPOS_SHOW;
2298 break;
2299 case SW_SHOWNORMAL:
2300 showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
2301 break;
2302 }
2303
2304 /* We can't activate a child window (WINE) */
2305 if(getStyle() & WS_CHILD)
2306 showstate &= ~SWPOS_ACTIVATE;
2307
2308 if(showstate & SWPOS_SHOW) {
2309 setStyle(getStyle() | WS_VISIBLE);
2310 }
2311 else setStyle(getStyle() & ~WS_VISIBLE);
2312
2313 BOOL rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
2314
2315 return rc;
2316}
2317//******************************************************************************
2318//******************************************************************************
2319BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2320{
2321 BOOL rc = FALSE;
2322 Win32BaseWindow *window;
2323 HWND hParent = 0;
2324
2325 dprintf (("SetWindowPos %x %x (%d,%d)(%d,%d) %x", Win32Hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
2326
2327 if (fuFlags &
2328 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2329 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2330 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2331 SWP_NOOWNERZORDER))
2332 {
2333 return FALSE;
2334 }
2335
2336 WINDOWPOS wpos;
2337 SWP swp, swpOld;
2338
2339 wpos.flags = fuFlags;
2340 wpos.cy = cy;
2341 wpos.cx = cx;
2342 wpos.x = x;
2343 wpos.y = y;
2344 wpos.hwndInsertAfter = hwndInsertAfter;
2345 wpos.hwnd = getWindowHandle();
2346
2347 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2348 {
2349 if (isChild())
2350 {
2351 Win32BaseWindow *windowParent = getParent();
2352 if(windowParent) {
2353 hParent = getParent()->getOS2WindowHandle();
2354 }
2355 else dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2356 }
2357 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2358 }
2359
2360 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
2361 if (swp.fl == 0)
2362 return TRUE;
2363
2364// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2365 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2366 {
2367 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2368 if(wndBehind) {
2369 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2370 }
2371 else {
2372 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2373 swp.hwndInsertBehind = 0;
2374 }
2375 }
2376#if 0
2377 if (isFrameWindow())
2378 {
2379 if (!isChild())
2380 {
2381 POINT maxSize, maxPos, minTrack, maxTrack;
2382
2383 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
2384
2385 if (swp.cx > maxTrack.x) swp.cx = maxTrack.x;
2386 if (swp.cy > maxTrack.y) swp.cy = maxTrack.y;
2387 if (swp.cx < minTrack.x) swp.cx = minTrack.x;
2388 if (swp.cy < minTrack.y) swp.cy = minTrack.y;
2389 }
2390 swp.hwnd = OS2HwndFrame;
2391 }
2392 else
2393#endif
2394 swp.hwnd = OS2HwndFrame;
2395
2396 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2397
2398 rc = OSLibWinSetMultWindowPos(&swp, 1);
2399
2400 if (rc == FALSE)
2401 {
2402 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2403 }
2404
2405 //SWP_FRAMECHANGED is ignored, not necessary for OS/2
2406
2407 return (rc);
2408}
2409//******************************************************************************
2410//TODO: WPF_RESTOREMAXIMIZED
2411//******************************************************************************
2412BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
2413{
2414 if(isFrameWindow())
2415 {
2416 // Set the minimized position
2417 if (winpos->flags & WPF_SETMINPOSITION)
2418 {
2419 OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
2420 }
2421
2422 //TODO: Max position
2423
2424 // Set the new restore position.
2425 OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
2426 }
2427
2428 return ShowWindow(winpos->showCmd);
2429}
2430//******************************************************************************
2431//Also destroys all the child windows (destroy children first, parent last)
2432//******************************************************************************
2433BOOL Win32BaseWindow::DestroyWindow()
2434{
2435 /* Call hooks */
2436 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2437 {
2438 return FALSE;
2439 }
2440
2441 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2442 {
2443 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2444 /* FIXME: clean up palette - see "Internals" p.352 */
2445 }
2446
2447 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2448 {
2449 if(getParent())
2450 {
2451 /* Notify the parent window only */
2452 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2453 if( !::IsWindow(getWindowHandle()) )
2454 {
2455 return TRUE;
2456 }
2457 }
2458 else DebugInt3();
2459 }
2460 fDestroyWindowCalled = TRUE;
2461 return OSLibWinDestroyWindow(OS2HwndFrame);
2462}
2463//******************************************************************************
2464//******************************************************************************
2465Win32BaseWindow *Win32BaseWindow::getParent()
2466{
2467 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::GetParent();
2468 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2469}
2470//******************************************************************************
2471//******************************************************************************
2472HWND Win32BaseWindow::GetParent()
2473{
2474 Win32BaseWindow *wndparent;
2475
2476 if ((!(getStyle() & (WS_POPUP|WS_CHILD))))
2477 {
2478 return 0;
2479 }
2480 wndparent = ((getStyle() & WS_CHILD) ? getParent() : getOwner());
2481
2482 return (wndparent) ? wndparent->getWindowHandle() : 0;
2483}
2484//******************************************************************************
2485//******************************************************************************
2486HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2487{
2488 HWND oldhwnd;
2489 Win32BaseWindow *newparent;
2490
2491 if(getParent()) {
2492 oldhwnd = getParent()->getWindowHandle();
2493 getParent()->RemoveChild(this);
2494 }
2495 else oldhwnd = 0;
2496
2497 newparent = GetWindowFromHandle(hwndNewParent);
2498 if(newparent)
2499 {
2500 setParent(newparent);
2501 getParent()->AddChild(this);
2502 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2503 return oldhwnd;
2504 }
2505 else {
2506 setParent(windowDesktop);
2507 windowDesktop->AddChild(this);
2508 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2509 return oldhwnd;
2510 }
2511}
2512//******************************************************************************
2513//******************************************************************************
2514BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2515{
2516 if(getParent()) {
2517 return getParent()->getWindowHandle() == hwndParent;
2518 }
2519 else return 0;
2520}
2521//******************************************************************************
2522//******************************************************************************
2523HWND Win32BaseWindow::GetTopWindow()
2524{
2525 return GetWindow(GW_CHILD);
2526}
2527//******************************************************************************
2528// Get the top-level parent for a child window.
2529//******************************************************************************
2530Win32BaseWindow *Win32BaseWindow::GetTopParent()
2531{
2532 Win32BaseWindow *window = this;
2533
2534 while(window && (window->getStyle() & WS_CHILD))
2535 {
2536 window = window->getParent();
2537 }
2538 return window;
2539}
2540//******************************************************************************
2541//Don't call WinUpdateWindow as that one also updates the child windows
2542//Also need to send WM_PAINT directly to the window procedure, which doesn't
2543//always happen with WinUpdateWindow (could be posted if thread doesn't own window)
2544//******************************************************************************
2545BOOL Win32BaseWindow::UpdateWindow()
2546{
2547 RECT rect;
2548
2549 if(OSLibWinQueryUpdateRect(OS2Hwnd, &rect))
2550 {//update region not empty
2551 HDC hdc;
2552
2553 hdc = O32_GetDC(OS2Hwnd);
2554 if (isIcon)
2555 {
2556 SendInternalMessageA(WM_ICONERASEBKGND, (WPARAM)hdc, 0);
2557 SendInternalMessageA(WM_PAINTICON, 0, 0);
2558 }
2559 else
2560 {
2561 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
2562 SendInternalMessageA(WM_PAINT, 0, 0);
2563 }
2564 O32_ReleaseDC(OS2Hwnd, hdc);
2565 }
2566 return TRUE;
2567}
2568//******************************************************************************
2569//******************************************************************************
2570BOOL Win32BaseWindow::IsIconic()
2571{
2572 return OSLibWinIsIconic(OS2Hwnd);
2573}
2574//******************************************************************************
2575//TODO: Should not enumerate children that are created during the enumeration!
2576//******************************************************************************
2577BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2578{
2579 BOOL rc = TRUE;
2580 HWND hwnd;
2581 Win32BaseWindow *prevchild = 0, *child = 0;
2582
2583 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2584 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2585 {
2586 dprintf(("EnumChildWindows: enumerating child %x", child->getWindowHandle()));
2587 hwnd = child->getWindowHandle();
2588 if(child->getOwner()) {
2589 continue; //shouldn't have an owner (Wine)
2590 }
2591 if(lpfn(hwnd, lParam) == FALSE)
2592 {
2593 rc = FALSE;
2594 break;
2595 }
2596 //check if the window still exists
2597 if(!::IsWindow(hwnd))
2598 {
2599 child = prevchild;
2600 continue;
2601 }
2602 if(child->getFirstChild() != NULL)
2603 {
2604 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2605 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2606 {
2607 rc = FALSE;
2608 break;
2609 }
2610 }
2611 prevchild = child;
2612 }
2613 return rc;
2614}
2615//******************************************************************************
2616//Enumerate first-level children only and check thread id
2617//******************************************************************************
2618BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2619{
2620 Win32BaseWindow *child = 0;
2621 ULONG tid, pid;
2622 BOOL rc;
2623 HWND hwnd;
2624
2625 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2626
2627 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2628 {
2629 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2630
2631 if(dwThreadId == tid) {
2632 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2633 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2634 break;
2635 }
2636 }
2637 }
2638 return TRUE;
2639}
2640//******************************************************************************
2641//Enumerate first-level children only
2642//******************************************************************************
2643BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2644{
2645 Win32BaseWindow *child = 0;
2646 BOOL rc;
2647 HWND hwnd;
2648
2649 dprintf(("EnumWindows %x %x", lpfn, lParam));
2650
2651 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2652 {
2653 hwnd = child->getWindowHandle();
2654
2655 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2656 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2657 break;
2658 }
2659 }
2660 return TRUE;
2661}
2662//******************************************************************************
2663//******************************************************************************
2664Win32BaseWindow *Win32BaseWindow::FindWindowById(int id)
2665{
2666 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2667 {
2668 if (child->getWindowId() == id)
2669 {
2670 return child;
2671 }
2672 }
2673 return 0;
2674}
2675//******************************************************************************
2676//TODO:
2677//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
2678//the current process owns them.
2679//******************************************************************************
2680HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPSTR lpszClass, LPSTR lpszWindow,
2681 BOOL fUnicode)
2682{
2683 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
2684 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
2685
2686 if((hwndParent != OSLIB_HWND_DESKTOP && !parent) ||
2687 (hwndChildAfter != 0 && !child) ||
2688 (hwndParent == OSLIB_HWND_DESKTOP && hwndChildAfter != 0))
2689 {
2690 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
2691 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2692 return 0;
2693 }
2694 if(hwndParent != OSLIB_HWND_DESKTOP)
2695 {//if the current process owns the window, just do a quick search
2696 child = (Win32BaseWindow *)parent->getFirstChild();
2697 if(hwndChildAfter != 0)
2698 {
2699 while(child)
2700 {
2701 if(child->getWindowHandle() == hwndChildAfter)
2702 {
2703 child = (Win32BaseWindow *)child->getNextChild();
2704 break;
2705 }
2706 child = (Win32BaseWindow *)child->getNextChild();
2707 }
2708 }
2709 while(child)
2710 {
2711 if(child->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2712 (!lpszWindow || child->hasWindowName(lpszWindow, fUnicode)))
2713 {
2714 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
2715 return child->getWindowHandle();
2716 }
2717 child = (Win32BaseWindow *)child->getNextChild();
2718 }
2719 }
2720 else {
2721 Win32BaseWindow *wnd;
2722 HWND henum, hwnd;
2723
2724 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
2725 hwnd = OSLibWinGetNextWindow(henum);
2726
2727 while(hwnd)
2728 {
2729 wnd = GetWindowFromOS2Handle(hwnd);
2730 if(wnd == NULL) {
2731 hwnd = OSLibWinQueryClientWindow(hwnd);
2732 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
2733 if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
2734 }
2735
2736 if(wnd) {
2737 if(wnd->getWindowClass()->hasClassName(lpszClass, fUnicode) &&
2738 (!lpszWindow || wnd->hasWindowName(lpszWindow, fUnicode)))
2739 {
2740 OSLibWinEndEnumWindows(henum);
2741 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
2742 return wnd->getWindowHandle();
2743 }
2744 }
2745 hwnd = OSLibWinGetNextWindow(henum);
2746 }
2747 OSLibWinEndEnumWindows(henum);
2748 }
2749 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
2750 return 0;
2751}
2752//******************************************************************************
2753//******************************************************************************
2754HWND Win32BaseWindow::GetWindow(UINT uCmd)
2755{
2756 HWND hwndRelated = 0;
2757 Win32BaseWindow *window;
2758
2759 switch(uCmd)
2760 {
2761 case GW_HWNDFIRST:
2762 if(getParent()) {
2763 window = (Win32BaseWindow *)getParent()->getFirstChild();
2764 hwndRelated = window->getWindowHandle();
2765 }
2766 break;
2767
2768 case GW_HWNDLAST:
2769 if(!getParent())
2770 {
2771 goto end;
2772 }
2773
2774 window = this;
2775 while(window->getNextChild())
2776 {
2777 window = (Win32BaseWindow *)window->getNextChild();
2778 }
2779 hwndRelated = window->getWindowHandle();
2780 break;
2781
2782 case GW_HWNDNEXT:
2783 window = (Win32BaseWindow *)getNextChild();
2784 if(window) {
2785 hwndRelated = window->getWindowHandle();
2786 }
2787 break;
2788
2789 case GW_HWNDPREV:
2790 if(!getParent())
2791 {
2792 goto end;
2793 }
2794 window = (Win32BaseWindow *)(getParent()->getFirstChild()); /* First sibling */
2795 if(window == this)
2796 {
2797 hwndRelated = 0; /* First in list */
2798 goto end;
2799 }
2800 while(window->getNextChild())
2801 {
2802 if (window->getNextChild() == this)
2803 {
2804 hwndRelated = window->getWindowHandle();
2805 goto end;
2806 }
2807 window = (Win32BaseWindow *)window->getNextChild();
2808 }
2809 break;
2810
2811 case GW_OWNER:
2812 if(getOwner()) {
2813 hwndRelated = getOwner()->getWindowHandle();
2814 }
2815 break;
2816
2817 case GW_CHILD:
2818 if(getFirstChild()) {
2819 hwndRelated = ((Win32BaseWindow *)getFirstChild())->getWindowHandle();
2820 }
2821 break;
2822 }
2823end:
2824 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
2825 return hwndRelated;
2826}
2827//******************************************************************************
2828//******************************************************************************
2829HWND Win32BaseWindow::SetActiveWindow()
2830{
2831 HWND hwndActive;
2832 Win32BaseWindow *win32wnd;
2833 ULONG magic;
2834
2835 hwndActive = OSLibWinSetActiveWindow(OS2HwndFrame);
2836 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32WNDPTR);
2837 magic = OSLibWinGetWindowULong(hwndActive, OFFSET_WIN32PM_MAGIC);
2838 if(CheckMagicDword(magic) && win32wnd)
2839 {
2840 return win32wnd->getWindowHandle();
2841 }
2842 return 0;
2843}
2844//******************************************************************************
2845//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
2846//******************************************************************************
2847BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
2848{
2849 return OSLibWinEnableWindow(OS2HwndFrame, fEnable);
2850}
2851//******************************************************************************
2852//******************************************************************************
2853BOOL Win32BaseWindow::CloseWindow()
2854{
2855 return OSLibWinMinimizeWindow(OS2HwndFrame);
2856}
2857//******************************************************************************
2858//******************************************************************************
2859HWND Win32BaseWindow::GetActiveWindow()
2860{
2861 HWND hwndActive;
2862 Win32BaseWindow *win32wnd;
2863 ULONG magic;
2864
2865 hwndActive = OSLibWinQueryActiveWindow();
2866
2867 return OS2ToWin32Handle(hwndActive);
2868}
2869//******************************************************************************
2870//******************************************************************************
2871BOOL Win32BaseWindow::IsWindowEnabled()
2872{
2873 return OSLibWinIsWindowEnabled(OS2HwndFrame);
2874}
2875//******************************************************************************
2876//******************************************************************************
2877BOOL Win32BaseWindow::IsWindowVisible()
2878{
2879#if 1
2880 return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
2881#else
2882 return OSLibWinIsWindowVisible(OS2HwndFrame);
2883#endif
2884}
2885//******************************************************************************
2886//******************************************************************************
2887BOOL Win32BaseWindow::GetWindowRect(PRECT pRect)
2888{
2889 return OSLibWinQueryWindowRect(OS2HwndFrame, pRect, RELATIVE_TO_SCREEN);
2890}
2891//******************************************************************************
2892//******************************************************************************
2893BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
2894{
2895 if(wndname == NULL)
2896 return FALSE;
2897
2898 if(fUnicode) {
2899 return (lstrcmpW(windowNameW, (LPWSTR)wndname) == 0);
2900 }
2901 else return (strcmp(windowNameA, wndname) == 0);
2902}
2903//******************************************************************************
2904//******************************************************************************
2905int Win32BaseWindow::GetWindowTextLength()
2906{
2907 return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
2908}
2909//******************************************************************************
2910//******************************************************************************
2911int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
2912{
2913 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2914}
2915//******************************************************************************
2916//******************************************************************************
2917int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
2918{
2919 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
2920}
2921//******************************************************************************
2922//******************************************************************************
2923BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
2924{
2925 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
2926}
2927//******************************************************************************
2928//******************************************************************************
2929BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
2930{
2931 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
2932}
2933//******************************************************************************
2934//******************************************************************************
2935VOID Win32BaseWindow::updateWindowStyle(DWORD oldExStyle,DWORD oldStyle)
2936{
2937 if(IsWindowDestroyed()) return;
2938
2939 //CB: todo: dwExStyle, creating new frame controls, destroy not used controls, WS_VISIBLE, WS_CHILD, ...
2940 // write test cases
2941 if ((dwStyle & 0xFFFF0000) != (oldStyle & 0xFFFF0000))
2942 {
2943 //dprintf(("updateWindowStyle: %x %x",oldStyle,dwStyle));
2944 OSLibSetWindowStyle(OS2HwndFrame, dwStyle, fTaskList);
2945 }
2946}
2947//******************************************************************************
2948//******************************************************************************
2949LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
2950{
2951 LONG oldval;
2952
2953 dprintf2(("SetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
2954 switch(index) {
2955 case GWL_EXSTYLE:
2956 {
2957 STYLESTRUCT ss;
2958
2959 if(dwExStyle == value)
2960 return value;
2961
2962 ss.styleOld = dwExStyle;
2963 ss.styleNew = value;
2964 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
2965 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
2966 setExStyle(ss.styleNew);
2967 updateWindowStyle(ss.styleOld,getStyle());
2968 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
2969 return ss.styleOld;
2970 }
2971 case GWL_STYLE:
2972 {
2973 STYLESTRUCT ss;
2974
2975 if(dwStyle == value)
2976 return value;
2977
2978 value &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way (WINE) */
2979 ss.styleOld = getStyle();
2980 ss.styleNew = value | (ss.styleOld & (WS_VISIBLE | WS_CHILD));
2981 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
2982 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
2983 setStyle(ss.styleNew);
2984 updateWindowStyle(dwExStyle,ss.styleOld);
2985 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
2986#ifdef DEBUG
2987 PrintWindowStyle(ss.styleNew, 0);
2988#endif
2989 return ss.styleOld;
2990 }
2991 case GWL_WNDPROC:
2992 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
2993 //WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A, WIN_PROC_WINDOW);
2994 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, WINPROC_GetProcType(win32wndproc), WIN_PROC_WINDOW);
2995 return oldval;
2996 case GWL_HINSTANCE:
2997 oldval = hInstance;
2998 hInstance = value;
2999 return oldval;
3000 case GWL_HWNDPARENT:
3001 return SetParent((HWND)value);
3002 case GWL_ID:
3003 oldval = getWindowId();
3004 setWindowId(value);
3005 return oldval;
3006 case GWL_USERDATA:
3007 oldval = userData;
3008 userData = value;
3009 return oldval;
3010 default:
3011 if(index >= 0 && index/4 < nrUserWindowLong)
3012 {
3013 oldval = userWindowLong[index/4];
3014 userWindowLong[index/4] = value;
3015 return oldval;
3016 }
3017 SetLastError(ERROR_INVALID_PARAMETER);
3018 return 0;
3019 }
3020}
3021//******************************************************************************
3022//******************************************************************************
3023ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3024{
3025 ULONG value;
3026
3027 switch(index) {
3028 case GWL_EXSTYLE:
3029 value = dwExStyle;
3030 break;
3031 case GWL_STYLE:
3032 value = dwStyle;
3033 break;
3034 case GWL_WNDPROC:
3035 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3036 break;
3037 case GWL_HINSTANCE:
3038 value = hInstance;
3039 break;
3040 case GWL_HWNDPARENT:
3041 if(getParent()) {
3042 value = getParent()->getWindowHandle();
3043 }
3044 else value = 0;
3045 break;
3046 case GWL_ID:
3047 value = getWindowId();
3048 break;
3049 case GWL_USERDATA:
3050 value = userData;
3051 break;
3052 default:
3053 if(index >= 0 && index/4 < nrUserWindowLong)
3054 {
3055 value = userWindowLong[index/4];
3056 break;
3057 }
3058 SetLastError(ERROR_INVALID_PARAMETER);
3059 return 0;
3060 }
3061 dprintf2(("GetWindowLongA %x %d %x", getWindowHandle(), index, value));
3062 return value;
3063}
3064//******************************************************************************
3065//******************************************************************************
3066WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3067{
3068 WORD oldval;
3069
3070 if(index >= 0 && index/4 < nrUserWindowLong)
3071 {
3072 oldval = ((WORD *)userWindowLong)[index/2];
3073 ((WORD *)userWindowLong)[index/2] = value;
3074 return oldval;
3075 }
3076 SetLastError(ERROR_INVALID_PARAMETER);
3077 return 0;
3078}
3079//******************************************************************************
3080//******************************************************************************
3081WORD Win32BaseWindow::GetWindowWord(int index)
3082{
3083 if(index >= 0 && index/4 < nrUserWindowLong)
3084 {
3085 return ((WORD *)userWindowLong)[index/2];
3086 }
3087 SetLastError(ERROR_INVALID_PARAMETER);
3088 return 0;
3089}
3090//******************************************************************************
3091//******************************************************************************
3092void Win32BaseWindow::setWindowId(DWORD id)
3093{
3094 windowId = id;
3095 dprintf(("Set window ID to %x", id));
3096 OSLibSetWindowID(OS2HwndFrame, id);
3097}
3098//******************************************************************************
3099//******************************************************************************
3100Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3101{
3102 Win32BaseWindow *window;
3103
3104 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3105 return window;
3106 }
3107// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3108 return NULL;
3109}
3110//******************************************************************************
3111//******************************************************************************
3112Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
3113{
3114 Win32BaseWindow *win32wnd;
3115 DWORD magic;
3116
3117 if(hwnd == OSLIB_HWND_DESKTOP)
3118 {
3119 return windowDesktop;
3120 }
3121
3122 win32wnd = (Win32BaseWindow *)OSLibWinGetWindowULong(hwnd, OFFSET_WIN32WNDPTR);
3123 magic = OSLibWinGetWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
3124
3125 if(win32wnd && CheckMagicDword(magic)) {
3126 return win32wnd;
3127 }
3128// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwnd));
3129 return 0;
3130}
3131//******************************************************************************
3132//******************************************************************************
3133Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3134{
3135 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3136}
3137//******************************************************************************
3138//******************************************************************************
3139HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
3140{
3141 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3142
3143 if(window) {
3144 return window->getOS2WindowHandle();
3145 }
3146// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3147 return hwnd;
3148}
3149//******************************************************************************
3150//******************************************************************************
3151HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
3152{
3153 Win32BaseWindow *window = GetWindowFromHandle(hwnd);
3154
3155 if(window) {
3156 return window->getOS2FrameWindowHandle();
3157 }
3158// dprintf2(("Win32BaseWindow::Win32ToOS2FrameHandle: not a win32 window %x", hwnd));
3159 return hwnd;
3160}
3161//******************************************************************************
3162//******************************************************************************
3163HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
3164{
3165 Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
3166
3167 if(window) {
3168 return window->getWindowHandle();
3169 }
3170 window = GetWindowFromOS2FrameHandle(hwnd);
3171 if(window) {
3172 return window->getWindowHandle();
3173 }
3174// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3175 return 0;
3176// else return hwnd; //OS/2 window handle
3177}
3178//******************************************************************************
3179// GetNextDlgTabItem32 (USER32.276)
3180//******************************************************************************
3181HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
3182{
3183 Win32BaseWindow *child, *nextchild, *lastchild;
3184 HWND retvalue;
3185
3186 if (hwndCtrl)
3187 {
3188 child = GetWindowFromHandle(hwndCtrl);
3189 if (!child)
3190 {
3191 retvalue = 0;
3192 goto END;
3193 }
3194 /* Make sure hwndCtrl is a top-level child */
3195 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3196 {
3197 child = child->getParent();
3198 if(child == NULL) break;
3199 }
3200
3201 if (!child || (child->getParent() != this))
3202 {
3203 retvalue = 0;
3204 goto END;
3205 }
3206 }
3207 else
3208 {
3209 /* No ctrl specified -> start from the beginning */
3210 child = (Win32BaseWindow *)getFirstChild();
3211 if (!child)
3212 {
3213 retvalue = 0;
3214 goto END;
3215 }
3216
3217 if (!fPrevious)
3218 {
3219 while (child->getNextChild())
3220 {
3221 child = (Win32BaseWindow *)child->getNextChild();
3222 }
3223 }
3224 }
3225
3226 lastchild = child;
3227 nextchild = (Win32BaseWindow *)child->getNextChild();
3228 while (TRUE)
3229 {
3230 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild();
3231
3232 if (child == nextchild) break;
3233
3234 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) &&
3235 !(nextchild->getStyle() & WS_DISABLED))
3236 {
3237 lastchild = nextchild;
3238 if (!fPrevious) break;
3239 }
3240 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3241 }
3242 retvalue = lastchild->getWindowHandle();
3243
3244END:
3245 return retvalue;
3246}
3247//******************************************************************************
3248//******************************************************************************
3249HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3250{
3251 Win32BaseWindow *child, *nextchild, *lastchild;
3252 HWND retvalue;
3253
3254 if (hwndCtrl)
3255 {
3256 child = GetWindowFromHandle(hwndCtrl);
3257 if (!child)
3258 {
3259 retvalue = 0;
3260 goto END;
3261 }
3262 /* Make sure hwndCtrl is a top-level child */
3263 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3264 {
3265 child = child->getParent();
3266 if(child == NULL) break;
3267 }
3268
3269 if (!child || (child->getParent() != this))
3270 {
3271 retvalue = 0;
3272 goto END;
3273 }
3274 }
3275 else
3276 {
3277 /* No ctrl specified -> start from the beginning */
3278 child = (Win32BaseWindow *)getFirstChild();
3279 if (!child)
3280 {
3281 retvalue = 0;
3282 goto END;
3283 }
3284
3285 if (fPrevious)
3286 {
3287 while (child->getNextChild())
3288 {
3289 child = (Win32BaseWindow *)child->getNextChild();
3290 }
3291 }
3292 }
3293
3294 lastchild = child;
3295 nextchild = (Win32BaseWindow *)child->getNextChild();
3296 while (TRUE)
3297 {
3298 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3299 {
3300 /* Wrap-around to the beginning of the group */
3301 Win32BaseWindow *pWndTemp;
3302
3303 nextchild = (Win32BaseWindow *)getFirstChild();
3304
3305 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3306 {
3307 if (pWndTemp->getStyle() & WS_GROUP)
3308 nextchild = pWndTemp;
3309
3310 if (pWndTemp == child)
3311 break;
3312 }
3313
3314 }
3315 if (nextchild == child)
3316 break;
3317
3318 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3319 {
3320 lastchild = nextchild;
3321
3322 if (!fPrevious)
3323 break;
3324 }
3325
3326 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3327 }
3328 retvalue = lastchild->getWindowHandle();
3329END:
3330 return retvalue;
3331}
3332//******************************************************************************
3333//******************************************************************************
3334#ifdef DEBUG
3335void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3336{
3337 char style[256] = "";
3338 char exstyle[256] = "";
3339
3340 /* Window styles */
3341 if(dwStyle & WS_CHILD)
3342 strcat(style, "WS_CHILD ");
3343 if(dwStyle & WS_POPUP)
3344 strcat(style, "WS_POPUP ");
3345 if(dwStyle & WS_VISIBLE)
3346 strcat(style, "WS_VISIBLE ");
3347 if(dwStyle & WS_DISABLED)
3348 strcat(style, "WS_DISABLED ");
3349 if(dwStyle & WS_CLIPSIBLINGS)
3350 strcat(style, "WS_CLIPSIBLINGS ");
3351 if(dwStyle & WS_CLIPCHILDREN)
3352 strcat(style, "WS_CLIPCHILDREN ");
3353 if(dwStyle & WS_MAXIMIZE)
3354 strcat(style, "WS_MAXIMIZE ");
3355 if(dwStyle & WS_MINIMIZE)
3356 strcat(style, "WS_MINIMIZE ");
3357 if(dwStyle & WS_GROUP)
3358 strcat(style, "WS_GROUP ");
3359 if(dwStyle & WS_TABSTOP)
3360 strcat(style, "WS_TABSTOP ");
3361
3362 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3363 strcat(style, "WS_CAPTION ");
3364 if(dwStyle & WS_DLGFRAME)
3365 strcat(style, "WS_DLGFRAME ");
3366 if(dwStyle & WS_BORDER)
3367 strcat(style, "WS_BORDER ");
3368
3369 if(dwStyle & WS_VSCROLL)
3370 strcat(style, "WS_VSCROLL ");
3371 if(dwStyle & WS_HSCROLL)
3372 strcat(style, "WS_HSCROLL ");
3373 if(dwStyle & WS_SYSMENU)
3374 strcat(style, "WS_SYSMENU ");
3375 if(dwStyle & WS_THICKFRAME)
3376 strcat(style, "WS_THICKFRAME ");
3377 if(dwStyle & WS_MINIMIZEBOX)
3378 strcat(style, "WS_MINIMIZEBOX ");
3379 if(dwStyle & WS_MAXIMIZEBOX)
3380 strcat(style, "WS_MAXIMIZEBOX ");
3381
3382 if(dwExStyle & WS_EX_DLGMODALFRAME)
3383 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3384 if(dwExStyle & WS_EX_ACCEPTFILES)
3385 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3386 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3387 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3388 if(dwExStyle & WS_EX_TOPMOST)
3389 strcat(exstyle, "WS_EX_TOPMOST ");
3390 if(dwExStyle & WS_EX_TRANSPARENT)
3391 strcat(exstyle, "WS_EX_TRANSPARENT ");
3392
3393 if(dwExStyle & WS_EX_MDICHILD)
3394 strcat(exstyle, "WS_EX_MDICHILD ");
3395 if(dwExStyle & WS_EX_TOOLWINDOW)
3396 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3397 if(dwExStyle & WS_EX_WINDOWEDGE)
3398 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3399 if(dwExStyle & WS_EX_CLIENTEDGE)
3400 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3401 if(dwExStyle & WS_EX_CONTEXTHELP)
3402 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3403 if(dwExStyle & WS_EX_RIGHT)
3404 strcat(exstyle, "WS_EX_RIGHT ");
3405 if(dwExStyle & WS_EX_LEFT)
3406 strcat(exstyle, "WS_EX_LEFT ");
3407 if(dwExStyle & WS_EX_RTLREADING)
3408 strcat(exstyle, "WS_EX_RTLREADING ");
3409 if(dwExStyle & WS_EX_LTRREADING)
3410 strcat(exstyle, "WS_EX_LTRREADING ");
3411 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3412 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3413 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3414 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3415 if(dwExStyle & WS_EX_CONTROLPARENT)
3416 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3417 if(dwExStyle & WS_EX_STATICEDGE)
3418 strcat(exstyle, "WS_EX_STATICEDGE ");
3419 if(dwExStyle & WS_EX_APPWINDOW)
3420 strcat(exstyle, "WS_EX_APPWINDOW ");
3421
3422 dprintf(("Window style: %x %s", dwStyle, style));
3423 dprintf(("Window exStyle: %x %s (FS = %x)", dwExStyle, exstyle, GetFS()));
3424}
3425#endif
3426//******************************************************************************
3427//******************************************************************************
3428
3429GenericObject *Win32BaseWindow::windows = NULL;
Note: See TracBrowser for help on using the repository browser.