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

Last change on this file since 10316 was 10316, checked in by sandervl, 22 years ago

Visible & Clip region changes

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