user32: Properly update position after dragging an iconic window.
[wine.git] / dlls / user32 / winpos.c
blobacfd4810d55f09fad1a4e19dfaebc6fb56e26b62
1 /*
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "wine/server.h"
34 #include "controls.h"
35 #include "user_private.h"
36 #include "win.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)))
74 typedef struct
76 INT actualCount;
77 INT suggestedCount;
78 BOOL valid;
79 INT wMagic;
80 HWND hwndParent;
81 WINDOWPOS winPos[1];
82 } DWP;
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 );
100 if (ret)
102 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd, wine_dbgstr_rect(rect) );
105 return ret;
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
114 int nRet = ERROR;
115 NTSTATUS status;
116 HRGN win_rgn = 0;
117 RGNDATA *data;
118 size_t size = 256;
122 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
124 SetLastError( ERROR_OUTOFMEMORY );
125 return ERROR;
127 SERVER_START_REQ( get_window_region )
129 req->window = 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 );
134 if (reply_size)
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;
145 SERVER_END_REQ;
146 HeapFree( GetProcessHeap(), 0, data );
147 } while (status == STATUS_BUFFER_OVERFLOW);
149 if (status) SetLastError( RtlNtStatusToDosError(status) );
150 else if (win_rgn)
152 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
153 DeleteObject( win_rgn );
155 return nRet;
159 /***********************************************************************
160 * SetWindowRgn (USER32.@)
162 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
164 static const RECT empty_rect;
165 BOOL ret;
167 if (hrgn)
169 RGNDATA *data;
170 DWORD size;
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 );
177 return FALSE;
179 SERVER_START_REQ( set_window_region )
181 req->window = hwnd;
182 req->redraw = (bRedraw != 0);
183 if (data->rdh.nCount)
184 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
185 else
186 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
187 ret = !wine_server_call_err( req );
189 SERVER_END_REQ;
191 else /* clear existing region */
193 SERVER_START_REQ( set_window_region )
195 req->window = hwnd;
196 req->redraw = (bRedraw != 0);
197 ret = !wine_server_call_err( req );
199 SERVER_END_REQ;
202 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
204 if (ret)
206 UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
207 if (!bRedraw) swp_flags |= SWP_NOREDRAW;
208 SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
209 invalidate_dce( hwnd, NULL );
211 return ret;
215 /***********************************************************************
216 * GetClientRect (USER32.@)
218 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
220 BOOL ret;
222 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
224 rect->right -= rect->left;
225 rect->bottom -= rect->top;
226 rect->left = rect->top = 0;
228 return ret;
232 /*******************************************************************
233 * ClientToScreen (USER32.@)
235 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
237 MapWindowPoints( hwnd, 0, lppnt, 1 );
238 return TRUE;
242 /*******************************************************************
243 * ScreenToClient (USER32.@)
245 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
247 MapWindowPoints( 0, hwnd, lppnt, 1 );
248 return TRUE;
252 /***********************************************************************
253 * list_children_from_point
255 * Get the list of children that can contain point from the server.
256 * Point is in screen coordinates.
257 * Returned list must be freed by caller.
259 static HWND *list_children_from_point( HWND hwnd, POINT pt )
261 HWND *list;
262 int size = 128;
264 for (;;)
266 int count = 0;
268 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
270 SERVER_START_REQ( get_window_children_from_point )
272 req->parent = hwnd;
273 req->x = pt.x;
274 req->y = pt.y;
275 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
276 if (!wine_server_call( req )) count = reply->count;
278 SERVER_END_REQ;
279 if (count && count < size)
281 list[count] = 0;
282 return list;
284 HeapFree( GetProcessHeap(), 0, list );
285 if (!count) break;
286 size = count + 1; /* restart with a large enough buffer */
288 return NULL;
292 /***********************************************************************
293 * WINPOS_WindowFromPoint
295 * Find the window and hittest for a given point.
297 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
299 int i, res;
300 HWND ret, *list;
302 if (!hwndScope) hwndScope = GetDesktopWindow();
304 *hittest = HTNOWHERE;
306 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
308 /* now determine the hittest */
310 for (i = 0; list[i]; i++)
312 LONG style = GetWindowLongW( list[i], GWL_STYLE );
314 /* If window is minimized or disabled, return at once */
315 if (style & WS_MINIMIZE)
317 *hittest = HTCAPTION;
318 break;
320 if (style & WS_DISABLED)
322 *hittest = HTERROR;
323 break;
325 /* Send WM_NCCHITTEST (if same thread) */
326 if (!WIN_IsCurrentThread( list[i] ))
328 *hittest = HTCLIENT;
329 break;
331 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
332 if (res != HTTRANSPARENT)
334 *hittest = res; /* Found the window */
335 break;
337 /* continue search with next window in z-order */
339 ret = list[i];
340 HeapFree( GetProcessHeap(), 0, list );
341 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
342 return ret;
346 /*******************************************************************
347 * WindowFromPoint (USER32.@)
349 HWND WINAPI WindowFromPoint( POINT pt )
351 INT hittest;
352 return WINPOS_WindowFromPoint( 0, pt, &hittest );
356 /*******************************************************************
357 * ChildWindowFromPoint (USER32.@)
359 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
361 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
364 /*******************************************************************
365 * RealChildWindowFromPoint (USER32.@)
367 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
369 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
372 /*******************************************************************
373 * ChildWindowFromPointEx (USER32.@)
375 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
377 /* pt is in the client coordinates */
378 HWND *list;
379 int i;
380 RECT rect;
381 HWND retvalue;
383 GetClientRect( hwndParent, &rect );
384 if (!PtInRect( &rect, pt )) return 0;
385 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
387 for (i = 0; list[i]; i++)
389 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
390 if (!PtInRect( &rect, pt )) continue;
391 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
393 LONG style = GetWindowLongW( list[i], GWL_STYLE );
394 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
395 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
397 if (uFlags & CWP_SKIPTRANSPARENT)
399 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
401 break;
403 retvalue = list[i];
404 HeapFree( GetProcessHeap(), 0, list );
405 if (!retvalue) retvalue = hwndParent;
406 return retvalue;
410 /*******************************************************************
411 * WINPOS_GetWinOffset
413 * Calculate the offset between the origin of the two windows. Used
414 * to implement MapWindowPoints.
416 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
418 WND * wndPtr;
420 offset->x = offset->y = 0;
422 /* Translate source window origin to screen coords */
423 if (hwndFrom)
425 HWND hwnd = hwndFrom;
427 while (hwnd)
429 if (hwnd == hwndTo) return;
430 if (!(wndPtr = WIN_GetPtr( hwnd )))
432 ERR( "bad hwndFrom = %p\n", hwnd );
433 return;
435 if (wndPtr == WND_DESKTOP) break;
436 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
437 offset->x += wndPtr->rectClient.left;
438 offset->y += wndPtr->rectClient.top;
439 hwnd = wndPtr->parent;
440 WIN_ReleasePtr( wndPtr );
444 /* Translate origin to destination window coords */
445 if (hwndTo)
447 HWND hwnd = hwndTo;
449 while (hwnd)
451 if (!(wndPtr = WIN_GetPtr( hwnd )))
453 ERR( "bad hwndTo = %p\n", hwnd );
454 return;
456 if (wndPtr == WND_DESKTOP) break;
457 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
458 offset->x -= wndPtr->rectClient.left;
459 offset->y -= wndPtr->rectClient.top;
460 hwnd = wndPtr->parent;
461 WIN_ReleasePtr( wndPtr );
464 return;
466 other_process: /* one of the parents may belong to another process, do it the hard way */
467 offset->x = offset->y = 0;
468 SERVER_START_REQ( get_windows_offset )
470 req->from = hwndFrom;
471 req->to = hwndTo;
472 if (!wine_server_call( req ))
474 offset->x = reply->x;
475 offset->y = reply->y;
478 SERVER_END_REQ;
482 /*******************************************************************
483 * MapWindowPoints (USER.258)
485 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
486 LPPOINT16 lppt, UINT16 count )
488 POINT offset;
490 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
491 while (count--)
493 lppt->x += offset.x;
494 lppt->y += offset.y;
495 lppt++;
500 /*******************************************************************
501 * MapWindowPoints (USER32.@)
503 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
505 POINT offset;
507 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
508 while (count--)
510 lppt->x += offset.x;
511 lppt->y += offset.y;
512 lppt++;
514 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
518 /***********************************************************************
519 * IsIconic (USER32.@)
521 BOOL WINAPI IsIconic(HWND hWnd)
523 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
527 /***********************************************************************
528 * IsZoomed (USER32.@)
530 BOOL WINAPI IsZoomed(HWND hWnd)
532 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
536 /*******************************************************************
537 * AllowSetForegroundWindow (USER32.@)
539 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
541 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
542 * implemented, then fix this function. */
543 return TRUE;
547 /*******************************************************************
548 * LockSetForegroundWindow (USER32.@)
550 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
552 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
553 * implemented, then fix this function. */
554 return TRUE;
558 /***********************************************************************
559 * BringWindowToTop (USER32.@)
561 BOOL WINAPI BringWindowToTop( HWND hwnd )
563 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
567 /***********************************************************************
568 * MoveWindow (USER32.@)
570 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
571 BOOL repaint )
573 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
574 if (!repaint) flags |= SWP_NOREDRAW;
575 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
576 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
579 /***********************************************************************
580 * WINPOS_InitPlacement
582 static void WINPOS_InitPlacement( WND* wnd )
584 if (IsRectEmpty( &wnd->normal_rect ))
586 /* this happens when the window is minimized/maximized
587 * for the first time (rectWindow is not adjusted yet) */
589 wnd->normal_rect = wnd->rectWindow;
590 wnd->min_pos.x = wnd->min_pos.y = -1;
591 wnd->max_pos.x = wnd->max_pos.y = -1;
594 if( wnd->dwStyle & WS_MINIMIZE )
596 wnd->min_pos.x = wnd->rectWindow.left;
597 wnd->min_pos.y = wnd->rectWindow.top;
599 else if( wnd->dwStyle & WS_MAXIMIZE )
601 wnd->max_pos.x = wnd->rectWindow.left;
602 wnd->max_pos.y = wnd->rectWindow.top;
604 else
606 wnd->normal_rect = wnd->rectWindow;
610 /***********************************************************************
611 * WINPOS_RedrawIconTitle
613 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
615 HWND icon_title = 0;
616 WND *win = WIN_GetPtr( hWnd );
618 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
620 icon_title = win->icon_title;
621 WIN_ReleasePtr( win );
623 if (!icon_title) return FALSE;
624 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
625 InvalidateRect( icon_title, NULL, TRUE );
626 return TRUE;
629 /***********************************************************************
630 * WINPOS_ShowIconTitle
632 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
634 if (!GetPropA( hwnd, "__wine_x11_managed" ))
636 WND *win = WIN_GetPtr( hwnd );
637 HWND title = 0;
639 TRACE("%p %i\n", hwnd, (bShow != 0) );
641 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
642 title = win->icon_title;
643 WIN_ReleasePtr( win );
645 if( bShow )
647 if (!title)
649 title = ICONTITLE_Create( hwnd );
650 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
652 DestroyWindow( title );
653 return FALSE;
655 win->icon_title = title;
656 WIN_ReleasePtr( win );
658 if (!IsWindowVisible(title))
660 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
661 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
662 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
665 else if (title) ShowWindow( title, SW_HIDE );
667 return FALSE;
670 /*******************************************************************
671 * WINPOS_GetMinMaxInfo
673 * Get the minimized and maximized information for a window.
675 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
676 POINT *minTrack, POINT *maxTrack )
678 MINMAXINFO MinMax;
679 HMONITOR monitor;
680 INT xinc, yinc;
681 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
682 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
683 RECT rc;
684 WND *win;
686 /* Compute default values */
688 GetWindowRect(hwnd, &rc);
689 MinMax.ptReserved.x = rc.left;
690 MinMax.ptReserved.y = rc.top;
692 if (style & WS_CHILD)
694 if ((style & WS_CAPTION) == WS_CAPTION)
695 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
697 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
698 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
700 /* avoid calculating this twice */
701 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
703 MinMax.ptMaxSize.x = rc.right - rc.left;
704 MinMax.ptMaxSize.y = rc.bottom - rc.top;
706 else
708 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
709 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
711 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
712 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
713 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
714 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
716 if (HAS_DLGFRAME( style, exstyle ))
718 xinc = GetSystemMetrics(SM_CXDLGFRAME);
719 yinc = GetSystemMetrics(SM_CYDLGFRAME);
721 else
723 xinc = yinc = 0;
724 if (HAS_THICKFRAME(style))
726 xinc += GetSystemMetrics(SM_CXFRAME);
727 yinc += GetSystemMetrics(SM_CYFRAME);
729 if (style & WS_BORDER)
731 xinc += GetSystemMetrics(SM_CXBORDER);
732 yinc += GetSystemMetrics(SM_CYBORDER);
735 MinMax.ptMaxSize.x += 2 * xinc;
736 MinMax.ptMaxSize.y += 2 * yinc;
738 MinMax.ptMaxPosition.x = -xinc;
739 MinMax.ptMaxPosition.y = -yinc;
740 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
742 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
743 WIN_ReleasePtr( win );
746 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
748 /* if the app didn't change the values, adapt them for the current monitor */
750 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
752 MONITORINFO mon_info;
754 mon_info.cbSize = sizeof(mon_info);
755 GetMonitorInfoW( monitor, &mon_info );
757 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
758 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
760 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
761 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
763 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
765 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
766 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
770 /* Some sanity checks */
772 TRACE("%d %d / %d %d / %d %d / %d %d\n",
773 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
774 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
775 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
776 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
777 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
778 MinMax.ptMinTrackSize.x );
779 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
780 MinMax.ptMinTrackSize.y );
782 if (maxSize) *maxSize = MinMax.ptMaxSize;
783 if (maxPos) *maxPos = MinMax.ptMaxPosition;
784 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
785 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
789 /***********************************************************************
790 * WINPOS_FindIconPos
792 * Find a suitable place for an iconic window.
794 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
796 RECT rect, rectParent;
797 HWND parent, child;
798 HRGN hrgn, tmp;
799 int xspacing, yspacing;
801 parent = GetAncestor( hwnd, GA_PARENT );
802 GetClientRect( parent, &rectParent );
803 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
804 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
805 return pt; /* The icon already has a suitable position */
807 xspacing = GetSystemMetrics(SM_CXICONSPACING);
808 yspacing = GetSystemMetrics(SM_CYICONSPACING);
810 /* Check if another icon already occupies this spot */
811 /* FIXME: this is completely inefficient */
813 hrgn = CreateRectRgn( 0, 0, 0, 0 );
814 tmp = CreateRectRgn( 0, 0, 0, 0 );
815 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
817 WND *childPtr;
818 if (child == hwnd) continue;
819 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
820 continue;
821 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
822 continue;
823 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
824 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
825 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
826 WIN_ReleasePtr( childPtr );
828 DeleteObject( tmp );
830 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
832 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
834 rect.right = rect.left + xspacing;
835 rect.top = rect.bottom - yspacing;
836 if (!RectInRegion( hrgn, &rect ))
838 /* No window was found, so it's OK for us */
839 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
840 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
841 DeleteObject( hrgn );
842 return pt;
846 DeleteObject( hrgn );
847 pt.x = pt.y = 0;
848 return pt;
852 /***********************************************************************
853 * WINPOS_MinMaximize
855 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
857 WND *wndPtr;
858 UINT swpFlags = 0;
859 POINT size;
860 LONG old_style;
861 WINDOWPLACEMENT wpl;
863 TRACE("%p %u\n", hwnd, cmd );
865 wpl.length = sizeof(wpl);
866 GetWindowPlacement( hwnd, &wpl );
868 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
869 return SWP_NOSIZE | SWP_NOMOVE;
871 if (IsIconic( hwnd ))
873 switch (cmd)
875 case SW_SHOWMINNOACTIVE:
876 case SW_SHOWMINIMIZED:
877 case SW_FORCEMINIMIZE:
878 case SW_MINIMIZE:
879 return SWP_NOSIZE | SWP_NOMOVE;
881 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
882 swpFlags |= SWP_NOCOPYBITS;
885 switch( cmd )
887 case SW_SHOWMINNOACTIVE:
888 case SW_SHOWMINIMIZED:
889 case SW_FORCEMINIMIZE:
890 case SW_MINIMIZE:
891 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
892 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
893 else wndPtr->flags &= ~WIN_RESTORE_MAX;
894 WIN_ReleasePtr( wndPtr );
896 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
898 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
900 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
901 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
902 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
903 swpFlags |= SWP_NOCOPYBITS;
904 break;
906 case SW_MAXIMIZE:
907 old_style = GetWindowLongW( hwnd, GWL_STYLE );
908 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
910 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
912 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
913 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
915 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
916 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
917 break;
919 case SW_SHOWNOACTIVATE:
920 case SW_SHOWNORMAL:
921 case SW_RESTORE:
922 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
923 if (old_style & WS_MINIMIZE)
925 BOOL restore_max;
927 WINPOS_ShowIconTitle( hwnd, FALSE );
929 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
930 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
931 WIN_ReleasePtr( wndPtr );
932 if (restore_max)
934 /* Restore to maximized position */
935 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
936 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
937 swpFlags |= SWP_STATECHANGED;
938 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
939 break;
942 else if (!(old_style & WS_MAXIMIZE)) break;
944 swpFlags |= SWP_STATECHANGED;
946 /* Restore to normal position */
948 *rect = wpl.rcNormalPosition;
949 rect->right -= rect->left;
950 rect->bottom -= rect->top;
952 break;
955 return swpFlags;
959 /***********************************************************************
960 * show_window
962 * Implementation of ShowWindow and ShowWindowAsync.
964 static BOOL show_window( HWND hwnd, INT cmd )
966 WND *wndPtr;
967 HWND parent;
968 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
969 BOOL wasVisible = (style & WS_VISIBLE) != 0;
970 BOOL showFlag = TRUE;
971 RECT newPos = {0, 0, 0, 0};
972 UINT swp = 0;
974 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
976 switch(cmd)
978 case SW_HIDE:
979 if (!wasVisible) return FALSE;
980 showFlag = FALSE;
981 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
982 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
983 break;
985 case SW_SHOWMINNOACTIVE:
986 case SW_MINIMIZE:
987 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
988 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
989 /* fall through */
990 case SW_SHOWMINIMIZED:
991 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
992 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
993 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
994 break;
996 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
997 if (!wasVisible) swp |= SWP_SHOWWINDOW;
998 swp |= SWP_FRAMECHANGED;
999 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1000 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
1001 break;
1003 case SW_SHOWNA:
1004 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1005 if (style & WS_CHILD) swp |= SWP_NOZORDER;
1006 break;
1007 case SW_SHOW:
1008 if (wasVisible) return TRUE;
1009 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1010 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1011 break;
1013 case SW_SHOWNOACTIVATE:
1014 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1015 /* fall through */
1016 case SW_RESTORE:
1017 /* fall through */
1018 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1019 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1020 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1021 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1023 swp |= SWP_FRAMECHANGED;
1024 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1026 else
1028 if (wasVisible) return TRUE;
1029 swp |= SWP_NOSIZE | SWP_NOMOVE;
1031 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1032 break;
1033 default:
1034 return wasVisible;
1037 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1039 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1040 if (!IsWindow( hwnd )) return wasVisible;
1043 parent = GetAncestor( hwnd, GA_PARENT );
1044 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1046 /* if parent is not visible simply toggle WS_VISIBLE and return */
1047 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1048 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1050 else
1051 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1052 newPos.right, newPos.bottom, LOWORD(swp) );
1054 if (cmd == SW_HIDE)
1056 HWND hFocus;
1058 WINPOS_ShowIconTitle( hwnd, FALSE );
1060 /* FIXME: This will cause the window to be activated irrespective
1061 * of whether it is owned by the same thread. Has to be done
1062 * asynchronously.
1065 if (hwnd == GetActiveWindow())
1066 WINPOS_ActivateOtherWindow(hwnd);
1068 /* Revert focus to parent */
1069 hFocus = GetFocus();
1070 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1072 HWND parent = GetAncestor(hwnd, GA_PARENT);
1073 if (parent == GetDesktopWindow()) parent = 0;
1074 SetFocus(parent);
1076 return wasVisible;
1079 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1081 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1083 if (wndPtr->flags & WIN_NEED_SIZE)
1085 /* should happen only in CreateWindowEx() */
1086 int wParam = SIZE_RESTORED;
1087 RECT client = wndPtr->rectClient;
1089 wndPtr->flags &= ~WIN_NEED_SIZE;
1090 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1091 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1092 WIN_ReleasePtr( wndPtr );
1094 SendMessageW( hwnd, WM_SIZE, wParam,
1095 MAKELONG( client.right - client.left, client.bottom - client.top ));
1096 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1098 else WIN_ReleasePtr( wndPtr );
1100 /* if previous state was minimized Windows sets focus to the window */
1101 if (style & WS_MINIMIZE) SetFocus( hwnd );
1103 return wasVisible;
1107 /***********************************************************************
1108 * ShowWindowAsync (USER32.@)
1110 * doesn't wait; returns immediately.
1111 * used by threads to toggle windows in other (possibly hanging) threads
1113 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1115 HWND full_handle;
1117 if (is_broadcast(hwnd))
1119 SetLastError( ERROR_INVALID_PARAMETER );
1120 return FALSE;
1123 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1124 return show_window( full_handle, cmd );
1126 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1130 /***********************************************************************
1131 * ShowWindow (USER32.@)
1133 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1135 HWND full_handle;
1137 if (is_broadcast(hwnd))
1139 SetLastError( ERROR_INVALID_PARAMETER );
1140 return FALSE;
1142 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1143 return show_window( full_handle, cmd );
1145 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1149 /***********************************************************************
1150 * GetInternalWindowPos (USER32.@)
1152 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1153 LPPOINT ptIcon )
1155 WINDOWPLACEMENT wndpl;
1156 if (GetWindowPlacement( hwnd, &wndpl ))
1158 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1159 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1160 return wndpl.showCmd;
1162 return 0;
1166 /***********************************************************************
1167 * GetWindowPlacement (USER32.@)
1169 * Win95:
1170 * Fails if wndpl->length of Win95 (!) apps is invalid.
1172 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1174 WND *pWnd = WIN_GetPtr( hwnd );
1176 if (!pWnd) return FALSE;
1178 if (pWnd == WND_DESKTOP)
1180 wndpl->length = sizeof(*wndpl);
1181 wndpl->showCmd = SW_SHOWNORMAL;
1182 wndpl->flags = 0;
1183 wndpl->ptMinPosition.x = -1;
1184 wndpl->ptMinPosition.y = -1;
1185 wndpl->ptMaxPosition.x = -1;
1186 wndpl->ptMaxPosition.y = -1;
1187 GetWindowRect( hwnd, &wndpl->rcNormalPosition );
1188 return TRUE;
1190 if (pWnd == WND_OTHER_PROCESS)
1192 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1193 return FALSE;
1196 WINPOS_InitPlacement( pWnd );
1197 wndpl->length = sizeof(*wndpl);
1198 if( pWnd->dwStyle & WS_MINIMIZE )
1199 wndpl->showCmd = SW_SHOWMINIMIZED;
1200 else
1201 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1202 if( pWnd->flags & WIN_RESTORE_MAX )
1203 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1204 else
1205 wndpl->flags = 0;
1206 wndpl->ptMinPosition = pWnd->min_pos;
1207 wndpl->ptMaxPosition = pWnd->max_pos;
1208 wndpl->rcNormalPosition = pWnd->normal_rect;
1209 WIN_ReleasePtr( pWnd );
1211 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1212 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1213 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1214 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1215 return TRUE;
1218 /* make sure the specified rect is visible on screen */
1219 static void make_rect_onscreen( RECT *rect )
1221 MONITORINFO info;
1222 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1224 info.cbSize = sizeof(info);
1225 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1226 /* FIXME: map coordinates from rcWork to rcMonitor */
1227 if (rect->right <= info.rcWork.left)
1229 rect->right += info.rcWork.left - rect->left;
1230 rect->left = info.rcWork.left;
1232 else if (rect->left >= info.rcWork.right)
1234 rect->left += info.rcWork.right - rect->right;
1235 rect->right = info.rcWork.right;
1237 if (rect->bottom <= info.rcWork.top)
1239 rect->bottom += info.rcWork.top - rect->top;
1240 rect->top = info.rcWork.top;
1242 else if (rect->top >= info.rcWork.bottom)
1244 rect->top += info.rcWork.bottom - rect->bottom;
1245 rect->bottom = info.rcWork.bottom;
1249 /* make sure the specified point is visible on screen */
1250 static void make_point_onscreen( POINT *pt )
1252 RECT rect;
1254 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1255 make_rect_onscreen( &rect );
1256 pt->x = rect.left;
1257 pt->y = rect.top;
1261 /***********************************************************************
1262 * WINPOS_SetPlacement
1264 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1266 DWORD style;
1267 WND *pWnd = WIN_GetPtr( hwnd );
1268 WINDOWPLACEMENT wp = *wndpl;
1270 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1271 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1272 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1274 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1275 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1276 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1277 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1278 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1279 wine_dbgstr_rect(&wp.rcNormalPosition) );
1281 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1283 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1284 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1285 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1287 style = pWnd->dwStyle;
1289 WIN_ReleasePtr( pWnd );
1291 if( style & WS_MINIMIZE )
1293 if (flags & PLACE_MIN)
1295 WINPOS_ShowIconTitle( hwnd, FALSE );
1296 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1297 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1300 else if( style & WS_MAXIMIZE )
1302 if (flags & PLACE_MAX)
1303 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1304 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1306 else if( flags & PLACE_RECT )
1307 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1308 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1309 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1310 SWP_NOZORDER | SWP_NOACTIVATE );
1312 ShowWindow( hwnd, wndpl->showCmd );
1314 if (IsIconic( hwnd ))
1316 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1318 /* SDK: ...valid only the next time... */
1319 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1321 pWnd = WIN_GetPtr( hwnd );
1322 if (pWnd && pWnd != WND_OTHER_PROCESS)
1324 pWnd->flags |= WIN_RESTORE_MAX;
1325 WIN_ReleasePtr( pWnd );
1329 return TRUE;
1333 /***********************************************************************
1334 * SetWindowPlacement (USER32.@)
1336 * Win95:
1337 * Fails if wndpl->length of Win95 (!) apps is invalid.
1339 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1341 UINT flags = PLACE_MAX | PLACE_RECT;
1342 if (!wpl) return FALSE;
1343 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1344 return WINPOS_SetPlacement( hwnd, wpl, flags );
1348 /***********************************************************************
1349 * AnimateWindow (USER32.@)
1350 * Shows/Hides a window with an animation
1351 * NO ANIMATION YET
1353 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1355 FIXME("partial stub\n");
1357 /* If trying to show/hide and it's already *
1358 * shown/hidden or invalid window, fail with *
1359 * invalid parameter */
1360 if(!IsWindow(hwnd) ||
1361 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1362 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1364 SetLastError(ERROR_INVALID_PARAMETER);
1365 return FALSE;
1368 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1370 return TRUE;
1373 /***********************************************************************
1374 * SetInternalWindowPos (USER32.@)
1376 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1377 LPRECT rect, LPPOINT pt )
1379 WINDOWPLACEMENT wndpl;
1380 UINT flags;
1382 wndpl.length = sizeof(wndpl);
1383 wndpl.showCmd = showCmd;
1384 wndpl.flags = flags = 0;
1386 if( pt )
1388 flags |= PLACE_MIN;
1389 wndpl.flags |= WPF_SETMINPOSITION;
1390 wndpl.ptMinPosition = *pt;
1392 if( rect )
1394 flags |= PLACE_RECT;
1395 wndpl.rcNormalPosition = *rect;
1397 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1401 /*******************************************************************
1402 * can_activate_window
1404 * Check if we can activate the specified window.
1406 static BOOL can_activate_window( HWND hwnd )
1408 LONG style;
1410 if (!hwnd) return FALSE;
1411 style = GetWindowLongW( hwnd, GWL_STYLE );
1412 if (!(style & WS_VISIBLE)) return FALSE;
1413 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1414 return !(style & WS_DISABLED);
1418 /*******************************************************************
1419 * WINPOS_ActivateOtherWindow
1421 * Activates window other than pWnd.
1423 void WINPOS_ActivateOtherWindow(HWND hwnd)
1425 HWND hwndTo, fg;
1427 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1429 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1430 if (can_activate_window( hwndTo )) goto done;
1433 hwndTo = hwnd;
1434 for (;;)
1436 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1437 if (can_activate_window( hwndTo )) break;
1440 done:
1441 fg = GetForegroundWindow();
1442 TRACE("win = %p fg = %p\n", hwndTo, fg);
1443 if (!fg || (hwnd == fg))
1445 if (SetForegroundWindow( hwndTo )) return;
1447 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1451 /***********************************************************************
1452 * WINPOS_HandleWindowPosChanging
1454 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1456 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1458 POINT minTrack, maxTrack;
1459 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1461 if (winpos->flags & SWP_NOSIZE) return 0;
1462 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1464 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1465 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1466 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1467 if (!(style & WS_MINIMIZE))
1469 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1470 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1473 return 0;
1477 /***********************************************************************
1478 * dump_winpos_flags
1480 static void dump_winpos_flags(UINT flags)
1482 static const DWORD dumped_flags = (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW |
1483 SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW |
1484 SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOOWNERZORDER |
1485 SWP_NOSENDCHANGING | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS |
1486 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_STATECHANGED);
1487 TRACE("flags:");
1488 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1489 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1490 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1491 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1492 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1493 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1494 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1495 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1496 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1497 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1498 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1499 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1500 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1501 if(flags & SWP_NOCLIENTSIZE) TRACE(" SWP_NOCLIENTSIZE");
1502 if(flags & SWP_NOCLIENTMOVE) TRACE(" SWP_NOCLIENTMOVE");
1503 if(flags & SWP_STATECHANGED) TRACE(" SWP_STATECHANGED");
1505 if(flags & ~dumped_flags) TRACE(" %08x", flags & ~dumped_flags);
1506 TRACE("\n");
1509 /***********************************************************************
1510 * SWP_DoWinPosChanging
1512 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1514 WND *wndPtr;
1516 /* Send WM_WINDOWPOSCHANGING message */
1518 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1519 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1521 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1522 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1524 /* Calculate new position and size */
1526 *pNewWindowRect = wndPtr->rectWindow;
1527 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1528 : wndPtr->rectClient;
1530 if (!(pWinpos->flags & SWP_NOSIZE))
1532 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1533 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1535 if (!(pWinpos->flags & SWP_NOMOVE))
1537 pNewWindowRect->left = pWinpos->x;
1538 pNewWindowRect->top = pWinpos->y;
1539 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1540 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1542 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1543 pWinpos->y - wndPtr->rectWindow.top );
1545 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1547 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1548 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1549 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1550 TRACE( "current %s style %08x new %s\n",
1551 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1552 wine_dbgstr_rect( pNewWindowRect ));
1554 WIN_ReleasePtr( wndPtr );
1555 return TRUE;
1558 /***********************************************************************
1559 * get_valid_rects
1561 * Compute the valid rects from the old and new client rect and WVR_* flags.
1562 * Helper for WM_NCCALCSIZE handling.
1564 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1565 RECT *valid )
1567 int cx, cy;
1569 if (flags & WVR_REDRAW)
1571 SetRectEmpty( &valid[0] );
1572 SetRectEmpty( &valid[1] );
1573 return;
1576 if (flags & WVR_VALIDRECTS)
1578 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1579 !IntersectRect( &valid[1], &valid[1], old_client ))
1581 SetRectEmpty( &valid[0] );
1582 SetRectEmpty( &valid[1] );
1583 return;
1585 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1587 else
1589 valid[0] = *new_client;
1590 valid[1] = *old_client;
1593 /* make sure the rectangles have the same size */
1594 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1595 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1597 if (flags & WVR_ALIGNBOTTOM)
1599 valid[0].top = valid[0].bottom - cy;
1600 valid[1].top = valid[1].bottom - cy;
1602 else
1604 valid[0].bottom = valid[0].top + cy;
1605 valid[1].bottom = valid[1].top + cy;
1607 if (flags & WVR_ALIGNRIGHT)
1609 valid[0].left = valid[0].right - cx;
1610 valid[1].left = valid[1].right - cx;
1612 else
1614 valid[0].right = valid[0].left + cx;
1615 valid[1].right = valid[1].left + cx;
1620 /***********************************************************************
1621 * SWP_DoOwnedPopups
1623 * fix Z order taking into account owned popups -
1624 * basically we need to maintain them above the window that owns them
1626 * FIXME: hide/show owned popups when owner visibility changes.
1628 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1630 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1631 HWND owner, *list = NULL;
1632 unsigned int i;
1634 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1636 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1638 /* make sure this popup stays above the owner */
1640 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1642 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1644 for (i = 0; list[i]; i++)
1646 if (list[i] == owner)
1648 if (i > 0) hwndInsertAfter = list[i-1];
1649 else hwndInsertAfter = HWND_TOP;
1650 break;
1653 if (hwndInsertAfter == HWND_NOTOPMOST)
1655 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1657 else if (list[i] == hwndInsertAfter) break;
1661 else if (style & WS_CHILD) return hwndInsertAfter;
1663 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1664 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1666 i = 0;
1667 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1669 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1671 /* skip all the topmost windows */
1672 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1675 else if (hwndInsertAfter != HWND_TOPMOST)
1677 /* skip windows that are already placed correctly */
1678 for (i = 0; list[i]; i++)
1680 if (list[i] == hwndInsertAfter) break;
1681 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1685 for ( ; list[i]; i++)
1687 if (list[i] == hwnd) break;
1688 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1689 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1690 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1691 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1692 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1693 hwndInsertAfter = list[i];
1696 done:
1697 HeapFree( GetProcessHeap(), 0, list );
1698 return hwndInsertAfter;
1701 /***********************************************************************
1702 * SWP_DoNCCalcSize
1704 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1705 RECT *validRects )
1707 UINT wvrFlags = 0;
1708 WND *wndPtr;
1710 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1712 /* Send WM_NCCALCSIZE message to get new client area */
1713 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1715 NCCALCSIZE_PARAMS params;
1716 WINDOWPOS winposCopy;
1718 params.rgrc[0] = *pNewWindowRect;
1719 params.rgrc[1] = wndPtr->rectWindow;
1720 params.rgrc[2] = wndPtr->rectClient;
1721 params.lppos = &winposCopy;
1722 winposCopy = *pWinpos;
1723 WIN_ReleasePtr( wndPtr );
1725 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1727 *pNewClientRect = params.rgrc[0];
1729 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1731 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1732 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1733 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1735 if( pNewClientRect->left != wndPtr->rectClient.left ||
1736 pNewClientRect->top != wndPtr->rectClient.top )
1737 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1739 if( (pNewClientRect->right - pNewClientRect->left !=
1740 wndPtr->rectClient.right - wndPtr->rectClient.left))
1741 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1742 else
1743 wvrFlags &= ~WVR_HREDRAW;
1745 if (pNewClientRect->bottom - pNewClientRect->top !=
1746 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1747 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1748 else
1749 wvrFlags &= ~WVR_VREDRAW;
1751 validRects[0] = params.rgrc[1];
1752 validRects[1] = params.rgrc[2];
1754 else
1756 if (!(pWinpos->flags & SWP_NOMOVE) &&
1757 (pNewClientRect->left != wndPtr->rectClient.left ||
1758 pNewClientRect->top != wndPtr->rectClient.top))
1759 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1762 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1764 SetRectEmpty( &validRects[0] );
1765 SetRectEmpty( &validRects[1] );
1767 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1769 WIN_ReleasePtr( wndPtr );
1770 return wvrFlags;
1773 /* fix redundant flags and values in the WINDOWPOS structure */
1774 static BOOL fixup_flags( WINDOWPOS *winpos )
1776 HWND parent;
1777 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1778 BOOL ret = TRUE;
1780 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1782 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1783 return FALSE;
1785 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1787 /* Finally make sure that all coordinates are valid */
1788 if (winpos->x < -32768) winpos->x = -32768;
1789 else if (winpos->x > 32767) winpos->x = 32767;
1790 if (winpos->y < -32768) winpos->y = -32768;
1791 else if (winpos->y > 32767) winpos->y = 32767;
1793 if (winpos->cx < 0) winpos->cx = 0;
1794 else if (winpos->cx > 32767) winpos->cx = 32767;
1795 if (winpos->cy < 0) winpos->cy = 0;
1796 else if (winpos->cy > 32767) winpos->cy = 32767;
1798 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1799 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1801 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1802 else
1804 winpos->flags &= ~SWP_HIDEWINDOW;
1805 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1808 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1809 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1810 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1812 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1813 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1815 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1817 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1818 (winpos->flags & SWP_NOZORDER ||
1819 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1821 winpos->flags &= ~SWP_NOZORDER;
1822 winpos->hwndInsertAfter = HWND_TOP;
1826 /* Check hwndInsertAfter */
1827 if (winpos->flags & SWP_NOZORDER) goto done;
1829 /* fix sign extension */
1830 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1831 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1833 /* hwndInsertAfter must be a sibling of the window */
1834 if (winpos->hwndInsertAfter == HWND_TOP)
1836 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1837 winpos->flags |= SWP_NOZORDER;
1839 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1841 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1842 winpos->flags |= SWP_NOZORDER;
1844 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1846 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1847 winpos->flags |= SWP_NOZORDER;
1849 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1851 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1852 winpos->flags |= SWP_NOZORDER;
1854 else
1856 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1857 else
1859 /* don't need to change the Zorder of hwnd if it's already inserted
1860 * after hwndInsertAfter or when inserting hwnd after itself.
1862 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1863 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1864 winpos->flags |= SWP_NOZORDER;
1867 done:
1868 WIN_ReleasePtr( wndPtr );
1869 return ret;
1873 /***********************************************************************
1874 * set_window_pos
1876 * Backend implementation of SetWindowPos.
1878 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1879 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1881 WND *win;
1882 BOOL ret;
1883 RECT visible_rect, old_window_rect;
1885 visible_rect = *window_rect;
1886 USER_Driver->pWindowPosChanging( hwnd, insert_after, swp_flags,
1887 window_rect, client_rect, &visible_rect );
1889 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
1890 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
1892 old_window_rect = win->rectWindow;
1893 SERVER_START_REQ( set_window_pos )
1895 req->handle = hwnd;
1896 req->previous = insert_after;
1897 req->flags = swp_flags;
1898 req->window.left = window_rect->left;
1899 req->window.top = window_rect->top;
1900 req->window.right = window_rect->right;
1901 req->window.bottom = window_rect->bottom;
1902 req->client.left = client_rect->left;
1903 req->client.top = client_rect->top;
1904 req->client.right = client_rect->right;
1905 req->client.bottom = client_rect->bottom;
1906 if (memcmp( window_rect, &visible_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
1908 wine_server_add_data( req, &visible_rect, sizeof(visible_rect) );
1909 if (!IsRectEmpty( &valid_rects[0] ))
1910 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1912 if ((ret = !wine_server_call( req )))
1914 win->dwStyle = reply->new_style;
1915 win->dwExStyle = reply->new_ex_style;
1916 win->rectWindow = *window_rect;
1917 win->rectClient = *client_rect;
1920 SERVER_END_REQ;
1921 WIN_ReleasePtr( win );
1923 if (ret)
1925 if (((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) ||
1926 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW | SWP_STATECHANGED)))
1927 invalidate_dce( hwnd, &old_window_rect );
1929 USER_Driver->pWindowPosChanged( hwnd, insert_after, swp_flags, window_rect,
1930 client_rect, &visible_rect, valid_rects );
1932 return ret;
1936 /***********************************************************************
1937 * USER_SetWindowPos
1939 * User32 internal function
1941 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1943 RECT newWindowRect, newClientRect, valid_rects[2];
1944 UINT orig_flags;
1946 orig_flags = winpos->flags;
1948 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1949 if (!(winpos->flags & SWP_NOMOVE))
1951 if (winpos->x < -32768) winpos->x = -32768;
1952 else if (winpos->x > 32767) winpos->x = 32767;
1953 if (winpos->y < -32768) winpos->y = -32768;
1954 else if (winpos->y > 32767) winpos->y = 32767;
1956 if (!(winpos->flags & SWP_NOSIZE))
1958 if (winpos->cx < 0) winpos->cx = 0;
1959 else if (winpos->cx > 32767) winpos->cx = 32767;
1960 if (winpos->cy < 0) winpos->cy = 0;
1961 else if (winpos->cy > 32767) winpos->cy = 32767;
1964 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1966 /* Fix redundant flags */
1967 if (!fixup_flags( winpos )) return FALSE;
1969 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1971 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1972 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1975 /* Common operations */
1977 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1979 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1980 &newWindowRect, &newClientRect, valid_rects ))
1981 return FALSE;
1983 /* erase parent when hiding or resizing child */
1984 if (!(orig_flags & SWP_DEFERERASE) &&
1985 ((orig_flags & SWP_HIDEWINDOW) ||
1986 (!(orig_flags & SWP_SHOWWINDOW) &&
1987 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1989 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1990 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1991 erase_now( parent, 0 );
1994 if( winpos->flags & SWP_HIDEWINDOW )
1995 HideCaret(winpos->hwnd);
1996 else if (winpos->flags & SWP_SHOWWINDOW)
1997 ShowCaret(winpos->hwnd);
1999 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
2001 /* child windows get WM_CHILDACTIVATE message */
2002 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
2003 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
2004 else
2005 SetForegroundWindow( winpos->hwnd );
2008 /* And last, send the WM_WINDOWPOSCHANGED message */
2010 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2012 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2014 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2015 and always contains final window position.
2017 winpos->x = newWindowRect.left;
2018 winpos->y = newWindowRect.top;
2019 winpos->cx = newWindowRect.right - newWindowRect.left;
2020 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2021 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2023 return TRUE;
2026 /***********************************************************************
2027 * SetWindowPos (USER32.@)
2029 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2030 INT x, INT y, INT cx, INT cy, UINT flags )
2032 WINDOWPOS winpos;
2034 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2035 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2036 if(TRACE_ON(win)) dump_winpos_flags(flags);
2038 if (is_broadcast(hwnd))
2040 SetLastError( ERROR_INVALID_PARAMETER );
2041 return FALSE;
2044 winpos.hwnd = WIN_GetFullHandle(hwnd);
2045 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2046 winpos.x = x;
2047 winpos.y = y;
2048 winpos.cx = cx;
2049 winpos.cy = cy;
2050 winpos.flags = flags;
2052 if (WIN_IsCurrentThread( hwnd ))
2053 return USER_SetWindowPos(&winpos);
2055 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2059 /***********************************************************************
2060 * BeginDeferWindowPos (USER32.@)
2062 HDWP WINAPI BeginDeferWindowPos( INT count )
2064 HDWP handle;
2065 DWP *pDWP;
2067 TRACE("%d\n", count);
2069 if (count < 0)
2071 SetLastError(ERROR_INVALID_PARAMETER);
2072 return 0;
2074 /* Windows allows zero count, in which case it allocates context for 8 moves */
2075 if (count == 0) count = 8;
2077 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2078 if (!handle) return 0;
2079 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2080 pDWP->actualCount = 0;
2081 pDWP->suggestedCount = count;
2082 pDWP->valid = TRUE;
2083 pDWP->wMagic = DWP_MAGIC;
2084 pDWP->hwndParent = 0;
2086 TRACE("returning hdwp %p\n", handle);
2087 return handle;
2091 /***********************************************************************
2092 * DeferWindowPos (USER32.@)
2094 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2095 INT x, INT y, INT cx, INT cy,
2096 UINT flags )
2098 DWP *pDWP;
2099 int i;
2100 HDWP newhdwp = hdwp,retvalue;
2102 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2103 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2105 hwnd = WIN_GetFullHandle( hwnd );
2106 if (is_desktop_window( hwnd )) return 0;
2108 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2110 USER_Lock();
2112 for (i = 0; i < pDWP->actualCount; i++)
2114 if (pDWP->winPos[i].hwnd == hwnd)
2116 /* Merge with the other changes */
2117 if (!(flags & SWP_NOZORDER))
2119 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2121 if (!(flags & SWP_NOMOVE))
2123 pDWP->winPos[i].x = x;
2124 pDWP->winPos[i].y = y;
2126 if (!(flags & SWP_NOSIZE))
2128 pDWP->winPos[i].cx = cx;
2129 pDWP->winPos[i].cy = cy;
2131 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2132 SWP_NOZORDER | SWP_NOREDRAW |
2133 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2134 SWP_NOOWNERZORDER);
2135 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2136 SWP_FRAMECHANGED);
2137 retvalue = hdwp;
2138 goto END;
2141 if (pDWP->actualCount >= pDWP->suggestedCount)
2143 newhdwp = USER_HEAP_REALLOC( hdwp,
2144 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2145 if (!newhdwp)
2147 retvalue = 0;
2148 goto END;
2150 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2151 pDWP->suggestedCount++;
2153 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2154 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2155 pDWP->winPos[pDWP->actualCount].x = x;
2156 pDWP->winPos[pDWP->actualCount].y = y;
2157 pDWP->winPos[pDWP->actualCount].cx = cx;
2158 pDWP->winPos[pDWP->actualCount].cy = cy;
2159 pDWP->winPos[pDWP->actualCount].flags = flags;
2160 pDWP->actualCount++;
2161 retvalue = newhdwp;
2162 END:
2163 USER_Unlock();
2164 return retvalue;
2168 /***********************************************************************
2169 * EndDeferWindowPos (USER32.@)
2171 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2173 DWP *pDWP;
2174 WINDOWPOS *winpos;
2175 BOOL res = TRUE;
2176 int i;
2178 TRACE("%p\n", hdwp);
2180 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2181 if (!pDWP) return FALSE;
2182 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2184 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2185 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2186 winpos->cx, winpos->cy, winpos->flags);
2188 if (!(res = USER_SetWindowPos( winpos ))) break;
2190 USER_HEAP_FREE( hdwp );
2191 return res;
2195 /***********************************************************************
2196 * ArrangeIconicWindows (USER32.@)
2198 UINT WINAPI ArrangeIconicWindows( HWND parent )
2200 RECT rectParent;
2201 HWND hwndChild;
2202 INT x, y, xspacing, yspacing;
2204 GetClientRect( parent, &rectParent );
2205 x = rectParent.left;
2206 y = rectParent.bottom;
2207 xspacing = GetSystemMetrics(SM_CXICONSPACING);
2208 yspacing = GetSystemMetrics(SM_CYICONSPACING);
2210 hwndChild = GetWindow( parent, GW_CHILD );
2211 while (hwndChild)
2213 if( IsIconic( hwndChild ) )
2215 WINPOS_ShowIconTitle( hwndChild, FALSE );
2217 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
2218 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
2219 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
2220 if( IsWindow(hwndChild) )
2221 WINPOS_ShowIconTitle(hwndChild , TRUE );
2223 if (x <= rectParent.right - xspacing) x += xspacing;
2224 else
2226 x = rectParent.left;
2227 y -= yspacing;
2230 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
2232 return yspacing;
2236 /***********************************************************************
2237 * draw_moving_frame
2239 * Draw the frame used when moving or resizing window.
2241 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
2243 if (thickframe)
2245 const int width = GetSystemMetrics(SM_CXFRAME);
2246 const int height = GetSystemMetrics(SM_CYFRAME);
2248 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
2249 PatBlt( hdc, rect->left, rect->top,
2250 rect->right - rect->left - width, height, PATINVERT );
2251 PatBlt( hdc, rect->left, rect->top + height, width,
2252 rect->bottom - rect->top - height, PATINVERT );
2253 PatBlt( hdc, rect->left + width, rect->bottom - 1,
2254 rect->right - rect->left - width, -height, PATINVERT );
2255 PatBlt( hdc, rect->right - 1, rect->top, -width,
2256 rect->bottom - rect->top - height, PATINVERT );
2257 SelectObject( hdc, hbrush );
2259 else DrawFocusRect( hdc, rect );
2263 /***********************************************************************
2264 * start_size_move
2266 * Initialization of a move or resize, when initiated from a menu choice.
2267 * Return hit test code for caption or sizing border.
2269 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
2271 LONG hittest = 0;
2272 POINT pt;
2273 MSG msg;
2274 RECT rectWindow;
2276 GetWindowRect( hwnd, &rectWindow );
2278 if ((wParam & 0xfff0) == SC_MOVE)
2280 /* Move pointer at the center of the caption */
2281 RECT rect = rectWindow;
2282 /* Note: to be exactly centered we should take the different types
2283 * of border into account, but it shouldn't make more than a few pixels
2284 * of difference so let's not bother with that */
2285 rect.top += GetSystemMetrics(SM_CYBORDER);
2286 if (style & WS_SYSMENU)
2287 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2288 if (style & WS_MINIMIZEBOX)
2289 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2290 if (style & WS_MAXIMIZEBOX)
2291 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2292 pt.x = (rect.right + rect.left) / 2;
2293 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2294 hittest = HTCAPTION;
2295 *capturePoint = pt;
2297 else /* SC_SIZE */
2299 SetCursor( LoadCursorW( 0, (LPWSTR)IDC_SIZEALL ) );
2300 pt.x = pt.y = 0;
2301 while(!hittest)
2303 if (!GetMessageW( &msg, 0, 0, 0 )) return 0;
2304 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2306 switch(msg.message)
2308 case WM_MOUSEMOVE:
2309 pt.x = min( max( msg.pt.x, rectWindow.left ), rectWindow.right - 1 );
2310 pt.y = min( max( msg.pt.y, rectWindow.top ), rectWindow.bottom - 1 );
2311 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
2312 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
2313 break;
2315 case WM_LBUTTONUP:
2316 return 0;
2318 case WM_KEYDOWN:
2319 switch(msg.wParam)
2321 case VK_UP:
2322 hittest = HTTOP;
2323 pt.x =(rectWindow.left+rectWindow.right)/2;
2324 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2325 break;
2326 case VK_DOWN:
2327 hittest = HTBOTTOM;
2328 pt.x =(rectWindow.left+rectWindow.right)/2;
2329 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2330 break;
2331 case VK_LEFT:
2332 hittest = HTLEFT;
2333 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2334 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2335 break;
2336 case VK_RIGHT:
2337 hittest = HTRIGHT;
2338 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2339 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2340 break;
2341 case VK_RETURN:
2342 case VK_ESCAPE:
2343 return 0;
2345 break;
2346 default:
2347 TranslateMessage( &msg );
2348 DispatchMessageW( &msg );
2349 break;
2352 *capturePoint = pt;
2354 SetCursorPos( pt.x, pt.y );
2355 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
2356 return hittest;
2360 /***********************************************************************
2361 * WINPOS_SysCommandSizeMove
2363 * Perform SC_MOVE and SC_SIZE commands.
2365 void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
2367 MSG msg;
2368 RECT sizingRect, mouseRect, origRect;
2369 HDC hdc;
2370 HWND parent;
2371 LONG hittest = (LONG)(wParam & 0x0f);
2372 WPARAM syscommand = wParam & 0xfff0;
2373 HCURSOR hDragCursor = 0, hOldCursor = 0;
2374 POINT minTrack, maxTrack;
2375 POINT capturePoint, pt;
2376 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2377 BOOL thickframe = HAS_THICKFRAME( style );
2378 BOOL iconic = style & WS_MINIMIZE;
2379 BOOL moved = FALSE;
2380 DWORD dwPoint = GetMessagePos ();
2381 BOOL DragFullWindows = TRUE;
2383 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
2385 pt.x = (short)LOWORD(dwPoint);
2386 pt.y = (short)HIWORD(dwPoint);
2387 capturePoint = pt;
2389 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2390 hwnd, syscommand, hittest, pt.x, pt.y);
2392 if (syscommand == SC_MOVE)
2394 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2395 if (!hittest) return;
2397 else /* SC_SIZE */
2399 if ( hittest && (syscommand != SC_MOUSEMENU) )
2400 hittest += (HTLEFT - WMSZ_LEFT);
2401 else
2403 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2404 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2405 if (!hittest)
2407 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2408 return;
2413 /* Get min/max info */
2415 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
2416 GetWindowRect( hwnd, &sizingRect );
2417 if (style & WS_CHILD)
2419 parent = GetParent(hwnd);
2420 /* make sizing rect relative to parent */
2421 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
2422 GetClientRect( parent, &mouseRect );
2424 else
2426 parent = 0;
2427 GetClientRect( GetDesktopWindow(), &mouseRect );
2428 mouseRect.left = GetSystemMetrics( SM_XVIRTUALSCREEN );
2429 mouseRect.top = GetSystemMetrics( SM_YVIRTUALSCREEN );
2430 mouseRect.right = mouseRect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
2431 mouseRect.bottom = mouseRect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
2433 origRect = sizingRect;
2435 if (ON_LEFT_BORDER(hittest))
2437 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2438 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2440 else if (ON_RIGHT_BORDER(hittest))
2442 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2443 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2445 if (ON_TOP_BORDER(hittest))
2447 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2448 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2450 else if (ON_BOTTOM_BORDER(hittest))
2452 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2453 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2455 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2457 /* Retrieve a default cache DC (without using the window style) */
2458 hdc = GetDCEx( parent, 0, DCX_CACHE );
2460 if( iconic ) /* create a cursor for dragging */
2462 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
2463 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
2464 if( !hDragCursor ) iconic = FALSE;
2467 /* we only allow disabling the full window drag for child windows */
2468 if (parent) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0 );
2470 /* repaint the window before moving it around */
2471 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2473 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2474 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2476 while(1)
2478 int dx = 0, dy = 0;
2480 if (!GetMessageW( &msg, 0, 0, 0 )) break;
2481 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2483 /* Exit on button-up, Return, or Esc */
2484 if ((msg.message == WM_LBUTTONUP) ||
2485 ((msg.message == WM_KEYDOWN) &&
2486 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2488 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2490 TranslateMessage( &msg );
2491 DispatchMessageW( &msg );
2492 continue; /* We are not interested in other messages */
2495 pt = msg.pt;
2497 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2499 case VK_UP: pt.y -= 8; break;
2500 case VK_DOWN: pt.y += 8; break;
2501 case VK_LEFT: pt.x -= 8; break;
2502 case VK_RIGHT: pt.x += 8; break;
2505 pt.x = max( pt.x, mouseRect.left );
2506 pt.x = min( pt.x, mouseRect.right );
2507 pt.y = max( pt.y, mouseRect.top );
2508 pt.y = min( pt.y, mouseRect.bottom );
2510 dx = pt.x - capturePoint.x;
2511 dy = pt.y - capturePoint.y;
2513 if (dx || dy)
2515 if( !moved )
2517 moved = TRUE;
2519 if( iconic ) /* ok, no system popup tracking */
2521 hOldCursor = SetCursor(hDragCursor);
2522 ShowCursor( TRUE );
2523 WINPOS_ShowIconTitle( hwnd, FALSE );
2525 else if(!DragFullWindows)
2526 draw_moving_frame( hdc, &sizingRect, thickframe );
2529 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2530 else
2532 RECT newRect = sizingRect;
2533 WPARAM wpSizingHit = 0;
2535 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2536 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2537 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2538 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2539 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2540 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2541 capturePoint = pt;
2543 /* determine the hit location */
2544 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2545 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2546 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2548 if (!iconic)
2550 if(!DragFullWindows)
2551 draw_moving_frame( hdc, &newRect, thickframe );
2552 else
2553 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2554 newRect.right - newRect.left,
2555 newRect.bottom - newRect.top,
2556 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2558 sizingRect = newRect;
2563 if( iconic )
2565 if( moved ) /* restore cursors, show icon title later on */
2567 ShowCursor( FALSE );
2568 SetCursor( hOldCursor );
2571 else if (moved && !DragFullWindows)
2573 draw_moving_frame( hdc, &sizingRect, thickframe );
2576 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2577 ReleaseDC( parent, hdc );
2579 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2580 moved = FALSE;
2582 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2583 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2585 /* window moved or resized */
2586 if (moved)
2588 /* if the moving/resizing isn't canceled call SetWindowPos
2589 * with the new position or the new size of the window
2591 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2593 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2594 if(!DragFullWindows || iconic)
2595 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2596 sizingRect.right - sizingRect.left,
2597 sizingRect.bottom - sizingRect.top,
2598 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2600 else
2601 { /* restore previous size/position */
2602 if(DragFullWindows)
2603 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2604 origRect.right - origRect.left,
2605 origRect.bottom - origRect.top,
2606 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2610 if (IsIconic(hwnd))
2612 /* Single click brings up the system menu when iconized */
2614 if( !moved )
2616 if(style & WS_SYSMENU )
2617 SendMessageW( hwnd, WM_SYSCOMMAND,
2618 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2620 else WINPOS_ShowIconTitle( hwnd, TRUE );