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

Last change on this file since 10496 was 10496, checked in by sandervl, 21 years ago

added stress test case for drawing; more logging

File size: 77.5 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 MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
1398 BOOL repaint )
1399{
1400 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
1401
1402 if (!repaint) flags |= SWP_NOREDRAW;
1403 dprintf(("MoveWindow: %x %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint ));
1404
1405 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1406}
1407//******************************************************************************
1408//******************************************************************************
1409BOOL WIN32API ClientToScreen (HWND hwnd, PPOINT pt)
1410{
1411 PRECT rcl;
1412
1413 if(hwnd == HWND_DESKTOP) {
1414 return(TRUE); //nothing to do
1415 }
1416 if(!IsWindow(hwnd)) {
1417 dprintf(("warning: ClientToScreen window %x not found!", hwnd));
1418 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1419 return (FALSE);
1420 }
1421#ifdef DEBUG
1422 POINT tmp = *pt;
1423#endif
1424 MapWindowPoints(hwnd, 0, pt, 1);
1425 dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
1426
1427 return TRUE;
1428}
1429//******************************************************************************
1430//Note: count 0 is a legal parameter (verified in NT4)
1431//******************************************************************************
1432HDWP WIN32API BeginDeferWindowPos(int count)
1433{
1434 HDWP handle;
1435 DWP *pDWP;
1436
1437 if (count < 0)
1438 {
1439 dprintf(("USER32: BeginDeferWindowPos invalid param %d", count));
1440 SetLastError(ERROR_INVALID_PARAMETER);
1441 return 0;
1442 }
1443 dprintf(("USER32: BeginDeferWindowPos %d", count));
1444 if(count == 0)
1445 count = 8; // change to any non-zero value
1446
1447 handle = (HDWP)HeapAlloc(GetProcessHeap(), 0, sizeof(DWP) + (count-1)*sizeof(WINDOWPOS));
1448 if (!handle)
1449 return 0;
1450
1451 pDWP = (DWP *) handle;
1452 pDWP->actualCount = 0;
1453 pDWP->suggestedCount = count;
1454 pDWP->valid = TRUE;
1455 pDWP->wMagic = DWP_MAGIC;
1456 pDWP->hwndParent = 0;
1457 return handle;
1458}
1459/***********************************************************************
1460 * DeferWindowPos (USER32.128)
1461 *
1462 * TODO: SvL: Does this need to be thread safe?
1463 *
1464 */
1465HDWP WIN32API DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1466 INT x, INT y, INT cx, INT cy,
1467 UINT flags )
1468{
1469 DWP *pDWP;
1470 int i;
1471 HDWP newhdwp = hdwp,retvalue;
1472
1473 pDWP = (DWP *)hdwp;
1474 if (!pDWP) {
1475 SetLastError(ERROR_INVALID_PARAMETER);
1476 return 0;
1477 }
1478
1479 if (hwnd == GetDesktopWindow())
1480 return 0;
1481
1482 if(!IsWindow(hwnd)) {
1483 dprintf(("DeferWindowPos, window %x not found", hwnd));
1484 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1485 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1486 return 0;
1487 }
1488
1489 dprintf(("USER32: DeferWindowPos hdwp %x hwnd %x hwndAfter %x (%d,%d)(%d,%d) %x", hdwp, hwnd, hwndAfter,
1490 x, y, cx, cy, flags));
1491
1492/* Numega Bounds Checker Demo dislikes the following code.
1493 In fact, I've not been able to find any "same parent" requirement in any docu
1494 [AM 980509]
1495 */
1496#if 0
1497 /* All the windows of a DeferWindowPos() must have the same parent */
1498 parent = pWnd->parent->hwndSelf;
1499 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1500 else if (parent != pDWP->hwndParent)
1501 {
1502 USER_HEAP_FREE( hdwp );
1503 retvalue = 0;
1504 goto END;
1505 }
1506#endif
1507
1508 for (i = 0; i < pDWP->actualCount; i++)
1509 {
1510 if (pDWP->winPos[i].hwnd == hwnd)
1511 {
1512 /* Merge with the other changes */
1513 if (!(flags & SWP_NOZORDER))
1514 {
1515 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1516 }
1517 if (!(flags & SWP_NOMOVE))
1518 {
1519 pDWP->winPos[i].x = x;
1520 pDWP->winPos[i].y = y;
1521 }
1522 if (!(flags & SWP_NOSIZE))
1523 {
1524 pDWP->winPos[i].cx = cx;
1525 pDWP->winPos[i].cy = cy;
1526 }
1527 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1528 SWP_NOZORDER | SWP_NOREDRAW |
1529 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1530 SWP_NOOWNERZORDER);
1531 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1532 SWP_FRAMECHANGED);
1533 retvalue = hdwp;
1534 goto END;
1535 }
1536 }
1537 if (pDWP->actualCount >= pDWP->suggestedCount)
1538 {
1539 //DWP structure already contains WINDOWPOS, allocated with (count-1)
1540 //in BeginDeferWindowPos; pDWP->suggestedCount alloc increases it by one
1541 newhdwp = (HDWP)HeapReAlloc(GetProcessHeap(), 0, (LPVOID)hdwp,
1542 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS));
1543 if (!newhdwp)
1544 {
1545 retvalue = 0;
1546 goto END;
1547 }
1548 pDWP = (DWP *) newhdwp;
1549 pDWP->suggestedCount++;
1550 }
1551 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1552 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1553 pDWP->winPos[pDWP->actualCount].x = x;
1554 pDWP->winPos[pDWP->actualCount].y = y;
1555 pDWP->winPos[pDWP->actualCount].cx = cx;
1556 pDWP->winPos[pDWP->actualCount].cy = cy;
1557 pDWP->winPos[pDWP->actualCount].flags = flags;
1558 pDWP->actualCount++;
1559 retvalue = newhdwp;
1560END:
1561 return retvalue;
1562}
1563//******************************************************************************
1564//******************************************************************************
1565BOOL WIN32API EndDeferWindowPos( HDWP hdwp)
1566{
1567 DWP *pDWP;
1568 WINDOWPOS *winpos;
1569 BOOL res = TRUE;
1570 int i;
1571
1572 pDWP = (DWP *) hdwp;
1573 if (!pDWP) {
1574 dprintf(("**EndDeferWindowPos invalid parameter\n"));
1575 SetLastError(ERROR_INVALID_PARAMETER);
1576 return FALSE;
1577 }
1578 dprintf(("**EndDeferWindowPos for %d windows", pDWP->actualCount));
1579 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1580 {
1581 dprintf(("**EndDeferWindowPos %x (%d,%d) (%d,%d) %x", winpos->hwnd, winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags));
1582 if (!(res = SetWindowPos(winpos->hwnd, winpos->hwndInsertAfter,
1583 winpos->x, winpos->y, winpos->cx,
1584 winpos->cy, winpos->flags )))
1585 break;
1586 }
1587 dprintf(("**EndDeferWindowPos DONE"));
1588 HeapFree(GetProcessHeap(), 0, (LPVOID)hdwp);
1589 return res;
1590}
1591//******************************************************************************
1592//******************************************************************************
1593HWND WIN32API ChildWindowFromPoint( HWND hwnd, POINT pt)
1594{
1595 dprintf(("USER32: ChildWindowFromPoint\n"));
1596 return ChildWindowFromPointEx(hwnd, pt, 0);
1597}
1598/*****************************************************************************
1599 * Name : HWND WIN32API ChildWindowFromPointEx
1600 * Purpose : pt: client coordinates
1601 * Parameters:
1602 * Variables :
1603 * Result : If the function succeeds, the return value is the window handle.
1604 * If the function fails, the return value is zero
1605 * Remark :
1606 * Status : COMPLETELY IMPLEMENTED AND TESTED
1607 *
1608 * Author : Rene Pronk [Sun, 1999/08/08 23:30]
1609 *****************************************************************************/
1610HWND WIN32API ChildWindowFromPointEx (HWND hwndParent, POINT pt, UINT uFlags)
1611{
1612 RECT rect;
1613 HWND hWnd;
1614
1615 dprintf(("ChildWindowFromPointEx(%08xh,%08xh,%08xh).\n",
1616 hwndParent, pt, uFlags));
1617
1618 if (GetWindowRect (hwndParent, &rect) == 0) {
1619 // oops, invalid handle
1620 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1621 return NULL;
1622 }
1623
1624 ClientToScreen(hwndParent, &pt);
1625 if (PtInRect (&rect, pt) == 0) {
1626 // point is outside window
1627 return NULL;
1628 }
1629
1630 // get first child
1631 hWnd = GetWindow (hwndParent, GW_CHILD);
1632
1633 while (hWnd != NULL)
1634 {
1635 // do I need to skip this window?
1636 if (((uFlags & CWP_SKIPINVISIBLE) &&
1637 (IsWindowVisible (hWnd) == FALSE)) ||
1638 ((uFlags & CWP_SKIPDISABLED) &&
1639 (IsWindowEnabled (hWnd) == FALSE)) ||
1640 ((uFlags & CWP_SKIPTRANSPARENT) &&
1641 (GetWindowLongA (hWnd, GWL_EXSTYLE) & WS_EX_TRANSPARENT)))
1642 {
1643 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1644 continue;
1645 }
1646
1647 // is the point in this window's rect?
1648 GetWindowRect (hWnd, &rect);
1649 if (PtInRect (&rect,pt) == FALSE) {
1650 hWnd = GetWindow (hWnd, GW_HWNDNEXT);
1651 continue;
1652 }
1653
1654 dprintf(("ChildWindowFromPointEx returned %x", hWnd));
1655 // found it!
1656 return hWnd;
1657 }
1658 // the point is in the parentwindow but the parentwindow has no child
1659 // at this coordinate
1660 dprintf(("ChildWindowFromPointEx returned parent %x", hwndParent));
1661 return hwndParent;
1662}
1663//******************************************************************************
1664//******************************************************************************
1665BOOL WIN32API CloseWindow(HWND hwnd)
1666{
1667 Win32BaseWindow *window;
1668
1669 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1670 if(!window) {
1671 dprintf(("CloseWindow, window %x not found", hwnd));
1672 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1673 return 0;
1674 }
1675 dprintf(("CloseWindow %x\n", hwnd));
1676 BOOL ret = window->CloseWindow();
1677 RELEASE_WNDOBJ(window);
1678 return ret;
1679}
1680//******************************************************************************
1681//******************************************************************************
1682static BOOL IsPointInWindow(HWND hwnd, POINT point)
1683{
1684 RECT rectWindow;
1685 DWORD hittest, dwStyle, dwExStyle;
1686
1687 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
1688 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1689
1690 GetWindowRect(hwnd, &rectWindow);
1691
1692 /* If point is in window, and window is visible, and it */
1693 /* is enabled (or it's a top-level window), then explore */
1694 /* its children. Otherwise, go to the next window. */
1695
1696 if( (dwStyle & WS_VISIBLE) &&
1697 ((dwExStyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) != (WS_EX_LAYERED | WS_EX_TRANSPARENT)) &&
1698 (!(dwStyle & WS_DISABLED) || ((dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
1699 ((point.x >= rectWindow.left) && (point.x < rectWindow.right) &&
1700 (point.y >= rectWindow.top) && (point.y < rectWindow.bottom))
1701#if 1
1702 )
1703#else
1704 &&
1705 (wndPtr->hrgnWnd ? PtInRegion(wndPtr->hrgnWnd, 1))
1706#endif
1707 {
1708 DWORD dwThreadId = GetCurrentThreadId();
1709
1710 //Don't send WM_NCHITTEST if this window doesn't belong to the current thread
1711 if(dwThreadId != GetWindowThreadProcessId(hwnd, NULL))
1712 {
1713 return TRUE;
1714 }
1715 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, MAKELONG(point.x, point.y));
1716 if(hittest != HTTRANSPARENT) {
1717 return TRUE;
1718 }
1719 }
1720 return FALSE;
1721}
1722//******************************************************************************
1723//TODO: Does this return handles of hidden or disabled windows?
1724//******************************************************************************
1725HWND WIN32API WindowFromPoint( POINT point)
1726{
1727 HWND hwndOS2, hwnd;
1728 POINT wPoint;
1729
1730 wPoint.x = point.x;
1731 wPoint.y = mapScreenY(point.y);
1732
1733 hwndOS2 = OSLibWinWindowFromPoint(OSLIB_HWND_DESKTOP, (PVOID)&wPoint);
1734 if(hwndOS2)
1735 {
1736 hwnd = OS2ToWin32Handle(hwndOS2);
1737 while(hwnd)
1738 {
1739 if(IsPointInWindow(hwnd, point)) {
1740 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwnd));
1741 return hwnd;
1742 }
1743#if 0
1744//TODO: breaks a lot of things
1745 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1746#else
1747 //try siblings
1748 HWND hwndSibling;
1749 HWND hwndParent = GetParent(hwnd);
1750
1751 if(hwndParent) {
1752 hwndSibling = GetWindow(hwndParent, GW_CHILD);
1753 while(hwndSibling) {
1754 if(hwndSibling != hwnd) {
1755 if(IsPointInWindow(hwndSibling, point)) {
1756 dprintf(("WindowFromPoint (%d,%d) %x->%x\n", point.x, point.y, hwndOS2, hwndSibling));
1757 return hwndSibling;
1758 }
1759 }
1760 hwndSibling = GetWindow(hwndSibling, GW_HWNDNEXT);
1761 }
1762 }
1763 hwnd = hwndParent;
1764#endif
1765 }
1766 }
1767 dprintf(("WindowFromPoint (%d,%d) %x->1\n", point.x, point.y, hwndOS2));
1768 return windowDesktop->getWindowHandle();
1769}
1770//******************************************************************************
1771//******************************************************************************
1772BOOL WIN32API IsWindowUnicode(HWND hwnd)
1773{
1774 Win32BaseWindow *window;
1775
1776 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1777 if(!window) {
1778 dprintf(("IsWindowUnicode, window %x not found", hwnd));
1779 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1780 return 0;
1781 }
1782 BOOL ret = window->IsWindowUnicode();
1783 RELEASE_WNDOBJ(window);
1784 return ret;
1785}
1786/***********************************************************************
1787 * SwitchToThisWindow (USER32.539)
1788 */
1789VOID WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
1790{
1791 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
1792}
1793//******************************************************************************
1794//******************************************************************************
1795BOOL WIN32API EnumThreadWindows(DWORD dwThreadId, WNDENUMPROC lpfn, LPARAM lParam)
1796{
1797 return windowDesktop->EnumThreadWindows(dwThreadId, lpfn, lParam);
1798}
1799//******************************************************************************
1800//******************************************************************************
1801BOOL WIN32API EnumChildWindows(HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
1802{
1803 Win32BaseWindow *window;
1804 BOOL ret = TRUE;
1805 ULONG henum;
1806 HWND hwndNext;
1807
1808 if(lpfn == NULL) {
1809 dprintf(("EnumChildWindows invalid parameter %x %x\n", hwnd, lParam));
1810 SetLastError(ERROR_INVALID_PARAMETER);
1811 return FALSE;
1812 }
1813 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1814 if(!window) {
1815 dprintf(("EnumChildWindows, window %x not found", hwnd));
1816 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1817 return FALSE;
1818 }
1819 ret = window->EnumChildWindows(lpfn, lParam);
1820 RELEASE_WNDOBJ(window);
1821 return ret;
1822}
1823//******************************************************************************
1824//******************************************************************************
1825BOOL WIN32API EnumWindows(WNDENUMPROC lpfn, LPARAM lParam)
1826{
1827 return windowDesktop->EnumWindows(lpfn, lParam);
1828}
1829//******************************************************************************
1830//******************************************************************************
1831UINT WIN32API ArrangeIconicWindows( HWND parent)
1832{
1833 RECT rectParent;
1834 HWND hwndChild;
1835 INT x, y, xspacing, yspacing;
1836
1837 dprintf(("USER32: ArrangeIconicWindows %x", parent));
1838 dprintf(("USER32: TODO: icon title!!"));
1839
1840 GetClientRect(parent, &rectParent);
1841 x = rectParent.left;
1842 y = rectParent.bottom;
1843 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1844 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1845
1846 hwndChild = GetWindow( parent, GW_CHILD );
1847 while (hwndChild)
1848 {
1849 if( IsIconic( hwndChild ) )
1850 {
1851// WND *wndPtr = WIN_FindWndPtr(hwndChild);
1852
1853// WINPOS_ShowIconTitle( wndPtr, FALSE );
1854
1855 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
1856 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
1857 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1858// if( IsWindow(hwndChild) )
1859// WINPOS_ShowIconTitle(wndPtr , TRUE );
1860// WIN_ReleaseWndPtr(wndPtr);
1861
1862 if (x <= rectParent.right - xspacing) x += xspacing;
1863 else
1864 {
1865 x = rectParent.left;
1866 y -= yspacing;
1867 }
1868 }
1869 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
1870 }
1871 return yspacing;
1872}
1873//******************************************************************************
1874//restores iconized window to previous size/position
1875//******************************************************************************
1876BOOL WIN32API OpenIcon(HWND hwnd)
1877{
1878 dprintf(("USER32: OpenIcon %x", hwnd));
1879
1880 if(!IsIconic(hwnd))
1881 return FALSE;
1882 ShowWindow(hwnd, SW_SHOWNORMAL);
1883 return TRUE;
1884}
1885//******************************************************************************
1886//SDK: Windows can only be shown with ShowOwnedPopups if they were previously
1887// hidden with the same api
1888//TODO: -> needs testing
1889//******************************************************************************
1890BOOL WIN32API ShowOwnedPopups(HWND hwndOwner, BOOL fShow)
1891{
1892 Win32BaseWindow *window, *owner;
1893 HWND hwnd;
1894
1895 owner = Win32BaseWindow::GetWindowFromHandle(hwndOwner);
1896 if(!owner) {
1897 dprintf(("ShowOwnedPopups, window %x not found", hwndOwner));
1898 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1899 return FALSE;
1900 }
1901 dprintf(("USER32: ShowOwnedPopups %x %d", hwndOwner, fShow));
1902
1903 hwnd = GetWindow(GetDesktopWindow(), GW_CHILD);
1904 while(hwnd) {
1905 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1906 if(window) {
1907 if(window == owner && (window->getStyle() & WS_POPUP))
1908 {
1909 if(fShow) {
1910 if(window->getFlags() & WIN_NEEDS_SHOW_OWNEDPOPUP)
1911 {
1912 /*
1913 * In Windows, ShowOwnedPopups(TRUE) generates WM_SHOWWINDOW messages with SW_PARENTOPENING,
1914 * regardless of the state of the owner
1915 */
1916 SendMessageA(hwnd, WM_SHOWWINDOW, SW_SHOW, SW_PARENTOPENING);
1917 window->setFlags(window->getFlags() & ~WIN_NEEDS_SHOW_OWNEDPOPUP);
1918 }
1919 }
1920 else
1921 {
1922 if(IsWindowVisible(hwnd))
1923 {
1924 /*
1925 * In Windows, ShowOwnedPopups(FALSE) generates WM_SHOWWINDOW messages with SW_PARENTCLOSING,
1926 * regardless of the state of the owner
1927 */
1928 SendMessageA(hwnd, WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
1929 window->setFlags(window->getFlags() | WIN_NEEDS_SHOW_OWNEDPOPUP);
1930 }
1931 }
1932 }
1933 RELEASE_WNDOBJ(window);
1934 }
1935 else dprintf(("WARNING: window %x is not valid", hwnd));
1936
1937 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1938 }
1939 RELEASE_WNDOBJ(owner);
1940 return TRUE;
1941}
1942//******************************************************************************
1943//******************************************************************************
1944HWND WIN32API GetForegroundWindow()
1945{
1946 HWND hwnd;
1947
1948 hwnd = OS2ToWin32Handle(OSLibWinQueryActiveWindow());
1949 return hwnd;
1950}
1951//******************************************************************************
1952
1953/******************************************************************************
1954 * The return value identifies the most recently active pop-up window.
1955 * The return value is the same as the hWnd parameter, if any of the
1956 * following conditions are met:
1957 *
1958 * - The window identified by hWnd was most recently active.
1959 * - The window identified by hWnd does not own any pop-up windows.
1960 * - The window identified by hWnd is not a top-level window or it is
1961 * owned by another window.
1962 */
1963HWND WIN32API GetLastActivePopup(HWND hWnd)
1964{
1965 Win32BaseWindow *owner;
1966
1967 owner = Win32BaseWindow::GetWindowFromHandle(hWnd);
1968 if(!owner)
1969 {
1970 dprintf(("GetLastActivePopup, window %x not found", hWnd));
1971 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1972 return hWnd;
1973 }
1974
1975 HWND hwndRetVal = owner->getLastActive();
1976 if (!IsWindow( hwndRetVal ))
1977 hwndRetVal = owner->getWindowHandle();
1978
1979 RELEASE_WNDOBJ(owner);
1980
1981 return hwndRetVal;
1982}
1983//******************************************************************************
1984//******************************************************************************
1985DWORD WIN32API GetWindowThreadProcessId(HWND hwnd, PDWORD lpdwProcessId)
1986{
1987 Win32BaseWindow *window;
1988 DWORD dwThreadId;
1989
1990 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
1991 if(!window) {
1992 dprintf(("GetWindowThreadProcessId, window %x not found", hwnd));
1993 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1994 return 0;
1995 }
1996 dwThreadId = window->getThreadId();
1997 if(lpdwProcessId) {
1998 *lpdwProcessId = window->getProcessId();
1999 }
2000 RELEASE_WNDOBJ(window);
2001
2002 return dwThreadId;
2003}
2004//******************************************************************************
2005//******************************************************************************
2006DWORD WIN32API GetWindowContextHelpId(HWND hwnd)
2007{
2008 Win32BaseWindow *window;
2009
2010 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2011 if(!window) {
2012 dprintf(("GetWindowContextHelpId, window %x not found", hwnd));
2013 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2014 return 0;
2015 }
2016 dprintf(("GetWindowContextHelpId %x", hwnd));
2017 DWORD ret = window->getWindowContextHelpId();
2018 RELEASE_WNDOBJ(window);
2019 return ret;
2020}
2021//******************************************************************************
2022//******************************************************************************
2023BOOL WIN32API SetWindowContextHelpId(HWND hwnd, DWORD dwContextHelpId)
2024{
2025 Win32BaseWindow *window;
2026
2027 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2028 if(!window) {
2029 dprintf(("SetWindowContextHelpId, window %x not found", hwnd));
2030 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2031 return 0;
2032 }
2033 dprintf(("SetWindowContextHelpId %x %d", hwnd, dwContextHelpId));
2034 window->setWindowContextHelpId(dwContextHelpId);
2035 RELEASE_WNDOBJ(window);
2036 return(TRUE);
2037}
2038//******************************************************************************
2039//******************************************************************************
2040HANDLE WIN32API GetPropA(HWND hwnd, LPCSTR str )
2041{
2042 Win32BaseWindow *window;
2043
2044 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2045 if(!window) {
2046 dprintf(("GetPropA, window %x not found", hwnd));
2047 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2048 return 0;
2049 }
2050 HANDLE ret = window->getProp(str);
2051 RELEASE_WNDOBJ(window);
2052 return ret;
2053}
2054//******************************************************************************
2055//******************************************************************************
2056HANDLE WIN32API GetPropW(HWND hwnd, LPCWSTR str)
2057{
2058 Win32BaseWindow *window;
2059 LPSTR strA;
2060 HANDLE ret;
2061
2062 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2063 if(!window) {
2064 dprintf(("GetPropW, window %x not found", hwnd));
2065 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2066 return 0;
2067 }
2068
2069 if(HIWORD(str)) {
2070 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2071 }
2072 else strA = (LPSTR)str;
2073
2074 ret = window->getProp(strA);
2075
2076 RELEASE_WNDOBJ(window);
2077 if(HIWORD(str)) HeapFree( GetProcessHeap(), 0, strA );
2078 return ret;
2079}
2080//******************************************************************************
2081//******************************************************************************
2082BOOL WIN32API SetPropA(HWND hwnd, LPCSTR str, HANDLE handle )
2083{
2084 Win32BaseWindow *window;
2085
2086 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2087 if(!window) {
2088 dprintf(("SetPropA, window %x not found", hwnd));
2089 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2090 return FALSE;
2091 }
2092 BOOL ret = window->setProp(str, handle);
2093 RELEASE_WNDOBJ(window);
2094 return ret;
2095}
2096//******************************************************************************
2097//******************************************************************************
2098BOOL SetPropW(HWND hwnd, LPCWSTR str, HANDLE handle )
2099{
2100 BOOL ret;
2101 LPSTR strA;
2102
2103 if (!HIWORD(str))
2104 return SetPropA( hwnd, (LPCSTR)(UINT)LOWORD(str), handle );
2105 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2106 ret = SetPropA( hwnd, strA, handle );
2107 HeapFree( GetProcessHeap(), 0, strA );
2108 return ret;
2109}
2110//******************************************************************************
2111//******************************************************************************
2112HANDLE WIN32API RemovePropA(HWND hwnd, LPCSTR str)
2113{
2114 Win32BaseWindow *window;
2115
2116 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2117 if(!window) {
2118 dprintf(("RemovePropA, window %x not found", hwnd));
2119 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2120 return 0;
2121 }
2122 HANDLE ret = window->removeProp(str);
2123 RELEASE_WNDOBJ(window);
2124 return ret;
2125}
2126//******************************************************************************
2127//******************************************************************************
2128HANDLE WIN32API RemovePropW(HWND hwnd, LPCWSTR str)
2129{
2130 LPSTR strA;
2131 HANDLE ret;
2132
2133 if (!HIWORD(str))
2134 return RemovePropA( hwnd, (LPCSTR)(UINT)LOWORD(str) );
2135 strA = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
2136 ret = RemovePropA( hwnd, strA );
2137 HeapFree( GetProcessHeap(), 0, strA );
2138 return ret;
2139}
2140//******************************************************************************
2141//******************************************************************************
2142INT WIN32API EnumPropsA(HWND hwnd, PROPENUMPROCA func )
2143{
2144 return EnumPropsExA( hwnd, (PROPENUMPROCEXA)func, 0 );
2145}
2146//******************************************************************************
2147//******************************************************************************
2148INT WIN32API EnumPropsW(HWND hwnd, PROPENUMPROCW func )
2149{
2150 return EnumPropsExW( hwnd, (PROPENUMPROCEXW)func, 0 );
2151}
2152//******************************************************************************
2153//******************************************************************************
2154INT WIN32API EnumPropsExA(HWND hwnd, PROPENUMPROCEXA func, LPARAM lParam)
2155{
2156 Win32BaseWindow *window;
2157
2158 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2159 if(!window) {
2160 dprintf(("EnumPropsExA, window %x not found", hwnd));
2161 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2162 return -1;
2163 }
2164 INT ret = window->enumPropsExA(func, lParam);
2165 RELEASE_WNDOBJ(window);
2166 return ret;
2167}
2168//******************************************************************************
2169//******************************************************************************
2170INT WIN32API EnumPropsExW(HWND hwnd, PROPENUMPROCEXW func, LPARAM lParam)
2171{
2172 Win32BaseWindow *window;
2173
2174 window = Win32BaseWindow::GetWindowFromHandle(hwnd);
2175 if(!window) {
2176 dprintf(("EnumPropsExA, window %x not found", hwnd));
2177 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2178 return -1;
2179 }
2180 INT ret = window->enumPropsExW(func, lParam);
2181 RELEASE_WNDOBJ(window);
2182 return ret;
2183}
2184//******************************************************************************
2185//The GetWindowModuleFileName function retrieves the full path and file name of
2186//the module associated with the specified window handle.
2187//******************************************************************************
2188UINT WIN32API GetWindowModuleFileNameA(HWND hwnd, LPTSTR lpszFileName, UINT cchFileNameMax)
2189{
2190 WNDPROC lpfnWindowProc;
2191
2192 if (!IsWindow(hwnd)) {
2193 dprintf(("warning: GetWindowModuleFileName: window %x not found!", hwnd));
2194 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
2195 return 0;
2196 }
2197 lpfnWindowProc = (WNDPROC)GetWindowLongA(hwnd, GWL_WNDPROC);
2198 return GetProcModuleFileNameA((ULONG)lpfnWindowProc, lpszFileName, cchFileNameMax);
2199}
2200//******************************************************************************
2201//******************************************************************************
2202
2203
2204/*****************************************************************************
2205 * Name : BOOL WIN32API AnyPopup
2206 * Purpose : The AnyPopup function indicates whether an owned, visible,
2207 * top-level pop-up, or overlapped window exists on the screen. The
2208 * function searches the entire Windows screen, not just the calling
2209 * application's client area.
2210 * Parameters: VOID
2211 * Variables :
2212 * Result : If a pop-up window exists, the return value is TRUE even if the
2213 * pop-up window is completely covered by other windows. Otherwise,
2214 * it is FALSE.
2215 * Remark : AnyPopup is a Windows version 1.x function and is retained for
2216 * compatibility purposes. It is generally not useful.
2217 * Status : UNTESTED STUB
2218 *
2219 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
2220 *****************************************************************************/
2221BOOL WIN32API AnyPopup()
2222{
2223 dprintf(("USER32:AnyPopup() not implemented.\n"));
2224
2225 return (FALSE);
2226}
Note: See TracBrowser for help on using the repository browser.