Include <stdlib.h> to obtain a prototype of abs().
[wine] / windows / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27 #include "winerror.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winerror.h"
32 #include "wine/winuser16.h"
33 #include "wine/server.h"
34 #include "controls.h"
35 #include "user.h"
36 #include "win.h"
37 #include "message.h"
38 #include "winpos.h"
39 #include "nonclient.h"
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
43
44 #define HAS_DLGFRAME(style,exStyle) \
45     (((exStyle) & WS_EX_DLGMODALFRAME) || \
46      (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
47
48 #define HAS_THICKFRAME(style) \
49     (((style) & WS_THICKFRAME) && \
50      !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
51
52 #define EMPTYPOINT(pt)          ((*(LONG*)&(pt)) == -1)
53
54 #define PLACE_MIN               0x0001
55 #define PLACE_MAX               0x0002
56 #define PLACE_RECT              0x0004
57
58
59 #define DWP_MAGIC  ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
60
61 typedef struct
62 {
63     INT       actualCount;
64     INT       suggestedCount;
65     BOOL      valid;
66     INT       wMagic;
67     HWND      hwndParent;
68     WINDOWPOS winPos[1];
69 } DWP;
70
71 /* ----- internal variables ----- */
72
73 static LPCSTR atomInternalPos;
74
75
76 /***********************************************************************
77  *           WINPOS_CreateInternalPosAtom
78  */
79 BOOL WINPOS_CreateInternalPosAtom()
80 {
81     LPCSTR str = "SysIP";
82     atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
83     return (atomInternalPos) ? TRUE : FALSE;
84 }
85
86 /***********************************************************************
87  *           WINPOS_CheckInternalPos
88  *
89  * Called when a window is destroyed.
90  */
91 void WINPOS_CheckInternalPos( HWND hwnd )
92 {
93     LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
94
95     if( lpPos )
96     {
97         if( IsWindow(lpPos->hwndIconTitle) )
98             DestroyWindow( lpPos->hwndIconTitle );
99         HeapFree( GetProcessHeap(), 0, lpPos );
100     }
101 }
102
103 /***********************************************************************
104  *              ArrangeIconicWindows (USER32.@)
105  */
106 UINT WINAPI ArrangeIconicWindows( HWND parent )
107 {
108     RECT rectParent;
109     HWND hwndChild;
110     INT x, y, xspacing, yspacing;
111
112     GetClientRect( parent, &rectParent );
113     x = rectParent.left;
114     y = rectParent.bottom;
115     xspacing = GetSystemMetrics(SM_CXICONSPACING);
116     yspacing = GetSystemMetrics(SM_CYICONSPACING);
117
118     hwndChild = GetWindow( parent, GW_CHILD );
119     while (hwndChild)
120     {
121         if( IsIconic( hwndChild ) )
122         {
123             WINPOS_ShowIconTitle( hwndChild, FALSE );
124
125             SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
126                             y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
127                             SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
128             if( IsWindow(hwndChild) )
129                 WINPOS_ShowIconTitle(hwndChild , TRUE );
130
131             if (x <= rectParent.right - xspacing) x += xspacing;
132             else
133             {
134                 x = rectParent.left;
135                 y -= yspacing;
136             }
137         }
138         hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
139     }
140     return yspacing;
141 }
142
143
144 /***********************************************************************
145  *              SwitchToThisWindow (USER32.@)
146  */
147 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
148 {
149     ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
150 }
151
152
153 /***********************************************************************
154  *              GetWindowRect (USER32.@)
155  */
156 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
157 {
158     BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
159     if (ret)
160     {
161         MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
162         TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
163                hwnd, rect->left, rect->top, rect->right, rect->bottom);
164     }
165     return ret;
166 }
167
168
169 /***********************************************************************
170  *              GetWindowRgn (USER32.@)
171  */
172 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
173 {
174     int nRet = ERROR;
175     WND *wndPtr = WIN_GetPtr( hwnd );
176
177     if (wndPtr == WND_OTHER_PROCESS)
178     {
179         if (IsWindow( hwnd ))
180             FIXME( "not supported on other process window %p\n", hwnd );
181         wndPtr = NULL;
182     }
183     if (!wndPtr)
184     {
185         SetLastError( ERROR_INVALID_WINDOW_HANDLE );
186         return ERROR;
187     }
188     if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
189     WIN_ReleasePtr( wndPtr );
190     return nRet;
191 }
192
193
194 /***********************************************************************
195  *              SetWindowRgn (USER32.@)
196  */
197 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
198 {
199     RECT rect;
200     WND *wndPtr;
201
202     if (hrgn) /* verify that region really exists */
203     {
204         if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
205     }
206
207     if (USER_Driver.pSetWindowRgn)
208         return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
209
210     if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
211     {
212         if (IsWindow( hwnd ))
213             FIXME( "not supported on other process window %p\n", hwnd );
214         wndPtr = NULL;
215     }
216     if (!wndPtr)
217     {
218         SetLastError( ERROR_INVALID_WINDOW_HANDLE );
219         return FALSE;
220     }
221
222     if (wndPtr->hrgnWnd == hrgn)
223     {
224         WIN_ReleasePtr( wndPtr );
225         return TRUE;
226     }
227
228     if (wndPtr->hrgnWnd)
229     {
230         /* delete previous region */
231         DeleteObject(wndPtr->hrgnWnd);
232         wndPtr->hrgnWnd = 0;
233     }
234     wndPtr->hrgnWnd = hrgn;
235     WIN_ReleasePtr( wndPtr );
236
237     /* Size the window to the rectangle of the new region (if it isn't NULL) */
238     if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
239                             rect.right  - rect.left, rect.bottom - rect.top,
240                             SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
241                             SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
242     return TRUE;
243 }
244
245
246 /***********************************************************************
247  *              GetClientRect (USER32.@)
248  */
249 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
250 {
251     BOOL ret;
252
253     rect->right = rect->bottom = 0;
254     if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
255     {
256         rect->right -= rect->left;
257         rect->bottom -= rect->top;
258     }
259     rect->left = rect->top = 0;
260     return ret;
261 }
262
263
264 /*******************************************************************
265  *              ClientToScreen (USER32.@)
266  */
267 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
268 {
269     MapWindowPoints( hwnd, 0, lppnt, 1 );
270     return TRUE;
271 }
272
273
274 /*******************************************************************
275  *              ScreenToClient (USER32.@)
276  */
277 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
278 {
279     MapWindowPoints( 0, hwnd, lppnt, 1 );
280     return TRUE;
281 }
282
283
284 /***********************************************************************
285  *           find_child_from_point
286  *
287  * Find the child that contains pt. Helper for WindowFromPoint.
288  * pt is in parent client coordinates.
289  * lparam is the param to pass in the WM_NCHITTEST message.
290  */
291 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
292 {
293     int i, res;
294     LONG style, exstyle;
295     RECT rectWindow, rectClient;
296     WND *wndPtr;
297     HWND *list = WIN_ListChildren( parent );
298     HWND retvalue = 0;
299
300     if (!list) return 0;
301     for (i = 0; list[i]; i++)
302     {
303         /* If point is in window, and window is visible, and it  */
304         /* is enabled (or it's a top-level window), then explore */
305         /* its children. Otherwise, go to the next window.       */
306
307         style = GetWindowLongW( list[i], GWL_STYLE );
308         if (!(style & WS_VISIBLE)) continue;  /* not visible -> skip */
309         if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
310             continue;  /* disabled child -> skip */
311         exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
312         if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
313             continue;  /* transparent -> skip */
314
315         if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
316         if (!PtInRect( &rectWindow, pt )) continue;  /* not in window -> skip */
317
318         /* FIXME: check window region for other processes too */
319         if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
320         {
321             if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
322                                                 pt.x - rectWindow.left, pt.y - rectWindow.top ))
323             {
324                 WIN_ReleasePtr( wndPtr );
325                 continue;  /* point outside window region -> skip */
326             }
327             WIN_ReleasePtr( wndPtr );
328         }
329
330         /* If window is minimized or disabled, return at once */
331         if (style & WS_MINIMIZE)
332         {
333             *hittest = HTCAPTION;
334             retvalue = list[i];
335             break;
336         }
337         if (style & WS_DISABLED)
338         {
339             *hittest = HTERROR;
340             retvalue = list[i];
341             break;
342         }
343
344         /* If point is in client area, explore children */
345         if (PtInRect( &rectClient, pt ))
346         {
347             POINT new_pt;
348
349             new_pt.x = pt.x - rectClient.left;
350             new_pt.y = pt.y - rectClient.top;
351             if ((retvalue = find_child_from_point( list[i], new_pt, hittest, lparam ))) break;
352         }
353
354         /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
355         if (!WIN_IsCurrentThread( list[i] ))
356         {
357             *hittest = HTCLIENT;
358             retvalue = list[i];
359             break;
360         }
361         if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
362         {
363             *hittest = res;  /* Found the window */
364             retvalue = list[i];
365             break;
366         }
367         /* continue search with next sibling */
368     }
369     HeapFree( GetProcessHeap(), 0, list );
370     return retvalue;
371 }
372
373
374 /***********************************************************************
375  *           WINPOS_WindowFromPoint
376  *
377  * Find the window and hittest for a given point.
378  */
379 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
380 {
381     POINT xy = pt;
382     int res;
383     LONG style;
384
385     TRACE("scope %p %ld,%ld\n", hwndScope, pt.x, pt.y);
386
387     if (!hwndScope) hwndScope = GetDesktopWindow();
388     style = GetWindowLongW( hwndScope, GWL_STYLE );
389
390     *hittest = HTERROR;
391     if (style & WS_DISABLED) return 0;
392
393     MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
394
395     if (!(style & WS_MINIMIZE))
396     {
397         RECT rectClient;
398         if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
399         {
400             HWND ret;
401
402             xy.x -= rectClient.left;
403             xy.y -= rectClient.top;
404             if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
405             {
406                 TRACE( "found child %p\n", ret );
407                 return ret;
408             }
409         }
410     }
411
412     /* If nothing found, try the scope window */
413     if (!WIN_IsCurrentThread( hwndScope ))
414     {
415         *hittest = HTCLIENT;
416         TRACE( "returning %p\n", hwndScope );
417         return hwndScope;
418     }
419     res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
420     if (res != HTTRANSPARENT)
421     {
422         *hittest = res;  /* Found the window */
423         TRACE( "returning %p\n", hwndScope );
424         return hwndScope;
425     }
426     *hittest = HTNOWHERE;
427     TRACE( "nothing found\n" );
428     return 0;
429 }
430
431
432 /*******************************************************************
433  *              WindowFromPoint (USER32.@)
434  */
435 HWND WINAPI WindowFromPoint( POINT pt )
436 {
437     INT hittest;
438     return WINPOS_WindowFromPoint( 0, pt, &hittest );
439 }
440
441
442 /*******************************************************************
443  *              ChildWindowFromPoint (USER32.@)
444  */
445 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
446 {
447     return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
448 }
449
450 /*******************************************************************
451  *              ChildWindowFromPointEx (USER32.@)
452  */
453 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
454 {
455     /* pt is in the client coordinates */
456     HWND *list;
457     int i;
458     RECT rect;
459     HWND retvalue;
460
461     GetClientRect( hwndParent, &rect );
462     if (!PtInRect( &rect, pt )) return 0;
463     if (!(list = WIN_ListChildren( hwndParent ))) return 0;
464
465     for (i = 0; list[i]; i++)
466     {
467         if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
468         if (!PtInRect( &rect, pt )) continue;
469         if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
470         {
471             LONG style = GetWindowLongW( list[i], GWL_STYLE );
472             if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
473             if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
474         }
475         if (uFlags & CWP_SKIPTRANSPARENT)
476         {
477             if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
478         }
479         break;
480     }
481     retvalue = list[i];
482     HeapFree( GetProcessHeap(), 0, list );
483     if (!retvalue) retvalue = hwndParent;
484     return retvalue;
485 }
486
487
488 /*******************************************************************
489  *         WINPOS_GetWinOffset
490  *
491  * Calculate the offset between the origin of the two windows. Used
492  * to implement MapWindowPoints.
493  */
494 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
495 {
496     WND * wndPtr;
497
498     offset->x = offset->y = 0;
499
500     /* Translate source window origin to screen coords */
501     if (hwndFrom)
502     {
503         HWND hwnd = hwndFrom;
504
505         while (hwnd)
506         {
507             if (hwnd == hwndTo) return;
508             if (!(wndPtr = WIN_GetPtr( hwnd )))
509             {
510                 ERR( "bad hwndFrom = %p\n", hwnd );
511                 return;
512             }
513             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
514             offset->x += wndPtr->rectClient.left;
515             offset->y += wndPtr->rectClient.top;
516             hwnd = wndPtr->parent;
517             WIN_ReleasePtr( wndPtr );
518         }
519     }
520
521     /* Translate origin to destination window coords */
522     if (hwndTo)
523     {
524         HWND hwnd = hwndTo;
525
526         while (hwnd)
527         {
528             if (!(wndPtr = WIN_GetPtr( hwnd )))
529             {
530                 ERR( "bad hwndTo = %p\n", hwnd );
531                 return;
532             }
533             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
534             offset->x -= wndPtr->rectClient.left;
535             offset->y -= wndPtr->rectClient.top;
536             hwnd = wndPtr->parent;
537             WIN_ReleasePtr( wndPtr );
538         }
539     }
540     return;
541
542  other_process:  /* one of the parents may belong to another process, do it the hard way */
543     offset->x = offset->y = 0;
544     SERVER_START_REQ( get_windows_offset )
545     {
546         req->from = hwndFrom;
547         req->to   = hwndTo;
548         if (!wine_server_call( req ))
549         {
550             offset->x = reply->x;
551             offset->y = reply->y;
552         }
553     }
554     SERVER_END_REQ;
555 }
556
557
558 /*******************************************************************
559  *              MapWindowPoints (USER.258)
560  */
561 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
562                                LPPOINT16 lppt, UINT16 count )
563 {
564     POINT offset;
565
566     WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
567     while (count--)
568     {
569         lppt->x += offset.x;
570         lppt->y += offset.y;
571         lppt++;
572     }
573 }
574
575
576 /*******************************************************************
577  *              MapWindowPoints (USER32.@)
578  */
579 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
580 {
581     POINT offset;
582
583     WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
584     while (count--)
585     {
586         lppt->x += offset.x;
587         lppt->y += offset.y;
588         lppt++;
589     }
590     return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
591 }
592
593
594 /***********************************************************************
595  *              IsIconic (USER32.@)
596  */
597 BOOL WINAPI IsIconic(HWND hWnd)
598 {
599     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
600 }
601
602
603 /***********************************************************************
604  *              IsZoomed (USER32.@)
605  */
606 BOOL WINAPI IsZoomed(HWND hWnd)
607 {
608     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
609 }
610
611
612 /*******************************************************************
613  *              AllowSetForegroundWindow (USER32.@)
614  */
615 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
616 {
617     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
618      * implemented, then fix this function. */
619     return TRUE;
620 }
621
622
623 /*******************************************************************
624  *              LockSetForegroundWindow (USER32.@)
625  */
626 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
627 {
628     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
629      * implemented, then fix this function. */
630     return TRUE;
631 }
632
633
634 /***********************************************************************
635  *              BringWindowToTop (USER32.@)
636  */
637 BOOL WINAPI BringWindowToTop( HWND hwnd )
638 {
639     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
640 }
641
642
643 /***********************************************************************
644  *              MoveWindow (USER32.@)
645  */
646 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
647                             BOOL repaint )
648 {
649     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
650     if (!repaint) flags |= SWP_NOREDRAW;
651     TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
652     return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
653 }
654
655 /***********************************************************************
656  *           WINPOS_InitInternalPos
657  */
658 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
659 {
660     LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
661                                                       atomInternalPos );
662     if( !lpPos )
663     {
664         /* this happens when the window is minimized/maximized
665          * for the first time (rectWindow is not adjusted yet) */
666
667         lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
668         if( !lpPos ) return NULL;
669
670         SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
671         lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
672         CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
673         *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
674     }
675
676     if( wnd->dwStyle & WS_MINIMIZE )
677         CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
678     else if( wnd->dwStyle & WS_MAXIMIZE )
679         CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
680     else if( restoreRect )
681         CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
682
683     return lpPos;
684 }
685
686 /***********************************************************************
687  *           WINPOS_RedrawIconTitle
688  */
689 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
690 {
691     LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
692     if( lpPos )
693     {
694         if( lpPos->hwndIconTitle )
695         {
696             SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
697             InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
698             return TRUE;
699         }
700     }
701     return FALSE;
702 }
703
704 /***********************************************************************
705  *           WINPOS_ShowIconTitle
706  */
707 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
708 {
709     LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
710
711     if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_MANAGED))
712     {
713         HWND title = lpPos->hwndIconTitle;
714
715         TRACE("%p %i\n", hwnd, (bShow != 0) );
716
717         if( !title )
718             lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
719         if( bShow )
720         {
721             if (!IsWindowVisible(title))
722             {
723                 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
724                 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
725                               SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
726             }
727         }
728         else ShowWindow( title, SW_HIDE );
729     }
730     return FALSE;
731 }
732
733 /*******************************************************************
734  *           WINPOS_GetMinMaxInfo
735  *
736  * Get the minimized and maximized information for a window.
737  */
738 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
739                            POINT *minTrack, POINT *maxTrack )
740 {
741     LPINTERNALPOS lpPos;
742     MINMAXINFO MinMax;
743     INT xinc, yinc;
744     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
745     LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
746     RECT rc;
747
748     /* Compute default values */
749
750     GetWindowRect(hwnd, &rc);
751     MinMax.ptReserved.x = rc.left;
752     MinMax.ptReserved.y = rc.top;
753
754     if (style & WS_CHILD)
755     {
756         GetClientRect(GetParent(hwnd), &rc);
757         MinMax.ptMaxSize.x = rc.right;
758         MinMax.ptMaxSize.y = rc.bottom;
759     }
760     else
761     {
762         MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
763         MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
764     }
765     MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
766     MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
767     MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
768     MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
769
770     if (HAS_DLGFRAME( style, exstyle ))
771     {
772         xinc = GetSystemMetrics(SM_CXDLGFRAME);
773         yinc = GetSystemMetrics(SM_CYDLGFRAME);
774     }
775     else
776     {
777         xinc = yinc = 0;
778         if (HAS_THICKFRAME(style))
779         {
780             xinc += GetSystemMetrics(SM_CXFRAME);
781             yinc += GetSystemMetrics(SM_CYFRAME);
782         }
783         if (style & WS_BORDER)
784         {
785             xinc += GetSystemMetrics(SM_CXBORDER);
786             yinc += GetSystemMetrics(SM_CYBORDER);
787         }
788     }
789     MinMax.ptMaxSize.x += 2 * xinc;
790     MinMax.ptMaxSize.y += 2 * yinc;
791
792     lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
793     if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
794         CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
795     else
796     {
797         MinMax.ptMaxPosition.x = -xinc;
798         MinMax.ptMaxPosition.y = -yinc;
799     }
800
801     SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
802
803       /* Some sanity checks */
804
805     TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
806                       MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
807                       MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
808                       MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
809                       MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
810     MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
811                                    MinMax.ptMinTrackSize.x );
812     MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
813                                    MinMax.ptMinTrackSize.y );
814
815     if (maxSize) *maxSize = MinMax.ptMaxSize;
816     if (maxPos) *maxPos = MinMax.ptMaxPosition;
817     if (minTrack) *minTrack = MinMax.ptMinTrackSize;
818     if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
819 }
820
821 /***********************************************************************
822  *              ShowWindowAsync (USER32.@)
823  *
824  * doesn't wait; returns immediately.
825  * used by threads to toggle windows in other (possibly hanging) threads
826  */
827 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
828 {
829     HWND full_handle;
830
831     if (is_broadcast(hwnd))
832     {
833         SetLastError( ERROR_INVALID_PARAMETER );
834         return FALSE;
835     }
836
837     if ((full_handle = WIN_IsCurrentThread( hwnd )))
838         return USER_Driver.pShowWindow( full_handle, cmd );
839     return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
840 }
841
842
843 /***********************************************************************
844  *              ShowWindow (USER32.@)
845  */
846 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
847 {
848     HWND full_handle;
849
850     if (is_broadcast(hwnd))
851     {
852         SetLastError( ERROR_INVALID_PARAMETER );
853         return FALSE;
854     }
855     if ((full_handle = WIN_IsCurrentThread( hwnd )))
856     {
857         if (USER_Driver.pShowWindow)
858             return USER_Driver.pShowWindow( full_handle, cmd );
859         return FALSE;
860     }
861     return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
862 }
863
864
865 /***********************************************************************
866  *              GetInternalWindowPos (USER32.@)
867  */
868 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
869                                       LPPOINT ptIcon )
870 {
871     WINDOWPLACEMENT wndpl;
872     if (GetWindowPlacement( hwnd, &wndpl ))
873     {
874         if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
875         if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
876         return wndpl.showCmd;
877     }
878     return 0;
879 }
880
881
882 /***********************************************************************
883  *              GetWindowPlacement (USER32.@)
884  *
885  * Win95:
886  * Fails if wndpl->length of Win95 (!) apps is invalid.
887  */
888 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
889 {
890     WND *pWnd = WIN_FindWndPtr( hwnd );
891     LPINTERNALPOS lpPos;
892
893     if(!pWnd ) return FALSE;
894
895     lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
896     wndpl->length  = sizeof(*wndpl);
897     if( pWnd->dwStyle & WS_MINIMIZE )
898         wndpl->showCmd = SW_SHOWMINIMIZED;
899     else
900         wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
901     if( pWnd->flags & WIN_RESTORE_MAX )
902         wndpl->flags = WPF_RESTORETOMAXIMIZED;
903     else
904         wndpl->flags = 0;
905     CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
906     CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
907     CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
908     WIN_ReleaseWndPtr(pWnd);
909     return TRUE;
910 }
911
912
913 /***********************************************************************
914  *           WINPOS_SetPlacement
915  */
916 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
917 {
918     WND *pWnd = WIN_FindWndPtr( hwnd );
919     if( pWnd )
920     {
921         LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
922                              *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
923
924         if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
925         if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
926         if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
927
928         if( pWnd->dwStyle & WS_MINIMIZE )
929         {
930             WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
931             if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
932                 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
933                                 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
934         }
935         else if( pWnd->dwStyle & WS_MAXIMIZE )
936         {
937             if( !EMPTYPOINT(lpPos->ptMaxPos) )
938                 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
939                                 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
940         }
941         else if( flags & PLACE_RECT )
942                 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
943                                 lpPos->rectNormal.right - lpPos->rectNormal.left,
944                                 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
945                                 SWP_NOZORDER | SWP_NOACTIVATE );
946
947         ShowWindow( hwnd, wndpl->showCmd );
948         if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
949         {
950             if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
951
952             /* SDK: ...valid only the next time... */
953             if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
954         }
955         WIN_ReleaseWndPtr(pWnd);
956         return TRUE;
957     }
958     return FALSE;
959 }
960
961
962 /***********************************************************************
963  *              SetWindowPlacement (USER32.@)
964  *
965  * Win95:
966  * Fails if wndpl->length of Win95 (!) apps is invalid.
967  */
968 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
969 {
970     if (!wpl) return FALSE;
971     return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
972 }
973
974
975 /***********************************************************************
976  *              AnimateWindow (USER32.@)
977  *              Shows/Hides a window with an animation
978  *              NO ANIMATION YET
979  */
980 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
981 {
982         FIXME("partial stub\n");
983
984         /* If trying to show/hide and it's already   *
985          * shown/hidden or invalid window, fail with *
986          * invalid parameter                         */
987         if(!IsWindow(hwnd) ||
988            (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
989            (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
990         {
991                 SetLastError(ERROR_INVALID_PARAMETER);
992                 return FALSE;
993         }
994
995         ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
996
997         return TRUE;
998 }
999
1000 /***********************************************************************
1001  *              SetInternalWindowPos (USER32.@)
1002  */
1003 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1004                                     LPRECT rect, LPPOINT pt )
1005 {
1006     if( IsWindow(hwnd) )
1007     {
1008         WINDOWPLACEMENT wndpl;
1009         UINT flags;
1010
1011         wndpl.length  = sizeof(wndpl);
1012         wndpl.showCmd = showCmd;
1013         wndpl.flags = flags = 0;
1014
1015         if( pt )
1016         {
1017             flags |= PLACE_MIN;
1018             wndpl.flags |= WPF_SETMINPOSITION;
1019             wndpl.ptMinPosition = *pt;
1020         }
1021         if( rect )
1022         {
1023             flags |= PLACE_RECT;
1024             wndpl.rcNormalPosition = *rect;
1025         }
1026         WINPOS_SetPlacement( hwnd, &wndpl, flags );
1027     }
1028 }
1029
1030
1031 /*******************************************************************
1032  *         can_activate_window
1033  *
1034  * Check if we can activate the specified window.
1035  */
1036 static BOOL can_activate_window( HWND hwnd )
1037 {
1038     LONG style;
1039
1040     if (!hwnd) return FALSE;
1041     style = GetWindowLongW( hwnd, GWL_STYLE );
1042     if (!(style & WS_VISIBLE)) return FALSE;
1043     if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1044     return !(style & WS_DISABLED);
1045 }
1046
1047
1048 /*******************************************************************
1049  *         WINPOS_ActivateOtherWindow
1050  *
1051  *  Activates window other than pWnd.
1052  */
1053 void WINPOS_ActivateOtherWindow(HWND hwnd)
1054 {
1055     HWND hwndTo, fg;
1056
1057     if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1058     {
1059         hwndTo = GetAncestor( hwndTo, GA_ROOT );
1060         if (can_activate_window( hwndTo )) goto done;
1061     }
1062
1063     hwndTo = hwnd;
1064     for (;;)
1065     {
1066         if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1067         if (can_activate_window( hwndTo )) break;
1068     }
1069
1070  done:
1071     fg = GetForegroundWindow();
1072     TRACE("win = %p fg = %p\n", hwndTo, fg);
1073     if (!fg || (hwnd == fg))
1074     {
1075         if (SetForegroundWindow( hwndTo )) return;
1076     }
1077     if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1078 }
1079
1080
1081 /***********************************************************************
1082  *           WINPOS_HandleWindowPosChanging16
1083  *
1084  * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1085  */
1086 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1087 {
1088     POINT maxSize, minTrack;
1089     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1090
1091     if (winpos->flags & SWP_NOSIZE) return 0;
1092     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1093     {
1094         WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1095         if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1096         if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1097         if (!(style & WS_MINIMIZE))
1098         {
1099             if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1100             if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1101         }
1102     }
1103     return 0;
1104 }
1105
1106
1107 /***********************************************************************
1108  *           WINPOS_HandleWindowPosChanging
1109  *
1110  * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1111  */
1112 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1113 {
1114     POINT maxSize, minTrack;
1115     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1116
1117     if (winpos->flags & SWP_NOSIZE) return 0;
1118     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1119     {
1120         WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1121         winpos->cx = min( winpos->cx, maxSize.x );
1122         winpos->cy = min( winpos->cy, maxSize.y );
1123         if (!(style & WS_MINIMIZE))
1124         {
1125             if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1126             if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1127         }
1128     }
1129     return 0;
1130 }
1131
1132
1133 /***********************************************************************
1134  *           dump_winpos_flags
1135  */
1136 static void dump_winpos_flags(UINT flags)
1137 {
1138     TRACE("flags:");
1139     if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1140     if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1141     if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1142     if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1143     if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1144     if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1145     if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1146     if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1147     if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1148     if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1149     if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1150     if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1151     if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1152
1153 #define DUMPED_FLAGS \
1154     (SWP_NOSIZE | \
1155     SWP_NOMOVE | \
1156     SWP_NOZORDER | \
1157     SWP_NOREDRAW | \
1158     SWP_NOACTIVATE | \
1159     SWP_FRAMECHANGED | \
1160     SWP_SHOWWINDOW | \
1161     SWP_HIDEWINDOW | \
1162     SWP_NOCOPYBITS | \
1163     SWP_NOOWNERZORDER | \
1164     SWP_NOSENDCHANGING | \
1165     SWP_DEFERERASE | \
1166     SWP_ASYNCWINDOWPOS)
1167
1168     if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1169     TRACE("\n");
1170 #undef DUMPED_FLAGS
1171 }
1172
1173 /***********************************************************************
1174  *              SetWindowPos (USER32.@)
1175  */
1176 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1177                           INT x, INT y, INT cx, INT cy, UINT flags )
1178 {
1179     WINDOWPOS winpos;
1180
1181     TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1182           hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1183     if(TRACE_ON(win)) dump_winpos_flags(flags);
1184
1185     if (is_broadcast(hwnd))
1186     {
1187         SetLastError( ERROR_INVALID_PARAMETER );
1188         return FALSE;
1189     }
1190
1191     winpos.hwnd = WIN_GetFullHandle(hwnd);
1192     winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1193     winpos.x = x;
1194     winpos.y = y;
1195     winpos.cx = cx;
1196     winpos.cy = cy;
1197     winpos.flags = flags;
1198     if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1199     return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1200 }
1201
1202
1203 /***********************************************************************
1204  *              BeginDeferWindowPos (USER32.@)
1205  */
1206 HDWP WINAPI BeginDeferWindowPos( INT count )
1207 {
1208     HDWP handle;
1209     DWP *pDWP;
1210
1211     TRACE("%d\n", count);
1212
1213     if (count < 0)
1214     {
1215         SetLastError(ERROR_INVALID_PARAMETER);
1216         return 0;
1217     }
1218     /* Windows allows zero count, in which case it allocates context for 8 moves */
1219     if (count == 0) count = 8;
1220
1221     handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1222     if (!handle) return 0;
1223     pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1224     pDWP->actualCount    = 0;
1225     pDWP->suggestedCount = count;
1226     pDWP->valid          = TRUE;
1227     pDWP->wMagic         = DWP_MAGIC;
1228     pDWP->hwndParent     = 0;
1229
1230     TRACE("returning hdwp %p\n", handle);
1231     return handle;
1232 }
1233
1234
1235 /***********************************************************************
1236  *              DeferWindowPos (USER32.@)
1237  */
1238 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1239                                 INT x, INT y, INT cx, INT cy,
1240                                 UINT flags )
1241 {
1242     DWP *pDWP;
1243     int i;
1244     HDWP newhdwp = hdwp,retvalue;
1245
1246     TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1247           hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1248
1249     hwnd = WIN_GetFullHandle( hwnd );
1250     if (hwnd == GetDesktopWindow()) return 0;
1251
1252     if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1253
1254     USER_Lock();
1255
1256     for (i = 0; i < pDWP->actualCount; i++)
1257     {
1258         if (pDWP->winPos[i].hwnd == hwnd)
1259         {
1260               /* Merge with the other changes */
1261             if (!(flags & SWP_NOZORDER))
1262             {
1263                 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1264             }
1265             if (!(flags & SWP_NOMOVE))
1266             {
1267                 pDWP->winPos[i].x = x;
1268                 pDWP->winPos[i].y = y;
1269             }
1270             if (!(flags & SWP_NOSIZE))
1271             {
1272                 pDWP->winPos[i].cx = cx;
1273                 pDWP->winPos[i].cy = cy;
1274             }
1275             pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1276                                                SWP_NOZORDER | SWP_NOREDRAW |
1277                                                SWP_NOACTIVATE | SWP_NOCOPYBITS|
1278                                                SWP_NOOWNERZORDER);
1279             pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1280                                               SWP_FRAMECHANGED);
1281             retvalue = hdwp;
1282             goto END;
1283         }
1284     }
1285     if (pDWP->actualCount >= pDWP->suggestedCount)
1286     {
1287         newhdwp = USER_HEAP_REALLOC( hdwp,
1288                       sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1289         if (!newhdwp)
1290         {
1291             retvalue = 0;
1292             goto END;
1293         }
1294         pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1295         pDWP->suggestedCount++;
1296     }
1297     pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1298     pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1299     pDWP->winPos[pDWP->actualCount].x = x;
1300     pDWP->winPos[pDWP->actualCount].y = y;
1301     pDWP->winPos[pDWP->actualCount].cx = cx;
1302     pDWP->winPos[pDWP->actualCount].cy = cy;
1303     pDWP->winPos[pDWP->actualCount].flags = flags;
1304     pDWP->actualCount++;
1305     retvalue = newhdwp;
1306 END:
1307     USER_Unlock();
1308     return retvalue;
1309 }
1310
1311
1312 /***********************************************************************
1313  *              EndDeferWindowPos (USER32.@)
1314  */
1315 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1316 {
1317     DWP *pDWP;
1318     WINDOWPOS *winpos;
1319     BOOL res = TRUE;
1320     int i;
1321
1322     TRACE("%p\n", hdwp);
1323
1324     pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1325     if (!pDWP) return FALSE;
1326     for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1327     {
1328         if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1329     }
1330     USER_HEAP_FREE( hdwp );
1331     return res;
1332 }
1333
1334
1335 /***********************************************************************
1336  *              TileChildWindows (USER.199)
1337  */
1338 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1339 {
1340     FIXME("(%04x, %d): stub\n", parent, action);
1341 }
1342
1343 /***********************************************************************
1344  *              CascadeChildWindows (USER.198)
1345  */
1346 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1347 {
1348     FIXME("(%04x, %d): stub\n", parent, action);
1349 }