push 73336d9f381967eae40f391d78198b916ed9848d
[wine/hacks.git] / dlls / user32 / winpos.c
blob6ee350812eb826321f7cccd1790579a1d2cde36f
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 = 32;
264 for (;;)
266 int count = 0;
268 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
270 SERVER_START_REQ( get_window_children_from_point )
272 req->parent = hwnd;
273 req->x = pt.x;
274 req->y = pt.y;
275 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
276 if (!wine_server_call( req )) count = reply->count;
278 SERVER_END_REQ;
279 if (count && count < size)
281 list[count] = 0;
282 return list;
284 HeapFree( GetProcessHeap(), 0, list );
285 if (!count) break;
286 size = count + 1; /* restart with a large enough buffer */
288 return NULL;
292 /***********************************************************************
293 * WINPOS_WindowFromPoint
295 * Find the window and hittest for a given point.
297 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
299 int i, res;
300 HWND ret, *list;
302 if (!hwndScope) hwndScope = GetDesktopWindow();
304 *hittest = HTNOWHERE;
306 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
308 /* now determine the hittest */
310 for (i = 0; list[i]; i++)
312 LONG style = GetWindowLongW( list[i], GWL_STYLE );
314 /* If window is minimized or disabled, return at once */
315 if (style & WS_MINIMIZE)
317 *hittest = HTCAPTION;
318 break;
320 if (style & WS_DISABLED)
322 *hittest = HTERROR;
323 break;
325 /* Send WM_NCCHITTEST (if same thread) */
326 if (!WIN_IsCurrentThread( list[i] ))
328 *hittest = HTCLIENT;
329 break;
331 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
332 if (res != HTTRANSPARENT)
334 *hittest = res; /* Found the window */
335 break;
337 /* continue search with next window in z-order */
339 ret = list[i];
340 HeapFree( GetProcessHeap(), 0, list );
341 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
342 return ret;
346 /*******************************************************************
347 * WindowFromPoint (USER32.@)
349 HWND WINAPI WindowFromPoint( POINT pt )
351 INT hittest;
352 return WINPOS_WindowFromPoint( 0, pt, &hittest );
356 /*******************************************************************
357 * ChildWindowFromPoint (USER32.@)
359 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
361 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
364 /*******************************************************************
365 * RealChildWindowFromPoint (USER32.@)
367 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
369 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
372 /*******************************************************************
373 * ChildWindowFromPointEx (USER32.@)
375 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
377 /* pt is in the client coordinates */
378 HWND *list;
379 int i;
380 RECT rect;
381 HWND retvalue;
383 GetClientRect( hwndParent, &rect );
384 if (!PtInRect( &rect, pt )) return 0;
385 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
387 for (i = 0; list[i]; i++)
389 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
390 if (!PtInRect( &rect, pt )) continue;
391 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
393 LONG style = GetWindowLongW( list[i], GWL_STYLE );
394 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
395 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
397 if (uFlags & CWP_SKIPTRANSPARENT)
399 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
401 break;
403 retvalue = list[i];
404 HeapFree( GetProcessHeap(), 0, list );
405 if (!retvalue) retvalue = hwndParent;
406 return retvalue;
410 /*******************************************************************
411 * WINPOS_GetWinOffset
413 * Calculate the offset between the origin of the two windows. Used
414 * to implement MapWindowPoints.
416 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
418 WND * wndPtr;
420 offset->x = offset->y = 0;
422 /* Translate source window origin to screen coords */
423 if (hwndFrom)
425 HWND hwnd = hwndFrom;
427 while (hwnd)
429 if (hwnd == hwndTo) return;
430 if (!(wndPtr = WIN_GetPtr( hwnd )))
432 ERR( "bad hwndFrom = %p\n", hwnd );
433 return;
435 if (wndPtr == WND_DESKTOP) break;
436 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
437 offset->x += wndPtr->rectClient.left;
438 offset->y += wndPtr->rectClient.top;
439 hwnd = wndPtr->parent;
440 WIN_ReleasePtr( wndPtr );
444 /* Translate origin to destination window coords */
445 if (hwndTo)
447 HWND hwnd = hwndTo;
449 while (hwnd)
451 if (!(wndPtr = WIN_GetPtr( hwnd )))
453 ERR( "bad hwndTo = %p\n", hwnd );
454 return;
456 if (wndPtr == WND_DESKTOP) break;
457 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
458 offset->x -= wndPtr->rectClient.left;
459 offset->y -= wndPtr->rectClient.top;
460 hwnd = wndPtr->parent;
461 WIN_ReleasePtr( wndPtr );
464 return;
466 other_process: /* one of the parents may belong to another process, do it the hard way */
467 offset->x = offset->y = 0;
468 SERVER_START_REQ( get_windows_offset )
470 req->from = hwndFrom;
471 req->to = hwndTo;
472 if (!wine_server_call( req ))
474 offset->x = reply->x;
475 offset->y = reply->y;
478 SERVER_END_REQ;
482 /*******************************************************************
483 * MapWindowPoints (USER.258)
485 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
486 LPPOINT16 lppt, UINT16 count )
488 POINT offset;
490 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
491 while (count--)
493 lppt->x += offset.x;
494 lppt->y += offset.y;
495 lppt++;
500 /*******************************************************************
501 * MapWindowPoints (USER32.@)
503 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
505 POINT offset;
507 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
508 while (count--)
510 lppt->x += offset.x;
511 lppt->y += offset.y;
512 lppt++;
514 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
518 /***********************************************************************
519 * IsIconic (USER32.@)
521 BOOL WINAPI IsIconic(HWND hWnd)
523 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
527 /***********************************************************************
528 * IsZoomed (USER32.@)
530 BOOL WINAPI IsZoomed(HWND hWnd)
532 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
536 /*******************************************************************
537 * AllowSetForegroundWindow (USER32.@)
539 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
541 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
542 * implemented, then fix this function. */
543 return TRUE;
547 /*******************************************************************
548 * LockSetForegroundWindow (USER32.@)
550 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
552 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
553 * implemented, then fix this function. */
554 return TRUE;
558 /***********************************************************************
559 * BringWindowToTop (USER32.@)
561 BOOL WINAPI BringWindowToTop( HWND hwnd )
563 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
567 /***********************************************************************
568 * MoveWindow (USER32.@)
570 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
571 BOOL repaint )
573 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
574 if (!repaint) flags |= SWP_NOREDRAW;
575 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
576 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
579 /***********************************************************************
580 * WINPOS_InitPlacement
582 static void WINPOS_InitPlacement( WND* wnd )
584 if (IsRectEmpty( &wnd->normal_rect ))
586 /* this happens when the window is minimized/maximized
587 * for the first time (rectWindow is not adjusted yet) */
589 wnd->normal_rect = wnd->rectWindow;
590 wnd->min_pos.x = wnd->min_pos.y = -1;
591 wnd->max_pos.x = wnd->max_pos.y = -1;
594 if( wnd->dwStyle & WS_MINIMIZE )
596 wnd->min_pos.x = wnd->rectWindow.left;
597 wnd->min_pos.y = wnd->rectWindow.top;
599 else if( wnd->dwStyle & WS_MAXIMIZE )
601 wnd->max_pos.x = wnd->rectWindow.left;
602 wnd->max_pos.y = wnd->rectWindow.top;
604 else
606 wnd->normal_rect = wnd->rectWindow;
610 /***********************************************************************
611 * WINPOS_RedrawIconTitle
613 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
615 HWND icon_title = 0;
616 WND *win = WIN_GetPtr( hWnd );
618 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
620 icon_title = win->icon_title;
621 WIN_ReleasePtr( win );
623 if (!icon_title) return FALSE;
624 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
625 InvalidateRect( icon_title, NULL, TRUE );
626 return TRUE;
629 /***********************************************************************
630 * WINPOS_ShowIconTitle
632 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
634 if (!GetPropA( hwnd, "__wine_x11_managed" ))
636 WND *win = WIN_GetPtr( hwnd );
637 HWND title = 0;
639 TRACE("%p %i\n", hwnd, (bShow != 0) );
641 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
642 title = win->icon_title;
643 WIN_ReleasePtr( win );
645 if( bShow )
647 if (!title)
649 title = ICONTITLE_Create( hwnd );
650 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
652 DestroyWindow( title );
653 return FALSE;
655 win->icon_title = title;
656 WIN_ReleasePtr( win );
658 if (!IsWindowVisible(title))
660 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
661 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
662 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
665 else if (title) ShowWindow( title, SW_HIDE );
667 return FALSE;
670 /*******************************************************************
671 * WINPOS_GetMinMaxInfo
673 * Get the minimized and maximized information for a window.
675 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
676 POINT *minTrack, POINT *maxTrack )
678 MINMAXINFO MinMax;
679 HMONITOR monitor;
680 INT xinc, yinc;
681 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
682 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
683 RECT rc;
684 WND *win;
686 /* Compute default values */
688 GetWindowRect(hwnd, &rc);
689 MinMax.ptReserved.x = rc.left;
690 MinMax.ptReserved.y = rc.top;
692 if (style & WS_CHILD)
694 if ((style & WS_CAPTION) == WS_CAPTION)
695 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
697 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
698 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
700 /* avoid calculating this twice */
701 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
703 MinMax.ptMaxSize.x = rc.right - rc.left;
704 MinMax.ptMaxSize.y = rc.bottom - rc.top;
706 else
708 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
709 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
711 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
712 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
713 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
714 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
716 if (HAS_DLGFRAME( style, exstyle ))
718 xinc = GetSystemMetrics(SM_CXDLGFRAME);
719 yinc = GetSystemMetrics(SM_CYDLGFRAME);
721 else
723 xinc = yinc = 0;
724 if (HAS_THICKFRAME(style))
726 xinc += GetSystemMetrics(SM_CXFRAME);
727 yinc += GetSystemMetrics(SM_CYFRAME);
729 if (style & WS_BORDER)
731 xinc += GetSystemMetrics(SM_CXBORDER);
732 yinc += GetSystemMetrics(SM_CYBORDER);
735 MinMax.ptMaxSize.x += 2 * xinc;
736 MinMax.ptMaxSize.y += 2 * yinc;
738 MinMax.ptMaxPosition.x = -xinc;
739 MinMax.ptMaxPosition.y = -yinc;
740 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
742 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
743 WIN_ReleasePtr( win );
746 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
748 /* if the app didn't change the values, adapt them for the current monitor */
750 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
752 MONITORINFO mon_info;
754 mon_info.cbSize = sizeof(mon_info);
755 GetMonitorInfoW( monitor, &mon_info );
757 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
758 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
760 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
761 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
763 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
765 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
766 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
770 /* Some sanity checks */
772 TRACE("%d %d / %d %d / %d %d / %d %d\n",
773 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
774 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
775 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
776 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
777 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
778 MinMax.ptMinTrackSize.x );
779 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
780 MinMax.ptMinTrackSize.y );
782 if (maxSize) *maxSize = MinMax.ptMaxSize;
783 if (maxPos) *maxPos = MinMax.ptMaxPosition;
784 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
785 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
789 /***********************************************************************
790 * WINPOS_FindIconPos
792 * Find a suitable place for an iconic window.
794 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
796 RECT rect, rectParent;
797 HWND parent, child;
798 HRGN hrgn, tmp;
799 int xspacing, yspacing;
801 parent = GetAncestor( hwnd, GA_PARENT );
802 GetClientRect( parent, &rectParent );
803 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
804 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
805 return pt; /* The icon already has a suitable position */
807 xspacing = GetSystemMetrics(SM_CXICONSPACING);
808 yspacing = GetSystemMetrics(SM_CYICONSPACING);
810 /* Check if another icon already occupies this spot */
811 /* FIXME: this is completely inefficient */
813 hrgn = CreateRectRgn( 0, 0, 0, 0 );
814 tmp = CreateRectRgn( 0, 0, 0, 0 );
815 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
817 WND *childPtr;
818 if (child == hwnd) continue;
819 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
820 continue;
821 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
822 continue;
823 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
824 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
825 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
826 WIN_ReleasePtr( childPtr );
828 DeleteObject( tmp );
830 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
832 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
834 rect.right = rect.left + xspacing;
835 rect.top = rect.bottom - yspacing;
836 if (!RectInRegion( hrgn, &rect ))
838 /* No window was found, so it's OK for us */
839 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
840 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
841 DeleteObject( hrgn );
842 return pt;
846 DeleteObject( hrgn );
847 pt.x = pt.y = 0;
848 return pt;
852 /***********************************************************************
853 * WINPOS_MinMaximize
855 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
857 WND *wndPtr;
858 UINT swpFlags = 0;
859 POINT size;
860 LONG old_style;
861 WINDOWPLACEMENT wpl;
863 TRACE("%p %u\n", hwnd, cmd );
865 wpl.length = sizeof(wpl);
866 GetWindowPlacement( hwnd, &wpl );
868 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
869 return SWP_NOSIZE | SWP_NOMOVE;
871 if (IsIconic( hwnd ))
873 switch (cmd)
875 case SW_SHOWMINNOACTIVE:
876 case SW_SHOWMINIMIZED:
877 case SW_FORCEMINIMIZE:
878 case SW_MINIMIZE:
879 return SWP_NOSIZE | SWP_NOMOVE;
881 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
882 swpFlags |= SWP_NOCOPYBITS;
885 switch( cmd )
887 case SW_SHOWMINNOACTIVE:
888 case SW_SHOWMINIMIZED:
889 case SW_FORCEMINIMIZE:
890 case SW_MINIMIZE:
891 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
892 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
893 else wndPtr->flags &= ~WIN_RESTORE_MAX;
894 WIN_ReleasePtr( wndPtr );
896 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
898 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
900 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
901 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
902 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
903 swpFlags |= SWP_NOCOPYBITS;
904 break;
906 case SW_MAXIMIZE:
907 old_style = GetWindowLongW( hwnd, GWL_STYLE );
908 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
910 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
912 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
913 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
915 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
916 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
917 break;
919 case SW_SHOWNOACTIVATE:
920 case SW_SHOWNORMAL:
921 case SW_RESTORE:
922 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
923 if (old_style & WS_MINIMIZE)
925 BOOL restore_max;
927 WINPOS_ShowIconTitle( hwnd, FALSE );
929 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
930 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
931 WIN_ReleasePtr( wndPtr );
932 if (restore_max)
934 /* Restore to maximized position */
935 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
936 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
937 swpFlags |= SWP_STATECHANGED;
938 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
939 break;
942 else if (!(old_style & WS_MAXIMIZE)) break;
944 swpFlags |= SWP_STATECHANGED;
946 /* Restore to normal position */
948 *rect = wpl.rcNormalPosition;
949 rect->right -= rect->left;
950 rect->bottom -= rect->top;
952 break;
955 return swpFlags;
959 /***********************************************************************
960 * show_window
962 * Implementation of ShowWindow and ShowWindowAsync.
964 static BOOL show_window( HWND hwnd, INT cmd )
966 WND *wndPtr;
967 HWND parent;
968 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
969 BOOL wasVisible = (style & WS_VISIBLE) != 0;
970 BOOL showFlag = TRUE;
971 RECT newPos = {0, 0, 0, 0};
972 UINT swp = 0;
974 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
976 switch(cmd)
978 case SW_HIDE:
979 if (!wasVisible) return FALSE;
980 showFlag = FALSE;
981 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
982 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
983 break;
985 case SW_SHOWMINNOACTIVE:
986 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
987 /* fall through */
988 case SW_MINIMIZE:
989 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
990 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
991 /* fall through */
992 case SW_SHOWMINIMIZED:
993 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
994 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
995 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
996 break;
998 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
999 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1000 swp |= SWP_FRAMECHANGED;
1001 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1002 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
1003 break;
1005 case SW_SHOWNA:
1006 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1007 if (style & WS_CHILD) swp |= SWP_NOZORDER;
1008 break;
1009 case SW_SHOW:
1010 if (wasVisible) return TRUE;
1011 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1012 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1013 break;
1015 case SW_SHOWNOACTIVATE:
1016 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1017 /* fall through */
1018 case SW_RESTORE:
1019 /* fall through */
1020 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1021 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1022 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1023 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1025 swp |= SWP_FRAMECHANGED;
1026 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1028 else
1030 if (wasVisible) return TRUE;
1031 swp |= SWP_NOSIZE | SWP_NOMOVE;
1033 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1034 break;
1035 default:
1036 return wasVisible;
1039 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1041 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1042 if (!IsWindow( hwnd )) return wasVisible;
1045 parent = GetAncestor( hwnd, GA_PARENT );
1046 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1048 /* if parent is not visible simply toggle WS_VISIBLE and return */
1049 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1050 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1052 else
1053 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1054 newPos.right, newPos.bottom, LOWORD(swp) );
1056 if (cmd == SW_HIDE)
1058 HWND hFocus;
1060 WINPOS_ShowIconTitle( hwnd, FALSE );
1062 /* FIXME: This will cause the window to be activated irrespective
1063 * of whether it is owned by the same thread. Has to be done
1064 * asynchronously.
1067 if (hwnd == GetActiveWindow())
1068 WINPOS_ActivateOtherWindow(hwnd);
1070 /* Revert focus to parent */
1071 hFocus = GetFocus();
1072 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1074 HWND parent = GetAncestor(hwnd, GA_PARENT);
1075 if (parent == GetDesktopWindow()) parent = 0;
1076 SetFocus(parent);
1080 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1082 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1084 if (wndPtr->flags & WIN_NEED_SIZE)
1086 /* should happen only in CreateWindowEx() */
1087 int wParam = SIZE_RESTORED;
1088 RECT client = wndPtr->rectClient;
1090 wndPtr->flags &= ~WIN_NEED_SIZE;
1091 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1092 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1093 WIN_ReleasePtr( wndPtr );
1095 SendMessageW( hwnd, WM_SIZE, wParam,
1096 MAKELONG( client.right - client.left, client.bottom - client.top ));
1097 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1099 else WIN_ReleasePtr( wndPtr );
1101 /* if previous state was minimized Windows sets focus to the window */
1102 if (style & WS_MINIMIZE) SetFocus( hwnd );
1104 return wasVisible;
1108 /***********************************************************************
1109 * ShowWindowAsync (USER32.@)
1111 * doesn't wait; returns immediately.
1112 * used by threads to toggle windows in other (possibly hanging) threads
1114 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1116 HWND full_handle;
1118 if (is_broadcast(hwnd))
1120 SetLastError( ERROR_INVALID_PARAMETER );
1121 return FALSE;
1124 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1125 return show_window( full_handle, cmd );
1127 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1131 /***********************************************************************
1132 * ShowWindow (USER32.@)
1134 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1136 HWND full_handle;
1138 if (is_broadcast(hwnd))
1140 SetLastError( ERROR_INVALID_PARAMETER );
1141 return FALSE;
1143 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1144 return show_window( full_handle, cmd );
1146 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1150 /***********************************************************************
1151 * GetInternalWindowPos (USER32.@)
1153 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1154 LPPOINT ptIcon )
1156 WINDOWPLACEMENT wndpl;
1157 if (GetWindowPlacement( hwnd, &wndpl ))
1159 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1160 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1161 return wndpl.showCmd;
1163 return 0;
1167 /***********************************************************************
1168 * GetWindowPlacement (USER32.@)
1170 * Win95:
1171 * Fails if wndpl->length of Win95 (!) apps is invalid.
1173 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1175 WND *pWnd = WIN_GetPtr( hwnd );
1177 if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
1178 if (pWnd == WND_OTHER_PROCESS)
1180 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1181 return FALSE;
1184 WINPOS_InitPlacement( pWnd );
1185 wndpl->length = sizeof(*wndpl);
1186 if( pWnd->dwStyle & WS_MINIMIZE )
1187 wndpl->showCmd = SW_SHOWMINIMIZED;
1188 else
1189 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1190 if( pWnd->flags & WIN_RESTORE_MAX )
1191 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1192 else
1193 wndpl->flags = 0;
1194 wndpl->ptMinPosition = pWnd->min_pos;
1195 wndpl->ptMaxPosition = pWnd->max_pos;
1196 wndpl->rcNormalPosition = pWnd->normal_rect;
1197 WIN_ReleasePtr( pWnd );
1199 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1200 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1201 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1202 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1203 return TRUE;
1206 /* make sure the specified rect is visible on screen */
1207 static void make_rect_onscreen( RECT *rect )
1209 MONITORINFO info;
1210 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1212 info.cbSize = sizeof(info);
1213 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1214 /* FIXME: map coordinates from rcWork to rcMonitor */
1215 if (rect->right <= info.rcWork.left)
1217 rect->right += info.rcWork.left - rect->left;
1218 rect->left = info.rcWork.left;
1220 else if (rect->left >= info.rcWork.right)
1222 rect->left += info.rcWork.right - rect->right;
1223 rect->right = info.rcWork.right;
1225 if (rect->bottom <= info.rcWork.top)
1227 rect->bottom += info.rcWork.top - rect->top;
1228 rect->top = info.rcWork.top;
1230 else if (rect->top >= info.rcWork.bottom)
1232 rect->top += info.rcWork.bottom - rect->bottom;
1233 rect->bottom = info.rcWork.bottom;
1237 /* make sure the specified point is visible on screen */
1238 static void make_point_onscreen( POINT *pt )
1240 RECT rect;
1242 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1243 make_rect_onscreen( &rect );
1244 pt->x = rect.left;
1245 pt->y = rect.top;
1249 /***********************************************************************
1250 * WINPOS_SetPlacement
1252 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1254 DWORD style;
1255 WND *pWnd = WIN_GetPtr( hwnd );
1256 WINDOWPLACEMENT wp = *wndpl;
1258 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1259 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1260 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1262 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1263 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1264 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1265 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1266 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1267 wine_dbgstr_rect(&wp.rcNormalPosition) );
1269 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1271 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1272 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1273 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1275 style = pWnd->dwStyle;
1277 WIN_ReleasePtr( pWnd );
1279 if( style & WS_MINIMIZE )
1281 if (flags & PLACE_MIN)
1283 WINPOS_ShowIconTitle( hwnd, FALSE );
1284 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1285 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1288 else if( style & WS_MAXIMIZE )
1290 if (flags & PLACE_MAX)
1291 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1292 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1294 else if( flags & PLACE_RECT )
1295 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1296 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1297 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1298 SWP_NOZORDER | SWP_NOACTIVATE );
1300 ShowWindow( hwnd, wndpl->showCmd );
1302 if (IsIconic( hwnd ))
1304 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1306 /* SDK: ...valid only the next time... */
1307 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1309 pWnd = WIN_GetPtr( hwnd );
1310 if (pWnd && pWnd != WND_OTHER_PROCESS)
1312 pWnd->flags |= WIN_RESTORE_MAX;
1313 WIN_ReleasePtr( pWnd );
1317 return TRUE;
1321 /***********************************************************************
1322 * SetWindowPlacement (USER32.@)
1324 * Win95:
1325 * Fails if wndpl->length of Win95 (!) apps is invalid.
1327 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1329 UINT flags = PLACE_MAX | PLACE_RECT;
1330 if (!wpl) return FALSE;
1331 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1332 return WINPOS_SetPlacement( hwnd, wpl, flags );
1336 /***********************************************************************
1337 * AnimateWindow (USER32.@)
1338 * Shows/Hides a window with an animation
1339 * NO ANIMATION YET
1341 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1343 FIXME("partial stub\n");
1345 /* If trying to show/hide and it's already *
1346 * shown/hidden or invalid window, fail with *
1347 * invalid parameter */
1348 if(!IsWindow(hwnd) ||
1349 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1350 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1352 SetLastError(ERROR_INVALID_PARAMETER);
1353 return FALSE;
1356 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1358 return TRUE;
1361 /***********************************************************************
1362 * SetInternalWindowPos (USER32.@)
1364 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1365 LPRECT rect, LPPOINT pt )
1367 WINDOWPLACEMENT wndpl;
1368 UINT flags;
1370 wndpl.length = sizeof(wndpl);
1371 wndpl.showCmd = showCmd;
1372 wndpl.flags = flags = 0;
1374 if( pt )
1376 flags |= PLACE_MIN;
1377 wndpl.flags |= WPF_SETMINPOSITION;
1378 wndpl.ptMinPosition = *pt;
1380 if( rect )
1382 flags |= PLACE_RECT;
1383 wndpl.rcNormalPosition = *rect;
1385 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1389 /*******************************************************************
1390 * can_activate_window
1392 * Check if we can activate the specified window.
1394 static BOOL can_activate_window( HWND hwnd )
1396 LONG style;
1398 if (!hwnd) return FALSE;
1399 style = GetWindowLongW( hwnd, GWL_STYLE );
1400 if (!(style & WS_VISIBLE)) return FALSE;
1401 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1402 return !(style & WS_DISABLED);
1406 /*******************************************************************
1407 * WINPOS_ActivateOtherWindow
1409 * Activates window other than pWnd.
1411 void WINPOS_ActivateOtherWindow(HWND hwnd)
1413 HWND hwndTo, fg;
1415 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1417 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1418 if (can_activate_window( hwndTo )) goto done;
1421 hwndTo = hwnd;
1422 for (;;)
1424 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1425 if (can_activate_window( hwndTo )) break;
1428 done:
1429 fg = GetForegroundWindow();
1430 TRACE("win = %p fg = %p\n", hwndTo, fg);
1431 if (!fg || (hwnd == fg))
1433 if (SetForegroundWindow( hwndTo )) return;
1435 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1439 /***********************************************************************
1440 * WINPOS_HandleWindowPosChanging
1442 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1444 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1446 POINT minTrack, maxTrack;
1447 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1449 if (winpos->flags & SWP_NOSIZE) return 0;
1450 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1452 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1453 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1454 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1455 if (!(style & WS_MINIMIZE))
1457 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1458 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1461 return 0;
1465 /***********************************************************************
1466 * dump_winpos_flags
1468 static void dump_winpos_flags(UINT flags)
1470 TRACE("flags:");
1471 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1472 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1473 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1474 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1475 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1476 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1477 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1478 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1479 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1480 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1481 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1482 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1483 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1485 #define DUMPED_FLAGS \
1486 (SWP_NOSIZE | \
1487 SWP_NOMOVE | \
1488 SWP_NOZORDER | \
1489 SWP_NOREDRAW | \
1490 SWP_NOACTIVATE | \
1491 SWP_FRAMECHANGED | \
1492 SWP_SHOWWINDOW | \
1493 SWP_HIDEWINDOW | \
1494 SWP_NOCOPYBITS | \
1495 SWP_NOOWNERZORDER | \
1496 SWP_NOSENDCHANGING | \
1497 SWP_DEFERERASE | \
1498 SWP_ASYNCWINDOWPOS)
1500 if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1501 TRACE("\n");
1502 #undef DUMPED_FLAGS
1505 /***********************************************************************
1506 * SWP_DoWinPosChanging
1508 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1510 WND *wndPtr;
1512 /* Send WM_WINDOWPOSCHANGING message */
1514 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1515 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1517 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1518 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1520 /* Calculate new position and size */
1522 *pNewWindowRect = wndPtr->rectWindow;
1523 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1524 : wndPtr->rectClient;
1526 if (!(pWinpos->flags & SWP_NOSIZE))
1528 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1529 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1531 if (!(pWinpos->flags & SWP_NOMOVE))
1533 pNewWindowRect->left = pWinpos->x;
1534 pNewWindowRect->top = pWinpos->y;
1535 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1536 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1538 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1539 pWinpos->y - wndPtr->rectWindow.top );
1541 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1543 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1544 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1545 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1546 TRACE( "current %s style %08x new %s\n",
1547 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1548 wine_dbgstr_rect( pNewWindowRect ));
1550 WIN_ReleasePtr( wndPtr );
1551 return TRUE;
1554 /***********************************************************************
1555 * get_valid_rects
1557 * Compute the valid rects from the old and new client rect and WVR_* flags.
1558 * Helper for WM_NCCALCSIZE handling.
1560 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1561 RECT *valid )
1563 int cx, cy;
1565 if (flags & WVR_REDRAW)
1567 SetRectEmpty( &valid[0] );
1568 SetRectEmpty( &valid[1] );
1569 return;
1572 if (flags & WVR_VALIDRECTS)
1574 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1575 !IntersectRect( &valid[1], &valid[1], old_client ))
1577 SetRectEmpty( &valid[0] );
1578 SetRectEmpty( &valid[1] );
1579 return;
1581 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1583 else
1585 valid[0] = *new_client;
1586 valid[1] = *old_client;
1589 /* make sure the rectangles have the same size */
1590 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1591 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1593 if (flags & WVR_ALIGNBOTTOM)
1595 valid[0].top = valid[0].bottom - cy;
1596 valid[1].top = valid[1].bottom - cy;
1598 else
1600 valid[0].bottom = valid[0].top + cy;
1601 valid[1].bottom = valid[1].top + cy;
1603 if (flags & WVR_ALIGNRIGHT)
1605 valid[0].left = valid[0].right - cx;
1606 valid[1].left = valid[1].right - cx;
1608 else
1610 valid[0].right = valid[0].left + cx;
1611 valid[1].right = valid[1].left + cx;
1616 /***********************************************************************
1617 * SWP_DoOwnedPopups
1619 * fix Z order taking into account owned popups -
1620 * basically we need to maintain them above the window that owns them
1622 * FIXME: hide/show owned popups when owner visibility changes.
1624 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1626 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1627 HWND owner, *list = NULL;
1628 unsigned int i;
1630 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1632 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1634 /* make sure this popup stays above the owner */
1636 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1638 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1640 for (i = 0; list[i]; i++)
1642 if (list[i] == owner)
1644 if (i > 0) hwndInsertAfter = list[i-1];
1645 else hwndInsertAfter = HWND_TOP;
1646 break;
1649 if (hwndInsertAfter == HWND_NOTOPMOST)
1651 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1653 else if (list[i] == hwndInsertAfter) break;
1657 else if (style & WS_CHILD) return hwndInsertAfter;
1659 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1660 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1662 i = 0;
1663 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1665 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1667 /* skip all the topmost windows */
1668 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1671 else if (hwndInsertAfter != HWND_TOPMOST)
1673 /* skip windows that are already placed correctly */
1674 for (i = 0; list[i]; i++)
1676 if (list[i] == hwndInsertAfter) break;
1677 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1681 for ( ; list[i]; i++)
1683 if (list[i] == hwnd) break;
1684 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1685 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1686 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1687 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1688 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1689 hwndInsertAfter = list[i];
1692 done:
1693 HeapFree( GetProcessHeap(), 0, list );
1694 return hwndInsertAfter;
1697 /***********************************************************************
1698 * SWP_DoNCCalcSize
1700 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1701 RECT *validRects )
1703 UINT wvrFlags = 0;
1704 WND *wndPtr;
1706 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1708 /* Send WM_NCCALCSIZE message to get new client area */
1709 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1711 NCCALCSIZE_PARAMS params;
1712 WINDOWPOS winposCopy;
1714 params.rgrc[0] = *pNewWindowRect;
1715 params.rgrc[1] = wndPtr->rectWindow;
1716 params.rgrc[2] = wndPtr->rectClient;
1717 params.lppos = &winposCopy;
1718 winposCopy = *pWinpos;
1719 WIN_ReleasePtr( wndPtr );
1721 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1723 *pNewClientRect = params.rgrc[0];
1725 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1727 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1728 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1729 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1731 if( pNewClientRect->left != wndPtr->rectClient.left ||
1732 pNewClientRect->top != wndPtr->rectClient.top )
1733 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1735 if( (pNewClientRect->right - pNewClientRect->left !=
1736 wndPtr->rectClient.right - wndPtr->rectClient.left))
1737 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1738 else
1739 wvrFlags &= ~WVR_HREDRAW;
1741 if (pNewClientRect->bottom - pNewClientRect->top !=
1742 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1743 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1744 else
1745 wvrFlags &= ~WVR_VREDRAW;
1747 validRects[0] = params.rgrc[1];
1748 validRects[1] = params.rgrc[2];
1750 else
1752 if (!(pWinpos->flags & SWP_NOMOVE) &&
1753 (pNewClientRect->left != wndPtr->rectClient.left ||
1754 pNewClientRect->top != wndPtr->rectClient.top))
1755 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1758 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1760 SetRectEmpty( &validRects[0] );
1761 SetRectEmpty( &validRects[1] );
1763 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1765 WIN_ReleasePtr( wndPtr );
1766 return wvrFlags;
1769 /* fix redundant flags and values in the WINDOWPOS structure */
1770 static BOOL fixup_flags( WINDOWPOS *winpos )
1772 HWND parent;
1773 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1774 BOOL ret = TRUE;
1776 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1778 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1779 return FALSE;
1781 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1783 /* Finally make sure that all coordinates are valid */
1784 if (winpos->x < -32768) winpos->x = -32768;
1785 else if (winpos->x > 32767) winpos->x = 32767;
1786 if (winpos->y < -32768) winpos->y = -32768;
1787 else if (winpos->y > 32767) winpos->y = 32767;
1789 if (winpos->cx < 0) winpos->cx = 0;
1790 else if (winpos->cx > 32767) winpos->cx = 32767;
1791 if (winpos->cy < 0) winpos->cy = 0;
1792 else if (winpos->cy > 32767) winpos->cy = 32767;
1794 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1795 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1797 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1798 else
1800 winpos->flags &= ~SWP_HIDEWINDOW;
1801 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1804 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1805 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1806 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1808 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1809 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1811 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1813 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1814 (winpos->flags & SWP_NOZORDER ||
1815 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1817 winpos->flags &= ~SWP_NOZORDER;
1818 winpos->hwndInsertAfter = HWND_TOP;
1822 /* Check hwndInsertAfter */
1823 if (winpos->flags & SWP_NOZORDER) goto done;
1825 /* fix sign extension */
1826 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1827 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1829 /* hwndInsertAfter must be a sibling of the window */
1830 if (winpos->hwndInsertAfter == HWND_TOP)
1832 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1833 winpos->flags |= SWP_NOZORDER;
1835 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1837 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1838 winpos->flags |= SWP_NOZORDER;
1840 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1842 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1843 winpos->flags |= SWP_NOZORDER;
1845 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1847 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1848 winpos->flags |= SWP_NOZORDER;
1850 else
1852 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1853 else
1855 /* don't need to change the Zorder of hwnd if it's already inserted
1856 * after hwndInsertAfter or when inserting hwnd after itself.
1858 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1859 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1860 winpos->flags |= SWP_NOZORDER;
1863 done:
1864 WIN_ReleasePtr( wndPtr );
1865 return ret;
1869 /***********************************************************************
1870 * set_window_pos
1872 * Backend implementation of SetWindowPos.
1874 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1875 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1877 WND *win;
1878 BOOL ret;
1879 RECT visible_rect, old_window_rect;
1880 DWORD new_style;
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 (!IsRectEmpty( &valid_rects[0] ))
1900 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1901 if ((ret = !wine_server_call( req )))
1903 win->dwStyle = reply->new_style;
1904 win->dwExStyle = reply->new_ex_style;
1905 win->rectWindow = *window_rect;
1906 win->rectClient = *client_rect;
1907 visible_rect.left = reply->visible.left;
1908 visible_rect.top = reply->visible.top;
1909 visible_rect.right = reply->visible.right;
1910 visible_rect.bottom = reply->visible.bottom;
1913 SERVER_END_REQ;
1914 new_style = win->dwStyle;
1915 WIN_ReleasePtr( win );
1917 if (ret)
1919 USER_Driver->pSetWindowPos( hwnd, insert_after, swp_flags, window_rect,
1920 client_rect, &visible_rect, valid_rects );
1922 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
1923 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
1924 invalidate_dce( hwnd, &old_window_rect );
1926 return ret;
1930 /***********************************************************************
1931 * USER_SetWindowPos
1933 * User32 internal function
1935 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1937 RECT newWindowRect, newClientRect, valid_rects[2];
1938 UINT orig_flags;
1940 orig_flags = winpos->flags;
1942 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1943 if (!(winpos->flags & SWP_NOMOVE))
1945 if (winpos->x < -32768) winpos->x = -32768;
1946 else if (winpos->x > 32767) winpos->x = 32767;
1947 if (winpos->y < -32768) winpos->y = -32768;
1948 else if (winpos->y > 32767) winpos->y = 32767;
1950 if (!(winpos->flags & SWP_NOSIZE))
1952 if (winpos->cx < 0) winpos->cx = 0;
1953 else if (winpos->cx > 32767) winpos->cx = 32767;
1954 if (winpos->cy < 0) winpos->cy = 0;
1955 else if (winpos->cy > 32767) winpos->cy = 32767;
1958 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1960 /* Fix redundant flags */
1961 if (!fixup_flags( winpos )) return FALSE;
1963 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1965 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1966 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1969 /* Common operations */
1971 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1973 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1974 &newWindowRect, &newClientRect, valid_rects ))
1975 return FALSE;
1977 /* erase parent when hiding or resizing child */
1978 if (!(orig_flags & SWP_DEFERERASE) &&
1979 ((orig_flags & SWP_HIDEWINDOW) ||
1980 (!(orig_flags & SWP_SHOWWINDOW) &&
1981 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1983 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1984 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1985 erase_now( parent, 0 );
1988 if( winpos->flags & SWP_HIDEWINDOW )
1989 HideCaret(winpos->hwnd);
1990 else if (winpos->flags & SWP_SHOWWINDOW)
1991 ShowCaret(winpos->hwnd);
1993 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
1995 /* child windows get WM_CHILDACTIVATE message */
1996 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1997 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1998 else
1999 SetForegroundWindow( winpos->hwnd );
2002 /* And last, send the WM_WINDOWPOSCHANGED message */
2004 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2006 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2008 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2009 and always contains final window position.
2011 winpos->x = newWindowRect.left;
2012 winpos->y = newWindowRect.top;
2013 winpos->cx = newWindowRect.right - newWindowRect.left;
2014 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2015 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2017 return TRUE;
2020 /***********************************************************************
2021 * SetWindowPos (USER32.@)
2023 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2024 INT x, INT y, INT cx, INT cy, UINT flags )
2026 WINDOWPOS winpos;
2028 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2029 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2030 if(TRACE_ON(win)) dump_winpos_flags(flags);
2032 if (is_broadcast(hwnd))
2034 SetLastError( ERROR_INVALID_PARAMETER );
2035 return FALSE;
2038 winpos.hwnd = WIN_GetFullHandle(hwnd);
2039 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2040 winpos.x = x;
2041 winpos.y = y;
2042 winpos.cx = cx;
2043 winpos.cy = cy;
2044 winpos.flags = flags;
2046 if (WIN_IsCurrentThread( hwnd ))
2047 return USER_SetWindowPos(&winpos);
2049 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2053 /***********************************************************************
2054 * BeginDeferWindowPos (USER32.@)
2056 HDWP WINAPI BeginDeferWindowPos( INT count )
2058 HDWP handle;
2059 DWP *pDWP;
2061 TRACE("%d\n", count);
2063 if (count < 0)
2065 SetLastError(ERROR_INVALID_PARAMETER);
2066 return 0;
2068 /* Windows allows zero count, in which case it allocates context for 8 moves */
2069 if (count == 0) count = 8;
2071 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2072 if (!handle) return 0;
2073 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2074 pDWP->actualCount = 0;
2075 pDWP->suggestedCount = count;
2076 pDWP->valid = TRUE;
2077 pDWP->wMagic = DWP_MAGIC;
2078 pDWP->hwndParent = 0;
2080 TRACE("returning hdwp %p\n", handle);
2081 return handle;
2085 /***********************************************************************
2086 * DeferWindowPos (USER32.@)
2088 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2089 INT x, INT y, INT cx, INT cy,
2090 UINT flags )
2092 DWP *pDWP;
2093 int i;
2094 HDWP newhdwp = hdwp,retvalue;
2096 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2097 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2099 hwnd = WIN_GetFullHandle( hwnd );
2100 if (hwnd == GetDesktopWindow()) return 0;
2102 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2104 USER_Lock();
2106 for (i = 0; i < pDWP->actualCount; i++)
2108 if (pDWP->winPos[i].hwnd == hwnd)
2110 /* Merge with the other changes */
2111 if (!(flags & SWP_NOZORDER))
2113 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2115 if (!(flags & SWP_NOMOVE))
2117 pDWP->winPos[i].x = x;
2118 pDWP->winPos[i].y = y;
2120 if (!(flags & SWP_NOSIZE))
2122 pDWP->winPos[i].cx = cx;
2123 pDWP->winPos[i].cy = cy;
2125 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2126 SWP_NOZORDER | SWP_NOREDRAW |
2127 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2128 SWP_NOOWNERZORDER);
2129 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2130 SWP_FRAMECHANGED);
2131 retvalue = hdwp;
2132 goto END;
2135 if (pDWP->actualCount >= pDWP->suggestedCount)
2137 newhdwp = USER_HEAP_REALLOC( hdwp,
2138 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2139 if (!newhdwp)
2141 retvalue = 0;
2142 goto END;
2144 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2145 pDWP->suggestedCount++;
2147 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2148 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2149 pDWP->winPos[pDWP->actualCount].x = x;
2150 pDWP->winPos[pDWP->actualCount].y = y;
2151 pDWP->winPos[pDWP->actualCount].cx = cx;
2152 pDWP->winPos[pDWP->actualCount].cy = cy;
2153 pDWP->winPos[pDWP->actualCount].flags = flags;
2154 pDWP->actualCount++;
2155 retvalue = newhdwp;
2156 END:
2157 USER_Unlock();
2158 return retvalue;
2162 /***********************************************************************
2163 * EndDeferWindowPos (USER32.@)
2165 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2167 DWP *pDWP;
2168 WINDOWPOS *winpos;
2169 BOOL res = TRUE;
2170 int i;
2172 TRACE("%p\n", hdwp);
2174 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2175 if (!pDWP) return FALSE;
2176 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2178 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2179 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2180 winpos->cx, winpos->cy, winpos->flags);
2182 if (!(res = USER_SetWindowPos( winpos ))) break;
2184 USER_HEAP_FREE( hdwp );
2185 return res;
2189 /***********************************************************************
2190 * ArrangeIconicWindows (USER32.@)
2192 UINT WINAPI ArrangeIconicWindows( HWND parent )
2194 RECT rectParent;
2195 HWND hwndChild;
2196 INT x, y, xspacing, yspacing;
2198 GetClientRect( parent, &rectParent );
2199 x = rectParent.left;
2200 y = rectParent.bottom;
2201 xspacing = GetSystemMetrics(SM_CXICONSPACING);
2202 yspacing = GetSystemMetrics(SM_CYICONSPACING);
2204 hwndChild = GetWindow( parent, GW_CHILD );
2205 while (hwndChild)
2207 if( IsIconic( hwndChild ) )
2209 WINPOS_ShowIconTitle( hwndChild, FALSE );
2211 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
2212 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
2213 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
2214 if( IsWindow(hwndChild) )
2215 WINPOS_ShowIconTitle(hwndChild , TRUE );
2217 if (x <= rectParent.right - xspacing) x += xspacing;
2218 else
2220 x = rectParent.left;
2221 y -= yspacing;
2224 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
2226 return yspacing;
2230 /***********************************************************************
2231 * draw_moving_frame
2233 * Draw the frame used when moving or resizing window.
2235 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
2237 if (thickframe)
2239 const int width = GetSystemMetrics(SM_CXFRAME);
2240 const int height = GetSystemMetrics(SM_CYFRAME);
2242 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
2243 PatBlt( hdc, rect->left, rect->top,
2244 rect->right - rect->left - width, height, PATINVERT );
2245 PatBlt( hdc, rect->left, rect->top + height, width,
2246 rect->bottom - rect->top - height, PATINVERT );
2247 PatBlt( hdc, rect->left + width, rect->bottom - 1,
2248 rect->right - rect->left - width, -height, PATINVERT );
2249 PatBlt( hdc, rect->right - 1, rect->top, -width,
2250 rect->bottom - rect->top - height, PATINVERT );
2251 SelectObject( hdc, hbrush );
2253 else DrawFocusRect( hdc, rect );
2257 /***********************************************************************
2258 * start_size_move
2260 * Initialization of a move or resize, when initiated from a menu choice.
2261 * Return hit test code for caption or sizing border.
2263 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
2265 LONG hittest = 0;
2266 POINT pt;
2267 MSG msg;
2268 RECT rectWindow;
2270 GetWindowRect( hwnd, &rectWindow );
2272 if ((wParam & 0xfff0) == SC_MOVE)
2274 /* Move pointer at the center of the caption */
2275 RECT rect = rectWindow;
2276 /* Note: to be exactly centered we should take the different types
2277 * of border into account, but it shouldn't make more than a few pixels
2278 * of difference so let's not bother with that */
2279 rect.top += GetSystemMetrics(SM_CYBORDER);
2280 if (style & WS_SYSMENU)
2281 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2282 if (style & WS_MINIMIZEBOX)
2283 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2284 if (style & WS_MAXIMIZEBOX)
2285 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2286 pt.x = (rect.right + rect.left) / 2;
2287 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2288 hittest = HTCAPTION;
2289 *capturePoint = pt;
2291 else /* SC_SIZE */
2293 SetCursor( LoadCursorW( 0, (LPWSTR)IDC_SIZEALL ) );
2294 pt.x = pt.y = 0;
2295 while(!hittest)
2297 if (!GetMessageW( &msg, 0, 0, 0 )) return 0;
2298 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2300 switch(msg.message)
2302 case WM_MOUSEMOVE:
2303 pt = msg.pt;
2304 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
2305 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
2306 break;
2308 case WM_LBUTTONUP:
2309 return 0;
2311 case WM_KEYDOWN:
2312 switch(msg.wParam)
2314 case VK_UP:
2315 hittest = HTTOP;
2316 pt.x =(rectWindow.left+rectWindow.right)/2;
2317 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2318 break;
2319 case VK_DOWN:
2320 hittest = HTBOTTOM;
2321 pt.x =(rectWindow.left+rectWindow.right)/2;
2322 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2323 break;
2324 case VK_LEFT:
2325 hittest = HTLEFT;
2326 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2327 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2328 break;
2329 case VK_RIGHT:
2330 hittest = HTRIGHT;
2331 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2332 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2333 break;
2334 case VK_RETURN:
2335 case VK_ESCAPE:
2336 return 0;
2338 break;
2339 default:
2340 TranslateMessage( &msg );
2341 DispatchMessageW( &msg );
2342 break;
2345 *capturePoint = pt;
2347 SetCursorPos( pt.x, pt.y );
2348 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
2349 return hittest;
2353 /***********************************************************************
2354 * WINPOS_SysCommandSizeMove
2356 * Perform SC_MOVE and SC_SIZE commands.
2358 void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
2360 MSG msg;
2361 RECT sizingRect, mouseRect, origRect;
2362 HDC hdc;
2363 HWND parent;
2364 LONG hittest = (LONG)(wParam & 0x0f);
2365 WPARAM syscommand = wParam & 0xfff0;
2366 HCURSOR hDragCursor = 0, hOldCursor = 0;
2367 POINT minTrack, maxTrack;
2368 POINT capturePoint, pt;
2369 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2370 BOOL thickframe = HAS_THICKFRAME( style );
2371 BOOL iconic = style & WS_MINIMIZE;
2372 BOOL moved = FALSE;
2373 DWORD dwPoint = GetMessagePos ();
2374 BOOL DragFullWindows = TRUE;
2376 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
2378 pt.x = (short)LOWORD(dwPoint);
2379 pt.y = (short)HIWORD(dwPoint);
2380 capturePoint = pt;
2382 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2383 hwnd, syscommand, hittest, pt.x, pt.y);
2385 if (USER_Driver->pSysCommandSizeMove( hwnd, wParam )) return;
2387 if (syscommand == SC_MOVE)
2389 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2390 if (!hittest) return;
2392 else /* SC_SIZE */
2394 if ( hittest && (syscommand != SC_MOUSEMENU) )
2395 hittest += (HTLEFT - WMSZ_LEFT);
2396 else
2398 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2399 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2400 if (!hittest)
2402 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2403 return;
2408 /* Get min/max info */
2410 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
2411 GetWindowRect( hwnd, &sizingRect );
2412 if (style & WS_CHILD)
2414 parent = GetParent(hwnd);
2415 /* make sizing rect relative to parent */
2416 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
2417 GetClientRect( parent, &mouseRect );
2419 else
2421 parent = 0;
2422 GetClientRect( GetDesktopWindow(), &mouseRect );
2423 mouseRect.left = GetSystemMetrics( SM_XVIRTUALSCREEN );
2424 mouseRect.top = GetSystemMetrics( SM_YVIRTUALSCREEN );
2425 mouseRect.right = mouseRect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
2426 mouseRect.bottom = mouseRect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
2428 origRect = sizingRect;
2430 if (ON_LEFT_BORDER(hittest))
2432 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2433 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2435 else if (ON_RIGHT_BORDER(hittest))
2437 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2438 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2440 if (ON_TOP_BORDER(hittest))
2442 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2443 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2445 else if (ON_BOTTOM_BORDER(hittest))
2447 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2448 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2450 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2452 /* Retrieve a default cache DC (without using the window style) */
2453 hdc = GetDCEx( parent, 0, DCX_CACHE );
2455 if( iconic ) /* create a cursor for dragging */
2457 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
2458 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
2459 if( !hDragCursor ) iconic = FALSE;
2462 /* we only allow disabling the full window drag for child windows */
2463 if (parent) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0 );
2465 /* repaint the window before moving it around */
2466 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2468 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2469 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2471 while(1)
2473 int dx = 0, dy = 0;
2475 if (!GetMessageW( &msg, 0, 0, 0 )) break;
2476 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2478 /* Exit on button-up, Return, or Esc */
2479 if ((msg.message == WM_LBUTTONUP) ||
2480 ((msg.message == WM_KEYDOWN) &&
2481 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2483 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2485 TranslateMessage( &msg );
2486 DispatchMessageW( &msg );
2487 continue; /* We are not interested in other messages */
2490 pt = msg.pt;
2492 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2494 case VK_UP: pt.y -= 8; break;
2495 case VK_DOWN: pt.y += 8; break;
2496 case VK_LEFT: pt.x -= 8; break;
2497 case VK_RIGHT: pt.x += 8; break;
2500 pt.x = max( pt.x, mouseRect.left );
2501 pt.x = min( pt.x, mouseRect.right );
2502 pt.y = max( pt.y, mouseRect.top );
2503 pt.y = min( pt.y, mouseRect.bottom );
2505 dx = pt.x - capturePoint.x;
2506 dy = pt.y - capturePoint.y;
2508 if (dx || dy)
2510 if( !moved )
2512 moved = TRUE;
2514 if( iconic ) /* ok, no system popup tracking */
2516 hOldCursor = SetCursor(hDragCursor);
2517 ShowCursor( TRUE );
2518 WINPOS_ShowIconTitle( hwnd, FALSE );
2520 else if(!DragFullWindows)
2521 draw_moving_frame( hdc, &sizingRect, thickframe );
2524 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2525 else
2527 RECT newRect = sizingRect;
2528 WPARAM wpSizingHit = 0;
2530 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2531 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2532 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2533 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2534 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2535 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2536 capturePoint = pt;
2538 /* determine the hit location */
2539 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2540 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2541 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2543 if (!iconic)
2545 if(!DragFullWindows)
2546 draw_moving_frame( hdc, &newRect, thickframe );
2547 else
2548 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2549 newRect.right - newRect.left,
2550 newRect.bottom - newRect.top,
2551 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2553 sizingRect = newRect;
2558 if( iconic )
2560 if( moved ) /* restore cursors, show icon title later on */
2562 ShowCursor( FALSE );
2563 SetCursor( hOldCursor );
2566 else if (moved && !DragFullWindows)
2568 draw_moving_frame( hdc, &sizingRect, thickframe );
2571 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2572 ReleaseDC( parent, hdc );
2574 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2575 moved = FALSE;
2577 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2578 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2580 /* window moved or resized */
2581 if (moved)
2583 /* if the moving/resizing isn't canceled call SetWindowPos
2584 * with the new position or the new size of the window
2586 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2588 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2589 if(!DragFullWindows)
2590 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2591 sizingRect.right - sizingRect.left,
2592 sizingRect.bottom - sizingRect.top,
2593 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2595 else
2596 { /* restore previous size/position */
2597 if(DragFullWindows)
2598 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2599 origRect.right - origRect.left,
2600 origRect.bottom - origRect.top,
2601 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2605 if (IsIconic(hwnd))
2607 /* Single click brings up the system menu when iconized */
2609 if( !moved )
2611 if(style & WS_SYSMENU )
2612 SendMessageW( hwnd, WM_SYSCOMMAND,
2613 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2615 else WINPOS_ShowIconTitle( hwnd, TRUE );