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