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

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

EndDialog fix

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