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

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

fixed restoring of minimized or maximized window

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