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

Last change on this file since 7338 was 7338, checked in by phaller, 24 years ago

optimized set/get window text, heap pressure reduced

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