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

Last change on this file since 21303 was 21303, checked in by ydario, 16 years ago

User32 updates.

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