winecfg: Fix the Bulgarian translation.
[wine.git] / dlls / user32 / winpos.c
blob621f89a25a530b08145fc2fdb7342b56449a300f
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "wine/server.h"
34 #include "controls.h"
35 #include "user_private.h"
36 #include "win.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define PLACE_MIN 0x0001
68 #define PLACE_MAX 0x0002
69 #define PLACE_RECT 0x0004
72 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
74 typedef struct
76 INT actualCount;
77 INT suggestedCount;
78 BOOL valid;
79 INT wMagic;
80 HWND hwndParent;
81 WINDOWPOS winPos[1];
82 } DWP;
85 /***********************************************************************
86 * SwitchToThisWindow (USER32.@)
88 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
90 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
99 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
100 if (ret)
102 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd, wine_dbgstr_rect(rect) );
105 return ret;
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
114 int nRet = ERROR;
115 NTSTATUS status;
116 HRGN win_rgn = 0;
117 RGNDATA *data;
118 size_t size = 256;
122 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
124 SetLastError( ERROR_OUTOFMEMORY );
125 return ERROR;
127 SERVER_START_REQ( get_window_region )
129 req->window = hwnd;
130 wine_server_set_reply( req, data->Buffer, size );
131 if (!(status = wine_server_call( req )))
133 size_t reply_size = wine_server_reply_size( reply );
134 if (reply_size)
136 data->rdh.dwSize = sizeof(data->rdh);
137 data->rdh.iType = RDH_RECTANGLES;
138 data->rdh.nCount = reply_size / sizeof(RECT);
139 data->rdh.nRgnSize = reply_size;
140 win_rgn = ExtCreateRegion( NULL, size, data );
143 else size = reply->total_size;
145 SERVER_END_REQ;
146 HeapFree( GetProcessHeap(), 0, data );
147 } while (status == STATUS_BUFFER_OVERFLOW);
149 if (status) SetLastError( RtlNtStatusToDosError(status) );
150 else if (win_rgn)
152 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
153 DeleteObject( win_rgn );
155 return nRet;
159 /***********************************************************************
160 * SetWindowRgn (USER32.@)
162 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
164 static const RECT empty_rect;
165 BOOL ret;
167 if (hrgn)
169 RGNDATA *data;
170 DWORD size;
172 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
173 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
174 if (!GetRegionData( hrgn, size, data ))
176 HeapFree( GetProcessHeap(), 0, data );
177 return FALSE;
179 SERVER_START_REQ( set_window_region )
181 req->window = hwnd;
182 req->redraw = (bRedraw != 0);
183 if (data->rdh.nCount)
184 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
185 else
186 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
187 ret = !wine_server_call_err( req );
189 SERVER_END_REQ;
191 else /* clear existing region */
193 SERVER_START_REQ( set_window_region )
195 req->window = hwnd;
196 req->redraw = (bRedraw != 0);
197 ret = !wine_server_call_err( req );
199 SERVER_END_REQ;
202 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
204 if (ret)
206 UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
207 if (!bRedraw) swp_flags |= SWP_NOREDRAW;
208 SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
209 invalidate_dce( hwnd, NULL );
211 return ret;
215 /***********************************************************************
216 * GetClientRect (USER32.@)
218 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
220 BOOL ret;
222 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
224 rect->right -= rect->left;
225 rect->bottom -= rect->top;
226 rect->left = rect->top = 0;
228 return ret;
232 /*******************************************************************
233 * ClientToScreen (USER32.@)
235 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
237 MapWindowPoints( hwnd, 0, lppnt, 1 );
238 return TRUE;
242 /*******************************************************************
243 * ScreenToClient (USER32.@)
245 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
247 MapWindowPoints( 0, hwnd, lppnt, 1 );
248 return TRUE;
252 /***********************************************************************
253 * list_children_from_point
255 * Get the list of children that can contain point from the server.
256 * Point is in screen coordinates.
257 * Returned list must be freed by caller.
259 static HWND *list_children_from_point( HWND hwnd, POINT pt )
261 HWND *list;
262 int size = 128;
264 for (;;)
266 int count = 0;
268 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
270 SERVER_START_REQ( get_window_children_from_point )
272 req->parent = hwnd;
273 req->x = pt.x;
274 req->y = pt.y;
275 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
276 if (!wine_server_call( req )) count = reply->count;
278 SERVER_END_REQ;
279 if (count && count < size)
281 list[count] = 0;
282 return list;
284 HeapFree( GetProcessHeap(), 0, list );
285 if (!count) break;
286 size = count + 1; /* restart with a large enough buffer */
288 return NULL;
292 /***********************************************************************
293 * WINPOS_WindowFromPoint
295 * Find the window and hittest for a given point.
297 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
299 int i, res;
300 HWND ret, *list;
302 if (!hwndScope) hwndScope = GetDesktopWindow();
304 *hittest = HTNOWHERE;
306 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
308 /* now determine the hittest */
310 for (i = 0; list[i]; i++)
312 LONG style = GetWindowLongW( list[i], GWL_STYLE );
314 /* If window is minimized or disabled, return at once */
315 if (style & WS_MINIMIZE)
317 *hittest = HTCAPTION;
318 break;
320 if (style & WS_DISABLED)
322 *hittest = HTERROR;
323 break;
325 /* Send WM_NCCHITTEST (if same thread) */
326 if (!WIN_IsCurrentThread( list[i] ))
328 *hittest = HTCLIENT;
329 break;
331 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
332 if (res != HTTRANSPARENT)
334 *hittest = res; /* Found the window */
335 break;
337 /* continue search with next window in z-order */
339 ret = list[i];
340 HeapFree( GetProcessHeap(), 0, list );
341 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
342 return ret;
346 /*******************************************************************
347 * WindowFromPoint (USER32.@)
349 HWND WINAPI WindowFromPoint( POINT pt )
351 INT hittest;
352 return WINPOS_WindowFromPoint( 0, pt, &hittest );
356 /*******************************************************************
357 * ChildWindowFromPoint (USER32.@)
359 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
361 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
364 /*******************************************************************
365 * RealChildWindowFromPoint (USER32.@)
367 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
369 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
372 /*******************************************************************
373 * ChildWindowFromPointEx (USER32.@)
375 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
377 /* pt is in the client coordinates */
378 HWND *list;
379 int i;
380 RECT rect;
381 HWND retvalue;
383 GetClientRect( hwndParent, &rect );
384 if (!PtInRect( &rect, pt )) return 0;
385 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
387 for (i = 0; list[i]; i++)
389 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
390 if (!PtInRect( &rect, pt )) continue;
391 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
393 LONG style = GetWindowLongW( list[i], GWL_STYLE );
394 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
395 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
397 if (uFlags & CWP_SKIPTRANSPARENT)
399 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
401 break;
403 retvalue = list[i];
404 HeapFree( GetProcessHeap(), 0, list );
405 if (!retvalue) retvalue = hwndParent;
406 return retvalue;
410 /*******************************************************************
411 * WINPOS_GetWinOffset
413 * Calculate the offset between the origin of the two windows. Used
414 * to implement MapWindowPoints.
416 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
418 WND * wndPtr;
420 offset->x = offset->y = 0;
422 /* Translate source window origin to screen coords */
423 if (hwndFrom)
425 HWND hwnd = hwndFrom;
427 while (hwnd)
429 if (hwnd == hwndTo) return;
430 if (!(wndPtr = WIN_GetPtr( hwnd )))
432 ERR( "bad hwndFrom = %p\n", hwnd );
433 return;
435 if (wndPtr == WND_DESKTOP) break;
436 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
437 offset->x += wndPtr->rectClient.left;
438 offset->y += wndPtr->rectClient.top;
439 hwnd = wndPtr->parent;
440 WIN_ReleasePtr( wndPtr );
444 /* Translate origin to destination window coords */
445 if (hwndTo)
447 HWND hwnd = hwndTo;
449 while (hwnd)
451 if (!(wndPtr = WIN_GetPtr( hwnd )))
453 ERR( "bad hwndTo = %p\n", hwnd );
454 return;
456 if (wndPtr == WND_DESKTOP) break;
457 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
458 offset->x -= wndPtr->rectClient.left;
459 offset->y -= wndPtr->rectClient.top;
460 hwnd = wndPtr->parent;
461 WIN_ReleasePtr( wndPtr );
464 return;
466 other_process: /* one of the parents may belong to another process, do it the hard way */
467 offset->x = offset->y = 0;
468 SERVER_START_REQ( get_windows_offset )
470 req->from = hwndFrom;
471 req->to = hwndTo;
472 if (!wine_server_call( req ))
474 offset->x = reply->x;
475 offset->y = reply->y;
478 SERVER_END_REQ;
482 /*******************************************************************
483 * MapWindowPoints (USER.258)
485 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
486 LPPOINT16 lppt, UINT16 count )
488 POINT offset;
490 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
491 while (count--)
493 lppt->x += offset.x;
494 lppt->y += offset.y;
495 lppt++;
500 /*******************************************************************
501 * MapWindowPoints (USER32.@)
503 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
505 POINT offset;
507 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
508 while (count--)
510 lppt->x += offset.x;
511 lppt->y += offset.y;
512 lppt++;
514 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
518 /***********************************************************************
519 * IsIconic (USER32.@)
521 BOOL WINAPI IsIconic(HWND hWnd)
523 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
527 /***********************************************************************
528 * IsZoomed (USER32.@)
530 BOOL WINAPI IsZoomed(HWND hWnd)
532 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
536 /*******************************************************************
537 * AllowSetForegroundWindow (USER32.@)
539 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
541 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
542 * implemented, then fix this function. */
543 return TRUE;
547 /*******************************************************************
548 * LockSetForegroundWindow (USER32.@)
550 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
552 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
553 * implemented, then fix this function. */
554 return TRUE;
558 /***********************************************************************
559 * BringWindowToTop (USER32.@)
561 BOOL WINAPI BringWindowToTop( HWND hwnd )
563 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
567 /***********************************************************************
568 * MoveWindow (USER32.@)
570 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
571 BOOL repaint )
573 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
574 if (!repaint) flags |= SWP_NOREDRAW;
575 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
576 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
579 /***********************************************************************
580 * WINPOS_InitPlacement
582 static void WINPOS_InitPlacement( WND* wnd )
584 if (IsRectEmpty( &wnd->normal_rect ))
586 /* this happens when the window is minimized/maximized
587 * for the first time (rectWindow is not adjusted yet) */
589 wnd->normal_rect = wnd->rectWindow;
590 wnd->min_pos.x = wnd->min_pos.y = -1;
591 wnd->max_pos.x = wnd->max_pos.y = -1;
594 if( wnd->dwStyle & WS_MINIMIZE )
596 wnd->min_pos.x = wnd->rectWindow.left;
597 wnd->min_pos.y = wnd->rectWindow.top;
599 else if( wnd->dwStyle & WS_MAXIMIZE )
601 wnd->max_pos.x = wnd->rectWindow.left;
602 wnd->max_pos.y = wnd->rectWindow.top;
604 else
606 wnd->normal_rect = wnd->rectWindow;
610 /***********************************************************************
611 * WINPOS_RedrawIconTitle
613 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
615 HWND icon_title = 0;
616 WND *win = WIN_GetPtr( hWnd );
618 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
620 icon_title = win->icon_title;
621 WIN_ReleasePtr( win );
623 if (!icon_title) return FALSE;
624 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
625 InvalidateRect( icon_title, NULL, TRUE );
626 return TRUE;
629 /***********************************************************************
630 * WINPOS_ShowIconTitle
632 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
634 if (!GetPropA( hwnd, "__wine_x11_managed" ))
636 WND *win = WIN_GetPtr( hwnd );
637 HWND title = 0;
639 TRACE("%p %i\n", hwnd, (bShow != 0) );
641 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
642 title = win->icon_title;
643 WIN_ReleasePtr( win );
645 if( bShow )
647 if (!title)
649 title = ICONTITLE_Create( hwnd );
650 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
652 DestroyWindow( title );
653 return FALSE;
655 win->icon_title = title;
656 WIN_ReleasePtr( win );
658 if (!IsWindowVisible(title))
660 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
661 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
662 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
665 else if (title) ShowWindow( title, SW_HIDE );
667 return FALSE;
670 /*******************************************************************
671 * WINPOS_GetMinMaxInfo
673 * Get the minimized and maximized information for a window.
675 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
676 POINT *minTrack, POINT *maxTrack )
678 MINMAXINFO MinMax;
679 HMONITOR monitor;
680 INT xinc, yinc;
681 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
682 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
683 RECT rc;
684 WND *win;
686 /* Compute default values */
688 GetWindowRect(hwnd, &rc);
689 MinMax.ptReserved.x = rc.left;
690 MinMax.ptReserved.y = rc.top;
692 if (style & WS_CHILD)
694 if ((style & WS_CAPTION) == WS_CAPTION)
695 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
697 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
698 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
700 /* avoid calculating this twice */
701 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
703 MinMax.ptMaxSize.x = rc.right - rc.left;
704 MinMax.ptMaxSize.y = rc.bottom - rc.top;
706 else
708 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
709 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
711 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
712 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
713 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
714 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
716 if (HAS_DLGFRAME( style, exstyle ))
718 xinc = GetSystemMetrics(SM_CXDLGFRAME);
719 yinc = GetSystemMetrics(SM_CYDLGFRAME);
721 else
723 xinc = yinc = 0;
724 if (HAS_THICKFRAME(style))
726 xinc += GetSystemMetrics(SM_CXFRAME);
727 yinc += GetSystemMetrics(SM_CYFRAME);
729 if (style & WS_BORDER)
731 xinc += GetSystemMetrics(SM_CXBORDER);
732 yinc += GetSystemMetrics(SM_CYBORDER);
735 MinMax.ptMaxSize.x += 2 * xinc;
736 MinMax.ptMaxSize.y += 2 * yinc;
738 MinMax.ptMaxPosition.x = -xinc;
739 MinMax.ptMaxPosition.y = -yinc;
740 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
742 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
743 WIN_ReleasePtr( win );
746 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
748 /* if the app didn't change the values, adapt them for the current monitor */
750 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
752 MONITORINFO mon_info;
754 mon_info.cbSize = sizeof(mon_info);
755 GetMonitorInfoW( monitor, &mon_info );
757 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
758 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
760 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
761 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
763 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
765 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
766 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
770 /* Some sanity checks */
772 TRACE("%d %d / %d %d / %d %d / %d %d\n",
773 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
774 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
775 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
776 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
777 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
778 MinMax.ptMinTrackSize.x );
779 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
780 MinMax.ptMinTrackSize.y );
782 if (maxSize) *maxSize = MinMax.ptMaxSize;
783 if (maxPos) *maxPos = MinMax.ptMaxPosition;
784 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
785 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
789 /***********************************************************************
790 * WINPOS_FindIconPos
792 * Find a suitable place for an iconic window.
794 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
796 RECT rect, rectParent;
797 HWND parent, child;
798 HRGN hrgn, tmp;
799 int xspacing, yspacing;
801 parent = GetAncestor( hwnd, GA_PARENT );
802 GetClientRect( parent, &rectParent );
803 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
804 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
805 return pt; /* The icon already has a suitable position */
807 xspacing = GetSystemMetrics(SM_CXICONSPACING);
808 yspacing = GetSystemMetrics(SM_CYICONSPACING);
810 /* Check if another icon already occupies this spot */
811 /* FIXME: this is completely inefficient */
813 hrgn = CreateRectRgn( 0, 0, 0, 0 );
814 tmp = CreateRectRgn( 0, 0, 0, 0 );
815 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
817 WND *childPtr;
818 if (child == hwnd) continue;
819 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
820 continue;
821 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
822 continue;
823 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
824 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
825 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
826 WIN_ReleasePtr( childPtr );
828 DeleteObject( tmp );
830 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
832 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
834 rect.right = rect.left + xspacing;
835 rect.top = rect.bottom - yspacing;
836 if (!RectInRegion( hrgn, &rect ))
838 /* No window was found, so it's OK for us */
839 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
840 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
841 DeleteObject( hrgn );
842 return pt;
846 DeleteObject( hrgn );
847 pt.x = pt.y = 0;
848 return pt;
852 /***********************************************************************
853 * WINPOS_MinMaximize
855 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
857 WND *wndPtr;
858 UINT swpFlags = 0;
859 POINT size;
860 LONG old_style;
861 WINDOWPLACEMENT wpl;
863 TRACE("%p %u\n", hwnd, cmd );
865 wpl.length = sizeof(wpl);
866 GetWindowPlacement( hwnd, &wpl );
868 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
869 return SWP_NOSIZE | SWP_NOMOVE;
871 if (IsIconic( hwnd ))
873 switch (cmd)
875 case SW_SHOWMINNOACTIVE:
876 case SW_SHOWMINIMIZED:
877 case SW_FORCEMINIMIZE:
878 case SW_MINIMIZE:
879 return SWP_NOSIZE | SWP_NOMOVE;
881 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
882 swpFlags |= SWP_NOCOPYBITS;
885 switch( cmd )
887 case SW_SHOWMINNOACTIVE:
888 case SW_SHOWMINIMIZED:
889 case SW_FORCEMINIMIZE:
890 case SW_MINIMIZE:
891 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
892 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
893 else wndPtr->flags &= ~WIN_RESTORE_MAX;
894 WIN_ReleasePtr( wndPtr );
896 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
898 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
900 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
901 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
902 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
903 swpFlags |= SWP_NOCOPYBITS;
904 break;
906 case SW_MAXIMIZE:
907 old_style = GetWindowLongW( hwnd, GWL_STYLE );
908 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
910 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
912 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
913 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
915 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
916 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
917 break;
919 case SW_SHOWNOACTIVATE:
920 case SW_SHOWNORMAL:
921 case SW_RESTORE:
922 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
923 if (old_style & WS_MINIMIZE)
925 BOOL restore_max;
927 WINPOS_ShowIconTitle( hwnd, FALSE );
929 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
930 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
931 WIN_ReleasePtr( wndPtr );
932 if (restore_max)
934 /* Restore to maximized position */
935 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
936 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
937 swpFlags |= SWP_STATECHANGED;
938 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
939 break;
942 else if (!(old_style & WS_MAXIMIZE)) break;
944 swpFlags |= SWP_STATECHANGED;
946 /* Restore to normal position */
948 *rect = wpl.rcNormalPosition;
949 rect->right -= rect->left;
950 rect->bottom -= rect->top;
952 break;
955 return swpFlags;
959 /***********************************************************************
960 * show_window
962 * Implementation of ShowWindow and ShowWindowAsync.
964 static BOOL show_window( HWND hwnd, INT cmd )
966 WND *wndPtr;
967 HWND parent;
968 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
969 BOOL wasVisible = (style & WS_VISIBLE) != 0;
970 BOOL showFlag = TRUE;
971 RECT newPos = {0, 0, 0, 0};
972 UINT swp = 0;
974 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
976 switch(cmd)
978 case SW_HIDE:
979 if (!wasVisible) return FALSE;
980 showFlag = FALSE;
981 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
982 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
983 break;
985 case SW_SHOWMINNOACTIVE:
986 case SW_MINIMIZE:
987 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
988 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
989 /* fall through */
990 case SW_SHOWMINIMIZED:
991 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
992 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
993 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
994 break;
996 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
997 if (!wasVisible) swp |= SWP_SHOWWINDOW;
998 swp |= SWP_FRAMECHANGED;
999 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1000 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
1001 break;
1003 case SW_SHOWNA:
1004 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1005 if (style & WS_CHILD) swp |= SWP_NOZORDER;
1006 break;
1007 case SW_SHOW:
1008 if (wasVisible) return TRUE;
1009 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1010 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1011 break;
1013 case SW_SHOWNOACTIVATE:
1014 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1015 /* fall through */
1016 case SW_RESTORE:
1017 /* fall through */
1018 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1019 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1020 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1021 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1023 swp |= SWP_FRAMECHANGED;
1024 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1026 else
1028 if (wasVisible) return TRUE;
1029 swp |= SWP_NOSIZE | SWP_NOMOVE;
1031 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1032 break;
1033 default:
1034 return wasVisible;
1037 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1039 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1040 if (!IsWindow( hwnd )) return wasVisible;
1043 parent = GetAncestor( hwnd, GA_PARENT );
1044 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1046 /* if parent is not visible simply toggle WS_VISIBLE and return */
1047 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1048 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1050 else
1051 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1052 newPos.right, newPos.bottom, LOWORD(swp) );
1054 if (cmd == SW_HIDE)
1056 HWND hFocus;
1058 WINPOS_ShowIconTitle( hwnd, FALSE );
1060 /* FIXME: This will cause the window to be activated irrespective
1061 * of whether it is owned by the same thread. Has to be done
1062 * asynchronously.
1065 if (hwnd == GetActiveWindow())
1066 WINPOS_ActivateOtherWindow(hwnd);
1068 /* Revert focus to parent */
1069 hFocus = GetFocus();
1070 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1072 HWND parent = GetAncestor(hwnd, GA_PARENT);
1073 if (parent == GetDesktopWindow()) parent = 0;
1074 SetFocus(parent);
1078 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1080 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1082 if (wndPtr->flags & WIN_NEED_SIZE)
1084 /* should happen only in CreateWindowEx() */
1085 int wParam = SIZE_RESTORED;
1086 RECT client = wndPtr->rectClient;
1088 wndPtr->flags &= ~WIN_NEED_SIZE;
1089 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1090 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1091 WIN_ReleasePtr( wndPtr );
1093 SendMessageW( hwnd, WM_SIZE, wParam,
1094 MAKELONG( client.right - client.left, client.bottom - client.top ));
1095 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1097 else WIN_ReleasePtr( wndPtr );
1099 /* if previous state was minimized Windows sets focus to the window */
1100 if (style & WS_MINIMIZE) SetFocus( hwnd );
1102 return wasVisible;
1106 /***********************************************************************
1107 * ShowWindowAsync (USER32.@)
1109 * doesn't wait; returns immediately.
1110 * used by threads to toggle windows in other (possibly hanging) threads
1112 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1114 HWND full_handle;
1116 if (is_broadcast(hwnd))
1118 SetLastError( ERROR_INVALID_PARAMETER );
1119 return FALSE;
1122 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1123 return show_window( full_handle, cmd );
1125 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1129 /***********************************************************************
1130 * ShowWindow (USER32.@)
1132 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1134 HWND full_handle;
1136 if (is_broadcast(hwnd))
1138 SetLastError( ERROR_INVALID_PARAMETER );
1139 return FALSE;
1141 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1142 return show_window( full_handle, cmd );
1144 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1148 /***********************************************************************
1149 * GetInternalWindowPos (USER32.@)
1151 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1152 LPPOINT ptIcon )
1154 WINDOWPLACEMENT wndpl;
1155 if (GetWindowPlacement( hwnd, &wndpl ))
1157 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1158 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1159 return wndpl.showCmd;
1161 return 0;
1165 /***********************************************************************
1166 * GetWindowPlacement (USER32.@)
1168 * Win95:
1169 * Fails if wndpl->length of Win95 (!) apps is invalid.
1171 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1173 WND *pWnd = WIN_GetPtr( hwnd );
1175 if (!pWnd) return FALSE;
1177 if (pWnd == WND_DESKTOP)
1179 wndpl->length = sizeof(*wndpl);
1180 wndpl->showCmd = SW_SHOWNORMAL;
1181 wndpl->flags = 0;
1182 wndpl->ptMinPosition.x = -1;
1183 wndpl->ptMinPosition.y = -1;
1184 wndpl->ptMaxPosition.x = -1;
1185 wndpl->ptMaxPosition.y = -1;
1186 GetWindowRect( hwnd, &wndpl->rcNormalPosition );
1187 return TRUE;
1189 if (pWnd == WND_OTHER_PROCESS)
1191 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1192 return FALSE;
1195 WINPOS_InitPlacement( pWnd );
1196 wndpl->length = sizeof(*wndpl);
1197 if( pWnd->dwStyle & WS_MINIMIZE )
1198 wndpl->showCmd = SW_SHOWMINIMIZED;
1199 else
1200 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1201 if( pWnd->flags & WIN_RESTORE_MAX )
1202 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1203 else
1204 wndpl->flags = 0;
1205 wndpl->ptMinPosition = pWnd->min_pos;
1206 wndpl->ptMaxPosition = pWnd->max_pos;
1207 wndpl->rcNormalPosition = pWnd->normal_rect;
1208 WIN_ReleasePtr( pWnd );
1210 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1211 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1212 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1213 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1214 return TRUE;
1217 /* make sure the specified rect is visible on screen */
1218 static void make_rect_onscreen( RECT *rect )
1220 MONITORINFO info;
1221 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1223 info.cbSize = sizeof(info);
1224 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1225 /* FIXME: map coordinates from rcWork to rcMonitor */
1226 if (rect->right <= info.rcWork.left)
1228 rect->right += info.rcWork.left - rect->left;
1229 rect->left = info.rcWork.left;
1231 else if (rect->left >= info.rcWork.right)
1233 rect->left += info.rcWork.right - rect->right;
1234 rect->right = info.rcWork.right;
1236 if (rect->bottom <= info.rcWork.top)
1238 rect->bottom += info.rcWork.top - rect->top;
1239 rect->top = info.rcWork.top;
1241 else if (rect->top >= info.rcWork.bottom)
1243 rect->top += info.rcWork.bottom - rect->bottom;
1244 rect->bottom = info.rcWork.bottom;
1248 /* make sure the specified point is visible on screen */
1249 static void make_point_onscreen( POINT *pt )
1251 RECT rect;
1253 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1254 make_rect_onscreen( &rect );
1255 pt->x = rect.left;
1256 pt->y = rect.top;
1260 /***********************************************************************
1261 * WINPOS_SetPlacement
1263 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1265 DWORD style;
1266 WND *pWnd = WIN_GetPtr( hwnd );
1267 WINDOWPLACEMENT wp = *wndpl;
1269 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1270 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1271 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1273 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1274 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1275 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1276 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1277 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1278 wine_dbgstr_rect(&wp.rcNormalPosition) );
1280 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1282 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1283 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1284 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1286 style = pWnd->dwStyle;
1288 WIN_ReleasePtr( pWnd );
1290 if( style & WS_MINIMIZE )
1292 if (flags & PLACE_MIN)
1294 WINPOS_ShowIconTitle( hwnd, FALSE );
1295 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1296 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1299 else if( style & WS_MAXIMIZE )
1301 if (flags & PLACE_MAX)
1302 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1303 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1305 else if( flags & PLACE_RECT )
1306 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1307 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1308 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1309 SWP_NOZORDER | SWP_NOACTIVATE );
1311 ShowWindow( hwnd, wndpl->showCmd );
1313 if (IsIconic( hwnd ))
1315 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1317 /* SDK: ...valid only the next time... */
1318 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1320 pWnd = WIN_GetPtr( hwnd );
1321 if (pWnd && pWnd != WND_OTHER_PROCESS)
1323 pWnd->flags |= WIN_RESTORE_MAX;
1324 WIN_ReleasePtr( pWnd );
1328 return TRUE;
1332 /***********************************************************************
1333 * SetWindowPlacement (USER32.@)
1335 * Win95:
1336 * Fails if wndpl->length of Win95 (!) apps is invalid.
1338 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1340 UINT flags = PLACE_MAX | PLACE_RECT;
1341 if (!wpl) return FALSE;
1342 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1343 return WINPOS_SetPlacement( hwnd, wpl, flags );
1347 /***********************************************************************
1348 * AnimateWindow (USER32.@)
1349 * Shows/Hides a window with an animation
1350 * NO ANIMATION YET
1352 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1354 FIXME("partial stub\n");
1356 /* If trying to show/hide and it's already *
1357 * shown/hidden or invalid window, fail with *
1358 * invalid parameter */
1359 if(!IsWindow(hwnd) ||
1360 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1361 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1363 SetLastError(ERROR_INVALID_PARAMETER);
1364 return FALSE;
1367 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1369 return TRUE;
1372 /***********************************************************************
1373 * SetInternalWindowPos (USER32.@)
1375 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1376 LPRECT rect, LPPOINT pt )
1378 WINDOWPLACEMENT wndpl;
1379 UINT flags;
1381 wndpl.length = sizeof(wndpl);
1382 wndpl.showCmd = showCmd;
1383 wndpl.flags = flags = 0;
1385 if( pt )
1387 flags |= PLACE_MIN;
1388 wndpl.flags |= WPF_SETMINPOSITION;
1389 wndpl.ptMinPosition = *pt;
1391 if( rect )
1393 flags |= PLACE_RECT;
1394 wndpl.rcNormalPosition = *rect;
1396 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1400 /*******************************************************************
1401 * can_activate_window
1403 * Check if we can activate the specified window.
1405 static BOOL can_activate_window( HWND hwnd )
1407 LONG style;
1409 if (!hwnd) return FALSE;
1410 style = GetWindowLongW( hwnd, GWL_STYLE );
1411 if (!(style & WS_VISIBLE)) return FALSE;
1412 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1413 return !(style & WS_DISABLED);
1417 /*******************************************************************
1418 * WINPOS_ActivateOtherWindow
1420 * Activates window other than pWnd.
1422 void WINPOS_ActivateOtherWindow(HWND hwnd)
1424 HWND hwndTo, fg;
1426 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1428 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1429 if (can_activate_window( hwndTo )) goto done;
1432 hwndTo = hwnd;
1433 for (;;)
1435 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1436 if (can_activate_window( hwndTo )) break;
1439 done:
1440 fg = GetForegroundWindow();
1441 TRACE("win = %p fg = %p\n", hwndTo, fg);
1442 if (!fg || (hwnd == fg))
1444 if (SetForegroundWindow( hwndTo )) return;
1446 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1450 /***********************************************************************
1451 * WINPOS_HandleWindowPosChanging
1453 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1455 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1457 POINT minTrack, maxTrack;
1458 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1460 if (winpos->flags & SWP_NOSIZE) return 0;
1461 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1463 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1464 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1465 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1466 if (!(style & WS_MINIMIZE))
1468 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1469 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1472 return 0;
1476 /***********************************************************************
1477 * dump_winpos_flags
1479 static void dump_winpos_flags(UINT flags)
1481 static const DWORD dumped_flags = (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW |
1482 SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW |
1483 SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOOWNERZORDER |
1484 SWP_NOSENDCHANGING | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS |
1485 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_STATECHANGED);
1486 TRACE("flags:");
1487 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1488 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1489 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1490 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1491 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1492 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1493 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1494 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1495 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1496 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1497 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1498 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1499 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1500 if(flags & SWP_NOCLIENTSIZE) TRACE(" SWP_NOCLIENTSIZE");
1501 if(flags & SWP_NOCLIENTMOVE) TRACE(" SWP_NOCLIENTMOVE");
1502 if(flags & SWP_STATECHANGED) TRACE(" SWP_STATECHANGED");
1504 if(flags & ~dumped_flags) TRACE(" %08x", flags & ~dumped_flags);
1505 TRACE("\n");
1508 /***********************************************************************
1509 * SWP_DoWinPosChanging
1511 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1513 WND *wndPtr;
1515 /* Send WM_WINDOWPOSCHANGING message */
1517 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1518 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1520 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1521 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1523 /* Calculate new position and size */
1525 *pNewWindowRect = wndPtr->rectWindow;
1526 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1527 : wndPtr->rectClient;
1529 if (!(pWinpos->flags & SWP_NOSIZE))
1531 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1532 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1534 if (!(pWinpos->flags & SWP_NOMOVE))
1536 pNewWindowRect->left = pWinpos->x;
1537 pNewWindowRect->top = pWinpos->y;
1538 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1539 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1541 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1542 pWinpos->y - wndPtr->rectWindow.top );
1544 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1546 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1547 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1548 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1549 TRACE( "current %s style %08x new %s\n",
1550 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1551 wine_dbgstr_rect( pNewWindowRect ));
1553 WIN_ReleasePtr( wndPtr );
1554 return TRUE;
1557 /***********************************************************************
1558 * get_valid_rects
1560 * Compute the valid rects from the old and new client rect and WVR_* flags.
1561 * Helper for WM_NCCALCSIZE handling.
1563 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1564 RECT *valid )
1566 int cx, cy;
1568 if (flags & WVR_REDRAW)
1570 SetRectEmpty( &valid[0] );
1571 SetRectEmpty( &valid[1] );
1572 return;
1575 if (flags & WVR_VALIDRECTS)
1577 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1578 !IntersectRect( &valid[1], &valid[1], old_client ))
1580 SetRectEmpty( &valid[0] );
1581 SetRectEmpty( &valid[1] );
1582 return;
1584 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1586 else
1588 valid[0] = *new_client;
1589 valid[1] = *old_client;
1592 /* make sure the rectangles have the same size */
1593 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1594 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1596 if (flags & WVR_ALIGNBOTTOM)
1598 valid[0].top = valid[0].bottom - cy;
1599 valid[1].top = valid[1].bottom - cy;
1601 else
1603 valid[0].bottom = valid[0].top + cy;
1604 valid[1].bottom = valid[1].top + cy;
1606 if (flags & WVR_ALIGNRIGHT)
1608 valid[0].left = valid[0].right - cx;
1609 valid[1].left = valid[1].right - cx;
1611 else
1613 valid[0].right = valid[0].left + cx;
1614 valid[1].right = valid[1].left + cx;
1619 /***********************************************************************
1620 * SWP_DoOwnedPopups
1622 * fix Z order taking into account owned popups -
1623 * basically we need to maintain them above the window that owns them
1625 * FIXME: hide/show owned popups when owner visibility changes.
1627 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1629 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1630 HWND owner, *list = NULL;
1631 unsigned int i;
1633 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1635 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1637 /* make sure this popup stays above the owner */
1639 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1641 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1643 for (i = 0; list[i]; i++)
1645 if (list[i] == owner)
1647 if (i > 0) hwndInsertAfter = list[i-1];
1648 else hwndInsertAfter = HWND_TOP;
1649 break;
1652 if (hwndInsertAfter == HWND_NOTOPMOST)
1654 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1656 else if (list[i] == hwndInsertAfter) break;
1660 else if (style & WS_CHILD) return hwndInsertAfter;
1662 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1663 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1665 i = 0;
1666 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1668 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1670 /* skip all the topmost windows */
1671 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1674 else if (hwndInsertAfter != HWND_TOPMOST)
1676 /* skip windows that are already placed correctly */
1677 for (i = 0; list[i]; i++)
1679 if (list[i] == hwndInsertAfter) break;
1680 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1684 for ( ; list[i]; i++)
1686 if (list[i] == hwnd) break;
1687 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1688 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1689 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1690 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1691 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1692 hwndInsertAfter = list[i];
1695 done:
1696 HeapFree( GetProcessHeap(), 0, list );
1697 return hwndInsertAfter;
1700 /***********************************************************************
1701 * SWP_DoNCCalcSize
1703 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1704 RECT *validRects )
1706 UINT wvrFlags = 0;
1707 WND *wndPtr;
1709 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1711 /* Send WM_NCCALCSIZE message to get new client area */
1712 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1714 NCCALCSIZE_PARAMS params;
1715 WINDOWPOS winposCopy;
1717 params.rgrc[0] = *pNewWindowRect;
1718 params.rgrc[1] = wndPtr->rectWindow;
1719 params.rgrc[2] = wndPtr->rectClient;
1720 params.lppos = &winposCopy;
1721 winposCopy = *pWinpos;
1722 WIN_ReleasePtr( wndPtr );
1724 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1726 *pNewClientRect = params.rgrc[0];
1728 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1730 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1731 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1732 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1734 if( pNewClientRect->left != wndPtr->rectClient.left ||
1735 pNewClientRect->top != wndPtr->rectClient.top )
1736 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1738 if( (pNewClientRect->right - pNewClientRect->left !=
1739 wndPtr->rectClient.right - wndPtr->rectClient.left))
1740 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1741 else
1742 wvrFlags &= ~WVR_HREDRAW;
1744 if (pNewClientRect->bottom - pNewClientRect->top !=
1745 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1746 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1747 else
1748 wvrFlags &= ~WVR_VREDRAW;
1750 validRects[0] = params.rgrc[1];
1751 validRects[1] = params.rgrc[2];
1753 else
1755 if (!(pWinpos->flags & SWP_NOMOVE) &&
1756 (pNewClientRect->left != wndPtr->rectClient.left ||
1757 pNewClientRect->top != wndPtr->rectClient.top))
1758 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1761 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1763 SetRectEmpty( &validRects[0] );
1764 SetRectEmpty( &validRects[1] );
1766 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1768 WIN_ReleasePtr( wndPtr );
1769 return wvrFlags;
1772 /* fix redundant flags and values in the WINDOWPOS structure */
1773 static BOOL fixup_flags( WINDOWPOS *winpos )
1775 HWND parent;
1776 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1777 BOOL ret = TRUE;
1779 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1781 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1782 return FALSE;
1784 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1786 /* Finally make sure that all coordinates are valid */
1787 if (winpos->x < -32768) winpos->x = -32768;
1788 else if (winpos->x > 32767) winpos->x = 32767;
1789 if (winpos->y < -32768) winpos->y = -32768;
1790 else if (winpos->y > 32767) winpos->y = 32767;
1792 if (winpos->cx < 0) winpos->cx = 0;
1793 else if (winpos->cx > 32767) winpos->cx = 32767;
1794 if (winpos->cy < 0) winpos->cy = 0;
1795 else if (winpos->cy > 32767) winpos->cy = 32767;
1797 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1798 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1800 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1801 else
1803 winpos->flags &= ~SWP_HIDEWINDOW;
1804 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1807 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1808 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1809 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1811 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1812 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1814 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1816 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1817 (winpos->flags & SWP_NOZORDER ||
1818 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1820 winpos->flags &= ~SWP_NOZORDER;
1821 winpos->hwndInsertAfter = HWND_TOP;
1825 /* Check hwndInsertAfter */
1826 if (winpos->flags & SWP_NOZORDER) goto done;
1828 /* fix sign extension */
1829 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1830 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1832 /* hwndInsertAfter must be a sibling of the window */
1833 if (winpos->hwndInsertAfter == HWND_TOP)
1835 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1836 winpos->flags |= SWP_NOZORDER;
1838 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1840 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1841 winpos->flags |= SWP_NOZORDER;
1843 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1845 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1846 winpos->flags |= SWP_NOZORDER;
1848 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1850 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1851 winpos->flags |= SWP_NOZORDER;
1853 else
1855 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1856 else
1858 /* don't need to change the Zorder of hwnd if it's already inserted
1859 * after hwndInsertAfter or when inserting hwnd after itself.
1861 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1862 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1863 winpos->flags |= SWP_NOZORDER;
1866 done:
1867 WIN_ReleasePtr( wndPtr );
1868 return ret;
1872 /***********************************************************************
1873 * set_window_pos
1875 * Backend implementation of SetWindowPos.
1877 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1878 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1880 WND *win;
1881 BOOL ret;
1882 RECT visible_rect, old_window_rect;
1884 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
1885 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
1887 old_window_rect = win->rectWindow;
1888 SERVER_START_REQ( set_window_pos )
1890 req->handle = hwnd;
1891 req->previous = insert_after;
1892 req->flags = swp_flags;
1893 req->window.left = window_rect->left;
1894 req->window.top = window_rect->top;
1895 req->window.right = window_rect->right;
1896 req->window.bottom = window_rect->bottom;
1897 req->client.left = client_rect->left;
1898 req->client.top = client_rect->top;
1899 req->client.right = client_rect->right;
1900 req->client.bottom = client_rect->bottom;
1901 if (!IsRectEmpty( &valid_rects[0] ))
1902 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1903 if ((ret = !wine_server_call( req )))
1905 win->dwStyle = reply->new_style;
1906 win->dwExStyle = reply->new_ex_style;
1907 win->rectWindow = *window_rect;
1908 win->rectClient = *client_rect;
1909 visible_rect.left = reply->visible.left;
1910 visible_rect.top = reply->visible.top;
1911 visible_rect.right = reply->visible.right;
1912 visible_rect.bottom = reply->visible.bottom;
1915 SERVER_END_REQ;
1916 WIN_ReleasePtr( win );
1918 if (ret)
1920 /* FIXME: should update visible rect before invalidating DCE */
1921 if (((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) ||
1922 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW | SWP_STATECHANGED)))
1923 invalidate_dce( hwnd, &old_window_rect );
1925 USER_Driver->pSetWindowPos( hwnd, insert_after, swp_flags, window_rect,
1926 client_rect, &visible_rect, valid_rects );
1928 return ret;
1932 /***********************************************************************
1933 * USER_SetWindowPos
1935 * User32 internal function
1937 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1939 RECT newWindowRect, newClientRect, valid_rects[2];
1940 UINT orig_flags;
1942 orig_flags = winpos->flags;
1944 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1945 if (!(winpos->flags & SWP_NOMOVE))
1947 if (winpos->x < -32768) winpos->x = -32768;
1948 else if (winpos->x > 32767) winpos->x = 32767;
1949 if (winpos->y < -32768) winpos->y = -32768;
1950 else if (winpos->y > 32767) winpos->y = 32767;
1952 if (!(winpos->flags & SWP_NOSIZE))
1954 if (winpos->cx < 0) winpos->cx = 0;
1955 else if (winpos->cx > 32767) winpos->cx = 32767;
1956 if (winpos->cy < 0) winpos->cy = 0;
1957 else if (winpos->cy > 32767) winpos->cy = 32767;
1960 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1962 /* Fix redundant flags */
1963 if (!fixup_flags( winpos )) return FALSE;
1965 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1967 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1968 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1971 /* Common operations */
1973 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1975 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1976 &newWindowRect, &newClientRect, valid_rects ))
1977 return FALSE;
1979 /* erase parent when hiding or resizing child */
1980 if (!(orig_flags & SWP_DEFERERASE) &&
1981 ((orig_flags & SWP_HIDEWINDOW) ||
1982 (!(orig_flags & SWP_SHOWWINDOW) &&
1983 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1985 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1986 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1987 erase_now( parent, 0 );
1990 if( winpos->flags & SWP_HIDEWINDOW )
1991 HideCaret(winpos->hwnd);
1992 else if (winpos->flags & SWP_SHOWWINDOW)
1993 ShowCaret(winpos->hwnd);
1995 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
1997 /* child windows get WM_CHILDACTIVATE message */
1998 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1999 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
2000 else
2001 SetForegroundWindow( winpos->hwnd );
2004 /* And last, send the WM_WINDOWPOSCHANGED message */
2006 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2008 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2010 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2011 and always contains final window position.
2013 winpos->x = newWindowRect.left;
2014 winpos->y = newWindowRect.top;
2015 winpos->cx = newWindowRect.right - newWindowRect.left;
2016 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2017 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2019 return TRUE;
2022 /***********************************************************************
2023 * SetWindowPos (USER32.@)
2025 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2026 INT x, INT y, INT cx, INT cy, UINT flags )
2028 WINDOWPOS winpos;
2030 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2031 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2032 if(TRACE_ON(win)) dump_winpos_flags(flags);
2034 if (is_broadcast(hwnd))
2036 SetLastError( ERROR_INVALID_PARAMETER );
2037 return FALSE;
2040 winpos.hwnd = WIN_GetFullHandle(hwnd);
2041 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2042 winpos.x = x;
2043 winpos.y = y;
2044 winpos.cx = cx;
2045 winpos.cy = cy;
2046 winpos.flags = flags;
2048 if (WIN_IsCurrentThread( hwnd ))
2049 return USER_SetWindowPos(&winpos);
2051 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2055 /***********************************************************************
2056 * BeginDeferWindowPos (USER32.@)
2058 HDWP WINAPI BeginDeferWindowPos( INT count )
2060 HDWP handle;
2061 DWP *pDWP;
2063 TRACE("%d\n", count);
2065 if (count < 0)
2067 SetLastError(ERROR_INVALID_PARAMETER);
2068 return 0;
2070 /* Windows allows zero count, in which case it allocates context for 8 moves */
2071 if (count == 0) count = 8;
2073 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2074 if (!handle) return 0;
2075 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2076 pDWP->actualCount = 0;
2077 pDWP->suggestedCount = count;
2078 pDWP->valid = TRUE;
2079 pDWP->wMagic = DWP_MAGIC;
2080 pDWP->hwndParent = 0;
2082 TRACE("returning hdwp %p\n", handle);
2083 return handle;
2087 /***********************************************************************
2088 * DeferWindowPos (USER32.@)
2090 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2091 INT x, INT y, INT cx, INT cy,
2092 UINT flags )
2094 DWP *pDWP;
2095 int i;
2096 HDWP newhdwp = hdwp,retvalue;
2098 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2099 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2101 hwnd = WIN_GetFullHandle( hwnd );
2102 if (hwnd == GetDesktopWindow()) return 0;
2104 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2106 USER_Lock();
2108 for (i = 0; i < pDWP->actualCount; i++)
2110 if (pDWP->winPos[i].hwnd == hwnd)
2112 /* Merge with the other changes */
2113 if (!(flags & SWP_NOZORDER))
2115 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2117 if (!(flags & SWP_NOMOVE))
2119 pDWP->winPos[i].x = x;
2120 pDWP->winPos[i].y = y;
2122 if (!(flags & SWP_NOSIZE))
2124 pDWP->winPos[i].cx = cx;
2125 pDWP->winPos[i].cy = cy;
2127 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2128 SWP_NOZORDER | SWP_NOREDRAW |
2129 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2130 SWP_NOOWNERZORDER);
2131 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2132 SWP_FRAMECHANGED);
2133 retvalue = hdwp;
2134 goto END;
2137 if (pDWP->actualCount >= pDWP->suggestedCount)
2139 newhdwp = USER_HEAP_REALLOC( hdwp,
2140 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2141 if (!newhdwp)
2143 retvalue = 0;
2144 goto END;
2146 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2147 pDWP->suggestedCount++;
2149 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2150 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2151 pDWP->winPos[pDWP->actualCount].x = x;
2152 pDWP->winPos[pDWP->actualCount].y = y;
2153 pDWP->winPos[pDWP->actualCount].cx = cx;
2154 pDWP->winPos[pDWP->actualCount].cy = cy;
2155 pDWP->winPos[pDWP->actualCount].flags = flags;
2156 pDWP->actualCount++;
2157 retvalue = newhdwp;
2158 END:
2159 USER_Unlock();
2160 return retvalue;
2164 /***********************************************************************
2165 * EndDeferWindowPos (USER32.@)
2167 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2169 DWP *pDWP;
2170 WINDOWPOS *winpos;
2171 BOOL res = TRUE;
2172 int i;
2174 TRACE("%p\n", hdwp);
2176 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2177 if (!pDWP) return FALSE;
2178 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2180 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2181 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2182 winpos->cx, winpos->cy, winpos->flags);
2184 if (!(res = USER_SetWindowPos( winpos ))) break;
2186 USER_HEAP_FREE( hdwp );
2187 return res;
2191 /***********************************************************************
2192 * ArrangeIconicWindows (USER32.@)
2194 UINT WINAPI ArrangeIconicWindows( HWND parent )
2196 RECT rectParent;
2197 HWND hwndChild;
2198 INT x, y, xspacing, yspacing;
2200 GetClientRect( parent, &rectParent );
2201 x = rectParent.left;
2202 y = rectParent.bottom;
2203 xspacing = GetSystemMetrics(SM_CXICONSPACING);
2204 yspacing = GetSystemMetrics(SM_CYICONSPACING);
2206 hwndChild = GetWindow( parent, GW_CHILD );
2207 while (hwndChild)
2209 if( IsIconic( hwndChild ) )
2211 WINPOS_ShowIconTitle( hwndChild, FALSE );
2213 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
2214 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
2215 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
2216 if( IsWindow(hwndChild) )
2217 WINPOS_ShowIconTitle(hwndChild , TRUE );
2219 if (x <= rectParent.right - xspacing) x += xspacing;
2220 else
2222 x = rectParent.left;
2223 y -= yspacing;
2226 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
2228 return yspacing;
2232 /***********************************************************************
2233 * draw_moving_frame
2235 * Draw the frame used when moving or resizing window.
2237 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
2239 if (thickframe)
2241 const int width = GetSystemMetrics(SM_CXFRAME);
2242 const int height = GetSystemMetrics(SM_CYFRAME);
2244 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
2245 PatBlt( hdc, rect->left, rect->top,
2246 rect->right - rect->left - width, height, PATINVERT );
2247 PatBlt( hdc, rect->left, rect->top + height, width,
2248 rect->bottom - rect->top - height, PATINVERT );
2249 PatBlt( hdc, rect->left + width, rect->bottom - 1,
2250 rect->right - rect->left - width, -height, PATINVERT );
2251 PatBlt( hdc, rect->right - 1, rect->top, -width,
2252 rect->bottom - rect->top - height, PATINVERT );
2253 SelectObject( hdc, hbrush );
2255 else DrawFocusRect( hdc, rect );
2259 /***********************************************************************
2260 * start_size_move
2262 * Initialization of a move or resize, when initiated from a menu choice.
2263 * Return hit test code for caption or sizing border.
2265 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
2267 LONG hittest = 0;
2268 POINT pt;
2269 MSG msg;
2270 RECT rectWindow;
2272 GetWindowRect( hwnd, &rectWindow );
2274 if ((wParam & 0xfff0) == SC_MOVE)
2276 /* Move pointer at the center of the caption */
2277 RECT rect = rectWindow;
2278 /* Note: to be exactly centered we should take the different types
2279 * of border into account, but it shouldn't make more than a few pixels
2280 * of difference so let's not bother with that */
2281 rect.top += GetSystemMetrics(SM_CYBORDER);
2282 if (style & WS_SYSMENU)
2283 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2284 if (style & WS_MINIMIZEBOX)
2285 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2286 if (style & WS_MAXIMIZEBOX)
2287 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2288 pt.x = (rect.right + rect.left) / 2;
2289 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2290 hittest = HTCAPTION;
2291 *capturePoint = pt;
2293 else /* SC_SIZE */
2295 SetCursor( LoadCursorW( 0, (LPWSTR)IDC_SIZEALL ) );
2296 pt.x = pt.y = 0;
2297 while(!hittest)
2299 if (!GetMessageW( &msg, 0, 0, 0 )) return 0;
2300 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2302 switch(msg.message)
2304 case WM_MOUSEMOVE:
2305 pt.x = min( max( msg.pt.x, rectWindow.left ), rectWindow.right - 1 );
2306 pt.y = min( max( msg.pt.y, rectWindow.top ), rectWindow.bottom - 1 );
2307 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
2308 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
2309 break;
2311 case WM_LBUTTONUP:
2312 return 0;
2314 case WM_KEYDOWN:
2315 switch(msg.wParam)
2317 case VK_UP:
2318 hittest = HTTOP;
2319 pt.x =(rectWindow.left+rectWindow.right)/2;
2320 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2321 break;
2322 case VK_DOWN:
2323 hittest = HTBOTTOM;
2324 pt.x =(rectWindow.left+rectWindow.right)/2;
2325 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2326 break;
2327 case VK_LEFT:
2328 hittest = HTLEFT;
2329 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2330 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2331 break;
2332 case VK_RIGHT:
2333 hittest = HTRIGHT;
2334 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2335 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2336 break;
2337 case VK_RETURN:
2338 case VK_ESCAPE:
2339 return 0;
2341 break;
2342 default:
2343 TranslateMessage( &msg );
2344 DispatchMessageW( &msg );
2345 break;
2348 *capturePoint = pt;
2350 SetCursorPos( pt.x, pt.y );
2351 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
2352 return hittest;
2356 /***********************************************************************
2357 * WINPOS_SysCommandSizeMove
2359 * Perform SC_MOVE and SC_SIZE commands.
2361 void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
2363 MSG msg;
2364 RECT sizingRect, mouseRect, origRect;
2365 HDC hdc;
2366 HWND parent;
2367 LONG hittest = (LONG)(wParam & 0x0f);
2368 WPARAM syscommand = wParam & 0xfff0;
2369 HCURSOR hDragCursor = 0, hOldCursor = 0;
2370 POINT minTrack, maxTrack;
2371 POINT capturePoint, pt;
2372 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2373 BOOL thickframe = HAS_THICKFRAME( style );
2374 BOOL iconic = style & WS_MINIMIZE;
2375 BOOL moved = FALSE;
2376 DWORD dwPoint = GetMessagePos ();
2377 BOOL DragFullWindows = TRUE;
2379 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
2381 pt.x = (short)LOWORD(dwPoint);
2382 pt.y = (short)HIWORD(dwPoint);
2383 capturePoint = pt;
2385 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2386 hwnd, syscommand, hittest, pt.x, pt.y);
2388 if (syscommand == SC_MOVE)
2390 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2391 if (!hittest) return;
2393 else /* SC_SIZE */
2395 if ( hittest && (syscommand != SC_MOUSEMENU) )
2396 hittest += (HTLEFT - WMSZ_LEFT);
2397 else
2399 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2400 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2401 if (!hittest)
2403 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2404 return;
2409 /* Get min/max info */
2411 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
2412 GetWindowRect( hwnd, &sizingRect );
2413 if (style & WS_CHILD)
2415 parent = GetParent(hwnd);
2416 /* make sizing rect relative to parent */
2417 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
2418 GetClientRect( parent, &mouseRect );
2420 else
2422 parent = 0;
2423 GetClientRect( GetDesktopWindow(), &mouseRect );
2424 mouseRect.left = GetSystemMetrics( SM_XVIRTUALSCREEN );
2425 mouseRect.top = GetSystemMetrics( SM_YVIRTUALSCREEN );
2426 mouseRect.right = mouseRect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
2427 mouseRect.bottom = mouseRect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
2429 origRect = sizingRect;
2431 if (ON_LEFT_BORDER(hittest))
2433 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2434 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2436 else if (ON_RIGHT_BORDER(hittest))
2438 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2439 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2441 if (ON_TOP_BORDER(hittest))
2443 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2444 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2446 else if (ON_BOTTOM_BORDER(hittest))
2448 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2449 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2451 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2453 /* Retrieve a default cache DC (without using the window style) */
2454 hdc = GetDCEx( parent, 0, DCX_CACHE );
2456 if( iconic ) /* create a cursor for dragging */
2458 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
2459 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
2460 if( !hDragCursor ) iconic = FALSE;
2463 /* we only allow disabling the full window drag for child windows */
2464 if (parent) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0 );
2466 /* repaint the window before moving it around */
2467 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2469 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2470 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2472 while(1)
2474 int dx = 0, dy = 0;
2476 if (!GetMessageW( &msg, 0, 0, 0 )) break;
2477 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2479 /* Exit on button-up, Return, or Esc */
2480 if ((msg.message == WM_LBUTTONUP) ||
2481 ((msg.message == WM_KEYDOWN) &&
2482 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2484 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2486 TranslateMessage( &msg );
2487 DispatchMessageW( &msg );
2488 continue; /* We are not interested in other messages */
2491 pt = msg.pt;
2493 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2495 case VK_UP: pt.y -= 8; break;
2496 case VK_DOWN: pt.y += 8; break;
2497 case VK_LEFT: pt.x -= 8; break;
2498 case VK_RIGHT: pt.x += 8; break;
2501 pt.x = max( pt.x, mouseRect.left );
2502 pt.x = min( pt.x, mouseRect.right );
2503 pt.y = max( pt.y, mouseRect.top );
2504 pt.y = min( pt.y, mouseRect.bottom );
2506 dx = pt.x - capturePoint.x;
2507 dy = pt.y - capturePoint.y;
2509 if (dx || dy)
2511 if( !moved )
2513 moved = TRUE;
2515 if( iconic ) /* ok, no system popup tracking */
2517 hOldCursor = SetCursor(hDragCursor);
2518 ShowCursor( TRUE );
2519 WINPOS_ShowIconTitle( hwnd, FALSE );
2521 else if(!DragFullWindows)
2522 draw_moving_frame( hdc, &sizingRect, thickframe );
2525 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2526 else
2528 RECT newRect = sizingRect;
2529 WPARAM wpSizingHit = 0;
2531 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2532 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2533 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2534 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2535 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2536 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2537 capturePoint = pt;
2539 /* determine the hit location */
2540 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2541 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2542 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2544 if (!iconic)
2546 if(!DragFullWindows)
2547 draw_moving_frame( hdc, &newRect, thickframe );
2548 else
2549 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2550 newRect.right - newRect.left,
2551 newRect.bottom - newRect.top,
2552 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2554 sizingRect = newRect;
2559 if( iconic )
2561 if( moved ) /* restore cursors, show icon title later on */
2563 ShowCursor( FALSE );
2564 SetCursor( hOldCursor );
2567 else if (moved && !DragFullWindows)
2569 draw_moving_frame( hdc, &sizingRect, thickframe );
2572 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2573 ReleaseDC( parent, hdc );
2575 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2576 moved = FALSE;
2578 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2579 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2581 /* window moved or resized */
2582 if (moved)
2584 /* if the moving/resizing isn't canceled call SetWindowPos
2585 * with the new position or the new size of the window
2587 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2589 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2590 if(!DragFullWindows)
2591 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2592 sizingRect.right - sizingRect.left,
2593 sizingRect.bottom - sizingRect.top,
2594 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2596 else
2597 { /* restore previous size/position */
2598 if(DragFullWindows)
2599 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2600 origRect.right - origRect.left,
2601 origRect.bottom - origRect.top,
2602 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2606 if (IsIconic(hwnd))
2608 /* Single click brings up the system menu when iconized */
2610 if( !moved )
2612 if(style & WS_SYSMENU )
2613 SendMessageW( hwnd, WM_SYSCOMMAND,
2614 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2616 else WINPOS_ShowIconTitle( hwnd, TRUE );