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

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

Fix for Notes crash when switching to new view

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