user32: Add an entry point for ShowWindow to the driver interface.
[wine/gsoc_dplay.git] / dlls / user32 / winpos.c
blob2bbaab97d645204c1888890d0c66b63b74c0af3e
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winerror.h"
33 #include "wine/server.h"
34 #include "controls.h"
35 #include "user_private.h"
36 #include "win.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define PLACE_MIN 0x0001
68 #define PLACE_MAX 0x0002
69 #define PLACE_RECT 0x0004
72 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
74 typedef struct
76 INT actualCount;
77 INT suggestedCount;
78 BOOL valid;
79 INT wMagic;
80 HWND hwndParent;
81 WINDOWPOS winPos[1];
82 } DWP;
85 /***********************************************************************
86 * SwitchToThisWindow (USER32.@)
88 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
90 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
99 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
100 if (ret)
102 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd, wine_dbgstr_rect(rect) );
105 return ret;
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
114 int nRet = ERROR;
115 NTSTATUS status;
116 HRGN win_rgn = 0;
117 RGNDATA *data;
118 size_t size = 256;
122 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
124 SetLastError( ERROR_OUTOFMEMORY );
125 return ERROR;
127 SERVER_START_REQ( get_window_region )
129 req->window = hwnd;
130 wine_server_set_reply( req, data->Buffer, size );
131 if (!(status = wine_server_call( req )))
133 size_t reply_size = wine_server_reply_size( reply );
134 if (reply_size)
136 data->rdh.dwSize = sizeof(data->rdh);
137 data->rdh.iType = RDH_RECTANGLES;
138 data->rdh.nCount = reply_size / sizeof(RECT);
139 data->rdh.nRgnSize = reply_size;
140 win_rgn = ExtCreateRegion( NULL, size, data );
143 else size = reply->total_size;
145 SERVER_END_REQ;
146 HeapFree( GetProcessHeap(), 0, data );
147 } while (status == STATUS_BUFFER_OVERFLOW);
149 if (status) SetLastError( RtlNtStatusToDosError(status) );
150 else if (win_rgn)
152 nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
153 DeleteObject( win_rgn );
155 return nRet;
159 /***********************************************************************
160 * SetWindowRgn (USER32.@)
162 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
164 static const RECT empty_rect;
165 BOOL ret;
167 if (hrgn)
169 RGNDATA *data;
170 DWORD size;
172 if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
173 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
174 if (!GetRegionData( hrgn, size, data ))
176 HeapFree( GetProcessHeap(), 0, data );
177 return FALSE;
179 SERVER_START_REQ( set_window_region )
181 req->window = hwnd;
182 req->redraw = (bRedraw != 0);
183 if (data->rdh.nCount)
184 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
185 else
186 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
187 ret = !wine_server_call_err( req );
189 SERVER_END_REQ;
191 else /* clear existing region */
193 SERVER_START_REQ( set_window_region )
195 req->window = hwnd;
196 req->redraw = (bRedraw != 0);
197 ret = !wine_server_call_err( req );
199 SERVER_END_REQ;
202 if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
204 if (ret)
206 UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
207 if (!bRedraw) swp_flags |= SWP_NOREDRAW;
208 SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
209 invalidate_dce( hwnd, NULL );
211 return ret;
215 /***********************************************************************
216 * GetClientRect (USER32.@)
218 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
220 BOOL ret;
222 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
224 rect->right -= rect->left;
225 rect->bottom -= rect->top;
226 rect->left = rect->top = 0;
228 return ret;
232 /*******************************************************************
233 * ClientToScreen (USER32.@)
235 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
237 MapWindowPoints( hwnd, 0, lppnt, 1 );
238 return TRUE;
242 /*******************************************************************
243 * ScreenToClient (USER32.@)
245 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
247 MapWindowPoints( 0, hwnd, lppnt, 1 );
248 return TRUE;
252 /***********************************************************************
253 * list_children_from_point
255 * Get the list of children that can contain point from the server.
256 * Point is in screen coordinates.
257 * Returned list must be freed by caller.
259 static HWND *list_children_from_point( HWND hwnd, POINT pt )
261 HWND *list;
262 int size = 128;
264 for (;;)
266 int count = 0;
268 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
270 SERVER_START_REQ( get_window_children_from_point )
272 req->parent = hwnd;
273 req->x = pt.x;
274 req->y = pt.y;
275 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
276 if (!wine_server_call( req )) count = reply->count;
278 SERVER_END_REQ;
279 if (count && count < size)
281 list[count] = 0;
282 return list;
284 HeapFree( GetProcessHeap(), 0, list );
285 if (!count) break;
286 size = count + 1; /* restart with a large enough buffer */
288 return NULL;
292 /***********************************************************************
293 * WINPOS_WindowFromPoint
295 * Find the window and hittest for a given point.
297 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
299 int i, res;
300 HWND ret, *list;
302 if (!hwndScope) hwndScope = GetDesktopWindow();
304 *hittest = HTNOWHERE;
306 if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
308 /* now determine the hittest */
310 for (i = 0; list[i]; i++)
312 LONG style = GetWindowLongW( list[i], GWL_STYLE );
314 /* If window is minimized or disabled, return at once */
315 if (style & WS_MINIMIZE)
317 *hittest = HTCAPTION;
318 break;
320 if (style & WS_DISABLED)
322 *hittest = HTERROR;
323 break;
325 /* Send WM_NCCHITTEST (if same thread) */
326 if (!WIN_IsCurrentThread( list[i] ))
328 *hittest = HTCLIENT;
329 break;
331 res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
332 if (res != HTTRANSPARENT)
334 *hittest = res; /* Found the window */
335 break;
337 /* continue search with next window in z-order */
339 ret = list[i];
340 HeapFree( GetProcessHeap(), 0, list );
341 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
342 return ret;
346 /*******************************************************************
347 * WindowFromPoint (USER32.@)
349 HWND WINAPI WindowFromPoint( POINT pt )
351 INT hittest;
352 return WINPOS_WindowFromPoint( 0, pt, &hittest );
356 /*******************************************************************
357 * ChildWindowFromPoint (USER32.@)
359 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
361 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
364 /*******************************************************************
365 * RealChildWindowFromPoint (USER32.@)
367 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
369 return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
372 /*******************************************************************
373 * ChildWindowFromPointEx (USER32.@)
375 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
377 /* pt is in the client coordinates */
378 HWND *list;
379 int i;
380 RECT rect;
381 HWND retvalue;
383 GetClientRect( hwndParent, &rect );
384 if (!PtInRect( &rect, pt )) return 0;
385 if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
387 for (i = 0; list[i]; i++)
389 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
390 if (!PtInRect( &rect, pt )) continue;
391 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
393 LONG style = GetWindowLongW( list[i], GWL_STYLE );
394 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
395 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
397 if (uFlags & CWP_SKIPTRANSPARENT)
399 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
401 break;
403 retvalue = list[i];
404 HeapFree( GetProcessHeap(), 0, list );
405 if (!retvalue) retvalue = hwndParent;
406 return retvalue;
410 /*******************************************************************
411 * WINPOS_GetWinOffset
413 * Calculate the offset between the origin of the two windows. Used
414 * to implement MapWindowPoints.
416 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
418 WND * wndPtr;
420 offset->x = offset->y = 0;
422 /* Translate source window origin to screen coords */
423 if (hwndFrom)
425 HWND hwnd = hwndFrom;
427 while (hwnd)
429 if (hwnd == hwndTo) return;
430 if (!(wndPtr = WIN_GetPtr( hwnd )))
432 ERR( "bad hwndFrom = %p\n", hwnd );
433 return;
435 if (wndPtr == WND_DESKTOP) break;
436 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
437 if (wndPtr->parent)
439 offset->x += wndPtr->rectClient.left;
440 offset->y += wndPtr->rectClient.top;
442 hwnd = wndPtr->parent;
443 WIN_ReleasePtr( wndPtr );
447 /* Translate origin to destination window coords */
448 if (hwndTo)
450 HWND hwnd = hwndTo;
452 while (hwnd)
454 if (!(wndPtr = WIN_GetPtr( hwnd )))
456 ERR( "bad hwndTo = %p\n", hwnd );
457 return;
459 if (wndPtr == WND_DESKTOP) break;
460 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
461 if (wndPtr->parent)
463 offset->x -= wndPtr->rectClient.left;
464 offset->y -= wndPtr->rectClient.top;
466 hwnd = wndPtr->parent;
467 WIN_ReleasePtr( wndPtr );
470 return;
472 other_process: /* one of the parents may belong to another process, do it the hard way */
473 offset->x = offset->y = 0;
474 SERVER_START_REQ( get_windows_offset )
476 req->from = hwndFrom;
477 req->to = hwndTo;
478 if (!wine_server_call( req ))
480 offset->x = reply->x;
481 offset->y = reply->y;
484 SERVER_END_REQ;
488 /*******************************************************************
489 * MapWindowPoints (USER.258)
491 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
492 LPPOINT16 lppt, UINT16 count )
494 POINT offset;
496 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
497 while (count--)
499 lppt->x += offset.x;
500 lppt->y += offset.y;
501 lppt++;
506 /*******************************************************************
507 * MapWindowPoints (USER32.@)
509 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
511 POINT offset;
513 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
514 while (count--)
516 lppt->x += offset.x;
517 lppt->y += offset.y;
518 lppt++;
520 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
524 /***********************************************************************
525 * IsIconic (USER32.@)
527 BOOL WINAPI IsIconic(HWND hWnd)
529 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
533 /***********************************************************************
534 * IsZoomed (USER32.@)
536 BOOL WINAPI IsZoomed(HWND hWnd)
538 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
542 /*******************************************************************
543 * AllowSetForegroundWindow (USER32.@)
545 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
547 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
548 * implemented, then fix this function. */
549 return TRUE;
553 /*******************************************************************
554 * LockSetForegroundWindow (USER32.@)
556 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
558 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
559 * implemented, then fix this function. */
560 return TRUE;
564 /***********************************************************************
565 * BringWindowToTop (USER32.@)
567 BOOL WINAPI BringWindowToTop( HWND hwnd )
569 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
573 /***********************************************************************
574 * MoveWindow (USER32.@)
576 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
577 BOOL repaint )
579 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
580 if (!repaint) flags |= SWP_NOREDRAW;
581 TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
582 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
585 /***********************************************************************
586 * WINPOS_InitPlacement
588 static void WINPOS_InitPlacement( WND* wnd )
590 if (IsRectEmpty( &wnd->normal_rect ))
592 /* this happens when the window is minimized/maximized
593 * for the first time (rectWindow is not adjusted yet) */
595 wnd->normal_rect = wnd->rectWindow;
596 wnd->min_pos.x = wnd->min_pos.y = -1;
597 wnd->max_pos.x = wnd->max_pos.y = -1;
600 if( wnd->dwStyle & WS_MINIMIZE )
602 wnd->min_pos.x = wnd->rectWindow.left;
603 wnd->min_pos.y = wnd->rectWindow.top;
605 else if( wnd->dwStyle & WS_MAXIMIZE )
607 wnd->max_pos.x = wnd->rectWindow.left;
608 wnd->max_pos.y = wnd->rectWindow.top;
610 else
612 wnd->normal_rect = wnd->rectWindow;
616 /***********************************************************************
617 * WINPOS_RedrawIconTitle
619 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
621 HWND icon_title = 0;
622 WND *win = WIN_GetPtr( hWnd );
624 if (win && win != WND_OTHER_PROCESS && win != WND_DESKTOP)
626 icon_title = win->icon_title;
627 WIN_ReleasePtr( win );
629 if (!icon_title) return FALSE;
630 SendMessageW( icon_title, WM_SHOWWINDOW, TRUE, 0 );
631 InvalidateRect( icon_title, NULL, TRUE );
632 return TRUE;
635 /***********************************************************************
636 * WINPOS_ShowIconTitle
638 static BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
640 if (!GetPropA( hwnd, "__wine_x11_managed" ))
642 WND *win = WIN_GetPtr( hwnd );
643 HWND title = 0;
645 TRACE("%p %i\n", hwnd, (bShow != 0) );
647 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP) return FALSE;
648 title = win->icon_title;
649 WIN_ReleasePtr( win );
651 if( bShow )
653 if (!title)
655 title = ICONTITLE_Create( hwnd );
656 if (!(win = WIN_GetPtr( hwnd )) || win == WND_OTHER_PROCESS)
658 DestroyWindow( title );
659 return FALSE;
661 win->icon_title = title;
662 WIN_ReleasePtr( win );
664 if (!IsWindowVisible(title))
666 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
667 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
668 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
671 else if (title) ShowWindow( title, SW_HIDE );
673 return FALSE;
676 /*******************************************************************
677 * WINPOS_GetMinMaxInfo
679 * Get the minimized and maximized information for a window.
681 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
682 POINT *minTrack, POINT *maxTrack )
684 MINMAXINFO MinMax;
685 HMONITOR monitor;
686 INT xinc, yinc;
687 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
688 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
689 RECT rc;
690 WND *win;
692 /* Compute default values */
694 GetWindowRect(hwnd, &rc);
695 MinMax.ptReserved.x = rc.left;
696 MinMax.ptReserved.y = rc.top;
698 if (style & WS_CHILD)
700 if ((style & WS_CAPTION) == WS_CAPTION)
701 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
703 GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
704 AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
706 /* avoid calculating this twice */
707 style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
709 MinMax.ptMaxSize.x = rc.right - rc.left;
710 MinMax.ptMaxSize.y = rc.bottom - rc.top;
712 else
714 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
715 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
717 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
718 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
719 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
720 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
722 if (HAS_DLGFRAME( style, exstyle ))
724 xinc = GetSystemMetrics(SM_CXDLGFRAME);
725 yinc = GetSystemMetrics(SM_CYDLGFRAME);
727 else
729 xinc = yinc = 0;
730 if (HAS_THICKFRAME(style))
732 xinc += GetSystemMetrics(SM_CXFRAME);
733 yinc += GetSystemMetrics(SM_CYFRAME);
735 if (style & WS_BORDER)
737 xinc += GetSystemMetrics(SM_CXBORDER);
738 yinc += GetSystemMetrics(SM_CYBORDER);
741 MinMax.ptMaxSize.x += 2 * xinc;
742 MinMax.ptMaxSize.y += 2 * yinc;
744 MinMax.ptMaxPosition.x = -xinc;
745 MinMax.ptMaxPosition.y = -yinc;
746 if ((win = WIN_GetPtr( hwnd )) && win != WND_DESKTOP && win != WND_OTHER_PROCESS)
748 if (!EMPTYPOINT(win->max_pos)) MinMax.ptMaxPosition = win->max_pos;
749 WIN_ReleasePtr( win );
752 SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
754 /* if the app didn't change the values, adapt them for the current monitor */
756 if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
758 MONITORINFO mon_info;
760 mon_info.cbSize = sizeof(mon_info);
761 GetMonitorInfoW( monitor, &mon_info );
763 if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
764 MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
766 MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
767 MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
769 if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
771 MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
772 MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
776 /* Some sanity checks */
778 TRACE("%d %d / %d %d / %d %d / %d %d\n",
779 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
780 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
781 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
782 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
783 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
784 MinMax.ptMinTrackSize.x );
785 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
786 MinMax.ptMinTrackSize.y );
788 if (maxSize) *maxSize = MinMax.ptMaxSize;
789 if (maxPos) *maxPos = MinMax.ptMaxPosition;
790 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
791 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
795 /***********************************************************************
796 * WINPOS_FindIconPos
798 * Find a suitable place for an iconic window.
800 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
802 RECT rect, rectParent;
803 HWND parent, child;
804 HRGN hrgn, tmp;
805 int xspacing, yspacing;
807 parent = GetAncestor( hwnd, GA_PARENT );
808 GetClientRect( parent, &rectParent );
809 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
810 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
811 return pt; /* The icon already has a suitable position */
813 xspacing = GetSystemMetrics(SM_CXICONSPACING);
814 yspacing = GetSystemMetrics(SM_CYICONSPACING);
816 /* Check if another icon already occupies this spot */
817 /* FIXME: this is completely inefficient */
819 hrgn = CreateRectRgn( 0, 0, 0, 0 );
820 tmp = CreateRectRgn( 0, 0, 0, 0 );
821 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
823 WND *childPtr;
824 if (child == hwnd) continue;
825 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
826 continue;
827 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
828 continue;
829 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
830 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
831 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
832 WIN_ReleasePtr( childPtr );
834 DeleteObject( tmp );
836 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
838 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
840 rect.right = rect.left + xspacing;
841 rect.top = rect.bottom - yspacing;
842 if (!RectInRegion( hrgn, &rect ))
844 /* No window was found, so it's OK for us */
845 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
846 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
847 DeleteObject( hrgn );
848 return pt;
852 DeleteObject( hrgn );
853 pt.x = pt.y = 0;
854 return pt;
858 /***********************************************************************
859 * WINPOS_MinMaximize
861 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
863 WND *wndPtr;
864 UINT swpFlags = 0;
865 POINT size;
866 LONG old_style;
867 WINDOWPLACEMENT wpl;
869 TRACE("%p %u\n", hwnd, cmd );
871 wpl.length = sizeof(wpl);
872 GetWindowPlacement( hwnd, &wpl );
874 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
875 return SWP_NOSIZE | SWP_NOMOVE;
877 if (IsIconic( hwnd ))
879 switch (cmd)
881 case SW_SHOWMINNOACTIVE:
882 case SW_SHOWMINIMIZED:
883 case SW_FORCEMINIMIZE:
884 case SW_MINIMIZE:
885 return SWP_NOSIZE | SWP_NOMOVE;
887 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
888 swpFlags |= SWP_NOCOPYBITS;
891 switch( cmd )
893 case SW_SHOWMINNOACTIVE:
894 case SW_SHOWMINIMIZED:
895 case SW_FORCEMINIMIZE:
896 case SW_MINIMIZE:
897 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
898 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
899 else wndPtr->flags &= ~WIN_RESTORE_MAX;
900 WIN_ReleasePtr( wndPtr );
902 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
904 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
906 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
907 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
908 wpl.ptMinPosition.x + GetSystemMetrics(SM_CXICON),
909 wpl.ptMinPosition.y + GetSystemMetrics(SM_CYICON) );
910 swpFlags |= SWP_NOCOPYBITS;
911 break;
913 case SW_MAXIMIZE:
914 old_style = GetWindowLongW( hwnd, GWL_STYLE );
915 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
917 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
919 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
920 if (old_style & WS_MINIMIZE) WINPOS_ShowIconTitle( hwnd, FALSE );
922 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
923 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
924 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
925 break;
927 case SW_SHOWNOACTIVATE:
928 case SW_SHOWNORMAL:
929 case SW_RESTORE:
930 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
931 if (old_style & WS_MINIMIZE)
933 BOOL restore_max;
935 WINPOS_ShowIconTitle( hwnd, FALSE );
937 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
938 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
939 WIN_ReleasePtr( wndPtr );
940 if (restore_max)
942 /* Restore to maximized position */
943 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
944 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
945 swpFlags |= SWP_STATECHANGED;
946 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y,
947 wpl.ptMaxPosition.x + size.x, wpl.ptMaxPosition.y + size.y );
948 break;
951 else if (!(old_style & WS_MAXIMIZE)) break;
953 swpFlags |= SWP_STATECHANGED;
955 /* Restore to normal position */
957 *rect = wpl.rcNormalPosition;
958 break;
961 return swpFlags;
965 /***********************************************************************
966 * show_window
968 * Implementation of ShowWindow and ShowWindowAsync.
970 static BOOL show_window( HWND hwnd, INT cmd )
972 WND *wndPtr;
973 HWND parent;
974 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
975 BOOL wasVisible = (style & WS_VISIBLE) != 0;
976 BOOL showFlag = TRUE;
977 RECT newPos = {0, 0, 0, 0};
978 UINT swp = 0;
980 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
982 switch(cmd)
984 case SW_HIDE:
985 if (!wasVisible) return FALSE;
986 showFlag = FALSE;
987 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
988 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
989 break;
991 case SW_SHOWMINNOACTIVE:
992 case SW_MINIMIZE:
993 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
994 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
995 /* fall through */
996 case SW_SHOWMINIMIZED:
997 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
998 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
999 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
1000 break;
1002 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1003 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1004 swp |= SWP_FRAMECHANGED;
1005 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1006 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
1007 break;
1009 case SW_SHOWNA:
1010 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1011 if (style & WS_CHILD) swp |= SWP_NOZORDER;
1012 break;
1013 case SW_SHOW:
1014 if (wasVisible) return TRUE;
1015 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1016 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1017 break;
1019 case SW_SHOWNOACTIVATE:
1020 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1021 /* fall through */
1022 case SW_RESTORE:
1023 /* fall through */
1024 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1025 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1026 if (!wasVisible) swp |= SWP_SHOWWINDOW;
1027 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1029 swp |= SWP_FRAMECHANGED;
1030 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1032 else
1034 if (wasVisible) return TRUE;
1035 swp |= SWP_NOSIZE | SWP_NOMOVE;
1037 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1038 break;
1039 default:
1040 return wasVisible;
1043 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
1045 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1046 if (!IsWindow( hwnd )) return wasVisible;
1049 swp = USER_Driver->pShowWindow( hwnd, cmd, &newPos, swp );
1051 parent = GetAncestor( hwnd, GA_PARENT );
1052 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
1054 /* if parent is not visible simply toggle WS_VISIBLE and return */
1055 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1056 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1058 else
1059 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1060 newPos.right - newPos.left, newPos.bottom - newPos.top, swp );
1062 if (cmd == SW_HIDE)
1064 HWND hFocus;
1066 WINPOS_ShowIconTitle( hwnd, FALSE );
1068 /* FIXME: This will cause the window to be activated irrespective
1069 * of whether it is owned by the same thread. Has to be done
1070 * asynchronously.
1073 if (hwnd == GetActiveWindow())
1074 WINPOS_ActivateOtherWindow(hwnd);
1076 /* Revert focus to parent */
1077 hFocus = GetFocus();
1078 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1080 HWND parent = GetAncestor(hwnd, GA_PARENT);
1081 if (parent == GetDesktopWindow()) parent = 0;
1082 SetFocus(parent);
1084 return wasVisible;
1087 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1089 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1091 if (wndPtr->flags & WIN_NEED_SIZE)
1093 /* should happen only in CreateWindowEx() */
1094 int wParam = SIZE_RESTORED;
1095 RECT client = wndPtr->rectClient;
1097 wndPtr->flags &= ~WIN_NEED_SIZE;
1098 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1099 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1100 WIN_ReleasePtr( wndPtr );
1102 SendMessageW( hwnd, WM_SIZE, wParam,
1103 MAKELONG( client.right - client.left, client.bottom - client.top ));
1104 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1106 else WIN_ReleasePtr( wndPtr );
1108 /* if previous state was minimized Windows sets focus to the window */
1109 if (style & WS_MINIMIZE) SetFocus( hwnd );
1111 return wasVisible;
1115 /***********************************************************************
1116 * ShowWindowAsync (USER32.@)
1118 * doesn't wait; returns immediately.
1119 * used by threads to toggle windows in other (possibly hanging) threads
1121 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
1123 HWND full_handle;
1125 if (is_broadcast(hwnd))
1127 SetLastError( ERROR_INVALID_PARAMETER );
1128 return FALSE;
1131 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1132 return show_window( full_handle, cmd );
1134 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1138 /***********************************************************************
1139 * ShowWindow (USER32.@)
1141 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
1143 HWND full_handle;
1145 if (is_broadcast(hwnd))
1147 SetLastError( ERROR_INVALID_PARAMETER );
1148 return FALSE;
1150 if ((full_handle = WIN_IsCurrentThread( hwnd )))
1151 return show_window( full_handle, cmd );
1153 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
1157 /***********************************************************************
1158 * GetInternalWindowPos (USER32.@)
1160 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1161 LPPOINT ptIcon )
1163 WINDOWPLACEMENT wndpl;
1164 if (GetWindowPlacement( hwnd, &wndpl ))
1166 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1167 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1168 return wndpl.showCmd;
1170 return 0;
1174 /***********************************************************************
1175 * GetWindowPlacement (USER32.@)
1177 * Win95:
1178 * Fails if wndpl->length of Win95 (!) apps is invalid.
1180 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1182 WND *pWnd = WIN_GetPtr( hwnd );
1184 if (!pWnd) return FALSE;
1186 if (pWnd == WND_DESKTOP)
1188 wndpl->length = sizeof(*wndpl);
1189 wndpl->showCmd = SW_SHOWNORMAL;
1190 wndpl->flags = 0;
1191 wndpl->ptMinPosition.x = -1;
1192 wndpl->ptMinPosition.y = -1;
1193 wndpl->ptMaxPosition.x = -1;
1194 wndpl->ptMaxPosition.y = -1;
1195 GetWindowRect( hwnd, &wndpl->rcNormalPosition );
1196 return TRUE;
1198 if (pWnd == WND_OTHER_PROCESS)
1200 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
1201 return FALSE;
1204 WINPOS_InitPlacement( pWnd );
1205 wndpl->length = sizeof(*wndpl);
1206 if( pWnd->dwStyle & WS_MINIMIZE )
1207 wndpl->showCmd = SW_SHOWMINIMIZED;
1208 else
1209 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1210 if( pWnd->flags & WIN_RESTORE_MAX )
1211 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1212 else
1213 wndpl->flags = 0;
1214 wndpl->ptMinPosition = pWnd->min_pos;
1215 wndpl->ptMaxPosition = pWnd->max_pos;
1216 wndpl->rcNormalPosition = pWnd->normal_rect;
1217 WIN_ReleasePtr( pWnd );
1219 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1220 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1221 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1222 wine_dbgstr_rect(&wndpl->rcNormalPosition) );
1223 return TRUE;
1226 /* make sure the specified rect is visible on screen */
1227 static void make_rect_onscreen( RECT *rect )
1229 MONITORINFO info;
1230 HMONITOR monitor = MonitorFromRect( rect, MONITOR_DEFAULTTONEAREST );
1232 info.cbSize = sizeof(info);
1233 if (!monitor || !GetMonitorInfoW( monitor, &info )) return;
1234 /* FIXME: map coordinates from rcWork to rcMonitor */
1235 if (rect->right <= info.rcWork.left)
1237 rect->right += info.rcWork.left - rect->left;
1238 rect->left = info.rcWork.left;
1240 else if (rect->left >= info.rcWork.right)
1242 rect->left += info.rcWork.right - rect->right;
1243 rect->right = info.rcWork.right;
1245 if (rect->bottom <= info.rcWork.top)
1247 rect->bottom += info.rcWork.top - rect->top;
1248 rect->top = info.rcWork.top;
1250 else if (rect->top >= info.rcWork.bottom)
1252 rect->top += info.rcWork.bottom - rect->bottom;
1253 rect->bottom = info.rcWork.bottom;
1257 /* make sure the specified point is visible on screen */
1258 static void make_point_onscreen( POINT *pt )
1260 RECT rect;
1262 SetRect( &rect, pt->x, pt->y, pt->x + 1, pt->y + 1 );
1263 make_rect_onscreen( &rect );
1264 pt->x = rect.left;
1265 pt->y = rect.top;
1269 /***********************************************************************
1270 * WINPOS_SetPlacement
1272 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1274 DWORD style;
1275 WND *pWnd = WIN_GetPtr( hwnd );
1276 WINDOWPLACEMENT wp = *wndpl;
1278 if (flags & PLACE_MIN) make_point_onscreen( &wp.ptMinPosition );
1279 if (flags & PLACE_MAX) make_point_onscreen( &wp.ptMaxPosition );
1280 if (flags & PLACE_RECT) make_rect_onscreen( &wp.rcNormalPosition );
1282 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1283 hwnd, wndpl->ptMinPosition.x, wndpl->ptMinPosition.y,
1284 wndpl->ptMaxPosition.x, wndpl->ptMaxPosition.y,
1285 wine_dbgstr_rect(&wndpl->rcNormalPosition), flags,
1286 wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y,
1287 wine_dbgstr_rect(&wp.rcNormalPosition) );
1289 if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
1291 if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
1292 if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
1293 if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
1295 style = pWnd->dwStyle;
1297 WIN_ReleasePtr( pWnd );
1299 if( style & WS_MINIMIZE )
1301 if (flags & PLACE_MIN)
1303 WINPOS_ShowIconTitle( hwnd, FALSE );
1304 SetWindowPos( hwnd, 0, wp.ptMinPosition.x, wp.ptMinPosition.y, 0, 0,
1305 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1308 else if( style & WS_MAXIMIZE )
1310 if (flags & PLACE_MAX)
1311 SetWindowPos( hwnd, 0, wp.ptMaxPosition.x, wp.ptMaxPosition.y, 0, 0,
1312 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1314 else if( flags & PLACE_RECT )
1315 SetWindowPos( hwnd, 0, wp.rcNormalPosition.left, wp.rcNormalPosition.top,
1316 wp.rcNormalPosition.right - wp.rcNormalPosition.left,
1317 wp.rcNormalPosition.bottom - wp.rcNormalPosition.top,
1318 SWP_NOZORDER | SWP_NOACTIVATE );
1320 ShowWindow( hwnd, wndpl->showCmd );
1322 if (IsIconic( hwnd ))
1324 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1326 /* SDK: ...valid only the next time... */
1327 if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1329 pWnd = WIN_GetPtr( hwnd );
1330 if (pWnd && pWnd != WND_OTHER_PROCESS)
1332 pWnd->flags |= WIN_RESTORE_MAX;
1333 WIN_ReleasePtr( pWnd );
1337 return TRUE;
1341 /***********************************************************************
1342 * SetWindowPlacement (USER32.@)
1344 * Win95:
1345 * Fails if wndpl->length of Win95 (!) apps is invalid.
1347 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1349 UINT flags = PLACE_MAX | PLACE_RECT;
1350 if (!wpl) return FALSE;
1351 if (wpl->flags & WPF_SETMINPOSITION) flags |= PLACE_MIN;
1352 return WINPOS_SetPlacement( hwnd, wpl, flags );
1356 /***********************************************************************
1357 * AnimateWindow (USER32.@)
1358 * Shows/Hides a window with an animation
1359 * NO ANIMATION YET
1361 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1363 FIXME("partial stub\n");
1365 /* If trying to show/hide and it's already *
1366 * shown/hidden or invalid window, fail with *
1367 * invalid parameter */
1368 if(!IsWindow(hwnd) ||
1369 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1370 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1372 SetLastError(ERROR_INVALID_PARAMETER);
1373 return FALSE;
1376 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1378 return TRUE;
1381 /***********************************************************************
1382 * SetInternalWindowPos (USER32.@)
1384 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1385 LPRECT rect, LPPOINT pt )
1387 WINDOWPLACEMENT wndpl;
1388 UINT flags;
1390 wndpl.length = sizeof(wndpl);
1391 wndpl.showCmd = showCmd;
1392 wndpl.flags = flags = 0;
1394 if( pt )
1396 flags |= PLACE_MIN;
1397 wndpl.flags |= WPF_SETMINPOSITION;
1398 wndpl.ptMinPosition = *pt;
1400 if( rect )
1402 flags |= PLACE_RECT;
1403 wndpl.rcNormalPosition = *rect;
1405 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1409 /*******************************************************************
1410 * can_activate_window
1412 * Check if we can activate the specified window.
1414 static BOOL can_activate_window( HWND hwnd )
1416 LONG style;
1418 if (!hwnd) return FALSE;
1419 style = GetWindowLongW( hwnd, GWL_STYLE );
1420 if (!(style & WS_VISIBLE)) return FALSE;
1421 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1422 return !(style & WS_DISABLED);
1426 /*******************************************************************
1427 * WINPOS_ActivateOtherWindow
1429 * Activates window other than pWnd.
1431 void WINPOS_ActivateOtherWindow(HWND hwnd)
1433 HWND hwndTo, fg;
1435 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1437 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1438 if (can_activate_window( hwndTo )) goto done;
1441 hwndTo = hwnd;
1442 for (;;)
1444 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1445 if (can_activate_window( hwndTo )) break;
1448 done:
1449 fg = GetForegroundWindow();
1450 TRACE("win = %p fg = %p\n", hwndTo, fg);
1451 if (!fg || (hwnd == fg))
1453 if (SetForegroundWindow( hwndTo )) return;
1455 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1459 /***********************************************************************
1460 * WINPOS_HandleWindowPosChanging
1462 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1464 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1466 POINT minTrack, maxTrack;
1467 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1469 if (winpos->flags & SWP_NOSIZE) return 0;
1470 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1472 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1473 if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1474 if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1475 if (!(style & WS_MINIMIZE))
1477 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1478 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1481 return 0;
1485 /***********************************************************************
1486 * dump_winpos_flags
1488 static void dump_winpos_flags(UINT flags)
1490 static const DWORD dumped_flags = (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW |
1491 SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW |
1492 SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOOWNERZORDER |
1493 SWP_NOSENDCHANGING | SWP_DEFERERASE | SWP_ASYNCWINDOWPOS |
1494 SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_STATECHANGED);
1495 TRACE("flags:");
1496 if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1497 if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1498 if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1499 if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1500 if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1501 if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1502 if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1503 if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1504 if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1505 if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1506 if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1507 if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1508 if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1509 if(flags & SWP_NOCLIENTSIZE) TRACE(" SWP_NOCLIENTSIZE");
1510 if(flags & SWP_NOCLIENTMOVE) TRACE(" SWP_NOCLIENTMOVE");
1511 if(flags & SWP_STATECHANGED) TRACE(" SWP_STATECHANGED");
1513 if(flags & ~dumped_flags) TRACE(" %08x", flags & ~dumped_flags);
1514 TRACE("\n");
1517 /***********************************************************************
1518 * SWP_DoWinPosChanging
1520 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1522 WND *wndPtr;
1524 /* Send WM_WINDOWPOSCHANGING message */
1526 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1527 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1529 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1530 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1532 /* Calculate new position and size */
1534 *pNewWindowRect = wndPtr->rectWindow;
1535 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1536 : wndPtr->rectClient;
1538 if (!(pWinpos->flags & SWP_NOSIZE))
1540 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
1541 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1543 if (!(pWinpos->flags & SWP_NOMOVE))
1545 pNewWindowRect->left = pWinpos->x;
1546 pNewWindowRect->top = pWinpos->y;
1547 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
1548 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1550 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1551 pWinpos->y - wndPtr->rectWindow.top );
1553 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1555 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1556 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1557 pWinpos->cx, pWinpos->cy, pWinpos->flags );
1558 TRACE( "current %s style %08x new %s\n",
1559 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1560 wine_dbgstr_rect( pNewWindowRect ));
1562 WIN_ReleasePtr( wndPtr );
1563 return TRUE;
1566 /***********************************************************************
1567 * get_valid_rects
1569 * Compute the valid rects from the old and new client rect and WVR_* flags.
1570 * Helper for WM_NCCALCSIZE handling.
1572 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1573 RECT *valid )
1575 int cx, cy;
1577 if (flags & WVR_REDRAW)
1579 SetRectEmpty( &valid[0] );
1580 SetRectEmpty( &valid[1] );
1581 return;
1584 if (flags & WVR_VALIDRECTS)
1586 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1587 !IntersectRect( &valid[1], &valid[1], old_client ))
1589 SetRectEmpty( &valid[0] );
1590 SetRectEmpty( &valid[1] );
1591 return;
1593 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1595 else
1597 valid[0] = *new_client;
1598 valid[1] = *old_client;
1601 /* make sure the rectangles have the same size */
1602 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1603 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1605 if (flags & WVR_ALIGNBOTTOM)
1607 valid[0].top = valid[0].bottom - cy;
1608 valid[1].top = valid[1].bottom - cy;
1610 else
1612 valid[0].bottom = valid[0].top + cy;
1613 valid[1].bottom = valid[1].top + cy;
1615 if (flags & WVR_ALIGNRIGHT)
1617 valid[0].left = valid[0].right - cx;
1618 valid[1].left = valid[1].right - cx;
1620 else
1622 valid[0].right = valid[0].left + cx;
1623 valid[1].right = valid[1].left + cx;
1628 /***********************************************************************
1629 * SWP_DoOwnedPopups
1631 * fix Z order taking into account owned popups -
1632 * basically we need to maintain them above the window that owns them
1634 * FIXME: hide/show owned popups when owner visibility changes.
1636 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1638 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1639 HWND owner, *list = NULL;
1640 unsigned int i;
1642 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1644 if ((style & WS_POPUP) && (owner = GetWindow( hwnd, GW_OWNER )))
1646 /* make sure this popup stays above the owner */
1648 if (hwndInsertAfter != HWND_TOP && hwndInsertAfter != HWND_TOPMOST)
1650 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter;
1652 for (i = 0; list[i]; i++)
1654 if (list[i] == owner)
1656 if (i > 0) hwndInsertAfter = list[i-1];
1657 else hwndInsertAfter = HWND_TOP;
1658 break;
1661 if (hwndInsertAfter == HWND_NOTOPMOST)
1663 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) break;
1665 else if (list[i] == hwndInsertAfter) break;
1669 else if (style & WS_CHILD) return hwndInsertAfter;
1671 if (hwndInsertAfter == HWND_BOTTOM) goto done;
1672 if (!list && !(list = WIN_ListChildren( GetDesktopWindow() ))) goto done;
1674 i = 0;
1675 if (hwndInsertAfter == HWND_TOP || hwndInsertAfter == HWND_NOTOPMOST)
1677 if (hwndInsertAfter == HWND_NOTOPMOST || !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_TOPMOST))
1679 /* skip all the topmost windows */
1680 while (list[i] && (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TOPMOST)) i++;
1683 else if (hwndInsertAfter != HWND_TOPMOST)
1685 /* skip windows that are already placed correctly */
1686 for (i = 0; list[i]; i++)
1688 if (list[i] == hwndInsertAfter) break;
1689 if (list[i] == hwnd) goto done; /* nothing to do if window is moving backwards in z-order */
1693 for ( ; list[i]; i++)
1695 if (list[i] == hwnd) break;
1696 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP)) continue;
1697 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1698 TRACE( "moving %p owned by %p after %p\n", list[i], hwnd, hwndInsertAfter );
1699 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
1700 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE );
1701 hwndInsertAfter = list[i];
1704 done:
1705 HeapFree( GetProcessHeap(), 0, list );
1706 return hwndInsertAfter;
1709 /***********************************************************************
1710 * SWP_DoNCCalcSize
1712 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1713 RECT *validRects )
1715 UINT wvrFlags = 0;
1716 WND *wndPtr;
1718 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1720 /* Send WM_NCCALCSIZE message to get new client area */
1721 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1723 NCCALCSIZE_PARAMS params;
1724 WINDOWPOS winposCopy;
1726 params.rgrc[0] = *pNewWindowRect;
1727 params.rgrc[1] = wndPtr->rectWindow;
1728 params.rgrc[2] = wndPtr->rectClient;
1729 params.lppos = &winposCopy;
1730 winposCopy = *pWinpos;
1731 WIN_ReleasePtr( wndPtr );
1733 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1735 *pNewClientRect = params.rgrc[0];
1737 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1739 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1740 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1741 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1743 if( pNewClientRect->left != wndPtr->rectClient.left ||
1744 pNewClientRect->top != wndPtr->rectClient.top )
1745 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1747 if( (pNewClientRect->right - pNewClientRect->left !=
1748 wndPtr->rectClient.right - wndPtr->rectClient.left))
1749 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1750 else
1751 wvrFlags &= ~WVR_HREDRAW;
1753 if (pNewClientRect->bottom - pNewClientRect->top !=
1754 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1755 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1756 else
1757 wvrFlags &= ~WVR_VREDRAW;
1759 validRects[0] = params.rgrc[1];
1760 validRects[1] = params.rgrc[2];
1762 else
1764 if (!(pWinpos->flags & SWP_NOMOVE) &&
1765 (pNewClientRect->left != wndPtr->rectClient.left ||
1766 pNewClientRect->top != wndPtr->rectClient.top))
1767 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1770 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1772 SetRectEmpty( &validRects[0] );
1773 SetRectEmpty( &validRects[1] );
1775 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1777 WIN_ReleasePtr( wndPtr );
1778 return wvrFlags;
1781 /* fix redundant flags and values in the WINDOWPOS structure */
1782 static BOOL fixup_flags( WINDOWPOS *winpos )
1784 HWND parent;
1785 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1786 BOOL ret = TRUE;
1788 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1790 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1791 return FALSE;
1793 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
1795 /* Finally make sure that all coordinates are valid */
1796 if (winpos->x < -32768) winpos->x = -32768;
1797 else if (winpos->x > 32767) winpos->x = 32767;
1798 if (winpos->y < -32768) winpos->y = -32768;
1799 else if (winpos->y > 32767) winpos->y = 32767;
1801 if (winpos->cx < 0) winpos->cx = 0;
1802 else if (winpos->cx > 32767) winpos->cx = 32767;
1803 if (winpos->cy < 0) winpos->cy = 0;
1804 else if (winpos->cy > 32767) winpos->cy = 32767;
1806 parent = GetAncestor( winpos->hwnd, GA_PARENT );
1807 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1809 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1810 else
1812 winpos->flags &= ~SWP_HIDEWINDOW;
1813 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1816 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1817 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1818 winpos->flags |= SWP_NOSIZE; /* Already the right size */
1820 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1821 winpos->flags |= SWP_NOMOVE; /* Already the right position */
1823 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1825 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)) && /* Bring to the top when activating */
1826 (winpos->flags & SWP_NOZORDER ||
1827 (winpos->hwndInsertAfter != HWND_TOPMOST && winpos->hwndInsertAfter != HWND_NOTOPMOST)))
1829 winpos->flags &= ~SWP_NOZORDER;
1830 winpos->hwndInsertAfter = HWND_TOP;
1834 /* Check hwndInsertAfter */
1835 if (winpos->flags & SWP_NOZORDER) goto done;
1837 /* fix sign extension */
1838 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1839 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1841 /* hwndInsertAfter must be a sibling of the window */
1842 if (winpos->hwndInsertAfter == HWND_TOP)
1844 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1845 winpos->flags |= SWP_NOZORDER;
1847 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1849 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1850 winpos->flags |= SWP_NOZORDER;
1852 else if (winpos->hwndInsertAfter == HWND_TOPMOST)
1854 if ((wndPtr->dwExStyle & WS_EX_TOPMOST) && GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1855 winpos->flags |= SWP_NOZORDER;
1857 else if (winpos->hwndInsertAfter == HWND_NOTOPMOST)
1859 if (!(wndPtr->dwExStyle & WS_EX_TOPMOST))
1860 winpos->flags |= SWP_NOZORDER;
1862 else
1864 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1865 else
1867 /* don't need to change the Zorder of hwnd if it's already inserted
1868 * after hwndInsertAfter or when inserting hwnd after itself.
1870 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1871 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1872 winpos->flags |= SWP_NOZORDER;
1875 done:
1876 WIN_ReleasePtr( wndPtr );
1877 return ret;
1881 /***********************************************************************
1882 * set_window_pos
1884 * Backend implementation of SetWindowPos.
1886 BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
1887 const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects )
1889 WND *win;
1890 BOOL ret;
1891 RECT visible_rect, old_window_rect;
1893 visible_rect = *window_rect;
1894 USER_Driver->pWindowPosChanging( hwnd, insert_after, swp_flags,
1895 window_rect, client_rect, &visible_rect );
1897 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
1898 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
1900 old_window_rect = win->rectWindow;
1901 SERVER_START_REQ( set_window_pos )
1903 req->handle = hwnd;
1904 req->previous = insert_after;
1905 req->flags = swp_flags;
1906 req->window.left = window_rect->left;
1907 req->window.top = window_rect->top;
1908 req->window.right = window_rect->right;
1909 req->window.bottom = window_rect->bottom;
1910 req->client.left = client_rect->left;
1911 req->client.top = client_rect->top;
1912 req->client.right = client_rect->right;
1913 req->client.bottom = client_rect->bottom;
1914 if (memcmp( window_rect, &visible_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
1916 wine_server_add_data( req, &visible_rect, sizeof(visible_rect) );
1917 if (!IsRectEmpty( &valid_rects[0] ))
1918 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
1920 if ((ret = !wine_server_call( req )))
1922 win->dwStyle = reply->new_style;
1923 win->dwExStyle = reply->new_ex_style;
1924 win->rectWindow = *window_rect;
1925 win->rectClient = *client_rect;
1928 SERVER_END_REQ;
1929 WIN_ReleasePtr( win );
1931 if (ret)
1933 if (((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) ||
1934 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW | SWP_STATECHANGED)))
1935 invalidate_dce( hwnd, &old_window_rect );
1937 USER_Driver->pWindowPosChanged( hwnd, insert_after, swp_flags, window_rect,
1938 client_rect, &visible_rect, valid_rects );
1940 return ret;
1944 /***********************************************************************
1945 * USER_SetWindowPos
1947 * User32 internal function
1949 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1951 RECT newWindowRect, newClientRect, valid_rects[2];
1952 UINT orig_flags;
1954 orig_flags = winpos->flags;
1956 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1957 if (!(winpos->flags & SWP_NOMOVE))
1959 if (winpos->x < -32768) winpos->x = -32768;
1960 else if (winpos->x > 32767) winpos->x = 32767;
1961 if (winpos->y < -32768) winpos->y = -32768;
1962 else if (winpos->y > 32767) winpos->y = 32767;
1964 if (!(winpos->flags & SWP_NOSIZE))
1966 if (winpos->cx < 0) winpos->cx = 0;
1967 else if (winpos->cx > 32767) winpos->cx = 32767;
1968 if (winpos->cy < 0) winpos->cy = 0;
1969 else if (winpos->cy > 32767) winpos->cy = 32767;
1972 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1974 /* Fix redundant flags */
1975 if (!fixup_flags( winpos )) return FALSE;
1977 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1979 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1980 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1983 /* Common operations */
1985 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1987 if (!set_window_pos( winpos->hwnd, winpos->hwndInsertAfter, winpos->flags,
1988 &newWindowRect, &newClientRect, valid_rects ))
1989 return FALSE;
1991 /* erase parent when hiding or resizing child */
1992 if (!(orig_flags & SWP_DEFERERASE) &&
1993 ((orig_flags & SWP_HIDEWINDOW) ||
1994 (!(orig_flags & SWP_SHOWWINDOW) &&
1995 (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)))
1997 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1998 if (!parent || parent == GetDesktopWindow()) parent = winpos->hwnd;
1999 erase_now( parent, 0 );
2002 if( winpos->flags & SWP_HIDEWINDOW )
2003 HideCaret(winpos->hwnd);
2004 else if (winpos->flags & SWP_SHOWWINDOW)
2005 ShowCaret(winpos->hwnd);
2007 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
2009 /* child windows get WM_CHILDACTIVATE message */
2010 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
2011 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
2012 else
2013 SetForegroundWindow( winpos->hwnd );
2016 /* And last, send the WM_WINDOWPOSCHANGED message */
2018 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2020 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
2022 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2023 and always contains final window position.
2025 winpos->x = newWindowRect.left;
2026 winpos->y = newWindowRect.top;
2027 winpos->cx = newWindowRect.right - newWindowRect.left;
2028 winpos->cy = newWindowRect.bottom - newWindowRect.top;
2029 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
2031 return TRUE;
2034 /***********************************************************************
2035 * SetWindowPos (USER32.@)
2037 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
2038 INT x, INT y, INT cx, INT cy, UINT flags )
2040 WINDOWPOS winpos;
2042 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2043 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
2044 if(TRACE_ON(win)) dump_winpos_flags(flags);
2046 if (is_broadcast(hwnd))
2048 SetLastError( ERROR_INVALID_PARAMETER );
2049 return FALSE;
2052 winpos.hwnd = WIN_GetFullHandle(hwnd);
2053 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
2054 winpos.x = x;
2055 winpos.y = y;
2056 winpos.cx = cx;
2057 winpos.cy = cy;
2058 winpos.flags = flags;
2060 if (WIN_IsCurrentThread( hwnd ))
2061 return USER_SetWindowPos(&winpos);
2063 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
2067 /***********************************************************************
2068 * BeginDeferWindowPos (USER32.@)
2070 HDWP WINAPI BeginDeferWindowPos( INT count )
2072 HDWP handle;
2073 DWP *pDWP;
2075 TRACE("%d\n", count);
2077 if (count < 0)
2079 SetLastError(ERROR_INVALID_PARAMETER);
2080 return 0;
2082 /* Windows allows zero count, in which case it allocates context for 8 moves */
2083 if (count == 0) count = 8;
2085 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
2086 if (!handle) return 0;
2087 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2088 pDWP->actualCount = 0;
2089 pDWP->suggestedCount = count;
2090 pDWP->valid = TRUE;
2091 pDWP->wMagic = DWP_MAGIC;
2092 pDWP->hwndParent = 0;
2094 TRACE("returning hdwp %p\n", handle);
2095 return handle;
2099 /***********************************************************************
2100 * DeferWindowPos (USER32.@)
2102 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
2103 INT x, INT y, INT cx, INT cy,
2104 UINT flags )
2106 DWP *pDWP;
2107 int i;
2108 HDWP newhdwp = hdwp,retvalue;
2110 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2111 hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
2113 hwnd = WIN_GetFullHandle( hwnd );
2114 if (is_desktop_window( hwnd )) return 0;
2116 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
2118 USER_Lock();
2120 for (i = 0; i < pDWP->actualCount; i++)
2122 if (pDWP->winPos[i].hwnd == hwnd)
2124 /* Merge with the other changes */
2125 if (!(flags & SWP_NOZORDER))
2127 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
2129 if (!(flags & SWP_NOMOVE))
2131 pDWP->winPos[i].x = x;
2132 pDWP->winPos[i].y = y;
2134 if (!(flags & SWP_NOSIZE))
2136 pDWP->winPos[i].cx = cx;
2137 pDWP->winPos[i].cy = cy;
2139 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2140 SWP_NOZORDER | SWP_NOREDRAW |
2141 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2142 SWP_NOOWNERZORDER);
2143 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2144 SWP_FRAMECHANGED);
2145 retvalue = hdwp;
2146 goto END;
2149 if (pDWP->actualCount >= pDWP->suggestedCount)
2151 newhdwp = USER_HEAP_REALLOC( hdwp,
2152 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
2153 if (!newhdwp)
2155 retvalue = 0;
2156 goto END;
2158 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2159 pDWP->suggestedCount++;
2161 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2162 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2163 pDWP->winPos[pDWP->actualCount].x = x;
2164 pDWP->winPos[pDWP->actualCount].y = y;
2165 pDWP->winPos[pDWP->actualCount].cx = cx;
2166 pDWP->winPos[pDWP->actualCount].cy = cy;
2167 pDWP->winPos[pDWP->actualCount].flags = flags;
2168 pDWP->actualCount++;
2169 retvalue = newhdwp;
2170 END:
2171 USER_Unlock();
2172 return retvalue;
2176 /***********************************************************************
2177 * EndDeferWindowPos (USER32.@)
2179 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
2181 DWP *pDWP;
2182 WINDOWPOS *winpos;
2183 BOOL res = TRUE;
2184 int i;
2186 TRACE("%p\n", hdwp);
2188 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2189 if (!pDWP) return FALSE;
2190 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2192 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2193 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
2194 winpos->cx, winpos->cy, winpos->flags);
2196 if (!(res = USER_SetWindowPos( winpos ))) break;
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 );