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

Last change on this file since 21334 was 21334, checked in by vladest, 16 years ago

Added functions, required for Flash 9/10 plugin

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