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

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

minor update

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