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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
28 #define WIN32_NO_STATUS
34 #include "wine/winuser16.h"
35 #include "wine/server.h"
37 #include "user_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
58 #define PLACE_MIN 0x0001
59 #define PLACE_MAX 0x0002
60 #define PLACE_RECT 0x0004
63 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
81 } INTERNALPOS
, *LPINTERNALPOS
;
83 /* ----- internal functions ----- */
85 static const WCHAR SysIP_W
[] = { 'S','y','s','I','P',0 };
87 static inline INTERNALPOS
*get_internal_pos( HWND hwnd
)
89 return GetPropW( hwnd
, SysIP_W
);
92 static inline void set_internal_pos( HWND hwnd
, INTERNALPOS
*pos
)
94 SetPropW( hwnd
, SysIP_W
, pos
);
97 /***********************************************************************
98 * WINPOS_CheckInternalPos
100 * Called when a window is destroyed.
102 void WINPOS_CheckInternalPos( HWND hwnd
)
104 LPINTERNALPOS lpPos
= get_internal_pos( hwnd
);
108 if( IsWindow(lpPos
->hwndIconTitle
) )
109 DestroyWindow( lpPos
->hwndIconTitle
);
110 HeapFree( GetProcessHeap(), 0, lpPos
);
114 /***********************************************************************
115 * ArrangeIconicWindows (USER32.@)
117 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
121 INT x
, y
, xspacing
, yspacing
;
123 GetClientRect( parent
, &rectParent
);
125 y
= rectParent
.bottom
;
126 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
127 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
129 hwndChild
= GetWindow( parent
, GW_CHILD
);
132 if( IsIconic( hwndChild
) )
134 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
136 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
137 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
138 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
139 if( IsWindow(hwndChild
) )
140 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
142 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
149 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
155 /***********************************************************************
156 * SwitchToThisWindow (USER32.@)
158 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
160 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
164 /***********************************************************************
165 * GetWindowRect (USER32.@)
167 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
169 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
172 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
173 TRACE( "hwnd %p (%d,%d)-(%d,%d)\n",
174 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
180 /***********************************************************************
181 * GetWindowRgn (USER32.@)
183 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
193 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
195 SetLastError( ERROR_OUTOFMEMORY
);
198 SERVER_START_REQ( get_window_region
)
201 wine_server_set_reply( req
, data
->Buffer
, size
);
202 if (!(status
= wine_server_call( req
)))
204 size_t reply_size
= wine_server_reply_size( reply
);
207 data
->rdh
.dwSize
= sizeof(data
->rdh
);
208 data
->rdh
.iType
= RDH_RECTANGLES
;
209 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
210 data
->rdh
.nRgnSize
= reply_size
;
211 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
214 else size
= reply
->total_size
;
217 HeapFree( GetProcessHeap(), 0, data
);
218 } while (status
== STATUS_BUFFER_OVERFLOW
);
220 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
223 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
224 DeleteObject( win_rgn
);
230 /***********************************************************************
231 * SetWindowRgn (USER32.@)
233 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
235 static const RECT empty_rect
;
243 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
244 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
245 if (!GetRegionData( hrgn
, size
, data
))
247 HeapFree( GetProcessHeap(), 0, data
);
250 SERVER_START_REQ( set_window_region
)
253 req
->redraw
= (bRedraw
!= 0);
254 if (data
->rdh
.nCount
)
255 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
257 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
258 ret
= !wine_server_call_err( req
);
262 else /* clear existing region */
264 SERVER_START_REQ( set_window_region
)
267 req
->redraw
= (bRedraw
!= 0);
268 ret
= !wine_server_call_err( req
);
273 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
277 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
;
278 if (hrgn
) swp_flags
|= SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
279 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
280 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
286 /***********************************************************************
287 * GetClientRect (USER32.@)
289 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
293 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
295 rect
->right
-= rect
->left
;
296 rect
->bottom
-= rect
->top
;
297 rect
->left
= rect
->top
= 0;
303 /*******************************************************************
304 * ClientToScreen (USER32.@)
306 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
308 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
313 /*******************************************************************
314 * ScreenToClient (USER32.@)
316 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
318 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
323 /***********************************************************************
324 * list_children_from_point
326 * Get the list of children that can contain point from the server.
327 * Point is in screen coordinates.
328 * Returned list must be freed by caller.
330 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
339 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
341 SERVER_START_REQ( get_window_children_from_point
)
346 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
347 if (!wine_server_call( req
)) count
= reply
->count
;
350 if (count
&& count
< size
)
355 HeapFree( GetProcessHeap(), 0, list
);
357 size
= count
+ 1; /* restart with a large enough buffer */
363 /***********************************************************************
364 * WINPOS_WindowFromPoint
366 * Find the window and hittest for a given point.
368 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
373 if (!hwndScope
) hwndScope
= GetDesktopWindow();
375 *hittest
= HTNOWHERE
;
377 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
379 /* now determine the hittest */
381 for (i
= 0; list
[i
]; i
++)
383 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
385 /* If window is minimized or disabled, return at once */
386 if (style
& WS_MINIMIZE
)
388 *hittest
= HTCAPTION
;
391 if (style
& WS_DISABLED
)
396 /* Send WM_NCCHITTEST (if same thread) */
397 if (!WIN_IsCurrentThread( list
[i
] ))
402 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
403 if (res
!= HTTRANSPARENT
)
405 *hittest
= res
; /* Found the window */
408 /* continue search with next window in z-order */
411 HeapFree( GetProcessHeap(), 0, list
);
412 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
417 /*******************************************************************
418 * WindowFromPoint (USER32.@)
420 HWND WINAPI
WindowFromPoint( POINT pt
)
423 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
427 /*******************************************************************
428 * ChildWindowFromPoint (USER32.@)
430 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
432 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
435 /*******************************************************************
436 * RealChildWindowFromPoint (USER32.@)
438 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
440 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
);
443 /*******************************************************************
444 * ChildWindowFromPointEx (USER32.@)
446 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
448 /* pt is in the client coordinates */
454 GetClientRect( hwndParent
, &rect
);
455 if (!PtInRect( &rect
, pt
)) return 0;
456 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
458 for (i
= 0; list
[i
]; i
++)
460 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
461 if (!PtInRect( &rect
, pt
)) continue;
462 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
464 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
465 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
466 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
468 if (uFlags
& CWP_SKIPTRANSPARENT
)
470 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
475 HeapFree( GetProcessHeap(), 0, list
);
476 if (!retvalue
) retvalue
= hwndParent
;
481 /*******************************************************************
482 * WINPOS_GetWinOffset
484 * Calculate the offset between the origin of the two windows. Used
485 * to implement MapWindowPoints.
487 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
491 offset
->x
= offset
->y
= 0;
493 /* Translate source window origin to screen coords */
496 HWND hwnd
= hwndFrom
;
500 if (hwnd
== hwndTo
) return;
501 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
503 ERR( "bad hwndFrom = %p\n", hwnd
);
506 if (wndPtr
== WND_DESKTOP
) break;
507 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
508 offset
->x
+= wndPtr
->rectClient
.left
;
509 offset
->y
+= wndPtr
->rectClient
.top
;
510 hwnd
= wndPtr
->parent
;
511 WIN_ReleasePtr( wndPtr
);
515 /* Translate origin to destination window coords */
522 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
524 ERR( "bad hwndTo = %p\n", hwnd
);
527 if (wndPtr
== WND_DESKTOP
) break;
528 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
529 offset
->x
-= wndPtr
->rectClient
.left
;
530 offset
->y
-= wndPtr
->rectClient
.top
;
531 hwnd
= wndPtr
->parent
;
532 WIN_ReleasePtr( wndPtr
);
537 other_process
: /* one of the parents may belong to another process, do it the hard way */
538 offset
->x
= offset
->y
= 0;
539 SERVER_START_REQ( get_windows_offset
)
541 req
->from
= hwndFrom
;
543 if (!wine_server_call( req
))
545 offset
->x
= reply
->x
;
546 offset
->y
= reply
->y
;
553 /*******************************************************************
554 * MapWindowPoints (USER.258)
556 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
557 LPPOINT16 lppt
, UINT16 count
)
561 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
571 /*******************************************************************
572 * MapWindowPoints (USER32.@)
574 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
578 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
585 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
589 /***********************************************************************
590 * IsIconic (USER32.@)
592 BOOL WINAPI
IsIconic(HWND hWnd
)
594 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
598 /***********************************************************************
599 * IsZoomed (USER32.@)
601 BOOL WINAPI
IsZoomed(HWND hWnd
)
603 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
607 /*******************************************************************
608 * AllowSetForegroundWindow (USER32.@)
610 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
612 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
613 * implemented, then fix this function. */
618 /*******************************************************************
619 * LockSetForegroundWindow (USER32.@)
621 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
623 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
624 * implemented, then fix this function. */
629 /***********************************************************************
630 * BringWindowToTop (USER32.@)
632 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
634 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
638 /***********************************************************************
639 * MoveWindow (USER32.@)
641 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
644 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
645 if (!repaint
) flags
|= SWP_NOREDRAW
;
646 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
647 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
650 /***********************************************************************
651 * WINPOS_InitInternalPos
653 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
)
655 LPINTERNALPOS lpPos
= get_internal_pos( wnd
->hwndSelf
);
658 /* this happens when the window is minimized/maximized
659 * for the first time (rectWindow is not adjusted yet) */
661 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
662 if( !lpPos
) return NULL
;
664 set_internal_pos( wnd
->hwndSelf
, lpPos
);
665 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
666 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
667 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
668 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
669 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
670 lpPos
->ptIconPos
.x
= lpPos
->ptIconPos
.y
= -1;
671 lpPos
->ptMaxPos
.x
= lpPos
->ptMaxPos
.y
= -1;
674 if( wnd
->dwStyle
& WS_MINIMIZE
)
676 lpPos
->ptIconPos
.x
= wnd
->rectWindow
.left
;
677 lpPos
->ptIconPos
.y
= wnd
->rectWindow
.top
;
679 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
681 lpPos
->ptMaxPos
.x
= wnd
->rectWindow
.left
;
682 lpPos
->ptMaxPos
.y
= wnd
->rectWindow
.top
;
686 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
687 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
688 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
689 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
694 /***********************************************************************
695 * WINPOS_RedrawIconTitle
697 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
699 LPINTERNALPOS lpPos
= get_internal_pos( hWnd
);
702 if( lpPos
->hwndIconTitle
)
704 SendMessageW( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
705 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
712 /***********************************************************************
713 * WINPOS_ShowIconTitle
715 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
717 LPINTERNALPOS lpPos
= get_internal_pos( hwnd
);
719 if (lpPos
&& !GetPropA( hwnd
, "__wine_x11_managed" ))
721 HWND title
= lpPos
->hwndIconTitle
;
723 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
726 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
729 if (!IsWindowVisible(title
))
731 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
732 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
733 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
736 else ShowWindow( title
, SW_HIDE
);
741 /*******************************************************************
742 * WINPOS_GetMinMaxInfo
744 * Get the minimized and maximized information for a window.
746 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
747 POINT
*minTrack
, POINT
*maxTrack
)
753 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
754 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
757 /* Compute default values */
759 GetWindowRect(hwnd
, &rc
);
760 MinMax
.ptReserved
.x
= rc
.left
;
761 MinMax
.ptReserved
.y
= rc
.top
;
763 if (style
& WS_CHILD
)
765 if ((style
& WS_CAPTION
) == WS_CAPTION
)
766 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
768 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
769 AdjustWindowRectEx(&rc
, style
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
771 /* avoid calculating this twice */
772 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
774 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
775 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
779 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
780 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
782 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
783 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
784 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
785 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
787 if (HAS_DLGFRAME( style
, exstyle
))
789 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
790 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
795 if (HAS_THICKFRAME(style
))
797 xinc
+= GetSystemMetrics(SM_CXFRAME
);
798 yinc
+= GetSystemMetrics(SM_CYFRAME
);
800 if (style
& WS_BORDER
)
802 xinc
+= GetSystemMetrics(SM_CXBORDER
);
803 yinc
+= GetSystemMetrics(SM_CYBORDER
);
806 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
807 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
809 lpPos
= get_internal_pos( hwnd
);
810 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
812 MinMax
.ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
813 MinMax
.ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
817 MinMax
.ptMaxPosition
.x
= -xinc
;
818 MinMax
.ptMaxPosition
.y
= -yinc
;
821 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
823 /* if the app didn't change the values, adapt them for the current monitor */
825 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
827 MONITORINFO mon_info
;
829 mon_info
.cbSize
= sizeof(mon_info
);
830 GetMonitorInfoW( monitor
, &mon_info
);
832 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
833 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
835 MinMax
.ptMaxSize
.x
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) + 2 * xinc
;
836 MinMax
.ptMaxSize
.y
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) + 2 * yinc
;
838 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
840 MinMax
.ptMaxPosition
.x
= mon_info
.rcWork
.left
- xinc
;
841 MinMax
.ptMaxPosition
.y
= mon_info
.rcWork
.top
- yinc
;
845 /* Some sanity checks */
847 TRACE("%d %d / %d %d / %d %d / %d %d\n",
848 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
849 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
850 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
851 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
852 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
853 MinMax
.ptMinTrackSize
.x
);
854 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
855 MinMax
.ptMinTrackSize
.y
);
857 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
858 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
859 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
860 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
863 /***********************************************************************
864 * ShowWindowAsync (USER32.@)
866 * doesn't wait; returns immediately.
867 * used by threads to toggle windows in other (possibly hanging) threads
869 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
873 if (is_broadcast(hwnd
))
875 SetLastError( ERROR_INVALID_PARAMETER
);
879 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
880 return USER_Driver
->pShowWindow( full_handle
, cmd
);
882 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
886 /***********************************************************************
887 * ShowWindow (USER32.@)
889 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
893 if (is_broadcast(hwnd
))
895 SetLastError( ERROR_INVALID_PARAMETER
);
898 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
899 return USER_Driver
->pShowWindow( full_handle
, cmd
);
901 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
905 /***********************************************************************
906 * GetInternalWindowPos (USER32.@)
908 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
911 WINDOWPLACEMENT wndpl
;
912 if (GetWindowPlacement( hwnd
, &wndpl
))
914 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
915 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
916 return wndpl
.showCmd
;
922 /***********************************************************************
923 * GetWindowPlacement (USER32.@)
926 * Fails if wndpl->length of Win95 (!) apps is invalid.
928 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
930 WND
*pWnd
= WIN_GetPtr( hwnd
);
933 if (!pWnd
|| pWnd
== WND_DESKTOP
) return FALSE
;
934 if (pWnd
== WND_OTHER_PROCESS
)
936 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
940 lpPos
= WINPOS_InitInternalPos( pWnd
);
941 wndpl
->length
= sizeof(*wndpl
);
942 if( pWnd
->dwStyle
& WS_MINIMIZE
)
943 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
945 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
946 if( pWnd
->flags
& WIN_RESTORE_MAX
)
947 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
950 wndpl
->ptMinPosition
.x
= lpPos
->ptIconPos
.x
;
951 wndpl
->ptMinPosition
.y
= lpPos
->ptIconPos
.y
;
952 wndpl
->ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
953 wndpl
->ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
954 wndpl
->rcNormalPosition
.left
= lpPos
->rectNormal
.left
;
955 wndpl
->rcNormalPosition
.top
= lpPos
->rectNormal
.top
;
956 wndpl
->rcNormalPosition
.right
= lpPos
->rectNormal
.right
;
957 wndpl
->rcNormalPosition
.bottom
= lpPos
->rectNormal
.bottom
;
958 WIN_ReleasePtr( pWnd
);
963 /***********************************************************************
964 * WINPOS_SetPlacement
966 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
970 WND
*pWnd
= WIN_GetPtr( hwnd
);
972 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
973 lpPos
= WINPOS_InitInternalPos( pWnd
);
975 if( flags
& PLACE_MIN
)
977 lpPos
->ptIconPos
.x
= wndpl
->ptMinPosition
.x
;
978 lpPos
->ptIconPos
.y
= wndpl
->ptMinPosition
.y
;
980 if( flags
& PLACE_MAX
)
982 lpPos
->ptMaxPos
.x
= wndpl
->ptMaxPosition
.x
;
983 lpPos
->ptMaxPos
.y
= wndpl
->ptMaxPosition
.y
;
985 if( flags
& PLACE_RECT
)
987 lpPos
->rectNormal
.left
= wndpl
->rcNormalPosition
.left
;
988 lpPos
->rectNormal
.top
= wndpl
->rcNormalPosition
.top
;
989 lpPos
->rectNormal
.right
= wndpl
->rcNormalPosition
.right
;
990 lpPos
->rectNormal
.bottom
= wndpl
->rcNormalPosition
.bottom
;
993 style
= pWnd
->dwStyle
;
994 WIN_ReleasePtr( pWnd
);
996 if( style
& WS_MINIMIZE
)
998 WINPOS_ShowIconTitle( hwnd
, FALSE
);
999 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
1000 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
1001 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1003 else if( style
& WS_MAXIMIZE
)
1005 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
1006 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
1007 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1009 else if( flags
& PLACE_RECT
)
1010 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
1011 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
1012 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
1013 SWP_NOZORDER
| SWP_NOACTIVATE
);
1015 ShowWindow( hwnd
, wndpl
->showCmd
);
1017 if (IsIconic( hwnd
))
1019 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1021 /* SDK: ...valid only the next time... */
1022 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1024 pWnd
= WIN_GetPtr( hwnd
);
1025 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1027 pWnd
->flags
|= WIN_RESTORE_MAX
;
1028 WIN_ReleasePtr( pWnd
);
1036 /***********************************************************************
1037 * SetWindowPlacement (USER32.@)
1040 * Fails if wndpl->length of Win95 (!) apps is invalid.
1042 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1044 if (!wpl
) return FALSE
;
1045 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1049 /***********************************************************************
1050 * AnimateWindow (USER32.@)
1051 * Shows/Hides a window with an animation
1054 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1056 FIXME("partial stub\n");
1058 /* If trying to show/hide and it's already *
1059 * shown/hidden or invalid window, fail with *
1060 * invalid parameter */
1061 if(!IsWindow(hwnd
) ||
1062 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1063 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1065 SetLastError(ERROR_INVALID_PARAMETER
);
1069 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1074 /***********************************************************************
1075 * SetInternalWindowPos (USER32.@)
1077 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1078 LPRECT rect
, LPPOINT pt
)
1080 if( IsWindow(hwnd
) )
1082 WINDOWPLACEMENT wndpl
;
1085 wndpl
.length
= sizeof(wndpl
);
1086 wndpl
.showCmd
= showCmd
;
1087 wndpl
.flags
= flags
= 0;
1092 wndpl
.flags
|= WPF_SETMINPOSITION
;
1093 wndpl
.ptMinPosition
= *pt
;
1097 flags
|= PLACE_RECT
;
1098 wndpl
.rcNormalPosition
= *rect
;
1100 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1105 /*******************************************************************
1106 * can_activate_window
1108 * Check if we can activate the specified window.
1110 static BOOL
can_activate_window( HWND hwnd
)
1114 if (!hwnd
) return FALSE
;
1115 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1116 if (!(style
& WS_VISIBLE
)) return FALSE
;
1117 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1118 return !(style
& WS_DISABLED
);
1122 /*******************************************************************
1123 * WINPOS_ActivateOtherWindow
1125 * Activates window other than pWnd.
1127 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1131 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1133 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1134 if (can_activate_window( hwndTo
)) goto done
;
1140 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1141 if (can_activate_window( hwndTo
)) break;
1145 fg
= GetForegroundWindow();
1146 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1147 if (!fg
|| (hwnd
== fg
))
1149 if (SetForegroundWindow( hwndTo
)) return;
1151 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1155 /***********************************************************************
1156 * WINPOS_HandleWindowPosChanging
1158 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1160 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1162 POINT minTrack
, maxTrack
;
1163 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1165 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1166 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1168 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1169 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1170 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1171 if (!(style
& WS_MINIMIZE
))
1173 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1174 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1181 /***********************************************************************
1184 static void dump_winpos_flags(UINT flags
)
1187 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1188 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1189 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1190 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1191 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1192 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1193 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1194 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1195 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1196 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1197 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1198 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1199 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1201 #define DUMPED_FLAGS \
1207 SWP_FRAMECHANGED | \
1211 SWP_NOOWNERZORDER | \
1212 SWP_NOSENDCHANGING | \
1216 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1221 /***********************************************************************
1222 * SWP_DoWinPosChanging
1224 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1228 /* Send WM_WINDOWPOSCHANGING message */
1230 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1231 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1233 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1234 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1236 /* Calculate new position and size */
1238 *pNewWindowRect
= wndPtr
->rectWindow
;
1239 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1240 : wndPtr
->rectClient
;
1242 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1244 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1245 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1247 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1249 pNewWindowRect
->left
= pWinpos
->x
;
1250 pNewWindowRect
->top
= pWinpos
->y
;
1251 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1252 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1254 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1255 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1257 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1259 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1260 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1261 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1262 TRACE( "current %s style %08x new %s\n",
1263 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1264 wine_dbgstr_rect( pNewWindowRect
));
1266 WIN_ReleasePtr( wndPtr
);
1270 /***********************************************************************
1273 * Compute the valid rects from the old and new client rect and WVR_* flags.
1274 * Helper for WM_NCCALCSIZE handling.
1276 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1281 if (flags
& WVR_REDRAW
)
1283 SetRectEmpty( &valid
[0] );
1284 SetRectEmpty( &valid
[1] );
1288 if (flags
& WVR_VALIDRECTS
)
1290 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1291 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1293 SetRectEmpty( &valid
[0] );
1294 SetRectEmpty( &valid
[1] );
1297 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1301 valid
[0] = *new_client
;
1302 valid
[1] = *old_client
;
1305 /* make sure the rectangles have the same size */
1306 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1307 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1309 if (flags
& WVR_ALIGNBOTTOM
)
1311 valid
[0].top
= valid
[0].bottom
- cy
;
1312 valid
[1].top
= valid
[1].bottom
- cy
;
1316 valid
[0].bottom
= valid
[0].top
+ cy
;
1317 valid
[1].bottom
= valid
[1].top
+ cy
;
1319 if (flags
& WVR_ALIGNRIGHT
)
1321 valid
[0].left
= valid
[0].right
- cx
;
1322 valid
[1].left
= valid
[1].right
- cx
;
1326 valid
[0].right
= valid
[0].left
+ cx
;
1327 valid
[1].right
= valid
[1].left
+ cx
;
1331 struct move_owned_info
1337 static BOOL CALLBACK
move_owned_popups( HWND hwnd
, LPARAM lparam
)
1339 struct move_owned_info
*info
= (struct move_owned_info
*)lparam
;
1341 if (hwnd
== info
->owner
) return FALSE
;
1342 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) &&
1343 GetWindow( hwnd
, GW_OWNER
) == info
->owner
)
1345 SetWindowPos( hwnd
, info
->insert_after
, 0, 0, 0, 0,
1346 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1347 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1348 info
->insert_after
= hwnd
;
1353 /***********************************************************************
1356 * fix Z order taking into account owned popups -
1357 * basically we need to maintain them above the window that owns them
1359 * FIXME: hide/show owned popups when owner visibility changes.
1361 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1363 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
1364 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1365 struct move_owned_info info
;
1367 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1369 if ((style
& WS_POPUP
) && owner
)
1371 /* make sure this popup stays above the owner */
1373 if( hwndInsertAfter
!= HWND_TOP
)
1375 HWND hwndLocalPrev
= HWND_TOP
;
1376 HWND prev
= GetWindow( owner
, GW_HWNDPREV
);
1378 while (prev
&& prev
!= hwndInsertAfter
)
1380 if (hwndLocalPrev
== HWND_TOP
&& GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
)
1381 hwndLocalPrev
= prev
;
1382 prev
= GetWindow( prev
, GW_HWNDPREV
);
1384 if (!prev
) hwndInsertAfter
= hwndLocalPrev
;
1387 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1390 info
.insert_after
= hwndInsertAfter
;
1391 EnumWindows( move_owned_popups
, (LPARAM
)&info
);
1392 return info
.insert_after
;
1395 /***********************************************************************
1398 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1404 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1406 /* Send WM_NCCALCSIZE message to get new client area */
1407 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1409 NCCALCSIZE_PARAMS params
;
1410 WINDOWPOS winposCopy
;
1412 params
.rgrc
[0] = *pNewWindowRect
;
1413 params
.rgrc
[1] = wndPtr
->rectWindow
;
1414 params
.rgrc
[2] = wndPtr
->rectClient
;
1415 params
.lppos
= &winposCopy
;
1416 winposCopy
= *pWinpos
;
1417 WIN_ReleasePtr( wndPtr
);
1419 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1421 *pNewClientRect
= params
.rgrc
[0];
1423 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1425 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1426 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1427 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1429 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1430 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1431 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1433 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1434 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1435 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1437 wvrFlags
&= ~WVR_HREDRAW
;
1439 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1440 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1441 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1443 wvrFlags
&= ~WVR_VREDRAW
;
1445 validRects
[0] = params
.rgrc
[1];
1446 validRects
[1] = params
.rgrc
[2];
1450 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1451 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1452 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1453 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1456 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1458 SetRectEmpty( &validRects
[0] );
1459 SetRectEmpty( &validRects
[1] );
1461 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1463 WIN_ReleasePtr( wndPtr
);
1467 /* fix redundant flags and values in the WINDOWPOS structure */
1468 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1471 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1474 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1476 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1479 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1481 /* Finally make sure that all coordinates are valid */
1482 if (winpos
->x
< -32768) winpos
->x
= -32768;
1483 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1484 if (winpos
->y
< -32768) winpos
->y
= -32768;
1485 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1487 if (winpos
->cx
< 0) winpos
->cx
= 0;
1488 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1489 if (winpos
->cy
< 0) winpos
->cy
= 0;
1490 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1492 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1493 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1495 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1498 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1499 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1502 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1503 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1504 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1506 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1507 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1509 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1511 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) /* Bring to the top when activating */
1513 winpos
->flags
&= ~SWP_NOZORDER
;
1514 winpos
->hwndInsertAfter
= HWND_TOP
;
1518 /* Check hwndInsertAfter */
1519 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1521 /* fix sign extension */
1522 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1523 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1525 /* FIXME: TOPMOST not supported yet */
1526 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
1527 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
1529 /* hwndInsertAfter must be a sibling of the window */
1530 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1532 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1533 winpos
->flags
|= SWP_NOZORDER
;
1535 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1537 if (GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1538 winpos
->flags
|= SWP_NOZORDER
;
1542 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1545 /* don't need to change the Zorder of hwnd if it's already inserted
1546 * after hwndInsertAfter or when inserting hwnd after itself.
1548 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1549 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1550 winpos
->flags
|= SWP_NOZORDER
;
1554 WIN_ReleasePtr( wndPtr
);
1558 /***********************************************************************
1561 * User32 internal function
1563 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1565 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1568 orig_flags
= winpos
->flags
;
1570 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1571 if (!(winpos
->flags
& SWP_NOMOVE
))
1573 if (winpos
->x
< -32768) winpos
->x
= -32768;
1574 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1575 if (winpos
->y
< -32768) winpos
->y
= -32768;
1576 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1578 if (!(winpos
->flags
& SWP_NOSIZE
))
1580 if (winpos
->cx
< 0) winpos
->cx
= 0;
1581 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1582 if (winpos
->cy
< 0) winpos
->cy
= 0;
1583 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1586 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1588 /* Fix redundant flags */
1589 if (!fixup_flags( winpos
)) return FALSE
;
1591 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1593 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1594 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
1597 /* Common operations */
1599 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
1601 if(!USER_Driver
->pSetWindowPos( winpos
->hwnd
, winpos
->hwndInsertAfter
,
1602 &newWindowRect
, &newClientRect
, orig_flags
, valid_rects
))
1605 if (!(orig_flags
& SWP_SHOWWINDOW
))
1607 UINT rdw_flags
= RDW_FRAME
| RDW_ERASE
;
1608 if ( !(orig_flags
& SWP_DEFERERASE
) ) rdw_flags
|= RDW_ERASENOW
;
1609 RedrawWindow( winpos
->hwnd
, NULL
, NULL
, rdw_flags
);
1612 if( winpos
->flags
& SWP_HIDEWINDOW
)
1613 HideCaret(winpos
->hwnd
);
1614 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1615 ShowCaret(winpos
->hwnd
);
1617 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
1619 /* child windows get WM_CHILDACTIVATE message */
1620 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1621 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1623 SetForegroundWindow( winpos
->hwnd
);
1626 /* And last, send the WM_WINDOWPOSCHANGED message */
1628 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1630 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
1632 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1633 and always contains final window position.
1635 winpos
->x
= newWindowRect
.left
;
1636 winpos
->y
= newWindowRect
.top
;
1637 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
1638 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
1639 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
1644 /***********************************************************************
1645 * SetWindowPos (USER32.@)
1647 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1648 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1652 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1653 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1654 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1656 if (is_broadcast(hwnd
))
1658 SetLastError( ERROR_INVALID_PARAMETER
);
1662 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1663 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1668 winpos
.flags
= flags
;
1670 if (WIN_IsCurrentThread( hwnd
))
1671 return USER_SetWindowPos(&winpos
);
1673 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1677 /***********************************************************************
1678 * BeginDeferWindowPos (USER32.@)
1680 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1685 TRACE("%d\n", count
);
1689 SetLastError(ERROR_INVALID_PARAMETER
);
1692 /* Windows allows zero count, in which case it allocates context for 8 moves */
1693 if (count
== 0) count
= 8;
1695 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1696 if (!handle
) return 0;
1697 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1698 pDWP
->actualCount
= 0;
1699 pDWP
->suggestedCount
= count
;
1701 pDWP
->wMagic
= DWP_MAGIC
;
1702 pDWP
->hwndParent
= 0;
1704 TRACE("returning hdwp %p\n", handle
);
1709 /***********************************************************************
1710 * DeferWindowPos (USER32.@)
1712 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1713 INT x
, INT y
, INT cx
, INT cy
,
1718 HDWP newhdwp
= hdwp
,retvalue
;
1720 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1721 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
1723 hwnd
= WIN_GetFullHandle( hwnd
);
1724 if (hwnd
== GetDesktopWindow()) return 0;
1726 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1730 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1732 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1734 /* Merge with the other changes */
1735 if (!(flags
& SWP_NOZORDER
))
1737 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1739 if (!(flags
& SWP_NOMOVE
))
1741 pDWP
->winPos
[i
].x
= x
;
1742 pDWP
->winPos
[i
].y
= y
;
1744 if (!(flags
& SWP_NOSIZE
))
1746 pDWP
->winPos
[i
].cx
= cx
;
1747 pDWP
->winPos
[i
].cy
= cy
;
1749 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1750 SWP_NOZORDER
| SWP_NOREDRAW
|
1751 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1753 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1759 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1761 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1762 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1768 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1769 pDWP
->suggestedCount
++;
1771 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1772 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1773 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1774 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1775 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1776 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1777 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1778 pDWP
->actualCount
++;
1786 /***********************************************************************
1787 * EndDeferWindowPos (USER32.@)
1789 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1796 TRACE("%p\n", hdwp
);
1798 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1799 if (!pDWP
) return FALSE
;
1800 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1802 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1803 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
1804 winpos
->cx
, winpos
->cy
, winpos
->flags
);
1806 if (!(res
= USER_SetWindowPos( winpos
))) break;
1808 USER_HEAP_FREE( hdwp
);
1813 /***********************************************************************
1814 * TileChildWindows (USER.199)
1816 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1818 FIXME("(%04x, %d): stub\n", parent
, action
);
1821 /***********************************************************************
1822 * CascadeChildWindows (USER.198)
1824 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1826 FIXME("(%04x, %d): stub\n", parent
, action
);