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
23 #include "wine/port.h"
33 #include "wine/winuser16.h"
34 #include "wine/server.h"
36 #include "user_private.h"
40 #include "nonclient.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(win
);
45 #define HAS_DLGFRAME(style,exStyle) \
46 (((exStyle) & WS_EX_DLGMODALFRAME) || \
47 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
49 #define HAS_THICKFRAME(style) \
50 (((style) & WS_THICKFRAME) && \
51 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
53 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
55 #define PLACE_MIN 0x0001
56 #define PLACE_MAX 0x0002
57 #define PLACE_RECT 0x0004
60 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
78 } INTERNALPOS
, *LPINTERNALPOS
;
80 /* ----- internal variables ----- */
82 static LPCSTR atomInternalPos
;
85 /***********************************************************************
86 * WINPOS_CreateInternalPosAtom
88 BOOL
WINPOS_CreateInternalPosAtom()
91 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
92 return (atomInternalPos
) ? TRUE
: FALSE
;
95 /***********************************************************************
96 * WINPOS_CheckInternalPos
98 * Called when a window is destroyed.
100 void WINPOS_CheckInternalPos( HWND hwnd
)
102 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
106 if( IsWindow(lpPos
->hwndIconTitle
) )
107 DestroyWindow( lpPos
->hwndIconTitle
);
108 HeapFree( GetProcessHeap(), 0, lpPos
);
112 /***********************************************************************
113 * ArrangeIconicWindows (USER32.@)
115 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
119 INT x
, y
, xspacing
, yspacing
;
121 GetClientRect( parent
, &rectParent
);
123 y
= rectParent
.bottom
;
124 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
125 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
127 hwndChild
= GetWindow( parent
, GW_CHILD
);
130 if( IsIconic( hwndChild
) )
132 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
134 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
135 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
136 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
137 if( IsWindow(hwndChild
) )
138 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
140 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
147 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
153 /***********************************************************************
154 * SwitchToThisWindow (USER32.@)
156 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
158 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
162 /***********************************************************************
163 * GetWindowRect (USER32.@)
165 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
167 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
170 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
171 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
172 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
178 /***********************************************************************
179 * GetWindowRgn (USER32.@)
181 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
191 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
193 SetLastError( ERROR_OUTOFMEMORY
);
196 SERVER_START_REQ( get_window_region
)
199 wine_server_set_reply( req
, data
->Buffer
, size
);
200 if (!(status
= wine_server_call( req
)))
202 size_t reply_size
= wine_server_reply_size( reply
);
205 data
->rdh
.dwSize
= sizeof(data
->rdh
);
206 data
->rdh
.iType
= RDH_RECTANGLES
;
207 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
208 data
->rdh
.nRgnSize
= reply_size
;
209 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
212 else size
= reply
->total_size
;
215 HeapFree( GetProcessHeap(), 0, data
);
216 } while (status
== STATUS_BUFFER_OVERFLOW
);
218 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
221 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
222 DeleteObject( win_rgn
);
228 /***********************************************************************
229 * SetWindowRgn (USER32.@)
231 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
233 static const RECT empty_rect
;
241 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
242 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
243 if (!GetRegionData( hrgn
, size
, data
))
245 HeapFree( GetProcessHeap(), 0, data
);
248 SERVER_START_REQ( set_window_region
)
251 if (data
->rdh
.nCount
)
252 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
254 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
255 ret
= !wine_server_call_err( req
);
259 else /* clear existing region */
261 SERVER_START_REQ( set_window_region
)
264 ret
= !wine_server_call_err( req
);
269 if (ret
&& USER_Driver
.pSetWindowRgn
)
270 ret
= USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
272 if (ret
&& bRedraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
277 /***********************************************************************
278 * GetClientRect (USER32.@)
280 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
284 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
286 rect
->right
-= rect
->left
;
287 rect
->bottom
-= rect
->top
;
288 rect
->left
= rect
->top
= 0;
294 /*******************************************************************
295 * ClientToScreen (USER32.@)
297 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
299 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
304 /*******************************************************************
305 * ScreenToClient (USER32.@)
307 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
309 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
314 /***********************************************************************
315 * list_children_from_point
317 * Get the list of children that can contain point from the server.
318 * Point is in screen coordinates.
319 * Returned list must be freed by caller.
321 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
330 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
332 SERVER_START_REQ( get_window_children_from_point
)
337 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
338 if (!wine_server_call( req
)) count
= reply
->count
;
341 if (count
&& count
< size
)
346 HeapFree( GetProcessHeap(), 0, list
);
348 size
= count
+ 1; /* restart with a large enough buffer */
354 /***********************************************************************
355 * WINPOS_WindowFromPoint
357 * Find the window and hittest for a given point.
359 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
364 if (!hwndScope
) hwndScope
= GetDesktopWindow();
366 *hittest
= HTNOWHERE
;
368 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
370 /* now determine the hittest */
372 for (i
= 0; list
[i
]; i
++)
374 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
376 /* If window is minimized or disabled, return at once */
377 if (style
& WS_MINIMIZE
)
379 *hittest
= HTCAPTION
;
382 if (style
& WS_DISABLED
)
387 /* Send WM_NCCHITTEST (if same thread) */
388 if (!WIN_IsCurrentThread( list
[i
] ))
393 res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
394 if (res
!= HTTRANSPARENT
)
396 *hittest
= res
; /* Found the window */
399 /* continue search with next window in z-order */
402 HeapFree( GetProcessHeap(), 0, list
);
403 TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
408 /*******************************************************************
409 * WindowFromPoint (USER32.@)
411 HWND WINAPI
WindowFromPoint( POINT pt
)
414 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
418 /*******************************************************************
419 * ChildWindowFromPoint (USER32.@)
421 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
423 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
426 /*******************************************************************
427 * ChildWindowFromPointEx (USER32.@)
429 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
431 /* pt is in the client coordinates */
437 GetClientRect( hwndParent
, &rect
);
438 if (!PtInRect( &rect
, pt
)) return 0;
439 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
441 for (i
= 0; list
[i
]; i
++)
443 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
444 if (!PtInRect( &rect
, pt
)) continue;
445 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
447 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
448 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
449 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
451 if (uFlags
& CWP_SKIPTRANSPARENT
)
453 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
458 HeapFree( GetProcessHeap(), 0, list
);
459 if (!retvalue
) retvalue
= hwndParent
;
464 /*******************************************************************
465 * WINPOS_GetWinOffset
467 * Calculate the offset between the origin of the two windows. Used
468 * to implement MapWindowPoints.
470 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
474 offset
->x
= offset
->y
= 0;
476 /* Translate source window origin to screen coords */
479 HWND hwnd
= hwndFrom
;
483 if (hwnd
== hwndTo
) return;
484 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
486 ERR( "bad hwndFrom = %p\n", hwnd
);
489 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
490 offset
->x
+= wndPtr
->rectClient
.left
;
491 offset
->y
+= wndPtr
->rectClient
.top
;
492 hwnd
= wndPtr
->parent
;
493 WIN_ReleasePtr( wndPtr
);
497 /* Translate origin to destination window coords */
504 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
506 ERR( "bad hwndTo = %p\n", hwnd
);
509 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
510 offset
->x
-= wndPtr
->rectClient
.left
;
511 offset
->y
-= wndPtr
->rectClient
.top
;
512 hwnd
= wndPtr
->parent
;
513 WIN_ReleasePtr( wndPtr
);
518 other_process
: /* one of the parents may belong to another process, do it the hard way */
519 offset
->x
= offset
->y
= 0;
520 SERVER_START_REQ( get_windows_offset
)
522 req
->from
= hwndFrom
;
524 if (!wine_server_call( req
))
526 offset
->x
= reply
->x
;
527 offset
->y
= reply
->y
;
534 /*******************************************************************
535 * MapWindowPoints (USER.258)
537 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
538 LPPOINT16 lppt
, UINT16 count
)
542 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
552 /*******************************************************************
553 * MapWindowPoints (USER32.@)
555 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
559 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
566 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
570 /***********************************************************************
571 * IsIconic (USER32.@)
573 BOOL WINAPI
IsIconic(HWND hWnd
)
575 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
579 /***********************************************************************
580 * IsZoomed (USER32.@)
582 BOOL WINAPI
IsZoomed(HWND hWnd
)
584 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
588 /*******************************************************************
589 * AllowSetForegroundWindow (USER32.@)
591 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
593 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
594 * implemented, then fix this function. */
599 /*******************************************************************
600 * LockSetForegroundWindow (USER32.@)
602 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
604 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
605 * implemented, then fix this function. */
610 /***********************************************************************
611 * BringWindowToTop (USER32.@)
613 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
615 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
619 /***********************************************************************
620 * MoveWindow (USER32.@)
622 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
625 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
626 if (!repaint
) flags
|= SWP_NOREDRAW
;
627 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
628 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
631 /***********************************************************************
632 * WINPOS_InitInternalPos
634 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
636 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
640 /* this happens when the window is minimized/maximized
641 * for the first time (rectWindow is not adjusted yet) */
643 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
644 if( !lpPos
) return NULL
;
646 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
647 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
648 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
649 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
650 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
651 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
652 lpPos
->ptIconPos
.x
= lpPos
->ptIconPos
.y
= -1;
653 lpPos
->ptMaxPos
.x
= lpPos
->ptMaxPos
.y
= -1;
656 if( wnd
->dwStyle
& WS_MINIMIZE
)
658 lpPos
->ptIconPos
.x
= pt
.x
;
659 lpPos
->ptIconPos
.y
= pt
.y
;
661 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
663 lpPos
->ptMaxPos
.x
= pt
.x
;
664 lpPos
->ptMaxPos
.y
= pt
.y
;
666 else if( restoreRect
)
668 lpPos
->rectNormal
.left
= restoreRect
->left
;
669 lpPos
->rectNormal
.top
= restoreRect
->top
;
670 lpPos
->rectNormal
.right
= restoreRect
->right
;
671 lpPos
->rectNormal
.bottom
= restoreRect
->bottom
;
676 /***********************************************************************
677 * WINPOS_RedrawIconTitle
679 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
681 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
684 if( lpPos
->hwndIconTitle
)
686 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
687 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
694 /***********************************************************************
695 * WINPOS_ShowIconTitle
697 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
699 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
701 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
703 HWND title
= lpPos
->hwndIconTitle
;
705 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
708 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
711 if (!IsWindowVisible(title
))
713 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
714 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
715 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
718 else ShowWindow( title
, SW_HIDE
);
723 /*******************************************************************
724 * WINPOS_GetMinMaxInfo
726 * Get the minimized and maximized information for a window.
728 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
729 POINT
*minTrack
, POINT
*maxTrack
)
734 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
735 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
738 /* Compute default values */
740 GetWindowRect(hwnd
, &rc
);
741 MinMax
.ptReserved
.x
= rc
.left
;
742 MinMax
.ptReserved
.y
= rc
.top
;
744 if (style
& WS_CHILD
)
746 if ((style
& WS_CAPTION
) == WS_CAPTION
)
747 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
749 GetClientRect(GetParent(hwnd
), &rc
);
750 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
752 /* avoid calculating this twice */
753 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
755 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
756 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
760 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
761 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
763 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
764 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
765 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
766 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
768 if (HAS_DLGFRAME( style
, exstyle
))
770 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
771 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
776 if (HAS_THICKFRAME(style
))
778 xinc
+= GetSystemMetrics(SM_CXFRAME
);
779 yinc
+= GetSystemMetrics(SM_CYFRAME
);
781 if (style
& WS_BORDER
)
783 xinc
+= GetSystemMetrics(SM_CXBORDER
);
784 yinc
+= GetSystemMetrics(SM_CYBORDER
);
787 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
788 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
790 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
791 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
793 MinMax
.ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
794 MinMax
.ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
798 MinMax
.ptMaxPosition
.x
= -xinc
;
799 MinMax
.ptMaxPosition
.y
= -yinc
;
802 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
804 /* Some sanity checks */
806 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
807 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
808 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
809 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
810 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
811 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
812 MinMax
.ptMinTrackSize
.x
);
813 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
814 MinMax
.ptMinTrackSize
.y
);
816 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
817 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
818 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
819 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
822 /***********************************************************************
823 * ShowWindowAsync (USER32.@)
825 * doesn't wait; returns immediately.
826 * used by threads to toggle windows in other (possibly hanging) threads
828 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
832 if (is_broadcast(hwnd
))
834 SetLastError( ERROR_INVALID_PARAMETER
);
838 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
840 if (USER_Driver
.pShowWindow
)
841 return USER_Driver
.pShowWindow( full_handle
, cmd
);
844 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
848 /***********************************************************************
849 * ShowWindow (USER32.@)
851 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
855 if (is_broadcast(hwnd
))
857 SetLastError( ERROR_INVALID_PARAMETER
);
860 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
862 if (USER_Driver
.pShowWindow
)
863 return USER_Driver
.pShowWindow( full_handle
, cmd
);
866 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
870 /***********************************************************************
871 * GetInternalWindowPos (USER32.@)
873 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
876 WINDOWPLACEMENT wndpl
;
877 if (GetWindowPlacement( hwnd
, &wndpl
))
879 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
880 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
881 return wndpl
.showCmd
;
887 /***********************************************************************
888 * GetWindowPlacement (USER32.@)
891 * Fails if wndpl->length of Win95 (!) apps is invalid.
893 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
895 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
898 if(!pWnd
) return FALSE
;
900 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
901 wndpl
->length
= sizeof(*wndpl
);
902 if( pWnd
->dwStyle
& WS_MINIMIZE
)
903 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
905 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
906 if( pWnd
->flags
& WIN_RESTORE_MAX
)
907 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
910 wndpl
->ptMinPosition
.x
= lpPos
->ptIconPos
.x
;
911 wndpl
->ptMinPosition
.y
= lpPos
->ptIconPos
.y
;
912 wndpl
->ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
913 wndpl
->ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
914 wndpl
->rcNormalPosition
.left
= lpPos
->rectNormal
.left
;
915 wndpl
->rcNormalPosition
.top
= lpPos
->rectNormal
.top
;
916 wndpl
->rcNormalPosition
.right
= lpPos
->rectNormal
.right
;
917 wndpl
->rcNormalPosition
.bottom
= lpPos
->rectNormal
.bottom
;
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
)
936 lpPos
->ptIconPos
.x
= wndpl
->ptMinPosition
.x
;
937 lpPos
->ptIconPos
.y
= wndpl
->ptMinPosition
.y
;
939 if( flags
& PLACE_MAX
)
941 lpPos
->ptMaxPos
.x
= wndpl
->ptMaxPosition
.x
;
942 lpPos
->ptMaxPos
.y
= wndpl
->ptMaxPosition
.y
;
944 if( flags
& PLACE_RECT
)
946 lpPos
->rectNormal
.left
= wndpl
->rcNormalPosition
.left
;
947 lpPos
->rectNormal
.top
= wndpl
->rcNormalPosition
.top
;
948 lpPos
->rectNormal
.right
= wndpl
->rcNormalPosition
.right
;
949 lpPos
->rectNormal
.bottom
= wndpl
->rcNormalPosition
.bottom
;
951 if( pWnd
->dwStyle
& WS_MINIMIZE
)
953 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
954 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
955 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
956 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
958 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
960 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
961 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
962 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
964 else if( flags
& PLACE_RECT
)
965 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
966 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
967 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
968 SWP_NOZORDER
| SWP_NOACTIVATE
);
970 ShowWindow( hwnd
, wndpl
->showCmd
);
971 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
973 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
975 /* SDK: ...valid only the next time... */
976 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
978 WIN_ReleaseWndPtr(pWnd
);
985 /***********************************************************************
986 * SetWindowPlacement (USER32.@)
989 * Fails if wndpl->length of Win95 (!) apps is invalid.
991 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
993 if (!wpl
) return FALSE
;
994 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
998 /***********************************************************************
999 * AnimateWindow (USER32.@)
1000 * Shows/Hides a window with an animation
1003 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1005 FIXME("partial stub\n");
1007 /* If trying to show/hide and it's already *
1008 * shown/hidden or invalid window, fail with *
1009 * invalid parameter */
1010 if(!IsWindow(hwnd
) ||
1011 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1012 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1014 SetLastError(ERROR_INVALID_PARAMETER
);
1018 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1023 /***********************************************************************
1024 * SetInternalWindowPos (USER32.@)
1026 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1027 LPRECT rect
, LPPOINT pt
)
1029 if( IsWindow(hwnd
) )
1031 WINDOWPLACEMENT wndpl
;
1034 wndpl
.length
= sizeof(wndpl
);
1035 wndpl
.showCmd
= showCmd
;
1036 wndpl
.flags
= flags
= 0;
1041 wndpl
.flags
|= WPF_SETMINPOSITION
;
1042 wndpl
.ptMinPosition
= *pt
;
1046 flags
|= PLACE_RECT
;
1047 wndpl
.rcNormalPosition
= *rect
;
1049 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1054 /*******************************************************************
1055 * can_activate_window
1057 * Check if we can activate the specified window.
1059 static BOOL
can_activate_window( HWND hwnd
)
1063 if (!hwnd
) return FALSE
;
1064 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1065 if (!(style
& WS_VISIBLE
)) return FALSE
;
1066 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1067 return !(style
& WS_DISABLED
);
1071 /*******************************************************************
1072 * WINPOS_ActivateOtherWindow
1074 * Activates window other than pWnd.
1076 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1080 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1082 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1083 if (can_activate_window( hwndTo
)) goto done
;
1089 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1090 if (can_activate_window( hwndTo
)) break;
1094 fg
= GetForegroundWindow();
1095 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1096 if (!fg
|| (hwnd
== fg
))
1098 if (SetForegroundWindow( hwndTo
)) return;
1100 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1104 /***********************************************************************
1105 * WINPOS_HandleWindowPosChanging16
1107 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1109 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1111 POINT minTrack
, maxTrack
;
1112 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1114 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1115 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1117 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1118 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1119 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1120 if (!(style
& WS_MINIMIZE
))
1122 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1123 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1130 /***********************************************************************
1131 * WINPOS_HandleWindowPosChanging
1133 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1135 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1137 POINT minTrack
, maxTrack
;
1138 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1140 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1141 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1143 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1144 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1145 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1146 if (!(style
& WS_MINIMIZE
))
1148 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1149 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1156 /***********************************************************************
1159 static void dump_winpos_flags(UINT flags
)
1162 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1163 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1164 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1165 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1166 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1167 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1168 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1169 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1170 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1171 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1172 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1173 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1174 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1176 #define DUMPED_FLAGS \
1182 SWP_FRAMECHANGED | \
1186 SWP_NOOWNERZORDER | \
1187 SWP_NOSENDCHANGING | \
1191 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1196 /***********************************************************************
1197 * SetWindowPos (USER32.@)
1199 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1200 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1204 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1205 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1206 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1208 if (is_broadcast(hwnd
))
1210 SetLastError( ERROR_INVALID_PARAMETER
);
1214 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1215 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1220 winpos
.flags
= flags
;
1221 if (WIN_IsCurrentThread( hwnd
))
1223 if (USER_Driver
.pSetWindowPos
)
1224 return USER_Driver
.pSetWindowPos( &winpos
);
1227 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1231 /***********************************************************************
1232 * BeginDeferWindowPos (USER32.@)
1234 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1239 TRACE("%d\n", count
);
1243 SetLastError(ERROR_INVALID_PARAMETER
);
1246 /* Windows allows zero count, in which case it allocates context for 8 moves */
1247 if (count
== 0) count
= 8;
1249 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1250 if (!handle
) return 0;
1251 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1252 pDWP
->actualCount
= 0;
1253 pDWP
->suggestedCount
= count
;
1255 pDWP
->wMagic
= DWP_MAGIC
;
1256 pDWP
->hwndParent
= 0;
1258 TRACE("returning hdwp %p\n", handle
);
1263 /***********************************************************************
1264 * DeferWindowPos (USER32.@)
1266 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1267 INT x
, INT y
, INT cx
, INT cy
,
1272 HDWP newhdwp
= hdwp
,retvalue
;
1274 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1275 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
1277 hwnd
= WIN_GetFullHandle( hwnd
);
1278 if (hwnd
== GetDesktopWindow()) return 0;
1280 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1284 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1286 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1288 /* Merge with the other changes */
1289 if (!(flags
& SWP_NOZORDER
))
1291 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1293 if (!(flags
& SWP_NOMOVE
))
1295 pDWP
->winPos
[i
].x
= x
;
1296 pDWP
->winPos
[i
].y
= y
;
1298 if (!(flags
& SWP_NOSIZE
))
1300 pDWP
->winPos
[i
].cx
= cx
;
1301 pDWP
->winPos
[i
].cy
= cy
;
1303 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1304 SWP_NOZORDER
| SWP_NOREDRAW
|
1305 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1307 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1313 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1315 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1316 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1322 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1323 pDWP
->suggestedCount
++;
1325 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1326 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1327 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1328 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1329 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1330 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1331 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1332 pDWP
->actualCount
++;
1340 /***********************************************************************
1341 * EndDeferWindowPos (USER32.@)
1343 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1350 TRACE("%p\n", hdwp
);
1352 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1353 if (!pDWP
) return FALSE
;
1354 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1356 if (!USER_Driver
.pSetWindowPos
|| !(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1358 USER_HEAP_FREE( hdwp
);
1363 /***********************************************************************
1364 * TileChildWindows (USER.199)
1366 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1368 FIXME("(%04x, %d): stub\n", parent
, action
);
1371 /***********************************************************************
1372 * CascadeChildWindows (USER.198)
1374 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1376 FIXME("(%04x, %d): stub\n", parent
, action
);