user32: Return a proper rectangle from WINPOS_MinMaximize.
[wine/multimedia.git] / dlls / user32 / winpos.c
blobfed65e9bb5e0824e8e0c734c0455bad40f323768
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "wine/server.h"
34 #include "controls.h"
35 #include "user_private.h"
36 #include "win.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define PLACE_MIN 0x0001
68 #define PLACE_MAX 0x0002
69 #define PLACE_RECT 0x0004
72 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
74 typedef struct
76 INT actualCount;
77 INT suggestedCount;
78 BOOL valid;
79 INT wMagic;
80 HWND hwndParent;
81 WINDOWPOS winPos[1];
82 } DWP;
85 /***********************************************************************
86 * SwitchToThisWindow (USER32.@)
88 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
90 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
99 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
100 if (ret)
102 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd, wine_dbgstr_rect(rect) );
105 return ret;
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
114 int nRet = ERROR;
115 NTSTATUS status;
116 HRGN win_rgn = 0;
117 RGNDATA *data;
118 size_t size = 256;
122 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
124 SetLastError( ERROR_OUTOFMEMORY );
125 return ERROR;
127 SERVER_START_REQ( get_window_region )
129 req->window = hwnd;
130 wine_server_set_reply( req, data->Buffer, size );
131 if (!(status = wine_server_call( req )))
133 size_t reply_size = wine_server_reply_size( reply );
134 if (reply_size)
136 data->rdh.dwSize = sizeof(data->rdh);
137 data->rdh.iType = RDH_RECTANGLES;
138 data->rdh.nCount = reply_size / sizeof(RECT);
139 data->rdh.nRgnSize = reply_size;
140 win_rgn = ExtCreateRegion( NULL, size, data );
143 else size = reply->total_size;
145 SERVER_END_REQ;
146 HeapFree( GetProcessHeap(), 0, data );
147 } while (status == STATUS_BUFFER_OVERFLOW);
149 if (status) SetLastError( RtlNtStatusToDosError(status) );
150 else if (win_rgn)
152 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
153 DeleteObject( win_rgn );
155 return nRet;
159 /***********************************************************************
160 * SetWindowRgn (USER32.@)
162 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
164 static const RECT empty_rect;
165 BOOL ret;
167 if (hrgn)
169 RGNDATA *data;
170 DWORD size;
172 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
173 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
174 if (!GetRegionData( hrgn, size, data ))
176 HeapFree( GetProcessHeap(), 0, data );
177 return FALSE;
179 SERVER_START_REQ( set_window_region )
181 req->window = hwnd;
182 req->redraw = (bRedraw != 0);
183 if (data->rdh.nCount)
184 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
185 else
186 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
187 ret = !wine_server_call_err( req );
189 SERVER_END_REQ;
191 else /* clear existing region */
193 SERVER_START_REQ( set_window_region )
195 req->window = hwnd;
196 req->redraw = (bRedraw != 0);
197 ret = !wine_server_call_err( req );
199 SERVER_END_REQ;
202 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
204 if (ret)
206 UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
207 if (!bRedraw) swp_flags |= SWP_NOREDRAW;
208 SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
209 invalidate_dce( hwnd, NULL );
211 return ret;
215 /***********************************************************************
216 * GetClientRect (USER32.@)
218 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
220 BOOL ret;
222 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
224 rect->right -= rect->left;
225 rect->bottom -= rect->top;
226 rect->left = rect->top = 0;
228 return ret;
232 /*******************************************************************
233 * ClientToScreen (USER32.@)
235 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
237 MapWindowPoints( hwnd, 0, lppnt, 1 );
238 return TRUE;
242 /*******************************************************************
243 * ScreenToClient (USER32.@)
245 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
247 MapWindowPoints( 0, hwnd, lppnt, 1 );
248 return TRUE;
252 /***********************************************************************
253 * list_children_from_point
255 * Get the list of children that can contain point from the server.
256 * Point is in screen coordinates.
257 * Returned list must be freed by caller.
259 static HWND *list_children_from_point( HWND hwnd, POINT pt )
261 HWND *list;
262 int size = 128;
264 for (;;)
266 int count = 0;
268 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
270 SERVER_START_REQ( get_window_children_from_point )
272 req->parent = hwnd;
273 req->x = pt.x;
274 req->y = pt.y;
275 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
276 if (!wine_server_call( req )) count = reply->count;
278 SERVER_END_REQ;
279 if (count && count < size)
281 list[count] = 0;
282 return list;
284 HeapFree( GetProcessHeap(), 0, list );
285 if (!count) break;
286 size = count + 1; /* restart with a large enough buffer */
288 return NULL;
292 /***********************************************************************
293 * WINPOS_WindowFromPoint
295 * Find the window and hittest for a given point.
297 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
299 int i, res;
300 HWND ret, *list;
302 if (!hwndScope) hwndScope = GetDesktopWindow();
304 *hittest = HTNOWHERE;
306 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
308 /* now determine the hittest */
310 for (i = 0; list[i]; i++)
312 LONG style = GetWindowLongW( list[i], GWL_STYLE );
314 /* If window is minimized or disabled, return at once */
315 if (style & WS_MINIMIZE)
317 *hittest = HTCAPTION;
318 break;
320 if (style & WS_DISABLED)
322 *hittest = HTERROR;
323 break;
325 /* Send WM_NCCHITTEST (if same thread) */
326 if (!WIN_IsCurrentThread( list[i] ))
328 *hittest = HTCLIENT;
329 break;
331 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
332 if (res != HTTRANSPARENT)
334 *hittest = res; /* Found the window */
335 break;
337 /* continue search with next window in z-order */
339 ret = list[i];
340 HeapFree( GetProcessHeap(), 0, list );
341 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
342 return ret;
346 /*******************************************************************
347 * WindowFromPoint (USER32.@)
349 HWND WINAPI WindowFromPoint( POINT pt )
351 INT hittest;
352 return WINPOS_WindowFromPoint( 0, pt, &hittest );
356 /*******************************************************************
357 * ChildWindowFromPoint (USER32.@)
359 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
361 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
364 /*******************************************************************
365 * RealChildWindowFromPoint (USER32.@)
367 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
369 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
372 /*******************************************************************
373 * ChildWindowFromPointEx (USER32.@)
375 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
377 /* pt is in the client coordinates */
378 HWND *list;
379 int i;
380 RECT rect;
381 HWND retvalue;
383 GetClientRect( hwndParent, &rect );
384 if (!PtInRect( &rect, pt )) return 0;
385 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
387 for (i = 0; list[i]; i++)
389 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
390 if (!PtInRect( &rect, pt )) continue;
391 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
393 LONG style = GetWindowLongW( list[i], GWL_STYLE );
394 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
395 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
397 if (uFlags & CWP_SKIPTRANSPARENT)
399 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
401 break;
403 retvalue = list[i];
404 HeapFree( GetProcessHeap(), 0, list );
405 if (!retvalue) retvalue = hwndParent;
406 return retvalue;
410 /*******************************************************************
411 * WINPOS_GetWinOffset
413 * Calculate the offset between the origin of the two windows. Used
414 * to implement MapWindowPoints.
416 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
418 WND * wndPtr;
420 offset->x = offset->y = 0;
422 /* Translate source window origin to screen coords */
423 if (hwndFrom)
425 HWND hwnd = hwndFrom;
427 while (hwnd)
429 if (hwnd == hwndTo) return;
430 if (!(wndPtr = WIN_GetPtr( hwnd )))
432 ERR( "bad hwndFrom = %p\n", hwnd );
433 return;
435 if (wndPtr == WND_DESKTOP) break;
436 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
437 if (wndPtr->parent)
439 offset->x += wndPtr->rectClient.left;
440 offset->y += wndPtr->rectClient.top;
442 hwnd = wndPtr->parent;
443 WIN_ReleasePtr( wndPtr );
447 /* Translate origin to destination window coords */
448 if (hwndTo)
450 HWND hwnd = hwndTo;
452 while (hwnd)
454 if (!(wndPtr = WIN_GetPtr( hwnd )))
456 ERR( "bad hwndTo = %p\n", hwnd );
457 return;
459 if (wndPtr == WND_DESKTOP) break;
460 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
461 if (wndPtr->parent)
463 offset->x -= wndPtr->rectClient.left;
464 offset->y -= wndPtr->rectClient.top;
466 hwnd = wndPtr->parent;
467 WIN_ReleasePtr( wndPtr );
470 return;
472 other_process: /* one of the parents may belong to another process, do it the hard way */
473 offset->x = offset->y = 0;
474 SERVER_START_REQ( get_windows_offset )
476 req->from = hwndFrom;
477 req->to = hwndTo;
478 if (!wine_server_call( req ))
480 offset->x = reply->x;
481 offset->y = reply->y;
484 SERVER_END_REQ;
488 /*******************************************************************
489 * MapWindowPoints (USER.258)
491 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
492 LPPOINT16 lppt, UINT16 count )
494 POINT offset;
496 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
497 while (count--)
499 lppt->x += offset.x;
500 lppt->y += offset.y;
501 lppt++;
506 /*******************************************************************
507 * MapWindowPoints (USER32.@)
509 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
511 POINT offset;
513 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
514 while (count--)
516 lppt->x += offset.x;
517 lppt->y += offset.y;
518 lppt++;
520 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
524 /***********************************************************************
525 * IsIconic (USER32.@)
527 BOOL WINAPI IsIconic(HWND hWnd)
529 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
533 /***********************************************************************
534 * IsZoomed (USER32.@)
536 BOOL WINAPI IsZoomed(HWND hWnd)
538 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
542 /*******************************************************************
543 * AllowSetForegroundWindow (USER32.@)
545 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
547 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
548 * implemented, then fix this function. */
549 return TRUE;
553 /*******************************************************************
554 * LockSetForegroundWindow (USER32.@)
556 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
558 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
559 * implemented, then fix this function. */
560 return TRUE;
564 /***********************************************************************
565 * BringWindowToTop (USER32.@)
567 BOOL WINAPI BringWindowToTop( HWND hwnd )
569 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
573 /***********************************************************************
574 * MoveWindow (USER32.@)
576 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
577 BOOL repaint )
579 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
580 if (!repaint) flags |= SWP_NOREDRAW;
581 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
582 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
585 /***********************************************************************
586 * WINPOS_InitPlacement
588 static void WINPOS_InitPlacement( WND* wnd )
590 if (IsRectEmpty( &wnd->normal_rect ))
592 /* this happens when the window is minimized/maximized
593 * for the first time (rectWindow is not adjusted yet) */
595 wnd->normal_rect = wnd->rectWindow;
596 wnd->min_pos.x = wnd->min_pos.y = -1;
597 wnd->max_pos.x = wnd->max_pos.y = -1;
600 if( wnd->dwStyle & WS_MINIMIZE )
602 wnd->min_pos.x = wnd->rectWindow.left;
603 wnd->min_pos.y = wnd->rectWindow.top;
605 else if( wnd->dwStyle & WS_MAXIMIZE )
607 wnd->max_pos.x = wnd->rectWindow.left;
608 wnd->max_pos.y = wnd->rectWindow.top;
610 else
612 wnd->normal_rect = wnd->rectWindow;
616 /***********************************************************************
617 * WINPOS_RedrawIconTitle
619 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
621 HWND icon_title = 0;
622 WND *win = WIN_GetPtr( hWnd );
624 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
626 icon_title = win->icon_title;
627 WIN_ReleasePtr( win );
629 if (!icon_title) return FALSE;
630 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
631 InvalidateRect( icon_title, NULL, TRUE );
632 return TRUE;
635 /***********************************************************************
636 * WINPOS_ShowIconTitle
638 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
640 if (!GetPropA( hwnd, "__wine_x11_managed" ))
642 WND *win = WIN_GetPtr( hwnd );
643 HWND title = 0;
645 TRACE("%p %i\n", hwnd, (bShow != 0) );
647 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
648 title = win->icon_title;
649 WIN_ReleasePtr( win );
651 if( bShow )
653 if (!title)
655 title = ICONTITLE_Create( hwnd );
656 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
658 DestroyWindow( title );
659 return FALSE;
661 win->icon_title = title;
662 WIN_ReleasePtr( win );
664 if (!IsWindowVisible(title))
666 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
667 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
668 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
671 else if (title) ShowWindow( title, SW_HIDE );
673 return FALSE;
676 /*******************************************************************
677 * WINPOS_GetMinMaxInfo
679 * Get the minimized and maximized information for a window.
681 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
682 POINT *minTrack, POINT *maxTrack )
684 MINMAXINFO MinMax;
685 HMONITOR monitor;
686 INT xinc, yinc;
687 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
688 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
689 RECT rc;
690 WND *win;
692 /* Compute default values */
694 GetWindowRect(hwnd, &rc);
695 MinMax.ptReserved.x = rc.left;
696 MinMax.ptReserved.y = rc.top;
698 if (style & WS_CHILD)
700 if ((style & WS_CAPTION) == WS_CAPTION)
701 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
703 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
704 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
706 /* avoid calculating this twice */
707 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
709 MinMax.ptMaxSize.x = rc.right - rc.left;
710 MinMax.ptMaxSize.y = rc.bottom - rc.top;
712 else
714 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
715 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
717 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
718 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
719 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
720 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
722 if (HAS_DLGFRAME( style, exstyle ))
724 xinc = GetSystemMetrics(SM_CXDLGFRAME);
725 yinc = GetSystemMetrics(SM_CYDLGFRAME);
727 else
729 xinc = yinc = 0;
730 if (HAS_THICKFRAME(style))
732 xinc += GetSystemMetrics(SM_CXFRAME);
733 yinc += GetSystemMetrics(SM_CYFRAME);
735 if (style & WS_BORDER)
737 xinc += GetSystemMetrics(SM_CXBORDER);
738 yinc += GetSystemMetrics(SM_CYBORDER);
741 MinMax.ptMaxSize.x += 2 * xinc;
742 MinMax.ptMaxSize.y += 2 * yinc;
744 MinMax.ptMaxPosition.x = -xinc;
745 MinMax.ptMaxPosition.y = -yinc;
746 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
748 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
749 WIN_ReleasePtr( win );
752 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
754 /* if the app didn't change the values, adapt them for the current monitor */
756 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
758 MONITORINFO mon_info;
760 mon_info.cbSize = sizeof(mon_info);
761 GetMonitorInfoW( monitor, &mon_info );
763 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
764 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
766 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
767 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
769 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
771 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
772 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
776 /* Some sanity checks */
778 TRACE("%d %d / %d %d / %d %d / %d %d\n",
779 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
780 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
781 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
782 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
783 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
784 MinMax.ptMinTrackSize.x );
785 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
786 MinMax.ptMinTrackSize.y );
788 if (maxSize) *maxSize = MinMax.ptMaxSize;
789 if (maxPos) *maxPos = MinMax.ptMaxPosition;
790 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
791 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
795 /***********************************************************************
796 * WINPOS_FindIconPos
798 * Find a suitable place for an iconic window.
800 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
802 RECT rect, rectParent;
803 HWND parent, child;
804 HRGN hrgn, tmp;
805 int xspacing, yspacing;
807 parent = GetAncestor( hwnd, GA_PARENT );
808 GetClientRect( parent, &rectParent );
809 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
810 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
811 return pt; /* The icon already has a suitable position */
813 xspacing = GetSystemMetrics(SM_CXICONSPACING);
814 yspacing = GetSystemMetrics(SM_CYICONSPACING);
816 /* Check if another icon already occupies this spot */
817 /* FIXME: this is completely inefficient */
819 hrgn = CreateRectRgn( 0, 0, 0, 0 );
820 tmp = CreateRectRgn( 0, 0, 0, 0 );
821 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
823 WND *childPtr;
824 if (child == hwnd) continue;
825 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
826 continue;
827 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
828 continue;
829 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
830 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
831 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
832 WIN_ReleasePtr( childPtr );
834 DeleteObject( tmp );
836 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
838 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
840 rect.right = rect.left + xspacing;
841 rect.top = rect.bottom - yspacing;
842 if (!RectInRegion( hrgn, &rect ))
844 /* No window was found, so it's OK for us */
845 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
846 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
847 DeleteObject( hrgn );
848 return pt;
852 DeleteObject( hrgn );
853 pt.x = pt.y = 0;
854 return pt;
858 /***********************************************************************
859 * WINPOS_MinMaximize
861 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
863 WND *wndPtr;
864 UINT swpFlags = 0;
865 POINT size;
866 LONG old_style;
867 WINDOWPLACEMENT wpl;
869 TRACE("%p %u\n", hwnd, cmd );
871 wpl.length = sizeof(wpl);
872 GetWindowPlacement( hwnd, &wpl );
874 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
875 return SWP_NOSIZE | SWP_NOMOVE;
877 if (IsIconic( hwnd ))
879 switch (cmd)
881 case SW_SHOWMINNOACTIVE:
882 case SW_SHOWMINIMIZED:
883 case SW_FORCEMINIMIZE:
884 case SW_MINIMIZE:
885 return SWP_NOSIZE | SWP_NOMOVE;
887 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
888 swpFlags |= SWP_NOCOPYBITS;
891 switch( cmd )
893 case SW_SHOWMINNOACTIVE:
894 case SW_SHOWMINIMIZED:
895 case SW_FORCEMINIMIZE:
896 case SW_MINIMIZE:
897 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
898 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
899 else wndPtr->flags &= ~WIN_RESTORE_MAX;
900 WIN_ReleasePtr( wndPtr );
902 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
904 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
906 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
907 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
908 wpl.ptMinPosition.x + GetSystemMetrics(SM_CXICON),
909 wpl.ptMinPosition.y + GetSystemMetrics(SM_CYICON) );
910 swpFlags |= SWP_NOCOPYBITS;
911 break;
913 case SW_MAXIMIZE:
914 old_style = GetWindowLongW( hwnd, GWL_STYLE );
915 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
917 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
919 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
920 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
922 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
923 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
924 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
925 break;
927 case SW_SHOWNOACTIVATE:
928 case SW_SHOWNORMAL:
929 case SW_RESTORE:
930 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
931 if (old_style & WS_MINIMIZE)
933 BOOL restore_max;
935 WINPOS_ShowIconTitle( hwnd, FALSE );
937 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
938 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
939 WIN_ReleasePtr( wndPtr );
940 if (restore_max)
942 /* Restore to maximized position */
943 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
944 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
945 swpFlags |= SWP_STATECHANGED;
946 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
947 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
948 break;
951 else if (!(old_style & WS_MAXIMIZE)) break;
953 swpFlags |= SWP_STATECHANGED;
955 /* Restore to normal position */
957 *rect = wpl.rcNormalPosition;
958 break;
961 return swpFlags;
965 /***********************************************************************
966 * show_window
968 * Implementation of ShowWindow and ShowWindowAsync.
970 static BOOL show_window( HWND hwnd, INT cmd )
972 WND *wndPtr;
973 HWND parent;
974 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
975 BOOL wasVisible = (style & WS_VISIBLE) != 0;
976 BOOL showFlag = TRUE;
977 RECT newPos = {0, 0, 0, 0};
978 UINT swp = 0;
980 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
982 switch(cmd)
984 case SW_HIDE:
985 if (!wasVisible) return FALSE;
986 showFlag = FALSE;
987 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
988 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
989 break;
991 case SW_SHOWMINNOACTIVE:
992 case SW_MINIMIZE:
993 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
994 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
995 /* fall through */
996 case SW_SHOWMINIMIZED:
997 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
998 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
999 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
1000 break;
1002 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1003 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1004 swp |= SWP_FRAMECHANGED;
1005 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1006 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
1007 break;
1009 case SW_SHOWNA:
1010 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1011 if (style & WS_CHILD) swp |= SWP_NOZORDER;
1012 break;
1013 case SW_SHOW:
1014 if (wasVisible) return TRUE;
1015 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1016 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1017 break;
1019 case SW_SHOWNOACTIVATE:
1020 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1021 /* fall through */
1022 case SW_RESTORE:
1023 /* fall through */
1024 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1025 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1026 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1027 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1029 swp |= SWP_FRAMECHANGED;
1030 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1032 else
1034 if (wasVisible) return TRUE;
1035 swp |= SWP_NOSIZE | SWP_NOMOVE;
1037 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1038 break;
1039 default:
1040 return wasVisible;
1043 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1045 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1046 if (!IsWindow( hwnd )) return wasVisible;
1049 parent = GetAncestor( hwnd, GA_PARENT );
1050 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1052 /* if parent is not visible simply toggle WS_VISIBLE and return */
1053 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1054 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1056 else
1057 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1058 newPos.right - newPos.left, newPos.bottom - newPos.top, swp );
1060 if (cmd == SW_HIDE)
1062 HWND hFocus;
1064 WINPOS_ShowIconTitle( hwnd, FALSE );
1066 /* FIXME: This will cause the window to be activated irrespective
1067 * of whether it is owned by the same thread. Has to be done
1068 * asynchronously.
1071 if (hwnd == GetActiveWindow())
1072 WINPOS_ActivateOtherWindow(hwnd);
1074 /* Revert focus to parent */
1075 hFocus = GetFocus();
1076 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1078 HWND parent = GetAncestor(hwnd, GA_PARENT);
1079 if (parent == GetDesktopWindow()) parent = 0;
1080 SetFocus(parent);
1082 return wasVisible;
1085 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1087 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1089 if (wndPtr->flags & WIN_NEED_SIZE)
1091 /* should happen only in CreateWindowEx() */
1092 int wParam = SIZE_RESTORED;
1093 RECT client = wndPtr->rectClient;
1095 wndPtr->flags &= ~WIN_NEED_SIZE;
1096 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1097 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1098 WIN_ReleasePtr( wndPtr );
1100 SendMessageW( hwnd, WM_SIZE, wParam,
1101 MAKELONG( client.right - client.left, client.bottom - client.top ));
1102 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1104 else WIN_ReleasePtr( wndPtr );
1106 /* if previous state was minimized Windows sets focus to the window */
1107 if (style & WS_MINIMIZE) SetFocus( hwnd );
1109 return wasVisible;
1113 /***********************************************************************
1114 * ShowWindowAsync (USER32.@)
1116 * doesn't wait; returns immediately.
1117 * used by threads to toggle windows in other (possibly hanging) threads
1119 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1121 HWND full_handle;
1123 if (is_broadcast(hwnd))
1125 SetLastError( ERROR_INVALID_PARAMETER );
1126 return FALSE;
1129 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1130 return show_window( full_handle, cmd );
1132 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1136 /***********************************************************************
1137 * ShowWindow (USER32.@)
1139 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1141 HWND full_handle;
1143 if (is_broadcast(hwnd))
1145 SetLastError( ERROR_INVALID_PARAMETER );
1146 return FALSE;
1148 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1149 return show_window( full_handle, cmd );
1151 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1155 /***********************************************************************
1156 * GetInternalWindowPos (USER32.@)
1158 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1159 LPPOINT ptIcon )
1161 WINDOWPLACEMENT wndpl;
1162 if (GetWindowPlacement( hwnd, &wndpl ))
1164 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1165 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1166 return wndpl.showCmd;
1168 return 0;
1172 /***********************************************************************
1173 * GetWindowPlacement (USER32.@)
1175 * Win95:
1176 * Fails if wndpl->length of Win95 (!) apps is invalid.
1178 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1180 WND *pWnd = WIN_GetPtr( hwnd );
1182 if (!pWnd) return FALSE;
1184 if (pWnd == WND_DESKTOP)
1186 wndpl->length = sizeof(*wndpl);
1187 wndpl->showCmd = SW_SHOWNORMAL;
1188 wndpl->flags = 0;
1189 wndpl->ptMinPosition.x = -1;
1190 wndpl->ptMinPosition.y = -1;
1191 wndpl->ptMaxPosition.x = -1;
1192 wndpl->ptMaxPosition.y = -1;
1193 GetWindowRect( hwnd, &wndpl->rcNormalPosition );
1194 return TRUE;
1196 if (pWnd == WND_OTHER_PROCESS)
1198 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1199 return FALSE;
1202 WINPOS_InitPlacement( pWnd );
1203 wndpl->length = sizeof(*wndpl);
1204 if( pWnd->dwStyle & WS_MINIMIZE )
1205 wndpl->showCmd = SW_SHOWMINIMIZED;
1206 else
1207 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1208 if( pWnd->flags & WIN_RESTORE_MAX )
1209 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1210 else
1211 wndpl->flags = 0;
1212 wndpl->ptMinPosition = pWnd->min_pos;
1213 wndpl->ptMaxPosition = pWnd->max_pos;
1214 wndpl->rcNormalPosition = pWnd->normal_rect;
1215 WIN_ReleasePtr( pWnd );
1217 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1218 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1219 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1220 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1221 return TRUE;
1224 /* make sure the specified rect is visible on screen */
1225 static void make_rect_onscreen( RECT *rect )
1227 MONITORINFO info;
1228 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1230 info.cbSize = sizeof(info);
1231 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1232 /* FIXME: map coordinates from rcWork to rcMonitor */
1233 if (rect->right <= info.rcWork.left)
1235 rect->right += info.rcWork.left - rect->left;
1236 rect->left = info.rcWork.left;
1238 else if (rect->left >= info.rcWork.right)
1240 rect->left += info.rcWork.right - rect->right;
1241 rect->right = info.rcWork.right;
1243 if (rect->bottom <= info.rcWork.top)
1245 rect->bottom += info.rcWork.top - rect->top;
1246 rect->top = info.rcWork.top;
1248 else if (rect->top >= info.rcWork.bottom)
1250 rect->top += info.rcWork.bottom - rect->bottom;
1251 rect->bottom = info.rcWork.bottom;
1255 /* make sure the specified point is visible on screen */
1256 static void make_point_onscreen( POINT *pt )
1258 RECT rect;
1260 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1261 make_rect_onscreen( &rect );
1262 pt->x = rect.left;
1263 pt->y = rect.top;
1267 /***********************************************************************
1268 * WINPOS_SetPlacement
1270 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1272 DWORD style;
1273 WND *pWnd = WIN_GetPtr( hwnd );
1274 WINDOWPLACEMENT wp = *wndpl;
1276 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1277 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1278 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1280 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1281 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1282 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1283 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1284 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1285 wine_dbgstr_rect(&wp.rcNormalPosition) );
1287 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1289 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1290 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1291 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1293 style = pWnd->dwStyle;
1295 WIN_ReleasePtr( pWnd );
1297 if( style & WS_MINIMIZE )
1299 if (flags & PLACE_MIN)
1301 WINPOS_ShowIconTitle( hwnd, FALSE );
1302 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1303 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1306 else if( style & WS_MAXIMIZE )
1308 if (flags & PLACE_MAX)
1309 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1310 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1312 else if( flags & PLACE_RECT )
1313 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1314 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1315 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1316 SWP_NOZORDER | SWP_NOACTIVATE );
1318 ShowWindow( hwnd, wndpl->showCmd );
1320 if (IsIconic( hwnd ))
1322 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1324 /* SDK: ...valid only the next time... */
1325 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1327 pWnd = WIN_GetPtr( hwnd );
1328 if (pWnd && pWnd != WND_OTHER_PROCESS)
1330 pWnd->flags |= WIN_RESTORE_MAX;
1331 WIN_ReleasePtr( pWnd );
1335 return TRUE;
1339 /***********************************************************************
1340 * SetWindowPlacement (USER32.@)
1342 * Win95:
1343 * Fails if wndpl->length of Win95 (!) apps is invalid.
1345 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1347 UINT flags = PLACE_MAX | PLACE_RECT;
1348 if (!wpl) return FALSE;
1349 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1350 return WINPOS_SetPlacement( hwnd, wpl, flags );
1354 /***********************************************************************
1355 * AnimateWindow (USER32.@)
1356 * Shows/Hides a window with an animation
1357 * NO ANIMATION YET
1359 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1361 FIXME("partial stub\n");
1363 /* If trying to show/hide and it's already *
1364 * shown/hidden or invalid window, fail with *
1365 * invalid parameter */
1366 if(!IsWindow(hwnd) ||
1367 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1368 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1370 SetLastError(ERROR_INVALID_PARAMETER);
1371 return FALSE;
1374 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1376 return TRUE;
1379 /***********************************************************************
1380 * SetInternalWindowPos (USER32.@)
1382 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1383 LPRECT rect, LPPOINT pt )
1385 WINDOWPLACEMENT wndpl;
1386 UINT flags;
1388 wndpl.length = sizeof(wndpl);
1389 wndpl.showCmd = showCmd;
1390 wndpl.flags = flags = 0;
1392 if( pt )
1394 flags |= PLACE_MIN;
1395 wndpl.flags |= WPF_SETMINPOSITION;
1396 wndpl.ptMinPosition = *pt;
1398 if( rect )
1400 flags |= PLACE_RECT;
1401 wndpl.rcNormalPosition = *rect;
1403 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1407 /*******************************************************************
1408 * can_activate_window
1410 * Check if we can activate the specified window.
1412 static BOOL can_activate_window( HWND hwnd )
1414 LONG style;
1416 if (!hwnd) return FALSE;
1417 style = GetWindowLongW( hwnd, GWL_STYLE );
1418 if (!(style & WS_VISIBLE)) return FALSE;
1419 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1420 return !(style & WS_DISABLED);
1424 /*******************************************************************
1425 * WINPOS_ActivateOtherWindow
1427 * Activates window other than pWnd.
1429 void WINPOS_ActivateOtherWindow(HWND hwnd)
1431 HWND hwndTo, fg;
1433 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1435 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1436 if (can_activate_window( hwndTo )) goto done;
1439 hwndTo = hwnd;
1440 for (;;)
1442 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1443 if (can_activate_window( hwndTo )) break;
1446 done:
1447 fg = GetForegroundWindow();
1448 TRACE("win = %p fg = %p\n", hwndTo, fg);
1449 if (!fg || (hwnd == fg))
1451 if (SetForegroundWindow( hwndTo )) return;
1453 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1457 /***********************************************************************
1458 * WINPOS_HandleWindowPosChanging
1460 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1462 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1464 POINT minTrack, maxTrack;
1465 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1467 if (winpos->flags & SWP_NOSIZE) return 0;
1468 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1470 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1471 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1472 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1473 if (!(style & WS_MINIMIZE))
1475 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1476 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1479 return 0;
1483 /***********************************************************************
1484 * dump_winpos_flags
1486 static void dump_winpos_flags(UINT flags)
1488 static const DWORD dumped_flags = (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW |
1489 SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW |
1490 SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOOWNERZORDER |
1491 SWP_NOSENDCHANGING | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS |
1492 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_STATECHANGED);
1493 TRACE("flags:");
1494 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1495 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1496 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1497 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1498 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1499 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1500 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1501 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1502 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1503 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1504 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1505 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1506 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1507 if(flags & SWP_NOCLIENTSIZE) TRACE(" SWP_NOCLIENTSIZE");
1508 if(flags & SWP_NOCLIENTMOVE) TRACE(" SWP_NOCLIENTMOVE");
1509 if(flags & SWP_STATECHANGED) TRACE(" SWP_STATECHANGED");
1511 if(flags & ~dumped_flags) TRACE(" %08x", flags & ~dumped_flags);
1512 TRACE("\n");
1515 /***********************************************************************
1516 * SWP_DoWinPosChanging
1518 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1520 WND *wndPtr;
1522 /* Send WM_WINDOWPOSCHANGING message */
1524 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1525 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1527 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1528 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1530 /* Calculate new position and size */
1532 *pNewWindowRect = wndPtr->rectWindow;
1533 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1534 : wndPtr->rectClient;
1536 if (!(pWinpos->flags & SWP_NOSIZE))
1538 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1539 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1541 if (!(pWinpos->flags & SWP_NOMOVE))
1543 pNewWindowRect->left = pWinpos->x;
1544 pNewWindowRect->top = pWinpos->y;
1545 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1546 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1548 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1549 pWinpos->y - wndPtr->rectWindow.top );
1551 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1553 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1554 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1555 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1556 TRACE( "current %s style %08x new %s\n",
1557 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1558 wine_dbgstr_rect( pNewWindowRect ));
1560 WIN_ReleasePtr( wndPtr );
1561 return TRUE;
1564 /***********************************************************************
1565 * get_valid_rects
1567 * Compute the valid rects from the old and new client rect and WVR_* flags.
1568 * Helper for WM_NCCALCSIZE handling.
1570 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1571 RECT *valid )
1573 int cx, cy;
1575 if (flags & WVR_REDRAW)
1577 SetRectEmpty( &valid[0] );
1578 SetRectEmpty( &valid[1] );
1579 return;
1582 if (flags & WVR_VALIDRECTS)
1584 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1585 !IntersectRect( &valid[1], &valid[1], old_client ))
1587 SetRectEmpty( &valid[0] );
1588 SetRectEmpty( &valid[1] );
1589 return;
1591 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1593 else
1595 valid[0] = *new_client;
1596 valid[1] = *old_client;
1599 /* make sure the rectangles have the same size */
1600 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1601 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1603 if (flags & WVR_ALIGNBOTTOM)
1605 valid[0].top = valid[0].bottom - cy;
1606 valid[1].top = valid[1].bottom - cy;
1608 else
1610 valid[0].bottom = valid[0].top + cy;
1611 valid[1].bottom = valid[1].top + cy;
1613 if (flags & WVR_ALIGNRIGHT)
1615 valid[0].left = valid[0].right - cx;
1616 valid[1].left = valid[1].right - cx;
1618 else
1620 valid[0].right = valid[0].left + cx;
1621 valid[1].right = valid[1].left + cx;
1626 /***********************************************************************
1627 * SWP_DoOwnedPopups
1629 * fix Z order taking into account owned popups -
1630 * basically we need to maintain them above the window that owns them
1632 * FIXME: hide/show owned popups when owner visibility changes.
1634 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1636 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1637 HWND owner, *list = NULL;
1638 unsigned int i;
1640 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1642 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1644 /* make sure this popup stays above the owner */
1646 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1648 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1650 for (i = 0; list[i]; i++)
1652 if (list[i] == owner)
1654 if (i > 0) hwndInsertAfter = list[i-1];
1655 else hwndInsertAfter = HWND_TOP;
1656 break;
1659 if (hwndInsertAfter == HWND_NOTOPMOST)
1661 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1663 else if (list[i] == hwndInsertAfter) break;
1667 else if (style & WS_CHILD) return hwndInsertAfter;
1669 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1670 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1672 i = 0;
1673 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1675 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1677 /* skip all the topmost windows */
1678 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1681 else if (hwndInsertAfter != HWND_TOPMOST)
1683 /* skip windows that are already placed correctly */
1684 for (i = 0; list[i]; i++)
1686 if (list[i] == hwndInsertAfter) break;
1687 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1691 for ( ; list[i]; i++)
1693 if (list[i] == hwnd) break;
1694 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1695 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1696 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1697 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1698 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1699 hwndInsertAfter = list[i];
1702 done:
1703 HeapFree( GetProcessHeap(), 0, list );
1704 return hwndInsertAfter;
1707 /***********************************************************************
1708 * SWP_DoNCCalcSize
1710 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1711 RECT *validRects )
1713 UINT wvrFlags = 0;
1714 WND *wndPtr;
1716 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1718 /* Send WM_NCCALCSIZE message to get new client area */
1719 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1721 NCCALCSIZE_PARAMS params;
1722 WINDOWPOS winposCopy;
1724 params.rgrc[0] = *pNewWindowRect;
1725 params.rgrc[1] = wndPtr->rectWindow;
1726 params.rgrc[2] = wndPtr->rectClient;
1727 params.lppos = &winposCopy;
1728 winposCopy = *pWinpos;
1729 WIN_ReleasePtr( wndPtr );
1731 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1733 *pNewClientRect = params.rgrc[0];
1735 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1737 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1738 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1739 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1741 if( pNewClientRect->left != wndPtr->rectClient.left ||
1742 pNewClientRect->top != wndPtr->rectClient.top )
1743 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1745 if( (pNewClientRect->right - pNewClientRect->left !=
1746 wndPtr->rectClient.right - wndPtr->rectClient.left))
1747 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1748 else
1749 wvrFlags &= ~WVR_HREDRAW;
1751 if (pNewClientRect->bottom - pNewClientRect->top !=
1752 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1753 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1754 else
1755 wvrFlags &= ~WVR_VREDRAW;
1757 validRects[0] = params.rgrc[1];
1758 validRects[1] = params.rgrc[2];
1760 else
1762 if (!(pWinpos->flags & SWP_NOMOVE) &&
1763 (pNewClientRect->left != wndPtr->rectClient.left ||
1764 pNewClientRect->top != wndPtr->rectClient.top))
1765 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1768 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1770 SetRectEmpty( &validRects[0] );
1771 SetRectEmpty( &validRects[1] );
1773 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1775 WIN_ReleasePtr( wndPtr );
1776 return wvrFlags;
1779 /* fix redundant flags and values in the WINDOWPOS structure */
1780 static BOOL fixup_flags( WINDOWPOS *winpos )
1782 HWND parent;
1783 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1784 BOOL ret = TRUE;
1786 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1788 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1789 return FALSE;
1791 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1793 /* Finally make sure that all coordinates are valid */
1794 if (winpos->x < -32768) winpos->x = -32768;
1795 else if (winpos->x > 32767) winpos->x = 32767;
1796 if (winpos->y < -32768) winpos->y = -32768;
1797 else if (winpos->y > 32767) winpos->y = 32767;
1799 if (winpos->cx < 0) winpos->cx = 0;
1800 else if (winpos->cx > 32767) winpos->cx = 32767;
1801 if (winpos->cy < 0) winpos->cy = 0;
1802 else if (winpos->cy > 32767) winpos->cy = 32767;
1804 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1805 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1807 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1808 else
1810 winpos->flags &= ~SWP_HIDEWINDOW;
1811 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1814 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1815 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1816 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1818 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1819 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1821 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1823 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1824 (winpos->flags & SWP_NOZORDER ||
1825 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1827 winpos->flags &= ~SWP_NOZORDER;
1828 winpos->hwndInsertAfter = HWND_TOP;
1832 /* Check hwndInsertAfter */
1833 if (winpos->flags & SWP_NOZORDER) goto done;
1835 /* fix sign extension */
1836 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1837 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1839 /* hwndInsertAfter must be a sibling of the window */
1840 if (winpos->hwndInsertAfter == HWND_TOP)
1842 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1843 winpos->flags |= SWP_NOZORDER;
1845 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1847 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1848 winpos->flags |= SWP_NOZORDER;
1850 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1852 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1853 winpos->flags |= SWP_NOZORDER;
1855 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1857 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1858 winpos->flags |= SWP_NOZORDER;
1860 else
1862 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1863 else
1865 /* don't need to change the Zorder of hwnd if it's already inserted
1866 * after hwndInsertAfter or when inserting hwnd after itself.
1868 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1869 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1870 winpos->flags |= SWP_NOZORDER;
1873 done:
1874 WIN_ReleasePtr( wndPtr );
1875 return ret;
1879 /***********************************************************************
1880 * set_window_pos
1882 * Backend implementation of SetWindowPos.
1884 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1885 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1887 WND *win;
1888 BOOL ret;
1889 RECT visible_rect, old_window_rect;
1891 visible_rect = *window_rect;
1892 USER_Driver->pWindowPosChanging( hwnd, insert_after, swp_flags,
1893 window_rect, client_rect, &visible_rect );
1895 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
1896 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
1898 old_window_rect = win->rectWindow;
1899 SERVER_START_REQ( set_window_pos )
1901 req->handle = hwnd;
1902 req->previous = insert_after;
1903 req->flags = swp_flags;
1904 req->window.left = window_rect->left;
1905 req->window.top = window_rect->top;
1906 req->window.right = window_rect->right;
1907 req->window.bottom = window_rect->bottom;
1908 req->client.left = client_rect->left;
1909 req->client.top = client_rect->top;
1910 req->client.right = client_rect->right;
1911 req->client.bottom = client_rect->bottom;
1912 if (memcmp( window_rect, &visible_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
1914 wine_server_add_data( req, &visible_rect, sizeof(visible_rect) );
1915 if (!IsRectEmpty( &valid_rects[0] ))
1916 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1918 if ((ret = !wine_server_call( req )))
1920 win->dwStyle = reply->new_style;
1921 win->dwExStyle = reply->new_ex_style;
1922 win->rectWindow = *window_rect;
1923 win->rectClient = *client_rect;
1926 SERVER_END_REQ;
1927 WIN_ReleasePtr( win );
1929 if (ret)
1931 if (((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) ||
1932 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW | SWP_STATECHANGED)))
1933 invalidate_dce( hwnd, &old_window_rect );
1935 USER_Driver->pWindowPosChanged( hwnd, insert_after, swp_flags, window_rect,
1936 client_rect, &visible_rect, valid_rects );
1938 return ret;
1942 /***********************************************************************
1943 * USER_SetWindowPos
1945 * User32 internal function
1947 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1949 RECT newWindowRect, newClientRect, valid_rects[2];
1950 UINT orig_flags;
1952 orig_flags = winpos->flags;
1954 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1955 if (!(winpos->flags & SWP_NOMOVE))
1957 if (winpos->x < -32768) winpos->x = -32768;
1958 else if (winpos->x > 32767) winpos->x = 32767;
1959 if (winpos->y < -32768) winpos->y = -32768;
1960 else if (winpos->y > 32767) winpos->y = 32767;
1962 if (!(winpos->flags & SWP_NOSIZE))
1964 if (winpos->cx < 0) winpos->cx = 0;
1965 else if (winpos->cx > 32767) winpos->cx = 32767;
1966 if (winpos->cy < 0) winpos->cy = 0;
1967 else if (winpos->cy > 32767) winpos->cy = 32767;
1970 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1972 /* Fix redundant flags */
1973 if (!fixup_flags( winpos )) return FALSE;
1975 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1977 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1978 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1981 /* Common operations */
1983 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1985 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1986 &newWindowRect, &newClientRect, valid_rects ))
1987 return FALSE;
1989 /* erase parent when hiding or resizing child */
1990 if (!(orig_flags & SWP_DEFERERASE) &&
1991 ((orig_flags & SWP_HIDEWINDOW) ||
1992 (!(orig_flags & SWP_SHOWWINDOW) &&
1993 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1995 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1996 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1997 erase_now( parent, 0 );
2000 if( winpos->flags & SWP_HIDEWINDOW )
2001 HideCaret(winpos->hwnd);
2002 else if (winpos->flags & SWP_SHOWWINDOW)
2003 ShowCaret(winpos->hwnd);
2005 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
2007 /* child windows get WM_CHILDACTIVATE message */
2008 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
2009 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
2010 else
2011 SetForegroundWindow( winpos->hwnd );
2014 /* And last, send the WM_WINDOWPOSCHANGED message */
2016 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2018 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2020 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2021 and always contains final window position.
2023 winpos->x = newWindowRect.left;
2024 winpos->y = newWindowRect.top;
2025 winpos->cx = newWindowRect.right - newWindowRect.left;
2026 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2027 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2029 return TRUE;
2032 /***********************************************************************
2033 * SetWindowPos (USER32.@)
2035 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2036 INT x, INT y, INT cx, INT cy, UINT flags )
2038 WINDOWPOS winpos;
2040 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2041 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2042 if(TRACE_ON(win)) dump_winpos_flags(flags);
2044 if (is_broadcast(hwnd))
2046 SetLastError( ERROR_INVALID_PARAMETER );
2047 return FALSE;
2050 winpos.hwnd = WIN_GetFullHandle(hwnd);
2051 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2052 winpos.x = x;
2053 winpos.y = y;
2054 winpos.cx = cx;
2055 winpos.cy = cy;
2056 winpos.flags = flags;
2058 if (WIN_IsCurrentThread( hwnd ))
2059 return USER_SetWindowPos(&winpos);
2061 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2065 /***********************************************************************
2066 * BeginDeferWindowPos (USER32.@)
2068 HDWP WINAPI BeginDeferWindowPos( INT count )
2070 HDWP handle;
2071 DWP *pDWP;
2073 TRACE("%d\n", count);
2075 if (count < 0)
2077 SetLastError(ERROR_INVALID_PARAMETER);
2078 return 0;
2080 /* Windows allows zero count, in which case it allocates context for 8 moves */
2081 if (count == 0) count = 8;
2083 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2084 if (!handle) return 0;
2085 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2086 pDWP->actualCount = 0;
2087 pDWP->suggestedCount = count;
2088 pDWP->valid = TRUE;
2089 pDWP->wMagic = DWP_MAGIC;
2090 pDWP->hwndParent = 0;
2092 TRACE("returning hdwp %p\n", handle);
2093 return handle;
2097 /***********************************************************************
2098 * DeferWindowPos (USER32.@)
2100 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2101 INT x, INT y, INT cx, INT cy,
2102 UINT flags )
2104 DWP *pDWP;
2105 int i;
2106 HDWP newhdwp = hdwp,retvalue;
2108 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2109 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2111 hwnd = WIN_GetFullHandle( hwnd );
2112 if (is_desktop_window( hwnd )) return 0;
2114 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2116 USER_Lock();
2118 for (i = 0; i < pDWP->actualCount; i++)
2120 if (pDWP->winPos[i].hwnd == hwnd)
2122 /* Merge with the other changes */
2123 if (!(flags & SWP_NOZORDER))
2125 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2127 if (!(flags & SWP_NOMOVE))
2129 pDWP->winPos[i].x = x;
2130 pDWP->winPos[i].y = y;
2132 if (!(flags & SWP_NOSIZE))
2134 pDWP->winPos[i].cx = cx;
2135 pDWP->winPos[i].cy = cy;
2137 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2138 SWP_NOZORDER | SWP_NOREDRAW |
2139 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2140 SWP_NOOWNERZORDER);
2141 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2142 SWP_FRAMECHANGED);
2143 retvalue = hdwp;
2144 goto END;
2147 if (pDWP->actualCount >= pDWP->suggestedCount)
2149 newhdwp = USER_HEAP_REALLOC( hdwp,
2150 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2151 if (!newhdwp)
2153 retvalue = 0;
2154 goto END;
2156 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2157 pDWP->suggestedCount++;
2159 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2160 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2161 pDWP->winPos[pDWP->actualCount].x = x;
2162 pDWP->winPos[pDWP->actualCount].y = y;
2163 pDWP->winPos[pDWP->actualCount].cx = cx;
2164 pDWP->winPos[pDWP->actualCount].cy = cy;
2165 pDWP->winPos[pDWP->actualCount].flags = flags;
2166 pDWP->actualCount++;
2167 retvalue = newhdwp;
2168 END:
2169 USER_Unlock();
2170 return retvalue;
2174 /***********************************************************************
2175 * EndDeferWindowPos (USER32.@)
2177 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2179 DWP *pDWP;
2180 WINDOWPOS *winpos;
2181 BOOL res = TRUE;
2182 int i;
2184 TRACE("%p\n", hdwp);
2186 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2187 if (!pDWP) return FALSE;
2188 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2190 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2191 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2192 winpos->cx, winpos->cy, winpos->flags);
2194 if (!(res = USER_SetWindowPos( winpos ))) break;
2196 USER_HEAP_FREE( hdwp );
2197 return res;
2201 /***********************************************************************
2202 * ArrangeIconicWindows (USER32.@)
2204 UINT WINAPI ArrangeIconicWindows( HWND parent )
2206 RECT rectParent;
2207 HWND hwndChild;
2208 INT x, y, xspacing, yspacing;
2210 GetClientRect( parent, &rectParent );
2211 x = rectParent.left;
2212 y = rectParent.bottom;
2213 xspacing = GetSystemMetrics(SM_CXICONSPACING);
2214 yspacing = GetSystemMetrics(SM_CYICONSPACING);
2216 hwndChild = GetWindow( parent, GW_CHILD );
2217 while (hwndChild)
2219 if( IsIconic( hwndChild ) )
2221 WINPOS_ShowIconTitle( hwndChild, FALSE );
2223 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
2224 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
2225 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
2226 if( IsWindow(hwndChild) )
2227 WINPOS_ShowIconTitle(hwndChild , TRUE );
2229 if (x <= rectParent.right - xspacing) x += xspacing;
2230 else
2232 x = rectParent.left;
2233 y -= yspacing;
2236 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
2238 return yspacing;
2242 /***********************************************************************
2243 * draw_moving_frame
2245 * Draw the frame used when moving or resizing window.
2247 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
2249 if (thickframe)
2251 const int width = GetSystemMetrics(SM_CXFRAME);
2252 const int height = GetSystemMetrics(SM_CYFRAME);
2254 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
2255 PatBlt( hdc, rect->left, rect->top,
2256 rect->right - rect->left - width, height, PATINVERT );
2257 PatBlt( hdc, rect->left, rect->top + height, width,
2258 rect->bottom - rect->top - height, PATINVERT );
2259 PatBlt( hdc, rect->left + width, rect->bottom - 1,
2260 rect->right - rect->left - width, -height, PATINVERT );
2261 PatBlt( hdc, rect->right - 1, rect->top, -width,
2262 rect->bottom - rect->top - height, PATINVERT );
2263 SelectObject( hdc, hbrush );
2265 else DrawFocusRect( hdc, rect );
2269 /***********************************************************************
2270 * start_size_move
2272 * Initialization of a move or resize, when initiated from a menu choice.
2273 * Return hit test code for caption or sizing border.
2275 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
2277 LONG hittest = 0;
2278 POINT pt;
2279 MSG msg;
2280 RECT rectWindow;
2282 GetWindowRect( hwnd, &rectWindow );
2284 if ((wParam & 0xfff0) == SC_MOVE)
2286 /* Move pointer at the center of the caption */
2287 RECT rect = rectWindow;
2288 /* Note: to be exactly centered we should take the different types
2289 * of border into account, but it shouldn't make more than a few pixels
2290 * of difference so let's not bother with that */
2291 rect.top += GetSystemMetrics(SM_CYBORDER);
2292 if (style & WS_SYSMENU)
2293 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2294 if (style & WS_MINIMIZEBOX)
2295 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2296 if (style & WS_MAXIMIZEBOX)
2297 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2298 pt.x = (rect.right + rect.left) / 2;
2299 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2300 hittest = HTCAPTION;
2301 *capturePoint = pt;
2303 else /* SC_SIZE */
2305 SetCursor( LoadCursorW( 0, (LPWSTR)IDC_SIZEALL ) );
2306 pt.x = pt.y = 0;
2307 while(!hittest)
2309 if (!GetMessageW( &msg, 0, 0, 0 )) return 0;
2310 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2312 switch(msg.message)
2314 case WM_MOUSEMOVE:
2315 pt.x = min( max( msg.pt.x, rectWindow.left ), rectWindow.right - 1 );
2316 pt.y = min( max( msg.pt.y, rectWindow.top ), rectWindow.bottom - 1 );
2317 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
2318 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
2319 break;
2321 case WM_LBUTTONUP:
2322 return 0;
2324 case WM_KEYDOWN:
2325 switch(msg.wParam)
2327 case VK_UP:
2328 hittest = HTTOP;
2329 pt.x =(rectWindow.left+rectWindow.right)/2;
2330 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2331 break;
2332 case VK_DOWN:
2333 hittest = HTBOTTOM;
2334 pt.x =(rectWindow.left+rectWindow.right)/2;
2335 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2336 break;
2337 case VK_LEFT:
2338 hittest = HTLEFT;
2339 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2340 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2341 break;
2342 case VK_RIGHT:
2343 hittest = HTRIGHT;
2344 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2345 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2346 break;
2347 case VK_RETURN:
2348 case VK_ESCAPE:
2349 return 0;
2351 break;
2352 default:
2353 TranslateMessage( &msg );
2354 DispatchMessageW( &msg );
2355 break;
2358 *capturePoint = pt;
2360 SetCursorPos( pt.x, pt.y );
2361 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
2362 return hittest;
2366 /***********************************************************************
2367 * WINPOS_SysCommandSizeMove
2369 * Perform SC_MOVE and SC_SIZE commands.
2371 void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
2373 MSG msg;
2374 RECT sizingRect, mouseRect, origRect;
2375 HDC hdc;
2376 HWND parent;
2377 LONG hittest = (LONG)(wParam & 0x0f);
2378 WPARAM syscommand = wParam & 0xfff0;
2379 HCURSOR hDragCursor = 0, hOldCursor = 0;
2380 POINT minTrack, maxTrack;
2381 POINT capturePoint, pt;
2382 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2383 BOOL thickframe = HAS_THICKFRAME( style );
2384 BOOL iconic = style & WS_MINIMIZE;
2385 BOOL moved = FALSE;
2386 DWORD dwPoint = GetMessagePos ();
2387 BOOL DragFullWindows = TRUE;
2389 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
2391 pt.x = (short)LOWORD(dwPoint);
2392 pt.y = (short)HIWORD(dwPoint);
2393 capturePoint = pt;
2395 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2396 hwnd, syscommand, hittest, pt.x, pt.y);
2398 if (syscommand == SC_MOVE)
2400 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2401 if (!hittest) return;
2403 else /* SC_SIZE */
2405 if ( hittest && (syscommand != SC_MOUSEMENU) )
2406 hittest += (HTLEFT - WMSZ_LEFT);
2407 else
2409 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2410 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2411 if (!hittest)
2413 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2414 return;
2419 /* Get min/max info */
2421 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
2422 GetWindowRect( hwnd, &sizingRect );
2423 if (style & WS_CHILD)
2425 parent = GetParent(hwnd);
2426 /* make sizing rect relative to parent */
2427 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
2428 GetClientRect( parent, &mouseRect );
2430 else
2432 parent = 0;
2433 GetClientRect( GetDesktopWindow(), &mouseRect );
2434 mouseRect.left = GetSystemMetrics( SM_XVIRTUALSCREEN );
2435 mouseRect.top = GetSystemMetrics( SM_YVIRTUALSCREEN );
2436 mouseRect.right = mouseRect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
2437 mouseRect.bottom = mouseRect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
2439 origRect = sizingRect;
2441 if (ON_LEFT_BORDER(hittest))
2443 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2444 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2446 else if (ON_RIGHT_BORDER(hittest))
2448 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2449 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2451 if (ON_TOP_BORDER(hittest))
2453 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2454 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2456 else if (ON_BOTTOM_BORDER(hittest))
2458 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2459 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2461 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2463 /* Retrieve a default cache DC (without using the window style) */
2464 hdc = GetDCEx( parent, 0, DCX_CACHE );
2466 if( iconic ) /* create a cursor for dragging */
2468 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
2469 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
2470 if( !hDragCursor ) iconic = FALSE;
2473 /* we only allow disabling the full window drag for child windows */
2474 if (parent) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0 );
2476 /* repaint the window before moving it around */
2477 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2479 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2480 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2482 while(1)
2484 int dx = 0, dy = 0;
2486 if (!GetMessageW( &msg, 0, 0, 0 )) break;
2487 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2489 /* Exit on button-up, Return, or Esc */
2490 if ((msg.message == WM_LBUTTONUP) ||
2491 ((msg.message == WM_KEYDOWN) &&
2492 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2494 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2496 TranslateMessage( &msg );
2497 DispatchMessageW( &msg );
2498 continue; /* We are not interested in other messages */
2501 pt = msg.pt;
2503 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2505 case VK_UP: pt.y -= 8; break;
2506 case VK_DOWN: pt.y += 8; break;
2507 case VK_LEFT: pt.x -= 8; break;
2508 case VK_RIGHT: pt.x += 8; break;
2511 pt.x = max( pt.x, mouseRect.left );
2512 pt.x = min( pt.x, mouseRect.right );
2513 pt.y = max( pt.y, mouseRect.top );
2514 pt.y = min( pt.y, mouseRect.bottom );
2516 dx = pt.x - capturePoint.x;
2517 dy = pt.y - capturePoint.y;
2519 if (dx || dy)
2521 if( !moved )
2523 moved = TRUE;
2525 if( iconic ) /* ok, no system popup tracking */
2527 hOldCursor = SetCursor(hDragCursor);
2528 ShowCursor( TRUE );
2529 WINPOS_ShowIconTitle( hwnd, FALSE );
2531 else if(!DragFullWindows)
2532 draw_moving_frame( hdc, &sizingRect, thickframe );
2535 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2536 else
2538 RECT newRect = sizingRect;
2539 WPARAM wpSizingHit = 0;
2541 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2542 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2543 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2544 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2545 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2546 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2547 capturePoint = pt;
2549 /* determine the hit location */
2550 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2551 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2552 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2554 if (!iconic)
2556 if(!DragFullWindows)
2557 draw_moving_frame( hdc, &newRect, thickframe );
2558 else
2559 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2560 newRect.right - newRect.left,
2561 newRect.bottom - newRect.top,
2562 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2564 sizingRect = newRect;
2569 if( iconic )
2571 if( moved ) /* restore cursors, show icon title later on */
2573 ShowCursor( FALSE );
2574 SetCursor( hOldCursor );
2577 else if (moved && !DragFullWindows)
2579 draw_moving_frame( hdc, &sizingRect, thickframe );
2582 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2583 ReleaseDC( parent, hdc );
2585 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2586 moved = FALSE;
2588 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2589 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2591 /* window moved or resized */
2592 if (moved)
2594 /* if the moving/resizing isn't canceled call SetWindowPos
2595 * with the new position or the new size of the window
2597 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2599 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2600 if(!DragFullWindows || iconic)
2601 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2602 sizingRect.right - sizingRect.left,
2603 sizingRect.bottom - sizingRect.top,
2604 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2606 else
2607 { /* restore previous size/position */
2608 if(DragFullWindows)
2609 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2610 origRect.right - origRect.left,
2611 origRect.bottom - origRect.top,
2612 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2616 if (IsIconic(hwnd))
2618 /* Single click brings up the system menu when iconized */
2620 if( !moved )
2622 if(style & WS_SYSMENU )
2623 SendMessageW( hwnd, WM_SYSCOMMAND,
2624 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2626 else WINPOS_ShowIconTitle( hwnd, TRUE );