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
33 #include "wine/server.h"
35 #include "user_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
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) ((pt).x == -1 && (pt).y == -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)))
76 /***********************************************************************
77 * ArrangeIconicWindows (USER32.@)
79 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
83 INT x
, y
, xspacing
, yspacing
;
85 GetClientRect( parent
, &rectParent
);
87 y
= rectParent
.bottom
;
88 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
89 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
91 hwndChild
= GetWindow( parent
, GW_CHILD
);
94 if( IsIconic( hwndChild
) )
96 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
98 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
99 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
100 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
101 if( IsWindow(hwndChild
) )
102 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
104 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
111 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
117 /***********************************************************************
118 * SwitchToThisWindow (USER32.@)
120 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
122 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
126 /***********************************************************************
127 * GetWindowRect (USER32.@)
129 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
131 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
134 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
135 TRACE( "hwnd %p (%s)\n", hwnd
, wine_dbgstr_rect(rect
) );
141 /***********************************************************************
142 * GetWindowRgn (USER32.@)
144 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
154 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
156 SetLastError( ERROR_OUTOFMEMORY
);
159 SERVER_START_REQ( get_window_region
)
162 wine_server_set_reply( req
, data
->Buffer
, size
);
163 if (!(status
= wine_server_call( req
)))
165 size_t reply_size
= wine_server_reply_size( reply
);
168 data
->rdh
.dwSize
= sizeof(data
->rdh
);
169 data
->rdh
.iType
= RDH_RECTANGLES
;
170 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
171 data
->rdh
.nRgnSize
= reply_size
;
172 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
175 else size
= reply
->total_size
;
178 HeapFree( GetProcessHeap(), 0, data
);
179 } while (status
== STATUS_BUFFER_OVERFLOW
);
181 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
184 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
185 DeleteObject( win_rgn
);
191 /***********************************************************************
192 * SetWindowRgn (USER32.@)
194 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
196 static const RECT empty_rect
;
204 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
205 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
206 if (!GetRegionData( hrgn
, size
, data
))
208 HeapFree( GetProcessHeap(), 0, data
);
211 SERVER_START_REQ( set_window_region
)
214 req
->redraw
= (bRedraw
!= 0);
215 if (data
->rdh
.nCount
)
216 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
218 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
219 ret
= !wine_server_call_err( req
);
223 else /* clear existing region */
225 SERVER_START_REQ( set_window_region
)
228 req
->redraw
= (bRedraw
!= 0);
229 ret
= !wine_server_call_err( req
);
234 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
238 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
239 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
240 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
241 invalidate_dce( hwnd
, NULL
);
247 /***********************************************************************
248 * GetClientRect (USER32.@)
250 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
254 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
256 rect
->right
-= rect
->left
;
257 rect
->bottom
-= rect
->top
;
258 rect
->left
= rect
->top
= 0;
264 /*******************************************************************
265 * ClientToScreen (USER32.@)
267 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
269 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
274 /*******************************************************************
275 * ScreenToClient (USER32.@)
277 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
279 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
284 /***********************************************************************
285 * list_children_from_point
287 * Get the list of children that can contain point from the server.
288 * Point is in screen coordinates.
289 * Returned list must be freed by caller.
291 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
300 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
302 SERVER_START_REQ( get_window_children_from_point
)
307 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
308 if (!wine_server_call( req
)) count
= reply
->count
;
311 if (count
&& count
< size
)
316 HeapFree( GetProcessHeap(), 0, list
);
318 size
= count
+ 1; /* restart with a large enough buffer */
324 /***********************************************************************
325 * WINPOS_WindowFromPoint
327 * Find the window and hittest for a given point.
329 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
334 if (!hwndScope
) hwndScope
= GetDesktopWindow();
336 *hittest
= HTNOWHERE
;
338 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
340 /* now determine the hittest */
342 for (i
= 0; list
[i
]; i
++)
344 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
346 /* If window is minimized or disabled, return at once */
347 if (style
& WS_MINIMIZE
)
349 *hittest
= HTCAPTION
;
352 if (style
& WS_DISABLED
)
357 /* Send WM_NCCHITTEST (if same thread) */
358 if (!WIN_IsCurrentThread( list
[i
] ))
363 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
364 if (res
!= HTTRANSPARENT
)
366 *hittest
= res
; /* Found the window */
369 /* continue search with next window in z-order */
372 HeapFree( GetProcessHeap(), 0, list
);
373 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
378 /*******************************************************************
379 * WindowFromPoint (USER32.@)
381 HWND WINAPI
WindowFromPoint( POINT pt
)
384 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
388 /*******************************************************************
389 * ChildWindowFromPoint (USER32.@)
391 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
393 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
396 /*******************************************************************
397 * RealChildWindowFromPoint (USER32.@)
399 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
401 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
);
404 /*******************************************************************
405 * ChildWindowFromPointEx (USER32.@)
407 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
409 /* pt is in the client coordinates */
415 GetClientRect( hwndParent
, &rect
);
416 if (!PtInRect( &rect
, pt
)) return 0;
417 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
419 for (i
= 0; list
[i
]; i
++)
421 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
422 if (!PtInRect( &rect
, pt
)) continue;
423 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
425 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
426 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
427 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
429 if (uFlags
& CWP_SKIPTRANSPARENT
)
431 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
436 HeapFree( GetProcessHeap(), 0, list
);
437 if (!retvalue
) retvalue
= hwndParent
;
442 /*******************************************************************
443 * WINPOS_GetWinOffset
445 * Calculate the offset between the origin of the two windows. Used
446 * to implement MapWindowPoints.
448 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
452 offset
->x
= offset
->y
= 0;
454 /* Translate source window origin to screen coords */
457 HWND hwnd
= hwndFrom
;
461 if (hwnd
== hwndTo
) return;
462 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
464 ERR( "bad hwndFrom = %p\n", hwnd
);
467 if (wndPtr
== WND_DESKTOP
) break;
468 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
469 offset
->x
+= wndPtr
->rectClient
.left
;
470 offset
->y
+= wndPtr
->rectClient
.top
;
471 hwnd
= wndPtr
->parent
;
472 WIN_ReleasePtr( wndPtr
);
476 /* Translate origin to destination window coords */
483 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
485 ERR( "bad hwndTo = %p\n", hwnd
);
488 if (wndPtr
== WND_DESKTOP
) break;
489 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
490 offset
->x
-= wndPtr
->rectClient
.left
;
491 offset
->y
-= wndPtr
->rectClient
.top
;
492 hwnd
= wndPtr
->parent
;
493 WIN_ReleasePtr( wndPtr
);
498 other_process
: /* one of the parents may belong to another process, do it the hard way */
499 offset
->x
= offset
->y
= 0;
500 SERVER_START_REQ( get_windows_offset
)
502 req
->from
= hwndFrom
;
504 if (!wine_server_call( req
))
506 offset
->x
= reply
->x
;
507 offset
->y
= reply
->y
;
514 /*******************************************************************
515 * MapWindowPoints (USER.258)
517 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
518 LPPOINT16 lppt
, UINT16 count
)
522 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
532 /*******************************************************************
533 * MapWindowPoints (USER32.@)
535 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
539 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
546 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
550 /***********************************************************************
551 * IsIconic (USER32.@)
553 BOOL WINAPI
IsIconic(HWND hWnd
)
555 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
559 /***********************************************************************
560 * IsZoomed (USER32.@)
562 BOOL WINAPI
IsZoomed(HWND hWnd
)
564 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
568 /*******************************************************************
569 * AllowSetForegroundWindow (USER32.@)
571 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
573 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
574 * implemented, then fix this function. */
579 /*******************************************************************
580 * LockSetForegroundWindow (USER32.@)
582 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
584 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
585 * implemented, then fix this function. */
590 /***********************************************************************
591 * BringWindowToTop (USER32.@)
593 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
595 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
599 /***********************************************************************
600 * MoveWindow (USER32.@)
602 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
605 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
606 if (!repaint
) flags
|= SWP_NOREDRAW
;
607 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
608 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
611 /***********************************************************************
612 * WINPOS_InitPlacement
614 static void WINPOS_InitPlacement( WND
* wnd
)
616 if (IsRectEmpty( &wnd
->normal_rect
))
618 /* this happens when the window is minimized/maximized
619 * for the first time (rectWindow is not adjusted yet) */
621 wnd
->normal_rect
= wnd
->rectWindow
;
622 wnd
->min_pos
.x
= wnd
->min_pos
.y
= -1;
623 wnd
->max_pos
.x
= wnd
->max_pos
.y
= -1;
626 if( wnd
->dwStyle
& WS_MINIMIZE
)
628 wnd
->min_pos
.x
= wnd
->rectWindow
.left
;
629 wnd
->min_pos
.y
= wnd
->rectWindow
.top
;
631 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
633 wnd
->max_pos
.x
= wnd
->rectWindow
.left
;
634 wnd
->max_pos
.y
= wnd
->rectWindow
.top
;
638 wnd
->normal_rect
= wnd
->rectWindow
;
642 /***********************************************************************
643 * WINPOS_RedrawIconTitle
645 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
648 WND
*win
= WIN_GetPtr( hWnd
);
650 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
652 icon_title
= win
->icon_title
;
653 WIN_ReleasePtr( win
);
655 if (!icon_title
) return FALSE
;
656 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
657 InvalidateRect( icon_title
, NULL
, TRUE
);
661 /***********************************************************************
662 * WINPOS_ShowIconTitle
664 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
666 if (!GetPropA( hwnd
, "__wine_x11_managed" ))
668 WND
*win
= WIN_GetPtr( hwnd
);
671 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
673 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
674 title
= win
->icon_title
;
675 WIN_ReleasePtr( win
);
681 title
= ICONTITLE_Create( hwnd
);
682 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
684 DestroyWindow( title
);
687 win
->icon_title
= title
;
688 WIN_ReleasePtr( win
);
690 if (!IsWindowVisible(title
))
692 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
693 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
694 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
697 else if (title
) ShowWindow( title
, SW_HIDE
);
702 /*******************************************************************
703 * WINPOS_GetMinMaxInfo
705 * Get the minimized and maximized information for a window.
707 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
708 POINT
*minTrack
, POINT
*maxTrack
)
713 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
714 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
718 /* Compute default values */
720 GetWindowRect(hwnd
, &rc
);
721 MinMax
.ptReserved
.x
= rc
.left
;
722 MinMax
.ptReserved
.y
= rc
.top
;
724 if (style
& WS_CHILD
)
726 if ((style
& WS_CAPTION
) == WS_CAPTION
)
727 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
729 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
730 AdjustWindowRectEx(&rc
, style
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
732 /* avoid calculating this twice */
733 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
735 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
736 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
740 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
741 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
743 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
744 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
745 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
746 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
748 if (HAS_DLGFRAME( style
, exstyle
))
750 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
751 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
756 if (HAS_THICKFRAME(style
))
758 xinc
+= GetSystemMetrics(SM_CXFRAME
);
759 yinc
+= GetSystemMetrics(SM_CYFRAME
);
761 if (style
& WS_BORDER
)
763 xinc
+= GetSystemMetrics(SM_CXBORDER
);
764 yinc
+= GetSystemMetrics(SM_CYBORDER
);
767 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
768 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
770 MinMax
.ptMaxPosition
.x
= -xinc
;
771 MinMax
.ptMaxPosition
.y
= -yinc
;
772 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
774 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
775 WIN_ReleasePtr( win
);
778 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
780 /* if the app didn't change the values, adapt them for the current monitor */
782 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
784 MONITORINFO mon_info
;
786 mon_info
.cbSize
= sizeof(mon_info
);
787 GetMonitorInfoW( monitor
, &mon_info
);
789 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
790 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
792 MinMax
.ptMaxSize
.x
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) + 2 * xinc
;
793 MinMax
.ptMaxSize
.y
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) + 2 * yinc
;
795 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
797 MinMax
.ptMaxPosition
.x
= mon_info
.rcWork
.left
- xinc
;
798 MinMax
.ptMaxPosition
.y
= mon_info
.rcWork
.top
- yinc
;
802 /* Some sanity checks */
804 TRACE("%d %d / %d %d / %d %d / %d %d\n",
805 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
806 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
807 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
808 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
809 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
810 MinMax
.ptMinTrackSize
.x
);
811 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
812 MinMax
.ptMinTrackSize
.y
);
814 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
815 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
816 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
817 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
821 /***********************************************************************
824 * Find a suitable place for an iconic window.
826 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
828 RECT rect
, rectParent
;
831 int xspacing
, yspacing
;
833 parent
= GetAncestor( hwnd
, GA_PARENT
);
834 GetClientRect( parent
, &rectParent
);
835 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
836 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
837 return pt
; /* The icon already has a suitable position */
839 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
840 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
842 /* Check if another icon already occupies this spot */
843 /* FIXME: this is completely inefficient */
845 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
846 tmp
= CreateRectRgn( 0, 0, 0, 0 );
847 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
850 if (child
== hwnd
) continue;
851 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
853 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
855 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
856 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
857 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
858 WIN_ReleasePtr( childPtr
);
862 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
864 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
866 rect
.right
= rect
.left
+ xspacing
;
867 rect
.top
= rect
.bottom
- yspacing
;
868 if (!RectInRegion( hrgn
, &rect
))
870 /* No window was found, so it's OK for us */
871 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
872 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
873 DeleteObject( hrgn
);
878 DeleteObject( hrgn
);
884 /***********************************************************************
887 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
895 TRACE("%p %u\n", hwnd
, cmd
);
897 wpl
.length
= sizeof(wpl
);
898 GetWindowPlacement( hwnd
, &wpl
);
900 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
901 return SWP_NOSIZE
| SWP_NOMOVE
;
903 if (IsIconic( hwnd
))
907 case SW_SHOWMINNOACTIVE
:
908 case SW_SHOWMINIMIZED
:
909 case SW_FORCEMINIMIZE
:
911 return SWP_NOSIZE
| SWP_NOMOVE
;
913 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
914 swpFlags
|= SWP_NOCOPYBITS
;
919 case SW_SHOWMINNOACTIVE
:
920 case SW_SHOWMINIMIZED
:
921 case SW_FORCEMINIMIZE
:
923 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
924 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
925 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
926 WIN_ReleasePtr( wndPtr
);
928 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
930 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
932 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
933 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
934 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
935 swpFlags
|= SWP_NOCOPYBITS
;
939 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
940 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
942 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
944 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
945 if (old_style
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, FALSE
);
947 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
948 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
951 case SW_SHOWNOACTIVATE
:
954 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
955 if (old_style
& WS_MINIMIZE
)
959 WINPOS_ShowIconTitle( hwnd
, FALSE
);
961 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
962 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
963 WIN_ReleasePtr( wndPtr
);
966 /* Restore to maximized position */
967 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
968 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
969 swpFlags
|= SWP_STATECHANGED
;
970 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
974 else if (!(old_style
& WS_MAXIMIZE
)) break;
976 swpFlags
|= SWP_STATECHANGED
;
978 /* Restore to normal position */
980 *rect
= wpl
.rcNormalPosition
;
981 rect
->right
-= rect
->left
;
982 rect
->bottom
-= rect
->top
;
991 /***********************************************************************
994 * Implementation of ShowWindow and ShowWindowAsync.
996 static BOOL
show_window( HWND hwnd
, INT cmd
)
1000 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1001 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
1002 BOOL showFlag
= TRUE
;
1003 RECT newPos
= {0, 0, 0, 0};
1006 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
1011 if (!wasVisible
) return FALSE
;
1013 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1014 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1017 case SW_SHOWMINNOACTIVE
:
1018 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1021 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1022 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1024 case SW_SHOWMINIMIZED
:
1025 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1026 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1027 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
1030 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1031 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1032 swp
|= SWP_FRAMECHANGED
;
1033 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1034 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
1038 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1039 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
1042 if (wasVisible
) return TRUE
;
1043 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1044 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1047 case SW_SHOWNOACTIVATE
:
1048 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1052 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1053 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1054 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1055 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1057 swp
|= SWP_FRAMECHANGED
;
1058 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1062 if (wasVisible
) return TRUE
;
1063 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1065 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1071 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1073 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1074 if (!IsWindow( hwnd
)) return wasVisible
;
1077 parent
= GetAncestor( hwnd
, GA_PARENT
);
1078 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1080 /* if parent is not visible simply toggle WS_VISIBLE and return */
1081 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1082 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1085 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1086 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1092 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1094 /* FIXME: This will cause the window to be activated irrespective
1095 * of whether it is owned by the same thread. Has to be done
1099 if (hwnd
== GetActiveWindow())
1100 WINPOS_ActivateOtherWindow(hwnd
);
1102 /* Revert focus to parent */
1103 hFocus
= GetFocus();
1104 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
1106 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1107 if (parent
== GetDesktopWindow()) parent
= 0;
1112 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1114 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1116 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1118 /* should happen only in CreateWindowEx() */
1119 int wParam
= SIZE_RESTORED
;
1120 RECT client
= wndPtr
->rectClient
;
1122 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1123 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1124 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1125 WIN_ReleasePtr( wndPtr
);
1127 SendMessageW( hwnd
, WM_SIZE
, wParam
,
1128 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
1129 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1131 else WIN_ReleasePtr( wndPtr
);
1133 /* if previous state was minimized Windows sets focus to the window */
1134 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1140 /***********************************************************************
1141 * ShowWindowAsync (USER32.@)
1143 * doesn't wait; returns immediately.
1144 * used by threads to toggle windows in other (possibly hanging) threads
1146 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1150 if (is_broadcast(hwnd
))
1152 SetLastError( ERROR_INVALID_PARAMETER
);
1156 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1157 return show_window( full_handle
, cmd
);
1159 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1163 /***********************************************************************
1164 * ShowWindow (USER32.@)
1166 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1170 if (is_broadcast(hwnd
))
1172 SetLastError( ERROR_INVALID_PARAMETER
);
1175 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1176 return show_window( full_handle
, cmd
);
1178 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1182 /***********************************************************************
1183 * GetInternalWindowPos (USER32.@)
1185 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1188 WINDOWPLACEMENT wndpl
;
1189 if (GetWindowPlacement( hwnd
, &wndpl
))
1191 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1192 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1193 return wndpl
.showCmd
;
1199 /***********************************************************************
1200 * GetWindowPlacement (USER32.@)
1203 * Fails if wndpl->length of Win95 (!) apps is invalid.
1205 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1207 WND
*pWnd
= WIN_GetPtr( hwnd
);
1209 if (!pWnd
|| pWnd
== WND_DESKTOP
) return FALSE
;
1210 if (pWnd
== WND_OTHER_PROCESS
)
1212 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
1216 WINPOS_InitPlacement( pWnd
);
1217 wndpl
->length
= sizeof(*wndpl
);
1218 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1219 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1221 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1222 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1223 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1226 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1227 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1228 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1229 WIN_ReleasePtr( pWnd
);
1231 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1232 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1233 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1234 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1238 /* make sure the specified rect is visible on screen */
1239 static void make_rect_onscreen( RECT
*rect
)
1242 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1244 info
.cbSize
= sizeof(info
);
1245 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1246 /* FIXME: map coordinates from rcWork to rcMonitor */
1247 if (rect
->right
<= info
.rcWork
.left
)
1249 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1250 rect
->left
= info
.rcWork
.left
;
1252 else if (rect
->left
>= info
.rcWork
.right
)
1254 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1255 rect
->right
= info
.rcWork
.right
;
1257 if (rect
->bottom
<= info
.rcWork
.top
)
1259 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1260 rect
->top
= info
.rcWork
.top
;
1262 else if (rect
->top
>= info
.rcWork
.bottom
)
1264 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1265 rect
->bottom
= info
.rcWork
.bottom
;
1269 /* make sure the specified point is visible on screen */
1270 static void make_point_onscreen( POINT
*pt
)
1274 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1275 make_rect_onscreen( &rect
);
1281 /***********************************************************************
1282 * WINPOS_SetPlacement
1284 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1287 WND
*pWnd
= WIN_GetPtr( hwnd
);
1288 WINDOWPLACEMENT wp
= *wndpl
;
1290 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1291 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1292 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1294 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1295 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1296 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1297 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1298 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1299 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1301 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1303 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1304 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1305 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1307 style
= pWnd
->dwStyle
;
1309 WIN_ReleasePtr( pWnd
);
1311 if( style
& WS_MINIMIZE
)
1313 if (flags
& PLACE_MIN
)
1315 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1316 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1317 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1320 else if( style
& WS_MAXIMIZE
)
1322 if (flags
& PLACE_MAX
)
1323 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1324 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1326 else if( flags
& PLACE_RECT
)
1327 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1328 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1329 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1330 SWP_NOZORDER
| SWP_NOACTIVATE
);
1332 ShowWindow( hwnd
, wndpl
->showCmd
);
1334 if (IsIconic( hwnd
))
1336 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1338 /* SDK: ...valid only the next time... */
1339 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1341 pWnd
= WIN_GetPtr( hwnd
);
1342 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1344 pWnd
->flags
|= WIN_RESTORE_MAX
;
1345 WIN_ReleasePtr( pWnd
);
1353 /***********************************************************************
1354 * SetWindowPlacement (USER32.@)
1357 * Fails if wndpl->length of Win95 (!) apps is invalid.
1359 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1361 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1362 if (!wpl
) return FALSE
;
1363 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1364 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1368 /***********************************************************************
1369 * AnimateWindow (USER32.@)
1370 * Shows/Hides a window with an animation
1373 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1375 FIXME("partial stub\n");
1377 /* If trying to show/hide and it's already *
1378 * shown/hidden or invalid window, fail with *
1379 * invalid parameter */
1380 if(!IsWindow(hwnd
) ||
1381 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1382 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1384 SetLastError(ERROR_INVALID_PARAMETER
);
1388 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1393 /***********************************************************************
1394 * SetInternalWindowPos (USER32.@)
1396 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1397 LPRECT rect
, LPPOINT pt
)
1399 WINDOWPLACEMENT wndpl
;
1402 wndpl
.length
= sizeof(wndpl
);
1403 wndpl
.showCmd
= showCmd
;
1404 wndpl
.flags
= flags
= 0;
1409 wndpl
.flags
|= WPF_SETMINPOSITION
;
1410 wndpl
.ptMinPosition
= *pt
;
1414 flags
|= PLACE_RECT
;
1415 wndpl
.rcNormalPosition
= *rect
;
1417 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1421 /*******************************************************************
1422 * can_activate_window
1424 * Check if we can activate the specified window.
1426 static BOOL
can_activate_window( HWND hwnd
)
1430 if (!hwnd
) return FALSE
;
1431 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1432 if (!(style
& WS_VISIBLE
)) return FALSE
;
1433 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1434 return !(style
& WS_DISABLED
);
1438 /*******************************************************************
1439 * WINPOS_ActivateOtherWindow
1441 * Activates window other than pWnd.
1443 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1447 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1449 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1450 if (can_activate_window( hwndTo
)) goto done
;
1456 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1457 if (can_activate_window( hwndTo
)) break;
1461 fg
= GetForegroundWindow();
1462 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1463 if (!fg
|| (hwnd
== fg
))
1465 if (SetForegroundWindow( hwndTo
)) return;
1467 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1471 /***********************************************************************
1472 * WINPOS_HandleWindowPosChanging
1474 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1476 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1478 POINT minTrack
, maxTrack
;
1479 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1481 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1482 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1484 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1485 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1486 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1487 if (!(style
& WS_MINIMIZE
))
1489 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1490 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1497 /***********************************************************************
1500 static void dump_winpos_flags(UINT flags
)
1503 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1504 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1505 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1506 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1507 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1508 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1509 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1510 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1511 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1512 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1513 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1514 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1515 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1517 #define DUMPED_FLAGS \
1523 SWP_FRAMECHANGED | \
1527 SWP_NOOWNERZORDER | \
1528 SWP_NOSENDCHANGING | \
1532 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1537 /***********************************************************************
1538 * SWP_DoWinPosChanging
1540 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1544 /* Send WM_WINDOWPOSCHANGING message */
1546 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1547 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1549 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1550 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1552 /* Calculate new position and size */
1554 *pNewWindowRect
= wndPtr
->rectWindow
;
1555 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1556 : wndPtr
->rectClient
;
1558 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1560 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1561 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1563 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1565 pNewWindowRect
->left
= pWinpos
->x
;
1566 pNewWindowRect
->top
= pWinpos
->y
;
1567 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1568 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1570 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1571 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1573 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1575 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1576 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1577 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1578 TRACE( "current %s style %08x new %s\n",
1579 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1580 wine_dbgstr_rect( pNewWindowRect
));
1582 WIN_ReleasePtr( wndPtr
);
1586 /***********************************************************************
1589 * Compute the valid rects from the old and new client rect and WVR_* flags.
1590 * Helper for WM_NCCALCSIZE handling.
1592 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1597 if (flags
& WVR_REDRAW
)
1599 SetRectEmpty( &valid
[0] );
1600 SetRectEmpty( &valid
[1] );
1604 if (flags
& WVR_VALIDRECTS
)
1606 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1607 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1609 SetRectEmpty( &valid
[0] );
1610 SetRectEmpty( &valid
[1] );
1613 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1617 valid
[0] = *new_client
;
1618 valid
[1] = *old_client
;
1621 /* make sure the rectangles have the same size */
1622 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1623 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1625 if (flags
& WVR_ALIGNBOTTOM
)
1627 valid
[0].top
= valid
[0].bottom
- cy
;
1628 valid
[1].top
= valid
[1].bottom
- cy
;
1632 valid
[0].bottom
= valid
[0].top
+ cy
;
1633 valid
[1].bottom
= valid
[1].top
+ cy
;
1635 if (flags
& WVR_ALIGNRIGHT
)
1637 valid
[0].left
= valid
[0].right
- cx
;
1638 valid
[1].left
= valid
[1].right
- cx
;
1642 valid
[0].right
= valid
[0].left
+ cx
;
1643 valid
[1].right
= valid
[1].left
+ cx
;
1648 /***********************************************************************
1651 * fix Z order taking into account owned popups -
1652 * basically we need to maintain them above the window that owns them
1654 * FIXME: hide/show owned popups when owner visibility changes.
1656 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1658 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1659 HWND owner
, *list
= NULL
;
1662 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1664 if ((style
& WS_POPUP
) && (owner
= GetWindow( hwnd
, GW_OWNER
)))
1666 /* make sure this popup stays above the owner */
1668 if (hwndInsertAfter
!= HWND_TOP
&& hwndInsertAfter
!= HWND_TOPMOST
)
1670 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1672 for (i
= 0; list
[i
]; i
++)
1674 if (list
[i
] == owner
)
1676 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1677 else hwndInsertAfter
= HWND_TOP
;
1681 if (hwndInsertAfter
== HWND_NOTOPMOST
)
1683 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) break;
1685 else if (list
[i
] == hwndInsertAfter
) break;
1689 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1691 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1692 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1695 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1697 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1699 /* skip all the topmost windows */
1700 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1703 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1705 /* skip windows that are already placed correctly */
1706 for (i
= 0; list
[i
]; i
++)
1708 if (list
[i
] == hwndInsertAfter
) break;
1709 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1713 for ( ; list
[i
]; i
++)
1715 if (list
[i
] == hwnd
) break;
1716 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
)) continue;
1717 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1718 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1719 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1720 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1721 hwndInsertAfter
= list
[i
];
1725 HeapFree( GetProcessHeap(), 0, list
);
1726 return hwndInsertAfter
;
1729 /***********************************************************************
1732 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1738 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1740 /* Send WM_NCCALCSIZE message to get new client area */
1741 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1743 NCCALCSIZE_PARAMS params
;
1744 WINDOWPOS winposCopy
;
1746 params
.rgrc
[0] = *pNewWindowRect
;
1747 params
.rgrc
[1] = wndPtr
->rectWindow
;
1748 params
.rgrc
[2] = wndPtr
->rectClient
;
1749 params
.lppos
= &winposCopy
;
1750 winposCopy
= *pWinpos
;
1751 WIN_ReleasePtr( wndPtr
);
1753 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1755 *pNewClientRect
= params
.rgrc
[0];
1757 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1759 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1760 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1761 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1763 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1764 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1765 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1767 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1768 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1769 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1771 wvrFlags
&= ~WVR_HREDRAW
;
1773 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1774 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1775 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1777 wvrFlags
&= ~WVR_VREDRAW
;
1779 validRects
[0] = params
.rgrc
[1];
1780 validRects
[1] = params
.rgrc
[2];
1784 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1785 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1786 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1787 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1790 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1792 SetRectEmpty( &validRects
[0] );
1793 SetRectEmpty( &validRects
[1] );
1795 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1797 WIN_ReleasePtr( wndPtr
);
1801 /* fix redundant flags and values in the WINDOWPOS structure */
1802 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1805 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1808 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1810 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1813 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1815 /* Finally make sure that all coordinates are valid */
1816 if (winpos
->x
< -32768) winpos
->x
= -32768;
1817 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1818 if (winpos
->y
< -32768) winpos
->y
= -32768;
1819 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1821 if (winpos
->cx
< 0) winpos
->cx
= 0;
1822 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1823 if (winpos
->cy
< 0) winpos
->cy
= 0;
1824 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1826 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1827 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1829 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1832 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1833 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1836 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1837 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1838 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1840 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1841 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1843 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1845 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1846 (winpos
->flags
& SWP_NOZORDER
||
1847 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1849 winpos
->flags
&= ~SWP_NOZORDER
;
1850 winpos
->hwndInsertAfter
= HWND_TOP
;
1854 /* Check hwndInsertAfter */
1855 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1857 /* fix sign extension */
1858 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1859 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1861 /* hwndInsertAfter must be a sibling of the window */
1862 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1864 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1865 winpos
->flags
|= SWP_NOZORDER
;
1867 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1869 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1870 winpos
->flags
|= SWP_NOZORDER
;
1872 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1874 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1875 winpos
->flags
|= SWP_NOZORDER
;
1877 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1879 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1880 winpos
->flags
|= SWP_NOZORDER
;
1884 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1887 /* don't need to change the Zorder of hwnd if it's already inserted
1888 * after hwndInsertAfter or when inserting hwnd after itself.
1890 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1891 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1892 winpos
->flags
|= SWP_NOZORDER
;
1896 WIN_ReleasePtr( wndPtr
);
1901 /***********************************************************************
1904 * Backend implementation of SetWindowPos.
1906 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1907 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
1911 RECT visible_rect
, old_window_rect
;
1914 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
1915 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
1917 old_window_rect
= win
->rectWindow
;
1918 SERVER_START_REQ( set_window_pos
)
1921 req
->previous
= insert_after
;
1922 req
->flags
= swp_flags
;
1923 req
->window
.left
= window_rect
->left
;
1924 req
->window
.top
= window_rect
->top
;
1925 req
->window
.right
= window_rect
->right
;
1926 req
->window
.bottom
= window_rect
->bottom
;
1927 req
->client
.left
= client_rect
->left
;
1928 req
->client
.top
= client_rect
->top
;
1929 req
->client
.right
= client_rect
->right
;
1930 req
->client
.bottom
= client_rect
->bottom
;
1931 if (!IsRectEmpty( &valid_rects
[0] ))
1932 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
1933 if ((ret
= !wine_server_call( req
)))
1935 win
->dwStyle
= reply
->new_style
;
1936 win
->dwExStyle
= reply
->new_ex_style
;
1937 win
->rectWindow
= *window_rect
;
1938 win
->rectClient
= *client_rect
;
1939 visible_rect
.left
= reply
->visible
.left
;
1940 visible_rect
.top
= reply
->visible
.top
;
1941 visible_rect
.right
= reply
->visible
.right
;
1942 visible_rect
.bottom
= reply
->visible
.bottom
;
1946 new_style
= win
->dwStyle
;
1947 WIN_ReleasePtr( win
);
1951 USER_Driver
->pSetWindowPos( hwnd
, insert_after
, swp_flags
, window_rect
,
1952 client_rect
, &visible_rect
, valid_rects
);
1954 if ((((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) && (new_style
& WS_VISIBLE
)) ||
1955 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)))
1956 invalidate_dce( hwnd
, &old_window_rect
);
1962 /***********************************************************************
1965 * User32 internal function
1967 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1969 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1972 orig_flags
= winpos
->flags
;
1974 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1975 if (!(winpos
->flags
& SWP_NOMOVE
))
1977 if (winpos
->x
< -32768) winpos
->x
= -32768;
1978 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1979 if (winpos
->y
< -32768) winpos
->y
= -32768;
1980 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1982 if (!(winpos
->flags
& SWP_NOSIZE
))
1984 if (winpos
->cx
< 0) winpos
->cx
= 0;
1985 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1986 if (winpos
->cy
< 0) winpos
->cy
= 0;
1987 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1990 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1992 /* Fix redundant flags */
1993 if (!fixup_flags( winpos
)) return FALSE
;
1995 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1997 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1998 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
2001 /* Common operations */
2003 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
2005 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
2006 &newWindowRect
, &newClientRect
, valid_rects
))
2009 /* erase parent when hiding or resizing child */
2010 if (!(orig_flags
& SWP_DEFERERASE
) &&
2011 ((orig_flags
& SWP_HIDEWINDOW
) ||
2012 (!(orig_flags
& SWP_SHOWWINDOW
) &&
2013 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
2015 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2016 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
2017 erase_now( parent
, 0 );
2020 if( winpos
->flags
& SWP_HIDEWINDOW
)
2021 HideCaret(winpos
->hwnd
);
2022 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2023 ShowCaret(winpos
->hwnd
);
2025 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2027 /* child windows get WM_CHILDACTIVATE message */
2028 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2029 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2031 SetForegroundWindow( winpos
->hwnd
);
2034 /* And last, send the WM_WINDOWPOSCHANGED message */
2036 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2038 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2040 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2041 and always contains final window position.
2043 winpos
->x
= newWindowRect
.left
;
2044 winpos
->y
= newWindowRect
.top
;
2045 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2046 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2047 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2052 /***********************************************************************
2053 * SetWindowPos (USER32.@)
2055 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2056 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2060 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2061 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2062 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2064 if (is_broadcast(hwnd
))
2066 SetLastError( ERROR_INVALID_PARAMETER
);
2070 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2071 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2076 winpos
.flags
= flags
;
2078 if (WIN_IsCurrentThread( hwnd
))
2079 return USER_SetWindowPos(&winpos
);
2081 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2085 /***********************************************************************
2086 * BeginDeferWindowPos (USER32.@)
2088 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2093 TRACE("%d\n", count
);
2097 SetLastError(ERROR_INVALID_PARAMETER
);
2100 /* Windows allows zero count, in which case it allocates context for 8 moves */
2101 if (count
== 0) count
= 8;
2103 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
2104 if (!handle
) return 0;
2105 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
2106 pDWP
->actualCount
= 0;
2107 pDWP
->suggestedCount
= count
;
2109 pDWP
->wMagic
= DWP_MAGIC
;
2110 pDWP
->hwndParent
= 0;
2112 TRACE("returning hdwp %p\n", handle
);
2117 /***********************************************************************
2118 * DeferWindowPos (USER32.@)
2120 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2121 INT x
, INT y
, INT cx
, INT cy
,
2126 HDWP newhdwp
= hdwp
,retvalue
;
2128 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2129 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2131 hwnd
= WIN_GetFullHandle( hwnd
);
2132 if (hwnd
== GetDesktopWindow()) return 0;
2134 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
2138 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2140 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2142 /* Merge with the other changes */
2143 if (!(flags
& SWP_NOZORDER
))
2145 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2147 if (!(flags
& SWP_NOMOVE
))
2149 pDWP
->winPos
[i
].x
= x
;
2150 pDWP
->winPos
[i
].y
= y
;
2152 if (!(flags
& SWP_NOSIZE
))
2154 pDWP
->winPos
[i
].cx
= cx
;
2155 pDWP
->winPos
[i
].cy
= cy
;
2157 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2158 SWP_NOZORDER
| SWP_NOREDRAW
|
2159 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2161 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2167 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2169 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2170 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
2176 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
2177 pDWP
->suggestedCount
++;
2179 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2180 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2181 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2182 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2183 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2184 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2185 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2186 pDWP
->actualCount
++;
2194 /***********************************************************************
2195 * EndDeferWindowPos (USER32.@)
2197 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2204 TRACE("%p\n", hdwp
);
2206 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
2207 if (!pDWP
) return FALSE
;
2208 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
2210 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2211 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2212 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2214 if (!(res
= USER_SetWindowPos( winpos
))) break;
2216 USER_HEAP_FREE( hdwp
);