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
, size
, 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
.nCount
, 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 xspacing
, yspacing
;
857 parent
= GetAncestor( hwnd
, GA_PARENT
);
858 GetClientRect( parent
, &rectParent
);
859 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
860 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
861 return pt
; /* The icon already has a suitable position */
863 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
864 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
866 /* Check if another icon already occupies this spot */
867 /* FIXME: this is completely inefficient */
869 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
870 tmp
= CreateRectRgn( 0, 0, 0, 0 );
871 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
873 if (child
== hwnd
) continue;
874 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
876 if (WIN_GetRectangles( child
, COORDS_PARENT
, &rect
, NULL
))
878 SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
879 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
884 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
886 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
888 rect
.right
= rect
.left
+ xspacing
;
889 rect
.top
= rect
.bottom
- yspacing
;
890 if (!RectInRegion( hrgn
, &rect
))
892 /* No window was found, so it's OK for us */
893 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
894 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
895 DeleteObject( hrgn
);
900 DeleteObject( hrgn
);
906 /***********************************************************************
909 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
917 TRACE("%p %u\n", hwnd
, cmd
);
919 wpl
.length
= sizeof(wpl
);
920 GetWindowPlacement( hwnd
, &wpl
);
922 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
923 return SWP_NOSIZE
| SWP_NOMOVE
;
925 if (IsIconic( hwnd
))
929 case SW_SHOWMINNOACTIVE
:
930 case SW_SHOWMINIMIZED
:
931 case SW_FORCEMINIMIZE
:
933 return SWP_NOSIZE
| SWP_NOMOVE
;
935 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
936 swpFlags
|= SWP_NOCOPYBITS
;
941 case SW_SHOWMINNOACTIVE
:
942 case SW_SHOWMINIMIZED
:
943 case SW_FORCEMINIMIZE
:
945 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
946 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
947 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
948 WIN_ReleasePtr( wndPtr
);
950 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
952 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
954 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
955 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
956 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
957 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
958 swpFlags
|= SWP_NOCOPYBITS
;
962 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
963 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
965 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
967 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
968 if (old_style
& WS_MINIMIZE
)
970 if ((wndPtr
= WIN_GetPtr( hwnd
)) && wndPtr
!= WND_OTHER_PROCESS
)
972 wndPtr
->flags
|= WIN_RESTORE_MAX
;
973 WIN_ReleasePtr( wndPtr
);
975 WINPOS_ShowIconTitle( hwnd
, FALSE
);
978 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
979 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
980 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
983 case SW_SHOWNOACTIVATE
:
984 if ((wndPtr
= WIN_GetPtr( hwnd
)) && wndPtr
!= WND_OTHER_PROCESS
)
986 wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
987 WIN_ReleasePtr( wndPtr
);
992 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
993 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
994 if (old_style
& WS_MINIMIZE
)
998 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1000 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1001 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
1002 WIN_ReleasePtr( wndPtr
);
1005 /* Restore to maximized position */
1006 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1007 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
1008 swpFlags
|= SWP_STATECHANGED
;
1009 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
1010 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
1014 else if (!(old_style
& WS_MAXIMIZE
)) break;
1016 swpFlags
|= SWP_STATECHANGED
;
1018 /* Restore to normal position */
1020 *rect
= wpl
.rcNormalPosition
;
1028 /***********************************************************************
1031 * Implementation of ShowWindow and ShowWindowAsync.
1033 static BOOL
show_window( HWND hwnd
, INT cmd
)
1037 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1038 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
1039 BOOL showFlag
= TRUE
;
1040 RECT newPos
= {0, 0, 0, 0};
1043 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
1048 if (!wasVisible
) return FALSE
;
1050 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1051 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1054 case SW_SHOWMINNOACTIVE
:
1056 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1057 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1059 case SW_SHOWMINIMIZED
:
1060 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1061 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1062 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
1065 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1066 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1067 swp
|= SWP_FRAMECHANGED
;
1068 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1069 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
1073 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1074 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
1077 if (wasVisible
) return TRUE
;
1078 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1079 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1082 case SW_SHOWNOACTIVATE
:
1083 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1087 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1088 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1089 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1090 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1092 swp
|= SWP_FRAMECHANGED
;
1093 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1097 if (wasVisible
) return TRUE
;
1098 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1100 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1106 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1108 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1109 if (!IsWindow( hwnd
)) return wasVisible
;
1112 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1114 parent
= GetAncestor( hwnd
, GA_PARENT
);
1115 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1117 /* if parent is not visible simply toggle WS_VISIBLE and return */
1118 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1119 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1122 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1123 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1129 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1131 /* FIXME: This will cause the window to be activated irrespective
1132 * of whether it is owned by the same thread. Has to be done
1136 if (hwnd
== GetActiveWindow())
1137 WINPOS_ActivateOtherWindow(hwnd
);
1139 /* Revert focus to parent */
1140 hFocus
= GetFocus();
1143 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1144 if (parent
== GetDesktopWindow()) parent
= 0;
1150 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1152 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1154 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1156 /* should happen only in CreateWindowEx() */
1157 int wParam
= SIZE_RESTORED
;
1161 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &client
);
1162 lparam
= MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
);
1163 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1164 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1165 else if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1167 wParam
= SIZE_MINIMIZED
;
1170 WIN_ReleasePtr( wndPtr
);
1172 SendMessageW( hwnd
, WM_SIZE
, wParam
, lparam
);
1173 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1175 else WIN_ReleasePtr( wndPtr
);
1177 /* if previous state was minimized Windows sets focus to the window */
1178 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1184 /***********************************************************************
1185 * ShowWindowAsync (USER32.@)
1187 * doesn't wait; returns immediately.
1188 * used by threads to toggle windows in other (possibly hanging) threads
1190 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1194 if (is_broadcast(hwnd
))
1196 SetLastError( ERROR_INVALID_PARAMETER
);
1200 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1201 return show_window( full_handle
, cmd
);
1203 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1207 /***********************************************************************
1208 * ShowWindow (USER32.@)
1210 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1214 if (is_broadcast(hwnd
))
1216 SetLastError( ERROR_INVALID_PARAMETER
);
1219 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1220 return show_window( full_handle
, cmd
);
1222 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1226 /***********************************************************************
1227 * GetInternalWindowPos (USER32.@)
1229 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1232 WINDOWPLACEMENT wndpl
;
1233 if (GetWindowPlacement( hwnd
, &wndpl
))
1235 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1236 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1237 return wndpl
.showCmd
;
1243 /***********************************************************************
1244 * GetWindowPlacement (USER32.@)
1247 * Fails if wndpl->length of Win95 (!) apps is invalid.
1249 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1251 WND
*pWnd
= WIN_GetPtr( hwnd
);
1253 if (!pWnd
) return FALSE
;
1255 if (pWnd
== WND_DESKTOP
)
1257 wndpl
->length
= sizeof(*wndpl
);
1258 wndpl
->showCmd
= SW_SHOWNORMAL
;
1260 wndpl
->ptMinPosition
.x
= -1;
1261 wndpl
->ptMinPosition
.y
= -1;
1262 wndpl
->ptMaxPosition
.x
= -1;
1263 wndpl
->ptMaxPosition
.y
= -1;
1264 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1267 if (pWnd
== WND_OTHER_PROCESS
)
1269 if (!IsWindow( hwnd
)) return FALSE
;
1270 FIXME( "not supported on other process window %p\n", hwnd
);
1271 /* provide some dummy information */
1272 wndpl
->length
= sizeof(*wndpl
);
1273 wndpl
->showCmd
= SW_SHOWNORMAL
;
1275 wndpl
->ptMinPosition
.x
= -1;
1276 wndpl
->ptMinPosition
.y
= -1;
1277 wndpl
->ptMaxPosition
.x
= -1;
1278 wndpl
->ptMaxPosition
.y
= -1;
1279 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1283 /* update the placement according to the current style */
1284 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1286 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1287 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1289 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1291 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1292 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1296 pWnd
->normal_rect
= pWnd
->rectWindow
;
1299 wndpl
->length
= sizeof(*wndpl
);
1300 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1301 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1303 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1304 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1305 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1308 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1309 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1310 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1311 WIN_ReleasePtr( pWnd
);
1313 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1314 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1315 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1316 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1320 /* make sure the specified rect is visible on screen */
1321 static void make_rect_onscreen( RECT
*rect
)
1324 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1326 info
.cbSize
= sizeof(info
);
1327 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1328 /* FIXME: map coordinates from rcWork to rcMonitor */
1329 if (rect
->right
<= info
.rcWork
.left
)
1331 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1332 rect
->left
= info
.rcWork
.left
;
1334 else if (rect
->left
>= info
.rcWork
.right
)
1336 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1337 rect
->right
= info
.rcWork
.right
;
1339 if (rect
->bottom
<= info
.rcWork
.top
)
1341 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1342 rect
->top
= info
.rcWork
.top
;
1344 else if (rect
->top
>= info
.rcWork
.bottom
)
1346 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1347 rect
->bottom
= info
.rcWork
.bottom
;
1351 /* make sure the specified point is visible on screen */
1352 static void make_point_onscreen( POINT
*pt
)
1356 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1357 make_rect_onscreen( &rect
);
1363 /***********************************************************************
1364 * WINPOS_SetPlacement
1366 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1369 WND
*pWnd
= WIN_GetPtr( hwnd
);
1370 WINDOWPLACEMENT wp
= *wndpl
;
1372 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1373 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1374 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1376 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1377 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1378 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1379 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1380 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1381 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1383 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1385 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1386 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1387 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1389 style
= pWnd
->dwStyle
;
1391 WIN_ReleasePtr( pWnd
);
1393 if( style
& WS_MINIMIZE
)
1395 if (flags
& PLACE_MIN
)
1397 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1398 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1399 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1402 else if( style
& WS_MAXIMIZE
)
1404 if (flags
& PLACE_MAX
)
1405 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1406 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1408 else if( flags
& PLACE_RECT
)
1409 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1410 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1411 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1412 SWP_NOZORDER
| SWP_NOACTIVATE
);
1414 ShowWindow( hwnd
, wndpl
->showCmd
);
1416 if (IsIconic( hwnd
))
1418 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1420 /* SDK: ...valid only the next time... */
1421 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1423 pWnd
= WIN_GetPtr( hwnd
);
1424 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1426 pWnd
->flags
|= WIN_RESTORE_MAX
;
1427 WIN_ReleasePtr( pWnd
);
1435 /***********************************************************************
1436 * SetWindowPlacement (USER32.@)
1439 * Fails if wndpl->length of Win95 (!) apps is invalid.
1441 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1443 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1444 if (!wpl
) return FALSE
;
1445 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1446 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1450 /***********************************************************************
1451 * AnimateWindow (USER32.@)
1452 * Shows/Hides a window with an animation
1455 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1457 FIXME("partial stub\n");
1459 /* If trying to show/hide and it's already *
1460 * shown/hidden or invalid window, fail with *
1461 * invalid parameter */
1462 if(!IsWindow(hwnd
) ||
1463 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1464 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1466 SetLastError(ERROR_INVALID_PARAMETER
);
1470 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1475 /***********************************************************************
1476 * SetInternalWindowPos (USER32.@)
1478 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1479 LPRECT rect
, LPPOINT pt
)
1481 WINDOWPLACEMENT wndpl
;
1484 wndpl
.length
= sizeof(wndpl
);
1485 wndpl
.showCmd
= showCmd
;
1486 wndpl
.flags
= flags
= 0;
1491 wndpl
.flags
|= WPF_SETMINPOSITION
;
1492 wndpl
.ptMinPosition
= *pt
;
1496 flags
|= PLACE_RECT
;
1497 wndpl
.rcNormalPosition
= *rect
;
1499 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1503 /*******************************************************************
1504 * can_activate_window
1506 * Check if we can activate the specified window.
1508 static BOOL
can_activate_window( HWND hwnd
)
1512 if (!hwnd
) return FALSE
;
1513 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1514 if (!(style
& WS_VISIBLE
)) return FALSE
;
1515 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1516 return !(style
& WS_DISABLED
);
1520 /*******************************************************************
1521 * WINPOS_ActivateOtherWindow
1523 * Activates window other than pWnd.
1525 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1529 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1531 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1532 if (can_activate_window( hwndTo
)) goto done
;
1538 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1539 if (can_activate_window( hwndTo
)) goto done
;
1542 hwndTo
= GetTopWindow( 0 );
1550 if (can_activate_window( hwndTo
)) goto done
;
1551 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1555 fg
= GetForegroundWindow();
1556 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1557 if (!fg
|| (hwnd
== fg
))
1559 if (SetForegroundWindow( hwndTo
)) return;
1561 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1565 /***********************************************************************
1566 * WINPOS_HandleWindowPosChanging
1568 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1570 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1572 POINT minTrack
, maxTrack
;
1573 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1575 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1576 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1578 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1579 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1580 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1581 if (!(style
& WS_MINIMIZE
))
1583 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1584 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1591 /***********************************************************************
1594 static void dump_winpos_flags(UINT flags
)
1596 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1597 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1598 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1599 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1600 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1602 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1603 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1604 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1605 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1606 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1607 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1608 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1609 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1610 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1611 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1612 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1613 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1614 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1615 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1616 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1617 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1619 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1623 /***********************************************************************
1624 * SWP_DoWinPosChanging
1626 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1629 RECT window_rect
, client_rect
;
1631 /* Send WM_WINDOWPOSCHANGING message */
1633 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1634 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1636 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1637 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1639 /* Calculate new position and size */
1641 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1642 *pNewWindowRect
= window_rect
;
1643 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? window_rect
: client_rect
;
1645 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1647 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1649 pNewWindowRect
->right
= pNewWindowRect
->left
+ GetSystemMetrics(SM_CXICON
);
1650 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ GetSystemMetrics(SM_CYICON
);
1654 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1655 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1658 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1660 pNewWindowRect
->left
= pWinpos
->x
;
1661 pNewWindowRect
->top
= pWinpos
->y
;
1662 pNewWindowRect
->right
+= pWinpos
->x
- window_rect
.left
;
1663 pNewWindowRect
->bottom
+= pWinpos
->y
- window_rect
.top
;
1665 OffsetRect( pNewClientRect
, pWinpos
->x
- window_rect
.left
,
1666 pWinpos
->y
- window_rect
.top
);
1668 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1670 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1671 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1672 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1673 TRACE( "current %s style %08x new %s\n",
1674 wine_dbgstr_rect( &window_rect
), wndPtr
->dwStyle
,
1675 wine_dbgstr_rect( pNewWindowRect
));
1677 WIN_ReleasePtr( wndPtr
);
1681 /***********************************************************************
1684 * Compute the valid rects from the old and new client rect and WVR_* flags.
1685 * Helper for WM_NCCALCSIZE handling.
1687 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1692 if (flags
& WVR_REDRAW
)
1694 SetRectEmpty( &valid
[0] );
1695 SetRectEmpty( &valid
[1] );
1699 if (flags
& WVR_VALIDRECTS
)
1701 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1702 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1704 SetRectEmpty( &valid
[0] );
1705 SetRectEmpty( &valid
[1] );
1708 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1712 valid
[0] = *new_client
;
1713 valid
[1] = *old_client
;
1716 /* make sure the rectangles have the same size */
1717 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1718 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1720 if (flags
& WVR_ALIGNBOTTOM
)
1722 valid
[0].top
= valid
[0].bottom
- cy
;
1723 valid
[1].top
= valid
[1].bottom
- cy
;
1727 valid
[0].bottom
= valid
[0].top
+ cy
;
1728 valid
[1].bottom
= valid
[1].top
+ cy
;
1730 if (flags
& WVR_ALIGNRIGHT
)
1732 valid
[0].left
= valid
[0].right
- cx
;
1733 valid
[1].left
= valid
[1].right
- cx
;
1737 valid
[0].right
= valid
[0].left
+ cx
;
1738 valid
[1].right
= valid
[1].left
+ cx
;
1743 /***********************************************************************
1746 * fix Z order taking into account owned popups -
1747 * basically we need to maintain them above the window that owns them
1749 * FIXME: hide/show owned popups when owner visibility changes.
1751 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1753 HWND owner
, *list
= NULL
;
1756 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1758 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return hwndInsertAfter
;
1760 if ((owner
= GetWindow( hwnd
, GW_OWNER
)))
1762 /* make sure this popup stays above the owner */
1764 if (hwndInsertAfter
!= HWND_TOPMOST
)
1766 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1768 for (i
= 0; list
[i
]; i
++)
1770 BOOL topmost
= (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1772 if (list
[i
] == owner
)
1774 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1775 else hwndInsertAfter
= topmost
? HWND_TOPMOST
: HWND_TOP
;
1779 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1781 if (!topmost
) break;
1783 else if (list
[i
] == hwndInsertAfter
) break;
1788 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1789 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1792 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1794 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1796 /* skip all the topmost windows */
1797 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1800 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1802 /* skip windows that are already placed correctly */
1803 for (i
= 0; list
[i
]; i
++)
1805 if (list
[i
] == hwndInsertAfter
) break;
1806 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1810 for ( ; list
[i
]; i
++)
1812 if (list
[i
] == hwnd
) break;
1813 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1814 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1815 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1816 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1817 hwndInsertAfter
= list
[i
];
1821 HeapFree( GetProcessHeap(), 0, list
);
1822 return hwndInsertAfter
;
1825 /***********************************************************************
1828 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1832 RECT window_rect
, client_rect
;
1834 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1836 /* Send WM_NCCALCSIZE message to get new client area */
1837 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1839 NCCALCSIZE_PARAMS params
;
1840 WINDOWPOS winposCopy
;
1842 params
.rgrc
[0] = *pNewWindowRect
;
1843 params
.rgrc
[1] = window_rect
;
1844 params
.rgrc
[2] = client_rect
;
1845 params
.lppos
= &winposCopy
;
1846 winposCopy
= *pWinpos
;
1848 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1850 *pNewClientRect
= params
.rgrc
[0];
1852 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1853 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
),
1854 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1856 if( pNewClientRect
->left
!= client_rect
.left
||
1857 pNewClientRect
->top
!= client_rect
.top
)
1858 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1860 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1861 client_rect
.right
- client_rect
.left
))
1862 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1864 wvrFlags
&= ~WVR_HREDRAW
;
1866 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1867 client_rect
.bottom
- client_rect
.top
)
1868 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1870 wvrFlags
&= ~WVR_VREDRAW
;
1872 validRects
[0] = params
.rgrc
[1];
1873 validRects
[1] = params
.rgrc
[2];
1877 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1878 (pNewClientRect
->left
!= client_rect
.left
||
1879 pNewClientRect
->top
!= client_rect
.top
))
1880 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1883 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1885 SetRectEmpty( &validRects
[0] );
1886 SetRectEmpty( &validRects
[1] );
1888 else get_valid_rects( &client_rect
, pNewClientRect
, wvrFlags
, validRects
);
1893 /* fix redundant flags and values in the WINDOWPOS structure */
1894 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1899 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1902 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1904 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1907 winpos
->hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
1909 /* Finally make sure that all coordinates are valid */
1910 if (winpos
->x
< -32768) winpos
->x
= -32768;
1911 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1912 if (winpos
->y
< -32768) winpos
->y
= -32768;
1913 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1915 if (winpos
->cx
< 0) winpos
->cx
= 0;
1916 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1917 if (winpos
->cy
< 0) winpos
->cy
= 0;
1918 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1920 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1921 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1923 if (winpos
->flags
& SWP_HIDEWINDOW
) wndPtr
->flags
|= WIN_HIDDEN
;
1924 else if (winpos
->flags
& SWP_SHOWWINDOW
) wndPtr
->flags
&= ~WIN_HIDDEN
;
1926 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1929 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1930 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1933 WIN_GetRectangles( winpos
->hwnd
, COORDS_SCREEN
, &window_rect
, NULL
);
1934 if ((window_rect
.right
- window_rect
.left
== winpos
->cx
) &&
1935 (window_rect
.bottom
- window_rect
.top
== winpos
->cy
))
1936 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1940 ClientToScreen( parent
, &pt
);
1941 if ((window_rect
.left
== pt
.x
) && (window_rect
.top
== pt
.y
))
1942 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1944 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1946 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1947 (winpos
->flags
& SWP_NOZORDER
||
1948 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1950 winpos
->flags
&= ~SWP_NOZORDER
;
1951 winpos
->hwndInsertAfter
= HWND_TOP
;
1955 /* Check hwndInsertAfter */
1956 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1958 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1960 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1961 winpos
->flags
|= SWP_NOZORDER
;
1963 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1965 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1966 winpos
->flags
|= SWP_NOZORDER
;
1968 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1970 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1971 winpos
->flags
|= SWP_NOZORDER
;
1973 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1975 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1976 winpos
->flags
|= SWP_NOZORDER
;
1980 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1981 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1982 winpos
->flags
|= SWP_NOZORDER
;
1985 WIN_ReleasePtr( wndPtr
);
1990 /***********************************************************************
1991 * update_surface_region
1993 static void update_surface_region( HWND hwnd
)
1999 WND
*win
= WIN_GetPtr( hwnd
);
2001 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return;
2002 if (!win
->surface
) goto done
;
2006 if (!(data
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( RGNDATA
, Buffer
[size
] )))) goto done
;
2008 SERVER_START_REQ( get_surface_region
)
2010 req
->window
= wine_server_user_handle( hwnd
);
2011 wine_server_set_reply( req
, data
->Buffer
, size
);
2012 if (!(status
= wine_server_call( req
)))
2014 size_t reply_size
= wine_server_reply_size( reply
);
2017 data
->rdh
.dwSize
= sizeof(data
->rdh
);
2018 data
->rdh
.iType
= RDH_RECTANGLES
;
2019 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
2020 data
->rdh
.nRgnSize
= reply_size
;
2021 region
= ExtCreateRegion( NULL
, size
, data
);
2022 OffsetRgn( region
, -reply
->visible_rect
.left
, -reply
->visible_rect
.top
);
2025 else size
= reply
->total_size
;
2028 HeapFree( GetProcessHeap(), 0, data
);
2029 } while (status
== STATUS_BUFFER_OVERFLOW
);
2031 if (status
) goto done
;
2033 win
->surface
->funcs
->set_region( win
->surface
, region
);
2034 if (region
) DeleteObject( region
);
2037 WIN_ReleasePtr( win
);
2041 /***********************************************************************
2044 * Backend implementation of SetWindowPos.
2046 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
2047 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
2050 HWND surface_win
= 0, parent
= GetAncestor( hwnd
, GA_PARENT
);
2053 RECT visible_rect
, old_visible_rect
, old_window_rect
;
2054 struct window_surface
*old_surface
, *new_surface
= NULL
;
2056 if (!parent
|| parent
== GetDesktopWindow())
2058 new_surface
= &dummy_surface
; /* provide a default surface for top-level windows */
2059 window_surface_add_ref( new_surface
);
2061 visible_rect
= *window_rect
;
2062 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
2063 window_rect
, client_rect
, &visible_rect
, &new_surface
);
2065 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_window_rect
, NULL
);
2067 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
2069 if (new_surface
) window_surface_release( new_surface
);
2072 old_width
= win
->rectClient
.right
- win
->rectClient
.left
;
2073 old_visible_rect
= win
->visible_rect
;
2074 old_surface
= win
->surface
;
2075 if (old_surface
!= new_surface
) swp_flags
|= SWP_FRAMECHANGED
; /* force refreshing non-client area */
2077 SERVER_START_REQ( set_window_pos
)
2079 req
->handle
= wine_server_user_handle( hwnd
);
2080 req
->previous
= wine_server_user_handle( insert_after
);
2081 req
->swp_flags
= swp_flags
;
2082 req
->window
.left
= window_rect
->left
;
2083 req
->window
.top
= window_rect
->top
;
2084 req
->window
.right
= window_rect
->right
;
2085 req
->window
.bottom
= window_rect
->bottom
;
2086 req
->client
.left
= client_rect
->left
;
2087 req
->client
.top
= client_rect
->top
;
2088 req
->client
.right
= client_rect
->right
;
2089 req
->client
.bottom
= client_rect
->bottom
;
2090 if (memcmp( window_rect
, &visible_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
2092 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
2093 if (!IsRectEmpty( &valid_rects
[0] ))
2094 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
2096 if (new_surface
) req
->paint_flags
|= SET_WINPOS_PAINT_SURFACE
;
2097 if (win
->pixel_format
) req
->paint_flags
|= SET_WINPOS_PIXEL_FORMAT
;
2099 if ((ret
= !wine_server_call( req
)))
2101 win
->dwStyle
= reply
->new_style
;
2102 win
->dwExStyle
= reply
->new_ex_style
;
2103 win
->rectWindow
= *window_rect
;
2104 win
->rectClient
= *client_rect
;
2105 win
->visible_rect
= visible_rect
;
2106 win
->surface
= new_surface
;
2107 surface_win
= wine_server_ptr_handle( reply
->surface_win
);
2108 if (GetWindowLongW( win
->parent
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
)
2111 GetClientRect( win
->parent
, &client
);
2112 mirror_rect( &client
, &win
->rectWindow
);
2113 mirror_rect( &client
, &win
->rectClient
);
2114 mirror_rect( &client
, &win
->visible_rect
);
2116 /* if an RTL window is resized the children have moved */
2117 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
&& client_rect
->right
- client_rect
->left
!= old_width
)
2118 win
->flags
|= WIN_CHILDREN_MOVED
;
2125 if (surface_win
) update_surface_region( surface_win
);
2126 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
2127 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
| SWP_FRAMECHANGED
)))
2128 invalidate_dce( win
, &old_window_rect
);
2131 WIN_ReleasePtr( win
);
2135 TRACE( "win %p surface %p -> %p\n", hwnd
, old_surface
, new_surface
);
2136 register_window_surface( old_surface
, new_surface
);
2139 if (!IsRectEmpty( valid_rects
))
2141 move_window_bits( hwnd
, old_surface
, new_surface
, &visible_rect
,
2142 &old_visible_rect
, client_rect
, valid_rects
);
2143 valid_rects
= NULL
; /* prevent the driver from trying to also move the bits */
2145 window_surface_release( old_surface
);
2147 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
2148 client_rect
, &visible_rect
, valid_rects
, new_surface
);
2150 else if (new_surface
) window_surface_release( new_surface
);
2156 /***********************************************************************
2159 * User32 internal function
2161 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
2163 RECT newWindowRect
, newClientRect
, valid_rects
[2];
2166 orig_flags
= winpos
->flags
;
2168 /* First, check z-order arguments. */
2169 if (!(winpos
->flags
& SWP_NOZORDER
))
2171 /* fix sign extension */
2172 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
2173 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
2175 if (!(winpos
->hwndInsertAfter
== HWND_TOP
||
2176 winpos
->hwndInsertAfter
== HWND_BOTTOM
||
2177 winpos
->hwndInsertAfter
== HWND_TOPMOST
||
2178 winpos
->hwndInsertAfter
== HWND_NOTOPMOST
))
2180 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2181 HWND insertafter_parent
= GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
);
2183 /* hwndInsertAfter must be a sibling of the window */
2184 if (!insertafter_parent
) return FALSE
;
2185 if (insertafter_parent
!= parent
) return TRUE
;
2189 /* Make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
2190 if (!(winpos
->flags
& SWP_NOMOVE
))
2192 if (winpos
->x
< -32768) winpos
->x
= -32768;
2193 else if (winpos
->x
> 32767) winpos
->x
= 32767;
2194 if (winpos
->y
< -32768) winpos
->y
= -32768;
2195 else if (winpos
->y
> 32767) winpos
->y
= 32767;
2197 if (!(winpos
->flags
& SWP_NOSIZE
))
2199 if (winpos
->cx
< 0) winpos
->cx
= 0;
2200 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
2201 if (winpos
->cy
< 0) winpos
->cy
= 0;
2202 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
2205 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
2207 /* Fix redundant flags */
2208 if (!fixup_flags( winpos
)) return FALSE
;
2210 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
2212 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
2213 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
2216 /* Common operations */
2218 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
2220 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
2221 &newWindowRect
, &newClientRect
, valid_rects
))
2224 /* erase parent when hiding or resizing child */
2225 if (!(orig_flags
& SWP_DEFERERASE
) &&
2226 ((orig_flags
& SWP_HIDEWINDOW
) ||
2227 (!(orig_flags
& SWP_SHOWWINDOW
) &&
2228 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
2230 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2231 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
2232 erase_now( parent
, 0 );
2235 if( winpos
->flags
& SWP_HIDEWINDOW
)
2236 HideCaret(winpos
->hwnd
);
2237 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2238 ShowCaret(winpos
->hwnd
);
2240 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2242 /* child windows get WM_CHILDACTIVATE message */
2243 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2244 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2246 SetForegroundWindow( winpos
->hwnd
);
2249 /* And last, send the WM_WINDOWPOSCHANGED message */
2251 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2253 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2255 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2256 and always contains final window position.
2258 winpos
->x
= newWindowRect
.left
;
2259 winpos
->y
= newWindowRect
.top
;
2260 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2261 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2262 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2267 /***********************************************************************
2268 * SetWindowPos (USER32.@)
2270 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2271 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2275 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2276 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2277 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2279 if (is_broadcast(hwnd
))
2281 SetLastError( ERROR_INVALID_PARAMETER
);
2285 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2286 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2291 winpos
.flags
= flags
;
2293 if (WIN_IsCurrentThread( hwnd
))
2294 return USER_SetWindowPos(&winpos
);
2296 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2300 /***********************************************************************
2301 * BeginDeferWindowPos (USER32.@)
2303 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2308 TRACE("%d\n", count
);
2312 SetLastError(ERROR_INVALID_PARAMETER
);
2315 /* Windows allows zero count, in which case it allocates context for 8 moves */
2316 if (count
== 0) count
= 8;
2318 if (!(pDWP
= HeapAlloc( GetProcessHeap(), 0, sizeof(DWP
)))) return 0;
2320 pDWP
->actualCount
= 0;
2321 pDWP
->suggestedCount
= count
;
2322 pDWP
->hwndParent
= 0;
2324 if (!(pDWP
->winPos
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(WINDOWPOS
) )) ||
2325 !(handle
= alloc_user_handle( &pDWP
->obj
, USER_DWP
)))
2327 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2328 HeapFree( GetProcessHeap(), 0, pDWP
);
2331 TRACE("returning hdwp %p\n", handle
);
2336 /***********************************************************************
2337 * DeferWindowPos (USER32.@)
2339 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2340 INT x
, INT y
, INT cx
, INT cy
,
2345 HDWP retvalue
= hdwp
;
2347 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2348 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2350 hwnd
= WIN_GetFullHandle( hwnd
);
2351 if (is_desktop_window( hwnd
)) return 0;
2353 if (!(pDWP
= get_user_handle_ptr( hdwp
, USER_DWP
))) return 0;
2354 if (pDWP
== OBJ_OTHER_PROCESS
)
2356 FIXME( "other process handle %p?\n", hdwp
);
2360 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2362 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2364 /* Merge with the other changes */
2365 if (!(flags
& SWP_NOZORDER
))
2367 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2369 if (!(flags
& SWP_NOMOVE
))
2371 pDWP
->winPos
[i
].x
= x
;
2372 pDWP
->winPos
[i
].y
= y
;
2374 if (!(flags
& SWP_NOSIZE
))
2376 pDWP
->winPos
[i
].cx
= cx
;
2377 pDWP
->winPos
[i
].cy
= cy
;
2379 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2380 SWP_NOZORDER
| SWP_NOREDRAW
|
2381 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2383 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2388 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2390 WINDOWPOS
*newpos
= HeapReAlloc( GetProcessHeap(), 0, pDWP
->winPos
,
2391 pDWP
->suggestedCount
* 2 * sizeof(WINDOWPOS
) );
2397 pDWP
->suggestedCount
*= 2;
2398 pDWP
->winPos
= newpos
;
2400 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2401 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2402 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2403 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2404 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2405 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2406 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2407 pDWP
->actualCount
++;
2409 release_user_handle_ptr( pDWP
);
2414 /***********************************************************************
2415 * EndDeferWindowPos (USER32.@)
2417 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2424 TRACE("%p\n", hdwp
);
2426 if (!(pDWP
= free_user_handle( hdwp
, USER_DWP
))) return FALSE
;
2427 if (pDWP
== OBJ_OTHER_PROCESS
)
2429 FIXME( "other process handle %p?\n", hdwp
);
2433 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2435 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2436 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2437 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2439 if (WIN_IsCurrentThread( winpos
->hwnd
))
2440 res
= USER_SetWindowPos( winpos
);
2442 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2444 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2445 HeapFree( GetProcessHeap(), 0, pDWP
);
2450 /***********************************************************************
2451 * ArrangeIconicWindows (USER32.@)
2453 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2457 INT x
, y
, xspacing
, yspacing
;
2459 GetClientRect( parent
, &rectParent
);
2460 x
= rectParent
.left
;
2461 y
= rectParent
.bottom
;
2462 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2463 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2465 hwndChild
= GetWindow( parent
, GW_CHILD
);
2468 if( IsIconic( hwndChild
) )
2470 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2472 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2473 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
2474 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2475 if( IsWindow(hwndChild
) )
2476 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2478 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
2481 x
= rectParent
.left
;
2485 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2491 /***********************************************************************
2494 * Draw the frame used when moving or resizing window.
2496 static void draw_moving_frame( HWND parent
, HDC hdc
, RECT
*screen_rect
, BOOL thickframe
)
2498 RECT rect
= *screen_rect
;
2500 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2503 const int width
= GetSystemMetrics(SM_CXFRAME
);
2504 const int height
= GetSystemMetrics(SM_CYFRAME
);
2506 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2507 PatBlt( hdc
, rect
.left
, rect
.top
,
2508 rect
.right
- rect
.left
- width
, height
, PATINVERT
);
2509 PatBlt( hdc
, rect
.left
, rect
.top
+ height
, width
,
2510 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2511 PatBlt( hdc
, rect
.left
+ width
, rect
.bottom
- 1,
2512 rect
.right
- rect
.left
- width
, -height
, PATINVERT
);
2513 PatBlt( hdc
, rect
.right
- 1, rect
.top
, -width
,
2514 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2515 SelectObject( hdc
, hbrush
);
2517 else DrawFocusRect( hdc
, &rect
);
2521 /***********************************************************************
2524 * Initialization of a move or resize, when initiated from a menu choice.
2525 * Return hit test code for caption or sizing border.
2527 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2534 GetWindowRect( hwnd
, &rectWindow
);
2536 if ((wParam
& 0xfff0) == SC_MOVE
)
2538 /* Move pointer at the center of the caption */
2539 RECT rect
= rectWindow
;
2540 /* Note: to be exactly centered we should take the different types
2541 * of border into account, but it shouldn't make more than a few pixels
2542 * of difference so let's not bother with that */
2543 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2544 if (style
& WS_SYSMENU
)
2545 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2546 if (style
& WS_MINIMIZEBOX
)
2547 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2548 if (style
& WS_MAXIMIZEBOX
)
2549 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2550 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2551 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2552 hittest
= HTCAPTION
;
2557 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2561 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2562 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2567 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2568 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2569 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2570 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2581 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2582 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2586 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2587 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2591 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2592 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2596 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2597 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2605 TranslateMessage( &msg
);
2606 DispatchMessageW( &msg
);
2612 SetCursorPos( pt
.x
, pt
.y
);
2613 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2618 /***********************************************************************
2619 * WINPOS_SysCommandSizeMove
2621 * Perform SC_MOVE and SC_SIZE commands.
2623 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2626 RECT sizingRect
, mouseRect
, origRect
;
2629 LONG hittest
= (LONG
)(wParam
& 0x0f);
2630 WPARAM syscommand
= wParam
& 0xfff0;
2631 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2632 POINT minTrack
, maxTrack
;
2633 POINT capturePoint
, pt
;
2634 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2635 BOOL thickframe
= HAS_THICKFRAME( style
);
2636 BOOL iconic
= style
& WS_MINIMIZE
;
2638 DWORD dwPoint
= GetMessagePos ();
2639 BOOL DragFullWindows
= TRUE
;
2642 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2644 pt
.x
= (short)LOWORD(dwPoint
);
2645 pt
.y
= (short)HIWORD(dwPoint
);
2649 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2650 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2652 if (syscommand
== SC_MOVE
)
2654 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2655 if (!hittest
) return;
2659 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2660 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2663 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2664 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2667 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2673 /* Get min/max info */
2675 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2676 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &sizingRect
, NULL
);
2677 origRect
= sizingRect
;
2678 if (style
& WS_CHILD
)
2680 parent
= GetParent(hwnd
);
2681 GetClientRect( parent
, &mouseRect
);
2682 MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2683 MapWindowPoints( parent
, 0, (LPPOINT
)&sizingRect
, 2 );
2688 mouseRect
= get_virtual_screen_rect();
2689 mon
= MonitorFromPoint( pt
, MONITOR_DEFAULTTONEAREST
);
2692 if (ON_LEFT_BORDER(hittest
))
2694 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
+capturePoint
.x
-sizingRect
.left
);
2695 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
+capturePoint
.x
-sizingRect
.left
);
2697 else if (ON_RIGHT_BORDER(hittest
))
2699 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
+capturePoint
.x
-sizingRect
.right
);
2700 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
+capturePoint
.x
-sizingRect
.right
);
2702 if (ON_TOP_BORDER(hittest
))
2704 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
+capturePoint
.y
-sizingRect
.top
);
2705 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
+capturePoint
.y
-sizingRect
.top
);
2707 else if (ON_BOTTOM_BORDER(hittest
))
2709 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
+capturePoint
.y
-sizingRect
.bottom
);
2710 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
+capturePoint
.y
-sizingRect
.bottom
);
2713 /* Retrieve a default cache DC (without using the window style) */
2714 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2716 if( iconic
) /* create a cursor for dragging */
2718 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2719 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2720 if( !hDragCursor
) iconic
= FALSE
;
2723 /* we only allow disabling the full window drag for child windows */
2724 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2726 /* repaint the window before moving it around */
2727 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2729 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2730 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2736 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2737 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2739 /* Exit on button-up, Return, or Esc */
2740 if ((msg
.message
== WM_LBUTTONUP
) ||
2741 ((msg
.message
== WM_KEYDOWN
) &&
2742 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2744 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2746 TranslateMessage( &msg
);
2747 DispatchMessageW( &msg
);
2748 continue; /* We are not interested in other messages */
2753 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2755 case VK_UP
: pt
.y
-= 8; break;
2756 case VK_DOWN
: pt
.y
+= 8; break;
2757 case VK_LEFT
: pt
.x
-= 8; break;
2758 case VK_RIGHT
: pt
.x
+= 8; break;
2761 pt
.x
= max( pt
.x
, mouseRect
.left
);
2762 pt
.x
= min( pt
.x
, mouseRect
.right
- 1 );
2763 pt
.y
= max( pt
.y
, mouseRect
.top
);
2764 pt
.y
= min( pt
.y
, mouseRect
.bottom
- 1 );
2771 if ((newmon
= MonitorFromPoint( pt
, MONITOR_DEFAULTTONULL
)))
2774 info
.cbSize
= sizeof(info
);
2775 if (mon
&& GetMonitorInfoW( mon
, &info
))
2777 pt
.x
= max( pt
.x
, info
.rcWork
.left
);
2778 pt
.x
= min( pt
.x
, info
.rcWork
.right
- 1 );
2779 pt
.y
= max( pt
.y
, info
.rcWork
.top
);
2780 pt
.y
= min( pt
.y
, info
.rcWork
.bottom
- 1 );
2784 dx
= pt
.x
- capturePoint
.x
;
2785 dy
= pt
.y
- capturePoint
.y
;
2793 if( iconic
) /* ok, no system popup tracking */
2795 hOldCursor
= SetCursor(hDragCursor
);
2797 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2799 else if(!DragFullWindows
)
2800 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2803 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2806 if(!iconic
&& !DragFullWindows
) draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2807 if (hittest
== HTCAPTION
) OffsetRect( &sizingRect
, dx
, dy
);
2808 if (ON_LEFT_BORDER(hittest
)) sizingRect
.left
+= dx
;
2809 else if (ON_RIGHT_BORDER(hittest
)) sizingRect
.right
+= dx
;
2810 if (ON_TOP_BORDER(hittest
)) sizingRect
.top
+= dy
;
2811 else if (ON_BOTTOM_BORDER(hittest
)) sizingRect
.bottom
+= dy
;
2814 /* determine the hit location */
2815 if (syscommand
== SC_SIZE
)
2817 WPARAM wpSizingHit
= 0;
2819 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2820 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2821 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&sizingRect
);
2824 SendMessageW( hwnd
, WM_MOVING
, 0, (LPARAM
)&sizingRect
);
2828 if(!DragFullWindows
)
2829 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2832 RECT rect
= sizingRect
;
2833 MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2834 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
2835 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2836 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2845 if( moved
) /* restore cursors, show icon title later on */
2847 ShowCursor( FALSE
);
2848 SetCursor( hOldCursor
);
2851 else if (moved
&& !DragFullWindows
)
2853 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2856 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2857 ReleaseDC( parent
, hdc
);
2858 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2860 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2863 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2864 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2866 /* window moved or resized */
2869 /* if the moving/resizing isn't canceled call SetWindowPos
2870 * with the new position or the new size of the window
2872 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2874 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2875 if(!DragFullWindows
|| iconic
)
2876 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2877 sizingRect
.right
- sizingRect
.left
,
2878 sizingRect
.bottom
- sizingRect
.top
,
2879 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2882 { /* restore previous size/position */
2884 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2885 origRect
.right
- origRect
.left
,
2886 origRect
.bottom
- origRect
.top
,
2887 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2893 /* Single click brings up the system menu when iconized */
2897 if(style
& WS_SYSMENU
)
2898 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2899 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2901 else WINPOS_ShowIconTitle( hwnd
, TRUE
);