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

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

SetFocus fix

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