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

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

wm_erasebkgnd handling changes for dialogs

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