2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
33 #include "wine/winuser16.h"
34 #include "wine/server.h"
36 #include "user_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 #define HAS_DLGFRAME(style,exStyle) \
44 (((exStyle) & WS_EX_DLGMODALFRAME) || \
45 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
47 #define HAS_THICKFRAME(style) \
48 (((style) & WS_THICKFRAME) && \
49 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
51 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
53 #define PLACE_MIN 0x0001
54 #define PLACE_MAX 0x0002
55 #define PLACE_RECT 0x0004
58 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
76 } INTERNALPOS
, *LPINTERNALPOS
;
78 /* ----- internal variables ----- */
80 static LPCSTR atomInternalPos
;
83 /***********************************************************************
84 * WINPOS_CreateInternalPosAtom
86 BOOL
WINPOS_CreateInternalPosAtom()
89 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
90 return (atomInternalPos
) ? TRUE
: FALSE
;
93 /***********************************************************************
94 * WINPOS_CheckInternalPos
96 * Called when a window is destroyed.
98 void WINPOS_CheckInternalPos( HWND hwnd
)
100 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
104 if( IsWindow(lpPos
->hwndIconTitle
) )
105 DestroyWindow( lpPos
->hwndIconTitle
);
106 HeapFree( GetProcessHeap(), 0, lpPos
);
110 /***********************************************************************
111 * ArrangeIconicWindows (USER32.@)
113 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
117 INT x
, y
, xspacing
, yspacing
;
119 GetClientRect( parent
, &rectParent
);
121 y
= rectParent
.bottom
;
122 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
123 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
125 hwndChild
= GetWindow( parent
, GW_CHILD
);
128 if( IsIconic( hwndChild
) )
130 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
132 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
133 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
134 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
135 if( IsWindow(hwndChild
) )
136 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
138 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
145 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
151 /***********************************************************************
152 * SwitchToThisWindow (USER32.@)
154 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
156 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
160 /***********************************************************************
161 * GetWindowRect (USER32.@)
163 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
165 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
168 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
169 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
170 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
176 /***********************************************************************
177 * GetWindowRgn (USER32.@)
179 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
189 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
191 SetLastError( ERROR_OUTOFMEMORY
);
194 SERVER_START_REQ( get_window_region
)
197 wine_server_set_reply( req
, data
->Buffer
, size
);
198 if (!(status
= wine_server_call( req
)))
200 size_t reply_size
= wine_server_reply_size( reply
);
203 data
->rdh
.dwSize
= sizeof(data
->rdh
);
204 data
->rdh
.iType
= RDH_RECTANGLES
;
205 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
206 data
->rdh
.nRgnSize
= reply_size
;
207 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
210 else size
= reply
->total_size
;
213 HeapFree( GetProcessHeap(), 0, data
);
214 } while (status
== STATUS_BUFFER_OVERFLOW
);
216 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
219 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
220 DeleteObject( win_rgn
);
226 /***********************************************************************
227 * SetWindowRgn (USER32.@)
229 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
231 static const RECT empty_rect
;
239 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
240 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
241 if (!GetRegionData( hrgn
, size
, data
))
243 HeapFree( GetProcessHeap(), 0, data
);
246 SERVER_START_REQ( set_window_region
)
249 if (data
->rdh
.nCount
)
250 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
252 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
253 ret
= !wine_server_call_err( req
);
257 else /* clear existing region */
259 SERVER_START_REQ( set_window_region
)
262 ret
= !wine_server_call_err( req
);
267 if (ret
&& USER_Driver
.pSetWindowRgn
)
268 ret
= USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
270 if (ret
&& bRedraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
275 /***********************************************************************
276 * GetClientRect (USER32.@)
278 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
282 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
284 rect
->right
-= rect
->left
;
285 rect
->bottom
-= rect
->top
;
286 rect
->left
= rect
->top
= 0;
292 /*******************************************************************
293 * ClientToScreen (USER32.@)
295 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
297 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
302 /*******************************************************************
303 * ScreenToClient (USER32.@)
305 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
307 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
312 /***********************************************************************
313 * list_children_from_point
315 * Get the list of children that can contain point from the server.
316 * Point is in screen coordinates.
317 * Returned list must be freed by caller.
319 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
328 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
330 SERVER_START_REQ( get_window_children_from_point
)
335 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
336 if (!wine_server_call( req
)) count
= reply
->count
;
339 if (count
&& count
< size
)
344 HeapFree( GetProcessHeap(), 0, list
);
346 size
= count
+ 1; /* restart with a large enough buffer */
352 /***********************************************************************
353 * WINPOS_WindowFromPoint
355 * Find the window and hittest for a given point.
357 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
362 if (!hwndScope
) hwndScope
= GetDesktopWindow();
364 *hittest
= HTNOWHERE
;
366 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
368 /* now determine the hittest */
370 for (i
= 0; list
[i
]; i
++)
372 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
374 /* If window is minimized or disabled, return at once */
375 if (style
& WS_MINIMIZE
)
377 *hittest
= HTCAPTION
;
380 if (style
& WS_DISABLED
)
385 /* Send WM_NCCHITTEST (if same thread) */
386 if (!WIN_IsCurrentThread( list
[i
] ))
391 res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
392 if (res
!= HTTRANSPARENT
)
394 *hittest
= res
; /* Found the window */
397 /* continue search with next window in z-order */
400 HeapFree( GetProcessHeap(), 0, list
);
401 TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
406 /*******************************************************************
407 * WindowFromPoint (USER32.@)
409 HWND WINAPI
WindowFromPoint( POINT pt
)
412 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
416 /*******************************************************************
417 * ChildWindowFromPoint (USER32.@)
419 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
421 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
424 /*******************************************************************
425 * ChildWindowFromPointEx (USER32.@)
427 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
429 /* pt is in the client coordinates */
435 GetClientRect( hwndParent
, &rect
);
436 if (!PtInRect( &rect
, pt
)) return 0;
437 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
439 for (i
= 0; list
[i
]; i
++)
441 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
442 if (!PtInRect( &rect
, pt
)) continue;
443 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
445 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
446 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
447 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
449 if (uFlags
& CWP_SKIPTRANSPARENT
)
451 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
456 HeapFree( GetProcessHeap(), 0, list
);
457 if (!retvalue
) retvalue
= hwndParent
;
462 /*******************************************************************
463 * WINPOS_GetWinOffset
465 * Calculate the offset between the origin of the two windows. Used
466 * to implement MapWindowPoints.
468 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
472 offset
->x
= offset
->y
= 0;
474 /* Translate source window origin to screen coords */
477 HWND hwnd
= hwndFrom
;
481 if (hwnd
== hwndTo
) return;
482 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
484 ERR( "bad hwndFrom = %p\n", hwnd
);
487 if (wndPtr
== WND_DESKTOP
) break;
488 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
489 offset
->x
+= wndPtr
->rectClient
.left
;
490 offset
->y
+= wndPtr
->rectClient
.top
;
491 hwnd
= wndPtr
->parent
;
492 WIN_ReleasePtr( wndPtr
);
496 /* Translate origin to destination window coords */
503 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
505 ERR( "bad hwndTo = %p\n", hwnd
);
508 if (wndPtr
== WND_DESKTOP
) break;
509 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
510 offset
->x
-= wndPtr
->rectClient
.left
;
511 offset
->y
-= wndPtr
->rectClient
.top
;
512 hwnd
= wndPtr
->parent
;
513 WIN_ReleasePtr( wndPtr
);
518 other_process
: /* one of the parents may belong to another process, do it the hard way */
519 offset
->x
= offset
->y
= 0;
520 SERVER_START_REQ( get_windows_offset
)
522 req
->from
= hwndFrom
;
524 if (!wine_server_call( req
))
526 offset
->x
= reply
->x
;
527 offset
->y
= reply
->y
;
534 /*******************************************************************
535 * MapWindowPoints (USER.258)
537 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
538 LPPOINT16 lppt
, UINT16 count
)
542 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
552 /*******************************************************************
553 * MapWindowPoints (USER32.@)
555 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
559 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
566 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
570 /***********************************************************************
571 * IsIconic (USER32.@)
573 BOOL WINAPI
IsIconic(HWND hWnd
)
575 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
579 /***********************************************************************
580 * IsZoomed (USER32.@)
582 BOOL WINAPI
IsZoomed(HWND hWnd
)
584 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
588 /*******************************************************************
589 * AllowSetForegroundWindow (USER32.@)
591 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
593 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
594 * implemented, then fix this function. */
599 /*******************************************************************
600 * LockSetForegroundWindow (USER32.@)
602 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
604 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
605 * implemented, then fix this function. */
610 /***********************************************************************
611 * BringWindowToTop (USER32.@)
613 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
615 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
619 /***********************************************************************
620 * MoveWindow (USER32.@)
622 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
625 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
626 if (!repaint
) flags
|= SWP_NOREDRAW
;
627 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
628 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
631 /***********************************************************************
632 * WINPOS_InitInternalPos
634 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
)
636 LPINTERNALPOS lpPos
= GetPropA( wnd
->hwndSelf
, atomInternalPos
);
639 /* this happens when the window is minimized/maximized
640 * for the first time (rectWindow is not adjusted yet) */
642 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
643 if( !lpPos
) return NULL
;
645 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
646 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
647 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
648 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
649 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
650 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
651 lpPos
->ptIconPos
.x
= lpPos
->ptIconPos
.y
= -1;
652 lpPos
->ptMaxPos
.x
= lpPos
->ptMaxPos
.y
= -1;
655 if( wnd
->dwStyle
& WS_MINIMIZE
)
657 lpPos
->ptIconPos
.x
= wnd
->rectWindow
.left
;
658 lpPos
->ptIconPos
.y
= wnd
->rectWindow
.top
;
660 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
662 lpPos
->ptMaxPos
.x
= wnd
->rectWindow
.left
;
663 lpPos
->ptMaxPos
.y
= wnd
->rectWindow
.top
;
667 lpPos
->rectNormal
.left
= wnd
->rectWindow
.left
;
668 lpPos
->rectNormal
.top
= wnd
->rectWindow
.top
;
669 lpPos
->rectNormal
.right
= wnd
->rectWindow
.right
;
670 lpPos
->rectNormal
.bottom
= wnd
->rectWindow
.bottom
;
675 /***********************************************************************
676 * WINPOS_RedrawIconTitle
678 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
680 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
683 if( lpPos
->hwndIconTitle
)
685 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
686 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
693 /***********************************************************************
694 * WINPOS_ShowIconTitle
696 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
698 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
700 if (lpPos
&& !GetPropA( hwnd
, "__wine_x11_managed" ))
702 HWND title
= lpPos
->hwndIconTitle
;
704 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
707 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
710 if (!IsWindowVisible(title
))
712 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
713 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
714 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
717 else ShowWindow( title
, SW_HIDE
);
722 /*******************************************************************
723 * WINPOS_GetMinMaxInfo
725 * Get the minimized and maximized information for a window.
727 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
728 POINT
*minTrack
, POINT
*maxTrack
)
733 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
734 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
737 /* Compute default values */
739 GetWindowRect(hwnd
, &rc
);
740 MinMax
.ptReserved
.x
= rc
.left
;
741 MinMax
.ptReserved
.y
= rc
.top
;
743 if (style
& WS_CHILD
)
745 if ((style
& WS_CAPTION
) == WS_CAPTION
)
746 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
748 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
749 AdjustWindowRectEx(&rc
, style
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
751 /* avoid calculating this twice */
752 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
754 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
755 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
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
) + 2*GetSystemMetrics(SM_CXFRAME
);
765 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
) + 2*GetSystemMetrics(SM_CYFRAME
);
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
) )
792 MinMax
.ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
793 MinMax
.ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
797 MinMax
.ptMaxPosition
.x
= -xinc
;
798 MinMax
.ptMaxPosition
.y
= -yinc
;
801 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
803 /* Some sanity checks */
805 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
806 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
807 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
808 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
809 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
810 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
811 MinMax
.ptMinTrackSize
.x
);
812 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
813 MinMax
.ptMinTrackSize
.y
);
815 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
816 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
817 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
818 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
821 /***********************************************************************
822 * ShowWindowAsync (USER32.@)
824 * doesn't wait; returns immediately.
825 * used by threads to toggle windows in other (possibly hanging) threads
827 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
831 if (is_broadcast(hwnd
))
833 SetLastError( ERROR_INVALID_PARAMETER
);
837 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
839 if (USER_Driver
.pShowWindow
)
840 return USER_Driver
.pShowWindow( full_handle
, cmd
);
843 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
847 /***********************************************************************
848 * ShowWindow (USER32.@)
850 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
854 if (is_broadcast(hwnd
))
856 SetLastError( ERROR_INVALID_PARAMETER
);
859 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
861 if (USER_Driver
.pShowWindow
)
862 return USER_Driver
.pShowWindow( full_handle
, cmd
);
865 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
869 /***********************************************************************
870 * GetInternalWindowPos (USER32.@)
872 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
875 WINDOWPLACEMENT wndpl
;
876 if (GetWindowPlacement( hwnd
, &wndpl
))
878 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
879 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
880 return wndpl
.showCmd
;
886 /***********************************************************************
887 * GetWindowPlacement (USER32.@)
890 * Fails if wndpl->length of Win95 (!) apps is invalid.
892 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
894 WND
*pWnd
= WIN_GetPtr( hwnd
);
897 if (!pWnd
|| pWnd
== WND_DESKTOP
) return FALSE
;
898 if (pWnd
== WND_OTHER_PROCESS
)
900 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
904 lpPos
= WINPOS_InitInternalPos( pWnd
);
905 wndpl
->length
= sizeof(*wndpl
);
906 if( pWnd
->dwStyle
& WS_MINIMIZE
)
907 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
909 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
910 if( pWnd
->flags
& WIN_RESTORE_MAX
)
911 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
914 wndpl
->ptMinPosition
.x
= lpPos
->ptIconPos
.x
;
915 wndpl
->ptMinPosition
.y
= lpPos
->ptIconPos
.y
;
916 wndpl
->ptMaxPosition
.x
= lpPos
->ptMaxPos
.x
;
917 wndpl
->ptMaxPosition
.y
= lpPos
->ptMaxPos
.y
;
918 wndpl
->rcNormalPosition
.left
= lpPos
->rectNormal
.left
;
919 wndpl
->rcNormalPosition
.top
= lpPos
->rectNormal
.top
;
920 wndpl
->rcNormalPosition
.right
= lpPos
->rectNormal
.right
;
921 wndpl
->rcNormalPosition
.bottom
= lpPos
->rectNormal
.bottom
;
922 WIN_ReleasePtr( pWnd
);
927 /***********************************************************************
928 * WINPOS_SetPlacement
930 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
934 WND
*pWnd
= WIN_GetPtr( hwnd
);
936 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
937 lpPos
= WINPOS_InitInternalPos( pWnd
);
939 if( flags
& PLACE_MIN
)
941 lpPos
->ptIconPos
.x
= wndpl
->ptMinPosition
.x
;
942 lpPos
->ptIconPos
.y
= wndpl
->ptMinPosition
.y
;
944 if( flags
& PLACE_MAX
)
946 lpPos
->ptMaxPos
.x
= wndpl
->ptMaxPosition
.x
;
947 lpPos
->ptMaxPos
.y
= wndpl
->ptMaxPosition
.y
;
949 if( flags
& PLACE_RECT
)
951 lpPos
->rectNormal
.left
= wndpl
->rcNormalPosition
.left
;
952 lpPos
->rectNormal
.top
= wndpl
->rcNormalPosition
.top
;
953 lpPos
->rectNormal
.right
= wndpl
->rcNormalPosition
.right
;
954 lpPos
->rectNormal
.bottom
= wndpl
->rcNormalPosition
.bottom
;
957 style
= pWnd
->dwStyle
;
958 WIN_ReleasePtr( pWnd
);
960 if( style
& WS_MINIMIZE
)
962 WINPOS_ShowIconTitle( hwnd
, FALSE
);
963 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
964 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
965 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
967 else if( style
& WS_MAXIMIZE
)
969 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
970 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
971 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
973 else if( flags
& PLACE_RECT
)
974 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
975 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
976 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
977 SWP_NOZORDER
| SWP_NOACTIVATE
);
979 ShowWindow( hwnd
, wndpl
->showCmd
);
981 if (IsIconic( hwnd
))
983 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
985 /* SDK: ...valid only the next time... */
986 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
988 pWnd
= WIN_GetPtr( hwnd
);
989 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
991 pWnd
->flags
|= WIN_RESTORE_MAX
;
992 WIN_ReleasePtr( pWnd
);
1000 /***********************************************************************
1001 * SetWindowPlacement (USER32.@)
1004 * Fails if wndpl->length of Win95 (!) apps is invalid.
1006 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1008 if (!wpl
) return FALSE
;
1009 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1013 /***********************************************************************
1014 * AnimateWindow (USER32.@)
1015 * Shows/Hides a window with an animation
1018 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1020 FIXME("partial stub\n");
1022 /* If trying to show/hide and it's already *
1023 * shown/hidden or invalid window, fail with *
1024 * invalid parameter */
1025 if(!IsWindow(hwnd
) ||
1026 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1027 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1029 SetLastError(ERROR_INVALID_PARAMETER
);
1033 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1038 /***********************************************************************
1039 * SetInternalWindowPos (USER32.@)
1041 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1042 LPRECT rect
, LPPOINT pt
)
1044 if( IsWindow(hwnd
) )
1046 WINDOWPLACEMENT wndpl
;
1049 wndpl
.length
= sizeof(wndpl
);
1050 wndpl
.showCmd
= showCmd
;
1051 wndpl
.flags
= flags
= 0;
1056 wndpl
.flags
|= WPF_SETMINPOSITION
;
1057 wndpl
.ptMinPosition
= *pt
;
1061 flags
|= PLACE_RECT
;
1062 wndpl
.rcNormalPosition
= *rect
;
1064 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1069 /*******************************************************************
1070 * can_activate_window
1072 * Check if we can activate the specified window.
1074 static BOOL
can_activate_window( HWND hwnd
)
1078 if (!hwnd
) return FALSE
;
1079 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1080 if (!(style
& WS_VISIBLE
)) return FALSE
;
1081 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1082 return !(style
& WS_DISABLED
);
1086 /*******************************************************************
1087 * WINPOS_ActivateOtherWindow
1089 * Activates window other than pWnd.
1091 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1095 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1097 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1098 if (can_activate_window( hwndTo
)) goto done
;
1104 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1105 if (can_activate_window( hwndTo
)) break;
1109 fg
= GetForegroundWindow();
1110 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1111 if (!fg
|| (hwnd
== fg
))
1113 if (SetForegroundWindow( hwndTo
)) return;
1115 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
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
))
1212 if (USER_Driver
.pSetWindowPos
)
1213 return USER_Driver
.pSetWindowPos( &winpos
);
1216 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1220 /***********************************************************************
1221 * BeginDeferWindowPos (USER32.@)
1223 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1228 TRACE("%d\n", count
);
1232 SetLastError(ERROR_INVALID_PARAMETER
);
1235 /* Windows allows zero count, in which case it allocates context for 8 moves */
1236 if (count
== 0) count
= 8;
1238 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1239 if (!handle
) return 0;
1240 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1241 pDWP
->actualCount
= 0;
1242 pDWP
->suggestedCount
= count
;
1244 pDWP
->wMagic
= DWP_MAGIC
;
1245 pDWP
->hwndParent
= 0;
1247 TRACE("returning hdwp %p\n", handle
);
1252 /***********************************************************************
1253 * DeferWindowPos (USER32.@)
1255 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1256 INT x
, INT y
, INT cx
, INT cy
,
1261 HDWP newhdwp
= hdwp
,retvalue
;
1263 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1264 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
1266 hwnd
= WIN_GetFullHandle( hwnd
);
1267 if (hwnd
== GetDesktopWindow()) return 0;
1269 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1273 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1275 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1277 /* Merge with the other changes */
1278 if (!(flags
& SWP_NOZORDER
))
1280 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1282 if (!(flags
& SWP_NOMOVE
))
1284 pDWP
->winPos
[i
].x
= x
;
1285 pDWP
->winPos
[i
].y
= y
;
1287 if (!(flags
& SWP_NOSIZE
))
1289 pDWP
->winPos
[i
].cx
= cx
;
1290 pDWP
->winPos
[i
].cy
= cy
;
1292 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1293 SWP_NOZORDER
| SWP_NOREDRAW
|
1294 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1296 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1302 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1304 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1305 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1311 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1312 pDWP
->suggestedCount
++;
1314 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1315 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1316 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1317 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1318 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1319 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1320 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1321 pDWP
->actualCount
++;
1329 /***********************************************************************
1330 * EndDeferWindowPos (USER32.@)
1332 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1339 TRACE("%p\n", hdwp
);
1341 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1342 if (!pDWP
) return FALSE
;
1343 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1345 if (!USER_Driver
.pSetWindowPos
|| !(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1347 USER_HEAP_FREE( hdwp
);
1352 /***********************************************************************
1353 * TileChildWindows (USER.199)
1355 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1357 FIXME("(%04x, %d): stub\n", parent
, action
);
1360 /***********************************************************************
1361 * CascadeChildWindows (USER.198)
1363 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1365 FIXME("(%04x, %d): stub\n", parent
, action
);