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

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

OS/2 looks changes + fixes

File size: 134.0 KB
Line 
1/* $Id: win32wbase.cpp,v 1.266 2001-06-13 10:29:46 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
1346 if( ctlType == CTLCOLOR_SCROLLBAR)
1347 {
1348 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
1349 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
1350 SetTextColor( hdc, GetSysColor(COLOR_3DFACE));
1351 SetBkColor( hdc, bk);
1352
1353 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
1354 * we better use 0x55aa bitmap brush to make scrollbar's background
1355 * look different from the window background.
1356 */
1357 if (bk == GetSysColor(COLOR_WINDOW)) {
1358 return GetPattern55AABrush();
1359 }
1360
1361 UnrealizeObject( hb );
1362 return (LRESULT)hb;
1363 }
1364
1365 SetTextColor( hdc, GetSysColor(COLOR_WINDOWTEXT));
1366
1367 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
1368 {
1369 SetBkColor( hdc, GetSysColor(COLOR_WINDOW) );
1370 }
1371 else
1372 {
1373 SetBkColor( hdc, GetSysColor(COLOR_3DFACE) );
1374 return (LRESULT)GetSysColorBrush(COLOR_3DFACE);
1375 }
1376 return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
1377}
1378//******************************************************************************
1379//******************************************************************************
1380LRESULT Win32BaseWindow::DefWndPrint(HDC hdc,ULONG uFlags)
1381{
1382 /*
1383 * Visibility flag.
1384 */
1385 if ( (uFlags & PRF_CHECKVISIBLE) &&
1386 !IsWindowVisible(getWindowHandle()) )
1387 return 0;
1388
1389 /*
1390 * Unimplemented flags.
1391 */
1392 if ( (uFlags & PRF_CHILDREN) ||
1393 (uFlags & PRF_OWNED) ||
1394 (uFlags & PRF_NONCLIENT) )
1395 {
1396 dprintf(("WM_PRINT message with unsupported flags\n"));
1397 }
1398
1399 /*
1400 * Background
1401 */
1402 if ( uFlags & PRF_ERASEBKGND)
1403 SendInternalMessageA(WM_ERASEBKGND, (WPARAM)hdc, 0);
1404
1405 /*
1406 * Client area
1407 */
1408 if ( uFlags & PRF_CLIENT)
1409 SendInternalMessageA(WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
1410
1411
1412 return 0;
1413}
1414//******************************************************************************
1415//******************************************************************************
1416LRESULT Win32BaseWindow::DefWindowProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
1417{
1418 switch(Msg)
1419 {
1420 case WM_CLOSE:
1421 dprintf(("DefWindowProcA: WM_CLOSE %x", getWindowHandle()));
1422 DestroyWindow();
1423 return 0;
1424
1425 case WM_GETTEXTLENGTH:
1426 if(windowNameA) {
1427 return strlen(windowNameA);
1428 }
1429 else {
1430 return 0;
1431 }
1432
1433 case WM_GETTEXT:
1434 if (!lParam || !wParam) return 0;
1435 if (!windowNameA) ((LPSTR)lParam)[0] = 0;
1436 else lstrcpynA((LPSTR)lParam, windowNameA, wParam);
1437 return min((windowNameA ? strlen(windowNameA) : 0), wParam);
1438
1439 case WM_SETTEXT:
1440 {
1441 LPCSTR lpsz = (LPCSTR)lParam;
1442
1443 if(windowNameA) free(windowNameA);
1444 if(windowNameW) free(windowNameW);
1445 if (lParam)
1446 {
1447 int wndNameLength = strlen(lpsz);
1448 windowNameA = (LPSTR)_smalloc(wndNameLength+1);
1449 strcpy(windowNameA, lpsz);
1450 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1451 lstrcpyAtoW(windowNameW, windowNameA);
1452 }
1453 else
1454 {
1455 windowNameA = NULL;
1456 windowNameW = NULL;
1457 }
1458 dprintf(("WM_SETTEXT of %x to %s\n", Win32Hwnd, lParam));
1459 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1460 {
1461 HandleNCPaint((HRGN)1);
1462 if(hTaskList) {
1463 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1464 if(fOS2Look) {
1465 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1466 }
1467 }
1468 }
1469
1470 return TRUE;
1471 }
1472
1473 case WM_SETREDRAW:
1474 {
1475 if (wParam)
1476 {
1477 setStyle(getStyle() | WS_VISIBLE);
1478 dprintf(("Enable window update for %x", getWindowHandle()));
1479 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, TRUE);
1480 }
1481 else
1482 {
1483 if (getStyle() & WS_VISIBLE)
1484 {
1485 setStyle(getStyle() & ~WS_VISIBLE);
1486 dprintf(("Disable window update for %x", getWindowHandle()));
1487 OSLibWinEnableWindowUpdate(OS2HwndFrame, OS2Hwnd, FALSE);
1488 }
1489 }
1490 return 0;
1491 }
1492
1493 case WM_CTLCOLORMSGBOX:
1494 case WM_CTLCOLOREDIT:
1495 case WM_CTLCOLORLISTBOX:
1496 case WM_CTLCOLORBTN:
1497 case WM_CTLCOLORDLG:
1498 case WM_CTLCOLORSTATIC:
1499 case WM_CTLCOLORSCROLLBAR:
1500 return DefWndControlColor(Msg - WM_CTLCOLORMSGBOX, (HDC)wParam);
1501
1502 case WM_CTLCOLOR:
1503 return DefWndControlColor(HIWORD(lParam), (HDC)wParam);
1504
1505 case WM_VKEYTOITEM:
1506 case WM_CHARTOITEM:
1507 return -1;
1508
1509 case WM_PARENTNOTIFY:
1510 return 0;
1511
1512 case WM_MOUSEACTIVATE:
1513 {
1514 dprintf(("DefWndProc: WM_MOUSEACTIVATE for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1515 if(getStyle() & WS_CHILD && !(getExStyle() & WS_EX_NOPARENTNOTIFY) )
1516 {
1517 if(getParent()) {
1518 LRESULT rc = getParent()->SendInternalMessageA(WM_MOUSEACTIVATE, wParam, lParam );
1519 if(rc) return rc;
1520 }
1521 }
1522 return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE;
1523 }
1524
1525 case WM_ACTIVATE:
1526 /* The default action in Windows is to set the keyboard focus to
1527 * the window, if it's being activated and not minimized */
1528 if (LOWORD(wParam) != WA_INACTIVE) {
1529 if(!(getStyle() & WS_MINIMIZE))
1530 SetFocus(getWindowHandle());
1531 }
1532 return 0;
1533
1534 case WM_SETCURSOR:
1535 {
1536 dprintf(("DefWndProc: WM_SETCURSOR for %x Msg %s", Win32Hwnd, GetMsgText(HIWORD(lParam))));
1537 if((getStyle() & WS_CHILD))
1538 {
1539 if(getParent()) {
1540 LRESULT rc = getParent()->SendInternalMessageA(WM_SETCURSOR, wParam, lParam);
1541 if(rc) return rc;
1542 }
1543 }
1544 if (wParam == getWindowHandle())
1545 {
1546 HCURSOR hCursor;
1547
1548 switch(LOWORD(lParam))
1549 {
1550 case HTCLIENT:
1551 hCursor = windowClass ? windowClass->getCursor():LoadCursorA(0,IDC_ARROWA);
1552 break;
1553
1554 case HTLEFT:
1555 case HTRIGHT:
1556 hCursor = LoadCursorA(0,IDC_SIZEWEA);
1557 break;
1558
1559 case HTTOP:
1560 case HTBOTTOM:
1561 hCursor = LoadCursorA(0,IDC_SIZENSA);
1562 break;
1563
1564 case HTTOPLEFT:
1565 case HTBOTTOMRIGHT:
1566 hCursor = LoadCursorA(0,IDC_SIZENWSEA);
1567 break;
1568
1569 case HTTOPRIGHT:
1570 case HTBOTTOMLEFT:
1571 hCursor = LoadCursorA(0,IDC_SIZENESWA);
1572 break;
1573
1574 default:
1575 hCursor = LoadCursorA(0,IDC_ARROWA);
1576 break;
1577 }
1578
1579 if (hCursor)
1580 {
1581 SetCursor(hCursor);
1582 return 1;
1583 }
1584 else return 0;
1585 }
1586 else return 0;
1587 }
1588
1589 case WM_MOUSEMOVE:
1590 return 0;
1591
1592 case WM_WINDOWPOSCHANGED:
1593 {
1594 PWINDOWPOS wpos = (PWINDOWPOS)lParam;
1595 WPARAM wp = SIZE_RESTORED;
1596
1597 if (!(wpos->flags & SWP_NOMOVE) && !(wpos->flags & SWP_NOCLIENTMOVE))
1598 {
1599 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left,rectClient.top));
1600 }
1601 if (!(wpos->flags & SWP_NOSIZE) && !(wpos->flags & SWP_NOCLIENTSIZE))
1602 {
1603 if (dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
1604 else
1605 if (dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
1606
1607 SendInternalMessageA(WM_SIZE, wp, MAKELONG(rectClient.right - rectClient.left,
1608 rectClient.bottom - rectClient.top));
1609 }
1610 return 0;
1611 }
1612 case WM_WINDOWPOSCHANGING:
1613 return HandleWindowPosChanging((WINDOWPOS *)lParam);
1614
1615 case WM_ERASEBKGND:
1616 case WM_ICONERASEBKGND:
1617 {
1618 RECT rect;
1619 int rc;
1620
1621 if(getWindowHandle() == 0x68000044) {
1622 rc = GetClipBox( (HDC)wParam, &rect );
1623 FillRect( (HDC)wParam, &rect, GetSysColorBrush(COLOR_WINDOWTEXT));
1624 return 1;
1625 }
1626
1627 if (!windowClass || !windowClass->getBackgroundBrush()) return 0;
1628
1629 rc = GetClipBox( (HDC)wParam, &rect );
1630 if ((rc == SIMPLEREGION) || (rc == COMPLEXREGION))
1631 {
1632 HBRUSH hBrush = windowClass->getBackgroundBrush();
1633
1634 if (hBrush <= (HBRUSH)(SYSCOLOR_GetLastColor()+1))
1635 hBrush = GetSysColorBrush(hBrush-1);
1636
1637 FillRect( (HDC)wParam, &rect, hBrush);
1638 }
1639 return 1;
1640 }
1641
1642 case WM_PRINT:
1643 return DefWndPrint(wParam,lParam);
1644
1645 case WM_PAINTICON:
1646 case WM_PAINT:
1647 {
1648 PAINTSTRUCT ps;
1649 HDC hdc = BeginPaint(getWindowHandle(), &ps );
1650 if( hdc )
1651 {
1652 if( (getStyle() & WS_MINIMIZE) && (getWindowClass()->getIcon() || hIcon))
1653 {
1654 int x = (rectWindow.right - rectWindow.left - GetSystemMetrics(SM_CXICON))/2;
1655 int y = (rectWindow.bottom - rectWindow.top - GetSystemMetrics(SM_CYICON))/2;
1656 dprintf(("Painting class icon: vis rect=(%i,%i - %i,%i)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ));
1657 DrawIcon(hdc, x, y, hIcon ? hIcon:getWindowClass()->getIcon() );
1658 }
1659 EndPaint(getWindowHandle(), &ps );
1660 }
1661 return 0;
1662 }
1663
1664 case WM_GETDLGCODE:
1665 return 0;
1666
1667 case WM_NCPAINT:
1668 return HandleNCPaint((HRGN)wParam);
1669
1670 case WM_NCACTIVATE:
1671 return HandleNCActivate(wParam);
1672
1673 case WM_NCCREATE:
1674 return(TRUE);
1675
1676 case WM_NCDESTROY:
1677 return 0;
1678
1679 case WM_NCCALCSIZE:
1680 return HandleNCCalcSize((BOOL)wParam,(RECT*)lParam);
1681
1682 case WM_NCLBUTTONDOWN:
1683 return HandleNCLButtonDown(wParam,lParam);
1684
1685 case WM_LBUTTONDBLCLK:
1686 case WM_NCLBUTTONDBLCLK:
1687 return HandleNCLButtonDblClk(wParam,lParam);
1688
1689 case WM_NCRBUTTONDOWN:
1690 case WM_NCRBUTTONDBLCLK:
1691 case WM_NCMBUTTONDOWN:
1692 case WM_NCMBUTTONDBLCLK:
1693 if (lastHitTestVal == HTERROR) MessageBeep(MB_ICONEXCLAMATION);
1694 return 0;
1695
1696 case WM_NCRBUTTONUP:
1697 return HandleNCRButtonUp(wParam,lParam);
1698
1699 case WM_NCMBUTTONUP:
1700 return 0;
1701
1702 case WM_NCHITTEST:
1703 {
1704 POINT point;
1705 LRESULT retvalue;
1706
1707 point.x = (SHORT)LOWORD(lParam);
1708 point.y = (SHORT)HIWORD(lParam);
1709
1710 retvalue = HandleNCHitTest(point);
1711#if 0 //CB: let the Corel people fix the bugs first
1712 if(retvalue == HTMENU)
1713 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,TRUE);
1714 else
1715 MENU_TrackMouseMenuBar_MouseMove(Win32Hwnd,point,FALSE);
1716#endif
1717 return retvalue;
1718 }
1719
1720 case WM_SYSCOMMAND:
1721 {
1722 POINT point;
1723
1724 point.x = LOWORD(lParam);
1725 point.y = HIWORD(lParam);
1726 return HandleSysCommand(wParam,&point);
1727 }
1728
1729 case WM_SYSKEYDOWN:
1730 if(wParam == VK_F4) /* try to close the window */
1731 {
1732 Win32BaseWindow *window = GetWindowFromHandle(GetTopParent());
1733 if(window && !(window->getClass()->getStyle() & CS_NOCLOSE))
1734 PostMessageA(window->getWindowHandle(), WM_SYSCOMMAND, SC_CLOSE, 0);
1735 if(window) RELEASE_WNDOBJ(window);
1736 return 0;
1737 }
1738
1739 Win32BaseWindow *siblingWindow;
1740 HWND sibling;
1741 char nameBuffer [40], mnemonic;
1742 int nameLength;
1743
1744 GetWindowTextA (nameBuffer, 40);
1745
1746 // search all sibling to see it this key is their mnemonic
1747 sibling = GetWindow (GW_HWNDFIRST);
1748 while (sibling != 0) {
1749 siblingWindow = GetWindowFromHandle (sibling);
1750 nameLength = siblingWindow->GetWindowTextA (nameBuffer, 40);
1751
1752 // find the siblings mnemonic
1753 mnemonic = '\0';
1754 for (int i=0 ; i<nameLength ; i++) {
1755 if (IsDBCSLeadByte(nameBuffer[i])) {
1756 // Skip DBCS
1757 continue;
1758 }
1759 if (nameBuffer [i] == '&') {
1760 mnemonic = nameBuffer [i+1];
1761 if ((mnemonic >= 'a') && (mnemonic <= 'z'))
1762 mnemonic -= 32; // make it uppercase
1763 break; // stop searching
1764 }
1765 }
1766
1767 // key matches siblings mnemonic, send mouseclick
1768 if (mnemonic == (char) wParam) {
1769 siblingWindow->SendInternalMessageA (BM_CLICK, 0, 0);
1770 }
1771 sibling = siblingWindow->GetNextWindow (GW_HWNDNEXT);
1772 RELEASE_WNDOBJ(siblingWindow);
1773 }
1774
1775 return 0;
1776
1777#if 0 //CB: todo: MSDN docu: Windown handles these messages and not WM_SYSCHAR (the code below doesn't work)
1778 case WM_KEYDOWN:
1779 case WM_KEYUP:
1780 case WM_SYSKEYDOWN:
1781 case WM_SYSKEYUP:
1782#endif
1783
1784 case WM_SYSCHAR:
1785 {
1786 int iMenuSysKey = 0;
1787 if (wParam == VK_RETURN && (getStyle() & WS_MINIMIZE))
1788 {
1789 PostMessageA(getWindowHandle(), WM_SYSCOMMAND,
1790 (WPARAM)SC_RESTORE, 0L );
1791 break;
1792 }
1793 if((HIWORD(lParam) & KEYDATA_ALT) && wParam)
1794 {
1795 if (wParam == VK_TAB || wParam == VK_ESCAPE || wParam == VK_F4)
1796 break;
1797 if (wParam == VK_SPACE && (getStyle() & WS_CHILD)) {
1798 getParent()->SendMessageA(Msg, wParam, lParam );
1799 }
1800 else SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam );
1801 }
1802#if 0
1803 else /* check for Ctrl-Esc */
1804 if (wParam != VK_ESCAPE) MessageBeep(0);
1805 break;
1806#endif
1807 }
1808
1809 case WM_SETHOTKEY:
1810 hotkey = wParam;
1811 return 1; //CB: always successful
1812
1813 case WM_GETHOTKEY:
1814 return hotkey;
1815
1816 case WM_CONTEXTMENU:
1817 if ((dwStyle & WS_CHILD) && getParent())
1818 getParent()->SendInternalMessageA(WM_CONTEXTMENU,wParam,lParam);
1819 return 0;
1820
1821 case WM_SHOWWINDOW:
1822 if (!lParam) return 0; /* sent from ShowWindow */
1823 if (!(dwStyle & WS_POPUP) || !owner) return 0;
1824 if ((dwStyle & WS_VISIBLE) && wParam) return 0;
1825 else if (!(dwStyle & WS_VISIBLE) && !wParam) return 0;
1826 ShowWindow(wParam ? SW_SHOW:SW_HIDE);
1827 return 0;
1828
1829 case WM_CANCELMODE:
1830 if (getParent() == windowDesktop) EndMenu();
1831 if (GetCapture() == Win32Hwnd) ReleaseCapture();
1832 return 0;
1833
1834 case WM_DROPOBJECT:
1835 return DRAG_FILE;
1836
1837 case WM_QUERYDROPOBJECT:
1838 return (dwExStyle & WS_EX_ACCEPTFILES) ? 1:0;
1839
1840 case WM_QUERYDRAGICON:
1841 {
1842 HICON hDragIcon = windowClass->getCursor();
1843 UINT len;
1844
1845 if(hDragIcon) return (LRESULT)hDragIcon;
1846 for(len = 1; len < 64; len++)
1847 {
1848 hDragIcon = LoadIconA(hInstance,MAKEINTRESOURCEA(len));
1849 if(hDragIcon)
1850 return (LRESULT)hDragIcon;
1851 }
1852 return (LRESULT)LoadIconA(0,IDI_APPLICATIONA);
1853 }
1854
1855 case WM_QUERYOPEN:
1856 case WM_QUERYENDSESSION:
1857 return 1;
1858
1859 case WM_NOTIFYFORMAT:
1860 return IsWindowUnicode() ? NFR_UNICODE:NFR_ANSI;
1861
1862 case WM_SETICON:
1863 case WM_GETICON:
1864 {
1865 LRESULT result = 0;
1866
1867 /* Set the appropriate icon members in the window structure. */
1868 if (wParam == ICON_SMALL)
1869 {
1870 result = hIconSm;
1871 if (Msg == WM_SETICON)
1872 hIconSm = (HICON)lParam;
1873 }
1874 else
1875 {
1876 result = hIcon;
1877 if (Msg == WM_SETICON)
1878 {
1879 hIcon = (HICON)lParam;
1880 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1881 OSLibWinSetIcon(OS2Hwnd,hIcon);
1882 }
1883 }
1884 if ((Msg == WM_SETICON) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
1885 HandleNCPaint((HRGN)1);
1886
1887 return result;
1888 }
1889
1890 case WM_HELP:
1891 if (getParent()) getParent()->SendInternalMessageA(Msg,wParam,lParam);
1892 break;
1893
1894 case WM_NOTIFY:
1895 return 0; //comctl32 controls expect this
1896
1897 default:
1898 return 0;
1899 }
1900 return 0;
1901}
1902//******************************************************************************
1903//******************************************************************************
1904LRESULT Win32BaseWindow::DefWindowProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
1905{
1906 switch(Msg)
1907 {
1908 case WM_GETTEXTLENGTH:
1909 if(windowNameW) {
1910 return lstrlenW(windowNameW);
1911 }
1912 else return 0;
1913
1914 case WM_GETTEXT:
1915 if (!lParam || !wParam) return 0;
1916 if (!windowNameW) ((LPWSTR)lParam)[0] = 0;
1917 else lstrcpynW((LPWSTR)lParam,windowNameW,wParam);
1918 return min((windowNameW ? lstrlenW(windowNameW) : 0),wParam);
1919
1920 case WM_SETTEXT:
1921 {
1922 LPWSTR lpsz = (LPWSTR)lParam;
1923
1924 if(windowNameA) free(windowNameA);
1925 if(windowNameW) free(windowNameW);
1926 if (lParam)
1927 {
1928 // Wide
1929 int wndNameLength = lstrlenW(lpsz);
1930 windowNameW = (LPWSTR)_smalloc((wndNameLength+1)*sizeof(WCHAR));
1931 lstrcpyW(windowNameW,lpsz);
1932 // Ascii
1933 LPSTR tmp = HEAP_strdupWtoA(GetProcessHeap(), 0, lpsz);
1934 if(tmp) {
1935 long tmpLength = strlen( tmp );
1936 windowNameA = (LPSTR)_smalloc(tmpLength+1);
1937 strcpy(windowNameA,tmp);
1938 windowNameA[tmpLength] = 0; // need ?
1939 HEAP_free(tmp);
1940 }
1941 else {
1942 windowNameA = (LPSTR)_smalloc(1);
1943 windowNameA[0] = 0;
1944 }
1945 }
1946 else
1947 {
1948 windowNameA = NULL;
1949 windowNameW = NULL;
1950 }
1951 dprintf(("WM_SETTEXT of %x\n",Win32Hwnd));
1952 if ((dwStyle & WS_CAPTION) == WS_CAPTION)
1953 {
1954 HandleNCPaint((HRGN)1);
1955 if(hTaskList) {
1956 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
1957 if(fOS2Look) {
1958 OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
1959 }
1960 }
1961 }
1962
1963 return TRUE;
1964 }
1965
1966 default:
1967 return DefWindowProcA(Msg, wParam, lParam);
1968 }
1969}
1970//******************************************************************************
1971//******************************************************************************
1972LRESULT Win32BaseWindow::SendMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1973{
1974 //if the destination window is created by this process & thread, call window proc directly
1975 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1976 return SendInternalMessageA(Msg, wParam, lParam);
1977 }
1978 //otherwise use WinSendMsg to send it to the right process/thread
1979 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
1980 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
1981}
1982//******************************************************************************
1983//******************************************************************************
1984LRESULT Win32BaseWindow::SendMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
1985{
1986 //if the destination window is created by this process & thread, call window proc directly
1987 if(dwProcessId == currentProcessId && dwThreadId == GetCurrentThreadId()) {
1988 return SendInternalMessageW(Msg, wParam, lParam);
1989 }
1990 //otherwise use WinSendMsg to send it to the right process/thread
1991 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, TRUE);
1992}
1993//******************************************************************************
1994//Called as a result of an OS/2 message or called from a class method
1995//******************************************************************************
1996LRESULT Win32BaseWindow::SendInternalMessageA(ULONG Msg, WPARAM wParam, LPARAM lParam)
1997{
1998 LRESULT rc;
1999 HWND hwnd = getWindowHandle();
2000 BOOL fInternalMsgBackup = fInternalMsg;
2001
2002 //if the destination window was created by this process & thread, call window proc directly
2003 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
2004 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2005 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2006 }
2007
2008 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, FALSE, TRUE);
2009
2010 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, FALSE);
2011
2012 fInternalMsg = TRUE;
2013 switch(Msg)
2014 {
2015 case WM_CREATE:
2016 {
2017 if(CallWindowProcA(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2018 dprintf(("WM_CREATE returned -1\n"));
2019 rc = -1; //don't create window
2020 break;
2021 }
2022 rc = 0;
2023 break;
2024 }
2025 case WM_LBUTTONDOWN:
2026 case WM_MBUTTONDOWN:
2027 case WM_RBUTTONDOWN:
2028 {
2029 if (getParent())
2030 {
2031 POINTS pt = MAKEPOINTS(lParam);
2032 POINT point;
2033
2034 point.x = pt.x;
2035 point.y = pt.y;
2036 MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
2037 NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
2038 }
2039 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2040 break;
2041 }
2042 case WM_NCHITTEST:
2043 rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
2044 break;
2045
2046 case WM_DESTROY:
2047 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2048 break;
2049
2050 default:
2051 rc = CallWindowProcA(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2052 break;
2053 }
2054 if(!::IsWindow(hwnd)) {
2055 //window might have been destroyed by now. (this pointer invalid)
2056 //we must return immediately
2057 //(MS Visual C++ install heap corruption)
2058 //TODO: could happen in several places here!!!!
2059 return rc;
2060 }
2061 fInternalMsg = fInternalMsgBackup;
2062 dprintf2(("SendMessageA %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
2063 return rc;
2064}
2065//******************************************************************************
2066//Called as a result of an OS/2 message or called from a class method
2067//******************************************************************************
2068LRESULT Win32BaseWindow::SendInternalMessageW(ULONG Msg, WPARAM wParam, LPARAM lParam)
2069{
2070 LRESULT rc;
2071 HWND hwnd = getWindowHandle();
2072 BOOL fInternalMsgBackup = fInternalMsg;
2073
2074 //if the destination window was created by this process & thread, call window proc directly
2075 if(dwProcessId != currentProcessId || dwThreadId != GetCurrentThreadId()) {
2076 dprintf(("SendMessages (inter-process) %x %x %x %x", getWindowHandle(), Msg, wParam, lParam));
2077 return OSLibSendMessage(getOS2WindowHandle(), Msg, wParam, lParam, FALSE);
2078 }
2079
2080 DebugPrintMessage(getWindowHandle(), Msg, wParam, lParam, TRUE, TRUE);
2081
2082 CallWindowHookProc(WH_CALLWNDPROC, Msg, wParam, lParam, TRUE);
2083
2084 fInternalMsg = TRUE;
2085 switch(Msg)
2086 {
2087 case WM_CREATE:
2088 {
2089 if(CallWindowProcW(win32wndproc, getWindowHandle(), WM_CREATE, 0, lParam) == -1) {
2090 dprintf(("WM_CREATE returned -1\n"));
2091 rc = -1; //don't create window
2092 break;
2093 }
2094 rc = 0;
2095 break;
2096 }
2097 case WM_LBUTTONDOWN:
2098 case WM_MBUTTONDOWN:
2099 case WM_RBUTTONDOWN:
2100 NotifyParent(Msg, wParam, lParam);
2101 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
2102 break;
2103
2104 case WM_NCHITTEST:
2105 rc = lastHitTestVal = win32wndproc(getWindowHandle(), WM_NCHITTEST, wParam, lParam);
2106 break;
2107
2108 case WM_DESTROY:
2109 rc = win32wndproc(getWindowHandle(), WM_DESTROY, 0, 0);
2110 break;
2111 default:
2112 rc = CallWindowProcW(win32wndproc, getWindowHandle(), Msg, wParam, lParam);
2113 break;
2114 }
2115 if(!::IsWindow(hwnd)) {
2116 //window might have been destroyed by now. (this pointer invalid)
2117 //we must return immediately
2118 //(MS Visual C++ install heap corruption)
2119 //TODO: could happen in several places here!!!!
2120 return rc;
2121 }
2122 fInternalMsg = fInternalMsgBackup;
2123 dprintf2(("SendMessageW %x %x %x %x returned %d", getWindowHandle(), Msg, wParam, lParam, rc));
2124 return rc;
2125}
2126//******************************************************************************
2127//******************************************************************************
2128void Win32BaseWindow::CallWindowHookProc(ULONG hooktype, ULONG Msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
2129{
2130 CWPSTRUCT cwp;
2131
2132 cwp.lParam = lParam;
2133 cwp.wParam = wParam;
2134 cwp.message = Msg;
2135 cwp.hwnd = getWindowHandle();
2136
2137 switch(hooktype) {
2138 case WH_CALLWNDPROC:
2139 if(fUnicode) {
2140 HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2141 }
2142 else HOOK_CallHooksA(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
2143 break;
2144 }
2145}
2146//******************************************************************************
2147//TODO: Do this more efficiently
2148//******************************************************************************
2149LRESULT Win32BaseWindow::BroadcastMessageA(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2150{
2151 Win32BaseWindow *window;
2152 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2153
2154 dprintf(("BroadCastMessageA %x %x %x", msg, wParam, lParam, GetFS()));
2155
2156 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2157 window = GetWindowFromHandle(hwnd++);
2158 if(window) {
2159 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2160 {
2161 if(type == BROADCAST_SEND) {
2162 ::SendMessageA(window->getWindowHandle(), msg, wParam, lParam);
2163 }
2164 else PostMessageA(window->getWindowHandle(), msg, wParam, lParam);
2165 }
2166 RELEASE_WNDOBJ(window);
2167 }
2168 }
2169 return 0;
2170}
2171//******************************************************************************
2172//TODO: Do this more efficiently
2173//******************************************************************************
2174LRESULT Win32BaseWindow::BroadcastMessageW(int type, UINT msg, WPARAM wParam, LPARAM lParam)
2175{
2176 Win32BaseWindow *window;
2177 HWND hwnd = WNDHANDLE_MAGIC_HIGHWORD;
2178
2179 dprintf(("BroadCastMessageW %x %x %x", msg, wParam, lParam));
2180
2181 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
2182 window = GetWindowFromHandle(hwnd++);
2183 if(window) {
2184 if ((window->getStyle() & WS_POPUP) || ((window->getStyle() & WS_CAPTION) == WS_CAPTION))
2185 {
2186 if(type == BROADCAST_SEND) {
2187 ::SendMessageW(window->getWindowHandle(), msg, wParam, lParam);
2188 }
2189 else PostMessageW(window->getWindowHandle(), msg, wParam, lParam);
2190 }
2191 RELEASE_WNDOBJ(window);
2192 }
2193 }
2194 return 0;
2195}
2196//******************************************************************************
2197//******************************************************************************
2198void Win32BaseWindow::NotifyParent(UINT Msg, WPARAM wParam, LPARAM lParam)
2199{
2200 Win32BaseWindow *window = this;
2201 Win32BaseWindow *parentwindow;
2202
2203 while(window)
2204 {
2205 if(window->getStyle() & WS_CHILD && !(window->getExStyle() & WS_EX_NOPARENTNOTIFY) )
2206 {
2207 /* Notify the parent window only */
2208 parentwindow = window->getParent();
2209 if(parentwindow) {
2210 parentwindow->SendInternalMessageA(WM_PARENTNOTIFY, MAKEWPARAM(Msg, getWindowId()), lParam );
2211 }
2212 }
2213 else break;
2214
2215 window = parentwindow;
2216 }
2217}
2218//******************************************************************************
2219// Returns the big or small icon for the window, falling back to the
2220// class as windows does.
2221//******************************************************************************
2222HICON Win32BaseWindow::IconForWindow(WPARAM fType)
2223{
2224 HICON hWndIcon;
2225
2226 if (fType == ICON_BIG)
2227 {
2228 if (hIcon)
2229 hWndIcon = hIcon;
2230 else
2231 if (windowClass && windowClass->getIcon())
2232 hWndIcon = windowClass->getIcon();
2233 else
2234 if (!(dwStyle & DS_MODALFRAME))
2235 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2236 else hWndIcon = 0;
2237 }
2238 else
2239 {
2240 if (hIconSm)
2241 hWndIcon = hIconSm;
2242 else
2243 if (hIcon)
2244 hWndIcon = hIcon;
2245 else
2246 if (windowClass && windowClass->getIconSm())
2247 hWndIcon = windowClass->getIconSm();
2248 else
2249 if (windowClass && windowClass->getIcon())
2250 hWndIcon = windowClass->getIcon();
2251 else
2252 if (!(dwStyle & DS_MODALFRAME))
2253 hWndIcon = LoadImageA(0,MAKEINTRESOURCEA(OIC_ODINICON),IMAGE_ICON,0,0,LR_DEFAULTCOLOR);
2254 else hWndIcon = 0;
2255 }
2256
2257 return hWndIcon;
2258}
2259//******************************************************************************
2260//******************************************************************************
2261BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
2262{
2263 ULONG swp = 0;
2264 HWND hWinAfter;
2265 BOOL rc,wasVisible,showFlag;
2266 RECT newPos = {0, 0, 0, 0};
2267
2268 dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
2269 wasVisible = (getStyle() & WS_VISIBLE) != 0;
2270
2271 switch(nCmdShow)
2272 {
2273 case SW_HIDE:
2274 if (!wasVisible) goto END;
2275
2276 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER;
2277 break;
2278
2279 case SW_SHOWMINNOACTIVE:
2280 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2281 /* fall through */
2282 case SW_SHOWMINIMIZED:
2283 swp |= SWP_SHOWWINDOW;
2284 /* fall through */
2285 case SW_MINIMIZE:
2286 swp |= SWP_FRAMECHANGED;
2287 if( !(getStyle() & WS_MINIMIZE) ) {
2288 swp |= MinMaximize(SW_MINIMIZE, &newPos );
2289 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2290 }
2291 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2292 break;
2293
2294 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
2295 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2296 if( !(getStyle() & WS_MAXIMIZE) ) {
2297 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
2298 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2299 }
2300 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2301 break;
2302
2303 case SW_SHOWNA:
2304 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2305 /* fall through */
2306 case SW_SHOW:
2307 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
2308
2309 /*
2310 * ShowWindow has a little peculiar behavior that if the
2311 * window is already the topmost window, it will not
2312 * activate it.
2313 */
2314 if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
2315 swp |= SWP_NOACTIVATE;
2316
2317 break;
2318
2319 case SW_SHOWNOACTIVATE:
2320 swp |= SWP_NOZORDER;
2321 if (GetActiveWindow())
2322 swp |= SWP_NOACTIVATE;
2323 /* fall through */
2324 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
2325 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
2326 case SW_RESTORE:
2327 //TODO: WIN_RESTORE_MAX flag!!!!!!!!!!!!!!
2328 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
2329
2330 if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) ) {
2331 swp |= MinMaximize(SW_RESTORE, &newPos );
2332 fMinMaxChange = TRUE; //-> invalidate entire window in WM_CALCINVALIDRECT
2333 }
2334 else swp |= SWP_NOSIZE | SWP_NOMOVE;
2335 break;
2336 }
2337
2338 showFlag = (nCmdShow != SW_HIDE);
2339 if (showFlag != wasVisible)
2340 {
2341 SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
2342 if (!::IsWindow( getWindowHandle() )) goto END;
2343 }
2344
2345 /* We can't activate a child window */
2346 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
2347 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
2348
2349 SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
2350
2351 if(!(swp & SWP_NOACTIVATE)) {
2352 OSLibWinSetActiveWindow(OS2HwndFrame);
2353 }
2354
2355 if (flags & WIN_NEED_SIZE)
2356 {
2357 /* should happen only in CreateWindowEx() */
2358 int wParam = SIZE_RESTORED;
2359
2360 flags &= ~WIN_NEED_SIZE;
2361 if (dwStyle & WS_MAXIMIZE)
2362 wParam = SIZE_MAXIMIZED;
2363 else
2364 if (dwStyle & WS_MINIMIZE)
2365 wParam = SIZE_MINIMIZED;
2366
2367 SendInternalMessageA(WM_SIZE, wParam,
2368 MAKELONG(rectClient.right-rectClient.left,
2369 rectClient.bottom-rectClient.top));
2370 SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
2371 }
2372//testestest
2373 //temporary workaround for file dialogs with template dialog child
2374 //they don't redraw when switching directories
2375 //For some reason the new child's (syslistview32) update rectangle stays
2376 //empty after its parent is made visible with ShowWindow
2377 //TODO: find real cause
2378 if(!wasVisible) {
2379 InvalidateRect(getWindowHandle(), NULL, TRUE);
2380 }
2381//testestest
2382END:
2383 fMinMaxChange = FALSE;
2384 return wasVisible;
2385}
2386//******************************************************************************
2387//******************************************************************************
2388BOOL Win32BaseWindow::SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags)
2389{
2390 BOOL rc = FALSE;
2391 Win32BaseWindow *window;
2392 HWND hParent = 0;
2393 RECT oldClientRect = rectClient;
2394
2395 if (fuFlags &
2396 ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER |
2397 SWP_NOREDRAW | SWP_NOACTIVATE | SWP_FRAMECHANGED |
2398 SWP_SHOWWINDOW | SWP_HIDEWINDOW | SWP_NOCOPYBITS |
2399 SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_DEFERERASE |
2400 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE))
2401 {
2402 dprintf(("ERROR: SetWindowPos; UNKNOWN flag"));
2403 return FALSE;
2404 }
2405
2406 if( fuFlags & (SWP_DEFERERASE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)) {
2407 dprintf(("WARNING: SetWindowPos; unsupported flag"));
2408 }
2409
2410 if(IsWindowDestroyed()) {
2411 //changing the position of a window that's being destroyed can cause crashes in PMMERGE
2412 dprintf(("SetWindowPos; window already destroyed"));
2413 return TRUE;
2414 }
2415#if 0
2416 /* Fix redundant flags */
2417 if(getStyle() & WS_VISIBLE) {
2418 fuFlags &= ~SWP_SHOWWINDOW;
2419 }
2420 else
2421 {
2422 if (!(fuFlags & SWP_SHOWWINDOW))
2423 fuFlags |= SWP_NOREDRAW;
2424 fuFlags &= ~SWP_HIDEWINDOW;
2425 }
2426
2427 if(cx < 0) cx = 0;
2428 if(cy < 0) cy = 0;
2429
2430 if((rectWindow.right - rectWindow.left == cx) && (rectWindow.bottom - rectWindow.top == cy)) {
2431 fuFlags |= SWP_NOSIZE; /* Already the right size */
2432 }
2433
2434 if((rectWindow.left == x) && (rectWindow.top == y)) {
2435 fuFlags |= SWP_NOMOVE; /* Already the right position */
2436 }
2437
2438 if(getWindowHandle() == GetActiveWindow()) {
2439 fuFlags |= SWP_NOACTIVATE; /* Already active */
2440 }
2441 else
2442 if((getStyle() & (WS_POPUP | WS_CHILD)) != WS_CHILD )
2443 {
2444 if(!(fuFlags & SWP_NOACTIVATE)) /* Bring to the top when activating */
2445 {
2446 fuFlags &= ~SWP_NOZORDER;
2447 hwndInsertAfter = HWND_TOP;
2448 }
2449 }
2450#endif
2451
2452 if(!fCreateSetWindowPos)
2453 {//don't change size; modify internal structures only
2454 //TODO: not 100% correct yet (activate)
2455 if(!(fuFlags & SWP_NOZORDER)) {
2456 hwndLinkAfter = hwndInsertAfter;
2457 }
2458 if(!(fuFlags & SWP_NOMOVE)) {
2459 rectWindow.bottom = (rectWindow.bottom - rectWindow.top) + y;
2460 rectWindow.top = y;
2461 rectWindow.right = (rectWindow.right - rectWindow.left) + x;
2462 rectWindow.left = x;
2463 }
2464 if(!(fuFlags & SWP_NOSIZE)) {
2465 rectWindow.bottom = rectWindow.top + cy;
2466 rectWindow.right = rectWindow.left + cx;
2467 }
2468 return TRUE;
2469 }
2470
2471 WINDOWPOS wpos;
2472 SWP swp, swpOld;
2473 wpos.flags = fuFlags;
2474 wpos.cy = cy;
2475 wpos.cx = cx;
2476 wpos.x = x;
2477 wpos.y = y;
2478 wpos.hwndInsertAfter = hwndInsertAfter;
2479 wpos.hwnd = getWindowHandle();
2480
2481 if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
2482 {
2483 if (isChild())
2484 {
2485 if(!getParent()) {
2486 dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
2487 }
2488 }
2489 OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
2490 }
2491
2492 if(getParent()) {
2493 OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getClientHeight(),
2494 OS2HwndFrame);
2495 }
2496 else OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), OS2HwndFrame);
2497
2498 if (swp.fl == 0) {
2499 if(fuFlags & SWP_FRAMECHANGED)
2500 {
2501 NotifyFrameChanged(&wpos, &oldClientRect);
2502 }
2503 return TRUE;
2504 }
2505
2506// if ((swp.fl & SWPOS_ZORDER) && (swp.hwndInsertBehind > HWNDOS_BOTTOM))
2507 if ((swp.hwndInsertBehind > HWNDOS_BOTTOM))
2508 {
2509 Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
2510 if(wndBehind) {
2511 swp.hwndInsertBehind = wndBehind->getOS2FrameWindowHandle();
2512 RELEASE_WNDOBJ(wndBehind);
2513 }
2514 else {
2515 dprintf(("ERROR: SetWindowPos: hwndInsertBehind %x invalid!",swp.hwndInsertBehind));
2516 swp.hwndInsertBehind = 0;
2517 }
2518 }
2519 swp.hwnd = OS2HwndFrame;
2520
2521 if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible(getWindowHandle())) {
2522 setStyle(getStyle() | WS_VISIBLE);
2523 if(hTaskList) {
2524 dprintf(("Adding window %x to tasklist", getWindowHandle()));
2525 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 1);
2526 }
2527 }
2528 else
2529 if((fuFlags & SWP_HIDEWINDOW) && IsWindowVisible(getWindowHandle())) {
2530 setStyle(getStyle() & ~WS_VISIBLE);
2531 if(hTaskList && !(getStyle() & WS_MINIMIZE)) {
2532 dprintf(("Removing window %x from tasklist", getWindowHandle()));
2533 OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), 0);
2534 }
2535 }
2536 dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
2537 rc = OSLibWinSetMultWindowPos(&swp, 1);
2538
2539 if(rc == FALSE)
2540 {
2541 dprintf(("OSLibWinSetMultWindowPos failed! Error %x",OSLibWinGetLastError()));
2542 return 0;
2543 }
2544
2545 if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
2546 {
2547 NotifyFrameChanged(&wpos, &oldClientRect);
2548 }
2549 return (rc);
2550}
2551//******************************************************************************
2552//Called by ScrollWindowEx (dc.cpp) to notify child window that it has moved
2553//******************************************************************************
2554BOOL Win32BaseWindow::ScrollWindow(int dx, int dy)
2555{
2556 rectWindow.left += dx;
2557 rectWindow.right += dx;
2558 rectWindow.top += dy;
2559 rectWindow.bottom += dy;
2560 SendInternalMessageA(WM_MOVE, 0, MAKELONG(rectClient.left, rectClient.top));
2561 return TRUE;
2562}
2563//******************************************************************************
2564//******************************************************************************
2565void Win32BaseWindow::NotifyFrameChanged(WINDOWPOS *wpos, RECT *oldClientRect)
2566{
2567 HRGN hrgn, hrgnClient;
2568 RECT rect;
2569
2570 MsgFormatFrame(NULL);
2571
2572 if(RECT_WIDTH(rectClient) != RECT_WIDTH(*oldClientRect) ||
2573 RECT_HEIGHT(rectClient) != RECT_HEIGHT(*oldClientRect))
2574 {
2575 wpos->flags &= ~(SWP_NOSIZE|SWP_NOCLIENTSIZE);
2576 wpos->cx = RECT_WIDTH(rectWindow);
2577 wpos->cy = RECT_HEIGHT(rectWindow);
2578 }
2579
2580 if(rectClient.left != oldClientRect->left ||
2581 rectClient.top != oldClientRect->top)
2582 {
2583 wpos->flags &= ~(SWP_NOMOVE|SWP_NOCLIENTMOVE);
2584 wpos->x = rectWindow.left;
2585 wpos->y = rectWindow.top;
2586 }
2587
2588 WINDOWPOS wpOld = *wpos;
2589 SendInternalMessageA(WM_WINDOWPOSCHANGING, 0, (LPARAM)wpos);
2590
2591 if ((wpos->hwndInsertAfter != wpOld.hwndInsertAfter) ||
2592 (wpos->x != wpOld.x) || (wpos->y != wpOld.y) || (wpos->cx != wpOld.cx) || (wpos->cy != wpOld.cy) || (wpos->flags != wpOld.flags))
2593 {
2594 dprintf(("WARNING, NotifyFrameChanged: TODO -> adjust flags!!!!"));
2595 SetWindowPos(wpos->hwndInsertAfter, wpos->x, wpos->y, wpos->cx, wpos->cy, wpos->flags | SWP_NOSENDCHANGING);
2596 }
2597 else SendInternalMessageA(WM_WINDOWPOSCHANGED, 0, (LPARAM)wpos);
2598
2599 //Calculate invalid areas
2600 rect = rectWindow;
2601 OffsetRect(&rect, -rectWindow.left, -rectWindow.top);
2602 hrgn = CreateRectRgnIndirect(&rect);
2603 if (!hrgn) {
2604 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2605 return;
2606 }
2607 rect = rectClient;
2608 hrgnClient = CreateRectRgnIndirect(&rect);
2609 if (!hrgn) {
2610 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2611 return;
2612 }
2613 CombineRgn(hrgn, hrgn, hrgnClient, RGN_DIFF);
2614 DeleteObject(hrgnClient);
2615
2616 if(!EqualRect(oldClientRect, &rectClient)) {
2617 UnionRect(oldClientRect, oldClientRect, &rectClient);
2618 hrgnClient = CreateRectRgnIndirect(oldClientRect);
2619 if (!hrgn) {
2620 dprintf(("ERROR: NotifyFrameChanged, CreateRectRgnIndirect failed!!"));
2621 return;
2622 }
2623 CombineRgn(hrgn, hrgn, hrgnClient, RGN_OR);
2624 DeleteObject(hrgnClient);
2625 }
2626 RedrawWindow(getWindowHandle(), NULL, hrgn, RDW_ALLCHILDREN |
2627 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME);
2628 DeleteObject(hrgn);
2629}
2630//******************************************************************************
2631//TODO: Check how this api really works in NT
2632//******************************************************************************
2633BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
2634{
2635 dprintf(("SetWindowPlacement %x min (%d,%d)", getWindowHandle(), wndpl->ptMinPosition.x, wndpl->ptMinPosition.y));
2636 dprintf(("SetWindowPlacement %x max (%d,%d)", getWindowHandle(), wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y));
2637 dprintf(("SetWindowPlacement %x norm (%d,%d)(%d,%d)", getWindowHandle(), wndpl->rcNormalPosition.left, wndpl->rcNormalPosition.top, wndpl->rcNormalPosition.right, wndpl->rcNormalPosition.bottom));
2638 windowpos.ptMinPosition = wndpl->ptMinPosition;
2639 windowpos.ptMaxPosition = wndpl->ptMaxPosition;
2640 windowpos.rcNormalPosition = wndpl->rcNormalPosition;
2641
2642 if(getStyle() & WS_MINIMIZE )
2643 {
2644 //TODO: Why can't this be (0,0)?
2645 if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
2646 SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
2647 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2648 }
2649 }
2650 else
2651 if(getStyle() & WS_MAXIMIZE )
2652 {
2653 //TODO: Why can't this be (0,0)?
2654 if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
2655 SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
2656 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
2657 }
2658 else {
2659 SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
2660 windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
2661 windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
2662 SWP_NOZORDER | SWP_NOACTIVATE );
2663 }
2664 ShowWindow(wndpl->showCmd);
2665 if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
2666 {
2667 /* SDK: ...valid only the next time... */
2668 if(wndpl->flags & WPF_RESTORETOMAXIMIZED)
2669 setFlags(getFlags() | WIN_RESTORE_MAX);
2670 }
2671 return TRUE;
2672}
2673//******************************************************************************
2674//******************************************************************************
2675BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
2676{
2677 wndpl->length = sizeof(*wndpl);
2678 if(getStyle() & WS_MINIMIZE )
2679 wndpl->showCmd = SW_SHOWMINIMIZED;
2680 else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
2681
2682 //TODO: Verify if this is correct -> SDK docs claim this flag must always be set to 0
2683 if(getFlags() & WIN_RESTORE_MAX )
2684 wndpl->flags = WPF_RESTORETOMAXIMIZED;
2685 else wndpl->flags = 0;
2686
2687 wndpl->ptMinPosition = windowpos.ptMinPosition;
2688 wndpl->ptMaxPosition = windowpos.ptMaxPosition;
2689 //Must be in parent coordinates (or screen if no parent); verified in NT4, SP6
2690 wndpl->rcNormalPosition = rectWindow;
2691
2692 return TRUE;
2693}
2694//******************************************************************************
2695//Also destroys all the child windows (destroy children first, parent last)
2696//******************************************************************************
2697BOOL Win32BaseWindow::DestroyWindow()
2698{
2699 HWND hwnd = getWindowHandle();
2700
2701 dprintf(("DestroyWindow %x", hwnd));
2702
2703 /* Call hooks */
2704 if(HOOK_CallHooksA( WH_CBT, HCBT_DESTROYWND, getWindowHandle(), 0L))
2705 {
2706 return FALSE;
2707 }
2708
2709 if(!(getStyle() & WS_CHILD) && getOwner() == NULL)
2710 {
2711 HOOK_CallHooksA(WH_SHELL, HSHELL_WINDOWDESTROYED, getWindowHandle(), 0L);
2712 /* FIXME: clean up palette - see "Internals" p.352 */
2713 }
2714
2715 if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_NOPARENTNOTIFY))
2716 {
2717 if(getParent() && getParent()->IsWindowDestroyed() == FALSE)
2718 {
2719 /* Notify the parent window only */
2720 getParent()->SendMessageA(WM_PARENTNOTIFY, MAKEWPARAM(WM_DESTROY, getWindowId()), (LPARAM)getWindowHandle());
2721 if(!::IsWindow(hwnd) )
2722 {
2723 return TRUE;
2724 }
2725 }
2726//// else DebugInt3();
2727 }
2728 /* Hide the window */
2729 if(IsWindowVisible(getWindowHandle()))
2730 {
2731 SetWindowPos(0, 0, 0, 0, 0, SWP_HIDEWINDOW |
2732 SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
2733 if(!::IsWindow(hwnd))
2734 {
2735 return TRUE;
2736 }
2737 }
2738 dprintf(("DestroyWindow %x -> HIDDEN", hwnd));
2739
2740 fDestroyWindowCalled = TRUE;
2741 return OSLibWinDestroyWindow(OS2HwndFrame);
2742}
2743//******************************************************************************
2744//******************************************************************************
2745Win32BaseWindow *Win32BaseWindow::getParent()
2746{
2747 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2748 return ((ULONG)wndparent == (ULONG)windowDesktop) ? NULL : wndparent;
2749}
2750//******************************************************************************
2751//Note: does not set last error if no parent (verified in NT4, SP6)
2752//******************************************************************************
2753HWND Win32BaseWindow::GetParent()
2754{
2755 if((!(getStyle() & (WS_POPUP|WS_CHILD)))) {
2756 return 0;
2757 }
2758
2759 Win32BaseWindow *wndparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2760
2761 if(getStyle() & WS_CHILD) {
2762 if(wndparent) {
2763 return wndparent->getWindowHandle();
2764 }
2765 dprintf(("WARNING: GetParent: WS_CHILD but no parent!!"));
2766 DebugInt3();
2767 return 0;
2768 }
2769 else return (getOwner()) ? getOwner()->getWindowHandle() : 0;
2770}
2771//******************************************************************************
2772//******************************************************************************
2773HWND Win32BaseWindow::SetParent(HWND hwndNewParent)
2774{
2775 HWND oldhwnd;
2776 Win32BaseWindow *newparent;
2777 Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::getParentOfChild();
2778 BOOL fShow = FALSE;
2779
2780 if(oldparent) {
2781 oldhwnd = oldparent->getWindowHandle();
2782 oldparent->removeChild(this);
2783 }
2784 else oldhwnd = 0;
2785
2786 /* Windows hides the window first, then shows it again
2787 * including the WM_SHOWWINDOW messages and all */
2788 if(fCreated && (getStyle() & WS_VISIBLE)) {
2789 ShowWindow(SW_HIDE);
2790 fShow = TRUE;
2791 }
2792 if(oldparent) {
2793 RELEASE_WNDOBJ(oldparent);
2794 }
2795 newparent = GetWindowFromHandle(hwndNewParent);
2796 if(newparent && !newparent->isDesktopWindow())
2797 {
2798 setParent(newparent);
2799 getParent()->addChild(this);
2800 OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
2801 if(!(getStyle() & WS_CHILD))
2802 {
2803 //TODO: Send WM_STYLECHANGED msg?
2804 setStyle(getStyle() | WS_CHILD);
2805 if(getWindowId())
2806 {
2807 DestroyMenu( (HMENU) getWindowId() );
2808 setWindowId(0);
2809 }
2810 }
2811 }
2812 else {
2813 if(newparent) RELEASE_WNDOBJ(newparent);
2814
2815 setParent(windowDesktop);
2816 windowDesktop->addRef();
2817 windowDesktop->addChild(this);
2818 OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
2819
2820 //TODO: Send WM_STYLECHANGED msg?
2821 setStyle(getStyle() & ~WS_CHILD);
2822 setWindowId(0);
2823 }
2824 /* SetParent additionally needs to make hwndChild the topmost window
2825 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2826 WM_WINDOWPOSCHANGED notification messages.
2827 */
2828 if(fCreated) {
2829 SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
2830 SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
2831
2832 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2833 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2834 }
2835 return oldhwnd;
2836}
2837//******************************************************************************
2838//******************************************************************************
2839BOOL Win32BaseWindow::IsChild(HWND hwndParent)
2840{
2841 if(getParent()) {
2842 if(getParent()->getWindowHandle() == hwndParent)
2843 return TRUE;
2844
2845 return getParent()->IsChild(hwndParent);
2846 }
2847 else return 0;
2848}
2849//******************************************************************************
2850//******************************************************************************
2851HWND Win32BaseWindow::GetTopWindow()
2852{
2853 HWND hwndTop;
2854 Win32BaseWindow *topwindow;
2855
2856 hwndTop = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
2857 if(!isDesktopWindow())
2858 {
2859 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2860 if(topwindow) {
2861 hwndTop = topwindow->getWindowHandle();
2862 RELEASE_WNDOBJ(topwindow);
2863 return hwndTop;
2864 }
2865 return 0;
2866 }
2867 while(hwndTop) {
2868 topwindow = GetWindowFromOS2FrameHandle(hwndTop);
2869 if(topwindow) {
2870 hwndTop = topwindow->getWindowHandle();
2871 RELEASE_WNDOBJ(topwindow);
2872 return hwndTop;
2873 }
2874 hwndTop = OSLibWinQueryWindow(hwndTop, QWOS_NEXT);
2875 }
2876
2877 return 0;
2878}
2879//******************************************************************************
2880// Get the top-level parent for a child window.
2881//******************************************************************************
2882HWND Win32BaseWindow::GetTopParent()
2883{
2884 Win32BaseWindow *window = this;
2885 HWND hwndTopParent = 0;
2886
2887 lock();
2888 while(window && (window->getStyle() & WS_CHILD))
2889 {
2890 window = window->getParent();
2891 }
2892 if(window) {
2893 hwndTopParent = window->getWindowHandle();
2894 }
2895 unlock();
2896 return hwndTopParent;
2897}
2898//******************************************************************************
2899//TODO: Should not enumerate children that are created during the enumeration!
2900//******************************************************************************
2901BOOL Win32BaseWindow::EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam)
2902{
2903 BOOL rc = TRUE;
2904 HWND hwnd;
2905 Win32BaseWindow *prevchild = 0, *child = 0;
2906
2907 dprintf(("EnumChildWindows of %x parameter %x %x (%x)", getWindowHandle(), lpfn, lParam, getFirstChild()));
2908 lock();
2909 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2910 {
2911 dprintf(("EnumChildWindows: enumerating child %x (owner %x; parent %x)", child->getWindowHandle(), (child->getOwner()) ? child->getOwner()->getWindowHandle() : 0, getWindowHandle()));
2912 hwnd = child->getWindowHandle();
2913 if(child->IsWindowDestroyed() || child->getOwner()) {
2914 continue; //shouldn't have an owner (Wine)
2915 }
2916 child->addRef();
2917 unlock();
2918 if(lpfn(hwnd, lParam) == FALSE)
2919 {
2920 child->release();
2921 return FALSE;
2922 }
2923 child->release();
2924 lock();
2925 //check if the window still exists
2926 if(!::IsWindow(hwnd))
2927 {
2928 child = prevchild;
2929 continue;
2930 }
2931 if(child->getFirstChild() != NULL)
2932 {
2933 dprintf(("EnumChildWindows: Enumerate children of %x", child->getWindowHandle()));
2934 child->addRef();
2935 unlock();
2936 if(child->EnumChildWindows(lpfn, lParam) == FALSE)
2937 {
2938 child->release();
2939 return FALSE;
2940 }
2941 child->release();
2942 lock();
2943 }
2944 prevchild = child;
2945 }
2946 unlock();
2947 return rc;
2948}
2949//******************************************************************************
2950//Enumerate first-level children only and check thread id
2951//******************************************************************************
2952BOOL Win32BaseWindow::EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
2953{
2954 Win32BaseWindow *child = 0;
2955 ULONG tid, pid;
2956 BOOL rc;
2957 HWND hwnd;
2958
2959 dprintf(("EnumThreadWindows %x %x %x", dwThreadId, lpfn, lParam));
2960
2961 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2962 {
2963 OSLibWinQueryWindowProcess(child->getOS2WindowHandle(), &pid, &tid);
2964
2965 if(dwThreadId == tid) {
2966 dprintf2(("EnumThreadWindows: Found Window %x", child->getWindowHandle()));
2967 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2968 break;
2969 }
2970 }
2971 }
2972 return TRUE;
2973}
2974//******************************************************************************
2975//Enumerate first-level children only
2976//******************************************************************************
2977BOOL Win32BaseWindow::EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
2978{
2979 Win32BaseWindow *child = 0;
2980 BOOL rc;
2981 HWND hwnd;
2982
2983 dprintf(("EnumWindows %x %x", lpfn, lParam));
2984
2985 for (child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
2986 {
2987 hwnd = child->getWindowHandle();
2988
2989 dprintf2(("EnumWindows: Found Window %x", child->getWindowHandle()));
2990 if((rc = lpfn(child->getWindowHandle(), lParam)) == FALSE) {
2991 break;
2992 }
2993 }
2994 return TRUE;
2995}
2996//******************************************************************************
2997//******************************************************************************
2998HWND Win32BaseWindow::FindWindowById(int id)
2999{
3000 lock();
3001 for (Win32BaseWindow *child = (Win32BaseWindow *)getFirstChild(); child; child = (Win32BaseWindow *)child->getNextChild())
3002 {
3003 if (child->getWindowId() == id)
3004 {
3005 unlock();
3006 return child->getWindowHandle();
3007 }
3008 }
3009 unlock();
3010 return 0;
3011}
3012//******************************************************************************
3013//TODO:
3014//We assume (for now) that if hwndParent or hwndChildAfter are real window handles, that
3015//the current process owns them.
3016//******************************************************************************
3017HWND Win32BaseWindow::FindWindowEx(HWND hwndParent, HWND hwndChildAfter, ATOM atom, LPSTR lpszWindow)
3018{
3019 Win32BaseWindow *parent = GetWindowFromHandle(hwndParent);
3020 Win32BaseWindow *child = GetWindowFromHandle(hwndChildAfter);
3021 Win32BaseWindow *firstchild = child;
3022
3023 dprintf(("FindWindowEx %x %x %x %s", hwndParent, hwndChildAfter, atom, lpszWindow));
3024 if((hwndParent != 0 && !parent) ||
3025 (hwndChildAfter != 0 && !child) ||
3026 (hwndParent == 0 && hwndChildAfter != 0))
3027 {
3028 if(parent) RELEASE_WNDOBJ(parent);
3029 if(firstchild) RELEASE_WNDOBJ(firstchild);
3030 dprintf(("Win32BaseWindow::FindWindowEx: parent or child not found %x %x", hwndParent, hwndChildAfter));
3031 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
3032 return 0;
3033 }
3034 SetLastError(0);
3035 if(hwndParent != 0)
3036 {//if the current process owns the window, just do a quick search
3037 lock(&critsect);
3038 child = (Win32BaseWindow *)parent->getFirstChild();
3039 if(hwndChildAfter != 0)
3040 {
3041 while(child)
3042 {
3043 if(child->getWindowHandle() == hwndChildAfter)
3044 {
3045 child = (Win32BaseWindow *)child->getNextChild();
3046 break;
3047 }
3048 child = (Win32BaseWindow *)child->getNextChild();
3049 }
3050 }
3051 while(child)
3052 {
3053 //According to Wine, the class doesn't need to be specified
3054 if((!atom || child->getWindowClass()->getAtom() == atom) &&
3055 (!lpszWindow || child->hasWindowName(lpszWindow)))
3056 {
3057 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3058 HWND hwndChild = child->getWindowHandle();
3059 unlock(&critsect);
3060 if(parent) RELEASE_WNDOBJ(parent);
3061 if(firstchild) RELEASE_WNDOBJ(firstchild);
3062 dprintf(("FindWindowEx: Found window %x", child->getWindowHandle()));
3063 return hwndChild;
3064 }
3065 child = (Win32BaseWindow *)child->getNextChild();
3066 }
3067 unlock(&critsect);
3068 if(parent) RELEASE_WNDOBJ(parent);
3069 if(firstchild) RELEASE_WNDOBJ(firstchild);
3070 }
3071 else {
3072 Win32BaseWindow *wnd;
3073 HWND henum, hwnd;
3074
3075 henum = OSLibWinBeginEnumWindows(OSLIB_HWND_DESKTOP);
3076 hwnd = OSLibWinGetNextWindow(henum);
3077
3078 while(hwnd)
3079 {
3080 wnd = GetWindowFromOS2FrameHandle(hwnd);
3081 if(wnd == NULL) {
3082 hwnd = OSLibWinQueryClientWindow(hwnd);
3083 if(hwnd) wnd = GetWindowFromOS2Handle(hwnd);
3084 }
3085
3086 if(wnd) {
3087 //According to Wine, the class doesn't need to be specified
3088 if((!atom || wnd->getWindowClass()->getAtom() == atom) &&
3089 (!lpszWindow || wnd->hasWindowName(lpszWindow)))
3090 {
3091 OSLibWinEndEnumWindows(henum);
3092 dprintf(("FindWindowEx: Found window %x", wnd->getWindowHandle()));
3093 HWND hwndret = wnd->getWindowHandle();
3094 RELEASE_WNDOBJ(wnd);
3095 return hwndret;
3096 }
3097 RELEASE_WNDOBJ(wnd);
3098 }
3099 hwnd = OSLibWinGetNextWindow(henum);
3100 }
3101 OSLibWinEndEnumWindows(henum);
3102 if(parent) RELEASE_WNDOBJ(parent);
3103 if(firstchild) RELEASE_WNDOBJ(firstchild);
3104 }
3105 SetLastError(ERROR_CANNOT_FIND_WND_CLASS); //TODO: not always correct
3106 return 0;
3107}
3108//******************************************************************************
3109//******************************************************************************
3110HWND Win32BaseWindow::GetWindow(UINT uCmd)
3111{
3112 HWND hwndRelated = 0;
3113 Win32BaseWindow *window;
3114
3115 switch(uCmd)
3116 {
3117 case GW_HWNDFIRST:
3118 if(getParent())
3119 {
3120 window = (Win32BaseWindow *)getParent();
3121 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_TOP);
3122 window = GetWindowFromOS2FrameHandle(hwndRelated);
3123 if(window) {
3124 hwndRelated = window->getWindowHandle();
3125 RELEASE_WNDOBJ(window);
3126 }
3127 else hwndRelated = 0;
3128 }
3129 else {
3130 dprintf(("WARNING: GW_HWNDFIRST not correctly implemented for toplevel/most windows!"));
3131 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3132 }
3133 break;
3134
3135 case GW_HWNDLAST:
3136 if(getParent()) {
3137 window = (Win32BaseWindow *)getParent();
3138 hwndRelated = OSLibWinQueryWindow(window->getOS2WindowHandle(), QWOS_BOTTOM);
3139 dprintf(("os2 handle %x", hwndRelated));
3140 window = GetWindowFromOS2FrameHandle(hwndRelated);
3141 if(window) {
3142 hwndRelated = window->getWindowHandle();
3143 RELEASE_WNDOBJ(window);
3144 }
3145 else hwndRelated = 0;
3146 }
3147 else {
3148 dprintf(("WARNING: GW_HWNDLAST not correctly implemented for toplevel/most windows!"));
3149 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3150 }
3151 break;
3152
3153 case GW_HWNDNEXT:
3154 if(getParent()) {
3155 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_NEXT);
3156 window = GetWindowFromOS2FrameHandle(hwndRelated);
3157 if(window) {
3158 hwndRelated = window->getWindowHandle();
3159 RELEASE_WNDOBJ(window);
3160 }
3161 else hwndRelated = 0;
3162 }
3163 else {
3164 dprintf(("WARNING: GW_HWNDNEXT not correctly implemented for toplevel/most windows!"));
3165 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3166 }
3167 break;
3168
3169 case GW_HWNDPREV:
3170 if(getParent()) {
3171 hwndRelated = OSLibWinQueryWindow(getOS2FrameWindowHandle(), QWOS_PREV);
3172 window = GetWindowFromOS2FrameHandle(hwndRelated);
3173 if(window) {
3174 hwndRelated = window->getWindowHandle();
3175 RELEASE_WNDOBJ(window);
3176 }
3177 else hwndRelated = 0;
3178 }
3179 else {
3180 dprintf(("WARNING: GW_HWNDPREV not correctly implemented for toplevel/most windows!"));
3181 hwndRelated = 0; //TODO: not correct; should get first child in z-order of desktop
3182 }
3183 break;
3184
3185 case GW_OWNER:
3186 if(getOwner()) {
3187 hwndRelated = getOwner()->getWindowHandle();
3188 }
3189 break;
3190
3191 case GW_CHILD:
3192 hwndRelated = OSLibWinQueryWindow(getOS2WindowHandle(), QWOS_TOP);
3193 window = GetWindowFromOS2FrameHandle(hwndRelated);
3194 if(window) {
3195 hwndRelated = window->getWindowHandle();
3196 RELEASE_WNDOBJ(window);
3197 }
3198 else hwndRelated = 0;
3199 break;
3200 }
3201end:
3202 dprintf(("GetWindow %x %d returned %x", getWindowHandle(), uCmd, hwndRelated));
3203 return hwndRelated;
3204}
3205//******************************************************************************
3206//******************************************************************************
3207HWND Win32BaseWindow::SetActiveWindow()
3208{
3209 HWND hwndActive;
3210
3211 dprintf(("SetActiveWindow %x", getWindowHandle()));
3212 if(GetActiveWindow() == getWindowHandle()) {
3213 dprintf(("Window already active"));
3214 return getWindowHandle();
3215 }
3216 if (HOOK_IsHooked( WH_CBT ))
3217 {
3218 CBTACTIVATESTRUCT cbta;
3219 LRESULT ret;
3220
3221 cbta.fMouse = FALSE;
3222 cbta.hWndActive = GetActiveWindow();
3223 ret = HOOK_CallHooksA(WH_CBT, HCBT_ACTIVATE, getWindowHandle(), (LPARAM)&cbta);
3224 if(ret)
3225 {
3226 dprintf(("SetActiveWindow %x, CBT hook cancelled operation", getWindowHandle()));
3227 return cbta.hWndActive;
3228 }
3229 }
3230 SetWindowPos(HWND_TOP, 0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
3231
3232// if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
3233// dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
3234// }
3235 hwndActive = GetActiveWindow();
3236 return (hwndActive) ? hwndActive : windowDesktop->getWindowHandle(); //pretend the desktop was active
3237}
3238//******************************************************************************
3239//Used to change active status of an mdi window
3240//******************************************************************************
3241BOOL Win32BaseWindow::DeactivateChildWindow()
3242{
3243 /* child windows get a WM_CHILDACTIVATE message */
3244 if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
3245 {
3246 ULONG flags = OSLibWinGetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS);
3247 OSLibWinSetWindowULong(getOS2WindowHandle(), OFFSET_WIN32FLAGS, (flags & ~WINDOWFLAG_ACTIVE));
3248 return TRUE;
3249 }
3250 DebugInt3(); //should not be called for non-child window
3251 return FALSE;
3252}
3253//******************************************************************************
3254//WM_ENABLE is sent to hwnd, but not to it's children (as it should be)
3255//******************************************************************************
3256BOOL Win32BaseWindow::EnableWindow(BOOL fEnable)
3257{
3258 BOOL rc;
3259
3260 dprintf(("Win32BaseWindow::EnableWindow %x %d", getWindowHandle(), fEnable));
3261 //return true if previous state was disabled, else false (sdk docs)
3262 rc = (getStyle() & WS_DISABLED) != 0;
3263 if(rc && !fEnable) {
3264 SendMessageA(WM_CANCELMODE, 0, 0);
3265 }
3266 OSLibWinEnableWindow(OS2HwndFrame, fEnable);
3267 if(fEnable == FALSE) {
3268 //SvL: No need to clear focus as PM already does this
3269 if(getWindowHandle() == GetCapture()) {
3270 ReleaseCapture(); /* A disabled window can't capture the mouse */
3271 dprintf(("Released capture for window %x that is being disabled", getWindowHandle()));
3272 }
3273 }
3274 return rc;
3275}
3276//******************************************************************************
3277//******************************************************************************
3278BOOL Win32BaseWindow::CloseWindow()
3279{
3280 return OSLibWinMinimizeWindow(OS2Hwnd);
3281}
3282//******************************************************************************
3283//TODO: Not be 100% correct; should return active window of current thread
3284// or NULL when there is none -> WinQueryActiveWindow just returns
3285// the current active window
3286//******************************************************************************
3287HWND Win32BaseWindow::GetActiveWindow()
3288{
3289 HWND hwndActive;
3290
3291 hwndActive = OSLibWinQueryActiveWindow();
3292
3293 return OS2ToWin32Handle(hwndActive);
3294}
3295//******************************************************************************
3296//******************************************************************************
3297BOOL Win32BaseWindow::hasWindowName(LPSTR wndname, BOOL fUnicode)
3298{
3299 INT len = GetWindowTextLength(fUnicode);
3300 BOOL res;
3301
3302 if (wndname == NULL)
3303 return (len == 0);
3304
3305 len++;
3306 if (fUnicode)
3307 {
3308 WCHAR *text = (WCHAR*)malloc(len*sizeof(WCHAR));
3309
3310 GetWindowTextW(text,len);
3311 res = (lstrcmpW(text,(LPWSTR)wndname) == 0);
3312 free(text);
3313 }
3314 else
3315 {
3316 CHAR *text = (CHAR*)malloc(len*sizeof(CHAR));
3317
3318 GetWindowTextA(text,len);
3319 res = (strcmp(text,wndname) == 0);
3320 free(text);
3321 }
3322
3323 return res;
3324}
3325//******************************************************************************
3326//******************************************************************************
3327CHAR *Win32BaseWindow::getWindowNamePtrA()
3328{
3329 INT len = GetWindowTextLength(FALSE);
3330 CHAR *text;
3331
3332 if (len == 0) return NULL;
3333 len++;
3334 text = (CHAR*)malloc(len*sizeof(CHAR));
3335 GetWindowTextA(text,len);
3336
3337 return text;
3338}
3339//******************************************************************************
3340//******************************************************************************
3341WCHAR *Win32BaseWindow::getWindowNamePtrW()
3342{
3343 INT len = GetWindowTextLength(TRUE);
3344 WCHAR *text;
3345
3346 if (len == 0) return NULL;
3347 len++;
3348 text = (WCHAR*)malloc(len*sizeof(WCHAR));
3349 GetWindowTextW(text,len);
3350
3351 return text;
3352}
3353//******************************************************************************
3354//******************************************************************************
3355VOID Win32BaseWindow::freeWindowNamePtr(PVOID namePtr)
3356{
3357 if (namePtr) free(namePtr);
3358}
3359//******************************************************************************
3360//When using this API for a window that was created by a different process, NT
3361//does NOT send WM_GETTEXTLENGTH.
3362//******************************************************************************
3363int Win32BaseWindow::GetWindowTextLength(BOOL fUnicode)
3364{
3365 //if the destination window is created by this process, send message
3366 if(dwProcessId == currentProcessId) {
3367 if(fUnicode) {
3368 return SendInternalMessageW(WM_GETTEXTLENGTH,0,0);
3369 }
3370 else return SendInternalMessageA(WM_GETTEXTLENGTH,0,0);
3371 }
3372 //else get data directory from window structure
3373 //TODO: must lock window structure.... (TODO)
3374 if(fUnicode) {
3375 if(windowNameW) {
3376 return strlenW(windowNameW);
3377 }
3378 else return 0;
3379 }
3380 else {
3381 if(windowNameA) {
3382 return strlen(windowNameA);
3383 }
3384 else return 0;
3385 }
3386}
3387//******************************************************************************
3388//When using this API for a window that was created by a different process, NT
3389//does NOT send WM_GETTEXT.
3390//******************************************************************************
3391int Win32BaseWindow::GetWindowTextA(LPSTR lpsz, int cch)
3392{
3393 //if the destination window is created by this process, send message
3394 if(dwProcessId == currentProcessId) {
3395 return SendInternalMessageA(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3396 }
3397 //else get data directory from window structure
3398 if (!lpsz || !cch) return 0;
3399 if (!windowNameA) lpsz[0] = 0;
3400 else lstrcpynA(lpsz, windowNameA, cch);
3401 return min((windowNameA ? strlen(windowNameA) : 0), cch);
3402}
3403//******************************************************************************
3404//When using this API for a window that was created by a different process, NT
3405//does NOT send WM_GETTEXT.
3406//******************************************************************************
3407int Win32BaseWindow::GetWindowTextW(LPWSTR lpsz, int cch)
3408{
3409 //if the destination window is created by this process, send message
3410 if(dwProcessId == currentProcessId) {
3411 return SendInternalMessageW(WM_GETTEXT,(WPARAM)cch,(LPARAM)lpsz);
3412 }
3413 //else get data directory from window structure
3414 if (!lpsz || !cch) return 0;
3415 if (!windowNameW) lpsz[0] = 0;
3416 else lstrcpynW(lpsz, windowNameW, cch);
3417 return min((windowNameW ? strlenW(windowNameW) : 0), cch);
3418}
3419//******************************************************************************
3420//TODO: How does this work when the target window belongs to a different process???
3421//******************************************************************************
3422BOOL Win32BaseWindow::SetWindowTextA(LPSTR lpsz)
3423{
3424 return SendInternalMessageA(WM_SETTEXT,0,(LPARAM)lpsz);
3425}
3426//******************************************************************************
3427//******************************************************************************
3428BOOL Win32BaseWindow::SetWindowTextW(LPWSTR lpsz)
3429{
3430 return SendInternalMessageW(WM_SETTEXT,0,(LPARAM)lpsz);
3431}
3432//******************************************************************************
3433//******************************************************************************
3434LONG Win32BaseWindow::SetWindowLongA(int index, ULONG value, BOOL fUnicode)
3435{
3436 LONG oldval;
3437
3438 switch(index) {
3439 case GWL_EXSTYLE:
3440 {
3441 STYLESTRUCT ss;
3442
3443 if(dwExStyle == value) {
3444 oldval = value;
3445 break;
3446 }
3447 ss.styleOld = dwExStyle;
3448 ss.styleNew = value;
3449 dprintf(("SetWindowLong GWL_EXSTYLE %x old %x new style %x", getWindowHandle(), dwExStyle, value));
3450 SendInternalMessageA(WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&ss);
3451 setExStyle(ss.styleNew);
3452 SendInternalMessageA(WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&ss);
3453 oldval = ss.styleOld;
3454 break;
3455 }
3456 case GWL_STYLE:
3457 {
3458 STYLESTRUCT ss;
3459
3460 //SvL: TODO: Can you change minimize or maximize status here too?
3461
3462 if(dwStyle == value) {
3463 oldval = value;
3464 break;
3465 }
3466 value &= ~(WS_CHILD|WS_VISIBLE); /* Some bits can't be changed this way (WINE) */
3467 ss.styleOld = getStyle();
3468 ss.styleNew = value | (ss.styleOld & (WS_CHILD|WS_VISIBLE));
3469 dprintf(("SetWindowLong GWL_STYLE %x old %x new style %x", getWindowHandle(), ss.styleOld, ss.styleNew));
3470 SendInternalMessageA(WM_STYLECHANGING,GWL_STYLE,(LPARAM)&ss);
3471 setStyle(ss.styleNew);
3472 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
3473 OSLibSetWindowStyle(getOS2FrameWindowHandle(), getOS2WindowHandle(), getStyle(), getExStyle());
3474#ifdef DEBUG
3475 PrintWindowStyle(ss.styleNew, 0);
3476#endif
3477 oldval = ss.styleOld;
3478 break;
3479 }
3480 case GWL_WNDPROC:
3481 {
3482 //Note: Type of SetWindowLong determines new window proc type
3483 // UNLESS the new window proc has already been registered
3484 // (use the old type in that case)
3485 // (VERIFIED in NT 4, SP6)
3486 WINDOWPROCTYPE type = WINPROC_GetProcType((HWINDOWPROC)value);
3487 if(type == WIN_PROC_INVALID) {
3488 type = (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A;
3489 }
3490 oldval = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3491 dprintf(("SetWindowLong GWL_WNDPROC %x old %x new wndproc %x", getWindowHandle(), oldval, value));
3492 WINPROC_SetProc((HWINDOWPROC *)&win32wndproc, (WNDPROC)value, type, WIN_PROC_WINDOW);
3493 break;
3494 }
3495 case GWL_HINSTANCE:
3496 oldval = hInstance;
3497 hInstance = value;
3498 break;
3499
3500 case GWL_HWNDPARENT:
3501 oldval = SetParent((HWND)value);
3502 break;
3503
3504 case GWL_ID:
3505 oldval = getWindowId();
3506 setWindowId(value);
3507 break;
3508
3509 case GWL_USERDATA:
3510 oldval = userData;
3511 userData = value;
3512 break;
3513
3514 default:
3515 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3516 {
3517 oldval = *(ULONG *)(userWindowBytes + index);
3518 *(ULONG *)(userWindowBytes + index) = value;
3519 break;
3520 }
3521 dprintf(("WARNING: SetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3522 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3523 return 0;
3524 }
3525 //Note: NT4, SP6 does not set the last error to 0
3526 SetLastError(ERROR_SUCCESS);
3527 dprintf2(("SetWindowLong%c %x %d %x returned %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value, oldval));
3528 return oldval;
3529}
3530//******************************************************************************
3531//******************************************************************************
3532ULONG Win32BaseWindow::GetWindowLongA(int index, BOOL fUnicode)
3533{
3534 ULONG value;
3535
3536 switch(index) {
3537 case GWL_EXSTYLE:
3538 value = dwExStyle;
3539 break;
3540 case GWL_STYLE:
3541 value = dwStyle;
3542 break;
3543 case GWL_WNDPROC:
3544 value = (LONG)WINPROC_GetProc(win32wndproc, (fUnicode) ? WIN_PROC_32W : WIN_PROC_32A);
3545 break;
3546 case GWL_HINSTANCE:
3547 value = hInstance;
3548 break;
3549 case GWL_HWNDPARENT:
3550 value = GetParent();
3551 break;
3552 case GWL_ID:
3553 value = getWindowId();
3554 break;
3555 case GWL_USERDATA:
3556 value = userData;
3557 break;
3558 default:
3559 if(index >= 0 && index + sizeof(ULONG) <= nrUserWindowBytes)
3560 {
3561 value = *(ULONG *)(userWindowBytes + index);
3562 break;
3563 }
3564 dprintf(("WARNING: GetWindowLong%c %x %d %x returned %x INVALID index!", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3565 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3566 return 0;
3567 }
3568 dprintf2(("GetWindowLong%c %x %d %x", (fUnicode) ? 'W' : 'A', getWindowHandle(), index, value));
3569 //Note: NT4, SP6 does not set the last error to 0
3570 SetLastError(ERROR_SUCCESS);
3571 return value;
3572}
3573//******************************************************************************
3574//******************************************************************************
3575WORD Win32BaseWindow::SetWindowWord(int index, WORD value)
3576{
3577 WORD oldval;
3578
3579 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3580 {
3581 oldval = *(WORD *)(userWindowBytes + index);
3582 *(WORD *)(userWindowBytes + index) = value;
3583 //Note: NT4, SP6 does not set the last error to 0
3584 dprintf2(("SetWindowWord %x %d %x returned %x", getWindowHandle(), index, value, oldval));
3585 SetLastError(ERROR_SUCCESS);
3586 return oldval;
3587 }
3588 dprintf(("WARNING: SetWindowWord %x %d %x returned %x INVALID index!", getWindowHandle(), index, value));
3589 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3590 return 0;
3591}
3592//******************************************************************************
3593//******************************************************************************
3594WORD Win32BaseWindow::GetWindowWord(int index)
3595{
3596 if(index >= 0 && index + sizeof(WORD) <= nrUserWindowBytes)
3597 {
3598 //Note: NT4, SP6 does not set the last error to 0
3599 SetLastError(ERROR_SUCCESS);
3600 dprintf2(("GetWindowWord %x %d %x", getWindowHandle(), index, *(WORD *)(userWindowBytes + index)));
3601 return *(WORD *)(userWindowBytes + index);
3602 }
3603 dprintf(("WARNING: GetWindowWord %x %d returned %x INVALID index!", getWindowHandle(), index));
3604 SetLastError(ERROR_INVALID_INDEX); //verified in NT4, SP6
3605 return 0;
3606}
3607//******************************************************************************
3608//******************************************************************************
3609void Win32BaseWindow::setWindowId(DWORD id)
3610{
3611 dwIDMenu = id;
3612}
3613//******************************************************************************
3614//******************************************************************************
3615HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious)
3616{
3617 Win32BaseWindow *firstchild = NULL, *child, *nextchild, *lastchild;
3618 HWND retvalue;
3619
3620 lock();
3621 if (hwndCtrl)
3622 {
3623 firstchild = child = GetWindowFromHandle(hwndCtrl);
3624 if (!child)
3625 {
3626 retvalue = 0;
3627 goto END;
3628 }
3629 /* Make sure hwndCtrl is a top-level child */
3630 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this))
3631 {
3632 child = child->getParent();
3633 if(child == NULL) break;
3634 }
3635 if (!child || (child->getParent() != this))
3636 {
3637 retvalue = 0;
3638 goto END;
3639 }
3640 }
3641 else
3642 {
3643 /* No ctrl specified -> start from the beginning */
3644 child = (Win32BaseWindow *)getFirstChild();
3645 if (!child)
3646 {
3647 retvalue = 0;
3648 goto END;
3649 }
3650
3651 if (fPrevious)
3652 {
3653 while (child->getNextChild())
3654 {
3655 child = (Win32BaseWindow *)child->getNextChild();
3656 }
3657 }
3658 }
3659
3660 lastchild = child;
3661 nextchild = (Win32BaseWindow *)child->getNextChild();
3662 while (TRUE)
3663 {
3664 if (!nextchild || (nextchild->getStyle() & WS_GROUP))
3665 {
3666 /* Wrap-around to the beginning of the group */
3667 Win32BaseWindow *pWndTemp;
3668
3669 nextchild = (Win32BaseWindow *)getFirstChild();
3670
3671 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild())
3672 {
3673 if (pWndTemp->getStyle() & WS_GROUP)
3674 nextchild = pWndTemp;
3675
3676 if (pWndTemp == child)
3677 break;
3678 }
3679
3680 }
3681 if (nextchild == child)
3682 break;
3683
3684 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED))
3685 {
3686 lastchild = nextchild;
3687
3688 if (!fPrevious)
3689 break;
3690 }
3691
3692 nextchild = (Win32BaseWindow *)nextchild->getNextChild();
3693 }
3694 retvalue = lastchild->getWindowHandle();
3695END:
3696 unlock();
3697 if(firstchild) RELEASE_WNDOBJ(firstchild);
3698 return retvalue;
3699}
3700//******************************************************************************
3701//Locates window in linked list and increases reference count (if found)
3702//Window object must be unreferenced after usage
3703//******************************************************************************
3704Win32BaseWindow *Win32BaseWindow::GetWindowFromHandle(HWND hwnd)
3705{
3706 Win32BaseWindow *window;
3707
3708 lock(&critsect);
3709 if(HwGetWindowHandleData(hwnd, (DWORD *)&window) == TRUE) {
3710 if(window) {
3711//// dprintf(("addRef %x; refcount %d", hwnd, window->getRefCount()+1));
3712 window->addRef();
3713 }
3714 unlock(&critsect);
3715 return window;
3716 }
3717 unlock(&critsect);
3718// dprintf2(("Win32BaseWindow::GetWindowFromHandle: not a win32 window %x", hwnd));
3719 return NULL;
3720}
3721//******************************************************************************
3722//Locates window in linked list and increases reference count (if found)
3723//Window object must be unreferenced after usage
3724//******************************************************************************
3725Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwndOS2)
3726{
3727 DWORD magic;
3728 HWND hwnd;
3729
3730 if(hwndOS2 == OSLIB_HWND_DESKTOP)
3731 {
3732 windowDesktop->addRef();
3733 return windowDesktop;
3734 }
3735
3736 hwnd = (HWND)OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32WNDPTR);
3737 magic = OSLibWinGetWindowULong(hwndOS2, OFFSET_WIN32PM_MAGIC);
3738
3739 if(hwnd && CheckMagicDword(magic)) {
3740 return GetWindowFromHandle(hwnd);
3741 }
3742// dprintf2(("Win32BaseWindow::GetWindowFromOS2Handle: not an Odin os2 window %x", hwndOS2));
3743 return 0;
3744}
3745//******************************************************************************
3746//Locates window in linked list and increases reference count (if found)
3747//Window object must be unreferenced after usage
3748//******************************************************************************
3749Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
3750{
3751 return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
3752}
3753//******************************************************************************
3754//******************************************************************************
3755HWND WIN32API Win32ToOS2Handle(HWND hwnd)
3756{
3757 HWND hwndOS2;
3758
3759 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromHandle(hwnd);
3760
3761 if(window) {
3762 hwndOS2 = window->getOS2WindowHandle();
3763 RELEASE_WNDOBJ(window);
3764 return hwndOS2;
3765 }
3766// dprintf2(("Win32BaseWindow::Win32ToOS2Handle: not a win32 window %x", hwnd));
3767 return hwnd;
3768}
3769//******************************************************************************
3770//******************************************************************************
3771HWND WIN32API OS2ToWin32Handle(HWND hwnd)
3772{
3773 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
3774 HWND hwndWin32;
3775
3776 if(window) {
3777 hwndWin32 = window->getWindowHandle();
3778 RELEASE_WNDOBJ(window);
3779 return hwndWin32;
3780 }
3781 window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
3782 if(window) {
3783 hwndWin32 = window->getWindowHandle();
3784 RELEASE_WNDOBJ(window);
3785 return hwndWin32;
3786 }
3787
3788// dprintf2(("Win32BaseWindow::OS2ToWin32Handle: not a win32 window %x", hwnd));
3789 return 0;
3790// else return hwnd; //OS/2 window handle
3791}
3792//******************************************************************************
3793//******************************************************************************
3794GenericObject *Win32BaseWindow::windows = NULL;
3795CRITICAL_SECTION Win32BaseWindow::critsect = {0};
3796
3797//******************************************************************************
3798//******************************************************************************
3799#ifdef DEBUG
3800void PrintWindowStyle(DWORD dwStyle, DWORD dwExStyle)
3801{
3802 char style[256] = "";
3803 char exstyle[256] = "";
3804
3805 /* Window styles */
3806 if(dwStyle & WS_CHILD)
3807 strcat(style, "WS_CHILD ");
3808 if(dwStyle & WS_POPUP)
3809 strcat(style, "WS_POPUP ");
3810 if(dwStyle & WS_VISIBLE)
3811 strcat(style, "WS_VISIBLE ");
3812 if(dwStyle & WS_DISABLED)
3813 strcat(style, "WS_DISABLED ");
3814 if(dwStyle & WS_CLIPSIBLINGS)
3815 strcat(style, "WS_CLIPSIBLINGS ");
3816 if(dwStyle & WS_CLIPCHILDREN)
3817 strcat(style, "WS_CLIPCHILDREN ");
3818 if(dwStyle & WS_MAXIMIZE)
3819 strcat(style, "WS_MAXIMIZE ");
3820 if(dwStyle & WS_MINIMIZE)
3821 strcat(style, "WS_MINIMIZE ");
3822 if(dwStyle & WS_GROUP)
3823 strcat(style, "WS_GROUP ");
3824 if(dwStyle & WS_TABSTOP)
3825 strcat(style, "WS_TABSTOP ");
3826
3827 if((dwStyle & WS_CAPTION) == WS_CAPTION)
3828 strcat(style, "WS_CAPTION ");
3829 if(dwStyle & WS_DLGFRAME)
3830 strcat(style, "WS_DLGFRAME ");
3831 if(dwStyle & WS_BORDER)
3832 strcat(style, "WS_BORDER ");
3833
3834 if(dwStyle & WS_VSCROLL)
3835 strcat(style, "WS_VSCROLL ");
3836 if(dwStyle & WS_HSCROLL)
3837 strcat(style, "WS_HSCROLL ");
3838 if(dwStyle & WS_SYSMENU)
3839 strcat(style, "WS_SYSMENU ");
3840 if(dwStyle & WS_THICKFRAME)
3841 strcat(style, "WS_THICKFRAME ");
3842 if(dwStyle & WS_MINIMIZEBOX)
3843 strcat(style, "WS_MINIMIZEBOX ");
3844 if(dwStyle & WS_MAXIMIZEBOX)
3845 strcat(style, "WS_MAXIMIZEBOX ");
3846
3847 if(dwExStyle & WS_EX_DLGMODALFRAME)
3848 strcat(exstyle, "WS_EX_DLGMODALFRAME ");
3849 if(dwExStyle & WS_EX_ACCEPTFILES)
3850 strcat(exstyle, "WS_EX_ACCEPTFILES ");
3851 if(dwExStyle & WS_EX_NOPARENTNOTIFY)
3852 strcat(exstyle, "WS_EX_NOPARENTNOTIFY ");
3853 if(dwExStyle & WS_EX_TOPMOST)
3854 strcat(exstyle, "WS_EX_TOPMOST ");
3855 if(dwExStyle & WS_EX_TRANSPARENT)
3856 strcat(exstyle, "WS_EX_TRANSPARENT ");
3857
3858 if(dwExStyle & WS_EX_MDICHILD)
3859 strcat(exstyle, "WS_EX_MDICHILD ");
3860 if(dwExStyle & WS_EX_TOOLWINDOW)
3861 strcat(exstyle, "WS_EX_TOOLWINDOW ");
3862 if(dwExStyle & WS_EX_WINDOWEDGE)
3863 strcat(exstyle, "WS_EX_WINDOWEDGE ");
3864 if(dwExStyle & WS_EX_CLIENTEDGE)
3865 strcat(exstyle, "WS_EX_CLIENTEDGE ");
3866 if(dwExStyle & WS_EX_CONTEXTHELP)
3867 strcat(exstyle, "WS_EX_CONTEXTHELP ");
3868 if(dwExStyle & WS_EX_RIGHT)
3869 strcat(exstyle, "WS_EX_RIGHT ");
3870 if(dwExStyle & WS_EX_LEFT)
3871 strcat(exstyle, "WS_EX_LEFT ");
3872 if(dwExStyle & WS_EX_RTLREADING)
3873 strcat(exstyle, "WS_EX_RTLREADING ");
3874 if(dwExStyle & WS_EX_LTRREADING)
3875 strcat(exstyle, "WS_EX_LTRREADING ");
3876 if(dwExStyle & WS_EX_LEFTSCROLLBAR)
3877 strcat(exstyle, "WS_EX_LEFTSCROLLBAR ");
3878 if(dwExStyle & WS_EX_RIGHTSCROLLBAR)
3879 strcat(exstyle, "WS_EX_RIGHTSCROLLBAR ");
3880 if(dwExStyle & WS_EX_CONTROLPARENT)
3881 strcat(exstyle, "WS_EX_CONTROLPARENT ");
3882 if(dwExStyle & WS_EX_STATICEDGE)
3883 strcat(exstyle, "WS_EX_STATICEDGE ");
3884 if(dwExStyle & WS_EX_APPWINDOW)
3885 strcat(exstyle, "WS_EX_APPWINDOW ");
3886
3887 dprintf(("Window style: %x %s", dwStyle, style));
3888 dprintf(("Window exStyle: %x %s", dwExStyle, exstyle));
3889}
3890#endif
3891//******************************************************************************
3892//******************************************************************************
Note: See TracBrowser for help on using the repository browser.