d680cc177a6c1ecb4f3ad726402499c8d985f3cb
[wine/wine64.git] / dlls / user32 / winpos.c
blobd680cc177a6c1ecb4f3ad726402499c8d985f3cb
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "wine/server.h"
34 #include "controls.h"
35 #include "user_private.h"
36 #include "win.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define PLACE_MIN 0x0001
68 #define PLACE_MAX 0x0002
69 #define PLACE_RECT 0x0004
72 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
74 typedef struct
76 INT actualCount;
77 INT suggestedCount;
78 BOOL valid;
79 INT wMagic;
80 HWND hwndParent;
81 WINDOWPOS winPos[1];
82 } DWP;
85 /***********************************************************************
86 * SwitchToThisWindow (USER32.@)
88 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
90 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
99 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
100 if (ret)
102 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd, wine_dbgstr_rect(rect) );
105 return ret;
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
114 int nRet = ERROR;
115 NTSTATUS status;
116 HRGN win_rgn = 0;
117 RGNDATA *data;
118 size_t size = 256;
122 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
124 SetLastError( ERROR_OUTOFMEMORY );
125 return ERROR;
127 SERVER_START_REQ( get_window_region )
129 req->window = wine_server_user_handle( hwnd );
130 wine_server_set_reply( req, data->Buffer, size );
131 if (!(status = wine_server_call( req )))
133 size_t reply_size = wine_server_reply_size( reply );
134 if (reply_size)
136 data->rdh.dwSize = sizeof(data->rdh);
137 data->rdh.iType = RDH_RECTANGLES;
138 data->rdh.nCount = reply_size / sizeof(RECT);
139 data->rdh.nRgnSize = reply_size;
140 win_rgn = ExtCreateRegion( NULL, size, data );
143 else size = reply->total_size;
145 SERVER_END_REQ;
146 HeapFree( GetProcessHeap(), 0, data );
147 } while (status == STATUS_BUFFER_OVERFLOW);
149 if (status) SetLastError( RtlNtStatusToDosError(status) );
150 else if (win_rgn)
152 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
153 DeleteObject( win_rgn );
155 return nRet;
159 /***********************************************************************
160 * SetWindowRgn (USER32.@)
162 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
164 static const RECT empty_rect;
165 BOOL ret;
167 if (hrgn)
169 RGNDATA *data;
170 DWORD size;
172 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
173 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
174 if (!GetRegionData( hrgn, size, data ))
176 HeapFree( GetProcessHeap(), 0, data );
177 return FALSE;
179 SERVER_START_REQ( set_window_region )
181 req->window = wine_server_user_handle( hwnd );
182 req->redraw = (bRedraw != 0);
183 if (data->rdh.nCount)
184 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
185 else
186 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
187 ret = !wine_server_call_err( req );
189 SERVER_END_REQ;
191 else /* clear existing region */
193 SERVER_START_REQ( set_window_region )
195 req->window = wine_server_user_handle( 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 i, 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 = wine_server_user_handle( hwnd );
273 req->x = pt.x;
274 req->y = pt.y;
275 wine_server_set_reply( req, list, (size-1) * sizeof(user_handle_t) );
276 if (!wine_server_call( req )) count = reply->count;
278 SERVER_END_REQ;
279 if (count && count < size)
281 /* start from the end since HWND is potentially larger than user_handle_t */
282 for (i = count - 1; i >= 0; i--)
283 list[i] = wine_server_ptr_handle( ((user_handle_t *)list)[i] );
284 list[count] = 0;
285 return list;
287 HeapFree( GetProcessHeap(), 0, list );
288 if (!count) break;
289 size = count + 1; /* restart with a large enough buffer */
291 return NULL;
295 /***********************************************************************
296 * WINPOS_WindowFromPoint
298 * Find the window and hittest for a given point.
300 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
302 int i, res;
303 HWND ret, *list;
305 if (!hwndScope) hwndScope = GetDesktopWindow();
307 *hittest = HTNOWHERE;
309 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
311 /* now determine the hittest */
313 for (i = 0; list[i]; i++)
315 LONG style = GetWindowLongW( list[i], GWL_STYLE );
317 /* If window is minimized or disabled, return at once */
318 if (style & WS_MINIMIZE)
320 *hittest = HTCAPTION;
321 break;
323 if (style & WS_DISABLED)
325 *hittest = HTERROR;
326 break;
328 /* Send WM_NCCHITTEST (if same thread) */
329 if (!WIN_IsCurrentThread( list[i] ))
331 *hittest = HTCLIENT;
332 break;
334 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
335 if (res != HTTRANSPARENT)
337 *hittest = res; /* Found the window */
338 break;
340 /* continue search with next window in z-order */
342 ret = list[i];
343 HeapFree( GetProcessHeap(), 0, list );
344 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
345 return ret;
349 /*******************************************************************
350 * WindowFromPoint (USER32.@)
352 HWND WINAPI WindowFromPoint( POINT pt )
354 INT hittest;
355 return WINPOS_WindowFromPoint( 0, pt, &hittest );
359 /*******************************************************************
360 * ChildWindowFromPoint (USER32.@)
362 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
364 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
367 /*******************************************************************
368 * RealChildWindowFromPoint (USER32.@)
370 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
372 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
375 /*******************************************************************
376 * ChildWindowFromPointEx (USER32.@)
378 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
380 /* pt is in the client coordinates */
381 HWND *list;
382 int i;
383 RECT rect;
384 HWND retvalue;
386 GetClientRect( hwndParent, &rect );
387 if (!PtInRect( &rect, pt )) return 0;
388 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
390 for (i = 0; list[i]; i++)
392 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
393 if (!PtInRect( &rect, pt )) continue;
394 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
396 LONG style = GetWindowLongW( list[i], GWL_STYLE );
397 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
398 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
400 if (uFlags & CWP_SKIPTRANSPARENT)
402 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
404 break;
406 retvalue = list[i];
407 HeapFree( GetProcessHeap(), 0, list );
408 if (!retvalue) retvalue = hwndParent;
409 return retvalue;
413 /*******************************************************************
414 * WINPOS_GetWinOffset
416 * Calculate the offset between the origin of the two windows. Used
417 * to implement MapWindowPoints.
419 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
421 WND * wndPtr;
423 offset->x = offset->y = 0;
425 /* Translate source window origin to screen coords */
426 if (hwndFrom)
428 HWND hwnd = hwndFrom;
430 while (hwnd)
432 if (hwnd == hwndTo) return;
433 if (!(wndPtr = WIN_GetPtr( hwnd )))
435 ERR( "bad hwndFrom = %p\n", hwnd );
436 return;
438 if (wndPtr == WND_DESKTOP) break;
439 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
440 if (wndPtr->parent)
442 offset->x += wndPtr->rectClient.left;
443 offset->y += wndPtr->rectClient.top;
445 hwnd = wndPtr->parent;
446 WIN_ReleasePtr( wndPtr );
450 /* Translate origin to destination window coords */
451 if (hwndTo)
453 HWND hwnd = hwndTo;
455 while (hwnd)
457 if (!(wndPtr = WIN_GetPtr( hwnd )))
459 ERR( "bad hwndTo = %p\n", hwnd );
460 return;
462 if (wndPtr == WND_DESKTOP) break;
463 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
464 if (wndPtr->parent)
466 offset->x -= wndPtr->rectClient.left;
467 offset->y -= wndPtr->rectClient.top;
469 hwnd = wndPtr->parent;
470 WIN_ReleasePtr( wndPtr );
473 return;
475 other_process: /* one of the parents may belong to another process, do it the hard way */
476 offset->x = offset->y = 0;
477 SERVER_START_REQ( get_windows_offset )
479 req->from = wine_server_user_handle( hwndFrom );
480 req->to = wine_server_user_handle( hwndTo );
481 if (!wine_server_call( req ))
483 offset->x = reply->x;
484 offset->y = reply->y;
487 SERVER_END_REQ;
491 /*******************************************************************
492 * MapWindowPoints (USER.258)
494 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
495 LPPOINT16 lppt, UINT16 count )
497 POINT offset;
499 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
500 while (count--)
502 lppt->x += offset.x;
503 lppt->y += offset.y;
504 lppt++;
509 /*******************************************************************
510 * MapWindowPoints (USER32.@)
512 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
514 POINT offset;
516 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
517 while (count--)
519 lppt->x += offset.x;
520 lppt->y += offset.y;
521 lppt++;
523 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
527 /***********************************************************************
528 * IsIconic (USER32.@)
530 BOOL WINAPI IsIconic(HWND hWnd)
532 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
536 /***********************************************************************
537 * IsZoomed (USER32.@)
539 BOOL WINAPI IsZoomed(HWND hWnd)
541 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
545 /*******************************************************************
546 * AllowSetForegroundWindow (USER32.@)
548 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
550 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
551 * implemented, then fix this function. */
552 return TRUE;
556 /*******************************************************************
557 * LockSetForegroundWindow (USER32.@)
559 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
561 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
562 * implemented, then fix this function. */
563 return TRUE;
567 /***********************************************************************
568 * BringWindowToTop (USER32.@)
570 BOOL WINAPI BringWindowToTop( HWND hwnd )
572 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
576 /***********************************************************************
577 * MoveWindow (USER32.@)
579 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
580 BOOL repaint )
582 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
583 if (!repaint) flags |= SWP_NOREDRAW;
584 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
585 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
589 /***********************************************************************
590 * WINPOS_RedrawIconTitle
592 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
594 HWND icon_title = 0;
595 WND *win = WIN_GetPtr( hWnd );
597 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
599 icon_title = win->icon_title;
600 WIN_ReleasePtr( win );
602 if (!icon_title) return FALSE;
603 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
604 InvalidateRect( icon_title, NULL, TRUE );
605 return TRUE;
608 /***********************************************************************
609 * WINPOS_ShowIconTitle
611 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
613 if (!GetPropA( hwnd, "__wine_x11_managed" ))
615 WND *win = WIN_GetPtr( hwnd );
616 HWND title = 0;
618 TRACE("%p %i\n", hwnd, (bShow != 0) );
620 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
621 title = win->icon_title;
622 WIN_ReleasePtr( win );
624 if( bShow )
626 if (!title)
628 title = ICONTITLE_Create( hwnd );
629 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
631 DestroyWindow( title );
632 return FALSE;
634 win->icon_title = title;
635 WIN_ReleasePtr( win );
637 if (!IsWindowVisible(title))
639 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
640 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
641 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
644 else if (title) ShowWindow( title, SW_HIDE );
646 return FALSE;
649 /*******************************************************************
650 * WINPOS_GetMinMaxInfo
652 * Get the minimized and maximized information for a window.
654 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
655 POINT *minTrack, POINT *maxTrack )
657 MINMAXINFO MinMax;
658 HMONITOR monitor;
659 INT xinc, yinc;
660 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
661 LONG exstyle = GetWindowLongW( hwnd, GWL_EXSTYLE );
662 RECT rc;
663 WND *win;
665 /* Compute default values */
667 GetWindowRect(hwnd, &rc);
668 MinMax.ptReserved.x = rc.left;
669 MinMax.ptReserved.y = rc.top;
671 if (style & WS_CHILD)
673 if ((style & WS_CAPTION) == WS_CAPTION)
674 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
676 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
677 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
679 /* avoid calculating this twice */
680 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
682 MinMax.ptMaxSize.x = rc.right - rc.left;
683 MinMax.ptMaxSize.y = rc.bottom - rc.top;
685 else
687 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
688 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
690 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
691 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
692 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
693 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
695 if (HAS_DLGFRAME( style, exstyle ))
697 xinc = GetSystemMetrics(SM_CXDLGFRAME);
698 yinc = GetSystemMetrics(SM_CYDLGFRAME);
700 else
702 xinc = yinc = 0;
703 if (HAS_THICKFRAME(style))
705 xinc += GetSystemMetrics(SM_CXFRAME);
706 yinc += GetSystemMetrics(SM_CYFRAME);
708 if (style & WS_BORDER)
710 xinc += GetSystemMetrics(SM_CXBORDER);
711 yinc += GetSystemMetrics(SM_CYBORDER);
714 MinMax.ptMaxSize.x += 2 * xinc;
715 MinMax.ptMaxSize.y += 2 * yinc;
717 MinMax.ptMaxPosition.x = -xinc;
718 MinMax.ptMaxPosition.y = -yinc;
719 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
721 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
722 WIN_ReleasePtr( win );
725 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
727 /* if the app didn't change the values, adapt them for the current monitor */
729 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
731 RECT rc_work;
732 MONITORINFO mon_info;
734 mon_info.cbSize = sizeof(mon_info);
735 GetMonitorInfoW( monitor, &mon_info );
737 rc_work = mon_info.rcMonitor;
739 if (style & WS_MAXIMIZEBOX)
741 if ((style & WS_CAPTION) == WS_CAPTION || !(style & (WS_CHILD | WS_POPUP)))
742 rc_work = mon_info.rcWork;
745 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
746 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
748 MinMax.ptMaxSize.x = (rc_work.right - rc_work.left) + 2 * xinc;
749 MinMax.ptMaxSize.y = (rc_work.bottom - rc_work.top) + 2 * yinc;
751 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
753 MinMax.ptMaxPosition.x = rc_work.left - xinc;
754 MinMax.ptMaxPosition.y = rc_work.top - yinc;
758 /* Some sanity checks */
760 TRACE("%d %d / %d %d / %d %d / %d %d\n",
761 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
762 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
763 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
764 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
765 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
766 MinMax.ptMinTrackSize.x );
767 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
768 MinMax.ptMinTrackSize.y );
770 if (maxSize) *maxSize = MinMax.ptMaxSize;
771 if (maxPos) *maxPos = MinMax.ptMaxPosition;
772 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
773 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
777 /***********************************************************************
778 * WINPOS_FindIconPos
780 * Find a suitable place for an iconic window.
782 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
784 RECT rect, rectParent;
785 HWND parent, child;
786 HRGN hrgn, tmp;
787 int xspacing, yspacing;
789 parent = GetAncestor( hwnd, GA_PARENT );
790 GetClientRect( parent, &rectParent );
791 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
792 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
793 return pt; /* The icon already has a suitable position */
795 xspacing = GetSystemMetrics(SM_CXICONSPACING);
796 yspacing = GetSystemMetrics(SM_CYICONSPACING);
798 /* Check if another icon already occupies this spot */
799 /* FIXME: this is completely inefficient */
801 hrgn = CreateRectRgn( 0, 0, 0, 0 );
802 tmp = CreateRectRgn( 0, 0, 0, 0 );
803 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
805 WND *childPtr;
806 if (child == hwnd) continue;
807 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
808 continue;
809 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
810 continue;
811 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
812 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
813 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
814 WIN_ReleasePtr( childPtr );
816 DeleteObject( tmp );
818 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
820 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
822 rect.right = rect.left + xspacing;
823 rect.top = rect.bottom - yspacing;
824 if (!RectInRegion( hrgn, &rect ))
826 /* No window was found, so it's OK for us */
827 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
828 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
829 DeleteObject( hrgn );
830 return pt;
834 DeleteObject( hrgn );
835 pt.x = pt.y = 0;
836 return pt;
840 /***********************************************************************
841 * WINPOS_MinMaximize
843 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
845 WND *wndPtr;
846 UINT swpFlags = 0;
847 POINT size;
848 LONG old_style;
849 WINDOWPLACEMENT wpl;
851 TRACE("%p %u\n", hwnd, cmd );
853 wpl.length = sizeof(wpl);
854 GetWindowPlacement( hwnd, &wpl );
856 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
857 return SWP_NOSIZE | SWP_NOMOVE;
859 if (IsIconic( hwnd ))
861 switch (cmd)
863 case SW_SHOWMINNOACTIVE:
864 case SW_SHOWMINIMIZED:
865 case SW_FORCEMINIMIZE:
866 case SW_MINIMIZE:
867 return SWP_NOSIZE | SWP_NOMOVE;
869 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
870 swpFlags |= SWP_NOCOPYBITS;
873 switch( cmd )
875 case SW_SHOWMINNOACTIVE:
876 case SW_SHOWMINIMIZED:
877 case SW_FORCEMINIMIZE:
878 case SW_MINIMIZE:
879 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
880 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
881 else wndPtr->flags &= ~WIN_RESTORE_MAX;
882 WIN_ReleasePtr( wndPtr );
884 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
886 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
888 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
889 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
890 wpl.ptMinPosition.x + GetSystemMetrics(SM_CXICON),
891 wpl.ptMinPosition.y + GetSystemMetrics(SM_CYICON) );
892 swpFlags |= SWP_NOCOPYBITS;
893 break;
895 case SW_MAXIMIZE:
896 old_style = GetWindowLongW( hwnd, GWL_STYLE );
897 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
899 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
901 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
902 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
904 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
905 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
906 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
907 break;
909 case SW_SHOWNOACTIVATE:
910 case SW_SHOWNORMAL:
911 case SW_RESTORE:
912 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
913 if (old_style & WS_MINIMIZE)
915 BOOL restore_max;
917 WINPOS_ShowIconTitle( hwnd, FALSE );
919 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
920 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
921 WIN_ReleasePtr( wndPtr );
922 if (restore_max)
924 /* Restore to maximized position */
925 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
926 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
927 swpFlags |= SWP_STATECHANGED;
928 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
929 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
930 break;
933 else if (!(old_style & WS_MAXIMIZE)) break;
935 swpFlags |= SWP_STATECHANGED;
937 /* Restore to normal position */
939 *rect = wpl.rcNormalPosition;
940 break;
943 return swpFlags;
947 /***********************************************************************
948 * show_window
950 * Implementation of ShowWindow and ShowWindowAsync.
952 static BOOL show_window( HWND hwnd, INT cmd )
954 WND *wndPtr;
955 HWND parent;
956 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
957 BOOL wasVisible = (style & WS_VISIBLE) != 0;
958 BOOL showFlag = TRUE;
959 RECT newPos = {0, 0, 0, 0};
960 UINT swp = 0;
962 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
964 switch(cmd)
966 case SW_HIDE:
967 if (!wasVisible) return FALSE;
968 showFlag = FALSE;
969 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
970 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
971 break;
973 case SW_SHOWMINNOACTIVE:
974 case SW_MINIMIZE:
975 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
976 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
977 /* fall through */
978 case SW_SHOWMINIMIZED:
979 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
980 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
981 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
982 break;
984 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
985 if (!wasVisible) swp |= SWP_SHOWWINDOW;
986 swp |= SWP_FRAMECHANGED;
987 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
988 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
989 break;
991 case SW_SHOWNA:
992 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
993 if (style & WS_CHILD) swp |= SWP_NOZORDER;
994 break;
995 case SW_SHOW:
996 if (wasVisible) return TRUE;
997 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
998 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
999 break;
1001 case SW_SHOWNOACTIVATE:
1002 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1003 /* fall through */
1004 case SW_RESTORE:
1005 /* fall through */
1006 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1007 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1008 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1009 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1011 swp |= SWP_FRAMECHANGED;
1012 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1014 else
1016 if (wasVisible) return TRUE;
1017 swp |= SWP_NOSIZE | SWP_NOMOVE;
1019 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1020 break;
1021 default:
1022 return wasVisible;
1025 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1027 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1028 if (!IsWindow( hwnd )) return wasVisible;
1031 swp = USER_Driver->pShowWindow( hwnd, cmd, &newPos, swp );
1033 parent = GetAncestor( hwnd, GA_PARENT );
1034 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1036 /* if parent is not visible simply toggle WS_VISIBLE and return */
1037 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1038 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1040 else
1041 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1042 newPos.right - newPos.left, newPos.bottom - newPos.top, swp );
1044 if (cmd == SW_HIDE)
1046 HWND hFocus;
1048 WINPOS_ShowIconTitle( hwnd, FALSE );
1050 /* FIXME: This will cause the window to be activated irrespective
1051 * of whether it is owned by the same thread. Has to be done
1052 * asynchronously.
1055 if (hwnd == GetActiveWindow())
1056 WINPOS_ActivateOtherWindow(hwnd);
1058 /* Revert focus to parent */
1059 hFocus = GetFocus();
1060 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1062 HWND parent = GetAncestor(hwnd, GA_PARENT);
1063 if (parent == GetDesktopWindow()) parent = 0;
1064 SetFocus(parent);
1066 return wasVisible;
1069 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1071 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1073 if (wndPtr->flags & WIN_NEED_SIZE)
1075 /* should happen only in CreateWindowEx() */
1076 int wParam = SIZE_RESTORED;
1077 RECT client = wndPtr->rectClient;
1079 wndPtr->flags &= ~WIN_NEED_SIZE;
1080 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1081 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1082 WIN_ReleasePtr( wndPtr );
1084 SendMessageW( hwnd, WM_SIZE, wParam,
1085 MAKELONG( client.right - client.left, client.bottom - client.top ));
1086 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1088 else WIN_ReleasePtr( wndPtr );
1090 /* if previous state was minimized Windows sets focus to the window */
1091 if (style & WS_MINIMIZE) SetFocus( hwnd );
1093 return wasVisible;
1097 /***********************************************************************
1098 * ShowWindowAsync (USER32.@)
1100 * doesn't wait; returns immediately.
1101 * used by threads to toggle windows in other (possibly hanging) threads
1103 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1105 HWND full_handle;
1107 if (is_broadcast(hwnd))
1109 SetLastError( ERROR_INVALID_PARAMETER );
1110 return FALSE;
1113 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1114 return show_window( full_handle, cmd );
1116 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1120 /***********************************************************************
1121 * ShowWindow (USER32.@)
1123 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1125 HWND full_handle;
1127 if (is_broadcast(hwnd))
1129 SetLastError( ERROR_INVALID_PARAMETER );
1130 return FALSE;
1132 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1133 return show_window( full_handle, cmd );
1135 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1139 /***********************************************************************
1140 * GetInternalWindowPos (USER32.@)
1142 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1143 LPPOINT ptIcon )
1145 WINDOWPLACEMENT wndpl;
1146 if (GetWindowPlacement( hwnd, &wndpl ))
1148 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1149 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1150 return wndpl.showCmd;
1152 return 0;
1156 /***********************************************************************
1157 * GetWindowPlacement (USER32.@)
1159 * Win95:
1160 * Fails if wndpl->length of Win95 (!) apps is invalid.
1162 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1164 WND *pWnd = WIN_GetPtr( hwnd );
1166 if (!pWnd) return FALSE;
1168 if (pWnd == WND_DESKTOP)
1170 wndpl->length = sizeof(*wndpl);
1171 wndpl->showCmd = SW_SHOWNORMAL;
1172 wndpl->flags = 0;
1173 wndpl->ptMinPosition.x = -1;
1174 wndpl->ptMinPosition.y = -1;
1175 wndpl->ptMaxPosition.x = -1;
1176 wndpl->ptMaxPosition.y = -1;
1177 GetWindowRect( hwnd, &wndpl->rcNormalPosition );
1178 return TRUE;
1180 if (pWnd == WND_OTHER_PROCESS)
1182 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1183 return FALSE;
1186 /* update the placement according to the current style */
1187 if (pWnd->dwStyle & WS_MINIMIZE)
1189 pWnd->min_pos.x = pWnd->rectWindow.left;
1190 pWnd->min_pos.y = pWnd->rectWindow.top;
1192 else if (pWnd->dwStyle & WS_MAXIMIZE)
1194 pWnd->max_pos.x = pWnd->rectWindow.left;
1195 pWnd->max_pos.y = pWnd->rectWindow.top;
1197 else
1199 pWnd->normal_rect = pWnd->rectWindow;
1202 wndpl->length = sizeof(*wndpl);
1203 if( pWnd->dwStyle & WS_MINIMIZE )
1204 wndpl->showCmd = SW_SHOWMINIMIZED;
1205 else
1206 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1207 if( pWnd->flags & WIN_RESTORE_MAX )
1208 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1209 else
1210 wndpl->flags = 0;
1211 wndpl->ptMinPosition = pWnd->min_pos;
1212 wndpl->ptMaxPosition = pWnd->max_pos;
1213 wndpl->rcNormalPosition = pWnd->normal_rect;
1214 WIN_ReleasePtr( pWnd );
1216 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1217 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1218 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1219 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1220 return TRUE;
1223 /* make sure the specified rect is visible on screen */
1224 static void make_rect_onscreen( RECT *rect )
1226 MONITORINFO info;
1227 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1229 info.cbSize = sizeof(info);
1230 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1231 /* FIXME: map coordinates from rcWork to rcMonitor */
1232 if (rect->right <= info.rcWork.left)
1234 rect->right += info.rcWork.left - rect->left;
1235 rect->left = info.rcWork.left;
1237 else if (rect->left >= info.rcWork.right)
1239 rect->left += info.rcWork.right - rect->right;
1240 rect->right = info.rcWork.right;
1242 if (rect->bottom <= info.rcWork.top)
1244 rect->bottom += info.rcWork.top - rect->top;
1245 rect->top = info.rcWork.top;
1247 else if (rect->top >= info.rcWork.bottom)
1249 rect->top += info.rcWork.bottom - rect->bottom;
1250 rect->bottom = info.rcWork.bottom;
1254 /* make sure the specified point is visible on screen */
1255 static void make_point_onscreen( POINT *pt )
1257 RECT rect;
1259 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1260 make_rect_onscreen( &rect );
1261 pt->x = rect.left;
1262 pt->y = rect.top;
1266 /***********************************************************************
1267 * WINPOS_SetPlacement
1269 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1271 DWORD style;
1272 WND *pWnd = WIN_GetPtr( hwnd );
1273 WINDOWPLACEMENT wp = *wndpl;
1275 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1276 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1277 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1279 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1280 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1281 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1282 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1283 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1284 wine_dbgstr_rect(&wp.rcNormalPosition) );
1286 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1288 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1289 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1290 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1292 style = pWnd->dwStyle;
1294 WIN_ReleasePtr( pWnd );
1296 if( style & WS_MINIMIZE )
1298 if (flags & PLACE_MIN)
1300 WINPOS_ShowIconTitle( hwnd, FALSE );
1301 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1302 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1305 else if( style & WS_MAXIMIZE )
1307 if (flags & PLACE_MAX)
1308 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1309 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1311 else if( flags & PLACE_RECT )
1312 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1313 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1314 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1315 SWP_NOZORDER | SWP_NOACTIVATE );
1317 ShowWindow( hwnd, wndpl->showCmd );
1319 if (IsIconic( hwnd ))
1321 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1323 /* SDK: ...valid only the next time... */
1324 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1326 pWnd = WIN_GetPtr( hwnd );
1327 if (pWnd && pWnd != WND_OTHER_PROCESS)
1329 pWnd->flags |= WIN_RESTORE_MAX;
1330 WIN_ReleasePtr( pWnd );
1334 return TRUE;
1338 /***********************************************************************
1339 * SetWindowPlacement (USER32.@)
1341 * Win95:
1342 * Fails if wndpl->length of Win95 (!) apps is invalid.
1344 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1346 UINT flags = PLACE_MAX | PLACE_RECT;
1347 if (!wpl) return FALSE;
1348 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1349 return WINPOS_SetPlacement( hwnd, wpl, flags );
1353 /***********************************************************************
1354 * AnimateWindow (USER32.@)
1355 * Shows/Hides a window with an animation
1356 * NO ANIMATION YET
1358 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1360 FIXME("partial stub\n");
1362 /* If trying to show/hide and it's already *
1363 * shown/hidden or invalid window, fail with *
1364 * invalid parameter */
1365 if(!IsWindow(hwnd) ||
1366 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1367 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1369 SetLastError(ERROR_INVALID_PARAMETER);
1370 return FALSE;
1373 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1375 return TRUE;
1378 /***********************************************************************
1379 * SetInternalWindowPos (USER32.@)
1381 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1382 LPRECT rect, LPPOINT pt )
1384 WINDOWPLACEMENT wndpl;
1385 UINT flags;
1387 wndpl.length = sizeof(wndpl);
1388 wndpl.showCmd = showCmd;
1389 wndpl.flags = flags = 0;
1391 if( pt )
1393 flags |= PLACE_MIN;
1394 wndpl.flags |= WPF_SETMINPOSITION;
1395 wndpl.ptMinPosition = *pt;
1397 if( rect )
1399 flags |= PLACE_RECT;
1400 wndpl.rcNormalPosition = *rect;
1402 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1406 /*******************************************************************
1407 * can_activate_window
1409 * Check if we can activate the specified window.
1411 static BOOL can_activate_window( HWND hwnd )
1413 LONG style;
1415 if (!hwnd) return FALSE;
1416 style = GetWindowLongW( hwnd, GWL_STYLE );
1417 if (!(style & WS_VISIBLE)) return FALSE;
1418 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1419 return !(style & WS_DISABLED);
1423 /*******************************************************************
1424 * WINPOS_ActivateOtherWindow
1426 * Activates window other than pWnd.
1428 void WINPOS_ActivateOtherWindow(HWND hwnd)
1430 HWND hwndTo, fg;
1432 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1434 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1435 if (can_activate_window( hwndTo )) goto done;
1438 hwndTo = hwnd;
1439 for (;;)
1441 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1442 if (can_activate_window( hwndTo )) break;
1445 done:
1446 fg = GetForegroundWindow();
1447 TRACE("win = %p fg = %p\n", hwndTo, fg);
1448 if (!fg || (hwnd == fg))
1450 if (SetForegroundWindow( hwndTo )) return;
1452 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1456 /***********************************************************************
1457 * WINPOS_HandleWindowPosChanging
1459 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1461 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1463 POINT minTrack, maxTrack;
1464 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1466 if (winpos->flags & SWP_NOSIZE) return 0;
1467 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1469 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1470 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1471 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1472 if (!(style & WS_MINIMIZE))
1474 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1475 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1478 return 0;
1482 /***********************************************************************
1483 * dump_winpos_flags
1485 static void dump_winpos_flags(UINT flags)
1487 static const DWORD dumped_flags = (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW |
1488 SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW |
1489 SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOOWNERZORDER |
1490 SWP_NOSENDCHANGING | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS |
1491 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_STATECHANGED);
1492 TRACE("flags:");
1493 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1494 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1495 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1496 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1497 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1498 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1499 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1500 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1501 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1502 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1503 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1504 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1505 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1506 if(flags & SWP_NOCLIENTSIZE) TRACE(" SWP_NOCLIENTSIZE");
1507 if(flags & SWP_NOCLIENTMOVE) TRACE(" SWP_NOCLIENTMOVE");
1508 if(flags & SWP_STATECHANGED) TRACE(" SWP_STATECHANGED");
1510 if(flags & ~dumped_flags) TRACE(" %08x", flags & ~dumped_flags);
1511 TRACE("\n");
1514 /***********************************************************************
1515 * SWP_DoWinPosChanging
1517 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1519 WND *wndPtr;
1521 /* Send WM_WINDOWPOSCHANGING message */
1523 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1524 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1526 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1527 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1529 /* Calculate new position and size */
1531 *pNewWindowRect = wndPtr->rectWindow;
1532 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1533 : wndPtr->rectClient;
1535 if (!(pWinpos->flags & SWP_NOSIZE))
1537 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1538 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1540 if (!(pWinpos->flags & SWP_NOMOVE))
1542 pNewWindowRect->left = pWinpos->x;
1543 pNewWindowRect->top = pWinpos->y;
1544 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1545 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1547 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1548 pWinpos->y - wndPtr->rectWindow.top );
1550 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1552 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1553 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1554 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1555 TRACE( "current %s style %08x new %s\n",
1556 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1557 wine_dbgstr_rect( pNewWindowRect ));
1559 WIN_ReleasePtr( wndPtr );
1560 return TRUE;
1563 /***********************************************************************
1564 * get_valid_rects
1566 * Compute the valid rects from the old and new client rect and WVR_* flags.
1567 * Helper for WM_NCCALCSIZE handling.
1569 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1570 RECT *valid )
1572 int cx, cy;
1574 if (flags & WVR_REDRAW)
1576 SetRectEmpty( &valid[0] );
1577 SetRectEmpty( &valid[1] );
1578 return;
1581 if (flags & WVR_VALIDRECTS)
1583 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1584 !IntersectRect( &valid[1], &valid[1], old_client ))
1586 SetRectEmpty( &valid[0] );
1587 SetRectEmpty( &valid[1] );
1588 return;
1590 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1592 else
1594 valid[0] = *new_client;
1595 valid[1] = *old_client;
1598 /* make sure the rectangles have the same size */
1599 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1600 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1602 if (flags & WVR_ALIGNBOTTOM)
1604 valid[0].top = valid[0].bottom - cy;
1605 valid[1].top = valid[1].bottom - cy;
1607 else
1609 valid[0].bottom = valid[0].top + cy;
1610 valid[1].bottom = valid[1].top + cy;
1612 if (flags & WVR_ALIGNRIGHT)
1614 valid[0].left = valid[0].right - cx;
1615 valid[1].left = valid[1].right - cx;
1617 else
1619 valid[0].right = valid[0].left + cx;
1620 valid[1].right = valid[1].left + cx;
1625 /***********************************************************************
1626 * SWP_DoOwnedPopups
1628 * fix Z order taking into account owned popups -
1629 * basically we need to maintain them above the window that owns them
1631 * FIXME: hide/show owned popups when owner visibility changes.
1633 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1635 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1636 HWND owner, *list = NULL;
1637 unsigned int i;
1639 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1641 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1643 /* make sure this popup stays above the owner */
1645 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1647 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1649 for (i = 0; list[i]; i++)
1651 if (list[i] == owner)
1653 if (i > 0) hwndInsertAfter = list[i-1];
1654 else hwndInsertAfter = HWND_TOP;
1655 break;
1658 if (hwndInsertAfter == HWND_NOTOPMOST)
1660 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1662 else if (list[i] == hwndInsertAfter) break;
1666 else if (style & WS_CHILD) return hwndInsertAfter;
1668 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1669 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1671 i = 0;
1672 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1674 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1676 /* skip all the topmost windows */
1677 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1680 else if (hwndInsertAfter != HWND_TOPMOST)
1682 /* skip windows that are already placed correctly */
1683 for (i = 0; list[i]; i++)
1685 if (list[i] == hwndInsertAfter) break;
1686 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1690 for ( ; list[i]; i++)
1692 if (list[i] == hwnd) break;
1693 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1694 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1695 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1696 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1697 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1698 hwndInsertAfter = list[i];
1701 done:
1702 HeapFree( GetProcessHeap(), 0, list );
1703 return hwndInsertAfter;
1706 /***********************************************************************
1707 * SWP_DoNCCalcSize
1709 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1710 RECT *validRects )
1712 UINT wvrFlags = 0;
1713 WND *wndPtr;
1715 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1717 /* Send WM_NCCALCSIZE message to get new client area */
1718 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1720 NCCALCSIZE_PARAMS params;
1721 WINDOWPOS winposCopy;
1723 params.rgrc[0] = *pNewWindowRect;
1724 params.rgrc[1] = wndPtr->rectWindow;
1725 params.rgrc[2] = wndPtr->rectClient;
1726 params.lppos = &winposCopy;
1727 winposCopy = *pWinpos;
1728 WIN_ReleasePtr( wndPtr );
1730 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1732 *pNewClientRect = params.rgrc[0];
1734 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1736 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1737 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1738 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1740 if( pNewClientRect->left != wndPtr->rectClient.left ||
1741 pNewClientRect->top != wndPtr->rectClient.top )
1742 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1744 if( (pNewClientRect->right - pNewClientRect->left !=
1745 wndPtr->rectClient.right - wndPtr->rectClient.left))
1746 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1747 else
1748 wvrFlags &= ~WVR_HREDRAW;
1750 if (pNewClientRect->bottom - pNewClientRect->top !=
1751 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1752 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1753 else
1754 wvrFlags &= ~WVR_VREDRAW;
1756 validRects[0] = params.rgrc[1];
1757 validRects[1] = params.rgrc[2];
1759 else
1761 if (!(pWinpos->flags & SWP_NOMOVE) &&
1762 (pNewClientRect->left != wndPtr->rectClient.left ||
1763 pNewClientRect->top != wndPtr->rectClient.top))
1764 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1767 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1769 SetRectEmpty( &validRects[0] );
1770 SetRectEmpty( &validRects[1] );
1772 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1774 WIN_ReleasePtr( wndPtr );
1775 return wvrFlags;
1778 /* fix redundant flags and values in the WINDOWPOS structure */
1779 static BOOL fixup_flags( WINDOWPOS *winpos )
1781 HWND parent;
1782 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1783 BOOL ret = TRUE;
1785 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1787 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1788 return FALSE;
1790 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1792 /* Finally make sure that all coordinates are valid */
1793 if (winpos->x < -32768) winpos->x = -32768;
1794 else if (winpos->x > 32767) winpos->x = 32767;
1795 if (winpos->y < -32768) winpos->y = -32768;
1796 else if (winpos->y > 32767) winpos->y = 32767;
1798 if (winpos->cx < 0) winpos->cx = 0;
1799 else if (winpos->cx > 32767) winpos->cx = 32767;
1800 if (winpos->cy < 0) winpos->cy = 0;
1801 else if (winpos->cy > 32767) winpos->cy = 32767;
1803 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1804 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1806 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1807 else
1809 winpos->flags &= ~SWP_HIDEWINDOW;
1810 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1813 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1814 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1815 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1817 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1818 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1820 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1822 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1823 (winpos->flags & SWP_NOZORDER ||
1824 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1826 winpos->flags &= ~SWP_NOZORDER;
1827 winpos->hwndInsertAfter = HWND_TOP;
1831 /* Check hwndInsertAfter */
1832 if (winpos->flags & SWP_NOZORDER) goto done;
1834 /* fix sign extension */
1835 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1836 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1838 /* hwndInsertAfter must be a sibling of the window */
1839 if (winpos->hwndInsertAfter == HWND_TOP)
1841 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1842 winpos->flags |= SWP_NOZORDER;
1844 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1846 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1847 winpos->flags |= SWP_NOZORDER;
1849 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1851 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1852 winpos->flags |= SWP_NOZORDER;
1854 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1856 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1857 winpos->flags |= SWP_NOZORDER;
1859 else
1861 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1862 else
1864 /* don't need to change the Zorder of hwnd if it's already inserted
1865 * after hwndInsertAfter or when inserting hwnd after itself.
1867 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1868 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1869 winpos->flags |= SWP_NOZORDER;
1872 done:
1873 WIN_ReleasePtr( wndPtr );
1874 return ret;
1878 /***********************************************************************
1879 * set_window_pos
1881 * Backend implementation of SetWindowPos.
1883 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1884 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1886 WND *win;
1887 BOOL ret;
1888 RECT visible_rect, old_window_rect;
1890 visible_rect = *window_rect;
1891 USER_Driver->pWindowPosChanging( hwnd, insert_after, swp_flags,
1892 window_rect, client_rect, &visible_rect );
1894 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
1895 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
1897 old_window_rect = win->rectWindow;
1898 SERVER_START_REQ( set_window_pos )
1900 req->handle = wine_server_user_handle( hwnd );
1901 req->previous = wine_server_user_handle( insert_after );
1902 req->flags = swp_flags;
1903 req->window.left = window_rect->left;
1904 req->window.top = window_rect->top;
1905 req->window.right = window_rect->right;
1906 req->window.bottom = window_rect->bottom;
1907 req->client.left = client_rect->left;
1908 req->client.top = client_rect->top;
1909 req->client.right = client_rect->right;
1910 req->client.bottom = client_rect->bottom;
1911 if (memcmp( window_rect, &visible_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
1913 wine_server_add_data( req, &visible_rect, sizeof(visible_rect) );
1914 if (!IsRectEmpty( &valid_rects[0] ))
1915 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1917 if ((ret = !wine_server_call( req )))
1919 win->dwStyle = reply->new_style;
1920 win->dwExStyle = reply->new_ex_style;
1921 win->rectWindow = *window_rect;
1922 win->rectClient = *client_rect;
1925 SERVER_END_REQ;
1926 WIN_ReleasePtr( win );
1928 if (ret)
1930 if (((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) ||
1931 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW | SWP_STATECHANGED)))
1932 invalidate_dce( hwnd, &old_window_rect );
1934 USER_Driver->pWindowPosChanged( hwnd, insert_after, swp_flags, window_rect,
1935 client_rect, &visible_rect, valid_rects );
1937 return ret;
1941 /***********************************************************************
1942 * USER_SetWindowPos
1944 * User32 internal function
1946 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1948 RECT newWindowRect, newClientRect, valid_rects[2];
1949 UINT orig_flags;
1951 orig_flags = winpos->flags;
1953 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1954 if (!(winpos->flags & SWP_NOMOVE))
1956 if (winpos->x < -32768) winpos->x = -32768;
1957 else if (winpos->x > 32767) winpos->x = 32767;
1958 if (winpos->y < -32768) winpos->y = -32768;
1959 else if (winpos->y > 32767) winpos->y = 32767;
1961 if (!(winpos->flags & SWP_NOSIZE))
1963 if (winpos->cx < 0) winpos->cx = 0;
1964 else if (winpos->cx > 32767) winpos->cx = 32767;
1965 if (winpos->cy < 0) winpos->cy = 0;
1966 else if (winpos->cy > 32767) winpos->cy = 32767;
1969 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1971 /* Fix redundant flags */
1972 if (!fixup_flags( winpos )) return FALSE;
1974 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1976 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1977 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1980 /* Common operations */
1982 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1984 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1985 &newWindowRect, &newClientRect, valid_rects ))
1986 return FALSE;
1988 /* erase parent when hiding or resizing child */
1989 if (!(orig_flags & SWP_DEFERERASE) &&
1990 ((orig_flags & SWP_HIDEWINDOW) ||
1991 (!(orig_flags & SWP_SHOWWINDOW) &&
1992 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1994 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1995 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1996 erase_now( parent, 0 );
1999 if( winpos->flags & SWP_HIDEWINDOW )
2000 HideCaret(winpos->hwnd);
2001 else if (winpos->flags & SWP_SHOWWINDOW)
2002 ShowCaret(winpos->hwnd);
2004 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
2006 /* child windows get WM_CHILDACTIVATE message */
2007 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
2008 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
2009 else
2010 SetForegroundWindow( winpos->hwnd );
2013 /* And last, send the WM_WINDOWPOSCHANGED message */
2015 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2017 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2019 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2020 and always contains final window position.
2022 winpos->x = newWindowRect.left;
2023 winpos->y = newWindowRect.top;
2024 winpos->cx = newWindowRect.right - newWindowRect.left;
2025 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2026 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2028 return TRUE;
2031 /***********************************************************************
2032 * SetWindowPos (USER32.@)
2034 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2035 INT x, INT y, INT cx, INT cy, UINT flags )
2037 WINDOWPOS winpos;
2039 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2040 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2041 if(TRACE_ON(win)) dump_winpos_flags(flags);
2043 if (is_broadcast(hwnd))
2045 SetLastError( ERROR_INVALID_PARAMETER );
2046 return FALSE;
2049 winpos.hwnd = WIN_GetFullHandle(hwnd);
2050 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2051 winpos.x = x;
2052 winpos.y = y;
2053 winpos.cx = cx;
2054 winpos.cy = cy;
2055 winpos.flags = flags;
2057 if (WIN_IsCurrentThread( hwnd ))
2058 return USER_SetWindowPos(&winpos);
2060 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2064 /***********************************************************************
2065 * BeginDeferWindowPos (USER32.@)
2067 HDWP WINAPI BeginDeferWindowPos( INT count )
2069 HDWP handle;
2070 DWP *pDWP;
2072 TRACE("%d\n", count);
2074 if (count < 0)
2076 SetLastError(ERROR_INVALID_PARAMETER);
2077 return 0;
2079 /* Windows allows zero count, in which case it allocates context for 8 moves */
2080 if (count == 0) count = 8;
2082 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2083 if (!handle) return 0;
2084 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2085 pDWP->actualCount = 0;
2086 pDWP->suggestedCount = count;
2087 pDWP->valid = TRUE;
2088 pDWP->wMagic = DWP_MAGIC;
2089 pDWP->hwndParent = 0;
2091 TRACE("returning hdwp %p\n", handle);
2092 return handle;
2096 /***********************************************************************
2097 * DeferWindowPos (USER32.@)
2099 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2100 INT x, INT y, INT cx, INT cy,
2101 UINT flags )
2103 DWP *pDWP;
2104 int i;
2105 HDWP newhdwp = hdwp,retvalue;
2107 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2108 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2110 hwnd = WIN_GetFullHandle( hwnd );
2111 if (is_desktop_window( hwnd )) return 0;
2113 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2115 USER_Lock();
2117 for (i = 0; i < pDWP->actualCount; i++)
2119 if (pDWP->winPos[i].hwnd == hwnd)
2121 /* Merge with the other changes */
2122 if (!(flags & SWP_NOZORDER))
2124 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2126 if (!(flags & SWP_NOMOVE))
2128 pDWP->winPos[i].x = x;
2129 pDWP->winPos[i].y = y;
2131 if (!(flags & SWP_NOSIZE))
2133 pDWP->winPos[i].cx = cx;
2134 pDWP->winPos[i].cy = cy;
2136 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2137 SWP_NOZORDER | SWP_NOREDRAW |
2138 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2139 SWP_NOOWNERZORDER);
2140 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2141 SWP_FRAMECHANGED);
2142 retvalue = hdwp;
2143 goto END;
2146 if (pDWP->actualCount >= pDWP->suggestedCount)
2148 newhdwp = USER_HEAP_REALLOC( hdwp,
2149 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2150 if (!newhdwp)
2152 retvalue = 0;
2153 goto END;
2155 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2156 pDWP->suggestedCount++;
2158 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2159 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2160 pDWP->winPos[pDWP->actualCount].x = x;
2161 pDWP->winPos[pDWP->actualCount].y = y;
2162 pDWP->winPos[pDWP->actualCount].cx = cx;
2163 pDWP->winPos[pDWP->actualCount].cy = cy;
2164 pDWP->winPos[pDWP->actualCount].flags = flags;
2165 pDWP->actualCount++;
2166 retvalue = newhdwp;
2167 END:
2168 USER_Unlock();
2169 return retvalue;
2173 /***********************************************************************
2174 * EndDeferWindowPos (USER32.@)
2176 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2178 DWP *pDWP;
2179 WINDOWPOS *winpos;
2180 BOOL res = TRUE;
2181 int i;
2183 TRACE("%p\n", hdwp);
2185 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2186 if (!pDWP) return FALSE;
2187 for (i = 0, winpos = pDWP->winPos; res && i < pDWP->actualCount; i++, winpos++)
2189 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2190 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2191 winpos->cx, winpos->cy, winpos->flags);
2193 if (WIN_IsCurrentThread( winpos->hwnd ))
2194 res = USER_SetWindowPos( winpos );
2195 else
2196 res = SendMessageW( winpos->hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)winpos );
2198 USER_HEAP_FREE( hdwp );
2199 return res;
2203 /***********************************************************************
2204 * ArrangeIconicWindows (USER32.@)
2206 UINT WINAPI ArrangeIconicWindows( HWND parent )
2208 RECT rectParent;
2209 HWND hwndChild;
2210 INT x, y, xspacing, yspacing;
2212 GetClientRect( parent, &rectParent );
2213 x = rectParent.left;
2214 y = rectParent.bottom;
2215 xspacing = GetSystemMetrics(SM_CXICONSPACING);
2216 yspacing = GetSystemMetrics(SM_CYICONSPACING);
2218 hwndChild = GetWindow( parent, GW_CHILD );
2219 while (hwndChild)
2221 if( IsIconic( hwndChild ) )
2223 WINPOS_ShowIconTitle( hwndChild, FALSE );
2225 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
2226 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
2227 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
2228 if( IsWindow(hwndChild) )
2229 WINPOS_ShowIconTitle(hwndChild , TRUE );
2231 if (x <= rectParent.right - xspacing) x += xspacing;
2232 else
2234 x = rectParent.left;
2235 y -= yspacing;
2238 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
2240 return yspacing;
2244 /***********************************************************************
2245 * draw_moving_frame
2247 * Draw the frame used when moving or resizing window.
2249 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
2251 if (thickframe)
2253 const int width = GetSystemMetrics(SM_CXFRAME);
2254 const int height = GetSystemMetrics(SM_CYFRAME);
2256 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
2257 PatBlt( hdc, rect->left, rect->top,
2258 rect->right - rect->left - width, height, PATINVERT );
2259 PatBlt( hdc, rect->left, rect->top + height, width,
2260 rect->bottom - rect->top - height, PATINVERT );
2261 PatBlt( hdc, rect->left + width, rect->bottom - 1,
2262 rect->right - rect->left - width, -height, PATINVERT );
2263 PatBlt( hdc, rect->right - 1, rect->top, -width,
2264 rect->bottom - rect->top - height, PATINVERT );
2265 SelectObject( hdc, hbrush );
2267 else DrawFocusRect( hdc, rect );
2271 /***********************************************************************
2272 * start_size_move
2274 * Initialization of a move or resize, when initiated from a menu choice.
2275 * Return hit test code for caption or sizing border.
2277 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
2279 LONG hittest = 0;
2280 POINT pt;
2281 MSG msg;
2282 RECT rectWindow;
2284 GetWindowRect( hwnd, &rectWindow );
2286 if ((wParam & 0xfff0) == SC_MOVE)
2288 /* Move pointer at the center of the caption */
2289 RECT rect = rectWindow;
2290 /* Note: to be exactly centered we should take the different types
2291 * of border into account, but it shouldn't make more than a few pixels
2292 * of difference so let's not bother with that */
2293 rect.top += GetSystemMetrics(SM_CYBORDER);
2294 if (style & WS_SYSMENU)
2295 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2296 if (style & WS_MINIMIZEBOX)
2297 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2298 if (style & WS_MAXIMIZEBOX)
2299 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2300 pt.x = (rect.right + rect.left) / 2;
2301 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2302 hittest = HTCAPTION;
2303 *capturePoint = pt;
2305 else /* SC_SIZE */
2307 SetCursor( LoadCursorW( 0, (LPWSTR)IDC_SIZEALL ) );
2308 pt.x = pt.y = 0;
2309 while(!hittest)
2311 if (!GetMessageW( &msg, 0, 0, 0 )) return 0;
2312 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2314 switch(msg.message)
2316 case WM_MOUSEMOVE:
2317 pt.x = min( max( msg.pt.x, rectWindow.left ), rectWindow.right - 1 );
2318 pt.y = min( max( msg.pt.y, rectWindow.top ), rectWindow.bottom - 1 );
2319 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
2320 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
2321 break;
2323 case WM_LBUTTONUP:
2324 return 0;
2326 case WM_KEYDOWN:
2327 switch(msg.wParam)
2329 case VK_UP:
2330 hittest = HTTOP;
2331 pt.x =(rectWindow.left+rectWindow.right)/2;
2332 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2333 break;
2334 case VK_DOWN:
2335 hittest = HTBOTTOM;
2336 pt.x =(rectWindow.left+rectWindow.right)/2;
2337 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2338 break;
2339 case VK_LEFT:
2340 hittest = HTLEFT;
2341 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2342 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2343 break;
2344 case VK_RIGHT:
2345 hittest = HTRIGHT;
2346 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2347 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2348 break;
2349 case VK_RETURN:
2350 case VK_ESCAPE:
2351 return 0;
2353 break;
2354 default:
2355 TranslateMessage( &msg );
2356 DispatchMessageW( &msg );
2357 break;
2360 *capturePoint = pt;
2362 SetCursorPos( pt.x, pt.y );
2363 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
2364 return hittest;
2368 /***********************************************************************
2369 * WINPOS_SysCommandSizeMove
2371 * Perform SC_MOVE and SC_SIZE commands.
2373 void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
2375 MSG msg;
2376 RECT sizingRect, mouseRect, origRect;
2377 HDC hdc;
2378 HWND parent;
2379 LONG hittest = (LONG)(wParam & 0x0f);
2380 WPARAM syscommand = wParam & 0xfff0;
2381 HCURSOR hDragCursor = 0, hOldCursor = 0;
2382 POINT minTrack, maxTrack;
2383 POINT capturePoint, pt;
2384 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2385 BOOL thickframe = HAS_THICKFRAME( style );
2386 BOOL iconic = style & WS_MINIMIZE;
2387 BOOL moved = FALSE;
2388 DWORD dwPoint = GetMessagePos ();
2389 BOOL DragFullWindows = TRUE;
2391 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
2393 pt.x = (short)LOWORD(dwPoint);
2394 pt.y = (short)HIWORD(dwPoint);
2395 capturePoint = pt;
2397 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2398 hwnd, syscommand, hittest, pt.x, pt.y);
2400 if (syscommand == SC_MOVE)
2402 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2403 if (!hittest) return;
2405 else /* SC_SIZE */
2407 if ( hittest && (syscommand != SC_MOUSEMENU) )
2408 hittest += (HTLEFT - WMSZ_LEFT);
2409 else
2411 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2412 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
2413 if (!hittest)
2415 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2416 return;
2421 /* Get min/max info */
2423 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
2424 GetWindowRect( hwnd, &sizingRect );
2425 if (style & WS_CHILD)
2427 parent = GetParent(hwnd);
2428 /* make sizing rect relative to parent */
2429 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
2430 GetClientRect( parent, &mouseRect );
2432 else
2434 parent = 0;
2435 GetClientRect( GetDesktopWindow(), &mouseRect );
2436 mouseRect.left = GetSystemMetrics( SM_XVIRTUALSCREEN );
2437 mouseRect.top = GetSystemMetrics( SM_YVIRTUALSCREEN );
2438 mouseRect.right = mouseRect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN );
2439 mouseRect.bottom = mouseRect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN );
2441 origRect = sizingRect;
2443 if (ON_LEFT_BORDER(hittest))
2445 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2446 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2448 else if (ON_RIGHT_BORDER(hittest))
2450 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2451 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2453 if (ON_TOP_BORDER(hittest))
2455 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2456 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2458 else if (ON_BOTTOM_BORDER(hittest))
2460 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2461 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2463 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2465 /* Retrieve a default cache DC (without using the window style) */
2466 hdc = GetDCEx( parent, 0, DCX_CACHE );
2468 if( iconic ) /* create a cursor for dragging */
2470 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
2471 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
2472 if( !hDragCursor ) iconic = FALSE;
2475 /* we only allow disabling the full window drag for child windows */
2476 if (parent) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0 );
2478 /* repaint the window before moving it around */
2479 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2481 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2482 set_capture_window( hwnd, GUI_INMOVESIZE, NULL );
2484 while(1)
2486 int dx = 0, dy = 0;
2488 if (!GetMessageW( &msg, 0, 0, 0 )) break;
2489 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2491 /* Exit on button-up, Return, or Esc */
2492 if ((msg.message == WM_LBUTTONUP) ||
2493 ((msg.message == WM_KEYDOWN) &&
2494 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2496 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2498 TranslateMessage( &msg );
2499 DispatchMessageW( &msg );
2500 continue; /* We are not interested in other messages */
2503 pt = msg.pt;
2505 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2507 case VK_UP: pt.y -= 8; break;
2508 case VK_DOWN: pt.y += 8; break;
2509 case VK_LEFT: pt.x -= 8; break;
2510 case VK_RIGHT: pt.x += 8; break;
2513 pt.x = max( pt.x, mouseRect.left );
2514 pt.x = min( pt.x, mouseRect.right );
2515 pt.y = max( pt.y, mouseRect.top );
2516 pt.y = min( pt.y, mouseRect.bottom );
2518 dx = pt.x - capturePoint.x;
2519 dy = pt.y - capturePoint.y;
2521 if (dx || dy)
2523 if( !moved )
2525 moved = TRUE;
2527 if( iconic ) /* ok, no system popup tracking */
2529 hOldCursor = SetCursor(hDragCursor);
2530 ShowCursor( TRUE );
2531 WINPOS_ShowIconTitle( hwnd, FALSE );
2533 else if(!DragFullWindows)
2534 draw_moving_frame( hdc, &sizingRect, thickframe );
2537 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2538 else
2540 RECT newRect = sizingRect;
2541 WPARAM wpSizingHit = 0;
2543 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2544 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2545 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2546 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2547 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2548 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2549 capturePoint = pt;
2551 /* determine the hit location */
2552 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2553 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2554 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2556 if (!iconic)
2558 if(!DragFullWindows)
2559 draw_moving_frame( hdc, &newRect, thickframe );
2560 else
2561 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2562 newRect.right - newRect.left,
2563 newRect.bottom - newRect.top,
2564 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2566 sizingRect = newRect;
2571 if( iconic )
2573 if( moved ) /* restore cursors, show icon title later on */
2575 ShowCursor( FALSE );
2576 SetCursor( hOldCursor );
2579 else if (moved && !DragFullWindows)
2581 draw_moving_frame( hdc, &sizingRect, thickframe );
2584 set_capture_window( 0, GUI_INMOVESIZE, NULL );
2585 ReleaseDC( parent, hdc );
2587 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2588 moved = FALSE;
2590 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2591 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2593 /* window moved or resized */
2594 if (moved)
2596 /* if the moving/resizing isn't canceled call SetWindowPos
2597 * with the new position or the new size of the window
2599 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2601 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2602 if(!DragFullWindows || iconic)
2603 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2604 sizingRect.right - sizingRect.left,
2605 sizingRect.bottom - sizingRect.top,
2606 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2608 else
2609 { /* restore previous size/position */
2610 if(DragFullWindows)
2611 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2612 origRect.right - origRect.left,
2613 origRect.bottom - origRect.top,
2614 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2618 if (IsIconic(hwnd))
2620 /* Single click brings up the system menu when iconized */
2622 if( !moved )
2624 if(style & WS_SYSMENU )
2625 SendMessageW( hwnd, WM_SYSCOMMAND,
2626 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2628 else WINPOS_ShowIconTitle( hwnd, TRUE );