urlmon/tests: Keep track of download state in tests.
[wine] / dlls / user32 / winpos.c
1 /*
2  * Window position related functions.
3  *
4  * Copyright 1993, 1994, 1995 Alexandre Julliard
5  *                       1995, 1996, 1999 Alex Korobka
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "winerror.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winerror.h"
34 #include "wine/winuser16.h"
35 #include "wine/server.h"
36 #include "controls.h"
37 #include "user_private.h"
38 #include "win.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
42
43 #define SWP_AGG_NOGEOMETRYCHANGE \
44     (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
45 #define SWP_AGG_NOPOSCHANGE \
46     (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
47 #define SWP_AGG_STATUSFLAGS \
48     (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
49
50 #define HAS_DLGFRAME(style,exStyle) \
51     (((exStyle) & WS_EX_DLGMODALFRAME) || \
52      (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
53
54 #define HAS_THICKFRAME(style) \
55     (((style) & WS_THICKFRAME) && \
56      !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
57
58 #define EMPTYPOINT(pt)          ((*(LONG*)&(pt)) == -1)
59
60 #define PLACE_MIN               0x0001
61 #define PLACE_MAX               0x0002
62 #define PLACE_RECT              0x0004
63
64
65 #define DWP_MAGIC  ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
66
67 typedef struct
68 {
69     INT       actualCount;
70     INT       suggestedCount;
71     BOOL      valid;
72     INT       wMagic;
73     HWND      hwndParent;
74     WINDOWPOS winPos[1];
75 } DWP;
76
77 typedef struct
78 {
79     RECT16   rectNormal;
80     POINT16  ptIconPos;
81     POINT16  ptMaxPos;
82     HWND     hwndIconTitle;
83 } INTERNALPOS, *LPINTERNALPOS;
84
85 /* ----- internal functions ----- */
86
87 static const WCHAR SysIP_W[] = { 'S','y','s','I','P',0 };
88
89 static inline INTERNALPOS *get_internal_pos( HWND hwnd )
90 {
91     return GetPropW( hwnd, SysIP_W );
92 }
93
94 static inline void set_internal_pos( HWND hwnd, INTERNALPOS *pos )
95 {
96     SetPropW( hwnd, SysIP_W, pos );
97 }
98
99 /***********************************************************************
100  *           WINPOS_CheckInternalPos
101  *
102  * Called when a window is destroyed.
103  */
104 void WINPOS_CheckInternalPos( HWND hwnd )
105 {
106     LPINTERNALPOS lpPos = get_internal_pos( hwnd );
107
108     if ( lpPos )
109     {
110         if( IsWindow(lpPos->hwndIconTitle) )
111             DestroyWindow( lpPos->hwndIconTitle );
112         HeapFree( GetProcessHeap(), 0, lpPos );
113     }
114 }
115
116 /***********************************************************************
117  *              ArrangeIconicWindows (USER32.@)
118  */
119 UINT WINAPI ArrangeIconicWindows( HWND parent )
120 {
121     RECT rectParent;
122     HWND hwndChild;
123     INT x, y, xspacing, yspacing;
124
125     GetClientRect( parent, &rectParent );
126     x = rectParent.left;
127     y = rectParent.bottom;
128     xspacing = GetSystemMetrics(SM_CXICONSPACING);
129     yspacing = GetSystemMetrics(SM_CYICONSPACING);
130
131     hwndChild = GetWindow( parent, GW_CHILD );
132     while (hwndChild)
133     {
134         if( IsIconic( hwndChild ) )
135         {
136             WINPOS_ShowIconTitle( hwndChild, FALSE );
137
138             SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
139                             y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
140                             SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
141             if( IsWindow(hwndChild) )
142                 WINPOS_ShowIconTitle(hwndChild , TRUE );
143
144             if (x <= rectParent.right - xspacing) x += xspacing;
145             else
146             {
147                 x = rectParent.left;
148                 y -= yspacing;
149             }
150         }
151         hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
152     }
153     return yspacing;
154 }
155
156
157 /***********************************************************************
158  *              SwitchToThisWindow (USER32.@)
159  */
160 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
161 {
162     ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
163 }
164
165
166 /***********************************************************************
167  *              GetWindowRect (USER32.@)
168  */
169 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
170 {
171     BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
172     if (ret)
173     {
174         MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
175         TRACE( "hwnd %p (%d,%d)-(%d,%d)\n",
176                hwnd, rect->left, rect->top, rect->right, rect->bottom);
177     }
178     return ret;
179 }
180
181
182 /***********************************************************************
183  *              GetWindowRgn (USER32.@)
184  */
185 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
186 {
187     int nRet = ERROR;
188     NTSTATUS status;
189     HRGN win_rgn = 0;
190     RGNDATA *data;
191     size_t size = 256;
192
193     do
194     {
195         if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 )))
196         {
197             SetLastError( ERROR_OUTOFMEMORY );
198             return ERROR;
199         }
200         SERVER_START_REQ( get_window_region )
201         {
202             req->window = hwnd;
203             wine_server_set_reply( req, data->Buffer, size );
204             if (!(status = wine_server_call( req )))
205             {
206                 size_t reply_size = wine_server_reply_size( reply );
207                 if (reply_size)
208                 {
209                     data->rdh.dwSize   = sizeof(data->rdh);
210                     data->rdh.iType    = RDH_RECTANGLES;
211                     data->rdh.nCount   = reply_size / sizeof(RECT);
212                     data->rdh.nRgnSize = reply_size;
213                     win_rgn = ExtCreateRegion( NULL, size, data );
214                 }
215             }
216             else size = reply->total_size;
217         }
218         SERVER_END_REQ;
219         HeapFree( GetProcessHeap(), 0, data );
220     } while (status == STATUS_BUFFER_OVERFLOW);
221
222     if (status) SetLastError( RtlNtStatusToDosError(status) );
223     else if (win_rgn)
224     {
225         nRet = CombineRgn( hrgn, win_rgn, 0, RGN_COPY );
226         DeleteObject( win_rgn );
227     }
228     return nRet;
229 }
230
231
232 /***********************************************************************
233  *              SetWindowRgn (USER32.@)
234  */
235 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
236 {
237     static const RECT empty_rect;
238     BOOL ret;
239
240     if (hrgn)
241     {
242         RGNDATA *data;
243         DWORD size;
244
245         if (!(size = GetRegionData( hrgn, 0, NULL ))) return FALSE;
246         if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
247         if (!GetRegionData( hrgn, size, data ))
248         {
249             HeapFree( GetProcessHeap(), 0, data );
250             return FALSE;
251         }
252         SERVER_START_REQ( set_window_region )
253         {
254             req->window = hwnd;
255             req->redraw = (bRedraw != 0);
256             if (data->rdh.nCount)
257                 wine_server_add_data( req, data->Buffer, data->rdh.nCount * sizeof(RECT) );
258             else
259                 wine_server_add_data( req, &empty_rect, sizeof(empty_rect) );
260             ret = !wine_server_call_err( req );
261         }
262         SERVER_END_REQ;
263     }
264     else  /* clear existing region */
265     {
266         SERVER_START_REQ( set_window_region )
267         {
268             req->window = hwnd;
269             req->redraw = (bRedraw != 0);
270             ret = !wine_server_call_err( req );
271         }
272         SERVER_END_REQ;
273     }
274
275     if (ret) ret = USER_Driver->pSetWindowRgn( hwnd, hrgn, bRedraw );
276
277     if (ret)
278     {
279         UINT swp_flags = SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED;
280         if (hrgn) swp_flags |= SWP_NOCLIENTSIZE|SWP_NOCLIENTMOVE;
281         if (!bRedraw) swp_flags |= SWP_NOREDRAW;
282         SetWindowPos( hwnd, 0, 0, 0, 0, 0, swp_flags );
283     }
284     return ret;
285 }
286
287
288 /***********************************************************************
289  *              GetClientRect (USER32.@)
290  */
291 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
292 {
293     BOOL ret;
294
295     if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
296     {
297         rect->right -= rect->left;
298         rect->bottom -= rect->top;
299         rect->left = rect->top = 0;
300     }
301     return ret;
302 }
303
304
305 /*******************************************************************
306  *              ClientToScreen (USER32.@)
307  */
308 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
309 {
310     MapWindowPoints( hwnd, 0, lppnt, 1 );
311     return TRUE;
312 }
313
314
315 /*******************************************************************
316  *              ScreenToClient (USER32.@)
317  */
318 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
319 {
320     MapWindowPoints( 0, hwnd, lppnt, 1 );
321     return TRUE;
322 }
323
324
325 /***********************************************************************
326  *           list_children_from_point
327  *
328  * Get the list of children that can contain point from the server.
329  * Point is in screen coordinates.
330  * Returned list must be freed by caller.
331  */
332 static HWND *list_children_from_point( HWND hwnd, POINT pt )
333 {
334     HWND *list;
335     int size = 32;
336
337     for (;;)
338     {
339         int count = 0;
340
341         if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
342
343         SERVER_START_REQ( get_window_children_from_point )
344         {
345             req->parent = hwnd;
346             req->x = pt.x;
347             req->y = pt.y;
348             wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
349             if (!wine_server_call( req )) count = reply->count;
350         }
351         SERVER_END_REQ;
352         if (count && count < size)
353         {
354             list[count] = 0;
355             return list;
356         }
357         HeapFree( GetProcessHeap(), 0, list );
358         if (!count) break;
359         size = count + 1;  /* restart with a large enough buffer */
360     }
361     return NULL;
362 }
363
364
365 /***********************************************************************
366  *           WINPOS_WindowFromPoint
367  *
368  * Find the window and hittest for a given point.
369  */
370 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
371 {
372     int i, res;
373     HWND ret, *list;
374
375     if (!hwndScope) hwndScope = GetDesktopWindow();
376
377     *hittest = HTNOWHERE;
378
379     if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
380
381     /* now determine the hittest */
382
383     for (i = 0; list[i]; i++)
384     {
385         LONG style = GetWindowLongW( list[i], GWL_STYLE );
386
387         /* If window is minimized or disabled, return at once */
388         if (style & WS_MINIMIZE)
389         {
390             *hittest = HTCAPTION;
391             break;
392         }
393         if (style & WS_DISABLED)
394         {
395             *hittest = HTERROR;
396             break;
397         }
398         /* Send WM_NCCHITTEST (if same thread) */
399         if (!WIN_IsCurrentThread( list[i] ))
400         {
401             *hittest = HTCLIENT;
402             break;
403         }
404         res = SendMessageW( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
405         if (res != HTTRANSPARENT)
406         {
407             *hittest = res;  /* Found the window */
408             break;
409         }
410         /* continue search with next window in z-order */
411     }
412     ret = list[i];
413     HeapFree( GetProcessHeap(), 0, list );
414     TRACE( "scope %p (%d,%d) returning %p\n", hwndScope, pt.x, pt.y, ret );
415     return ret;
416 }
417
418
419 /*******************************************************************
420  *              WindowFromPoint (USER32.@)
421  */
422 HWND WINAPI WindowFromPoint( POINT pt )
423 {
424     INT hittest;
425     return WINPOS_WindowFromPoint( 0, pt, &hittest );
426 }
427
428
429 /*******************************************************************
430  *              ChildWindowFromPoint (USER32.@)
431  */
432 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
433 {
434     return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
435 }
436
437 /*******************************************************************
438  *              RealChildWindowFromPoint (USER32.@)
439  */
440 HWND WINAPI RealChildWindowFromPoint( HWND hwndParent, POINT pt )
441 {
442     return ChildWindowFromPointEx( hwndParent, pt, CWP_SKIPTRANSPARENT );
443 }
444
445 /*******************************************************************
446  *              ChildWindowFromPointEx (USER32.@)
447  */
448 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
449 {
450     /* pt is in the client coordinates */
451     HWND *list;
452     int i;
453     RECT rect;
454     HWND retvalue;
455
456     GetClientRect( hwndParent, &rect );
457     if (!PtInRect( &rect, pt )) return 0;
458     if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
459
460     for (i = 0; list[i]; i++)
461     {
462         if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
463         if (!PtInRect( &rect, pt )) continue;
464         if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
465         {
466             LONG style = GetWindowLongW( list[i], GWL_STYLE );
467             if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
468             if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
469         }
470         if (uFlags & CWP_SKIPTRANSPARENT)
471         {
472             if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
473         }
474         break;
475     }
476     retvalue = list[i];
477     HeapFree( GetProcessHeap(), 0, list );
478     if (!retvalue) retvalue = hwndParent;
479     return retvalue;
480 }
481
482
483 /*******************************************************************
484  *         WINPOS_GetWinOffset
485  *
486  * Calculate the offset between the origin of the two windows. Used
487  * to implement MapWindowPoints.
488  */
489 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
490 {
491     WND * wndPtr;
492
493     offset->x = offset->y = 0;
494
495     /* Translate source window origin to screen coords */
496     if (hwndFrom)
497     {
498         HWND hwnd = hwndFrom;
499
500         while (hwnd)
501         {
502             if (hwnd == hwndTo) return;
503             if (!(wndPtr = WIN_GetPtr( hwnd )))
504             {
505                 ERR( "bad hwndFrom = %p\n", hwnd );
506                 return;
507             }
508             if (wndPtr == WND_DESKTOP) break;
509             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
510             offset->x += wndPtr->rectClient.left;
511             offset->y += wndPtr->rectClient.top;
512             hwnd = wndPtr->parent;
513             WIN_ReleasePtr( wndPtr );
514         }
515     }
516
517     /* Translate origin to destination window coords */
518     if (hwndTo)
519     {
520         HWND hwnd = hwndTo;
521
522         while (hwnd)
523         {
524             if (!(wndPtr = WIN_GetPtr( hwnd )))
525             {
526                 ERR( "bad hwndTo = %p\n", hwnd );
527                 return;
528             }
529             if (wndPtr == WND_DESKTOP) break;
530             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
531             offset->x -= wndPtr->rectClient.left;
532             offset->y -= wndPtr->rectClient.top;
533             hwnd = wndPtr->parent;
534             WIN_ReleasePtr( wndPtr );
535         }
536     }
537     return;
538
539  other_process:  /* one of the parents may belong to another process, do it the hard way */
540     offset->x = offset->y = 0;
541     SERVER_START_REQ( get_windows_offset )
542     {
543         req->from = hwndFrom;
544         req->to   = hwndTo;
545         if (!wine_server_call( req ))
546         {
547             offset->x = reply->x;
548             offset->y = reply->y;
549         }
550     }
551     SERVER_END_REQ;
552 }
553
554
555 /*******************************************************************
556  *              MapWindowPoints (USER.258)
557  */
558 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
559                                LPPOINT16 lppt, UINT16 count )
560 {
561     POINT offset;
562
563     WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
564     while (count--)
565     {
566         lppt->x += offset.x;
567         lppt->y += offset.y;
568         lppt++;
569     }
570 }
571
572
573 /*******************************************************************
574  *              MapWindowPoints (USER32.@)
575  */
576 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
577 {
578     POINT offset;
579
580     WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
581     while (count--)
582     {
583         lppt->x += offset.x;
584         lppt->y += offset.y;
585         lppt++;
586     }
587     return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
588 }
589
590
591 /***********************************************************************
592  *              IsIconic (USER32.@)
593  */
594 BOOL WINAPI IsIconic(HWND hWnd)
595 {
596     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
597 }
598
599
600 /***********************************************************************
601  *              IsZoomed (USER32.@)
602  */
603 BOOL WINAPI IsZoomed(HWND hWnd)
604 {
605     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
606 }
607
608
609 /*******************************************************************
610  *              AllowSetForegroundWindow (USER32.@)
611  */
612 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
613 {
614     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
615      * implemented, then fix this function. */
616     return TRUE;
617 }
618
619
620 /*******************************************************************
621  *              LockSetForegroundWindow (USER32.@)
622  */
623 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
624 {
625     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
626      * implemented, then fix this function. */
627     return TRUE;
628 }
629
630
631 /***********************************************************************
632  *              BringWindowToTop (USER32.@)
633  */
634 BOOL WINAPI BringWindowToTop( HWND hwnd )
635 {
636     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
637 }
638
639
640 /***********************************************************************
641  *              MoveWindow (USER32.@)
642  */
643 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
644                             BOOL repaint )
645 {
646     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
647     if (!repaint) flags |= SWP_NOREDRAW;
648     TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
649     return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
650 }
651
652 /***********************************************************************
653  *           WINPOS_InitInternalPos
654  */
655 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd )
656 {
657     LPINTERNALPOS lpPos = get_internal_pos( wnd->hwndSelf );
658     if( !lpPos )
659     {
660         /* this happens when the window is minimized/maximized
661          * for the first time (rectWindow is not adjusted yet) */
662
663         lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
664         if( !lpPos ) return NULL;
665
666         set_internal_pos( wnd->hwndSelf, lpPos );
667         lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
668         lpPos->rectNormal.left   = wnd->rectWindow.left;
669         lpPos->rectNormal.top    = wnd->rectWindow.top;
670         lpPos->rectNormal.right  = wnd->rectWindow.right;
671         lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
672         lpPos->ptIconPos.x = lpPos->ptIconPos.y = -1;
673         lpPos->ptMaxPos.x = lpPos->ptMaxPos.y = -1;
674     }
675
676     if( wnd->dwStyle & WS_MINIMIZE )
677     {
678         lpPos->ptIconPos.x = wnd->rectWindow.left;
679         lpPos->ptIconPos.y = wnd->rectWindow.top;
680     }
681     else if( wnd->dwStyle & WS_MAXIMIZE )
682     {
683         lpPos->ptMaxPos.x = wnd->rectWindow.left;
684         lpPos->ptMaxPos.y = wnd->rectWindow.top;
685     }
686     else
687     {
688         lpPos->rectNormal.left   = wnd->rectWindow.left;
689         lpPos->rectNormal.top    = wnd->rectWindow.top;
690         lpPos->rectNormal.right  = wnd->rectWindow.right;
691         lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
692     }
693     return lpPos;
694 }
695
696 /***********************************************************************
697  *           WINPOS_RedrawIconTitle
698  */
699 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
700 {
701     LPINTERNALPOS lpPos = get_internal_pos( hWnd );
702     if( lpPos )
703     {
704         if( lpPos->hwndIconTitle )
705         {
706             SendMessageW( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
707             InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
708             return TRUE;
709         }
710     }
711     return FALSE;
712 }
713
714 /***********************************************************************
715  *           WINPOS_ShowIconTitle
716  */
717 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
718 {
719     LPINTERNALPOS lpPos = get_internal_pos( hwnd );
720
721     if (lpPos && !GetPropA( hwnd, "__wine_x11_managed" ))
722     {
723         HWND title = lpPos->hwndIconTitle;
724
725         TRACE("%p %i\n", hwnd, (bShow != 0) );
726
727         if( !title )
728             lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
729         if( bShow )
730         {
731             if (!IsWindowVisible(title))
732             {
733                 SendMessageW( title, WM_SHOWWINDOW, TRUE, 0 );
734                 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
735                               SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
736             }
737         }
738         else ShowWindow( title, SW_HIDE );
739     }
740     return FALSE;
741 }
742
743 /*******************************************************************
744  *           WINPOS_GetMinMaxInfo
745  *
746  * Get the minimized and maximized information for a window.
747  */
748 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
749                            POINT *minTrack, POINT *maxTrack )
750 {
751     LPINTERNALPOS lpPos;
752     MINMAXINFO MinMax;
753     HMONITOR monitor;
754     INT xinc, yinc;
755     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
756     LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
757     RECT rc;
758
759     /* Compute default values */
760
761     GetWindowRect(hwnd, &rc);
762     MinMax.ptReserved.x = rc.left;
763     MinMax.ptReserved.y = rc.top;
764
765     if (style & WS_CHILD)
766     {
767         if ((style & WS_CAPTION) == WS_CAPTION)
768             style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
769
770         GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
771         AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
772
773         /* avoid calculating this twice */
774         style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
775
776         MinMax.ptMaxSize.x = rc.right - rc.left;
777         MinMax.ptMaxSize.y = rc.bottom - rc.top;
778     }
779     else
780     {
781         MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
782         MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
783     }
784     MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
785     MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
786     MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXMAXTRACK);
787     MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYMAXTRACK);
788
789     if (HAS_DLGFRAME( style, exstyle ))
790     {
791         xinc = GetSystemMetrics(SM_CXDLGFRAME);
792         yinc = GetSystemMetrics(SM_CYDLGFRAME);
793     }
794     else
795     {
796         xinc = yinc = 0;
797         if (HAS_THICKFRAME(style))
798         {
799             xinc += GetSystemMetrics(SM_CXFRAME);
800             yinc += GetSystemMetrics(SM_CYFRAME);
801         }
802         if (style & WS_BORDER)
803         {
804             xinc += GetSystemMetrics(SM_CXBORDER);
805             yinc += GetSystemMetrics(SM_CYBORDER);
806         }
807     }
808     MinMax.ptMaxSize.x += 2 * xinc;
809     MinMax.ptMaxSize.y += 2 * yinc;
810
811     lpPos = get_internal_pos( hwnd );
812     if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
813     {
814         MinMax.ptMaxPosition.x = lpPos->ptMaxPos.x;
815         MinMax.ptMaxPosition.y = lpPos->ptMaxPos.y;
816     }
817     else
818     {
819         MinMax.ptMaxPosition.x = -xinc;
820         MinMax.ptMaxPosition.y = -yinc;
821     }
822
823     SendMessageW( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
824
825     /* if the app didn't change the values, adapt them for the current monitor */
826
827     if ((monitor = MonitorFromWindow( hwnd, MONITOR_DEFAULTTOPRIMARY )))
828     {
829         MONITORINFO mon_info;
830
831         mon_info.cbSize = sizeof(mon_info);
832         GetMonitorInfoW( monitor, &mon_info );
833
834         if (MinMax.ptMaxSize.x == GetSystemMetrics(SM_CXSCREEN) + 2 * xinc &&
835             MinMax.ptMaxSize.y == GetSystemMetrics(SM_CYSCREEN) + 2 * yinc)
836         {
837             MinMax.ptMaxSize.x = (mon_info.rcWork.right - mon_info.rcWork.left) + 2 * xinc;
838             MinMax.ptMaxSize.y = (mon_info.rcWork.bottom - mon_info.rcWork.top) + 2 * yinc;
839         }
840         if (MinMax.ptMaxPosition.x == -xinc && MinMax.ptMaxPosition.y == -yinc)
841         {
842             MinMax.ptMaxPosition.x = mon_info.rcWork.left - xinc;
843             MinMax.ptMaxPosition.y = mon_info.rcWork.top - yinc;
844         }
845     }
846
847       /* Some sanity checks */
848
849     TRACE("%d %d / %d %d / %d %d / %d %d\n",
850                       MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
851                       MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
852                       MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
853                       MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
854     MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
855                                    MinMax.ptMinTrackSize.x );
856     MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
857                                    MinMax.ptMinTrackSize.y );
858
859     if (maxSize) *maxSize = MinMax.ptMaxSize;
860     if (maxPos) *maxPos = MinMax.ptMaxPosition;
861     if (minTrack) *minTrack = MinMax.ptMinTrackSize;
862     if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
863 }
864
865 /***********************************************************************
866  *              ShowWindowAsync (USER32.@)
867  *
868  * doesn't wait; returns immediately.
869  * used by threads to toggle windows in other (possibly hanging) threads
870  */
871 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
872 {
873     HWND full_handle;
874
875     if (is_broadcast(hwnd))
876     {
877         SetLastError( ERROR_INVALID_PARAMETER );
878         return FALSE;
879     }
880
881     if ((full_handle = WIN_IsCurrentThread( hwnd )))
882         return USER_Driver->pShowWindow( full_handle, cmd );
883
884     return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
885 }
886
887
888 /***********************************************************************
889  *              ShowWindow (USER32.@)
890  */
891 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
892 {
893     HWND full_handle;
894
895     if (is_broadcast(hwnd))
896     {
897         SetLastError( ERROR_INVALID_PARAMETER );
898         return FALSE;
899     }
900     if ((full_handle = WIN_IsCurrentThread( hwnd )))
901         return USER_Driver->pShowWindow( full_handle, cmd );
902
903     return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
904 }
905
906
907 /***********************************************************************
908  *              GetInternalWindowPos (USER32.@)
909  */
910 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
911                                       LPPOINT ptIcon )
912 {
913     WINDOWPLACEMENT wndpl;
914     if (GetWindowPlacement( hwnd, &wndpl ))
915     {
916         if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
917         if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
918         return wndpl.showCmd;
919     }
920     return 0;
921 }
922
923
924 /***********************************************************************
925  *              GetWindowPlacement (USER32.@)
926  *
927  * Win95:
928  * Fails if wndpl->length of Win95 (!) apps is invalid.
929  */
930 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
931 {
932     WND *pWnd = WIN_GetPtr( hwnd );
933     LPINTERNALPOS lpPos;
934
935     if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
936     if (pWnd == WND_OTHER_PROCESS)
937     {
938         if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
939         return FALSE;
940     }
941
942     lpPos = WINPOS_InitInternalPos( pWnd );
943     wndpl->length  = sizeof(*wndpl);
944     if( pWnd->dwStyle & WS_MINIMIZE )
945         wndpl->showCmd = SW_SHOWMINIMIZED;
946     else
947         wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
948     if( pWnd->flags & WIN_RESTORE_MAX )
949         wndpl->flags = WPF_RESTORETOMAXIMIZED;
950     else
951         wndpl->flags = 0;
952     wndpl->ptMinPosition.x = lpPos->ptIconPos.x;
953     wndpl->ptMinPosition.y = lpPos->ptIconPos.y;
954     wndpl->ptMaxPosition.x = lpPos->ptMaxPos.x;
955     wndpl->ptMaxPosition.y = lpPos->ptMaxPos.y;
956     wndpl->rcNormalPosition.left   = lpPos->rectNormal.left;
957     wndpl->rcNormalPosition.top    = lpPos->rectNormal.top;
958     wndpl->rcNormalPosition.right  = lpPos->rectNormal.right;
959     wndpl->rcNormalPosition.bottom = lpPos->rectNormal.bottom;
960     WIN_ReleasePtr( pWnd );
961     return TRUE;
962 }
963
964
965 /***********************************************************************
966  *           WINPOS_SetPlacement
967  */
968 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
969 {
970     LPINTERNALPOS lpPos;
971     DWORD style;
972     WND *pWnd = WIN_GetPtr( hwnd );
973
974     if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
975     lpPos = WINPOS_InitInternalPos( pWnd );
976
977     if( flags & PLACE_MIN )
978     {
979         lpPos->ptIconPos.x = wndpl->ptMinPosition.x;
980         lpPos->ptIconPos.y = wndpl->ptMinPosition.y;
981     }
982     if( flags & PLACE_MAX )
983     {
984         lpPos->ptMaxPos.x = wndpl->ptMaxPosition.x;
985         lpPos->ptMaxPos.y = wndpl->ptMaxPosition.y;
986     }
987     if( flags & PLACE_RECT)
988     {
989         lpPos->rectNormal.left   = wndpl->rcNormalPosition.left;
990         lpPos->rectNormal.top    = wndpl->rcNormalPosition.top;
991         lpPos->rectNormal.right  = wndpl->rcNormalPosition.right;
992         lpPos->rectNormal.bottom = wndpl->rcNormalPosition.bottom;
993     }
994
995     style = pWnd->dwStyle;
996     WIN_ReleasePtr( pWnd );
997
998     if( style & WS_MINIMIZE )
999     {
1000         WINPOS_ShowIconTitle( hwnd, FALSE );
1001         if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
1002             SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
1003                           0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1004     }
1005     else if( style & WS_MAXIMIZE )
1006     {
1007         if( !EMPTYPOINT(lpPos->ptMaxPos) )
1008             SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
1009                           0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1010     }
1011     else if( flags & PLACE_RECT )
1012         SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
1013                       lpPos->rectNormal.right - lpPos->rectNormal.left,
1014                       lpPos->rectNormal.bottom - lpPos->rectNormal.top,
1015                       SWP_NOZORDER | SWP_NOACTIVATE );
1016
1017     ShowWindow( hwnd, wndpl->showCmd );
1018
1019     if (IsIconic( hwnd ))
1020     {
1021         if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
1022
1023         /* SDK: ...valid only the next time... */
1024         if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
1025         {
1026             pWnd = WIN_GetPtr( hwnd );
1027             if (pWnd && pWnd != WND_OTHER_PROCESS)
1028             {
1029                 pWnd->flags |= WIN_RESTORE_MAX;
1030                 WIN_ReleasePtr( pWnd );
1031             }
1032         }
1033     }
1034     return TRUE;
1035 }
1036
1037
1038 /***********************************************************************
1039  *              SetWindowPlacement (USER32.@)
1040  *
1041  * Win95:
1042  * Fails if wndpl->length of Win95 (!) apps is invalid.
1043  */
1044 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1045 {
1046     if (!wpl) return FALSE;
1047     return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1048 }
1049
1050
1051 /***********************************************************************
1052  *              AnimateWindow (USER32.@)
1053  *              Shows/Hides a window with an animation
1054  *              NO ANIMATION YET
1055  */
1056 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1057 {
1058         FIXME("partial stub\n");
1059
1060         /* If trying to show/hide and it's already   *
1061          * shown/hidden or invalid window, fail with *
1062          * invalid parameter                         */
1063         if(!IsWindow(hwnd) ||
1064            (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1065            (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1066         {
1067                 SetLastError(ERROR_INVALID_PARAMETER);
1068                 return FALSE;
1069         }
1070
1071         ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1072
1073         return TRUE;
1074 }
1075
1076 /***********************************************************************
1077  *              SetInternalWindowPos (USER32.@)
1078  */
1079 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1080                                     LPRECT rect, LPPOINT pt )
1081 {
1082     if( IsWindow(hwnd) )
1083     {
1084         WINDOWPLACEMENT wndpl;
1085         UINT flags;
1086
1087         wndpl.length  = sizeof(wndpl);
1088         wndpl.showCmd = showCmd;
1089         wndpl.flags = flags = 0;
1090
1091         if( pt )
1092         {
1093             flags |= PLACE_MIN;
1094             wndpl.flags |= WPF_SETMINPOSITION;
1095             wndpl.ptMinPosition = *pt;
1096         }
1097         if( rect )
1098         {
1099             flags |= PLACE_RECT;
1100             wndpl.rcNormalPosition = *rect;
1101         }
1102         WINPOS_SetPlacement( hwnd, &wndpl, flags );
1103     }
1104 }
1105
1106
1107 /*******************************************************************
1108  *         can_activate_window
1109  *
1110  * Check if we can activate the specified window.
1111  */
1112 static BOOL can_activate_window( HWND hwnd )
1113 {
1114     LONG style;
1115
1116     if (!hwnd) return FALSE;
1117     style = GetWindowLongW( hwnd, GWL_STYLE );
1118     if (!(style & WS_VISIBLE)) return FALSE;
1119     if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1120     return !(style & WS_DISABLED);
1121 }
1122
1123
1124 /*******************************************************************
1125  *         WINPOS_ActivateOtherWindow
1126  *
1127  *  Activates window other than pWnd.
1128  */
1129 void WINPOS_ActivateOtherWindow(HWND hwnd)
1130 {
1131     HWND hwndTo, fg;
1132
1133     if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1134     {
1135         hwndTo = GetAncestor( hwndTo, GA_ROOT );
1136         if (can_activate_window( hwndTo )) goto done;
1137     }
1138
1139     hwndTo = hwnd;
1140     for (;;)
1141     {
1142         if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1143         if (can_activate_window( hwndTo )) break;
1144     }
1145
1146  done:
1147     fg = GetForegroundWindow();
1148     TRACE("win = %p fg = %p\n", hwndTo, fg);
1149     if (!fg || (hwnd == fg))
1150     {
1151         if (SetForegroundWindow( hwndTo )) return;
1152     }
1153     if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1154 }
1155
1156
1157 /***********************************************************************
1158  *           WINPOS_HandleWindowPosChanging
1159  *
1160  * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1161  */
1162 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1163 {
1164     POINT minTrack, maxTrack;
1165     LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1166
1167     if (winpos->flags & SWP_NOSIZE) return 0;
1168     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1169     {
1170         WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1171         if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1172         if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1173         if (!(style & WS_MINIMIZE))
1174         {
1175             if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1176             if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1177         }
1178     }
1179     return 0;
1180 }
1181
1182
1183 /***********************************************************************
1184  *           dump_winpos_flags
1185  */
1186 static void dump_winpos_flags(UINT flags)
1187 {
1188     TRACE("flags:");
1189     if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1190     if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1191     if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1192     if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1193     if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1194     if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1195     if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1196     if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1197     if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1198     if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1199     if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1200     if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1201     if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1202
1203 #define DUMPED_FLAGS \
1204     (SWP_NOSIZE | \
1205     SWP_NOMOVE | \
1206     SWP_NOZORDER | \
1207     SWP_NOREDRAW | \
1208     SWP_NOACTIVATE | \
1209     SWP_FRAMECHANGED | \
1210     SWP_SHOWWINDOW | \
1211     SWP_HIDEWINDOW | \
1212     SWP_NOCOPYBITS | \
1213     SWP_NOOWNERZORDER | \
1214     SWP_NOSENDCHANGING | \
1215     SWP_DEFERERASE | \
1216     SWP_ASYNCWINDOWPOS)
1217
1218     if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1219     TRACE("\n");
1220 #undef DUMPED_FLAGS
1221 }
1222
1223 /***********************************************************************
1224  *           SWP_DoWinPosChanging
1225  */
1226 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
1227 {
1228     WND *wndPtr;
1229
1230     /* Send WM_WINDOWPOSCHANGING message */
1231
1232     if (!(pWinpos->flags & SWP_NOSENDCHANGING))
1233         SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
1234
1235     if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
1236         wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
1237
1238     /* Calculate new position and size */
1239
1240     *pNewWindowRect = wndPtr->rectWindow;
1241     *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1242                                                     : wndPtr->rectClient;
1243
1244     if (!(pWinpos->flags & SWP_NOSIZE))
1245     {
1246         pNewWindowRect->right  = pNewWindowRect->left + pWinpos->cx;
1247         pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
1248     }
1249     if (!(pWinpos->flags & SWP_NOMOVE))
1250     {
1251         pNewWindowRect->left    = pWinpos->x;
1252         pNewWindowRect->top     = pWinpos->y;
1253         pNewWindowRect->right  += pWinpos->x - wndPtr->rectWindow.left;
1254         pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
1255
1256         OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
1257                                     pWinpos->y - wndPtr->rectWindow.top );
1258     }
1259     pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1260
1261     TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1262            pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
1263            pWinpos->cx, pWinpos->cy, pWinpos->flags );
1264     TRACE( "current %s style %08x new %s\n",
1265            wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
1266            wine_dbgstr_rect( pNewWindowRect ));
1267
1268     WIN_ReleasePtr( wndPtr );
1269     return TRUE;
1270 }
1271
1272 /***********************************************************************
1273  *           get_valid_rects
1274  *
1275  * Compute the valid rects from the old and new client rect and WVR_* flags.
1276  * Helper for WM_NCCALCSIZE handling.
1277  */
1278 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
1279                                     RECT *valid )
1280 {
1281     int cx, cy;
1282
1283     if (flags & WVR_REDRAW)
1284     {
1285         SetRectEmpty( &valid[0] );
1286         SetRectEmpty( &valid[1] );
1287         return;
1288     }
1289
1290     if (flags & WVR_VALIDRECTS)
1291     {
1292         if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
1293             !IntersectRect( &valid[1], &valid[1], old_client ))
1294         {
1295             SetRectEmpty( &valid[0] );
1296             SetRectEmpty( &valid[1] );
1297             return;
1298         }
1299         flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
1300     }
1301     else
1302     {
1303         valid[0] = *new_client;
1304         valid[1] = *old_client;
1305     }
1306
1307     /* make sure the rectangles have the same size */
1308     cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
1309     cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
1310
1311     if (flags & WVR_ALIGNBOTTOM)
1312     {
1313         valid[0].top = valid[0].bottom - cy;
1314         valid[1].top = valid[1].bottom - cy;
1315     }
1316     else
1317     {
1318         valid[0].bottom = valid[0].top + cy;
1319         valid[1].bottom = valid[1].top + cy;
1320     }
1321     if (flags & WVR_ALIGNRIGHT)
1322     {
1323         valid[0].left = valid[0].right - cx;
1324         valid[1].left = valid[1].right - cx;
1325     }
1326     else
1327     {
1328         valid[0].right = valid[0].left + cx;
1329         valid[1].right = valid[1].left + cx;
1330     }
1331 }
1332
1333 struct move_owned_info
1334 {
1335     HWND owner;
1336     HWND insert_after;
1337 };
1338
1339 static BOOL CALLBACK move_owned_popups( HWND hwnd, LPARAM lparam )
1340 {
1341     struct move_owned_info *info = (struct move_owned_info *)lparam;
1342
1343     if (hwnd == info->owner) return FALSE;
1344     if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) &&
1345         GetWindow( hwnd, GW_OWNER ) == info->owner)
1346     {
1347         SetWindowPos( hwnd, info->insert_after, 0, 0, 0, 0,
1348                       SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
1349                       SWP_NOSENDCHANGING | SWP_DEFERERASE );
1350         info->insert_after = hwnd;
1351     }
1352     return TRUE;
1353 }
1354
1355 /***********************************************************************
1356  *           SWP_DoOwnedPopups
1357  *
1358  * fix Z order taking into account owned popups -
1359  * basically we need to maintain them above the window that owns them
1360  *
1361  * FIXME: hide/show owned popups when owner visibility changes.
1362  */
1363 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
1364 {
1365     HWND owner = GetWindow( hwnd, GW_OWNER );
1366     LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1367     struct move_owned_info info;
1368
1369     TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
1370
1371     if ((style & WS_POPUP) && owner)
1372     {
1373         /* make sure this popup stays above the owner */
1374
1375         if( hwndInsertAfter != HWND_TOP )
1376         {
1377             HWND hwndLocalPrev = HWND_TOP;
1378             HWND prev = GetWindow( owner, GW_HWNDPREV );
1379
1380             while (prev && prev != hwndInsertAfter)
1381             {
1382                 if (hwndLocalPrev == HWND_TOP && GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)
1383                     hwndLocalPrev = prev;
1384                 prev = GetWindow( prev, GW_HWNDPREV );
1385             }
1386             if (!prev) hwndInsertAfter = hwndLocalPrev;
1387         }
1388     }
1389     else if (style & WS_CHILD) return hwndInsertAfter;
1390
1391     info.owner = hwnd;
1392     info.insert_after = hwndInsertAfter;
1393     EnumWindows( move_owned_popups, (LPARAM)&info );
1394     return info.insert_after;
1395 }
1396
1397 /***********************************************************************
1398  *           SWP_DoNCCalcSize
1399  */
1400 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
1401                               RECT *validRects )
1402 {
1403     UINT wvrFlags = 0;
1404     WND *wndPtr;
1405
1406     if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1407
1408       /* Send WM_NCCALCSIZE message to get new client area */
1409     if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1410     {
1411         NCCALCSIZE_PARAMS params;
1412         WINDOWPOS winposCopy;
1413
1414         params.rgrc[0] = *pNewWindowRect;
1415         params.rgrc[1] = wndPtr->rectWindow;
1416         params.rgrc[2] = wndPtr->rectClient;
1417         params.lppos = &winposCopy;
1418         winposCopy = *pWinpos;
1419         WIN_ReleasePtr( wndPtr );
1420
1421         wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
1422
1423         *pNewClientRect = params.rgrc[0];
1424
1425         if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1426
1427         TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
1428                wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
1429                wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
1430
1431         if( pNewClientRect->left != wndPtr->rectClient.left ||
1432             pNewClientRect->top != wndPtr->rectClient.top )
1433             pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1434
1435         if( (pNewClientRect->right - pNewClientRect->left !=
1436              wndPtr->rectClient.right - wndPtr->rectClient.left))
1437             pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1438         else
1439             wvrFlags &= ~WVR_HREDRAW;
1440
1441         if (pNewClientRect->bottom - pNewClientRect->top !=
1442              wndPtr->rectClient.bottom - wndPtr->rectClient.top)
1443             pWinpos->flags &= ~SWP_NOCLIENTSIZE;
1444         else
1445             wvrFlags &= ~WVR_VREDRAW;
1446
1447         validRects[0] = params.rgrc[1];
1448         validRects[1] = params.rgrc[2];
1449     }
1450     else
1451     {
1452         if (!(pWinpos->flags & SWP_NOMOVE) &&
1453             (pNewClientRect->left != wndPtr->rectClient.left ||
1454              pNewClientRect->top != wndPtr->rectClient.top))
1455             pWinpos->flags &= ~SWP_NOCLIENTMOVE;
1456     }
1457
1458     if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
1459     {
1460         SetRectEmpty( &validRects[0] );
1461         SetRectEmpty( &validRects[1] );
1462     }
1463     else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
1464
1465     WIN_ReleasePtr( wndPtr );
1466     return wvrFlags;
1467 }
1468
1469 /* fix redundant flags and values in the WINDOWPOS structure */
1470 static BOOL fixup_flags( WINDOWPOS *winpos )
1471 {
1472     HWND parent;
1473     WND *wndPtr = WIN_GetPtr( winpos->hwnd );
1474     BOOL ret = TRUE;
1475
1476     if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
1477     {
1478         SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1479         return FALSE;
1480     }
1481     winpos->hwnd = wndPtr->hwndSelf;  /* make it a full handle */
1482
1483     /* Finally make sure that all coordinates are valid */
1484     if (winpos->x < -32768) winpos->x = -32768;
1485     else if (winpos->x > 32767) winpos->x = 32767;
1486     if (winpos->y < -32768) winpos->y = -32768;
1487     else if (winpos->y > 32767) winpos->y = 32767;
1488
1489     if (winpos->cx < 0) winpos->cx = 0;
1490     else if (winpos->cx > 32767) winpos->cx = 32767;
1491     if (winpos->cy < 0) winpos->cy = 0;
1492     else if (winpos->cy > 32767) winpos->cy = 32767;
1493
1494     parent = GetAncestor( winpos->hwnd, GA_PARENT );
1495     if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
1496
1497     if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
1498     else
1499     {
1500         winpos->flags &= ~SWP_HIDEWINDOW;
1501         if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
1502     }
1503
1504     if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
1505         (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
1506         winpos->flags |= SWP_NOSIZE;    /* Already the right size */
1507
1508     if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
1509         winpos->flags |= SWP_NOMOVE;    /* Already the right position */
1510
1511     if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
1512     {
1513         if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
1514         {
1515             winpos->flags &= ~SWP_NOZORDER;
1516             winpos->hwndInsertAfter = HWND_TOP;
1517         }
1518     }
1519
1520     /* Check hwndInsertAfter */
1521     if (winpos->flags & SWP_NOZORDER) goto done;
1522
1523     /* fix sign extension */
1524     if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
1525     else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
1526
1527       /* FIXME: TOPMOST not supported yet */
1528     if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
1529         (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
1530
1531     /* hwndInsertAfter must be a sibling of the window */
1532     if (winpos->hwndInsertAfter == HWND_TOP)
1533     {
1534         if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
1535             winpos->flags |= SWP_NOZORDER;
1536     }
1537     else if (winpos->hwndInsertAfter == HWND_BOTTOM)
1538     {
1539         if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
1540             winpos->flags |= SWP_NOZORDER;
1541     }
1542     else
1543     {
1544         if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
1545         else
1546         {
1547             /* don't need to change the Zorder of hwnd if it's already inserted
1548              * after hwndInsertAfter or when inserting hwnd after itself.
1549              */
1550             if ((winpos->hwnd == winpos->hwndInsertAfter) ||
1551                 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
1552                 winpos->flags |= SWP_NOZORDER;
1553         }
1554     }
1555  done:
1556     WIN_ReleasePtr( wndPtr );
1557     return ret;
1558 }
1559
1560 /***********************************************************************
1561  *              USER_SetWindowPos
1562  *
1563  *     User32 internal function
1564  */
1565 BOOL USER_SetWindowPos( WINDOWPOS * winpos )
1566 {
1567     RECT newWindowRect, newClientRect, valid_rects[2];
1568     UINT orig_flags;
1569     
1570     orig_flags = winpos->flags;
1571     
1572     /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1573     if (!(winpos->flags & SWP_NOMOVE))
1574     {
1575         if (winpos->x < -32768) winpos->x = -32768;
1576         else if (winpos->x > 32767) winpos->x = 32767;
1577         if (winpos->y < -32768) winpos->y = -32768;
1578         else if (winpos->y > 32767) winpos->y = 32767;
1579     }
1580     if (!(winpos->flags & SWP_NOSIZE))
1581     {
1582         if (winpos->cx < 0) winpos->cx = 0;
1583         else if (winpos->cx > 32767) winpos->cx = 32767;
1584         if (winpos->cy < 0) winpos->cy = 0;
1585         else if (winpos->cy > 32767) winpos->cy = 32767;
1586     }
1587
1588     if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
1589
1590     /* Fix redundant flags */
1591     if (!fixup_flags( winpos )) return FALSE;
1592
1593     if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
1594     {
1595         if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
1596             winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
1597     }
1598
1599     /* Common operations */
1600
1601     SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
1602
1603     if(!USER_Driver->pSetWindowPos( winpos->hwnd, winpos->hwndInsertAfter, 
1604                             &newWindowRect, &newClientRect, orig_flags, valid_rects ))
1605         return FALSE;
1606
1607     /* erase parent if hiding child */
1608     if (!(orig_flags & SWP_DEFERERASE))
1609     {
1610         if (orig_flags & SWP_HIDEWINDOW)
1611         {
1612             HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
1613             erase_now( parent, RDW_NOCHILDREN );
1614         }
1615         else if (!(orig_flags & SWP_SHOWWINDOW) &&
1616                  (winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOGEOMETRYCHANGE)
1617         {
1618             erase_now( winpos->hwnd, 0 );
1619         }
1620     }
1621
1622     if( winpos->flags & SWP_HIDEWINDOW )
1623         HideCaret(winpos->hwnd);
1624     else if (winpos->flags & SWP_SHOWWINDOW)
1625         ShowCaret(winpos->hwnd);
1626
1627     if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
1628     {
1629         /* child windows get WM_CHILDACTIVATE message */
1630         if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1631             SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1632         else
1633             SetForegroundWindow( winpos->hwnd );
1634     }
1635
1636       /* And last, send the WM_WINDOWPOSCHANGED message */
1637
1638     TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1639
1640     if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1641     {
1642         /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1643            and always contains final window position.
1644          */
1645         winpos->x = newWindowRect.left;
1646         winpos->y = newWindowRect.top;
1647         winpos->cx = newWindowRect.right - newWindowRect.left;
1648         winpos->cy = newWindowRect.bottom - newWindowRect.top;
1649         SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1650     }
1651     return TRUE;
1652 }
1653
1654 /***********************************************************************
1655  *              SetWindowPos (USER32.@)
1656  */
1657 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1658                           INT x, INT y, INT cx, INT cy, UINT flags )
1659 {
1660     WINDOWPOS winpos;
1661
1662     TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1663           hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1664     if(TRACE_ON(win)) dump_winpos_flags(flags);
1665
1666     if (is_broadcast(hwnd))
1667     {
1668         SetLastError( ERROR_INVALID_PARAMETER );
1669         return FALSE;
1670     }
1671
1672     winpos.hwnd = WIN_GetFullHandle(hwnd);
1673     winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1674     winpos.x = x;
1675     winpos.y = y;
1676     winpos.cx = cx;
1677     winpos.cy = cy;
1678     winpos.flags = flags;
1679     
1680     if (WIN_IsCurrentThread( hwnd ))
1681         return USER_SetWindowPos(&winpos);
1682
1683     return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1684 }
1685
1686
1687 /***********************************************************************
1688  *              BeginDeferWindowPos (USER32.@)
1689  */
1690 HDWP WINAPI BeginDeferWindowPos( INT count )
1691 {
1692     HDWP handle;
1693     DWP *pDWP;
1694
1695     TRACE("%d\n", count);
1696
1697     if (count < 0)
1698     {
1699         SetLastError(ERROR_INVALID_PARAMETER);
1700         return 0;
1701     }
1702     /* Windows allows zero count, in which case it allocates context for 8 moves */
1703     if (count == 0) count = 8;
1704
1705     handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1706     if (!handle) return 0;
1707     pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1708     pDWP->actualCount    = 0;
1709     pDWP->suggestedCount = count;
1710     pDWP->valid          = TRUE;
1711     pDWP->wMagic         = DWP_MAGIC;
1712     pDWP->hwndParent     = 0;
1713
1714     TRACE("returning hdwp %p\n", handle);
1715     return handle;
1716 }
1717
1718
1719 /***********************************************************************
1720  *              DeferWindowPos (USER32.@)
1721  */
1722 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1723                                 INT x, INT y, INT cx, INT cy,
1724                                 UINT flags )
1725 {
1726     DWP *pDWP;
1727     int i;
1728     HDWP newhdwp = hdwp,retvalue;
1729
1730     TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1731           hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1732
1733     hwnd = WIN_GetFullHandle( hwnd );
1734     if (hwnd == GetDesktopWindow()) return 0;
1735
1736     if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1737
1738     USER_Lock();
1739
1740     for (i = 0; i < pDWP->actualCount; i++)
1741     {
1742         if (pDWP->winPos[i].hwnd == hwnd)
1743         {
1744               /* Merge with the other changes */
1745             if (!(flags & SWP_NOZORDER))
1746             {
1747                 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1748             }
1749             if (!(flags & SWP_NOMOVE))
1750             {
1751                 pDWP->winPos[i].x = x;
1752                 pDWP->winPos[i].y = y;
1753             }
1754             if (!(flags & SWP_NOSIZE))
1755             {
1756                 pDWP->winPos[i].cx = cx;
1757                 pDWP->winPos[i].cy = cy;
1758             }
1759             pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1760                                                SWP_NOZORDER | SWP_NOREDRAW |
1761                                                SWP_NOACTIVATE | SWP_NOCOPYBITS|
1762                                                SWP_NOOWNERZORDER);
1763             pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1764                                               SWP_FRAMECHANGED);
1765             retvalue = hdwp;
1766             goto END;
1767         }
1768     }
1769     if (pDWP->actualCount >= pDWP->suggestedCount)
1770     {
1771         newhdwp = USER_HEAP_REALLOC( hdwp,
1772                       sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1773         if (!newhdwp)
1774         {
1775             retvalue = 0;
1776             goto END;
1777         }
1778         pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1779         pDWP->suggestedCount++;
1780     }
1781     pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1782     pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1783     pDWP->winPos[pDWP->actualCount].x = x;
1784     pDWP->winPos[pDWP->actualCount].y = y;
1785     pDWP->winPos[pDWP->actualCount].cx = cx;
1786     pDWP->winPos[pDWP->actualCount].cy = cy;
1787     pDWP->winPos[pDWP->actualCount].flags = flags;
1788     pDWP->actualCount++;
1789     retvalue = newhdwp;
1790 END:
1791     USER_Unlock();
1792     return retvalue;
1793 }
1794
1795
1796 /***********************************************************************
1797  *              EndDeferWindowPos (USER32.@)
1798  */
1799 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1800 {
1801     DWP *pDWP;
1802     WINDOWPOS *winpos;
1803     BOOL res = TRUE;
1804     int i;
1805
1806     TRACE("%p\n", hdwp);
1807
1808     pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1809     if (!pDWP) return FALSE;
1810     for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1811     {
1812         TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1813                winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
1814                winpos->cx, winpos->cy, winpos->flags);
1815
1816         if (!(res = USER_SetWindowPos( winpos ))) break;
1817     }
1818     USER_HEAP_FREE( hdwp );
1819     return res;
1820 }
1821
1822
1823 /***********************************************************************
1824  *              TileChildWindows (USER.199)
1825  */
1826 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1827 {
1828     FIXME("(%04x, %d): stub\n", parent, action);
1829 }
1830
1831 /***********************************************************************
1832  *              CascadeChildWindows (USER.198)
1833  */
1834 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1835 {
1836     FIXME("(%04x, %d): stub\n", parent, action);
1837 }