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"
40 #include "nonclient.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(win
);
45 #define HAS_DLGFRAME(style,exStyle) \
46 (((exStyle) & WS_EX_DLGMODALFRAME) || \
47 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
49 #define HAS_THICKFRAME(style) \
50 (((style) & WS_THICKFRAME) && \
51 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
53 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
55 #define PLACE_MIN 0x0001
56 #define PLACE_MAX 0x0002
57 #define PLACE_RECT 0x0004
60 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
72 /* ----- internal variables ----- */
74 static LPCSTR atomInternalPos
;
77 /***********************************************************************
78 * WINPOS_CreateInternalPosAtom
80 BOOL
WINPOS_CreateInternalPosAtom()
83 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
84 return (atomInternalPos
) ? TRUE
: FALSE
;
87 /***********************************************************************
88 * WINPOS_CheckInternalPos
90 * Called when a window is destroyed.
92 void WINPOS_CheckInternalPos( HWND hwnd
)
94 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
98 if( IsWindow(lpPos
->hwndIconTitle
) )
99 DestroyWindow( lpPos
->hwndIconTitle
);
100 HeapFree( GetProcessHeap(), 0, lpPos
);
104 /***********************************************************************
105 * ArrangeIconicWindows (USER32.@)
107 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
111 INT x
, y
, xspacing
, yspacing
;
113 GetClientRect( parent
, &rectParent
);
115 y
= rectParent
.bottom
;
116 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
117 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
119 hwndChild
= GetWindow( parent
, GW_CHILD
);
122 if( IsIconic( hwndChild
) )
124 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
126 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
127 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
128 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
129 if( IsWindow(hwndChild
) )
130 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
132 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
139 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
145 /***********************************************************************
146 * SwitchToThisWindow (USER32.@)
148 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
150 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
154 /***********************************************************************
155 * GetWindowRect (USER32.@)
157 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
159 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
162 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
163 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
164 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
170 /***********************************************************************
171 * GetWindowRgn (USER32.@)
173 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
183 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
185 SetLastError( ERROR_OUTOFMEMORY
);
188 SERVER_START_REQ( get_window_region
)
191 wine_server_set_reply( req
, data
->Buffer
, size
);
192 if (!(status
= wine_server_call( req
)))
194 size_t reply_size
= wine_server_reply_size( reply
);
197 data
->rdh
.dwSize
= sizeof(data
->rdh
);
198 data
->rdh
.iType
= RDH_RECTANGLES
;
199 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
200 data
->rdh
.nRgnSize
= reply_size
;
201 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
204 else size
= reply
->total_size
;
207 HeapFree( GetProcessHeap(), 0, data
);
208 } while (status
== STATUS_BUFFER_OVERFLOW
);
210 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
213 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
214 DeleteObject( win_rgn
);
220 /***********************************************************************
221 * SetWindowRgn (USER32.@)
223 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
225 static const RECT empty_rect
;
233 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
234 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
235 if (!GetRegionData( hrgn
, size
, data
))
237 HeapFree( GetProcessHeap(), 0, data
);
240 SERVER_START_REQ( set_window_region
)
243 if (data
->rdh
.nCount
)
244 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
246 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
247 ret
= !wine_server_call_err( req
);
251 else /* clear existing region */
253 SERVER_START_REQ( set_window_region
)
256 ret
= !wine_server_call_err( req
);
261 if (ret
&& USER_Driver
.pSetWindowRgn
)
262 ret
= USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
264 if (ret
&& bRedraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
269 /***********************************************************************
270 * GetClientRect (USER32.@)
272 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
276 rect
->right
= rect
->bottom
= 0;
277 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
279 rect
->right
-= rect
->left
;
280 rect
->bottom
-= rect
->top
;
282 rect
->left
= rect
->top
= 0;
287 /*******************************************************************
288 * ClientToScreen (USER32.@)
290 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
292 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
297 /*******************************************************************
298 * ScreenToClient (USER32.@)
300 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
302 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
307 /***********************************************************************
308 * list_children_from_point
310 * Get the list of children that can contain point from the server.
311 * Point is in screen coordinates.
312 * Returned list must be freed by caller.
314 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
323 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
325 SERVER_START_REQ( get_window_children_from_point
)
330 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
331 if (!wine_server_call( req
)) count
= reply
->count
;
334 if (count
&& count
< size
)
339 HeapFree( GetProcessHeap(), 0, list
);
341 size
= count
+ 1; /* restart with a large enough buffer */
347 /***********************************************************************
348 * WINPOS_WindowFromPoint
350 * Find the window and hittest for a given point.
352 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
357 if (!hwndScope
) hwndScope
= GetDesktopWindow();
359 *hittest
= HTNOWHERE
;
361 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
363 /* now determine the hittest */
365 for (i
= 0; list
[i
]; i
++)
367 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
369 /* If window is minimized or disabled, return at once */
370 if (style
& WS_MINIMIZE
)
372 *hittest
= HTCAPTION
;
375 if (style
& WS_DISABLED
)
380 /* Send WM_NCCHITTEST (if same thread) */
381 if (!WIN_IsCurrentThread( list
[i
] ))
386 res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
387 if (res
!= HTTRANSPARENT
)
389 *hittest
= res
; /* Found the window */
392 /* continue search with next window in z-order */
395 HeapFree( GetProcessHeap(), 0, list
);
396 TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
401 /*******************************************************************
402 * WindowFromPoint (USER32.@)
404 HWND WINAPI
WindowFromPoint( POINT pt
)
407 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
411 /*******************************************************************
412 * ChildWindowFromPoint (USER32.@)
414 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
416 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
419 /*******************************************************************
420 * ChildWindowFromPointEx (USER32.@)
422 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
424 /* pt is in the client coordinates */
430 GetClientRect( hwndParent
, &rect
);
431 if (!PtInRect( &rect
, pt
)) return 0;
432 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
434 for (i
= 0; list
[i
]; i
++)
436 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
437 if (!PtInRect( &rect
, pt
)) continue;
438 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
440 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
441 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
442 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
444 if (uFlags
& CWP_SKIPTRANSPARENT
)
446 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
451 HeapFree( GetProcessHeap(), 0, list
);
452 if (!retvalue
) retvalue
= hwndParent
;
457 /*******************************************************************
458 * WINPOS_GetWinOffset
460 * Calculate the offset between the origin of the two windows. Used
461 * to implement MapWindowPoints.
463 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
467 offset
->x
= offset
->y
= 0;
469 /* Translate source window origin to screen coords */
472 HWND hwnd
= hwndFrom
;
476 if (hwnd
== hwndTo
) return;
477 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
479 ERR( "bad hwndFrom = %p\n", hwnd
);
482 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
483 offset
->x
+= wndPtr
->rectClient
.left
;
484 offset
->y
+= wndPtr
->rectClient
.top
;
485 hwnd
= wndPtr
->parent
;
486 WIN_ReleasePtr( wndPtr
);
490 /* Translate origin to destination window coords */
497 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
499 ERR( "bad hwndTo = %p\n", hwnd
);
502 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
503 offset
->x
-= wndPtr
->rectClient
.left
;
504 offset
->y
-= wndPtr
->rectClient
.top
;
505 hwnd
= wndPtr
->parent
;
506 WIN_ReleasePtr( wndPtr
);
511 other_process
: /* one of the parents may belong to another process, do it the hard way */
512 offset
->x
= offset
->y
= 0;
513 SERVER_START_REQ( get_windows_offset
)
515 req
->from
= hwndFrom
;
517 if (!wine_server_call( req
))
519 offset
->x
= reply
->x
;
520 offset
->y
= reply
->y
;
527 /*******************************************************************
528 * MapWindowPoints (USER.258)
530 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
531 LPPOINT16 lppt
, UINT16 count
)
535 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
545 /*******************************************************************
546 * MapWindowPoints (USER32.@)
548 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
552 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
559 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
563 /***********************************************************************
564 * IsIconic (USER32.@)
566 BOOL WINAPI
IsIconic(HWND hWnd
)
568 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
572 /***********************************************************************
573 * IsZoomed (USER32.@)
575 BOOL WINAPI
IsZoomed(HWND hWnd
)
577 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
581 /*******************************************************************
582 * AllowSetForegroundWindow (USER32.@)
584 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
586 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
587 * implemented, then fix this function. */
592 /*******************************************************************
593 * LockSetForegroundWindow (USER32.@)
595 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
597 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
598 * implemented, then fix this function. */
603 /***********************************************************************
604 * BringWindowToTop (USER32.@)
606 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
608 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
612 /***********************************************************************
613 * MoveWindow (USER32.@)
615 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
618 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
619 if (!repaint
) flags
|= SWP_NOREDRAW
;
620 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
621 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
624 /***********************************************************************
625 * WINPOS_InitInternalPos
627 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
629 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
633 /* this happens when the window is minimized/maximized
634 * for the first time (rectWindow is not adjusted yet) */
636 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
637 if( !lpPos
) return NULL
;
639 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
640 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
641 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
642 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
643 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
644 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
645 lpPos
->ptIconPos
.x
= lpPos
->ptIconPos
.y
= -1;
646 lpPos
->ptMaxPos
.x
= lpPos
->ptMaxPos
.y
= -1;
649 if( wnd
->dwStyle
& WS_MINIMIZE
)
651 lpPos
->ptIconPos
.x
= pt
.x
;
652 lpPos
->ptIconPos
.y
= pt
.y
;
654 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
656 lpPos
->ptMaxPos
.x
= pt
.x
;
657 lpPos
->ptMaxPos
.y
= pt
.y
;
659 else if( restoreRect
)
661 lpPos
->rectNormal
.left
= restoreRect
->left
;
662 lpPos
->rectNormal
.top
= restoreRect
->top
;
663 lpPos
->rectNormal
.right
= restoreRect
->right
;
664 lpPos
->rectNormal
.bottom
= restoreRect
->bottom
;
669 /***********************************************************************
670 * WINPOS_RedrawIconTitle
672 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
674 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
677 if( lpPos
->hwndIconTitle
)
679 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
680 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
687 /***********************************************************************
688 * WINPOS_ShowIconTitle
690 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
692 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
694 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
696 HWND title
= lpPos
->hwndIconTitle
;
698 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
701 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
704 if (!IsWindowVisible(title
))
706 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
707 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
708 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
711 else ShowWindow( title
, SW_HIDE
);
716 /*******************************************************************
717 * WINPOS_GetMinMaxInfo
719 * Get the minimized and maximized information for a window.
721 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
722 POINT
*minTrack
, POINT
*maxTrack
)
727 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
728 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
731 /* Compute default values */
733 GetWindowRect(hwnd
, &rc
);
734 MinMax
.ptReserved
.x
= rc
.left
;
735 MinMax
.ptReserved
.y
= rc
.top
;
737 if (style
& WS_CHILD
)
739 if ((style
& WS_CAPTION
) == WS_CAPTION
)
740 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
742 GetClientRect(GetParent(hwnd
), &rc
);
743 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
745 /* avoid calculating this twice */
746 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
748 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
749 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
753 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
754 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
756 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
757 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
758 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
759 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
761 if (HAS_DLGFRAME( style
, exstyle
))
763 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
764 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
769 if (HAS_THICKFRAME(style
))
771 xinc
+= GetSystemMetrics(SM_CXFRAME
);
772 yinc
+= GetSystemMetrics(SM_CYFRAME
);
774 if (style
& WS_BORDER
)
776 xinc
+= GetSystemMetrics(SM_CXBORDER
);
777 yinc
+= GetSystemMetrics(SM_CYBORDER
);
780 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
781 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
783 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
784 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
786 MinMax
.ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
787 MinMax
.ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
791 MinMax
.ptMaxPosition
.x
= -xinc
;
792 MinMax
.ptMaxPosition
.y
= -yinc
;
795 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
797 /* Some sanity checks */
799 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
800 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
801 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
802 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
803 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
804 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
805 MinMax
.ptMinTrackSize
.x
);
806 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
807 MinMax
.ptMinTrackSize
.y
);
809 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
810 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
811 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
812 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
815 /***********************************************************************
816 * ShowWindowAsync (USER32.@)
818 * doesn't wait; returns immediately.
819 * used by threads to toggle windows in other (possibly hanging) threads
821 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
825 if (is_broadcast(hwnd
))
827 SetLastError( ERROR_INVALID_PARAMETER
);
831 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
832 return USER_Driver
.pShowWindow( full_handle
, cmd
);
833 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
837 /***********************************************************************
838 * ShowWindow (USER32.@)
840 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
844 if (is_broadcast(hwnd
))
846 SetLastError( ERROR_INVALID_PARAMETER
);
849 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
851 if (USER_Driver
.pShowWindow
)
852 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_FindWndPtr( hwnd
);
887 if(!pWnd
) return FALSE
;
889 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
890 wndpl
->length
= sizeof(*wndpl
);
891 if( pWnd
->dwStyle
& WS_MINIMIZE
)
892 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
894 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
895 if( pWnd
->flags
& WIN_RESTORE_MAX
)
896 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
899 wndpl
->ptMinPosition
.x
= lpPos
->ptIconPos
.x
;
900 wndpl
->ptMinPosition
.y
= lpPos
->ptIconPos
.y
;
901 wndpl
->ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
902 wndpl
->ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
903 wndpl
->rcNormalPosition
.left
= lpPos
->rectNormal
.left
;
904 wndpl
->rcNormalPosition
.top
= lpPos
->rectNormal
.top
;
905 wndpl
->rcNormalPosition
.right
= lpPos
->rectNormal
.right
;
906 wndpl
->rcNormalPosition
.bottom
= lpPos
->rectNormal
.bottom
;
907 WIN_ReleaseWndPtr(pWnd
);
912 /***********************************************************************
913 * WINPOS_SetPlacement
915 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
917 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
920 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
921 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
923 if( flags
& PLACE_MIN
)
925 lpPos
->ptIconPos
.x
= wndpl
->ptMinPosition
.x
;
926 lpPos
->ptIconPos
.y
= wndpl
->ptMinPosition
.y
;
928 if( flags
& PLACE_MAX
)
930 lpPos
->ptMaxPos
.x
= wndpl
->ptMaxPosition
.x
;
931 lpPos
->ptMaxPos
.y
= wndpl
->ptMaxPosition
.y
;
933 if( flags
& PLACE_RECT
)
935 lpPos
->rectNormal
.left
= wndpl
->rcNormalPosition
.left
;
936 lpPos
->rectNormal
.top
= wndpl
->rcNormalPosition
.top
;
937 lpPos
->rectNormal
.right
= wndpl
->rcNormalPosition
.right
;
938 lpPos
->rectNormal
.bottom
= wndpl
->rcNormalPosition
.bottom
;
940 if( pWnd
->dwStyle
& WS_MINIMIZE
)
942 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
943 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
944 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
945 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
947 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
949 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
950 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
951 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
953 else if( flags
& PLACE_RECT
)
954 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
955 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
956 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
957 SWP_NOZORDER
| SWP_NOACTIVATE
);
959 ShowWindow( hwnd
, wndpl
->showCmd
);
960 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
962 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
964 /* SDK: ...valid only the next time... */
965 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
967 WIN_ReleaseWndPtr(pWnd
);
974 /***********************************************************************
975 * SetWindowPlacement (USER32.@)
978 * Fails if wndpl->length of Win95 (!) apps is invalid.
980 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
982 if (!wpl
) return FALSE
;
983 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
987 /***********************************************************************
988 * AnimateWindow (USER32.@)
989 * Shows/Hides a window with an animation
992 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
994 FIXME("partial stub\n");
996 /* If trying to show/hide and it's already *
997 * shown/hidden or invalid window, fail with *
998 * invalid parameter */
999 if(!IsWindow(hwnd
) ||
1000 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1001 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1003 SetLastError(ERROR_INVALID_PARAMETER
);
1007 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1012 /***********************************************************************
1013 * SetInternalWindowPos (USER32.@)
1015 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1016 LPRECT rect
, LPPOINT pt
)
1018 if( IsWindow(hwnd
) )
1020 WINDOWPLACEMENT wndpl
;
1023 wndpl
.length
= sizeof(wndpl
);
1024 wndpl
.showCmd
= showCmd
;
1025 wndpl
.flags
= flags
= 0;
1030 wndpl
.flags
|= WPF_SETMINPOSITION
;
1031 wndpl
.ptMinPosition
= *pt
;
1035 flags
|= PLACE_RECT
;
1036 wndpl
.rcNormalPosition
= *rect
;
1038 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1043 /*******************************************************************
1044 * can_activate_window
1046 * Check if we can activate the specified window.
1048 static BOOL
can_activate_window( HWND hwnd
)
1052 if (!hwnd
) return FALSE
;
1053 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1054 if (!(style
& WS_VISIBLE
)) return FALSE
;
1055 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1056 return !(style
& WS_DISABLED
);
1060 /*******************************************************************
1061 * WINPOS_ActivateOtherWindow
1063 * Activates window other than pWnd.
1065 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1069 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1071 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1072 if (can_activate_window( hwndTo
)) goto done
;
1078 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1079 if (can_activate_window( hwndTo
)) break;
1083 fg
= GetForegroundWindow();
1084 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1085 if (!fg
|| (hwnd
== fg
))
1087 if (SetForegroundWindow( hwndTo
)) return;
1089 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1093 /***********************************************************************
1094 * WINPOS_HandleWindowPosChanging16
1096 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1098 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1100 POINT minTrack
, maxTrack
;
1101 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1103 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1104 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1106 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1107 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1108 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1109 if (!(style
& WS_MINIMIZE
))
1111 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1112 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1119 /***********************************************************************
1120 * WINPOS_HandleWindowPosChanging
1122 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1124 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1126 POINT minTrack
, maxTrack
;
1127 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1129 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1130 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1132 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1133 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1134 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1135 if (!(style
& WS_MINIMIZE
))
1137 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1138 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1145 /***********************************************************************
1148 static void dump_winpos_flags(UINT flags
)
1151 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1152 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1153 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1154 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1155 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1156 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1157 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1158 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1159 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1160 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1161 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1162 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1163 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1165 #define DUMPED_FLAGS \
1171 SWP_FRAMECHANGED | \
1175 SWP_NOOWNERZORDER | \
1176 SWP_NOSENDCHANGING | \
1180 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1185 /***********************************************************************
1186 * SetWindowPos (USER32.@)
1188 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1189 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1193 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1194 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1195 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1197 if (is_broadcast(hwnd
))
1199 SetLastError( ERROR_INVALID_PARAMETER
);
1203 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1204 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1209 winpos
.flags
= flags
;
1210 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1211 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1215 /***********************************************************************
1216 * BeginDeferWindowPos (USER32.@)
1218 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1223 TRACE("%d\n", count
);
1227 SetLastError(ERROR_INVALID_PARAMETER
);
1230 /* Windows allows zero count, in which case it allocates context for 8 moves */
1231 if (count
== 0) count
= 8;
1233 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1234 if (!handle
) return 0;
1235 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1236 pDWP
->actualCount
= 0;
1237 pDWP
->suggestedCount
= count
;
1239 pDWP
->wMagic
= DWP_MAGIC
;
1240 pDWP
->hwndParent
= 0;
1242 TRACE("returning hdwp %p\n", handle
);
1247 /***********************************************************************
1248 * DeferWindowPos (USER32.@)
1250 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1251 INT x
, INT y
, INT cx
, INT cy
,
1256 HDWP newhdwp
= hdwp
,retvalue
;
1258 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1259 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
1261 hwnd
= WIN_GetFullHandle( hwnd
);
1262 if (hwnd
== GetDesktopWindow()) return 0;
1264 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1268 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1270 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1272 /* Merge with the other changes */
1273 if (!(flags
& SWP_NOZORDER
))
1275 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1277 if (!(flags
& SWP_NOMOVE
))
1279 pDWP
->winPos
[i
].x
= x
;
1280 pDWP
->winPos
[i
].y
= y
;
1282 if (!(flags
& SWP_NOSIZE
))
1284 pDWP
->winPos
[i
].cx
= cx
;
1285 pDWP
->winPos
[i
].cy
= cy
;
1287 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1288 SWP_NOZORDER
| SWP_NOREDRAW
|
1289 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1291 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1297 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1299 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1300 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1306 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1307 pDWP
->suggestedCount
++;
1309 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1310 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1311 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1312 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1313 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1314 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1315 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1316 pDWP
->actualCount
++;
1324 /***********************************************************************
1325 * EndDeferWindowPos (USER32.@)
1327 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1334 TRACE("%p\n", hdwp
);
1336 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1337 if (!pDWP
) return FALSE
;
1338 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1340 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1342 USER_HEAP_FREE( hdwp
);
1347 /***********************************************************************
1348 * TileChildWindows (USER.199)
1350 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1352 FIXME("(%04x, %d): stub\n", parent
, action
);
1355 /***********************************************************************
1356 * CascadeChildWindows (USER.198)
1358 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1360 FIXME("(%04x, %d): stub\n", parent
, action
);