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