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

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

fix for GetTopWindow/GetWindow calls during WM_NCCREATE

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