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
);
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
)
181 req
->window
= wine_server_user_handle( hwnd
);
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
);
190 HeapFree( GetProcessHeap(), 0, data
);
192 else /* clear existing region */
194 SERVER_START_REQ( set_window_region
)
196 req
->window
= wine_server_user_handle( hwnd
);
197 req
->redraw
= (bRedraw
!= 0);
198 ret
= !wine_server_call_err( req
);
203 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
207 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
208 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
209 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
210 invalidate_dce( hwnd
, NULL
);
216 /***********************************************************************
217 * GetClientRect (USER32.@)
219 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
223 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
225 rect
->right
-= rect
->left
;
226 rect
->bottom
-= rect
->top
;
227 rect
->left
= rect
->top
= 0;
233 /*******************************************************************
234 * ClientToScreen (USER32.@)
236 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
238 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
243 /*******************************************************************
244 * ScreenToClient (USER32.@)
246 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
248 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
253 /***********************************************************************
254 * list_children_from_point
256 * Get the list of children that can contain point from the server.
257 * Point is in screen coordinates.
258 * Returned list must be freed by caller.
260 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
269 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
271 SERVER_START_REQ( get_window_children_from_point
)
273 req
->parent
= wine_server_user_handle( hwnd
);
276 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
277 if (!wine_server_call( req
)) count
= reply
->count
;
280 if (count
&& count
< size
)
282 /* start from the end since HWND is potentially larger than user_handle_t */
283 for (i
= count
- 1; i
>= 0; i
--)
284 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
288 HeapFree( GetProcessHeap(), 0, list
);
290 size
= count
+ 1; /* restart with a large enough buffer */
296 /***********************************************************************
297 * WINPOS_WindowFromPoint
299 * Find the window and hittest for a given point.
301 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
306 if (!hwndScope
) hwndScope
= GetDesktopWindow();
308 *hittest
= HTNOWHERE
;
310 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
312 /* now determine the hittest */
314 for (i
= 0; list
[i
]; i
++)
316 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
318 /* If window is minimized or disabled, return at once */
319 if (style
& WS_MINIMIZE
)
321 *hittest
= HTCAPTION
;
324 if (style
& WS_DISABLED
)
329 /* Send WM_NCCHITTEST (if same thread) */
330 if (!WIN_IsCurrentThread( list
[i
] ))
335 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
336 if (res
!= HTTRANSPARENT
)
338 *hittest
= res
; /* Found the window */
341 /* continue search with next window in z-order */
344 HeapFree( GetProcessHeap(), 0, list
);
345 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
350 /*******************************************************************
351 * WindowFromPoint (USER32.@)
353 HWND WINAPI
WindowFromPoint( POINT pt
)
356 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
360 /*******************************************************************
361 * ChildWindowFromPoint (USER32.@)
363 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
365 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
368 /*******************************************************************
369 * RealChildWindowFromPoint (USER32.@)
371 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
373 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
);
376 /*******************************************************************
377 * ChildWindowFromPointEx (USER32.@)
379 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
381 /* pt is in the client coordinates */
387 GetClientRect( hwndParent
, &rect
);
388 if (!PtInRect( &rect
, pt
)) return 0;
389 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
391 for (i
= 0; list
[i
]; i
++)
393 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
394 if (!PtInRect( &rect
, pt
)) continue;
395 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
397 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
398 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
399 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
401 if (uFlags
& CWP_SKIPTRANSPARENT
)
403 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
408 HeapFree( GetProcessHeap(), 0, list
);
409 if (!retvalue
) retvalue
= hwndParent
;
414 /*******************************************************************
415 * WINPOS_GetWinOffset
417 * Calculate the offset between the origin of the two windows. Used
418 * to implement MapWindowPoints.
420 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
424 offset
->x
= offset
->y
= 0;
426 /* Translate source window origin to screen coords */
429 HWND hwnd
= hwndFrom
;
433 if (hwnd
== hwndTo
) return;
434 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
436 ERR( "bad hwndFrom = %p\n", hwnd
);
439 if (wndPtr
== WND_DESKTOP
) break;
440 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
443 offset
->x
+= wndPtr
->rectClient
.left
;
444 offset
->y
+= wndPtr
->rectClient
.top
;
446 hwnd
= wndPtr
->parent
;
447 WIN_ReleasePtr( wndPtr
);
451 /* Translate origin to destination window coords */
458 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
460 ERR( "bad hwndTo = %p\n", hwnd
);
463 if (wndPtr
== WND_DESKTOP
) break;
464 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
467 offset
->x
-= wndPtr
->rectClient
.left
;
468 offset
->y
-= wndPtr
->rectClient
.top
;
470 hwnd
= wndPtr
->parent
;
471 WIN_ReleasePtr( wndPtr
);
476 other_process
: /* one of the parents may belong to another process, do it the hard way */
477 offset
->x
= offset
->y
= 0;
478 SERVER_START_REQ( get_windows_offset
)
480 req
->from
= wine_server_user_handle( hwndFrom
);
481 req
->to
= wine_server_user_handle( hwndTo
);
482 if (!wine_server_call( req
))
484 offset
->x
= reply
->x
;
485 offset
->y
= reply
->y
;
492 /*******************************************************************
493 * MapWindowPoints (USER.258)
495 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
496 LPPOINT16 lppt
, UINT16 count
)
500 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
510 /*******************************************************************
511 * MapWindowPoints (USER32.@)
513 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
517 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
524 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
528 /***********************************************************************
529 * IsIconic (USER32.@)
531 BOOL WINAPI
IsIconic(HWND hWnd
)
533 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
537 /***********************************************************************
538 * IsZoomed (USER32.@)
540 BOOL WINAPI
IsZoomed(HWND hWnd
)
542 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
546 /*******************************************************************
547 * AllowSetForegroundWindow (USER32.@)
549 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
551 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
552 * implemented, then fix this function. */
557 /*******************************************************************
558 * LockSetForegroundWindow (USER32.@)
560 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
562 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
563 * implemented, then fix this function. */
568 /***********************************************************************
569 * BringWindowToTop (USER32.@)
571 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
573 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
577 /***********************************************************************
578 * MoveWindow (USER32.@)
580 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
583 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
584 if (!repaint
) flags
|= SWP_NOREDRAW
;
585 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
586 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
590 /***********************************************************************
591 * WINPOS_RedrawIconTitle
593 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
596 WND
*win
= WIN_GetPtr( hWnd
);
598 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
600 icon_title
= win
->icon_title
;
601 WIN_ReleasePtr( win
);
603 if (!icon_title
) return FALSE
;
604 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
605 InvalidateRect( icon_title
, NULL
, TRUE
);
609 /***********************************************************************
610 * WINPOS_ShowIconTitle
612 static BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
614 if (!GetPropA( hwnd
, "__wine_x11_managed" ))
616 WND
*win
= WIN_GetPtr( hwnd
);
619 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
621 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
622 title
= win
->icon_title
;
623 WIN_ReleasePtr( win
);
629 title
= ICONTITLE_Create( hwnd
);
630 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
632 DestroyWindow( title
);
635 win
->icon_title
= title
;
636 WIN_ReleasePtr( win
);
638 if (!IsWindowVisible(title
))
640 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
641 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
642 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
645 else if (title
) ShowWindow( title
, SW_HIDE
);
650 /*******************************************************************
651 * WINPOS_GetMinMaxInfo
653 * Get the minimized and maximized information for a window.
655 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
656 POINT
*minTrack
, POINT
*maxTrack
)
661 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
663 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
667 /* Compute default values */
669 GetWindowRect(hwnd
, &rc
);
670 MinMax
.ptReserved
.x
= rc
.left
;
671 MinMax
.ptReserved
.y
= rc
.top
;
673 if ((style
& WS_CAPTION
) == WS_CAPTION
)
674 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
676 adjustedStyle
= style
;
678 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
679 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
684 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
685 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
686 if (style
& (WS_DLGFRAME
| WS_BORDER
))
688 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
689 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
693 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
694 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
696 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
697 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
698 MinMax
.ptMaxPosition
.x
= -xinc
;
699 MinMax
.ptMaxPosition
.y
= -yinc
;
701 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
703 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
704 WIN_ReleasePtr( win
);
707 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
709 /* if the app didn't change the values, adapt them for the current monitor */
711 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
714 MONITORINFO mon_info
;
716 mon_info
.cbSize
= sizeof(mon_info
);
717 GetMonitorInfoW( monitor
, &mon_info
);
719 rc_work
= mon_info
.rcMonitor
;
721 if (style
& WS_MAXIMIZEBOX
)
723 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
724 rc_work
= mon_info
.rcWork
;
727 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
728 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
730 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
731 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
733 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
735 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
736 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
740 /* Some sanity checks */
742 TRACE("%d %d / %d %d / %d %d / %d %d\n",
743 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
744 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
745 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
746 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
747 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
748 MinMax
.ptMinTrackSize
.x
);
749 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
750 MinMax
.ptMinTrackSize
.y
);
752 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
753 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
754 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
755 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
759 /***********************************************************************
762 * Find a suitable place for an iconic window.
764 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
766 RECT rect
, rectParent
;
769 int xspacing
, yspacing
;
771 parent
= GetAncestor( hwnd
, GA_PARENT
);
772 GetClientRect( parent
, &rectParent
);
773 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
774 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
775 return pt
; /* The icon already has a suitable position */
777 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
778 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
780 /* Check if another icon already occupies this spot */
781 /* FIXME: this is completely inefficient */
783 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
784 tmp
= CreateRectRgn( 0, 0, 0, 0 );
785 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
788 if (child
== hwnd
) continue;
789 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
791 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
793 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
794 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
795 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
796 WIN_ReleasePtr( childPtr
);
800 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
802 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
804 rect
.right
= rect
.left
+ xspacing
;
805 rect
.top
= rect
.bottom
- yspacing
;
806 if (!RectInRegion( hrgn
, &rect
))
808 /* No window was found, so it's OK for us */
809 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
810 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
811 DeleteObject( hrgn
);
816 DeleteObject( hrgn
);
822 /***********************************************************************
825 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
833 TRACE("%p %u\n", hwnd
, cmd
);
835 wpl
.length
= sizeof(wpl
);
836 GetWindowPlacement( hwnd
, &wpl
);
838 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
839 return SWP_NOSIZE
| SWP_NOMOVE
;
841 if (IsIconic( hwnd
))
845 case SW_SHOWMINNOACTIVE
:
846 case SW_SHOWMINIMIZED
:
847 case SW_FORCEMINIMIZE
:
849 return SWP_NOSIZE
| SWP_NOMOVE
;
851 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
852 swpFlags
|= SWP_NOCOPYBITS
;
857 case SW_SHOWMINNOACTIVE
:
858 case SW_SHOWMINIMIZED
:
859 case SW_FORCEMINIMIZE
:
861 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
862 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
863 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
864 WIN_ReleasePtr( wndPtr
);
866 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
868 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
870 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
871 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
872 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
873 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
874 swpFlags
|= SWP_NOCOPYBITS
;
878 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
879 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
881 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
883 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
884 if (old_style
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, FALSE
);
886 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
887 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
888 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
891 case SW_SHOWNOACTIVATE
:
894 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
895 if (old_style
& WS_MINIMIZE
)
899 WINPOS_ShowIconTitle( hwnd
, FALSE
);
901 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
902 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
903 WIN_ReleasePtr( wndPtr
);
906 /* Restore to maximized position */
907 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
908 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
909 swpFlags
|= SWP_STATECHANGED
;
910 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
911 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
915 else if (!(old_style
& WS_MAXIMIZE
)) break;
917 swpFlags
|= SWP_STATECHANGED
;
919 /* Restore to normal position */
921 *rect
= wpl
.rcNormalPosition
;
929 /***********************************************************************
932 * Implementation of ShowWindow and ShowWindowAsync.
934 static BOOL
show_window( HWND hwnd
, INT cmd
)
938 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
939 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
940 BOOL showFlag
= TRUE
;
941 RECT newPos
= {0, 0, 0, 0};
944 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
949 if (!wasVisible
) return FALSE
;
951 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
952 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
955 case SW_SHOWMINNOACTIVE
:
957 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
958 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
960 case SW_SHOWMINIMIZED
:
961 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
962 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
963 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
966 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
967 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
968 swp
|= SWP_FRAMECHANGED
;
969 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
970 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
974 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
975 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
978 if (wasVisible
) return TRUE
;
979 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
980 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
983 case SW_SHOWNOACTIVATE
:
984 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
988 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
989 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
990 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
991 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
993 swp
|= SWP_FRAMECHANGED
;
994 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
998 if (wasVisible
) return TRUE
;
999 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1001 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1007 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1009 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1010 if (!IsWindow( hwnd
)) return wasVisible
;
1013 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1015 parent
= GetAncestor( hwnd
, GA_PARENT
);
1016 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1018 /* if parent is not visible simply toggle WS_VISIBLE and return */
1019 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1020 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1023 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1024 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1030 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1032 /* FIXME: This will cause the window to be activated irrespective
1033 * of whether it is owned by the same thread. Has to be done
1037 if (hwnd
== GetActiveWindow())
1038 WINPOS_ActivateOtherWindow(hwnd
);
1040 /* Revert focus to parent */
1041 hFocus
= GetFocus();
1042 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
1044 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1045 if (parent
== GetDesktopWindow()) parent
= 0;
1051 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1053 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1055 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1057 /* should happen only in CreateWindowEx() */
1058 int wParam
= SIZE_RESTORED
;
1059 RECT client
= wndPtr
->rectClient
;
1061 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1062 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1063 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1064 WIN_ReleasePtr( wndPtr
);
1066 SendMessageW( hwnd
, WM_SIZE
, wParam
,
1067 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
1068 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1070 else WIN_ReleasePtr( wndPtr
);
1072 /* if previous state was minimized Windows sets focus to the window */
1073 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1079 /***********************************************************************
1080 * ShowWindowAsync (USER32.@)
1082 * doesn't wait; returns immediately.
1083 * used by threads to toggle windows in other (possibly hanging) threads
1085 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1089 if (is_broadcast(hwnd
))
1091 SetLastError( ERROR_INVALID_PARAMETER
);
1095 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1096 return show_window( full_handle
, cmd
);
1098 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1102 /***********************************************************************
1103 * ShowWindow (USER32.@)
1105 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1109 if (is_broadcast(hwnd
))
1111 SetLastError( ERROR_INVALID_PARAMETER
);
1114 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1115 return show_window( full_handle
, cmd
);
1117 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1121 /***********************************************************************
1122 * GetInternalWindowPos (USER32.@)
1124 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1127 WINDOWPLACEMENT wndpl
;
1128 if (GetWindowPlacement( hwnd
, &wndpl
))
1130 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1131 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1132 return wndpl
.showCmd
;
1138 /***********************************************************************
1139 * GetWindowPlacement (USER32.@)
1142 * Fails if wndpl->length of Win95 (!) apps is invalid.
1144 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1146 WND
*pWnd
= WIN_GetPtr( hwnd
);
1148 if (!pWnd
) return FALSE
;
1150 if (pWnd
== WND_DESKTOP
)
1152 wndpl
->length
= sizeof(*wndpl
);
1153 wndpl
->showCmd
= SW_SHOWNORMAL
;
1155 wndpl
->ptMinPosition
.x
= -1;
1156 wndpl
->ptMinPosition
.y
= -1;
1157 wndpl
->ptMaxPosition
.x
= -1;
1158 wndpl
->ptMaxPosition
.y
= -1;
1159 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1162 if (pWnd
== WND_OTHER_PROCESS
)
1164 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
1168 /* update the placement according to the current style */
1169 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1171 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1172 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1174 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1176 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1177 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1181 pWnd
->normal_rect
= pWnd
->rectWindow
;
1184 wndpl
->length
= sizeof(*wndpl
);
1185 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1186 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1188 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1189 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1190 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1193 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1194 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1195 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1196 WIN_ReleasePtr( pWnd
);
1198 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1199 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1200 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1201 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1205 /* make sure the specified rect is visible on screen */
1206 static void make_rect_onscreen( RECT
*rect
)
1209 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1211 info
.cbSize
= sizeof(info
);
1212 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1213 /* FIXME: map coordinates from rcWork to rcMonitor */
1214 if (rect
->right
<= info
.rcWork
.left
)
1216 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1217 rect
->left
= info
.rcWork
.left
;
1219 else if (rect
->left
>= info
.rcWork
.right
)
1221 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1222 rect
->right
= info
.rcWork
.right
;
1224 if (rect
->bottom
<= info
.rcWork
.top
)
1226 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1227 rect
->top
= info
.rcWork
.top
;
1229 else if (rect
->top
>= info
.rcWork
.bottom
)
1231 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1232 rect
->bottom
= info
.rcWork
.bottom
;
1236 /* make sure the specified point is visible on screen */
1237 static void make_point_onscreen( POINT
*pt
)
1241 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1242 make_rect_onscreen( &rect
);
1248 /***********************************************************************
1249 * WINPOS_SetPlacement
1251 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1254 WND
*pWnd
= WIN_GetPtr( hwnd
);
1255 WINDOWPLACEMENT wp
= *wndpl
;
1257 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1258 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1259 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1261 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1262 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1263 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1264 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1265 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1266 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1268 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1270 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1271 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1272 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1274 style
= pWnd
->dwStyle
;
1276 WIN_ReleasePtr( pWnd
);
1278 if( style
& WS_MINIMIZE
)
1280 if (flags
& PLACE_MIN
)
1282 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1283 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1284 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1287 else if( style
& WS_MAXIMIZE
)
1289 if (flags
& PLACE_MAX
)
1290 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1291 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1293 else if( flags
& PLACE_RECT
)
1294 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1295 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1296 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1297 SWP_NOZORDER
| SWP_NOACTIVATE
);
1299 ShowWindow( hwnd
, wndpl
->showCmd
);
1301 if (IsIconic( hwnd
))
1303 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1305 /* SDK: ...valid only the next time... */
1306 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1308 pWnd
= WIN_GetPtr( hwnd
);
1309 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1311 pWnd
->flags
|= WIN_RESTORE_MAX
;
1312 WIN_ReleasePtr( pWnd
);
1320 /***********************************************************************
1321 * SetWindowPlacement (USER32.@)
1324 * Fails if wndpl->length of Win95 (!) apps is invalid.
1326 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1328 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1329 if (!wpl
) return FALSE
;
1330 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1331 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1335 /***********************************************************************
1336 * AnimateWindow (USER32.@)
1337 * Shows/Hides a window with an animation
1340 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1342 FIXME("partial stub\n");
1344 /* If trying to show/hide and it's already *
1345 * shown/hidden or invalid window, fail with *
1346 * invalid parameter */
1347 if(!IsWindow(hwnd
) ||
1348 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1349 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1351 SetLastError(ERROR_INVALID_PARAMETER
);
1355 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1360 /***********************************************************************
1361 * SetInternalWindowPos (USER32.@)
1363 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1364 LPRECT rect
, LPPOINT pt
)
1366 WINDOWPLACEMENT wndpl
;
1369 wndpl
.length
= sizeof(wndpl
);
1370 wndpl
.showCmd
= showCmd
;
1371 wndpl
.flags
= flags
= 0;
1376 wndpl
.flags
|= WPF_SETMINPOSITION
;
1377 wndpl
.ptMinPosition
= *pt
;
1381 flags
|= PLACE_RECT
;
1382 wndpl
.rcNormalPosition
= *rect
;
1384 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1388 /*******************************************************************
1389 * can_activate_window
1391 * Check if we can activate the specified window.
1393 static BOOL
can_activate_window( HWND hwnd
)
1397 if (!hwnd
) return FALSE
;
1398 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1399 if (!(style
& WS_VISIBLE
)) return FALSE
;
1400 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1401 return !(style
& WS_DISABLED
);
1405 /*******************************************************************
1406 * WINPOS_ActivateOtherWindow
1408 * Activates window other than pWnd.
1410 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1414 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1416 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1417 if (can_activate_window( hwndTo
)) goto done
;
1423 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1424 if (can_activate_window( hwndTo
)) break;
1428 fg
= GetForegroundWindow();
1429 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1430 if (!fg
|| (hwnd
== fg
))
1432 if (SetForegroundWindow( hwndTo
)) return;
1434 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1438 /***********************************************************************
1439 * WINPOS_HandleWindowPosChanging
1441 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1443 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1445 POINT minTrack
, maxTrack
;
1446 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1448 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1449 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1451 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1452 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1453 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1454 if (!(style
& WS_MINIMIZE
))
1456 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1457 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1464 /***********************************************************************
1467 static void dump_winpos_flags(UINT flags
)
1469 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1470 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1471 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1472 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1473 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1475 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1476 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1477 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1478 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1479 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1480 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1481 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1482 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1483 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1484 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1485 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1486 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1487 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1488 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1489 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1490 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1492 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1496 /***********************************************************************
1497 * SWP_DoWinPosChanging
1499 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1503 /* Send WM_WINDOWPOSCHANGING message */
1505 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1506 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1508 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1509 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1511 /* Calculate new position and size */
1513 *pNewWindowRect
= wndPtr
->rectWindow
;
1514 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1515 : wndPtr
->rectClient
;
1517 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1519 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1520 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1522 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1524 pNewWindowRect
->left
= pWinpos
->x
;
1525 pNewWindowRect
->top
= pWinpos
->y
;
1526 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1527 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1529 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1530 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1532 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1534 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1535 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1536 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1537 TRACE( "current %s style %08x new %s\n",
1538 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1539 wine_dbgstr_rect( pNewWindowRect
));
1541 WIN_ReleasePtr( wndPtr
);
1545 /***********************************************************************
1548 * Compute the valid rects from the old and new client rect and WVR_* flags.
1549 * Helper for WM_NCCALCSIZE handling.
1551 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1556 if (flags
& WVR_REDRAW
)
1558 SetRectEmpty( &valid
[0] );
1559 SetRectEmpty( &valid
[1] );
1563 if (flags
& WVR_VALIDRECTS
)
1565 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1566 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1568 SetRectEmpty( &valid
[0] );
1569 SetRectEmpty( &valid
[1] );
1572 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1576 valid
[0] = *new_client
;
1577 valid
[1] = *old_client
;
1580 /* make sure the rectangles have the same size */
1581 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1582 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1584 if (flags
& WVR_ALIGNBOTTOM
)
1586 valid
[0].top
= valid
[0].bottom
- cy
;
1587 valid
[1].top
= valid
[1].bottom
- cy
;
1591 valid
[0].bottom
= valid
[0].top
+ cy
;
1592 valid
[1].bottom
= valid
[1].top
+ cy
;
1594 if (flags
& WVR_ALIGNRIGHT
)
1596 valid
[0].left
= valid
[0].right
- cx
;
1597 valid
[1].left
= valid
[1].right
- cx
;
1601 valid
[0].right
= valid
[0].left
+ cx
;
1602 valid
[1].right
= valid
[1].left
+ cx
;
1607 /***********************************************************************
1610 * fix Z order taking into account owned popups -
1611 * basically we need to maintain them above the window that owns them
1613 * FIXME: hide/show owned popups when owner visibility changes.
1615 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1617 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1618 HWND owner
, *list
= NULL
;
1621 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1623 if ((style
& WS_POPUP
) && (owner
= GetWindow( hwnd
, GW_OWNER
)))
1625 /* make sure this popup stays above the owner */
1627 if (hwndInsertAfter
!= HWND_TOP
&& hwndInsertAfter
!= HWND_TOPMOST
)
1629 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1631 for (i
= 0; list
[i
]; i
++)
1633 if (list
[i
] == owner
)
1635 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1636 else hwndInsertAfter
= HWND_TOP
;
1640 if (hwndInsertAfter
== HWND_NOTOPMOST
)
1642 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) break;
1644 else if (list
[i
] == hwndInsertAfter
) break;
1648 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1650 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1651 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1654 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1656 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1658 /* skip all the topmost windows */
1659 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1662 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1664 /* skip windows that are already placed correctly */
1665 for (i
= 0; list
[i
]; i
++)
1667 if (list
[i
] == hwndInsertAfter
) break;
1668 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1672 for ( ; list
[i
]; i
++)
1674 if (list
[i
] == hwnd
) break;
1675 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
)) continue;
1676 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1677 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1678 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1679 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1680 hwndInsertAfter
= list
[i
];
1684 HeapFree( GetProcessHeap(), 0, list
);
1685 return hwndInsertAfter
;
1688 /***********************************************************************
1691 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1697 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1699 /* Send WM_NCCALCSIZE message to get new client area */
1700 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1702 NCCALCSIZE_PARAMS params
;
1703 WINDOWPOS winposCopy
;
1705 params
.rgrc
[0] = *pNewWindowRect
;
1706 params
.rgrc
[1] = wndPtr
->rectWindow
;
1707 params
.rgrc
[2] = wndPtr
->rectClient
;
1708 params
.lppos
= &winposCopy
;
1709 winposCopy
= *pWinpos
;
1710 WIN_ReleasePtr( wndPtr
);
1712 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1714 *pNewClientRect
= params
.rgrc
[0];
1716 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1718 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1719 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1720 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1722 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1723 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1724 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1726 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1727 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1728 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1730 wvrFlags
&= ~WVR_HREDRAW
;
1732 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1733 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1734 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1736 wvrFlags
&= ~WVR_VREDRAW
;
1738 validRects
[0] = params
.rgrc
[1];
1739 validRects
[1] = params
.rgrc
[2];
1743 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1744 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1745 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1746 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1749 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1751 SetRectEmpty( &validRects
[0] );
1752 SetRectEmpty( &validRects
[1] );
1754 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1756 WIN_ReleasePtr( wndPtr
);
1760 /* fix redundant flags and values in the WINDOWPOS structure */
1761 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1764 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1767 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1769 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1772 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1774 /* Finally make sure that all coordinates are valid */
1775 if (winpos
->x
< -32768) winpos
->x
= -32768;
1776 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1777 if (winpos
->y
< -32768) winpos
->y
= -32768;
1778 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1780 if (winpos
->cx
< 0) winpos
->cx
= 0;
1781 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1782 if (winpos
->cy
< 0) winpos
->cy
= 0;
1783 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1785 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1786 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1788 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1791 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1792 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1795 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1796 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1797 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1799 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1800 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1802 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1804 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1805 (winpos
->flags
& SWP_NOZORDER
||
1806 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1808 winpos
->flags
&= ~SWP_NOZORDER
;
1809 winpos
->hwndInsertAfter
= HWND_TOP
;
1813 /* Check hwndInsertAfter */
1814 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1816 /* fix sign extension */
1817 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1818 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1820 /* hwndInsertAfter must be a sibling of the window */
1821 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1823 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1824 winpos
->flags
|= SWP_NOZORDER
;
1826 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1828 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1829 winpos
->flags
|= SWP_NOZORDER
;
1831 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1833 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1834 winpos
->flags
|= SWP_NOZORDER
;
1836 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1838 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1839 winpos
->flags
|= SWP_NOZORDER
;
1843 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1846 /* don't need to change the Zorder of hwnd if it's already inserted
1847 * after hwndInsertAfter or when inserting hwnd after itself.
1849 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1850 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1851 winpos
->flags
|= SWP_NOZORDER
;
1855 WIN_ReleasePtr( wndPtr
);
1860 /***********************************************************************
1863 * Backend implementation of SetWindowPos.
1865 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1866 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
1870 RECT visible_rect
, old_window_rect
;
1872 visible_rect
= *window_rect
;
1873 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
1874 window_rect
, client_rect
, &visible_rect
);
1876 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
1877 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
1879 old_window_rect
= win
->rectWindow
;
1880 SERVER_START_REQ( set_window_pos
)
1882 req
->handle
= wine_server_user_handle( hwnd
);
1883 req
->previous
= wine_server_user_handle( insert_after
);
1884 req
->flags
= swp_flags
;
1885 req
->window
.left
= window_rect
->left
;
1886 req
->window
.top
= window_rect
->top
;
1887 req
->window
.right
= window_rect
->right
;
1888 req
->window
.bottom
= window_rect
->bottom
;
1889 req
->client
.left
= client_rect
->left
;
1890 req
->client
.top
= client_rect
->top
;
1891 req
->client
.right
= client_rect
->right
;
1892 req
->client
.bottom
= client_rect
->bottom
;
1893 if (memcmp( window_rect
, &visible_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
1895 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
1896 if (!IsRectEmpty( &valid_rects
[0] ))
1897 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
1899 if ((ret
= !wine_server_call( req
)))
1901 win
->dwStyle
= reply
->new_style
;
1902 win
->dwExStyle
= reply
->new_ex_style
;
1903 win
->rectWindow
= *window_rect
;
1904 win
->rectClient
= *client_rect
;
1908 WIN_ReleasePtr( win
);
1912 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
1913 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
)))
1914 invalidate_dce( hwnd
, &old_window_rect
);
1916 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
1917 client_rect
, &visible_rect
, valid_rects
);
1923 /***********************************************************************
1926 * User32 internal function
1928 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1930 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1933 orig_flags
= winpos
->flags
;
1935 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1936 if (!(winpos
->flags
& SWP_NOMOVE
))
1938 if (winpos
->x
< -32768) winpos
->x
= -32768;
1939 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1940 if (winpos
->y
< -32768) winpos
->y
= -32768;
1941 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1943 if (!(winpos
->flags
& SWP_NOSIZE
))
1945 if (winpos
->cx
< 0) winpos
->cx
= 0;
1946 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1947 if (winpos
->cy
< 0) winpos
->cy
= 0;
1948 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1951 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1953 /* Fix redundant flags */
1954 if (!fixup_flags( winpos
)) return FALSE
;
1956 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1958 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1959 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
1962 /* Common operations */
1964 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
1966 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
1967 &newWindowRect
, &newClientRect
, valid_rects
))
1970 /* erase parent when hiding or resizing child */
1971 if (!(orig_flags
& SWP_DEFERERASE
) &&
1972 ((orig_flags
& SWP_HIDEWINDOW
) ||
1973 (!(orig_flags
& SWP_SHOWWINDOW
) &&
1974 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
1976 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1977 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
1978 erase_now( parent
, 0 );
1981 if( winpos
->flags
& SWP_HIDEWINDOW
)
1982 HideCaret(winpos
->hwnd
);
1983 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1984 ShowCaret(winpos
->hwnd
);
1986 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
1988 /* child windows get WM_CHILDACTIVATE message */
1989 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1990 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1992 SetForegroundWindow( winpos
->hwnd
);
1995 /* And last, send the WM_WINDOWPOSCHANGED message */
1997 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1999 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2001 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2002 and always contains final window position.
2004 winpos
->x
= newWindowRect
.left
;
2005 winpos
->y
= newWindowRect
.top
;
2006 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2007 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2008 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2013 /***********************************************************************
2014 * SetWindowPos (USER32.@)
2016 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2017 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2021 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2022 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2023 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2025 if (is_broadcast(hwnd
))
2027 SetLastError( ERROR_INVALID_PARAMETER
);
2031 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2032 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2037 winpos
.flags
= flags
;
2039 if (WIN_IsCurrentThread( hwnd
))
2040 return USER_SetWindowPos(&winpos
);
2042 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2046 /***********************************************************************
2047 * BeginDeferWindowPos (USER32.@)
2049 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2054 TRACE("%d\n", count
);
2058 SetLastError(ERROR_INVALID_PARAMETER
);
2061 /* Windows allows zero count, in which case it allocates context for 8 moves */
2062 if (count
== 0) count
= 8;
2064 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
2065 if (!handle
) return 0;
2066 pDWP
= USER_HEAP_LIN_ADDR( handle
);
2067 pDWP
->actualCount
= 0;
2068 pDWP
->suggestedCount
= count
;
2070 pDWP
->wMagic
= DWP_MAGIC
;
2071 pDWP
->hwndParent
= 0;
2073 TRACE("returning hdwp %p\n", handle
);
2078 /***********************************************************************
2079 * DeferWindowPos (USER32.@)
2081 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2082 INT x
, INT y
, INT cx
, INT cy
,
2087 HDWP newhdwp
= hdwp
,retvalue
;
2089 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2090 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2092 hwnd
= WIN_GetFullHandle( hwnd
);
2093 if (is_desktop_window( hwnd
)) return 0;
2095 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
2099 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2101 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2103 /* Merge with the other changes */
2104 if (!(flags
& SWP_NOZORDER
))
2106 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2108 if (!(flags
& SWP_NOMOVE
))
2110 pDWP
->winPos
[i
].x
= x
;
2111 pDWP
->winPos
[i
].y
= y
;
2113 if (!(flags
& SWP_NOSIZE
))
2115 pDWP
->winPos
[i
].cx
= cx
;
2116 pDWP
->winPos
[i
].cy
= cy
;
2118 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2119 SWP_NOZORDER
| SWP_NOREDRAW
|
2120 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2122 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2128 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2130 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2131 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
2137 pDWP
= USER_HEAP_LIN_ADDR( newhdwp
);
2138 pDWP
->suggestedCount
++;
2140 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2141 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2142 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2143 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2144 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2145 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2146 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2147 pDWP
->actualCount
++;
2155 /***********************************************************************
2156 * EndDeferWindowPos (USER32.@)
2158 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2165 TRACE("%p\n", hdwp
);
2167 pDWP
= USER_HEAP_LIN_ADDR( hdwp
);
2168 if (!pDWP
) return FALSE
;
2169 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2171 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2172 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2173 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2175 if (WIN_IsCurrentThread( winpos
->hwnd
))
2176 res
= USER_SetWindowPos( winpos
);
2178 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2180 USER_HEAP_FREE( hdwp
);
2185 /***********************************************************************
2186 * ArrangeIconicWindows (USER32.@)
2188 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2192 INT x
, y
, xspacing
, yspacing
;
2194 GetClientRect( parent
, &rectParent
);
2195 x
= rectParent
.left
;
2196 y
= rectParent
.bottom
;
2197 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2198 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2200 hwndChild
= GetWindow( parent
, GW_CHILD
);
2203 if( IsIconic( hwndChild
) )
2205 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2207 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2208 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
2209 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2210 if( IsWindow(hwndChild
) )
2211 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2213 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
2216 x
= rectParent
.left
;
2220 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2226 /***********************************************************************
2229 * Draw the frame used when moving or resizing window.
2231 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
2235 const int width
= GetSystemMetrics(SM_CXFRAME
);
2236 const int height
= GetSystemMetrics(SM_CYFRAME
);
2238 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2239 PatBlt( hdc
, rect
->left
, rect
->top
,
2240 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
2241 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
2242 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2243 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
2244 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
2245 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
2246 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2247 SelectObject( hdc
, hbrush
);
2249 else DrawFocusRect( hdc
, rect
);
2253 /***********************************************************************
2256 * Initialization of a move or resize, when initiated from a menu choice.
2257 * Return hit test code for caption or sizing border.
2259 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2266 GetWindowRect( hwnd
, &rectWindow
);
2268 if ((wParam
& 0xfff0) == SC_MOVE
)
2270 /* Move pointer at the center of the caption */
2271 RECT rect
= rectWindow
;
2272 /* Note: to be exactly centered we should take the different types
2273 * of border into account, but it shouldn't make more than a few pixels
2274 * of difference so let's not bother with that */
2275 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2276 if (style
& WS_SYSMENU
)
2277 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2278 if (style
& WS_MINIMIZEBOX
)
2279 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2280 if (style
& WS_MAXIMIZEBOX
)
2281 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2282 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2283 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2284 hittest
= HTCAPTION
;
2289 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2293 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2294 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2299 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2300 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2301 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2302 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2313 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2314 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2318 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2319 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2323 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2324 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2328 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2329 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2337 TranslateMessage( &msg
);
2338 DispatchMessageW( &msg
);
2344 SetCursorPos( pt
.x
, pt
.y
);
2345 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2350 /***********************************************************************
2351 * WINPOS_SysCommandSizeMove
2353 * Perform SC_MOVE and SC_SIZE commands.
2355 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2358 RECT sizingRect
, mouseRect
, origRect
;
2361 LONG hittest
= (LONG
)(wParam
& 0x0f);
2362 WPARAM syscommand
= wParam
& 0xfff0;
2363 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2364 POINT minTrack
, maxTrack
;
2365 POINT capturePoint
, pt
;
2366 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2367 BOOL thickframe
= HAS_THICKFRAME( style
);
2368 BOOL iconic
= style
& WS_MINIMIZE
;
2370 DWORD dwPoint
= GetMessagePos ();
2371 BOOL DragFullWindows
= TRUE
;
2373 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2375 pt
.x
= (short)LOWORD(dwPoint
);
2376 pt
.y
= (short)HIWORD(dwPoint
);
2379 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2380 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2382 if (syscommand
== SC_MOVE
)
2384 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2385 if (!hittest
) return;
2389 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2390 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2393 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2394 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2397 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2403 /* Get min/max info */
2405 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2406 GetWindowRect( hwnd
, &sizingRect
);
2407 if (style
& WS_CHILD
)
2409 parent
= GetParent(hwnd
);
2410 /* make sizing rect relative to parent */
2411 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2412 GetClientRect( parent
, &mouseRect
);
2417 GetClientRect( GetDesktopWindow(), &mouseRect
);
2418 mouseRect
.left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
2419 mouseRect
.top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
2420 mouseRect
.right
= mouseRect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
2421 mouseRect
.bottom
= mouseRect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
2423 origRect
= sizingRect
;
2425 if (ON_LEFT_BORDER(hittest
))
2427 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
2428 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
2430 else if (ON_RIGHT_BORDER(hittest
))
2432 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
2433 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
2435 if (ON_TOP_BORDER(hittest
))
2437 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
2438 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
2440 else if (ON_BOTTOM_BORDER(hittest
))
2442 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
2443 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
2445 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2447 /* Retrieve a default cache DC (without using the window style) */
2448 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2450 if( iconic
) /* create a cursor for dragging */
2452 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2453 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2454 if( !hDragCursor
) iconic
= FALSE
;
2457 /* we only allow disabling the full window drag for child windows */
2458 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2460 /* repaint the window before moving it around */
2461 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2463 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2464 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2470 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2471 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2473 /* Exit on button-up, Return, or Esc */
2474 if ((msg
.message
== WM_LBUTTONUP
) ||
2475 ((msg
.message
== WM_KEYDOWN
) &&
2476 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2478 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2480 TranslateMessage( &msg
);
2481 DispatchMessageW( &msg
);
2482 continue; /* We are not interested in other messages */
2487 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2489 case VK_UP
: pt
.y
-= 8; break;
2490 case VK_DOWN
: pt
.y
+= 8; break;
2491 case VK_LEFT
: pt
.x
-= 8; break;
2492 case VK_RIGHT
: pt
.x
+= 8; break;
2495 pt
.x
= max( pt
.x
, mouseRect
.left
);
2496 pt
.x
= min( pt
.x
, mouseRect
.right
);
2497 pt
.y
= max( pt
.y
, mouseRect
.top
);
2498 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2500 dx
= pt
.x
- capturePoint
.x
;
2501 dy
= pt
.y
- capturePoint
.y
;
2509 if( iconic
) /* ok, no system popup tracking */
2511 hOldCursor
= SetCursor(hDragCursor
);
2513 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2515 else if(!DragFullWindows
)
2516 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2519 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2522 RECT newRect
= sizingRect
;
2523 WPARAM wpSizingHit
= 0;
2525 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2526 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2527 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2528 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2529 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2530 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2533 /* determine the hit location */
2534 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2535 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2536 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2540 if(!DragFullWindows
)
2541 draw_moving_frame( hdc
, &newRect
, thickframe
);
2543 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2544 newRect
.right
- newRect
.left
,
2545 newRect
.bottom
- newRect
.top
,
2546 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2548 sizingRect
= newRect
;
2555 if( moved
) /* restore cursors, show icon title later on */
2557 ShowCursor( FALSE
);
2558 SetCursor( hOldCursor
);
2561 else if (moved
&& !DragFullWindows
)
2563 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2566 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2567 ReleaseDC( parent
, hdc
);
2569 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2572 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2573 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2575 /* window moved or resized */
2578 /* if the moving/resizing isn't canceled call SetWindowPos
2579 * with the new position or the new size of the window
2581 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2583 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2584 if(!DragFullWindows
|| iconic
)
2585 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2586 sizingRect
.right
- sizingRect
.left
,
2587 sizingRect
.bottom
- sizingRect
.top
,
2588 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2591 { /* restore previous size/position */
2593 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2594 origRect
.right
- origRect
.left
,
2595 origRect
.bottom
- origRect
.top
,
2596 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2602 /* Single click brings up the system menu when iconized */
2606 if(style
& WS_SYSMENU
)
2607 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2608 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2610 else WINPOS_ShowIconTitle( hwnd
, TRUE
);