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"
32 #include "wine/winuser16.h"
33 #include "wine/server.h"
39 #include "nonclient.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win
);
44 #define HAS_DLGFRAME(style,exStyle) \
45 (((exStyle) & WS_EX_DLGMODALFRAME) || \
46 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
48 #define HAS_THICKFRAME(style) \
49 (((style) & WS_THICKFRAME) && \
50 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
52 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
54 #define PLACE_MIN 0x0001
55 #define PLACE_MAX 0x0002
56 #define PLACE_RECT 0x0004
59 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
71 /* ----- internal variables ----- */
73 static LPCSTR atomInternalPos
;
76 /***********************************************************************
77 * WINPOS_CreateInternalPosAtom
79 BOOL
WINPOS_CreateInternalPosAtom()
82 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
83 return (atomInternalPos
) ? TRUE
: FALSE
;
86 /***********************************************************************
87 * WINPOS_CheckInternalPos
89 * Called when a window is destroyed.
91 void WINPOS_CheckInternalPos( HWND hwnd
)
93 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
97 if( IsWindow(lpPos
->hwndIconTitle
) )
98 DestroyWindow( lpPos
->hwndIconTitle
);
99 HeapFree( GetProcessHeap(), 0, lpPos
);
103 /***********************************************************************
104 * ArrangeIconicWindows (USER32.@)
106 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
110 INT x
, y
, xspacing
, yspacing
;
112 GetClientRect( parent
, &rectParent
);
114 y
= rectParent
.bottom
;
115 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
116 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
118 hwndChild
= GetWindow( parent
, GW_CHILD
);
121 if( IsIconic( hwndChild
) )
123 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
125 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
126 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
127 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
128 if( IsWindow(hwndChild
) )
129 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
131 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
138 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
144 /***********************************************************************
145 * SwitchToThisWindow (USER32.@)
147 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
149 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
153 /***********************************************************************
154 * GetWindowRect (USER32.@)
156 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
158 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
161 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
162 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
163 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
169 /***********************************************************************
170 * GetWindowRgn (USER32.@)
172 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
182 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
184 SetLastError( ERROR_OUTOFMEMORY
);
187 SERVER_START_REQ( get_window_region
)
190 wine_server_set_reply( req
, data
->Buffer
, size
);
191 if (!wine_server_call_err( req
))
193 if (!reply
->total_size
) retry
= FALSE
; /* no region at all */
194 else if (reply
->total_size
<= size
)
196 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
);
206 size
= reply
->total_size
;
212 HeapFree( GetProcessHeap(), 0, data
);
217 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
218 DeleteObject( win_rgn
);
224 /***********************************************************************
225 * SetWindowRgn (USER32.@)
227 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
229 static const RECT empty_rect
;
238 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
239 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
240 if (!GetRegionData( hrgn
, size
, data
))
242 HeapFree( GetProcessHeap(), 0, data
);
245 SERVER_START_REQ( set_window_region
)
248 if (data
->rdh
.nCount
)
249 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
251 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
252 ret
= !wine_server_call_err( req
);
256 else /* clear existing region */
258 SERVER_START_REQ( set_window_region
)
261 ret
= !wine_server_call_err( req
);
266 if (!ret
) return FALSE
;
268 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
270 if (IsWindow( hwnd
))
271 FIXME( "not properly supported on other process window %p\n", hwnd
);
276 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
280 if (wndPtr
->hrgnWnd
== hrgn
)
282 WIN_ReleasePtr( wndPtr
);
287 /* delete previous region */
288 DeleteObject(wndPtr
->hrgnWnd
);
291 wndPtr
->hrgnWnd
= hrgn
;
292 WIN_ReleasePtr( wndPtr
);
294 if (USER_Driver
.pSetWindowRgn
)
295 ret
= USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
297 if (ret
&& bRedraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
302 /***********************************************************************
303 * GetClientRect (USER32.@)
305 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
309 rect
->right
= rect
->bottom
= 0;
310 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
312 rect
->right
-= rect
->left
;
313 rect
->bottom
-= rect
->top
;
315 rect
->left
= rect
->top
= 0;
320 /*******************************************************************
321 * ClientToScreen (USER32.@)
323 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
325 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
330 /*******************************************************************
331 * ScreenToClient (USER32.@)
333 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
335 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
340 /***********************************************************************
341 * list_children_from_point
343 * Get the list of children that can contain point from the server.
344 * Point is in screen coordinates.
345 * Returned list must be freed by caller.
347 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
356 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
358 SERVER_START_REQ( get_window_children_from_point
)
363 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
364 if (!wine_server_call( req
)) count
= reply
->count
;
367 if (count
&& count
< size
)
372 HeapFree( GetProcessHeap(), 0, list
);
374 size
= count
+ 1; /* restart with a large enough buffer */
380 /***********************************************************************
381 * WINPOS_WindowFromPoint
383 * Find the window and hittest for a given point.
385 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
390 if (!hwndScope
) hwndScope
= GetDesktopWindow();
392 *hittest
= HTNOWHERE
;
394 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
396 /* now determine the hittest */
398 for (i
= 0; list
[i
]; i
++)
400 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
402 /* If window is minimized or disabled, return at once */
403 if (style
& WS_MINIMIZE
)
405 *hittest
= HTCAPTION
;
408 if (style
& WS_DISABLED
)
413 /* Send WM_NCCHITTEST (if same thread) */
414 if (!WIN_IsCurrentThread( list
[i
] ))
419 res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
420 if (res
!= HTTRANSPARENT
)
422 *hittest
= res
; /* Found the window */
425 /* continue search with next window in z-order */
428 HeapFree( GetProcessHeap(), 0, list
);
429 TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
434 /*******************************************************************
435 * WindowFromPoint (USER32.@)
437 HWND WINAPI
WindowFromPoint( POINT pt
)
440 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
444 /*******************************************************************
445 * ChildWindowFromPoint (USER32.@)
447 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
449 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
452 /*******************************************************************
453 * ChildWindowFromPointEx (USER32.@)
455 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
457 /* pt is in the client coordinates */
463 GetClientRect( hwndParent
, &rect
);
464 if (!PtInRect( &rect
, pt
)) return 0;
465 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
467 for (i
= 0; list
[i
]; i
++)
469 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
470 if (!PtInRect( &rect
, pt
)) continue;
471 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
473 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
474 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
475 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
477 if (uFlags
& CWP_SKIPTRANSPARENT
)
479 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
484 HeapFree( GetProcessHeap(), 0, list
);
485 if (!retvalue
) retvalue
= hwndParent
;
490 /*******************************************************************
491 * WINPOS_GetWinOffset
493 * Calculate the offset between the origin of the two windows. Used
494 * to implement MapWindowPoints.
496 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
500 offset
->x
= offset
->y
= 0;
502 /* Translate source window origin to screen coords */
505 HWND hwnd
= hwndFrom
;
509 if (hwnd
== hwndTo
) return;
510 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
512 ERR( "bad hwndFrom = %p\n", hwnd
);
515 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
516 offset
->x
+= wndPtr
->rectClient
.left
;
517 offset
->y
+= wndPtr
->rectClient
.top
;
518 hwnd
= wndPtr
->parent
;
519 WIN_ReleasePtr( wndPtr
);
523 /* Translate origin to destination window coords */
530 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
532 ERR( "bad hwndTo = %p\n", hwnd
);
535 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
536 offset
->x
-= wndPtr
->rectClient
.left
;
537 offset
->y
-= wndPtr
->rectClient
.top
;
538 hwnd
= wndPtr
->parent
;
539 WIN_ReleasePtr( wndPtr
);
544 other_process
: /* one of the parents may belong to another process, do it the hard way */
545 offset
->x
= offset
->y
= 0;
546 SERVER_START_REQ( get_windows_offset
)
548 req
->from
= hwndFrom
;
550 if (!wine_server_call( req
))
552 offset
->x
= reply
->x
;
553 offset
->y
= reply
->y
;
560 /*******************************************************************
561 * MapWindowPoints (USER.258)
563 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
564 LPPOINT16 lppt
, UINT16 count
)
568 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
578 /*******************************************************************
579 * MapWindowPoints (USER32.@)
581 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
585 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
592 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
596 /***********************************************************************
597 * IsIconic (USER32.@)
599 BOOL WINAPI
IsIconic(HWND hWnd
)
601 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
605 /***********************************************************************
606 * IsZoomed (USER32.@)
608 BOOL WINAPI
IsZoomed(HWND hWnd
)
610 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
614 /*******************************************************************
615 * AllowSetForegroundWindow (USER32.@)
617 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
619 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
620 * implemented, then fix this function. */
625 /*******************************************************************
626 * LockSetForegroundWindow (USER32.@)
628 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
630 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
631 * implemented, then fix this function. */
636 /***********************************************************************
637 * BringWindowToTop (USER32.@)
639 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
641 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
645 /***********************************************************************
646 * MoveWindow (USER32.@)
648 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
651 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
652 if (!repaint
) flags
|= SWP_NOREDRAW
;
653 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
654 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
657 /***********************************************************************
658 * WINPOS_InitInternalPos
660 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
662 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
666 /* this happens when the window is minimized/maximized
667 * for the first time (rectWindow is not adjusted yet) */
669 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
670 if( !lpPos
) return NULL
;
672 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
673 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
674 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
675 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
678 if( wnd
->dwStyle
& WS_MINIMIZE
)
679 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
680 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
681 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
682 else if( restoreRect
)
683 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
688 /***********************************************************************
689 * WINPOS_RedrawIconTitle
691 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
693 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
696 if( lpPos
->hwndIconTitle
)
698 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
699 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
706 /***********************************************************************
707 * WINPOS_ShowIconTitle
709 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
711 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
713 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
715 HWND title
= lpPos
->hwndIconTitle
;
717 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
720 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
723 if (!IsWindowVisible(title
))
725 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
726 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
727 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
730 else ShowWindow( title
, SW_HIDE
);
735 /*******************************************************************
736 * WINPOS_GetMinMaxInfo
738 * Get the minimized and maximized information for a window.
740 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
741 POINT
*minTrack
, POINT
*maxTrack
)
746 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
747 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
750 /* Compute default values */
752 GetWindowRect(hwnd
, &rc
);
753 MinMax
.ptReserved
.x
= rc
.left
;
754 MinMax
.ptReserved
.y
= rc
.top
;
756 if (style
& WS_CHILD
)
758 if ((style
& WS_CAPTION
) == WS_CAPTION
)
759 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
761 GetClientRect(GetParent(hwnd
), &rc
);
762 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
764 /* avoid calculating this twice */
765 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
767 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
768 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
772 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
773 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
775 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
776 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
777 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
778 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
780 if (HAS_DLGFRAME( style
, exstyle
))
782 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
783 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
788 if (HAS_THICKFRAME(style
))
790 xinc
+= GetSystemMetrics(SM_CXFRAME
);
791 yinc
+= GetSystemMetrics(SM_CYFRAME
);
793 if (style
& WS_BORDER
)
795 xinc
+= GetSystemMetrics(SM_CXBORDER
);
796 yinc
+= GetSystemMetrics(SM_CYBORDER
);
799 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
800 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
802 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
803 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
804 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
807 MinMax
.ptMaxPosition
.x
= -xinc
;
808 MinMax
.ptMaxPosition
.y
= -yinc
;
811 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
813 /* Some sanity checks */
815 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
816 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
817 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
818 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
819 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
820 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
821 MinMax
.ptMinTrackSize
.x
);
822 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
823 MinMax
.ptMinTrackSize
.y
);
825 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
826 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
827 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
828 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
831 /***********************************************************************
832 * ShowWindowAsync (USER32.@)
834 * doesn't wait; returns immediately.
835 * used by threads to toggle windows in other (possibly hanging) threads
837 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
841 if (is_broadcast(hwnd
))
843 SetLastError( ERROR_INVALID_PARAMETER
);
847 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
848 return USER_Driver
.pShowWindow( full_handle
, cmd
);
849 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
853 /***********************************************************************
854 * ShowWindow (USER32.@)
856 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
860 if (is_broadcast(hwnd
))
862 SetLastError( ERROR_INVALID_PARAMETER
);
865 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
867 if (USER_Driver
.pShowWindow
)
868 return USER_Driver
.pShowWindow( full_handle
, cmd
);
871 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
875 /***********************************************************************
876 * GetInternalWindowPos (USER32.@)
878 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
881 WINDOWPLACEMENT wndpl
;
882 if (GetWindowPlacement( hwnd
, &wndpl
))
884 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
885 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
886 return wndpl
.showCmd
;
892 /***********************************************************************
893 * GetWindowPlacement (USER32.@)
896 * Fails if wndpl->length of Win95 (!) apps is invalid.
898 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
900 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
903 if(!pWnd
) return FALSE
;
905 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
906 wndpl
->length
= sizeof(*wndpl
);
907 if( pWnd
->dwStyle
& WS_MINIMIZE
)
908 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
910 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
911 if( pWnd
->flags
& WIN_RESTORE_MAX
)
912 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
915 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
916 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
917 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
918 WIN_ReleaseWndPtr(pWnd
);
923 /***********************************************************************
924 * WINPOS_SetPlacement
926 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
928 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
931 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
932 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
934 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
935 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
936 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
938 if( pWnd
->dwStyle
& WS_MINIMIZE
)
940 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
941 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
942 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
943 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
945 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
947 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
948 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
949 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
951 else if( flags
& PLACE_RECT
)
952 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
953 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
954 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
955 SWP_NOZORDER
| SWP_NOACTIVATE
);
957 ShowWindow( hwnd
, wndpl
->showCmd
);
958 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
960 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
962 /* SDK: ...valid only the next time... */
963 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
965 WIN_ReleaseWndPtr(pWnd
);
972 /***********************************************************************
973 * SetWindowPlacement (USER32.@)
976 * Fails if wndpl->length of Win95 (!) apps is invalid.
978 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
980 if (!wpl
) return FALSE
;
981 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
985 /***********************************************************************
986 * AnimateWindow (USER32.@)
987 * Shows/Hides a window with an animation
990 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
992 FIXME("partial stub\n");
994 /* If trying to show/hide and it's already *
995 * shown/hidden or invalid window, fail with *
996 * invalid parameter */
997 if(!IsWindow(hwnd
) ||
998 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
999 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1001 SetLastError(ERROR_INVALID_PARAMETER
);
1005 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1010 /***********************************************************************
1011 * SetInternalWindowPos (USER32.@)
1013 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1014 LPRECT rect
, LPPOINT pt
)
1016 if( IsWindow(hwnd
) )
1018 WINDOWPLACEMENT wndpl
;
1021 wndpl
.length
= sizeof(wndpl
);
1022 wndpl
.showCmd
= showCmd
;
1023 wndpl
.flags
= flags
= 0;
1028 wndpl
.flags
|= WPF_SETMINPOSITION
;
1029 wndpl
.ptMinPosition
= *pt
;
1033 flags
|= PLACE_RECT
;
1034 wndpl
.rcNormalPosition
= *rect
;
1036 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1041 /*******************************************************************
1042 * can_activate_window
1044 * Check if we can activate the specified window.
1046 static BOOL
can_activate_window( HWND hwnd
)
1050 if (!hwnd
) return FALSE
;
1051 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1052 if (!(style
& WS_VISIBLE
)) return FALSE
;
1053 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1054 return !(style
& WS_DISABLED
);
1058 /*******************************************************************
1059 * WINPOS_ActivateOtherWindow
1061 * Activates window other than pWnd.
1063 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1067 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1069 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1070 if (can_activate_window( hwndTo
)) goto done
;
1076 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1077 if (can_activate_window( hwndTo
)) break;
1081 fg
= GetForegroundWindow();
1082 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1083 if (!fg
|| (hwnd
== fg
))
1085 if (SetForegroundWindow( hwndTo
)) return;
1087 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1091 /***********************************************************************
1092 * WINPOS_HandleWindowPosChanging16
1094 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1096 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1098 POINT minTrack
, maxTrack
;
1099 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1101 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1102 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1104 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1105 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1106 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1107 if (!(style
& WS_MINIMIZE
))
1109 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1110 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1117 /***********************************************************************
1118 * WINPOS_HandleWindowPosChanging
1120 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1122 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1124 POINT minTrack
, maxTrack
;
1125 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1127 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1128 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1130 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1131 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1132 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1133 if (!(style
& WS_MINIMIZE
))
1135 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1136 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1143 /***********************************************************************
1146 static void dump_winpos_flags(UINT flags
)
1149 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1150 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1151 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1152 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1153 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1154 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1155 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1156 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1157 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1158 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1159 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1160 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1161 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1163 #define DUMPED_FLAGS \
1169 SWP_FRAMECHANGED | \
1173 SWP_NOOWNERZORDER | \
1174 SWP_NOSENDCHANGING | \
1178 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1183 /***********************************************************************
1184 * SetWindowPos (USER32.@)
1186 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1187 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1191 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1192 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1193 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1195 if (is_broadcast(hwnd
))
1197 SetLastError( ERROR_INVALID_PARAMETER
);
1201 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1202 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1207 winpos
.flags
= flags
;
1208 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1209 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1213 /***********************************************************************
1214 * BeginDeferWindowPos (USER32.@)
1216 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1221 TRACE("%d\n", count
);
1225 SetLastError(ERROR_INVALID_PARAMETER
);
1228 /* Windows allows zero count, in which case it allocates context for 8 moves */
1229 if (count
== 0) count
= 8;
1231 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1232 if (!handle
) return 0;
1233 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1234 pDWP
->actualCount
= 0;
1235 pDWP
->suggestedCount
= count
;
1237 pDWP
->wMagic
= DWP_MAGIC
;
1238 pDWP
->hwndParent
= 0;
1240 TRACE("returning hdwp %p\n", handle
);
1245 /***********************************************************************
1246 * DeferWindowPos (USER32.@)
1248 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1249 INT x
, INT y
, INT cx
, INT cy
,
1254 HDWP newhdwp
= hdwp
,retvalue
;
1256 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1257 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
1259 hwnd
= WIN_GetFullHandle( hwnd
);
1260 if (hwnd
== GetDesktopWindow()) return 0;
1262 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1266 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1268 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1270 /* Merge with the other changes */
1271 if (!(flags
& SWP_NOZORDER
))
1273 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1275 if (!(flags
& SWP_NOMOVE
))
1277 pDWP
->winPos
[i
].x
= x
;
1278 pDWP
->winPos
[i
].y
= y
;
1280 if (!(flags
& SWP_NOSIZE
))
1282 pDWP
->winPos
[i
].cx
= cx
;
1283 pDWP
->winPos
[i
].cy
= cy
;
1285 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1286 SWP_NOZORDER
| SWP_NOREDRAW
|
1287 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1289 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1295 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1297 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1298 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1304 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1305 pDWP
->suggestedCount
++;
1307 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1308 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1309 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1310 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1311 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1312 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1313 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1314 pDWP
->actualCount
++;
1322 /***********************************************************************
1323 * EndDeferWindowPos (USER32.@)
1325 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1332 TRACE("%p\n", hdwp
);
1334 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1335 if (!pDWP
) return FALSE
;
1336 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1338 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1340 USER_HEAP_FREE( hdwp
);
1345 /***********************************************************************
1346 * TileChildWindows (USER.199)
1348 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1350 FIXME("(%04x, %d): stub\n", parent
, action
);
1353 /***********************************************************************
1354 * CascadeChildWindows (USER.198)
1356 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1358 FIXME("(%04x, %d): stub\n", parent
, action
);