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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
28 #define WIN32_NO_STATUS
33 #include "wine/server.h"
35 #include "user_private.h"
36 #include "wine/gdi_driver.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win
);
42 #define SWP_AGG_NOGEOMETRYCHANGE \
43 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
44 #define SWP_AGG_NOPOSCHANGE \
45 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
46 #define SWP_AGG_STATUSFLAGS \
47 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define SWP_AGG_NOCLIENTCHANGE \
49 (SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
51 #define HAS_DLGFRAME(style,exStyle) \
52 (((exStyle) & WS_EX_DLGMODALFRAME) || \
53 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
55 #define HAS_THICKFRAME(style) \
56 (((style) & WS_THICKFRAME) && \
57 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
59 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
61 #define ON_LEFT_BORDER(hit) \
62 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
63 #define ON_RIGHT_BORDER(hit) \
64 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
65 #define ON_TOP_BORDER(hit) \
66 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
67 #define ON_BOTTOM_BORDER(hit) \
68 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
70 #define PLACE_MIN 0x0001
71 #define PLACE_MAX 0x0002
72 #define PLACE_RECT 0x0004
76 struct user_object obj
;
84 /***********************************************************************
85 * SwitchToThisWindow (USER32.@)
87 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL alt_tab
)
89 if (IsIconic( hwnd
)) ShowWindow( hwnd
, SW_RESTORE
);
90 else BringWindowToTop( hwnd
);
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
99 BOOL ret
= WIN_GetRectangles( hwnd
, COORDS_SCREEN
, rect
, NULL
);
100 if (ret
) TRACE( "hwnd %p %s\n", hwnd
, wine_dbgstr_rect(rect
) );
105 /***********************************************************************
106 * GetWindowRgn (USER32.@)
108 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
118 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
120 SetLastError( ERROR_OUTOFMEMORY
);
123 SERVER_START_REQ( get_window_region
)
125 req
->window
= wine_server_user_handle( hwnd
);
126 wine_server_set_reply( req
, data
->Buffer
, size
);
127 if (!(status
= wine_server_call( req
)))
129 size_t reply_size
= wine_server_reply_size( reply
);
132 data
->rdh
.dwSize
= sizeof(data
->rdh
);
133 data
->rdh
.iType
= RDH_RECTANGLES
;
134 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
135 data
->rdh
.nRgnSize
= reply_size
;
136 win_rgn
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
);
139 else size
= reply
->total_size
;
142 HeapFree( GetProcessHeap(), 0, data
);
143 } while (status
== STATUS_BUFFER_OVERFLOW
);
145 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
148 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
149 DeleteObject( win_rgn
);
154 /***********************************************************************
155 * GetWindowRgnBox (USER32.@)
157 int WINAPI
GetWindowRgnBox( HWND hwnd
, LPRECT prect
)
165 if ((hrgn
= CreateRectRgn(0, 0, 0, 0)))
167 if ((ret
= GetWindowRgn( hwnd
, hrgn
)) != ERROR
)
168 ret
= GetRgnBox( hrgn
, prect
);
175 /***********************************************************************
176 * SetWindowRgn (USER32.@)
178 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
180 static const RECT empty_rect
;
188 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
189 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
190 if (!GetRegionData( hrgn
, size
, data
))
192 HeapFree( GetProcessHeap(), 0, data
);
195 SERVER_START_REQ( set_window_region
)
197 req
->window
= wine_server_user_handle( hwnd
);
198 req
->redraw
= (bRedraw
!= 0);
199 if (data
->rdh
.nCount
)
200 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
202 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
203 ret
= !wine_server_call_err( req
);
206 HeapFree( GetProcessHeap(), 0, data
);
208 else /* clear existing region */
210 SERVER_START_REQ( set_window_region
)
212 req
->window
= wine_server_user_handle( hwnd
);
213 req
->redraw
= (bRedraw
!= 0);
214 ret
= !wine_server_call_err( req
);
221 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
222 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
223 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
224 USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
225 if (hrgn
) DeleteObject( hrgn
);
231 /***********************************************************************
232 * GetClientRect (USER32.@)
234 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
236 return WIN_GetRectangles( hwnd
, COORDS_CLIENT
, NULL
, rect
);
240 /***********************************************************************
241 * list_children_from_point
243 * Get the list of children that can contain point from the server.
244 * Point is in screen coordinates.
245 * Returned list must be freed by caller.
247 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
256 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
258 SERVER_START_REQ( get_window_children_from_point
)
260 req
->parent
= wine_server_user_handle( hwnd
);
263 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
264 if (!wine_server_call( req
)) count
= reply
->count
;
267 if (count
&& count
< size
)
269 /* start from the end since HWND is potentially larger than user_handle_t */
270 for (i
= count
- 1; i
>= 0; i
--)
271 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
275 HeapFree( GetProcessHeap(), 0, list
);
277 size
= count
+ 1; /* restart with a large enough buffer */
283 /***********************************************************************
284 * WINPOS_WindowFromPoint
286 * Find the window and hittest for a given point.
288 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
293 if (!hwndScope
) hwndScope
= GetDesktopWindow();
295 *hittest
= HTNOWHERE
;
297 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
299 /* now determine the hittest */
301 for (i
= 0; list
[i
]; i
++)
303 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
305 /* If window is minimized or disabled, return at once */
306 if (style
& WS_MINIMIZE
)
308 *hittest
= HTCAPTION
;
311 if (style
& WS_DISABLED
)
316 /* Send WM_NCCHITTEST (if same thread) */
317 if (!WIN_IsCurrentThread( list
[i
] ))
322 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
323 if (res
!= HTTRANSPARENT
)
325 *hittest
= res
; /* Found the window */
328 /* continue search with next window in z-order */
331 HeapFree( GetProcessHeap(), 0, list
);
332 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
337 /*******************************************************************
338 * WindowFromPoint (USER32.@)
340 HWND WINAPI
WindowFromPoint( POINT pt
)
343 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
347 /*******************************************************************
348 * ChildWindowFromPoint (USER32.@)
350 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
352 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
355 /*******************************************************************
356 * RealChildWindowFromPoint (USER32.@)
358 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
360 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
| CWP_SKIPINVISIBLE
);
363 /*******************************************************************
364 * ChildWindowFromPointEx (USER32.@)
366 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
368 /* pt is in the client coordinates */
374 GetClientRect( hwndParent
, &rect
);
375 if (!PtInRect( &rect
, pt
)) return 0;
376 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
378 for (i
= 0; list
[i
]; i
++)
380 if (!WIN_GetRectangles( list
[i
], COORDS_PARENT
, &rect
, NULL
)) continue;
381 if (!PtInRect( &rect
, pt
)) continue;
382 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
384 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
385 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
386 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
388 if (uFlags
& CWP_SKIPTRANSPARENT
)
390 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
395 HeapFree( GetProcessHeap(), 0, list
);
396 if (!retvalue
) retvalue
= hwndParent
;
401 /*******************************************************************
402 * WINPOS_GetWinOffset
404 * Calculate the offset between the origin of the two windows. Used
405 * to implement MapWindowPoints.
407 static BOOL
WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, BOOL
*mirrored
, POINT
*ret_offset
)
411 BOOL mirror_from
, mirror_to
, ret
;
414 offset
.x
= offset
.y
= 0;
415 *mirrored
= mirror_from
= mirror_to
= FALSE
;
417 /* Translate source window origin to screen coords */
420 if (!(wndPtr
= WIN_GetPtr( hwndFrom
)))
422 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
425 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
426 if (wndPtr
!= WND_DESKTOP
)
428 if (wndPtr
->dwExStyle
& WS_EX_LAYOUTRTL
)
431 offset
.x
+= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
433 while (wndPtr
->parent
)
435 offset
.x
+= wndPtr
->rectClient
.left
;
436 offset
.y
+= wndPtr
->rectClient
.top
;
437 hwnd
= wndPtr
->parent
;
438 WIN_ReleasePtr( wndPtr
);
439 if (!(wndPtr
= WIN_GetPtr( hwnd
))) break;
440 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
441 if (wndPtr
== WND_DESKTOP
) break;
442 if (wndPtr
->flags
& WIN_CHILDREN_MOVED
)
444 WIN_ReleasePtr( wndPtr
);
448 if (wndPtr
&& wndPtr
!= WND_DESKTOP
) WIN_ReleasePtr( wndPtr
);
452 /* Translate origin to destination window coords */
455 if (!(wndPtr
= WIN_GetPtr( hwndTo
)))
457 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
460 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
461 if (wndPtr
!= WND_DESKTOP
)
463 if (wndPtr
->dwExStyle
& WS_EX_LAYOUTRTL
)
466 offset
.x
-= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
468 while (wndPtr
->parent
)
470 offset
.x
-= wndPtr
->rectClient
.left
;
471 offset
.y
-= wndPtr
->rectClient
.top
;
472 hwnd
= wndPtr
->parent
;
473 WIN_ReleasePtr( wndPtr
);
474 if (!(wndPtr
= WIN_GetPtr( hwnd
))) break;
475 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
476 if (wndPtr
== WND_DESKTOP
) break;
477 if (wndPtr
->flags
& WIN_CHILDREN_MOVED
)
479 WIN_ReleasePtr( wndPtr
);
483 if (wndPtr
&& wndPtr
!= WND_DESKTOP
) WIN_ReleasePtr( wndPtr
);
487 *mirrored
= mirror_from
^ mirror_to
;
488 if (mirror_from
) offset
.x
= -offset
.x
;
489 *ret_offset
= offset
;
492 other_process
: /* one of the parents may belong to another process, do it the hard way */
493 SERVER_START_REQ( get_windows_offset
)
495 req
->from
= wine_server_user_handle( hwndFrom
);
496 req
->to
= wine_server_user_handle( hwndTo
);
497 if ((ret
= !wine_server_call_err( req
)))
499 ret_offset
->x
= reply
->x
;
500 ret_offset
->y
= reply
->y
;
501 *mirrored
= reply
->mirror
;
508 /* map coordinates of a window region */
509 void map_window_region( HWND from
, HWND to
, HRGN hrgn
)
518 if (!WINPOS_GetWinOffset( from
, to
, &mirrored
, &offset
)) return;
522 OffsetRgn( hrgn
, offset
.x
, offset
.y
);
525 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return;
526 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return;
527 GetRegionData( hrgn
, size
, data
);
528 rect
= (RECT
*)data
->Buffer
;
529 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
531 int tmp
= -(rect
[i
].left
+ offset
.x
);
532 rect
[i
].left
= -(rect
[i
].right
+ offset
.x
);
534 rect
[i
].top
+= offset
.y
;
535 rect
[i
].bottom
+= offset
.y
;
537 if ((new_rgn
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
)))
539 CombineRgn( hrgn
, new_rgn
, 0, RGN_COPY
);
540 DeleteObject( new_rgn
);
542 HeapFree( GetProcessHeap(), 0, data
);
546 /*******************************************************************
547 * MapWindowPoints (USER32.@)
549 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
555 if (!WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &mirrored
, &offset
)) return 0;
557 for (i
= 0; i
< count
; i
++)
559 lppt
[i
].x
+= offset
.x
;
560 lppt
[i
].y
+= offset
.y
;
561 if (mirrored
) lppt
[i
].x
= -lppt
[i
].x
;
563 if (mirrored
&& count
== 2) /* special case for rectangle */
566 lppt
[0].x
= lppt
[1].x
;
569 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
573 /*******************************************************************
574 * ClientToScreen (USER32.@)
576 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
583 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
586 if (!WINPOS_GetWinOffset( hwnd
, 0, &mirrored
, &offset
)) return FALSE
;
587 lppnt
->x
+= offset
.x
;
588 lppnt
->y
+= offset
.y
;
589 if (mirrored
) lppnt
->x
= -lppnt
->x
;
594 /*******************************************************************
595 * ScreenToClient (USER32.@)
597 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
604 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
607 if (!WINPOS_GetWinOffset( 0, hwnd
, &mirrored
, &offset
)) return FALSE
;
608 lppnt
->x
+= offset
.x
;
609 lppnt
->y
+= offset
.y
;
610 if (mirrored
) lppnt
->x
= -lppnt
->x
;
615 /***********************************************************************
616 * IsIconic (USER32.@)
618 BOOL WINAPI
IsIconic(HWND hWnd
)
620 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
624 /***********************************************************************
625 * IsZoomed (USER32.@)
627 BOOL WINAPI
IsZoomed(HWND hWnd
)
629 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
633 /*******************************************************************
634 * AllowSetForegroundWindow (USER32.@)
636 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
638 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
639 * implemented, then fix this function. */
644 /*******************************************************************
645 * LockSetForegroundWindow (USER32.@)
647 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
649 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
650 * implemented, then fix this function. */
655 /***********************************************************************
656 * BringWindowToTop (USER32.@)
658 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
660 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
664 /***********************************************************************
665 * MoveWindow (USER32.@)
667 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
670 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
671 if (!repaint
) flags
|= SWP_NOREDRAW
;
672 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
673 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
677 /***********************************************************************
678 * WINPOS_RedrawIconTitle
680 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
683 WND
*win
= WIN_GetPtr( hWnd
);
685 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
687 icon_title
= win
->icon_title
;
688 WIN_ReleasePtr( win
);
690 if (!icon_title
) return FALSE
;
691 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
692 InvalidateRect( icon_title
, NULL
, TRUE
);
696 /***********************************************************************
697 * WINPOS_ShowIconTitle
699 static void WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
701 WND
*win
= WIN_GetPtr( hwnd
);
704 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
706 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return;
707 if (win
->rectWindow
.left
== -32000 || win
->rectWindow
.top
== -32000)
709 TRACE( "not showing title for hidden icon %p\n", hwnd
);
712 else title
= win
->icon_title
;
713 WIN_ReleasePtr( win
);
719 title
= ICONTITLE_Create( hwnd
);
720 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
722 DestroyWindow( title
);
725 win
->icon_title
= title
;
726 WIN_ReleasePtr( win
);
728 if (!IsWindowVisible(title
))
730 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
731 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
732 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
735 else if (title
) ShowWindow( title
, SW_HIDE
);
738 /*******************************************************************
739 * WINPOS_GetMinMaxInfo
741 * Get the minimized and maximized information for a window.
743 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
744 POINT
*minTrack
, POINT
*maxTrack
)
749 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
751 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
755 /* Compute default values */
757 GetWindowRect(hwnd
, &rc
);
758 MinMax
.ptReserved
.x
= rc
.left
;
759 MinMax
.ptReserved
.y
= rc
.top
;
761 if ((style
& WS_CAPTION
) == WS_CAPTION
)
762 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
764 adjustedStyle
= style
;
766 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
767 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
772 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
773 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
774 if (style
& (WS_DLGFRAME
| WS_BORDER
))
776 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
777 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
781 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
782 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
784 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
785 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
786 MinMax
.ptMaxPosition
.x
= -xinc
;
787 MinMax
.ptMaxPosition
.y
= -yinc
;
789 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
791 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
792 WIN_ReleasePtr( win
);
795 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
797 /* if the app didn't change the values, adapt them for the current monitor */
799 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
802 MONITORINFO mon_info
;
804 mon_info
.cbSize
= sizeof(mon_info
);
805 GetMonitorInfoW( monitor
, &mon_info
);
807 rc_work
= mon_info
.rcMonitor
;
809 if (style
& WS_MAXIMIZEBOX
)
811 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
812 rc_work
= mon_info
.rcWork
;
815 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
816 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
818 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
819 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
821 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
823 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
824 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
828 /* Some sanity checks */
830 TRACE("%d %d / %d %d / %d %d / %d %d\n",
831 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
832 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
833 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
834 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
835 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
836 MinMax
.ptMinTrackSize
.x
);
837 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
838 MinMax
.ptMinTrackSize
.y
);
840 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
841 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
842 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
843 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
847 /***********************************************************************
850 * Find a suitable place for an iconic window.
852 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
854 RECT rect
, rectParent
;
857 int x
, y
, xspacing
, yspacing
;
858 MINIMIZEDMETRICS metrics
;
860 metrics
.cbSize
= sizeof(metrics
);
861 SystemParametersInfoW( SPI_GETMINIMIZEDMETRICS
, sizeof(metrics
), &metrics
, 0 );
863 parent
= GetAncestor( hwnd
, GA_PARENT
);
864 if (parent
== GetDesktopWindow())
866 MONITORINFO mon_info
;
867 HMONITOR monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
869 mon_info
.cbSize
= sizeof( mon_info
);
870 GetMonitorInfoW( monitor
, &mon_info
);
871 rectParent
= mon_info
.rcWork
;
873 else GetClientRect( parent
, &rectParent
);
875 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
876 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
877 return pt
; /* The icon already has a suitable position */
879 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
880 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
882 /* Check if another icon already occupies this spot */
883 /* FIXME: this is completely inefficient */
885 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
886 tmp
= CreateRectRgn( 0, 0, 0, 0 );
887 for (child
= GetWindow( parent
, GW_CHILD
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
889 if (child
== hwnd
) continue;
890 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
892 if (WIN_GetRectangles( child
, COORDS_PARENT
, &rect
, NULL
))
894 SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
895 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
900 for (y
= 0; y
< (rectParent
.bottom
- rectParent
.top
) / yspacing
; y
++)
902 if (metrics
.iArrange
& ARW_STARTTOP
)
904 rect
.top
= rectParent
.top
+ y
* yspacing
;
905 rect
.bottom
= rect
.top
+ yspacing
;
909 rect
.bottom
= rectParent
.bottom
- y
* yspacing
;
910 rect
.top
= rect
.bottom
- yspacing
;
912 for (x
= 0; x
< (rectParent
.right
- rectParent
.left
) / xspacing
; x
++)
914 if (metrics
.iArrange
& ARW_STARTRIGHT
)
916 rect
.right
= rectParent
.right
- x
* xspacing
;
917 rect
.left
= rect
.right
- xspacing
;
921 rect
.left
= rectParent
.left
+ x
* xspacing
;
922 rect
.right
= rect
.left
+ xspacing
;
924 if (!RectInRegion( hrgn
, &rect
))
926 /* No window was found, so it's OK for us */
927 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
928 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
929 DeleteObject( hrgn
);
934 DeleteObject( hrgn
);
940 /***********************************************************************
943 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
950 TRACE("%p %u\n", hwnd
, cmd
);
952 wpl
.length
= sizeof(wpl
);
953 GetWindowPlacement( hwnd
, &wpl
);
955 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
956 return SWP_NOSIZE
| SWP_NOMOVE
;
958 if (IsIconic( hwnd
))
962 case SW_SHOWMINNOACTIVE
:
963 case SW_SHOWMINIMIZED
:
964 case SW_FORCEMINIMIZE
:
966 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
968 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
969 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
970 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
971 return SWP_NOSIZE
| SWP_NOMOVE
;
973 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
974 swpFlags
|= SWP_NOCOPYBITS
;
979 case SW_SHOWMINNOACTIVE
:
980 case SW_SHOWMINIMIZED
:
981 case SW_FORCEMINIMIZE
:
983 if (IsZoomed( hwnd
)) win_set_flags( hwnd
, WIN_RESTORE_MAX
, 0 );
984 else win_set_flags( hwnd
, 0, WIN_RESTORE_MAX
);
986 if (GetFocus() == hwnd
)
988 if (GetWindowLongW(hwnd
, GWL_STYLE
) & WS_CHILD
)
989 SetFocus(GetAncestor(hwnd
, GA_PARENT
));
994 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
996 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
998 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
999 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1000 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
1001 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
1002 swpFlags
|= SWP_NOCOPYBITS
;
1006 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1007 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
1009 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1011 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
1012 if (old_style
& WS_MINIMIZE
)
1014 win_set_flags( hwnd
, WIN_RESTORE_MAX
, 0 );
1015 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1018 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
1019 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
1020 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
1023 case SW_SHOWNOACTIVATE
:
1024 win_set_flags( hwnd
, 0, WIN_RESTORE_MAX
);
1028 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1029 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
1030 if (old_style
& WS_MINIMIZE
)
1032 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1033 if (win_get_flags( hwnd
) & WIN_RESTORE_MAX
)
1035 /* Restore to maximized position */
1036 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1037 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
1038 swpFlags
|= SWP_STATECHANGED
;
1039 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
1040 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
1044 else if (!(old_style
& WS_MAXIMIZE
)) break;
1046 swpFlags
|= SWP_STATECHANGED
;
1048 /* Restore to normal position */
1050 *rect
= wpl
.rcNormalPosition
;
1058 /***********************************************************************
1061 * Implementation of ShowWindow and ShowWindowAsync.
1063 static BOOL
show_window( HWND hwnd
, INT cmd
)
1067 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1068 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
1069 BOOL showFlag
= TRUE
;
1070 RECT newPos
= {0, 0, 0, 0};
1073 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
1078 if (!wasVisible
) return FALSE
;
1080 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1081 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1084 case SW_SHOWMINNOACTIVE
:
1086 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1087 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1089 case SW_SHOWMINIMIZED
:
1090 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1091 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1092 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
1095 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1096 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1097 swp
|= SWP_FRAMECHANGED
;
1098 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1099 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
1103 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1104 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
1107 if (wasVisible
) return TRUE
;
1108 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1109 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1112 case SW_SHOWNOACTIVATE
:
1113 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1117 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1118 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1119 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1120 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1122 swp
|= SWP_FRAMECHANGED
;
1123 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1127 if (wasVisible
) return TRUE
;
1128 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1130 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1136 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1138 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1139 if (!IsWindow( hwnd
)) return wasVisible
;
1142 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1144 parent
= GetAncestor( hwnd
, GA_PARENT
);
1145 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1147 /* if parent is not visible simply toggle WS_VISIBLE and return */
1148 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1149 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1152 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1153 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1159 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1161 /* FIXME: This will cause the window to be activated irrespective
1162 * of whether it is owned by the same thread. Has to be done
1166 if (hwnd
== GetActiveWindow())
1167 WINPOS_ActivateOtherWindow(hwnd
);
1169 /* Revert focus to parent */
1170 hFocus
= GetFocus();
1173 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1174 if (parent
== GetDesktopWindow()) parent
= 0;
1180 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1182 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1184 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1186 /* should happen only in CreateWindowEx() */
1187 int wParam
= SIZE_RESTORED
;
1191 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &client
);
1192 lparam
= MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
);
1193 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1194 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1195 else if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1197 wParam
= SIZE_MINIMIZED
;
1200 WIN_ReleasePtr( wndPtr
);
1202 SendMessageW( hwnd
, WM_SIZE
, wParam
, lparam
);
1203 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1205 else WIN_ReleasePtr( wndPtr
);
1207 /* if previous state was minimized Windows sets focus to the window */
1208 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1214 /***********************************************************************
1215 * ShowWindowAsync (USER32.@)
1217 * doesn't wait; returns immediately.
1218 * used by threads to toggle windows in other (possibly hanging) threads
1220 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1224 if (is_broadcast(hwnd
))
1226 SetLastError( ERROR_INVALID_PARAMETER
);
1230 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1231 return show_window( full_handle
, cmd
);
1233 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1237 /***********************************************************************
1238 * ShowWindow (USER32.@)
1240 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1244 if (is_broadcast(hwnd
))
1246 SetLastError( ERROR_INVALID_PARAMETER
);
1249 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1250 return show_window( full_handle
, cmd
);
1252 if ((cmd
== SW_HIDE
) && !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1255 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1259 /***********************************************************************
1260 * GetInternalWindowPos (USER32.@)
1262 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1265 WINDOWPLACEMENT wndpl
;
1267 wndpl
.length
= sizeof(wndpl
);
1268 if (GetWindowPlacement( hwnd
, &wndpl
))
1270 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1271 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1272 return wndpl
.showCmd
;
1278 /***********************************************************************
1279 * GetWindowPlacement (USER32.@)
1282 * Fails if wndpl->length of Win95 (!) apps is invalid.
1284 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1286 WND
*pWnd
= WIN_GetPtr( hwnd
);
1288 if (!pWnd
) return FALSE
;
1290 if (pWnd
== WND_DESKTOP
)
1292 wndpl
->length
= sizeof(*wndpl
);
1293 wndpl
->showCmd
= SW_SHOWNORMAL
;
1295 wndpl
->ptMinPosition
.x
= -1;
1296 wndpl
->ptMinPosition
.y
= -1;
1297 wndpl
->ptMaxPosition
.x
= -1;
1298 wndpl
->ptMaxPosition
.y
= -1;
1299 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1302 if (pWnd
== WND_OTHER_PROCESS
)
1304 if (!IsWindow( hwnd
)) return FALSE
;
1305 FIXME( "not supported on other process window %p\n", hwnd
);
1306 /* provide some dummy information */
1307 wndpl
->length
= sizeof(*wndpl
);
1308 wndpl
->showCmd
= SW_SHOWNORMAL
;
1310 wndpl
->ptMinPosition
.x
= -1;
1311 wndpl
->ptMinPosition
.y
= -1;
1312 wndpl
->ptMaxPosition
.x
= -1;
1313 wndpl
->ptMaxPosition
.y
= -1;
1314 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1318 /* update the placement according to the current style */
1319 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1321 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1322 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1324 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1326 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1327 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1331 pWnd
->normal_rect
= pWnd
->rectWindow
;
1334 wndpl
->length
= sizeof(*wndpl
);
1335 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1336 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1338 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1339 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1340 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1343 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1344 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1345 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1346 WIN_ReleasePtr( pWnd
);
1348 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1349 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1350 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1351 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1355 /* make sure the specified rect is visible on screen */
1356 static void make_rect_onscreen( RECT
*rect
)
1359 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1361 info
.cbSize
= sizeof(info
);
1362 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1363 /* FIXME: map coordinates from rcWork to rcMonitor */
1364 if (rect
->right
<= info
.rcWork
.left
)
1366 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1367 rect
->left
= info
.rcWork
.left
;
1369 else if (rect
->left
>= info
.rcWork
.right
)
1371 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1372 rect
->right
= info
.rcWork
.right
;
1374 if (rect
->bottom
<= info
.rcWork
.top
)
1376 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1377 rect
->top
= info
.rcWork
.top
;
1379 else if (rect
->top
>= info
.rcWork
.bottom
)
1381 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1382 rect
->bottom
= info
.rcWork
.bottom
;
1386 /* make sure the specified point is visible on screen */
1387 static void make_point_onscreen( POINT
*pt
)
1391 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1392 make_rect_onscreen( &rect
);
1398 /***********************************************************************
1399 * WINPOS_SetPlacement
1401 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1404 WND
*pWnd
= WIN_GetPtr( hwnd
);
1405 WINDOWPLACEMENT wp
= *wndpl
;
1407 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1408 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1409 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1411 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1412 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1413 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1414 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1415 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1416 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1418 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1420 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1421 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1422 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1424 style
= pWnd
->dwStyle
;
1426 WIN_ReleasePtr( pWnd
);
1428 if( style
& WS_MINIMIZE
)
1430 if (flags
& PLACE_MIN
)
1432 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1433 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1434 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1437 else if( style
& WS_MAXIMIZE
)
1439 if (flags
& PLACE_MAX
)
1440 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1441 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1443 else if( flags
& PLACE_RECT
)
1444 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1445 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1446 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1447 SWP_NOZORDER
| SWP_NOACTIVATE
);
1449 ShowWindow( hwnd
, wndpl
->showCmd
);
1451 if (IsIconic( hwnd
))
1453 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1455 /* SDK: ...valid only the next time... */
1456 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1457 win_set_flags( hwnd
, WIN_RESTORE_MAX
, 0 );
1463 /***********************************************************************
1464 * SetWindowPlacement (USER32.@)
1467 * Fails if wndpl->length of Win95 (!) apps is invalid.
1469 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1471 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1472 if (!wpl
) return FALSE
;
1473 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1474 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1478 /***********************************************************************
1479 * AnimateWindow (USER32.@)
1480 * Shows/Hides a window with an animation
1483 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1485 FIXME("partial stub\n");
1487 /* If trying to show/hide and it's already *
1488 * shown/hidden or invalid window, fail with *
1489 * invalid parameter */
1490 if(!IsWindow(hwnd
) ||
1491 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1492 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1494 SetLastError(ERROR_INVALID_PARAMETER
);
1498 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1503 /***********************************************************************
1504 * SetInternalWindowPos (USER32.@)
1506 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1507 LPRECT rect
, LPPOINT pt
)
1509 WINDOWPLACEMENT wndpl
;
1512 wndpl
.length
= sizeof(wndpl
);
1513 wndpl
.showCmd
= showCmd
;
1514 wndpl
.flags
= flags
= 0;
1519 wndpl
.flags
|= WPF_SETMINPOSITION
;
1520 wndpl
.ptMinPosition
= *pt
;
1524 flags
|= PLACE_RECT
;
1525 wndpl
.rcNormalPosition
= *rect
;
1527 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1531 /*******************************************************************
1532 * can_activate_window
1534 * Check if we can activate the specified window.
1536 static BOOL
can_activate_window( HWND hwnd
)
1540 if (!hwnd
) return FALSE
;
1541 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1542 if (!(style
& WS_VISIBLE
)) return FALSE
;
1543 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1544 return !(style
& WS_DISABLED
);
1548 /*******************************************************************
1549 * WINPOS_ActivateOtherWindow
1551 * Activates window other than pWnd.
1553 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1557 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1559 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1560 if (can_activate_window( hwndTo
)) goto done
;
1566 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1567 if (can_activate_window( hwndTo
)) goto done
;
1570 hwndTo
= GetTopWindow( 0 );
1578 if (can_activate_window( hwndTo
)) goto done
;
1579 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1583 fg
= GetForegroundWindow();
1584 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1585 if (!fg
|| (hwnd
== fg
))
1587 if (SetForegroundWindow( hwndTo
)) return;
1589 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1593 /***********************************************************************
1594 * WINPOS_HandleWindowPosChanging
1596 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1598 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1600 POINT minTrack
, maxTrack
;
1601 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1603 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1604 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1606 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1607 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1608 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1609 if (!(style
& WS_MINIMIZE
))
1611 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1612 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1619 /***********************************************************************
1622 static void dump_winpos_flags(UINT flags
)
1624 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1625 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1626 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1627 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1628 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1630 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1631 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1632 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1633 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1634 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1635 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1636 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1637 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1638 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1639 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1640 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1641 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1642 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1643 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1644 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1645 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1647 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1651 /***********************************************************************
1652 * SWP_DoWinPosChanging
1654 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1657 RECT window_rect
, client_rect
;
1659 /* Send WM_WINDOWPOSCHANGING message */
1661 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
)
1662 && !((pWinpos
->flags
& SWP_AGG_NOCLIENTCHANGE
) && (pWinpos
->flags
& SWP_SHOWWINDOW
)))
1663 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1665 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1666 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1668 /* Calculate new position and size */
1670 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1671 *pNewWindowRect
= window_rect
;
1672 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? window_rect
: client_rect
;
1674 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1676 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1678 pNewWindowRect
->right
= pNewWindowRect
->left
+ GetSystemMetrics(SM_CXICON
);
1679 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ GetSystemMetrics(SM_CYICON
);
1683 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1684 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1687 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1689 pNewWindowRect
->left
= pWinpos
->x
;
1690 pNewWindowRect
->top
= pWinpos
->y
;
1691 pNewWindowRect
->right
+= pWinpos
->x
- window_rect
.left
;
1692 pNewWindowRect
->bottom
+= pWinpos
->y
- window_rect
.top
;
1694 OffsetRect( pNewClientRect
, pWinpos
->x
- window_rect
.left
,
1695 pWinpos
->y
- window_rect
.top
);
1697 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1699 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1700 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1701 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1702 TRACE( "current %s style %08x new %s\n",
1703 wine_dbgstr_rect( &window_rect
), wndPtr
->dwStyle
,
1704 wine_dbgstr_rect( pNewWindowRect
));
1706 WIN_ReleasePtr( wndPtr
);
1710 /***********************************************************************
1713 * Compute the valid rects from the old and new client rect and WVR_* flags.
1714 * Helper for WM_NCCALCSIZE handling.
1716 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1721 if (flags
& WVR_REDRAW
)
1723 SetRectEmpty( &valid
[0] );
1724 SetRectEmpty( &valid
[1] );
1728 if (flags
& WVR_VALIDRECTS
)
1730 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1731 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1733 SetRectEmpty( &valid
[0] );
1734 SetRectEmpty( &valid
[1] );
1737 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1741 valid
[0] = *new_client
;
1742 valid
[1] = *old_client
;
1745 /* make sure the rectangles have the same size */
1746 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1747 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1749 if (flags
& WVR_ALIGNBOTTOM
)
1751 valid
[0].top
= valid
[0].bottom
- cy
;
1752 valid
[1].top
= valid
[1].bottom
- cy
;
1756 valid
[0].bottom
= valid
[0].top
+ cy
;
1757 valid
[1].bottom
= valid
[1].top
+ cy
;
1759 if (flags
& WVR_ALIGNRIGHT
)
1761 valid
[0].left
= valid
[0].right
- cx
;
1762 valid
[1].left
= valid
[1].right
- cx
;
1766 valid
[0].right
= valid
[0].left
+ cx
;
1767 valid
[1].right
= valid
[1].left
+ cx
;
1772 /***********************************************************************
1775 * fix Z order taking into account owned popups -
1776 * basically we need to maintain them above the window that owns them
1778 * FIXME: hide/show owned popups when owner visibility changes.
1780 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1782 HWND owner
, *list
= NULL
;
1785 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1787 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return hwndInsertAfter
;
1789 if ((owner
= GetWindow( hwnd
, GW_OWNER
)))
1791 /* make sure this popup stays above the owner */
1793 if (hwndInsertAfter
!= HWND_TOPMOST
)
1795 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1797 for (i
= 0; list
[i
]; i
++)
1799 BOOL topmost
= (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1801 if (list
[i
] == owner
)
1803 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1804 else hwndInsertAfter
= topmost
? HWND_TOPMOST
: HWND_TOP
;
1808 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1810 if (!topmost
) break;
1812 else if (list
[i
] == hwndInsertAfter
) break;
1817 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1818 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1821 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1823 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1825 /* skip all the topmost windows */
1826 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1829 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1831 /* skip windows that are already placed correctly */
1832 for (i
= 0; list
[i
]; i
++)
1834 if (list
[i
] == hwndInsertAfter
) break;
1835 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1839 for ( ; list
[i
]; i
++)
1841 if (list
[i
] == hwnd
) break;
1842 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1843 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1844 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1845 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1846 hwndInsertAfter
= list
[i
];
1850 HeapFree( GetProcessHeap(), 0, list
);
1851 return hwndInsertAfter
;
1854 /***********************************************************************
1857 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1861 RECT window_rect
, client_rect
;
1863 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1865 /* Send WM_NCCALCSIZE message to get new client area */
1866 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1868 NCCALCSIZE_PARAMS params
;
1869 WINDOWPOS winposCopy
;
1871 params
.rgrc
[0] = *pNewWindowRect
;
1872 params
.rgrc
[1] = window_rect
;
1873 params
.rgrc
[2] = client_rect
;
1874 params
.lppos
= &winposCopy
;
1875 winposCopy
= *pWinpos
;
1877 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1879 *pNewClientRect
= params
.rgrc
[0];
1881 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1882 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
),
1883 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1885 if( pNewClientRect
->left
!= client_rect
.left
||
1886 pNewClientRect
->top
!= client_rect
.top
)
1887 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1889 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1890 client_rect
.right
- client_rect
.left
))
1891 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1893 wvrFlags
&= ~WVR_HREDRAW
;
1895 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1896 client_rect
.bottom
- client_rect
.top
)
1897 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1899 wvrFlags
&= ~WVR_VREDRAW
;
1901 validRects
[0] = params
.rgrc
[1];
1902 validRects
[1] = params
.rgrc
[2];
1906 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1907 (pNewClientRect
->left
!= client_rect
.left
||
1908 pNewClientRect
->top
!= client_rect
.top
))
1909 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1912 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1914 SetRectEmpty( &validRects
[0] );
1915 SetRectEmpty( &validRects
[1] );
1917 else get_valid_rects( &client_rect
, pNewClientRect
, wvrFlags
, validRects
);
1922 /* fix redundant flags and values in the WINDOWPOS structure */
1923 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1928 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1931 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1933 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1936 winpos
->hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
1938 /* Finally make sure that all coordinates are valid */
1939 if (winpos
->x
< -32768) winpos
->x
= -32768;
1940 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1941 if (winpos
->y
< -32768) winpos
->y
= -32768;
1942 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1944 if (winpos
->cx
< 0) winpos
->cx
= 0;
1945 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1946 if (winpos
->cy
< 0) winpos
->cy
= 0;
1947 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1949 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1950 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1952 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1955 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1956 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1959 WIN_GetRectangles( winpos
->hwnd
, COORDS_SCREEN
, &window_rect
, NULL
);
1960 if ((window_rect
.right
- window_rect
.left
== winpos
->cx
) &&
1961 (window_rect
.bottom
- window_rect
.top
== winpos
->cy
))
1962 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1966 ClientToScreen( parent
, &pt
);
1967 if ((window_rect
.left
== pt
.x
) && (window_rect
.top
== pt
.y
))
1968 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1970 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1972 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1973 (winpos
->flags
& SWP_NOZORDER
||
1974 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1976 winpos
->flags
&= ~SWP_NOZORDER
;
1977 winpos
->hwndInsertAfter
= HWND_TOP
;
1981 /* Check hwndInsertAfter */
1982 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1984 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1986 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1987 winpos
->flags
|= SWP_NOZORDER
;
1989 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1991 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1992 winpos
->flags
|= SWP_NOZORDER
;
1994 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1996 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1997 winpos
->flags
|= SWP_NOZORDER
;
1999 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
2001 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
2002 winpos
->flags
|= SWP_NOZORDER
;
2006 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
2007 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
2008 winpos
->flags
|= SWP_NOZORDER
;
2011 WIN_ReleasePtr( wndPtr
);
2016 /***********************************************************************
2017 * update_surface_region
2019 static void update_surface_region( HWND hwnd
)
2025 WND
*win
= WIN_GetPtr( hwnd
);
2027 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return;
2028 if (!win
->surface
) goto done
;
2032 if (!(data
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( RGNDATA
, Buffer
[size
] )))) goto done
;
2034 SERVER_START_REQ( get_surface_region
)
2036 req
->window
= wine_server_user_handle( hwnd
);
2037 wine_server_set_reply( req
, data
->Buffer
, size
);
2038 if (!(status
= wine_server_call( req
)))
2040 size_t reply_size
= wine_server_reply_size( reply
);
2043 data
->rdh
.dwSize
= sizeof(data
->rdh
);
2044 data
->rdh
.iType
= RDH_RECTANGLES
;
2045 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
2046 data
->rdh
.nRgnSize
= reply_size
;
2047 region
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
);
2048 OffsetRgn( region
, -reply
->visible_rect
.left
, -reply
->visible_rect
.top
);
2051 else size
= reply
->total_size
;
2054 HeapFree( GetProcessHeap(), 0, data
);
2055 } while (status
== STATUS_BUFFER_OVERFLOW
);
2057 if (status
) goto done
;
2059 win
->surface
->funcs
->set_region( win
->surface
, region
);
2060 if (region
) DeleteObject( region
);
2063 WIN_ReleasePtr( win
);
2067 /***********************************************************************
2070 * Backend implementation of SetWindowPos.
2072 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2073 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
2076 HWND surface_win
= 0, parent
= GetAncestor( hwnd
, GA_PARENT
);
2077 BOOL ret
, needs_update
= FALSE
;
2078 RECT visible_rect
, old_visible_rect
, old_window_rect
, old_client_rect
;
2079 struct window_surface
*old_surface
, *new_surface
= NULL
;
2081 if (!parent
|| parent
== GetDesktopWindow())
2083 new_surface
= &dummy_surface
; /* provide a default surface for top-level windows */
2084 window_surface_add_ref( new_surface
);
2086 visible_rect
= *window_rect
;
2087 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
2088 window_rect
, client_rect
, &visible_rect
, &new_surface
);
2090 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_window_rect
, NULL
);
2092 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
2094 if (new_surface
) window_surface_release( new_surface
);
2097 old_visible_rect
= win
->visible_rect
;
2098 old_client_rect
= win
->rectClient
;
2099 old_surface
= win
->surface
;
2100 if (old_surface
!= new_surface
) swp_flags
|= SWP_FRAMECHANGED
; /* force refreshing non-client area */
2102 SERVER_START_REQ( set_window_pos
)
2104 req
->handle
= wine_server_user_handle( hwnd
);
2105 req
->previous
= wine_server_user_handle( insert_after
);
2106 req
->swp_flags
= swp_flags
;
2107 req
->window
.left
= window_rect
->left
;
2108 req
->window
.top
= window_rect
->top
;
2109 req
->window
.right
= window_rect
->right
;
2110 req
->window
.bottom
= window_rect
->bottom
;
2111 req
->client
.left
= client_rect
->left
;
2112 req
->client
.top
= client_rect
->top
;
2113 req
->client
.right
= client_rect
->right
;
2114 req
->client
.bottom
= client_rect
->bottom
;
2115 if (!EqualRect( window_rect
, &visible_rect
) || !IsRectEmpty( &valid_rects
[0] ))
2117 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
2118 if (!IsRectEmpty( &valid_rects
[0] ))
2119 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
2121 if (new_surface
) req
->paint_flags
|= SET_WINPOS_PAINT_SURFACE
;
2122 if (win
->pixel_format
) req
->paint_flags
|= SET_WINPOS_PIXEL_FORMAT
;
2124 if ((ret
= !wine_server_call( req
)))
2126 win
->dwStyle
= reply
->new_style
;
2127 win
->dwExStyle
= reply
->new_ex_style
;
2128 win
->rectWindow
= *window_rect
;
2129 win
->rectClient
= *client_rect
;
2130 win
->visible_rect
= visible_rect
;
2131 win
->surface
= new_surface
;
2132 surface_win
= wine_server_ptr_handle( reply
->surface_win
);
2133 needs_update
= reply
->needs_update
;
2134 if (GetWindowLongW( win
->parent
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
)
2137 GetClientRect( win
->parent
, &client
);
2138 mirror_rect( &client
, &win
->rectWindow
);
2139 mirror_rect( &client
, &win
->rectClient
);
2140 mirror_rect( &client
, &win
->visible_rect
);
2142 /* if an RTL window is resized the children have moved */
2143 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
&&
2144 client_rect
->right
- client_rect
->left
!= old_client_rect
.right
- old_client_rect
.left
)
2145 win
->flags
|= WIN_CHILDREN_MOVED
;
2152 if (needs_update
) update_surface_region( surface_win
);
2153 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
2154 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
| SWP_FRAMECHANGED
)))
2155 invalidate_dce( win
, &old_window_rect
);
2158 WIN_ReleasePtr( win
);
2162 TRACE( "win %p surface %p -> %p\n", hwnd
, old_surface
, new_surface
);
2163 register_window_surface( old_surface
, new_surface
);
2166 if (!IsRectEmpty( valid_rects
))
2168 move_window_bits( hwnd
, old_surface
, new_surface
, &visible_rect
,
2169 &old_visible_rect
, window_rect
, valid_rects
);
2170 valid_rects
= NULL
; /* prevent the driver from trying to also move the bits */
2172 window_surface_release( old_surface
);
2174 else if (surface_win
&& surface_win
!= hwnd
)
2176 if (!IsRectEmpty( valid_rects
))
2179 int x_offset
= old_visible_rect
.left
- visible_rect
.left
;
2180 int y_offset
= old_visible_rect
.top
- visible_rect
.top
;
2182 /* if all that happened is that the whole window moved, copy everything */
2183 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
2184 old_visible_rect
.right
- visible_rect
.right
== x_offset
&&
2185 old_visible_rect
.bottom
- visible_rect
.bottom
== y_offset
&&
2186 old_client_rect
.left
- client_rect
->left
== x_offset
&&
2187 old_client_rect
.right
- client_rect
->right
== x_offset
&&
2188 old_client_rect
.top
- client_rect
->top
== y_offset
&&
2189 old_client_rect
.bottom
- client_rect
->bottom
== y_offset
&&
2190 EqualRect( &valid_rects
[0], client_rect
))
2192 rects
[0] = visible_rect
;
2193 rects
[1] = old_visible_rect
;
2194 valid_rects
= rects
;
2196 move_window_bits_parent( hwnd
, surface_win
, window_rect
, valid_rects
);
2197 valid_rects
= NULL
; /* prevent the driver from trying to also move the bits */
2201 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
2202 client_rect
, &visible_rect
, valid_rects
, new_surface
);
2204 else if (new_surface
) window_surface_release( new_surface
);
2210 /***********************************************************************
2213 * User32 internal function
2215 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
2217 RECT newWindowRect
, newClientRect
, valid_rects
[2];
2220 orig_flags
= winpos
->flags
;
2222 /* First, check z-order arguments. */
2223 if (!(winpos
->flags
& SWP_NOZORDER
))
2225 /* fix sign extension */
2226 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
2227 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
2229 if (!(winpos
->hwndInsertAfter
== HWND_TOP
||
2230 winpos
->hwndInsertAfter
== HWND_BOTTOM
||
2231 winpos
->hwndInsertAfter
== HWND_TOPMOST
||
2232 winpos
->hwndInsertAfter
== HWND_NOTOPMOST
))
2234 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2235 HWND insertafter_parent
= GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
);
2237 /* hwndInsertAfter must be a sibling of the window */
2238 if (!insertafter_parent
) return FALSE
;
2239 if (insertafter_parent
!= parent
) return TRUE
;
2243 /* Make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
2244 if (!(winpos
->flags
& SWP_NOMOVE
))
2246 if (winpos
->x
< -32768) winpos
->x
= -32768;
2247 else if (winpos
->x
> 32767) winpos
->x
= 32767;
2248 if (winpos
->y
< -32768) winpos
->y
= -32768;
2249 else if (winpos
->y
> 32767) winpos
->y
= 32767;
2251 if (!(winpos
->flags
& SWP_NOSIZE
))
2253 if (winpos
->cx
< 0) winpos
->cx
= 0;
2254 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
2255 if (winpos
->cy
< 0) winpos
->cy
= 0;
2256 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
2259 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
2261 /* Fix redundant flags */
2262 if (!fixup_flags( winpos
)) return FALSE
;
2264 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
2266 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
2267 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
2270 /* Common operations */
2272 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
2274 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
2275 &newWindowRect
, &newClientRect
, valid_rects
))
2280 if( winpos
->flags
& SWP_HIDEWINDOW
)
2281 HideCaret(winpos
->hwnd
);
2282 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2283 ShowCaret(winpos
->hwnd
);
2285 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2287 /* child windows get WM_CHILDACTIVATE message */
2288 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2289 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2291 SetForegroundWindow( winpos
->hwnd
);
2294 if(!(orig_flags
& SWP_DEFERERASE
))
2296 /* erase parent when hiding or resizing child */
2297 if ((orig_flags
& SWP_HIDEWINDOW
) ||
2298 (!(orig_flags
& SWP_SHOWWINDOW
) &&
2299 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
))
2301 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2302 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
2303 erase_now( parent
, 0 );
2306 /* Give newly shown windows a chance to redraw */
2307 if(((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
)
2308 && !(orig_flags
& SWP_AGG_NOCLIENTCHANGE
) && (orig_flags
& SWP_SHOWWINDOW
))
2310 erase_now(winpos
->hwnd
, 0);
2314 /* And last, send the WM_WINDOWPOSCHANGED message */
2316 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2318 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
)
2319 && !((orig_flags
& SWP_AGG_NOCLIENTCHANGE
) && (orig_flags
& SWP_SHOWWINDOW
)))
2321 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2322 and always contains final window position.
2324 winpos
->x
= newWindowRect
.left
;
2325 winpos
->y
= newWindowRect
.top
;
2326 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2327 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2328 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2333 /***********************************************************************
2334 * SetWindowPos (USER32.@)
2336 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2337 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2341 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2342 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2343 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2345 if (is_broadcast(hwnd
))
2347 SetLastError( ERROR_INVALID_PARAMETER
);
2351 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2352 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2357 winpos
.flags
= flags
;
2359 if (WIN_IsCurrentThread( hwnd
))
2360 return USER_SetWindowPos(&winpos
);
2362 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2366 /***********************************************************************
2367 * BeginDeferWindowPos (USER32.@)
2369 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2374 TRACE("%d\n", count
);
2378 SetLastError(ERROR_INVALID_PARAMETER
);
2381 /* Windows allows zero count, in which case it allocates context for 8 moves */
2382 if (count
== 0) count
= 8;
2384 if (!(pDWP
= HeapAlloc( GetProcessHeap(), 0, sizeof(DWP
)))) return 0;
2386 pDWP
->actualCount
= 0;
2387 pDWP
->suggestedCount
= count
;
2388 pDWP
->hwndParent
= 0;
2390 if (!(pDWP
->winPos
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(WINDOWPOS
) )) ||
2391 !(handle
= alloc_user_handle( &pDWP
->obj
, USER_DWP
)))
2393 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2394 HeapFree( GetProcessHeap(), 0, pDWP
);
2397 TRACE("returning hdwp %p\n", handle
);
2402 /***********************************************************************
2403 * DeferWindowPos (USER32.@)
2405 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2406 INT x
, INT y
, INT cx
, INT cy
,
2411 HDWP retvalue
= hdwp
;
2413 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2414 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2416 hwnd
= WIN_GetFullHandle( hwnd
);
2417 if (is_desktop_window( hwnd
) || !IsWindow( hwnd
))
2419 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2423 if (!(pDWP
= get_user_handle_ptr( hdwp
, USER_DWP
))) return 0;
2424 if (pDWP
== OBJ_OTHER_PROCESS
)
2426 FIXME( "other process handle %p?\n", hdwp
);
2430 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2432 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2434 /* Merge with the other changes */
2435 if (!(flags
& SWP_NOZORDER
))
2437 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2439 if (!(flags
& SWP_NOMOVE
))
2441 pDWP
->winPos
[i
].x
= x
;
2442 pDWP
->winPos
[i
].y
= y
;
2444 if (!(flags
& SWP_NOSIZE
))
2446 pDWP
->winPos
[i
].cx
= cx
;
2447 pDWP
->winPos
[i
].cy
= cy
;
2449 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2450 SWP_NOZORDER
| SWP_NOREDRAW
|
2451 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2453 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2458 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2460 WINDOWPOS
*newpos
= HeapReAlloc( GetProcessHeap(), 0, pDWP
->winPos
,
2461 pDWP
->suggestedCount
* 2 * sizeof(WINDOWPOS
) );
2467 pDWP
->suggestedCount
*= 2;
2468 pDWP
->winPos
= newpos
;
2470 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2471 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2472 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2473 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2474 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2475 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2476 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2477 pDWP
->actualCount
++;
2479 release_user_handle_ptr( pDWP
);
2484 /***********************************************************************
2485 * EndDeferWindowPos (USER32.@)
2487 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2493 TRACE("%p\n", hdwp
);
2495 if (!(pDWP
= free_user_handle( hdwp
, USER_DWP
))) return FALSE
;
2496 if (pDWP
== OBJ_OTHER_PROCESS
)
2498 FIXME( "other process handle %p?\n", hdwp
);
2502 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
2504 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2505 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2506 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2508 if (WIN_IsCurrentThread( winpos
->hwnd
))
2509 USER_SetWindowPos( winpos
);
2511 SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2513 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2514 HeapFree( GetProcessHeap(), 0, pDWP
);
2519 /***********************************************************************
2520 * ArrangeIconicWindows (USER32.@)
2522 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2526 INT x
, y
, xspacing
, yspacing
;
2528 MINIMIZEDMETRICS metrics
;
2530 metrics
.cbSize
= sizeof(metrics
);
2531 SystemParametersInfoW( SPI_GETMINIMIZEDMETRICS
, sizeof(metrics
), &metrics
, 0 );
2533 if (parent
== GetDesktopWindow())
2535 MONITORINFO mon_info
;
2536 HMONITOR monitor
= MonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY
);
2538 mon_info
.cbSize
= sizeof( mon_info
);
2539 GetMonitorInfoW( monitor
, &mon_info
);
2540 rectParent
= mon_info
.rcWork
;
2542 else GetClientRect( parent
, &rectParent
);
2545 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2546 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2548 hwndChild
= GetWindow( parent
, GW_CHILD
);
2551 if( IsIconic( hwndChild
) )
2553 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2555 if (metrics
.iArrange
& ARW_STARTRIGHT
)
2556 pt
.x
= rectParent
.right
- (x
+ 1) * xspacing
;
2558 pt
.x
= rectParent
.left
+ x
* xspacing
;
2559 if (metrics
.iArrange
& ARW_STARTTOP
)
2560 pt
.y
= rectParent
.top
+ y
* yspacing
;
2562 pt
.y
= rectParent
.bottom
- (y
+ 1) * yspacing
;
2564 SetWindowPos( hwndChild
, 0, pt
.x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2565 pt
.y
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2, 0, 0,
2566 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2567 if( IsWindow(hwndChild
) )
2568 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2570 if (++x
>= (rectParent
.right
- rectParent
.left
) / xspacing
)
2576 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2582 /***********************************************************************
2585 * Draw the frame used when moving or resizing window.
2587 static void draw_moving_frame( HWND parent
, HDC hdc
, RECT
*screen_rect
, BOOL thickframe
)
2589 RECT rect
= *screen_rect
;
2591 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2594 const int width
= GetSystemMetrics(SM_CXFRAME
);
2595 const int height
= GetSystemMetrics(SM_CYFRAME
);
2597 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2598 PatBlt( hdc
, rect
.left
, rect
.top
,
2599 rect
.right
- rect
.left
- width
, height
, PATINVERT
);
2600 PatBlt( hdc
, rect
.left
, rect
.top
+ height
, width
,
2601 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2602 PatBlt( hdc
, rect
.left
+ width
, rect
.bottom
- 1,
2603 rect
.right
- rect
.left
- width
, -height
, PATINVERT
);
2604 PatBlt( hdc
, rect
.right
- 1, rect
.top
, -width
,
2605 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2606 SelectObject( hdc
, hbrush
);
2608 else DrawFocusRect( hdc
, &rect
);
2612 /***********************************************************************
2615 * Initialization of a move or resize, when initiated from a menu choice.
2616 * Return hit test code for caption or sizing border.
2618 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2625 GetWindowRect( hwnd
, &rectWindow
);
2627 if ((wParam
& 0xfff0) == SC_MOVE
)
2629 /* Move pointer at the center of the caption */
2630 RECT rect
= rectWindow
;
2631 /* Note: to be exactly centered we should take the different types
2632 * of border into account, but it shouldn't make more than a few pixels
2633 * of difference so let's not bother with that */
2634 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2635 if (style
& WS_SYSMENU
)
2636 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2637 if (style
& WS_MINIMIZEBOX
)
2638 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2639 if (style
& WS_MAXIMIZEBOX
)
2640 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2641 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2642 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2643 hittest
= HTCAPTION
;
2648 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2652 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2653 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2658 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2659 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2660 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2661 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2672 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2673 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2677 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2678 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2682 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2683 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2687 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2688 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2696 TranslateMessage( &msg
);
2697 DispatchMessageW( &msg
);
2703 SetCursorPos( pt
.x
, pt
.y
);
2704 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2709 /***********************************************************************
2710 * WINPOS_SysCommandSizeMove
2712 * Perform SC_MOVE and SC_SIZE commands.
2714 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2717 RECT sizingRect
, mouseRect
, origRect
;
2720 LONG hittest
= (LONG
)(wParam
& 0x0f);
2721 WPARAM syscommand
= wParam
& 0xfff0;
2722 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2723 POINT minTrack
, maxTrack
;
2724 POINT capturePoint
, pt
;
2725 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2726 BOOL thickframe
= HAS_THICKFRAME( style
);
2727 BOOL iconic
= style
& WS_MINIMIZE
;
2729 DWORD dwPoint
= GetMessagePos ();
2730 BOOL DragFullWindows
= TRUE
;
2733 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2735 pt
.x
= (short)LOWORD(dwPoint
);
2736 pt
.y
= (short)HIWORD(dwPoint
);
2740 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2741 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2743 if (syscommand
== SC_MOVE
)
2745 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2746 if (!hittest
) return;
2750 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2751 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2754 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2755 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2758 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2764 /* Get min/max info */
2766 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2767 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &sizingRect
, NULL
);
2768 origRect
= sizingRect
;
2769 if (style
& WS_CHILD
)
2771 parent
= GetParent(hwnd
);
2772 GetClientRect( parent
, &mouseRect
);
2773 MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2774 MapWindowPoints( parent
, 0, (LPPOINT
)&sizingRect
, 2 );
2779 mouseRect
= get_virtual_screen_rect();
2780 mon
= MonitorFromPoint( pt
, MONITOR_DEFAULTTONEAREST
);
2783 if (ON_LEFT_BORDER(hittest
))
2785 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
+capturePoint
.x
-sizingRect
.left
);
2786 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
+capturePoint
.x
-sizingRect
.left
);
2788 else if (ON_RIGHT_BORDER(hittest
))
2790 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
+capturePoint
.x
-sizingRect
.right
);
2791 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
+capturePoint
.x
-sizingRect
.right
);
2793 if (ON_TOP_BORDER(hittest
))
2795 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
+capturePoint
.y
-sizingRect
.top
);
2796 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
+capturePoint
.y
-sizingRect
.top
);
2798 else if (ON_BOTTOM_BORDER(hittest
))
2800 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
+capturePoint
.y
-sizingRect
.bottom
);
2801 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
+capturePoint
.y
-sizingRect
.bottom
);
2804 /* Retrieve a default cache DC (without using the window style) */
2805 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2807 if( iconic
) /* create a cursor for dragging */
2809 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2810 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2811 if( !hDragCursor
) iconic
= FALSE
;
2814 /* we only allow disabling the full window drag for child windows */
2815 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2817 /* repaint the window before moving it around */
2818 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2820 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2821 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2827 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2828 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2830 /* Exit on button-up, Return, or Esc */
2831 if ((msg
.message
== WM_LBUTTONUP
) ||
2832 ((msg
.message
== WM_KEYDOWN
) &&
2833 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2835 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2837 TranslateMessage( &msg
);
2838 DispatchMessageW( &msg
);
2839 continue; /* We are not interested in other messages */
2844 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2846 case VK_UP
: pt
.y
-= 8; break;
2847 case VK_DOWN
: pt
.y
+= 8; break;
2848 case VK_LEFT
: pt
.x
-= 8; break;
2849 case VK_RIGHT
: pt
.x
+= 8; break;
2852 pt
.x
= max( pt
.x
, mouseRect
.left
);
2853 pt
.x
= min( pt
.x
, mouseRect
.right
- 1 );
2854 pt
.y
= max( pt
.y
, mouseRect
.top
);
2855 pt
.y
= min( pt
.y
, mouseRect
.bottom
- 1 );
2862 if ((newmon
= MonitorFromPoint( pt
, MONITOR_DEFAULTTONULL
)))
2865 info
.cbSize
= sizeof(info
);
2866 if (mon
&& GetMonitorInfoW( mon
, &info
))
2868 pt
.x
= max( pt
.x
, info
.rcWork
.left
);
2869 pt
.x
= min( pt
.x
, info
.rcWork
.right
- 1 );
2870 pt
.y
= max( pt
.y
, info
.rcWork
.top
);
2871 pt
.y
= min( pt
.y
, info
.rcWork
.bottom
- 1 );
2875 dx
= pt
.x
- capturePoint
.x
;
2876 dy
= pt
.y
- capturePoint
.y
;
2884 if( iconic
) /* ok, no system popup tracking */
2886 hOldCursor
= SetCursor(hDragCursor
);
2888 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2890 else if(!DragFullWindows
)
2891 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2894 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2897 if(!iconic
&& !DragFullWindows
) draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2898 if (hittest
== HTCAPTION
) OffsetRect( &sizingRect
, dx
, dy
);
2899 if (ON_LEFT_BORDER(hittest
)) sizingRect
.left
+= dx
;
2900 else if (ON_RIGHT_BORDER(hittest
)) sizingRect
.right
+= dx
;
2901 if (ON_TOP_BORDER(hittest
)) sizingRect
.top
+= dy
;
2902 else if (ON_BOTTOM_BORDER(hittest
)) sizingRect
.bottom
+= dy
;
2905 /* determine the hit location */
2906 if (syscommand
== SC_SIZE
)
2908 WPARAM wpSizingHit
= 0;
2910 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2911 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2912 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&sizingRect
);
2915 SendMessageW( hwnd
, WM_MOVING
, 0, (LPARAM
)&sizingRect
);
2919 if(!DragFullWindows
)
2920 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2923 RECT rect
= sizingRect
;
2924 MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2925 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
2926 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2927 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2936 if( moved
) /* restore cursors, show icon title later on */
2938 ShowCursor( FALSE
);
2939 SetCursor( hOldCursor
);
2942 else if (moved
&& !DragFullWindows
)
2944 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2947 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2948 ReleaseDC( parent
, hdc
);
2949 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2951 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2954 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2955 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2957 /* window moved or resized */
2960 /* if the moving/resizing isn't canceled call SetWindowPos
2961 * with the new position or the new size of the window
2963 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2965 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2966 if(!DragFullWindows
|| iconic
)
2967 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2968 sizingRect
.right
- sizingRect
.left
,
2969 sizingRect
.bottom
- sizingRect
.top
,
2970 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2973 { /* restore previous size/position */
2975 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2976 origRect
.right
- origRect
.left
,
2977 origRect
.bottom
- origRect
.top
,
2978 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2984 /* Single click brings up the system menu when iconized */
2988 if(style
& WS_SYSMENU
)
2989 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2990 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2992 else WINPOS_ShowIconTitle( hwnd
, TRUE
);
2996 /***********************************************************************
2997 * LogicalToPhysicalPoint (USER32.@)
2999 BOOL WINAPI
LogicalToPhysicalPoint(HWND hwnd
, POINT
*point
)
3004 FIXME("(%p %p) stub\n", hwnd
, point
);
3008 /***********************************************************************
3009 * PhysicalToLogicalPoint (USER32.@)
3011 BOOL WINAPI
PhysicalToLogicalPoint(HWND hwnd
, POINT
*point
)
3016 FIXME("(%p %p) stub\n", hwnd
, point
);