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
73 struct user_object obj
;
81 /***********************************************************************
82 * SwitchToThisWindow (USER32.@)
84 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL alt_tab
)
86 if (IsIconic( hwnd
)) ShowWindow( hwnd
, SW_RESTORE
);
87 else BringWindowToTop( hwnd
);
91 /***********************************************************************
92 * GetWindowRect (USER32.@)
94 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
96 BOOL ret
= WIN_GetRectangles( hwnd
, COORDS_SCREEN
, rect
, NULL
);
97 if (ret
) TRACE( "hwnd %p %s\n", hwnd
, wine_dbgstr_rect(rect
) );
102 /***********************************************************************
103 * GetWindowRgn (USER32.@)
105 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
115 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
117 SetLastError( ERROR_OUTOFMEMORY
);
120 SERVER_START_REQ( get_window_region
)
122 req
->window
= wine_server_user_handle( hwnd
);
123 wine_server_set_reply( req
, data
->Buffer
, size
);
124 if (!(status
= wine_server_call( req
)))
126 size_t reply_size
= wine_server_reply_size( reply
);
129 data
->rdh
.dwSize
= sizeof(data
->rdh
);
130 data
->rdh
.iType
= RDH_RECTANGLES
;
131 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
132 data
->rdh
.nRgnSize
= reply_size
;
133 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
136 else size
= reply
->total_size
;
139 HeapFree( GetProcessHeap(), 0, data
);
140 } while (status
== STATUS_BUFFER_OVERFLOW
);
142 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
145 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
146 DeleteObject( win_rgn
);
151 /***********************************************************************
152 * GetWindowRgnBox (USER32.@)
154 int WINAPI
GetWindowRgnBox( HWND hwnd
, LPRECT prect
)
162 if ((hrgn
= CreateRectRgn(0, 0, 0, 0)))
164 if ((ret
= GetWindowRgn( hwnd
, hrgn
)) != ERROR
)
165 ret
= GetRgnBox( hrgn
, prect
);
172 /***********************************************************************
173 * SetWindowRgn (USER32.@)
175 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
177 static const RECT empty_rect
;
185 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
186 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
187 if (!GetRegionData( hrgn
, size
, data
))
189 HeapFree( GetProcessHeap(), 0, data
);
192 SERVER_START_REQ( set_window_region
)
194 req
->window
= wine_server_user_handle( hwnd
);
195 req
->redraw
= (bRedraw
!= 0);
196 if (data
->rdh
.nCount
)
197 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
199 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
200 ret
= !wine_server_call_err( req
);
203 HeapFree( GetProcessHeap(), 0, data
);
205 else /* clear existing region */
207 SERVER_START_REQ( set_window_region
)
209 req
->window
= wine_server_user_handle( hwnd
);
210 req
->redraw
= (bRedraw
!= 0);
211 ret
= !wine_server_call_err( req
);
216 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
220 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
221 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
222 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
223 invalidate_dce( hwnd
, NULL
);
224 if (hrgn
) DeleteObject( hrgn
);
230 /***********************************************************************
231 * GetClientRect (USER32.@)
233 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
235 return WIN_GetRectangles( hwnd
, COORDS_CLIENT
, NULL
, rect
);
239 /*******************************************************************
240 * ClientToScreen (USER32.@)
242 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
244 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
249 /*******************************************************************
250 * ScreenToClient (USER32.@)
252 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
254 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
259 /***********************************************************************
260 * list_children_from_point
262 * Get the list of children that can contain point from the server.
263 * Point is in screen coordinates.
264 * Returned list must be freed by caller.
266 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
275 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
277 SERVER_START_REQ( get_window_children_from_point
)
279 req
->parent
= wine_server_user_handle( hwnd
);
282 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
283 if (!wine_server_call( req
)) count
= reply
->count
;
286 if (count
&& count
< size
)
288 /* start from the end since HWND is potentially larger than user_handle_t */
289 for (i
= count
- 1; i
>= 0; i
--)
290 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
294 HeapFree( GetProcessHeap(), 0, list
);
296 size
= count
+ 1; /* restart with a large enough buffer */
302 /***********************************************************************
303 * WINPOS_WindowFromPoint
305 * Find the window and hittest for a given point.
307 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
312 if (!hwndScope
) hwndScope
= GetDesktopWindow();
314 *hittest
= HTNOWHERE
;
316 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
318 /* now determine the hittest */
320 for (i
= 0; list
[i
]; i
++)
322 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
324 /* If window is minimized or disabled, return at once */
325 if (style
& WS_MINIMIZE
)
327 *hittest
= HTCAPTION
;
330 if (style
& WS_DISABLED
)
335 /* Send WM_NCCHITTEST (if same thread) */
336 if (!WIN_IsCurrentThread( list
[i
] ))
341 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
342 if (res
!= HTTRANSPARENT
)
344 *hittest
= res
; /* Found the window */
347 /* continue search with next window in z-order */
350 HeapFree( GetProcessHeap(), 0, list
);
351 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
356 /*******************************************************************
357 * WindowFromPoint (USER32.@)
359 HWND WINAPI
WindowFromPoint( POINT pt
)
362 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
366 /*******************************************************************
367 * ChildWindowFromPoint (USER32.@)
369 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
371 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
374 /*******************************************************************
375 * RealChildWindowFromPoint (USER32.@)
377 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
379 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
| CWP_SKIPINVISIBLE
);
382 /*******************************************************************
383 * ChildWindowFromPointEx (USER32.@)
385 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
387 /* pt is in the client coordinates */
393 GetClientRect( hwndParent
, &rect
);
394 if (!PtInRect( &rect
, pt
)) return 0;
395 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
397 for (i
= 0; list
[i
]; i
++)
399 if (!WIN_GetRectangles( list
[i
], COORDS_PARENT
, &rect
, NULL
)) continue;
400 if (!PtInRect( &rect
, pt
)) continue;
401 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
403 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
404 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
405 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
407 if (uFlags
& CWP_SKIPTRANSPARENT
)
409 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
414 HeapFree( GetProcessHeap(), 0, list
);
415 if (!retvalue
) retvalue
= hwndParent
;
420 /*******************************************************************
421 * WINPOS_GetWinOffset
423 * Calculate the offset between the origin of the two windows. Used
424 * to implement MapWindowPoints.
426 static POINT
WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, BOOL
*mirrored
)
430 BOOL mirror_from
, mirror_to
;
433 offset
.x
= offset
.y
= 0;
434 *mirrored
= mirror_from
= mirror_to
= FALSE
;
436 /* Translate source window origin to screen coords */
439 if (!(wndPtr
= WIN_GetPtr( hwndFrom
))) return offset
;
440 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
441 if (wndPtr
!= WND_DESKTOP
)
443 if (wndPtr
->dwExStyle
& WS_EX_LAYOUTRTL
)
446 offset
.x
+= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
448 while (wndPtr
->parent
)
450 offset
.x
+= wndPtr
->rectClient
.left
;
451 offset
.y
+= wndPtr
->rectClient
.top
;
452 hwnd
= wndPtr
->parent
;
453 WIN_ReleasePtr( wndPtr
);
454 if (!(wndPtr
= WIN_GetPtr( hwnd
))) break;
455 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
456 if (wndPtr
== WND_DESKTOP
) break;
457 if (wndPtr
->flags
& WIN_CHILDREN_MOVED
)
459 WIN_ReleasePtr( wndPtr
);
463 if (wndPtr
&& wndPtr
!= WND_DESKTOP
) WIN_ReleasePtr( wndPtr
);
467 /* Translate origin to destination window coords */
470 if (!(wndPtr
= WIN_GetPtr( hwndTo
))) return offset
;
471 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
472 if (wndPtr
!= WND_DESKTOP
)
474 if (wndPtr
->dwExStyle
& WS_EX_LAYOUTRTL
)
477 offset
.x
-= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
479 while (wndPtr
->parent
)
481 offset
.x
-= wndPtr
->rectClient
.left
;
482 offset
.y
-= wndPtr
->rectClient
.top
;
483 hwnd
= wndPtr
->parent
;
484 WIN_ReleasePtr( wndPtr
);
485 if (!(wndPtr
= WIN_GetPtr( hwnd
))) break;
486 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
487 if (wndPtr
== WND_DESKTOP
) break;
488 if (wndPtr
->flags
& WIN_CHILDREN_MOVED
)
490 WIN_ReleasePtr( wndPtr
);
494 if (wndPtr
&& wndPtr
!= WND_DESKTOP
) WIN_ReleasePtr( wndPtr
);
498 *mirrored
= mirror_from
^ mirror_to
;
499 if (mirror_from
) offset
.x
= -offset
.x
;
502 other_process
: /* one of the parents may belong to another process, do it the hard way */
503 offset
.x
= offset
.y
= 0;
504 SERVER_START_REQ( get_windows_offset
)
506 req
->from
= wine_server_user_handle( hwndFrom
);
507 req
->to
= wine_server_user_handle( hwndTo
);
508 if (!wine_server_call( req
))
512 *mirrored
= reply
->mirror
;
519 /* map coordinates of a window region */
520 void map_window_region( HWND from
, HWND to
, HRGN hrgn
)
523 POINT offset
= WINPOS_GetWinOffset( from
, to
, &mirrored
);
531 OffsetRgn( hrgn
, offset
.x
, offset
.y
);
534 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return;
535 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return;
536 GetRegionData( hrgn
, size
, data
);
537 rect
= (RECT
*)data
->Buffer
;
538 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
540 int tmp
= -(rect
[i
].left
+ offset
.x
);
541 rect
[i
].left
= -(rect
[i
].right
+ offset
.x
);
543 rect
[i
].top
+= offset
.y
;
544 rect
[i
].bottom
+= offset
.y
;
546 if ((new_rgn
= ExtCreateRegion( NULL
, data
->rdh
.nCount
, data
)))
548 CombineRgn( hrgn
, new_rgn
, 0, RGN_COPY
);
549 DeleteObject( new_rgn
);
551 HeapFree( GetProcessHeap(), 0, data
);
555 /*******************************************************************
556 * MapWindowPoints (USER32.@)
558 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
561 POINT offset
= WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &mirrored
);
564 for (i
= 0; i
< count
; i
++)
566 lppt
[i
].x
+= offset
.x
;
567 lppt
[i
].y
+= offset
.y
;
568 if (mirrored
) lppt
[i
].x
= -lppt
[i
].x
;
570 if (mirrored
&& count
== 2) /* special case for rectangle */
573 lppt
[0].x
= lppt
[1].x
;
576 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
580 /***********************************************************************
581 * IsIconic (USER32.@)
583 BOOL WINAPI
IsIconic(HWND hWnd
)
585 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
589 /***********************************************************************
590 * IsZoomed (USER32.@)
592 BOOL WINAPI
IsZoomed(HWND hWnd
)
594 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
598 /*******************************************************************
599 * AllowSetForegroundWindow (USER32.@)
601 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
603 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
604 * implemented, then fix this function. */
609 /*******************************************************************
610 * LockSetForegroundWindow (USER32.@)
612 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
614 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
615 * implemented, then fix this function. */
620 /***********************************************************************
621 * BringWindowToTop (USER32.@)
623 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
625 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
629 /***********************************************************************
630 * MoveWindow (USER32.@)
632 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
635 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
636 if (!repaint
) flags
|= SWP_NOREDRAW
;
637 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
638 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
642 /***********************************************************************
643 * WINPOS_RedrawIconTitle
645 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
648 WND
*win
= WIN_GetPtr( hWnd
);
650 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
652 icon_title
= win
->icon_title
;
653 WIN_ReleasePtr( win
);
655 if (!icon_title
) return FALSE
;
656 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
657 InvalidateRect( icon_title
, NULL
, TRUE
);
661 /***********************************************************************
662 * WINPOS_ShowIconTitle
664 static BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
666 if (!GetPropA( hwnd
, "__wine_x11_managed" ))
668 WND
*win
= WIN_GetPtr( hwnd
);
671 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
673 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
674 title
= win
->icon_title
;
675 WIN_ReleasePtr( win
);
681 title
= ICONTITLE_Create( hwnd
);
682 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
684 DestroyWindow( title
);
687 win
->icon_title
= title
;
688 WIN_ReleasePtr( win
);
690 if (!IsWindowVisible(title
))
692 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
693 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
694 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
697 else if (title
) ShowWindow( title
, SW_HIDE
);
702 /*******************************************************************
703 * WINPOS_GetMinMaxInfo
705 * Get the minimized and maximized information for a window.
707 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
708 POINT
*minTrack
, POINT
*maxTrack
)
713 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
715 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
719 /* Compute default values */
721 GetWindowRect(hwnd
, &rc
);
722 MinMax
.ptReserved
.x
= rc
.left
;
723 MinMax
.ptReserved
.y
= rc
.top
;
725 if ((style
& WS_CAPTION
) == WS_CAPTION
)
726 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
728 adjustedStyle
= style
;
730 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
731 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
736 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
737 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
738 if (style
& (WS_DLGFRAME
| WS_BORDER
))
740 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
741 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
745 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
746 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
748 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
749 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
750 MinMax
.ptMaxPosition
.x
= -xinc
;
751 MinMax
.ptMaxPosition
.y
= -yinc
;
753 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
755 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
756 WIN_ReleasePtr( win
);
759 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
761 /* if the app didn't change the values, adapt them for the current monitor */
763 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
766 MONITORINFO mon_info
;
768 mon_info
.cbSize
= sizeof(mon_info
);
769 GetMonitorInfoW( monitor
, &mon_info
);
771 rc_work
= mon_info
.rcMonitor
;
773 if (style
& WS_MAXIMIZEBOX
)
775 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
776 rc_work
= mon_info
.rcWork
;
779 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
780 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
782 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
783 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
785 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
787 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
788 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
792 /* Some sanity checks */
794 TRACE("%d %d / %d %d / %d %d / %d %d\n",
795 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
796 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
797 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
798 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
799 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
800 MinMax
.ptMinTrackSize
.x
);
801 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
802 MinMax
.ptMinTrackSize
.y
);
804 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
805 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
806 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
807 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
811 /***********************************************************************
814 * Find a suitable place for an iconic window.
816 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
818 RECT rect
, rectParent
;
821 int xspacing
, yspacing
;
823 parent
= GetAncestor( hwnd
, GA_PARENT
);
824 GetClientRect( parent
, &rectParent
);
825 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
826 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
827 return pt
; /* The icon already has a suitable position */
829 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
830 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
832 /* Check if another icon already occupies this spot */
833 /* FIXME: this is completely inefficient */
835 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
836 tmp
= CreateRectRgn( 0, 0, 0, 0 );
837 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
839 if (child
== hwnd
) continue;
840 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
842 if (WIN_GetRectangles( child
, COORDS_PARENT
, &rect
, NULL
))
844 SetRectRgn( tmp
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
845 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
850 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
852 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
854 rect
.right
= rect
.left
+ xspacing
;
855 rect
.top
= rect
.bottom
- yspacing
;
856 if (!RectInRegion( hrgn
, &rect
))
858 /* No window was found, so it's OK for us */
859 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
860 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
861 DeleteObject( hrgn
);
866 DeleteObject( hrgn
);
872 /***********************************************************************
875 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
883 TRACE("%p %u\n", hwnd
, cmd
);
885 wpl
.length
= sizeof(wpl
);
886 GetWindowPlacement( hwnd
, &wpl
);
888 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
889 return SWP_NOSIZE
| SWP_NOMOVE
;
891 if (IsIconic( hwnd
))
895 case SW_SHOWMINNOACTIVE
:
896 case SW_SHOWMINIMIZED
:
897 case SW_FORCEMINIMIZE
:
899 return SWP_NOSIZE
| SWP_NOMOVE
;
901 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
902 swpFlags
|= SWP_NOCOPYBITS
;
907 case SW_SHOWMINNOACTIVE
:
908 case SW_SHOWMINIMIZED
:
909 case SW_FORCEMINIMIZE
:
911 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
912 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
913 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
914 WIN_ReleasePtr( wndPtr
);
916 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
918 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
920 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
921 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
922 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
923 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
924 swpFlags
|= SWP_NOCOPYBITS
;
928 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
929 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
931 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
933 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
934 if (old_style
& WS_MINIMIZE
)
936 if ((wndPtr
= WIN_GetPtr( hwnd
)) && wndPtr
!= WND_OTHER_PROCESS
)
938 wndPtr
->flags
|= WIN_RESTORE_MAX
;
939 WIN_ReleasePtr( wndPtr
);
941 WINPOS_ShowIconTitle( hwnd
, FALSE
);
944 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
945 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
946 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
949 case SW_SHOWNOACTIVATE
:
950 if ((wndPtr
= WIN_GetPtr( hwnd
)) && wndPtr
!= WND_OTHER_PROCESS
)
952 wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
953 WIN_ReleasePtr( wndPtr
);
958 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
959 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
960 if (old_style
& WS_MINIMIZE
)
964 WINPOS_ShowIconTitle( hwnd
, FALSE
);
966 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
967 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
968 WIN_ReleasePtr( wndPtr
);
971 /* Restore to maximized position */
972 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
973 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
974 swpFlags
|= SWP_STATECHANGED
;
975 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
976 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
980 else if (!(old_style
& WS_MAXIMIZE
)) break;
982 swpFlags
|= SWP_STATECHANGED
;
984 /* Restore to normal position */
986 *rect
= wpl
.rcNormalPosition
;
994 /***********************************************************************
997 * Implementation of ShowWindow and ShowWindowAsync.
999 static BOOL
show_window( HWND hwnd
, INT cmd
)
1003 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1004 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
1005 BOOL showFlag
= TRUE
;
1006 RECT newPos
= {0, 0, 0, 0};
1009 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
1014 if (!wasVisible
) return FALSE
;
1016 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1017 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1020 case SW_SHOWMINNOACTIVE
:
1022 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1023 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1025 case SW_SHOWMINIMIZED
:
1026 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1027 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1028 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
1031 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1032 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1033 swp
|= SWP_FRAMECHANGED
;
1034 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1035 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
1039 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1040 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
1043 if (wasVisible
) return TRUE
;
1044 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1045 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1048 case SW_SHOWNOACTIVATE
:
1049 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1053 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1054 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1055 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1056 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1058 swp
|= SWP_FRAMECHANGED
;
1059 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1063 if (wasVisible
) return TRUE
;
1064 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1066 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1072 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1074 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1075 if (!IsWindow( hwnd
)) return wasVisible
;
1078 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1080 parent
= GetAncestor( hwnd
, GA_PARENT
);
1081 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1083 /* if parent is not visible simply toggle WS_VISIBLE and return */
1084 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1085 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1088 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1089 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1095 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1097 /* FIXME: This will cause the window to be activated irrespective
1098 * of whether it is owned by the same thread. Has to be done
1102 if (hwnd
== GetActiveWindow())
1103 WINPOS_ActivateOtherWindow(hwnd
);
1105 /* Revert focus to parent */
1106 hFocus
= GetFocus();
1109 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1110 if (parent
== GetDesktopWindow()) parent
= 0;
1116 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1118 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1120 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1122 /* should happen only in CreateWindowEx() */
1123 int wParam
= SIZE_RESTORED
;
1127 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &client
);
1128 lparam
= MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
);
1129 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1130 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1131 else if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1133 wParam
= SIZE_MINIMIZED
;
1136 WIN_ReleasePtr( wndPtr
);
1138 SendMessageW( hwnd
, WM_SIZE
, wParam
, lparam
);
1139 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1141 else WIN_ReleasePtr( wndPtr
);
1143 /* if previous state was minimized Windows sets focus to the window */
1144 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1150 /***********************************************************************
1151 * ShowWindowAsync (USER32.@)
1153 * doesn't wait; returns immediately.
1154 * used by threads to toggle windows in other (possibly hanging) threads
1156 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1160 if (is_broadcast(hwnd
))
1162 SetLastError( ERROR_INVALID_PARAMETER
);
1166 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1167 return show_window( full_handle
, cmd
);
1169 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1173 /***********************************************************************
1174 * ShowWindow (USER32.@)
1176 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1180 if (is_broadcast(hwnd
))
1182 SetLastError( ERROR_INVALID_PARAMETER
);
1185 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1186 return show_window( full_handle
, cmd
);
1188 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1192 /***********************************************************************
1193 * GetInternalWindowPos (USER32.@)
1195 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1198 WINDOWPLACEMENT wndpl
;
1199 if (GetWindowPlacement( hwnd
, &wndpl
))
1201 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1202 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1203 return wndpl
.showCmd
;
1209 /***********************************************************************
1210 * GetWindowPlacement (USER32.@)
1213 * Fails if wndpl->length of Win95 (!) apps is invalid.
1215 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1217 WND
*pWnd
= WIN_GetPtr( hwnd
);
1219 if (!pWnd
) return FALSE
;
1221 if (pWnd
== WND_DESKTOP
)
1223 wndpl
->length
= sizeof(*wndpl
);
1224 wndpl
->showCmd
= SW_SHOWNORMAL
;
1226 wndpl
->ptMinPosition
.x
= -1;
1227 wndpl
->ptMinPosition
.y
= -1;
1228 wndpl
->ptMaxPosition
.x
= -1;
1229 wndpl
->ptMaxPosition
.y
= -1;
1230 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1233 if (pWnd
== WND_OTHER_PROCESS
)
1235 if (!IsWindow( hwnd
)) return FALSE
;
1236 FIXME( "not supported on other process window %p\n", hwnd
);
1237 /* provide some dummy information */
1238 wndpl
->length
= sizeof(*wndpl
);
1239 wndpl
->showCmd
= SW_SHOWNORMAL
;
1241 wndpl
->ptMinPosition
.x
= -1;
1242 wndpl
->ptMinPosition
.y
= -1;
1243 wndpl
->ptMaxPosition
.x
= -1;
1244 wndpl
->ptMaxPosition
.y
= -1;
1245 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1249 /* update the placement according to the current style */
1250 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1252 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1253 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1255 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1257 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1258 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1262 pWnd
->normal_rect
= pWnd
->rectWindow
;
1265 wndpl
->length
= sizeof(*wndpl
);
1266 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1267 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1269 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1270 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1271 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1274 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1275 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1276 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1277 WIN_ReleasePtr( pWnd
);
1279 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1280 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1281 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1282 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1286 /* make sure the specified rect is visible on screen */
1287 static void make_rect_onscreen( RECT
*rect
)
1290 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1292 info
.cbSize
= sizeof(info
);
1293 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1294 /* FIXME: map coordinates from rcWork to rcMonitor */
1295 if (rect
->right
<= info
.rcWork
.left
)
1297 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1298 rect
->left
= info
.rcWork
.left
;
1300 else if (rect
->left
>= info
.rcWork
.right
)
1302 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1303 rect
->right
= info
.rcWork
.right
;
1305 if (rect
->bottom
<= info
.rcWork
.top
)
1307 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1308 rect
->top
= info
.rcWork
.top
;
1310 else if (rect
->top
>= info
.rcWork
.bottom
)
1312 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1313 rect
->bottom
= info
.rcWork
.bottom
;
1317 /* make sure the specified point is visible on screen */
1318 static void make_point_onscreen( POINT
*pt
)
1322 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1323 make_rect_onscreen( &rect
);
1329 /***********************************************************************
1330 * WINPOS_SetPlacement
1332 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1335 WND
*pWnd
= WIN_GetPtr( hwnd
);
1336 WINDOWPLACEMENT wp
= *wndpl
;
1338 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1339 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1340 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1342 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1343 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1344 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1345 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1346 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1347 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1349 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1351 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1352 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1353 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1355 style
= pWnd
->dwStyle
;
1357 WIN_ReleasePtr( pWnd
);
1359 if( style
& WS_MINIMIZE
)
1361 if (flags
& PLACE_MIN
)
1363 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1364 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1365 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1368 else if( style
& WS_MAXIMIZE
)
1370 if (flags
& PLACE_MAX
)
1371 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1372 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1374 else if( flags
& PLACE_RECT
)
1375 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1376 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1377 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1378 SWP_NOZORDER
| SWP_NOACTIVATE
);
1380 ShowWindow( hwnd
, wndpl
->showCmd
);
1382 if (IsIconic( hwnd
))
1384 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1386 /* SDK: ...valid only the next time... */
1387 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1389 pWnd
= WIN_GetPtr( hwnd
);
1390 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1392 pWnd
->flags
|= WIN_RESTORE_MAX
;
1393 WIN_ReleasePtr( pWnd
);
1401 /***********************************************************************
1402 * SetWindowPlacement (USER32.@)
1405 * Fails if wndpl->length of Win95 (!) apps is invalid.
1407 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1409 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1410 if (!wpl
) return FALSE
;
1411 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1412 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1416 /***********************************************************************
1417 * AnimateWindow (USER32.@)
1418 * Shows/Hides a window with an animation
1421 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1423 FIXME("partial stub\n");
1425 /* If trying to show/hide and it's already *
1426 * shown/hidden or invalid window, fail with *
1427 * invalid parameter */
1428 if(!IsWindow(hwnd
) ||
1429 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1430 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1432 SetLastError(ERROR_INVALID_PARAMETER
);
1436 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1441 /***********************************************************************
1442 * SetInternalWindowPos (USER32.@)
1444 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1445 LPRECT rect
, LPPOINT pt
)
1447 WINDOWPLACEMENT wndpl
;
1450 wndpl
.length
= sizeof(wndpl
);
1451 wndpl
.showCmd
= showCmd
;
1452 wndpl
.flags
= flags
= 0;
1457 wndpl
.flags
|= WPF_SETMINPOSITION
;
1458 wndpl
.ptMinPosition
= *pt
;
1462 flags
|= PLACE_RECT
;
1463 wndpl
.rcNormalPosition
= *rect
;
1465 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1469 /*******************************************************************
1470 * can_activate_window
1472 * Check if we can activate the specified window.
1474 static BOOL
can_activate_window( HWND hwnd
)
1478 if (!hwnd
) return FALSE
;
1479 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1480 if (!(style
& WS_VISIBLE
)) return FALSE
;
1481 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1482 return !(style
& WS_DISABLED
);
1486 /*******************************************************************
1487 * WINPOS_ActivateOtherWindow
1489 * Activates window other than pWnd.
1491 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1495 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1497 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1498 if (can_activate_window( hwndTo
)) goto done
;
1504 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1505 if (can_activate_window( hwndTo
)) break;
1509 fg
= GetForegroundWindow();
1510 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1511 if (!fg
|| (hwnd
== fg
))
1513 if (SetForegroundWindow( hwndTo
)) return;
1515 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1519 /***********************************************************************
1520 * WINPOS_HandleWindowPosChanging
1522 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1524 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1526 POINT minTrack
, maxTrack
;
1527 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1529 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1530 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1532 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1533 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1534 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1535 if (!(style
& WS_MINIMIZE
))
1537 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1538 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1545 /***********************************************************************
1548 static void dump_winpos_flags(UINT flags
)
1550 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1551 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1552 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1553 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1554 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1556 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1557 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1558 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1559 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1560 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1561 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1562 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1563 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1564 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1565 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1566 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1567 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1568 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1569 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1570 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1571 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1573 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1577 /***********************************************************************
1578 * SWP_DoWinPosChanging
1580 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1583 RECT window_rect
, client_rect
;
1585 /* Send WM_WINDOWPOSCHANGING message */
1587 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1588 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1590 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1591 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1593 /* Calculate new position and size */
1595 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1596 *pNewWindowRect
= window_rect
;
1597 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? window_rect
: client_rect
;
1599 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1601 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
1603 pNewWindowRect
->right
= pNewWindowRect
->left
+ GetSystemMetrics(SM_CXICON
);
1604 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ GetSystemMetrics(SM_CYICON
);
1608 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1609 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1612 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1614 pNewWindowRect
->left
= pWinpos
->x
;
1615 pNewWindowRect
->top
= pWinpos
->y
;
1616 pNewWindowRect
->right
+= pWinpos
->x
- window_rect
.left
;
1617 pNewWindowRect
->bottom
+= pWinpos
->y
- window_rect
.top
;
1619 OffsetRect( pNewClientRect
, pWinpos
->x
- window_rect
.left
,
1620 pWinpos
->y
- window_rect
.top
);
1622 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1624 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1625 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1626 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1627 TRACE( "current %s style %08x new %s\n",
1628 wine_dbgstr_rect( &window_rect
), wndPtr
->dwStyle
,
1629 wine_dbgstr_rect( pNewWindowRect
));
1631 WIN_ReleasePtr( wndPtr
);
1635 /***********************************************************************
1638 * Compute the valid rects from the old and new client rect and WVR_* flags.
1639 * Helper for WM_NCCALCSIZE handling.
1641 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1646 if (flags
& WVR_REDRAW
)
1648 SetRectEmpty( &valid
[0] );
1649 SetRectEmpty( &valid
[1] );
1653 if (flags
& WVR_VALIDRECTS
)
1655 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1656 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1658 SetRectEmpty( &valid
[0] );
1659 SetRectEmpty( &valid
[1] );
1662 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1666 valid
[0] = *new_client
;
1667 valid
[1] = *old_client
;
1670 /* make sure the rectangles have the same size */
1671 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1672 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1674 if (flags
& WVR_ALIGNBOTTOM
)
1676 valid
[0].top
= valid
[0].bottom
- cy
;
1677 valid
[1].top
= valid
[1].bottom
- cy
;
1681 valid
[0].bottom
= valid
[0].top
+ cy
;
1682 valid
[1].bottom
= valid
[1].top
+ cy
;
1684 if (flags
& WVR_ALIGNRIGHT
)
1686 valid
[0].left
= valid
[0].right
- cx
;
1687 valid
[1].left
= valid
[1].right
- cx
;
1691 valid
[0].right
= valid
[0].left
+ cx
;
1692 valid
[1].right
= valid
[1].left
+ cx
;
1697 /***********************************************************************
1700 * fix Z order taking into account owned popups -
1701 * basically we need to maintain them above the window that owns them
1703 * FIXME: hide/show owned popups when owner visibility changes.
1705 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1707 HWND owner
, *list
= NULL
;
1710 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1712 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return hwndInsertAfter
;
1714 if ((owner
= GetWindow( hwnd
, GW_OWNER
)))
1716 /* make sure this popup stays above the owner */
1718 if (hwndInsertAfter
!= HWND_TOPMOST
)
1720 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1722 for (i
= 0; list
[i
]; i
++)
1724 BOOL topmost
= (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
1726 if (list
[i
] == owner
)
1728 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1729 else hwndInsertAfter
= topmost
? HWND_TOPMOST
: HWND_TOP
;
1733 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1735 if (!topmost
) break;
1737 else if (list
[i
] == hwndInsertAfter
) break;
1742 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1743 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1746 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1748 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1750 /* skip all the topmost windows */
1751 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1754 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1756 /* skip windows that are already placed correctly */
1757 for (i
= 0; list
[i
]; i
++)
1759 if (list
[i
] == hwndInsertAfter
) break;
1760 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1764 for ( ; list
[i
]; i
++)
1766 if (list
[i
] == hwnd
) break;
1767 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1768 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1769 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1770 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1771 hwndInsertAfter
= list
[i
];
1775 HeapFree( GetProcessHeap(), 0, list
);
1776 return hwndInsertAfter
;
1779 /***********************************************************************
1782 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1786 RECT window_rect
, client_rect
;
1788 WIN_GetRectangles( pWinpos
->hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
1790 /* Send WM_NCCALCSIZE message to get new client area */
1791 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1793 NCCALCSIZE_PARAMS params
;
1794 WINDOWPOS winposCopy
;
1796 params
.rgrc
[0] = *pNewWindowRect
;
1797 params
.rgrc
[1] = window_rect
;
1798 params
.rgrc
[2] = client_rect
;
1799 params
.lppos
= &winposCopy
;
1800 winposCopy
= *pWinpos
;
1802 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1804 *pNewClientRect
= params
.rgrc
[0];
1806 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1807 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
),
1808 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1810 if( pNewClientRect
->left
!= client_rect
.left
||
1811 pNewClientRect
->top
!= client_rect
.top
)
1812 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1814 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1815 client_rect
.right
- client_rect
.left
))
1816 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1818 wvrFlags
&= ~WVR_HREDRAW
;
1820 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1821 client_rect
.bottom
- client_rect
.top
)
1822 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1824 wvrFlags
&= ~WVR_VREDRAW
;
1826 validRects
[0] = params
.rgrc
[1];
1827 validRects
[1] = params
.rgrc
[2];
1831 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1832 (pNewClientRect
->left
!= client_rect
.left
||
1833 pNewClientRect
->top
!= client_rect
.top
))
1834 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1837 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1839 SetRectEmpty( &validRects
[0] );
1840 SetRectEmpty( &validRects
[1] );
1842 else get_valid_rects( &client_rect
, pNewClientRect
, wvrFlags
, validRects
);
1847 /* fix redundant flags and values in the WINDOWPOS structure */
1848 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1853 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1856 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1858 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1861 winpos
->hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
1863 /* Finally make sure that all coordinates are valid */
1864 if (winpos
->x
< -32768) winpos
->x
= -32768;
1865 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1866 if (winpos
->y
< -32768) winpos
->y
= -32768;
1867 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1869 if (winpos
->cx
< 0) winpos
->cx
= 0;
1870 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1871 if (winpos
->cy
< 0) winpos
->cy
= 0;
1872 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1874 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1875 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1877 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1880 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1881 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1884 WIN_GetRectangles( winpos
->hwnd
, COORDS_SCREEN
, &window_rect
, NULL
);
1885 if ((window_rect
.right
- window_rect
.left
== winpos
->cx
) &&
1886 (window_rect
.bottom
- window_rect
.top
== winpos
->cy
))
1887 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1891 ClientToScreen( parent
, &pt
);
1892 if ((window_rect
.left
== pt
.x
) && (window_rect
.top
== pt
.y
))
1893 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1895 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1897 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1898 (winpos
->flags
& SWP_NOZORDER
||
1899 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1901 winpos
->flags
&= ~SWP_NOZORDER
;
1902 winpos
->hwndInsertAfter
= HWND_TOP
;
1906 /* Check hwndInsertAfter */
1907 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1909 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1911 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1912 winpos
->flags
|= SWP_NOZORDER
;
1914 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1916 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1917 winpos
->flags
|= SWP_NOZORDER
;
1919 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1921 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1922 winpos
->flags
|= SWP_NOZORDER
;
1924 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1926 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1927 winpos
->flags
|= SWP_NOZORDER
;
1931 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1932 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1933 winpos
->flags
|= SWP_NOZORDER
;
1936 WIN_ReleasePtr( wndPtr
);
1941 /***********************************************************************
1944 * Backend implementation of SetWindowPos.
1946 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1947 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
1951 RECT visible_rect
, old_window_rect
;
1954 visible_rect
= *window_rect
;
1955 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
1956 window_rect
, client_rect
, &visible_rect
);
1958 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_window_rect
, NULL
);
1960 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
1961 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
1962 old_width
= win
->rectClient
.right
- win
->rectClient
.left
;
1964 SERVER_START_REQ( set_window_pos
)
1966 req
->handle
= wine_server_user_handle( hwnd
);
1967 req
->previous
= wine_server_user_handle( insert_after
);
1968 req
->flags
= swp_flags
;
1969 req
->window
.left
= window_rect
->left
;
1970 req
->window
.top
= window_rect
->top
;
1971 req
->window
.right
= window_rect
->right
;
1972 req
->window
.bottom
= window_rect
->bottom
;
1973 req
->client
.left
= client_rect
->left
;
1974 req
->client
.top
= client_rect
->top
;
1975 req
->client
.right
= client_rect
->right
;
1976 req
->client
.bottom
= client_rect
->bottom
;
1977 if (memcmp( window_rect
, &visible_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
1979 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
1980 if (!IsRectEmpty( &valid_rects
[0] ))
1981 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
1983 if ((ret
= !wine_server_call( req
)))
1985 win
->dwStyle
= reply
->new_style
;
1986 win
->dwExStyle
= reply
->new_ex_style
;
1987 win
->rectWindow
= *window_rect
;
1988 win
->rectClient
= *client_rect
;
1989 if (GetWindowLongW( win
->parent
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
)
1992 GetClientRect( win
->parent
, &client
);
1993 mirror_rect( &client
, &win
->rectWindow
);
1994 mirror_rect( &client
, &win
->rectClient
);
1996 /* if an RTL window is resized the children have moved */
1997 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
&& client_rect
->right
- client_rect
->left
!= old_width
)
1998 win
->flags
|= WIN_CHILDREN_MOVED
;
2002 WIN_ReleasePtr( win
);
2006 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
2007 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
)))
2008 invalidate_dce( hwnd
, &old_window_rect
);
2010 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
2011 client_rect
, &visible_rect
, valid_rects
);
2017 /***********************************************************************
2020 * User32 internal function
2022 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
2024 RECT newWindowRect
, newClientRect
, valid_rects
[2];
2027 orig_flags
= winpos
->flags
;
2029 /* First, check z-order arguments. */
2030 if (!(winpos
->flags
& SWP_NOZORDER
))
2032 /* fix sign extension */
2033 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
2034 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
2036 if (!(winpos
->hwndInsertAfter
== HWND_TOP
||
2037 winpos
->hwndInsertAfter
== HWND_BOTTOM
||
2038 winpos
->hwndInsertAfter
== HWND_TOPMOST
||
2039 winpos
->hwndInsertAfter
== HWND_NOTOPMOST
))
2041 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2042 HWND insertafter_parent
= GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
);
2044 /* hwndInsertAfter must be a sibling of the window */
2045 if (!insertafter_parent
) return FALSE
;
2046 if (insertafter_parent
!= parent
) return TRUE
;
2050 /* Make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
2051 if (!(winpos
->flags
& SWP_NOMOVE
))
2053 if (winpos
->x
< -32768) winpos
->x
= -32768;
2054 else if (winpos
->x
> 32767) winpos
->x
= 32767;
2055 if (winpos
->y
< -32768) winpos
->y
= -32768;
2056 else if (winpos
->y
> 32767) winpos
->y
= 32767;
2058 if (!(winpos
->flags
& SWP_NOSIZE
))
2060 if (winpos
->cx
< 0) winpos
->cx
= 0;
2061 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
2062 if (winpos
->cy
< 0) winpos
->cy
= 0;
2063 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
2066 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
2068 /* Fix redundant flags */
2069 if (!fixup_flags( winpos
)) return FALSE
;
2071 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
2073 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
2074 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
2077 /* Common operations */
2079 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
2081 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
2082 &newWindowRect
, &newClientRect
, valid_rects
))
2085 /* erase parent when hiding or resizing child */
2086 if (!(orig_flags
& SWP_DEFERERASE
) &&
2087 ((orig_flags
& SWP_HIDEWINDOW
) ||
2088 (!(orig_flags
& SWP_SHOWWINDOW
) &&
2089 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
2091 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
2092 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
2093 erase_now( parent
, 0 );
2096 if( winpos
->flags
& SWP_HIDEWINDOW
)
2097 HideCaret(winpos
->hwnd
);
2098 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2099 ShowCaret(winpos
->hwnd
);
2101 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2103 /* child windows get WM_CHILDACTIVATE message */
2104 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2105 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2107 SetForegroundWindow( winpos
->hwnd
);
2110 /* And last, send the WM_WINDOWPOSCHANGED message */
2112 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2114 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2116 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2117 and always contains final window position.
2119 winpos
->x
= newWindowRect
.left
;
2120 winpos
->y
= newWindowRect
.top
;
2121 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2122 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2123 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2128 /***********************************************************************
2129 * SetWindowPos (USER32.@)
2131 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2132 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2136 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2137 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2138 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2140 if (is_broadcast(hwnd
))
2142 SetLastError( ERROR_INVALID_PARAMETER
);
2146 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2147 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2152 winpos
.flags
= flags
;
2154 if (WIN_IsCurrentThread( hwnd
))
2155 return USER_SetWindowPos(&winpos
);
2157 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2161 /***********************************************************************
2162 * BeginDeferWindowPos (USER32.@)
2164 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2169 TRACE("%d\n", count
);
2173 SetLastError(ERROR_INVALID_PARAMETER
);
2176 /* Windows allows zero count, in which case it allocates context for 8 moves */
2177 if (count
== 0) count
= 8;
2179 if (!(pDWP
= HeapAlloc( GetProcessHeap(), 0, sizeof(DWP
)))) return 0;
2181 pDWP
->actualCount
= 0;
2182 pDWP
->suggestedCount
= count
;
2183 pDWP
->hwndParent
= 0;
2185 if (!(pDWP
->winPos
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(WINDOWPOS
) )) ||
2186 !(handle
= alloc_user_handle( &pDWP
->obj
, USER_DWP
)))
2188 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2189 HeapFree( GetProcessHeap(), 0, pDWP
);
2192 TRACE("returning hdwp %p\n", handle
);
2197 /***********************************************************************
2198 * DeferWindowPos (USER32.@)
2200 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2201 INT x
, INT y
, INT cx
, INT cy
,
2206 HDWP retvalue
= hdwp
;
2208 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2209 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2211 hwnd
= WIN_GetFullHandle( hwnd
);
2212 if (is_desktop_window( hwnd
)) return 0;
2214 if (!(pDWP
= get_user_handle_ptr( hdwp
, USER_DWP
))) return 0;
2215 if (pDWP
== OBJ_OTHER_PROCESS
)
2217 FIXME( "other process handle %p?\n", hdwp
);
2221 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2223 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2225 /* Merge with the other changes */
2226 if (!(flags
& SWP_NOZORDER
))
2228 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2230 if (!(flags
& SWP_NOMOVE
))
2232 pDWP
->winPos
[i
].x
= x
;
2233 pDWP
->winPos
[i
].y
= y
;
2235 if (!(flags
& SWP_NOSIZE
))
2237 pDWP
->winPos
[i
].cx
= cx
;
2238 pDWP
->winPos
[i
].cy
= cy
;
2240 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2241 SWP_NOZORDER
| SWP_NOREDRAW
|
2242 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2244 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2249 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2251 WINDOWPOS
*newpos
= HeapReAlloc( GetProcessHeap(), 0, pDWP
->winPos
,
2252 pDWP
->suggestedCount
* 2 * sizeof(WINDOWPOS
) );
2258 pDWP
->suggestedCount
*= 2;
2259 pDWP
->winPos
= newpos
;
2261 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2262 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2263 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2264 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2265 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2266 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2267 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2268 pDWP
->actualCount
++;
2270 release_user_handle_ptr( pDWP
);
2275 /***********************************************************************
2276 * EndDeferWindowPos (USER32.@)
2278 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2285 TRACE("%p\n", hdwp
);
2287 if (!(pDWP
= free_user_handle( hdwp
, USER_DWP
))) return FALSE
;
2288 if (pDWP
== OBJ_OTHER_PROCESS
)
2290 FIXME( "other process handle %p?\n", hdwp
);
2294 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2296 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2297 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2298 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2300 if (WIN_IsCurrentThread( winpos
->hwnd
))
2301 res
= USER_SetWindowPos( winpos
);
2303 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2305 HeapFree( GetProcessHeap(), 0, pDWP
->winPos
);
2306 HeapFree( GetProcessHeap(), 0, pDWP
);
2311 /***********************************************************************
2312 * ArrangeIconicWindows (USER32.@)
2314 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2318 INT x
, y
, xspacing
, yspacing
;
2320 GetClientRect( parent
, &rectParent
);
2321 x
= rectParent
.left
;
2322 y
= rectParent
.bottom
;
2323 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2324 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2326 hwndChild
= GetWindow( parent
, GW_CHILD
);
2329 if( IsIconic( hwndChild
) )
2331 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2333 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2334 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
2335 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2336 if( IsWindow(hwndChild
) )
2337 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2339 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
2342 x
= rectParent
.left
;
2346 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2352 /***********************************************************************
2355 * Draw the frame used when moving or resizing window.
2357 static void draw_moving_frame( HWND parent
, HDC hdc
, RECT
*screen_rect
, BOOL thickframe
)
2359 RECT rect
= *screen_rect
;
2361 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2364 const int width
= GetSystemMetrics(SM_CXFRAME
);
2365 const int height
= GetSystemMetrics(SM_CYFRAME
);
2367 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2368 PatBlt( hdc
, rect
.left
, rect
.top
,
2369 rect
.right
- rect
.left
- width
, height
, PATINVERT
);
2370 PatBlt( hdc
, rect
.left
, rect
.top
+ height
, width
,
2371 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2372 PatBlt( hdc
, rect
.left
+ width
, rect
.bottom
- 1,
2373 rect
.right
- rect
.left
- width
, -height
, PATINVERT
);
2374 PatBlt( hdc
, rect
.right
- 1, rect
.top
, -width
,
2375 rect
.bottom
- rect
.top
- height
, PATINVERT
);
2376 SelectObject( hdc
, hbrush
);
2378 else DrawFocusRect( hdc
, &rect
);
2382 /***********************************************************************
2385 * Initialization of a move or resize, when initiated from a menu choice.
2386 * Return hit test code for caption or sizing border.
2388 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2395 GetWindowRect( hwnd
, &rectWindow
);
2397 if ((wParam
& 0xfff0) == SC_MOVE
)
2399 /* Move pointer at the center of the caption */
2400 RECT rect
= rectWindow
;
2401 /* Note: to be exactly centered we should take the different types
2402 * of border into account, but it shouldn't make more than a few pixels
2403 * of difference so let's not bother with that */
2404 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2405 if (style
& WS_SYSMENU
)
2406 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2407 if (style
& WS_MINIMIZEBOX
)
2408 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2409 if (style
& WS_MAXIMIZEBOX
)
2410 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2411 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2412 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2413 hittest
= HTCAPTION
;
2418 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2422 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2423 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2428 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2429 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2430 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2431 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2442 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2443 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2447 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2448 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2452 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2453 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2457 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2458 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2466 TranslateMessage( &msg
);
2467 DispatchMessageW( &msg
);
2473 SetCursorPos( pt
.x
, pt
.y
);
2474 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2479 /***********************************************************************
2480 * WINPOS_SysCommandSizeMove
2482 * Perform SC_MOVE and SC_SIZE commands.
2484 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2487 RECT sizingRect
, mouseRect
, origRect
;
2490 LONG hittest
= (LONG
)(wParam
& 0x0f);
2491 WPARAM syscommand
= wParam
& 0xfff0;
2492 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2493 POINT minTrack
, maxTrack
;
2494 POINT capturePoint
, pt
;
2495 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2496 BOOL thickframe
= HAS_THICKFRAME( style
);
2497 BOOL iconic
= style
& WS_MINIMIZE
;
2499 DWORD dwPoint
= GetMessagePos ();
2500 BOOL DragFullWindows
= TRUE
;
2502 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2504 pt
.x
= (short)LOWORD(dwPoint
);
2505 pt
.y
= (short)HIWORD(dwPoint
);
2509 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2510 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2512 if (syscommand
== SC_MOVE
)
2514 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2515 if (!hittest
) return;
2519 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2520 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2523 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2524 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2527 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2533 /* Get min/max info */
2535 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2536 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &sizingRect
, NULL
);
2537 origRect
= sizingRect
;
2538 if (style
& WS_CHILD
)
2540 parent
= GetParent(hwnd
);
2541 GetClientRect( parent
, &mouseRect
);
2542 MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2543 MapWindowPoints( parent
, 0, (LPPOINT
)&sizingRect
, 2 );
2548 GetClientRect( GetDesktopWindow(), &mouseRect
);
2549 mouseRect
.left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
2550 mouseRect
.top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
2551 mouseRect
.right
= mouseRect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
2552 mouseRect
.bottom
= mouseRect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
2555 if (ON_LEFT_BORDER(hittest
))
2557 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
2558 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
2560 else if (ON_RIGHT_BORDER(hittest
))
2562 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
2563 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
2565 if (ON_TOP_BORDER(hittest
))
2567 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
2568 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
2570 else if (ON_BOTTOM_BORDER(hittest
))
2572 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
2573 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
2576 /* Retrieve a default cache DC (without using the window style) */
2577 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2579 if( iconic
) /* create a cursor for dragging */
2581 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2582 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2583 if( !hDragCursor
) iconic
= FALSE
;
2586 /* we only allow disabling the full window drag for child windows */
2587 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2589 /* repaint the window before moving it around */
2590 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2592 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2593 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2599 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2600 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2602 /* Exit on button-up, Return, or Esc */
2603 if ((msg
.message
== WM_LBUTTONUP
) ||
2604 ((msg
.message
== WM_KEYDOWN
) &&
2605 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2607 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2609 TranslateMessage( &msg
);
2610 DispatchMessageW( &msg
);
2611 continue; /* We are not interested in other messages */
2616 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2618 case VK_UP
: pt
.y
-= 8; break;
2619 case VK_DOWN
: pt
.y
+= 8; break;
2620 case VK_LEFT
: pt
.x
-= 8; break;
2621 case VK_RIGHT
: pt
.x
+= 8; break;
2624 pt
.x
= max( pt
.x
, mouseRect
.left
);
2625 pt
.x
= min( pt
.x
, mouseRect
.right
);
2626 pt
.y
= max( pt
.y
, mouseRect
.top
);
2627 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2629 dx
= pt
.x
- capturePoint
.x
;
2630 dy
= pt
.y
- capturePoint
.y
;
2638 if( iconic
) /* ok, no system popup tracking */
2640 hOldCursor
= SetCursor(hDragCursor
);
2642 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2644 else if(!DragFullWindows
)
2645 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2648 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2651 WPARAM wpSizingHit
= 0;
2653 if(!iconic
&& !DragFullWindows
) draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2654 if (hittest
== HTCAPTION
) OffsetRect( &sizingRect
, dx
, dy
);
2655 if (ON_LEFT_BORDER(hittest
)) sizingRect
.left
+= dx
;
2656 else if (ON_RIGHT_BORDER(hittest
)) sizingRect
.right
+= dx
;
2657 if (ON_TOP_BORDER(hittest
)) sizingRect
.top
+= dy
;
2658 else if (ON_BOTTOM_BORDER(hittest
)) sizingRect
.bottom
+= dy
;
2661 /* determine the hit location */
2662 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2663 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2664 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&sizingRect
);
2668 if(!DragFullWindows
)
2669 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2672 RECT rect
= sizingRect
;
2673 MapWindowPoints( 0, parent
, (POINT
*)&rect
, 2 );
2674 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
2675 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
2676 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2685 if( moved
) /* restore cursors, show icon title later on */
2687 ShowCursor( FALSE
);
2688 SetCursor( hOldCursor
);
2691 else if (moved
&& !DragFullWindows
)
2693 draw_moving_frame( parent
, hdc
, &sizingRect
, thickframe
);
2696 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2697 ReleaseDC( parent
, hdc
);
2698 if (parent
) MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2700 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2703 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2704 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2706 /* window moved or resized */
2709 /* if the moving/resizing isn't canceled call SetWindowPos
2710 * with the new position or the new size of the window
2712 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2714 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2715 if(!DragFullWindows
|| iconic
)
2716 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2717 sizingRect
.right
- sizingRect
.left
,
2718 sizingRect
.bottom
- sizingRect
.top
,
2719 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2722 { /* restore previous size/position */
2724 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2725 origRect
.right
- origRect
.left
,
2726 origRect
.bottom
- origRect
.top
,
2727 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2733 /* Single click brings up the system menu when iconized */
2737 if(style
& WS_SYSMENU
)
2738 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2739 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2741 else WINPOS_ShowIconTitle( hwnd
, TRUE
);