2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/winuser16.h"
28 #include "wine/server.h"
37 #include "nonclient.h"
38 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 #define HAS_DLGFRAME(style,exStyle) \
44 (((exStyle) & WS_EX_DLGMODALFRAME) || \
45 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
47 #define HAS_THICKFRAME(style) \
48 (((style) & WS_THICKFRAME) && \
49 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
51 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
53 #define PLACE_MIN 0x0001
54 #define PLACE_MAX 0x0002
55 #define PLACE_RECT 0x0004
58 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
70 /* ----- internal variables ----- */
72 static HWND hGlobalShellWindow
=0; /*the shell*/
73 static HWND hGlobalTaskmanWindow
=0;
74 static HWND hGlobalProgmanWindow
=0;
76 static LPCSTR atomInternalPos
;
79 /***********************************************************************
80 * WINPOS_CreateInternalPosAtom
82 BOOL
WINPOS_CreateInternalPosAtom()
85 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
86 return (atomInternalPos
) ? TRUE
: FALSE
;
89 /***********************************************************************
90 * WINPOS_CheckInternalPos
92 * Called when a window is destroyed.
94 void WINPOS_CheckInternalPos( HWND hwnd
)
96 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
100 if( IsWindow(lpPos
->hwndIconTitle
) )
101 DestroyWindow( lpPos
->hwndIconTitle
);
102 HeapFree( GetProcessHeap(), 0, lpPos
);
106 /***********************************************************************
107 * ArrangeIconicWindows (USER32.@)
109 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
113 INT x
, y
, xspacing
, yspacing
;
115 GetClientRect( parent
, &rectParent
);
117 y
= rectParent
.bottom
;
118 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
119 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
121 hwndChild
= GetWindow( parent
, GW_CHILD
);
124 if( IsIconic( hwndChild
) )
126 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
128 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
129 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
130 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
131 if( IsWindow(hwndChild
) )
132 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
134 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
141 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
147 /***********************************************************************
148 * SwitchToThisWindow (USER32.@)
150 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
152 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
156 /***********************************************************************
157 * GetWindowRect (USER32.@)
159 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
161 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
164 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
165 TRACE( "hwnd %04x (%d,%d)-(%d,%d)\n",
166 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
172 /***********************************************************************
173 * GetWindowRgn (USER32.@)
175 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
178 WND
*wndPtr
= WIN_GetPtr( hwnd
);
180 if (wndPtr
== WND_OTHER_PROCESS
)
182 if (IsWindow( hwnd
))
183 FIXME( "not supported on other process window %x\n", hwnd
);
188 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
191 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
192 WIN_ReleasePtr( wndPtr
);
197 /***********************************************************************
198 * SetWindowRgn (USER32.@)
200 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
205 if (hrgn
) /* verify that region really exists */
207 if (GetRgnBox( hrgn
, &rect
) == ERROR
) return FALSE
;
210 if (USER_Driver
.pSetWindowRgn
)
211 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
213 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
215 if (IsWindow( hwnd
))
216 FIXME( "not supported on other process window %x\n", hwnd
);
221 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
225 if (wndPtr
->hrgnWnd
== hrgn
)
227 WIN_ReleasePtr( wndPtr
);
233 /* delete previous region */
234 DeleteObject(wndPtr
->hrgnWnd
);
237 wndPtr
->hrgnWnd
= hrgn
;
238 WIN_ReleasePtr( wndPtr
);
240 /* Size the window to the rectangle of the new region (if it isn't NULL) */
241 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
242 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
243 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
244 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
249 /***********************************************************************
250 * GetClientRect (USER32.@)
252 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
256 rect
->right
= rect
->bottom
= 0;
257 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
259 rect
->right
-= rect
->left
;
260 rect
->bottom
-= rect
->top
;
262 rect
->left
= rect
->top
= 0;
267 /*******************************************************************
268 * ClientToScreen (USER32.@)
270 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
272 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
277 /*******************************************************************
278 * ScreenToClient (USER32.@)
280 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
282 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
287 /***********************************************************************
288 * find_child_from_point
290 * Find the child that contains pt. Helper for WindowFromPoint.
291 * pt is in parent client coordinates.
292 * lparam is the param to pass in the WM_NCHITTEST message.
294 static HWND
find_child_from_point( HWND parent
, POINT pt
, INT
*hittest
, LPARAM lparam
)
298 RECT rectWindow
, rectClient
;
300 HWND
*list
= WIN_ListChildren( parent
);
304 for (i
= 0; list
[i
]; i
++)
306 /* If point is in window, and window is visible, and it */
307 /* is enabled (or it's a top-level window), then explore */
308 /* its children. Otherwise, go to the next window. */
310 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
311 if (!(style
& WS_VISIBLE
)) continue; /* not visible -> skip */
312 if ((style
& (WS_POPUP
| WS_CHILD
| WS_DISABLED
)) == (WS_CHILD
| WS_DISABLED
))
313 continue; /* disabled child -> skip */
314 exstyle
= GetWindowLongW( list
[i
], GWL_EXSTYLE
);
315 if ((exstyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
| WS_EX_TRANSPARENT
))
316 continue; /* transparent -> skip */
318 if (!WIN_GetRectangles( list
[i
], &rectWindow
, &rectClient
)) continue;
319 if (!PtInRect( &rectWindow
, pt
)) continue; /* not in window -> skip */
321 /* FIXME: check window region for other processes too */
322 if ((wndPtr
= WIN_GetPtr( list
[i
] )) && wndPtr
!= WND_OTHER_PROCESS
)
324 if (wndPtr
->hrgnWnd
&& !PtInRegion( wndPtr
->hrgnWnd
,
325 pt
.x
- rectWindow
.left
, pt
.y
- rectWindow
.top
))
327 WIN_ReleasePtr( wndPtr
);
328 continue; /* point outside window region -> skip */
330 WIN_ReleasePtr( wndPtr
);
333 /* If window is minimized or disabled, return at once */
334 if (style
& WS_MINIMIZE
)
336 *hittest
= HTCAPTION
;
340 if (style
& WS_DISABLED
)
347 /* If point is in client area, explore children */
348 if (PtInRect( &rectClient
, pt
))
352 new_pt
.x
= pt
.x
- rectClient
.left
;
353 new_pt
.y
= pt
.y
- rectClient
.top
;
354 if ((retvalue
= find_child_from_point( list
[i
], new_pt
, hittest
, lparam
))) break;
357 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
358 if (!WIN_IsCurrentThread( list
[i
] ))
364 if ((res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, lparam
)) != HTTRANSPARENT
)
366 *hittest
= res
; /* Found the window */
370 /* continue search with next sibling */
372 HeapFree( GetProcessHeap(), 0, list
);
377 /***********************************************************************
378 * WINPOS_WindowFromPoint
380 * Find the window and hittest for a given point.
382 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
388 TRACE("scope %04x %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
390 if (!hwndScope
) hwndScope
= GetDesktopWindow();
391 style
= GetWindowLongW( hwndScope
, GWL_STYLE
);
394 if (style
& WS_DISABLED
) return 0;
396 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope
, GA_PARENT
), &xy
, 1 );
398 if (!(style
& WS_MINIMIZE
))
401 if (WIN_GetRectangles( hwndScope
, NULL
, &rectClient
) && PtInRect( &rectClient
, xy
))
405 xy
.x
-= rectClient
.left
;
406 xy
.y
-= rectClient
.top
;
407 if ((ret
= find_child_from_point( hwndScope
, xy
, hittest
, MAKELONG( pt
.x
, pt
.y
) )))
409 TRACE( "found child %x\n", ret
);
415 /* If nothing found, try the scope window */
416 if (!WIN_IsCurrentThread( hwndScope
))
419 TRACE( "returning %x\n", hwndScope
);
422 res
= SendMessageA( hwndScope
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
423 if (res
!= HTTRANSPARENT
)
425 *hittest
= res
; /* Found the window */
426 TRACE( "returning %x\n", hwndScope
);
429 *hittest
= HTNOWHERE
;
430 TRACE( "nothing found\n" );
435 /*******************************************************************
436 * WindowFromPoint (USER32.@)
438 HWND WINAPI
WindowFromPoint( POINT pt
)
441 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
445 /*******************************************************************
446 * ChildWindowFromPoint (USER32.@)
448 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
450 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
453 /*******************************************************************
454 * ChildWindowFromPointEx (USER32.@)
456 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
458 /* pt is in the client coordinates */
464 GetClientRect( hwndParent
, &rect
);
465 if (!PtInRect( &rect
, pt
)) return 0;
466 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
468 for (i
= 0; list
[i
]; i
++)
470 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
471 if (!PtInRect( &rect
, pt
)) continue;
472 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
474 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
475 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
476 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
478 if (uFlags
& CWP_SKIPTRANSPARENT
)
480 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
485 HeapFree( GetProcessHeap(), 0, list
);
486 if (!retvalue
) retvalue
= hwndParent
;
491 /*******************************************************************
492 * WINPOS_GetWinOffset
494 * Calculate the offset between the origin of the two windows. Used
495 * to implement MapWindowPoints.
497 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
501 offset
->x
= offset
->y
= 0;
503 /* Translate source window origin to screen coords */
506 HWND hwnd
= hwndFrom
;
510 if (hwnd
== hwndTo
) return;
511 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
513 ERR( "bad hwndFrom = %04x\n", hwnd
);
516 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
517 offset
->x
+= wndPtr
->rectClient
.left
;
518 offset
->y
+= wndPtr
->rectClient
.top
;
519 hwnd
= wndPtr
->parent
;
520 WIN_ReleasePtr( wndPtr
);
524 /* Translate origin to destination window coords */
531 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
533 ERR( "bad hwndTo = %04x\n", hwnd
);
536 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
537 offset
->x
-= wndPtr
->rectClient
.left
;
538 offset
->y
-= wndPtr
->rectClient
.top
;
539 hwnd
= wndPtr
->parent
;
540 WIN_ReleasePtr( wndPtr
);
545 other_process
: /* one of the parents may belong to another process, do it the hard way */
546 offset
->x
= offset
->y
= 0;
547 SERVER_START_REQ( get_windows_offset
)
549 req
->from
= hwndFrom
;
551 if (!wine_server_call( req
))
553 offset
->x
= reply
->x
;
554 offset
->y
= reply
->y
;
561 /*******************************************************************
562 * MapWindowPoints (USER.258)
564 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
565 LPPOINT16 lppt
, UINT16 count
)
569 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
579 /*******************************************************************
580 * MapWindowPoints (USER32.@)
582 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
586 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
593 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
597 /***********************************************************************
598 * IsIconic (USER32.@)
600 BOOL WINAPI
IsIconic(HWND hWnd
)
602 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
606 /***********************************************************************
607 * IsZoomed (USER32.@)
609 BOOL WINAPI
IsZoomed(HWND hWnd
)
611 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
615 /*******************************************************************
616 * AllowSetForegroundWindow (USER32.@)
618 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
620 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
621 * implemented, then fix this function. */
626 /*******************************************************************
627 * LockSetForegroundWindow (USER32.@)
629 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
631 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
632 * implemented, then fix this function. */
637 /*******************************************************************
638 * SetShellWindow (USER32.@)
640 HWND WINAPI
SetShellWindow(HWND hwndshell
)
641 { WARN("(hWnd=%08x) semi stub\n",hwndshell
);
643 hGlobalShellWindow
= WIN_GetFullHandle( hwndshell
);
644 return hGlobalShellWindow
;
648 /*******************************************************************
649 * GetShellWindow (USER32.@)
651 HWND WINAPI
GetShellWindow(void)
652 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow
);
654 return hGlobalShellWindow
;
658 /***********************************************************************
659 * BringWindowToTop (USER32.@)
661 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
663 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
667 /***********************************************************************
668 * MoveWindow (USER32.@)
670 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
673 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
674 if (!repaint
) flags
|= SWP_NOREDRAW
;
675 TRACE("%04x %d,%d %dx%d %d\n",
676 hwnd
, x
, y
, cx
, cy
, repaint
);
677 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
680 /***********************************************************************
681 * WINPOS_InitInternalPos
683 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
685 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
689 /* this happens when the window is minimized/maximized
690 * for the first time (rectWindow is not adjusted yet) */
692 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
693 if( !lpPos
) return NULL
;
695 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
696 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
697 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
698 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
701 if( wnd
->dwStyle
& WS_MINIMIZE
)
702 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
703 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
704 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
705 else if( restoreRect
)
706 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
711 /***********************************************************************
712 * WINPOS_RedrawIconTitle
714 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
716 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
719 if( lpPos
->hwndIconTitle
)
721 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
722 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
729 /***********************************************************************
730 * WINPOS_ShowIconTitle
732 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
734 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
736 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
738 HWND title
= lpPos
->hwndIconTitle
;
740 TRACE("0x%04x %i\n", hwnd
, (bShow
!= 0) );
743 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
746 if (!IsWindowVisible(title
))
748 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
749 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
750 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
753 else ShowWindow( title
, SW_HIDE
);
758 /*******************************************************************
759 * WINPOS_GetMinMaxInfo
761 * Get the minimized and maximized information for a window.
763 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
764 POINT
*minTrack
, POINT
*maxTrack
)
769 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
770 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
772 /* Compute default values */
774 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
775 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
776 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
777 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
778 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
779 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
781 if (HAS_DLGFRAME( style
, exstyle
))
783 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
784 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
789 if (HAS_THICKFRAME(style
))
791 xinc
+= GetSystemMetrics(SM_CXFRAME
);
792 yinc
+= GetSystemMetrics(SM_CYFRAME
);
794 if (style
& WS_BORDER
)
796 xinc
+= GetSystemMetrics(SM_CXBORDER
);
797 yinc
+= GetSystemMetrics(SM_CYBORDER
);
800 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
801 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
803 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
804 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
805 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
808 MinMax
.ptMaxPosition
.x
= -xinc
;
809 MinMax
.ptMaxPosition
.y
= -yinc
;
812 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
814 /* Some sanity checks */
816 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
817 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
818 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
819 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
820 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
821 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
822 MinMax
.ptMinTrackSize
.x
);
823 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
824 MinMax
.ptMinTrackSize
.y
);
826 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
827 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
828 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
829 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
832 /***********************************************************************
833 * ShowWindowAsync (USER32.@)
835 * doesn't wait; returns immediately.
836 * used by threads to toggle windows in other (possibly hanging) threads
838 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
840 /* FIXME: does ShowWindow() return immediately ? */
841 return ShowWindow(hwnd
, cmd
);
845 /***********************************************************************
846 * ShowWindow (USER32.@)
848 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
852 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
853 return USER_Driver
.pShowWindow( full_handle
, cmd
);
854 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
858 /***********************************************************************
859 * GetInternalWindowPos (USER.460)
861 UINT16 WINAPI
GetInternalWindowPos16( HWND16 hwnd
, LPRECT16 rectWnd
,
864 WINDOWPLACEMENT16 wndpl
;
865 if (GetWindowPlacement16( hwnd
, &wndpl
))
867 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
868 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
869 return wndpl
.showCmd
;
875 /***********************************************************************
876 * GetInternalWindowPos (USER32.@)
878 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
881 WINDOWPLACEMENT wndpl
;
882 if (GetWindowPlacement( hwnd
, &wndpl
))
884 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
885 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
886 return wndpl
.showCmd
;
892 /***********************************************************************
893 * GetWindowPlacement (USER32.@)
896 * Fails if wndpl->length of Win95 (!) apps is invalid.
898 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
900 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
903 if(!pWnd
) return FALSE
;
905 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
906 wndpl
->length
= sizeof(*wndpl
);
907 if( pWnd
->dwStyle
& WS_MINIMIZE
)
908 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
910 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
911 if( pWnd
->flags
& WIN_RESTORE_MAX
)
912 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
915 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
916 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
917 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
918 WIN_ReleaseWndPtr(pWnd
);
923 /***********************************************************************
924 * WINPOS_SetPlacement
926 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
928 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
931 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
932 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
934 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
935 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
936 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
938 if( pWnd
->dwStyle
& WS_MINIMIZE
)
940 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
941 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
942 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
943 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
945 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
947 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
948 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
949 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
951 else if( flags
& PLACE_RECT
)
952 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
953 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
954 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
955 SWP_NOZORDER
| SWP_NOACTIVATE
);
957 ShowWindow( hwnd
, wndpl
->showCmd
);
958 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
960 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
962 /* SDK: ...valid only the next time... */
963 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
965 WIN_ReleaseWndPtr(pWnd
);
972 /***********************************************************************
973 * SetWindowPlacement (USER32.@)
976 * Fails if wndpl->length of Win95 (!) apps is invalid.
978 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
980 if (!wpl
) return FALSE
;
981 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
985 /***********************************************************************
986 * AnimateWindow (USER32.@)
987 * Shows/Hides a window with an animation
990 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
992 FIXME("partial stub\n");
994 /* If trying to show/hide and it's already *
995 * shown/hidden or invalid window, fail with *
996 * invalid parameter */
997 if(!IsWindow(hwnd
) ||
998 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
999 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1001 SetLastError(ERROR_INVALID_PARAMETER
);
1005 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1010 /***********************************************************************
1011 * SetInternalWindowPos (USER32.@)
1013 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1014 LPRECT rect
, LPPOINT pt
)
1016 if( IsWindow(hwnd
) )
1018 WINDOWPLACEMENT wndpl
;
1021 wndpl
.length
= sizeof(wndpl
);
1022 wndpl
.showCmd
= showCmd
;
1023 wndpl
.flags
= flags
= 0;
1028 wndpl
.flags
|= WPF_SETMINPOSITION
;
1029 wndpl
.ptMinPosition
= *pt
;
1033 flags
|= PLACE_RECT
;
1034 wndpl
.rcNormalPosition
= *rect
;
1036 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1041 /*******************************************************************
1042 * can_activate_window
1044 * Check if we can activate the specified window.
1046 static BOOL
can_activate_window( HWND hwnd
)
1050 if (!hwnd
) return FALSE
;
1051 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1052 if (!(style
& WS_VISIBLE
)) return FALSE
;
1053 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1054 return !(style
& WS_DISABLED
);
1058 /*******************************************************************
1059 * WINPOS_ActivateOtherWindow
1061 * Activates window other than pWnd.
1063 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1067 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1069 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1070 if (can_activate_window( hwndTo
)) goto done
;
1076 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1077 if (can_activate_window( hwndTo
)) break;
1081 fg
= GetForegroundWindow();
1082 TRACE("win = %x fg = %x\n", hwndTo
, fg
);
1083 if (!fg
|| (hwnd
== fg
))
1085 if (SetForegroundWindow( hwndTo
)) return;
1087 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1091 /***********************************************************************
1092 * WINPOS_HandleWindowPosChanging16
1094 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1096 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1098 POINT maxSize
, minTrack
;
1099 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1101 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1102 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1104 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1105 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1106 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1107 if (!(style
& WS_MINIMIZE
))
1109 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1110 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1117 /***********************************************************************
1118 * WINPOS_HandleWindowPosChanging
1120 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1122 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1124 POINT maxSize
, minTrack
;
1125 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1127 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1128 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1130 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1131 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1132 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1133 if (!(style
& WS_MINIMIZE
))
1135 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1136 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1143 /***********************************************************************
1146 static void dump_winpos_flags(UINT flags
)
1149 if(flags
& SWP_NOSIZE
) DPRINTF(" SWP_NOSIZE");
1150 if(flags
& SWP_NOMOVE
) DPRINTF(" SWP_NOMOVE");
1151 if(flags
& SWP_NOZORDER
) DPRINTF(" SWP_NOZORDER");
1152 if(flags
& SWP_NOREDRAW
) DPRINTF(" SWP_NOREDRAW");
1153 if(flags
& SWP_NOACTIVATE
) DPRINTF(" SWP_NOACTIVATE");
1154 if(flags
& SWP_FRAMECHANGED
) DPRINTF(" SWP_FRAMECHANGED");
1155 if(flags
& SWP_SHOWWINDOW
) DPRINTF(" SWP_SHOWWINDOW");
1156 if(flags
& SWP_HIDEWINDOW
) DPRINTF(" SWP_HIDEWINDOW");
1157 if(flags
& SWP_NOCOPYBITS
) DPRINTF(" SWP_NOCOPYBITS");
1158 if(flags
& SWP_NOOWNERZORDER
) DPRINTF(" SWP_NOOWNERZORDER");
1159 if(flags
& SWP_NOSENDCHANGING
) DPRINTF(" SWP_NOSENDCHANGING");
1160 if(flags
& SWP_DEFERERASE
) DPRINTF(" SWP_DEFERERASE");
1161 if(flags
& SWP_ASYNCWINDOWPOS
) DPRINTF(" SWP_ASYNCWINDOWPOS");
1163 #define DUMPED_FLAGS \
1169 SWP_FRAMECHANGED | \
1173 SWP_NOOWNERZORDER | \
1174 SWP_NOSENDCHANGING | \
1178 if(flags
& ~DUMPED_FLAGS
) DPRINTF(" %08x", flags
& ~DUMPED_FLAGS
);
1183 /***********************************************************************
1184 * SetWindowPos (USER32.@)
1186 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1187 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1191 TRACE("hwnd %x, after %x, %d,%d (%dx%d), flags %08x\n",
1192 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1193 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1196 winpos
.hwndInsertAfter
= hwndInsertAfter
;
1201 winpos
.flags
= flags
;
1202 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1203 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1207 /***********************************************************************
1208 * BeginDeferWindowPos (USER32.@)
1210 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1217 SetLastError(ERROR_INVALID_PARAMETER
);
1220 /* Windows allows zero count, in which case it allocates context for 8 moves */
1221 if (count
== 0) count
= 8;
1223 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1224 if (!handle
) return 0;
1225 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1226 pDWP
->actualCount
= 0;
1227 pDWP
->suggestedCount
= count
;
1229 pDWP
->wMagic
= DWP_MAGIC
;
1230 pDWP
->hwndParent
= 0;
1235 /***********************************************************************
1236 * DeferWindowPos (USER32.@)
1238 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1239 INT x
, INT y
, INT cx
, INT cy
,
1244 HDWP newhdwp
= hdwp
,retvalue
;
1246 hwnd
= WIN_GetFullHandle( hwnd
);
1247 if (hwnd
== GetDesktopWindow()) return 0;
1249 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1253 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1255 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1257 /* Merge with the other changes */
1258 if (!(flags
& SWP_NOZORDER
))
1260 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
1262 if (!(flags
& SWP_NOMOVE
))
1264 pDWP
->winPos
[i
].x
= x
;
1265 pDWP
->winPos
[i
].y
= y
;
1267 if (!(flags
& SWP_NOSIZE
))
1269 pDWP
->winPos
[i
].cx
= cx
;
1270 pDWP
->winPos
[i
].cy
= cy
;
1272 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1273 SWP_NOZORDER
| SWP_NOREDRAW
|
1274 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1276 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1282 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1284 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1285 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1291 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1292 pDWP
->suggestedCount
++;
1294 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1295 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1296 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1297 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1298 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1299 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1300 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1301 pDWP
->actualCount
++;
1309 /***********************************************************************
1310 * EndDeferWindowPos (USER32.@)
1312 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1319 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1320 if (!pDWP
) return FALSE
;
1321 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1323 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1325 USER_HEAP_FREE( hdwp
);
1330 /***********************************************************************
1331 * TileChildWindows (USER.199)
1333 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1335 FIXME("(%04x, %d): stub\n", parent
, action
);
1338 /***********************************************************************
1339 * CascadeChildWindows (USER.198)
1341 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1343 FIXME("(%04x, %d): stub\n", parent
, action
);
1346 /***********************************************************************
1347 * SetProgmanWindow (USER32.@)
1349 HWND WINAPI
SetProgmanWindow ( HWND hwnd
)
1351 hGlobalProgmanWindow
= hwnd
;
1352 return hGlobalProgmanWindow
;
1355 /***********************************************************************
1356 * GetProgmanWindow (USER32.@)
1358 HWND WINAPI
GetProgmanWindow(void)
1360 return hGlobalProgmanWindow
;
1363 /***********************************************************************
1364 * SetShellWindowEx (USER32.@)
1365 * hwndProgman = Progman[Program Manager]
1366 * |-> SHELLDLL_DefView
1367 * hwndListView = | |-> SysListView32
1368 * | | |-> tooltips_class32
1374 HWND WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
1376 FIXME("0x%08x 0x%08x stub\n",hwndProgman
,hwndListView
);
1377 hGlobalShellWindow
= hwndProgman
;
1378 return hGlobalShellWindow
;
1382 /***********************************************************************
1383 * SetTaskmanWindow (USER32.@)
1385 * hwnd = MSTaskSwWClass
1386 * |-> SysTabControl32
1388 HWND WINAPI
SetTaskmanWindow ( HWND hwnd
)
1390 hGlobalTaskmanWindow
= hwnd
;
1391 return hGlobalTaskmanWindow
;
1394 /***********************************************************************
1395 * GetTaskmanWindow (USER32.@)
1397 HWND WINAPI
GetTaskmanWindow(void)
1399 return hGlobalTaskmanWindow
;