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

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

temporary workaround added for opera crash

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