source: trunk/src/user32/window.cpp@ 21916

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 78.8 KB
Line 
1/* $Id: window.cpp,v 1.140 2004-03-09 10:06:15 sandervl Exp $ */
2/*
3 * Win32 window apis for OS/2
4 *
5 * Copyright 1999-2001 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Parts based on Wine Windows code (windows\win.c, windows\property.c, windows\winpos.c)
10 *
11 * Copyright 1993, 1994, 1995 Alexandre Julliard
12 * 1995, 1996, 1999 Alex Korobka
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 *
17 * TODO: Decide what to do about commands for OS/2 windows (non-Win32 apps)
18 * TODO: ShowOwnedPopups needs to be tested
19 * GetLastActivePopup needs to be rewritten
20 *
21 */
22
23#include <odin.h>
24#include <odinwrap.h>
25#include <os2sel.h>
26
27#include <os2win.h>
28#include <misc.h>
29#include <string.h>
30#include <stdio.h>
31#include "win32wbase.h"
32#include "win32wmdiclient.h"
33#include "win32wdesktop.h"
34#include "win32dlg.h"
35#include "oslibwin.h"
36#include "oslibgdi.h"
37#include "user32.h"
38#include "winicon.h"
39#include "pmwindow.h"
40#include "oslibmsg.h"
41#include <win/winpos.h>
42#include <win/win.h>
43#include <heapstring.h>
44#include <winuser32.h>
45#include "hook.h"
46#include <wprocess.h>
47#include <custombuild.h>
48
49#define DBG_LOCALLOG DBG_window
50#include "dbglocal.h"
51
52ODINDEBUGCHANNEL(USER32-WINDOW)
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58//******************************************************************************
59//******************************************************************************
60HWND WIN32API CreateWindowExA(DWORD exStyle,
61 LPCSTR className,
62 LPCSTR windowName,
63 DWORD style,
64 INT x,
65 INT y,
66 INT width,
67 INT height,
68 HWND parent,
69 HMENU menu,
70 HINSTANCE instance,
71 LPVOID data )
72{
73 Win32BaseWindow *window;
74 ATOM classAtom;
75 CREATESTRUCTA cs;
76 char tmpClass[20];
77
78 if(exStyle & WS_EX_MDICHILD)
79 return CreateMDIWindowA(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
80
81 /* Find the class atom */
82 if (!(classAtom = GlobalFindAtomA(className)))
83 {
84 if (!HIWORD(className))
85 dprintf(("CreateWindowEx32A: bad class name %04x\n",LOWORD(className)));
86 else
87 dprintf(("CreateWindowEx32A: bad class name '%s'\n", className));
88
89 SetLastError(ERROR_INVALID_PARAMETER);
90 return 0;
91 }
92
93 // if the pointer to the classname string has the high word cleared,
94 // then it's not a pointer but a number for one of the builtin classes
95 if (!HIWORD(className))
96 {
97 sprintf(tmpClass,"#%d", (int) className);
98 className = tmpClass;
99 }
100
101 /* Create the window */
102 cs.lpCreateParams = data;
103 cs.hInstance = instance;
104 cs.hMenu = menu;
105 cs.hwndParent = parent;
106 cs.x = x;
107 cs.y = y;
108 cs.cx = width;
109 cs.cy = height;
110 cs.style = style;
111 cs.lpszName = windowName;
112 cs.lpszClass = className;
113 cs.dwExStyle = exStyle;
114
115 HOOK_CallOdinHookA(HODIN_PREWINDOWCREATEDA, 0, (DWORD)&cs);
116
117 if(HIWORD(className)) {
118 dprintf(("CreateWindowExA: window %s class %s parent %x (%d,%d) (%d,%d), %x %x menu=%x", windowName, className, parent, x, y, width, height, style, exStyle, menu));
119 }
120 else dprintf(("CreateWindowExA: window %s class %d parent %x (%d,%d) (%d,%d), %x %x menu=%x", windowName, className, parent, x, y, width, height, style, exStyle, menu));
121
122 if(!stricmp(className, MDICLIENTCLASSNAMEA)) {
123 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, FALSE);
124 }
125 else
126 if(!stricmp((char *) className, DIALOG_CLASS_NAMEA))
127 {
128 DLG_TEMPLATE dlgTemplate = {0};
129 dlgTemplate.style = cs.style;
130 dlgTemplate.exStyle = cs.dwExStyle;
131 dlgTemplate.x = cs.x;
132 dlgTemplate.y = cs.y;
133 dlgTemplate.cx = cs.cx;
134 dlgTemplate.cy = cs.cy;
135 dlgTemplate.className = cs.lpszClass;
136 dlgTemplate.caption = cs.lpszName;
137 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
138 (LPCSTR) &dlgTemplate,
139 cs.hwndParent,
140 NULL,
141 (LPARAM) data,
142 FALSE);
143 }
144 else {
145 window = new Win32BaseWindow( &cs, classAtom, FALSE );
146 }
147 if(window == NULL)
148 {
149 dprintf(("Win32BaseWindow creation failed!!"));
150 return 0;
151 }
152 if(GetLastError() != 0)
153 {
154 dprintf(("Win32BaseWindow error found!!"));
155 RELEASE_WNDOBJ(window);
156 delete window;
157 return 0;
158 }
159 HWND hwnd = window->getWindowHandle();
160
161 // set myself as last active popup / window
162 window->setLastActive( hwnd );
163
164 RELEASE_WNDOBJ(window);
165 return hwnd;
166}
167//******************************************************************************
168//******************************************************************************
169HWND WIN32API CreateWindowExW(DWORD exStyle,
170 LPCWSTR className,
171 LPCWSTR windowName,
172 DWORD style,
173 INT x,
174 INT y,
175 INT width,
176 INT height,
177 HWND parent,
178 HMENU menu,
179 HINSTANCE instance,
180 LPVOID data )
181{
182 Win32BaseWindow *window;
183 ATOM classAtom;
184 CREATESTRUCTA cs;
185 WCHAR tmpClassW[20];
186
187 if(exStyle & WS_EX_MDICHILD)
188 return CreateMDIWindowW(className, windowName, style, x, y, width, height, parent, instance, (LPARAM)data);
189
190 /* Find the class atom */
191 if (!(classAtom = GlobalFindAtomW(className)))
192 {
193 if (!HIWORD(className))
194 dprintf(("CreateWindowEx32W: bad class name %04x",LOWORD(className)));
195 else
196 dprintf(("CreateWindowEx32W: bad class name '%ls'", className));
197
198 SetLastError(ERROR_INVALID_PARAMETER);
199 return 0;
200 }
201#ifdef DEBUG
202 if(HIWORD(className)) {
203 dprintf(("CreateWindowExW: class %ls name %ls parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle, menu));
204 }
205 else dprintf(("CreateWindowExW: class %d name %ls parent %x (%d,%d) (%d,%d), %x %x menu=%x", className, HIWORD(windowName) ? windowName : NULL, parent, x, y, width, height, style, exStyle, menu));
206#endif
207 // if the pointer to the classname string has the high word cleared,
208 // then it's not a pointer but a number for one of the builtin classes
209 if (!HIWORD(className))
210 {
211 wsprintfW(tmpClassW, (LPCWSTR)L"#%d", (int) className);
212 className = tmpClassW;
213 }
214
215 /* Create the window */
216 cs.lpCreateParams = data;
217 cs.hInstance = instance;
218 cs.hMenu = menu;
219 cs.hwndParent = parent;
220 cs.x = x;
221 cs.y = y;
222 cs.cx = width;
223 cs.cy = height;
224 cs.style = style;
225 cs.lpszName = (LPSTR)windowName;
226 cs.lpszClass = (LPSTR)className;
227 cs.dwExStyle = exStyle;
228
229 if(!lstrcmpiW(className, (LPWSTR)MDICLIENTCLASSNAMEW)) {
230 window = (Win32BaseWindow *) new Win32MDIClientWindow(&cs, classAtom, TRUE);
231 }
232 else
233 if(!lstrcmpiW(className, (LPWSTR)DIALOG_CLASS_NAMEW))
234 {
235 DLG_TEMPLATE dlgTemplate = {0};
236 dlgTemplate.style = cs.style;
237 dlgTemplate.exStyle = cs.dwExStyle;
238 dlgTemplate.x = cs.x;
239 dlgTemplate.y = cs.y;
240 dlgTemplate.cx = cs.cx;
241 dlgTemplate.cy = cs.cy;
242 dlgTemplate.className = cs.lpszClass;
243 dlgTemplate.caption = cs.lpszName;
244 window = (Win32BaseWindow *) new Win32Dialog(cs.hInstance,
245 (LPCSTR) &dlgTemplate,
246 cs.hwndParent,
247 NULL,
248 (LPARAM) data,
249 TRUE);
250 }
251 else {
252 window = new Win32BaseWindow( &cs, classAtom, TRUE );
253 }
254 if(window == NULL)
255 {
256 dprintf(("Win32BaseWindow creation failed!!"));
257 return 0;
258 }
259 if(GetLastError() != 0)
260 {
261 dprintf(("Win32BaseWindow error found!!"));
262 RELEASE_WNDOBJ(window);
263 delete window;
264 return 0;
265 }
266 HWND hwnd = window->getWindowHandle();
267
268 // set myself as last active popup / window
269 window->setLastActive( hwnd );
270
271 RELEASE_WNDOBJ(window);
272 return hwnd;
273}
274//******************************************************************************
275//******************************************************************************
276BOOL WIN32API DestroyWindow(HWND hwnd)
277{
278 Win32BaseWindow *window;
279 BOOL ret;
280
281 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
282 if(!window) {
283 dprintf(("DestroyWindow, window %x not found", hwnd));
284 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
285 return 0;
286 }
287 ret = window->DestroyWindow();
288 RELEASE_WNDOBJ(window);
289 return ret;
290}
291//******************************************************************************
292//******************************************************************************
293HWND WIN32API SetActiveWindow(HWND hwnd)
294{
295 Win32BaseWindow *window;
296 HWND hwndActive;
297
298 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
299 if(!window) {
300 dprintf(("SetActiveWindow, window %x not found", hwnd));
301 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
302 return 0;
303 }
304 hwndActive = window->SetActiveWindow();
305
306 // check last active popup window
307 if (hwndActive)
308 {
309 // TODO:
310 // set last active popup window to the ancestor window
311 dprintf(("support for last active popup incorrectly implemented"));
312 }
313
314 RELEASE_WNDOBJ(window);
315 return hwndActive;
316}
317//******************************************************************************
318//Note: does not set last error if no parent (verified in NT4, SP6)
319//******************************************************************************
320HWND WIN32API GetParent(HWND hwnd)
321{
322 Win32BaseWindow *window;
323 HWND hwndParent;
324
325 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
326 if(!window) {
327 dprintf(("GetParent, window %x not found", hwnd));
328 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
329 return 0;
330 }
331 dprintf2(("GetParent %x", hwnd));
332 hwndParent = window->GetParent();
333 RELEASE_WNDOBJ(window);
334 return hwndParent;
335}
336//******************************************************************************
337//******************************************************************************
338HWND WIN32API SetParent(HWND hwndChild, HWND hwndNewParent)
339{
340 Win32BaseWindow *window;
341 HWND hwndOldParent;
342
343 window = Win32BaseWindow::GetWindowFromHandle(hwndChild);
344 if(!window) {
345 dprintf(("SetParent, window %x not found", hwndChild));
346 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
347 return 0;
348 }
349 if(hwndNewParent == HWND_DESKTOP) {
350 hwndNewParent = GetDesktopWindow();
351 }
352 else {
353 if(!IsWindow(hwndNewParent)) {
354 RELEASE_WNDOBJ(window);
355 dprintf(("SetParent, parent %x not found", hwndNewParent));
356 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
357 return 0;
358 }
359 }
360 dprintf(("SetParent %x %x", hwndChild, hwndNewParent));
361 hwndOldParent = window->SetParent(hwndNewParent);
362 RELEASE_WNDOBJ(window);
363 return hwndOldParent;
364}
365//******************************************************************************
366//******************************************************************************
367BOOL WIN32API IsChild(HWND hwndParent, HWND hwnd)
368{
369 Win32BaseWindow *window;
370 BOOL fIsChild;
371
372 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
373 if(!window) {
374 dprintf(("IsChild %x, window %x not found", hwndParent, hwnd));
375 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
376 return 0;
377 }
378 dprintf(("IsChild %x %x", hwndParent, hwnd));
379 fIsChild = window->IsChild(hwndParent);
380 RELEASE_WNDOBJ(window);
381 return fIsChild;
382}
383//******************************************************************************
384//******************************************************************************
385HWND WIN32API GetTopWindow(HWND hwnd)
386{
387 Win32BaseWindow *window;
388 HWND hwndTop;
389
390 if(hwnd == HWND_DESKTOP) {
391 windowDesktop->addRef();
392 window = windowDesktop;
393 }
394 else {
395 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
396 if(!window) {
397 dprintf(("GetTopWindow, window %x not found", hwnd));
398 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
399 return 0;
400 }
401 }
402 hwndTop = window->GetTopWindow();
403 dprintf2(("GetTopWindow %x returned %x", hwnd, hwndTop));
404 RELEASE_WNDOBJ(window);
405 return hwndTop;
406}
407//******************************************************************************
408//******************************************************************************
409BOOL WIN32API IsIconic(HWND hwnd)
410{
411 Win32BaseWindow *window;
412 BOOL fIsIconic;
413
414 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
415 if(!window) {
416 dprintf(("IsIconic, window %x not found", hwnd));
417 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
418 return FALSE;
419 }
420 fIsIconic = window->IsWindowIconic();
421 dprintf(("IsIconic %x returned %d", hwnd, fIsIconic));
422 RELEASE_WNDOBJ(window);
423 return fIsIconic;
424}
425//******************************************************************************
426//******************************************************************************
427HWND WIN32API GetWindow(HWND hwnd, UINT uCmd)
428{
429 Win32BaseWindow *window;
430 HWND hwndRelated;
431
432 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
433 if(!window) {
434 dprintf(("GetWindow, window %x not found", hwnd));
435 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
436 return 0;
437 }
438 hwndRelated = window->GetWindow(uCmd);
439 RELEASE_WNDOBJ(window);
440 return hwndRelated;
441}
442
443/******************************************************************************
444 * GetWindowInfo (USER32.@)
445 *
446 * Note: tests show that Windows doesn't check cbSize of the structure.
447 */
448BOOL WINAPI GetWindowInfo( HWND hwnd, PWINDOWINFO pwi)
449{
450 if (!pwi) return FALSE;
451 if (!IsWindow(hwnd)) return FALSE;
452
453 GetWindowRect(hwnd, &pwi->rcWindow);
454 GetClientRect(hwnd, &pwi->rcClient);
455 /* translate to screen coordinates */
456 MapWindowPoints(hwnd, 0, (LPPOINT)&pwi->rcClient, 2);
457
458 pwi->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
459 pwi->dwExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
460 pwi->dwWindowStatus = ((GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0);
461
462 pwi->cxWindowBorders = pwi->rcClient.left - pwi->rcWindow.left;
463 pwi->cyWindowBorders = pwi->rcWindow.bottom - pwi->rcClient.bottom;
464
465 pwi->atomWindowType = GetClassLongW( hwnd, GCW_ATOM );
466 pwi->wCreatorVersion = 0x0400;
467
468 return TRUE;
469}
470
471//******************************************************************************
472//******************************************************************************
473BOOL WIN32API EnableWindow(HWND hwnd, BOOL fEnable)
474{
475 Win32BaseWindow *window;
476 BOOL fEnabled;
477
478 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
479 if(!window) {
480 dprintf(("EnableWindow, window %x not found", hwnd));
481 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
482 return 0;
483 }
484 dprintf(("EnableWindow %x %d", hwnd, fEnable));
485 fEnabled = window->EnableWindow(fEnable);
486 RELEASE_WNDOBJ(window);
487 return fEnabled;
488}
489//******************************************************************************
490//******************************************************************************
491BOOL WIN32API BringWindowToTop(HWND hwnd)
492{
493 dprintf(("BringWindowToTop %x", hwnd));
494 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
495}
496/***********************************************************************
497 * SetInternalWindowPos (USER32.483)
498 */
499VOID WIN32API SetInternalWindowPos(HWND hwnd, UINT showCmd, LPRECT lpRect,
500 LPPOINT lpPoint )
501{
502 if( IsWindow(hwnd) )
503 {
504 WINDOWPLACEMENT wndpl;
505 UINT flags;
506
507 GetWindowPlacement(hwnd, &wndpl);
508 wndpl.length = sizeof(wndpl);
509 wndpl.showCmd = showCmd;
510 wndpl.flags = 0;
511
512 if(lpPoint)
513 {
514 wndpl.flags |= WPF_SETMINPOSITION;
515 wndpl.ptMinPosition = *lpPoint;
516 }
517 if(lpRect)
518 {
519 wndpl.rcNormalPosition = *lpRect;
520 }
521 SetWindowPlacement(hwnd, &wndpl);
522 }
523
524}
525/***********************************************************************
526 * GetInternalWindowPos (USER32.245)
527 */
528UINT WIN32API GetInternalWindowPos(HWND hwnd, LPRECT rectWnd, LPPOINT ptIcon )
529{
530 WINDOWPLACEMENT wndpl;
531
532 if(GetWindowPlacement( hwnd, &wndpl ))
533 {
534 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
535 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
536 return wndpl.showCmd;
537 }
538 return 0;
539}
540//******************************************************************************
541//******************************************************************************
542HWND GetActiveWindow()
543{
544 return Win32BaseWindow::GetActiveWindow();
545}
546//******************************************************************************
547//******************************************************************************
548BOOL WIN32API ShowWindow(HWND hwnd, INT nCmdShow)
549{
550 Win32BaseWindow *window;
551 BOOL ret;
552
553 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
554 if(!window) {
555 dprintf(("ShowWindow, window %x not found", hwnd));
556 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
557 return 0;
558 }
559
560 //PF Start PM restoration routine first if we restore from icon
561 //so all internal PM logic will work - this routine will always
562 //lead to ShowWindow(SW_RESTORE)
563
564 if ((nCmdShow == SW_RESTORE) && (window->getStyle() & WS_MINIMIZE) && fOS2Look )
565 {
566 dprintf(("ShowWindow: Initiating OS/2 PM restore"));
567 ret = OSLibWinRestoreWindow(window->getOS2FrameWindowHandle());
568 }
569 else
570 ret = window->ShowWindow(nCmdShow);
571 RELEASE_WNDOBJ(window);
572 return ret;
573}
574/*****************************************************************************
575 * Name : BOOL WIN32API ShowWindowAsync
576 * Purpose : The ShowWindowAsync function sets the show state of a window
577 * created by a different thread.
578 * Parameters: HWND hwnd handle of window
579 * int nCmdShow show state of window
580 * Variables :
581 * Result : If the window was previously visible, the return value is TRUE.
582 * If the window was previously hidden, the return value is FALSE.
583 * Remark :
584 * Status : UNTESTED STUB
585 *
586 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
587 *****************************************************************************/
588BOOL WIN32API ShowWindowAsync(HWND hwnd, int nCmdShow)
589{
590 dprintf(("USER32:ShowWindowAsync (%08xh,%08x) not correctly implemented.\n",
591 hwnd, nCmdShow));
592
593 return ShowWindow(hwnd, nCmdShow);
594}
595//******************************************************************************
596//******************************************************************************
597BOOL WIN32API SetWindowPos(HWND hwnd, HWND hwndInsertAfter, INT x,
598 INT y, INT cx, INT cy, UINT fuFlags)
599{
600 Win32BaseWindow *window;
601
602 if (!hwnd)
603 {
604 dprintf(("SetWindowPos: Can't move desktop!"));
605 return TRUE;
606 }
607 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
608 if(!window) {
609 dprintf(("SetWindowPos, window %x not found", hwnd));
610 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
611 return FALSE;
612 }
613 dprintf(("SetWindowPos %x %x x=%d y=%d cx=%d cy=%d %x", hwnd, hwndInsertAfter, x, y, cx, cy, fuFlags));
614 BOOL ret = window->SetWindowPos(hwndInsertAfter, x, y, cx, cy, fuFlags);
615 RELEASE_WNDOBJ(window);
616 return ret;
617}
618//******************************************************************************
619//NOTE: length must equal structure size or else api fails (verified in NT4, SP6)
620//******************************************************************************
621BOOL WIN32API SetWindowPlacement(HWND hwnd, const WINDOWPLACEMENT *winpos)
622{
623 Win32BaseWindow *window;
624
625 if(!winpos || winpos->length != sizeof(WINDOWPLACEMENT)) {
626 dprintf(("SetWindowPlacement %x invalid parameter", hwnd));
627 SetLastError(ERROR_INVALID_PARAMETER);
628 return FALSE;
629 }
630 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
631 if(!window) {
632 dprintf(("SetWindowPlacement, window %x not found", hwnd));
633 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
634 return FALSE;
635 }
636 dprintf(("USER32: SetWindowPlacement %x %x", hwnd, winpos));
637 BOOL ret = window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
638 RELEASE_WNDOBJ(window);
639 return ret;
640}
641//******************************************************************************
642//NOTE: Length does not need to be correct (even though the SDK docs claim otherwise)
643// (Verified in NT4, SP6)
644//******************************************************************************
645BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT winpos)
646{
647 Win32BaseWindow *window;
648
649 if(!winpos) {
650 dprintf(("GetWindowPlacement %x invalid parameter", hwnd));
651 SetLastError(ERROR_INVALID_PARAMETER);
652 return FALSE;
653 }
654 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
655 if(!window) {
656 dprintf(("GetWindowPlacement, window %x not found", hwnd));
657 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
658 return FALSE;
659 }
660 dprintf(("USER32: GetWindowPlacement %x %x", hwnd, winpos));
661 BOOL ret = window->GetWindowPlacement(winpos);
662 RELEASE_WNDOBJ(window);
663 return ret;
664}
665//******************************************************************************
666//******************************************************************************
667BOOL WIN32API IsWindow(HWND hwnd)
668{
669 Win32BaseWindow *window;
670
671 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
672 if(!window) {
673 dprintf(("IsWindow, window %x not found", hwnd));
674 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
675 return FALSE;
676 }
677 dprintf2(("IsWindow %x", hwnd));
678 BOOL fIsWindow = window->IsWindow();
679 RELEASE_WNDOBJ(window);
680 return fIsWindow;
681}
682//******************************************************************************
683//******************************************************************************
684BOOL WIN32API IsWindowEnabled(HWND hwnd)
685{
686 DWORD dwStyle;
687
688 if(!IsWindow(hwnd)) {
689 dprintf(("IsWindowEnabled, window %x not found", hwnd));
690 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
691 return 0;
692 }
693 dprintf(("IsWindowEnabled %x", hwnd));
694 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
695 if(dwStyle & WS_DISABLED) {
696 return FALSE;
697 }
698 return TRUE;
699}
700//******************************************************************************
701//******************************************************************************
702BOOL WIN32API IsWindowVisible(HWND hwnd)
703{
704 BOOL ret;
705 HWND hwndParent;
706 DWORD dwStyle;
707
708 if(hwnd == HWND_DESKTOP) {//TODO: verify in NT!
709 dprintf(("IsWindowVisible DESKTOP returned TRUE"));
710 return TRUE; //desktop is always visible
711 }
712 if(!IsWindow(hwnd)) {
713 dprintf(("IsWindowVisible, window %x not found", hwnd));
714 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
715 return 0;
716 }
717 //check visibility of this window
718 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
719 if(!(dwStyle & WS_VISIBLE)) {
720 ret = FALSE;
721 goto end;
722 }
723 ret = TRUE;
724
725 if(dwStyle & WS_CHILD)
726 {
727 //check visibility of parents
728 hwndParent = GetParent(hwnd);
729 while(hwndParent) {
730 dwStyle = GetWindowLongA(hwndParent, GWL_STYLE);
731 if(!(dwStyle & WS_VISIBLE)) {
732 dprintf(("IsWindowVisible %x returned FALSE (parent %x invisible)", hwnd, hwndParent));
733 return FALSE;
734 }
735 if(!(dwStyle & WS_CHILD)) {
736 break; //GetParent can also return the owner
737 }
738 hwndParent = GetParent(hwndParent);
739 }
740 }
741end:
742 dprintf(("IsWindowVisible %x returned %d", hwnd, ret));
743 return ret;
744}
745//******************************************************************************
746//******************************************************************************
747HWND WINAPI GetAncestor( HWND hwnd, UINT type )
748{
749 HWND hwndAncestor = 0;
750 Win32BaseWindow *window;
751
752 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
753 if(!window) {
754 dprintf(("GetAncestor, window %x not found", hwnd));
755 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
756 return FALSE;
757 }
758
759 if (type == GA_PARENT)
760 {
761 LONG dwStyle = GetWindowLongW( hwnd, GWL_STYLE );
762 if(dwStyle & WS_CHILD) {
763 hwndAncestor = GetParent(hwnd);
764 }
765 //else no child -> no parent (GetParent returns owner otherwise!)
766 }
767 else
768 if (type == GA_ROOT)
769 {
770 hwndAncestor = window->GetTopParent();
771 }
772 else
773 if (type == GA_ROOTOWNER)
774 {
775 if(hwnd != GetDesktopWindow())
776 {
777 hwndAncestor = hwnd;
778 for(;;)
779 {
780 HWND parent = GetParent( hwndAncestor );
781 if (!parent) break;
782 hwndAncestor = parent;
783 }
784 }
785 }
786 else dprintf(("Unsupported type %d", type));
787
788 RELEASE_WNDOBJ(window);
789 return hwndAncestor;
790}
791//******************************************************************************
792BOOL fIgnoreKeystrokes = FALSE;
793//******************************************************************************
794void SetFocusChanged()
795{
796 //Focus has changed; invalidate SetFocus(0) state
797 fIgnoreKeystrokes = FALSE;
798}
799//******************************************************************************
800//******************************************************************************
801HWND WIN32API SetFocus(HWND hwnd)
802{
803 Win32BaseWindow *window;
804 Win32BaseWindow *oldfocuswnd;
805 HWND lastFocus, lastFocus_W, hwnd_O, hwndTopParent, hwndTop;
806 BOOL activate, ret;
807 TEB *teb;
808
809 dprintf(("SetFocus %x", hwnd));
810 teb = GetThreadTEB();
811 if(teb == NULL) {
812 DebugInt3();
813 return 0;
814 }
815 //Special case; SetFocus(0) tells Windows to ignore keystrokes. Pressing
816 //a key now generates WM_SYSKEYDOWN/(WM_SYSCHAR)/WM_SYSKEYUP instead
817 //of WM_KEYDOWN/(WM_CHAR)/WM_KEYUP
818 //WM_KILLFOCUS is sent to the window that currently has focus
819 if(hwnd == 0) {
820 lastFocus_W = GetFocus();
821 if(lastFocus_W == 0) return 0; //nothing to do
822
823 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)lastFocus_W)) {
824 dprintf(("hook cancelled SetFocus call!"));
825 return 0;
826 }
827 fIgnoreKeystrokes = TRUE;
828 SendMessageA(lastFocus_W, WM_KILLFOCUS, 0, 0);
829
830 return lastFocus_W;
831 }
832
833 //SetFocus is not allowed for minimized or disabled windows (this window
834 //or any parent)
835 hwndTop = hwnd;
836 for (;;)
837 {
838 HWND parent;
839
840 LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
841 if (style & (WS_MINIMIZE | WS_DISABLED)) {
842 dprintf(("SetFocus, %x not allowed on minimized or disabled window (%x)", hwnd, style));
843 return 0;
844 }
845 parent = GetAncestor(hwndTop, GA_PARENT);
846 if (!parent || parent == GetDesktopWindow()) break;
847 hwndTop = parent;
848 }
849
850 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
851 if(!window) {
852 dprintf(("SetFocus, window %x not found", hwnd));
853 //Note: last error not set (NT4, SP6), returns current focus window
854 //SetLastError(ERROR_INVALID_WINDOW_HANDLE);
855 return GetFocus();
856 }
857
858 hwnd_O = window->getOS2WindowHandle();
859 lastFocus = OSLibWinQueryFocus (OSLIB_HWND_DESKTOP);
860
861 hwndTopParent = window->GetTopParent();
862 activate = FALSE;
863 lastFocus_W = OS2ToWin32Handle(lastFocus);
864 if(lastFocus_W) {
865 oldfocuswnd = Win32BaseWindow::GetWindowFromHandle(lastFocus_W);
866 if(lastFocus_W != hwnd && hwndTopParent != oldfocuswnd->GetTopParent()) {
867 activate = TRUE;
868 }
869 RELEASE_WNDOBJ(oldfocuswnd);
870 }
871 else activate = TRUE;
872
873 dprintf(("SetFocus %x (%x) -> %x (%x) act %d", lastFocus_W, lastFocus, hwnd, hwnd_O, activate));
874
875 if(HOOK_CallHooksA(WH_CBT, HCBT_SETFOCUS, hwnd, (LPARAM)lastFocus_W)) {
876 dprintf(("hook cancelled SetFocus call!"));
877 RELEASE_WNDOBJ(window);
878 return 0;
879 }
880
881 if(!IsWindow(hwnd)) return FALSE; //abort if window destroyed
882
883 //NOTE: Don't always activate the window or else the z-order will be changed!!
884 ret = (OSLibWinSetFocus(OSLIB_HWND_DESKTOP, hwnd_O, activate)) ? lastFocus_W : 0;
885 RELEASE_WNDOBJ(window);
886
887 //If keystrokes were ignored and focus is set to the old focus window, then
888 //PM won't send us a WM_SETFOCUS message. (as we don't inform PM for SetFocus(0))
889 if(fIgnoreKeystrokes && lastFocus_W == hwnd) {
890 dprintf(("Manually send WM_SETFOCUS; real focus window hasn't changed"));
891 SendMessageA(lastFocus_W, WM_SETFOCUS, 0, 0);
892 }
893 fIgnoreKeystrokes = FALSE;
894 return ret;
895}
896//******************************************************************************
897//******************************************************************************
898HWND WIN32API GetFocus()
899{
900 TEB *teb;
901 HWND hwnd;
902
903 teb = GetThreadTEB();
904 if(teb == NULL) {
905 DebugInt3();
906 return 0;
907 }
908 //If keystrokes are ignored (SetFocus(0)), then return 0
909 if(fIgnoreKeystrokes) {
910 dprintf(("GetFocus; returning 0 after SetFocus(0) call"));
911 return 0;
912 }
913 hwnd = OSLibWinQueryFocus(OSLIB_HWND_DESKTOP);
914 hwnd = OS2ToWin32Handle(hwnd);
915 dprintf(("USER32: GetFocus %x\n", hwnd));
916 return hwnd;
917}
918//******************************************************************************
919//******************************************************************************
920BOOL WIN32API GetGUIThreadInfo(DWORD dwThreadId, GUITHREADINFO *lpThreadInfo)
921{
922 dprintf(("!WARNING!: GetGUIThreadInfo not completely implemented!!"));
923
924 if(!lpThreadInfo || lpThreadInfo->cbSize != sizeof(GUITHREADINFO)) {
925 SetLastError(ERROR_INVALID_PARAMETER);
926 return FALSE;
927 }
928 //dwThreadId == 0 -> current thread
929 if(!dwThreadId) dwThreadId = GetCurrentThreadId();
930
931 lpThreadInfo->flags;
932 lpThreadInfo->hwndActive = GetActiveWindow();
933 if(lpThreadInfo->hwndActive) {
934 if(dwThreadId != GetWindowThreadProcessId(lpThreadInfo->hwndActive, NULL))
935 {//this thread doesn't own the active window (TODO: correct??)
936 lpThreadInfo->hwndActive = 0;
937 }
938 }
939 lpThreadInfo->hwndFocus = GetFocus();
940 lpThreadInfo->hwndCapture = GetCapture();
941 lpThreadInfo->flags = 0; //TODO:
942 lpThreadInfo->hwndMenuOwner = 0; //TODO: Handle to the window that owns any active menus
943 lpThreadInfo->hwndMoveSize = 0; //TODO: Handle to the window in a move or size loop.
944 lpThreadInfo->hwndCaret = 0; //TODO: Handle to the window that is displaying the caret
945 lpThreadInfo->rcCaret.left = 0;
946 lpThreadInfo->rcCaret.top = 0;
947 lpThreadInfo->rcCaret.right = 0;
948 lpThreadInfo->rcCaret.bottom = 0;
949
950 SetLastError(ERROR_SUCCESS);
951 return TRUE;
952}
953//******************************************************************************
954//******************************************************************************
955BOOL WIN32API IsZoomed(HWND hwnd)
956{
957 DWORD style;
958
959 style = GetWindowLongA(hwnd, GWL_STYLE);
960 dprintf(("USER32: IsZoomed %x returned %d", hwnd, ((style & WS_MAXIMIZE) != 0)));
961
962 return (style & WS_MAXIMIZE) != 0;
963}
964//******************************************************************************
965//******************************************************************************
966BOOL WIN32API LockWindowUpdate(HWND hwnd)
967{
968 return OSLibWinLockWindowUpdate(Win32ToOS2Handle(hwnd));
969}
970//******************************************************************************
971//******************************************************************************
972BOOL WIN32API GetWindowRect(HWND hwnd, PRECT pRect)
973{
974 Win32BaseWindow *window;
975
976 if(pRect == NULL) {
977 dprintf(("GetWindowRect %x invalid parameter!", hwnd));
978 SetLastError(ERROR_INVALID_PARAMETER);
979 return FALSE;
980 }
981
982 if(hwnd == HWND_DESKTOP) {
983 windowDesktop->addRef();
984 window = windowDesktop;
985 }
986 else window = Win32BaseWindow::GetWindowFromHandle(hwnd);
987
988 if(!window) {
989 dprintf(("GetWindowRect, window %x not found", hwnd));
990 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
991 return FALSE;
992 }
993 *pRect = *window->getWindowRect();
994
995 //convert from parent coordinates to screen (if necessary)
996 if(window->getParent()) {
997 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
998 }
999 RELEASE_WNDOBJ(window);
1000 dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
1001 return TRUE;
1002}
1003//******************************************************************************
1004//******************************************************************************
1005INT WIN32API GetWindowTextLengthA(HWND hwnd)
1006{
1007 Win32BaseWindow *window;
1008
1009 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1010 if(!window) {
1011 dprintf(("GetWindowTextLengthA, window %x not found", hwnd));
1012 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1013 return 0;
1014 }
1015 dprintf(("GetWindowTextLengthA %x", hwnd));
1016 int ret = window->GetWindowTextLengthA();
1017 RELEASE_WNDOBJ(window);
1018 return ret;
1019}
1020//******************************************************************************
1021//******************************************************************************
1022int WIN32API GetWindowTextA( HWND hwnd, LPSTR lpsz, int cch)
1023{
1024 Win32BaseWindow *window;
1025 int rc;
1026
1027 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1028 if(!window) {
1029 dprintf(("GetWindowTextA, window %x not found", hwnd));
1030 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1031 return 0;
1032 }
1033 rc = window->GetWindowTextA(lpsz, cch);
1034 dprintf(("GetWindowTextA %x %s", hwnd, lpsz));
1035 RELEASE_WNDOBJ(window);
1036 return rc;
1037}
1038//******************************************************************************
1039//******************************************************************************
1040int WIN32API GetWindowTextLengthW( HWND hwnd)
1041{
1042 Win32BaseWindow *window;
1043
1044 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1045 if(!window) {
1046 dprintf(("GetWindowTextLengthW, window %x not found", hwnd));
1047 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1048 return 0;
1049 }
1050 dprintf(("GetWindowTextLengthW %x", hwnd));
1051 int ret = window->GetWindowTextLengthW();
1052 RELEASE_WNDOBJ(window);
1053 return ret;
1054}
1055//******************************************************************************
1056//******************************************************************************
1057int WIN32API GetWindowTextW(HWND hwnd, LPWSTR lpsz, int cch)
1058{
1059 Win32BaseWindow *window;
1060
1061 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1062 if(!window) {
1063 dprintf(("GetWindowTextW, window %x not found", hwnd));
1064 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1065 return 0;
1066 }
1067 int rc = window->GetWindowTextW(lpsz, cch);
1068 RELEASE_WNDOBJ(window);
1069 dprintf(("GetWindowTextW %x %ls", hwnd, lpsz));
1070 return rc;
1071}
1072//******************************************************************************
1073//******************************************************************************
1074BOOL WIN32API SetWindowTextA(HWND hwnd, LPCSTR lpsz)
1075{
1076 Win32BaseWindow *window;
1077
1078 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1079 if(!window) {
1080 dprintf(("SetWindowTextA, window %x not found", hwnd));
1081 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1082 return 0;
1083 }
1084 dprintf(("SetWindowTextA %x %s", hwnd, lpsz));
1085 BOOL ret = window->SetWindowTextA((LPSTR)lpsz);
1086 RELEASE_WNDOBJ(window);
1087 return ret;
1088}
1089//******************************************************************************
1090//******************************************************************************
1091BOOL WIN32API SetWindowTextW( HWND hwnd, LPCWSTR lpsz)
1092{
1093 Win32BaseWindow *window;
1094
1095 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1096 if(!window) {
1097 dprintf(("SetWindowTextA, window %x not found", hwnd));
1098 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1099 return 0;
1100 }
1101 dprintf(("SetWindowTextW %x %ls", hwnd, lpsz));
1102 BOOL ret = window->SetWindowTextW((LPWSTR)lpsz);
1103 RELEASE_WNDOBJ(window);
1104 return ret;
1105}
1106/*******************************************************************
1107 * InternalGetWindowText (USER32.326)
1108 */
1109int WIN32API InternalGetWindowText(HWND hwnd,
1110 LPWSTR lpString,
1111 INT nMaxCount )
1112{
1113 dprintf(("USER32: InternalGetWindowText(%08xh,%08xh,%08xh) not properly implemented.\n",
1114 hwnd, lpString, nMaxCount));
1115
1116 return GetWindowTextW(hwnd, lpString,nMaxCount);
1117}
1118//******************************************************************************
1119//TODO: Correct?
1120//******************************************************************************
1121BOOL WIN32API SetForegroundWindow(HWND hwnd)
1122{
1123 dprintf((" SetForegroundWindow %x", hwnd));
1124
1125 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1126}
1127//******************************************************************************
1128//******************************************************************************
1129BOOL WIN32API GetClientRect( HWND hwnd, PRECT pRect)
1130{
1131 HWND hwndWin32 = hwnd;
1132 Win32BaseWindow *window;
1133
1134 if (!pRect)
1135 {
1136 SetLastError(ERROR_INVALID_PARAMETER);
1137 return FALSE;
1138 }
1139 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1140 if(!window) {
1141 dprintf(("GetClientRect, window %x not found", hwnd));
1142 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1143 return FALSE;
1144 }
1145 window->getClientRect(pRect);
1146 dprintf(("GetClientRect of %X returned (%d,%d) (%d,%d)\n", hwndWin32, pRect->left, pRect->top, pRect->right, pRect->bottom));
1147 RELEASE_WNDOBJ(window);
1148 return TRUE;
1149}
1150//******************************************************************************
1151//******************************************************************************
1152BOOL WIN32API AdjustWindowRect(PRECT rect, DWORD style, BOOL menu)
1153{
1154 return AdjustWindowRectEx(rect, style, menu, 0);
1155}
1156//******************************************************************************
1157//Calculate window rectangle based on given client rectangle, style, menu and extended style
1158//******************************************************************************
1159BOOL WIN32API AdjustWindowRectEx( PRECT rect, DWORD style, BOOL menu, DWORD exStyle)
1160{
1161 if(style == 0 && menu == FALSE && exStyle == 0) {
1162 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d) -> no change required", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1163 return TRUE; //nothing needs to be changed (VERIFIED in NT 4)
1164 }
1165 dprintf(("AdjustWindowRectEx %x %x %d (%d,%d)(%d,%d)\n", style, exStyle, menu, rect->left, rect->top, rect->right, rect->bottom));
1166 /* Correct the window style */
1167 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
1168 style |= WS_CAPTION;
1169
1170 //SvL: Include WS_POPUP -> otherwise HAS_THINFRAME is true for popup windows
1171 // Also include WS_CHILD -> otherwise HAS_THICKFRAME doesn't work correctly
1172 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_POPUP);
1173 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
1174 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
1175
1176 //Adjust rect outer (Win32BaseWindow::AdjustRectOuter)
1177 if (HAS_THICKFRAME(style,exStyle))
1178 InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
1179 else
1180 if (HAS_DLGFRAME(style,exStyle))
1181 InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
1182 else
1183 if (HAS_THINFRAME(style))
1184 InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1185
1186 if ((style & WS_CAPTION) == WS_CAPTION)
1187 {
1188 if (exStyle & WS_EX_TOOLWINDOW)
1189 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1190 else
1191 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1192 }
1193
1194 if (menu)
1195 rect->top -= GetSystemMetrics(SM_CYMENU);
1196
1197 //Adjust rect inner (Win32BaseWindow::AdjustRectInner)
1198 if(!(style & WS_ICONIC)) {
1199 if (exStyle & WS_EX_CLIENTEDGE)
1200 InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1201
1202 if (exStyle & WS_EX_STATICEDGE)
1203 InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
1204
1205 //SvL: scrollbars aren't checked *UNLESS* the style includes a border (any border)
1206 // --> VERIFIED IN NT4, SP6 (fixes MFC apps with scrollbars + bar controls)
1207 if(style & (WS_THICKFRAME|WS_BORDER|WS_DLGFRAME)) {
1208 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
1209 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1210 }
1211 }
1212
1213 dprintf(("AdjustWindowRectEx returned (%d,%d)(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom));
1214
1215 return TRUE;
1216}
1217//******************************************************************************
1218/* Coordinate Space and Transformation Functions */
1219//******************************************************************************
1220/*******************************************************************
1221 * WINPOS_GetWinOffset
1222 *
1223 * Calculate the offset between the origin of the two windows. Used
1224 * to implement MapWindowPoints.
1225 */
1226static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
1227 POINT *offset )
1228{
1229 Win32BaseWindow *window;
1230
1231 offset->x = offset->y = 0;
1232
1233 /* Translate source window origin to screen coords */
1234 if(wndFrom != windowDesktop)
1235 {
1236 window = wndFrom;
1237 while(window)
1238 {
1239 offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
1240 offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
1241 window = window->getParent();
1242 }
1243 }
1244
1245 /* Translate origin to destination window coords */
1246 if(wndTo != windowDesktop)
1247 {
1248 window = wndTo;
1249 while(window)
1250 {
1251 offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
1252 offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
1253 window = window->getParent();
1254 }
1255 }
1256}
1257//******************************************************************************
1258//******************************************************************************
1259int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
1260 UINT cPoints)
1261{
1262 Win32BaseWindow *wndfrom, *wndto;
1263 int retval = 0;
1264 POINT offset;
1265
1266 SetLastError(0);
1267 if(lpPoints == NULL || cPoints == 0) {
1268 dprintf(("MapWindowPoints error: lpPoints %p, cPoints %d", lpPoints, cPoints));
1269 SetLastError(ERROR_INVALID_PARAMETER);
1270 return 0;
1271 }
1272 if(hwndTo == hwndFrom)
1273 return 0; //nothing to do
1274
1275 if(hwndFrom == HWND_DESKTOP)
1276 {
1277 windowDesktop->addRef();
1278 wndfrom = windowDesktop;
1279 }
1280 else {
1281 wndfrom = Win32BaseWindow::GetWindowFromHandle(hwndFrom);
1282 if(!wndfrom) {
1283 dprintf(("MapWindowPoints, window %x not found", hwndFrom));
1284 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1285 return 0;
1286 }
1287 }
1288
1289 if(hwndTo == HWND_DESKTOP)
1290 {
1291 windowDesktop->addRef();
1292 wndto = windowDesktop;
1293 }
1294 else {
1295 wndto = Win32BaseWindow::GetWindowFromHandle(hwndTo);
1296 if(!wndto) {
1297 dprintf(("MapWindowPoints, window %x not found", hwndTo));
1298 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1299 return 0;
1300 }
1301 }
1302
1303 dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
1304 WINPOS_GetWinOffset(wndfrom, wndto, &offset);
1305
1306 RELEASE_WNDOBJ(wndto);
1307 RELEASE_WNDOBJ(wndfrom);
1308 for(int i=0;i<cPoints;i++)
1309 {
1310 lpPoints[i].x += offset.x;
1311 lpPoints[i].y += offset.y;
1312 }
1313 retval = ((LONG)offset.y << 16) | offset.x;
1314 return retval;
1315}
1316//******************************************************************************
1317//******************************************************************************
1318BOOL WIN32API ScreenToClient(HWND hwnd, LPPOINT pt)
1319{
1320 PRECT rcl;
1321 BOOL rc;
1322
1323 if(hwnd == HWND_DESKTOP) {
1324 return (TRUE); //nothing to do
1325 }
1326 if (!IsWindow(hwnd)) {
1327 dprintf(("warning: ScreenToClient: window %x not found!", hwnd));
1328 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1329 return FALSE;
1330 }
1331 SetLastError(0);
1332#ifdef DEBUG
1333 POINT tmp = *pt;
1334#endif
1335 MapWindowPoints(0, hwnd, pt, 1);
1336 dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1337 return TRUE;
1338}
1339//******************************************************************************
1340//******************************************************************************
1341HWND WIN32API GetDesktopWindow(void)
1342{
1343 HWND hDesktopWindow = windowDesktop->getWindowHandle();
1344 dprintf2(("USER32: GetDesktopWindow, returned %x\n", hDesktopWindow));
1345 return hDesktopWindow;
1346}
1347//******************************************************************************
1348//******************************************************************************
1349HWND WIN32API FindWindowA(LPCSTR lpszClass, LPCSTR lpszWindow)
1350{
1351 return FindWindowExA( NULL, NULL, lpszClass, lpszWindow );
1352}
1353//******************************************************************************
1354//******************************************************************************
1355HWND WIN32API FindWindowW( LPCWSTR lpClassName, LPCWSTR lpWindowName)
1356{
1357 return FindWindowExW( NULL, NULL, lpClassName, lpWindowName );
1358}
1359//******************************************************************************
1360//******************************************************************************
1361HWND WIN32API FindWindowExA(HWND hwndParent, HWND hwndChildAfter, LPCSTR lpszClass, LPCSTR lpszWindow)
1362{
1363 ATOM atom = 0;
1364
1365 if (lpszClass)
1366 {
1367 /* If the atom doesn't exist, then no class */
1368 /* with this name exists either. */
1369 if (!(atom = GlobalFindAtomA( lpszClass )))
1370 {
1371 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1372 return 0;
1373 }
1374 }
1375 return Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, (LPSTR)lpszWindow);
1376}
1377/*****************************************************************************
1378 * Name : HWND WIN32API FindWindowExW
1379 * Purpose : The FindWindowEx function retrieves the handle of a window whose
1380 * class name and window name match the specified strings. The
1381 * function searches child windows, beginning with the one following
1382 * the given child window.
1383 * Parameters: HWND hwndParent handle of parent window
1384 * HWND hwndChildAfter handle of a child window
1385 * LPCTSTR lpszClass address of class name
1386 * LPCTSTR lpszWindow address of window name
1387 * Variables :
1388 * Result : If the function succeeds, the return value is the handle of the
1389 * window that has the specified class and window names.
1390 * If the function fails, the return value is NULL. To get extended
1391 * error information, call GetLastError.
1392 * Remark :
1393 *
1394 *****************************************************************************/
1395
1396HWND WIN32API FindWindowExW(HWND hwndParent,
1397 HWND hwndChildAfter,
1398 LPCWSTR lpszClass,
1399 LPCWSTR lpszWindow)
1400{
1401 ATOM atom = 0;
1402 char *buffer;
1403 HWND hwnd;
1404
1405 if (lpszClass)
1406 {
1407 /* If the atom doesn't exist, then no class */
1408 /* with this name exists either. */
1409 if (!(atom = GlobalFindAtomW( lpszClass )))
1410 {
1411 SetLastError(ERROR_CANNOT_FIND_WND_CLASS);
1412 return 0;
1413 }
1414 }
1415 buffer = HEAP_strdupWtoA( GetProcessHeap(), 0, lpszWindow );
1416 hwnd = Win32BaseWindow::FindWindowEx(hwndParent, hwndChildAfter, atom, buffer);
1417 HeapFree( GetProcessHeap(), 0, buffer );
1418 return hwnd;
1419}
1420//******************************************************************************
1421//******************************************************************************
1422BOOL WIN32API FlashWindow(HWND hwnd, BOOL fFlash)
1423{
1424 dprintf(("FlashWindow %x %d\n", hwnd, fFlash));
1425// return OSLibWinFlashWindow(Win32ToOS2Handle(hwnd), fFlash);
1426 return 1;
1427}
1428//******************************************************************************
1429//******************************************************************************
1430BOOL WIN32API FlashWindowEx( PFLASHWINFO pfwi)
1431{
1432 dprintf(("FlashWindow %p %d\n", pfwi));
1433 return 1;
1434}
1435//******************************************************************************
1436//******************************************************************************
1437BOOL WIN32API MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1438 BOOL repaint )
1439{
1440 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1441
1442 if (!repaint) flags |= SWP_NOREDRAW;
1443 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1444
1445 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1446}
1447//******************************************************************************
1448//******************************************************************************
1449BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1450{
1451 PRECT rcl;
1452
1453 if(hwnd == HWND_DESKTOP) {
1454 return(TRUE); //nothing to do
1455 }
1456 if(!IsWindow(hwnd)) {
1457 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1458 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1459 return (FALSE);
1460 }
1461#ifdef DEBUG
1462 POINT tmp = *pt;
1463#endif
1464 MapWindowPoints(hwnd, 0, pt, 1);
1465 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1466
1467 return TRUE;
1468}
1469//******************************************************************************
1470//Note: count 0 is a legal parameter (verified in NT4)
1471//******************************************************************************
1472HDWP WIN32API BeginDeferWindowPos(int count)
1473{
1474 HDWP handle;
1475 DWP *pDWP;
1476
1477 if (count < 0)
1478 {
1479 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1480 SetLastError(ERROR_INVALID_PARAMETER);
1481 return 0;
1482 }
1483 dprintf(("USER32: BeginDeferWindowPos %d", count));
1484 if(count == 0)
1485 count = 8; // change to any non-zero value
1486
1487 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1488 if (!handle)
1489 return 0;
1490
1491 pDWP = (DWP *) handle;
1492 pDWP->actualCount = 0;
1493 pDWP->suggestedCount = count;
1494 pDWP->valid = TRUE;
1495 pDWP->wMagic = DWP_MAGIC;
1496 pDWP->hwndParent = 0;
1497 return handle;
1498}
1499/***********************************************************************
1500 * DeferWindowPos (USER32.128)
1501 *
1502 * TODO: SvL: Does this need to be thread safe?
1503 *
1504 */
1505HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1506 INT x, INT y, INT cx, INT cy,
1507 UINT flags )
1508{
1509 DWP *pDWP;
1510 int i;
1511 HDWP newhdwp = hdwp,retvalue;
1512
1513 pDWP = (DWP *)hdwp;
1514 if (!pDWP) {
1515 SetLastError(ERROR_INVALID_PARAMETER);
1516 return 0;
1517 }
1518
1519 if (hwnd == GetDesktopWindow())
1520 return 0;
1521
1522 if(!IsWindow(hwnd)) {
1523 dprintf(("DeferWindowPos, window %x not found", hwnd));
1524 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1525 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1526 return 0;
1527 }
1528
1529 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1530 x, y, cx, cy, flags));
1531
1532/* Numega Bounds Checker Demo dislikes the following code.
1533 In fact, I've not been able to find any "same parent" requirement in any docu
1534 [AM 980509]
1535 */
1536#if 0
1537 /* All the windows of a DeferWindowPos() must have the same parent */
1538 parent = pWnd->parent->hwndSelf;
1539 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1540 else if (parent != pDWP->hwndParent)
1541 {
1542 USER_HEAP_FREE( hdwp );
1543 retvalue = 0;
1544 goto END;
1545 }
1546#endif
1547
1548 for (i = 0; i < pDWP->actualCount; i++)
1549 {
1550 if (pDWP->winPos[i].hwnd == hwnd)
1551 {
1552 /* Merge with the other changes */
1553 if (!(flags & SWP_NOZORDER))
1554 {
1555 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1556 }
1557 if (!(flags & SWP_NOMOVE))
1558 {
1559 pDWP->winPos[i].x = x;
1560 pDWP->winPos[i].y = y;
1561 }
1562 if (!(flags & SWP_NOSIZE))
1563 {
1564 pDWP->winPos[i].cx = cx;
1565 pDWP->winPos[i].cy = cy;
1566 }
1567 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1568 SWP_NOZORDER | SWP_NOREDRAW |
1569 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1570 SWP_NOOWNERZORDER);
1571 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1572 SWP_FRAMECHANGED);
1573 retvalue = hdwp;
1574 goto END;
1575 }
1576 }
1577 if (pDWP->actualCount >= pDWP->suggestedCount)
1578 {
1579 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1580 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1581 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1582 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1583 if (!newhdwp)
1584 {
1585 retvalue = 0;
1586 goto END;
1587 }
1588 pDWP = (DWP *) newhdwp;
1589 pDWP->suggestedCount++;
1590 }
1591 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1592 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1593 pDWP->winPos[pDWP->actualCount].x = x;
1594 pDWP->winPos[pDWP->actualCount].y = y;
1595 pDWP->winPos[pDWP->actualCount].cx = cx;
1596 pDWP->winPos[pDWP->actualCount].cy = cy;
1597 pDWP->winPos[pDWP->actualCount].flags = flags;
1598 pDWP->actualCount++;
1599 retvalue = newhdwp;
1600END:
1601 return retvalue;
1602}
1603//******************************************************************************
1604//******************************************************************************
1605BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1606{
1607 DWP *pDWP;
1608 WINDOWPOS *winpos;
1609 BOOL res = TRUE;
1610 int i;
1611
1612 pDWP = (DWP *) hdwp;
1613 if (!pDWP) {
1614 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1615 SetLastError(ERROR_INVALID_PARAMETER);
1616 return FALSE;
1617 }
1618 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1619 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1620 {
1621 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1622 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1623 winpos->x, winpos->y, winpos->cx,
1624 winpos->cy, winpos->flags )))
1625 break;
1626 }
1627 dprintf(("**EndDeferWindowPos DONE"));
1628 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1629 return res;
1630}
1631//******************************************************************************
1632//******************************************************************************
1633HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1634{
1635 dprintf(("USER32: ChildWindowFromPoint\n"));
1636 return ChildWindowFromPointEx(hwnd, pt, 0);
1637}
1638/*****************************************************************************
1639 * Name : HWND WIN32API ChildWindowFromPointEx
1640 * Purpose : pt: client coordinates
1641 * Parameters:
1642 * Variables :
1643 * Result : If the function succeeds, the return value is the window handle.
1644 * If the function fails, the return value is zero
1645 * Remark :
1646 * Status : COMPLETELY IMPLEMENTED AND TESTED
1647 *
1648 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1649 *****************************************************************************/
1650HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1651{
1652 RECT rect;
1653 HWND hWnd;
1654
1655 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1656 hwndParent, pt, uFlags));
1657
1658 if (GetWindowRect (hwndParent, &rect) == 0) {
1659 // oops, invalid handle
1660 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1661 return NULL;
1662 }
1663
1664 ClientToScreen(hwndParent, &pt);
1665 if (PtInRect (&rect, pt) == 0) {
1666 // point is outside window
1667 return NULL;
1668 }
1669
1670 // get first child
1671 hWnd = GetWindow (hwndParent, GW_CHILD);
1672
1673 while (hWnd != NULL)
1674 {
1675 // do I need to skip this window?
1676 if (((uFlags & CWP_SKIPINVISIBLE) &&
1677 (IsWindowVisible (hWnd) == FALSE)) ||
1678 ((uFlags & CWP_SKIPDISABLED) &&
1679 (IsWindowEnabled (hWnd) == FALSE)) ||
1680 ((uFlags & CWP_SKIPTRANSPARENT) &&
1681 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1682 {
1683 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1684 continue;
1685 }
1686
1687 // is the point in this window's rect?
1688 GetWindowRect (hWnd, &rect);
1689 if (PtInRect (&rect,pt) == FALSE) {
1690 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1691 continue;
1692 }
1693
1694 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1695 // found it!
1696 return hWnd;
1697 }
1698 // the point is in the parentwindow but the parentwindow has no child
1699 // at this coordinate
1700 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1701 return hwndParent;
1702}
1703//******************************************************************************
1704//******************************************************************************
1705BOOL WIN32API CloseWindow(HWND hwnd)
1706{
1707 Win32BaseWindow *window;
1708
1709 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1710 if(!window) {
1711 dprintf(("CloseWindow, window %x not found", hwnd));
1712 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1713 return 0;
1714 }
1715 dprintf(("CloseWindow %x\n", hwnd));
1716 BOOL ret = window->CloseWindow();
1717 RELEASE_WNDOBJ(window);
1718 return ret;
1719}
1720//******************************************************************************
1721//******************************************************************************
1722static BOOL IsPointInWindow(HWND hwnd, POINT point)
1723{
1724 RECT rectWindow;
1725 DWORD hittest, dwStyle, dwExStyle;
1726
1727 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1728 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1729
1730 GetWindowRect(hwnd, &rectWindow);
1731
1732 /* If point is in window, and window is visible, and it */
1733 /* is enabled (or it's a top-level window), then explore */
1734 /* its children. Otherwise, go to the next window. */
1735
1736 if( (dwStyle & WS_VISIBLE) &&
1737 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1738 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1739 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1740 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1741#if 1
1742 )
1743#else
1744 &&
1745 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1746#endif
1747 {
1748 DWORD dwThreadId = GetCurrentThreadId();
1749
1750 //Don't send WM_NCHITTEST if this window doesn't belong to the current thread
1751 if(dwThreadId != GetWindowThreadProcessId(hwnd, NULL))
1752 {
1753 return TRUE;
1754 }
1755 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1756 if(hittest != HTTRANSPARENT) {
1757 return TRUE;
1758 }
1759 }
1760 return FALSE;
1761}
1762//******************************************************************************
1763//TODO: Does this return handles of hidden or disabled windows?
1764//******************************************************************************
1765HWND WIN32API WindowFromPoint( POINT point)
1766{
1767 HWND hwndOS2, hwnd;
1768 POINT wPoint;
1769
1770 wPoint.x = point.x;
1771 wPoint.y = mapScreenY(point.y);
1772
1773 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1774 if(hwndOS2)
1775 {
1776 hwnd = OS2ToWin32Handle(hwndOS2);
1777 while(hwnd)
1778 {
1779 if(IsPointInWindow(hwnd, point)) {
1780 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1781 return hwnd;
1782 }
1783#if 0
1784//TODO: breaks a lot of things
1785 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1786#else
1787 //try siblings
1788 HWND hwndSibling;
1789 HWND hwndParent = GetParent(hwnd);
1790
1791 if(hwndParent) {
1792 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1793 while(hwndSibling) {
1794 if(hwndSibling != hwnd) {
1795 if(IsPointInWindow(hwndSibling, point)) {
1796 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1797 return hwndSibling;
1798 }
1799 }
1800 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1801 }
1802 }
1803 hwnd = hwndParent;
1804#endif
1805 }
1806 }
1807 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1808 return windowDesktop->getWindowHandle();
1809}
1810//******************************************************************************
1811//******************************************************************************
1812BOOL WIN32API IsWindowUnicode(HWND hwnd)
1813{
1814 Win32BaseWindow *window;
1815
1816 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1817 if(!window) {
1818 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1819 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1820 return 0;
1821 }
1822 BOOL ret = window->IsWindowUnicode();
1823 RELEASE_WNDOBJ(window);
1824 return ret;
1825}
1826/***********************************************************************
1827 * SwitchToThisWindow (USER32.539)
1828 */
1829VOID WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1830{
1831 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1832}
1833//******************************************************************************
1834//******************************************************************************
1835BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1836{
1837 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1838}
1839//******************************************************************************
1840//******************************************************************************
1841BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1842{
1843 Win32BaseWindow *window;
1844 BOOL ret = TRUE;
1845 ULONG henum;
1846 HWND hwndNext;
1847
1848 if(lpfn == NULL) {
1849 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1850 SetLastError(ERROR_INVALID_PARAMETER);
1851 return FALSE;
1852 }
1853 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1854 if(!window) {
1855 dprintf(("EnumChildWindows, window %x not found", hwnd));
1856 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1857 return FALSE;
1858 }
1859 ret = window->EnumChildWindows(lpfn, lParam);
1860 RELEASE_WNDOBJ(window);
1861 return ret;
1862}
1863//******************************************************************************
1864//******************************************************************************
1865BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1866{
1867 return windowDesktop->EnumWindows(lpfn, lParam);
1868}
1869//******************************************************************************
1870//******************************************************************************
1871UINT WIN32API ArrangeIconicWindows( HWND parent)
1872{
1873 RECT rectParent;
1874 HWND hwndChild;
1875 INT x, y, xspacing, yspacing;
1876
1877 dprintf(("USER32: ArrangeIconicWindows %x", parent));
1878 dprintf(("USER32: TODO: icon title!!"));
1879
1880 GetClientRect(parent, &rectParent);
1881 x = rectParent.left;
1882 y = rectParent.bottom;
1883 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1884 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1885
1886 hwndChild = GetWindow( parent, GW_CHILD );
1887 while (hwndChild)
1888 {
1889 if( IsIconic( hwndChild ) )
1890 {
1891// WND *wndPtr = WIN_FindWndPtr(hwndChild);
1892
1893// WINPOS_ShowIconTitle( wndPtr, FALSE );
1894
1895 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
1896 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
1897 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1898// if( IsWindow(hwndChild) )
1899// WINPOS_ShowIconTitle(wndPtr , TRUE );
1900// WIN_ReleaseWndPtr(wndPtr);
1901
1902 if (x <= rectParent.right - xspacing) x += xspacing;
1903 else
1904 {
1905 x = rectParent.left;
1906 y -= yspacing;
1907 }
1908 }
1909 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1910 }
1911 return yspacing;
1912}
1913//******************************************************************************
1914//restores iconized window to previous size/position
1915//******************************************************************************
1916BOOL WIN32API OpenIcon(HWND hwnd)
1917{
1918 dprintf(("USER32: OpenIcon %x", hwnd));
1919
1920 if(!IsIconic(hwnd))
1921 return FALSE;
1922 ShowWindow(hwnd, SW_SHOWNORMAL);
1923 return TRUE;
1924}
1925//******************************************************************************
1926//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1927// hidden with the same api
1928//TODO: -> needs testing
1929//******************************************************************************
1930BOOL WIN32API ShowOwnedPopups(HWND hwndOwner, BOOL fShow)
1931{
1932 Win32BaseWindow *window, *owner;
1933 HWND hwnd;
1934
1935 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1936 if(!owner) {
1937 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1938 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1939 return FALSE;
1940 }
1941 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1942
1943 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1944 while(hwnd) {
1945 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1946 if(window) {
1947 if(window == owner && (window->getStyle() & WS_POPUP))
1948 {
1949 if(fShow) {
1950 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1951 {
1952 /*
1953 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1954 * regardless of the state of the owner
1955 */
1956 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1957 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1958 }
1959 }
1960 else
1961 {
1962 if(IsWindowVisible(hwnd))
1963 {
1964 /*
1965 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1966 * regardless of the state of the owner
1967 */
1968 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1969 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1970 }
1971 }
1972 }
1973 RELEASE_WNDOBJ(window);
1974 }
1975 else dprintf(("WARNING: window %x is not valid", hwnd));
1976
1977 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1978 }
1979 RELEASE_WNDOBJ(owner);
1980 return TRUE;
1981}
1982//******************************************************************************
1983//******************************************************************************
1984HWND WIN32API GetForegroundWindow()
1985{
1986 HWND hwnd;
1987
1988 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1989 return hwnd;
1990}
1991//******************************************************************************
1992
1993/******************************************************************************
1994 * The return value identifies the most recently active pop-up window.
1995 * The return value is the same as the hWnd parameter, if any of the
1996 * following conditions are met:
1997 *
1998 * - The window identified by hWnd was most recently active.
1999 * - The window identified by hWnd does not own any pop-up windows.
2000 * - The window identified by hWnd is not a top-level window or it is
2001 * owned by another window.
2002 */
2003HWND WIN32API GetLastActivePopup(HWND hWnd)
2004{
2005 Win32BaseWindow *owner;
2006
2007 owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
2008 if(!owner)
2009 {
2010 dprintf(("GetLastActivePopup, window %x not found", hWnd));
2011 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2012 return hWnd;
2013 }
2014
2015 HWND hwndRetVal = owner->getLastActive();
2016 if (!IsWindow( hwndRetVal ))
2017 hwndRetVal = owner->getWindowHandle();
2018
2019 RELEASE_WNDOBJ(owner);
2020
2021 return hwndRetVal;
2022}
2023//******************************************************************************
2024//******************************************************************************
2025DWORD WIN32API GetWindowThreadProcessId(HWND hwnd, PDWORD lpdwProcessId)
2026{
2027 Win32BaseWindow *window;
2028 DWORD dwThreadId;
2029
2030 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2031 if(!window) {
2032 dprintf(("GetWindowThreadProcessId, window %x not found", hwnd));
2033 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2034 return 0;
2035 }
2036 dwThreadId = window->getThreadId();
2037 if(lpdwProcessId) {
2038 *lpdwProcessId = window->getProcessId();
2039 }
2040 RELEASE_WNDOBJ(window);
2041
2042 return dwThreadId;
2043}
2044//******************************************************************************
2045//******************************************************************************
2046DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
2047{
2048 Win32BaseWindow *window;
2049
2050 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2051 if(!window) {
2052 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
2053 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2054 return 0;
2055 }
2056 dprintf(("GetWindowContextHelpId %x", hwnd));
2057 DWORD ret = window->getWindowContextHelpId();
2058 RELEASE_WNDOBJ(window);
2059 return ret;
2060}
2061//******************************************************************************
2062//******************************************************************************
2063BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
2064{
2065 Win32BaseWindow *window;
2066
2067 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2068 if(!window) {
2069 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
2070 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2071 return 0;
2072 }
2073 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
2074 window->setWindowContextHelpId(dwContextHelpId);
2075 RELEASE_WNDOBJ(window);
2076 return(TRUE);
2077}
2078//******************************************************************************
2079//******************************************************************************
2080HANDLE WIN32API GetPropA(HWND hwnd, LPCSTR str )
2081{
2082 Win32BaseWindow *window;
2083
2084 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2085 if(!window) {
2086 dprintf(("GetPropA, window %x not found", hwnd));
2087 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2088 return 0;
2089 }
2090 HANDLE ret = window->getProp(str);
2091 RELEASE_WNDOBJ(window);
2092 return ret;
2093}
2094//******************************************************************************
2095//******************************************************************************
2096HANDLE WIN32API GetPropW(HWND hwnd, LPCWSTR str)
2097{
2098 Win32BaseWindow *window;
2099 LPSTR strA;
2100 HANDLE ret;
2101
2102 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2103 if(!window) {
2104 dprintf(("GetPropW, window %x not found", hwnd));
2105 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2106 return 0;
2107 }
2108
2109 if(HIWORD(str)) {
2110 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2111 }
2112 else strA = (LPSTR)str;
2113
2114 ret = window->getProp(strA);
2115
2116 RELEASE_WNDOBJ(window);
2117 if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
2118 return ret;
2119}
2120//******************************************************************************
2121//******************************************************************************
2122BOOL WIN32API SetPropA(HWND hwnd, LPCSTR str, HANDLE handle )
2123{
2124 Win32BaseWindow *window;
2125
2126 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2127 if(!window) {
2128 dprintf(("SetPropA, window %x not found", hwnd));
2129 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2130 return FALSE;
2131 }
2132 BOOL ret = window->setProp(str, handle);
2133 RELEASE_WNDOBJ(window);
2134 return ret;
2135}
2136//******************************************************************************
2137//******************************************************************************
2138BOOL SetPropW(HWND hwnd, LPCWSTR str, HANDLE handle )
2139{
2140 BOOL ret;
2141 LPSTR strA;
2142
2143 if (!HIWORD(str))
2144 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
2145 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2146 ret = SetPropA( hwnd, strA, handle );
2147 HeapFree( GetProcessHeap(), 0, strA );
2148 return ret;
2149}
2150//******************************************************************************
2151//******************************************************************************
2152HANDLE WIN32API RemovePropA(HWND hwnd, LPCSTR str)
2153{
2154 Win32BaseWindow *window;
2155
2156 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2157 if(!window) {
2158 dprintf(("RemovePropA, window %x not found", hwnd));
2159 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2160 return 0;
2161 }
2162 HANDLE ret = window->removeProp(str);
2163 RELEASE_WNDOBJ(window);
2164 return ret;
2165}
2166//******************************************************************************
2167//******************************************************************************
2168HANDLE WIN32API RemovePropW(HWND hwnd, LPCWSTR str)
2169{
2170 LPSTR strA;
2171 HANDLE ret;
2172
2173 if (!HIWORD(str))
2174 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
2175 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2176 ret = RemovePropA( hwnd, strA );
2177 HeapFree( GetProcessHeap(), 0, strA );
2178 return ret;
2179}
2180//******************************************************************************
2181//******************************************************************************
2182INT WIN32API EnumPropsA(HWND hwnd, PROPENUMPROCA func )
2183{
2184 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
2185}
2186//******************************************************************************
2187//******************************************************************************
2188INT WIN32API EnumPropsW(HWND hwnd, PROPENUMPROCW func )
2189{
2190 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
2191}
2192//******************************************************************************
2193//******************************************************************************
2194INT WIN32API EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
2195{
2196 Win32BaseWindow *window;
2197
2198 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2199 if(!window) {
2200 dprintf(("EnumPropsExA, window %x not found", hwnd));
2201 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2202 return -1;
2203 }
2204 INT ret = window->enumPropsExA(func, lParam);
2205 RELEASE_WNDOBJ(window);
2206 return ret;
2207}
2208//******************************************************************************
2209//******************************************************************************
2210INT WIN32API EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
2211{
2212 Win32BaseWindow *window;
2213
2214 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2215 if(!window) {
2216 dprintf(("EnumPropsExA, window %x not found", hwnd));
2217 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2218 return -1;
2219 }
2220 INT ret = window->enumPropsExW(func, lParam);
2221 RELEASE_WNDOBJ(window);
2222 return ret;
2223}
2224//******************************************************************************
2225//The GetWindowModuleFileName function retrieves the full path and file name of
2226//the module associated with the specified window handle.
2227//******************************************************************************
2228UINT WIN32API GetWindowModuleFileNameA(HWND hwnd, LPTSTR lpszFileName, UINT cchFileNameMax)
2229{
2230 WNDPROC lpfnWindowProc;
2231
2232 if (!IsWindow(hwnd)) {
2233 dprintf(("warning: GetWindowModuleFileName: window %x not found!", hwnd));
2234 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2235 return 0;
2236 }
2237 lpfnWindowProc = (WNDPROC)GetWindowLongA(hwnd, GWL_WNDPROC);
2238 return GetProcModuleFileNameA((ULONG)lpfnWindowProc, lpszFileName, cchFileNameMax);
2239}
2240//******************************************************************************
2241//******************************************************************************
2242
2243
2244/*****************************************************************************
2245 * Name : BOOL WIN32API AnyPopup
2246 * Purpose : The AnyPopup function indicates whether an owned, visible,
2247 * top-level pop-up, or overlapped window exists on the screen. The
2248 * function searches the entire Windows screen, not just the calling
2249 * application's client area.
2250 * Parameters: VOID
2251 * Variables :
2252 * Result : If a pop-up window exists, the return value is TRUE even if the
2253 * pop-up window is completely covered by other windows. Otherwise,
2254 * it is FALSE.
2255 * Remark : AnyPopup is a Windows version 1.x function and is retained for
2256 * compatibility purposes. It is generally not useful.
2257 * Status : UNTESTED STUB
2258 *
2259 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
2260 *****************************************************************************/
2261BOOL WIN32API AnyPopup()
2262{
2263 dprintf(("USER32:AnyPopup() not implemented.\n"));
2264
2265 return (FALSE);
2266}
2267
2268#ifdef __cplusplus
2269} // extern "C"
2270#endif
Note: See TracBrowser for help on using the repository browser.