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
)
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
);
159 /***********************************************************************
160 * SetWindowRgn (USER32.@)
162 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
164 static const RECT empty_rect
;
172 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
173 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
174 if (!GetRegionData( hrgn
, size
, data
))
176 HeapFree( GetProcessHeap(), 0, data
);
179 SERVER_START_REQ( set_window_region
)
182 req
->redraw
= (bRedraw
!= 0);
183 if (data
->rdh
.nCount
)
184 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
186 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
187 ret
= !wine_server_call_err( req
);
191 else /* clear existing region */
193 SERVER_START_REQ( set_window_region
)
196 req
->redraw
= (bRedraw
!= 0);
197 ret
= !wine_server_call_err( req
);
202 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
206 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
207 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
208 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
209 invalidate_dce( hwnd
, NULL
);
215 /***********************************************************************
216 * GetClientRect (USER32.@)
218 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
222 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
224 rect
->right
-= rect
->left
;
225 rect
->bottom
-= rect
->top
;
226 rect
->left
= rect
->top
= 0;
232 /*******************************************************************
233 * ClientToScreen (USER32.@)
235 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
237 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
242 /*******************************************************************
243 * ScreenToClient (USER32.@)
245 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
247 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
252 /***********************************************************************
253 * list_children_from_point
255 * Get the list of children that can contain point from the server.
256 * Point is in screen coordinates.
257 * Returned list must be freed by caller.
259 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
268 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
270 SERVER_START_REQ( get_window_children_from_point
)
275 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
276 if (!wine_server_call( req
)) count
= reply
->count
;
279 if (count
&& count
< size
)
284 HeapFree( GetProcessHeap(), 0, list
);
286 size
= count
+ 1; /* restart with a large enough buffer */
292 /***********************************************************************
293 * WINPOS_WindowFromPoint
295 * Find the window and hittest for a given point.
297 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
302 if (!hwndScope
) hwndScope
= GetDesktopWindow();
304 *hittest
= HTNOWHERE
;
306 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
308 /* now determine the hittest */
310 for (i
= 0; list
[i
]; i
++)
312 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
314 /* If window is minimized or disabled, return at once */
315 if (style
& WS_MINIMIZE
)
317 *hittest
= HTCAPTION
;
320 if (style
& WS_DISABLED
)
325 /* Send WM_NCCHITTEST (if same thread) */
326 if (!WIN_IsCurrentThread( list
[i
] ))
331 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
332 if (res
!= HTTRANSPARENT
)
334 *hittest
= res
; /* Found the window */
337 /* continue search with next window in z-order */
340 HeapFree( GetProcessHeap(), 0, list
);
341 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
346 /*******************************************************************
347 * WindowFromPoint (USER32.@)
349 HWND WINAPI
WindowFromPoint( POINT pt
)
352 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
356 /*******************************************************************
357 * ChildWindowFromPoint (USER32.@)
359 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
361 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
364 /*******************************************************************
365 * RealChildWindowFromPoint (USER32.@)
367 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
369 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
);
372 /*******************************************************************
373 * ChildWindowFromPointEx (USER32.@)
375 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
377 /* pt is in the client coordinates */
383 GetClientRect( hwndParent
, &rect
);
384 if (!PtInRect( &rect
, pt
)) return 0;
385 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
387 for (i
= 0; list
[i
]; i
++)
389 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
390 if (!PtInRect( &rect
, pt
)) continue;
391 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
393 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
394 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
395 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
397 if (uFlags
& CWP_SKIPTRANSPARENT
)
399 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
404 HeapFree( GetProcessHeap(), 0, list
);
405 if (!retvalue
) retvalue
= hwndParent
;
410 /*******************************************************************
411 * WINPOS_GetWinOffset
413 * Calculate the offset between the origin of the two windows. Used
414 * to implement MapWindowPoints.
416 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
420 offset
->x
= offset
->y
= 0;
422 /* Translate source window origin to screen coords */
425 HWND hwnd
= hwndFrom
;
429 if (hwnd
== hwndTo
) return;
430 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
432 ERR( "bad hwndFrom = %p\n", hwnd
);
435 if (wndPtr
== WND_DESKTOP
) break;
436 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
439 offset
->x
+= wndPtr
->rectClient
.left
;
440 offset
->y
+= wndPtr
->rectClient
.top
;
442 hwnd
= wndPtr
->parent
;
443 WIN_ReleasePtr( wndPtr
);
447 /* Translate origin to destination window coords */
454 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
456 ERR( "bad hwndTo = %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
);
472 other_process
: /* one of the parents may belong to another process, do it the hard way */
473 offset
->x
= offset
->y
= 0;
474 SERVER_START_REQ( get_windows_offset
)
476 req
->from
= hwndFrom
;
478 if (!wine_server_call( req
))
480 offset
->x
= reply
->x
;
481 offset
->y
= reply
->y
;
488 /*******************************************************************
489 * MapWindowPoints (USER.258)
491 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
492 LPPOINT16 lppt
, UINT16 count
)
496 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
506 /*******************************************************************
507 * MapWindowPoints (USER32.@)
509 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
513 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
520 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
524 /***********************************************************************
525 * IsIconic (USER32.@)
527 BOOL WINAPI
IsIconic(HWND hWnd
)
529 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
533 /***********************************************************************
534 * IsZoomed (USER32.@)
536 BOOL WINAPI
IsZoomed(HWND hWnd
)
538 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
542 /*******************************************************************
543 * AllowSetForegroundWindow (USER32.@)
545 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
547 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
548 * implemented, then fix this function. */
553 /*******************************************************************
554 * LockSetForegroundWindow (USER32.@)
556 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
558 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
559 * implemented, then fix this function. */
564 /***********************************************************************
565 * BringWindowToTop (USER32.@)
567 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
569 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
573 /***********************************************************************
574 * MoveWindow (USER32.@)
576 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
579 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
580 if (!repaint
) flags
|= SWP_NOREDRAW
;
581 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
582 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
586 /***********************************************************************
587 * WINPOS_RedrawIconTitle
589 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
592 WND
*win
= WIN_GetPtr( hWnd
);
594 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
596 icon_title
= win
->icon_title
;
597 WIN_ReleasePtr( win
);
599 if (!icon_title
) return FALSE
;
600 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
601 InvalidateRect( icon_title
, NULL
, TRUE
);
605 /***********************************************************************
606 * WINPOS_ShowIconTitle
608 static BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
610 if (!GetPropA( hwnd
, "__wine_x11_managed" ))
612 WND
*win
= WIN_GetPtr( hwnd
);
615 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
617 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
618 title
= win
->icon_title
;
619 WIN_ReleasePtr( win
);
625 title
= ICONTITLE_Create( hwnd
);
626 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
628 DestroyWindow( title
);
631 win
->icon_title
= title
;
632 WIN_ReleasePtr( win
);
634 if (!IsWindowVisible(title
))
636 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
637 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
638 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
641 else if (title
) ShowWindow( title
, SW_HIDE
);
646 /*******************************************************************
647 * WINPOS_GetMinMaxInfo
649 * Get the minimized and maximized information for a window.
651 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
652 POINT
*minTrack
, POINT
*maxTrack
)
657 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
658 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
662 /* Compute default values */
664 GetWindowRect(hwnd
, &rc
);
665 MinMax
.ptReserved
.x
= rc
.left
;
666 MinMax
.ptReserved
.y
= rc
.top
;
668 if (style
& WS_CHILD
)
670 if ((style
& WS_CAPTION
) == WS_CAPTION
)
671 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
673 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
674 AdjustWindowRectEx(&rc
, style
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
676 /* avoid calculating this twice */
677 style
&= ~(WS_DLGFRAME
| WS_BORDER
| WS_THICKFRAME
);
679 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
680 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
684 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
685 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
687 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
688 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
689 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
690 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
692 if (HAS_DLGFRAME( style
, exstyle
))
694 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
695 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
700 if (HAS_THICKFRAME(style
))
702 xinc
+= GetSystemMetrics(SM_CXFRAME
);
703 yinc
+= GetSystemMetrics(SM_CYFRAME
);
705 if (style
& WS_BORDER
)
707 xinc
+= GetSystemMetrics(SM_CXBORDER
);
708 yinc
+= GetSystemMetrics(SM_CYBORDER
);
711 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
712 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
714 MinMax
.ptMaxPosition
.x
= -xinc
;
715 MinMax
.ptMaxPosition
.y
= -yinc
;
716 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
718 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
719 WIN_ReleasePtr( win
);
722 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
724 /* if the app didn't change the values, adapt them for the current monitor */
726 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
729 MONITORINFO mon_info
;
731 mon_info
.cbSize
= sizeof(mon_info
);
732 GetMonitorInfoW( monitor
, &mon_info
);
734 rc_work
= mon_info
.rcMonitor
;
736 if (style
& WS_MAXIMIZEBOX
)
738 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
739 rc_work
= mon_info
.rcWork
;
742 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
743 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
745 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
746 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
748 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
750 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
751 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
755 /* Some sanity checks */
757 TRACE("%d %d / %d %d / %d %d / %d %d\n",
758 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
759 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
760 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
761 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
762 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
763 MinMax
.ptMinTrackSize
.x
);
764 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
765 MinMax
.ptMinTrackSize
.y
);
767 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
768 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
769 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
770 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
774 /***********************************************************************
777 * Find a suitable place for an iconic window.
779 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
781 RECT rect
, rectParent
;
784 int xspacing
, yspacing
;
786 parent
= GetAncestor( hwnd
, GA_PARENT
);
787 GetClientRect( parent
, &rectParent
);
788 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
789 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
790 return pt
; /* The icon already has a suitable position */
792 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
793 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
795 /* Check if another icon already occupies this spot */
796 /* FIXME: this is completely inefficient */
798 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
799 tmp
= CreateRectRgn( 0, 0, 0, 0 );
800 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
803 if (child
== hwnd
) continue;
804 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
806 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
808 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
809 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
810 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
811 WIN_ReleasePtr( childPtr
);
815 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
817 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
819 rect
.right
= rect
.left
+ xspacing
;
820 rect
.top
= rect
.bottom
- yspacing
;
821 if (!RectInRegion( hrgn
, &rect
))
823 /* No window was found, so it's OK for us */
824 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
825 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
826 DeleteObject( hrgn
);
831 DeleteObject( hrgn
);
837 /***********************************************************************
840 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
848 TRACE("%p %u\n", hwnd
, cmd
);
850 wpl
.length
= sizeof(wpl
);
851 GetWindowPlacement( hwnd
, &wpl
);
853 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
854 return SWP_NOSIZE
| SWP_NOMOVE
;
856 if (IsIconic( hwnd
))
860 case SW_SHOWMINNOACTIVE
:
861 case SW_SHOWMINIMIZED
:
862 case SW_FORCEMINIMIZE
:
864 return SWP_NOSIZE
| SWP_NOMOVE
;
866 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
867 swpFlags
|= SWP_NOCOPYBITS
;
872 case SW_SHOWMINNOACTIVE
:
873 case SW_SHOWMINIMIZED
:
874 case SW_FORCEMINIMIZE
:
876 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
877 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
878 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
879 WIN_ReleasePtr( wndPtr
);
881 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
883 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
885 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
886 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
887 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
888 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
889 swpFlags
|= SWP_NOCOPYBITS
;
893 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
894 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
896 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
898 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
899 if (old_style
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, FALSE
);
901 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
902 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
903 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
906 case SW_SHOWNOACTIVATE
:
909 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
910 if (old_style
& WS_MINIMIZE
)
914 WINPOS_ShowIconTitle( hwnd
, FALSE
);
916 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
917 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
918 WIN_ReleasePtr( wndPtr
);
921 /* Restore to maximized position */
922 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
923 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
924 swpFlags
|= SWP_STATECHANGED
;
925 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
926 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
930 else if (!(old_style
& WS_MAXIMIZE
)) break;
932 swpFlags
|= SWP_STATECHANGED
;
934 /* Restore to normal position */
936 *rect
= wpl
.rcNormalPosition
;
944 /***********************************************************************
947 * Implementation of ShowWindow and ShowWindowAsync.
949 static BOOL
show_window( HWND hwnd
, INT cmd
)
953 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
954 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
955 BOOL showFlag
= TRUE
;
956 RECT newPos
= {0, 0, 0, 0};
959 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
964 if (!wasVisible
) return FALSE
;
966 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
967 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
970 case SW_SHOWMINNOACTIVE
:
972 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
973 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
975 case SW_SHOWMINIMIZED
:
976 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
977 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
978 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
981 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
982 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
983 swp
|= SWP_FRAMECHANGED
;
984 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
985 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
989 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
990 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
993 if (wasVisible
) return TRUE
;
994 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
995 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
998 case SW_SHOWNOACTIVATE
:
999 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1003 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1004 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1005 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1006 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1008 swp
|= SWP_FRAMECHANGED
;
1009 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1013 if (wasVisible
) return TRUE
;
1014 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1016 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1022 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1024 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1025 if (!IsWindow( hwnd
)) return wasVisible
;
1028 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1030 parent
= GetAncestor( hwnd
, GA_PARENT
);
1031 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1033 /* if parent is not visible simply toggle WS_VISIBLE and return */
1034 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1035 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1038 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1039 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1045 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1047 /* FIXME: This will cause the window to be activated irrespective
1048 * of whether it is owned by the same thread. Has to be done
1052 if (hwnd
== GetActiveWindow())
1053 WINPOS_ActivateOtherWindow(hwnd
);
1055 /* Revert focus to parent */
1056 hFocus
= GetFocus();
1057 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
1059 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1060 if (parent
== GetDesktopWindow()) parent
= 0;
1066 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1068 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1070 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1072 /* should happen only in CreateWindowEx() */
1073 int wParam
= SIZE_RESTORED
;
1074 RECT client
= wndPtr
->rectClient
;
1076 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1077 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1078 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1079 WIN_ReleasePtr( wndPtr
);
1081 SendMessageW( hwnd
, WM_SIZE
, wParam
,
1082 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
1083 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1085 else WIN_ReleasePtr( wndPtr
);
1087 /* if previous state was minimized Windows sets focus to the window */
1088 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1094 /***********************************************************************
1095 * ShowWindowAsync (USER32.@)
1097 * doesn't wait; returns immediately.
1098 * used by threads to toggle windows in other (possibly hanging) threads
1100 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1104 if (is_broadcast(hwnd
))
1106 SetLastError( ERROR_INVALID_PARAMETER
);
1110 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1111 return show_window( full_handle
, cmd
);
1113 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1117 /***********************************************************************
1118 * ShowWindow (USER32.@)
1120 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1124 if (is_broadcast(hwnd
))
1126 SetLastError( ERROR_INVALID_PARAMETER
);
1129 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1130 return show_window( full_handle
, cmd
);
1132 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1136 /***********************************************************************
1137 * GetInternalWindowPos (USER32.@)
1139 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1142 WINDOWPLACEMENT wndpl
;
1143 if (GetWindowPlacement( hwnd
, &wndpl
))
1145 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1146 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1147 return wndpl
.showCmd
;
1153 /***********************************************************************
1154 * GetWindowPlacement (USER32.@)
1157 * Fails if wndpl->length of Win95 (!) apps is invalid.
1159 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1161 WND
*pWnd
= WIN_GetPtr( hwnd
);
1163 if (!pWnd
) return FALSE
;
1165 if (pWnd
== WND_DESKTOP
)
1167 wndpl
->length
= sizeof(*wndpl
);
1168 wndpl
->showCmd
= SW_SHOWNORMAL
;
1170 wndpl
->ptMinPosition
.x
= -1;
1171 wndpl
->ptMinPosition
.y
= -1;
1172 wndpl
->ptMaxPosition
.x
= -1;
1173 wndpl
->ptMaxPosition
.y
= -1;
1174 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1177 if (pWnd
== WND_OTHER_PROCESS
)
1179 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
1183 /* update the placement according to the current style */
1184 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1186 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1187 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1189 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1191 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1192 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1196 pWnd
->normal_rect
= pWnd
->rectWindow
;
1199 wndpl
->length
= sizeof(*wndpl
);
1200 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1201 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1203 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1204 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1205 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1208 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1209 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1210 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1211 WIN_ReleasePtr( pWnd
);
1213 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1214 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1215 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1216 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1220 /* make sure the specified rect is visible on screen */
1221 static void make_rect_onscreen( RECT
*rect
)
1224 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1226 info
.cbSize
= sizeof(info
);
1227 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1228 /* FIXME: map coordinates from rcWork to rcMonitor */
1229 if (rect
->right
<= info
.rcWork
.left
)
1231 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1232 rect
->left
= info
.rcWork
.left
;
1234 else if (rect
->left
>= info
.rcWork
.right
)
1236 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1237 rect
->right
= info
.rcWork
.right
;
1239 if (rect
->bottom
<= info
.rcWork
.top
)
1241 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1242 rect
->top
= info
.rcWork
.top
;
1244 else if (rect
->top
>= info
.rcWork
.bottom
)
1246 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1247 rect
->bottom
= info
.rcWork
.bottom
;
1251 /* make sure the specified point is visible on screen */
1252 static void make_point_onscreen( POINT
*pt
)
1256 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1257 make_rect_onscreen( &rect
);
1263 /***********************************************************************
1264 * WINPOS_SetPlacement
1266 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1269 WND
*pWnd
= WIN_GetPtr( hwnd
);
1270 WINDOWPLACEMENT wp
= *wndpl
;
1272 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1273 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1274 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1276 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1277 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1278 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1279 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1280 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1281 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1283 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1285 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1286 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1287 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1289 style
= pWnd
->dwStyle
;
1291 WIN_ReleasePtr( pWnd
);
1293 if( style
& WS_MINIMIZE
)
1295 if (flags
& PLACE_MIN
)
1297 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1298 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1299 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1302 else if( style
& WS_MAXIMIZE
)
1304 if (flags
& PLACE_MAX
)
1305 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1306 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1308 else if( flags
& PLACE_RECT
)
1309 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1310 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1311 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1312 SWP_NOZORDER
| SWP_NOACTIVATE
);
1314 ShowWindow( hwnd
, wndpl
->showCmd
);
1316 if (IsIconic( hwnd
))
1318 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1320 /* SDK: ...valid only the next time... */
1321 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1323 pWnd
= WIN_GetPtr( hwnd
);
1324 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1326 pWnd
->flags
|= WIN_RESTORE_MAX
;
1327 WIN_ReleasePtr( pWnd
);
1335 /***********************************************************************
1336 * SetWindowPlacement (USER32.@)
1339 * Fails if wndpl->length of Win95 (!) apps is invalid.
1341 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1343 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1344 if (!wpl
) return FALSE
;
1345 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1346 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1350 /***********************************************************************
1351 * AnimateWindow (USER32.@)
1352 * Shows/Hides a window with an animation
1355 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1357 FIXME("partial stub\n");
1359 /* If trying to show/hide and it's already *
1360 * shown/hidden or invalid window, fail with *
1361 * invalid parameter */
1362 if(!IsWindow(hwnd
) ||
1363 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1364 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1366 SetLastError(ERROR_INVALID_PARAMETER
);
1370 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1375 /***********************************************************************
1376 * SetInternalWindowPos (USER32.@)
1378 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1379 LPRECT rect
, LPPOINT pt
)
1381 WINDOWPLACEMENT wndpl
;
1384 wndpl
.length
= sizeof(wndpl
);
1385 wndpl
.showCmd
= showCmd
;
1386 wndpl
.flags
= flags
= 0;
1391 wndpl
.flags
|= WPF_SETMINPOSITION
;
1392 wndpl
.ptMinPosition
= *pt
;
1396 flags
|= PLACE_RECT
;
1397 wndpl
.rcNormalPosition
= *rect
;
1399 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1403 /*******************************************************************
1404 * can_activate_window
1406 * Check if we can activate the specified window.
1408 static BOOL
can_activate_window( HWND hwnd
)
1412 if (!hwnd
) return FALSE
;
1413 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1414 if (!(style
& WS_VISIBLE
)) return FALSE
;
1415 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1416 return !(style
& WS_DISABLED
);
1420 /*******************************************************************
1421 * WINPOS_ActivateOtherWindow
1423 * Activates window other than pWnd.
1425 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1429 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1431 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1432 if (can_activate_window( hwndTo
)) goto done
;
1438 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1439 if (can_activate_window( hwndTo
)) break;
1443 fg
= GetForegroundWindow();
1444 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1445 if (!fg
|| (hwnd
== fg
))
1447 if (SetForegroundWindow( hwndTo
)) return;
1449 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1453 /***********************************************************************
1454 * WINPOS_HandleWindowPosChanging
1456 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1458 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1460 POINT minTrack
, maxTrack
;
1461 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1463 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1464 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1466 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1467 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1468 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1469 if (!(style
& WS_MINIMIZE
))
1471 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1472 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1479 /***********************************************************************
1482 static void dump_winpos_flags(UINT flags
)
1484 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1485 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1486 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1487 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1488 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1490 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1491 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1492 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1493 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1494 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1495 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1496 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1497 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1498 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1499 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1500 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1501 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1502 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1503 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1504 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1505 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1507 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1511 /***********************************************************************
1512 * SWP_DoWinPosChanging
1514 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1518 /* Send WM_WINDOWPOSCHANGING message */
1520 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1521 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1523 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1524 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1526 /* Calculate new position and size */
1528 *pNewWindowRect
= wndPtr
->rectWindow
;
1529 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1530 : wndPtr
->rectClient
;
1532 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1534 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1535 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1537 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1539 pNewWindowRect
->left
= pWinpos
->x
;
1540 pNewWindowRect
->top
= pWinpos
->y
;
1541 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1542 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1544 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1545 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1547 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1549 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1550 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1551 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1552 TRACE( "current %s style %08x new %s\n",
1553 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1554 wine_dbgstr_rect( pNewWindowRect
));
1556 WIN_ReleasePtr( wndPtr
);
1560 /***********************************************************************
1563 * Compute the valid rects from the old and new client rect and WVR_* flags.
1564 * Helper for WM_NCCALCSIZE handling.
1566 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1571 if (flags
& WVR_REDRAW
)
1573 SetRectEmpty( &valid
[0] );
1574 SetRectEmpty( &valid
[1] );
1578 if (flags
& WVR_VALIDRECTS
)
1580 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1581 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1583 SetRectEmpty( &valid
[0] );
1584 SetRectEmpty( &valid
[1] );
1587 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1591 valid
[0] = *new_client
;
1592 valid
[1] = *old_client
;
1595 /* make sure the rectangles have the same size */
1596 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1597 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1599 if (flags
& WVR_ALIGNBOTTOM
)
1601 valid
[0].top
= valid
[0].bottom
- cy
;
1602 valid
[1].top
= valid
[1].bottom
- cy
;
1606 valid
[0].bottom
= valid
[0].top
+ cy
;
1607 valid
[1].bottom
= valid
[1].top
+ cy
;
1609 if (flags
& WVR_ALIGNRIGHT
)
1611 valid
[0].left
= valid
[0].right
- cx
;
1612 valid
[1].left
= valid
[1].right
- cx
;
1616 valid
[0].right
= valid
[0].left
+ cx
;
1617 valid
[1].right
= valid
[1].left
+ cx
;
1622 /***********************************************************************
1625 * fix Z order taking into account owned popups -
1626 * basically we need to maintain them above the window that owns them
1628 * FIXME: hide/show owned popups when owner visibility changes.
1630 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1632 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1633 HWND owner
, *list
= NULL
;
1636 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1638 if ((style
& WS_POPUP
) && (owner
= GetWindow( hwnd
, GW_OWNER
)))
1640 /* make sure this popup stays above the owner */
1642 if (hwndInsertAfter
!= HWND_TOP
&& hwndInsertAfter
!= HWND_TOPMOST
)
1644 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1646 for (i
= 0; list
[i
]; i
++)
1648 if (list
[i
] == owner
)
1650 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1651 else hwndInsertAfter
= HWND_TOP
;
1655 if (hwndInsertAfter
== HWND_NOTOPMOST
)
1657 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) break;
1659 else if (list
[i
] == hwndInsertAfter
) break;
1663 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1665 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1666 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1669 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1671 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1673 /* skip all the topmost windows */
1674 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1677 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1679 /* skip windows that are already placed correctly */
1680 for (i
= 0; list
[i
]; i
++)
1682 if (list
[i
] == hwndInsertAfter
) break;
1683 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1687 for ( ; list
[i
]; i
++)
1689 if (list
[i
] == hwnd
) break;
1690 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
)) continue;
1691 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1692 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1693 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1694 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1695 hwndInsertAfter
= list
[i
];
1699 HeapFree( GetProcessHeap(), 0, list
);
1700 return hwndInsertAfter
;
1703 /***********************************************************************
1706 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1712 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1714 /* Send WM_NCCALCSIZE message to get new client area */
1715 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1717 NCCALCSIZE_PARAMS params
;
1718 WINDOWPOS winposCopy
;
1720 params
.rgrc
[0] = *pNewWindowRect
;
1721 params
.rgrc
[1] = wndPtr
->rectWindow
;
1722 params
.rgrc
[2] = wndPtr
->rectClient
;
1723 params
.lppos
= &winposCopy
;
1724 winposCopy
= *pWinpos
;
1725 WIN_ReleasePtr( wndPtr
);
1727 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1729 *pNewClientRect
= params
.rgrc
[0];
1731 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1733 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1734 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1735 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1737 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1738 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1739 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1741 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1742 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1743 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1745 wvrFlags
&= ~WVR_HREDRAW
;
1747 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1748 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1749 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1751 wvrFlags
&= ~WVR_VREDRAW
;
1753 validRects
[0] = params
.rgrc
[1];
1754 validRects
[1] = params
.rgrc
[2];
1758 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1759 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1760 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1761 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1764 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1766 SetRectEmpty( &validRects
[0] );
1767 SetRectEmpty( &validRects
[1] );
1769 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1771 WIN_ReleasePtr( wndPtr
);
1775 /* fix redundant flags and values in the WINDOWPOS structure */
1776 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1779 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1782 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1784 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1787 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1789 /* Finally make sure that all coordinates are valid */
1790 if (winpos
->x
< -32768) winpos
->x
= -32768;
1791 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1792 if (winpos
->y
< -32768) winpos
->y
= -32768;
1793 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1795 if (winpos
->cx
< 0) winpos
->cx
= 0;
1796 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1797 if (winpos
->cy
< 0) winpos
->cy
= 0;
1798 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1800 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1801 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1803 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1806 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1807 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1810 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1811 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1812 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1814 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1815 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1817 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1819 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1820 (winpos
->flags
& SWP_NOZORDER
||
1821 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1823 winpos
->flags
&= ~SWP_NOZORDER
;
1824 winpos
->hwndInsertAfter
= HWND_TOP
;
1828 /* Check hwndInsertAfter */
1829 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1831 /* fix sign extension */
1832 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1833 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1835 /* hwndInsertAfter must be a sibling of the window */
1836 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1838 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1839 winpos
->flags
|= SWP_NOZORDER
;
1841 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1843 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1844 winpos
->flags
|= SWP_NOZORDER
;
1846 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1848 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1849 winpos
->flags
|= SWP_NOZORDER
;
1851 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1853 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1854 winpos
->flags
|= SWP_NOZORDER
;
1858 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1861 /* don't need to change the Zorder of hwnd if it's already inserted
1862 * after hwndInsertAfter or when inserting hwnd after itself.
1864 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1865 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1866 winpos
->flags
|= SWP_NOZORDER
;
1870 WIN_ReleasePtr( wndPtr
);
1875 /***********************************************************************
1878 * Backend implementation of SetWindowPos.
1880 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1881 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
1885 RECT visible_rect
, old_window_rect
;
1887 visible_rect
= *window_rect
;
1888 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
1889 window_rect
, client_rect
, &visible_rect
);
1891 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
1892 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
1894 old_window_rect
= win
->rectWindow
;
1895 SERVER_START_REQ( set_window_pos
)
1898 req
->previous
= insert_after
;
1899 req
->flags
= swp_flags
;
1900 req
->window
.left
= window_rect
->left
;
1901 req
->window
.top
= window_rect
->top
;
1902 req
->window
.right
= window_rect
->right
;
1903 req
->window
.bottom
= window_rect
->bottom
;
1904 req
->client
.left
= client_rect
->left
;
1905 req
->client
.top
= client_rect
->top
;
1906 req
->client
.right
= client_rect
->right
;
1907 req
->client
.bottom
= client_rect
->bottom
;
1908 if (memcmp( window_rect
, &visible_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
1910 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
1911 if (!IsRectEmpty( &valid_rects
[0] ))
1912 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
1914 if ((ret
= !wine_server_call( req
)))
1916 win
->dwStyle
= reply
->new_style
;
1917 win
->dwExStyle
= reply
->new_ex_style
;
1918 win
->rectWindow
= *window_rect
;
1919 win
->rectClient
= *client_rect
;
1923 WIN_ReleasePtr( win
);
1927 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
1928 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
)))
1929 invalidate_dce( hwnd
, &old_window_rect
);
1931 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
1932 client_rect
, &visible_rect
, valid_rects
);
1938 /***********************************************************************
1941 * User32 internal function
1943 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1945 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1948 orig_flags
= winpos
->flags
;
1950 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1951 if (!(winpos
->flags
& SWP_NOMOVE
))
1953 if (winpos
->x
< -32768) winpos
->x
= -32768;
1954 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1955 if (winpos
->y
< -32768) winpos
->y
= -32768;
1956 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1958 if (!(winpos
->flags
& SWP_NOSIZE
))
1960 if (winpos
->cx
< 0) winpos
->cx
= 0;
1961 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1962 if (winpos
->cy
< 0) winpos
->cy
= 0;
1963 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1966 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1968 /* Fix redundant flags */
1969 if (!fixup_flags( winpos
)) return FALSE
;
1971 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1973 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1974 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
1977 /* Common operations */
1979 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
1981 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
1982 &newWindowRect
, &newClientRect
, valid_rects
))
1985 /* erase parent when hiding or resizing child */
1986 if (!(orig_flags
& SWP_DEFERERASE
) &&
1987 ((orig_flags
& SWP_HIDEWINDOW
) ||
1988 (!(orig_flags
& SWP_SHOWWINDOW
) &&
1989 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
1991 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1992 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
1993 erase_now( parent
, 0 );
1996 if( winpos
->flags
& SWP_HIDEWINDOW
)
1997 HideCaret(winpos
->hwnd
);
1998 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1999 ShowCaret(winpos
->hwnd
);
2001 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2003 /* child windows get WM_CHILDACTIVATE message */
2004 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2005 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2007 SetForegroundWindow( winpos
->hwnd
);
2010 /* And last, send the WM_WINDOWPOSCHANGED message */
2012 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2014 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2016 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2017 and always contains final window position.
2019 winpos
->x
= newWindowRect
.left
;
2020 winpos
->y
= newWindowRect
.top
;
2021 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2022 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2023 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2028 /***********************************************************************
2029 * SetWindowPos (USER32.@)
2031 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2032 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2036 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2037 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2038 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2040 if (is_broadcast(hwnd
))
2042 SetLastError( ERROR_INVALID_PARAMETER
);
2046 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2047 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2052 winpos
.flags
= flags
;
2054 if (WIN_IsCurrentThread( hwnd
))
2055 return USER_SetWindowPos(&winpos
);
2057 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2061 /***********************************************************************
2062 * BeginDeferWindowPos (USER32.@)
2064 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2069 TRACE("%d\n", count
);
2073 SetLastError(ERROR_INVALID_PARAMETER
);
2076 /* Windows allows zero count, in which case it allocates context for 8 moves */
2077 if (count
== 0) count
= 8;
2079 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
2080 if (!handle
) return 0;
2081 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
2082 pDWP
->actualCount
= 0;
2083 pDWP
->suggestedCount
= count
;
2085 pDWP
->wMagic
= DWP_MAGIC
;
2086 pDWP
->hwndParent
= 0;
2088 TRACE("returning hdwp %p\n", handle
);
2093 /***********************************************************************
2094 * DeferWindowPos (USER32.@)
2096 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2097 INT x
, INT y
, INT cx
, INT cy
,
2102 HDWP newhdwp
= hdwp
,retvalue
;
2104 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2105 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2107 hwnd
= WIN_GetFullHandle( hwnd
);
2108 if (is_desktop_window( hwnd
)) return 0;
2110 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
2114 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2116 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2118 /* Merge with the other changes */
2119 if (!(flags
& SWP_NOZORDER
))
2121 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2123 if (!(flags
& SWP_NOMOVE
))
2125 pDWP
->winPos
[i
].x
= x
;
2126 pDWP
->winPos
[i
].y
= y
;
2128 if (!(flags
& SWP_NOSIZE
))
2130 pDWP
->winPos
[i
].cx
= cx
;
2131 pDWP
->winPos
[i
].cy
= cy
;
2133 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2134 SWP_NOZORDER
| SWP_NOREDRAW
|
2135 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2137 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2143 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2145 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2146 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
2152 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
2153 pDWP
->suggestedCount
++;
2155 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2156 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2157 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2158 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2159 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2160 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2161 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2162 pDWP
->actualCount
++;
2170 /***********************************************************************
2171 * EndDeferWindowPos (USER32.@)
2173 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2180 TRACE("%p\n", hdwp
);
2182 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
2183 if (!pDWP
) return FALSE
;
2184 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2186 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2187 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2188 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2190 if (WIN_IsCurrentThread( winpos
->hwnd
))
2191 res
= USER_SetWindowPos( winpos
);
2193 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2195 USER_HEAP_FREE( hdwp
);
2200 /***********************************************************************
2201 * ArrangeIconicWindows (USER32.@)
2203 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2207 INT x
, y
, xspacing
, yspacing
;
2209 GetClientRect( parent
, &rectParent
);
2210 x
= rectParent
.left
;
2211 y
= rectParent
.bottom
;
2212 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2213 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2215 hwndChild
= GetWindow( parent
, GW_CHILD
);
2218 if( IsIconic( hwndChild
) )
2220 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2222 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2223 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
2224 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2225 if( IsWindow(hwndChild
) )
2226 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2228 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
2231 x
= rectParent
.left
;
2235 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2241 /***********************************************************************
2244 * Draw the frame used when moving or resizing window.
2246 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
2250 const int width
= GetSystemMetrics(SM_CXFRAME
);
2251 const int height
= GetSystemMetrics(SM_CYFRAME
);
2253 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2254 PatBlt( hdc
, rect
->left
, rect
->top
,
2255 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
2256 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
2257 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2258 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
2259 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
2260 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
2261 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2262 SelectObject( hdc
, hbrush
);
2264 else DrawFocusRect( hdc
, rect
);
2268 /***********************************************************************
2271 * Initialization of a move or resize, when initiated from a menu choice.
2272 * Return hit test code for caption or sizing border.
2274 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2281 GetWindowRect( hwnd
, &rectWindow
);
2283 if ((wParam
& 0xfff0) == SC_MOVE
)
2285 /* Move pointer at the center of the caption */
2286 RECT rect
= rectWindow
;
2287 /* Note: to be exactly centered we should take the different types
2288 * of border into account, but it shouldn't make more than a few pixels
2289 * of difference so let's not bother with that */
2290 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2291 if (style
& WS_SYSMENU
)
2292 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2293 if (style
& WS_MINIMIZEBOX
)
2294 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2295 if (style
& WS_MAXIMIZEBOX
)
2296 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2297 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2298 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2299 hittest
= HTCAPTION
;
2304 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2308 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2309 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2314 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2315 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2316 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2317 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2328 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2329 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2333 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2334 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2338 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2339 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2343 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2344 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2352 TranslateMessage( &msg
);
2353 DispatchMessageW( &msg
);
2359 SetCursorPos( pt
.x
, pt
.y
);
2360 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2365 /***********************************************************************
2366 * WINPOS_SysCommandSizeMove
2368 * Perform SC_MOVE and SC_SIZE commands.
2370 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2373 RECT sizingRect
, mouseRect
, origRect
;
2376 LONG hittest
= (LONG
)(wParam
& 0x0f);
2377 WPARAM syscommand
= wParam
& 0xfff0;
2378 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2379 POINT minTrack
, maxTrack
;
2380 POINT capturePoint
, pt
;
2381 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2382 BOOL thickframe
= HAS_THICKFRAME( style
);
2383 BOOL iconic
= style
& WS_MINIMIZE
;
2385 DWORD dwPoint
= GetMessagePos ();
2386 BOOL DragFullWindows
= TRUE
;
2388 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2390 pt
.x
= (short)LOWORD(dwPoint
);
2391 pt
.y
= (short)HIWORD(dwPoint
);
2394 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2395 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2397 if (syscommand
== SC_MOVE
)
2399 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2400 if (!hittest
) return;
2404 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2405 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2408 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2409 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2412 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2418 /* Get min/max info */
2420 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2421 GetWindowRect( hwnd
, &sizingRect
);
2422 if (style
& WS_CHILD
)
2424 parent
= GetParent(hwnd
);
2425 /* make sizing rect relative to parent */
2426 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2427 GetClientRect( parent
, &mouseRect
);
2432 GetClientRect( GetDesktopWindow(), &mouseRect
);
2433 mouseRect
.left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
2434 mouseRect
.top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
2435 mouseRect
.right
= mouseRect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
2436 mouseRect
.bottom
= mouseRect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
2438 origRect
= sizingRect
;
2440 if (ON_LEFT_BORDER(hittest
))
2442 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
2443 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
2445 else if (ON_RIGHT_BORDER(hittest
))
2447 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
2448 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
2450 if (ON_TOP_BORDER(hittest
))
2452 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
2453 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
2455 else if (ON_BOTTOM_BORDER(hittest
))
2457 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
2458 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
2460 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2462 /* Retrieve a default cache DC (without using the window style) */
2463 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2465 if( iconic
) /* create a cursor for dragging */
2467 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2468 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2469 if( !hDragCursor
) iconic
= FALSE
;
2472 /* we only allow disabling the full window drag for child windows */
2473 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2475 /* repaint the window before moving it around */
2476 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2478 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2479 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2485 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2486 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2488 /* Exit on button-up, Return, or Esc */
2489 if ((msg
.message
== WM_LBUTTONUP
) ||
2490 ((msg
.message
== WM_KEYDOWN
) &&
2491 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2493 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2495 TranslateMessage( &msg
);
2496 DispatchMessageW( &msg
);
2497 continue; /* We are not interested in other messages */
2502 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2504 case VK_UP
: pt
.y
-= 8; break;
2505 case VK_DOWN
: pt
.y
+= 8; break;
2506 case VK_LEFT
: pt
.x
-= 8; break;
2507 case VK_RIGHT
: pt
.x
+= 8; break;
2510 pt
.x
= max( pt
.x
, mouseRect
.left
);
2511 pt
.x
= min( pt
.x
, mouseRect
.right
);
2512 pt
.y
= max( pt
.y
, mouseRect
.top
);
2513 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2515 dx
= pt
.x
- capturePoint
.x
;
2516 dy
= pt
.y
- capturePoint
.y
;
2524 if( iconic
) /* ok, no system popup tracking */
2526 hOldCursor
= SetCursor(hDragCursor
);
2528 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2530 else if(!DragFullWindows
)
2531 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2534 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2537 RECT newRect
= sizingRect
;
2538 WPARAM wpSizingHit
= 0;
2540 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2541 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2542 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2543 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2544 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2545 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2548 /* determine the hit location */
2549 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2550 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2551 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2555 if(!DragFullWindows
)
2556 draw_moving_frame( hdc
, &newRect
, thickframe
);
2558 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2559 newRect
.right
- newRect
.left
,
2560 newRect
.bottom
- newRect
.top
,
2561 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2563 sizingRect
= newRect
;
2570 if( moved
) /* restore cursors, show icon title later on */
2572 ShowCursor( FALSE
);
2573 SetCursor( hOldCursor
);
2576 else if (moved
&& !DragFullWindows
)
2578 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2581 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2582 ReleaseDC( parent
, hdc
);
2584 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2587 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2588 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2590 /* window moved or resized */
2593 /* if the moving/resizing isn't canceled call SetWindowPos
2594 * with the new position or the new size of the window
2596 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2598 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2599 if(!DragFullWindows
|| iconic
)
2600 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2601 sizingRect
.right
- sizingRect
.left
,
2602 sizingRect
.bottom
- sizingRect
.top
,
2603 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2606 { /* restore previous size/position */
2608 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2609 origRect
.right
- origRect
.left
,
2610 origRect
.bottom
- origRect
.top
,
2611 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2617 /* Single click brings up the system menu when iconized */
2621 if(style
& WS_SYSMENU
)
2622 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2623 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2625 else WINPOS_ShowIconTitle( hwnd
, TRUE
);