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

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

Load entire bitmap into memory for LoadBitmapA (file)

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