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