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

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

enforce WS_EX_WINDOWEDGE

File size: 141.0 KB
Line 
1/* $Id: win32wbase.cpp,v 1.308 2001-12-30 16:51:37 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 return (rc);
2680}
2681//******************************************************************************
2682//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2683//******************************************************************************
2684BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2685{
2686 rectWindow.left += dx;
2687 rectWindow.right += dx;
2688 rectWindow.top += dy;
2689 rectWindow.bottom += dy;
2690 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2691 return TRUE;
2692}
2693//******************************************************************************
2694//******************************************************************************
2695void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2696{
2697 HRGN hrgn, hrgnClient;
2698 RECT rect;
2699
2700 MsgFormatFrame(NULL);
2701
2702 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2703 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2704 {
2705 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2706 wpos->cx = RECT_WIDTH(rectWindow);
2707 wpos->cy = RECT_HEIGHT(rectWindow);
2708 }
2709
2710 if(rectClient.left != oldClientRect->left ||
2711 rectClient.top != oldClientRect->top)
2712 {
2713 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2714 wpos->x = rectWindow.left;
2715 wpos->y = rectWindow.top;
2716 }
2717
2718 WINDOWPOS wpOld = *wpos;
2719 if(!(wpos->flags & SWP_NOSENDCHANGING))
2720 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2721
2722 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2723 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2724 {
2725 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2726 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2727 }
2728 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2729
2730 //Calculate invalid areas
2731 rect = rectWindow;
2732 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2733 hrgn = CreateRectRgnIndirect(&rect);
2734 if (!hrgn) {
2735 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2736 return;
2737 }
2738 rect = rectClient;
2739 hrgnClient = CreateRectRgnIndirect(&rect);
2740 if (!hrgn) {
2741 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2742 return;
2743 }
2744 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2745 DeleteObject(hrgnClient);
2746
2747 if(!EqualRect(oldClientRect, &rectClient)) {
2748 UnionRect(oldClientRect, oldClientRect, &rectClient);
2749 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2750 if (!hrgn) {
2751 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2752 return;
2753 }
2754 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2755 DeleteObject(hrgnClient);
2756 }
2757 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2758 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2759 DeleteObject(hrgn);
2760}
2761//******************************************************************************
2762//TODO: Check how this api really works in NT
2763//******************************************************************************
2764BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2765{
2766 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2767 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2768 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2769 windowpos.ptMinPosition = wndpl->ptMinPosition;
2770 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2771 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2772
2773 if(getStyle() & WS_MINIMIZE )
2774 {
2775 //TODO: Why can't this be (0,0)?
2776 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2777 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2778 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2779 }
2780 }
2781 else
2782 if(getStyle() & WS_MAXIMIZE )
2783 {
2784 //TODO: Why can't this be (0,0)?
2785 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2786 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2787 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2788 }
2789 else {
2790 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2791 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2792 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2793 SWP_NOZORDER | SWP_NOACTIVATE );
2794 }
2795 ShowWindow(wndpl->showCmd);
2796 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2797 {
2798 /* SDK: ...valid only the next time... */
2799 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2800 setFlags(getFlags() | WIN_RESTORE_MAX);
2801 }
2802 return TRUE;
2803}
2804//******************************************************************************
2805//******************************************************************************
2806BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2807{
2808 wndpl->length = sizeof(*wndpl);
2809 if(getStyle() & WS_MINIMIZE )
2810 wndpl->showCmd = SW_SHOWMINIMIZED;
2811 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2812
2813 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2814 if(getFlags() & WIN_RESTORE_MAX )
2815 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2816 else wndpl->flags = 0;
2817
2818 wndpl->ptMinPosition = windowpos.ptMinPosition;
2819 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2820 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2821 wndpl->rcNormalPosition = rectWindow;
2822
2823 return TRUE;
2824}
2825//******************************************************************************
2826//Also destroys all the child windows (destroy children first, parent last)
2827//******************************************************************************
2828BOOL Win32BaseWindow::DestroyWindow()
2829{
2830 HWND hwnd = getWindowHandle();
2831
2832 dprintf(("DestroyWindow %x", hwnd));
2833
2834 /* Call hooks */
2835 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2836 {
2837 return FALSE;
2838 }
2839
2840 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2841 {
2842 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2843 /* FIXME: clean up palette - see "Internals" p.352 */
2844 }
2845
2846 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2847 {
2848 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2849 {
2850 /* Notify the parent window only */
2851 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2852 if(!::IsWindow(hwnd) )
2853 {
2854 return TRUE;
2855 }
2856 }
2857//// else DebugInt3();
2858 }
2859 /* Hide the window */
2860 if(IsWindowVisible(getWindowHandle()))
2861 {
2862 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2863 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2864 if(!::IsWindow(hwnd))
2865 {
2866 return TRUE;
2867 }
2868 }
2869 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2870
2871 // check the handle for the last active popup window
2872 Win32BaseWindow* owner = getOwner();
2873 if (NULL != owner)
2874 {
2875 if (owner->getLastActive() == hwnd)
2876 owner->setLastActive( owner->getWindowHandle() );
2877 }
2878
2879 fDestroyWindowCalled = TRUE;
2880 return OSLibWinDestroyWindow(OS2HwndFrame);
2881}
2882//******************************************************************************
2883//******************************************************************************
2884Win32BaseWindow *Win32BaseWindow::getParent()
2885{
2886 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2887 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2888}
2889//******************************************************************************
2890//Note: does not set last error if no parent (verified in NT4, SP6)
2891//******************************************************************************
2892HWND Win32BaseWindow::GetParent()
2893{
2894 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2895
2896 if(getStyle() & WS_CHILD) {
2897 if(wndparent) {
2898 return wndparent->getWindowHandle();
2899 }
2900 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2901 DebugInt3();
2902 return 0;
2903 }
2904 else
2905 if(getStyle() & WS_POPUP)
2906 return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2907 else return 0;
2908}
2909//******************************************************************************
2910//******************************************************************************
2911HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2912{
2913 HWND oldhwnd;
2914 Win32BaseWindow *newparent;
2915 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2916 BOOL fShow = FALSE;
2917
2918 if(oldparent) {
2919 oldhwnd = oldparent->getWindowHandle();
2920 oldparent->removeChild(this);
2921 }
2922 else oldhwnd = 0;
2923
2924 /* Windows hides the window first, then shows it again
2925 * including the WM_SHOWWINDOW messages and all */
2926 if(IsWindowCreated() && (getStyle() & WS_VISIBLE)) {
2927 ShowWindow(SW_HIDE);
2928 fShow = TRUE;
2929 }
2930 if(oldparent) {
2931 //release parent here (increased refcount during creation)
2932 RELEASE_WNDOBJ(oldparent);
2933 }
2934 newparent = GetWindowFromHandle(hwndNewParent);
2935 if(newparent && !newparent->isDesktopWindow())
2936 {
2937 setParent(newparent);
2938 getParent()->addChild(this);
2939 fParentChange = TRUE;
2940
2941 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2942 if(!(getStyle() & WS_CHILD))
2943 {
2944 //TODO: Send WM_STYLECHANGED msg?
2945 setStyle(getStyle() | WS_CHILD);
2946 if(getWindowId())
2947 {
2948 DestroyMenu( (HMENU) getWindowId() );
2949 setWindowId(0);
2950 }
2951 }
2952 //SvL: Even though the win32 coordinates might not change, the PM
2953 // coordinates can. We must make sure the control stays at the
2954 // same position (y) relative to the (new) parent.
2955 SetWindowPos(HWND_TOPMOST, rectWindow.left, rectWindow.top, 0, 0,
2956 SWP_NOACTIVATE|SWP_NOSIZE);
2957 fParentChange = FALSE;
2958 }
2959 else {
2960 if(newparent) RELEASE_WNDOBJ(newparent);
2961
2962 setParent(windowDesktop);
2963 windowDesktop->addRef();
2964 windowDesktop->addChild(this);
2965 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2966
2967 //TODO: Send WM_STYLECHANGED msg?
2968 setStyle(getStyle() & ~WS_CHILD);
2969 setWindowId(0);
2970 }
2971 /* SetParent additionally needs to make hwndChild the topmost window
2972 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2973 WM_WINDOWPOSCHANGED notification messages.
2974 */
2975 if(state >= STATE_PRE_WMNCCREATE) {
2976 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2977 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2978
2979 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2980 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2981 }
2982 return oldhwnd;
2983}
2984//******************************************************************************
2985//******************************************************************************
2986BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2987{
2988 // PH: Optimizer won't unroll calls to getParent() even
2989 // in release build.
2990 Win32BaseWindow *_parent = getParent();
2991
2992 if(_parent)
2993 {
2994 if(_parent->getWindowHandle() == hwndParent)
2995 return TRUE;
2996
2997 return _parent->IsChild(hwndParent);
2998 }
2999 else
3000 return 0;
3001}
3002//******************************************************************************
3003//******************************************************************************
3004HWND Win32BaseWindow::GetTopWindow()
3005{
3006 HWND hwndTop;
3007 Win32BaseWindow *topwindow;
3008
3009 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3010 if(!isDesktopWindow())
3011 {
3012 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3013 //Note: GetTopWindow can't return a window that hasn't processed
3014 // WM_NCCREATE yet (verified in NT4, SP6)
3015 if(topwindow) {
3016 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3017 hwndTop = topwindow->getWindowHandle();
3018 }
3019 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3020 RELEASE_WNDOBJ(topwindow);
3021 return hwndTop;
3022 }
3023 if(topwindow) RELEASE_WNDOBJ(topwindow);
3024 return 0;
3025 }
3026 while(hwndTop) {
3027 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
3028 //Note: GetTopWindow can't return a window that hasn't processed
3029 // WM_NCCREATE yet (verified in NT4, SP6)
3030 if(topwindow) {
3031 if(topwindow->state >= STATE_POST_WMNCCREATE) {
3032 hwndTop = topwindow->getWindowHandle();
3033 }
3034 else hwndTop = topwindow->GetWindow(GW_HWNDNEXT);
3035 RELEASE_WNDOBJ(topwindow);
3036 return hwndTop;
3037 }
3038 if(topwindow) RELEASE_WNDOBJ(topwindow);
3039 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
3040 }
3041
3042 return 0;
3043}
3044//******************************************************************************
3045// Get the top-level parent for a child window.
3046//******************************************************************************
3047HWND Win32BaseWindow::GetTopParent()
3048{
3049 Win32BaseWindow *window = this;
3050 HWND hwndTopParent = 0;
3051
3052 lock();
3053 while(window && (window->getStyle() & WS_CHILD))
3054 {
3055 window = window->getParent();
3056 }
3057 if(window) {
3058 hwndTopParent = window->getWindowHandle();
3059 }
3060 unlock();
3061 return hwndTopParent;
3062}
3063//******************************************************************************
3064//TODO: Should not enumerate children that are created during the enumeration!
3065//******************************************************************************
3066BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
3067{
3068 BOOL rc = TRUE;
3069 HWND hwnd;
3070 Win32BaseWindow *prevchild = 0, *child = 0;
3071
3072 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
3073 lock();
3074 for (child = (Win32BaseWindow *)getFirstChild(); child != NULL; child = (Win32BaseWindow *)child->getNextChild())
3075 {
3076 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
3077 hwnd = child->getWindowHandle();
3078 if(child->IsWindowDestroyed() || child->getOwner()) {
3079 continue; //shouldn't have an owner (Wine)
3080 }
3081 child->addRef();
3082 unlock();
3083 if(lpfn(hwnd, lParam) == FALSE)
3084 {
3085 child->release();
3086 return FALSE;
3087 }
3088 child->release();
3089 lock();
3090 //check if the window still exists
3091 if(!::IsWindow(hwnd))
3092 {
3093 child = prevchild;
3094 if(child == NULL) break;
3095 continue;
3096 }
3097 if(child->getFirstChild() != NULL)
3098 {
3099 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
3100 child->addRef();
3101 unlock();
3102 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
3103 {
3104 child->release();
3105 return FALSE;
3106 }
3107 child->release();
3108 lock();
3109 }
3110 prevchild = child;
3111 }
3112 unlock();
3113 return rc;
3114}
3115//******************************************************************************
3116//Enumerate first-level children only and check thread id
3117//******************************************************************************
3118BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
3119{
3120 Win32BaseWindow *child = 0;
3121 ULONG tid, pid;
3122 BOOL rc;
3123 HWND hwnd;
3124
3125 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
3126
3127 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3128 {
3129 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
3130
3131 if(dwThreadId == tid) {
3132 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
3133 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3134 break;
3135 }
3136 }
3137 }
3138 return TRUE;
3139}
3140//******************************************************************************
3141//Enumerate first-level children only
3142//******************************************************************************
3143BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
3144{
3145 Win32BaseWindow *child = 0;
3146 BOOL rc;
3147 HWND hwnd;
3148
3149 dprintf(("EnumWindows %x %x", lpfn, lParam));
3150
3151 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3152 {
3153 hwnd = child->getWindowHandle();
3154
3155 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
3156 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
3157 break;
3158 }
3159 }
3160 return TRUE;
3161}
3162//******************************************************************************
3163//******************************************************************************
3164HWND Win32BaseWindow::FindWindowById(int id)
3165{
3166 HWND hwnd;
3167
3168 lock();
3169 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3170 {
3171 if (child->getWindowId() == id)
3172 {
3173 hwnd = child->getWindowHandle();
3174 unlock();
3175 return hwnd;
3176 }
3177 }
3178 unlock();
3179 return 0;
3180}
3181//******************************************************************************
3182//TODO:
3183//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3184//the current process owns them.
3185//******************************************************************************
3186HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3187{
3188 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3189 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3190 Win32BaseWindow *firstchild = child;
3191
3192 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3193 if((hwndParent != 0 && !parent) ||
3194 (hwndChildAfter != 0 && !child) ||
3195 (hwndParent == 0 && hwndChildAfter != 0))
3196 {
3197 if(parent) RELEASE_WNDOBJ(parent);
3198 if(firstchild) RELEASE_WNDOBJ(firstchild);
3199 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3200 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3201 return 0;
3202 }
3203 SetLastError(0);
3204 if(hwndParent != 0)
3205 {//if the current process owns the window, just do a quick search
3206 lock(&critsect);
3207 child = (Win32BaseWindow *)parent->getFirstChild();
3208 if(hwndChildAfter != 0)
3209 {
3210 while(child)
3211 {
3212 if(child->getWindowHandle() == hwndChildAfter)
3213 {
3214 child = (Win32BaseWindow *)child->getNextChild();
3215 break;
3216 }
3217 child = (Win32BaseWindow *)child->getNextChild();
3218 }
3219 }
3220 while(child)
3221 {
3222 //According to Wine, the class doesn't need to be specified
3223 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3224 (!lpszWindow || child->hasWindowName(lpszWindow)))
3225 {
3226 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3227 HWND hwndChild = child->getWindowHandle();
3228 unlock(&critsect);
3229 if(parent) RELEASE_WNDOBJ(parent);
3230 if(firstchild) RELEASE_WNDOBJ(firstchild);
3231 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3232 return hwndChild;
3233 }
3234 child = (Win32BaseWindow *)child->getNextChild();
3235 }
3236 unlock(&critsect);
3237 if(parent) RELEASE_WNDOBJ(parent);
3238 if(firstchild) RELEASE_WNDOBJ(firstchild);
3239 }
3240 else {
3241 Win32BaseWindow *wnd;
3242 HWND henum, hwnd;
3243
3244 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3245 hwnd = OSLibWinGetNextWindow(henum);
3246
3247 while(hwnd)
3248 {
3249 wnd = GetWindowFromOS2FrameHandle(hwnd);
3250 if(wnd == NULL) {
3251 hwnd = OSLibWinQueryClientWindow(hwnd);
3252 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3253 }
3254
3255 if(wnd) {
3256 //According to Wine, the class doesn't need to be specified
3257 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3258 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3259 {
3260 OSLibWinEndEnumWindows(henum);
3261 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3262 HWND hwndret = wnd->getWindowHandle();
3263 RELEASE_WNDOBJ(wnd);
3264 return hwndret;
3265 }
3266 RELEASE_WNDOBJ(wnd);
3267 }
3268 hwnd = OSLibWinGetNextWindow(henum);
3269 }
3270 OSLibWinEndEnumWindows(henum);
3271 if(parent) RELEASE_WNDOBJ(parent);
3272 if(firstchild) RELEASE_WNDOBJ(firstchild);
3273 }
3274 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3275 return 0;
3276}
3277//******************************************************************************
3278//******************************************************************************
3279HWND Win32BaseWindow::GetWindow(UINT uCmd)
3280{
3281 HWND hwndRelated = 0;
3282 Win32BaseWindow *window;
3283
3284 switch(uCmd)
3285 {
3286 case GW_HWNDFIRST:
3287 window = (Win32BaseWindow *)getParent();
3288 if(window)
3289 {
3290 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3291 window = GetWindowFromOS2FrameHandle(hwndRelated);
3292 if(window) {
3293 hwndRelated = window->getWindowHandle();
3294 RELEASE_WNDOBJ(window);
3295 }
3296 else hwndRelated = 0;
3297 }
3298 else {
3299 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3300 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3301 }
3302 break;
3303
3304 case GW_HWNDLAST:
3305 window = (Win32BaseWindow *)getParent();
3306 if(window) {
3307 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3308 dprintf(("os2 handle %x", hwndRelated));
3309 window = GetWindowFromOS2FrameHandle(hwndRelated);
3310 if(window) {
3311 hwndRelated = window->getWindowHandle();
3312 RELEASE_WNDOBJ(window);
3313 }
3314 else hwndRelated = 0;
3315 }
3316 else {
3317 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3318 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3319 }
3320 break;
3321
3322 case GW_HWNDNEXT:
3323 if(getParent()) {
3324 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3325 window = GetWindowFromOS2FrameHandle(hwndRelated);
3326 if(window) {
3327 hwndRelated = window->getWindowHandle();
3328 RELEASE_WNDOBJ(window);
3329 }
3330 else hwndRelated = 0;
3331 }
3332 else {
3333 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3334 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3335 }
3336 break;
3337
3338 case GW_HWNDPREV:
3339 if(getParent()) {
3340 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3341 window = GetWindowFromOS2FrameHandle(hwndRelated);
3342 if(window) {
3343 hwndRelated = window->getWindowHandle();
3344 RELEASE_WNDOBJ(window);
3345 }
3346 else hwndRelated = 0;
3347 }
3348 else {
3349 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3350 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3351 }
3352 break;
3353
3354 case GW_OWNER:
3355 {
3356 Win32BaseWindow *owner = getOwner();
3357 if(owner) {
3358 hwndRelated = owner->getWindowHandle();
3359 }
3360 break;
3361 }
3362
3363 case GW_CHILD:
3364 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3365 window = GetWindowFromOS2FrameHandle(hwndRelated);
3366
3367 //Before a window has processed WM_NCCREATE:
3368 //- GetWindow(parent, GW_CHILD) can't return that window handle
3369 //(verified in NT4, SP6)
3370 if(window) {
3371 if(window->state >= STATE_POST_WMNCCREATE) {
3372 hwndRelated = window->getWindowHandle();
3373 RELEASE_WNDOBJ(window);
3374 }
3375 else {
3376 hwndRelated = window->GetWindow(GW_HWNDNEXT);
3377 RELEASE_WNDOBJ(window);
3378 }
3379 }
3380 else hwndRelated = 0;
3381
3382 break;
3383
3384 //for internal use only
3385 case GW_HWNDNEXTCHILD:
3386 lock();
3387 window = (Win32BaseWindow *)getNextChild();
3388 if(window) {
3389 hwndRelated = window->getWindowHandle();
3390 }
3391 else hwndRelated = 0;
3392 unlock();
3393 break;
3394
3395 case GW_HWNDPREVCHILD:
3396 DebugInt3();
3397 break;
3398
3399 case GW_HWNDFIRSTCHILD:
3400 lock();
3401 window = (Win32BaseWindow *)getFirstChild();
3402 if(window) {
3403 hwndRelated = window->getWindowHandle();
3404 }
3405 else hwndRelated = 0;
3406 unlock();
3407 break;
3408
3409 case GW_HWNDLASTCHILD:
3410 lock();
3411 window = (Win32BaseWindow *)getFirstChild();
3412 if(window) {
3413 while (window->getNextChild())
3414 {
3415 window = (Win32BaseWindow *)window->getNextChild();
3416 }
3417 hwndRelated = window->getWindowHandle();
3418 }
3419 else hwndRelated = 0;
3420 unlock();
3421 break;
3422 }
3423end:
3424 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3425 return hwndRelated;
3426}
3427//******************************************************************************
3428//******************************************************************************
3429HWND Win32BaseWindow::SetActiveWindow()
3430{
3431 HWND hwndActive;
3432
3433 dprintf(("SetActiveWindow %x", getWindowHandle()));
3434 if(getStyle() & WS_CHILD) {
3435// if(getStyle() & (WS_DISABLED | WS_CHILD)) {
3436 dprintf(("WARNING: Window is a child or disabled"));
3437 return 0;
3438 }
3439
3440 if(GetActiveWindow() == getWindowHandle()) {
3441 dprintf(("Window already active"));
3442 return getWindowHandle();
3443 }
3444 if (HOOK_IsHooked( WH_CBT ))
3445 {
3446 CBTACTIVATESTRUCT cbta;
3447 LRESULT ret;
3448
3449 cbta.fMouse = FALSE;
3450 cbta.hWndActive = GetActiveWindow();
3451 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3452 if(ret)
3453 {
3454 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3455 return cbta.hWndActive;
3456 }
3457 }
3458 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3459
3460// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3461// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3462// }
3463 hwndActive = GetActiveWindow();
3464 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3465}
3466//******************************************************************************
3467//Used to change active status of an mdi window
3468//******************************************************************************
3469BOOL Win32BaseWindow::DeactivateChildWindow()
3470{
3471 /* child windows get a WM_CHILDACTIVATE message */
3472 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3473 {
3474 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3475 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3476 return TRUE;
3477 }
3478 DebugInt3(); //should not be called for non-child window
3479 return FALSE;
3480}
3481//******************************************************************************
3482//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3483//******************************************************************************
3484BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3485{
3486 BOOL rc;
3487
3488 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3489 //return true if previous state was disabled, else false (sdk docs)
3490 rc = (getStyle() & WS_DISABLED) != 0;
3491 if(rc && !fEnable) {
3492 SendMessageA(WM_CANCELMODE, 0, 0);
3493 }
3494 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3495 if(fEnable == FALSE) {
3496 //SvL: No need to clear focus as PM already does this
3497 if(getWindowHandle() == GetCapture()) {
3498 ReleaseCapture(); /* A disabled window can't capture the mouse */
3499 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3500 }
3501 }
3502 return rc;
3503}
3504//******************************************************************************
3505//******************************************************************************
3506BOOL Win32BaseWindow::CloseWindow()
3507{
3508 return OSLibWinMinimizeWindow(OS2Hwnd);
3509}
3510//******************************************************************************
3511//TODO: Not be 100% correct; should return active window of current thread
3512// or NULL when there is none -> WinQueryActiveWindow just returns
3513// the current active window
3514//******************************************************************************
3515HWND Win32BaseWindow::GetActiveWindow()
3516{
3517 HWND hwndActive;
3518
3519 hwndActive = OSLibWinQueryActiveWindow();
3520 return OS2ToWin32Handle(hwndActive);
3521}
3522//******************************************************************************
3523//******************************************************************************
3524BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3525{
3526 INT len = GetWindowTextLength(fUnicode);
3527 BOOL res;
3528
3529 if (wndname == NULL)
3530 return (len == 0);
3531
3532 len++;
3533 if (fUnicode)
3534 {
3535 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3536
3537 GetWindowTextW(text,len);
3538 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3539 free(text);
3540 }
3541 else
3542 {
3543 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3544
3545 GetWindowTextA(text,len);
3546 res = (strcmp(text,wndname) == 0);
3547 free(text);
3548 }
3549
3550 return res;
3551}
3552//******************************************************************************
3553//******************************************************************************
3554CHAR *Win32BaseWindow::getWindowNamePtrA()
3555{
3556 INT len = GetWindowTextLength(FALSE);
3557 CHAR *text;
3558
3559 if (len == 0) return NULL;
3560 len++;
3561 text = (CHAR*)malloc(len*sizeof(CHAR));
3562 GetWindowTextA(text,len);
3563
3564 return text;
3565}
3566//******************************************************************************
3567//******************************************************************************
3568WCHAR *Win32BaseWindow::getWindowNamePtrW()
3569{
3570 INT len = GetWindowTextLength(TRUE);
3571 WCHAR *text;
3572
3573 if (len == 0) return NULL;
3574 len++;
3575 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3576 GetWindowTextW(text,len);
3577
3578 return text;
3579}
3580//******************************************************************************
3581//******************************************************************************
3582VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3583{
3584 if (namePtr) free(namePtr);
3585}
3586//******************************************************************************
3587//When using this API for a window that was created by a different process, NT
3588//does NOT send WM_GETTEXTLENGTH.
3589//******************************************************************************
3590int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3591{
3592 //if the destination window is created by this process, send message
3593 if(dwProcessId == currentProcessId) {
3594 if(fUnicode) {
3595 return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
3596 }
3597 else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3598 }
3599 //else get data directory from window structure
3600 //TODO: must lock window structure.... (TODO)
3601 return windowNameLength;
3602}
3603//******************************************************************************
3604//When using this API for a window that was created by a different process, NT
3605//does NOT send WM_GETTEXT.
3606//******************************************************************************
3607int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3608{
3609 //if the destination window is created by this process, send message
3610 if(dwProcessId == currentProcessId) {
3611 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3612 }
3613
3614 //else get data directory from window structure
3615 if (!lpsz || !cch) return 0;
3616 if (!windowNameA) lpsz[0] = 0;
3617 else memcpy(lpsz, windowNameA, min(windowNameLength + 1, cch) );
3618 return min(windowNameLength, cch);
3619}
3620//******************************************************************************
3621//When using this API for a window that was created by a different process, NT
3622//does NOT send WM_GETTEXT.
3623//******************************************************************************
3624int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3625{
3626 //if the destination window is created by this process, send message
3627 if(dwProcessId == currentProcessId) {
3628 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3629 }
3630 //else get data directory from window structure
3631 if (!lpsz || !cch)
3632 return 0;
3633 if (!windowNameW)
3634 lpsz[0] = 0;
3635 else
3636 memcpy(lpsz, windowNameW, min( sizeof(WCHAR) * (windowNameLength+1), cch));
3637
3638 return min(windowNameLength, cch);
3639}
3640//******************************************************************************
3641//TODO: How does this work when the target window belongs to a different process???
3642//******************************************************************************
3643BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3644{
3645 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3646}
3647//******************************************************************************
3648//******************************************************************************
3649BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3650{
3651 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3652}
3653//******************************************************************************
3654//******************************************************************************
3655LONG Win32BaseWindow::SetWindowLong(int index, ULONG value, BOOL fUnicode)
3656{
3657 LONG oldval;
3658
3659 switch(index) {
3660 case GWL_EXSTYLE:
3661 {
3662 STYLESTRUCT ss;
3663
3664 if(dwExStyle == value) {
3665 oldval = value;
3666 break;
3667 }
3668 ss.styleOld = dwExStyle;
3669 ss.styleNew = value;
3670 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3671 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3672 setExStyle(ss.styleNew);
3673 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3674 oldval = ss.styleOld;
3675 break;
3676 }
3677 case GWL_STYLE:
3678 {
3679 STYLESTRUCT ss;
3680
3681 //SvL: TODO: Can you change minimize or maximize status here too?
3682
3683 if(dwStyle == value) {
3684 oldval = value;
3685 break;
3686 }
3687 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x (%x)", getWindowHandle(), dwStyle, value));
3688#ifdef DEBUG
3689// if((value & WS_CHILD) != (dwStyle & WS_CHILD)) {
3690// DebugInt3(); //is this allowed?
3691// }
3692#endif
3693 value &= ~(WS_CHILD);
3694 ss.styleOld = getStyle();
3695 ss.styleNew = value | (ss.styleOld & WS_CHILD);
3696 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3697 setStyle(ss.styleNew);
3698 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3699 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
3700
3701 //TODO: Might not be correct to use ShowWindow here
3702 if((ss.styleOld & WS_VISIBLE) != (ss.styleNew & WS_VISIBLE)) {
3703 if(ss.styleNew & WS_VISIBLE)
3704 ShowWindow(SW_SHOWNOACTIVATE);
3705 else ShowWindow(SW_HIDE);
3706 }
3707#ifdef DEBUG
3708 PrintWindowStyle(ss.styleNew, 0);
3709#endif
3710 oldval = ss.styleOld;
3711 break;
3712 }
3713 case GWL_WNDPROC:
3714 {
3715 //Note: Type of SetWindowLong determines new window proc type
3716 // UNLESS the new window proc has already been registered
3717 // (use the old type in that case)
3718 // (VERIFIED in NT 4, SP6)
3719 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3720 if(type == WIN_PROC_INVALID) {
3721 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3722 }
3723 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3724 dprintf(("SetWindowLong%c GWL_WNDPROC %x old %x new wndproc %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), oldval, value));
3725 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3726 break;
3727 }
3728 case GWL_HINSTANCE:
3729 oldval = hInstance;
3730 hInstance = value;
3731 break;
3732
3733 case GWL_HWNDPARENT:
3734 oldval = SetParent((HWND)value);
3735 break;
3736
3737 case GWL_ID:
3738 dprintf(("GWL_ID old %x, new %x", getWindowId(), value));
3739 oldval = getWindowId();
3740 setWindowId(value);
3741 break;
3742
3743 case GWL_USERDATA:
3744 oldval = userData;
3745 userData = value;
3746 break;
3747
3748 default:
3749 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3750 {
3751 oldval = *(ULONG *)(userWindowBytes + index);
3752 *(ULONG *)(userWindowBytes + index) = value;
3753 break;
3754 }
3755 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3756 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3757 return 0;
3758 }
3759 //Note: NT4, SP6 does not set the last error to 0
3760 SetLastError(ERROR_SUCCESS);
3761 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3762 return oldval;
3763}
3764//******************************************************************************
3765//******************************************************************************
3766ULONG Win32BaseWindow::GetWindowLong(int index, BOOL fUnicode)
3767{
3768 ULONG value;
3769
3770 switch(index) {
3771 case GWL_EXSTYLE:
3772 value = dwExStyle;
3773 break;
3774 case GWL_STYLE:
3775 value = dwStyle;
3776 break;
3777 case GWL_WNDPROC:
3778 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3779 break;
3780 case GWL_HINSTANCE:
3781 value = hInstance;
3782 break;
3783 case GWL_HWNDPARENT:
3784 value = GetParent();
3785 break;
3786 case GWL_ID:
3787 value = getWindowId();
3788 break;
3789 case GWL_USERDATA:
3790 value = userData;
3791 break;
3792 default:
3793 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3794 {
3795 value = *(ULONG *)(userWindowBytes + index);
3796 break;
3797 }
3798 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3799 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3800 return 0;
3801 }
3802 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3803 //Note: NT4, SP6 does not set the last error to 0
3804 SetLastError(ERROR_SUCCESS);
3805 return value;
3806}
3807//******************************************************************************
3808//******************************************************************************
3809WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3810{
3811 WORD oldval;
3812
3813 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3814 {
3815 oldval = *(WORD *)(userWindowBytes + index);
3816 *(WORD *)(userWindowBytes + index) = value;
3817 //Note: NT4, SP6 does not set the last error to 0
3818 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3819 SetLastError(ERROR_SUCCESS);
3820 return oldval;
3821 }
3822 switch(index)
3823 {
3824 case GWW_HINSTANCE:
3825 oldval = hInstance;
3826 hInstance = value;
3827 break;
3828
3829 case GWW_HWNDPARENT:
3830 oldval = SetParent((HWND)(WNDHANDLE_MAGIC_HIGHWORD | value));
3831 break;
3832
3833 case GWW_ID:
3834 oldval = getWindowId();
3835 setWindowId(value);
3836 break;
3837
3838 default:
3839 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3840 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3841 return 0;
3842 }
3843 //Note: NT4, SP6 does not set the last error to 0
3844 SetLastError(ERROR_SUCCESS);
3845 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3846 return oldval;
3847}
3848//******************************************************************************
3849//******************************************************************************
3850WORD Win32BaseWindow::GetWindowWord(int index)
3851{
3852 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3853 {
3854 //Note: NT4, SP6 does not set the last error to 0
3855 SetLastError(ERROR_SUCCESS);
3856 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3857 return *(WORD *)(userWindowBytes + index);
3858 }
3859 switch(index)
3860 {
3861 case GWW_ID:
3862 if(HIWORD(getWindowId()))
3863 dprintf(("WARNING: GWW_ID: discards high bits of 0x%08x!\n", getWindowId()));
3864 return (WORD)getWindowId();
3865
3866 case GWW_HWNDPARENT:
3867 dprintf(("WARNING: GWW_HWNDPARENT: discards high bits of 0x%08x!\n", GetParent()));
3868 return (WORD) GetParent();
3869
3870 case GWW_HINSTANCE:
3871 if (HIWORD(hInstance))
3872 dprintf(("WARNING: GWW_HINSTANCE: discards high bits of 0x%08x!\n", hInstance));
3873 return (WORD)hInstance;
3874 }
3875
3876 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3877 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3878 return 0;
3879}
3880//******************************************************************************
3881//Locates window in linked list and increases reference count (if found)
3882//Window object must be unreferenced after usage
3883//******************************************************************************
3884Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3885{
3886 Win32BaseWindow *window;
3887
3888////TODO: temporary workaround for crashes in Opera (pmwinx; releasesemaphore)
3889//// while browsing
3890//// Not thread safe now!
3891//// lock(&critsect);
3892 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3893 if(window) {
3894//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
3895 window->addRef();
3896 }
3897//// unlock(&critsect);
3898 return window;
3899 }
3900//// unlock(&critsect);
3901// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3902 return NULL;
3903}
3904//******************************************************************************
3905//Locates window in linked list and increases reference count (if found)
3906//Window object must be unreferenced after usage
3907//******************************************************************************
3908Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
3909{
3910 DWORD magic;
3911 HWND hwnd;
3912
3913 if(hwndOS2 == OSLIB_HWND_DESKTOP)
3914 {
3915 windowDesktop->addRef();
3916 return windowDesktop;
3917 }
3918
3919 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
3920 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
3921
3922 if(hwnd && CheckMagicDword(magic)) {
3923 return GetWindowFromHandle(hwnd);
3924 }
3925// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
3926 return 0;
3927}
3928//******************************************************************************
3929//Locates window in linked list and increases reference count (if found)
3930//Window object must be unreferenced after usage
3931//******************************************************************************
3932Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3933{
3934 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3935}
3936//******************************************************************************
3937//******************************************************************************
3938HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3939{
3940 HWND hwndOS2;
3941
3942 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3943
3944 if(window) {
3945 hwndOS2 = window->getOS2WindowHandle();
3946 RELEASE_WNDOBJ(window);
3947 return hwndOS2;
3948 }
3949// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3950 return hwnd;
3951}
3952//******************************************************************************
3953//******************************************************************************
3954HWND WIN32API Win32ToOS2FrameHandle(HWND hwnd)
3955{
3956 HWND hwndOS2;
3957
3958 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3959
3960 if(window) {
3961 hwndOS2 = window->getOS2FrameWindowHandle();
3962 RELEASE_WNDOBJ(window);
3963 return hwndOS2;
3964 }
3965// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3966 return hwnd;
3967}
3968//******************************************************************************
3969//******************************************************************************
3970HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3971{
3972 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3973 HWND hwndWin32;
3974
3975 if(window) {
3976 hwndWin32 = window->getWindowHandle();
3977 RELEASE_WNDOBJ(window);
3978 return hwndWin32;
3979 }
3980 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
3981 if(window) {
3982 hwndWin32 = window->getWindowHandle();
3983 RELEASE_WNDOBJ(window);
3984 return hwndWin32;
3985 }
3986
3987// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3988 return 0;
3989// else return hwnd; //OS/2 window handle
3990}
3991#ifdef DEBUG
3992LONG Win32BaseWindow::addRef()
3993{
3994// dprintf2(("addRef %x %d", getWindowHandle(), getRefCount()+1));
3995 return GenericObject::addRef();
3996}
3997//******************************************************************************
3998//******************************************************************************
3999LONG Win32BaseWindow::release(char *function, int line)
4000{
4001// dprintf2(("release %s %d %x %d", function, line, getWindowHandle(), getRefCount()-1));
4002 return GenericObject::release();
4003}
4004#endif
4005//******************************************************************************
4006//******************************************************************************
4007GenericObject *Win32BaseWindow::windows = NULL;
4008CRITICAL_SECTION Win32BaseWindow::critsect = {0};
4009
4010//******************************************************************************
4011//******************************************************************************
4012#ifdef DEBUG
4013void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
4014{
4015 char style[256] = "";
4016 char exstyle[256] = "";
4017
4018 /* Window styles */
4019 if(dwStyle & WS_CHILD)
4020 strcat(style, "WS_CHILD ");
4021 if(dwStyle & WS_POPUP)
4022 strcat(style, "WS_POPUP ");
4023 if(dwStyle & WS_VISIBLE)
4024 strcat(style, "WS_VISIBLE ");
4025 if(dwStyle & WS_DISABLED)
4026 strcat(style, "WS_DISABLED ");
4027 if(dwStyle & WS_CLIPSIBLINGS)
4028 strcat(style, "WS_CLIPSIBLINGS ");
4029 if(dwStyle & WS_CLIPCHILDREN)
4030 strcat(style, "WS_CLIPCHILDREN ");
4031 if(dwStyle & WS_MAXIMIZE)
4032 strcat(style, "WS_MAXIMIZE ");
4033 if(dwStyle & WS_MINIMIZE)
4034 strcat(style, "WS_MINIMIZE ");
4035 if(dwStyle & WS_GROUP)
4036 strcat(style, "WS_GROUP ");
4037 if(dwStyle & WS_TABSTOP)
4038 strcat(style, "WS_TABSTOP ");
4039
4040 if((dwStyle & WS_CAPTION) == WS_CAPTION)
4041 strcat(style, "WS_CAPTION ");
4042 if(dwStyle & WS_DLGFRAME)
4043 strcat(style, "WS_DLGFRAME ");
4044 if(dwStyle & WS_BORDER)
4045 strcat(style, "WS_BORDER ");
4046
4047 if(dwStyle & WS_VSCROLL)
4048 strcat(style, "WS_VSCROLL ");
4049 if(dwStyle & WS_HSCROLL)
4050 strcat(style, "WS_HSCROLL ");
4051 if(dwStyle & WS_SYSMENU)
4052 strcat(style, "WS_SYSMENU ");
4053 if(dwStyle & WS_THICKFRAME)
4054 strcat(style, "WS_THICKFRAME ");
4055 if(dwStyle & WS_MINIMIZEBOX)
4056 strcat(style, "WS_MINIMIZEBOX ");
4057 if(dwStyle & WS_MAXIMIZEBOX)
4058 strcat(style, "WS_MAXIMIZEBOX ");
4059
4060 if(dwExStyle & WS_EX_DLGMODALFRAME)
4061 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
4062 if(dwExStyle & WS_EX_ACCEPTFILES)
4063 strcat(exstyle, "WS_EX_ACCEPTFILES ");
4064 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
4065 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
4066 if(dwExStyle & WS_EX_TOPMOST)
4067 strcat(exstyle, "WS_EX_TOPMOST ");
4068 if(dwExStyle & WS_EX_TRANSPARENT)
4069 strcat(exstyle, "WS_EX_TRANSPARENT ");
4070
4071 if(dwExStyle & WS_EX_MDICHILD)
4072 strcat(exstyle, "WS_EX_MDICHILD ");
4073 if(dwExStyle & WS_EX_TOOLWINDOW)
4074 strcat(exstyle, "WS_EX_TOOLWINDOW ");
4075 if(dwExStyle & WS_EX_WINDOWEDGE)
4076 strcat(exstyle, "WS_EX_WINDOWEDGE ");
4077 if(dwExStyle & WS_EX_CLIENTEDGE)
4078 strcat(exstyle, "WS_EX_CLIENTEDGE ");
4079 if(dwExStyle & WS_EX_CONTEXTHELP)
4080 strcat(exstyle, "WS_EX_CONTEXTHELP ");
4081 if(dwExStyle & WS_EX_RIGHT)
4082 strcat(exstyle, "WS_EX_RIGHT ");
4083 if(dwExStyle & WS_EX_LEFT)
4084 strcat(exstyle, "WS_EX_LEFT ");
4085 if(dwExStyle & WS_EX_RTLREADING)
4086 strcat(exstyle, "WS_EX_RTLREADING ");
4087 if(dwExStyle & WS_EX_LTRREADING)
4088 strcat(exstyle, "WS_EX_LTRREADING ");
4089 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
4090 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
4091 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
4092 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
4093 if(dwExStyle & WS_EX_CONTROLPARENT)
4094 strcat(exstyle, "WS_EX_CONTROLPARENT ");
4095 if(dwExStyle & WS_EX_STATICEDGE)
4096 strcat(exstyle, "WS_EX_STATICEDGE ");
4097 if(dwExStyle & WS_EX_APPWINDOW)
4098 strcat(exstyle, "WS_EX_APPWINDOW ");
4099
4100 dprintf(("Window style: %x %s", dwStyle, style));
4101 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
4102}
4103#endif
4104//******************************************************************************
4105//******************************************************************************
Note: See TracBrowser for help on using the repository browser.