user32/tests: Fix some input test failures.
[wine/multimedia.git] / dlls / user32 / winpos.c
blobcbe844a8553a6ff1c4adeb6003fd4a7652c53f5f
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 if (wndPtr->parent)
439 offset->x += wndPtr->rectClient.left;
440 offset->y += wndPtr->rectClient.top;
442 hwnd = wndPtr->parent;
443 WIN_ReleasePtr( wndPtr );
447 /* Translate origin to destination window coords */
448 if (hwndTo)
450 HWND hwnd = hwndTo;
452 while (hwnd)
454 if (!(wndPtr = WIN_GetPtr( hwnd )))
456 ERR( "bad hwndTo = %p\n", hwnd );
457 return;
459 if (wndPtr == WND_DESKTOP) break;
460 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
461 if (wndPtr->parent)
463 offset->x -= wndPtr->rectClient.left;
464 offset->y -= wndPtr->rectClient.top;
466 hwnd = wndPtr->parent;
467 WIN_ReleasePtr( wndPtr );
470 return;
472 other_process: /* one of the parents may belong to another process, do it the hard way */
473 offset->x = offset->y = 0;
474 SERVER_START_REQ( get_windows_offset )
476 req->from = hwndFrom;
477 req->to = hwndTo;
478 if (!wine_server_call( req ))
480 offset->x = reply->x;
481 offset->y = reply->y;
484 SERVER_END_REQ;
488 /*******************************************************************
489 * MapWindowPoints (USER.258)
491 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
492 LPPOINT16 lppt, UINT16 count )
494 POINT offset;
496 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
497 while (count--)
499 lppt->x += offset.x;
500 lppt->y += offset.y;
501 lppt++;
506 /*******************************************************************
507 * MapWindowPoints (USER32.@)
509 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
511 POINT offset;
513 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
514 while (count--)
516 lppt->x += offset.x;
517 lppt->y += offset.y;
518 lppt++;
520 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
524 /***********************************************************************
525 * IsIconic (USER32.@)
527 BOOL WINAPI IsIconic(HWND hWnd)
529 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
533 /***********************************************************************
534 * IsZoomed (USER32.@)
536 BOOL WINAPI IsZoomed(HWND hWnd)
538 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
542 /*******************************************************************
543 * AllowSetForegroundWindow (USER32.@)
545 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
547 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
548 * implemented, then fix this function. */
549 return TRUE;
553 /*******************************************************************
554 * LockSetForegroundWindow (USER32.@)
556 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
558 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
559 * implemented, then fix this function. */
560 return TRUE;
564 /***********************************************************************
565 * BringWindowToTop (USER32.@)
567 BOOL WINAPI BringWindowToTop( HWND hwnd )
569 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
573 /***********************************************************************
574 * MoveWindow (USER32.@)
576 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
577 BOOL repaint )
579 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
580 if (!repaint) flags |= SWP_NOREDRAW;
581 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
582 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
586 /***********************************************************************
587 * WINPOS_RedrawIconTitle
589 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
591 HWND icon_title = 0;
592 WND *win = WIN_GetPtr( hWnd );
594 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
596 icon_title = win->icon_title;
597 WIN_ReleasePtr( win );
599 if (!icon_title) return FALSE;
600 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
601 InvalidateRect( icon_title, NULL, TRUE );
602 return TRUE;
605 /***********************************************************************
606 * WINPOS_ShowIconTitle
608 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
610 if (!GetPropA( hwnd, "__wine_x11_managed" ))
612 WND *win = WIN_GetPtr( hwnd );
613 HWND title = 0;
615 TRACE("%p %i\n", hwnd, (bShow != 0) );
617 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
618 title = win->icon_title;
619 WIN_ReleasePtr( win );
621 if( bShow )
623 if (!title)
625 title = ICONTITLE_Create( hwnd );
626 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
628 DestroyWindow( title );
629 return FALSE;
631 win->icon_title = title;
632 WIN_ReleasePtr( win );
634 if (!IsWindowVisible(title))
636 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
637 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
638 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
641 else if (title) ShowWindow( title, SW_HIDE );
643 return FALSE;
646 /*******************************************************************
647 * WINPOS_GetMinMaxInfo
649 * Get the minimized and maximized information for a window.
651 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
652 POINT *minTrack, POINT *maxTrack )
654 MINMAXINFO MinMax;
655 HMONITOR monitor;
656 INT xinc, yinc;
657 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
658 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
659 RECT rc;
660 WND *win;
662 /* Compute default values */
664 GetWindowRect(hwnd, &rc);
665 MinMax.ptReserved.x = rc.left;
666 MinMax.ptReserved.y = rc.top;
668 if (style & WS_CHILD)
670 if ((style & WS_CAPTION) == WS_CAPTION)
671 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
673 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
674 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
676 /* avoid calculating this twice */
677 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
679 MinMax.ptMaxSize.x = rc.right - rc.left;
680 MinMax.ptMaxSize.y = rc.bottom - rc.top;
682 else
684 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
685 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
687 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
688 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
689 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
690 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
692 if (HAS_DLGFRAME( style, exstyle ))
694 xinc = GetSystemMetrics(SM_CXDLGFRAME);
695 yinc = GetSystemMetrics(SM_CYDLGFRAME);
697 else
699 xinc = yinc = 0;
700 if (HAS_THICKFRAME(style))
702 xinc += GetSystemMetrics(SM_CXFRAME);
703 yinc += GetSystemMetrics(SM_CYFRAME);
705 if (style & WS_BORDER)
707 xinc += GetSystemMetrics(SM_CXBORDER);
708 yinc += GetSystemMetrics(SM_CYBORDER);
711 MinMax.ptMaxSize.x += 2 * xinc;
712 MinMax.ptMaxSize.y += 2 * yinc;
714 MinMax.ptMaxPosition.x = -xinc;
715 MinMax.ptMaxPosition.y = -yinc;
716 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
718 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
719 WIN_ReleasePtr( win );
722 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
724 /* if the app didn't change the values, adapt them for the current monitor */
726 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
728 MONITORINFO mon_info;
730 mon_info.cbSize = sizeof(mon_info);
731 GetMonitorInfoW( monitor, &mon_info );
733 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
734 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
736 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
737 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
739 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
741 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
742 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
746 /* Some sanity checks */
748 TRACE("%d %d / %d %d / %d %d / %d %d\n",
749 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
750 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
751 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
752 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
753 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
754 MinMax.ptMinTrackSize.x );
755 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
756 MinMax.ptMinTrackSize.y );
758 if (maxSize) *maxSize = MinMax.ptMaxSize;
759 if (maxPos) *maxPos = MinMax.ptMaxPosition;
760 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
761 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
765 /***********************************************************************
766 * WINPOS_FindIconPos
768 * Find a suitable place for an iconic window.
770 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
772 RECT rect, rectParent;
773 HWND parent, child;
774 HRGN hrgn, tmp;
775 int xspacing, yspacing;
777 parent = GetAncestor( hwnd, GA_PARENT );
778 GetClientRect( parent, &rectParent );
779 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
780 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
781 return pt; /* The icon already has a suitable position */
783 xspacing = GetSystemMetrics(SM_CXICONSPACING);
784 yspacing = GetSystemMetrics(SM_CYICONSPACING);
786 /* Check if another icon already occupies this spot */
787 /* FIXME: this is completely inefficient */
789 hrgn = CreateRectRgn( 0, 0, 0, 0 );
790 tmp = CreateRectRgn( 0, 0, 0, 0 );
791 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
793 WND *childPtr;
794 if (child == hwnd) continue;
795 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
796 continue;
797 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
798 continue;
799 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
800 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
801 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
802 WIN_ReleasePtr( childPtr );
804 DeleteObject( tmp );
806 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
808 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
810 rect.right = rect.left + xspacing;
811 rect.top = rect.bottom - yspacing;
812 if (!RectInRegion( hrgn, &rect ))
814 /* No window was found, so it's OK for us */
815 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
816 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
817 DeleteObject( hrgn );
818 return pt;
822 DeleteObject( hrgn );
823 pt.x = pt.y = 0;
824 return pt;
828 /***********************************************************************
829 * WINPOS_MinMaximize
831 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
833 WND *wndPtr;
834 UINT swpFlags = 0;
835 POINT size;
836 LONG old_style;
837 WINDOWPLACEMENT wpl;
839 TRACE("%p %u\n", hwnd, cmd );
841 wpl.length = sizeof(wpl);
842 GetWindowPlacement( hwnd, &wpl );
844 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
845 return SWP_NOSIZE | SWP_NOMOVE;
847 if (IsIconic( hwnd ))
849 switch (cmd)
851 case SW_SHOWMINNOACTIVE:
852 case SW_SHOWMINIMIZED:
853 case SW_FORCEMINIMIZE:
854 case SW_MINIMIZE:
855 return SWP_NOSIZE | SWP_NOMOVE;
857 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
858 swpFlags |= SWP_NOCOPYBITS;
861 switch( cmd )
863 case SW_SHOWMINNOACTIVE:
864 case SW_SHOWMINIMIZED:
865 case SW_FORCEMINIMIZE:
866 case SW_MINIMIZE:
867 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
868 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
869 else wndPtr->flags &= ~WIN_RESTORE_MAX;
870 WIN_ReleasePtr( wndPtr );
872 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
874 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
876 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
877 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
878 wpl.ptMinPosition.x + GetSystemMetrics(SM_CXICON),
879 wpl.ptMinPosition.y + GetSystemMetrics(SM_CYICON) );
880 swpFlags |= SWP_NOCOPYBITS;
881 break;
883 case SW_MAXIMIZE:
884 old_style = GetWindowLongW( hwnd, GWL_STYLE );
885 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
887 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
889 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
890 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
892 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
893 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
894 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
895 break;
897 case SW_SHOWNOACTIVATE:
898 case SW_SHOWNORMAL:
899 case SW_RESTORE:
900 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
901 if (old_style & WS_MINIMIZE)
903 BOOL restore_max;
905 WINPOS_ShowIconTitle( hwnd, FALSE );
907 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
908 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
909 WIN_ReleasePtr( wndPtr );
910 if (restore_max)
912 /* Restore to maximized position */
913 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
914 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
915 swpFlags |= SWP_STATECHANGED;
916 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
917 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
918 break;
921 else if (!(old_style & WS_MAXIMIZE)) break;
923 swpFlags |= SWP_STATECHANGED;
925 /* Restore to normal position */
927 *rect = wpl.rcNormalPosition;
928 break;
931 return swpFlags;
935 /***********************************************************************
936 * show_window
938 * Implementation of ShowWindow and ShowWindowAsync.
940 static BOOL show_window( HWND hwnd, INT cmd )
942 WND *wndPtr;
943 HWND parent;
944 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
945 BOOL wasVisible = (style & WS_VISIBLE) != 0;
946 BOOL showFlag = TRUE;
947 RECT newPos = {0, 0, 0, 0};
948 UINT swp = 0;
950 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
952 switch(cmd)
954 case SW_HIDE:
955 if (!wasVisible) return FALSE;
956 showFlag = FALSE;
957 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
958 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
959 break;
961 case SW_SHOWMINNOACTIVE:
962 case SW_MINIMIZE:
963 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
964 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
965 /* fall through */
966 case SW_SHOWMINIMIZED:
967 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
968 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
969 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
970 break;
972 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
973 if (!wasVisible) swp |= SWP_SHOWWINDOW;
974 swp |= SWP_FRAMECHANGED;
975 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
976 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
977 break;
979 case SW_SHOWNA:
980 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
981 if (style & WS_CHILD) swp |= SWP_NOZORDER;
982 break;
983 case SW_SHOW:
984 if (wasVisible) return TRUE;
985 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
986 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
987 break;
989 case SW_SHOWNOACTIVATE:
990 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
991 /* fall through */
992 case SW_RESTORE:
993 /* fall through */
994 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
995 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
996 if (!wasVisible) swp |= SWP_SHOWWINDOW;
997 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
999 swp |= SWP_FRAMECHANGED;
1000 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1002 else
1004 if (wasVisible) return TRUE;
1005 swp |= SWP_NOSIZE | SWP_NOMOVE;
1007 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1008 break;
1009 default:
1010 return wasVisible;
1013 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1015 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1016 if (!IsWindow( hwnd )) return wasVisible;
1019 swp = USER_Driver->pShowWindow( hwnd, cmd, &newPos, swp );
1021 parent = GetAncestor( hwnd, GA_PARENT );
1022 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1024 /* if parent is not visible simply toggle WS_VISIBLE and return */
1025 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1026 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1028 else
1029 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1030 newPos.right - newPos.left, newPos.bottom - newPos.top, swp );
1032 if (cmd == SW_HIDE)
1034 HWND hFocus;
1036 WINPOS_ShowIconTitle( hwnd, FALSE );
1038 /* FIXME: This will cause the window to be activated irrespective
1039 * of whether it is owned by the same thread. Has to be done
1040 * asynchronously.
1043 if (hwnd == GetActiveWindow())
1044 WINPOS_ActivateOtherWindow(hwnd);
1046 /* Revert focus to parent */
1047 hFocus = GetFocus();
1048 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1050 HWND parent = GetAncestor(hwnd, GA_PARENT);
1051 if (parent == GetDesktopWindow()) parent = 0;
1052 SetFocus(parent);
1054 return wasVisible;
1057 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1059 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1061 if (wndPtr->flags & WIN_NEED_SIZE)
1063 /* should happen only in CreateWindowEx() */
1064 int wParam = SIZE_RESTORED;
1065 RECT client = wndPtr->rectClient;
1067 wndPtr->flags &= ~WIN_NEED_SIZE;
1068 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1069 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1070 WIN_ReleasePtr( wndPtr );
1072 SendMessageW( hwnd, WM_SIZE, wParam,
1073 MAKELONG( client.right - client.left, client.bottom - client.top ));
1074 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1076 else WIN_ReleasePtr( wndPtr );
1078 /* if previous state was minimized Windows sets focus to the window */
1079 if (style & WS_MINIMIZE) SetFocus( hwnd );
1081 return wasVisible;
1085 /***********************************************************************
1086 * ShowWindowAsync (USER32.@)
1088 * doesn't wait; returns immediately.
1089 * used by threads to toggle windows in other (possibly hanging) threads
1091 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1093 HWND full_handle;
1095 if (is_broadcast(hwnd))
1097 SetLastError( ERROR_INVALID_PARAMETER );
1098 return FALSE;
1101 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1102 return show_window( full_handle, cmd );
1104 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1108 /***********************************************************************
1109 * ShowWindow (USER32.@)
1111 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1113 HWND full_handle;
1115 if (is_broadcast(hwnd))
1117 SetLastError( ERROR_INVALID_PARAMETER );
1118 return FALSE;
1120 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1121 return show_window( full_handle, cmd );
1123 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1127 /***********************************************************************
1128 * GetInternalWindowPos (USER32.@)
1130 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1131 LPPOINT ptIcon )
1133 WINDOWPLACEMENT wndpl;
1134 if (GetWindowPlacement( hwnd, &wndpl ))
1136 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1137 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1138 return wndpl.showCmd;
1140 return 0;
1144 /***********************************************************************
1145 * GetWindowPlacement (USER32.@)
1147 * Win95:
1148 * Fails if wndpl->length of Win95 (!) apps is invalid.
1150 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1152 WND *pWnd = WIN_GetPtr( hwnd );
1154 if (!pWnd) return FALSE;
1156 if (pWnd == WND_DESKTOP)
1158 wndpl->length = sizeof(*wndpl);
1159 wndpl->showCmd = SW_SHOWNORMAL;
1160 wndpl->flags = 0;
1161 wndpl->ptMinPosition.x = -1;
1162 wndpl->ptMinPosition.y = -1;
1163 wndpl->ptMaxPosition.x = -1;
1164 wndpl->ptMaxPosition.y = -1;
1165 GetWindowRect( hwnd, &wndpl->rcNormalPosition );
1166 return TRUE;
1168 if (pWnd == WND_OTHER_PROCESS)
1170 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1171 return FALSE;
1174 /* update the placement according to the current style */
1175 if (pWnd->dwStyle & WS_MINIMIZE)
1177 pWnd->min_pos.x = pWnd->rectWindow.left;
1178 pWnd->min_pos.y = pWnd->rectWindow.top;
1180 else if (pWnd->dwStyle & WS_MAXIMIZE)
1182 pWnd->max_pos.x = pWnd->rectWindow.left;
1183 pWnd->max_pos.y = pWnd->rectWindow.top;
1185 else
1187 pWnd->normal_rect = pWnd->rectWindow;
1190 wndpl->length = sizeof(*wndpl);
1191 if( pWnd->dwStyle & WS_MINIMIZE )
1192 wndpl->showCmd = SW_SHOWMINIMIZED;
1193 else
1194 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1195 if( pWnd->flags & WIN_RESTORE_MAX )
1196 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1197 else
1198 wndpl->flags = 0;
1199 wndpl->ptMinPosition = pWnd->min_pos;
1200 wndpl->ptMaxPosition = pWnd->max_pos;
1201 wndpl->rcNormalPosition = pWnd->normal_rect;
1202 WIN_ReleasePtr( pWnd );
1204 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1205 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1206 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1207 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1208 return TRUE;
1211 /* make sure the specified rect is visible on screen */
1212 static void make_rect_onscreen( RECT *rect )
1214 MONITORINFO info;
1215 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1217 info.cbSize = sizeof(info);
1218 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1219 /* FIXME: map coordinates from rcWork to rcMonitor */
1220 if (rect->right <= info.rcWork.left)
1222 rect->right += info.rcWork.left - rect->left;
1223 rect->left = info.rcWork.left;
1225 else if (rect->left >= info.rcWork.right)
1227 rect->left += info.rcWork.right - rect->right;
1228 rect->right = info.rcWork.right;
1230 if (rect->bottom <= info.rcWork.top)
1232 rect->bottom += info.rcWork.top - rect->top;
1233 rect->top = info.rcWork.top;
1235 else if (rect->top >= info.rcWork.bottom)
1237 rect->top += info.rcWork.bottom - rect->bottom;
1238 rect->bottom = info.rcWork.bottom;
1242 /* make sure the specified point is visible on screen */
1243 static void make_point_onscreen( POINT *pt )
1245 RECT rect;
1247 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1248 make_rect_onscreen( &rect );
1249 pt->x = rect.left;
1250 pt->y = rect.top;
1254 /***********************************************************************
1255 * WINPOS_SetPlacement
1257 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1259 DWORD style;
1260 WND *pWnd = WIN_GetPtr( hwnd );
1261 WINDOWPLACEMENT wp = *wndpl;
1263 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1264 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1265 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1267 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1268 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1269 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1270 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1271 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1272 wine_dbgstr_rect(&wp.rcNormalPosition) );
1274 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1276 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1277 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1278 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1280 style = pWnd->dwStyle;
1282 WIN_ReleasePtr( pWnd );
1284 if( style & WS_MINIMIZE )
1286 if (flags & PLACE_MIN)
1288 WINPOS_ShowIconTitle( hwnd, FALSE );
1289 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1290 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1293 else if( style & WS_MAXIMIZE )
1295 if (flags & PLACE_MAX)
1296 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1297 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1299 else if( flags & PLACE_RECT )
1300 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1301 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1302 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1303 SWP_NOZORDER | SWP_NOACTIVATE );
1305 ShowWindow( hwnd, wndpl->showCmd );
1307 if (IsIconic( hwnd ))
1309 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1311 /* SDK: ...valid only the next time... */
1312 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1314 pWnd = WIN_GetPtr( hwnd );
1315 if (pWnd && pWnd != WND_OTHER_PROCESS)
1317 pWnd->flags |= WIN_RESTORE_MAX;
1318 WIN_ReleasePtr( pWnd );
1322 return TRUE;
1326 /***********************************************************************
1327 * SetWindowPlacement (USER32.@)
1329 * Win95:
1330 * Fails if wndpl->length of Win95 (!) apps is invalid.
1332 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1334 UINT flags = PLACE_MAX | PLACE_RECT;
1335 if (!wpl) return FALSE;
1336 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1337 return WINPOS_SetPlacement( hwnd, wpl, flags );
1341 /***********************************************************************
1342 * AnimateWindow (USER32.@)
1343 * Shows/Hides a window with an animation
1344 * NO ANIMATION YET
1346 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1348 FIXME("partial stub\n");
1350 /* If trying to show/hide and it's already *
1351 * shown/hidden or invalid window, fail with *
1352 * invalid parameter */
1353 if(!IsWindow(hwnd) ||
1354 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1355 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1357 SetLastError(ERROR_INVALID_PARAMETER);
1358 return FALSE;
1361 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1363 return TRUE;
1366 /***********************************************************************
1367 * SetInternalWindowPos (USER32.@)
1369 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1370 LPRECT rect, LPPOINT pt )
1372 WINDOWPLACEMENT wndpl;
1373 UINT flags;
1375 wndpl.length = sizeof(wndpl);
1376 wndpl.showCmd = showCmd;
1377 wndpl.flags = flags = 0;
1379 if( pt )
1381 flags |= PLACE_MIN;
1382 wndpl.flags |= WPF_SETMINPOSITION;
1383 wndpl.ptMinPosition = *pt;
1385 if( rect )
1387 flags |= PLACE_RECT;
1388 wndpl.rcNormalPosition = *rect;
1390 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1394 /*******************************************************************
1395 * can_activate_window
1397 * Check if we can activate the specified window.
1399 static BOOL can_activate_window( HWND hwnd )
1401 LONG style;
1403 if (!hwnd) return FALSE;
1404 style = GetWindowLongW( hwnd, GWL_STYLE );
1405 if (!(style & WS_VISIBLE)) return FALSE;
1406 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1407 return !(style & WS_DISABLED);
1411 /*******************************************************************
1412 * WINPOS_ActivateOtherWindow
1414 * Activates window other than pWnd.
1416 void WINPOS_ActivateOtherWindow(HWND hwnd)
1418 HWND hwndTo, fg;
1420 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1422 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1423 if (can_activate_window( hwndTo )) goto done;
1426 hwndTo = hwnd;
1427 for (;;)
1429 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1430 if (can_activate_window( hwndTo )) break;
1433 done:
1434 fg = GetForegroundWindow();
1435 TRACE("win = %p fg = %p\n", hwndTo, fg);
1436 if (!fg || (hwnd == fg))
1438 if (SetForegroundWindow( hwndTo )) return;
1440 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1444 /***********************************************************************
1445 * WINPOS_HandleWindowPosChanging
1447 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1449 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1451 POINT minTrack, maxTrack;
1452 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1454 if (winpos->flags & SWP_NOSIZE) return 0;
1455 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1457 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1458 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1459 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1460 if (!(style & WS_MINIMIZE))
1462 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1463 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1466 return 0;
1470 /***********************************************************************
1471 * dump_winpos_flags
1473 static void dump_winpos_flags(UINT flags)
1475 static const DWORD dumped_flags = (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW |
1476 SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW |
1477 SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOOWNERZORDER |
1478 SWP_NOSENDCHANGING | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS |
1479 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_STATECHANGED);
1480 TRACE("flags:");
1481 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1482 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1483 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1484 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1485 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1486 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1487 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1488 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1489 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1490 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1491 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1492 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1493 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1494 if(flags & SWP_NOCLIENTSIZE) TRACE(" SWP_NOCLIENTSIZE");
1495 if(flags & SWP_NOCLIENTMOVE) TRACE(" SWP_NOCLIENTMOVE");
1496 if(flags & SWP_STATECHANGED) TRACE(" SWP_STATECHANGED");
1498 if(flags & ~dumped_flags) TRACE(" %08x", flags & ~dumped_flags);
1499 TRACE("\n");
1502 /***********************************************************************
1503 * SWP_DoWinPosChanging
1505 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1507 WND *wndPtr;
1509 /* Send WM_WINDOWPOSCHANGING message */
1511 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1512 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1514 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1515 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1517 /* Calculate new position and size */
1519 *pNewWindowRect = wndPtr->rectWindow;
1520 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1521 : wndPtr->rectClient;
1523 if (!(pWinpos->flags & SWP_NOSIZE))
1525 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1526 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1528 if (!(pWinpos->flags & SWP_NOMOVE))
1530 pNewWindowRect->left = pWinpos->x;
1531 pNewWindowRect->top = pWinpos->y;
1532 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1533 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1535 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1536 pWinpos->y - wndPtr->rectWindow.top );
1538 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1540 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1541 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1542 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1543 TRACE( "current %s style %08x new %s\n",
1544 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1545 wine_dbgstr_rect( pNewWindowRect ));
1547 WIN_ReleasePtr( wndPtr );
1548 return TRUE;
1551 /***********************************************************************
1552 * get_valid_rects
1554 * Compute the valid rects from the old and new client rect and WVR_* flags.
1555 * Helper for WM_NCCALCSIZE handling.
1557 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1558 RECT *valid )
1560 int cx, cy;
1562 if (flags & WVR_REDRAW)
1564 SetRectEmpty( &valid[0] );
1565 SetRectEmpty( &valid[1] );
1566 return;
1569 if (flags & WVR_VALIDRECTS)
1571 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1572 !IntersectRect( &valid[1], &valid[1], old_client ))
1574 SetRectEmpty( &valid[0] );
1575 SetRectEmpty( &valid[1] );
1576 return;
1578 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1580 else
1582 valid[0] = *new_client;
1583 valid[1] = *old_client;
1586 /* make sure the rectangles have the same size */
1587 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1588 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1590 if (flags & WVR_ALIGNBOTTOM)
1592 valid[0].top = valid[0].bottom - cy;
1593 valid[1].top = valid[1].bottom - cy;
1595 else
1597 valid[0].bottom = valid[0].top + cy;
1598 valid[1].bottom = valid[1].top + cy;
1600 if (flags & WVR_ALIGNRIGHT)
1602 valid[0].left = valid[0].right - cx;
1603 valid[1].left = valid[1].right - cx;
1605 else
1607 valid[0].right = valid[0].left + cx;
1608 valid[1].right = valid[1].left + cx;
1613 /***********************************************************************
1614 * SWP_DoOwnedPopups
1616 * fix Z order taking into account owned popups -
1617 * basically we need to maintain them above the window that owns them
1619 * FIXME: hide/show owned popups when owner visibility changes.
1621 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1623 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1624 HWND owner, *list = NULL;
1625 unsigned int i;
1627 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1629 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1631 /* make sure this popup stays above the owner */
1633 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1635 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1637 for (i = 0; list[i]; i++)
1639 if (list[i] == owner)
1641 if (i > 0) hwndInsertAfter = list[i-1];
1642 else hwndInsertAfter = HWND_TOP;
1643 break;
1646 if (hwndInsertAfter == HWND_NOTOPMOST)
1648 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1650 else if (list[i] == hwndInsertAfter) break;
1654 else if (style & WS_CHILD) return hwndInsertAfter;
1656 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1657 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1659 i = 0;
1660 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1662 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1664 /* skip all the topmost windows */
1665 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1668 else if (hwndInsertAfter != HWND_TOPMOST)
1670 /* skip windows that are already placed correctly */
1671 for (i = 0; list[i]; i++)
1673 if (list[i] == hwndInsertAfter) break;
1674 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1678 for ( ; list[i]; i++)
1680 if (list[i] == hwnd) break;
1681 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1682 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1683 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1684 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1685 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1686 hwndInsertAfter = list[i];
1689 done:
1690 HeapFree( GetProcessHeap(), 0, list );
1691 return hwndInsertAfter;
1694 /***********************************************************************
1695 * SWP_DoNCCalcSize
1697 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1698 RECT *validRects )
1700 UINT wvrFlags = 0;
1701 WND *wndPtr;
1703 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1705 /* Send WM_NCCALCSIZE message to get new client area */
1706 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1708 NCCALCSIZE_PARAMS params;
1709 WINDOWPOS winposCopy;
1711 params.rgrc[0] = *pNewWindowRect;
1712 params.rgrc[1] = wndPtr->rectWindow;
1713 params.rgrc[2] = wndPtr->rectClient;
1714 params.lppos = &winposCopy;
1715 winposCopy = *pWinpos;
1716 WIN_ReleasePtr( wndPtr );
1718 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1720 *pNewClientRect = params.rgrc[0];
1722 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1724 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1725 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1726 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1728 if( pNewClientRect->left != wndPtr->rectClient.left ||
1729 pNewClientRect->top != wndPtr->rectClient.top )
1730 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1732 if( (pNewClientRect->right - pNewClientRect->left !=
1733 wndPtr->rectClient.right - wndPtr->rectClient.left))
1734 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1735 else
1736 wvrFlags &= ~WVR_HREDRAW;
1738 if (pNewClientRect->bottom - pNewClientRect->top !=
1739 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1740 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1741 else
1742 wvrFlags &= ~WVR_VREDRAW;
1744 validRects[0] = params.rgrc[1];
1745 validRects[1] = params.rgrc[2];
1747 else
1749 if (!(pWinpos->flags & SWP_NOMOVE) &&
1750 (pNewClientRect->left != wndPtr->rectClient.left ||
1751 pNewClientRect->top != wndPtr->rectClient.top))
1752 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1755 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1757 SetRectEmpty( &validRects[0] );
1758 SetRectEmpty( &validRects[1] );
1760 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1762 WIN_ReleasePtr( wndPtr );
1763 return wvrFlags;
1766 /* fix redundant flags and values in the WINDOWPOS structure */
1767 static BOOL fixup_flags( WINDOWPOS *winpos )
1769 HWND parent;
1770 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1771 BOOL ret = TRUE;
1773 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1775 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1776 return FALSE;
1778 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1780 /* Finally make sure that all coordinates are valid */
1781 if (winpos->x < -32768) winpos->x = -32768;
1782 else if (winpos->x > 32767) winpos->x = 32767;
1783 if (winpos->y < -32768) winpos->y = -32768;
1784 else if (winpos->y > 32767) winpos->y = 32767;
1786 if (winpos->cx < 0) winpos->cx = 0;
1787 else if (winpos->cx > 32767) winpos->cx = 32767;
1788 if (winpos->cy < 0) winpos->cy = 0;
1789 else if (winpos->cy > 32767) winpos->cy = 32767;
1791 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1792 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1794 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1795 else
1797 winpos->flags &= ~SWP_HIDEWINDOW;
1798 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1801 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1802 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1803 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1805 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1806 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1808 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1810 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1811 (winpos->flags & SWP_NOZORDER ||
1812 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1814 winpos->flags &= ~SWP_NOZORDER;
1815 winpos->hwndInsertAfter = HWND_TOP;
1819 /* Check hwndInsertAfter */
1820 if (winpos->flags & SWP_NOZORDER) goto done;
1822 /* fix sign extension */
1823 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1824 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1826 /* hwndInsertAfter must be a sibling of the window */
1827 if (winpos->hwndInsertAfter == HWND_TOP)
1829 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1830 winpos->flags |= SWP_NOZORDER;
1832 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1834 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1835 winpos->flags |= SWP_NOZORDER;
1837 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1839 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1840 winpos->flags |= SWP_NOZORDER;
1842 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1844 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1845 winpos->flags |= SWP_NOZORDER;
1847 else
1849 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1850 else
1852 /* don't need to change the Zorder of hwnd if it's already inserted
1853 * after hwndInsertAfter or when inserting hwnd after itself.
1855 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1856 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1857 winpos->flags |= SWP_NOZORDER;
1860 done:
1861 WIN_ReleasePtr( wndPtr );
1862 return ret;
1866 /***********************************************************************
1867 * set_window_pos
1869 * Backend implementation of SetWindowPos.
1871 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1872 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1874 WND *win;
1875 BOOL ret;
1876 RECT visible_rect, old_window_rect;
1878 visible_rect = *window_rect;
1879 USER_Driver->pWindowPosChanging( hwnd, insert_after, swp_flags,
1880 window_rect, client_rect, &visible_rect );
1882 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
1883 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
1885 old_window_rect = win->rectWindow;
1886 SERVER_START_REQ( set_window_pos )
1888 req->handle = hwnd;
1889 req->previous = insert_after;
1890 req->flags = swp_flags;
1891 req->window.left = window_rect->left;
1892 req->window.top = window_rect->top;
1893 req->window.right = window_rect->right;
1894 req->window.bottom = window_rect->bottom;
1895 req->client.left = client_rect->left;
1896 req->client.top = client_rect->top;
1897 req->client.right = client_rect->right;
1898 req->client.bottom = client_rect->bottom;
1899 if (memcmp( window_rect, &visible_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
1901 wine_server_add_data( req, &visible_rect, sizeof(visible_rect) );
1902 if (!IsRectEmpty( &valid_rects[0] ))
1903 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1905 if ((ret = !wine_server_call( req )))
1907 win->dwStyle = reply->new_style;
1908 win->dwExStyle = reply->new_ex_style;
1909 win->rectWindow = *window_rect;
1910 win->rectClient = *client_rect;
1913 SERVER_END_REQ;
1914 WIN_ReleasePtr( win );
1916 if (ret)
1918 if (((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) ||
1919 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW | SWP_STATECHANGED)))
1920 invalidate_dce( hwnd, &old_window_rect );
1922 USER_Driver->pWindowPosChanged( hwnd, insert_after, swp_flags, window_rect,
1923 client_rect, &visible_rect, valid_rects );
1925 return ret;
1929 /***********************************************************************
1930 * USER_SetWindowPos
1932 * User32 internal function
1934 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1936 RECT newWindowRect, newClientRect, valid_rects[2];
1937 UINT orig_flags;
1939 orig_flags = winpos->flags;
1941 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1942 if (!(winpos->flags & SWP_NOMOVE))
1944 if (winpos->x < -32768) winpos->x = -32768;
1945 else if (winpos->x > 32767) winpos->x = 32767;
1946 if (winpos->y < -32768) winpos->y = -32768;
1947 else if (winpos->y > 32767) winpos->y = 32767;
1949 if (!(winpos->flags & SWP_NOSIZE))
1951 if (winpos->cx < 0) winpos->cx = 0;
1952 else if (winpos->cx > 32767) winpos->cx = 32767;
1953 if (winpos->cy < 0) winpos->cy = 0;
1954 else if (winpos->cy > 32767) winpos->cy = 32767;
1957 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1959 /* Fix redundant flags */
1960 if (!fixup_flags( winpos )) return FALSE;
1962 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1964 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1965 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1968 /* Common operations */
1970 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1972 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1973 &newWindowRect, &newClientRect, valid_rects ))
1974 return FALSE;
1976 /* erase parent when hiding or resizing child */
1977 if (!(orig_flags & SWP_DEFERERASE) &&
1978 ((orig_flags & SWP_HIDEWINDOW) ||
1979 (!(orig_flags & SWP_SHOWWINDOW) &&
1980 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1982 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1983 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1984 erase_now( parent, 0 );
1987 if( winpos->flags & SWP_HIDEWINDOW )
1988 HideCaret(winpos->hwnd);
1989 else if (winpos->flags & SWP_SHOWWINDOW)
1990 ShowCaret(winpos->hwnd);
1992 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
1994 /* child windows get WM_CHILDACTIVATE message */
1995 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1996 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1997 else
1998 SetForegroundWindow( winpos->hwnd );
2001 /* And last, send the WM_WINDOWPOSCHANGED message */
2003 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2005 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2007 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2008 and always contains final window position.
2010 winpos->x = newWindowRect.left;
2011 winpos->y = newWindowRect.top;
2012 winpos->cx = newWindowRect.right - newWindowRect.left;
2013 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2014 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2016 return TRUE;
2019 /***********************************************************************
2020 * SetWindowPos (USER32.@)
2022 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2023 INT x, INT y, INT cx, INT cy, UINT flags )
2025 WINDOWPOS winpos;
2027 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2028 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2029 if(TRACE_ON(win)) dump_winpos_flags(flags);
2031 if (is_broadcast(hwnd))
2033 SetLastError( ERROR_INVALID_PARAMETER );
2034 return FALSE;
2037 winpos.hwnd = WIN_GetFullHandle(hwnd);
2038 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2039 winpos.x = x;
2040 winpos.y = y;
2041 winpos.cx = cx;
2042 winpos.cy = cy;
2043 winpos.flags = flags;
2045 if (WIN_IsCurrentThread( hwnd ))
2046 return USER_SetWindowPos(&winpos);
2048 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2052 /***********************************************************************
2053 * BeginDeferWindowPos (USER32.@)
2055 HDWP WINAPI BeginDeferWindowPos( INT count )
2057 HDWP handle;
2058 DWP *pDWP;
2060 TRACE("%d\n", count);
2062 if (count < 0)
2064 SetLastError(ERROR_INVALID_PARAMETER);
2065 return 0;
2067 /* Windows allows zero count, in which case it allocates context for 8 moves */
2068 if (count == 0) count = 8;
2070 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2071 if (!handle) return 0;
2072 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2073 pDWP->actualCount = 0;
2074 pDWP->suggestedCount = count;
2075 pDWP->valid = TRUE;
2076 pDWP->wMagic = DWP_MAGIC;
2077 pDWP->hwndParent = 0;
2079 TRACE("returning hdwp %p\n", handle);
2080 return handle;
2084 /***********************************************************************
2085 * DeferWindowPos (USER32.@)
2087 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2088 INT x, INT y, INT cx, INT cy,
2089 UINT flags )
2091 DWP *pDWP;
2092 int i;
2093 HDWP newhdwp = hdwp,retvalue;
2095 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2096 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2098 hwnd = WIN_GetFullHandle( hwnd );
2099 if (is_desktop_window( hwnd )) return 0;
2101 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2103 USER_Lock();
2105 for (i = 0; i < pDWP->actualCount; i++)
2107 if (pDWP->winPos[i].hwnd == hwnd)
2109 /* Merge with the other changes */
2110 if (!(flags & SWP_NOZORDER))
2112 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2114 if (!(flags & SWP_NOMOVE))
2116 pDWP->winPos[i].x = x;
2117 pDWP->winPos[i].y = y;
2119 if (!(flags & SWP_NOSIZE))
2121 pDWP->winPos[i].cx = cx;
2122 pDWP->winPos[i].cy = cy;
2124 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2125 SWP_NOZORDER | SWP_NOREDRAW |
2126 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2127 SWP_NOOWNERZORDER);
2128 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2129 SWP_FRAMECHANGED);
2130 retvalue = hdwp;
2131 goto END;
2134 if (pDWP->actualCount >= pDWP->suggestedCount)
2136 newhdwp = USER_HEAP_REALLOC( hdwp,
2137 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2138 if (!newhdwp)
2140 retvalue = 0;
2141 goto END;
2143 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2144 pDWP->suggestedCount++;
2146 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2147 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2148 pDWP->winPos[pDWP->actualCount].x = x;
2149 pDWP->winPos[pDWP->actualCount].y = y;
2150 pDWP->winPos[pDWP->actualCount].cx = cx;
2151 pDWP->winPos[pDWP->actualCount].cy = cy;
2152 pDWP->winPos[pDWP->actualCount].flags = flags;
2153 pDWP->actualCount++;
2154 retvalue = newhdwp;
2155 END:
2156 USER_Unlock();
2157 return retvalue;
2161 /***********************************************************************
2162 * EndDeferWindowPos (USER32.@)
2164 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2166 DWP *pDWP;
2167 WINDOWPOS *winpos;
2168 BOOL res = TRUE;
2169 int i;
2171 TRACE("%p\n", hdwp);
2173 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2174 if (!pDWP) return FALSE;
2175 for (i = 0, winpos = pDWP->winPos; res && i < pDWP->actualCount; i++, winpos++)
2177 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2178 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2179 winpos->cx, winpos->cy, winpos->flags);
2181 if (WIN_IsCurrentThread( winpos->hwnd ))
2182 res = USER_SetWindowPos( winpos );
2183 else
2184 res = SendMessageW( winpos->hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)winpos );
2186 USER_HEAP_FREE( hdwp );
2187 return res;
2191 /***********************************************************************
2192 * ArrangeIconicWindows (USER32.@)
2194 UINT WINAPI ArrangeIconicWindows( HWND parent )
2196 RECT rectParent;
2197 HWND hwndChild;
2198 INT x, y, xspacing, yspacing;
2200 GetClientRect( parent, &rectParent );
2201 x = rectParent.left;
2202 y = rectParent.bottom;
2203 xspacing = GetSystemMetrics(SM_CXICONSPACING);
2204 yspacing = GetSystemMetrics(SM_CYICONSPACING);
2206 hwndChild = GetWindow( parent, GW_CHILD );
2207 while (hwndChild)
2209 if( IsIconic( hwndChild ) )
2211 WINPOS_ShowIconTitle( hwndChild, FALSE );
2213 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
2214 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
2215 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
2216 if( IsWindow(hwndChild) )
2217 WINPOS_ShowIconTitle(hwndChild , TRUE );
2219 if (x <= rectParent.right - xspacing) x += xspacing;
2220 else
2222 x = rectParent.left;
2223 y -= yspacing;
2226 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
2228 return yspacing;
2232 /***********************************************************************
2233 * draw_moving_frame
2235 * Draw the frame used when moving or resizing window.
2237 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
2239 if (thickframe)
2241 const int width = GetSystemMetrics(SM_CXFRAME);
2242 const int height = GetSystemMetrics(SM_CYFRAME);
2244 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
2245 PatBlt( hdc, rect->left, rect->top,
2246 rect->right - rect->left - width, height, PATINVERT );
2247 PatBlt( hdc, rect->left, rect->top + height, width,
2248 rect->bottom - rect->top - height, PATINVERT );
2249 PatBlt( hdc, rect->left + width, rect->bottom - 1,
2250 rect->right - rect->left - width, -height, PATINVERT );
2251 PatBlt( hdc, rect->right - 1, rect->top, -width,
2252 rect->bottom - rect->top - height, PATINVERT );
2253 SelectObject( hdc, hbrush );
2255 else DrawFocusRect( hdc, rect );
2259 /***********************************************************************
2260 * start_size_move
2262 * Initialization of a move or resize, when initiated from a menu choice.
2263 * Return hit test code for caption or sizing border.
2265 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
2267 LONG hittest = 0;
2268 POINT pt;
2269 MSG msg;
2270 RECT rectWindow;
2272 GetWindowRect( hwnd, &rectWindow );
2274 if ((wParam & 0xfff0) == SC_MOVE)
2276 /* Move pointer at the center of the caption */
2277 RECT rect = rectWindow;
2278 /* Note: to be exactly centered we should take the different types
2279 * of border into account, but it shouldn't make more than a few pixels
2280 * of difference so let's not bother with that */
2281 rect.top += GetSystemMetrics(SM_CYBORDER);
2282 if (style & WS_SYSMENU)
2283 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2284 if (style & WS_MINIMIZEBOX)
2285 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2286 if (style & WS_MAXIMIZEBOX)
2287 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2288 pt.x = (rect.right + rect.left) / 2;
2289 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2290 hittest = HTCAPTION;
2291 *capturePoint = pt;
2293 else /* SC_SIZE */
2295 SetCursor( LoadCursorW( 0, (LPWSTR)IDC_SIZEALL ) );
2296 pt.x = pt.y = 0;
2297 while(!hittest)
2299 if (!GetMessageW( &msg, 0, 0, 0 )) return 0;
2300 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2302 switch(msg.message)
2304 case WM_MOUSEMOVE:
2305 pt.x = min( max( msg.pt.x, rectWindow.left ), rectWindow.right - 1 );
2306 pt.y = min( max( msg.pt.y, rectWindow.top ), rectWindow.bottom - 1 );
2307 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
2308 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
2309 break;
2311 case WM_LBUTTONUP:
2312 return 0;
2314 case WM_KEYDOWN:
2315 switch(msg.wParam)
2317 case VK_UP:
2318 hittest = HTTOP;
2319 pt.x =(rectWindow.left+rectWindow.right)/2;
2320 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2321 break;
2322 case VK_DOWN:
2323 hittest = HTBOTTOM;
2324 pt.x =(rectWindow.left+rectWindow.right)/2;
2325 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2326 break;
2327 case VK_LEFT:
2328 hittest = HTLEFT;
2329 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2330 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2331 break;
2332 case VK_RIGHT:
2333 hittest = HTRIGHT;
2334 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2335 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2336 break;
2337 case VK_RETURN:
2338 case VK_ESCAPE:
2339 return 0;
2341 break;
2342 default:
2343 TranslateMessage( &msg );
2344 DispatchMessageW( &msg );
2345 break;
2348 *capturePoint = pt;
2350 SetCursorPos( pt.x, pt.y );
2351 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
2352 return hittest;
2356 /***********************************************************************
2357 * WINPOS_SysCommandSizeMove
2359 * Perform SC_MOVE and SC_SIZE commands.
2361 void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
2363 MSG msg;
2364 RECT sizingRect, mouseRect, origRect;
2365 HDC hdc;
2366 HWND parent;
2367 LONG hittest = (LONG)(wParam & 0x0f);
2368 WPARAM syscommand = wParam & 0xfff0;
2369 HCURSOR hDragCursor = 0, hOldCursor = 0;
2370 POINT minTrack, maxTrack;
2371 POINT capturePoint, pt;
2372 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2373 BOOL thickframe = HAS_THICKFRAME( style );
2374 BOOL iconic = style & WS_MINIMIZE;
2375 BOOL moved = FALSE;
2376 DWORD dwPoint = GetMessagePos ();
2377 BOOL DragFullWindows = TRUE;
2379 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
2381 pt.x = (short)LOWORD(dwPoint);
2382 pt.y = (short)HIWORD(dwPoint);
2383 capturePoint = pt;
2385 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2386 hwnd, syscommand, hittest, pt.x, pt.y);
2388 if (syscommand == SC_MOVE)
2390 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2391 if (!hittest) return;
2393 else /* SC_SIZE */
2395 if ( hittest && (syscommand != SC_MOUSEMENU) )
2396 hittest += (HTLEFT - WMSZ_LEFT);
2397 else
2399 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2400 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2401 if (!hittest)
2403 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2404 return;
2409 /* Get min/max info */
2411 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
2412 GetWindowRect( hwnd, &sizingRect );
2413 if (style & WS_CHILD)
2415 parent = GetParent(hwnd);
2416 /* make sizing rect relative to parent */
2417 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
2418 GetClientRect( parent, &mouseRect );
2420 else
2422 parent = 0;
2423 GetClientRect( GetDesktopWindow(), &mouseRect );
2424 mouseRect.left = GetSystemMetrics( SM_XVIRTUALSCREEN );
2425 mouseRect.top = GetSystemMetrics( SM_YVIRTUALSCREEN );
2426 mouseRect.right = mouseRect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
2427 mouseRect.bottom = mouseRect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
2429 origRect = sizingRect;
2431 if (ON_LEFT_BORDER(hittest))
2433 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2434 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2436 else if (ON_RIGHT_BORDER(hittest))
2438 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2439 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2441 if (ON_TOP_BORDER(hittest))
2443 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2444 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2446 else if (ON_BOTTOM_BORDER(hittest))
2448 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2449 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2451 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2453 /* Retrieve a default cache DC (without using the window style) */
2454 hdc = GetDCEx( parent, 0, DCX_CACHE );
2456 if( iconic ) /* create a cursor for dragging */
2458 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
2459 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
2460 if( !hDragCursor ) iconic = FALSE;
2463 /* we only allow disabling the full window drag for child windows */
2464 if (parent) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0 );
2466 /* repaint the window before moving it around */
2467 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2469 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2470 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2472 while(1)
2474 int dx = 0, dy = 0;
2476 if (!GetMessageW( &msg, 0, 0, 0 )) break;
2477 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2479 /* Exit on button-up, Return, or Esc */
2480 if ((msg.message == WM_LBUTTONUP) ||
2481 ((msg.message == WM_KEYDOWN) &&
2482 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2484 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2486 TranslateMessage( &msg );
2487 DispatchMessageW( &msg );
2488 continue; /* We are not interested in other messages */
2491 pt = msg.pt;
2493 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2495 case VK_UP: pt.y -= 8; break;
2496 case VK_DOWN: pt.y += 8; break;
2497 case VK_LEFT: pt.x -= 8; break;
2498 case VK_RIGHT: pt.x += 8; break;
2501 pt.x = max( pt.x, mouseRect.left );
2502 pt.x = min( pt.x, mouseRect.right );
2503 pt.y = max( pt.y, mouseRect.top );
2504 pt.y = min( pt.y, mouseRect.bottom );
2506 dx = pt.x - capturePoint.x;
2507 dy = pt.y - capturePoint.y;
2509 if (dx || dy)
2511 if( !moved )
2513 moved = TRUE;
2515 if( iconic ) /* ok, no system popup tracking */
2517 hOldCursor = SetCursor(hDragCursor);
2518 ShowCursor( TRUE );
2519 WINPOS_ShowIconTitle( hwnd, FALSE );
2521 else if(!DragFullWindows)
2522 draw_moving_frame( hdc, &sizingRect, thickframe );
2525 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2526 else
2528 RECT newRect = sizingRect;
2529 WPARAM wpSizingHit = 0;
2531 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2532 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2533 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2534 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2535 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2536 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2537 capturePoint = pt;
2539 /* determine the hit location */
2540 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2541 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2542 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2544 if (!iconic)
2546 if(!DragFullWindows)
2547 draw_moving_frame( hdc, &newRect, thickframe );
2548 else
2549 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2550 newRect.right - newRect.left,
2551 newRect.bottom - newRect.top,
2552 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2554 sizingRect = newRect;
2559 if( iconic )
2561 if( moved ) /* restore cursors, show icon title later on */
2563 ShowCursor( FALSE );
2564 SetCursor( hOldCursor );
2567 else if (moved && !DragFullWindows)
2569 draw_moving_frame( hdc, &sizingRect, thickframe );
2572 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2573 ReleaseDC( parent, hdc );
2575 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2576 moved = FALSE;
2578 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2579 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2581 /* window moved or resized */
2582 if (moved)
2584 /* if the moving/resizing isn't canceled call SetWindowPos
2585 * with the new position or the new size of the window
2587 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2589 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2590 if(!DragFullWindows || iconic)
2591 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2592 sizingRect.right - sizingRect.left,
2593 sizingRect.bottom - sizingRect.top,
2594 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2596 else
2597 { /* restore previous size/position */
2598 if(DragFullWindows)
2599 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2600 origRect.right - origRect.left,
2601 origRect.bottom - origRect.top,
2602 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2606 if (IsIconic(hwnd))
2608 /* Single click brings up the system menu when iconized */
2610 if( !moved )
2612 if(style & WS_SYSMENU )
2613 SendMessageW( hwnd, WM_SYSCOMMAND,
2614 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2616 else WINPOS_ShowIconTitle( hwnd, TRUE );