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

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

PostMessage memory leak fixed

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