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 if (data
->rdh
.nCount
)
254 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
256 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
257 ret
= !wine_server_call_err( req
);
261 else /* clear existing region */
263 SERVER_START_REQ( set_window_region
)
266 ret
= !wine_server_call_err( req
);
271 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
275 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
;
276 if (hrgn
) swp_flags
|= SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
277 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
278 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
284 /***********************************************************************
285 * GetClientRect (USER32.@)
287 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
291 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
293 rect
->right
-= rect
->left
;
294 rect
->bottom
-= rect
->top
;
295 rect
->left
= rect
->top
= 0;
301 /*******************************************************************
302 * ClientToScreen (USER32.@)
304 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
306 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
311 /*******************************************************************
312 * ScreenToClient (USER32.@)
314 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
316 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
321 /***********************************************************************
322 * list_children_from_point
324 * Get the list of children that can contain point from the server.
325 * Point is in screen coordinates.
326 * Returned list must be freed by caller.
328 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
337 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
339 SERVER_START_REQ( get_window_children_from_point
)
344 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
345 if (!wine_server_call( req
)) count
= reply
->count
;
348 if (count
&& count
< size
)
353 HeapFree( GetProcessHeap(), 0, list
);
355 size
= count
+ 1; /* restart with a large enough buffer */
361 /***********************************************************************
362 * WINPOS_WindowFromPoint
364 * Find the window and hittest for a given point.
366 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
371 if (!hwndScope
) hwndScope
= GetDesktopWindow();
373 *hittest
= HTNOWHERE
;
375 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
377 /* now determine the hittest */
379 for (i
= 0; list
[i
]; i
++)
381 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
383 /* If window is minimized or disabled, return at once */
384 if (style
& WS_MINIMIZE
)
386 *hittest
= HTCAPTION
;
389 if (style
& WS_DISABLED
)
394 /* Send WM_NCCHITTEST (if same thread) */
395 if (!WIN_IsCurrentThread( list
[i
] ))
400 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
401 if (res
!= HTTRANSPARENT
)
403 *hittest
= res
; /* Found the window */
406 /* continue search with next window in z-order */
409 HeapFree( GetProcessHeap(), 0, list
);
410 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
415 /*******************************************************************
416 * WindowFromPoint (USER32.@)
418 HWND WINAPI
WindowFromPoint( POINT pt
)
421 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
425 /*******************************************************************
426 * ChildWindowFromPoint (USER32.@)
428 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
430 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
433 /*******************************************************************
434 * ChildWindowFromPointEx (USER32.@)
436 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
438 /* pt is in the client coordinates */
444 GetClientRect( hwndParent
, &rect
);
445 if (!PtInRect( &rect
, pt
)) return 0;
446 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
448 for (i
= 0; list
[i
]; i
++)
450 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
451 if (!PtInRect( &rect
, pt
)) continue;
452 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
454 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
455 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
456 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
458 if (uFlags
& CWP_SKIPTRANSPARENT
)
460 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
465 HeapFree( GetProcessHeap(), 0, list
);
466 if (!retvalue
) retvalue
= hwndParent
;
471 /*******************************************************************
472 * WINPOS_GetWinOffset
474 * Calculate the offset between the origin of the two windows. Used
475 * to implement MapWindowPoints.
477 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
481 offset
->x
= offset
->y
= 0;
483 /* Translate source window origin to screen coords */
486 HWND hwnd
= hwndFrom
;
490 if (hwnd
== hwndTo
) return;
491 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
493 ERR( "bad hwndFrom = %p\n", hwnd
);
496 if (wndPtr
== WND_DESKTOP
) break;
497 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
498 offset
->x
+= wndPtr
->rectClient
.left
;
499 offset
->y
+= wndPtr
->rectClient
.top
;
500 hwnd
= wndPtr
->parent
;
501 WIN_ReleasePtr( wndPtr
);
505 /* Translate origin to destination window coords */
512 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
514 ERR( "bad hwndTo = %p\n", hwnd
);
517 if (wndPtr
== WND_DESKTOP
) break;
518 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
519 offset
->x
-= wndPtr
->rectClient
.left
;
520 offset
->y
-= wndPtr
->rectClient
.top
;
521 hwnd
= wndPtr
->parent
;
522 WIN_ReleasePtr( wndPtr
);
527 other_process
: /* one of the parents may belong to another process, do it the hard way */
528 offset
->x
= offset
->y
= 0;
529 SERVER_START_REQ( get_windows_offset
)
531 req
->from
= hwndFrom
;
533 if (!wine_server_call( req
))
535 offset
->x
= reply
->x
;
536 offset
->y
= reply
->y
;
543 /*******************************************************************
544 * MapWindowPoints (USER.258)
546 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
547 LPPOINT16 lppt
, UINT16 count
)
551 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
561 /*******************************************************************
562 * MapWindowPoints (USER32.@)
564 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
568 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
575 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
579 /***********************************************************************
580 * IsIconic (USER32.@)
582 BOOL WINAPI
IsIconic(HWND hWnd
)
584 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
588 /***********************************************************************
589 * IsZoomed (USER32.@)
591 BOOL WINAPI
IsZoomed(HWND hWnd
)
593 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
597 /*******************************************************************
598 * AllowSetForegroundWindow (USER32.@)
600 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
602 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
603 * implemented, then fix this function. */
608 /*******************************************************************
609 * LockSetForegroundWindow (USER32.@)
611 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
613 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
614 * implemented, then fix this function. */
619 /***********************************************************************
620 * BringWindowToTop (USER32.@)
622 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
624 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
628 /***********************************************************************
629 * MoveWindow (USER32.@)
631 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
634 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
635 if (!repaint
) flags
|= SWP_NOREDRAW
;
636 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
637 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
640 /***********************************************************************
641 * WINPOS_InitInternalPos
643 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
)
645 LPINTERNALPOS lpPos
= get_internal_pos( wnd
->hwndSelf
);
648 /* this happens when the window is minimized/maximized
649 * for the first time (rectWindow is not adjusted yet) */
651 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
652 if( !lpPos
) return NULL
;
654 set_internal_pos( wnd
->hwndSelf
, lpPos
);
655 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
656 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
657 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
658 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
659 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
660 lpPos
->ptIconPos
.x
= lpPos
->ptIconPos
.y
= -1;
661 lpPos
->ptMaxPos
.x
= lpPos
->ptMaxPos
.y
= -1;
664 if( wnd
->dwStyle
& WS_MINIMIZE
)
666 lpPos
->ptIconPos
.x
= wnd
->rectWindow
.left
;
667 lpPos
->ptIconPos
.y
= wnd
->rectWindow
.top
;
669 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
671 lpPos
->ptMaxPos
.x
= wnd
->rectWindow
.left
;
672 lpPos
->ptMaxPos
.y
= wnd
->rectWindow
.top
;
676 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
677 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
678 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
679 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
684 /***********************************************************************
685 * WINPOS_RedrawIconTitle
687 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
689 LPINTERNALPOS lpPos
= get_internal_pos( hWnd
);
692 if( lpPos
->hwndIconTitle
)
694 SendMessageW( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
695 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
702 /***********************************************************************
703 * WINPOS_ShowIconTitle
705 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
707 LPINTERNALPOS lpPos
= get_internal_pos( hwnd
);
709 if (lpPos
&& !GetPropA( hwnd
, "__wine_x11_managed" ))
711 HWND title
= lpPos
->hwndIconTitle
;
713 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
716 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
719 if (!IsWindowVisible(title
))
721 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
722 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
723 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
726 else ShowWindow( title
, SW_HIDE
);
731 /*******************************************************************
732 * WINPOS_GetMinMaxInfo
734 * Get the minimized and maximized information for a window.
736 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
737 POINT
*minTrack
, POINT
*maxTrack
)
743 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
744 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
747 /* Compute default values */
749 GetWindowRect(hwnd
, &rc
);
750 MinMax
.ptReserved
.x
= rc
.left
;
751 MinMax
.ptReserved
.y
= rc
.top
;
753 if (style
& WS_CHILD
)
755 if ((style
& WS_CAPTION
) == WS_CAPTION
)
756 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
758 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
759 AdjustWindowRectEx(&rc
, style
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
761 /* avoid calculating this twice */
762 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
764 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
765 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
769 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
770 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
772 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
773 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
774 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
775 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
777 if (HAS_DLGFRAME( style
, exstyle
))
779 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
780 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
785 if (HAS_THICKFRAME(style
))
787 xinc
+= GetSystemMetrics(SM_CXFRAME
);
788 yinc
+= GetSystemMetrics(SM_CYFRAME
);
790 if (style
& WS_BORDER
)
792 xinc
+= GetSystemMetrics(SM_CXBORDER
);
793 yinc
+= GetSystemMetrics(SM_CYBORDER
);
796 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
797 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
799 lpPos
= get_internal_pos( hwnd
);
800 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
802 MinMax
.ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
803 MinMax
.ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
807 MinMax
.ptMaxPosition
.x
= -xinc
;
808 MinMax
.ptMaxPosition
.y
= -yinc
;
811 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
813 /* if the app didn't change the values, adapt them for the current monitor */
815 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
817 MONITORINFO mon_info
;
819 mon_info
.cbSize
= sizeof(mon_info
);
820 GetMonitorInfoW( monitor
, &mon_info
);
822 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
823 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
825 MinMax
.ptMaxSize
.x
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) + 2 * xinc
;
826 MinMax
.ptMaxSize
.y
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) + 2 * yinc
;
828 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
830 MinMax
.ptMaxPosition
.x
= mon_info
.rcWork
.left
- xinc
;
831 MinMax
.ptMaxPosition
.y
= mon_info
.rcWork
.top
- yinc
;
835 /* Some sanity checks */
837 TRACE("%d %d / %d %d / %d %d / %d %d\n",
838 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
839 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
840 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
841 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
842 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
843 MinMax
.ptMinTrackSize
.x
);
844 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
845 MinMax
.ptMinTrackSize
.y
);
847 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
848 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
849 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
850 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
853 /***********************************************************************
854 * ShowWindowAsync (USER32.@)
856 * doesn't wait; returns immediately.
857 * used by threads to toggle windows in other (possibly hanging) threads
859 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
863 if (is_broadcast(hwnd
))
865 SetLastError( ERROR_INVALID_PARAMETER
);
869 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
870 return USER_Driver
->pShowWindow( full_handle
, cmd
);
872 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
876 /***********************************************************************
877 * ShowWindow (USER32.@)
879 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
883 if (is_broadcast(hwnd
))
885 SetLastError( ERROR_INVALID_PARAMETER
);
888 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
889 return USER_Driver
->pShowWindow( full_handle
, cmd
);
891 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
895 /***********************************************************************
896 * GetInternalWindowPos (USER32.@)
898 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
901 WINDOWPLACEMENT wndpl
;
902 if (GetWindowPlacement( hwnd
, &wndpl
))
904 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
905 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
906 return wndpl
.showCmd
;
912 /***********************************************************************
913 * GetWindowPlacement (USER32.@)
916 * Fails if wndpl->length of Win95 (!) apps is invalid.
918 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
920 WND
*pWnd
= WIN_GetPtr( hwnd
);
923 if (!pWnd
|| pWnd
== WND_DESKTOP
) return FALSE
;
924 if (pWnd
== WND_OTHER_PROCESS
)
926 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
930 lpPos
= WINPOS_InitInternalPos( pWnd
);
931 wndpl
->length
= sizeof(*wndpl
);
932 if( pWnd
->dwStyle
& WS_MINIMIZE
)
933 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
935 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
936 if( pWnd
->flags
& WIN_RESTORE_MAX
)
937 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
940 wndpl
->ptMinPosition
.x
= lpPos
->ptIconPos
.x
;
941 wndpl
->ptMinPosition
.y
= lpPos
->ptIconPos
.y
;
942 wndpl
->ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
943 wndpl
->ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
944 wndpl
->rcNormalPosition
.left
= lpPos
->rectNormal
.left
;
945 wndpl
->rcNormalPosition
.top
= lpPos
->rectNormal
.top
;
946 wndpl
->rcNormalPosition
.right
= lpPos
->rectNormal
.right
;
947 wndpl
->rcNormalPosition
.bottom
= lpPos
->rectNormal
.bottom
;
948 WIN_ReleasePtr( pWnd
);
953 /***********************************************************************
954 * WINPOS_SetPlacement
956 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
960 WND
*pWnd
= WIN_GetPtr( hwnd
);
962 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
963 lpPos
= WINPOS_InitInternalPos( pWnd
);
965 if( flags
& PLACE_MIN
)
967 lpPos
->ptIconPos
.x
= wndpl
->ptMinPosition
.x
;
968 lpPos
->ptIconPos
.y
= wndpl
->ptMinPosition
.y
;
970 if( flags
& PLACE_MAX
)
972 lpPos
->ptMaxPos
.x
= wndpl
->ptMaxPosition
.x
;
973 lpPos
->ptMaxPos
.y
= wndpl
->ptMaxPosition
.y
;
975 if( flags
& PLACE_RECT
)
977 lpPos
->rectNormal
.left
= wndpl
->rcNormalPosition
.left
;
978 lpPos
->rectNormal
.top
= wndpl
->rcNormalPosition
.top
;
979 lpPos
->rectNormal
.right
= wndpl
->rcNormalPosition
.right
;
980 lpPos
->rectNormal
.bottom
= wndpl
->rcNormalPosition
.bottom
;
983 style
= pWnd
->dwStyle
;
984 WIN_ReleasePtr( pWnd
);
986 if( style
& WS_MINIMIZE
)
988 WINPOS_ShowIconTitle( hwnd
, FALSE
);
989 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
990 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
991 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
993 else if( style
& WS_MAXIMIZE
)
995 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
996 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
997 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
999 else if( flags
& PLACE_RECT
)
1000 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
1001 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
1002 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
1003 SWP_NOZORDER
| SWP_NOACTIVATE
);
1005 ShowWindow( hwnd
, wndpl
->showCmd
);
1007 if (IsIconic( hwnd
))
1009 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1011 /* SDK: ...valid only the next time... */
1012 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1014 pWnd
= WIN_GetPtr( hwnd
);
1015 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1017 pWnd
->flags
|= WIN_RESTORE_MAX
;
1018 WIN_ReleasePtr( pWnd
);
1026 /***********************************************************************
1027 * SetWindowPlacement (USER32.@)
1030 * Fails if wndpl->length of Win95 (!) apps is invalid.
1032 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1034 if (!wpl
) return FALSE
;
1035 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1039 /***********************************************************************
1040 * AnimateWindow (USER32.@)
1041 * Shows/Hides a window with an animation
1044 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1046 FIXME("partial stub\n");
1048 /* If trying to show/hide and it's already *
1049 * shown/hidden or invalid window, fail with *
1050 * invalid parameter */
1051 if(!IsWindow(hwnd
) ||
1052 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1053 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1055 SetLastError(ERROR_INVALID_PARAMETER
);
1059 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1064 /***********************************************************************
1065 * SetInternalWindowPos (USER32.@)
1067 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1068 LPRECT rect
, LPPOINT pt
)
1070 if( IsWindow(hwnd
) )
1072 WINDOWPLACEMENT wndpl
;
1075 wndpl
.length
= sizeof(wndpl
);
1076 wndpl
.showCmd
= showCmd
;
1077 wndpl
.flags
= flags
= 0;
1082 wndpl
.flags
|= WPF_SETMINPOSITION
;
1083 wndpl
.ptMinPosition
= *pt
;
1087 flags
|= PLACE_RECT
;
1088 wndpl
.rcNormalPosition
= *rect
;
1090 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1095 /*******************************************************************
1096 * can_activate_window
1098 * Check if we can activate the specified window.
1100 static BOOL
can_activate_window( HWND hwnd
)
1104 if (!hwnd
) return FALSE
;
1105 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1106 if (!(style
& WS_VISIBLE
)) return FALSE
;
1107 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1108 return !(style
& WS_DISABLED
);
1112 /*******************************************************************
1113 * WINPOS_ActivateOtherWindow
1115 * Activates window other than pWnd.
1117 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1121 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1123 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1124 if (can_activate_window( hwndTo
)) goto done
;
1130 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1131 if (can_activate_window( hwndTo
)) break;
1135 fg
= GetForegroundWindow();
1136 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1137 if (!fg
|| (hwnd
== fg
))
1139 if (SetForegroundWindow( hwndTo
)) return;
1141 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1145 /***********************************************************************
1146 * WINPOS_HandleWindowPosChanging
1148 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1150 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1152 POINT minTrack
, maxTrack
;
1153 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1155 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1156 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1158 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1159 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1160 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1161 if (!(style
& WS_MINIMIZE
))
1163 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1164 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1171 /***********************************************************************
1174 static void dump_winpos_flags(UINT flags
)
1177 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1178 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1179 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1180 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1181 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1182 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1183 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1184 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1185 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1186 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1187 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1188 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1189 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1191 #define DUMPED_FLAGS \
1197 SWP_FRAMECHANGED | \
1201 SWP_NOOWNERZORDER | \
1202 SWP_NOSENDCHANGING | \
1206 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1211 /***********************************************************************
1212 * SWP_DoWinPosChanging
1214 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1218 /* Send WM_WINDOWPOSCHANGING message */
1220 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1221 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1223 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1224 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1226 /* Calculate new position and size */
1228 *pNewWindowRect
= wndPtr
->rectWindow
;
1229 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1230 : wndPtr
->rectClient
;
1232 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1234 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1235 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1237 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1239 pNewWindowRect
->left
= pWinpos
->x
;
1240 pNewWindowRect
->top
= pWinpos
->y
;
1241 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1242 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1244 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1245 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1247 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1249 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1250 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1251 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1252 TRACE( "current %s style %08x new %s\n",
1253 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1254 wine_dbgstr_rect( pNewWindowRect
));
1256 WIN_ReleasePtr( wndPtr
);
1260 /***********************************************************************
1263 * Compute the valid rects from the old and new client rect and WVR_* flags.
1264 * Helper for WM_NCCALCSIZE handling.
1266 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1271 if (flags
& WVR_REDRAW
)
1273 SetRectEmpty( &valid
[0] );
1274 SetRectEmpty( &valid
[1] );
1278 if (flags
& WVR_VALIDRECTS
)
1280 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1281 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1283 SetRectEmpty( &valid
[0] );
1284 SetRectEmpty( &valid
[1] );
1287 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1291 valid
[0] = *new_client
;
1292 valid
[1] = *old_client
;
1295 /* make sure the rectangles have the same size */
1296 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1297 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1299 if (flags
& WVR_ALIGNBOTTOM
)
1301 valid
[0].top
= valid
[0].bottom
- cy
;
1302 valid
[1].top
= valid
[1].bottom
- cy
;
1306 valid
[0].bottom
= valid
[0].top
+ cy
;
1307 valid
[1].bottom
= valid
[1].top
+ cy
;
1309 if (flags
& WVR_ALIGNRIGHT
)
1311 valid
[0].left
= valid
[0].right
- cx
;
1312 valid
[1].left
= valid
[1].right
- cx
;
1316 valid
[0].right
= valid
[0].left
+ cx
;
1317 valid
[1].right
= valid
[1].left
+ cx
;
1321 struct move_owned_info
1327 static BOOL CALLBACK
move_owned_popups( HWND hwnd
, LPARAM lparam
)
1329 struct move_owned_info
*info
= (struct move_owned_info
*)lparam
;
1331 if (hwnd
== info
->owner
) return FALSE
;
1332 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) &&
1333 GetWindow( hwnd
, GW_OWNER
) == info
->owner
)
1335 SetWindowPos( hwnd
, info
->insert_after
, 0, 0, 0, 0,
1336 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1337 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1338 info
->insert_after
= hwnd
;
1343 /***********************************************************************
1346 * fix Z order taking into account owned popups -
1347 * basically we need to maintain them above the window that owns them
1349 * FIXME: hide/show owned popups when owner visibility changes.
1351 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1353 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
1354 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1355 struct move_owned_info info
;
1357 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1359 if ((style
& WS_POPUP
) && owner
)
1361 /* make sure this popup stays above the owner */
1363 if( hwndInsertAfter
!= HWND_TOP
)
1365 HWND hwndLocalPrev
= HWND_TOP
;
1366 HWND prev
= GetWindow( owner
, GW_HWNDPREV
);
1368 while (prev
&& prev
!= hwndInsertAfter
)
1370 if (hwndLocalPrev
== HWND_TOP
&& GetWindowLongW( prev
, GWL_STYLE
) & WS_VISIBLE
)
1371 hwndLocalPrev
= prev
;
1372 prev
= GetWindow( prev
, GW_HWNDPREV
);
1374 if (!prev
) hwndInsertAfter
= hwndLocalPrev
;
1377 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1380 info
.insert_after
= hwndInsertAfter
;
1381 EnumWindows( move_owned_popups
, (LPARAM
)&info
);
1382 return info
.insert_after
;
1385 /***********************************************************************
1388 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1394 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1396 /* Send WM_NCCALCSIZE message to get new client area */
1397 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1399 NCCALCSIZE_PARAMS params
;
1400 WINDOWPOS winposCopy
;
1402 params
.rgrc
[0] = *pNewWindowRect
;
1403 params
.rgrc
[1] = wndPtr
->rectWindow
;
1404 params
.rgrc
[2] = wndPtr
->rectClient
;
1405 params
.lppos
= &winposCopy
;
1406 winposCopy
= *pWinpos
;
1407 WIN_ReleasePtr( wndPtr
);
1409 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1411 *pNewClientRect
= params
.rgrc
[0];
1413 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1415 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1416 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1417 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1419 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1420 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1421 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1423 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1424 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1425 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1427 wvrFlags
&= ~WVR_HREDRAW
;
1429 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1430 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1431 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1433 wvrFlags
&= ~WVR_VREDRAW
;
1435 validRects
[0] = params
.rgrc
[1];
1436 validRects
[1] = params
.rgrc
[2];
1440 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1441 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1442 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1443 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1446 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1448 SetRectEmpty( &validRects
[0] );
1449 SetRectEmpty( &validRects
[1] );
1451 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1453 WIN_ReleasePtr( wndPtr
);
1457 /* fix redundant flags and values in the WINDOWPOS structure */
1458 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1461 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1464 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1466 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1469 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1471 /* Finally make sure that all coordinates are valid */
1472 if (winpos
->x
< -32768) winpos
->x
= -32768;
1473 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1474 if (winpos
->y
< -32768) winpos
->y
= -32768;
1475 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1477 if (winpos
->cx
< 0) winpos
->cx
= 0;
1478 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1479 if (winpos
->cy
< 0) winpos
->cy
= 0;
1480 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1482 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1483 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1485 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1488 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1489 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1492 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1493 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1494 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1496 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1497 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1499 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1501 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
))) /* Bring to the top when activating */
1503 winpos
->flags
&= ~SWP_NOZORDER
;
1504 winpos
->hwndInsertAfter
= HWND_TOP
;
1508 /* Check hwndInsertAfter */
1509 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1511 /* fix sign extension */
1512 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1513 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1515 /* FIXME: TOPMOST not supported yet */
1516 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
1517 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
1519 /* hwndInsertAfter must be a sibling of the window */
1520 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1522 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1523 winpos
->flags
|= SWP_NOZORDER
;
1525 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1527 if (GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1528 winpos
->flags
|= SWP_NOZORDER
;
1532 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1535 /* don't need to change the Zorder of hwnd if it's already inserted
1536 * after hwndInsertAfter or when inserting hwnd after itself.
1538 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1539 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1540 winpos
->flags
|= SWP_NOZORDER
;
1544 WIN_ReleasePtr( wndPtr
);
1548 /***********************************************************************
1551 * User32 internal function
1553 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1555 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1558 orig_flags
= winpos
->flags
;
1560 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1561 if (!(winpos
->flags
& SWP_NOMOVE
))
1563 if (winpos
->x
< -32768) winpos
->x
= -32768;
1564 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1565 if (winpos
->y
< -32768) winpos
->y
= -32768;
1566 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1568 if (!(winpos
->flags
& SWP_NOSIZE
))
1570 if (winpos
->cx
< 0) winpos
->cx
= 0;
1571 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1572 if (winpos
->cy
< 0) winpos
->cy
= 0;
1573 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1576 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1578 /* Fix redundant flags */
1579 if (!fixup_flags( winpos
)) return FALSE
;
1581 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1583 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1584 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
1587 /* Common operations */
1589 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
1591 if(!USER_Driver
->pSetWindowPos( winpos
->hwnd
, winpos
->hwndInsertAfter
,
1592 &newWindowRect
, &newClientRect
, orig_flags
, valid_rects
))
1595 if (!(orig_flags
& SWP_SHOWWINDOW
))
1597 UINT rdw_flags
= RDW_FRAME
| RDW_ERASE
;
1598 if ( !(orig_flags
& SWP_DEFERERASE
) ) rdw_flags
|= RDW_ERASENOW
;
1599 RedrawWindow( winpos
->hwnd
, NULL
, NULL
, rdw_flags
);
1602 if( winpos
->flags
& SWP_HIDEWINDOW
)
1603 HideCaret(winpos
->hwnd
);
1604 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1605 ShowCaret(winpos
->hwnd
);
1607 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
1609 /* child windows get WM_CHILDACTIVATE message */
1610 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1611 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1613 SetForegroundWindow( winpos
->hwnd
);
1616 /* And last, send the WM_WINDOWPOSCHANGED message */
1618 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1620 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
1622 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1623 and always contains final window position.
1625 winpos
->x
= newWindowRect
.left
;
1626 winpos
->y
= newWindowRect
.top
;
1627 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
1628 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
1629 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
1634 /***********************************************************************
1635 * SetWindowPos (USER32.@)
1637 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1638 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1642 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1643 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1644 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1646 if (is_broadcast(hwnd
))
1648 SetLastError( ERROR_INVALID_PARAMETER
);
1652 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1653 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1658 winpos
.flags
= flags
;
1660 if (WIN_IsCurrentThread( hwnd
))
1661 return USER_SetWindowPos(&winpos
);
1663 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1667 /***********************************************************************
1668 * BeginDeferWindowPos (USER32.@)
1670 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1675 TRACE("%d\n", count
);
1679 SetLastError(ERROR_INVALID_PARAMETER
);
1682 /* Windows allows zero count, in which case it allocates context for 8 moves */
1683 if (count
== 0) count
= 8;
1685 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1686 if (!handle
) return 0;
1687 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1688 pDWP
->actualCount
= 0;
1689 pDWP
->suggestedCount
= count
;
1691 pDWP
->wMagic
= DWP_MAGIC
;
1692 pDWP
->hwndParent
= 0;
1694 TRACE("returning hdwp %p\n", handle
);
1699 /***********************************************************************
1700 * DeferWindowPos (USER32.@)
1702 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1703 INT x
, INT y
, INT cx
, INT cy
,
1708 HDWP newhdwp
= hdwp
,retvalue
;
1710 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1711 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
1713 hwnd
= WIN_GetFullHandle( hwnd
);
1714 if (hwnd
== GetDesktopWindow()) return 0;
1716 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1720 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1722 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1724 /* Merge with the other changes */
1725 if (!(flags
& SWP_NOZORDER
))
1727 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1729 if (!(flags
& SWP_NOMOVE
))
1731 pDWP
->winPos
[i
].x
= x
;
1732 pDWP
->winPos
[i
].y
= y
;
1734 if (!(flags
& SWP_NOSIZE
))
1736 pDWP
->winPos
[i
].cx
= cx
;
1737 pDWP
->winPos
[i
].cy
= cy
;
1739 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1740 SWP_NOZORDER
| SWP_NOREDRAW
|
1741 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1743 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1749 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1751 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1752 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1758 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1759 pDWP
->suggestedCount
++;
1761 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1762 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1763 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1764 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1765 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1766 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1767 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1768 pDWP
->actualCount
++;
1776 /***********************************************************************
1777 * EndDeferWindowPos (USER32.@)
1779 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1786 TRACE("%p\n", hdwp
);
1788 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1789 if (!pDWP
) return FALSE
;
1790 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1792 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1793 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
1794 winpos
->cx
, winpos
->cy
, winpos
->flags
);
1796 if (!(res
= USER_SetWindowPos( winpos
))) break;
1798 USER_HEAP_FREE( hdwp
);
1803 /***********************************************************************
1804 * TileChildWindows (USER.199)
1806 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1808 FIXME("(%04x, %d): stub\n", parent
, action
);
1811 /***********************************************************************
1812 * CascadeChildWindows (USER.198)
1814 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1816 FIXME("(%04x, %d): stub\n", parent
, action
);