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)
49 #define HAS_DLGFRAME(style,exStyle) \
50 (((exStyle) & WS_EX_DLGMODALFRAME) || \
51 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
53 #define HAS_THICKFRAME(style) \
54 (((style) & WS_THICKFRAME) && \
55 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
57 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
59 #define ON_LEFT_BORDER(hit) \
60 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
61 #define ON_RIGHT_BORDER(hit) \
62 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
63 #define ON_TOP_BORDER(hit) \
64 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
65 #define ON_BOTTOM_BORDER(hit) \
66 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
68 #define PLACE_MIN 0x0001
69 #define PLACE_MAX 0x0002
70 #define PLACE_RECT 0x0004
74 struct user_object obj
;
82 /***********************************************************************
83 * SwitchToThisWindow (USER32.@)
85 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL alt_tab
)
87 if (IsIconic( hwnd
)) ShowWindow( hwnd
, SW_RESTORE
);
88 else BringWindowToTop( hwnd
);
92 /***********************************************************************
93 * GetWindowRect (USER32.@)
95 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
97 BOOL ret
= WIN_GetRectangles( hwnd
, COORDS_SCREEN
, rect
, NULL
);
98 if (ret
) TRACE( "hwnd %p %s\n", hwnd
, wine_dbgstr_rect(rect
) );
103 /***********************************************************************
104 * GetWindowRgn (USER32.@)
106 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
116 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
118 SetLastError( ERROR_OUTOFMEMORY
);
121 SERVER_START_REQ( get_window_region
)
123 req
->window
= wine_server_user_handle( hwnd
);
124 wine_server_set_reply( req
, data
->Buffer
, size
);
125 if (!(status
= wine_server_call( req
)))
127 size_t reply_size
= wine_server_reply_size( reply
);
130 data
->rdh
.dwSize
= sizeof(data
->rdh
);
131 data
->rdh
.iType
= RDH_RECTANGLES
;
132 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
133 data
->rdh
.nRgnSize
= reply_size
;
134 win_rgn
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
);
137 else size
= reply
->total_size
;
140 HeapFree( GetProcessHeap(), 0, data
);
141 } while (status
== STATUS_BUFFER_OVERFLOW
);
143 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
146 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
147 DeleteObject( win_rgn
);
152 /***********************************************************************
153 * GetWindowRgnBox (USER32.@)
155 int WINAPI
GetWindowRgnBox( HWND hwnd
, LPRECT prect
)
163 if ((hrgn
= CreateRectRgn(0, 0, 0, 0)))
165 if ((ret
= GetWindowRgn( hwnd
, hrgn
)) != ERROR
)
166 ret
= GetRgnBox( hrgn
, prect
);
173 /***********************************************************************
174 * SetWindowRgn (USER32.@)
176 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
178 static const RECT empty_rect
;
186 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
187 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
188 if (!GetRegionData( hrgn
, size
, data
))
190 HeapFree( GetProcessHeap(), 0, data
);
193 SERVER_START_REQ( set_window_region
)
195 req
->window
= wine_server_user_handle( hwnd
);
196 req
->redraw
= (bRedraw
!= 0);
197 if (data
->rdh
.nCount
)
198 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
200 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
201 ret
= !wine_server_call_err( req
);
204 HeapFree( GetProcessHeap(), 0, data
);
206 else /* clear existing region */
208 SERVER_START_REQ( set_window_region
)
210 req
->window
= wine_server_user_handle( hwnd
);
211 req
->redraw
= (bRedraw
!= 0);
212 ret
= !wine_server_call_err( req
);
219 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
220 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
221 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
222 USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
223 if (hrgn
) DeleteObject( hrgn
);
229 /***********************************************************************
230 * GetClientRect (USER32.@)
232 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
234 return WIN_GetRectangles( hwnd
, COORDS_CLIENT
, NULL
, rect
);
238 /***********************************************************************
239 * list_children_from_point
241 * Get the list of children that can contain point from the server.
242 * Point is in screen coordinates.
243 * Returned list must be freed by caller.
245 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
254 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
256 SERVER_START_REQ( get_window_children_from_point
)
258 req
->parent
= wine_server_user_handle( hwnd
);
261 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
262 if (!wine_server_call( req
)) count
= reply
->count
;
265 if (count
&& count
< size
)
267 /* start from the end since HWND is potentially larger than user_handle_t */
268 for (i
= count
- 1; i
>= 0; i
--)
269 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
273 HeapFree( GetProcessHeap(), 0, list
);
275 size
= count
+ 1; /* restart with a large enough buffer */
281 /***********************************************************************
282 * WINPOS_WindowFromPoint
284 * Find the window and hittest for a given point.
286 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
291 if (!hwndScope
) hwndScope
= GetDesktopWindow();
293 *hittest
= HTNOWHERE
;
295 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
297 /* now determine the hittest */
299 for (i
= 0; list
[i
]; i
++)
301 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
303 /* If window is minimized or disabled, return at once */
304 if (style
& WS_MINIMIZE
)
306 *hittest
= HTCAPTION
;
309 if (style
& WS_DISABLED
)
314 /* Send WM_NCCHITTEST (if same thread) */
315 if (!WIN_IsCurrentThread( list
[i
] ))
320 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
321 if (res
!= HTTRANSPARENT
)
323 *hittest
= res
; /* Found the window */
326 /* continue search with next window in z-order */
329 HeapFree( GetProcessHeap(), 0, list
);
330 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
335 /*******************************************************************
336 * WindowFromPoint (USER32.@)
338 HWND WINAPI
WindowFromPoint( POINT pt
)
341 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
345 /*******************************************************************
346 * ChildWindowFromPoint (USER32.@)
348 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
350 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
353 /*******************************************************************
354 * RealChildWindowFromPoint (USER32.@)
356 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
358 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
| CWP_SKIPINVISIBLE
);
361 /*******************************************************************
362 * ChildWindowFromPointEx (USER32.@)
364 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
366 /* pt is in the client coordinates */
372 GetClientRect( hwndParent
, &rect
);
373 if (!PtInRect( &rect
, pt
)) return 0;
374 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
376 for (i
= 0; list
[i
]; i
++)
378 if (!WIN_GetRectangles( list
[i
], COORDS_PARENT
, &rect
, NULL
)) continue;
379 if (!PtInRect( &rect
, pt
)) continue;
380 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
382 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
383 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
384 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
386 if (uFlags
& CWP_SKIPTRANSPARENT
)
388 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
393 HeapFree( GetProcessHeap(), 0, list
);
394 if (!retvalue
) retvalue
= hwndParent
;
399 /*******************************************************************
400 * WINPOS_GetWinOffset
402 * Calculate the offset between the origin of the two windows. Used
403 * to implement MapWindowPoints.
405 static BOOL
WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, BOOL
*mirrored
, POINT
*ret_offset
)
409 BOOL mirror_from
, mirror_to
, ret
;
412 offset
.x
= offset
.y
= 0;
413 *mirrored
= mirror_from
= mirror_to
= FALSE
;
415 /* Translate source window origin to screen coords */
418 if (!(wndPtr
= WIN_GetPtr( hwndFrom
)))
420 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
423 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
424 if (wndPtr
!= WND_DESKTOP
)
426 if (wndPtr
->dwExStyle
& WS_EX_LAYOUTRTL
)
429 offset
.x
+= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
431 while (wndPtr
->parent
)
433 offset
.x
+= wndPtr
->rectClient
.left
;
434 offset
.y
+= wndPtr
->rectClient
.top
;
435 hwnd
= wndPtr
->parent
;
436 WIN_ReleasePtr( wndPtr
);
437 if (!(wndPtr
= WIN_GetPtr( hwnd
))) break;
438 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
439 if (wndPtr
== WND_DESKTOP
) break;
440 if (wndPtr
->flags
& WIN_CHILDREN_MOVED
)
442 WIN_ReleasePtr( wndPtr
);
446 if (wndPtr
&& wndPtr
!= WND_DESKTOP
) WIN_ReleasePtr( wndPtr
);
450 /* Translate origin to destination window coords */
453 if (!(wndPtr
= WIN_GetPtr( hwndTo
)))
455 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
458 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
459 if (wndPtr
!= WND_DESKTOP
)
461 if (wndPtr
->dwExStyle
& WS_EX_LAYOUTRTL
)
464 offset
.x
-= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
466 while (wndPtr
->parent
)
468 offset
.x
-= wndPtr
->rectClient
.left
;
469 offset
.y
-= wndPtr
->rectClient
.top
;
470 hwnd
= wndPtr
->parent
;
471 WIN_ReleasePtr( wndPtr
);
472 if (!(wndPtr
= WIN_GetPtr( hwnd
))) break;
473 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
474 if (wndPtr
== WND_DESKTOP
) break;
475 if (wndPtr
->flags
& WIN_CHILDREN_MOVED
)
477 WIN_ReleasePtr( wndPtr
);
481 if (wndPtr
&& wndPtr
!= WND_DESKTOP
) WIN_ReleasePtr( wndPtr
);
485 *mirrored
= mirror_from
^ mirror_to
;
486 if (mirror_from
) offset
.x
= -offset
.x
;
487 *ret_offset
= offset
;
490 other_process
: /* one of the parents may belong to another process, do it the hard way */
491 SERVER_START_REQ( get_windows_offset
)
493 req
->from
= wine_server_user_handle( hwndFrom
);
494 req
->to
= wine_server_user_handle( hwndTo
);
495 if ((ret
= !wine_server_call_err( req
)))
497 ret_offset
->x
= reply
->x
;
498 ret_offset
->y
= reply
->y
;
499 *mirrored
= reply
->mirror
;
506 /* map coordinates of a window region */
507 void map_window_region( HWND from
, HWND to
, HRGN hrgn
)
516 if (!WINPOS_GetWinOffset( from
, to
, &mirrored
, &offset
)) return;
520 OffsetRgn( hrgn
, offset
.x
, offset
.y
);
523 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return;
524 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return;
525 GetRegionData( hrgn
, size
, data
);
526 rect
= (RECT
*)data
->Buffer
;
527 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
529 int tmp
= -(rect
[i
].left
+ offset
.x
);
530 rect
[i
].left
= -(rect
[i
].right
+ offset
.x
);
532 rect
[i
].top
+= offset
.y
;
533 rect
[i
].bottom
+= offset
.y
;
535 if ((new_rgn
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
)))
537 CombineRgn( hrgn
, new_rgn
, 0, RGN_COPY
);
538 DeleteObject( new_rgn
);
540 HeapFree( GetProcessHeap(), 0, data
);
544 /*******************************************************************
545 * MapWindowPoints (USER32.@)
547 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
553 if (!WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &mirrored
, &offset
)) return 0;
555 for (i
= 0; i
< count
; i
++)
557 lppt
[i
].x
+= offset
.x
;
558 lppt
[i
].y
+= offset
.y
;
559 if (mirrored
) lppt
[i
].x
= -lppt
[i
].x
;
561 if (mirrored
&& count
== 2) /* special case for rectangle */
564 lppt
[0].x
= lppt
[1].x
;
567 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
571 /*******************************************************************
572 * ClientToScreen (USER32.@)
574 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
581 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
584 if (!WINPOS_GetWinOffset( hwnd
, 0, &mirrored
, &offset
)) return FALSE
;
585 lppnt
->x
+= offset
.x
;
586 lppnt
->y
+= offset
.y
;
587 if (mirrored
) lppnt
->x
= -lppnt
->x
;
592 /*******************************************************************
593 * ScreenToClient (USER32.@)
595 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
602 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
605 if (!WINPOS_GetWinOffset( 0, hwnd
, &mirrored
, &offset
)) return FALSE
;
606 lppnt
->x
+= offset
.x
;
607 lppnt
->y
+= offset
.y
;
608 if (mirrored
) lppnt
->x
= -lppnt
->x
;
613 /***********************************************************************
614 * IsIconic (USER32.@)
616 BOOL WINAPI
IsIconic(HWND hWnd
)
618 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
622 /***********************************************************************
623 * IsZoomed (USER32.@)
625 BOOL WINAPI
IsZoomed(HWND hWnd
)
627 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
631 /*******************************************************************
632 * AllowSetForegroundWindow (USER32.@)
634 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
636 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
637 * implemented, then fix this function. */
642 /*******************************************************************
643 * LockSetForegroundWindow (USER32.@)
645 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
647 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
648 * implemented, then fix this function. */
653 /***********************************************************************
654 * BringWindowToTop (USER32.@)
656 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
658 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
662 /***********************************************************************
663 * MoveWindow (USER32.@)
665 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
668 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
669 if (!repaint
) flags
|= SWP_NOREDRAW
;
670 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
671 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
675 /***********************************************************************
676 * WINPOS_RedrawIconTitle
678 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
681 WND
*win
= WIN_GetPtr( hWnd
);
683 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
685 icon_title
= win
->icon_title
;
686 WIN_ReleasePtr( win
);
688 if (!icon_title
) return FALSE
;
689 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
690 InvalidateRect( icon_title
, NULL
, TRUE
);
694 /***********************************************************************
695 * WINPOS_ShowIconTitle
697 static void WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
699 WND
*win
= WIN_GetPtr( hwnd
);
702 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
704 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return;
705 if (win
->rectWindow
.left
== -32000 || win
->rectWindow
.top
== -32000)
707 TRACE( "not showing title for hidden icon %p\n", hwnd
);
710 else title
= win
->icon_title
;
711 WIN_ReleasePtr( win
);
717 title
= ICONTITLE_Create( hwnd
);
718 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
720 DestroyWindow( title
);
723 win
->icon_title
= title
;
724 WIN_ReleasePtr( win
);
726 if (!IsWindowVisible(title
))
728 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
729 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
730 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
733 else if (title
) ShowWindow( title
, SW_HIDE
);
736 /*******************************************************************
737 * WINPOS_GetMinMaxInfo
739 * Get the minimized and maximized information for a window.
741 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
742 POINT
*minTrack
, POINT
*maxTrack
)
747 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
749 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
753 /* Compute default values */
755 GetWindowRect(hwnd
, &rc
);
756 MinMax
.ptReserved
.x
= rc
.left
;
757 MinMax
.ptReserved
.y
= rc
.top
;
759 if ((style
& WS_CAPTION
) == WS_CAPTION
)
760 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
762 adjustedStyle
= style
;
764 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
765 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
770 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
771 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
772 if (style
& (WS_DLGFRAME
| WS_BORDER
))
774 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
775 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
779 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
780 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
782 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
783 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
784 MinMax
.ptMaxPosition
.x
= -xinc
;
785 MinMax
.ptMaxPosition
.y
= -yinc
;
787 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
789 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
790 WIN_ReleasePtr( win
);
793 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
795 /* if the app didn't change the values, adapt them for the current monitor */
797 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
800 MONITORINFO mon_info
;
802 mon_info
.cbSize
= sizeof(mon_info
);
803 GetMonitorInfoW( monitor
, &mon_info
);
805 rc_work
= mon_info
.rcMonitor
;
807 if (style
& WS_MAXIMIZEBOX
)
809 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
810 rc_work
= mon_info
.rcWork
;
813 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
814 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
816 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
817 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
819 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
821 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
822 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
826 /* Some sanity checks */
828 TRACE("%d %d / %d %d / %d %d / %d %d\n",
829 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
830 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
831 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
832 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
833 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
834 MinMax
.ptMinTrackSize
.x
);
835 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
836 MinMax
.ptMinTrackSize
.y
);
838 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
839 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
840 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
841 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
845 /***********************************************************************
848 * Find a suitable place for an iconic window.
850 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
852 RECT rect
, rectParent
;
855 int x
, y
, xspacing
, yspacing
;
856 MINIMIZEDMETRICS metrics
;
858 metrics
.cbSize
= sizeof(metrics
);
859 SystemParametersInfoW( SPI_GETMINIMIZEDMETRICS
, sizeof(metrics
), &metrics
, 0 );
861 parent
= GetAncestor( hwnd
, GA_PARENT
);
862 if (parent
== GetDesktopWindow())
864 MONITORINFO mon_info
;
865 HMONITOR monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
);
867 mon_info
.cbSize
= sizeof( mon_info
);
868 GetMonitorInfoW( monitor
, &mon_info
);
869 rectParent
= mon_info
.rcWork
;
871 else GetClientRect( parent
, &rectParent
);
873 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
874 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
875 return pt
; /* The icon already has a suitable position */
877 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
878 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
880 /* Check if another icon already occupies this spot */
881 /* FIXME: this is completely inefficient */
883 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
884 tmp
= CreateRectRgn( 0, 0, 0, 0 );
885 for (child
= GetWindow( parent
, GW_CHILD
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
887 if (child
== hwnd
) continue;
888 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
890 if (WIN_GetRectangles( child
, COORDS_PARENT
, &rect
, NULL
))
892 SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
893 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
898 for (y
= 0; y
< (rectParent
.bottom
- rectParent
.top
) / yspacing
; y
++)
900 if (metrics
.iArrange
& ARW_STARTTOP
)
902 rect
.top
= rectParent
.top
+ y
* yspacing
;
903 rect
.bottom
= rect
.top
+ yspacing
;
907 rect
.bottom
= rectParent
.bottom
- y
* yspacing
;
908 rect
.top
= rect
.bottom
- yspacing
;
910 for (x
= 0; x
< (rectParent
.right
- rectParent
.left
) / xspacing
; x
++)
912 if (metrics
.iArrange
& ARW_STARTRIGHT
)
914 rect
.right
= rectParent
.right
- x
* xspacing
;
915 rect
.left
= rect
.right
- xspacing
;
919 rect
.left
= rectParent
.left
+ x
* xspacing
;
920 rect
.right
= rect
.left
+ xspacing
;
922 if (!RectInRegion( hrgn
, &rect
))
924 /* No window was found, so it's OK for us */
925 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
926 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
927 DeleteObject( hrgn
);
932 DeleteObject( hrgn
);
938 /***********************************************************************
941 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
948 TRACE("%p %u\n", hwnd
, cmd
);
950 wpl
.length
= sizeof(wpl
);
951 GetWindowPlacement( hwnd
, &wpl
);
953 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
954 return SWP_NOSIZE
| SWP_NOMOVE
;
956 if (IsIconic( hwnd
))
960 case SW_SHOWMINNOACTIVE
:
961 case SW_SHOWMINIMIZED
:
962 case SW_FORCEMINIMIZE
:
964 return SWP_NOSIZE
| SWP_NOMOVE
;
966 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
967 swpFlags
|= SWP_NOCOPYBITS
;
972 case SW_SHOWMINNOACTIVE
:
973 case SW_SHOWMINIMIZED
:
974 case SW_FORCEMINIMIZE
:
976 if (IsZoomed( hwnd
)) win_set_flags( hwnd
, WIN_RESTORE_MAX
, 0 );
977 else win_set_flags( hwnd
, 0, WIN_RESTORE_MAX
);
979 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
981 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
983 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
984 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
985 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
986 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
987 swpFlags
|= SWP_NOCOPYBITS
;
991 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
992 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
994 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
996 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
997 if (old_style
& WS_MINIMIZE
)
999 win_set_flags( hwnd
, WIN_RESTORE_MAX
, 0 );
1000 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1003 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
1004 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
1005 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
1008 case SW_SHOWNOACTIVATE
:
1009 win_set_flags( hwnd
, 0, WIN_RESTORE_MAX
);
1013 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1014 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
1015 if (old_style
& WS_MINIMIZE
)
1017 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1018 if (win_get_flags( hwnd
) & WIN_RESTORE_MAX
)
1020 /* Restore to maximized position */
1021 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1022 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
1023 swpFlags
|= SWP_STATECHANGED
;
1024 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
1025 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
1029 else if (!(old_style
& WS_MAXIMIZE
)) break;
1031 swpFlags
|= SWP_STATECHANGED
;
1033 /* Restore to normal position */
1035 *rect
= wpl
.rcNormalPosition
;
1043 /***********************************************************************
1046 * Implementation of ShowWindow and ShowWindowAsync.
1048 static BOOL
show_window( HWND hwnd
, INT cmd
)
1052 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1053 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
1054 BOOL showFlag
= TRUE
;
1055 RECT newPos
= {0, 0, 0, 0};
1058 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
1063 if (!wasVisible
) return FALSE
;
1065 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1066 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1069 case SW_SHOWMINNOACTIVE
:
1071 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1072 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1074 case SW_SHOWMINIMIZED
:
1075 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1076 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1077 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
1080 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1081 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1082 swp
|= SWP_FRAMECHANGED
;
1083 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1084 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
1088 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1089 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
1092 if (wasVisible
) return TRUE
;
1093 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1094 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1097 case SW_SHOWNOACTIVATE
:
1098 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1102 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1103 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1104 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1105 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1107 swp
|= SWP_FRAMECHANGED
;
1108 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1112 if (wasVisible
) return TRUE
;
1113 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1115 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1121 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1123 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1124 if (!IsWindow( hwnd
)) return wasVisible
;
1127 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1129 parent
= GetAncestor( hwnd
, GA_PARENT
);
1130 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1132 /* if parent is not visible simply toggle WS_VISIBLE and return */
1133 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1134 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1137 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1138 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1144 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1146 /* FIXME: This will cause the window to be activated irrespective
1147 * of whether it is owned by the same thread. Has to be done
1151 if (hwnd
== GetActiveWindow())
1152 WINPOS_ActivateOtherWindow(hwnd
);
1154 /* Revert focus to parent */
1155 hFocus
= GetFocus();
1158 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1159 if (parent
== GetDesktopWindow()) parent
= 0;
1165 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1167 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1169 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1171 /* should happen only in CreateWindowEx() */
1172 int wParam
= SIZE_RESTORED
;
1176 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &client
);
1177 lparam
= MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
);
1178 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1179 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1180 else if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1182 wParam
= SIZE_MINIMIZED
;
1185 WIN_ReleasePtr( wndPtr
);
1187 SendMessageW( hwnd
, WM_SIZE
, wParam
, lparam
);
1188 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1190 else WIN_ReleasePtr( wndPtr
);
1192 /* if previous state was minimized Windows sets focus to the window */
1193 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1199 /***********************************************************************
1200 * ShowWindowAsync (USER32.@)
1202 * doesn't wait; returns immediately.
1203 * used by threads to toggle windows in other (possibly hanging) threads
1205 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1209 if (is_broadcast(hwnd
))
1211 SetLastError( ERROR_INVALID_PARAMETER
);
1215 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1216 return show_window( full_handle
, cmd
);
1218 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1222 /***********************************************************************
1223 * ShowWindow (USER32.@)
1225 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1229 if (is_broadcast(hwnd
))
1231 SetLastError( ERROR_INVALID_PARAMETER
);
1234 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1235 return show_window( full_handle
, cmd
);
1237 if ((cmd
== SW_HIDE
) && !(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1240 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1244 /***********************************************************************
1245 * GetInternalWindowPos (USER32.@)
1247 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1250 WINDOWPLACEMENT wndpl
;
1251 if (GetWindowPlacement( hwnd
, &wndpl
))
1253 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1254 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1255 return wndpl
.showCmd
;
1261 /***********************************************************************
1262 * GetWindowPlacement (USER32.@)
1265 * Fails if wndpl->length of Win95 (!) apps is invalid.
1267 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1269 WND
*pWnd
= WIN_GetPtr( hwnd
);
1271 if (!pWnd
) return FALSE
;
1273 if (pWnd
== WND_DESKTOP
)
1275 wndpl
->length
= sizeof(*wndpl
);
1276 wndpl
->showCmd
= SW_SHOWNORMAL
;
1278 wndpl
->ptMinPosition
.x
= -1;
1279 wndpl
->ptMinPosition
.y
= -1;
1280 wndpl
->ptMaxPosition
.x
= -1;
1281 wndpl
->ptMaxPosition
.y
= -1;
1282 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1285 if (pWnd
== WND_OTHER_PROCESS
)
1287 if (!IsWindow( hwnd
)) return FALSE
;
1288 FIXME( "not supported on other process window %p\n", hwnd
);
1289 /* provide some dummy information */
1290 wndpl
->length
= sizeof(*wndpl
);
1291 wndpl
->showCmd
= SW_SHOWNORMAL
;
1293 wndpl
->ptMinPosition
.x
= -1;
1294 wndpl
->ptMinPosition
.y
= -1;
1295 wndpl
->ptMaxPosition
.x
= -1;
1296 wndpl
->ptMaxPosition
.y
= -1;
1297 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1301 /* update the placement according to the current style */
1302 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1304 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1305 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1307 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1309 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1310 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1314 pWnd
->normal_rect
= pWnd
->rectWindow
;
1317 wndpl
->length
= sizeof(*wndpl
);
1318 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1319 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1321 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1322 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1323 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1326 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1327 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1328 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1329 WIN_ReleasePtr( pWnd
);
1331 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1332 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1333 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1334 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1338 /* make sure the specified rect is visible on screen */
1339 static void make_rect_onscreen( RECT
*rect
)
1342 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1344 info
.cbSize
= sizeof(info
);
1345 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1346 /* FIXME: map coordinates from rcWork to rcMonitor */
1347 if (rect
->right
<= info
.rcWork
.left
)
1349 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1350 rect
->left
= info
.rcWork
.left
;
1352 else if (rect
->left
>= info
.rcWork
.right
)
1354 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1355 rect
->right
= info
.rcWork
.right
;
1357 if (rect
->bottom
<= info
.rcWork
.top
)
1359 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1360 rect
->top
= info
.rcWork
.top
;
1362 else if (rect
->top
>= info
.rcWork
.bottom
)
1364 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1365 rect
->bottom
= info
.rcWork
.bottom
;
1369 /* make sure the specified point is visible on screen */
1370 static void make_point_onscreen( POINT
*pt
)
1374 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1375 make_rect_onscreen( &rect
);
1381 /***********************************************************************
1382 * WINPOS_SetPlacement
1384 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1387 WND
*pWnd
= WIN_GetPtr( hwnd
);
1388 WINDOWPLACEMENT wp
= *wndpl
;
1390 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1391 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1392 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1394 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1395 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1396 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1397 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1398 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1399 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1401 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1403 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1404 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1405 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1407 style
= pWnd
->dwStyle
;
1409 WIN_ReleasePtr( pWnd
);
1411 if( style
& WS_MINIMIZE
)
1413 if (flags
& PLACE_MIN
)
1415 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1416 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1417 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1420 else if( style
& WS_MAXIMIZE
)
1422 if (flags
& PLACE_MAX
)
1423 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1424 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1426 else if( flags
& PLACE_RECT
)
1427 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1428 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1429 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1430 SWP_NOZORDER
| SWP_NOACTIVATE
);
1432 ShowWindow( hwnd
, wndpl
->showCmd
);
1434 if (IsIconic( hwnd
))
1436 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1438 /* SDK: ...valid only the next time... */
1439 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1440 win_set_flags( hwnd
, WIN_RESTORE_MAX
, 0 );
1446 /***********************************************************************
1447 * SetWindowPlacement (USER32.@)
1450 * Fails if wndpl->length of Win95 (!) apps is invalid.
1452 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1454 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1455 if (!wpl
) return FALSE
;
1456 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1457 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1461 /***********************************************************************
1462 * AnimateWindow (USER32.@)
1463 * Shows/Hides a window with an animation
1466 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1468 FIXME("partial stub\n");
1470 /* If trying to show/hide and it's already *
1471 * shown/hidden or invalid window, fail with *
1472 * invalid parameter */
1473 if(!IsWindow(hwnd
) ||
1474 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1475 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1477 SetLastError(ERROR_INVALID_PARAMETER
);
1481 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1486 /***********************************************************************
1487 * SetInternalWindowPos (USER32.@)
1489 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1490 LPRECT rect
, LPPOINT pt
)
1492 WINDOWPLACEMENT wndpl
;
1495 wndpl
.length
= sizeof(wndpl
);
1496 wndpl
.showCmd
= showCmd
;
1497 wndpl
.flags
= flags
= 0;
1502 wndpl
.flags
|= WPF_SETMINPOSITION
;
1503 wndpl
.ptMinPosition
= *pt
;
1507 flags
|= PLACE_RECT
;
1508 wndpl
.rcNormalPosition
= *rect
;
1510 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1514 /*******************************************************************
1515 * can_activate_window
1517 * Check if we can activate the specified window.
1519 static BOOL
can_activate_window( HWND hwnd
)
1523 if (!hwnd
) return FALSE
;
1524 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1525 if (!(style
& WS_VISIBLE
)) return FALSE
;
1526 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1527 return !(style
& WS_DISABLED
);
1531 /*******************************************************************
1532 * WINPOS_ActivateOtherWindow
1534 * Activates window other than pWnd.
1536 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1540 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1542 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1543 if (can_activate_window( hwndTo
)) goto done
;
1549 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1550 if (can_activate_window( hwndTo
)) goto done
;
1553 hwndTo
= GetTopWindow( 0 );
1561 if (can_activate_window( hwndTo
)) goto done
;
1562 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1566 fg
= GetForegroundWindow();
1567 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1568 if (!fg
|| (hwnd
== fg
))
1570 if (SetForegroundWindow( hwndTo
)) return;
1572 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1576 /***********************************************************************
1577 * WINPOS_HandleWindowPosChanging
1579 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1581 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1583 POINT minTrack
, maxTrack
;
1584 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1586 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1587 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1589 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1590 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1591 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1592 if (!(style
& WS_MINIMIZE
))
1594 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1595 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1602 /***********************************************************************
1605 static void dump_winpos_flags(UINT flags
)
1607 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1608 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1609 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1610 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1611 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1613 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1614 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1615 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1616 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1617 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1618 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1619 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1620 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1621 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1622 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1623 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1624 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1625 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1626 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1627 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1628 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1630 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1634 /***********************************************************************
1635 * SWP_DoWinPosChanging
1637 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1640 RECT window_rect
, client_rect
;
1642 /* Send WM_WINDOWPOSCHANGING message */
1644 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1645 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1647 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1648 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1650 /* Calculate new position and size */
1652 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1653 *pNewWindowRect
= window_rect
;
1654 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? window_rect
: client_rect
;
1656 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1658 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1660 pNewWindowRect
->right
= pNewWindowRect
->left
+ GetSystemMetrics(SM_CXICON
);
1661 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ GetSystemMetrics(SM_CYICON
);
1665 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1666 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1669 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1671 pNewWindowRect
->left
= pWinpos
->x
;
1672 pNewWindowRect
->top
= pWinpos
->y
;
1673 pNewWindowRect
->right
+= pWinpos
->x
- window_rect
.left
;
1674 pNewWindowRect
->bottom
+= pWinpos
->y
- window_rect
.top
;
1676 OffsetRect( pNewClientRect
, pWinpos
->x
- window_rect
.left
,
1677 pWinpos
->y
- window_rect
.top
);
1679 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1681 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1682 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1683 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1684 TRACE( "current %s style %08x new %s\n",
1685 wine_dbgstr_rect( &window_rect
), wndPtr
->dwStyle
,
1686 wine_dbgstr_rect( pNewWindowRect
));
1688 WIN_ReleasePtr( wndPtr
);
1692 /***********************************************************************
1695 * Compute the valid rects from the old and new client rect and WVR_* flags.
1696 * Helper for WM_NCCALCSIZE handling.
1698 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1703 if (flags
& WVR_REDRAW
)
1705 SetRectEmpty( &valid
[0] );
1706 SetRectEmpty( &valid
[1] );
1710 if (flags
& WVR_VALIDRECTS
)
1712 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1713 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1715 SetRectEmpty( &valid
[0] );
1716 SetRectEmpty( &valid
[1] );
1719 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1723 valid
[0] = *new_client
;
1724 valid
[1] = *old_client
;
1727 /* make sure the rectangles have the same size */
1728 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1729 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1731 if (flags
& WVR_ALIGNBOTTOM
)
1733 valid
[0].top
= valid
[0].bottom
- cy
;
1734 valid
[1].top
= valid
[1].bottom
- cy
;
1738 valid
[0].bottom
= valid
[0].top
+ cy
;
1739 valid
[1].bottom
= valid
[1].top
+ cy
;
1741 if (flags
& WVR_ALIGNRIGHT
)
1743 valid
[0].left
= valid
[0].right
- cx
;
1744 valid
[1].left
= valid
[1].right
- cx
;
1748 valid
[0].right
= valid
[0].left
+ cx
;
1749 valid
[1].right
= valid
[1].left
+ cx
;
1754 /***********************************************************************
1757 * fix Z order taking into account owned popups -
1758 * basically we need to maintain them above the window that owns them
1760 * FIXME: hide/show owned popups when owner visibility changes.
1762 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1764 HWND owner
, *list
= NULL
;
1767 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1769 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return hwndInsertAfter
;
1771 if ((owner
= GetWindow( hwnd
, GW_OWNER
)))
1773 /* make sure this popup stays above the owner */
1775 if (hwndInsertAfter
!= HWND_TOPMOST
)
1777 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1779 for (i
= 0; list
[i
]; i
++)
1781 BOOL topmost
= (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1783 if (list
[i
] == owner
)
1785 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1786 else hwndInsertAfter
= topmost
? HWND_TOPMOST
: HWND_TOP
;
1790 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1792 if (!topmost
) break;
1794 else if (list
[i
] == hwndInsertAfter
) break;
1799 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1800 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1803 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1805 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1807 /* skip all the topmost windows */
1808 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1811 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1813 /* skip windows that are already placed correctly */
1814 for (i
= 0; list
[i
]; i
++)
1816 if (list
[i
] == hwndInsertAfter
) break;
1817 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1821 for ( ; list
[i
]; i
++)
1823 if (list
[i
] == hwnd
) break;
1824 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1825 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1826 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1827 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1828 hwndInsertAfter
= list
[i
];
1832 HeapFree( GetProcessHeap(), 0, list
);
1833 return hwndInsertAfter
;
1836 /***********************************************************************
1839 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1843 RECT window_rect
, client_rect
;
1845 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1847 /* Send WM_NCCALCSIZE message to get new client area */
1848 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1850 NCCALCSIZE_PARAMS params
;
1851 WINDOWPOS winposCopy
;
1853 params
.rgrc
[0] = *pNewWindowRect
;
1854 params
.rgrc
[1] = window_rect
;
1855 params
.rgrc
[2] = client_rect
;
1856 params
.lppos
= &winposCopy
;
1857 winposCopy
= *pWinpos
;
1859 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1861 *pNewClientRect
= params
.rgrc
[0];
1863 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1864 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
),
1865 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1867 if( pNewClientRect
->left
!= client_rect
.left
||
1868 pNewClientRect
->top
!= client_rect
.top
)
1869 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1871 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1872 client_rect
.right
- client_rect
.left
))
1873 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1875 wvrFlags
&= ~WVR_HREDRAW
;
1877 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1878 client_rect
.bottom
- client_rect
.top
)
1879 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1881 wvrFlags
&= ~WVR_VREDRAW
;
1883 validRects
[0] = params
.rgrc
[1];
1884 validRects
[1] = params
.rgrc
[2];
1888 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1889 (pNewClientRect
->left
!= client_rect
.left
||
1890 pNewClientRect
->top
!= client_rect
.top
))
1891 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1894 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1896 SetRectEmpty( &validRects
[0] );
1897 SetRectEmpty( &validRects
[1] );
1899 else get_valid_rects( &client_rect
, pNewClientRect
, wvrFlags
, validRects
);
1904 /* fix redundant flags and values in the WINDOWPOS structure */
1905 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1910 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1913 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1915 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1918 winpos
->hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
1920 /* Finally make sure that all coordinates are valid */
1921 if (winpos
->x
< -32768) winpos
->x
= -32768;
1922 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1923 if (winpos
->y
< -32768) winpos
->y
= -32768;
1924 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1926 if (winpos
->cx
< 0) winpos
->cx
= 0;
1927 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1928 if (winpos
->cy
< 0) winpos
->cy
= 0;
1929 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1931 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1932 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1934 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1937 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1938 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1941 WIN_GetRectangles( winpos
->hwnd
, COORDS_SCREEN
, &window_rect
, NULL
);
1942 if ((window_rect
.right
- window_rect
.left
== winpos
->cx
) &&
1943 (window_rect
.bottom
- window_rect
.top
== winpos
->cy
))
1944 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1948 ClientToScreen( parent
, &pt
);
1949 if ((window_rect
.left
== pt
.x
) && (window_rect
.top
== pt
.y
))
1950 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1952 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1954 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1955 (winpos
->flags
& SWP_NOZORDER
||
1956 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1958 winpos
->flags
&= ~SWP_NOZORDER
;
1959 winpos
->hwndInsertAfter
= HWND_TOP
;
1963 /* Check hwndInsertAfter */
1964 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1966 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1968 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1969 winpos
->flags
|= SWP_NOZORDER
;
1971 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1973 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1974 winpos
->flags
|= SWP_NOZORDER
;
1976 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1978 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1979 winpos
->flags
|= SWP_NOZORDER
;
1981 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1983 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1984 winpos
->flags
|= SWP_NOZORDER
;
1988 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1989 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1990 winpos
->flags
|= SWP_NOZORDER
;
1993 WIN_ReleasePtr( wndPtr
);
1998 /***********************************************************************
1999 * update_surface_region
2001 static void update_surface_region( HWND hwnd
)
2007 WND
*win
= WIN_GetPtr( hwnd
);
2009 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return;
2010 if (!win
->surface
) goto done
;
2014 if (!(data
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( RGNDATA
, Buffer
[size
] )))) goto done
;
2016 SERVER_START_REQ( get_surface_region
)
2018 req
->window
= wine_server_user_handle( hwnd
);
2019 wine_server_set_reply( req
, data
->Buffer
, size
);
2020 if (!(status
= wine_server_call( req
)))
2022 size_t reply_size
= wine_server_reply_size( reply
);
2025 data
->rdh
.dwSize
= sizeof(data
->rdh
);
2026 data
->rdh
.iType
= RDH_RECTANGLES
;
2027 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
2028 data
->rdh
.nRgnSize
= reply_size
;
2029 region
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
);
2030 OffsetRgn( region
, -reply
->visible_rect
.left
, -reply
->visible_rect
.top
);
2033 else size
= reply
->total_size
;
2036 HeapFree( GetProcessHeap(), 0, data
);
2037 } while (status
== STATUS_BUFFER_OVERFLOW
);
2039 if (status
) goto done
;
2041 win
->surface
->funcs
->set_region( win
->surface
, region
);
2042 if (region
) DeleteObject( region
);
2045 WIN_ReleasePtr( win
);
2049 /***********************************************************************
2052 * Backend implementation of SetWindowPos.
2054 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2055 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
2058 HWND surface_win
= 0, parent
= GetAncestor( hwnd
, GA_PARENT
);
2061 RECT visible_rect
, old_visible_rect
, old_window_rect
;
2062 struct window_surface
*old_surface
, *new_surface
= NULL
;
2064 if (!parent
|| parent
== GetDesktopWindow())
2066 new_surface
= &dummy_surface
; /* provide a default surface for top-level windows */
2067 window_surface_add_ref( new_surface
);
2069 visible_rect
= *window_rect
;
2070 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
2071 window_rect
, client_rect
, &visible_rect
, &new_surface
);
2073 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_window_rect
, NULL
);
2075 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
2077 if (new_surface
) window_surface_release( new_surface
);
2080 old_width
= win
->rectClient
.right
- win
->rectClient
.left
;
2081 old_visible_rect
= win
->visible_rect
;
2082 old_surface
= win
->surface
;
2083 if (old_surface
!= new_surface
) swp_flags
|= SWP_FRAMECHANGED
; /* force refreshing non-client area */
2085 SERVER_START_REQ( set_window_pos
)
2087 req
->handle
= wine_server_user_handle( hwnd
);
2088 req
->previous
= wine_server_user_handle( insert_after
);
2089 req
->swp_flags
= swp_flags
;
2090 req
->window
.left
= window_rect
->left
;
2091 req
->window
.top
= window_rect
->top
;
2092 req
->window
.right
= window_rect
->right
;
2093 req
->window
.bottom
= window_rect
->bottom
;
2094 req
->client
.left
= client_rect
->left
;
2095 req
->client
.top
= client_rect
->top
;
2096 req
->client
.right
= client_rect
->right
;
2097 req
->client
.bottom
= client_rect
->bottom
;
2098 if (!EqualRect( window_rect
, &visible_rect
) || !IsRectEmpty( &valid_rects
[0] ))
2100 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
2101 if (!IsRectEmpty( &valid_rects
[0] ))
2102 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
2104 if (new_surface
) req
->paint_flags
|= SET_WINPOS_PAINT_SURFACE
;
2105 if (win
->pixel_format
) req
->paint_flags
|= SET_WINPOS_PIXEL_FORMAT
;
2107 if ((ret
= !wine_server_call( req
)))
2109 win
->dwStyle
= reply
->new_style
;
2110 win
->dwExStyle
= reply
->new_ex_style
;
2111 win
->rectWindow
= *window_rect
;
2112 win
->rectClient
= *client_rect
;
2113 win
->visible_rect
= visible_rect
;
2114 win
->surface
= new_surface
;
2115 surface_win
= wine_server_ptr_handle( reply
->surface_win
);
2116 if (GetWindowLongW( win
->parent
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
)
2119 GetClientRect( win
->parent
, &client
);
2120 mirror_rect( &client
, &win
->rectWindow
);
2121 mirror_rect( &client
, &win
->rectClient
);
2122 mirror_rect( &client
, &win
->visible_rect
);
2124 /* if an RTL window is resized the children have moved */
2125 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
&& client_rect
->right
- client_rect
->left
!= old_width
)
2126 win
->flags
|= WIN_CHILDREN_MOVED
;
2133 if (surface_win
) update_surface_region( surface_win
);
2134 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
2135 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
| SWP_FRAMECHANGED
)))
2136 invalidate_dce( win
, &old_window_rect
);
2139 WIN_ReleasePtr( win
);
2143 TRACE( "win %p surface %p -> %p\n", hwnd
, old_surface
, new_surface
);
2144 register_window_surface( old_surface
, new_surface
);
2147 if (!IsRectEmpty( valid_rects
))
2149 move_window_bits( hwnd
, old_surface
, new_surface
, &visible_rect
,
2150 &old_visible_rect
, client_rect
, valid_rects
);
2151 valid_rects
= NULL
; /* prevent the driver from trying to also move the bits */
2153 window_surface_release( old_surface
);
2155 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
2156 client_rect
, &visible_rect
, valid_rects
, new_surface
);
2158 else if (new_surface
) window_surface_release( new_surface
);
2164 /***********************************************************************
2167 * User32 internal function
2169 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
2171 RECT newWindowRect
, newClientRect
, valid_rects
[2];
2174 orig_flags
= winpos
->flags
;
2176 /* First, check z-order arguments. */
2177 if (!(winpos
->flags
& SWP_NOZORDER
))
2179 /* fix sign extension */
2180 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
2181 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
2183 if (!(winpos
->hwndInsertAfter
== HWND_TOP
||
2184 winpos
->hwndInsertAfter
== HWND_BOTTOM
||
2185 winpos
->hwndInsertAfter
== HWND_TOPMOST
||
2186 winpos
->hwndInsertAfter
== HWND_NOTOPMOST
))
2188 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2189 HWND insertafter_parent
= GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
);
2191 /* hwndInsertAfter must be a sibling of the window */
2192 if (!insertafter_parent
) return FALSE
;
2193 if (insertafter_parent
!= parent
) return TRUE
;
2197 /* Make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
2198 if (!(winpos
->flags
& SWP_NOMOVE
))
2200 if (winpos
->x
< -32768) winpos
->x
= -32768;
2201 else if (winpos
->x
> 32767) winpos
->x
= 32767;
2202 if (winpos
->y
< -32768) winpos
->y
= -32768;
2203 else if (winpos
->y
> 32767) winpos
->y
= 32767;
2205 if (!(winpos
->flags
& SWP_NOSIZE
))
2207 if (winpos
->cx
< 0) winpos
->cx
= 0;
2208 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
2209 if (winpos
->cy
< 0) winpos
->cy
= 0;
2210 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
2213 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
2215 /* Fix redundant flags */
2216 if (!fixup_flags( winpos
)) return FALSE
;
2218 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
2220 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
2221 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
2224 /* Common operations */
2226 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
2228 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
2229 &newWindowRect
, &newClientRect
, valid_rects
))
2232 /* erase parent when hiding or resizing child */
2233 if (!(orig_flags
& SWP_DEFERERASE
) &&
2234 ((orig_flags
& SWP_HIDEWINDOW
) ||
2235 (!(orig_flags
& SWP_SHOWWINDOW
) &&
2236 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
2238 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2239 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
2240 erase_now( parent
, 0 );
2243 if( winpos
->flags
& SWP_HIDEWINDOW
)
2244 HideCaret(winpos
->hwnd
);
2245 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2246 ShowCaret(winpos
->hwnd
);
2248 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2250 /* child windows get WM_CHILDACTIVATE message */
2251 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2252 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2254 SetForegroundWindow( winpos
->hwnd
);
2257 /* And last, send the WM_WINDOWPOSCHANGED message */
2259 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2261 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2263 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2264 and always contains final window position.
2266 winpos
->x
= newWindowRect
.left
;
2267 winpos
->y
= newWindowRect
.top
;
2268 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2269 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2270 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2275 /***********************************************************************
2276 * SetWindowPos (USER32.@)
2278 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2279 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2283 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2284 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2285 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2287 if (is_broadcast(hwnd
))
2289 SetLastError( ERROR_INVALID_PARAMETER
);
2293 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2294 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2299 winpos
.flags
= flags
;
2301 if (WIN_IsCurrentThread( hwnd
))
2302 return USER_SetWindowPos(&winpos
);
2304 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2308 /***********************************************************************
2309 * BeginDeferWindowPos (USER32.@)
2311 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2316 TRACE("%d\n", count
);
2320 SetLastError(ERROR_INVALID_PARAMETER
);
2323 /* Windows allows zero count, in which case it allocates context for 8 moves */
2324 if (count
== 0) count
= 8;
2326 if (!(pDWP
= HeapAlloc( GetProcessHeap(), 0, sizeof(DWP
)))) return 0;
2328 pDWP
->actualCount
= 0;
2329 pDWP
->suggestedCount
= count
;
2330 pDWP
->hwndParent
= 0;
2332 if (!(pDWP
->winPos
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(WINDOWPOS
) )) ||
2333 !(handle
= alloc_user_handle( &pDWP
->obj
, USER_DWP
)))
2335 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2336 HeapFree( GetProcessHeap(), 0, pDWP
);
2339 TRACE("returning hdwp %p\n", handle
);
2344 /***********************************************************************
2345 * DeferWindowPos (USER32.@)
2347 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2348 INT x
, INT y
, INT cx
, INT cy
,
2353 HDWP retvalue
= hdwp
;
2355 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2356 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2358 hwnd
= WIN_GetFullHandle( hwnd
);
2359 if (is_desktop_window( hwnd
) || !IsWindow( hwnd
))
2361 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2365 if (!(pDWP
= get_user_handle_ptr( hdwp
, USER_DWP
))) return 0;
2366 if (pDWP
== OBJ_OTHER_PROCESS
)
2368 FIXME( "other process handle %p?\n", hdwp
);
2372 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2374 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2376 /* Merge with the other changes */
2377 if (!(flags
& SWP_NOZORDER
))
2379 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2381 if (!(flags
& SWP_NOMOVE
))
2383 pDWP
->winPos
[i
].x
= x
;
2384 pDWP
->winPos
[i
].y
= y
;
2386 if (!(flags
& SWP_NOSIZE
))
2388 pDWP
->winPos
[i
].cx
= cx
;
2389 pDWP
->winPos
[i
].cy
= cy
;
2391 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2392 SWP_NOZORDER
| SWP_NOREDRAW
|
2393 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2395 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2400 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2402 WINDOWPOS
*newpos
= HeapReAlloc( GetProcessHeap(), 0, pDWP
->winPos
,
2403 pDWP
->suggestedCount
* 2 * sizeof(WINDOWPOS
) );
2409 pDWP
->suggestedCount
*= 2;
2410 pDWP
->winPos
= newpos
;
2412 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2413 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2414 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2415 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2416 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2417 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2418 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2419 pDWP
->actualCount
++;
2421 release_user_handle_ptr( pDWP
);
2426 /***********************************************************************
2427 * EndDeferWindowPos (USER32.@)
2429 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2436 TRACE("%p\n", hdwp
);
2438 if (!(pDWP
= free_user_handle( hdwp
, USER_DWP
))) return FALSE
;
2439 if (pDWP
== OBJ_OTHER_PROCESS
)
2441 FIXME( "other process handle %p?\n", hdwp
);
2445 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2447 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2448 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2449 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2451 if (WIN_IsCurrentThread( winpos
->hwnd
))
2452 res
= USER_SetWindowPos( winpos
);
2454 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2456 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2457 HeapFree( GetProcessHeap(), 0, pDWP
);
2462 /***********************************************************************
2463 * ArrangeIconicWindows (USER32.@)
2465 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2469 INT x
, y
, xspacing
, yspacing
;
2471 MINIMIZEDMETRICS metrics
;
2473 metrics
.cbSize
= sizeof(metrics
);
2474 SystemParametersInfoW( SPI_GETMINIMIZEDMETRICS
, sizeof(metrics
), &metrics
, 0 );
2476 if (parent
== GetDesktopWindow())
2478 MONITORINFO mon_info
;
2479 HMONITOR monitor
= MonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY
);
2481 mon_info
.cbSize
= sizeof( mon_info
);
2482 GetMonitorInfoW( monitor
, &mon_info
);
2483 rectParent
= mon_info
.rcWork
;
2485 else GetClientRect( parent
, &rectParent
);
2488 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2489 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2491 hwndChild
= GetWindow( parent
, GW_CHILD
);
2494 if( IsIconic( hwndChild
) )
2496 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2498 if (metrics
.iArrange
& ARW_STARTRIGHT
)
2499 pt
.x
= rectParent
.right
- (x
+ 1) * xspacing
;
2501 pt
.x
= rectParent
.left
+ x
* xspacing
;
2502 if (metrics
.iArrange
& ARW_STARTTOP
)
2503 pt
.y
= rectParent
.top
+ y
* yspacing
;
2505 pt
.y
= rectParent
.bottom
- (y
+ 1) * yspacing
;
2507 SetWindowPos( hwndChild
, 0, pt
.x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2508 pt
.y
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2, 0, 0,
2509 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2510 if( IsWindow(hwndChild
) )
2511 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2513 if (++x
>= (rectParent
.right
- rectParent
.left
) / xspacing
)
2519 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2525 /***********************************************************************
2528 * Draw the frame used when moving or resizing window.
2530 static void draw_moving_frame( HWND parent
, HDC hdc
, RECT
*screen_rect
, BOOL thickframe
)
2532 RECT rect
= *screen_rect
;
2534 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2537 const int width
= GetSystemMetrics(SM_CXFRAME
);
2538 const int height
= GetSystemMetrics(SM_CYFRAME
);
2540 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2541 PatBlt( hdc
, rect
.left
, rect
.top
,
2542 rect
.right
- rect
.left
- width
, height
, PATINVERT
);
2543 PatBlt( hdc
, rect
.left
, rect
.top
+ height
, width
,
2544 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2545 PatBlt( hdc
, rect
.left
+ width
, rect
.bottom
- 1,
2546 rect
.right
- rect
.left
- width
, -height
, PATINVERT
);
2547 PatBlt( hdc
, rect
.right
- 1, rect
.top
, -width
,
2548 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2549 SelectObject( hdc
, hbrush
);
2551 else DrawFocusRect( hdc
, &rect
);
2555 /***********************************************************************
2558 * Initialization of a move or resize, when initiated from a menu choice.
2559 * Return hit test code for caption or sizing border.
2561 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2568 GetWindowRect( hwnd
, &rectWindow
);
2570 if ((wParam
& 0xfff0) == SC_MOVE
)
2572 /* Move pointer at the center of the caption */
2573 RECT rect
= rectWindow
;
2574 /* Note: to be exactly centered we should take the different types
2575 * of border into account, but it shouldn't make more than a few pixels
2576 * of difference so let's not bother with that */
2577 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2578 if (style
& WS_SYSMENU
)
2579 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2580 if (style
& WS_MINIMIZEBOX
)
2581 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2582 if (style
& WS_MAXIMIZEBOX
)
2583 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2584 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2585 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2586 hittest
= HTCAPTION
;
2591 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2595 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2596 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2601 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2602 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2603 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2604 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2615 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2616 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2620 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2621 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2625 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2626 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2630 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2631 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2639 TranslateMessage( &msg
);
2640 DispatchMessageW( &msg
);
2646 SetCursorPos( pt
.x
, pt
.y
);
2647 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2652 /***********************************************************************
2653 * WINPOS_SysCommandSizeMove
2655 * Perform SC_MOVE and SC_SIZE commands.
2657 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2660 RECT sizingRect
, mouseRect
, origRect
;
2663 LONG hittest
= (LONG
)(wParam
& 0x0f);
2664 WPARAM syscommand
= wParam
& 0xfff0;
2665 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2666 POINT minTrack
, maxTrack
;
2667 POINT capturePoint
, pt
;
2668 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2669 BOOL thickframe
= HAS_THICKFRAME( style
);
2670 BOOL iconic
= style
& WS_MINIMIZE
;
2672 DWORD dwPoint
= GetMessagePos ();
2673 BOOL DragFullWindows
= TRUE
;
2676 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2678 pt
.x
= (short)LOWORD(dwPoint
);
2679 pt
.y
= (short)HIWORD(dwPoint
);
2683 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2684 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2686 if (syscommand
== SC_MOVE
)
2688 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2689 if (!hittest
) return;
2693 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2694 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2697 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2698 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2701 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2707 /* Get min/max info */
2709 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2710 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &sizingRect
, NULL
);
2711 origRect
= sizingRect
;
2712 if (style
& WS_CHILD
)
2714 parent
= GetParent(hwnd
);
2715 GetClientRect( parent
, &mouseRect
);
2716 MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2717 MapWindowPoints( parent
, 0, (LPPOINT
)&sizingRect
, 2 );
2722 mouseRect
= get_virtual_screen_rect();
2723 mon
= MonitorFromPoint( pt
, MONITOR_DEFAULTTONEAREST
);
2726 if (ON_LEFT_BORDER(hittest
))
2728 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
+capturePoint
.x
-sizingRect
.left
);
2729 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
+capturePoint
.x
-sizingRect
.left
);
2731 else if (ON_RIGHT_BORDER(hittest
))
2733 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
+capturePoint
.x
-sizingRect
.right
);
2734 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
+capturePoint
.x
-sizingRect
.right
);
2736 if (ON_TOP_BORDER(hittest
))
2738 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
+capturePoint
.y
-sizingRect
.top
);
2739 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
+capturePoint
.y
-sizingRect
.top
);
2741 else if (ON_BOTTOM_BORDER(hittest
))
2743 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
+capturePoint
.y
-sizingRect
.bottom
);
2744 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
+capturePoint
.y
-sizingRect
.bottom
);
2747 /* Retrieve a default cache DC (without using the window style) */
2748 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2750 if( iconic
) /* create a cursor for dragging */
2752 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2753 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2754 if( !hDragCursor
) iconic
= FALSE
;
2757 /* we only allow disabling the full window drag for child windows */
2758 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2760 /* repaint the window before moving it around */
2761 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2763 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2764 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2770 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2771 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2773 /* Exit on button-up, Return, or Esc */
2774 if ((msg
.message
== WM_LBUTTONUP
) ||
2775 ((msg
.message
== WM_KEYDOWN
) &&
2776 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2778 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2780 TranslateMessage( &msg
);
2781 DispatchMessageW( &msg
);
2782 continue; /* We are not interested in other messages */
2787 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2789 case VK_UP
: pt
.y
-= 8; break;
2790 case VK_DOWN
: pt
.y
+= 8; break;
2791 case VK_LEFT
: pt
.x
-= 8; break;
2792 case VK_RIGHT
: pt
.x
+= 8; break;
2795 pt
.x
= max( pt
.x
, mouseRect
.left
);
2796 pt
.x
= min( pt
.x
, mouseRect
.right
- 1 );
2797 pt
.y
= max( pt
.y
, mouseRect
.top
);
2798 pt
.y
= min( pt
.y
, mouseRect
.bottom
- 1 );
2805 if ((newmon
= MonitorFromPoint( pt
, MONITOR_DEFAULTTONULL
)))
2808 info
.cbSize
= sizeof(info
);
2809 if (mon
&& GetMonitorInfoW( mon
, &info
))
2811 pt
.x
= max( pt
.x
, info
.rcWork
.left
);
2812 pt
.x
= min( pt
.x
, info
.rcWork
.right
- 1 );
2813 pt
.y
= max( pt
.y
, info
.rcWork
.top
);
2814 pt
.y
= min( pt
.y
, info
.rcWork
.bottom
- 1 );
2818 dx
= pt
.x
- capturePoint
.x
;
2819 dy
= pt
.y
- capturePoint
.y
;
2827 if( iconic
) /* ok, no system popup tracking */
2829 hOldCursor
= SetCursor(hDragCursor
);
2831 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2833 else if(!DragFullWindows
)
2834 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2837 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2840 if(!iconic
&& !DragFullWindows
) draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2841 if (hittest
== HTCAPTION
) OffsetRect( &sizingRect
, dx
, dy
);
2842 if (ON_LEFT_BORDER(hittest
)) sizingRect
.left
+= dx
;
2843 else if (ON_RIGHT_BORDER(hittest
)) sizingRect
.right
+= dx
;
2844 if (ON_TOP_BORDER(hittest
)) sizingRect
.top
+= dy
;
2845 else if (ON_BOTTOM_BORDER(hittest
)) sizingRect
.bottom
+= dy
;
2848 /* determine the hit location */
2849 if (syscommand
== SC_SIZE
)
2851 WPARAM wpSizingHit
= 0;
2853 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2854 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2855 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&sizingRect
);
2858 SendMessageW( hwnd
, WM_MOVING
, 0, (LPARAM
)&sizingRect
);
2862 if(!DragFullWindows
)
2863 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2866 RECT rect
= sizingRect
;
2867 MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2868 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
2869 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2870 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2879 if( moved
) /* restore cursors, show icon title later on */
2881 ShowCursor( FALSE
);
2882 SetCursor( hOldCursor
);
2885 else if (moved
&& !DragFullWindows
)
2887 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2890 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2891 ReleaseDC( parent
, hdc
);
2892 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2894 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2897 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2898 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2900 /* window moved or resized */
2903 /* if the moving/resizing isn't canceled call SetWindowPos
2904 * with the new position or the new size of the window
2906 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2908 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2909 if(!DragFullWindows
|| iconic
)
2910 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2911 sizingRect
.right
- sizingRect
.left
,
2912 sizingRect
.bottom
- sizingRect
.top
,
2913 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2916 { /* restore previous size/position */
2918 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2919 origRect
.right
- origRect
.left
,
2920 origRect
.bottom
- origRect
.top
,
2921 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2927 /* Single click brings up the system menu when iconized */
2931 if(style
& WS_SYSMENU
)
2932 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2933 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2935 else WINPOS_ShowIconTitle( hwnd
, TRUE
);