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