Add more tests for text placement in single and multiline edit
[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., 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 "ntstatus.h"
33 #include "wine/winuser16.h"
34 #include "wine/server.h"
35 #include "controls.h"
36 #include "user_private.h"
37 #include "win.h"
38 #include "winpos.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
42
43 #define HAS_DLGFRAME(style,exStyle) \
44     (((exStyle) & WS_EX_DLGMODALFRAME) || \
45      (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
46
47 #define HAS_THICKFRAME(style) \
48     (((style) & WS_THICKFRAME) && \
49      !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
50
51 #define EMPTYPOINT(pt)          ((*(LONG*)&(pt)) == -1)
52
53 #define PLACE_MIN               0x0001
54 #define PLACE_MAX               0x0002
55 #define PLACE_RECT              0x0004
56
57
58 #define DWP_MAGIC  ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
59
60 typedef struct
61 {
62     INT       actualCount;
63     INT       suggestedCount;
64     BOOL      valid;
65     INT       wMagic;
66     HWND      hwndParent;
67     WINDOWPOS winPos[1];
68 } DWP;
69
70 typedef struct
71 {
72     RECT16   rectNormal;
73     POINT16  ptIconPos;
74     POINT16  ptMaxPos;
75     HWND     hwndIconTitle;
76 } INTERNALPOS, *LPINTERNALPOS;
77
78 /* ----- internal variables ----- */
79
80 static LPCSTR atomInternalPos;
81
82
83 /***********************************************************************
84  *           WINPOS_CreateInternalPosAtom
85  */
86 BOOL WINPOS_CreateInternalPosAtom()
87 {
88     LPCSTR str = "SysIP";
89     atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
90     return (atomInternalPos) ? TRUE : FALSE;
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 = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
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 && USER_Driver.pSetWindowRgn)
268         ret = USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
269
270     if (ret && bRedraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
271     return ret;
272 }
273
274
275 /***********************************************************************
276  *              GetClientRect (USER32.@)
277  */
278 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
279 {
280     BOOL ret;
281
282     if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
283     {
284         rect->right -= rect->left;
285         rect->bottom -= rect->top;
286         rect->left = rect->top = 0;
287     }
288     return ret;
289 }
290
291
292 /*******************************************************************
293  *              ClientToScreen (USER32.@)
294  */
295 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
296 {
297     MapWindowPoints( hwnd, 0, lppnt, 1 );
298     return TRUE;
299 }
300
301
302 /*******************************************************************
303  *              ScreenToClient (USER32.@)
304  */
305 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
306 {
307     MapWindowPoints( 0, hwnd, lppnt, 1 );
308     return TRUE;
309 }
310
311
312 /***********************************************************************
313  *           list_children_from_point
314  *
315  * Get the list of children that can contain point from the server.
316  * Point is in screen coordinates.
317  * Returned list must be freed by caller.
318  */
319 static HWND *list_children_from_point( HWND hwnd, POINT pt )
320 {
321     HWND *list;
322     int size = 32;
323
324     for (;;)
325     {
326         int count = 0;
327
328         if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
329
330         SERVER_START_REQ( get_window_children_from_point )
331         {
332             req->parent = hwnd;
333             req->x = pt.x;
334             req->y = pt.y;
335             wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
336             if (!wine_server_call( req )) count = reply->count;
337         }
338         SERVER_END_REQ;
339         if (count && count < size)
340         {
341             list[count] = 0;
342             return list;
343         }
344         HeapFree( GetProcessHeap(), 0, list );
345         if (!count) break;
346         size = count + 1;  /* restart with a large enough buffer */
347     }
348     return NULL;
349 }
350
351
352 /***********************************************************************
353  *           WINPOS_WindowFromPoint
354  *
355  * Find the window and hittest for a given point.
356  */
357 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
358 {
359     int i, res;
360     HWND ret, *list;
361
362     if (!hwndScope) hwndScope = GetDesktopWindow();
363
364     *hittest = HTNOWHERE;
365
366     if (!(list = list_children_from_point( hwndScope, pt ))) return 0;
367
368     /* now determine the hittest */
369
370     for (i = 0; list[i]; i++)
371     {
372         LONG style = GetWindowLongW( list[i], GWL_STYLE );
373
374         /* If window is minimized or disabled, return at once */
375         if (style & WS_MINIMIZE)
376         {
377             *hittest = HTCAPTION;
378             break;
379         }
380         if (style & WS_DISABLED)
381         {
382             *hittest = HTERROR;
383             break;
384         }
385         /* Send WM_NCCHITTEST (if same thread) */
386         if (!WIN_IsCurrentThread( list[i] ))
387         {
388             *hittest = HTCLIENT;
389             break;
390         }
391         res = SendMessageA( list[i], WM_NCHITTEST, 0, MAKELONG(pt.x,pt.y) );
392         if (res != HTTRANSPARENT)
393         {
394             *hittest = res;  /* Found the window */
395             break;
396         }
397         /* continue search with next window in z-order */
398     }
399     ret = list[i];
400     HeapFree( GetProcessHeap(), 0, list );
401     TRACE( "scope %p (%ld,%ld) returning %p\n", hwndScope, pt.x, pt.y, ret );
402     return ret;
403 }
404
405
406 /*******************************************************************
407  *              WindowFromPoint (USER32.@)
408  */
409 HWND WINAPI WindowFromPoint( POINT pt )
410 {
411     INT hittest;
412     return WINPOS_WindowFromPoint( 0, pt, &hittest );
413 }
414
415
416 /*******************************************************************
417  *              ChildWindowFromPoint (USER32.@)
418  */
419 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
420 {
421     return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
422 }
423
424 /*******************************************************************
425  *              ChildWindowFromPointEx (USER32.@)
426  */
427 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
428 {
429     /* pt is in the client coordinates */
430     HWND *list;
431     int i;
432     RECT rect;
433     HWND retvalue;
434
435     GetClientRect( hwndParent, &rect );
436     if (!PtInRect( &rect, pt )) return 0;
437     if (!(list = WIN_ListChildren( hwndParent ))) return hwndParent;
438
439     for (i = 0; list[i]; i++)
440     {
441         if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
442         if (!PtInRect( &rect, pt )) continue;
443         if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
444         {
445             LONG style = GetWindowLongW( list[i], GWL_STYLE );
446             if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
447             if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
448         }
449         if (uFlags & CWP_SKIPTRANSPARENT)
450         {
451             if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
452         }
453         break;
454     }
455     retvalue = list[i];
456     HeapFree( GetProcessHeap(), 0, list );
457     if (!retvalue) retvalue = hwndParent;
458     return retvalue;
459 }
460
461
462 /*******************************************************************
463  *         WINPOS_GetWinOffset
464  *
465  * Calculate the offset between the origin of the two windows. Used
466  * to implement MapWindowPoints.
467  */
468 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
469 {
470     WND * wndPtr;
471
472     offset->x = offset->y = 0;
473
474     /* Translate source window origin to screen coords */
475     if (hwndFrom)
476     {
477         HWND hwnd = hwndFrom;
478
479         while (hwnd)
480         {
481             if (hwnd == hwndTo) return;
482             if (!(wndPtr = WIN_GetPtr( hwnd )))
483             {
484                 ERR( "bad hwndFrom = %p\n", hwnd );
485                 return;
486             }
487             if (wndPtr == WND_DESKTOP) break;
488             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
489             offset->x += wndPtr->rectClient.left;
490             offset->y += wndPtr->rectClient.top;
491             hwnd = wndPtr->parent;
492             WIN_ReleasePtr( wndPtr );
493         }
494     }
495
496     /* Translate origin to destination window coords */
497     if (hwndTo)
498     {
499         HWND hwnd = hwndTo;
500
501         while (hwnd)
502         {
503             if (!(wndPtr = WIN_GetPtr( hwnd )))
504             {
505                 ERR( "bad hwndTo = %p\n", hwnd );
506                 return;
507             }
508             if (wndPtr == WND_DESKTOP) break;
509             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
510             offset->x -= wndPtr->rectClient.left;
511             offset->y -= wndPtr->rectClient.top;
512             hwnd = wndPtr->parent;
513             WIN_ReleasePtr( wndPtr );
514         }
515     }
516     return;
517
518  other_process:  /* one of the parents may belong to another process, do it the hard way */
519     offset->x = offset->y = 0;
520     SERVER_START_REQ( get_windows_offset )
521     {
522         req->from = hwndFrom;
523         req->to   = hwndTo;
524         if (!wine_server_call( req ))
525         {
526             offset->x = reply->x;
527             offset->y = reply->y;
528         }
529     }
530     SERVER_END_REQ;
531 }
532
533
534 /*******************************************************************
535  *              MapWindowPoints (USER.258)
536  */
537 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
538                                LPPOINT16 lppt, UINT16 count )
539 {
540     POINT offset;
541
542     WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
543     while (count--)
544     {
545         lppt->x += offset.x;
546         lppt->y += offset.y;
547         lppt++;
548     }
549 }
550
551
552 /*******************************************************************
553  *              MapWindowPoints (USER32.@)
554  */
555 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
556 {
557     POINT offset;
558
559     WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
560     while (count--)
561     {
562         lppt->x += offset.x;
563         lppt->y += offset.y;
564         lppt++;
565     }
566     return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
567 }
568
569
570 /***********************************************************************
571  *              IsIconic (USER32.@)
572  */
573 BOOL WINAPI IsIconic(HWND hWnd)
574 {
575     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
576 }
577
578
579 /***********************************************************************
580  *              IsZoomed (USER32.@)
581  */
582 BOOL WINAPI IsZoomed(HWND hWnd)
583 {
584     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
585 }
586
587
588 /*******************************************************************
589  *              AllowSetForegroundWindow (USER32.@)
590  */
591 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
592 {
593     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
594      * implemented, then fix this function. */
595     return TRUE;
596 }
597
598
599 /*******************************************************************
600  *              LockSetForegroundWindow (USER32.@)
601  */
602 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
603 {
604     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
605      * implemented, then fix this function. */
606     return TRUE;
607 }
608
609
610 /***********************************************************************
611  *              BringWindowToTop (USER32.@)
612  */
613 BOOL WINAPI BringWindowToTop( HWND hwnd )
614 {
615     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
616 }
617
618
619 /***********************************************************************
620  *              MoveWindow (USER32.@)
621  */
622 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
623                             BOOL repaint )
624 {
625     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
626     if (!repaint) flags |= SWP_NOREDRAW;
627     TRACE("%p %d,%d %dx%d %d\n", hwnd, x, y, cx, cy, repaint );
628     return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
629 }
630
631 /***********************************************************************
632  *           WINPOS_InitInternalPos
633  */
634 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd )
635 {
636     LPINTERNALPOS lpPos = GetPropA( wnd->hwndSelf, atomInternalPos );
637     if( !lpPos )
638     {
639         /* this happens when the window is minimized/maximized
640          * for the first time (rectWindow is not adjusted yet) */
641
642         lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
643         if( !lpPos ) return NULL;
644
645         SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
646         lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
647         lpPos->rectNormal.left   = wnd->rectWindow.left;
648         lpPos->rectNormal.top    = wnd->rectWindow.top;
649         lpPos->rectNormal.right  = wnd->rectWindow.right;
650         lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
651         lpPos->ptIconPos.x = lpPos->ptIconPos.y = -1;
652         lpPos->ptMaxPos.x = lpPos->ptMaxPos.y = -1;
653     }
654
655     if( wnd->dwStyle & WS_MINIMIZE )
656     {
657         lpPos->ptIconPos.x = wnd->rectWindow.left;
658         lpPos->ptIconPos.y = wnd->rectWindow.top;
659     }
660     else if( wnd->dwStyle & WS_MAXIMIZE )
661     {
662         lpPos->ptMaxPos.x = wnd->rectWindow.left;
663         lpPos->ptMaxPos.y = wnd->rectWindow.top;
664     }
665     else
666     {
667         lpPos->rectNormal.left   = wnd->rectWindow.left;
668         lpPos->rectNormal.top    = wnd->rectWindow.top;
669         lpPos->rectNormal.right  = wnd->rectWindow.right;
670         lpPos->rectNormal.bottom = wnd->rectWindow.bottom;
671     }
672     return lpPos;
673 }
674
675 /***********************************************************************
676  *           WINPOS_RedrawIconTitle
677  */
678 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
679 {
680     LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
681     if( lpPos )
682     {
683         if( lpPos->hwndIconTitle )
684         {
685             SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
686             InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
687             return TRUE;
688         }
689     }
690     return FALSE;
691 }
692
693 /***********************************************************************
694  *           WINPOS_ShowIconTitle
695  */
696 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
697 {
698     LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
699
700     if (lpPos && !GetPropA( hwnd, "__wine_x11_managed" ))
701     {
702         HWND title = lpPos->hwndIconTitle;
703
704         TRACE("%p %i\n", hwnd, (bShow != 0) );
705
706         if( !title )
707             lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
708         if( bShow )
709         {
710             if (!IsWindowVisible(title))
711             {
712                 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
713                 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
714                               SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
715             }
716         }
717         else ShowWindow( title, SW_HIDE );
718     }
719     return FALSE;
720 }
721
722 /*******************************************************************
723  *           WINPOS_GetMinMaxInfo
724  *
725  * Get the minimized and maximized information for a window.
726  */
727 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
728                            POINT *minTrack, POINT *maxTrack )
729 {
730     LPINTERNALPOS lpPos;
731     MINMAXINFO MinMax;
732     INT xinc, yinc;
733     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
734     LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
735     RECT rc;
736
737     /* Compute default values */
738
739     GetWindowRect(hwnd, &rc);
740     MinMax.ptReserved.x = rc.left;
741     MinMax.ptReserved.y = rc.top;
742
743     if (style & WS_CHILD)
744     {
745         if ((style & WS_CAPTION) == WS_CAPTION)
746             style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
747
748         GetClientRect(GetAncestor(hwnd,GA_PARENT), &rc);
749         AdjustWindowRectEx(&rc, style, ((style & WS_POPUP) && GetMenu(hwnd)), exstyle);
750
751         /* avoid calculating this twice */
752         style &= ~(WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
753
754         MinMax.ptMaxSize.x = rc.right - rc.left;
755         MinMax.ptMaxSize.y = rc.bottom - rc.top;
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) + 2*GetSystemMetrics(SM_CXFRAME);
765     MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN) + 2*GetSystemMetrics(SM_CYFRAME);
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     {
792         MinMax.ptMaxPosition.x = lpPos->ptMaxPos.x;
793         MinMax.ptMaxPosition.y = lpPos->ptMaxPos.y;
794     }
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     {
839         if (USER_Driver.pShowWindow)
840             return USER_Driver.pShowWindow( full_handle, cmd );
841         return FALSE;
842     }
843     return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
844 }
845
846
847 /***********************************************************************
848  *              ShowWindow (USER32.@)
849  */
850 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
851 {
852     HWND full_handle;
853
854     if (is_broadcast(hwnd))
855     {
856         SetLastError( ERROR_INVALID_PARAMETER );
857         return FALSE;
858     }
859     if ((full_handle = WIN_IsCurrentThread( hwnd )))
860     {
861         if (USER_Driver.pShowWindow)
862             return USER_Driver.pShowWindow( full_handle, cmd );
863         return FALSE;
864     }
865     return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
866 }
867
868
869 /***********************************************************************
870  *              GetInternalWindowPos (USER32.@)
871  */
872 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
873                                       LPPOINT ptIcon )
874 {
875     WINDOWPLACEMENT wndpl;
876     if (GetWindowPlacement( hwnd, &wndpl ))
877     {
878         if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
879         if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
880         return wndpl.showCmd;
881     }
882     return 0;
883 }
884
885
886 /***********************************************************************
887  *              GetWindowPlacement (USER32.@)
888  *
889  * Win95:
890  * Fails if wndpl->length of Win95 (!) apps is invalid.
891  */
892 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
893 {
894     WND *pWnd = WIN_GetPtr( hwnd );
895     LPINTERNALPOS lpPos;
896
897     if (!pWnd || pWnd == WND_DESKTOP) return FALSE;
898     if (pWnd == WND_OTHER_PROCESS)
899     {
900         if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
901         return FALSE;
902     }
903
904     lpPos = WINPOS_InitInternalPos( pWnd );
905     wndpl->length  = sizeof(*wndpl);
906     if( pWnd->dwStyle & WS_MINIMIZE )
907         wndpl->showCmd = SW_SHOWMINIMIZED;
908     else
909         wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
910     if( pWnd->flags & WIN_RESTORE_MAX )
911         wndpl->flags = WPF_RESTORETOMAXIMIZED;
912     else
913         wndpl->flags = 0;
914     wndpl->ptMinPosition.x = lpPos->ptIconPos.x;
915     wndpl->ptMinPosition.y = lpPos->ptIconPos.y;
916     wndpl->ptMaxPosition.x = lpPos->ptMaxPos.x;
917     wndpl->ptMaxPosition.y = lpPos->ptMaxPos.y;
918     wndpl->rcNormalPosition.left   = lpPos->rectNormal.left;
919     wndpl->rcNormalPosition.top    = lpPos->rectNormal.top;
920     wndpl->rcNormalPosition.right  = lpPos->rectNormal.right;
921     wndpl->rcNormalPosition.bottom = lpPos->rectNormal.bottom;
922     WIN_ReleasePtr( pWnd );
923     return TRUE;
924 }
925
926
927 /***********************************************************************
928  *           WINPOS_SetPlacement
929  */
930 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
931 {
932     LPINTERNALPOS lpPos;
933     DWORD style;
934     WND *pWnd = WIN_GetPtr( hwnd );
935
936     if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
937     lpPos = WINPOS_InitInternalPos( pWnd );
938
939     if( flags & PLACE_MIN )
940     {
941         lpPos->ptIconPos.x = wndpl->ptMinPosition.x;
942         lpPos->ptIconPos.y = wndpl->ptMinPosition.y;
943     }
944     if( flags & PLACE_MAX )
945     {
946         lpPos->ptMaxPos.x = wndpl->ptMaxPosition.x;
947         lpPos->ptMaxPos.y = wndpl->ptMaxPosition.y;
948     }
949     if( flags & PLACE_RECT)
950     {
951         lpPos->rectNormal.left   = wndpl->rcNormalPosition.left;
952         lpPos->rectNormal.top    = wndpl->rcNormalPosition.top;
953         lpPos->rectNormal.right  = wndpl->rcNormalPosition.right;
954         lpPos->rectNormal.bottom = wndpl->rcNormalPosition.bottom;
955     }
956
957     style = pWnd->dwStyle;
958     WIN_ReleasePtr( pWnd );
959
960     if( style & WS_MINIMIZE )
961     {
962         WINPOS_ShowIconTitle( hwnd, FALSE );
963         if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
964             SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
965                           0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
966     }
967     else if( style & WS_MAXIMIZE )
968     {
969         if( !EMPTYPOINT(lpPos->ptMaxPos) )
970             SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
971                           0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
972     }
973     else if( flags & PLACE_RECT )
974         SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
975                       lpPos->rectNormal.right - lpPos->rectNormal.left,
976                       lpPos->rectNormal.bottom - lpPos->rectNormal.top,
977                       SWP_NOZORDER | SWP_NOACTIVATE );
978
979     ShowWindow( hwnd, wndpl->showCmd );
980
981     if (IsIconic( hwnd ))
982     {
983         if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) WINPOS_ShowIconTitle( hwnd, TRUE );
984
985         /* SDK: ...valid only the next time... */
986         if( wndpl->flags & WPF_RESTORETOMAXIMIZED )
987         {
988             pWnd = WIN_GetPtr( hwnd );
989             if (pWnd && pWnd != WND_OTHER_PROCESS)
990             {
991                 pWnd->flags |= WIN_RESTORE_MAX;
992                 WIN_ReleasePtr( pWnd );
993             }
994         }
995     }
996     return TRUE;
997 }
998
999
1000 /***********************************************************************
1001  *              SetWindowPlacement (USER32.@)
1002  *
1003  * Win95:
1004  * Fails if wndpl->length of Win95 (!) apps is invalid.
1005  */
1006 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1007 {
1008     if (!wpl) return FALSE;
1009     return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1010 }
1011
1012
1013 /***********************************************************************
1014  *              AnimateWindow (USER32.@)
1015  *              Shows/Hides a window with an animation
1016  *              NO ANIMATION YET
1017  */
1018 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1019 {
1020         FIXME("partial stub\n");
1021
1022         /* If trying to show/hide and it's already   *
1023          * shown/hidden or invalid window, fail with *
1024          * invalid parameter                         */
1025         if(!IsWindow(hwnd) ||
1026            (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1027            (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1028         {
1029                 SetLastError(ERROR_INVALID_PARAMETER);
1030                 return FALSE;
1031         }
1032
1033         ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1034
1035         return TRUE;
1036 }
1037
1038 /***********************************************************************
1039  *              SetInternalWindowPos (USER32.@)
1040  */
1041 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1042                                     LPRECT rect, LPPOINT pt )
1043 {
1044     if( IsWindow(hwnd) )
1045     {
1046         WINDOWPLACEMENT wndpl;
1047         UINT flags;
1048
1049         wndpl.length  = sizeof(wndpl);
1050         wndpl.showCmd = showCmd;
1051         wndpl.flags = flags = 0;
1052
1053         if( pt )
1054         {
1055             flags |= PLACE_MIN;
1056             wndpl.flags |= WPF_SETMINPOSITION;
1057             wndpl.ptMinPosition = *pt;
1058         }
1059         if( rect )
1060         {
1061             flags |= PLACE_RECT;
1062             wndpl.rcNormalPosition = *rect;
1063         }
1064         WINPOS_SetPlacement( hwnd, &wndpl, flags );
1065     }
1066 }
1067
1068
1069 /*******************************************************************
1070  *         can_activate_window
1071  *
1072  * Check if we can activate the specified window.
1073  */
1074 static BOOL can_activate_window( HWND hwnd )
1075 {
1076     LONG style;
1077
1078     if (!hwnd) return FALSE;
1079     style = GetWindowLongW( hwnd, GWL_STYLE );
1080     if (!(style & WS_VISIBLE)) return FALSE;
1081     if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1082     return !(style & WS_DISABLED);
1083 }
1084
1085
1086 /*******************************************************************
1087  *         WINPOS_ActivateOtherWindow
1088  *
1089  *  Activates window other than pWnd.
1090  */
1091 void WINPOS_ActivateOtherWindow(HWND hwnd)
1092 {
1093     HWND hwndTo, fg;
1094
1095     if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1096     {
1097         hwndTo = GetAncestor( hwndTo, GA_ROOT );
1098         if (can_activate_window( hwndTo )) goto done;
1099     }
1100
1101     hwndTo = hwnd;
1102     for (;;)
1103     {
1104         if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1105         if (can_activate_window( hwndTo )) break;
1106     }
1107
1108  done:
1109     fg = GetForegroundWindow();
1110     TRACE("win = %p fg = %p\n", hwndTo, fg);
1111     if (!fg || (hwnd == fg))
1112     {
1113         if (SetForegroundWindow( hwndTo )) return;
1114     }
1115     if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1116 }
1117
1118
1119 /***********************************************************************
1120  *           WINPOS_HandleWindowPosChanging
1121  *
1122  * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1123  */
1124 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1125 {
1126     POINT minTrack, maxTrack;
1127     LONG style = GetWindowLongW( hwnd, GWL_STYLE );
1128
1129     if (winpos->flags & SWP_NOSIZE) return 0;
1130     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1131     {
1132         WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1133         if (winpos->cx > maxTrack.x) winpos->cx = maxTrack.x;
1134         if (winpos->cy > maxTrack.y) winpos->cy = maxTrack.y;
1135         if (!(style & WS_MINIMIZE))
1136         {
1137             if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1138             if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1139         }
1140     }
1141     return 0;
1142 }
1143
1144
1145 /***********************************************************************
1146  *           dump_winpos_flags
1147  */
1148 static void dump_winpos_flags(UINT flags)
1149 {
1150     TRACE("flags:");
1151     if(flags & SWP_NOSIZE) TRACE(" SWP_NOSIZE");
1152     if(flags & SWP_NOMOVE) TRACE(" SWP_NOMOVE");
1153     if(flags & SWP_NOZORDER) TRACE(" SWP_NOZORDER");
1154     if(flags & SWP_NOREDRAW) TRACE(" SWP_NOREDRAW");
1155     if(flags & SWP_NOACTIVATE) TRACE(" SWP_NOACTIVATE");
1156     if(flags & SWP_FRAMECHANGED) TRACE(" SWP_FRAMECHANGED");
1157     if(flags & SWP_SHOWWINDOW) TRACE(" SWP_SHOWWINDOW");
1158     if(flags & SWP_HIDEWINDOW) TRACE(" SWP_HIDEWINDOW");
1159     if(flags & SWP_NOCOPYBITS) TRACE(" SWP_NOCOPYBITS");
1160     if(flags & SWP_NOOWNERZORDER) TRACE(" SWP_NOOWNERZORDER");
1161     if(flags & SWP_NOSENDCHANGING) TRACE(" SWP_NOSENDCHANGING");
1162     if(flags & SWP_DEFERERASE) TRACE(" SWP_DEFERERASE");
1163     if(flags & SWP_ASYNCWINDOWPOS) TRACE(" SWP_ASYNCWINDOWPOS");
1164
1165 #define DUMPED_FLAGS \
1166     (SWP_NOSIZE | \
1167     SWP_NOMOVE | \
1168     SWP_NOZORDER | \
1169     SWP_NOREDRAW | \
1170     SWP_NOACTIVATE | \
1171     SWP_FRAMECHANGED | \
1172     SWP_SHOWWINDOW | \
1173     SWP_HIDEWINDOW | \
1174     SWP_NOCOPYBITS | \
1175     SWP_NOOWNERZORDER | \
1176     SWP_NOSENDCHANGING | \
1177     SWP_DEFERERASE | \
1178     SWP_ASYNCWINDOWPOS)
1179
1180     if(flags & ~DUMPED_FLAGS) TRACE(" %08x", flags & ~DUMPED_FLAGS);
1181     TRACE("\n");
1182 #undef DUMPED_FLAGS
1183 }
1184
1185 /***********************************************************************
1186  *              SetWindowPos (USER32.@)
1187  */
1188 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1189                           INT x, INT y, INT cx, INT cy, UINT flags )
1190 {
1191     WINDOWPOS winpos;
1192
1193     TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1194           hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1195     if(TRACE_ON(win)) dump_winpos_flags(flags);
1196
1197     if (is_broadcast(hwnd))
1198     {
1199         SetLastError( ERROR_INVALID_PARAMETER );
1200         return FALSE;
1201     }
1202
1203     winpos.hwnd = WIN_GetFullHandle(hwnd);
1204     winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1205     winpos.x = x;
1206     winpos.y = y;
1207     winpos.cx = cx;
1208     winpos.cy = cy;
1209     winpos.flags = flags;
1210     if (WIN_IsCurrentThread( hwnd ))
1211     {
1212         if (USER_Driver.pSetWindowPos)
1213             return USER_Driver.pSetWindowPos( &winpos );
1214         return FALSE;
1215     }
1216     return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1217 }
1218
1219
1220 /***********************************************************************
1221  *              BeginDeferWindowPos (USER32.@)
1222  */
1223 HDWP WINAPI BeginDeferWindowPos( INT count )
1224 {
1225     HDWP handle;
1226     DWP *pDWP;
1227
1228     TRACE("%d\n", count);
1229
1230     if (count < 0)
1231     {
1232         SetLastError(ERROR_INVALID_PARAMETER);
1233         return 0;
1234     }
1235     /* Windows allows zero count, in which case it allocates context for 8 moves */
1236     if (count == 0) count = 8;
1237
1238     handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1239     if (!handle) return 0;
1240     pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1241     pDWP->actualCount    = 0;
1242     pDWP->suggestedCount = count;
1243     pDWP->valid          = TRUE;
1244     pDWP->wMagic         = DWP_MAGIC;
1245     pDWP->hwndParent     = 0;
1246
1247     TRACE("returning hdwp %p\n", handle);
1248     return handle;
1249 }
1250
1251
1252 /***********************************************************************
1253  *              DeferWindowPos (USER32.@)
1254  */
1255 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1256                                 INT x, INT y, INT cx, INT cy,
1257                                 UINT flags )
1258 {
1259     DWP *pDWP;
1260     int i;
1261     HDWP newhdwp = hdwp,retvalue;
1262
1263     TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1264           hdwp, hwnd, hwndAfter, x, y, cx, cy, flags);
1265
1266     hwnd = WIN_GetFullHandle( hwnd );
1267     if (hwnd == GetDesktopWindow()) return 0;
1268
1269     if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1270
1271     USER_Lock();
1272
1273     for (i = 0; i < pDWP->actualCount; i++)
1274     {
1275         if (pDWP->winPos[i].hwnd == hwnd)
1276         {
1277               /* Merge with the other changes */
1278             if (!(flags & SWP_NOZORDER))
1279             {
1280                 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1281             }
1282             if (!(flags & SWP_NOMOVE))
1283             {
1284                 pDWP->winPos[i].x = x;
1285                 pDWP->winPos[i].y = y;
1286             }
1287             if (!(flags & SWP_NOSIZE))
1288             {
1289                 pDWP->winPos[i].cx = cx;
1290                 pDWP->winPos[i].cy = cy;
1291             }
1292             pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1293                                                SWP_NOZORDER | SWP_NOREDRAW |
1294                                                SWP_NOACTIVATE | SWP_NOCOPYBITS|
1295                                                SWP_NOOWNERZORDER);
1296             pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1297                                               SWP_FRAMECHANGED);
1298             retvalue = hdwp;
1299             goto END;
1300         }
1301     }
1302     if (pDWP->actualCount >= pDWP->suggestedCount)
1303     {
1304         newhdwp = USER_HEAP_REALLOC( hdwp,
1305                       sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1306         if (!newhdwp)
1307         {
1308             retvalue = 0;
1309             goto END;
1310         }
1311         pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1312         pDWP->suggestedCount++;
1313     }
1314     pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1315     pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1316     pDWP->winPos[pDWP->actualCount].x = x;
1317     pDWP->winPos[pDWP->actualCount].y = y;
1318     pDWP->winPos[pDWP->actualCount].cx = cx;
1319     pDWP->winPos[pDWP->actualCount].cy = cy;
1320     pDWP->winPos[pDWP->actualCount].flags = flags;
1321     pDWP->actualCount++;
1322     retvalue = newhdwp;
1323 END:
1324     USER_Unlock();
1325     return retvalue;
1326 }
1327
1328
1329 /***********************************************************************
1330  *              EndDeferWindowPos (USER32.@)
1331  */
1332 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1333 {
1334     DWP *pDWP;
1335     WINDOWPOS *winpos;
1336     BOOL res = TRUE;
1337     int i;
1338
1339     TRACE("%p\n", hdwp);
1340
1341     pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1342     if (!pDWP) return FALSE;
1343     for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1344     {
1345         if (!USER_Driver.pSetWindowPos || !(res = USER_Driver.pSetWindowPos( winpos ))) break;
1346     }
1347     USER_HEAP_FREE( hdwp );
1348     return res;
1349 }
1350
1351
1352 /***********************************************************************
1353  *              TileChildWindows (USER.199)
1354  */
1355 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1356 {
1357     FIXME("(%04x, %d): stub\n", parent, action);
1358 }
1359
1360 /***********************************************************************
1361  *              CascadeChildWindows (USER.198)
1362  */
1363 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1364 {
1365     FIXME("(%04x, %d): stub\n", parent, action);
1366 }