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

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

added visible region callback function

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