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