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

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

WM_ACTIVATEAPP fix

File size: 139.2 KB
Line 
1/* $Id: win32wbase.cpp,v 1.296 2001-10-25 10:40: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 return SendInternalMessageA(WM_ACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
1004}
1005//******************************************************************************
1006//******************************************************************************
1007ULONG Win32BaseWindow::MsgChildActivate(BOOL fActivate)
1008{
1009 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
1010 if(fDestroyWindowCalled) {
1011 return 0;
1012 }
1013
1014 //According to SDK docs, if app returns FALSE & window is being deactivated,
1015 //default processing is cancelled
1016 //TODO: According to Wine we should proceed anyway if window is sysmodal
1017 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
1018 {
1019 dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
1020 return 0;
1021 }
1022 /* child windows get a WM_CHILDACTIVATE message */
1023 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1024 {
1025 if(fActivate) {//WM_CHILDACTIVE is for activation only
1026 SendInternalMessageA(WM_CHILDACTIVATE, 0, 0L);
1027 }
1028 return 0;
1029 }
1030 DebugInt3();
1031 return 0;
1032}
1033//******************************************************************************
1034//******************************************************************************
1035ULONG Win32BaseWindow::DispatchMsgA(MSG *msg)
1036{
1037 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1038}
1039//******************************************************************************
1040//******************************************************************************
1041ULONG Win32BaseWindow::DispatchMsgW(MSG *msg)
1042{
1043 return SendInternalMessageW(msg->message, msg->wParam, msg->lParam);
1044}
1045//******************************************************************************
1046//******************************************************************************
1047ULONG Win32BaseWindow::MsgSetFocus(HWND hwnd)
1048{
1049 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
1050 if(fDestroyWindowCalled) {
1051 return 0;
1052 }
1053
1054 return SendInternalMessageA(WM_SETFOCUS, hwnd, 0);
1055}
1056//******************************************************************************
1057//******************************************************************************
1058ULONG Win32BaseWindow::MsgKillFocus(HWND hwnd)
1059{
1060 //SvL: Don't send WM_(NC)ACTIVATE messages when the window is being destroyed
1061 if(fDestroyWindowCalled) {
1062 return 0;
1063 }
1064 return SendInternalMessageA(WM_KILLFOCUS, hwnd, 0);
1065}
1066//******************************************************************************
1067//******************************************************************************
1068ULONG Win32BaseWindow::MsgButton(MSG *msg)
1069{
1070 BOOL fClick = FALSE;
1071
1072 dprintf(("MsgButton %d at (%d,%d)", msg->message, msg->pt.x, msg->pt.y));
1073 switch(msg->message) {
1074 case WM_LBUTTONDBLCLK:
1075 case WM_RBUTTONDBLCLK:
1076 case WM_MBUTTONDBLCLK:
1077 if (!(windowClass && windowClass->getClassLongA(GCL_STYLE) & CS_DBLCLKS))
1078 {
1079 msg->message = msg->message - (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); //dblclick -> down
1080 return MsgButton(msg);
1081 }
1082 break;
1083 case WM_NCLBUTTONDBLCLK:
1084 case WM_NCRBUTTONDBLCLK:
1085 case WM_NCMBUTTONDBLCLK:
1086 //Docs say CS_DBLCLKS style doesn't matter for non-client double clicks
1087 fClick = TRUE;
1088 break;
1089
1090 case WM_LBUTTONDOWN:
1091 case WM_RBUTTONDOWN:
1092 case WM_MBUTTONDOWN:
1093 case WM_NCLBUTTONDOWN:
1094 case WM_NCRBUTTONDOWN:
1095 case WM_NCMBUTTONDOWN:
1096 fClick = TRUE;
1097 break;
1098 }
1099
1100 if(fClick)
1101 {
1102 HWND hwndTop;
1103
1104 /* Activate the window if needed */
1105 hwndTop = GetTopParent();
1106
1107 HWND hwndActive = GetActiveWindow();
1108 if (hwndTop && (getWindowHandle() != hwndActive))
1109 {
1110 LONG ret = SendInternalMessageA(WM_MOUSEACTIVATE, hwndTop,
1111 MAKELONG( lastHitTestVal, msg->message) );
1112
1113 dprintf2(("WM_MOUSEACTIVATE returned %d", ret));
1114#if 0
1115 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
1116 eatMsg = TRUE;
1117#endif
1118 //SvL: 0 is not documented, but experiments in NT4 show that
1119 // the window will get activated when it returns this.
1120 // (FreeCell is an example)
1121 if(((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT) || (ret == 0))
1122 && (hwndTop != GetForegroundWindow()) )
1123 {
1124 Win32BaseWindow *win32top = Win32BaseWindow::GetWindowFromHandle(hwndTop);
1125
1126 //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
1127 if (win32top) {
1128 OSLibWinSetFocus(win32top->getOS2FrameWindowHandle());
1129 RELEASE_WNDOBJ(win32top);
1130 }
1131 }
1132 }
1133 }
1134
1135 SendInternalMessageA(WM_SETCURSOR, getWindowHandle(), MAKELONG(lastHitTestVal, msg->message));
1136
1137 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1138}
1139//******************************************************************************
1140//******************************************************************************
1141ULONG Win32BaseWindow::MsgPaint(ULONG tmp, ULONG select)
1142{
1143 if (select && IsWindowIconic())
1144 return SendInternalMessageA(WM_PAINTICON, 1, 0);
1145 else
1146 return SendInternalMessageA(WM_PAINT, 0, 0);
1147}
1148//******************************************************************************
1149//TODO: Is the clipper region of the window DC equal to the invalidated rectangle?
1150// (or are we simply erasing too much here)
1151//******************************************************************************
1152ULONG Win32BaseWindow::MsgEraseBackGround(HDC hdc)
1153{
1154 ULONG rc;
1155 HDC hdcErase = hdc;
1156
1157 if (hdcErase == 0)
1158 hdcErase = GetDC(getWindowHandle());
1159
1160 if(IsWindowIconic())
1161 rc = SendInternalMessageA(WM_ICONERASEBKGND, hdcErase, 0);
1162 else
1163 rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
1164 if (hdc == 0)
1165 ReleaseDC(getWindowHandle(), hdcErase);
1166 return (rc);
1167}
1168//******************************************************************************
1169//******************************************************************************
1170ULONG Win32BaseWindow::MsgMouseMove(MSG *msg)
1171{
1172 //TODO: hiword should be 0 if window enters menu mode (SDK docs)
1173 SendInternalMessageA(WM_SETCURSOR, Win32Hwnd, MAKELONG(lastHitTestVal, msg->message));
1174
1175 //translated message == WM_(NC)MOUSEMOVE
1176 return SendInternalMessageA(msg->message, msg->wParam, msg->lParam);
1177}
1178//******************************************************************************
1179//******************************************************************************
1180ULONG Win32BaseWindow::MsgChar(MSG *msg)
1181{
1182 return DispatchMsgA(msg);
1183}
1184//******************************************************************************
1185//TODO: Should use update region, not rectangle
1186//******************************************************************************
1187ULONG Win32BaseWindow::MsgNCPaint(PRECT pUpdateRect)
1188{
1189 HRGN hrgn;
1190 ULONG rc;
1191 RECT client = rectClient;
1192
1193 if ((pUpdateRect->left >= client.left) && (pUpdateRect->left < client.right) &&
1194 (pUpdateRect->right >= client.left) && (pUpdateRect->right < client.right) &&
1195 (pUpdateRect->top >= client.top) && (pUpdateRect->top < client.bottom) &&
1196 (pUpdateRect->bottom >= client.top) && (pUpdateRect->bottom < client.bottom))
1197 {
1198 return 0;
1199 }
1200
1201 dprintf(("MsgNCPaint (%d,%d)(%d,%d)", pUpdateRect->left, pUpdateRect->top, pUpdateRect->right, pUpdateRect->bottom));
1202 hrgn = CreateRectRgnIndirect(pUpdateRect);
1203
1204 rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
1205
1206 DeleteObject(hrgn);
1207
1208 return rc;
1209}
1210//******************************************************************************
1211//Called when either the frame's size or position has changed (lpWndPos != NULL)
1212//or when the frame layout has changed (i.e. scrollbars added/removed) (lpWndPos == NULL)
1213//******************************************************************************
1214ULONG Win32BaseWindow::MsgFormatFrame(WINDOWPOS *lpWndPos)
1215{
1216 RECT oldWindowRect = rectWindow, client = rectClient, newWindowRect;
1217 RECT newClientRect;
1218 WINDOWPOS wndPos;
1219 ULONG rc;
1220
1221 if(lpWndPos)
1222 {
1223 //set new window rectangle
1224 setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
1225 lpWndPos->y+lpWndPos->cy);
1226 newWindowRect = rectWindow;
1227 }
1228 else {
1229 wndPos.hwnd = getWindowHandle();
1230 wndPos.hwndInsertAfter = 0;
1231 newWindowRect= rectWindow;
1232 wndPos.x = newWindowRect.left;
1233 wndPos.y = newWindowRect.top;
1234 wndPos.cx = newWindowRect.right - newWindowRect.left;
1235 wndPos.cy = newWindowRect.bottom - newWindowRect.top;
1236 wndPos.flags = SWP_FRAMECHANGED;
1237 lpWndPos = &wndPos;
1238 }
1239
1240 newClientRect = rectClient;
1241 rc = SendNCCalcSize(TRUE, &newWindowRect, &oldWindowRect, &client, lpWndPos, &newClientRect);
1242 rectClient = newClientRect; //must update rectClient here
1243
1244 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));
1245 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));
1246
1247 if(!CanReceiveSizeMsgs() || !EqualRect(&client, &rectClient)) {
1248 OSLibWinSetClientPos(getOS2WindowHandle(), rectClient.left, rectClient.top, getClientWidth(), getClientHeight(), getWindowHeight());
1249 }
1250
1251#if 1
1252//this doesn't always work
1253// if(CanReceiveSizeMsgs() && (client.left != rectClient.left || client.top != rectClient.top))
1254 if(CanReceiveSizeMsgs() && ((oldWindowRect.right - oldWindowRect.left < rectClient.left
1255 || oldWindowRect.bottom - oldWindowRect.top < rectClient.top) ||
1256 (EqualRect(&oldWindowRect, &rectWindow) && (client.left != rectClient.left || client.top != rectClient.top))))
1257 {
1258 Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild();
1259
1260 //client rectangle has moved -> inform children
1261 dprintf(("MsgFormatFrame -> client rectangle has changed, move children"));
1262 while(child) {
1263 ::SetWindowPos(child->getWindowHandle(),
1264 HWND_TOP, child->getWindowRect()->left,
1265 child->getWindowRect()->top, 0, 0,
1266 SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
1267 child = (Win32BaseWindow *)child->getNextChild();
1268 }
1269 }
1270#endif
1271 if(fOS2Look && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1272 {
1273 RECT rect = {0};
1274 int height = getWindowHeight();
1275 RECTLOS2 rectOS2;
1276
1277 AdjustRectOuter(&rect, FALSE);
1278
1279 rect.left = -rect.left;
1280 rect.top = rect.bottom - rect.top;
1281 rect.right = rectWindow.right - rectWindow.left - rect.right;
1282
1283 rectOS2.xLeft = rect.left;
1284 rectOS2.xRight = rect.right;
1285 rectOS2.yBottom = height - rect.top;
1286 rectOS2.yTop = height - rect.bottom;
1287 OSLibWinPositionFrameControls(getOS2FrameWindowHandle(), &rectOS2, dwStyle, dwExStyle, IconForWindow(ICON_SMALL));
1288 }
1289 return rc;
1290}
1291//******************************************************************************
1292//******************************************************************************
1293ULONG Win32BaseWindow::MsgSetText(LPSTR lpsz, LONG cch)
1294{
1295 return SendInternalMessageA(WM_SETTEXT, 0, (LPARAM)lpsz);
1296}
1297//******************************************************************************
1298//******************************************************************************
1299ULONG Win32BaseWindow::MsgGetTextLength()
1300{
1301 return SendInternalMessageA(WM_GETTEXTLENGTH, 0, 0);
1302}
1303//******************************************************************************
1304//******************************************************************************
1305void Win32BaseWindow::MsgGetText(char *wndtext, ULONG textlength)
1306{
1307 SendInternalMessageA(WM_GETTEXT, textlength, (LPARAM)wndtext);
1308}
1309//******************************************************************************
1310//******************************************************************************
1311BOOL Win32BaseWindow::isMDIClient()
1312{
1313 return FALSE;
1314}
1315//******************************************************************************
1316//******************************************************************************
1317BOOL Win32BaseWindow::isMDIChild()
1318{
1319 return FALSE;
1320}
1321//******************************************************************************
1322//TODO: Not complete
1323//******************************************************************************
1324BOOL Win32BaseWindow::isFrameWindow()
1325{
1326 if(getParent() == NULL)
1327 return TRUE;
1328
1329 return FALSE;
1330}
1331//******************************************************************************
1332//******************************************************************************
1333BOOL Win32BaseWindow::isDesktopWindow()
1334{
1335 return FALSE;
1336}
1337//******************************************************************************
1338//******************************************************************************
1339BOOL Win32BaseWindow::IsWindowIconic()
1340{
1341 return ((getStyle() & WS_MINIMIZE) && windowClass->getIcon());
1342}
1343//******************************************************************************
1344//******************************************************************************
1345SCROLLBAR_INFO *Win32BaseWindow::getScrollInfo(int nBar)
1346{
1347 switch(nBar)
1348 {
1349 case SB_HORZ:
1350 if (!horzScrollInfo)
1351 {
1352 horzScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1353 if (!horzScrollInfo) break;
1354 horzScrollInfo->MinVal = horzScrollInfo->CurVal = horzScrollInfo->Page = 0;
1355 horzScrollInfo->MaxVal = 100;
1356 horzScrollInfo->flags = ESB_ENABLE_BOTH;
1357 }
1358 return horzScrollInfo;
1359
1360 case SB_VERT:
1361 if (!vertScrollInfo)
1362 {
1363 vertScrollInfo = (SCROLLBAR_INFO*)malloc(sizeof(SCROLLBAR_INFO));
1364 if (!vertScrollInfo) break;
1365 vertScrollInfo->MinVal = vertScrollInfo->CurVal = vertScrollInfo->Page = 0;
1366 vertScrollInfo->MaxVal = 100;
1367 vertScrollInfo->flags = ESB_ENABLE_BOTH;
1368 }
1369 return vertScrollInfo;
1370 }
1371
1372 return NULL;
1373}
1374//******************************************************************************
1375//******************************************************************************
1376LRESULT Win32BaseWindow::DefWndControlColor(UINT ctlType, HDC hdc)
1377{
1378 //SvL: Set background color to default button color (not window (white))
1379 if(ctlType == CTLCOLOR_BTN)
1380 {
1381 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1382 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1383 return GetSysColorBrush(COLOR_BTNFACE);
1384 }
1385 //SvL: Set background color to default dialog color if window is dialog
1386 if((ctlType == CTLCOLOR_DLG || ctlType == CTLCOLOR_STATIC) && IsDialog()) {
1387 SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
1388 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
1389 return GetSysColorBrush(COLOR_BTNFACE);
1390 }
1391 if( ctlType == CTLCOLOR_SCROLLBAR)
1392 {
1393 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1394 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1395 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1396 SetBkColor( hdc, bk);
1397
1398 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1399 * we better use 0x55aa bitmap brush to make scrollbar's background
1400 * look different from the window background.
1401 */
1402 if (bk == GetSysColor(COLOR_WINDOW)) {
1403 return GetPattern55AABrush();
1404 }
1405
1406 UnrealizeObject( hb );
1407 return (LRESULT)hb;
1408 }
1409
1410 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1411
1412 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1413 {
1414 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1415 }
1416 else
1417 {
1418 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1419 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1420 }
1421 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1422}
1423//******************************************************************************
1424//******************************************************************************
1425LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1426{
1427 /*
1428 * Visibility flag.
1429 */
1430 if ( (uFlags & PRF_CHECKVISIBLE) &&
1431 !IsWindowVisible(getWindowHandle()) )
1432 return 0;
1433
1434 /*
1435 * Unimplemented flags.
1436 */
1437 if ( (uFlags & PRF_CHILDREN) ||
1438 (uFlags & PRF_OWNED) ||
1439 (uFlags & PRF_NONCLIENT) )
1440 {
1441 dprintf(("WM_PRINT message with unsupported flags\n"));
1442 }
1443
1444 /*
1445 * Background
1446 */
1447 if ( uFlags & PRF_ERASEBKGND)
1448 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1449
1450 /*
1451 * Client area
1452 */
1453 if ( uFlags & PRF_CLIENT)
1454 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1455
1456
1457 return 0;
1458}
1459//******************************************************************************
1460//******************************************************************************
1461LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1462{
1463 switch(Msg)
1464 {
1465 case WM_CLOSE:
1466 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1467 DestroyWindow();
1468 return 0;
1469
1470 case WM_GETTEXTLENGTH:
1471 if(windowNameA) {
1472 return strlen(windowNameA);
1473 }
1474 else {
1475 return 0;
1476 }
1477
1478 case WM_GETTEXT:
1479 if (!lParam || !wParam) return 0;
1480 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1481 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1482 return min((windowNameA ? strlen(windowNameA) : 0), wParam);
1483
1484 case WM_SETTEXT:
1485 {
1486 LPCSTR lpsz = (LPCSTR)lParam;
1487
1488 if(windowNameA) free(windowNameA);
1489 if(windowNameW) free(windowNameW);
1490 if (lParam)
1491 {
1492 int wndNameLength = strlen(lpsz);
1493 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1494 strcpy(windowNameA, lpsz);
1495 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1496 lstrcpyAtoW(windowNameW, windowNameA);
1497 }
1498 else
1499 {
1500 windowNameA = NULL;
1501 windowNameW = NULL;
1502 }
1503 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1504 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1505 {
1506 HandleNCPaint((HRGN)1);
1507 if(hTaskList) {
1508 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1509 }
1510 if(fOS2Look) {
1511 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1512 }
1513 }
1514
1515 return TRUE;
1516 }
1517
1518 case WM_SETREDRAW:
1519 {
1520 if (wParam)
1521 {
1522 setStyle(getStyle() | WS_VISIBLE);
1523 dprintf(("Enable window update for %x", getWindowHandle()));
1524 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
1525 }
1526 else
1527 {
1528 if (getStyle() & WS_VISIBLE)
1529 {
1530 setStyle(getStyle() & ~WS_VISIBLE);
1531 dprintf(("Disable window update for %x", getWindowHandle()));
1532 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
1533 }
1534 }
1535 return 0;
1536 }
1537
1538 case WM_CTLCOLORMSGBOX:
1539 case WM_CTLCOLOREDIT:
1540 case WM_CTLCOLORLISTBOX:
1541 case WM_CTLCOLORBTN:
1542 case WM_CTLCOLORDLG:
1543 case WM_CTLCOLORSTATIC:
1544 case WM_CTLCOLORSCROLLBAR:
1545 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1546
1547 case WM_CTLCOLOR:
1548 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1549
1550 case WM_VKEYTOITEM:
1551 case WM_CHARTOITEM:
1552 return -1;
1553
1554 case WM_PARENTNOTIFY:
1555 return 0;
1556
1557 case WM_MOUSEACTIVATE:
1558 {
1559 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1560 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1561 {
1562 if(getParent()) {
1563 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1564 if(rc) return rc;
1565 }
1566 }
1567 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1568 }
1569
1570 case WM_ACTIVATE:
1571 /* The default action in Windows is to set the keyboard focus to
1572 * the window, if it's being activated and not minimized */
1573 if (LOWORD(wParam) != WA_INACTIVE) {
1574 if(!(getStyle() & WS_MINIMIZE))
1575 SetFocus(getWindowHandle());
1576 }
1577 return 0;
1578
1579 case WM_SETCURSOR:
1580 {
1581 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1582 if((getStyle() & WS_CHILD))
1583 {
1584 if(getParent()) {
1585 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1586 if(rc) return rc;
1587 }
1588 }
1589 if (wParam == getWindowHandle())
1590 {
1591 HCURSOR hCursor;
1592
1593 switch(LOWORD(lParam))
1594 {
1595 case HTCLIENT:
1596 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1597 break;
1598
1599 case HTLEFT:
1600 case HTRIGHT:
1601 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1602 break;
1603
1604 case HTTOP:
1605 case HTBOTTOM:
1606 hCursor = LoadCursorA(0,IDC_SIZENSA);
1607 break;
1608
1609 case HTTOPLEFT:
1610 case HTBOTTOMRIGHT:
1611 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1612 break;
1613
1614 case HTTOPRIGHT:
1615 case HTBOTTOMLEFT:
1616 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1617 break;
1618
1619 default:
1620 hCursor = LoadCursorA(0,IDC_ARROWA);
1621 break;
1622 }
1623
1624 if (hCursor)
1625 {
1626 SetCursor(hCursor);
1627 return 1;
1628 }
1629 else return 0;
1630 }
1631 else return 0;
1632 }
1633
1634 case WM_MOUSEMOVE:
1635 return 0;
1636
1637 case WM_WINDOWPOSCHANGED:
1638 {
1639 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1640 WPARAM wp = SIZE_RESTORED;
1641
1642 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1643 {
1644 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1645 }
1646 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1647 {
1648 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1649 else
1650 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1651
1652 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1653 rectClient.bottom - rectClient.top));
1654 }
1655 return 0;
1656 }
1657 case WM_WINDOWPOSCHANGING:
1658 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1659
1660 case WM_ERASEBKGND:
1661 case WM_ICONERASEBKGND:
1662 {
1663 RECT rect;
1664 int rc;
1665
1666 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1667
1668 rc = GetClipBox( (HDC)wParam, &rect );
1669 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1670 {
1671 HBRUSH hBrush = windowClass->getBackgroundBrush();
1672
1673 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1674 hBrush = GetSysColorBrush(hBrush-1);
1675
1676 FillRect( (HDC)wParam, &rect, hBrush);
1677 }
1678 return 1;
1679 }
1680
1681 case WM_PRINT:
1682 return DefWndPrint(wParam,lParam);
1683
1684 case WM_PAINTICON:
1685 case WM_PAINT:
1686 {
1687 PAINTSTRUCT ps;
1688 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1689 if( hdc )
1690 {
1691 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1692 {
1693 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1694 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1695 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1696 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1697 }
1698 EndPaint(getWindowHandle(), &ps );
1699 }
1700 return 0;
1701 }
1702
1703 case WM_GETDLGCODE:
1704 return 0;
1705
1706 case WM_NCPAINT:
1707 return HandleNCPaint((HRGN)wParam);
1708
1709 case WM_NCACTIVATE:
1710 return HandleNCActivate(wParam);
1711
1712 case WM_NCCREATE:
1713 return(TRUE);
1714
1715 case WM_NCDESTROY:
1716 return 0;
1717
1718 case WM_NCCALCSIZE:
1719 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1720
1721 case WM_NCLBUTTONDOWN:
1722 return HandleNCLButtonDown(wParam,lParam);
1723
1724 case WM_LBUTTONDBLCLK:
1725 case WM_NCLBUTTONDBLCLK:
1726 return HandleNCLButtonDblClk(wParam,lParam);
1727
1728 case WM_NCRBUTTONDOWN:
1729 case WM_NCRBUTTONDBLCLK:
1730 case WM_NCMBUTTONDOWN:
1731 case WM_NCMBUTTONDBLCLK:
1732 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1733 return 0;
1734
1735 case WM_NCRBUTTONUP:
1736 return HandleNCRButtonUp(wParam,lParam);
1737
1738 case WM_NCMBUTTONUP:
1739 return 0;
1740
1741 case WM_NCHITTEST:
1742 {
1743 POINT point;
1744 LRESULT retvalue;
1745
1746 point.x = (SHORT)LOWORD(lParam);
1747 point.y = (SHORT)HIWORD(lParam);
1748
1749 retvalue = HandleNCHitTest(point);
1750#if 0 //CB: let the Corel people fix the bugs first
1751 if(retvalue == HTMENU)
1752 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1753 else
1754 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1755#endif
1756 return retvalue;
1757 }
1758
1759 case WM_SYSCOMMAND:
1760 {
1761 POINT point;
1762
1763 point.x = LOWORD(lParam);
1764 point.y = HIWORD(lParam);
1765 return HandleSysCommand(wParam,&point);
1766 }
1767
1768 case WM_SYSKEYDOWN:
1769 {
1770 if( HIWORD(lParam) & KEYDATA_ALT )
1771 {
1772 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
1773 if( wParam == VK_MENU && !iMenuSysKey )
1774 iMenuSysKey = 1;
1775 else
1776 iMenuSysKey = 0;
1777
1778 iF10Key = 0;
1779
1780 if( wParam == VK_F4 ) /* try to close the window */
1781 {
1782 HWND top = GetTopWindow();
1783 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
1784 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
1785 }
1786 }
1787 else if( wParam == VK_F10 )
1788 iF10Key = 1;
1789 else
1790 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
1791 SendMessageW(WM_SYSCOMMAND, SC_KEYMENU, VK_SPACE );
1792
1793 Win32BaseWindow *siblingWindow;
1794 HWND sibling;
1795 char nameBuffer [40], mnemonic;
1796 int nameLength;
1797
1798 GetWindowTextA (nameBuffer, 40);
1799
1800 // search all sibling to see it this key is their mnemonic
1801 sibling = GetWindow (GW_HWNDFIRST);
1802 while (sibling != 0) {
1803 siblingWindow = GetWindowFromHandle (sibling);
1804 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1805
1806 // find the siblings mnemonic
1807 mnemonic = '\0';
1808 for (int i=0 ; i<nameLength ; i++) {
1809 if (IsDBCSLeadByte(nameBuffer[i])) {
1810 // Skip DBCS
1811 continue;
1812 }
1813 if (nameBuffer [i] == '&') {
1814 mnemonic = nameBuffer [i+1];
1815 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1816 mnemonic -= 32; // make it uppercase
1817 break; // stop searching
1818 }
1819 }
1820
1821 // key matches siblings mnemonic, send mouseclick
1822 if (mnemonic == (char) wParam) {
1823 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1824 }
1825 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1826 RELEASE_WNDOBJ(siblingWindow);
1827 }
1828
1829 return 0;
1830 }
1831
1832 case WM_KEYUP:
1833 case WM_SYSKEYUP:
1834 /* Press and release F10 or ALT */
1835 if (((wParam == VK_MENU) && iMenuSysKey) ||
1836 ((wParam == VK_F10) && iF10Key))
1837 ::SendMessageW( GetTopWindow(), WM_SYSCOMMAND, SC_KEYMENU, 0L );
1838 iMenuSysKey = iF10Key = 0;
1839 break;
1840
1841 case WM_SYSCHAR:
1842 {
1843 iMenuSysKey = 0;
1844 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1845 {
1846 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1847 (WPARAM)SC_RESTORE, 0L );
1848 break;
1849 }
1850 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1851 {
1852 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
1853 break;
1854 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1855 ::SendMessageW(GetParent(), Msg, wParam, lParam );
1856 }
1857 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1858 }
1859#if 0
1860 else /* check for Ctrl-Esc */
1861 if (wParam != VK_ESCAPE) MessageBeep(0);
1862 break;
1863#endif
1864 }
1865
1866 case WM_SETHOTKEY:
1867 hotkey = wParam;
1868 return 1; //CB: always successful
1869
1870 case WM_GETHOTKEY:
1871 return hotkey;
1872
1873 case WM_CONTEXTMENU:
1874 if ((dwStyle & WS_CHILD) && getParent())
1875 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1876 return 0;
1877
1878 case WM_SHOWWINDOW:
1879 if (!lParam) return 0; /* sent from ShowWindow */
1880 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1881 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1882 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1883 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1884 return 0;
1885
1886 case WM_CANCELMODE:
1887 if (getParent() == windowDesktop) EndMenu();
1888 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1889 return 0;
1890
1891 case WM_DROPOBJECT:
1892 return DRAG_FILE;
1893
1894 case WM_QUERYDROPOBJECT:
1895 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1896
1897 case WM_QUERYDRAGICON:
1898 {
1899 HICON hDragIcon = windowClass->getCursor();
1900 UINT len;
1901
1902 if(hDragIcon) return (LRESULT)hDragIcon;
1903 for(len = 1; len < 64; len++)
1904 {
1905 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1906 if(hDragIcon)
1907 return (LRESULT)hDragIcon;
1908 }
1909 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1910 }
1911
1912 case WM_QUERYOPEN:
1913 case WM_QUERYENDSESSION:
1914 return 1;
1915
1916 case WM_NOTIFYFORMAT:
1917 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1918
1919 case WM_SETICON:
1920 case WM_GETICON:
1921 {
1922 LRESULT result = 0;
1923
1924 /* Set the appropriate icon members in the window structure. */
1925 if (wParam == ICON_SMALL)
1926 {
1927 result = hIconSm;
1928 if (Msg == WM_SETICON)
1929 hIconSm = (HICON)lParam;
1930 }
1931 else
1932 {
1933 result = hIcon;
1934 if (Msg == WM_SETICON)
1935 {
1936 hIcon = (HICON)lParam;
1937 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1938 OSLibWinSetIcon(OS2HwndFrame,hIcon);
1939 }
1940 }
1941 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1942 HandleNCPaint((HRGN)1);
1943
1944 return result;
1945 }
1946
1947 case WM_HELP:
1948 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1949 break;
1950
1951 case WM_NOTIFY:
1952 return 0; //comctl32 controls expect this
1953
1954 default:
1955 return 0;
1956 }
1957 return 0;
1958}
1959//******************************************************************************
1960//******************************************************************************
1961LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1962{
1963 switch(Msg)
1964 {
1965 case WM_GETTEXTLENGTH:
1966 if(windowNameW) {
1967 return lstrlenW(windowNameW);
1968 }
1969 else return 0;
1970
1971 case WM_GETTEXT:
1972 if (!lParam || !wParam) return 0;
1973 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1974 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1975 return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam);
1976
1977 case WM_SETTEXT:
1978 {
1979 LPWSTR lpsz = (LPWSTR)lParam;
1980
1981 if(windowNameA) free(windowNameA);
1982 if(windowNameW) free(windowNameW);
1983 if (lParam)
1984 {
1985 // Wide
1986 int wndNameLength = lstrlenW(lpsz);
1987 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1988 lstrcpyW(windowNameW,lpsz);
1989 // Ascii
1990 LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz);
1991 if(tmp) {
1992 long tmpLength = strlen( tmp );
1993 windowNameA = (LPSTR)_smalloc(tmpLength+1);
1994 strcpy(windowNameA,tmp);
1995 windowNameA[tmpLength] = 0; // need ?
1996 HEAP_free(tmp);
1997 }
1998 else {
1999 windowNameA = (LPSTR)_smalloc(1);
2000 windowNameA[0] = 0;
2001 }
2002 }
2003 else
2004 {
2005 windowNameA = NULL;
2006 windowNameW = NULL;
2007 }
2008 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
2009 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
2010 {
2011 HandleNCPaint((HRGN)1);
2012 if(hTaskList) {
2013 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
2014 }
2015 if(fOS2Look) {
2016 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
2017 }
2018 }
2019
2020 return TRUE;
2021 }
2022
2023 default:
2024 return DefWindowProcA(Msg, wParam, lParam);
2025 }
2026}
2027//******************************************************************************
2028//******************************************************************************
2029LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
2030{
2031 //if the destination window is created by this process & thread, call window proc directly
2032 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
2033 return SendInternalMessageA(Msg, wParam, lParam);
2034 }
2035 //otherwise use WinSendMsg to send it to the right process/thread
2036 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2037 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2038}
2039//******************************************************************************
2040//******************************************************************************
2041LRESULT Win32BaseWindow::SendMessageW(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 SendInternalMessageW(Msg, wParam, lParam);
2046 }
2047 //otherwise use WinSendMsg to send it to the right process/thread
2048 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
2049}
2050//******************************************************************************
2051//Called as a result of an OS/2 message or called from a class method
2052//******************************************************************************
2053LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
2054{
2055 LRESULT rc;
2056 HWND hwnd = getWindowHandle();
2057 BOOL fInternalMsgBackup = fInternalMsg;
2058
2059 //if the destination window was created by this process & thread, call window proc directly
2060 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
2061 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2062 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2063 }
2064
2065 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
2066
2067 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
2068
2069 fInternalMsg = TRUE;
2070 switch(Msg)
2071 {
2072 case WM_CREATE:
2073 {
2074 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2075 dprintf(("WM_CREATE returned -1\n"));
2076 rc = -1; //don't create window
2077 break;
2078 }
2079 rc = 0;
2080 break;
2081 }
2082 case WM_LBUTTONDOWN:
2083 case WM_MBUTTONDOWN:
2084 case WM_RBUTTONDOWN:
2085 {
2086 if (getParent())
2087 {
2088 POINTS pt = MAKEPOINTS(lParam);
2089 POINT point;
2090
2091 point.x = pt.x;
2092 point.y = pt.y;
2093 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
2094 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
2095 }
2096 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2097 break;
2098 }
2099 case WM_NCHITTEST:
2100 rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
2101 break;
2102
2103 case WM_DESTROY:
2104 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2105 break;
2106
2107 default:
2108 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2109 break;
2110 }
2111 if(!::IsWindow(hwnd)) {
2112 //window might have been destroyed by now. (this pointer invalid)
2113 //we must return immediately
2114 //(MS Visual C++ install heap corruption)
2115 //TODO: could happen in several places here!!!!
2116 return rc;
2117 }
2118 fInternalMsg = fInternalMsgBackup;
2119 dprintf2(("SendMessageA %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
2120 return rc;
2121}
2122//******************************************************************************
2123//Called as a result of an OS/2 message or called from a class method
2124//******************************************************************************
2125LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
2126{
2127 LRESULT rc;
2128 HWND hwnd = getWindowHandle();
2129 BOOL fInternalMsgBackup = fInternalMsg;
2130
2131 //if the destination window was created by this process & thread, call window proc directly
2132 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
2133 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2134 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2135 }
2136
2137 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
2138
2139 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
2140
2141 fInternalMsg = TRUE;
2142 switch(Msg)
2143 {
2144 case WM_CREATE:
2145 {
2146 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2147 dprintf(("WM_CREATE returned -1\n"));
2148 rc = -1; //don't create window
2149 break;
2150 }
2151 rc = 0;
2152 break;
2153 }
2154 case WM_LBUTTONDOWN:
2155 case WM_MBUTTONDOWN:
2156 case WM_RBUTTONDOWN:
2157 NotifyParent(Msg, wParam, lParam);
2158 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2159 break;
2160
2161 case WM_NCHITTEST:
2162 rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
2163 break;
2164
2165 case WM_DESTROY:
2166 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2167 break;
2168 default:
2169 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2170 break;
2171 }
2172 if(!::IsWindow(hwnd)) {
2173 //window might have been destroyed by now. (this pointer invalid)
2174 //we must return immediately
2175 //(MS Visual C++ install heap corruption)
2176 //TODO: could happen in several places here!!!!
2177 return rc;
2178 }
2179 fInternalMsg = fInternalMsgBackup;
2180 dprintf2(("SendMessageW %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
2181 return rc;
2182}
2183//******************************************************************************
2184//******************************************************************************
2185void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2186{
2187 CWPSTRUCT cwp;
2188
2189 cwp.lParam = lParam;
2190 cwp.wParam = wParam;
2191 cwp.message = Msg;
2192 cwp.hwnd = getWindowHandle();
2193
2194 switch(hooktype) {
2195 case WH_CALLWNDPROC:
2196 if(fUnicode) {
2197 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2198 }
2199 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2200 break;
2201 }
2202}
2203//******************************************************************************
2204//TODO: Do this more efficiently
2205//******************************************************************************
2206LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2207{
2208 Win32BaseWindow *window;
2209 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2210
2211 dprintf(("BroadCastMessageA %x %x %x %s", msg, wParam, lParam, (type == BROADCAST_SEND) ? "Send" : "Post"));
2212
2213 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2214 window = GetWindowFromHandle(hwnd++);
2215 if(window) {
2216 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2217 {
2218 if(type == BROADCAST_SEND) {
2219 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
2220 }
2221 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2222 }
2223 RELEASE_WNDOBJ(window);
2224 }
2225 }
2226 return 0;
2227}
2228//******************************************************************************
2229//TODO: Do this more efficiently
2230//******************************************************************************
2231LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2232{
2233 Win32BaseWindow *window;
2234 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2235
2236 dprintf(("BroadCastMessageW %x %x %x %s", msg, wParam, lParam, (type == BROADCAST_SEND) ? "Send" : "Post"));
2237
2238 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2239 window = GetWindowFromHandle(hwnd++);
2240 if(window) {
2241 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2242 {
2243 if(type == BROADCAST_SEND) {
2244 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
2245 }
2246 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2247 }
2248 RELEASE_WNDOBJ(window);
2249 }
2250 }
2251 return 0;
2252}
2253//******************************************************************************
2254//******************************************************************************
2255void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2256{
2257 Win32BaseWindow *window = this;
2258 Win32BaseWindow *parentwindow;
2259
2260 while(window)
2261 {
2262 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2263 {
2264 /* Notify the parent window only */
2265 parentwindow = window->getParent();
2266 if(parentwindow) {
2267 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2268 }
2269 }
2270 else break;
2271
2272 window = parentwindow;
2273 }
2274}
2275//******************************************************************************
2276// Returns the big or small icon for the window, falling back to the
2277// class as windows does.
2278//******************************************************************************
2279HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2280{
2281 HICON hWndIcon;
2282
2283 if (fType == ICON_BIG)
2284 {
2285 if (hIcon)
2286 hWndIcon = hIcon;
2287 else
2288 if (windowClass && windowClass->getIcon())
2289 hWndIcon = windowClass->getIcon();
2290 else
2291 if (!(dwStyle & DS_MODALFRAME))
2292 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2293 else hWndIcon = 0;
2294 }
2295 else
2296 {
2297 if (hIconSm)
2298 hWndIcon = hIconSm;
2299 else
2300 if (hIcon)
2301 hWndIcon = hIcon;
2302 else
2303 if (windowClass && windowClass->getIconSm())
2304 hWndIcon = windowClass->getIconSm();
2305 else
2306 if (windowClass && windowClass->getIcon())
2307 hWndIcon = windowClass->getIcon();
2308 else
2309 if (!(dwStyle & DS_MODALFRAME))
2310 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2311 else hWndIcon = 0;
2312 }
2313
2314 return hWndIcon;
2315}
2316//******************************************************************************
2317//******************************************************************************
2318BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2319{
2320 ULONG swp = 0;
2321 HWND hWinAfter;
2322 BOOL rc,wasVisible,showFlag;
2323 RECT newPos = {0, 0, 0, 0};
2324
2325 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2326 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2327
2328 dwOldStyle = getStyle();
2329
2330 switch(nCmdShow)
2331 {
2332 case SW_HIDE:
2333 if (!wasVisible) goto END;
2334
2335 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2336 break;
2337
2338 case SW_SHOWMINNOACTIVE:
2339 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2340 /* fall through */
2341 case SW_SHOWMINIMIZED:
2342 swp |= SWP_SHOWWINDOW;
2343 /* fall through */
2344 case SW_MINIMIZE:
2345 swp |= SWP_FRAMECHANGED;
2346 if( !(getStyle() & WS_MINIMIZE) ) {
2347 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2348 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2349 }
2350 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2351 break;
2352
2353 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2354 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2355 if( !(getStyle() & WS_MAXIMIZE) ) {
2356 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2357 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2358 }
2359 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2360 break;
2361
2362 case SW_SHOWNA:
2363 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2364 /* fall through */
2365 case SW_SHOW:
2366 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2367
2368 /*
2369 * ShowWindow has a little peculiar behavior that if the
2370 * window is already the topmost window, it will not
2371 * activate it.
2372 */
2373 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2374 swp |= SWP_NOACTIVATE;
2375
2376 break;
2377
2378 case SW_SHOWNOACTIVATE:
2379 swp |= SWP_NOZORDER;
2380 if (GetActiveWindow())
2381 swp |= SWP_NOACTIVATE;
2382 /* fall through */
2383 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2384 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2385 case SW_RESTORE:
2386 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2387
2388 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2389 swp |= MinMaximize(SW_RESTORE, &newPos );
2390 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2391 }
2392 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2393 break;
2394 }
2395
2396 showFlag = (nCmdShow != SW_HIDE);
2397 if (showFlag != wasVisible)
2398 {
2399 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2400 if (!::IsWindow( getWindowHandle() )) goto END;
2401 }
2402
2403 /* We can't activate a child window */
2404 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2405 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2406
2407 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2408
2409 if(!(swp & SWP_NOACTIVATE)) {
2410 OSLibWinSetActiveWindow(OS2HwndFrame);
2411 }
2412
2413 if (flags & WIN_NEED_SIZE)
2414 {
2415 /* should happen only in CreateWindowEx() */
2416 int wParam = SIZE_RESTORED;
2417
2418 flags &= ~WIN_NEED_SIZE;
2419 if (dwStyle & WS_MAXIMIZE)
2420 wParam = SIZE_MAXIMIZED;
2421 else
2422 if (dwStyle & WS_MINIMIZE)
2423 wParam = SIZE_MINIMIZED;
2424
2425 SendInternalMessageA(WM_SIZE, wParam,
2426 MAKELONG(rectClient.right-rectClient.left,
2427 rectClient.bottom-rectClient.top));
2428 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2429 }
2430//testestest
2431 //temporary workaround for file dialogs with template dialog child
2432 //they don't redraw when switching directories
2433 //For some reason the new child's (syslistview32) update rectangle stays
2434 //empty after its parent is made visible with ShowWindow
2435 //TODO: find real cause
2436 if(!wasVisible) {
2437 InvalidateRect(getWindowHandle(), NULL, TRUE);
2438 }
2439//testestest
2440END:
2441 fMinMaxChange = FALSE;
2442 return wasVisible;
2443}
2444//******************************************************************************
2445//******************************************************************************
2446BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2447{
2448 BOOL rc = FALSE;
2449 Win32BaseWindow *window;
2450 HWND hParent = 0;
2451 RECT oldClientRect = rectClient;
2452
2453 if (fuFlags &
2454 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2455 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2456 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2457 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2458 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
2459 {
2460 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2461 return FALSE;
2462 }
2463
2464 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
2465 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2466 }
2467
2468 if(IsWindowDestroyed()) {
2469 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2470 dprintf(("SetWindowPos; window already destroyed"));
2471 return TRUE;
2472 }
2473#if 0
2474 /* Fix redundant flags */
2475 if(getStyle() & WS_VISIBLE) {
2476 fuFlags &= ~SWP_SHOWWINDOW;
2477 }
2478 else
2479 {
2480 if (!(fuFlags & SWP_SHOWWINDOW))
2481 fuFlags |= SWP_NOREDRAW;
2482 fuFlags &= ~SWP_HIDEWINDOW;
2483 }
2484
2485 if(cx < 0) cx = 0;
2486 if(cy < 0) cy = 0;
2487
2488 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2489 fuFlags |= SWP_NOSIZE; /* Already the right size */
2490 }
2491
2492 if((rectWindow.left == x) && (rectWindow.top == y)) {
2493 fuFlags |= SWP_NOMOVE; /* Already the right position */
2494 }
2495
2496 if(getWindowHandle() == GetActiveWindow()) {
2497 fuFlags |= SWP_NOACTIVATE; /* Already active */
2498 }
2499 else
2500 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2501 {
2502 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2503 {
2504 fuFlags &= ~SWP_NOZORDER;
2505 hwndInsertAfter = HWND_TOP;
2506 }
2507 }
2508#endif
2509
2510 //Note: Solitaire crashes when receiving WM_SIZE messages before WM_CREATE
2511 if(state < STATE_POST_WMNCCREATE)
2512 {//don't change size; modify internal structures only
2513 //TODO: not 100% correct yet (activate)
2514 dprintf2(("state < STATE_POST_WMNCCREATE"));
2515 if(!(fuFlags & SWP_NOZORDER)) {
2516 hwndLinkAfter = hwndInsertAfter;
2517 }
2518 if(!(fuFlags & SWP_NOMOVE)) {
2519 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2520 rectWindow.top = y;
2521 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2522 rectWindow.left = x;
2523 }
2524 if(!(fuFlags & SWP_NOSIZE)) {
2525 rectWindow.bottom = rectWindow.top + cy;
2526 rectWindow.right = rectWindow.left + cx;
2527 }
2528 return TRUE;
2529 }
2530
2531 WINDOWPOS wpos;
2532 SWP swp, swpOld;
2533 wpos.flags = fuFlags;
2534 wpos.cy = cy;
2535 wpos.cx = cx;
2536 wpos.x = x;
2537 wpos.y = y;
2538 wpos.hwndInsertAfter = hwndInsertAfter;
2539 wpos.hwnd = getWindowHandle();
2540
2541 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2542 {
2543 if (isChild())
2544 {
2545 if(!getParent()) {
2546 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2547 }
2548 }
2549 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2550 }
2551
2552 if(getParent()) {
2553 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2554 OS2HwndFrame);
2555 }
2556 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2557
2558 if (swp.fl == 0) {
2559 dprintf2(("swp.fl == 0"));
2560 if(fuFlags & SWP_FRAMECHANGED)
2561 {
2562 NotifyFrameChanged(&wpos, &oldClientRect);
2563 }
2564 return TRUE;
2565 }
2566
2567// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2568 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2569 {
2570 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2571 if(wndBehind) {
2572 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2573 RELEASE_WNDOBJ(wndBehind);
2574 }
2575 else {
2576 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2577 swp.hwndInsertBehind = 0;
2578 }
2579 }
2580 swp.hwnd = OS2HwndFrame;
2581
2582 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2583 setStyle(getStyle() | WS_VISIBLE);
2584 if(hTaskList) {
2585 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2586 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2587 }
2588 }
2589 else
2590 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2591 setStyle(getStyle() & ~WS_VISIBLE);
2592 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2593 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2594 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2595 }
2596 }
2597 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2598 rc = OSLibWinSetMultWindowPos(&swp, 1);
2599
2600 if(rc == FALSE)
2601 {
2602 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2603 return 0;
2604 }
2605
2606 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2607 {
2608 NotifyFrameChanged(&wpos, &oldClientRect);
2609 }
2610 return (rc);
2611}
2612//******************************************************************************
2613//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2614//******************************************************************************
2615BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2616{
2617 rectWindow.left += dx;
2618 rectWindow.right += dx;
2619 rectWindow.top += dy;
2620 rectWindow.bottom += dy;
2621 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2622 return TRUE;
2623}
2624//******************************************************************************
2625//******************************************************************************
2626void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2627{
2628 HRGN hrgn, hrgnClient;
2629 RECT rect;
2630
2631 MsgFormatFrame(NULL);
2632
2633 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2634 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2635 {
2636 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2637 wpos->cx = RECT_WIDTH(rectWindow);
2638 wpos->cy = RECT_HEIGHT(rectWindow);
2639 }
2640
2641 if(rectClient.left != oldClientRect->left ||
2642 rectClient.top != oldClientRect->top)
2643 {
2644 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2645 wpos->x = rectWindow.left;
2646 wpos->y = rectWindow.top;
2647 }
2648
2649 WINDOWPOS wpOld = *wpos;
2650 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2651
2652 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2653 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2654 {
2655 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2656 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2657 }
2658 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2659
2660 //Calculate invalid areas
2661 rect = rectWindow;
2662 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2663 hrgn = CreateRectRgnIndirect(&rect);
2664 if (!hrgn) {
2665 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2666 return;
2667 }
2668 rect = rectClient;
2669 hrgnClient = CreateRectRgnIndirect(&rect);
2670 if (!hrgn) {
2671 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2672 return;
2673 }
2674 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2675 DeleteObject(hrgnClient);
2676
2677 if(!EqualRect(oldClientRect, &rectClient)) {
2678 UnionRect(oldClientRect, oldClientRect, &rectClient);
2679 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2680 if (!hrgn) {
2681 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2682 return;
2683 }
2684 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2685 DeleteObject(hrgnClient);
2686 }
2687 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2688 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2689 DeleteObject(hrgn);
2690}
2691//******************************************************************************
2692//TODO: Check how this api really works in NT
2693//******************************************************************************
2694BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2695{
2696 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2697 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2698 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2699 windowpos.ptMinPosition = wndpl->ptMinPosition;
2700 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2701 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2702
2703 if(getStyle() & WS_MINIMIZE )
2704 {
2705 //TODO: Why can't this be (0,0)?
2706 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2707 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2708 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2709 }
2710 }
2711 else
2712 if(getStyle() & WS_MAXIMIZE )
2713 {
2714 //TODO: Why can't this be (0,0)?
2715 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2716 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2717 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2718 }
2719 else {
2720 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2721 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2722 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2723 SWP_NOZORDER | SWP_NOACTIVATE );
2724 }
2725 ShowWindow(wndpl->showCmd);
2726 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2727 {
2728 /* SDK: ...valid only the next time... */
2729 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2730 setFlags(getFlags() | WIN_RESTORE_MAX);
2731 }
2732 return TRUE;
2733}
2734//******************************************************************************
2735//******************************************************************************
2736BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2737{
2738 wndpl->length = sizeof(*wndpl);
2739 if(getStyle() & WS_MINIMIZE )
2740 wndpl->showCmd = SW_SHOWMINIMIZED;
2741 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2742
2743 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2744 if(getFlags() & WIN_RESTORE_MAX )
2745 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2746 else wndpl->flags = 0;
2747
2748 wndpl->ptMinPosition = windowpos.ptMinPosition;
2749 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2750 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2751 wndpl->rcNormalPosition = rectWindow;
2752
2753 return TRUE;
2754}
2755//******************************************************************************
2756//Also destroys all the child windows (destroy children first, parent last)
2757//******************************************************************************
2758BOOL Win32BaseWindow::DestroyWindow()
2759{
2760 HWND hwnd = getWindowHandle();
2761
2762 dprintf(("DestroyWindow %x", hwnd));
2763
2764 /* Call hooks */
2765 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2766 {
2767 return FALSE;
2768 }
2769
2770 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2771 {
2772 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2773 /* FIXME: clean up palette - see "Internals" p.352 */
2774 }
2775
2776 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2777 {
2778 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2779 {
2780 /* Notify the parent window only */
2781 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2782 if(!::IsWindow(hwnd) )
2783 {
2784 return TRUE;
2785 }
2786 }
2787//// else DebugInt3();
2788 }
2789 /* Hide the window */
2790 if(IsWindowVisible(getWindowHandle()))
2791 {
2792 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2793 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2794 if(!::IsWindow(hwnd))
2795 {
2796 return TRUE;
2797 }
2798 }
2799 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2800
2801 // check the handle for the last active popup window
2802 Win32BaseWindow* owner = getOwner();
2803 if (NULL != owner)
2804 {
2805 if (owner->getLastActive() == hwnd)
2806 owner->setLastActive( owner->getWindowHandle() );
2807 }
2808
2809 fDestroyWindowCalled = TRUE;
2810 return OSLibWinDestroyWindow(OS2HwndFrame);
2811}
2812//******************************************************************************
2813//******************************************************************************
2814Win32BaseWindow *Win32BaseWindow::getParent()
2815{
2816 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2817 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2818}
2819//******************************************************************************
2820//Note: does not set last error if no parent (verified in NT4, SP6)
2821//******************************************************************************
2822HWND Win32BaseWindow::GetParent()
2823{
2824 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2825
2826 if(getStyle() & WS_CHILD) {
2827 if(wndparent) {
2828 return wndparent->getWindowHandle();
2829 }
2830 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2831 DebugInt3();
2832 return 0;
2833 }
2834 else
2835 if(getStyle() & WS_POPUP)
2836 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2837 else return 0;
2838}
2839//******************************************************************************
2840//******************************************************************************
2841HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2842{
2843 HWND oldhwnd;
2844 Win32BaseWindow *newparent;
2845 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2846 BOOL fShow = FALSE;
2847
2848 if(oldparent) {
2849 oldhwnd = oldparent->getWindowHandle();
2850 oldparent->removeChild(this);
2851 }
2852 else oldhwnd = 0;
2853
2854 /* Windows hides the window first, then shows it again
2855 * including the WM_SHOWWINDOW messages and all */
2856 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
2857 ShowWindow(SW_HIDE);
2858 fShow = TRUE;
2859 }
2860 if(oldparent) {
2861 //release parent here (increased refcount during creation)
2862 RELEASE_WNDOBJ(oldparent);
2863 }
2864 newparent = GetWindowFromHandle(hwndNewParent);
2865 if(newparent && !newparent->isDesktopWindow())
2866 {
2867 setParent(newparent);
2868 getParent()->addChild(this);
2869 fParentChange = TRUE;
2870
2871 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2872 if(!(getStyle() & WS_CHILD))
2873 {
2874 //TODO: Send WM_STYLECHANGED msg?
2875 setStyle(getStyle() | WS_CHILD);
2876 if(getWindowId())
2877 {
2878 DestroyMenu( (HMENU) getWindowId() );
2879 setWindowId(0);
2880 }
2881 }
2882 //SvL: Even though the win32 coordinates might not change, the PM
2883 // coordinates can. We must make sure the control stays at the
2884 // same position (y) relative to the (new) parent.
2885 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
2886 SWP_NOACTIVATE|SWP_NOSIZE);
2887 fParentChange = FALSE;
2888 }
2889 else {
2890 if(newparent) RELEASE_WNDOBJ(newparent);
2891
2892 setParent(windowDesktop);
2893 windowDesktop->addRef();
2894 windowDesktop->addChild(this);
2895 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2896
2897 //TODO: Send WM_STYLECHANGED msg?
2898 setStyle(getStyle() & ~WS_CHILD);
2899 setWindowId(0);
2900 }
2901 /* SetParent additionally needs to make hwndChild the topmost window
2902 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2903 WM_WINDOWPOSCHANGED notification messages.
2904 */
2905 if(state >= STATE_PRE_WMNCCREATE) {
2906 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2907 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2908
2909 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2910 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2911 }
2912 return oldhwnd;
2913}
2914//******************************************************************************
2915//******************************************************************************
2916BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2917{
2918 // PH: Optimizer won't unroll calls to getParent() even
2919 // in release build.
2920 Win32BaseWindow *_parent = getParent();
2921
2922 if(_parent)
2923 {
2924 if(_parent->getWindowHandle() == hwndParent)
2925 return TRUE;
2926
2927 return _parent->IsChild(hwndParent);
2928 }
2929 else
2930 return 0;
2931}
2932//******************************************************************************
2933//******************************************************************************
2934HWND Win32BaseWindow::GetTopWindow()
2935{
2936 HWND hwndTop;
2937 Win32BaseWindow *topwindow;
2938
2939 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2940 if(!isDesktopWindow())
2941 {
2942 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2943 //Note: GetTopWindow can't return a window that hasn't processed
2944 // WM_NCCREATE yet (verified in NT4, SP6)
2945 if(topwindow) {
2946 if(topwindow->state >= STATE_POST_WMNCCREATE) {
2947 hwndTop = topwindow->getWindowHandle();
2948 }
2949 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
2950 RELEASE_WNDOBJ(topwindow);
2951 return hwndTop;
2952 }
2953 if(topwindow) RELEASE_WNDOBJ(topwindow);
2954 return 0;
2955 }
2956 while(hwndTop) {
2957 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2958 //Note: GetTopWindow can't return a window that hasn't processed
2959 // WM_NCCREATE yet (verified in NT4, SP6)
2960 if(topwindow) {
2961 if(topwindow->state >= STATE_POST_WMNCCREATE) {
2962 hwndTop = topwindow->getWindowHandle();
2963 }
2964 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
2965 RELEASE_WNDOBJ(topwindow);
2966 return hwndTop;
2967 }
2968 if(topwindow) RELEASE_WNDOBJ(topwindow);
2969 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2970 }
2971
2972 return 0;
2973}
2974//******************************************************************************
2975// Get the top-level parent for a child window.
2976//******************************************************************************
2977HWND Win32BaseWindow::GetTopParent()
2978{
2979 Win32BaseWindow *window = this;
2980 HWND hwndTopParent = 0;
2981
2982 lock();
2983 while(window && (window->getStyle() & WS_CHILD))
2984 {
2985 window = window->getParent();
2986 }
2987 if(window) {
2988 hwndTopParent = window->getWindowHandle();
2989 }
2990 unlock();
2991 return hwndTopParent;
2992}
2993//******************************************************************************
2994//TODO: Should not enumerate children that are created during the enumeration!
2995//******************************************************************************
2996BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2997{
2998 BOOL rc = TRUE;
2999 HWND hwnd;
3000 Win32BaseWindow *prevchild = 0, *child = 0;
3001
3002 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3003 lock();
3004 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3005 {
3006 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3007 hwnd = child->getWindowHandle();
3008 if(child->IsWindowDestroyed() || child->getOwner()) {
3009 continue; //shouldn't have an owner (Wine)
3010 }
3011 child->addRef();
3012 unlock();
3013 if(lpfn(hwnd, lParam) == FALSE)
3014 {
3015 child->release();
3016 return FALSE;
3017 }
3018 child->release();
3019 lock();
3020 //check if the window still exists
3021 if(!::IsWindow(hwnd))
3022 {
3023 child = prevchild;
3024 continue;
3025 }
3026 if(child->getFirstChild() != NULL)
3027 {
3028 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3029 child->addRef();
3030 unlock();
3031 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3032 {
3033 child->release();
3034 return FALSE;
3035 }
3036 child->release();
3037 lock();
3038 }
3039 prevchild = child;
3040 }
3041 unlock();
3042 return rc;
3043}
3044//******************************************************************************
3045//Enumerate first-level children only and check thread id
3046//******************************************************************************
3047BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3048{
3049 Win32BaseWindow *child = 0;
3050 ULONG tid, pid;
3051 BOOL rc;
3052 HWND hwnd;
3053
3054 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
3055
3056 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3057 {
3058 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
3059
3060 if(dwThreadId == tid) {
3061 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
3062 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3063 break;
3064 }
3065 }
3066 }
3067 return TRUE;
3068}
3069//******************************************************************************
3070//Enumerate first-level children only
3071//******************************************************************************
3072BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3073{
3074 Win32BaseWindow *child = 0;
3075 BOOL rc;
3076 HWND hwnd;
3077
3078 dprintf(("EnumWindows %x %x", lpfn, lParam));
3079
3080 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3081 {
3082 hwnd = child->getWindowHandle();
3083
3084 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
3085 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3086 break;
3087 }
3088 }
3089 return TRUE;
3090}
3091//******************************************************************************
3092//******************************************************************************
3093HWND Win32BaseWindow::FindWindowById(int id)
3094{
3095 HWND hwnd;
3096
3097 lock();
3098 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3099 {
3100 if (child->getWindowId() == id)
3101 {
3102 hwnd = child->getWindowHandle();
3103 unlock();
3104 return hwnd;
3105 }
3106 }
3107 unlock();
3108 return 0;
3109}
3110//******************************************************************************
3111//TODO:
3112//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3113//the current process owns them.
3114//******************************************************************************
3115HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3116{
3117 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3118 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3119 Win32BaseWindow *firstchild = child;
3120
3121 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3122 if((hwndParent != 0 && !parent) ||
3123 (hwndChildAfter != 0 && !child) ||
3124 (hwndParent == 0 && hwndChildAfter != 0))
3125 {
3126 if(parent) RELEASE_WNDOBJ(parent);
3127 if(firstchild) RELEASE_WNDOBJ(firstchild);
3128 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3129 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3130 return 0;
3131 }
3132 SetLastError(0);
3133 if(hwndParent != 0)
3134 {//if the current process owns the window, just do a quick search
3135 lock(&critsect);
3136 child = (Win32BaseWindow *)parent->getFirstChild();
3137 if(hwndChildAfter != 0)
3138 {
3139 while(child)
3140 {
3141 if(child->getWindowHandle() == hwndChildAfter)
3142 {
3143 child = (Win32BaseWindow *)child->getNextChild();
3144 break;
3145 }
3146 child = (Win32BaseWindow *)child->getNextChild();
3147 }
3148 }
3149 while(child)
3150 {
3151 //According to Wine, the class doesn't need to be specified
3152 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3153 (!lpszWindow || child->hasWindowName(lpszWindow)))
3154 {
3155 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3156 HWND hwndChild = child->getWindowHandle();
3157 unlock(&critsect);
3158 if(parent) RELEASE_WNDOBJ(parent);
3159 if(firstchild) RELEASE_WNDOBJ(firstchild);
3160 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3161 return hwndChild;
3162 }
3163 child = (Win32BaseWindow *)child->getNextChild();
3164 }
3165 unlock(&critsect);
3166 if(parent) RELEASE_WNDOBJ(parent);
3167 if(firstchild) RELEASE_WNDOBJ(firstchild);
3168 }
3169 else {
3170 Win32BaseWindow *wnd;
3171 HWND henum, hwnd;
3172
3173 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3174 hwnd = OSLibWinGetNextWindow(henum);
3175
3176 while(hwnd)
3177 {
3178 wnd = GetWindowFromOS2FrameHandle(hwnd);
3179 if(wnd == NULL) {
3180 hwnd = OSLibWinQueryClientWindow(hwnd);
3181 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3182 }
3183
3184 if(wnd) {
3185 //According to Wine, the class doesn't need to be specified
3186 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3187 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3188 {
3189 OSLibWinEndEnumWindows(henum);
3190 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3191 HWND hwndret = wnd->getWindowHandle();
3192 RELEASE_WNDOBJ(wnd);
3193 return hwndret;
3194 }
3195 RELEASE_WNDOBJ(wnd);
3196 }
3197 hwnd = OSLibWinGetNextWindow(henum);
3198 }
3199 OSLibWinEndEnumWindows(henum);
3200 if(parent) RELEASE_WNDOBJ(parent);
3201 if(firstchild) RELEASE_WNDOBJ(firstchild);
3202 }
3203 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3204 return 0;
3205}
3206//******************************************************************************
3207//******************************************************************************
3208HWND Win32BaseWindow::GetWindow(UINT uCmd)
3209{
3210 HWND hwndRelated = 0;
3211 Win32BaseWindow *window;
3212
3213 switch(uCmd)
3214 {
3215 case GW_HWNDFIRST:
3216 window = (Win32BaseWindow *)getParent();
3217 if(window)
3218 {
3219 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3220 window = GetWindowFromOS2FrameHandle(hwndRelated);
3221 if(window) {
3222 hwndRelated = window->getWindowHandle();
3223 RELEASE_WNDOBJ(window);
3224 }
3225 else hwndRelated = 0;
3226 }
3227 else {
3228 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3229 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3230 }
3231 break;
3232
3233 case GW_HWNDLAST:
3234 window = (Win32BaseWindow *)getParent();
3235 if(window) {
3236 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3237 dprintf(("os2 handle %x", hwndRelated));
3238 window = GetWindowFromOS2FrameHandle(hwndRelated);
3239 if(window) {
3240 hwndRelated = window->getWindowHandle();
3241 RELEASE_WNDOBJ(window);
3242 }
3243 else hwndRelated = 0;
3244 }
3245 else {
3246 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3247 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3248 }
3249 break;
3250
3251 case GW_HWNDNEXT:
3252 if(getParent()) {
3253 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3254 window = GetWindowFromOS2FrameHandle(hwndRelated);
3255 if(window) {
3256 hwndRelated = window->getWindowHandle();
3257 RELEASE_WNDOBJ(window);
3258 }
3259 else hwndRelated = 0;
3260 }
3261 else {
3262 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3263 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3264 }
3265 break;
3266
3267 case GW_HWNDPREV:
3268 if(getParent()) {
3269 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3270 window = GetWindowFromOS2FrameHandle(hwndRelated);
3271 if(window) {
3272 hwndRelated = window->getWindowHandle();
3273 RELEASE_WNDOBJ(window);
3274 }
3275 else hwndRelated = 0;
3276 }
3277 else {
3278 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3279 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3280 }
3281 break;
3282
3283 case GW_OWNER:
3284 {
3285 Win32BaseWindow *owner = getOwner();
3286 if(owner) {
3287 hwndRelated = owner->getWindowHandle();
3288 }
3289 break;
3290 }
3291
3292 case GW_CHILD:
3293 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3294 window = GetWindowFromOS2FrameHandle(hwndRelated);
3295
3296 //Before a window has processed WM_NCCREATE:
3297 //- GetWindow(parent, GW_CHILD) can't return that window handle
3298 //(verified in NT4, SP6)
3299 if(window) {
3300 if(window->state >= STATE_POST_WMNCCREATE) {
3301 hwndRelated = window->getWindowHandle();
3302 RELEASE_WNDOBJ(window);
3303 }
3304 else {
3305 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3306 RELEASE_WNDOBJ(window);
3307 }
3308 }
3309 else hwndRelated = 0;
3310
3311 break;
3312
3313 //for internal use only
3314 case GW_HWNDNEXTCHILD:
3315 lock();
3316 window = (Win32BaseWindow *)getNextChild();
3317 if(window) {
3318 hwndRelated = window->getWindowHandle();
3319 }
3320 else hwndRelated = 0;
3321 unlock();
3322 break;
3323
3324 case GW_HWNDPREVCHILD:
3325 DebugInt3();
3326 break;
3327
3328 case GW_HWNDFIRSTCHILD:
3329 lock();
3330 window = (Win32BaseWindow *)getFirstChild();
3331 if(window) {
3332 hwndRelated = window->getWindowHandle();
3333 }
3334 else hwndRelated = 0;
3335 unlock();
3336 break;
3337
3338 case GW_HWNDLASTCHILD:
3339 lock();
3340 window = (Win32BaseWindow *)getFirstChild();
3341 if(window) {
3342 while (window->getNextChild())
3343 {
3344 window = (Win32BaseWindow *)window->getNextChild();
3345 }
3346 hwndRelated = window->getWindowHandle();
3347 }
3348 else hwndRelated = 0;
3349 unlock();
3350 break;
3351 }
3352end:
3353 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3354 return hwndRelated;
3355}
3356//******************************************************************************
3357//******************************************************************************
3358HWND Win32BaseWindow::SetActiveWindow()
3359{
3360 HWND hwndActive;
3361
3362 dprintf(("SetActiveWindow %x", getWindowHandle()));
3363 if(getStyle() & WS_CHILD) {
3364// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3365 dprintf(("WARNING: Window is a child or disabled"));
3366 return 0;
3367 }
3368
3369 if(GetActiveWindow() == getWindowHandle()) {
3370 dprintf(("Window already active"));
3371 return getWindowHandle();
3372 }
3373 if (HOOK_IsHooked( WH_CBT ))
3374 {
3375 CBTACTIVATESTRUCT cbta;
3376 LRESULT ret;
3377
3378 cbta.fMouse = FALSE;
3379 cbta.hWndActive = GetActiveWindow();
3380 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3381 if(ret)
3382 {
3383 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3384 return cbta.hWndActive;
3385 }
3386 }
3387 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3388
3389// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3390// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3391// }
3392 hwndActive = GetActiveWindow();
3393 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3394}
3395//******************************************************************************
3396//Used to change active status of an mdi window
3397//******************************************************************************
3398BOOL Win32BaseWindow::DeactivateChildWindow()
3399{
3400 /* child windows get a WM_CHILDACTIVATE message */
3401 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3402 {
3403 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3404 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3405 return TRUE;
3406 }
3407 DebugInt3(); //should not be called for non-child window
3408 return FALSE;
3409}
3410//******************************************************************************
3411//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3412//******************************************************************************
3413BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3414{
3415 BOOL rc;
3416
3417 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3418 //return true if previous state was disabled, else false (sdk docs)
3419 rc = (getStyle() & WS_DISABLED) != 0;
3420 if(rc && !fEnable) {
3421 SendMessageA(WM_CANCELMODE, 0, 0);
3422 }
3423 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3424 if(fEnable == FALSE) {
3425 //SvL: No need to clear focus as PM already does this
3426 if(getWindowHandle() == GetCapture()) {
3427 ReleaseCapture(); /* A disabled window can't capture the mouse */
3428 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3429 }
3430 }
3431 return rc;
3432}
3433//******************************************************************************
3434//******************************************************************************
3435BOOL Win32BaseWindow::CloseWindow()
3436{
3437 return OSLibWinMinimizeWindow(OS2Hwnd);
3438}
3439//******************************************************************************
3440//TODO: Not be 100% correct; should return active window of current thread
3441// or NULL when there is none -> WinQueryActiveWindow just returns
3442// the current active window
3443//******************************************************************************
3444HWND Win32BaseWindow::GetActiveWindow()
3445{
3446 HWND hwndActive;
3447
3448 hwndActive = OSLibWinQueryActiveWindow();
3449
3450 return OS2ToWin32Handle(hwndActive);
3451}
3452//******************************************************************************
3453//******************************************************************************
3454BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3455{
3456 INT len = GetWindowTextLength(fUnicode);
3457 BOOL res;
3458
3459 if (wndname == NULL)
3460 return (len == 0);
3461
3462 len++;
3463 if (fUnicode)
3464 {
3465 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3466
3467 GetWindowTextW(text,len);
3468 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3469 free(text);
3470 }
3471 else
3472 {
3473 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3474
3475 GetWindowTextA(text,len);
3476 res = (strcmp(text,wndname) == 0);
3477 free(text);
3478 }
3479
3480 return res;
3481}
3482//******************************************************************************
3483//******************************************************************************
3484CHAR *Win32BaseWindow::getWindowNamePtrA()
3485{
3486 INT len = GetWindowTextLength(FALSE);
3487 CHAR *text;
3488
3489 if (len == 0) return NULL;
3490 len++;
3491 text = (CHAR*)malloc(len*sizeof(CHAR));
3492 GetWindowTextA(text,len);
3493
3494 return text;
3495}
3496//******************************************************************************
3497//******************************************************************************
3498WCHAR *Win32BaseWindow::getWindowNamePtrW()
3499{
3500 INT len = GetWindowTextLength(TRUE);
3501 WCHAR *text;
3502
3503 if (len == 0) return NULL;
3504 len++;
3505 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3506 GetWindowTextW(text,len);
3507
3508 return text;
3509}
3510//******************************************************************************
3511//******************************************************************************
3512VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3513{
3514 if (namePtr) free(namePtr);
3515}
3516//******************************************************************************
3517//When using this API for a window that was created by a different process, NT
3518//does NOT send WM_GETTEXTLENGTH.
3519//******************************************************************************
3520int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3521{
3522 //if the destination window is created by this process, send message
3523 if(dwProcessId == currentProcessId) {
3524 if(fUnicode) {
3525 return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
3526 }
3527 else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3528 }
3529 //else get data directory from window structure
3530 //TODO: must lock window structure.... (TODO)
3531 if(fUnicode) {
3532 if(windowNameW) {
3533 return strlenW(windowNameW);
3534 }
3535 else return 0;
3536 }
3537 else {
3538 if(windowNameA) {
3539 return strlen(windowNameA);
3540 }
3541 else return 0;
3542 }
3543}
3544//******************************************************************************
3545//When using this API for a window that was created by a different process, NT
3546//does NOT send WM_GETTEXT.
3547//******************************************************************************
3548int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3549{
3550 //if the destination window is created by this process, send message
3551 if(dwProcessId == currentProcessId) {
3552 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3553 }
3554 //else get data directory from window structure
3555 if (!lpsz || !cch) return 0;
3556 if (!windowNameA) lpsz[0] = 0;
3557 else lstrcpynA(lpsz, windowNameA, cch);
3558 return min((windowNameA ? strlen(windowNameA) : 0), cch);
3559}
3560//******************************************************************************
3561//When using this API for a window that was created by a different process, NT
3562//does NOT send WM_GETTEXT.
3563//******************************************************************************
3564int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3565{
3566 //if the destination window is created by this process, send message
3567 if(dwProcessId == currentProcessId) {
3568 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3569 }
3570 //else get data directory from window structure
3571 if (!lpsz || !cch) return 0;
3572 if (!windowNameW) lpsz[0] = 0;
3573 else lstrcpynW(lpsz, windowNameW, cch);
3574 return min((windowNameW ? strlenW(windowNameW) : 0), cch);
3575}
3576//******************************************************************************
3577//TODO: How does this work when the target window belongs to a different process???
3578//******************************************************************************
3579BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3580{
3581 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3582}
3583//******************************************************************************
3584//******************************************************************************
3585BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3586{
3587 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3588}
3589//******************************************************************************
3590//******************************************************************************
3591LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
3592{
3593 LONG oldval;
3594
3595 switch(index) {
3596 case GWL_EXSTYLE:
3597 {
3598 STYLESTRUCT ss;
3599
3600 if(dwExStyle == value) {
3601 oldval = value;
3602 break;
3603 }
3604 ss.styleOld = dwExStyle;
3605 ss.styleNew = value;
3606 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3607 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3608 setExStyle(ss.styleNew);
3609 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3610 oldval = ss.styleOld;
3611 break;
3612 }
3613 case GWL_STYLE:
3614 {
3615 STYLESTRUCT ss;
3616
3617 //SvL: TODO: Can you change minimize or maximize status here too?
3618
3619 if(dwStyle == value) {
3620 oldval = value;
3621 break;
3622 }
3623 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3624#ifdef DEBUG
3625// if((value & WS_CHILD) != (dwStyle & WS_CHILD)) {
3626// DebugInt3(); //is this allowed?
3627// }
3628#endif
3629 value &= ~(WS_CHILD);
3630 ss.styleOld = getStyle();
3631 ss.styleNew = value | (ss.styleOld & WS_CHILD);
3632 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3633 setStyle(ss.styleNew);
3634 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3635 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
3636
3637 //TODO: Might not be correct to use ShowWindow here
3638 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3639 if(ss.styleNew & WS_VISIBLE)
3640 ShowWindow(SW_SHOWNOACTIVATE);
3641 else ShowWindow(SW_HIDE);
3642 }
3643#ifdef DEBUG
3644 PrintWindowStyle(ss.styleNew, 0);
3645#endif
3646 oldval = ss.styleOld;
3647 break;
3648 }
3649 case GWL_WNDPROC:
3650 {
3651 //Note: Type of SetWindowLong determines new window proc type
3652 // UNLESS the new window proc has already been registered
3653 // (use the old type in that case)
3654 // (VERIFIED in NT 4, SP6)
3655 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3656 if(type == WIN_PROC_INVALID) {
3657 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3658 }
3659 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3660 dprintf(("SetWindowLong GWL_WNDPROC %x old %x new wndproc %x", getWindowHandle(), oldval, value));
3661 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3662 break;
3663 }
3664 case GWL_HINSTANCE:
3665 oldval = hInstance;
3666 hInstance = value;
3667 break;
3668
3669 case GWL_HWNDPARENT:
3670 oldval = SetParent((HWND)value);
3671 break;
3672
3673 case GWL_ID:
3674 oldval = getWindowId();
3675 setWindowId(value);
3676 break;
3677
3678 case GWL_USERDATA:
3679 oldval = userData;
3680 userData = value;
3681 break;
3682
3683 default:
3684 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3685 {
3686 oldval = *(ULONG *)(userWindowBytes + index);
3687 *(ULONG *)(userWindowBytes + index) = value;
3688 break;
3689 }
3690 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3691 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3692 return 0;
3693 }
3694 //Note: NT4, SP6 does not set the last error to 0
3695 SetLastError(ERROR_SUCCESS);
3696 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3697 return oldval;
3698}
3699//******************************************************************************
3700//******************************************************************************
3701ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3702{
3703 ULONG value;
3704
3705 switch(index) {
3706 case GWL_EXSTYLE:
3707 value = dwExStyle;
3708 break;
3709 case GWL_STYLE:
3710 value = dwStyle;
3711 break;
3712 case GWL_WNDPROC:
3713 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3714 break;
3715 case GWL_HINSTANCE:
3716 value = hInstance;
3717 break;
3718 case GWL_HWNDPARENT:
3719 value = GetParent();
3720 break;
3721 case GWL_ID:
3722 value = getWindowId();
3723 break;
3724 case GWL_USERDATA:
3725 value = userData;
3726 break;
3727 default:
3728 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3729 {
3730 value = *(ULONG *)(userWindowBytes + index);
3731 break;
3732 }
3733 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3734 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3735 return 0;
3736 }
3737 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3738 //Note: NT4, SP6 does not set the last error to 0
3739 SetLastError(ERROR_SUCCESS);
3740 return value;
3741}
3742//******************************************************************************
3743//******************************************************************************
3744WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3745{
3746 WORD oldval;
3747
3748 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3749 {
3750 oldval = *(WORD *)(userWindowBytes + index);
3751 *(WORD *)(userWindowBytes + index) = value;
3752 //Note: NT4, SP6 does not set the last error to 0
3753 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3754 SetLastError(ERROR_SUCCESS);
3755 return oldval;
3756 }
3757 switch(index)
3758 {
3759 case GWW_HINSTANCE:
3760 oldval = hInstance;
3761 hInstance = value;
3762 break;
3763
3764 case GWW_HWNDPARENT:
3765 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3766 break;
3767
3768 case GWW_ID:
3769 oldval = getWindowId();
3770 setWindowId(value);
3771 break;
3772
3773 default:
3774 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3775 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3776 return 0;
3777 }
3778 //Note: NT4, SP6 does not set the last error to 0
3779 SetLastError(ERROR_SUCCESS);
3780 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3781 return oldval;
3782}
3783//******************************************************************************
3784//******************************************************************************
3785WORD Win32BaseWindow::GetWindowWord(int index)
3786{
3787 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3788 {
3789 //Note: NT4, SP6 does not set the last error to 0
3790 SetLastError(ERROR_SUCCESS);
3791 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3792 return *(WORD *)(userWindowBytes + index);
3793 }
3794 switch(index)
3795 {
3796 case GWW_ID:
3797 if(HIWORD(getWindowId()))
3798 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3799 return (WORD)getWindowId();
3800
3801 case GWW_HWNDPARENT:
3802 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3803 return (WORD) GetParent();
3804
3805 case GWW_HINSTANCE:
3806 if (HIWORD(hInstance))
3807 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3808 return (WORD)hInstance;
3809 }
3810
3811 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3812 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3813 return 0;
3814}
3815//******************************************************************************
3816//******************************************************************************
3817void Win32BaseWindow::setWindowId(DWORD id)
3818{
3819 dwIDMenu = id;
3820}
3821//******************************************************************************
3822//Locates window in linked list and increases reference count (if found)
3823//Window object must be unreferenced after usage
3824//******************************************************************************
3825Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3826{
3827 Win32BaseWindow *window;
3828
3829////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
3830//// while browsing
3831//// Not thread safe now!
3832//// lock(&critsect);
3833 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3834 if(window) {
3835//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
3836 window->addRef();
3837 }
3838//// unlock(&critsect);
3839 return window;
3840 }
3841//// unlock(&critsect);
3842// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3843 return NULL;
3844}
3845//******************************************************************************
3846//Locates window in linked list and increases reference count (if found)
3847//Window object must be unreferenced after usage
3848//******************************************************************************
3849Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
3850{
3851 DWORD magic;
3852 HWND hwnd;
3853
3854 if(hwndOS2 == OSLIB_HWND_DESKTOP)
3855 {
3856 windowDesktop->addRef();
3857 return windowDesktop;
3858 }
3859
3860 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
3861 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
3862
3863 if(hwnd && CheckMagicDword(magic)) {
3864 return GetWindowFromHandle(hwnd);
3865 }
3866// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
3867 return 0;
3868}
3869//******************************************************************************
3870//Locates window in linked list and increases reference count (if found)
3871//Window object must be unreferenced after usage
3872//******************************************************************************
3873Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3874{
3875 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3876}
3877//******************************************************************************
3878//******************************************************************************
3879HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3880{
3881 HWND hwndOS2;
3882
3883 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3884
3885 if(window) {
3886 hwndOS2 = window->getOS2WindowHandle();
3887 RELEASE_WNDOBJ(window);
3888 return hwndOS2;
3889 }
3890// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3891 return hwnd;
3892}
3893//******************************************************************************
3894//******************************************************************************
3895HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
3896{
3897 HWND hwndOS2;
3898
3899 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3900
3901 if(window) {
3902 hwndOS2 = window->getOS2FrameWindowHandle();
3903 RELEASE_WNDOBJ(window);
3904 return hwndOS2;
3905 }
3906// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3907 return hwnd;
3908}
3909//******************************************************************************
3910//******************************************************************************
3911HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3912{
3913 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3914 HWND hwndWin32;
3915
3916 if(window) {
3917 hwndWin32 = window->getWindowHandle();
3918 RELEASE_WNDOBJ(window);
3919 return hwndWin32;
3920 }
3921 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
3922 if(window) {
3923 hwndWin32 = window->getWindowHandle();
3924 RELEASE_WNDOBJ(window);
3925 return hwndWin32;
3926 }
3927
3928// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3929 return 0;
3930// else return hwnd; //OS/2 window handle
3931}
3932#ifdef DEBUG
3933LONG Win32BaseWindow::addRef()
3934{
3935 dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
3936 return GenericObject::addRef();
3937}
3938//******************************************************************************
3939//******************************************************************************
3940LONG Win32BaseWindow::release(char *function, int line)
3941{
3942 dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
3943 return GenericObject::release();
3944}
3945#endif
3946//******************************************************************************
3947//******************************************************************************
3948GenericObject *Win32BaseWindow::windows = NULL;
3949CRITICAL_SECTION Win32BaseWindow::critsect = {0};
3950
3951//******************************************************************************
3952//******************************************************************************
3953#ifdef DEBUG
3954void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3955{
3956 char style[256] = "";
3957 char exstyle[256] = "";
3958
3959 /* Window styles */
3960 if(dwStyle & WS_CHILD)
3961 strcat(style, "WS_CHILD ");
3962 if(dwStyle & WS_POPUP)
3963 strcat(style, "WS_POPUP ");
3964 if(dwStyle & WS_VISIBLE)
3965 strcat(style, "WS_VISIBLE ");
3966 if(dwStyle & WS_DISABLED)
3967 strcat(style, "WS_DISABLED ");
3968 if(dwStyle & WS_CLIPSIBLINGS)
3969 strcat(style, "WS_CLIPSIBLINGS ");
3970 if(dwStyle & WS_CLIPCHILDREN)
3971 strcat(style, "WS_CLIPCHILDREN ");
3972 if(dwStyle & WS_MAXIMIZE)
3973 strcat(style, "WS_MAXIMIZE ");
3974 if(dwStyle & WS_MINIMIZE)
3975 strcat(style, "WS_MINIMIZE ");
3976 if(dwStyle & WS_GROUP)
3977 strcat(style, "WS_GROUP ");
3978 if(dwStyle & WS_TABSTOP)
3979 strcat(style, "WS_TABSTOP ");
3980
3981 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3982 strcat(style, "WS_CAPTION ");
3983 if(dwStyle & WS_DLGFRAME)
3984 strcat(style, "WS_DLGFRAME ");
3985 if(dwStyle & WS_BORDER)
3986 strcat(style, "WS_BORDER ");
3987
3988 if(dwStyle & WS_VSCROLL)
3989 strcat(style, "WS_VSCROLL ");
3990 if(dwStyle & WS_HSCROLL)
3991 strcat(style, "WS_HSCROLL ");
3992 if(dwStyle & WS_SYSMENU)
3993 strcat(style, "WS_SYSMENU ");
3994 if(dwStyle & WS_THICKFRAME)
3995 strcat(style, "WS_THICKFRAME ");
3996 if(dwStyle & WS_MINIMIZEBOX)
3997 strcat(style, "WS_MINIMIZEBOX ");
3998 if(dwStyle & WS_MAXIMIZEBOX)
3999 strcat(style, "WS_MAXIMIZEBOX ");
4000
4001 if(dwExStyle & WS_EX_DLGMODALFRAME)
4002 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4003 if(dwExStyle & WS_EX_ACCEPTFILES)
4004 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4005 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4006 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4007 if(dwExStyle & WS_EX_TOPMOST)
4008 strcat(exstyle, "WS_EX_TOPMOST ");
4009 if(dwExStyle & WS_EX_TRANSPARENT)
4010 strcat(exstyle, "WS_EX_TRANSPARENT ");
4011
4012 if(dwExStyle & WS_EX_MDICHILD)
4013 strcat(exstyle, "WS_EX_MDICHILD ");
4014 if(dwExStyle & WS_EX_TOOLWINDOW)
4015 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4016 if(dwExStyle & WS_EX_WINDOWEDGE)
4017 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4018 if(dwExStyle & WS_EX_CLIENTEDGE)
4019 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4020 if(dwExStyle & WS_EX_CONTEXTHELP)
4021 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4022 if(dwExStyle & WS_EX_RIGHT)
4023 strcat(exstyle, "WS_EX_RIGHT ");
4024 if(dwExStyle & WS_EX_LEFT)
4025 strcat(exstyle, "WS_EX_LEFT ");
4026 if(dwExStyle & WS_EX_RTLREADING)
4027 strcat(exstyle, "WS_EX_RTLREADING ");
4028 if(dwExStyle & WS_EX_LTRREADING)
4029 strcat(exstyle, "WS_EX_LTRREADING ");
4030 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4031 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4032 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4033 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4034 if(dwExStyle & WS_EX_CONTROLPARENT)
4035 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4036 if(dwExStyle & WS_EX_STATICEDGE)
4037 strcat(exstyle, "WS_EX_STATICEDGE ");
4038 if(dwExStyle & WS_EX_APPWINDOW)
4039 strcat(exstyle, "WS_EX_APPWINDOW ");
4040
4041 dprintf(("Window style: %x %s", dwStyle, style));
4042 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4043}
4044#endif
4045//******************************************************************************
4046//******************************************************************************
Note: See TracBrowser for help on using the repository browser.