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

Last change on this file since 7183 was 7183, checked in by sandervl, 24 years ago

IsWindowVisible fix for window with invisible owner

File size: 139.7 KB
Line 
1/* $Id: win32wbase.cpp,v 1.294 2001-10-24 10:26:45 sandervl Exp $ */
2/*
3 * Win32 Window Base Class for OS/2
4 *
5 * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c)
10 * Corel version: corel20000212
11 *
12 * Copyright 1993, 1994, 1996 Alexandre Julliard
13 * 1995 Alex Korobka
14 *
15 * TODO: Not thread/process safe
16 *
17 * NOTE: To access a window object, you must call GetWindowFromOS2Handle or
18 * GetWindowFromHandle. Both these methods increase the reference count
19 * of the object. When you're done with the object, you MUST call
20 * the release method!
21 * This mechanism prevents premature destruction of objects when there
22 * are still clients using it.
23 *
24 * NOTE: Client rectangle always relative to frame window
25 * Window rectangle in parent coordinates (relative to parent's client window)
26 * (screen coord. if no parent)
27 *
28 * NOTE: Status of window:
29 * Before a window has processed WM_NCCREATE:
30 * - GetTopWindow can't return that window handle
31 * - GetWindow(parent, GW_CHILD) can't return that window handle
32 * - IsChild works
33 * TODO: Does this affect more functions?? (other GetWindow ops)
34 * (verified in NT4, SP6)
35 *
36 * Project Odin Software License can be found in LICENSE.TXT
37 *
38 */
39#include <os2win.h>
40#include <win.h>
41#include <stdlib.h>
42#include <string.h>
43#include <stdarg.h>
44#include <assert.h>
45#include <misc.h>
46#include <heapstring.h>
47#include <winuser32.h>
48#include "win32wbase.h"
49#include "wndmsg.h"
50#include "oslibwin.h"
51#include "oslibmsg.h"
52#include "oslibutil.h"
53#include "oslibgdi.h"
54#include "oslibres.h"
55#include "oslibdos.h"
56#include "syscolor.h"
57#include "win32wndhandle.h"
58#include "dc.h"
59#include "win32wdesktop.h"
60#include "pmwindow.h"
61#include "controls.h"
62#include <wprocess.h>
63#include <win\hook.h>
64#include <menu.h>
65#define INCL_TIMERWIN32
66#include "timer.h"
67
68#define DBG_LOCALLOG DBG_win32wbase
69#include "dbglocal.h"
70
71/* bits in the dwKeyData */
72#define KEYDATA_ALT 0x2000
73#define KEYDATA_PREVSTATE 0x4000
74
75void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle);
76
77static fDestroyAll = FALSE;
78//For quick lookup of current process id
79static ULONG currentProcessId = -1;
80static int iF10Key = 0;
81static int iMenuSysKey = 0;
82
83
84
85/***
86 * Performance Optimization:
87 * we're directly inlining this micro function from win32wndhandle.cpp.
88 * Changes there must be reflected here.
89 ***/
90extern ULONG WindowHandleTable[MAX_WINDOW_HANDLES];
91
92BOOL INLINE i_HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
93{
94 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
95 return FALSE; //unknown window (PM?)
96 }
97 hwnd &= WNDHANDLE_MAGIC_MASK;
98 if(hwnd < MAX_WINDOW_HANDLES) {
99 *pdwUserData = WindowHandleTable[hwnd];
100 return TRUE;
101 }
102 *pdwUserData = 0;
103 return FALSE;
104}
105#define HwGetWindowHandleData(a,b) i_HwGetWindowHandleData(a,b)
106
107
108//******************************************************************************
109//******************************************************************************
110Win32BaseWindow::Win32BaseWindow()
111 : GenericObject(&windows, &critsect), ChildWindow(&critsect)
112{
113 Init();
114}
115//******************************************************************************
116//******************************************************************************
117Win32BaseWindow::Win32BaseWindow(HWND hwndOS2, ULONG reserved)
118 : GenericObject(&windows, &critsect), ChildWindow(&critsect)
119{
120 Init();
121 OS2Hwnd = hwndOS2;
122}
123//******************************************************************************
124//******************************************************************************
125Win32BaseWindow::Win32BaseWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
126 : GenericObject(&windows, &critsect), ChildWindow(&critsect)
127{
128 Init();
129 this->isUnicode = isUnicode;
130 CreateWindowExA(lpCreateStructA, classAtom);
131}
132//******************************************************************************
133//******************************************************************************
134void Win32BaseWindow::Init()
135{
136 isUnicode = FALSE;
137 fFirstShow = TRUE;
138 fIsDialog = FALSE;
139 fIsModalDialogOwner = FALSE;
140 OS2HwndModalDialog = 0;
141 fInternalMsg = FALSE;
142 fParentChange = FALSE;
143 fDestroyWindowCalled = FALSE;
144 fTaskList = FALSE;
145 fParentDC = FALSE;
146 fComingToTop = FALSE;
147 fMinMaxChange = FALSE;
148 fVisibleRegionChanged = FALSE;
149 fEraseBkgndFlag = TRUE;
150
151 state = STATE_INIT;
152 windowNameA = NULL;
153 windowNameW = NULL;
154
155 userWindowBytes = NULL;;
156 nrUserWindowBytes= 0;
157
158 OS2Hwnd = 0;
159 OS2HwndFrame = 0;
160 hSysMenu = 0;
161 Win32Hwnd = 0;
162
163 if(HwAllocateWindowHandle(&Win32Hwnd, (ULONG)this) == FALSE)
164 {
165 dprintf(("Win32BaseWindow::Init HwAllocateWindowHandle failed!!"));
166 DebugInt3();
167 }
168
169 posx = posy = 0;
170 width = height = 0;
171
172 dwExStyle = 0;
173 dwStyle = 0;
174 dwOldStyle = 0;
175 win32wndproc = 0;
176 hInstance = 0;
177 dwIDMenu = 0; //0xFFFFFFFF; //default -1
178 userData = 0;
179 contextHelpId = 0;
180 hotkey = 0;
181
182
183 hwndLinkAfter = HWND_BOTTOM;
184 flags = 0;
185 lastHitTestVal = HTOS_NORMAL;
186 owner = NULL;
187 windowClass = 0;
188
189 hIcon = 0;
190 hIconSm = 0;
191
192 horzScrollInfo = NULL;
193 vertScrollInfo = NULL;
194
195 propertyList = NULL;
196
197 cbExtra = 0;
198 pExtra = NULL;
199
200 ownDC = 0;
201 hWindowRegion = 0;
202 hClipRegion = 0;
203
204 hTaskList = 0;
205
206 if(currentProcessId == -1)
207 {
208 currentProcessId = GetCurrentProcessId();
209 }
210 dwThreadId = GetCurrentThreadId();
211 dwProcessId = currentProcessId;
212
213 memset(&windowpos, 0, sizeof(windowpos));
214 //min and max position are initially -1 (verified in NT4, SP6)
215 windowpos.ptMinPosition.x = -1;
216 windowpos.ptMinPosition.y = -1;
217 windowpos.ptMaxPosition.x = -1;
218 windowpos.ptMaxPosition.y = -1;
219
220 lpVisRgnNotifyProc = NULL;
221 dwVisRgnNotifyParam = NULL;
222}
223//******************************************************************************
224//todo get rid of resources (menu, icon etc)
225//******************************************************************************
226Win32BaseWindow::~Win32BaseWindow()
227{
228 if(getRefCount() < 0) {
229 DebugInt3();
230 }
231
232 if(hTaskList) {
233 OSLibWinRemoveFromTasklist(hTaskList);
234 }
235
236 OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE);
237 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
238 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
239
240 if(fDestroyAll) {
241 dprintf(("Destroying window %x %s", getWindowHandle(), windowNameA));
242 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
243 }
244 else
245 if(getParent() && getParent()->getFirstChild() == this && getNextChild() == NULL)
246 {
247 //if we're the last child that's being destroyed and our
248 //parent window was also destroyed, then we
249 if(getParent()->IsWindowDestroyed())
250 {
251 setParent(NULL); //or else we'll crash in the dtor of the ChildWindow class
252 }
253 }
254 /* Decrement class window counter */
255 if(windowClass) {
256 RELEASE_CLASSOBJ(windowClass);
257 }
258
259 if(isOwnDC())
260 releaseOwnDC(ownDC);
261
262 if(Win32Hwnd)
263 HwFreeWindowHandle(Win32Hwnd);
264
265 if(userWindowBytes)
266 free(userWindowBytes);
267
268 if(windowNameA) {
269 free(windowNameA);
270 windowNameA = NULL;
271 }
272 if(windowNameW) {
273 free(windowNameW);
274 windowNameW = NULL;
275 }
276 if(vertScrollInfo) {
277 free(vertScrollInfo);
278 vertScrollInfo = NULL;
279 }
280 if(horzScrollInfo) {
281 free(horzScrollInfo);
282 horzScrollInfo = NULL;
283 }
284 if(propertyList) {
285 removeWindowProps();
286 }
287 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
288 if(wndparent && !fDestroyAll) {
289 RELEASE_WNDOBJ(wndparent);
290 }
291 if(owner && !fDestroyAll) {
292 RELEASE_WNDOBJ(owner);
293 }
294 if(windowClass) {
295 RELEASE_CLASSOBJ(windowClass);
296 }
297}
298//******************************************************************************
299//******************************************************************************
300void Win32BaseWindow::DestroyAll()
301{
302 fDestroyAll = TRUE;
303 GenericObject::DestroyAll(windows);
304}
305//******************************************************************************
306//******************************************************************************
307BOOL Win32BaseWindow::isChild()
308{
309 return ((dwStyle & WS_CHILD) != 0);
310}
311//******************************************************************************
312//******************************************************************************
313BOOL Win32BaseWindow::IsWindowUnicode()
314{
315 dprintf2(("IsWindowUnicode %x %d", getWindowHandle(), WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W));
316 return (WINPROC_GetProcType(getWindowProc()) == WIN_PROC_32W);
317}
318//******************************************************************************
319//******************************************************************************
320BOOL Win32BaseWindow::CreateWindowExA(CREATESTRUCTA *cs, ATOM classAtom)
321{
322 char buffer[256];
323
324#ifdef DEBUG
325 PrintWindowStyle(cs->style, cs->dwExStyle);
326#endif
327
328 //If window has no owner/parent window, then it will be added to the tasklist
329 //(depending on visibility state)
330 if (!cs->hwndParent) fTaskList = TRUE;
331
332 sw = SW_SHOW;
333 SetLastError(0);
334
335 /* Find the parent window */
336 if (cs->hwndParent)
337 {
338 Win32BaseWindow *window = GetWindowFromHandle(cs->hwndParent);
339 if(!window) {
340 dprintf(("Bad parent %04x\n", cs->hwndParent ));
341 SetLastError(ERROR_INVALID_PARAMETER);
342 return FALSE;
343 }
344 /* Make sure parent is valid */
345 if (!window->IsWindow() )
346 {
347 RELEASE_WNDOBJ(window);
348 dprintf(("Bad parent %04x\n", cs->hwndParent ));
349 SetLastError(ERROR_INVALID_PARAMETER);
350 return FALSE;
351 }
352 RELEASE_WNDOBJ(window);
353 /* Windows does this for overlapped windows
354 * (I don't know about other styles.) */
355 if (cs->hwndParent == GetDesktopWindow() && (!(cs->style & WS_CHILD) || (cs->style & WS_POPUP)))
356 {
357 cs->hwndParent = 0;
358 }
359 }
360 else
361 if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) {
362 dprintf(("No parent for child window" ));
363 SetLastError(ERROR_INVALID_PARAMETER);
364 return FALSE; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
365 }
366
367 /* Find the window class */
368 windowClass = Win32WndClass::FindClass(cs->hInstance, (LPSTR)classAtom);
369 if (!windowClass)
370 {
371 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
372 dprintf(("Bad class '%s'", buffer ));
373 SetLastError(ERROR_INVALID_PARAMETER);
374 return 0;
375 }
376
377#ifdef DEBUG
378 if(HIWORD(cs->lpszClass))
379 {
380 if(isUnicode) dprintf(("Window class %ls", cs->lpszClass));
381 else dprintf(("Window class %s", cs->lpszClass));
382 }
383 else dprintf(("Window class %x", cs->lpszClass));
384#endif
385
386 /* Fix the lpszClass field: from existing programs, it seems ok to call a CreateWindowXXX
387 * with an atom as the class name, put some programs expect to have a *REAL* string in
388 * lpszClass when the CREATESTRUCT is sent with WM_CREATE
389 */
390 if (!HIWORD(cs->lpszClass) ) {
391 if (isUnicode) {
392 GlobalGetAtomNameW( classAtom, (LPWSTR)buffer, sizeof(buffer) );
393 }
394 else {
395 GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) );
396 }
397 cs->lpszClass = buffer;
398 }
399
400 /* Fix the coordinates */
401 fXDefault = FALSE;
402 fCXDefault = FALSE;
403 if ((cs->x == CW_USEDEFAULT) || (cs->x == CW_USEDEFAULT16))
404 {
405 /* Never believe Microsoft's documentation... CreateWindowEx doc says
406 * that if an overlapped window is created with WS_VISIBLE style bit
407 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
408 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
409 * reveals that
410 *
411 * 1) not only if checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
412 * 2) it does not ignore the y parameter as the docs claim; instead, it
413 * uses it as second parameter to ShowWindow() unless y is either
414 * CW_USEDEFAULT or CW_USEDEFAULT16.
415 *
416 * The fact that we didn't do 2) caused bogus windows pop up when wine
417 * was running apps that were using this obscure feature. Example -
418 * calc.exe that comes with Win98 (only Win98, it's different from
419 * the one that comes with Win95 and NT)
420 */
421 if ((cs->y != CW_USEDEFAULT) && (cs->y != CW_USEDEFAULT16)) sw = cs->y;
422
423 /* We have saved cs->y, now we can trash it */
424 cs->x = 0;
425 cs->y = 0;
426 fXDefault = TRUE;
427 }
428 if ((cs->cx == CW_USEDEFAULT) || (cs->cx == CW_USEDEFAULT16))
429 {
430 cs->cx = 600; /* FIXME */
431 cs->cy = 400;
432 fCXDefault = TRUE;
433 }
434 if (cs->style & (WS_POPUP | WS_CHILD))
435 {
436 fXDefault = FALSE;
437 if (fCXDefault)
438 {
439 fCXDefault = FALSE;
440 cs->cx = cs->cy = 0;
441 }
442 }
443 if (fXDefault && !fCXDefault) fXDefault = FALSE; //CB: only x positioning doesn't work (calc.exe,cdrlabel.exe)
444
445 //Allocate window words
446 nrUserWindowBytes = windowClass->getExtraWndBytes();
447 if(nrUserWindowBytes) {
448 userWindowBytes = (char *)_smalloc(nrUserWindowBytes);
449 memset(userWindowBytes, 0, nrUserWindowBytes);
450 }
451
452 if ((cs->style & WS_CHILD) && cs->hwndParent)
453 {
454 SetParent(cs->hwndParent);
455// owner = GetWindowFromHandle(cs->hwndParent);
456 owner = 0;
457/* if(owner == NULL)
458 {
459 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
460 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
461 return FALSE;
462 }*/
463 //SvL: Shell positioning shouldn't be done for child windows! (breaks Notes)
464 fXDefault = fCXDefault = FALSE;
465 }
466 else
467 {
468 SetParent(0);
469 if (!cs->hwndParent || (cs->hwndParent == windowDesktop->getWindowHandle())) {
470 owner = NULL;
471 }
472 else
473 {
474 Win32BaseWindow *wndparent = GetWindowFromHandle(cs->hwndParent);
475 if(wndparent) {
476 owner = GetWindowFromHandle(wndparent->GetTopParent());
477 RELEASE_WNDOBJ(wndparent);
478 }
479 else owner = NULL;
480
481 if(owner == NULL)
482 {
483 dprintf(("HwGetWindowHandleData couldn't find owner window %x!!!", cs->hwndParent));
484 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
485 return FALSE;
486 }
487 }
488 }
489
490 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, windowClass->getWindowProc(), WINPROC_GetProcType(windowClass->getWindowProc()), WIN_PROC_WINDOW);
491 hInstance = cs->hInstance;
492 dwStyle = cs->style & ~WS_VISIBLE;
493 dwOldStyle = dwStyle;
494 dwExStyle = cs->dwExStyle;
495
496 hwndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
497
498 /* Correct the window style */
499 if (!(cs->style & WS_CHILD))
500 {
501 dwStyle |= WS_CLIPSIBLINGS;
502 if (!(cs->style & WS_POPUP))
503 {
504 dwStyle |= WS_CAPTION;
505 flags |= WIN_NEED_SIZE;
506 }
507 }
508 if (cs->dwExStyle & WS_EX_DLGMODALFRAME) dwStyle &= ~WS_THICKFRAME;
509
510 //copy pointer of CREATESTRUCT for usage in MsgCreate method
511 tmpcs = cs;
512
513 //Store our window object pointer in thread local memory, so PMWINDOW.CPP can retrieve it
514 TEB *teb = GetThreadTEB();
515 if(teb == NULL) {
516 dprintf(("Window creation failed - teb == NULL")); //this is VERY bad
517 ExitProcess(666);
518 return FALSE;
519 }
520
521 teb->o.odin.newWindow = (ULONG)this;
522
523 DWORD dwOSWinStyle, dwOSFrameStyle;
524
525 OSLibWinConvertStyle(dwStyle,dwExStyle,&dwOSWinStyle, &dwOSFrameStyle);
526
527 OS2Hwnd = OSLibWinCreateWindow((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
528 dwOSWinStyle, dwOSFrameStyle, (char *)windowNameA,
529 (owner) ? owner->getOS2WindowHandle() : ((getParent()) ? getParent()->getOS2WindowHandle() : OSLIB_HWND_DESKTOP),
530 (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
531 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle(), &OS2HwndFrame);
532 if(OS2Hwnd == 0) {
533 dprintf(("Window creation failed!! OS LastError %0x", OSLibWinGetLastError()));
534 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
535 return FALSE;
536 }
537 OSLibWinSetVisibleRegionNotify(OS2Hwnd, TRUE);
538 state = STATE_CREATED;
539 SetLastError(0);
540 return TRUE;
541}
542//******************************************************************************
543//******************************************************************************
544BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2)
545{
546 CREATESTRUCTA *cs = tmpcs; //pointer to CREATESTRUCT used in CreateWindowExA method
547 POINT maxSize, maxPos, minTrack, maxTrack;
548 HWND hwnd = getWindowHandle();
549 LRESULT (* CALLBACK localSend32)(HWND, UINT, WPARAM, LPARAM);
550
551 OS2Hwnd = hwndOS2;
552
553 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, getWindowHandle()) == FALSE) {
554 dprintf(("WM_CREATE: WinSetWindowULong %X failed!!", OS2Hwnd));
555 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
556 return FALSE;
557 }
558 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, WIN32PM_MAGIC) == FALSE) {
559 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
560 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
561 return FALSE;
562 }
563 if(OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32FLAGS, 0) == FALSE) {
564 dprintf(("WM_CREATE: WinSetWindowULong2 %X failed!!", OS2Hwnd));
565 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
566 return FALSE;
567 }
568
569 if (HOOK_IsHooked( WH_CBT ))
570 {
571 CBT_CREATEWNDA cbtc;
572 LRESULT ret;
573
574 cbtc.lpcs = cs;
575 cbtc.hwndInsertAfter = hwndLinkAfter;
576 ret = (isUnicode) ? HOOK_CallHooksW(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc)
577 : HOOK_CallHooksA(WH_CBT, HCBT_CREATEWND, getWindowHandle(), (LPARAM)&cbtc);
578 if(ret)
579 {
580 dprintf(("CBT-hook returned 0!!"));
581 SetLastError(ERROR_CAN_NOT_COMPLETE); //todo: wrong error
582 return FALSE;
583 }
584 //todo: if hook changes parent, we need to do so too!!!!!!!!!!
585 }
586
587 if (cs->style & WS_HSCROLL)
588 {
589 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
590 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
591 horzScrollInfo->MaxVal = 100;
592 horzScrollInfo->flags = ESB_ENABLE_BOTH;
593 }
594
595 if (cs->style & WS_VSCROLL)
596 {
597 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
598 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
599 vertScrollInfo->MaxVal = 100;
600 vertScrollInfo->flags = ESB_ENABLE_BOTH;
601 }
602
603 if(HIWORD(cs->lpszName))
604 {
605 if (!isUnicode)
606 {
607 int wndNameLength = strlen(cs->lpszName);
608 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
609 strcpy(windowNameA,cs->lpszName);
610 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
611 lstrcpyAtoW(windowNameW,windowNameA);
612 windowNameA[wndNameLength] = 0;
613 windowNameW[wndNameLength] = 0;
614 }
615 else
616 {
617 // Wide
618 int wndNameLength = lstrlenW((LPWSTR)cs->lpszName);
619 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
620 lstrcpyW(windowNameW,(LPWSTR)cs->lpszName);
621 windowNameW[lstrlenW((LPWSTR)cs->lpszName)] = 0; // need ?
622 // Ascii
623 LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR)cs->lpszName);
624 if(tmp) {
625 long tmpLength = strlen( tmp );
626 windowNameA = (LPSTR)_smalloc(tmpLength+1);
627 strcpy(windowNameA,tmp);
628 windowNameA[tmpLength] = 0; // need ?
629 HEAP_free(tmp);
630 } else {
631 windowNameA = (LPSTR)_smalloc(1);
632 windowNameA[0] = 0;
633 }
634 }
635 if(fOS2Look) {
636 OSLibWinSetTitleBarText(OS2HwndFrame, windowNameA);
637 }
638 }
639
640//SvL: This completely messes up MS Word 97 (no button bar, no menu)
641#if 0
642 //adjust CW_USEDEFAULT position
643 if (fXDefault | fCXDefault)
644 {
645 RECT rect;
646
647 //SvL: Returns invalid rectangle (not the expected shell default size)
648 OSLibWinQueryWindowRect(OS2Hwnd,&rect,RELATIVE_TO_SCREEN);
649 if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
650 if (fXDefault)
651 {
652 cs->x = rect.left;
653 cs->y = rect.top;
654 if (!fCXDefault)
655 {
656 //CB: todo: adjust pos to screen rect
657 }
658 }
659 if (fCXDefault)
660 {
661 cs->cx = rect.right-rect.left;
662 cs->cy = rect.bottom-rect.top;
663 }
664 }
665#endif
666
667 fakeWinBase.hwndThis = OS2Hwnd;
668 fakeWinBase.pWindowClass = windowClass;
669
670 //Set icon from window or class
671 if (hIcon)
672 OSLibWinSetIcon(OS2HwndFrame,hIcon);
673 else
674 if (windowClass->getIcon())
675 OSLibWinSetIcon(OS2HwndFrame,windowClass->getIcon());
676
677 /* Get class or window DC if needed */
678 if(windowClass->getStyle() & CS_OWNDC) {
679 dprintf(("Class with CS_OWNDC style"));
680 ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE);
681 }
682 else
683 if (windowClass->getStyle() & CS_PARENTDC) {
684 fParentDC = TRUE;
685 ownDC = 0;
686 }
687 else
688 if (windowClass->getStyle() & CS_CLASSDC) {
689 dprintf(("WARNING: Class with CS_CLASSDC style!"));
690 //not a good solution, but it's a bit difficult to share a single
691 //DC among different windows... DevOpenDC apparently can't be used
692 //for window DCs and WinOpenWindowDC must be associated with a window
693 ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE);
694 }
695 /* Set the window menu */
696 if ((dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION )
697 {
698 if (cs->hMenu) {
699 ::SetMenu(getWindowHandle(), cs->hMenu);
700 }
701 else {
702 if (windowClass->getMenuNameA()) {
703 cs->hMenu = LoadMenuA(windowClass->getInstance(),windowClass->getMenuNameA());
704#if 0 //CB: hack for treeview test cases bug
705if (!cs->hMenu) cs->hMenu = LoadMenuA(windowClass->getInstance(),"MYAPP");
706#endif
707 if (cs->hMenu) ::SetMenu(getWindowHandle(), cs->hMenu );
708 }
709 }
710 }
711 else
712 {
713 setWindowId((DWORD)cs->hMenu);
714 }
715 hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0;
716
717 /* Send the WM_GETMINMAXINFO message and fix the size if needed */
718 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
719 {
720 GetMinMaxInfo(&maxSize, &maxPos, &minTrack, &maxTrack);
721 if (maxSize.x < cs->cx) cs->cx = maxSize.x;
722 if (maxSize.y < cs->cy) cs->cy = maxSize.y;
723 if (cs->cx < minTrack.x) cs->cx = minTrack.x;
724 if (cs->cy < minTrack.y) cs->cy = minTrack.y;
725 }
726
727 if(cs->style & WS_CHILD)
728 {
729 if(cs->cx < 0) cs->cx = 0;
730 if(cs->cy < 0) cs->cy = 0;
731 }
732 else
733 {
734 if (cs->cx <= 0) cs->cx = 1;
735 if (cs->cy <= 0) cs->cy = 1;
736 }
737
738 //set client & window rectangles from CreateWindowEx CREATESTRUCT
739 rectWindow.left = cs->x;
740 rectWindow.right = cs->x+cs->cx;
741 rectWindow.top = cs->y;
742 rectWindow.bottom = cs->y+cs->cy;
743 rectClient = rectWindow;
744 OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
745
746 /* Send the WM_CREATE message
747 * Perhaps we shouldn't allow width/height changes as well.
748 * See p327 in "Internals".
749 */
750 maxPos.x = rectWindow.left; maxPos.y = rectWindow.top;
751
752 if(fTaskList) {
753 hTaskList = OSLibWinAddToTaskList(OS2HwndFrame, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
754 }
755
756 localSend32 = (isUnicode) ? ::SendMessageW : ::SendMessageA;
757
758 state = STATE_PRE_WMNCCREATE;
759 if(localSend32(getWindowHandle(), WM_NCCREATE,0,(LPARAM)cs))
760 {
761 RECT tmpRect;
762
763 //CB: recheck flags
764 if (cs->style & (WS_POPUP | WS_CHILD))
765 {
766 fXDefault = FALSE;
767 if (fCXDefault)
768 {
769 fCXDefault = FALSE;
770 cs->cx = cs->cy = 0;
771 rectWindow.right = rectWindow.left;
772 rectWindow.bottom = rectWindow.top;
773 }
774 }
775 tmpRect = rectWindow;
776 state = STATE_POST_WMNCCREATE;
777
778 //set the window size and update the client
779 SetWindowPos(hwndLinkAfter, tmpRect.left, tmpRect.top, tmpRect.right-tmpRect.left, tmpRect.bottom-tmpRect.top,SWP_NOACTIVATE | SWP_NOREDRAW | SWP_FRAMECHANGED);
780
781 state = STATE_PRE_WMCREATE;
782 if (cs->style & WS_VISIBLE) dwStyle |= WS_VISIBLE; //program could change position in WM_CREATE
783 if( (localSend32(getWindowHandle(), WM_CREATE, 0, (LPARAM)cs )) != -1 )
784 {
785 state = STATE_POST_WMCREATE;
786
787 if(!(flags & WIN_NEED_SIZE))
788 {
789 SendInternalMessageA(WM_SIZE, SIZE_RESTORED,
790 MAKELONG(rectClient.right-rectClient.left,
791 rectClient.bottom-rectClient.top));
792
793 if(!::IsWindow(hwnd))
794 {
795 dprintf(("Createwindow: WM_SIZE destroyed window"));
796 goto end;
797 }
798 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
799 if(!::IsWindow(hwnd))
800 {
801 dprintf(("Createwindow: WM_MOVE destroyed window"));
802 goto end;
803 }
804 }
805 if (getStyle() & (WS_MINIMIZE | WS_MAXIMIZE))
806 {
807 RECT newPos;
808 UINT swFlag = (getStyle() & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
809 setStyle(getStyle() & ~(WS_MAXIMIZE | WS_MINIMIZE));
810 MinMaximize(swFlag, &newPos);
811 swFlag = ((getStyle() & WS_CHILD) || GetActiveWindow()) ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED
812 : SWP_NOZORDER | SWP_FRAMECHANGED;
813 SetWindowPos(0, newPos.left, newPos.top, newPos.right, newPos.bottom, swFlag);
814 if(!::IsWindow(hwnd))
815 {
816 dprintf(("Createwindow: min/max destroyed window"));
817 goto end;
818 }
819 }
820
821 if( (getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
822 {
823 /* Notify the parent window only */
824 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
825 {
826 getParent()->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_CREATE, getWindowId()), (LPARAM)getWindowHandle());
827 }
828 if(!::IsWindow(hwnd))
829 {
830 dprintf(("Createwindow: WM_PARENTNOTIFY destroyed window"));
831 goto end;
832 }
833 }
834
835 if(cs->style & WS_VISIBLE) {
836 dwStyle &= ~WS_VISIBLE;
837 ShowWindow(sw);
838 }
839
840 /* Call WH_SHELL hook */
841 if (!(getStyle() & WS_CHILD) && !owner)
842 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWCREATED, getWindowHandle(), 0);
843
844 SetLastError(0);
845 return TRUE;
846 }
847 }
848 dprintf(("Window creation FAILED (NCCREATE cancelled creation)"));
849 SetLastError(ERROR_OUTOFMEMORY); //TODO: Better error
850end:
851 return FALSE;
852}
853//******************************************************************************
854//******************************************************************************
855ULONG Win32BaseWindow::MsgQuit()
856{
857 return SendInternalMessageA(WM_QUIT, 0, 0);
858}
859//******************************************************************************
860//******************************************************************************
861ULONG Win32BaseWindow::MsgClose()
862{
863 return SendInternalMessageA(WM_CLOSE,0,0);
864}
865//******************************************************************************
866//******************************************************************************
867ULONG Win32BaseWindow::MsgDestroy()
868{
869 ULONG rc;
870 Win32BaseWindow *child;
871 HWND hwnd = getWindowHandle();
872
873 state = STATE_DESTROYED;
874
875 if(fDestroyWindowCalled == FALSE)
876 {//this window was destroyed because DestroyWindow was called for it's parent
877 //so: send a WM_PARENTNOTIFY now as that hasn't happened yet
878 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
879 {
880 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
881 {
882 /* Notify the parent window only */
883 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
884 }
885//// else DebugInt3();
886 }
887 }
888 SendInternalMessageA(WM_DESTROY, 0, 0);
889 if(::IsWindow(hwnd) == FALSE) {
890 //object already destroyed, so return immediately
891 return 1;
892 }
893 SendInternalMessageA(WM_NCDESTROY, 0, 0);
894
895 TIMER_KillTimerFromWindow(getWindowHandle());
896
897 if(getRefCount() == 0 && getFirstChild() == NULL && state == STATE_CREATED) {
898 delete this;
899 }
900 else {
901 //make sure no message can ever arrive for this window again (PM or from other win32 windows)
902 dprintf(("Mark window %x (%x) as deleted", getWindowHandle(), this));
903 markDeleted();
904 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
905 OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
906 if(Win32Hwnd) {
907 HwFreeWindowHandle(Win32Hwnd);
908 Win32Hwnd = 0;
909 }
910 }
911 return 1;
912}
913//******************************************************************************
914//******************************************************************************
915ULONG Win32BaseWindow::MsgEnable(BOOL fEnable)
916{
917 if(fEnable) {
918 dwStyle &= ~WS_DISABLED;
919 }
920 else dwStyle |= WS_DISABLED;
921
922 return SendInternalMessageA(WM_ENABLE, fEnable, 0);
923}
924//******************************************************************************
925//TODO: SW_PARENTCLOSING/OPENING flag (lParam)
926//******************************************************************************
927ULONG Win32BaseWindow::MsgShow(BOOL fShow)
928{
929 if(!CanReceiveSizeMsgs() || fDestroyWindowCalled) {
930 return 1;
931 }
932
933 if(fShow) {
934 setStyle(getStyle() | WS_VISIBLE);
935 if(getStyle() & WS_MINIMIZE) {
936 return ShowWindow(SW_RESTORE);
937 }
938 }
939 else setStyle(getStyle() & ~WS_VISIBLE);
940
941 //already sent from ShowWindow
942//// return SendInternalMessageA(WM_SHOWWINDOW, fShow, 0);
943 return 0;
944}
945//******************************************************************************
946//******************************************************************************
947ULONG Win32BaseWindow::MsgPosChanging(LPARAM lp)
948{
949 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
950 // a WM_WINDOWPOSCHANGED msg -> crash)
951 if(!CanReceiveSizeMsgs() || fDestroyWindowCalled)
952 return 0;
953
954 return SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, lp);
955}
956//******************************************************************************
957//******************************************************************************
958ULONG Win32BaseWindow::MsgPosChanged(LPARAM lp)
959{
960 //SvL: Notes crashes when switching views (calls DestroyWindow -> PM sends
961 // a WM_WINDOWPOSCHANGED msg -> crash)
962 if(!CanReceiveSizeMsgs() || fDestroyWindowCalled)
963 return 1;
964
965 return SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, lp);
966}
967//******************************************************************************
968//******************************************************************************
969ULONG Win32BaseWindow::MsgScroll(ULONG msg, ULONG scrollCode, ULONG scrollPos)
970{
971 //According to the SDK docs, the scrollbar handle (lParam) is 0 when the standard
972 //window scrollbars send these messages
973 return SendInternalMessageA(msg, MAKELONG(scrollCode, scrollPos), 0);
974}
975//******************************************************************************
976//******************************************************************************
977ULONG Win32BaseWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd, HWND hwndOS2Win)
978{
979 ULONG rc, procidhwnd = -1, threadidhwnd = 0;
980
981 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
982 if(fDestroyWindowCalled) {
983 return 0;
984 }
985
986 //According to SDK docs, if app returns FALSE & window is being deactivated,
987 //default processing is cancelled
988 //TODO: According to Wine we should proceed anyway if window is sysmodal
989 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
990 {
991 dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
992 return 0;
993 }
994 /* child windows get a WM_CHILDACTIVATE message */
995 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
996 {
997 if(fActivate) {//WM_CHILDACTIVE is for activation only
998 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
999 }
1000 return 0;
1001 }
1002
1003 rc = SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
1004
1005 if(hwndOS2Win) {
1006 threadidhwnd = O32_GetWindowThreadProcessId(hwndOS2Win, &procidhwnd);
1007 }
1008
1009 if(fActivate) {
1010 SendInternalMessageA(WM_ACTIVATEAPP, 1, dwThreadId); //activate; specify window thread id
1011 }
1012 else SendInternalMessageA(WM_ACTIVATEAPP, 0, threadidhwnd); //deactivate; specify thread id of other process
1013 return rc;
1014}
1015//******************************************************************************
1016//******************************************************************************
1017ULONG Win32BaseWindow::MsgChildActivate(BOOL fActivate)
1018{
1019 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
1020 if(fDestroyWindowCalled) {
1021 return 0;
1022 }
1023
1024 //According to SDK docs, if app returns FALSE & window is being deactivated,
1025 //default processing is cancelled
1026 //TODO: According to Wine we should proceed anyway if window is sysmodal
1027 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
1028 {
1029 dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
1030 return 0;
1031 }
1032 /* child windows get a WM_CHILDACTIVATE message */
1033 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1034 {
1035 if(fActivate) {//WM_CHILDACTIVE is for activation only
1036 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
1037 }
1038 return 0;
1039 }
1040 DebugInt3();
1041 return 0;
1042}
1043//******************************************************************************
1044//******************************************************************************
1045ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
1046{
1047 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1048}
1049//******************************************************************************
1050//******************************************************************************
1051ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
1052{
1053 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
1054}
1055//******************************************************************************
1056//******************************************************************************
1057ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1058{
1059 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
1060 if(fDestroyWindowCalled) {
1061 return 0;
1062 }
1063
1064 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1065}
1066//******************************************************************************
1067//******************************************************************************
1068ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1069{
1070 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
1071 if(fDestroyWindowCalled) {
1072 return 0;
1073 }
1074 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1075}
1076//******************************************************************************
1077//******************************************************************************
1078ULONG Win32BaseWindow::MsgButton(MSG *msg)
1079{
1080 BOOL fClick = FALSE;
1081
1082// dprintf(("MsgButton at (%d,%d)", msg->pt.x, msg->pt.y));
1083 switch(msg->message) {
1084 case WM_LBUTTONDBLCLK:
1085 case WM_RBUTTONDBLCLK:
1086 case WM_MBUTTONDBLCLK:
1087 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
1088 {
1089 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
1090 MsgButton(msg);
1091 msg->message++; //button-up
1092 return MsgButton(msg);
1093 }
1094 break;
1095 case WM_NCLBUTTONDBLCLK:
1096 case WM_NCRBUTTONDBLCLK:
1097 case WM_NCMBUTTONDBLCLK:
1098 //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
1099 fClick = TRUE;
1100 break;
1101
1102 case WM_LBUTTONDOWN:
1103 case WM_RBUTTONDOWN:
1104 case WM_MBUTTONDOWN:
1105 case WM_NCLBUTTONDOWN:
1106 case WM_NCRBUTTONDOWN:
1107 case WM_NCMBUTTONDOWN:
1108 fClick = TRUE;
1109 break;
1110 }
1111
1112 if(fClick)
1113 {
1114 HWND hwndTop;
1115
1116 /* Activate the window if needed */
1117 hwndTop = GetTopParent();
1118
1119 HWND hwndActive = GetActiveWindow();
1120 if (hwndTop && (getWindowHandle() != hwndActive))
1121 {
1122 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
1123 MAKELONG( lastHitTestVal, msg->message) );
1124
1125 dprintf2(("WM_MOUSEACTIVATE returned %d", ret));
1126#if 0
1127 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1128 eatMsg = TRUE;
1129#endif
1130 //SvL: 0 is not documented, but experiments in NT4 show that
1131 // the window will get activated when it returns this.
1132 // (FreeCell is an example)
1133 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT) || (ret == 0))
1134 && (hwndTop != GetForegroundWindow()) )
1135 {
1136 Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
1137
1138 //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
1139 if (win32top) {
1140 OSLibWinSetFocus(win32top->getOS2FrameWindowHandle());
1141 RELEASE_WNDOBJ(win32top);
1142 }
1143 }
1144 }
1145 }
1146
1147 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1148
1149 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1150}
1151//******************************************************************************
1152//******************************************************************************
1153ULONG Win32BaseWindow::MsgPaint(ULONG tmp, ULONG select)
1154{
1155 if (select && IsWindowIconic())
1156 return SendInternalMessageA(WM_PAINTICON, 1, 0);
1157 else
1158 return SendInternalMessageA(WM_PAINT, 0, 0);
1159}
1160//******************************************************************************
1161//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1162// (or are we simply erasing too much here)
1163//******************************************************************************
1164ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1165{
1166 ULONG rc;
1167 HDC hdcErase = hdc;
1168
1169 if (hdcErase == 0)
1170 hdcErase = GetDC(getWindowHandle());
1171
1172 if(IsWindowIconic())
1173 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1174 else
1175 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1176 if (hdc == 0)
1177 ReleaseDC(getWindowHandle(), hdcErase);
1178 return (rc);
1179}
1180//******************************************************************************
1181//******************************************************************************
1182ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1183{
1184 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1185 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1186
1187 //translated message == WM_(NC)MOUSEMOVE
1188 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1189}
1190//******************************************************************************
1191//******************************************************************************
1192ULONG Win32BaseWindow::MsgChar(MSG *msg)
1193{
1194 return DispatchMsgA(msg);
1195}
1196//******************************************************************************
1197//TODO: Should use update region, not rectangle
1198//******************************************************************************
1199ULONG Win32BaseWindow::MsgNCPaint(PRECT pUpdateRect)
1200{
1201 HRGN hrgn;
1202 ULONG rc;
1203 RECT client = rectClient;
1204
1205 if ((pUpdateRect->left >= client.left) && (pUpdateRect->left < client.right) &&
1206 (pUpdateRect->right >= client.left) && (pUpdateRect->right < client.right) &&
1207 (pUpdateRect->top >= client.top) && (pUpdateRect->top < client.bottom) &&
1208 (pUpdateRect->bottom >= client.top) && (pUpdateRect->bottom < client.bottom))
1209 {
1210 return 0;
1211 }
1212
1213 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", pUpdateRect->left, pUpdateRect->top, pUpdateRect->right, pUpdateRect->bottom));
1214 hrgn = CreateRectRgnIndirect(pUpdateRect);
1215
1216 rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
1217
1218 DeleteObject(hrgn);
1219
1220 return rc;
1221}
1222//******************************************************************************
1223//Called when either the frame's size or position has changed (lpWndPos != NULL)
1224//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1225//******************************************************************************
1226ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1227{
1228 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1229 RECT newClientRect;
1230 WINDOWPOS wndPos;
1231 ULONG rc;
1232
1233 if(lpWndPos)
1234 {
1235 //set new window rectangle
1236 setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
1237 lpWndPos->y+lpWndPos->cy);
1238 newWindowRect = rectWindow;
1239 }
1240 else {
1241 wndPos.hwnd = getWindowHandle();
1242 wndPos.hwndInsertAfter = 0;
1243 newWindowRect= rectWindow;
1244 wndPos.x = newWindowRect.left;
1245 wndPos.y = newWindowRect.top;
1246 wndPos.cx = newWindowRect.right - newWindowRect.left;
1247 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1248 wndPos.flags = SWP_FRAMECHANGED;
1249 lpWndPos = &wndPos;
1250 }
1251
1252 newClientRect = rectClient;
1253 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &newClientRect);
1254 rectClient = newClientRect; //must update rectClient here
1255
1256 dprintf(("MsgFormatFrame: old client rect (%d,%d)(%d,%d), new client (%d,%d)(%d,%d)", client.left, client.top, client.right, client.bottom, rectClient.left, rectClient.top, rectClient.right, rectClient.bottom));
1257 dprintf(("MsgFormatFrame: old window rect (%d,%d)(%d,%d), new window (%d,%d)(%d,%d)", oldWindowRect.left, oldWindowRect.top, oldWindowRect.right, oldWindowRect.bottom, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
1258
1259 if(!CanReceiveSizeMsgs() || !EqualRect(&client, &rectClient)) {
1260 OSLibWinSetClientPos(getOS2WindowHandle(), rectClient.left, rectClient.top, getClientWidth(), getClientHeight(), getWindowHeight());
1261 }
1262
1263#if 1
1264//this doesn't always work
1265// if(CanReceiveSizeMsgs() && (client.left != rectClient.left || client.top != rectClient.top))
1266 if(CanReceiveSizeMsgs() && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
1267 || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
1268 (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
1269 {
1270 Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
1271
1272 //client rectangle has moved -> inform children
1273 dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
1274 while(child) {
1275 ::SetWindowPos(child->getWindowHandle(),
1276 HWND_TOP, child->getWindowRect()->left,
1277 child->getWindowRect()->top, 0, 0,
1278 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
1279 child = (Win32BaseWindow *)child->getNextChild();
1280 }
1281 }
1282#endif
1283 if(fOS2Look && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1284 {
1285 RECT rect = {0};
1286 int height = getWindowHeight();
1287 RECTLOS2 rectOS2;
1288
1289 AdjustRectOuter(&rect, FALSE);
1290
1291 rect.left = -rect.left;
1292 rect.top = rect.bottom - rect.top;
1293 rect.right = rectWindow.right - rectWindow.left - rect.right;
1294
1295 rectOS2.xLeft = rect.left;
1296 rectOS2.xRight = rect.right;
1297 rectOS2.yBottom = height - rect.top;
1298 rectOS2.yTop = height - rect.bottom;
1299 OSLibWinPositionFrameControls(getOS2FrameWindowHandle(), &rectOS2, dwStyle, dwExStyle, IconForWindow(ICON_SMALL));
1300 }
1301 return rc;
1302}
1303//******************************************************************************
1304//******************************************************************************
1305ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1306{
1307 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1308}
1309//******************************************************************************
1310//******************************************************************************
1311ULONG Win32BaseWindow::MsgGetTextLength()
1312{
1313 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1314}
1315//******************************************************************************
1316//******************************************************************************
1317void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1318{
1319 SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
1320}
1321//******************************************************************************
1322//******************************************************************************
1323BOOL Win32BaseWindow::isMDIClient()
1324{
1325 return FALSE;
1326}
1327//******************************************************************************
1328//******************************************************************************
1329BOOL Win32BaseWindow::isMDIChild()
1330{
1331 return FALSE;
1332}
1333//******************************************************************************
1334//TODO: Not complete
1335//******************************************************************************
1336BOOL Win32BaseWindow::isFrameWindow()
1337{
1338 if(getParent() == NULL)
1339 return TRUE;
1340
1341 return FALSE;
1342}
1343//******************************************************************************
1344//******************************************************************************
1345BOOL Win32BaseWindow::isDesktopWindow()
1346{
1347 return FALSE;
1348}
1349//******************************************************************************
1350//******************************************************************************
1351BOOL Win32BaseWindow::IsWindowIconic()
1352{
1353 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1354}
1355//******************************************************************************
1356//******************************************************************************
1357SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1358{
1359 switch(nBar)
1360 {
1361 case SB_HORZ:
1362 if (!horzScrollInfo)
1363 {
1364 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1365 if (!horzScrollInfo) break;
1366 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1367 horzScrollInfo->MaxVal = 100;
1368 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1369 }
1370 return horzScrollInfo;
1371
1372 case SB_VERT:
1373 if (!vertScrollInfo)
1374 {
1375 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1376 if (!vertScrollInfo) break;
1377 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1378 vertScrollInfo->MaxVal = 100;
1379 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1380 }
1381 return vertScrollInfo;
1382 }
1383
1384 return NULL;
1385}
1386//******************************************************************************
1387//******************************************************************************
1388LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1389{
1390 //SvL: Set background color to default button color (not window (white))
1391 if(ctlType == CTLCOLOR_BTN)
1392 {
1393 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1394 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1395 return GetSysColorBrush(COLOR_BTNFACE);
1396 }
1397 //SvL: Set background color to default dialog color if window is dialog
1398 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1399 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1400 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1401 return GetSysColorBrush(COLOR_BTNFACE);
1402 }
1403 if( ctlType == CTLCOLOR_SCROLLBAR)
1404 {
1405 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1406 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1407 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1408 SetBkColor( hdc, bk);
1409
1410 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1411 * we better use 0x55aa bitmap brush to make scrollbar's background
1412 * look different from the window background.
1413 */
1414 if (bk == GetSysColor(COLOR_WINDOW)) {
1415 return GetPattern55AABrush();
1416 }
1417
1418 UnrealizeObject( hb );
1419 return (LRESULT)hb;
1420 }
1421
1422 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1423
1424 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1425 {
1426 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1427 }
1428 else
1429 {
1430 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1431 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1432 }
1433 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1434}
1435//******************************************************************************
1436//******************************************************************************
1437LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1438{
1439 /*
1440 * Visibility flag.
1441 */
1442 if ( (uFlags & PRF_CHECKVISIBLE) &&
1443 !IsWindowVisible(getWindowHandle()) )
1444 return 0;
1445
1446 /*
1447 * Unimplemented flags.
1448 */
1449 if ( (uFlags & PRF_CHILDREN) ||
1450 (uFlags & PRF_OWNED) ||
1451 (uFlags & PRF_NONCLIENT) )
1452 {
1453 dprintf(("WM_PRINT message with unsupported flags\n"));
1454 }
1455
1456 /*
1457 * Background
1458 */
1459 if ( uFlags & PRF_ERASEBKGND)
1460 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1461
1462 /*
1463 * Client area
1464 */
1465 if ( uFlags & PRF_CLIENT)
1466 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1467
1468
1469 return 0;
1470}
1471//******************************************************************************
1472//******************************************************************************
1473LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1474{
1475 switch(Msg)
1476 {
1477 case WM_CLOSE:
1478 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1479 DestroyWindow();
1480 return 0;
1481
1482 case WM_GETTEXTLENGTH:
1483 if(windowNameA) {
1484 return strlen(windowNameA);
1485 }
1486 else {
1487 return 0;
1488 }
1489
1490 case WM_GETTEXT:
1491 if (!lParam || !wParam) return 0;
1492 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1493 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1494 return min((windowNameA ? strlen(windowNameA) : 0), wParam);
1495
1496 case WM_SETTEXT:
1497 {
1498 LPCSTR lpsz = (LPCSTR)lParam;
1499
1500 if(windowNameA) free(windowNameA);
1501 if(windowNameW) free(windowNameW);
1502 if (lParam)
1503 {
1504 int wndNameLength = strlen(lpsz);
1505 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1506 strcpy(windowNameA, lpsz);
1507 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1508 lstrcpyAtoW(windowNameW, windowNameA);
1509 }
1510 else
1511 {
1512 windowNameA = NULL;
1513 windowNameW = NULL;
1514 }
1515 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1516 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1517 {
1518 HandleNCPaint((HRGN)1);
1519 if(hTaskList) {
1520 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1521 }
1522 if(fOS2Look) {
1523 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1524 }
1525 }
1526
1527 return TRUE;
1528 }
1529
1530 case WM_SETREDRAW:
1531 {
1532 if (wParam)
1533 {
1534 setStyle(getStyle() | WS_VISIBLE);
1535 dprintf(("Enable window update for %x", getWindowHandle()));
1536 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
1537 }
1538 else
1539 {
1540 if (getStyle() & WS_VISIBLE)
1541 {
1542 setStyle(getStyle() & ~WS_VISIBLE);
1543 dprintf(("Disable window update for %x", getWindowHandle()));
1544 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
1545 }
1546 }
1547 return 0;
1548 }
1549
1550 case WM_CTLCOLORMSGBOX:
1551 case WM_CTLCOLOREDIT:
1552 case WM_CTLCOLORLISTBOX:
1553 case WM_CTLCOLORBTN:
1554 case WM_CTLCOLORDLG:
1555 case WM_CTLCOLORSTATIC:
1556 case WM_CTLCOLORSCROLLBAR:
1557 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1558
1559 case WM_CTLCOLOR:
1560 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1561
1562 case WM_VKEYTOITEM:
1563 case WM_CHARTOITEM:
1564 return -1;
1565
1566 case WM_PARENTNOTIFY:
1567 return 0;
1568
1569 case WM_MOUSEACTIVATE:
1570 {
1571 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1572 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1573 {
1574 if(getParent()) {
1575 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1576 if(rc) return rc;
1577 }
1578 }
1579 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1580 }
1581
1582 case WM_ACTIVATE:
1583 /* The default action in Windows is to set the keyboard focus to
1584 * the window, if it's being activated and not minimized */
1585 if (LOWORD(wParam) != WA_INACTIVE) {
1586 if(!(getStyle() & WS_MINIMIZE))
1587 SetFocus(getWindowHandle());
1588 }
1589 return 0;
1590
1591 case WM_SETCURSOR:
1592 {
1593 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1594 if((getStyle() & WS_CHILD))
1595 {
1596 if(getParent()) {
1597 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1598 if(rc) return rc;
1599 }
1600 }
1601 if (wParam == getWindowHandle())
1602 {
1603 HCURSOR hCursor;
1604
1605 switch(LOWORD(lParam))
1606 {
1607 case HTCLIENT:
1608 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1609 break;
1610
1611 case HTLEFT:
1612 case HTRIGHT:
1613 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1614 break;
1615
1616 case HTTOP:
1617 case HTBOTTOM:
1618 hCursor = LoadCursorA(0,IDC_SIZENSA);
1619 break;
1620
1621 case HTTOPLEFT:
1622 case HTBOTTOMRIGHT:
1623 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1624 break;
1625
1626 case HTTOPRIGHT:
1627 case HTBOTTOMLEFT:
1628 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1629 break;
1630
1631 default:
1632 hCursor = LoadCursorA(0,IDC_ARROWA);
1633 break;
1634 }
1635
1636 if (hCursor)
1637 {
1638 SetCursor(hCursor);
1639 return 1;
1640 }
1641 else return 0;
1642 }
1643 else return 0;
1644 }
1645
1646 case WM_MOUSEMOVE:
1647 return 0;
1648
1649 case WM_WINDOWPOSCHANGED:
1650 {
1651 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1652 WPARAM wp = SIZE_RESTORED;
1653
1654 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1655 {
1656 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1657 }
1658 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1659 {
1660 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1661 else
1662 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1663
1664 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1665 rectClient.bottom - rectClient.top));
1666 }
1667 return 0;
1668 }
1669 case WM_WINDOWPOSCHANGING:
1670 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1671
1672 case WM_ERASEBKGND:
1673 case WM_ICONERASEBKGND:
1674 {
1675 RECT rect;
1676 int rc;
1677
1678 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1679
1680 rc = GetClipBox( (HDC)wParam, &rect );
1681 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1682 {
1683 HBRUSH hBrush = windowClass->getBackgroundBrush();
1684
1685 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1686 hBrush = GetSysColorBrush(hBrush-1);
1687
1688 FillRect( (HDC)wParam, &rect, hBrush);
1689 }
1690 return 1;
1691 }
1692
1693 case WM_PRINT:
1694 return DefWndPrint(wParam,lParam);
1695
1696 case WM_PAINTICON:
1697 case WM_PAINT:
1698 {
1699 PAINTSTRUCT ps;
1700 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1701 if( hdc )
1702 {
1703 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1704 {
1705 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1706 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1707 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1708 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1709 }
1710 EndPaint(getWindowHandle(), &ps );
1711 }
1712 return 0;
1713 }
1714
1715 case WM_GETDLGCODE:
1716 return 0;
1717
1718 case WM_NCPAINT:
1719 return HandleNCPaint((HRGN)wParam);
1720
1721 case WM_NCACTIVATE:
1722 return HandleNCActivate(wParam);
1723
1724 case WM_NCCREATE:
1725 return(TRUE);
1726
1727 case WM_NCDESTROY:
1728 return 0;
1729
1730 case WM_NCCALCSIZE:
1731 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1732
1733 case WM_NCLBUTTONDOWN:
1734 return HandleNCLButtonDown(wParam,lParam);
1735
1736 case WM_LBUTTONDBLCLK:
1737 case WM_NCLBUTTONDBLCLK:
1738 return HandleNCLButtonDblClk(wParam,lParam);
1739
1740 case WM_NCRBUTTONDOWN:
1741 case WM_NCRBUTTONDBLCLK:
1742 case WM_NCMBUTTONDOWN:
1743 case WM_NCMBUTTONDBLCLK:
1744 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1745 return 0;
1746
1747 case WM_NCRBUTTONUP:
1748 return HandleNCRButtonUp(wParam,lParam);
1749
1750 case WM_NCMBUTTONUP:
1751 return 0;
1752
1753 case WM_NCHITTEST:
1754 {
1755 POINT point;
1756 LRESULT retvalue;
1757
1758 point.x = (SHORT)LOWORD(lParam);
1759 point.y = (SHORT)HIWORD(lParam);
1760
1761 retvalue = HandleNCHitTest(point);
1762#if 0 //CB: let the Corel people fix the bugs first
1763 if(retvalue == HTMENU)
1764 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1765 else
1766 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1767#endif
1768 return retvalue;
1769 }
1770
1771 case WM_SYSCOMMAND:
1772 {
1773 POINT point;
1774
1775 point.x = LOWORD(lParam);
1776 point.y = HIWORD(lParam);
1777 return HandleSysCommand(wParam,&point);
1778 }
1779
1780 case WM_SYSKEYDOWN:
1781 {
1782 if( HIWORD(lParam) & KEYDATA_ALT )
1783 {
1784 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
1785 if( wParam == VK_MENU && !iMenuSysKey )
1786 iMenuSysKey = 1;
1787 else
1788 iMenuSysKey = 0;
1789
1790 iF10Key = 0;
1791
1792 if( wParam == VK_F4 ) /* try to close the window */
1793 {
1794 HWND top = GetTopWindow();
1795 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
1796 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
1797 }
1798 }
1799 else if( wParam == VK_F10 )
1800 iF10Key = 1;
1801 else
1802 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
1803 SendMessageW(WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
1804
1805 Win32BaseWindow *siblingWindow;
1806 HWND sibling;
1807 char nameBuffer [40], mnemonic;
1808 int nameLength;
1809
1810 GetWindowTextA (nameBuffer, 40);
1811
1812 // search all sibling to see it this key is their mnemonic
1813 sibling = GetWindow (GW_HWNDFIRST);
1814 while (sibling != 0) {
1815 siblingWindow = GetWindowFromHandle (sibling);
1816 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1817
1818 // find the siblings mnemonic
1819 mnemonic = '\0';
1820 for (int i=0 ; i<nameLength ; i++) {
1821 if (IsDBCSLeadByte(nameBuffer[i])) {
1822 // Skip DBCS
1823 continue;
1824 }
1825 if (nameBuffer [i] == '&') {
1826 mnemonic = nameBuffer [i+1];
1827 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1828 mnemonic -= 32; // make it uppercase
1829 break; // stop searching
1830 }
1831 }
1832
1833 // key matches siblings mnemonic, send mouseclick
1834 if (mnemonic == (char) wParam) {
1835 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1836 }
1837 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1838 RELEASE_WNDOBJ(siblingWindow);
1839 }
1840
1841 return 0;
1842 }
1843
1844 case WM_KEYUP:
1845 case WM_SYSKEYUP:
1846 /* Press and release F10 or ALT */
1847 if (((wParam == VK_MENU) && iMenuSysKey) ||
1848 ((wParam == VK_F10) && iF10Key))
1849 ::SendMessageW( GetTopWindow(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
1850 iMenuSysKey = iF10Key = 0;
1851 break;
1852
1853 case WM_SYSCHAR:
1854 {
1855 iMenuSysKey = 0;
1856 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1857 {
1858 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1859 (WPARAM)SC_RESTORE, 0L );
1860 break;
1861 }
1862 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1863 {
1864 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
1865 break;
1866 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1867 ::SendMessageW(GetParent(), Msg, wParam, lParam );
1868 }
1869 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1870 }
1871#if 0
1872 else /* check for Ctrl-Esc */
1873 if (wParam != VK_ESCAPE) MessageBeep(0);
1874 break;
1875#endif
1876 }
1877
1878 case WM_SETHOTKEY:
1879 hotkey = wParam;
1880 return 1; //CB: always successful
1881
1882 case WM_GETHOTKEY:
1883 return hotkey;
1884
1885 case WM_CONTEXTMENU:
1886 if ((dwStyle & WS_CHILD) && getParent())
1887 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1888 return 0;
1889
1890 case WM_SHOWWINDOW:
1891 if (!lParam) return 0; /* sent from ShowWindow */
1892 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1893 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1894 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1895 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1896 return 0;
1897
1898 case WM_CANCELMODE:
1899 if (getParent() == windowDesktop) EndMenu();
1900 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1901 return 0;
1902
1903 case WM_DROPOBJECT:
1904 return DRAG_FILE;
1905
1906 case WM_QUERYDROPOBJECT:
1907 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1908
1909 case WM_QUERYDRAGICON:
1910 {
1911 HICON hDragIcon = windowClass->getCursor();
1912 UINT len;
1913
1914 if(hDragIcon) return (LRESULT)hDragIcon;
1915 for(len = 1; len < 64; len++)
1916 {
1917 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1918 if(hDragIcon)
1919 return (LRESULT)hDragIcon;
1920 }
1921 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1922 }
1923
1924 case WM_QUERYOPEN:
1925 case WM_QUERYENDSESSION:
1926 return 1;
1927
1928 case WM_NOTIFYFORMAT:
1929 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1930
1931 case WM_SETICON:
1932 case WM_GETICON:
1933 {
1934 LRESULT result = 0;
1935
1936 /* Set the appropriate icon members in the window structure. */
1937 if (wParam == ICON_SMALL)
1938 {
1939 result = hIconSm;
1940 if (Msg == WM_SETICON)
1941 hIconSm = (HICON)lParam;
1942 }
1943 else
1944 {
1945 result = hIcon;
1946 if (Msg == WM_SETICON)
1947 {
1948 hIcon = (HICON)lParam;
1949 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1950 OSLibWinSetIcon(OS2HwndFrame,hIcon);
1951 }
1952 }
1953 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1954 HandleNCPaint((HRGN)1);
1955
1956 return result;
1957 }
1958
1959 case WM_HELP:
1960 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1961 break;
1962
1963 case WM_NOTIFY:
1964 return 0; //comctl32 controls expect this
1965
1966 default:
1967 return 0;
1968 }
1969 return 0;
1970}
1971//******************************************************************************
1972//******************************************************************************
1973LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1974{
1975 switch(Msg)
1976 {
1977 case WM_GETTEXTLENGTH:
1978 if(windowNameW) {
1979 return lstrlenW(windowNameW);
1980 }
1981 else return 0;
1982
1983 case WM_GETTEXT:
1984 if (!lParam || !wParam) return 0;
1985 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1986 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1987 return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam);
1988
1989 case WM_SETTEXT:
1990 {
1991 LPWSTR lpsz = (LPWSTR)lParam;
1992
1993 if(windowNameA) free(windowNameA);
1994 if(windowNameW) free(windowNameW);
1995 if (lParam)
1996 {
1997 // Wide
1998 int wndNameLength = lstrlenW(lpsz);
1999 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
2000 lstrcpyW(windowNameW,lpsz);
2001 // Ascii
2002 LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz);
2003 if(tmp) {
2004 long tmpLength = strlen( tmp );
2005 windowNameA = (LPSTR)_smalloc(tmpLength+1);
2006 strcpy(windowNameA,tmp);
2007 windowNameA[tmpLength] = 0; // need ?
2008 HEAP_free(tmp);
2009 }
2010 else {
2011 windowNameA = (LPSTR)_smalloc(1);
2012 windowNameA[0] = 0;
2013 }
2014 }
2015 else
2016 {
2017 windowNameA = NULL;
2018 windowNameW = NULL;
2019 }
2020 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
2021 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2022 {
2023 HandleNCPaint((HRGN)1);
2024 if(hTaskList) {
2025 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2026 }
2027 if(fOS2Look) {
2028 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
2029 }
2030 }
2031
2032 return TRUE;
2033 }
2034
2035 default:
2036 return DefWindowProcA(Msg, wParam, lParam);
2037 }
2038}
2039//******************************************************************************
2040//******************************************************************************
2041LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
2042{
2043 //if the destination window is created by this process & thread, call window proc directly
2044 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
2045 return SendInternalMessageA(Msg, wParam, lParam);
2046 }
2047 //otherwise use WinSendMsg to send it to the right process/thread
2048 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2049 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2050}
2051//******************************************************************************
2052//******************************************************************************
2053LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
2054{
2055 //if the destination window is created by this process & thread, call window proc directly
2056 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
2057 return SendInternalMessageW(Msg, wParam, lParam);
2058 }
2059 //otherwise use WinSendMsg to send it to the right process/thread
2060 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
2061}
2062//******************************************************************************
2063//Called as a result of an OS/2 message or called from a class method
2064//******************************************************************************
2065LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
2066{
2067 LRESULT rc;
2068 HWND hwnd = getWindowHandle();
2069 BOOL fInternalMsgBackup = fInternalMsg;
2070
2071 //if the destination window was created by this process & thread, call window proc directly
2072 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
2073 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2074 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2075 }
2076
2077 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
2078
2079 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
2080
2081 fInternalMsg = TRUE;
2082 switch(Msg)
2083 {
2084 case WM_CREATE:
2085 {
2086 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2087 dprintf(("WM_CREATE returned -1\n"));
2088 rc = -1; //don't create window
2089 break;
2090 }
2091 rc = 0;
2092 break;
2093 }
2094 case WM_LBUTTONDOWN:
2095 case WM_MBUTTONDOWN:
2096 case WM_RBUTTONDOWN:
2097 {
2098 if (getParent())
2099 {
2100 POINTS pt = MAKEPOINTS(lParam);
2101 POINT point;
2102
2103 point.x = pt.x;
2104 point.y = pt.y;
2105 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
2106 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
2107 }
2108 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2109 break;
2110 }
2111 case WM_NCHITTEST:
2112 rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
2113 break;
2114
2115 case WM_DESTROY:
2116 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2117 break;
2118
2119 default:
2120 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2121 break;
2122 }
2123 if(!::IsWindow(hwnd)) {
2124 //window might have been destroyed by now. (this pointer invalid)
2125 //we must return immediately
2126 //(MS Visual C++ install heap corruption)
2127 //TODO: could happen in several places here!!!!
2128 return rc;
2129 }
2130 fInternalMsg = fInternalMsgBackup;
2131 dprintf2(("SendMessageA %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
2132 return rc;
2133}
2134//******************************************************************************
2135//Called as a result of an OS/2 message or called from a class method
2136//******************************************************************************
2137LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
2138{
2139 LRESULT rc;
2140 HWND hwnd = getWindowHandle();
2141 BOOL fInternalMsgBackup = fInternalMsg;
2142
2143 //if the destination window was created by this process & thread, call window proc directly
2144 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
2145 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2146 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2147 }
2148
2149 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
2150
2151 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
2152
2153 fInternalMsg = TRUE;
2154 switch(Msg)
2155 {
2156 case WM_CREATE:
2157 {
2158 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2159 dprintf(("WM_CREATE returned -1\n"));
2160 rc = -1; //don't create window
2161 break;
2162 }
2163 rc = 0;
2164 break;
2165 }
2166 case WM_LBUTTONDOWN:
2167 case WM_MBUTTONDOWN:
2168 case WM_RBUTTONDOWN:
2169 NotifyParent(Msg, wParam, lParam);
2170 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2171 break;
2172
2173 case WM_NCHITTEST:
2174 rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
2175 break;
2176
2177 case WM_DESTROY:
2178 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2179 break;
2180 default:
2181 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2182 break;
2183 }
2184 if(!::IsWindow(hwnd)) {
2185 //window might have been destroyed by now. (this pointer invalid)
2186 //we must return immediately
2187 //(MS Visual C++ install heap corruption)
2188 //TODO: could happen in several places here!!!!
2189 return rc;
2190 }
2191 fInternalMsg = fInternalMsgBackup;
2192 dprintf2(("SendMessageW %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
2193 return rc;
2194}
2195//******************************************************************************
2196//******************************************************************************
2197void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2198{
2199 CWPSTRUCT cwp;
2200
2201 cwp.lParam = lParam;
2202 cwp.wParam = wParam;
2203 cwp.message = Msg;
2204 cwp.hwnd = getWindowHandle();
2205
2206 switch(hooktype) {
2207 case WH_CALLWNDPROC:
2208 if(fUnicode) {
2209 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2210 }
2211 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2212 break;
2213 }
2214}
2215//******************************************************************************
2216//TODO: Do this more efficiently
2217//******************************************************************************
2218LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2219{
2220 Win32BaseWindow *window;
2221 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2222
2223 dprintf(("BroadCastMessageA %x %x %x %s", msg, wParam, lParam, (type == BROADCAST_SEND) ? "Send" : "Post"));
2224
2225 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2226 window = GetWindowFromHandle(hwnd++);
2227 if(window) {
2228 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2229 {
2230 if(type == BROADCAST_SEND) {
2231 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
2232 }
2233 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2234 }
2235 RELEASE_WNDOBJ(window);
2236 }
2237 }
2238 return 0;
2239}
2240//******************************************************************************
2241//TODO: Do this more efficiently
2242//******************************************************************************
2243LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2244{
2245 Win32BaseWindow *window;
2246 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2247
2248 dprintf(("BroadCastMessageW %x %x %x %s", msg, wParam, lParam, (type == BROADCAST_SEND) ? "Send" : "Post"));
2249
2250 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2251 window = GetWindowFromHandle(hwnd++);
2252 if(window) {
2253 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2254 {
2255 if(type == BROADCAST_SEND) {
2256 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
2257 }
2258 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2259 }
2260 RELEASE_WNDOBJ(window);
2261 }
2262 }
2263 return 0;
2264}
2265//******************************************************************************
2266//******************************************************************************
2267void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2268{
2269 Win32BaseWindow *window = this;
2270 Win32BaseWindow *parentwindow;
2271
2272 while(window)
2273 {
2274 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2275 {
2276 /* Notify the parent window only */
2277 parentwindow = window->getParent();
2278 if(parentwindow) {
2279 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2280 }
2281 }
2282 else break;
2283
2284 window = parentwindow;
2285 }
2286}
2287//******************************************************************************
2288// Returns the big or small icon for the window, falling back to the
2289// class as windows does.
2290//******************************************************************************
2291HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2292{
2293 HICON hWndIcon;
2294
2295 if (fType == ICON_BIG)
2296 {
2297 if (hIcon)
2298 hWndIcon = hIcon;
2299 else
2300 if (windowClass && windowClass->getIcon())
2301 hWndIcon = windowClass->getIcon();
2302 else
2303 if (!(dwStyle & DS_MODALFRAME))
2304 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2305 else hWndIcon = 0;
2306 }
2307 else
2308 {
2309 if (hIconSm)
2310 hWndIcon = hIconSm;
2311 else
2312 if (hIcon)
2313 hWndIcon = hIcon;
2314 else
2315 if (windowClass && windowClass->getIconSm())
2316 hWndIcon = windowClass->getIconSm();
2317 else
2318 if (windowClass && windowClass->getIcon())
2319 hWndIcon = windowClass->getIcon();
2320 else
2321 if (!(dwStyle & DS_MODALFRAME))
2322 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2323 else hWndIcon = 0;
2324 }
2325
2326 return hWndIcon;
2327}
2328//******************************************************************************
2329//******************************************************************************
2330BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2331{
2332 ULONG swp = 0;
2333 HWND hWinAfter;
2334 BOOL rc,wasVisible,showFlag;
2335 RECT newPos = {0, 0, 0, 0};
2336
2337 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2338 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2339
2340 dwOldStyle = getStyle();
2341
2342 switch(nCmdShow)
2343 {
2344 case SW_HIDE:
2345 if (!wasVisible) goto END;
2346
2347 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2348 break;
2349
2350 case SW_SHOWMINNOACTIVE:
2351 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2352 /* fall through */
2353 case SW_SHOWMINIMIZED:
2354 swp |= SWP_SHOWWINDOW;
2355 /* fall through */
2356 case SW_MINIMIZE:
2357 swp |= SWP_FRAMECHANGED;
2358 if( !(getStyle() & WS_MINIMIZE) ) {
2359 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2360 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2361 }
2362 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2363 break;
2364
2365 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2366 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2367 if( !(getStyle() & WS_MAXIMIZE) ) {
2368 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2369 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2370 }
2371 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2372 break;
2373
2374 case SW_SHOWNA:
2375 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2376 /* fall through */
2377 case SW_SHOW:
2378 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2379
2380 /*
2381 * ShowWindow has a little peculiar behavior that if the
2382 * window is already the topmost window, it will not
2383 * activate it.
2384 */
2385 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2386 swp |= SWP_NOACTIVATE;
2387
2388 break;
2389
2390 case SW_SHOWNOACTIVATE:
2391 swp |= SWP_NOZORDER;
2392 if (GetActiveWindow())
2393 swp |= SWP_NOACTIVATE;
2394 /* fall through */
2395 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2396 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2397 case SW_RESTORE:
2398 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2399
2400 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2401 swp |= MinMaximize(SW_RESTORE, &newPos );
2402 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2403 }
2404 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2405 break;
2406 }
2407
2408 showFlag = (nCmdShow != SW_HIDE);
2409 if (showFlag != wasVisible)
2410 {
2411 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2412 if (!::IsWindow( getWindowHandle() )) goto END;
2413 }
2414
2415 /* We can't activate a child window */
2416 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2417 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2418
2419 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2420
2421 if(!(swp & SWP_NOACTIVATE)) {
2422 OSLibWinSetActiveWindow(OS2HwndFrame);
2423 }
2424
2425 if (flags & WIN_NEED_SIZE)
2426 {
2427 /* should happen only in CreateWindowEx() */
2428 int wParam = SIZE_RESTORED;
2429
2430 flags &= ~WIN_NEED_SIZE;
2431 if (dwStyle & WS_MAXIMIZE)
2432 wParam = SIZE_MAXIMIZED;
2433 else
2434 if (dwStyle & WS_MINIMIZE)
2435 wParam = SIZE_MINIMIZED;
2436
2437 SendInternalMessageA(WM_SIZE, wParam,
2438 MAKELONG(rectClient.right-rectClient.left,
2439 rectClient.bottom-rectClient.top));
2440 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2441 }
2442//testestest
2443 //temporary workaround for file dialogs with template dialog child
2444 //they don't redraw when switching directories
2445 //For some reason the new child's (syslistview32) update rectangle stays
2446 //empty after its parent is made visible with ShowWindow
2447 //TODO: find real cause
2448 if(!wasVisible) {
2449 InvalidateRect(getWindowHandle(), NULL, TRUE);
2450 }
2451//testestest
2452END:
2453 fMinMaxChange = FALSE;
2454 return wasVisible;
2455}
2456//******************************************************************************
2457//******************************************************************************
2458BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2459{
2460 BOOL rc = FALSE;
2461 Win32BaseWindow *window;
2462 HWND hParent = 0;
2463 RECT oldClientRect = rectClient;
2464
2465 if (fuFlags &
2466 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2467 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2468 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2469 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2470 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
2471 {
2472 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2473 return FALSE;
2474 }
2475
2476 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
2477 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2478 }
2479
2480 if(IsWindowDestroyed()) {
2481 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2482 dprintf(("SetWindowPos; window already destroyed"));
2483 return TRUE;
2484 }
2485#if 0
2486 /* Fix redundant flags */
2487 if(getStyle() & WS_VISIBLE) {
2488 fuFlags &= ~SWP_SHOWWINDOW;
2489 }
2490 else
2491 {
2492 if (!(fuFlags & SWP_SHOWWINDOW))
2493 fuFlags |= SWP_NOREDRAW;
2494 fuFlags &= ~SWP_HIDEWINDOW;
2495 }
2496
2497 if(cx < 0) cx = 0;
2498 if(cy < 0) cy = 0;
2499
2500 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2501 fuFlags |= SWP_NOSIZE; /* Already the right size */
2502 }
2503
2504 if((rectWindow.left == x) && (rectWindow.top == y)) {
2505 fuFlags |= SWP_NOMOVE; /* Already the right position */
2506 }
2507
2508 if(getWindowHandle() == GetActiveWindow()) {
2509 fuFlags |= SWP_NOACTIVATE; /* Already active */
2510 }
2511 else
2512 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2513 {
2514 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2515 {
2516 fuFlags &= ~SWP_NOZORDER;
2517 hwndInsertAfter = HWND_TOP;
2518 }
2519 }
2520#endif
2521
2522 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2523 if(state < STATE_POST_WMNCCREATE)
2524 {//don't change size; modify internal structures only
2525 //TODO: not 100% correct yet (activate)
2526 dprintf2(("state < STATE_POST_WMNCCREATE"));
2527 if(!(fuFlags & SWP_NOZORDER)) {
2528 hwndLinkAfter = hwndInsertAfter;
2529 }
2530 if(!(fuFlags & SWP_NOMOVE)) {
2531 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2532 rectWindow.top = y;
2533 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2534 rectWindow.left = x;
2535 }
2536 if(!(fuFlags & SWP_NOSIZE)) {
2537 rectWindow.bottom = rectWindow.top + cy;
2538 rectWindow.right = rectWindow.left + cx;
2539 }
2540 return TRUE;
2541 }
2542
2543 WINDOWPOS wpos;
2544 SWP swp, swpOld;
2545 wpos.flags = fuFlags;
2546 wpos.cy = cy;
2547 wpos.cx = cx;
2548 wpos.x = x;
2549 wpos.y = y;
2550 wpos.hwndInsertAfter = hwndInsertAfter;
2551 wpos.hwnd = getWindowHandle();
2552
2553 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2554 {
2555 if (isChild())
2556 {
2557 if(!getParent()) {
2558 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2559 }
2560 }
2561 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2562 }
2563
2564 if(getParent()) {
2565 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2566 OS2HwndFrame);
2567 }
2568 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2569
2570 if (swp.fl == 0) {
2571 dprintf2(("swp.fl == 0"));
2572 if(fuFlags & SWP_FRAMECHANGED)
2573 {
2574 NotifyFrameChanged(&wpos, &oldClientRect);
2575 }
2576 return TRUE;
2577 }
2578
2579// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2580 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2581 {
2582 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2583 if(wndBehind) {
2584 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2585 RELEASE_WNDOBJ(wndBehind);
2586 }
2587 else {
2588 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2589 swp.hwndInsertBehind = 0;
2590 }
2591 }
2592 swp.hwnd = OS2HwndFrame;
2593
2594 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2595 setStyle(getStyle() | WS_VISIBLE);
2596 if(hTaskList) {
2597 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2598 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2599 }
2600 }
2601 else
2602 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2603 setStyle(getStyle() & ~WS_VISIBLE);
2604 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2605 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2606 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2607 }
2608 }
2609 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2610 rc = OSLibWinSetMultWindowPos(&swp, 1);
2611
2612 if(rc == FALSE)
2613 {
2614 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2615 return 0;
2616 }
2617
2618 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2619 {
2620 NotifyFrameChanged(&wpos, &oldClientRect);
2621 }
2622 return (rc);
2623}
2624//******************************************************************************
2625//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2626//******************************************************************************
2627BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2628{
2629 rectWindow.left += dx;
2630 rectWindow.right += dx;
2631 rectWindow.top += dy;
2632 rectWindow.bottom += dy;
2633 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2634 return TRUE;
2635}
2636//******************************************************************************
2637//******************************************************************************
2638void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2639{
2640 HRGN hrgn, hrgnClient;
2641 RECT rect;
2642
2643 MsgFormatFrame(NULL);
2644
2645 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2646 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2647 {
2648 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2649 wpos->cx = RECT_WIDTH(rectWindow);
2650 wpos->cy = RECT_HEIGHT(rectWindow);
2651 }
2652
2653 if(rectClient.left != oldClientRect->left ||
2654 rectClient.top != oldClientRect->top)
2655 {
2656 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2657 wpos->x = rectWindow.left;
2658 wpos->y = rectWindow.top;
2659 }
2660
2661 WINDOWPOS wpOld = *wpos;
2662 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2663
2664 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2665 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2666 {
2667 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2668 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2669 }
2670 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2671
2672 //Calculate invalid areas
2673 rect = rectWindow;
2674 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2675 hrgn = CreateRectRgnIndirect(&rect);
2676 if (!hrgn) {
2677 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2678 return;
2679 }
2680 rect = rectClient;
2681 hrgnClient = CreateRectRgnIndirect(&rect);
2682 if (!hrgn) {
2683 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2684 return;
2685 }
2686 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2687 DeleteObject(hrgnClient);
2688
2689 if(!EqualRect(oldClientRect, &rectClient)) {
2690 UnionRect(oldClientRect, oldClientRect, &rectClient);
2691 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2692 if (!hrgn) {
2693 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2694 return;
2695 }
2696 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2697 DeleteObject(hrgnClient);
2698 }
2699 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2700 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2701 DeleteObject(hrgn);
2702}
2703//******************************************************************************
2704//TODO: Check how this api really works in NT
2705//******************************************************************************
2706BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2707{
2708 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2709 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2710 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2711 windowpos.ptMinPosition = wndpl->ptMinPosition;
2712 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2713 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2714
2715 if(getStyle() & WS_MINIMIZE )
2716 {
2717 //TODO: Why can't this be (0,0)?
2718 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2719 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2720 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2721 }
2722 }
2723 else
2724 if(getStyle() & WS_MAXIMIZE )
2725 {
2726 //TODO: Why can't this be (0,0)?
2727 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2728 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2729 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2730 }
2731 else {
2732 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2733 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2734 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2735 SWP_NOZORDER | SWP_NOACTIVATE );
2736 }
2737 ShowWindow(wndpl->showCmd);
2738 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2739 {
2740 /* SDK: ...valid only the next time... */
2741 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2742 setFlags(getFlags() | WIN_RESTORE_MAX);
2743 }
2744 return TRUE;
2745}
2746//******************************************************************************
2747//******************************************************************************
2748BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2749{
2750 wndpl->length = sizeof(*wndpl);
2751 if(getStyle() & WS_MINIMIZE )
2752 wndpl->showCmd = SW_SHOWMINIMIZED;
2753 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2754
2755 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2756 if(getFlags() & WIN_RESTORE_MAX )
2757 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2758 else wndpl->flags = 0;
2759
2760 wndpl->ptMinPosition = windowpos.ptMinPosition;
2761 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2762 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2763 wndpl->rcNormalPosition = rectWindow;
2764
2765 return TRUE;
2766}
2767//******************************************************************************
2768//Also destroys all the child windows (destroy children first, parent last)
2769//******************************************************************************
2770BOOL Win32BaseWindow::DestroyWindow()
2771{
2772 HWND hwnd = getWindowHandle();
2773
2774 dprintf(("DestroyWindow %x", hwnd));
2775
2776 /* Call hooks */
2777 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2778 {
2779 return FALSE;
2780 }
2781
2782 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2783 {
2784 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2785 /* FIXME: clean up palette - see "Internals" p.352 */
2786 }
2787
2788 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2789 {
2790 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2791 {
2792 /* Notify the parent window only */
2793 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2794 if(!::IsWindow(hwnd) )
2795 {
2796 return TRUE;
2797 }
2798 }
2799//// else DebugInt3();
2800 }
2801 /* Hide the window */
2802 if(IsWindowVisible(getWindowHandle()))
2803 {
2804 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2805 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2806 if(!::IsWindow(hwnd))
2807 {
2808 return TRUE;
2809 }
2810 }
2811 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2812
2813 // check the handle for the last active popup window
2814 Win32BaseWindow* owner = getOwner();
2815 if (NULL != owner)
2816 {
2817 if (owner->getLastActive() == hwnd)
2818 owner->setLastActive( owner->getWindowHandle() );
2819 }
2820
2821 fDestroyWindowCalled = TRUE;
2822 return OSLibWinDestroyWindow(OS2HwndFrame);
2823}
2824//******************************************************************************
2825//******************************************************************************
2826Win32BaseWindow *Win32BaseWindow::getParent()
2827{
2828 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2829 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2830}
2831//******************************************************************************
2832//Note: does not set last error if no parent (verified in NT4, SP6)
2833//******************************************************************************
2834HWND Win32BaseWindow::GetParent()
2835{
2836 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2837
2838 if(getStyle() & WS_CHILD) {
2839 if(wndparent) {
2840 return wndparent->getWindowHandle();
2841 }
2842 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2843 DebugInt3();
2844 return 0;
2845 }
2846 else
2847 if(getStyle() & WS_POPUP)
2848 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2849 else return 0;
2850}
2851//******************************************************************************
2852//******************************************************************************
2853HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2854{
2855 HWND oldhwnd;
2856 Win32BaseWindow *newparent;
2857 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2858 BOOL fShow = FALSE;
2859
2860 if(oldparent) {
2861 oldhwnd = oldparent->getWindowHandle();
2862 oldparent->removeChild(this);
2863 }
2864 else oldhwnd = 0;
2865
2866 /* Windows hides the window first, then shows it again
2867 * including the WM_SHOWWINDOW messages and all */
2868 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
2869 ShowWindow(SW_HIDE);
2870 fShow = TRUE;
2871 }
2872 if(oldparent) {
2873 //release parent here (increased refcount during creation)
2874 RELEASE_WNDOBJ(oldparent);
2875 }
2876 newparent = GetWindowFromHandle(hwndNewParent);
2877 if(newparent && !newparent->isDesktopWindow())
2878 {
2879 setParent(newparent);
2880 getParent()->addChild(this);
2881 fParentChange = TRUE;
2882
2883 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2884 if(!(getStyle() & WS_CHILD))
2885 {
2886 //TODO: Send WM_STYLECHANGED msg?
2887 setStyle(getStyle() | WS_CHILD);
2888 if(getWindowId())
2889 {
2890 DestroyMenu( (HMENU) getWindowId() );
2891 setWindowId(0);
2892 }
2893 }
2894 //SvL: Even though the win32 coordinates might not change, the PM
2895 // coordinates can. We must make sure the control stays at the
2896 // same position (y) relative to the (new) parent.
2897 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
2898 SWP_NOACTIVATE|SWP_NOSIZE);
2899 fParentChange = FALSE;
2900 }
2901 else {
2902 if(newparent) RELEASE_WNDOBJ(newparent);
2903
2904 setParent(windowDesktop);
2905 windowDesktop->addRef();
2906 windowDesktop->addChild(this);
2907 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2908
2909 //TODO: Send WM_STYLECHANGED msg?
2910 setStyle(getStyle() & ~WS_CHILD);
2911 setWindowId(0);
2912 }
2913 /* SetParent additionally needs to make hwndChild the topmost window
2914 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2915 WM_WINDOWPOSCHANGED notification messages.
2916 */
2917 if(state >= STATE_PRE_WMNCCREATE) {
2918 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2919 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2920
2921 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2922 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2923 }
2924 return oldhwnd;
2925}
2926//******************************************************************************
2927//******************************************************************************
2928BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2929{
2930 // PH: Optimizer won't unroll calls to getParent() even
2931 // in release build.
2932 Win32BaseWindow *_parent = getParent();
2933
2934 if(_parent)
2935 {
2936 if(_parent->getWindowHandle() == hwndParent)
2937 return TRUE;
2938
2939 return _parent->IsChild(hwndParent);
2940 }
2941 else
2942 return 0;
2943}
2944//******************************************************************************
2945//******************************************************************************
2946HWND Win32BaseWindow::GetTopWindow()
2947{
2948 HWND hwndTop;
2949 Win32BaseWindow *topwindow;
2950
2951 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2952 if(!isDesktopWindow())
2953 {
2954 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2955 //Note: GetTopWindow can't return a window that hasn't processed
2956 // WM_NCCREATE yet (verified in NT4, SP6)
2957 if(topwindow) {
2958 if(topwindow->state >= STATE_POST_WMNCCREATE) {
2959 hwndTop = topwindow->getWindowHandle();
2960 }
2961 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
2962 RELEASE_WNDOBJ(topwindow);
2963 return hwndTop;
2964 }
2965 if(topwindow) RELEASE_WNDOBJ(topwindow);
2966 return 0;
2967 }
2968 while(hwndTop) {
2969 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2970 //Note: GetTopWindow can't return a window that hasn't processed
2971 // WM_NCCREATE yet (verified in NT4, SP6)
2972 if(topwindow) {
2973 if(topwindow->state >= STATE_POST_WMNCCREATE) {
2974 hwndTop = topwindow->getWindowHandle();
2975 }
2976 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
2977 RELEASE_WNDOBJ(topwindow);
2978 return hwndTop;
2979 }
2980 if(topwindow) RELEASE_WNDOBJ(topwindow);
2981 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2982 }
2983
2984 return 0;
2985}
2986//******************************************************************************
2987// Get the top-level parent for a child window.
2988//******************************************************************************
2989HWND Win32BaseWindow::GetTopParent()
2990{
2991 Win32BaseWindow *window = this;
2992 HWND hwndTopParent = 0;
2993
2994 lock();
2995 while(window && (window->getStyle() & WS_CHILD))
2996 {
2997 window = window->getParent();
2998 }
2999 if(window) {
3000 hwndTopParent = window->getWindowHandle();
3001 }
3002 unlock();
3003 return hwndTopParent;
3004}
3005//******************************************************************************
3006//TODO: Should not enumerate children that are created during the enumeration!
3007//******************************************************************************
3008BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
3009{
3010 BOOL rc = TRUE;
3011 HWND hwnd;
3012 Win32BaseWindow *prevchild = 0, *child = 0;
3013
3014 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3015 lock();
3016 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3017 {
3018 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3019 hwnd = child->getWindowHandle();
3020 if(child->IsWindowDestroyed() || child->getOwner()) {
3021 continue; //shouldn't have an owner (Wine)
3022 }
3023 child->addRef();
3024 unlock();
3025 if(lpfn(hwnd, lParam) == FALSE)
3026 {
3027 child->release();
3028 return FALSE;
3029 }
3030 child->release();
3031 lock();
3032 //check if the window still exists
3033 if(!::IsWindow(hwnd))
3034 {
3035 child = prevchild;
3036 continue;
3037 }
3038 if(child->getFirstChild() != NULL)
3039 {
3040 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3041 child->addRef();
3042 unlock();
3043 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3044 {
3045 child->release();
3046 return FALSE;
3047 }
3048 child->release();
3049 lock();
3050 }
3051 prevchild = child;
3052 }
3053 unlock();
3054 return rc;
3055}
3056//******************************************************************************
3057//Enumerate first-level children only and check thread id
3058//******************************************************************************
3059BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3060{
3061 Win32BaseWindow *child = 0;
3062 ULONG tid, pid;
3063 BOOL rc;
3064 HWND hwnd;
3065
3066 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
3067
3068 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3069 {
3070 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
3071
3072 if(dwThreadId == tid) {
3073 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
3074 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3075 break;
3076 }
3077 }
3078 }
3079 return TRUE;
3080}
3081//******************************************************************************
3082//Enumerate first-level children only
3083//******************************************************************************
3084BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3085{
3086 Win32BaseWindow *child = 0;
3087 BOOL rc;
3088 HWND hwnd;
3089
3090 dprintf(("EnumWindows %x %x", lpfn, lParam));
3091
3092 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3093 {
3094 hwnd = child->getWindowHandle();
3095
3096 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
3097 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3098 break;
3099 }
3100 }
3101 return TRUE;
3102}
3103//******************************************************************************
3104//******************************************************************************
3105HWND Win32BaseWindow::FindWindowById(int id)
3106{
3107 HWND hwnd;
3108
3109 lock();
3110 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3111 {
3112 if (child->getWindowId() == id)
3113 {
3114 hwnd = child->getWindowHandle();
3115 unlock();
3116 return hwnd;
3117 }
3118 }
3119 unlock();
3120 return 0;
3121}
3122//******************************************************************************
3123//TODO:
3124//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3125//the current process owns them.
3126//******************************************************************************
3127HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3128{
3129 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3130 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3131 Win32BaseWindow *firstchild = child;
3132
3133 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3134 if((hwndParent != 0 && !parent) ||
3135 (hwndChildAfter != 0 && !child) ||
3136 (hwndParent == 0 && hwndChildAfter != 0))
3137 {
3138 if(parent) RELEASE_WNDOBJ(parent);
3139 if(firstchild) RELEASE_WNDOBJ(firstchild);
3140 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3141 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3142 return 0;
3143 }
3144 SetLastError(0);
3145 if(hwndParent != 0)
3146 {//if the current process owns the window, just do a quick search
3147 lock(&critsect);
3148 child = (Win32BaseWindow *)parent->getFirstChild();
3149 if(hwndChildAfter != 0)
3150 {
3151 while(child)
3152 {
3153 if(child->getWindowHandle() == hwndChildAfter)
3154 {
3155 child = (Win32BaseWindow *)child->getNextChild();
3156 break;
3157 }
3158 child = (Win32BaseWindow *)child->getNextChild();
3159 }
3160 }
3161 while(child)
3162 {
3163 //According to Wine, the class doesn't need to be specified
3164 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3165 (!lpszWindow || child->hasWindowName(lpszWindow)))
3166 {
3167 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3168 HWND hwndChild = child->getWindowHandle();
3169 unlock(&critsect);
3170 if(parent) RELEASE_WNDOBJ(parent);
3171 if(firstchild) RELEASE_WNDOBJ(firstchild);
3172 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3173 return hwndChild;
3174 }
3175 child = (Win32BaseWindow *)child->getNextChild();
3176 }
3177 unlock(&critsect);
3178 if(parent) RELEASE_WNDOBJ(parent);
3179 if(firstchild) RELEASE_WNDOBJ(firstchild);
3180 }
3181 else {
3182 Win32BaseWindow *wnd;
3183 HWND henum, hwnd;
3184
3185 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3186 hwnd = OSLibWinGetNextWindow(henum);
3187
3188 while(hwnd)
3189 {
3190 wnd = GetWindowFromOS2FrameHandle(hwnd);
3191 if(wnd == NULL) {
3192 hwnd = OSLibWinQueryClientWindow(hwnd);
3193 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3194 }
3195
3196 if(wnd) {
3197 //According to Wine, the class doesn't need to be specified
3198 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3199 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3200 {
3201 OSLibWinEndEnumWindows(henum);
3202 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3203 HWND hwndret = wnd->getWindowHandle();
3204 RELEASE_WNDOBJ(wnd);
3205 return hwndret;
3206 }
3207 RELEASE_WNDOBJ(wnd);
3208 }
3209 hwnd = OSLibWinGetNextWindow(henum);
3210 }
3211 OSLibWinEndEnumWindows(henum);
3212 if(parent) RELEASE_WNDOBJ(parent);
3213 if(firstchild) RELEASE_WNDOBJ(firstchild);
3214 }
3215 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3216 return 0;
3217}
3218//******************************************************************************
3219//******************************************************************************
3220HWND Win32BaseWindow::GetWindow(UINT uCmd)
3221{
3222 HWND hwndRelated = 0;
3223 Win32BaseWindow *window;
3224
3225 switch(uCmd)
3226 {
3227 case GW_HWNDFIRST:
3228 window = (Win32BaseWindow *)getParent();
3229 if(window)
3230 {
3231 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3232 window = GetWindowFromOS2FrameHandle(hwndRelated);
3233 if(window) {
3234 hwndRelated = window->getWindowHandle();
3235 RELEASE_WNDOBJ(window);
3236 }
3237 else hwndRelated = 0;
3238 }
3239 else {
3240 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3241 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3242 }
3243 break;
3244
3245 case GW_HWNDLAST:
3246 window = (Win32BaseWindow *)getParent();
3247 if(window) {
3248 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3249 dprintf(("os2 handle %x", hwndRelated));
3250 window = GetWindowFromOS2FrameHandle(hwndRelated);
3251 if(window) {
3252 hwndRelated = window->getWindowHandle();
3253 RELEASE_WNDOBJ(window);
3254 }
3255 else hwndRelated = 0;
3256 }
3257 else {
3258 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3259 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3260 }
3261 break;
3262
3263 case GW_HWNDNEXT:
3264 if(getParent()) {
3265 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3266 window = GetWindowFromOS2FrameHandle(hwndRelated);
3267 if(window) {
3268 hwndRelated = window->getWindowHandle();
3269 RELEASE_WNDOBJ(window);
3270 }
3271 else hwndRelated = 0;
3272 }
3273 else {
3274 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3275 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3276 }
3277 break;
3278
3279 case GW_HWNDPREV:
3280 if(getParent()) {
3281 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3282 window = GetWindowFromOS2FrameHandle(hwndRelated);
3283 if(window) {
3284 hwndRelated = window->getWindowHandle();
3285 RELEASE_WNDOBJ(window);
3286 }
3287 else hwndRelated = 0;
3288 }
3289 else {
3290 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3291 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3292 }
3293 break;
3294
3295 case GW_OWNER:
3296 {
3297 Win32BaseWindow *owner = getOwner();
3298 if(owner) {
3299 hwndRelated = owner->getWindowHandle();
3300 }
3301 break;
3302 }
3303
3304 case GW_CHILD:
3305 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3306 window = GetWindowFromOS2FrameHandle(hwndRelated);
3307
3308 //Before a window has processed WM_NCCREATE:
3309 //- GetWindow(parent, GW_CHILD) can't return that window handle
3310 //(verified in NT4, SP6)
3311 if(window) {
3312 if(window->state >= STATE_POST_WMNCCREATE) {
3313 hwndRelated = window->getWindowHandle();
3314 RELEASE_WNDOBJ(window);
3315 }
3316 else {
3317 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3318 RELEASE_WNDOBJ(window);
3319 }
3320 }
3321 else hwndRelated = 0;
3322
3323 break;
3324
3325 //for internal use only
3326 case GW_HWNDNEXTCHILD:
3327 lock();
3328 window = (Win32BaseWindow *)getNextChild();
3329 if(window) {
3330 hwndRelated = window->getWindowHandle();
3331 }
3332 else hwndRelated = 0;
3333 unlock();
3334 break;
3335
3336 case GW_HWNDPREVCHILD:
3337 DebugInt3();
3338 break;
3339
3340 case GW_HWNDFIRSTCHILD:
3341 lock();
3342 window = (Win32BaseWindow *)getFirstChild();
3343 if(window) {
3344 hwndRelated = window->getWindowHandle();
3345 }
3346 else hwndRelated = 0;
3347 unlock();
3348 break;
3349
3350 case GW_HWNDLASTCHILD:
3351 lock();
3352 window = (Win32BaseWindow *)getFirstChild();
3353 if(window) {
3354 while (window->getNextChild())
3355 {
3356 window = (Win32BaseWindow *)window->getNextChild();
3357 }
3358 hwndRelated = window->getWindowHandle();
3359 }
3360 else hwndRelated = 0;
3361 unlock();
3362 break;
3363 }
3364end:
3365 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3366 return hwndRelated;
3367}
3368//******************************************************************************
3369//******************************************************************************
3370HWND Win32BaseWindow::SetActiveWindow()
3371{
3372 HWND hwndActive;
3373
3374 dprintf(("SetActiveWindow %x", getWindowHandle()));
3375 if(getStyle() & WS_CHILD) {
3376// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3377 dprintf(("WARNING: Window is a child or disabled"));
3378 return 0;
3379 }
3380
3381 if(GetActiveWindow() == getWindowHandle()) {
3382 dprintf(("Window already active"));
3383 return getWindowHandle();
3384 }
3385 if (HOOK_IsHooked( WH_CBT ))
3386 {
3387 CBTACTIVATESTRUCT cbta;
3388 LRESULT ret;
3389
3390 cbta.fMouse = FALSE;
3391 cbta.hWndActive = GetActiveWindow();
3392 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3393 if(ret)
3394 {
3395 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3396 return cbta.hWndActive;
3397 }
3398 }
3399 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3400
3401// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3402// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3403// }
3404 hwndActive = GetActiveWindow();
3405 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3406}
3407//******************************************************************************
3408//Used to change active status of an mdi window
3409//******************************************************************************
3410BOOL Win32BaseWindow::DeactivateChildWindow()
3411{
3412 /* child windows get a WM_CHILDACTIVATE message */
3413 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3414 {
3415 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3416 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3417 return TRUE;
3418 }
3419 DebugInt3(); //should not be called for non-child window
3420 return FALSE;
3421}
3422//******************************************************************************
3423//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3424//******************************************************************************
3425BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3426{
3427 BOOL rc;
3428
3429 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3430 //return true if previous state was disabled, else false (sdk docs)
3431 rc = (getStyle() & WS_DISABLED) != 0;
3432 if(rc && !fEnable) {
3433 SendMessageA(WM_CANCELMODE, 0, 0);
3434 }
3435 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3436 if(fEnable == FALSE) {
3437 //SvL: No need to clear focus as PM already does this
3438 if(getWindowHandle() == GetCapture()) {
3439 ReleaseCapture(); /* A disabled window can't capture the mouse */
3440 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3441 }
3442 }
3443 return rc;
3444}
3445//******************************************************************************
3446//******************************************************************************
3447BOOL Win32BaseWindow::CloseWindow()
3448{
3449 return OSLibWinMinimizeWindow(OS2Hwnd);
3450}
3451//******************************************************************************
3452//TODO: Not be 100% correct; should return active window of current thread
3453// or NULL when there is none -> WinQueryActiveWindow just returns
3454// the current active window
3455//******************************************************************************
3456HWND Win32BaseWindow::GetActiveWindow()
3457{
3458 HWND hwndActive;
3459
3460 hwndActive = OSLibWinQueryActiveWindow();
3461
3462 return OS2ToWin32Handle(hwndActive);
3463}
3464//******************************************************************************
3465//******************************************************************************
3466BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3467{
3468 INT len = GetWindowTextLength(fUnicode);
3469 BOOL res;
3470
3471 if (wndname == NULL)
3472 return (len == 0);
3473
3474 len++;
3475 if (fUnicode)
3476 {
3477 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3478
3479 GetWindowTextW(text,len);
3480 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3481 free(text);
3482 }
3483 else
3484 {
3485 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3486
3487 GetWindowTextA(text,len);
3488 res = (strcmp(text,wndname) == 0);
3489 free(text);
3490 }
3491
3492 return res;
3493}
3494//******************************************************************************
3495//******************************************************************************
3496CHAR *Win32BaseWindow::getWindowNamePtrA()
3497{
3498 INT len = GetWindowTextLength(FALSE);
3499 CHAR *text;
3500
3501 if (len == 0) return NULL;
3502 len++;
3503 text = (CHAR*)malloc(len*sizeof(CHAR));
3504 GetWindowTextA(text,len);
3505
3506 return text;
3507}
3508//******************************************************************************
3509//******************************************************************************
3510WCHAR *Win32BaseWindow::getWindowNamePtrW()
3511{
3512 INT len = GetWindowTextLength(TRUE);
3513 WCHAR *text;
3514
3515 if (len == 0) return NULL;
3516 len++;
3517 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3518 GetWindowTextW(text,len);
3519
3520 return text;
3521}
3522//******************************************************************************
3523//******************************************************************************
3524VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3525{
3526 if (namePtr) free(namePtr);
3527}
3528//******************************************************************************
3529//When using this API for a window that was created by a different process, NT
3530//does NOT send WM_GETTEXTLENGTH.
3531//******************************************************************************
3532int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3533{
3534 //if the destination window is created by this process, send message
3535 if(dwProcessId == currentProcessId) {
3536 if(fUnicode) {
3537 return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
3538 }
3539 else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3540 }
3541 //else get data directory from window structure
3542 //TODO: must lock window structure.... (TODO)
3543 if(fUnicode) {
3544 if(windowNameW) {
3545 return strlenW(windowNameW);
3546 }
3547 else return 0;
3548 }
3549 else {
3550 if(windowNameA) {
3551 return strlen(windowNameA);
3552 }
3553 else return 0;
3554 }
3555}
3556//******************************************************************************
3557//When using this API for a window that was created by a different process, NT
3558//does NOT send WM_GETTEXT.
3559//******************************************************************************
3560int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3561{
3562 //if the destination window is created by this process, send message
3563 if(dwProcessId == currentProcessId) {
3564 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3565 }
3566 //else get data directory from window structure
3567 if (!lpsz || !cch) return 0;
3568 if (!windowNameA) lpsz[0] = 0;
3569 else lstrcpynA(lpsz, windowNameA, cch);
3570 return min((windowNameA ? strlen(windowNameA) : 0), cch);
3571}
3572//******************************************************************************
3573//When using this API for a window that was created by a different process, NT
3574//does NOT send WM_GETTEXT.
3575//******************************************************************************
3576int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3577{
3578 //if the destination window is created by this process, send message
3579 if(dwProcessId == currentProcessId) {
3580 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3581 }
3582 //else get data directory from window structure
3583 if (!lpsz || !cch) return 0;
3584 if (!windowNameW) lpsz[0] = 0;
3585 else lstrcpynW(lpsz, windowNameW, cch);
3586 return min((windowNameW ? strlenW(windowNameW) : 0), cch);
3587}
3588//******************************************************************************
3589//TODO: How does this work when the target window belongs to a different process???
3590//******************************************************************************
3591BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3592{
3593 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3594}
3595//******************************************************************************
3596//******************************************************************************
3597BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3598{
3599 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3600}
3601//******************************************************************************
3602//******************************************************************************
3603LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
3604{
3605 LONG oldval;
3606
3607 switch(index) {
3608 case GWL_EXSTYLE:
3609 {
3610 STYLESTRUCT ss;
3611
3612 if(dwExStyle == value) {
3613 oldval = value;
3614 break;
3615 }
3616 ss.styleOld = dwExStyle;
3617 ss.styleNew = value;
3618 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3619 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3620 setExStyle(ss.styleNew);
3621 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3622 oldval = ss.styleOld;
3623 break;
3624 }
3625 case GWL_STYLE:
3626 {
3627 STYLESTRUCT ss;
3628
3629 //SvL: TODO: Can you change minimize or maximize status here too?
3630
3631 if(dwStyle == value) {
3632 oldval = value;
3633 break;
3634 }
3635 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3636#ifdef DEBUG
3637// if((value & WS_CHILD) != (dwStyle & WS_CHILD)) {
3638// DebugInt3(); //is this allowed?
3639// }
3640#endif
3641 value &= ~(WS_CHILD);
3642 ss.styleOld = getStyle();
3643 ss.styleNew = value | (ss.styleOld & WS_CHILD);
3644 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3645 setStyle(ss.styleNew);
3646 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3647 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
3648
3649 //TODO: Might not be correct to use ShowWindow here
3650 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3651 if(ss.styleNew & WS_VISIBLE)
3652 ShowWindow(SW_SHOWNOACTIVATE);
3653 else ShowWindow(SW_HIDE);
3654 }
3655#ifdef DEBUG
3656 PrintWindowStyle(ss.styleNew, 0);
3657#endif
3658 oldval = ss.styleOld;
3659 break;
3660 }
3661 case GWL_WNDPROC:
3662 {
3663 //Note: Type of SetWindowLong determines new window proc type
3664 // UNLESS the new window proc has already been registered
3665 // (use the old type in that case)
3666 // (VERIFIED in NT 4, SP6)
3667 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3668 if(type == WIN_PROC_INVALID) {
3669 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3670 }
3671 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3672 dprintf(("SetWindowLong GWL_WNDPROC %x old %x new wndproc %x", getWindowHandle(), oldval, value));
3673 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3674 break;
3675 }
3676 case GWL_HINSTANCE:
3677 oldval = hInstance;
3678 hInstance = value;
3679 break;
3680
3681 case GWL_HWNDPARENT:
3682 oldval = SetParent((HWND)value);
3683 break;
3684
3685 case GWL_ID:
3686 oldval = getWindowId();
3687 setWindowId(value);
3688 break;
3689
3690 case GWL_USERDATA:
3691 oldval = userData;
3692 userData = value;
3693 break;
3694
3695 default:
3696 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3697 {
3698 oldval = *(ULONG *)(userWindowBytes + index);
3699 *(ULONG *)(userWindowBytes + index) = value;
3700 break;
3701 }
3702 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3703 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3704 return 0;
3705 }
3706 //Note: NT4, SP6 does not set the last error to 0
3707 SetLastError(ERROR_SUCCESS);
3708 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3709 return oldval;
3710}
3711//******************************************************************************
3712//******************************************************************************
3713ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3714{
3715 ULONG value;
3716
3717 switch(index) {
3718 case GWL_EXSTYLE:
3719 value = dwExStyle;
3720 break;
3721 case GWL_STYLE:
3722 value = dwStyle;
3723 break;
3724 case GWL_WNDPROC:
3725 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3726 break;
3727 case GWL_HINSTANCE:
3728 value = hInstance;
3729 break;
3730 case GWL_HWNDPARENT:
3731 value = GetParent();
3732 break;
3733 case GWL_ID:
3734 value = getWindowId();
3735 break;
3736 case GWL_USERDATA:
3737 value = userData;
3738 break;
3739 default:
3740 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3741 {
3742 value = *(ULONG *)(userWindowBytes + index);
3743 break;
3744 }
3745 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3746 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3747 return 0;
3748 }
3749 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3750 //Note: NT4, SP6 does not set the last error to 0
3751 SetLastError(ERROR_SUCCESS);
3752 return value;
3753}
3754//******************************************************************************
3755//******************************************************************************
3756WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3757{
3758 WORD oldval;
3759
3760 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3761 {
3762 oldval = *(WORD *)(userWindowBytes + index);
3763 *(WORD *)(userWindowBytes + index) = value;
3764 //Note: NT4, SP6 does not set the last error to 0
3765 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3766 SetLastError(ERROR_SUCCESS);
3767 return oldval;
3768 }
3769 switch(index)
3770 {
3771 case GWW_HINSTANCE:
3772 oldval = hInstance;
3773 hInstance = value;
3774 break;
3775
3776 case GWW_HWNDPARENT:
3777 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3778 break;
3779
3780 case GWW_ID:
3781 oldval = getWindowId();
3782 setWindowId(value);
3783 break;
3784
3785 default:
3786 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3787 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3788 return 0;
3789 }
3790 //Note: NT4, SP6 does not set the last error to 0
3791 SetLastError(ERROR_SUCCESS);
3792 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3793 return oldval;
3794}
3795//******************************************************************************
3796//******************************************************************************
3797WORD Win32BaseWindow::GetWindowWord(int index)
3798{
3799 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3800 {
3801 //Note: NT4, SP6 does not set the last error to 0
3802 SetLastError(ERROR_SUCCESS);
3803 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3804 return *(WORD *)(userWindowBytes + index);
3805 }
3806 switch(index)
3807 {
3808 case GWW_ID:
3809 if(HIWORD(getWindowId()))
3810 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3811 return (WORD)getWindowId();
3812
3813 case GWW_HWNDPARENT:
3814 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3815 return (WORD) GetParent();
3816
3817 case GWW_HINSTANCE:
3818 if (HIWORD(hInstance))
3819 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3820 return (WORD)hInstance;
3821 }
3822
3823 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3824 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3825 return 0;
3826}
3827//******************************************************************************
3828//******************************************************************************
3829void Win32BaseWindow::setWindowId(DWORD id)
3830{
3831 dwIDMenu = id;
3832}
3833//******************************************************************************
3834//Locates window in linked list and increases reference count (if found)
3835//Window object must be unreferenced after usage
3836//******************************************************************************
3837Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3838{
3839 Win32BaseWindow *window;
3840
3841////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
3842//// while browsing
3843//// Not thread safe now!
3844//// lock(&critsect);
3845 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3846 if(window) {
3847//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
3848 window->addRef();
3849 }
3850//// unlock(&critsect);
3851 return window;
3852 }
3853//// unlock(&critsect);
3854// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3855 return NULL;
3856}
3857//******************************************************************************
3858//Locates window in linked list and increases reference count (if found)
3859//Window object must be unreferenced after usage
3860//******************************************************************************
3861Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
3862{
3863 DWORD magic;
3864 HWND hwnd;
3865
3866 if(hwndOS2 == OSLIB_HWND_DESKTOP)
3867 {
3868 windowDesktop->addRef();
3869 return windowDesktop;
3870 }
3871
3872 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
3873 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
3874
3875 if(hwnd && CheckMagicDword(magic)) {
3876 return GetWindowFromHandle(hwnd);
3877 }
3878// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
3879 return 0;
3880}
3881//******************************************************************************
3882//Locates window in linked list and increases reference count (if found)
3883//Window object must be unreferenced after usage
3884//******************************************************************************
3885Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3886{
3887 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3888}
3889//******************************************************************************
3890//******************************************************************************
3891HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3892{
3893 HWND hwndOS2;
3894
3895 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3896
3897 if(window) {
3898 hwndOS2 = window->getOS2WindowHandle();
3899 RELEASE_WNDOBJ(window);
3900 return hwndOS2;
3901 }
3902// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3903 return hwnd;
3904}
3905//******************************************************************************
3906//******************************************************************************
3907HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
3908{
3909 HWND hwndOS2;
3910
3911 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3912
3913 if(window) {
3914 hwndOS2 = window->getOS2FrameWindowHandle();
3915 RELEASE_WNDOBJ(window);
3916 return hwndOS2;
3917 }
3918// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3919 return hwnd;
3920}
3921//******************************************************************************
3922//******************************************************************************
3923HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3924{
3925 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3926 HWND hwndWin32;
3927
3928 if(window) {
3929 hwndWin32 = window->getWindowHandle();
3930 RELEASE_WNDOBJ(window);
3931 return hwndWin32;
3932 }
3933 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
3934 if(window) {
3935 hwndWin32 = window->getWindowHandle();
3936 RELEASE_WNDOBJ(window);
3937 return hwndWin32;
3938 }
3939
3940// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3941 return 0;
3942// else return hwnd; //OS/2 window handle
3943}
3944#ifdef DEBUG
3945LONG Win32BaseWindow::addRef()
3946{
3947 dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
3948 return GenericObject::addRef();
3949}
3950//******************************************************************************
3951//******************************************************************************
3952LONG Win32BaseWindow::release(char *function, int line)
3953{
3954 dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
3955 return GenericObject::release();
3956}
3957#endif
3958//******************************************************************************
3959//******************************************************************************
3960GenericObject *Win32BaseWindow::windows = NULL;
3961CRITICAL_SECTION Win32BaseWindow::critsect = {0};
3962
3963//******************************************************************************
3964//******************************************************************************
3965#ifdef DEBUG
3966void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3967{
3968 char style[256] = "";
3969 char exstyle[256] = "";
3970
3971 /* Window styles */
3972 if(dwStyle & WS_CHILD)
3973 strcat(style, "WS_CHILD ");
3974 if(dwStyle & WS_POPUP)
3975 strcat(style, "WS_POPUP ");
3976 if(dwStyle & WS_VISIBLE)
3977 strcat(style, "WS_VISIBLE ");
3978 if(dwStyle & WS_DISABLED)
3979 strcat(style, "WS_DISABLED ");
3980 if(dwStyle & WS_CLIPSIBLINGS)
3981 strcat(style, "WS_CLIPSIBLINGS ");
3982 if(dwStyle & WS_CLIPCHILDREN)
3983 strcat(style, "WS_CLIPCHILDREN ");
3984 if(dwStyle & WS_MAXIMIZE)
3985 strcat(style, "WS_MAXIMIZE ");
3986 if(dwStyle & WS_MINIMIZE)
3987 strcat(style, "WS_MINIMIZE ");
3988 if(dwStyle & WS_GROUP)
3989 strcat(style, "WS_GROUP ");
3990 if(dwStyle & WS_TABSTOP)
3991 strcat(style, "WS_TABSTOP ");
3992
3993 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3994 strcat(style, "WS_CAPTION ");
3995 if(dwStyle & WS_DLGFRAME)
3996 strcat(style, "WS_DLGFRAME ");
3997 if(dwStyle & WS_BORDER)
3998 strcat(style, "WS_BORDER ");
3999
4000 if(dwStyle & WS_VSCROLL)
4001 strcat(style, "WS_VSCROLL ");
4002 if(dwStyle & WS_HSCROLL)
4003 strcat(style, "WS_HSCROLL ");
4004 if(dwStyle & WS_SYSMENU)
4005 strcat(style, "WS_SYSMENU ");
4006 if(dwStyle & WS_THICKFRAME)
4007 strcat(style, "WS_THICKFRAME ");
4008 if(dwStyle & WS_MINIMIZEBOX)
4009 strcat(style, "WS_MINIMIZEBOX ");
4010 if(dwStyle & WS_MAXIMIZEBOX)
4011 strcat(style, "WS_MAXIMIZEBOX ");
4012
4013 if(dwExStyle & WS_EX_DLGMODALFRAME)
4014 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4015 if(dwExStyle & WS_EX_ACCEPTFILES)
4016 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4017 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4018 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4019 if(dwExStyle & WS_EX_TOPMOST)
4020 strcat(exstyle, "WS_EX_TOPMOST ");
4021 if(dwExStyle & WS_EX_TRANSPARENT)
4022 strcat(exstyle, "WS_EX_TRANSPARENT ");
4023
4024 if(dwExStyle & WS_EX_MDICHILD)
4025 strcat(exstyle, "WS_EX_MDICHILD ");
4026 if(dwExStyle & WS_EX_TOOLWINDOW)
4027 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4028 if(dwExStyle & WS_EX_WINDOWEDGE)
4029 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4030 if(dwExStyle & WS_EX_CLIENTEDGE)
4031 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4032 if(dwExStyle & WS_EX_CONTEXTHELP)
4033 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4034 if(dwExStyle & WS_EX_RIGHT)
4035 strcat(exstyle, "WS_EX_RIGHT ");
4036 if(dwExStyle & WS_EX_LEFT)
4037 strcat(exstyle, "WS_EX_LEFT ");
4038 if(dwExStyle & WS_EX_RTLREADING)
4039 strcat(exstyle, "WS_EX_RTLREADING ");
4040 if(dwExStyle & WS_EX_LTRREADING)
4041 strcat(exstyle, "WS_EX_LTRREADING ");
4042 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4043 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4044 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4045 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4046 if(dwExStyle & WS_EX_CONTROLPARENT)
4047 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4048 if(dwExStyle & WS_EX_STATICEDGE)
4049 strcat(exstyle, "WS_EX_STATICEDGE ");
4050 if(dwExStyle & WS_EX_APPWINDOW)
4051 strcat(exstyle, "WS_EX_APPWINDOW ");
4052
4053 dprintf(("Window style: %x %s", dwStyle, style));
4054 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4055}
4056#endif
4057//******************************************************************************
4058//******************************************************************************
Note: See TracBrowser for help on using the repository browser.