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
29 #include "wine/winuser16.h"
30 #include "wine/server.h"
36 #include "nonclient.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 #define HAS_DLGFRAME(style,exStyle) \
42 (((exStyle) & WS_EX_DLGMODALFRAME) || \
43 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
45 #define HAS_THICKFRAME(style) \
46 (((style) & WS_THICKFRAME) && \
47 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
49 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
51 #define PLACE_MIN 0x0001
52 #define PLACE_MAX 0x0002
53 #define PLACE_RECT 0x0004
56 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
68 /* ----- internal variables ----- */
70 static LPCSTR atomInternalPos;
73 /***********************************************************************
74 * WINPOS_CreateInternalPosAtom
76 BOOL WINPOS_CreateInternalPosAtom()
79 atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
80 return (atomInternalPos) ? TRUE : FALSE;
83 /***********************************************************************
84 * WINPOS_CheckInternalPos
86 * Called when a window is destroyed.
88 void WINPOS_CheckInternalPos( HWND hwnd )
90 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
94 if( IsWindow(lpPos->hwndIconTitle) )
95 DestroyWindow( lpPos->hwndIconTitle );
96 HeapFree( GetProcessHeap(), 0, lpPos );
100 /***********************************************************************
101 * ArrangeIconicWindows (USER32.@)
103 UINT WINAPI ArrangeIconicWindows( HWND parent )
107 INT x, y, xspacing, yspacing;
109 GetClientRect( parent, &rectParent );
111 y = rectParent.bottom;
112 xspacing = GetSystemMetrics(SM_CXICONSPACING);
113 yspacing = GetSystemMetrics(SM_CYICONSPACING);
115 hwndChild = GetWindow( parent, GW_CHILD );
118 if( IsIconic( hwndChild ) )
120 WINPOS_ShowIconTitle( hwndChild, FALSE );
122 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
123 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
124 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
125 if( IsWindow(hwndChild) )
126 WINPOS_ShowIconTitle(hwndChild , TRUE );
128 if (x <= rectParent.right - xspacing) x += xspacing;
135 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
141 /***********************************************************************
142 * SwitchToThisWindow (USER32.@)
144 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
146 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
150 /***********************************************************************
151 * GetWindowRect (USER32.@)
153 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
155 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
158 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
159 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
160 hwnd, rect->left, rect->top, rect->right, rect->bottom);
166 /***********************************************************************
167 * GetWindowRgn (USER32.@)
169 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
172 WND *wndPtr = WIN_GetPtr( hwnd );
174 if (wndPtr == WND_OTHER_PROCESS)
176 if (IsWindow( hwnd ))
177 FIXME( "not supported on other process window %p\n", hwnd );
182 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
185 if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
186 WIN_ReleasePtr( wndPtr );
191 /***********************************************************************
192 * SetWindowRgn (USER32.@)
194 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
199 if (hrgn) /* verify that region really exists */
201 if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
204 if (USER_Driver.pSetWindowRgn)
205 return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
207 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
209 if (IsWindow( hwnd ))
210 FIXME( "not supported on other process window %p\n", hwnd );
215 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
219 if (wndPtr->hrgnWnd == hrgn)
221 WIN_ReleasePtr( wndPtr );
227 /* delete previous region */
228 DeleteObject(wndPtr->hrgnWnd);
231 wndPtr->hrgnWnd = hrgn;
232 WIN_ReleasePtr( wndPtr );
234 /* Size the window to the rectangle of the new region (if it isn't NULL) */
235 if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
236 rect.right - rect.left, rect.bottom - rect.top,
237 SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
238 SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
243 /***********************************************************************
244 * GetClientRect (USER32.@)
246 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
250 rect->right = rect->bottom = 0;
251 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
253 rect->right -= rect->left;
254 rect->bottom -= rect->top;
256 rect->left = rect->top = 0;
261 /*******************************************************************
262 * ClientToScreen (USER32.@)
264 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
266 MapWindowPoints( hwnd, 0, lppnt, 1 );
271 /*******************************************************************
272 * ScreenToClient (USER32.@)
274 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
276 MapWindowPoints( 0, hwnd, lppnt, 1 );
281 /***********************************************************************
282 * find_child_from_point
284 * Find the child that contains pt. Helper for WindowFromPoint.
285 * pt is in parent client coordinates.
286 * lparam is the param to pass in the WM_NCHITTEST message.
288 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
292 RECT rectWindow, rectClient;
294 HWND *list = WIN_ListChildren( parent );
298 for (i = 0; list[i]; i++)
300 /* If point is in window, and window is visible, and it */
301 /* is enabled (or it's a top-level window), then explore */
302 /* its children. Otherwise, go to the next window. */
304 style = GetWindowLongW( list[i], GWL_STYLE );
305 if (!(style & WS_VISIBLE)) continue; /* not visible -> skip */
306 if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
307 continue; /* disabled child -> skip */
308 exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
309 if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
310 continue; /* transparent -> skip */
312 if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
313 if (!PtInRect( &rectWindow, pt )) continue; /* not in window -> skip */
315 /* FIXME: check window region for other processes too */
316 if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
318 if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
319 pt.x - rectWindow.left, pt.y - rectWindow.top ))
321 WIN_ReleasePtr( wndPtr );
322 continue; /* point outside window region -> skip */
324 WIN_ReleasePtr( wndPtr );
327 /* If window is minimized or disabled, return at once */
328 if (style & WS_MINIMIZE)
330 *hittest = HTCAPTION;
334 if (style & WS_DISABLED)
341 /* If point is in client area, explore children */
342 if (PtInRect( &rectClient, pt ))
346 new_pt.x = pt.x - rectClient.left;
347 new_pt.y = pt.y - rectClient.top;
348 if ((retvalue = find_child_from_point( list[i], new_pt, hittest, lparam ))) break;
351 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
352 if (!WIN_IsCurrentThread( list[i] ))
358 if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
360 *hittest = res; /* Found the window */
364 /* continue search with next sibling */
366 HeapFree( GetProcessHeap(), 0, list );
371 /***********************************************************************
372 * WINPOS_WindowFromPoint
374 * Find the window and hittest for a given point.
376 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
382 TRACE("scope %p %ld,%ld\n", hwndScope, pt.x, pt.y);
384 if (!hwndScope) hwndScope = GetDesktopWindow();
385 style = GetWindowLongW( hwndScope, GWL_STYLE );
388 if (style & WS_DISABLED) return 0;
390 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
392 if (!(style & WS_MINIMIZE))
395 if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
399 xy.x -= rectClient.left;
400 xy.y -= rectClient.top;
401 if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
403 TRACE( "found child %p\n", ret );
409 /* If nothing found, try the scope window */
410 if (!WIN_IsCurrentThread( hwndScope ))
413 TRACE( "returning %p\n", hwndScope );
416 res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
417 if (res != HTTRANSPARENT)
419 *hittest = res; /* Found the window */
420 TRACE( "returning %p\n", hwndScope );
423 *hittest = HTNOWHERE;
424 TRACE( "nothing found\n" );
429 /*******************************************************************
430 * WindowFromPoint (USER32.@)
432 HWND WINAPI WindowFromPoint( POINT pt )
435 return WINPOS_WindowFromPoint( 0, pt, &hittest );
439 /*******************************************************************
440 * ChildWindowFromPoint (USER32.@)
442 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
444 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
447 /*******************************************************************
448 * ChildWindowFromPointEx (USER32.@)
450 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
452 /* pt is in the client coordinates */
458 GetClientRect( hwndParent, &rect );
459 if (!PtInRect( &rect, pt )) return 0;
460 if (!(list = WIN_ListChildren( hwndParent ))) return 0;
462 for (i = 0; list[i]; i++)
464 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
465 if (!PtInRect( &rect, pt )) continue;
466 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
468 LONG style = GetWindowLongW( list[i], GWL_STYLE );
469 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
470 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
472 if (uFlags & CWP_SKIPTRANSPARENT)
474 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
479 HeapFree( GetProcessHeap(), 0, list );
480 if (!retvalue) retvalue = hwndParent;
485 /*******************************************************************
486 * WINPOS_GetWinOffset
488 * Calculate the offset between the origin of the two windows. Used
489 * to implement MapWindowPoints.
491 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
495 offset->x = offset->y = 0;
497 /* Translate source window origin to screen coords */
500 HWND hwnd = hwndFrom;
504 if (hwnd == hwndTo) return;
505 if (!(wndPtr = WIN_GetPtr( hwnd )))
507 ERR( "bad hwndFrom = %p\n", hwnd );
510 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
511 offset->x += wndPtr->rectClient.left;
512 offset->y += wndPtr->rectClient.top;
513 hwnd = wndPtr->parent;
514 WIN_ReleasePtr( wndPtr );
518 /* Translate origin to destination window coords */
525 if (!(wndPtr = WIN_GetPtr( hwnd )))
527 ERR( "bad hwndTo = %p\n", hwnd );
530 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
531 offset->x -= wndPtr->rectClient.left;
532 offset->y -= wndPtr->rectClient.top;
533 hwnd = wndPtr->parent;
534 WIN_ReleasePtr( wndPtr );
539 other_process: /* one of the parents may belong to another process, do it the hard way */
540 offset->x = offset->y = 0;
541 SERVER_START_REQ( get_windows_offset )
543 req->from = hwndFrom;
545 if (!wine_server_call( req ))
547 offset->x = reply->x;
548 offset->y = reply->y;
555 /*******************************************************************
556 * MapWindowPoints (USER.258)
558 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
559 LPPOINT16 lppt, UINT16 count )
563 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
573 /*******************************************************************
574 * MapWindowPoints (USER32.@)
576 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
580 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
587 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
591 /***********************************************************************
592 * IsIconic (USER32.@)
594 BOOL WINAPI IsIconic(HWND hWnd)
596 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
600 /***********************************************************************
601 * IsZoomed (USER32.@)
603 BOOL WINAPI IsZoomed(HWND hWnd)
605 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
609 /*******************************************************************
610 * AllowSetForegroundWindow (USER32.@)
612 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
614 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
615 * implemented, then fix this function. */
620 /*******************************************************************
621 * LockSetForegroundWindow (USER32.@)
623 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
625 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
626 * implemented, then fix this function. */
631 /***********************************************************************
632 * BringWindowToTop (USER32.@)
634 BOOL WINAPI BringWindowToTop( HWND hwnd )
636 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
640 /***********************************************************************
641 * MoveWindow (USER32.@)
643 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
646 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
647 if (!repaint) flags |= SWP_NOREDRAW;
648 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
649 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
652 /***********************************************************************
653 * WINPOS_InitInternalPos
655 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
657 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
661 /* this happens when the window is minimized/maximized
662 * for the first time (rectWindow is not adjusted yet) */
664 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
665 if( !lpPos ) return NULL;
667 SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
668 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
669 CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
670 *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
673 if( wnd->dwStyle & WS_MINIMIZE )
674 CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
675 else if( wnd->dwStyle & WS_MAXIMIZE )
676 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
677 else if( restoreRect )
678 CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
683 /***********************************************************************
684 * WINPOS_RedrawIconTitle
686 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
688 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
691 if( lpPos->hwndIconTitle )
693 SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
694 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
701 /***********************************************************************
702 * WINPOS_ShowIconTitle
704 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
706 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
708 if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_MANAGED))
710 HWND title = lpPos->hwndIconTitle;
712 TRACE("%p %i\n", hwnd, (bShow != 0) );
715 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
718 if (!IsWindowVisible(title))
720 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
721 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
722 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
725 else ShowWindow( title, SW_HIDE );
730 /*******************************************************************
731 * WINPOS_GetMinMaxInfo
733 * Get the minimized and maximized information for a window.
735 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
736 POINT *minTrack, POINT *maxTrack )
741 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
742 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
745 /* Compute default values */
747 GetWindowRect(hwnd, &rc);
748 MinMax.ptReserved.x = rc.left;
749 MinMax.ptReserved.y = rc.top;
751 if (style & WS_CHILD)
753 GetClientRect(GetParent(hwnd), &rc);
754 MinMax.ptMaxSize.x = rc.right;
755 MinMax.ptMaxSize.y = rc.bottom;
759 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
760 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
762 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
763 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
764 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
765 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
767 if (HAS_DLGFRAME( style, exstyle ))
769 xinc = GetSystemMetrics(SM_CXDLGFRAME);
770 yinc = GetSystemMetrics(SM_CYDLGFRAME);
775 if (HAS_THICKFRAME(style))
777 xinc += GetSystemMetrics(SM_CXFRAME);
778 yinc += GetSystemMetrics(SM_CYFRAME);
780 if (style & WS_BORDER)
782 xinc += GetSystemMetrics(SM_CXBORDER);
783 yinc += GetSystemMetrics(SM_CYBORDER);
786 MinMax.ptMaxSize.x += 2 * xinc;
787 MinMax.ptMaxSize.y += 2 * yinc;
789 lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
790 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
791 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
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 );
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 )))
854 if (USER_Driver.pShowWindow)
855 return USER_Driver.pShowWindow( full_handle, cmd );
858 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
862 /***********************************************************************
863 * GetInternalWindowPos (USER32.@)
865 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
868 WINDOWPLACEMENT wndpl;
869 if (GetWindowPlacement( hwnd, &wndpl ))
871 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
872 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
873 return wndpl.showCmd;
879 /***********************************************************************
880 * GetWindowPlacement (USER32.@)
883 * Fails if wndpl->length of Win95 (!) apps is invalid.
885 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
887 WND *pWnd = WIN_FindWndPtr( hwnd );
890 if(!pWnd ) return FALSE;
892 lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
893 wndpl->length = sizeof(*wndpl);
894 if( pWnd->dwStyle & WS_MINIMIZE )
895 wndpl->showCmd = SW_SHOWMINIMIZED;
897 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
898 if( pWnd->flags & WIN_RESTORE_MAX )
899 wndpl->flags = WPF_RESTORETOMAXIMIZED;
902 CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
903 CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
904 CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
905 WIN_ReleaseWndPtr(pWnd);
910 /***********************************************************************
911 * WINPOS_SetPlacement
913 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
915 WND *pWnd = WIN_FindWndPtr( hwnd );
918 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
919 *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
921 if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
922 if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
923 if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
925 if( pWnd->dwStyle & WS_MINIMIZE )
927 WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
928 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
929 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
930 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
932 else if( pWnd->dwStyle & WS_MAXIMIZE )
934 if( !EMPTYPOINT(lpPos->ptMaxPos) )
935 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
936 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
938 else if( flags & PLACE_RECT )
939 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
940 lpPos->rectNormal.right - lpPos->rectNormal.left,
941 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
942 SWP_NOZORDER | SWP_NOACTIVATE );
944 ShowWindow( hwnd, wndpl->showCmd );
945 if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
947 if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
949 /* SDK: ...valid only the next time... */
950 if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
952 WIN_ReleaseWndPtr(pWnd);
959 /***********************************************************************
960 * SetWindowPlacement (USER32.@)
963 * Fails if wndpl->length of Win95 (!) apps is invalid.
965 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
967 if (!wpl) return FALSE;
968 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
972 /***********************************************************************
973 * AnimateWindow (USER32.@)
974 * Shows/Hides a window with an animation
977 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
979 FIXME("partial stub\n");
981 /* If trying to show/hide and it's already *
982 * shown/hidden or invalid window, fail with *
983 * invalid parameter */
984 if(!IsWindow(hwnd) ||
985 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
986 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
988 SetLastError(ERROR_INVALID_PARAMETER);
992 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
997 /***********************************************************************
998 * SetInternalWindowPos (USER32.@)
1000 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1001 LPRECT rect, LPPOINT pt )
1003 if( IsWindow(hwnd) )
1005 WINDOWPLACEMENT wndpl;
1008 wndpl.length = sizeof(wndpl);
1009 wndpl.showCmd = showCmd;
1010 wndpl.flags = flags = 0;
1015 wndpl.flags |= WPF_SETMINPOSITION;
1016 wndpl.ptMinPosition = *pt;
1020 flags |= PLACE_RECT;
1021 wndpl.rcNormalPosition = *rect;
1023 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1028 /*******************************************************************
1029 * can_activate_window
1031 * Check if we can activate the specified window.
1033 static BOOL can_activate_window( HWND hwnd )
1037 if (!hwnd) return FALSE;
1038 style = GetWindowLongW( hwnd, GWL_STYLE );
1039 if (!(style & WS_VISIBLE)) return FALSE;
1040 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1041 return !(style & WS_DISABLED);
1045 /*******************************************************************
1046 * WINPOS_ActivateOtherWindow
1048 * Activates window other than pWnd.
1050 void WINPOS_ActivateOtherWindow(HWND hwnd)
1054 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1056 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1057 if (can_activate_window( hwndTo )) goto done;
1063 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1064 if (can_activate_window( hwndTo )) break;
1068 fg = GetForegroundWindow();
1069 TRACE("win = %p fg = %p\n", hwndTo, fg);
1070 if (!fg || (hwnd == fg))
1072 if (SetForegroundWindow( hwndTo )) return;
1074 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1078 /***********************************************************************
1079 * WINPOS_HandleWindowPosChanging16
1081 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1083 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1085 POINT maxSize, minTrack;
1086 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1088 if (winpos->flags & SWP_NOSIZE) return 0;
1089 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1091 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1092 if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1093 if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1094 if (!(style & WS_MINIMIZE))
1096 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1097 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1104 /***********************************************************************
1105 * WINPOS_HandleWindowPosChanging
1107 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1109 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1111 POINT maxSize, minTrack;
1112 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1114 if (winpos->flags & SWP_NOSIZE) return 0;
1115 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1117 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1118 winpos->cx = min( winpos->cx, maxSize.x );
1119 winpos->cy = min( winpos->cy, maxSize.y );
1120 if (!(style & WS_MINIMIZE))
1122 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1123 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1130 /***********************************************************************
1133 static void dump_winpos_flags(UINT flags)
1136 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1137 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1138 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1139 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1140 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1141 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1142 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1143 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1144 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1145 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1146 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1147 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1148 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1150 #define DUMPED_FLAGS \
1156 SWP_FRAMECHANGED | \
1160 SWP_NOOWNERZORDER | \
1161 SWP_NOSENDCHANGING | \
1165 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1170 /***********************************************************************
1171 * SetWindowPos (USER32.@)
1173 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1174 INT x, INT y, INT cx, INT cy, UINT flags )
1178 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1179 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1180 if(TRACE_ON(win)) dump_winpos_flags(flags);
1182 if (is_broadcast(hwnd))
1184 SetLastError( ERROR_INVALID_PARAMETER );
1188 winpos.hwnd = WIN_GetFullHandle(hwnd);
1189 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1194 winpos.flags = flags;
1195 if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1196 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1200 /***********************************************************************
1201 * BeginDeferWindowPos (USER32.@)
1203 HDWP WINAPI BeginDeferWindowPos( INT count )
1208 TRACE("%d\n", count);
1212 SetLastError(ERROR_INVALID_PARAMETER);
1215 /* Windows allows zero count, in which case it allocates context for 8 moves */
1216 if (count == 0) count = 8;
1218 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1219 if (!handle) return 0;
1220 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1221 pDWP->actualCount = 0;
1222 pDWP->suggestedCount = count;
1224 pDWP->wMagic = DWP_MAGIC;
1225 pDWP->hwndParent = 0;
1227 TRACE("returning hdwp %p\n", handle);
1232 /***********************************************************************
1233 * DeferWindowPos (USER32.@)
1235 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1236 INT x, INT y, INT cx, INT cy,
1241 HDWP newhdwp = hdwp,retvalue;
1243 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1244 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1246 hwnd = WIN_GetFullHandle( hwnd );
1247 if (hwnd == GetDesktopWindow()) return 0;
1249 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1253 for (i = 0; i < pDWP->actualCount; i++)
1255 if (pDWP->winPos[i].hwnd == hwnd)
1257 /* Merge with the other changes */
1258 if (!(flags & SWP_NOZORDER))
1260 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1262 if (!(flags & SWP_NOMOVE))
1264 pDWP->winPos[i].x = x;
1265 pDWP->winPos[i].y = y;
1267 if (!(flags & SWP_NOSIZE))
1269 pDWP->winPos[i].cx = cx;
1270 pDWP->winPos[i].cy = cy;
1272 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1273 SWP_NOZORDER | SWP_NOREDRAW |
1274 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1276 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1282 if (pDWP->actualCount >= pDWP->suggestedCount)
1284 newhdwp = USER_HEAP_REALLOC( hdwp,
1285 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1291 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1292 pDWP->suggestedCount++;
1294 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1295 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1296 pDWP->winPos[pDWP->actualCount].x = x;
1297 pDWP->winPos[pDWP->actualCount].y = y;
1298 pDWP->winPos[pDWP->actualCount].cx = cx;
1299 pDWP->winPos[pDWP->actualCount].cy = cy;
1300 pDWP->winPos[pDWP->actualCount].flags = flags;
1301 pDWP->actualCount++;
1309 /***********************************************************************
1310 * EndDeferWindowPos (USER32.@)
1312 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1319 TRACE("%p\n", hdwp);
1321 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1322 if (!pDWP) return FALSE;
1323 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1325 if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1327 USER_HEAP_FREE( hdwp );
1332 /***********************************************************************
1333 * TileChildWindows (USER.199)
1335 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1337 FIXME("(%04x, %d): stub\n", parent, action);
1340 /***********************************************************************
1341 * CascadeChildWindows (USER.198)
1343 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1345 FIXME("(%04x, %d): stub\n", parent, action);