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"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define PLACE_MIN 0x0001
68 #define PLACE_MAX 0x0002
69 #define PLACE_RECT 0x0004
72 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
85 /***********************************************************************
86 * SwitchToThisWindow (USER32.@)
88 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
90 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
99 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
102 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd
, wine_dbgstr_rect(rect
) );
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
122 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
124 SetLastError( ERROR_OUTOFMEMORY
);
127 SERVER_START_REQ( get_window_region
)
129 req
->window
= wine_server_user_handle( hwnd
);
130 wine_server_set_reply( req
, data
->Buffer
, size
);
131 if (!(status
= wine_server_call( req
)))
133 size_t reply_size
= wine_server_reply_size( reply
);
136 data
->rdh
.dwSize
= sizeof(data
->rdh
);
137 data
->rdh
.iType
= RDH_RECTANGLES
;
138 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
139 data
->rdh
.nRgnSize
= reply_size
;
140 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
143 else size
= reply
->total_size
;
146 HeapFree( GetProcessHeap(), 0, data
);
147 } while (status
== STATUS_BUFFER_OVERFLOW
);
149 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
152 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
153 DeleteObject( win_rgn
);
158 /***********************************************************************
159 * GetWindowRgnBox (USER32.@)
161 int WINAPI
GetWindowRgnBox( HWND hwnd
, LPRECT prect
)
169 if ((hrgn
= CreateRectRgn(0, 0, 0, 0)))
171 if ((ret
= GetWindowRgn( hwnd
, hrgn
)) != ERROR
)
172 ret
= GetRgnBox( hrgn
, prect
);
179 /***********************************************************************
180 * SetWindowRgn (USER32.@)
182 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
184 static const RECT empty_rect
;
192 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
193 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
194 if (!GetRegionData( hrgn
, size
, data
))
196 HeapFree( GetProcessHeap(), 0, data
);
199 SERVER_START_REQ( set_window_region
)
201 req
->window
= wine_server_user_handle( hwnd
);
202 req
->redraw
= (bRedraw
!= 0);
203 if (data
->rdh
.nCount
)
204 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
206 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
207 ret
= !wine_server_call_err( req
);
210 HeapFree( GetProcessHeap(), 0, data
);
212 else /* clear existing region */
214 SERVER_START_REQ( set_window_region
)
216 req
->window
= wine_server_user_handle( hwnd
);
217 req
->redraw
= (bRedraw
!= 0);
218 ret
= !wine_server_call_err( req
);
223 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
227 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
228 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
229 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
230 invalidate_dce( hwnd
, NULL
);
236 /***********************************************************************
237 * GetClientRect (USER32.@)
239 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
243 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
245 rect
->right
-= rect
->left
;
246 rect
->bottom
-= rect
->top
;
247 rect
->left
= rect
->top
= 0;
253 /*******************************************************************
254 * ClientToScreen (USER32.@)
256 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
258 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
263 /*******************************************************************
264 * ScreenToClient (USER32.@)
266 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
268 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
273 /***********************************************************************
274 * list_children_from_point
276 * Get the list of children that can contain point from the server.
277 * Point is in screen coordinates.
278 * Returned list must be freed by caller.
280 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
289 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
291 SERVER_START_REQ( get_window_children_from_point
)
293 req
->parent
= wine_server_user_handle( hwnd
);
296 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
297 if (!wine_server_call( req
)) count
= reply
->count
;
300 if (count
&& count
< size
)
302 /* start from the end since HWND is potentially larger than user_handle_t */
303 for (i
= count
- 1; i
>= 0; i
--)
304 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
308 HeapFree( GetProcessHeap(), 0, list
);
310 size
= count
+ 1; /* restart with a large enough buffer */
316 /***********************************************************************
317 * WINPOS_WindowFromPoint
319 * Find the window and hittest for a given point.
321 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
326 if (!hwndScope
) hwndScope
= GetDesktopWindow();
328 *hittest
= HTNOWHERE
;
330 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
332 /* now determine the hittest */
334 for (i
= 0; list
[i
]; i
++)
336 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
338 /* If window is minimized or disabled, return at once */
339 if (style
& WS_MINIMIZE
)
341 *hittest
= HTCAPTION
;
344 if (style
& WS_DISABLED
)
349 /* Send WM_NCCHITTEST (if same thread) */
350 if (!WIN_IsCurrentThread( list
[i
] ))
355 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
356 if (res
!= HTTRANSPARENT
)
358 *hittest
= res
; /* Found the window */
361 /* continue search with next window in z-order */
364 HeapFree( GetProcessHeap(), 0, list
);
365 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
370 /*******************************************************************
371 * WindowFromPoint (USER32.@)
373 HWND WINAPI
WindowFromPoint( POINT pt
)
376 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
380 /*******************************************************************
381 * ChildWindowFromPoint (USER32.@)
383 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
385 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
388 /*******************************************************************
389 * RealChildWindowFromPoint (USER32.@)
391 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
393 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
);
396 /*******************************************************************
397 * ChildWindowFromPointEx (USER32.@)
399 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
401 /* pt is in the client coordinates */
407 GetClientRect( hwndParent
, &rect
);
408 if (!PtInRect( &rect
, pt
)) return 0;
409 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
411 for (i
= 0; list
[i
]; i
++)
413 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
414 if (!PtInRect( &rect
, pt
)) continue;
415 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
417 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
418 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
419 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
421 if (uFlags
& CWP_SKIPTRANSPARENT
)
423 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
428 HeapFree( GetProcessHeap(), 0, list
);
429 if (!retvalue
) retvalue
= hwndParent
;
434 /*******************************************************************
435 * WINPOS_GetWinOffset
437 * Calculate the offset between the origin of the two windows. Used
438 * to implement MapWindowPoints.
440 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
444 offset
->x
= offset
->y
= 0;
446 /* Translate source window origin to screen coords */
449 HWND hwnd
= hwndFrom
;
453 if (hwnd
== hwndTo
) return;
454 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
456 ERR( "bad hwndFrom = %p\n", hwnd
);
459 if (wndPtr
== WND_DESKTOP
) break;
460 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
463 offset
->x
+= wndPtr
->rectClient
.left
;
464 offset
->y
+= wndPtr
->rectClient
.top
;
466 hwnd
= wndPtr
->parent
;
467 WIN_ReleasePtr( wndPtr
);
471 /* Translate origin to destination window coords */
478 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
480 ERR( "bad hwndTo = %p\n", hwnd
);
483 if (wndPtr
== WND_DESKTOP
) break;
484 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
487 offset
->x
-= wndPtr
->rectClient
.left
;
488 offset
->y
-= wndPtr
->rectClient
.top
;
490 hwnd
= wndPtr
->parent
;
491 WIN_ReleasePtr( wndPtr
);
496 other_process
: /* one of the parents may belong to another process, do it the hard way */
497 offset
->x
= offset
->y
= 0;
498 SERVER_START_REQ( get_windows_offset
)
500 req
->from
= wine_server_user_handle( hwndFrom
);
501 req
->to
= wine_server_user_handle( hwndTo
);
502 if (!wine_server_call( req
))
504 offset
->x
= reply
->x
;
505 offset
->y
= reply
->y
;
512 /*******************************************************************
513 * MapWindowPoints (USER.258)
515 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
516 LPPOINT16 lppt
, UINT16 count
)
520 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
530 /*******************************************************************
531 * MapWindowPoints (USER32.@)
533 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
537 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
544 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
548 /***********************************************************************
549 * IsIconic (USER32.@)
551 BOOL WINAPI
IsIconic(HWND hWnd
)
553 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
557 /***********************************************************************
558 * IsZoomed (USER32.@)
560 BOOL WINAPI
IsZoomed(HWND hWnd
)
562 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
566 /*******************************************************************
567 * AllowSetForegroundWindow (USER32.@)
569 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
571 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
572 * implemented, then fix this function. */
577 /*******************************************************************
578 * LockSetForegroundWindow (USER32.@)
580 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
582 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
583 * implemented, then fix this function. */
588 /***********************************************************************
589 * BringWindowToTop (USER32.@)
591 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
593 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
597 /***********************************************************************
598 * MoveWindow (USER32.@)
600 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
603 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
604 if (!repaint
) flags
|= SWP_NOREDRAW
;
605 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
606 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
610 /***********************************************************************
611 * WINPOS_RedrawIconTitle
613 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
616 WND
*win
= WIN_GetPtr( hWnd
);
618 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
620 icon_title
= win
->icon_title
;
621 WIN_ReleasePtr( win
);
623 if (!icon_title
) return FALSE
;
624 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
625 InvalidateRect( icon_title
, NULL
, TRUE
);
629 /***********************************************************************
630 * WINPOS_ShowIconTitle
632 static BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
634 if (!GetPropA( hwnd
, "__wine_x11_managed" ))
636 WND
*win
= WIN_GetPtr( hwnd
);
639 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
641 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
642 title
= win
->icon_title
;
643 WIN_ReleasePtr( win
);
649 title
= ICONTITLE_Create( hwnd
);
650 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
652 DestroyWindow( title
);
655 win
->icon_title
= title
;
656 WIN_ReleasePtr( win
);
658 if (!IsWindowVisible(title
))
660 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
661 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
662 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
665 else if (title
) ShowWindow( title
, SW_HIDE
);
670 /*******************************************************************
671 * WINPOS_GetMinMaxInfo
673 * Get the minimized and maximized information for a window.
675 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
676 POINT
*minTrack
, POINT
*maxTrack
)
681 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
683 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
687 /* Compute default values */
689 GetWindowRect(hwnd
, &rc
);
690 MinMax
.ptReserved
.x
= rc
.left
;
691 MinMax
.ptReserved
.y
= rc
.top
;
693 if ((style
& WS_CAPTION
) == WS_CAPTION
)
694 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
696 adjustedStyle
= style
;
698 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
699 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
704 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
705 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
706 if (style
& (WS_DLGFRAME
| WS_BORDER
))
708 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
709 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
713 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
714 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
716 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
717 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
718 MinMax
.ptMaxPosition
.x
= -xinc
;
719 MinMax
.ptMaxPosition
.y
= -yinc
;
721 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
723 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
724 WIN_ReleasePtr( win
);
727 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
729 /* if the app didn't change the values, adapt them for the current monitor */
731 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
734 MONITORINFO mon_info
;
736 mon_info
.cbSize
= sizeof(mon_info
);
737 GetMonitorInfoW( monitor
, &mon_info
);
739 rc_work
= mon_info
.rcMonitor
;
741 if (style
& WS_MAXIMIZEBOX
)
743 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
744 rc_work
= mon_info
.rcWork
;
747 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
748 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
750 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
751 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
753 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
755 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
756 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
760 /* Some sanity checks */
762 TRACE("%d %d / %d %d / %d %d / %d %d\n",
763 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
764 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
765 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
766 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
767 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
768 MinMax
.ptMinTrackSize
.x
);
769 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
770 MinMax
.ptMinTrackSize
.y
);
772 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
773 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
774 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
775 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
779 /***********************************************************************
782 * Find a suitable place for an iconic window.
784 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
786 RECT rect
, rectParent
;
789 int xspacing
, yspacing
;
791 parent
= GetAncestor( hwnd
, GA_PARENT
);
792 GetClientRect( parent
, &rectParent
);
793 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
794 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
795 return pt
; /* The icon already has a suitable position */
797 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
798 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
800 /* Check if another icon already occupies this spot */
801 /* FIXME: this is completely inefficient */
803 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
804 tmp
= CreateRectRgn( 0, 0, 0, 0 );
805 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
808 if (child
== hwnd
) continue;
809 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
811 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
813 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
814 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
815 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
816 WIN_ReleasePtr( childPtr
);
820 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
822 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
824 rect
.right
= rect
.left
+ xspacing
;
825 rect
.top
= rect
.bottom
- yspacing
;
826 if (!RectInRegion( hrgn
, &rect
))
828 /* No window was found, so it's OK for us */
829 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
830 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
831 DeleteObject( hrgn
);
836 DeleteObject( hrgn
);
842 /***********************************************************************
845 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
853 TRACE("%p %u\n", hwnd
, cmd
);
855 wpl
.length
= sizeof(wpl
);
856 GetWindowPlacement( hwnd
, &wpl
);
858 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
859 return SWP_NOSIZE
| SWP_NOMOVE
;
861 if (IsIconic( hwnd
))
865 case SW_SHOWMINNOACTIVE
:
866 case SW_SHOWMINIMIZED
:
867 case SW_FORCEMINIMIZE
:
869 return SWP_NOSIZE
| SWP_NOMOVE
;
871 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
872 swpFlags
|= SWP_NOCOPYBITS
;
877 case SW_SHOWMINNOACTIVE
:
878 case SW_SHOWMINIMIZED
:
879 case SW_FORCEMINIMIZE
:
881 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
882 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
883 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
884 WIN_ReleasePtr( wndPtr
);
886 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
888 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
890 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
891 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
892 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
893 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
894 swpFlags
|= SWP_NOCOPYBITS
;
898 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
899 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
901 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
903 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
904 if (old_style
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, FALSE
);
906 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
907 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
908 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
911 case SW_SHOWNOACTIVATE
:
914 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
915 if (old_style
& WS_MINIMIZE
)
919 WINPOS_ShowIconTitle( hwnd
, FALSE
);
921 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
922 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
923 WIN_ReleasePtr( wndPtr
);
926 /* Restore to maximized position */
927 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
928 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
929 swpFlags
|= SWP_STATECHANGED
;
930 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
931 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
935 else if (!(old_style
& WS_MAXIMIZE
)) break;
937 swpFlags
|= SWP_STATECHANGED
;
939 /* Restore to normal position */
941 *rect
= wpl
.rcNormalPosition
;
949 /***********************************************************************
952 * Implementation of ShowWindow and ShowWindowAsync.
954 static BOOL
show_window( HWND hwnd
, INT cmd
)
958 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
959 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
960 BOOL showFlag
= TRUE
;
961 RECT newPos
= {0, 0, 0, 0};
964 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
969 if (!wasVisible
) return FALSE
;
971 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
972 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
975 case SW_SHOWMINNOACTIVE
:
977 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
978 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
980 case SW_SHOWMINIMIZED
:
981 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
982 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
983 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
986 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
987 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
988 swp
|= SWP_FRAMECHANGED
;
989 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
990 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
994 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
995 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
998 if (wasVisible
) return TRUE
;
999 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1000 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1003 case SW_SHOWNOACTIVATE
:
1004 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1008 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1009 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1010 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1011 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1013 swp
|= SWP_FRAMECHANGED
;
1014 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1018 if (wasVisible
) return TRUE
;
1019 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1021 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1027 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1029 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1030 if (!IsWindow( hwnd
)) return wasVisible
;
1033 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1035 parent
= GetAncestor( hwnd
, GA_PARENT
);
1036 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1038 /* if parent is not visible simply toggle WS_VISIBLE and return */
1039 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1040 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1043 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1044 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1050 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1052 /* FIXME: This will cause the window to be activated irrespective
1053 * of whether it is owned by the same thread. Has to be done
1057 if (hwnd
== GetActiveWindow())
1058 WINPOS_ActivateOtherWindow(hwnd
);
1060 /* Revert focus to parent */
1061 hFocus
= GetFocus();
1062 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
1064 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1065 if (parent
== GetDesktopWindow()) parent
= 0;
1071 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1073 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1075 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1077 /* should happen only in CreateWindowEx() */
1078 int wParam
= SIZE_RESTORED
;
1079 RECT client
= wndPtr
->rectClient
;
1080 LPARAM lparam
= MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
);
1082 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1083 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1084 else if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1086 wParam
= SIZE_MINIMIZED
;
1089 WIN_ReleasePtr( wndPtr
);
1091 SendMessageW( hwnd
, WM_SIZE
, wParam
, lparam
);
1092 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1094 else WIN_ReleasePtr( wndPtr
);
1096 /* if previous state was minimized Windows sets focus to the window */
1097 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1103 /***********************************************************************
1104 * ShowWindowAsync (USER32.@)
1106 * doesn't wait; returns immediately.
1107 * used by threads to toggle windows in other (possibly hanging) threads
1109 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1113 if (is_broadcast(hwnd
))
1115 SetLastError( ERROR_INVALID_PARAMETER
);
1119 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1120 return show_window( full_handle
, cmd
);
1122 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1126 /***********************************************************************
1127 * ShowWindow (USER32.@)
1129 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1133 if (is_broadcast(hwnd
))
1135 SetLastError( ERROR_INVALID_PARAMETER
);
1138 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1139 return show_window( full_handle
, cmd
);
1141 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1145 /***********************************************************************
1146 * GetInternalWindowPos (USER32.@)
1148 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1151 WINDOWPLACEMENT wndpl
;
1152 if (GetWindowPlacement( hwnd
, &wndpl
))
1154 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1155 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1156 return wndpl
.showCmd
;
1162 /***********************************************************************
1163 * GetWindowPlacement (USER32.@)
1166 * Fails if wndpl->length of Win95 (!) apps is invalid.
1168 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1170 WND
*pWnd
= WIN_GetPtr( hwnd
);
1172 if (!pWnd
) return FALSE
;
1174 if (pWnd
== WND_DESKTOP
)
1176 wndpl
->length
= sizeof(*wndpl
);
1177 wndpl
->showCmd
= SW_SHOWNORMAL
;
1179 wndpl
->ptMinPosition
.x
= -1;
1180 wndpl
->ptMinPosition
.y
= -1;
1181 wndpl
->ptMaxPosition
.x
= -1;
1182 wndpl
->ptMaxPosition
.y
= -1;
1183 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1186 if (pWnd
== WND_OTHER_PROCESS
)
1188 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
1192 /* update the placement according to the current style */
1193 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1195 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1196 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1198 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1200 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1201 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1205 pWnd
->normal_rect
= pWnd
->rectWindow
;
1208 wndpl
->length
= sizeof(*wndpl
);
1209 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1210 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1212 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1213 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1214 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1217 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1218 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1219 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1220 WIN_ReleasePtr( pWnd
);
1222 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1223 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1224 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1225 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1229 /* make sure the specified rect is visible on screen */
1230 static void make_rect_onscreen( RECT
*rect
)
1233 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1235 info
.cbSize
= sizeof(info
);
1236 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1237 /* FIXME: map coordinates from rcWork to rcMonitor */
1238 if (rect
->right
<= info
.rcWork
.left
)
1240 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1241 rect
->left
= info
.rcWork
.left
;
1243 else if (rect
->left
>= info
.rcWork
.right
)
1245 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1246 rect
->right
= info
.rcWork
.right
;
1248 if (rect
->bottom
<= info
.rcWork
.top
)
1250 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1251 rect
->top
= info
.rcWork
.top
;
1253 else if (rect
->top
>= info
.rcWork
.bottom
)
1255 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1256 rect
->bottom
= info
.rcWork
.bottom
;
1260 /* make sure the specified point is visible on screen */
1261 static void make_point_onscreen( POINT
*pt
)
1265 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1266 make_rect_onscreen( &rect
);
1272 /***********************************************************************
1273 * WINPOS_SetPlacement
1275 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1278 WND
*pWnd
= WIN_GetPtr( hwnd
);
1279 WINDOWPLACEMENT wp
= *wndpl
;
1281 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1282 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1283 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1285 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1286 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1287 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1288 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1289 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1290 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1292 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1294 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1295 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1296 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1298 style
= pWnd
->dwStyle
;
1300 WIN_ReleasePtr( pWnd
);
1302 if( style
& WS_MINIMIZE
)
1304 if (flags
& PLACE_MIN
)
1306 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1307 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1308 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1311 else if( style
& WS_MAXIMIZE
)
1313 if (flags
& PLACE_MAX
)
1314 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1315 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1317 else if( flags
& PLACE_RECT
)
1318 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1319 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1320 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1321 SWP_NOZORDER
| SWP_NOACTIVATE
);
1323 ShowWindow( hwnd
, wndpl
->showCmd
);
1325 if (IsIconic( hwnd
))
1327 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1329 /* SDK: ...valid only the next time... */
1330 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1332 pWnd
= WIN_GetPtr( hwnd
);
1333 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1335 pWnd
->flags
|= WIN_RESTORE_MAX
;
1336 WIN_ReleasePtr( pWnd
);
1344 /***********************************************************************
1345 * SetWindowPlacement (USER32.@)
1348 * Fails if wndpl->length of Win95 (!) apps is invalid.
1350 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1352 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1353 if (!wpl
) return FALSE
;
1354 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1355 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1359 /***********************************************************************
1360 * AnimateWindow (USER32.@)
1361 * Shows/Hides a window with an animation
1364 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1366 FIXME("partial stub\n");
1368 /* If trying to show/hide and it's already *
1369 * shown/hidden or invalid window, fail with *
1370 * invalid parameter */
1371 if(!IsWindow(hwnd
) ||
1372 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1373 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1375 SetLastError(ERROR_INVALID_PARAMETER
);
1379 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1384 /***********************************************************************
1385 * SetInternalWindowPos (USER32.@)
1387 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1388 LPRECT rect
, LPPOINT pt
)
1390 WINDOWPLACEMENT wndpl
;
1393 wndpl
.length
= sizeof(wndpl
);
1394 wndpl
.showCmd
= showCmd
;
1395 wndpl
.flags
= flags
= 0;
1400 wndpl
.flags
|= WPF_SETMINPOSITION
;
1401 wndpl
.ptMinPosition
= *pt
;
1405 flags
|= PLACE_RECT
;
1406 wndpl
.rcNormalPosition
= *rect
;
1408 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1412 /*******************************************************************
1413 * can_activate_window
1415 * Check if we can activate the specified window.
1417 static BOOL
can_activate_window( HWND hwnd
)
1421 if (!hwnd
) return FALSE
;
1422 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1423 if (!(style
& WS_VISIBLE
)) return FALSE
;
1424 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1425 return !(style
& WS_DISABLED
);
1429 /*******************************************************************
1430 * WINPOS_ActivateOtherWindow
1432 * Activates window other than pWnd.
1434 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1438 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1440 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1441 if (can_activate_window( hwndTo
)) goto done
;
1447 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1448 if (can_activate_window( hwndTo
)) break;
1452 fg
= GetForegroundWindow();
1453 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1454 if (!fg
|| (hwnd
== fg
))
1456 if (SetForegroundWindow( hwndTo
)) return;
1458 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1462 /***********************************************************************
1463 * WINPOS_HandleWindowPosChanging
1465 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1467 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1469 POINT minTrack
, maxTrack
;
1470 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1472 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1473 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1475 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1476 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1477 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1478 if (!(style
& WS_MINIMIZE
))
1480 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1481 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1488 /***********************************************************************
1491 static void dump_winpos_flags(UINT flags
)
1493 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1494 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1495 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1496 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1497 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1499 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1500 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1501 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1502 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1503 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1504 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1505 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1506 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1507 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1508 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1509 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1510 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1511 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1512 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1513 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1514 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1516 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1520 /***********************************************************************
1521 * SWP_DoWinPosChanging
1523 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1527 /* Send WM_WINDOWPOSCHANGING message */
1529 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1530 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1532 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1533 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1535 /* Calculate new position and size */
1537 *pNewWindowRect
= wndPtr
->rectWindow
;
1538 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1539 : wndPtr
->rectClient
;
1541 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1543 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1544 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1546 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1548 pNewWindowRect
->left
= pWinpos
->x
;
1549 pNewWindowRect
->top
= pWinpos
->y
;
1550 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1551 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1553 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1554 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1556 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1558 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1559 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1560 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1561 TRACE( "current %s style %08x new %s\n",
1562 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1563 wine_dbgstr_rect( pNewWindowRect
));
1565 WIN_ReleasePtr( wndPtr
);
1569 /***********************************************************************
1572 * Compute the valid rects from the old and new client rect and WVR_* flags.
1573 * Helper for WM_NCCALCSIZE handling.
1575 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1580 if (flags
& WVR_REDRAW
)
1582 SetRectEmpty( &valid
[0] );
1583 SetRectEmpty( &valid
[1] );
1587 if (flags
& WVR_VALIDRECTS
)
1589 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1590 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1592 SetRectEmpty( &valid
[0] );
1593 SetRectEmpty( &valid
[1] );
1596 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1600 valid
[0] = *new_client
;
1601 valid
[1] = *old_client
;
1604 /* make sure the rectangles have the same size */
1605 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1606 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1608 if (flags
& WVR_ALIGNBOTTOM
)
1610 valid
[0].top
= valid
[0].bottom
- cy
;
1611 valid
[1].top
= valid
[1].bottom
- cy
;
1615 valid
[0].bottom
= valid
[0].top
+ cy
;
1616 valid
[1].bottom
= valid
[1].top
+ cy
;
1618 if (flags
& WVR_ALIGNRIGHT
)
1620 valid
[0].left
= valid
[0].right
- cx
;
1621 valid
[1].left
= valid
[1].right
- cx
;
1625 valid
[0].right
= valid
[0].left
+ cx
;
1626 valid
[1].right
= valid
[1].left
+ cx
;
1631 /***********************************************************************
1634 * fix Z order taking into account owned popups -
1635 * basically we need to maintain them above the window that owns them
1637 * FIXME: hide/show owned popups when owner visibility changes.
1639 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1641 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1642 HWND owner
, *list
= NULL
;
1645 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1647 if ((style
& WS_POPUP
) && (owner
= GetWindow( hwnd
, GW_OWNER
)))
1649 /* make sure this popup stays above the owner */
1651 if (hwndInsertAfter
!= HWND_TOP
&& hwndInsertAfter
!= HWND_TOPMOST
)
1653 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1655 for (i
= 0; list
[i
]; i
++)
1657 if (list
[i
] == owner
)
1659 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1660 else hwndInsertAfter
= HWND_TOP
;
1664 if (hwndInsertAfter
== HWND_NOTOPMOST
)
1666 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) break;
1668 else if (list
[i
] == hwndInsertAfter
) break;
1672 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1674 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1675 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1678 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1680 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1682 /* skip all the topmost windows */
1683 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1686 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1688 /* skip windows that are already placed correctly */
1689 for (i
= 0; list
[i
]; i
++)
1691 if (list
[i
] == hwndInsertAfter
) break;
1692 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1696 for ( ; list
[i
]; i
++)
1698 if (list
[i
] == hwnd
) break;
1699 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
)) continue;
1700 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1701 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1702 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1703 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1704 hwndInsertAfter
= list
[i
];
1708 HeapFree( GetProcessHeap(), 0, list
);
1709 return hwndInsertAfter
;
1712 /***********************************************************************
1715 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1721 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1723 /* Send WM_NCCALCSIZE message to get new client area */
1724 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1726 NCCALCSIZE_PARAMS params
;
1727 WINDOWPOS winposCopy
;
1729 params
.rgrc
[0] = *pNewWindowRect
;
1730 params
.rgrc
[1] = wndPtr
->rectWindow
;
1731 params
.rgrc
[2] = wndPtr
->rectClient
;
1732 params
.lppos
= &winposCopy
;
1733 winposCopy
= *pWinpos
;
1734 WIN_ReleasePtr( wndPtr
);
1736 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1738 *pNewClientRect
= params
.rgrc
[0];
1740 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1742 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1743 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1744 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1746 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1747 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1748 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1750 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1751 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1752 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1754 wvrFlags
&= ~WVR_HREDRAW
;
1756 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1757 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1758 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1760 wvrFlags
&= ~WVR_VREDRAW
;
1762 validRects
[0] = params
.rgrc
[1];
1763 validRects
[1] = params
.rgrc
[2];
1767 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1768 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1769 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1770 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1773 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1775 SetRectEmpty( &validRects
[0] );
1776 SetRectEmpty( &validRects
[1] );
1778 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1780 WIN_ReleasePtr( wndPtr
);
1784 /* fix redundant flags and values in the WINDOWPOS structure */
1785 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1788 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1791 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1793 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1796 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1798 /* Finally make sure that all coordinates are valid */
1799 if (winpos
->x
< -32768) winpos
->x
= -32768;
1800 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1801 if (winpos
->y
< -32768) winpos
->y
= -32768;
1802 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1804 if (winpos
->cx
< 0) winpos
->cx
= 0;
1805 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1806 if (winpos
->cy
< 0) winpos
->cy
= 0;
1807 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1809 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1810 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1812 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1815 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1816 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1819 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1820 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1821 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1823 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1824 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1826 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1828 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1829 (winpos
->flags
& SWP_NOZORDER
||
1830 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1832 winpos
->flags
&= ~SWP_NOZORDER
;
1833 winpos
->hwndInsertAfter
= HWND_TOP
;
1837 /* Check hwndInsertAfter */
1838 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1840 /* fix sign extension */
1841 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1842 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1844 /* hwndInsertAfter must be a sibling of the window */
1845 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1847 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1848 winpos
->flags
|= SWP_NOZORDER
;
1850 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1852 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1853 winpos
->flags
|= SWP_NOZORDER
;
1855 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1857 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1858 winpos
->flags
|= SWP_NOZORDER
;
1860 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1862 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1863 winpos
->flags
|= SWP_NOZORDER
;
1867 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1870 /* don't need to change the Zorder of hwnd if it's already inserted
1871 * after hwndInsertAfter or when inserting hwnd after itself.
1873 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1874 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1875 winpos
->flags
|= SWP_NOZORDER
;
1879 WIN_ReleasePtr( wndPtr
);
1884 /***********************************************************************
1887 * Backend implementation of SetWindowPos.
1889 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1890 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
1894 RECT visible_rect
, old_window_rect
;
1896 visible_rect
= *window_rect
;
1897 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
1898 window_rect
, client_rect
, &visible_rect
);
1900 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
1901 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
1903 old_window_rect
= win
->rectWindow
;
1904 SERVER_START_REQ( set_window_pos
)
1906 req
->handle
= wine_server_user_handle( hwnd
);
1907 req
->previous
= wine_server_user_handle( insert_after
);
1908 req
->flags
= swp_flags
;
1909 req
->window
.left
= window_rect
->left
;
1910 req
->window
.top
= window_rect
->top
;
1911 req
->window
.right
= window_rect
->right
;
1912 req
->window
.bottom
= window_rect
->bottom
;
1913 req
->client
.left
= client_rect
->left
;
1914 req
->client
.top
= client_rect
->top
;
1915 req
->client
.right
= client_rect
->right
;
1916 req
->client
.bottom
= client_rect
->bottom
;
1917 if (memcmp( window_rect
, &visible_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
1919 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
1920 if (!IsRectEmpty( &valid_rects
[0] ))
1921 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
1923 if ((ret
= !wine_server_call( req
)))
1925 win
->dwStyle
= reply
->new_style
;
1926 win
->dwExStyle
= reply
->new_ex_style
;
1927 win
->rectWindow
= *window_rect
;
1928 win
->rectClient
= *client_rect
;
1932 WIN_ReleasePtr( win
);
1936 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
1937 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
)))
1938 invalidate_dce( hwnd
, &old_window_rect
);
1940 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
1941 client_rect
, &visible_rect
, valid_rects
);
1947 /***********************************************************************
1950 * User32 internal function
1952 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1954 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1957 orig_flags
= winpos
->flags
;
1959 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1960 if (!(winpos
->flags
& SWP_NOMOVE
))
1962 if (winpos
->x
< -32768) winpos
->x
= -32768;
1963 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1964 if (winpos
->y
< -32768) winpos
->y
= -32768;
1965 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1967 if (!(winpos
->flags
& SWP_NOSIZE
))
1969 if (winpos
->cx
< 0) winpos
->cx
= 0;
1970 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1971 if (winpos
->cy
< 0) winpos
->cy
= 0;
1972 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1975 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1977 /* Fix redundant flags */
1978 if (!fixup_flags( winpos
)) return FALSE
;
1980 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1982 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1983 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
1986 /* Common operations */
1988 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
1990 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
1991 &newWindowRect
, &newClientRect
, valid_rects
))
1994 /* erase parent when hiding or resizing child */
1995 if (!(orig_flags
& SWP_DEFERERASE
) &&
1996 ((orig_flags
& SWP_HIDEWINDOW
) ||
1997 (!(orig_flags
& SWP_SHOWWINDOW
) &&
1998 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
2000 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2001 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
2002 erase_now( parent
, 0 );
2005 if( winpos
->flags
& SWP_HIDEWINDOW
)
2006 HideCaret(winpos
->hwnd
);
2007 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2008 ShowCaret(winpos
->hwnd
);
2010 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2012 /* child windows get WM_CHILDACTIVATE message */
2013 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2014 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2016 SetForegroundWindow( winpos
->hwnd
);
2019 /* And last, send the WM_WINDOWPOSCHANGED message */
2021 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2023 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2025 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2026 and always contains final window position.
2028 winpos
->x
= newWindowRect
.left
;
2029 winpos
->y
= newWindowRect
.top
;
2030 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2031 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2032 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2037 /***********************************************************************
2038 * SetWindowPos (USER32.@)
2040 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2041 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2045 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2046 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2047 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2049 if (is_broadcast(hwnd
))
2051 SetLastError( ERROR_INVALID_PARAMETER
);
2055 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2056 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2061 winpos
.flags
= flags
;
2063 if (WIN_IsCurrentThread( hwnd
))
2064 return USER_SetWindowPos(&winpos
);
2066 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2070 /***********************************************************************
2071 * BeginDeferWindowPos (USER32.@)
2073 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2078 TRACE("%d\n", count
);
2082 SetLastError(ERROR_INVALID_PARAMETER
);
2085 /* Windows allows zero count, in which case it allocates context for 8 moves */
2086 if (count
== 0) count
= 8;
2088 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
2089 if (!handle
) return 0;
2090 pDWP
= USER_HEAP_LIN_ADDR( handle
);
2091 pDWP
->actualCount
= 0;
2092 pDWP
->suggestedCount
= count
;
2094 pDWP
->wMagic
= DWP_MAGIC
;
2095 pDWP
->hwndParent
= 0;
2097 TRACE("returning hdwp %p\n", handle
);
2102 /***********************************************************************
2103 * DeferWindowPos (USER32.@)
2105 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2106 INT x
, INT y
, INT cx
, INT cy
,
2111 HDWP newhdwp
= hdwp
,retvalue
;
2113 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2114 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2116 hwnd
= WIN_GetFullHandle( hwnd
);
2117 if (is_desktop_window( hwnd
)) return 0;
2119 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
2123 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2125 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2127 /* Merge with the other changes */
2128 if (!(flags
& SWP_NOZORDER
))
2130 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2132 if (!(flags
& SWP_NOMOVE
))
2134 pDWP
->winPos
[i
].x
= x
;
2135 pDWP
->winPos
[i
].y
= y
;
2137 if (!(flags
& SWP_NOSIZE
))
2139 pDWP
->winPos
[i
].cx
= cx
;
2140 pDWP
->winPos
[i
].cy
= cy
;
2142 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2143 SWP_NOZORDER
| SWP_NOREDRAW
|
2144 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2146 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2152 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2154 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2155 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
2161 pDWP
= USER_HEAP_LIN_ADDR( newhdwp
);
2162 pDWP
->suggestedCount
++;
2164 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2165 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2166 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2167 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2168 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2169 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2170 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2171 pDWP
->actualCount
++;
2179 /***********************************************************************
2180 * EndDeferWindowPos (USER32.@)
2182 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2189 TRACE("%p\n", hdwp
);
2191 pDWP
= USER_HEAP_LIN_ADDR( hdwp
);
2192 if (!pDWP
) return FALSE
;
2193 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2195 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2196 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2197 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2199 if (WIN_IsCurrentThread( winpos
->hwnd
))
2200 res
= USER_SetWindowPos( winpos
);
2202 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2204 USER_HEAP_FREE( hdwp
);
2209 /***********************************************************************
2210 * ArrangeIconicWindows (USER32.@)
2212 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2216 INT x
, y
, xspacing
, yspacing
;
2218 GetClientRect( parent
, &rectParent
);
2219 x
= rectParent
.left
;
2220 y
= rectParent
.bottom
;
2221 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2222 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2224 hwndChild
= GetWindow( parent
, GW_CHILD
);
2227 if( IsIconic( hwndChild
) )
2229 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2231 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2232 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
2233 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2234 if( IsWindow(hwndChild
) )
2235 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2237 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
2240 x
= rectParent
.left
;
2244 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2250 /***********************************************************************
2253 * Draw the frame used when moving or resizing window.
2255 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
2259 const int width
= GetSystemMetrics(SM_CXFRAME
);
2260 const int height
= GetSystemMetrics(SM_CYFRAME
);
2262 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2263 PatBlt( hdc
, rect
->left
, rect
->top
,
2264 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
2265 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
2266 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2267 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
2268 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
2269 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
2270 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2271 SelectObject( hdc
, hbrush
);
2273 else DrawFocusRect( hdc
, rect
);
2277 /***********************************************************************
2280 * Initialization of a move or resize, when initiated from a menu choice.
2281 * Return hit test code for caption or sizing border.
2283 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2290 GetWindowRect( hwnd
, &rectWindow
);
2292 if ((wParam
& 0xfff0) == SC_MOVE
)
2294 /* Move pointer at the center of the caption */
2295 RECT rect
= rectWindow
;
2296 /* Note: to be exactly centered we should take the different types
2297 * of border into account, but it shouldn't make more than a few pixels
2298 * of difference so let's not bother with that */
2299 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2300 if (style
& WS_SYSMENU
)
2301 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2302 if (style
& WS_MINIMIZEBOX
)
2303 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2304 if (style
& WS_MAXIMIZEBOX
)
2305 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2306 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2307 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2308 hittest
= HTCAPTION
;
2313 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2317 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2318 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2323 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2324 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2325 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2326 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2337 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2338 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2342 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2343 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2347 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2348 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2352 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2353 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2361 TranslateMessage( &msg
);
2362 DispatchMessageW( &msg
);
2368 SetCursorPos( pt
.x
, pt
.y
);
2369 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2374 /***********************************************************************
2375 * WINPOS_SysCommandSizeMove
2377 * Perform SC_MOVE and SC_SIZE commands.
2379 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2382 RECT sizingRect
, mouseRect
, origRect
;
2385 LONG hittest
= (LONG
)(wParam
& 0x0f);
2386 WPARAM syscommand
= wParam
& 0xfff0;
2387 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2388 POINT minTrack
, maxTrack
;
2389 POINT capturePoint
, pt
;
2390 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2391 BOOL thickframe
= HAS_THICKFRAME( style
);
2392 BOOL iconic
= style
& WS_MINIMIZE
;
2394 DWORD dwPoint
= GetMessagePos ();
2395 BOOL DragFullWindows
= TRUE
;
2397 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2399 pt
.x
= (short)LOWORD(dwPoint
);
2400 pt
.y
= (short)HIWORD(dwPoint
);
2403 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2404 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2406 if (syscommand
== SC_MOVE
)
2408 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2409 if (!hittest
) return;
2413 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2414 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2417 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2418 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2421 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2427 /* Get min/max info */
2429 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2430 GetWindowRect( hwnd
, &sizingRect
);
2431 if (style
& WS_CHILD
)
2433 parent
= GetParent(hwnd
);
2434 /* make sizing rect relative to parent */
2435 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2436 GetClientRect( parent
, &mouseRect
);
2441 GetClientRect( GetDesktopWindow(), &mouseRect
);
2442 mouseRect
.left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
2443 mouseRect
.top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
2444 mouseRect
.right
= mouseRect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
2445 mouseRect
.bottom
= mouseRect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
2447 origRect
= sizingRect
;
2449 if (ON_LEFT_BORDER(hittest
))
2451 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
2452 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
2454 else if (ON_RIGHT_BORDER(hittest
))
2456 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
2457 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
2459 if (ON_TOP_BORDER(hittest
))
2461 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
2462 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
2464 else if (ON_BOTTOM_BORDER(hittest
))
2466 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
2467 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
2469 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2471 /* Retrieve a default cache DC (without using the window style) */
2472 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2474 if( iconic
) /* create a cursor for dragging */
2476 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2477 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2478 if( !hDragCursor
) iconic
= FALSE
;
2481 /* we only allow disabling the full window drag for child windows */
2482 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2484 /* repaint the window before moving it around */
2485 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2487 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2488 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2494 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2495 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2497 /* Exit on button-up, Return, or Esc */
2498 if ((msg
.message
== WM_LBUTTONUP
) ||
2499 ((msg
.message
== WM_KEYDOWN
) &&
2500 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2502 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2504 TranslateMessage( &msg
);
2505 DispatchMessageW( &msg
);
2506 continue; /* We are not interested in other messages */
2511 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2513 case VK_UP
: pt
.y
-= 8; break;
2514 case VK_DOWN
: pt
.y
+= 8; break;
2515 case VK_LEFT
: pt
.x
-= 8; break;
2516 case VK_RIGHT
: pt
.x
+= 8; break;
2519 pt
.x
= max( pt
.x
, mouseRect
.left
);
2520 pt
.x
= min( pt
.x
, mouseRect
.right
);
2521 pt
.y
= max( pt
.y
, mouseRect
.top
);
2522 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2524 dx
= pt
.x
- capturePoint
.x
;
2525 dy
= pt
.y
- capturePoint
.y
;
2533 if( iconic
) /* ok, no system popup tracking */
2535 hOldCursor
= SetCursor(hDragCursor
);
2537 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2539 else if(!DragFullWindows
)
2540 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2543 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2546 RECT newRect
= sizingRect
;
2547 WPARAM wpSizingHit
= 0;
2549 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2550 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2551 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2552 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2553 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2554 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2557 /* determine the hit location */
2558 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2559 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2560 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2564 if(!DragFullWindows
)
2565 draw_moving_frame( hdc
, &newRect
, thickframe
);
2567 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2568 newRect
.right
- newRect
.left
,
2569 newRect
.bottom
- newRect
.top
,
2570 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2572 sizingRect
= newRect
;
2579 if( moved
) /* restore cursors, show icon title later on */
2581 ShowCursor( FALSE
);
2582 SetCursor( hOldCursor
);
2585 else if (moved
&& !DragFullWindows
)
2587 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2590 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2591 ReleaseDC( parent
, hdc
);
2593 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2596 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2597 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2599 /* window moved or resized */
2602 /* if the moving/resizing isn't canceled call SetWindowPos
2603 * with the new position or the new size of the window
2605 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2607 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2608 if(!DragFullWindows
|| iconic
)
2609 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2610 sizingRect
.right
- sizingRect
.left
,
2611 sizingRect
.bottom
- sizingRect
.top
,
2612 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2615 { /* restore previous size/position */
2617 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2618 origRect
.right
- origRect
.left
,
2619 origRect
.bottom
- origRect
.top
,
2620 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2626 /* Single click brings up the system menu when iconized */
2630 if(style
& WS_SYSMENU
)
2631 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2632 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2634 else WINPOS_ShowIconTitle( hwnd
, TRUE
);