2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
33 #include "wine/winuser16.h"
34 #include "wine/server.h"
36 #include "user_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
43 #define HAS_DLGFRAME(style,exStyle) \
44 (((exStyle) & WS_EX_DLGMODALFRAME) || \
45 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
47 #define HAS_THICKFRAME(style) \
48 (((style) & WS_THICKFRAME) && \
49 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
51 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
53 #define PLACE_MIN 0x0001
54 #define PLACE_MAX 0x0002
55 #define PLACE_RECT 0x0004
58 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
76 } INTERNALPOS, *LPINTERNALPOS;
78 /* ----- internal functions ----- */
80 static inline INTERNALPOS *get_internal_pos( HWND hwnd )
82 return GetPropA( hwnd, "SysIP" );
85 static inline void set_internal_pos( HWND hwnd, INTERNALPOS *pos )
87 SetPropA( hwnd, "SysIP", pos );
90 /***********************************************************************
91 * WINPOS_CheckInternalPos
93 * Called when a window is destroyed.
95 void WINPOS_CheckInternalPos( HWND hwnd )
97 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
101 if( IsWindow(lpPos->hwndIconTitle) )
102 DestroyWindow( lpPos->hwndIconTitle );
103 HeapFree( GetProcessHeap(), 0, lpPos );
107 /***********************************************************************
108 * ArrangeIconicWindows (USER32.@)
110 UINT WINAPI ArrangeIconicWindows( HWND parent )
114 INT x, y, xspacing, yspacing;
116 GetClientRect( parent, &rectParent );
118 y = rectParent.bottom;
119 xspacing = GetSystemMetrics(SM_CXICONSPACING);
120 yspacing = GetSystemMetrics(SM_CYICONSPACING);
122 hwndChild = GetWindow( parent, GW_CHILD );
125 if( IsIconic( hwndChild ) )
127 WINPOS_ShowIconTitle( hwndChild, FALSE );
129 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
130 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
131 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
132 if( IsWindow(hwndChild) )
133 WINPOS_ShowIconTitle(hwndChild , TRUE );
135 if (x <= rectParent.right - xspacing) x += xspacing;
142 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
148 /***********************************************************************
149 * SwitchToThisWindow (USER32.@)
151 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
153 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
157 /***********************************************************************
158 * GetWindowRect (USER32.@)
160 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
162 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
165 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
166 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
167 hwnd, rect->left, rect->top, rect->right, rect->bottom);
173 /***********************************************************************
174 * GetWindowRgn (USER32.@)
176 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
186 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
188 SetLastError( ERROR_OUTOFMEMORY );
191 SERVER_START_REQ( get_window_region )
194 wine_server_set_reply( req, data->Buffer, size );
195 if (!(status = wine_server_call( req )))
197 size_t reply_size = wine_server_reply_size( reply );
200 data->rdh.dwSize = sizeof(data->rdh);
201 data->rdh.iType = RDH_RECTANGLES;
202 data->rdh.nCount = reply_size / sizeof(RECT);
203 data->rdh.nRgnSize = reply_size;
204 win_rgn = ExtCreateRegion( NULL, size, data );
207 else size = reply->total_size;
210 HeapFree( GetProcessHeap(), 0, data );
211 } while (status == STATUS_BUFFER_OVERFLOW);
213 if (status) SetLastError( RtlNtStatusToDosError(status) );
216 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
217 DeleteObject( win_rgn );
223 /***********************************************************************
224 * SetWindowRgn (USER32.@)
226 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
228 static const RECT empty_rect;
236 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
237 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
238 if (!GetRegionData( hrgn, size, data ))
240 HeapFree( GetProcessHeap(), 0, data );
243 SERVER_START_REQ( set_window_region )
246 if (data->rdh.nCount)
247 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
249 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
250 ret = !wine_server_call_err( req );
254 else /* clear existing region */
256 SERVER_START_REQ( set_window_region )
259 ret = !wine_server_call_err( req );
264 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
266 if (ret && bRedraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
271 /***********************************************************************
272 * GetClientRect (USER32.@)
274 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
278 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
280 rect->right -= rect->left;
281 rect->bottom -= rect->top;
282 rect->left = rect->top = 0;
288 /*******************************************************************
289 * ClientToScreen (USER32.@)
291 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
293 MapWindowPoints( hwnd, 0, lppnt, 1 );
298 /*******************************************************************
299 * ScreenToClient (USER32.@)
301 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
303 MapWindowPoints( 0, hwnd, lppnt, 1 );
308 /***********************************************************************
309 * list_children_from_point
311 * Get the list of children that can contain point from the server.
312 * Point is in screen coordinates.
313 * Returned list must be freed by caller.
315 static HWND *list_children_from_point( HWND hwnd, POINT pt )
324 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
326 SERVER_START_REQ( get_window_children_from_point )
331 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
332 if (!wine_server_call( req )) count = reply->count;
335 if (count && count < size)
340 HeapFree( GetProcessHeap(), 0, list );
342 size = count + 1; /* restart with a large enough buffer */
348 /***********************************************************************
349 * WINPOS_WindowFromPoint
351 * Find the window and hittest for a given point.
353 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
358 if (!hwndScope) hwndScope = GetDesktopWindow();
360 *hittest = HTNOWHERE;
362 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
364 /* now determine the hittest */
366 for (i = 0; list[i]; i++)
368 LONG style = GetWindowLongW( list[i], GWL_STYLE );
370 /* If window is minimized or disabled, return at once */
371 if (style & WS_MINIMIZE)
373 *hittest = HTCAPTION;
376 if (style & WS_DISABLED)
381 /* Send WM_NCCHITTEST (if same thread) */
382 if (!WIN_IsCurrentThread( list[i] ))
387 res = SendMessageA( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
388 if (res != HTTRANSPARENT)
390 *hittest = res; /* Found the window */
393 /* continue search with next window in z-order */
396 HeapFree( GetProcessHeap(), 0, list );
397 TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope, pt.x, pt.y, ret );
402 /*******************************************************************
403 * WindowFromPoint (USER32.@)
405 HWND WINAPI WindowFromPoint( POINT pt )
408 return WINPOS_WindowFromPoint( 0, pt, &hittest );
412 /*******************************************************************
413 * ChildWindowFromPoint (USER32.@)
415 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
417 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
420 /*******************************************************************
421 * ChildWindowFromPointEx (USER32.@)
423 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
425 /* pt is in the client coordinates */
431 GetClientRect( hwndParent, &rect );
432 if (!PtInRect( &rect, pt )) return 0;
433 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
435 for (i = 0; list[i]; i++)
437 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
438 if (!PtInRect( &rect, pt )) continue;
439 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
441 LONG style = GetWindowLongW( list[i], GWL_STYLE );
442 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
443 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
445 if (uFlags & CWP_SKIPTRANSPARENT)
447 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
452 HeapFree( GetProcessHeap(), 0, list );
453 if (!retvalue) retvalue = hwndParent;
458 /*******************************************************************
459 * WINPOS_GetWinOffset
461 * Calculate the offset between the origin of the two windows. Used
462 * to implement MapWindowPoints.
464 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
468 offset->x = offset->y = 0;
470 /* Translate source window origin to screen coords */
473 HWND hwnd = hwndFrom;
477 if (hwnd == hwndTo) return;
478 if (!(wndPtr = WIN_GetPtr( hwnd )))
480 ERR( "bad hwndFrom = %p\n", hwnd );
483 if (wndPtr == WND_DESKTOP) break;
484 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
485 offset->x += wndPtr->rectClient.left;
486 offset->y += wndPtr->rectClient.top;
487 hwnd = wndPtr->parent;
488 WIN_ReleasePtr( wndPtr );
492 /* Translate origin to destination window coords */
499 if (!(wndPtr = WIN_GetPtr( hwnd )))
501 ERR( "bad hwndTo = %p\n", hwnd );
504 if (wndPtr == WND_DESKTOP) break;
505 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
506 offset->x -= wndPtr->rectClient.left;
507 offset->y -= wndPtr->rectClient.top;
508 hwnd = wndPtr->parent;
509 WIN_ReleasePtr( wndPtr );
514 other_process: /* one of the parents may belong to another process, do it the hard way */
515 offset->x = offset->y = 0;
516 SERVER_START_REQ( get_windows_offset )
518 req->from = hwndFrom;
520 if (!wine_server_call( req ))
522 offset->x = reply->x;
523 offset->y = reply->y;
530 /*******************************************************************
531 * MapWindowPoints (USER.258)
533 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
534 LPPOINT16 lppt, UINT16 count )
538 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
548 /*******************************************************************
549 * MapWindowPoints (USER32.@)
551 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
555 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
562 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
566 /***********************************************************************
567 * IsIconic (USER32.@)
569 BOOL WINAPI IsIconic(HWND hWnd)
571 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
575 /***********************************************************************
576 * IsZoomed (USER32.@)
578 BOOL WINAPI IsZoomed(HWND hWnd)
580 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
584 /*******************************************************************
585 * AllowSetForegroundWindow (USER32.@)
587 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
589 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
590 * implemented, then fix this function. */
595 /*******************************************************************
596 * LockSetForegroundWindow (USER32.@)
598 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
600 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
601 * implemented, then fix this function. */
606 /***********************************************************************
607 * BringWindowToTop (USER32.@)
609 BOOL WINAPI BringWindowToTop( HWND hwnd )
611 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
615 /***********************************************************************
616 * MoveWindow (USER32.@)
618 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
621 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
622 if (!repaint) flags |= SWP_NOREDRAW;
623 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
624 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
627 /***********************************************************************
628 * WINPOS_InitInternalPos
630 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd )
632 LPINTERNALPOS lpPos = get_internal_pos( wnd->hwndSelf );
635 /* this happens when the window is minimized/maximized
636 * for the first time (rectWindow is not adjusted yet) */
638 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
639 if( !lpPos ) return NULL;
641 set_internal_pos( wnd->hwndSelf, lpPos );
642 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
643 lpPos->rectNormal.left = wnd->rectWindow.left;
644 lpPos->rectNormal.top = wnd->rectWindow.top;
645 lpPos->rectNormal.right = wnd->rectWindow.right;
646 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
647 lpPos->ptIconPos.x = lpPos->ptIconPos.y = -1;
648 lpPos->ptMaxPos.x = lpPos->ptMaxPos.y = -1;
651 if( wnd->dwStyle & WS_MINIMIZE )
653 lpPos->ptIconPos.x = wnd->rectWindow.left;
654 lpPos->ptIconPos.y = wnd->rectWindow.top;
656 else if( wnd->dwStyle & WS_MAXIMIZE )
658 lpPos->ptMaxPos.x = wnd->rectWindow.left;
659 lpPos->ptMaxPos.y = wnd->rectWindow.top;
663 lpPos->rectNormal.left = wnd->rectWindow.left;
664 lpPos->rectNormal.top = wnd->rectWindow.top;
665 lpPos->rectNormal.right = wnd->rectWindow.right;
666 lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
671 /***********************************************************************
672 * WINPOS_RedrawIconTitle
674 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
676 LPINTERNALPOS lpPos = get_internal_pos( hWnd );
679 if( lpPos->hwndIconTitle )
681 SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
682 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
689 /***********************************************************************
690 * WINPOS_ShowIconTitle
692 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
694 LPINTERNALPOS lpPos = get_internal_pos( hwnd );
696 if (lpPos && !GetPropA( hwnd, "__wine_x11_managed" ))
698 HWND title = lpPos->hwndIconTitle;
700 TRACE("%p %i\n", hwnd, (bShow != 0) );
703 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
706 if (!IsWindowVisible(title))
708 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
709 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
710 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
713 else ShowWindow( title, SW_HIDE );
718 /*******************************************************************
719 * WINPOS_GetMinMaxInfo
721 * Get the minimized and maximized information for a window.
723 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
724 POINT *minTrack, POINT *maxTrack )
729 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
730 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
733 /* Compute default values */
735 GetWindowRect(hwnd, &rc);
736 MinMax.ptReserved.x = rc.left;
737 MinMax.ptReserved.y = rc.top;
739 if (style & WS_CHILD)
741 if ((style & WS_CAPTION) == WS_CAPTION)
742 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
744 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
745 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
747 /* avoid calculating this twice */
748 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
750 MinMax.ptMaxSize.x = rc.right - rc.left;
751 MinMax.ptMaxSize.y = rc.bottom - rc.top;
755 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
756 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
758 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
759 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
760 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN) + 2*GetSystemMetrics(SM_CXFRAME);
761 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN) + 2*GetSystemMetrics(SM_CYFRAME);
763 if (HAS_DLGFRAME( style, exstyle ))
765 xinc = GetSystemMetrics(SM_CXDLGFRAME);
766 yinc = GetSystemMetrics(SM_CYDLGFRAME);
771 if (HAS_THICKFRAME(style))
773 xinc += GetSystemMetrics(SM_CXFRAME);
774 yinc += GetSystemMetrics(SM_CYFRAME);
776 if (style & WS_BORDER)
778 xinc += GetSystemMetrics(SM_CXBORDER);
779 yinc += GetSystemMetrics(SM_CYBORDER);
782 MinMax.ptMaxSize.x += 2 * xinc;
783 MinMax.ptMaxSize.y += 2 * yinc;
785 lpPos = get_internal_pos( hwnd );
786 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
788 MinMax.ptMaxPosition.x = lpPos->ptMaxPos.x;
789 MinMax.ptMaxPosition.y = lpPos->ptMaxPos.y;
793 MinMax.ptMaxPosition.x = -xinc;
794 MinMax.ptMaxPosition.y = -yinc;
797 SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
799 /* Some sanity checks */
801 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
802 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
803 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
804 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
805 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
806 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
807 MinMax.ptMinTrackSize.x );
808 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
809 MinMax.ptMinTrackSize.y );
811 if (maxSize) *maxSize = MinMax.ptMaxSize;
812 if (maxPos) *maxPos = MinMax.ptMaxPosition;
813 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
814 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
817 /***********************************************************************
818 * ShowWindowAsync (USER32.@)
820 * doesn't wait; returns immediately.
821 * used by threads to toggle windows in other (possibly hanging) threads
823 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
827 if (is_broadcast(hwnd))
829 SetLastError( ERROR_INVALID_PARAMETER );
833 if ((full_handle = WIN_IsCurrentThread( hwnd )))
834 return USER_Driver->pShowWindow( full_handle, cmd );
836 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
840 /***********************************************************************
841 * ShowWindow (USER32.@)
843 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
847 if (is_broadcast(hwnd))
849 SetLastError( ERROR_INVALID_PARAMETER );
852 if ((full_handle = WIN_IsCurrentThread( hwnd )))
853 return USER_Driver->pShowWindow( full_handle, cmd );
855 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
859 /***********************************************************************
860 * GetInternalWindowPos (USER32.@)
862 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
865 WINDOWPLACEMENT wndpl;
866 if (GetWindowPlacement( hwnd, &wndpl ))
868 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
869 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
870 return wndpl.showCmd;
876 /***********************************************************************
877 * GetWindowPlacement (USER32.@)
880 * Fails if wndpl->length of Win95 (!) apps is invalid.
882 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
884 WND *pWnd = WIN_GetPtr( hwnd );
887 if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
888 if (pWnd == WND_OTHER_PROCESS)
890 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
894 lpPos = WINPOS_InitInternalPos( pWnd );
895 wndpl->length = sizeof(*wndpl);
896 if( pWnd->dwStyle & WS_MINIMIZE )
897 wndpl->showCmd = SW_SHOWMINIMIZED;
899 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
900 if( pWnd->flags & WIN_RESTORE_MAX )
901 wndpl->flags = WPF_RESTORETOMAXIMIZED;
904 wndpl->ptMinPosition.x = lpPos->ptIconPos.x;
905 wndpl->ptMinPosition.y = lpPos->ptIconPos.y;
906 wndpl->ptMaxPosition.x = lpPos->ptMaxPos.x;
907 wndpl->ptMaxPosition.y = lpPos->ptMaxPos.y;
908 wndpl->rcNormalPosition.left = lpPos->rectNormal.left;
909 wndpl->rcNormalPosition.top = lpPos->rectNormal.top;
910 wndpl->rcNormalPosition.right = lpPos->rectNormal.right;
911 wndpl->rcNormalPosition.bottom = lpPos->rectNormal.bottom;
912 WIN_ReleasePtr( pWnd );
917 /***********************************************************************
918 * WINPOS_SetPlacement
920 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
924 WND *pWnd = WIN_GetPtr( hwnd );
926 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
927 lpPos = WINPOS_InitInternalPos( pWnd );
929 if( flags & PLACE_MIN )
931 lpPos->ptIconPos.x = wndpl->ptMinPosition.x;
932 lpPos->ptIconPos.y = wndpl->ptMinPosition.y;
934 if( flags & PLACE_MAX )
936 lpPos->ptMaxPos.x = wndpl->ptMaxPosition.x;
937 lpPos->ptMaxPos.y = wndpl->ptMaxPosition.y;
939 if( flags & PLACE_RECT)
941 lpPos->rectNormal.left = wndpl->rcNormalPosition.left;
942 lpPos->rectNormal.top = wndpl->rcNormalPosition.top;
943 lpPos->rectNormal.right = wndpl->rcNormalPosition.right;
944 lpPos->rectNormal.bottom = wndpl->rcNormalPosition.bottom;
947 style = pWnd->dwStyle;
948 WIN_ReleasePtr( pWnd );
950 if( style & WS_MINIMIZE )
952 WINPOS_ShowIconTitle( hwnd, FALSE );
953 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
954 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
955 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
957 else if( style & WS_MAXIMIZE )
959 if( !EMPTYPOINT(lpPos->ptMaxPos) )
960 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
961 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
963 else if( flags & PLACE_RECT )
964 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
965 lpPos->rectNormal.right - lpPos->rectNormal.left,
966 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
967 SWP_NOZORDER | SWP_NOACTIVATE );
969 ShowWindow( hwnd, wndpl->showCmd );
971 if (IsIconic( hwnd ))
973 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
975 /* SDK: ...valid only the next time... */
976 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
978 pWnd = WIN_GetPtr( hwnd );
979 if (pWnd && pWnd != WND_OTHER_PROCESS)
981 pWnd->flags |= WIN_RESTORE_MAX;
982 WIN_ReleasePtr( pWnd );
990 /***********************************************************************
991 * SetWindowPlacement (USER32.@)
994 * Fails if wndpl->length of Win95 (!) apps is invalid.
996 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
998 if (!wpl) return FALSE;
999 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1003 /***********************************************************************
1004 * AnimateWindow (USER32.@)
1005 * Shows/Hides a window with an animation
1008 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1010 FIXME("partial stub\n");
1012 /* If trying to show/hide and it's already *
1013 * shown/hidden or invalid window, fail with *
1014 * invalid parameter */
1015 if(!IsWindow(hwnd) ||
1016 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1017 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1019 SetLastError(ERROR_INVALID_PARAMETER);
1023 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1028 /***********************************************************************
1029 * SetInternalWindowPos (USER32.@)
1031 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1032 LPRECT rect, LPPOINT pt )
1034 if( IsWindow(hwnd) )
1036 WINDOWPLACEMENT wndpl;
1039 wndpl.length = sizeof(wndpl);
1040 wndpl.showCmd = showCmd;
1041 wndpl.flags = flags = 0;
1046 wndpl.flags |= WPF_SETMINPOSITION;
1047 wndpl.ptMinPosition = *pt;
1051 flags |= PLACE_RECT;
1052 wndpl.rcNormalPosition = *rect;
1054 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1059 /*******************************************************************
1060 * can_activate_window
1062 * Check if we can activate the specified window.
1064 static BOOL can_activate_window( HWND hwnd )
1068 if (!hwnd) return FALSE;
1069 style = GetWindowLongW( hwnd, GWL_STYLE );
1070 if (!(style & WS_VISIBLE)) return FALSE;
1071 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1072 return !(style & WS_DISABLED);
1076 /*******************************************************************
1077 * WINPOS_ActivateOtherWindow
1079 * Activates window other than pWnd.
1081 void WINPOS_ActivateOtherWindow(HWND hwnd)
1085 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1087 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1088 if (can_activate_window( hwndTo )) goto done;
1094 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1095 if (can_activate_window( hwndTo )) break;
1099 fg = GetForegroundWindow();
1100 TRACE("win = %p fg = %p\n", hwndTo, fg);
1101 if (!fg || (hwnd == fg))
1103 if (SetForegroundWindow( hwndTo )) return;
1105 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1109 /***********************************************************************
1110 * WINPOS_HandleWindowPosChanging
1112 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1114 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1116 POINT minTrack, maxTrack;
1117 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1119 if (winpos->flags & SWP_NOSIZE) return 0;
1120 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1122 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1123 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1124 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1125 if (!(style & WS_MINIMIZE))
1127 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1128 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1135 /***********************************************************************
1138 static void dump_winpos_flags(UINT flags)
1141 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1142 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1143 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1144 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1145 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1146 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1147 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1148 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1149 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1150 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1151 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1152 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1153 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1155 #define DUMPED_FLAGS \
1161 SWP_FRAMECHANGED | \
1165 SWP_NOOWNERZORDER | \
1166 SWP_NOSENDCHANGING | \
1170 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1175 /***********************************************************************
1176 * SetWindowPos (USER32.@)
1178 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1179 INT x, INT y, INT cx, INT cy, UINT flags )
1183 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1184 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1185 if(TRACE_ON(win)) dump_winpos_flags(flags);
1187 if (is_broadcast(hwnd))
1189 SetLastError( ERROR_INVALID_PARAMETER );
1193 winpos.hwnd = WIN_GetFullHandle(hwnd);
1194 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1199 winpos.flags = flags;
1200 if (WIN_IsCurrentThread( hwnd ))
1201 return USER_Driver->pSetWindowPos( &winpos );
1203 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1207 /***********************************************************************
1208 * BeginDeferWindowPos (USER32.@)
1210 HDWP WINAPI BeginDeferWindowPos( INT count )
1215 TRACE("%d\n", count);
1219 SetLastError(ERROR_INVALID_PARAMETER);
1222 /* Windows allows zero count, in which case it allocates context for 8 moves */
1223 if (count == 0) count = 8;
1225 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1226 if (!handle) return 0;
1227 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1228 pDWP->actualCount = 0;
1229 pDWP->suggestedCount = count;
1231 pDWP->wMagic = DWP_MAGIC;
1232 pDWP->hwndParent = 0;
1234 TRACE("returning hdwp %p\n", handle);
1239 /***********************************************************************
1240 * DeferWindowPos (USER32.@)
1242 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1243 INT x, INT y, INT cx, INT cy,
1248 HDWP newhdwp = hdwp,retvalue;
1250 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1251 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1253 hwnd = WIN_GetFullHandle( hwnd );
1254 if (hwnd == GetDesktopWindow()) return 0;
1256 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1260 for (i = 0; i < pDWP->actualCount; i++)
1262 if (pDWP->winPos[i].hwnd == hwnd)
1264 /* Merge with the other changes */
1265 if (!(flags & SWP_NOZORDER))
1267 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1269 if (!(flags & SWP_NOMOVE))
1271 pDWP->winPos[i].x = x;
1272 pDWP->winPos[i].y = y;
1274 if (!(flags & SWP_NOSIZE))
1276 pDWP->winPos[i].cx = cx;
1277 pDWP->winPos[i].cy = cy;
1279 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1280 SWP_NOZORDER | SWP_NOREDRAW |
1281 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1283 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1289 if (pDWP->actualCount >= pDWP->suggestedCount)
1291 newhdwp = USER_HEAP_REALLOC( hdwp,
1292 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1298 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1299 pDWP->suggestedCount++;
1301 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1302 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1303 pDWP->winPos[pDWP->actualCount].x = x;
1304 pDWP->winPos[pDWP->actualCount].y = y;
1305 pDWP->winPos[pDWP->actualCount].cx = cx;
1306 pDWP->winPos[pDWP->actualCount].cy = cy;
1307 pDWP->winPos[pDWP->actualCount].flags = flags;
1308 pDWP->actualCount++;
1316 /***********************************************************************
1317 * EndDeferWindowPos (USER32.@)
1319 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1326 TRACE("%p\n", hdwp);
1328 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1329 if (!pDWP) return FALSE;
1330 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1332 if (!(res = USER_Driver->pSetWindowPos( winpos ))) break;
1334 USER_HEAP_FREE( hdwp );
1339 /***********************************************************************
1340 * TileChildWindows (USER.199)
1342 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1344 FIXME("(%04x, %d): stub\n", parent, action);
1347 /***********************************************************************
1348 * CascadeChildWindows (USER.198)
1350 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1352 FIXME("(%04x, %d): stub\n", parent, action);