2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
28 #define WIN32_NO_STATUS
34 #include "wine/winuser16.h"
35 #include "wine/server.h"
37 #include "user_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
44 #define HAS_DLGFRAME(style,exStyle) \
45 (((exStyle) & WS_EX_DLGMODALFRAME) || \
46 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
48 #define HAS_THICKFRAME(style) \
49 (((style) & WS_THICKFRAME) && \
50 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
52 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
54 #define PLACE_MIN 0x0001
55 #define PLACE_MAX 0x0002
56 #define PLACE_RECT 0x0004
59 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
77 } INTERNALPOS, *LPINTERNALPOS;
79 /* ----- internal functions ----- */
81 static inline INTERNALPOS *get_internal_pos( HWND hwnd )
83 return GetPropA( hwnd, "SysIP" );
86 static inline void set_internal_pos( HWND hwnd, INTERNALPOS *pos )
88 SetPropA( hwnd, "SysIP", pos );
91 /***********************************************************************
92 * WINPOS_CheckInternalPos
94 * Called when a window is destroyed.
96 void WINPOS_CheckInternalPos( HWND hwnd )
98 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
102 if( IsWindow(lpPos->hwndIconTitle) )
103 DestroyWindow( lpPos->hwndIconTitle );
104 HeapFree( GetProcessHeap(), 0, lpPos );
108 /***********************************************************************
109 * ArrangeIconicWindows (USER32.@)
111 UINT WINAPI ArrangeIconicWindows( HWND parent )
115 INT x, y, xspacing, yspacing;
117 GetClientRect( parent, &rectParent );
119 y = rectParent.bottom;
120 xspacing = GetSystemMetrics(SM_CXICONSPACING);
121 yspacing = GetSystemMetrics(SM_CYICONSPACING);
123 hwndChild = GetWindow( parent, GW_CHILD );
126 if( IsIconic( hwndChild ) )
128 WINPOS_ShowIconTitle( hwndChild, FALSE );
130 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
131 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
132 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
133 if( IsWindow(hwndChild) )
134 WINPOS_ShowIconTitle(hwndChild , TRUE );
136 if (x <= rectParent.right - xspacing) x += xspacing;
143 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
149 /***********************************************************************
150 * SwitchToThisWindow (USER32.@)
152 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
154 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
158 /***********************************************************************
159 * GetWindowRect (USER32.@)
161 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
163 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
166 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
167 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
168 hwnd, rect->left, rect->top, rect->right, rect->bottom);
174 /***********************************************************************
175 * GetWindowRgn (USER32.@)
177 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
187 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
189 SetLastError( ERROR_OUTOFMEMORY );
192 SERVER_START_REQ( get_window_region )
195 wine_server_set_reply( req, data->Buffer, size );
196 if (!(status = wine_server_call( req )))
198 size_t reply_size = wine_server_reply_size( reply );
201 data->rdh.dwSize = sizeof(data->rdh);
202 data->rdh.iType = RDH_RECTANGLES;
203 data->rdh.nCount = reply_size / sizeof(RECT);
204 data->rdh.nRgnSize = reply_size;
205 win_rgn = ExtCreateRegion( NULL, size, data );
208 else size = reply->total_size;
211 HeapFree( GetProcessHeap(), 0, data );
212 } while (status == STATUS_BUFFER_OVERFLOW);
214 if (status) SetLastError( RtlNtStatusToDosError(status) );
217 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
218 DeleteObject( win_rgn );
224 /***********************************************************************
225 * SetWindowRgn (USER32.@)
227 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
229 static const RECT empty_rect;
237 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
238 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
239 if (!GetRegionData( hrgn, size, data ))
241 HeapFree( GetProcessHeap(), 0, data );
244 SERVER_START_REQ( set_window_region )
247 if (data->rdh.nCount)
248 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
250 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
251 ret = !wine_server_call_err( req );
255 else /* clear existing region */
257 SERVER_START_REQ( set_window_region )
260 ret = !wine_server_call_err( req );
265 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
267 if (ret && bRedraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
272 /***********************************************************************
273 * GetClientRect (USER32.@)
275 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
279 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
281 rect->right -= rect->left;
282 rect->bottom -= rect->top;
283 rect->left = rect->top = 0;
289 /*******************************************************************
290 * ClientToScreen (USER32.@)
292 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
294 MapWindowPoints( hwnd, 0, lppnt, 1 );
299 /*******************************************************************
300 * ScreenToClient (USER32.@)
302 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
304 MapWindowPoints( 0, hwnd, lppnt, 1 );
309 /***********************************************************************
310 * list_children_from_point
312 * Get the list of children that can contain point from the server.
313 * Point is in screen coordinates.
314 * Returned list must be freed by caller.
316 static HWND *list_children_from_point( HWND hwnd, POINT pt )
325 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
327 SERVER_START_REQ( get_window_children_from_point )
332 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
333 if (!wine_server_call( req )) count = reply->count;
336 if (count && count < size)
341 HeapFree( GetProcessHeap(), 0, list );
343 size = count + 1; /* restart with a large enough buffer */
349 /***********************************************************************
350 * WINPOS_WindowFromPoint
352 * Find the window and hittest for a given point.
354 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
359 if (!hwndScope) hwndScope = GetDesktopWindow();
361 *hittest = HTNOWHERE;
363 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
365 /* now determine the hittest */
367 for (i = 0; list[i]; i++)
369 LONG style = GetWindowLongW( list[i], GWL_STYLE );
371 /* If window is minimized or disabled, return at once */
372 if (style & WS_MINIMIZE)
374 *hittest = HTCAPTION;
377 if (style & WS_DISABLED)
382 /* Send WM_NCCHITTEST (if same thread) */
383 if (!WIN_IsCurrentThread( list[i] ))
388 res = SendMessageA( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
389 if (res != HTTRANSPARENT)
391 *hittest = res; /* Found the window */
394 /* continue search with next window in z-order */
397 HeapFree( GetProcessHeap(), 0, list );
398 TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope, pt.x, pt.y, ret );
403 /*******************************************************************
404 * WindowFromPoint (USER32.@)
406 HWND WINAPI WindowFromPoint( POINT pt )
409 return WINPOS_WindowFromPoint( 0, pt, &hittest );
413 /*******************************************************************
414 * ChildWindowFromPoint (USER32.@)
416 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
418 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
421 /*******************************************************************
422 * ChildWindowFromPointEx (USER32.@)
424 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
426 /* pt is in the client coordinates */
432 GetClientRect( hwndParent, &rect );
433 if (!PtInRect( &rect, pt )) return 0;
434 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
436 for (i = 0; list[i]; i++)
438 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
439 if (!PtInRect( &rect, pt )) continue;
440 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
442 LONG style = GetWindowLongW( list[i], GWL_STYLE );
443 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
444 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
446 if (uFlags & CWP_SKIPTRANSPARENT)
448 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
453 HeapFree( GetProcessHeap(), 0, list );
454 if (!retvalue) retvalue = hwndParent;
459 /*******************************************************************
460 * WINPOS_GetWinOffset
462 * Calculate the offset between the origin of the two windows. Used
463 * to implement MapWindowPoints.
465 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
469 offset->x = offset->y = 0;
471 /* Translate source window origin to screen coords */
474 HWND hwnd = hwndFrom;
478 if (hwnd == hwndTo) return;
479 if (!(wndPtr = WIN_GetPtr( hwnd )))
481 ERR( "bad hwndFrom = %p\n", hwnd );
484 if (wndPtr == WND_DESKTOP) break;
485 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
486 offset->x += wndPtr->rectClient.left;
487 offset->y += wndPtr->rectClient.top;
488 hwnd = wndPtr->parent;
489 WIN_ReleasePtr( wndPtr );
493 /* Translate origin to destination window coords */
500 if (!(wndPtr = WIN_GetPtr( hwnd )))
502 ERR( "bad hwndTo = %p\n", hwnd );
505 if (wndPtr == WND_DESKTOP) break;
506 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
507 offset->x -= wndPtr->rectClient.left;
508 offset->y -= wndPtr->rectClient.top;
509 hwnd = wndPtr->parent;
510 WIN_ReleasePtr( wndPtr );
515 other_process: /* one of the parents may belong to another process, do it the hard way */
516 offset->x = offset->y = 0;
517 SERVER_START_REQ( get_windows_offset )
519 req->from = hwndFrom;
521 if (!wine_server_call( req ))
523 offset->x = reply->x;
524 offset->y = reply->y;
531 /*******************************************************************
532 * MapWindowPoints (USER.258)
534 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
535 LPPOINT16 lppt, UINT16 count )
539 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
549 /*******************************************************************
550 * MapWindowPoints (USER32.@)
552 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
556 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
563 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
567 /***********************************************************************
568 * IsIconic (USER32.@)
570 BOOL WINAPI IsIconic(HWND hWnd)
572 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
576 /***********************************************************************
577 * IsZoomed (USER32.@)
579 BOOL WINAPI IsZoomed(HWND hWnd)
581 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
585 /*******************************************************************
586 * AllowSetForegroundWindow (USER32.@)
588 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
590 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
591 * implemented, then fix this function. */
596 /*******************************************************************
597 * LockSetForegroundWindow (USER32.@)
599 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
601 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
602 * implemented, then fix this function. */
607 /***********************************************************************
608 * BringWindowToTop (USER32.@)
610 BOOL WINAPI BringWindowToTop( HWND hwnd )
612 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
616 /***********************************************************************
617 * MoveWindow (USER32.@)
619 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
622 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
623 if (!repaint) flags |= SWP_NOREDRAW;
624 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
625 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
628 /***********************************************************************
629 * WINPOS_InitInternalPos
631 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd )
633 LPINTERNALPOS lpPos = get_internal_pos( wnd->hwndSelf );
636 /* this happens when the window is minimized/maximized
637 * for the first time (rectWindow is not adjusted yet) */
639 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
640 if( !lpPos ) return NULL;
642 set_internal_pos( wnd->hwndSelf, lpPos );
643 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
644 lpPos->rectNormal.left = wnd->rectWindow.left;
645 lpPos->rectNormal.top = wnd->rectWindow.top;
646 lpPos->rectNormal.right = wnd->rectWindow.right;
647 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
648 lpPos->ptIconPos.x = lpPos->ptIconPos.y = -1;
649 lpPos->ptMaxPos.x = lpPos->ptMaxPos.y = -1;
652 if( wnd->dwStyle & WS_MINIMIZE )
654 lpPos->ptIconPos.x = wnd->rectWindow.left;
655 lpPos->ptIconPos.y = wnd->rectWindow.top;
657 else if( wnd->dwStyle & WS_MAXIMIZE )
659 lpPos->ptMaxPos.x = wnd->rectWindow.left;
660 lpPos->ptMaxPos.y = wnd->rectWindow.top;
664 lpPos->rectNormal.left = wnd->rectWindow.left;
665 lpPos->rectNormal.top = wnd->rectWindow.top;
666 lpPos->rectNormal.right = wnd->rectWindow.right;
667 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
672 /***********************************************************************
673 * WINPOS_RedrawIconTitle
675 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
677 LPINTERNALPOS lpPos = get_internal_pos( hWnd );
680 if( lpPos->hwndIconTitle )
682 SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
683 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
690 /***********************************************************************
691 * WINPOS_ShowIconTitle
693 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
695 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
697 if (lpPos && !GetPropA( hwnd, "__wine_x11_managed" ))
699 HWND title = lpPos->hwndIconTitle;
701 TRACE("%p %i\n", hwnd, (bShow != 0) );
704 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
707 if (!IsWindowVisible(title))
709 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
710 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
711 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
714 else ShowWindow( title, SW_HIDE );
719 /*******************************************************************
720 * WINPOS_GetMinMaxInfo
722 * Get the minimized and maximized information for a window.
724 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
725 POINT *minTrack, POINT *maxTrack )
730 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
731 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
734 /* Compute default values */
736 GetWindowRect(hwnd, &rc);
737 MinMax.ptReserved.x = rc.left;
738 MinMax.ptReserved.y = rc.top;
740 if (style & WS_CHILD)
742 if ((style & WS_CAPTION) == WS_CAPTION)
743 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
745 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
746 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
748 /* avoid calculating this twice */
749 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
751 MinMax.ptMaxSize.x = rc.right - rc.left;
752 MinMax.ptMaxSize.y = rc.bottom - rc.top;
756 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
757 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
759 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
760 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
761 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN) + 2*GetSystemMetrics(SM_CXFRAME);
762 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN) + 2*GetSystemMetrics(SM_CYFRAME);
764 if (HAS_DLGFRAME( style, exstyle ))
766 xinc = GetSystemMetrics(SM_CXDLGFRAME);
767 yinc = GetSystemMetrics(SM_CYDLGFRAME);
772 if (HAS_THICKFRAME(style))
774 xinc += GetSystemMetrics(SM_CXFRAME);
775 yinc += GetSystemMetrics(SM_CYFRAME);
777 if (style & WS_BORDER)
779 xinc += GetSystemMetrics(SM_CXBORDER);
780 yinc += GetSystemMetrics(SM_CYBORDER);
783 MinMax.ptMaxSize.x += 2 * xinc;
784 MinMax.ptMaxSize.y += 2 * yinc;
786 lpPos = get_internal_pos( hwnd );
787 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
789 MinMax.ptMaxPosition.x = lpPos->ptMaxPos.x;
790 MinMax.ptMaxPosition.y = lpPos->ptMaxPos.y;
794 MinMax.ptMaxPosition.x = -xinc;
795 MinMax.ptMaxPosition.y = -yinc;
798 SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
800 /* Some sanity checks */
802 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
803 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
804 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
805 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
806 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
807 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
808 MinMax.ptMinTrackSize.x );
809 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
810 MinMax.ptMinTrackSize.y );
812 if (maxSize) *maxSize = MinMax.ptMaxSize;
813 if (maxPos) *maxPos = MinMax.ptMaxPosition;
814 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
815 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
818 /***********************************************************************
819 * ShowWindowAsync (USER32.@)
821 * doesn't wait; returns immediately.
822 * used by threads to toggle windows in other (possibly hanging) threads
824 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
828 if (is_broadcast(hwnd))
830 SetLastError( ERROR_INVALID_PARAMETER );
834 if ((full_handle = WIN_IsCurrentThread( hwnd )))
835 return USER_Driver->pShowWindow( full_handle, cmd );
837 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
841 /***********************************************************************
842 * ShowWindow (USER32.@)
844 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
848 if (is_broadcast(hwnd))
850 SetLastError( ERROR_INVALID_PARAMETER );
853 if ((full_handle = WIN_IsCurrentThread( hwnd )))
854 return USER_Driver->pShowWindow( full_handle, cmd );
856 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
860 /***********************************************************************
861 * GetInternalWindowPos (USER32.@)
863 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
866 WINDOWPLACEMENT wndpl;
867 if (GetWindowPlacement( hwnd, &wndpl ))
869 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
870 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
871 return wndpl.showCmd;
877 /***********************************************************************
878 * GetWindowPlacement (USER32.@)
881 * Fails if wndpl->length of Win95 (!) apps is invalid.
883 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
885 WND *pWnd = WIN_GetPtr( hwnd );
888 if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
889 if (pWnd == WND_OTHER_PROCESS)
891 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
895 lpPos = WINPOS_InitInternalPos( pWnd );
896 wndpl->length = sizeof(*wndpl);
897 if( pWnd->dwStyle & WS_MINIMIZE )
898 wndpl->showCmd = SW_SHOWMINIMIZED;
900 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
901 if( pWnd->flags & WIN_RESTORE_MAX )
902 wndpl->flags = WPF_RESTORETOMAXIMIZED;
905 wndpl->ptMinPosition.x = lpPos->ptIconPos.x;
906 wndpl->ptMinPosition.y = lpPos->ptIconPos.y;
907 wndpl->ptMaxPosition.x = lpPos->ptMaxPos.x;
908 wndpl->ptMaxPosition.y = lpPos->ptMaxPos.y;
909 wndpl->rcNormalPosition.left = lpPos->rectNormal.left;
910 wndpl->rcNormalPosition.top = lpPos->rectNormal.top;
911 wndpl->rcNormalPosition.right = lpPos->rectNormal.right;
912 wndpl->rcNormalPosition.bottom = lpPos->rectNormal.bottom;
913 WIN_ReleasePtr( pWnd );
918 /***********************************************************************
919 * WINPOS_SetPlacement
921 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
925 WND *pWnd = WIN_GetPtr( hwnd );
927 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
928 lpPos = WINPOS_InitInternalPos( pWnd );
930 if( flags & PLACE_MIN )
932 lpPos->ptIconPos.x = wndpl->ptMinPosition.x;
933 lpPos->ptIconPos.y = wndpl->ptMinPosition.y;
935 if( flags & PLACE_MAX )
937 lpPos->ptMaxPos.x = wndpl->ptMaxPosition.x;
938 lpPos->ptMaxPos.y = wndpl->ptMaxPosition.y;
940 if( flags & PLACE_RECT)
942 lpPos->rectNormal.left = wndpl->rcNormalPosition.left;
943 lpPos->rectNormal.top = wndpl->rcNormalPosition.top;
944 lpPos->rectNormal.right = wndpl->rcNormalPosition.right;
945 lpPos->rectNormal.bottom = wndpl->rcNormalPosition.bottom;
948 style = pWnd->dwStyle;
949 WIN_ReleasePtr( pWnd );
951 if( style & WS_MINIMIZE )
953 WINPOS_ShowIconTitle( hwnd, FALSE );
954 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
955 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
956 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
958 else if( style & WS_MAXIMIZE )
960 if( !EMPTYPOINT(lpPos->ptMaxPos) )
961 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
962 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
964 else if( flags & PLACE_RECT )
965 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
966 lpPos->rectNormal.right - lpPos->rectNormal.left,
967 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
968 SWP_NOZORDER | SWP_NOACTIVATE );
970 ShowWindow( hwnd, wndpl->showCmd );
972 if (IsIconic( hwnd ))
974 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
976 /* SDK: ...valid only the next time... */
977 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
979 pWnd = WIN_GetPtr( hwnd );
980 if (pWnd && pWnd != WND_OTHER_PROCESS)
982 pWnd->flags |= WIN_RESTORE_MAX;
983 WIN_ReleasePtr( pWnd );
991 /***********************************************************************
992 * SetWindowPlacement (USER32.@)
995 * Fails if wndpl->length of Win95 (!) apps is invalid.
997 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
999 if (!wpl) return FALSE;
1000 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1004 /***********************************************************************
1005 * AnimateWindow (USER32.@)
1006 * Shows/Hides a window with an animation
1009 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1011 FIXME("partial stub\n");
1013 /* If trying to show/hide and it's already *
1014 * shown/hidden or invalid window, fail with *
1015 * invalid parameter */
1016 if(!IsWindow(hwnd) ||
1017 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1018 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1020 SetLastError(ERROR_INVALID_PARAMETER);
1024 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1029 /***********************************************************************
1030 * SetInternalWindowPos (USER32.@)
1032 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1033 LPRECT rect, LPPOINT pt )
1035 if( IsWindow(hwnd) )
1037 WINDOWPLACEMENT wndpl;
1040 wndpl.length = sizeof(wndpl);
1041 wndpl.showCmd = showCmd;
1042 wndpl.flags = flags = 0;
1047 wndpl.flags |= WPF_SETMINPOSITION;
1048 wndpl.ptMinPosition = *pt;
1052 flags |= PLACE_RECT;
1053 wndpl.rcNormalPosition = *rect;
1055 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1060 /*******************************************************************
1061 * can_activate_window
1063 * Check if we can activate the specified window.
1065 static BOOL can_activate_window( HWND hwnd )
1069 if (!hwnd) return FALSE;
1070 style = GetWindowLongW( hwnd, GWL_STYLE );
1071 if (!(style & WS_VISIBLE)) return FALSE;
1072 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1073 return !(style & WS_DISABLED);
1077 /*******************************************************************
1078 * WINPOS_ActivateOtherWindow
1080 * Activates window other than pWnd.
1082 void WINPOS_ActivateOtherWindow(HWND hwnd)
1086 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1088 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1089 if (can_activate_window( hwndTo )) goto done;
1095 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1096 if (can_activate_window( hwndTo )) break;
1100 fg = GetForegroundWindow();
1101 TRACE("win = %p fg = %p\n", hwndTo, fg);
1102 if (!fg || (hwnd == fg))
1104 if (SetForegroundWindow( hwndTo )) return;
1106 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1110 /***********************************************************************
1111 * WINPOS_HandleWindowPosChanging
1113 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1115 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1117 POINT minTrack, maxTrack;
1118 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1120 if (winpos->flags & SWP_NOSIZE) return 0;
1121 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1123 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1124 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1125 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1126 if (!(style & WS_MINIMIZE))
1128 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1129 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1136 /***********************************************************************
1139 static void dump_winpos_flags(UINT flags)
1142 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1143 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1144 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1145 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1146 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1147 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1148 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1149 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1150 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1151 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1152 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1153 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1154 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1156 #define DUMPED_FLAGS \
1162 SWP_FRAMECHANGED | \
1166 SWP_NOOWNERZORDER | \
1167 SWP_NOSENDCHANGING | \
1171 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1176 /***********************************************************************
1177 * SetWindowPos (USER32.@)
1179 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1180 INT x, INT y, INT cx, INT cy, UINT flags )
1184 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1185 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1186 if(TRACE_ON(win)) dump_winpos_flags(flags);
1188 if (is_broadcast(hwnd))
1190 SetLastError( ERROR_INVALID_PARAMETER );
1194 winpos.hwnd = WIN_GetFullHandle(hwnd);
1195 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1200 winpos.flags = flags;
1201 if (WIN_IsCurrentThread( hwnd ))
1202 return USER_Driver->pSetWindowPos( &winpos );
1204 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1208 /***********************************************************************
1209 * BeginDeferWindowPos (USER32.@)
1211 HDWP WINAPI BeginDeferWindowPos( INT count )
1216 TRACE("%d\n", count);
1220 SetLastError(ERROR_INVALID_PARAMETER);
1223 /* Windows allows zero count, in which case it allocates context for 8 moves */
1224 if (count == 0) count = 8;
1226 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1227 if (!handle) return 0;
1228 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1229 pDWP->actualCount = 0;
1230 pDWP->suggestedCount = count;
1232 pDWP->wMagic = DWP_MAGIC;
1233 pDWP->hwndParent = 0;
1235 TRACE("returning hdwp %p\n", handle);
1240 /***********************************************************************
1241 * DeferWindowPos (USER32.@)
1243 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1244 INT x, INT y, INT cx, INT cy,
1249 HDWP newhdwp = hdwp,retvalue;
1251 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1252 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1254 hwnd = WIN_GetFullHandle( hwnd );
1255 if (hwnd == GetDesktopWindow()) return 0;
1257 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1261 for (i = 0; i < pDWP->actualCount; i++)
1263 if (pDWP->winPos[i].hwnd == hwnd)
1265 /* Merge with the other changes */
1266 if (!(flags & SWP_NOZORDER))
1268 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1270 if (!(flags & SWP_NOMOVE))
1272 pDWP->winPos[i].x = x;
1273 pDWP->winPos[i].y = y;
1275 if (!(flags & SWP_NOSIZE))
1277 pDWP->winPos[i].cx = cx;
1278 pDWP->winPos[i].cy = cy;
1280 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1281 SWP_NOZORDER | SWP_NOREDRAW |
1282 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1284 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1290 if (pDWP->actualCount >= pDWP->suggestedCount)
1292 newhdwp = USER_HEAP_REALLOC( hdwp,
1293 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1299 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1300 pDWP->suggestedCount++;
1302 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1303 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1304 pDWP->winPos[pDWP->actualCount].x = x;
1305 pDWP->winPos[pDWP->actualCount].y = y;
1306 pDWP->winPos[pDWP->actualCount].cx = cx;
1307 pDWP->winPos[pDWP->actualCount].cy = cy;
1308 pDWP->winPos[pDWP->actualCount].flags = flags;
1309 pDWP->actualCount++;
1317 /***********************************************************************
1318 * EndDeferWindowPos (USER32.@)
1320 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1327 TRACE("%p\n", hdwp);
1329 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1330 if (!pDWP) return FALSE;
1331 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1333 if (!(res = USER_Driver->pSetWindowPos( winpos ))) break;
1335 USER_HEAP_FREE( hdwp );
1340 /***********************************************************************
1341 * TileChildWindows (USER.199)
1343 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1345 FIXME("(%04x, %d): stub\n", parent, action);
1348 /***********************************************************************
1349 * CascadeChildWindows (USER.198)
1351 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1353 FIXME("(%04x, %d): stub\n", parent, action);