Release 980201
[wine.git] / windows / winpos.c
blob1c1bdd4142e6aa0028a7ba507a9c6027bfb8dcb1
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996 Alex Korobka
6 */
8 #include "ts_xlib.h"
9 #include "ts_xutil.h"
10 #include <X11/Xatom.h>
11 #include "sysmetrics.h"
12 #include "heap.h"
13 #include "module.h"
14 #include "user.h"
15 #include "win.h"
16 #include "hook.h"
17 #include "message.h"
18 #include "queue.h"
19 #include "options.h"
20 #include "winpos.h"
21 #include "dce.h"
22 #include "nonclient.h"
23 #include "stddebug.h"
24 /* #define DEBUG_WIN */
25 #include "debug.h"
27 #define HAS_DLGFRAME(style,exStyle) \
28 (((exStyle) & WS_EX_DLGMODALFRAME) || \
29 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
31 #define HAS_THICKFRAME(style) \
32 (((style) & WS_THICKFRAME) && \
33 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
35 #define SWP_AGG_NOGEOMETRYCHANGE \
36 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
37 #define SWP_AGG_NOPOSCHANGE \
38 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
39 #define SWP_AGG_STATUSFLAGS \
40 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
42 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
44 #define PLACE_MIN 0x0001
45 #define PLACE_MAX 0x0002
46 #define PLACE_RECT 0x0004
48 #define SMC_NOCOPY 0x0001
49 #define SMC_NOPARENTERASE 0x0002
50 #define SMC_DRAWFRAME 0x0004
51 #define SMC_SETXPOS 0x0008
53 /* ----- external functions ----- */
55 extern void FOCUS_SwitchFocus( HWND32 , HWND32 );
56 extern HWND32 CARET_GetHwnd();
58 /* ----- internal variables ----- */
60 static HWND32 hwndActive = 0; /* Currently active window */
61 static HWND32 hwndPrevActive = 0; /* Previously active window */
63 static LPCSTR atomInternalPos;
65 extern MESSAGEQUEUE* pActiveQueue;
67 /***********************************************************************
68 * WINPOS_CreateInternalPosAtom
70 BOOL32 WINPOS_CreateInternalPosAtom()
72 LPSTR str = "SysIP";
73 atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtom32A(str);
74 return (atomInternalPos) ? TRUE : FALSE;
77 /***********************************************************************
78 * WINPOS_CheckInternalPos
80 * Called when a window is destroyed.
82 void WINPOS_CheckInternalPos( HWND32 hwnd )
84 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetProp32A( hwnd, atomInternalPos );
86 if( hwnd == hwndPrevActive ) hwndPrevActive = 0;
87 if( hwnd == hwndActive )
89 hwndActive = 0;
90 dprintf_win(stddeb,"\tattempt to activate destroyed window!\n");
93 if( lpPos )
95 if( IsWindow32(lpPos->hwndIconTitle) )
96 DestroyWindow32( lpPos->hwndIconTitle );
97 HeapFree( SystemHeap, 0, lpPos );
101 /***********************************************************************
102 * WINPOS_FindIconPos
104 * Find a suitable place for an iconic window.
106 static POINT16 WINPOS_FindIconPos( WND* wndPtr, POINT16 pt )
108 RECT16 rectParent;
109 short x, y, xspacing, yspacing;
111 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
112 if ((pt.x >= rectParent.left) && (pt.x + SYSMETRICS_CXICON < rectParent.right) &&
113 (pt.y >= rectParent.top) && (pt.y + SYSMETRICS_CYICON < rectParent.bottom))
114 return pt; /* The icon already has a suitable position */
116 xspacing = SYSMETRICS_CXICONSPACING;
117 yspacing = SYSMETRICS_CYICONSPACING;
119 y = rectParent.bottom;
120 for (;;)
122 for (x = rectParent.left; x <= rectParent.right-xspacing; x += xspacing)
124 /* Check if another icon already occupies this spot */
125 WND *childPtr = wndPtr->parent->child;
126 while (childPtr)
128 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
130 if ((childPtr->rectWindow.left < x + xspacing) &&
131 (childPtr->rectWindow.right >= x) &&
132 (childPtr->rectWindow.top <= y) &&
133 (childPtr->rectWindow.bottom > y - yspacing))
134 break; /* There's a window in there */
136 childPtr = childPtr->next;
138 if (!childPtr) /* No window was found, so it's OK for us */
140 pt.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
141 pt.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
142 return pt;
145 y -= yspacing;
150 /***********************************************************************
151 * ArrangeIconicWindows16 (USER.170)
153 UINT16 WINAPI ArrangeIconicWindows16( HWND16 parent)
155 return ArrangeIconicWindows32(parent);
157 /***********************************************************************
158 * ArrangeIconicWindows32 (USER32.6)
160 UINT32 WINAPI ArrangeIconicWindows32( HWND32 parent )
162 RECT32 rectParent;
163 HWND32 hwndChild;
164 INT32 x, y, xspacing, yspacing;
166 GetClientRect32( parent, &rectParent );
167 x = rectParent.left;
168 y = rectParent.bottom;
169 xspacing = SYSMETRICS_CXICONSPACING;
170 yspacing = SYSMETRICS_CYICONSPACING;
172 hwndChild = GetWindow32( parent, GW_CHILD );
173 while (hwndChild)
175 if( IsIconic32( hwndChild ) )
177 WINPOS_ShowIconTitle( WIN_FindWndPtr(hwndChild), FALSE );
178 SetWindowPos32( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
179 y - yspacing - SYSMETRICS_CYICON/2, 0, 0,
180 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
181 if( IsWindow32(hwndChild) )
182 WINPOS_ShowIconTitle( WIN_FindWndPtr(hwndChild), TRUE );
183 if (x <= rectParent.right - xspacing) x += xspacing;
184 else
186 x = rectParent.left;
187 y -= yspacing;
190 hwndChild = GetWindow32( hwndChild, GW_HWNDNEXT );
192 return yspacing;
196 /***********************************************************************
197 * SwitchToThisWindow16 (USER.172)
199 void WINAPI SwitchToThisWindow16( HWND16 hwnd, BOOL16 restore )
201 SwitchToThisWindow32( hwnd, restore );
205 /***********************************************************************
206 * SwitchToThisWindow32 (USER32.538)
208 void WINAPI SwitchToThisWindow32( HWND32 hwnd, BOOL32 restore )
210 ShowWindow32( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
214 /***********************************************************************
215 * GetWindowRect16 (USER.32)
217 void WINAPI GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
219 WND * wndPtr = WIN_FindWndPtr( hwnd );
220 if (!wndPtr) return;
222 CONV_RECT32TO16( &wndPtr->rectWindow, rect );
223 if (wndPtr->dwStyle & WS_CHILD)
224 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
228 /***********************************************************************
229 * GetWindowRect32 (USER32.308)
231 void WINAPI GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
233 WND * wndPtr = WIN_FindWndPtr( hwnd );
234 if (!wndPtr) return;
236 *rect = wndPtr->rectWindow;
237 if (wndPtr->dwStyle & WS_CHILD)
238 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
242 /***********************************************************************
243 * GetClientRect16 (USER.33)
245 void WINAPI GetClientRect16( HWND16 hwnd, LPRECT16 rect )
247 WND * wndPtr = WIN_FindWndPtr( hwnd );
249 rect->left = rect->top = rect->right = rect->bottom = 0;
250 if (wndPtr)
252 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
253 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
258 /***********************************************************************
259 * GetClientRect32 (USER32.219)
261 void WINAPI GetClientRect32( HWND32 hwnd, LPRECT32 rect )
263 WND * wndPtr = WIN_FindWndPtr( hwnd );
265 rect->left = rect->top = rect->right = rect->bottom = 0;
266 if (wndPtr)
268 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
269 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
274 /*******************************************************************
275 * ClientToScreen16 (USER.28)
277 void WINAPI ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
279 MapWindowPoints16( hwnd, 0, lppnt, 1 );
283 /*******************************************************************
284 * ClientToScreen32 (USER32.51)
286 BOOL32 WINAPI ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
288 MapWindowPoints32( hwnd, 0, lppnt, 1 );
289 return TRUE;
293 /*******************************************************************
294 * ScreenToClient16 (USER.29)
296 void WINAPI ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
298 MapWindowPoints16( 0, hwnd, lppnt, 1 );
302 /*******************************************************************
303 * ScreenToClient32 (USER32.446)
305 void WINAPI ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
307 MapWindowPoints32( 0, hwnd, lppnt, 1 );
311 /***********************************************************************
312 * WINPOS_WindowFromPoint
314 * Find the window and hittest for a given point.
316 INT16 WINPOS_WindowFromPoint( WND* wndScope, POINT16 pt, WND **ppWnd )
318 WND *wndPtr;
319 INT16 hittest = HTERROR;
320 POINT16 xy = pt;
322 *ppWnd = NULL;
323 wndPtr = wndScope->child;
324 MapWindowPoints16( GetDesktopWindow16(), wndScope->hwndSelf, &xy, 1 );
326 for (;;)
328 while (wndPtr)
330 /* If point is in window, and window is visible, and it */
331 /* is enabled (or it's a top-level window), then explore */
332 /* its children. Otherwise, go to the next window. */
334 if ((wndPtr->dwStyle & WS_VISIBLE) &&
335 (!(wndPtr->dwStyle & WS_DISABLED) ||
336 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
337 (xy.x >= wndPtr->rectWindow.left) &&
338 (xy.x < wndPtr->rectWindow.right) &&
339 (xy.y >= wndPtr->rectWindow.top) &&
340 (xy.y < wndPtr->rectWindow.bottom))
342 *ppWnd = wndPtr; /* Got a suitable window */
344 /* If window is minimized or disabled, return at once */
345 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
346 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
348 /* If point is not in client area, ignore the children */
349 if ((xy.x < wndPtr->rectClient.left) ||
350 (xy.x >= wndPtr->rectClient.right) ||
351 (xy.y < wndPtr->rectClient.top) ||
352 (xy.y >= wndPtr->rectClient.bottom)) break;
354 xy.x -= wndPtr->rectClient.left;
355 xy.y -= wndPtr->rectClient.top;
356 wndPtr = wndPtr->child;
358 else wndPtr = wndPtr->next;
361 /* If nothing found, try the scope window */
362 if (!*ppWnd) *ppWnd = wndScope;
364 /* Send the WM_NCHITTEST message (only if to the same task) */
365 if ((*ppWnd)->hmemTaskQ == GetTaskQueue(0))
367 hittest = (INT16)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST,
368 0, MAKELONG( pt.x, pt.y ) );
369 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
371 else return HTCLIENT;
373 /* If no children found in last search, make point relative to parent */
374 if (!wndPtr)
376 xy.x += (*ppWnd)->rectClient.left;
377 xy.y += (*ppWnd)->rectClient.top;
380 /* Restart the search from the next sibling */
381 wndPtr = (*ppWnd)->next;
382 *ppWnd = (*ppWnd)->parent;
387 /*******************************************************************
388 * WindowFromPoint16 (USER.30)
390 HWND16 WINAPI WindowFromPoint16( POINT16 pt )
392 WND *pWnd;
393 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt, &pWnd );
394 return pWnd->hwndSelf;
398 /*******************************************************************
399 * WindowFromPoint32 (USER32.581)
401 HWND32 WINAPI WindowFromPoint32( POINT32 pt )
403 WND *pWnd;
404 POINT16 pt16;
405 CONV_POINT32TO16( &pt, &pt16 );
406 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt16, &pWnd );
407 return (HWND32)pWnd->hwndSelf;
411 /*******************************************************************
412 * ChildWindowFromPoint16 (USER.191)
414 HWND16 WINAPI ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
416 POINT32 pt32;
417 CONV_POINT16TO32( &pt, &pt32 );
418 return (HWND16)ChildWindowFromPoint32( hwndParent, pt32 );
422 /*******************************************************************
423 * ChildWindowFromPoint32 (USER32.48)
425 HWND32 WINAPI ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
427 /* pt is in the client coordinates */
429 WND* wnd = WIN_FindWndPtr(hwndParent);
430 RECT32 rect;
432 if( !wnd ) return 0;
434 /* get client rect fast */
435 rect.top = rect.left = 0;
436 rect.right = wnd->rectClient.right - wnd->rectClient.left;
437 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
439 if (!PtInRect32( &rect, pt )) return 0;
441 wnd = wnd->child;
442 while ( wnd )
444 if (PtInRect32( &wnd->rectWindow, pt )) return wnd->hwndSelf;
445 wnd = wnd->next;
447 return hwndParent;
451 /*******************************************************************
452 * WINPOS_GetWinOffset
454 * Calculate the offset between the origin of the two windows. Used
455 * to implement MapWindowPoints.
457 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
458 POINT32 *offset )
460 WND * wndPtr;
462 offset->x = offset->y = 0;
463 if (hwndFrom == hwndTo ) return;
465 /* Translate source window origin to screen coords */
466 if (hwndFrom)
468 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
470 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
471 return;
473 while (wndPtr->parent)
475 offset->x += wndPtr->rectClient.left;
476 offset->y += wndPtr->rectClient.top;
477 wndPtr = wndPtr->parent;
481 /* Translate origin to destination window coords */
482 if (hwndTo)
484 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
486 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
487 return;
489 while (wndPtr->parent)
491 offset->x -= wndPtr->rectClient.left;
492 offset->y -= wndPtr->rectClient.top;
493 wndPtr = wndPtr->parent;
499 /*******************************************************************
500 * MapWindowPoints16 (USER.258)
502 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
503 LPPOINT16 lppt, UINT16 count )
505 POINT32 offset;
507 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
508 while (count--)
510 lppt->x += offset.x;
511 lppt->y += offset.y;
512 lppt++;
517 /*******************************************************************
518 * MapWindowPoints32 (USER32.385)
520 void WINAPI MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
521 LPPOINT32 lppt, UINT32 count )
523 POINT32 offset;
525 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
526 while (count--)
528 lppt->x += offset.x;
529 lppt->y += offset.y;
530 lppt++;
535 /***********************************************************************
536 * IsIconic16 (USER.31)
538 BOOL16 WINAPI IsIconic16(HWND16 hWnd)
540 return IsIconic32(hWnd);
544 /***********************************************************************
545 * IsIconic32 (USER32.344)
547 BOOL32 WINAPI IsIconic32(HWND32 hWnd)
549 WND * wndPtr = WIN_FindWndPtr(hWnd);
550 if (wndPtr == NULL) return FALSE;
551 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
555 /***********************************************************************
556 * IsZoomed (USER.272)
558 BOOL16 WINAPI IsZoomed16(HWND16 hWnd)
560 return IsZoomed32(hWnd);
564 /***********************************************************************
565 * IsZoomed (USER32.351)
567 BOOL32 WINAPI IsZoomed32(HWND32 hWnd)
569 WND * wndPtr = WIN_FindWndPtr(hWnd);
570 if (wndPtr == NULL) return FALSE;
571 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
575 /*******************************************************************
576 * GetActiveWindow (USER.60)
578 HWND16 WINAPI GetActiveWindow16(void)
580 return (HWND16)hwndActive;
583 /*******************************************************************
584 * GetActiveWindow (USER32.204)
586 HWND32 WINAPI GetActiveWindow32(void)
588 return (HWND32)hwndActive;
592 /*******************************************************************
593 * WINPOS_CanActivate
595 static BOOL32 WINPOS_CanActivate(WND* pWnd)
597 if( pWnd && ((pWnd->dwStyle & (WS_DISABLED | WS_VISIBLE | WS_CHILD))
598 == WS_VISIBLE) ) return TRUE;
599 return FALSE;
603 /*******************************************************************
604 * SetActiveWindow16 (USER.59)
606 HWND16 WINAPI SetActiveWindow16( HWND16 hwnd )
608 return SetActiveWindow32(hwnd);
612 /*******************************************************************
613 * SetActiveWindow32 (USER32.462)
615 HWND32 WINAPI SetActiveWindow32( HWND32 hwnd )
617 HWND32 prev = hwndActive;
618 WND *wndPtr = WIN_FindWndPtr( hwnd );
620 if ( !WINPOS_CanActivate(wndPtr) ) return 0;
622 WINPOS_SetActiveWindow( hwnd, 0, 0 );
623 return prev;
627 /*******************************************************************
628 * GetForegroundWindow16 (USER.608)
630 HWND16 WINAPI GetForegroundWindow16(void)
632 return (HWND16)GetForegroundWindow32();
636 /*******************************************************************
637 * SetForegroundWindow16 (USER.609)
639 BOOL16 WINAPI SetForegroundWindow16( HWND16 hwnd )
641 return SetForegroundWindow32( hwnd );
645 /*******************************************************************
646 * GetForegroundWindow32 (USER32.241)
648 HWND32 WINAPI GetForegroundWindow32(void)
650 return GetActiveWindow32();
654 /*******************************************************************
655 * SetForegroundWindow32 (USER32.482)
657 BOOL32 WINAPI SetForegroundWindow32( HWND32 hwnd )
659 SetActiveWindow32( hwnd );
660 return TRUE;
664 /*******************************************************************
665 * GetShellWindow16 (USER.600)
667 HWND16 WINAPI GetShellWindow16(void)
669 return GetShellWindow32();
672 /*******************************************************************
673 * SetShellWindow32 (USER32.287)
675 HWND32 WINAPI SetShellWindow32(HWND32 hwndshell)
677 fprintf( stdnimp, "SetShellWindow(%08x): empty stub\n",hwndshell );
678 return 0;
682 /*******************************************************************
683 * GetShellWindow32 (USER32.287)
685 HWND32 WINAPI GetShellWindow32(void)
687 fprintf( stdnimp, "GetShellWindow: empty stub\n" );
688 return 0;
692 /***********************************************************************
693 * BringWindowToTop16 (USER.45)
695 BOOL16 WINAPI BringWindowToTop16( HWND16 hwnd )
697 return BringWindowToTop32(hwnd);
701 /***********************************************************************
702 * BringWindowToTop32 (USER32.10)
704 BOOL32 WINAPI BringWindowToTop32( HWND32 hwnd )
706 return SetWindowPos32( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
710 /***********************************************************************
711 * MoveWindow16 (USER.56)
713 BOOL16 WINAPI MoveWindow16( HWND16 hwnd, INT16 x, INT16 y, INT16 cx, INT16 cy,
714 BOOL16 repaint )
716 return MoveWindow32(hwnd,x,y,cx,cy,repaint);
720 /***********************************************************************
721 * MoveWindow32 (USER32.398)
723 BOOL32 WINAPI MoveWindow32( HWND32 hwnd, INT32 x, INT32 y, INT32 cx, INT32 cy,
724 BOOL32 repaint )
726 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
727 if (!repaint) flags |= SWP_NOREDRAW;
728 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
729 hwnd, x, y, cx, cy, repaint );
730 return SetWindowPos32( hwnd, 0, x, y, cx, cy, flags );
733 /***********************************************************************
734 * WINPOS_InitInternalPos
736 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT32 pt,
737 LPRECT32 restoreRect )
739 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetProp32A( wnd->hwndSelf,
740 atomInternalPos );
741 if( !lpPos )
743 /* this happens when the window is minimized/maximized
744 * for the first time (rectWindow is not adjusted yet) */
746 lpPos = HeapAlloc( SystemHeap, 0, sizeof(INTERNALPOS) );
747 if( !lpPos ) return NULL;
749 SetProp32A( wnd->hwndSelf, atomInternalPos, (HANDLE32)lpPos );
750 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
751 CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
752 *(UINT32*)&lpPos->ptIconPos = *(UINT32*)&lpPos->ptMaxPos = 0xFFFFFFFF;
755 if( wnd->dwStyle & WS_MINIMIZE )
756 CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
757 else if( wnd->dwStyle & WS_MAXIMIZE )
758 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
759 else if( restoreRect )
760 CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
762 return lpPos;
765 /***********************************************************************
766 * WINPOS_RedrawIconTitle
768 BOOL32 WINPOS_RedrawIconTitle( HWND32 hWnd )
770 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetProp32A( hWnd, atomInternalPos );
771 if( lpPos )
773 if( lpPos->hwndIconTitle )
775 SendMessage32A( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
776 InvalidateRect32( lpPos->hwndIconTitle, NULL, TRUE );
777 return TRUE;
780 return FALSE;
783 /***********************************************************************
784 * WINPOS_ShowIconTitle
786 BOOL32 WINPOS_ShowIconTitle( WND* pWnd, BOOL32 bShow )
788 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetProp32A( pWnd->hwndSelf, atomInternalPos );
790 if( lpPos && !(pWnd->flags & WIN_MANAGED))
792 HWND16 hWnd = lpPos->hwndIconTitle;
794 dprintf_win(stddeb,"ShowIconTitle: 0x%04x %i\n", pWnd->hwndSelf, (bShow != 0) );
796 if( !hWnd )
797 lpPos->hwndIconTitle = hWnd = ICONTITLE_Create( pWnd );
798 if( bShow )
800 pWnd = WIN_FindWndPtr(hWnd);
802 if( !(pWnd->dwStyle & WS_VISIBLE) )
804 SendMessage32A( hWnd, WM_SHOWWINDOW, TRUE, 0 );
805 SetWindowPos32( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
806 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
809 else ShowWindow32( hWnd, SW_HIDE );
811 return FALSE;
814 /*******************************************************************
815 * WINPOS_GetMinMaxInfo
817 * Get the minimized and maximized information for a window.
819 void WINPOS_GetMinMaxInfo( WND *wndPtr, POINT32 *maxSize, POINT32 *maxPos,
820 POINT32 *minTrack, POINT32 *maxTrack )
822 LPINTERNALPOS lpPos;
823 MINMAXINFO32 MinMax;
824 INT32 xinc, yinc;
826 /* Compute default values */
828 MinMax.ptMaxSize.x = SYSMETRICS_CXSCREEN;
829 MinMax.ptMaxSize.y = SYSMETRICS_CYSCREEN;
830 MinMax.ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
831 MinMax.ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
832 MinMax.ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
833 MinMax.ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
835 if (wndPtr->flags & WIN_MANAGED) xinc = yinc = 0;
836 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
838 xinc = SYSMETRICS_CXDLGFRAME;
839 yinc = SYSMETRICS_CYDLGFRAME;
841 else
843 xinc = yinc = 0;
844 if (HAS_THICKFRAME(wndPtr->dwStyle))
846 xinc += SYSMETRICS_CXFRAME;
847 yinc += SYSMETRICS_CYFRAME;
849 if (wndPtr->dwStyle & WS_BORDER)
851 xinc += SYSMETRICS_CXBORDER;
852 yinc += SYSMETRICS_CYBORDER;
855 MinMax.ptMaxSize.x += 2 * xinc;
856 MinMax.ptMaxSize.y += 2 * yinc;
858 lpPos = (LPINTERNALPOS)GetProp32A( wndPtr->hwndSelf, atomInternalPos );
859 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
860 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
861 else
863 MinMax.ptMaxPosition.x = -xinc;
864 MinMax.ptMaxPosition.y = -yinc;
867 SendMessage32A( wndPtr->hwndSelf, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
869 /* Some sanity checks */
871 dprintf_win(stddeb,"GetMinMaxInfo: %d %d / %d %d / %d %d / %d %d\n",
872 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
873 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
874 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
875 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
876 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
877 MinMax.ptMinTrackSize.x );
878 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
879 MinMax.ptMinTrackSize.y );
881 if (maxSize) *maxSize = MinMax.ptMaxSize;
882 if (maxPos) *maxPos = MinMax.ptMaxPosition;
883 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
884 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
887 /***********************************************************************
888 * WINPOS_MinMaximize
890 * Fill in lpRect and return additional flags to be used with SetWindowPos().
891 * This function assumes that 'cmd' is different from the current window
892 * state.
894 UINT16 WINPOS_MinMaximize( WND* wndPtr, UINT16 cmd, LPRECT16 lpRect )
896 UINT16 swpFlags = 0;
897 POINT32 pt;
898 POINT32 size = { wndPtr->rectWindow.left, wndPtr->rectWindow.top };
899 LPINTERNALPOS lpPos = WINPOS_InitInternalPos( wndPtr, size,
900 &wndPtr->rectWindow );
902 dprintf_win(stddeb,"MinMaximize: 0x%04x %u\n", wndPtr->hwndSelf, cmd );
904 if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, wndPtr->hwndSelf, cmd))
906 if( wndPtr->dwStyle & WS_MINIMIZE )
908 if( !SendMessage32A( wndPtr->hwndSelf, WM_QUERYOPEN, 0, 0L ) )
909 return (SWP_NOSIZE | SWP_NOMOVE);
910 swpFlags |= SWP_NOCOPYBITS;
912 switch( cmd )
914 case SW_MINIMIZE:
915 if( wndPtr->dwStyle & WS_MAXIMIZE)
917 wndPtr->flags |= WIN_RESTORE_MAX;
918 wndPtr->dwStyle &= ~WS_MAXIMIZE;
920 else
921 wndPtr->flags &= ~WIN_RESTORE_MAX;
922 wndPtr->dwStyle |= WS_MINIMIZE;
924 lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
926 SetRect16( lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
927 SYSMETRICS_CXICON, SYSMETRICS_CYICON );
928 swpFlags |= SWP_NOCOPYBITS;
929 break;
931 case SW_MAXIMIZE:
932 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
933 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
934 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
936 if( wndPtr->dwStyle & WS_MINIMIZE )
938 WINPOS_ShowIconTitle( wndPtr, FALSE );
939 wndPtr->dwStyle &= ~WS_MINIMIZE;
941 wndPtr->dwStyle |= WS_MAXIMIZE;
943 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
944 size.x, size.y );
945 break;
947 case SW_RESTORE:
948 if( wndPtr->dwStyle & WS_MINIMIZE )
950 wndPtr->dwStyle &= ~WS_MINIMIZE;
951 WINPOS_ShowIconTitle( wndPtr, FALSE );
952 if( wndPtr->flags & WIN_RESTORE_MAX)
954 /* Restore to maximized position */
955 CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
956 WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
957 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
958 wndPtr->dwStyle |= WS_MAXIMIZE;
959 SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
960 break;
963 else
964 if( !(wndPtr->dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
965 else wndPtr->dwStyle &= ~WS_MAXIMIZE;
967 /* Restore to normal position */
969 *lpRect = lpPos->rectNormal;
970 lpRect->right -= lpRect->left;
971 lpRect->bottom -= lpRect->top;
973 break;
975 } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
976 return swpFlags;
979 /***********************************************************************
980 * ShowWindow16 (USER.42)
982 BOOL16 WINAPI ShowWindow16( HWND16 hwnd, INT16 cmd )
984 return ShowWindow32(hwnd,cmd);
988 /***********************************************************************
989 * ShowWindow32 (USER.42)
991 BOOL32 WINAPI ShowWindow32( HWND32 hwnd, INT32 cmd )
993 WND* wndPtr = WIN_FindWndPtr( hwnd );
994 BOOL32 wasVisible, showFlag;
995 RECT16 newPos = {0, 0, 0, 0};
996 int swp = 0;
998 if (!wndPtr) return FALSE;
1000 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
1002 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1004 switch(cmd)
1006 case SW_HIDE:
1007 if (!wasVisible) return FALSE;
1008 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1009 SWP_NOACTIVATE | SWP_NOZORDER;
1010 break;
1012 case SW_SHOWMINNOACTIVE:
1013 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1014 /* fall through */
1015 case SW_SHOWMINIMIZED:
1016 swp |= SWP_SHOWWINDOW;
1017 /* fall through */
1018 case SW_MINIMIZE:
1019 swp |= SWP_FRAMECHANGED;
1020 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1021 swp |= WINPOS_MinMaximize( wndPtr, SW_MINIMIZE, &newPos );
1022 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1023 break;
1025 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1026 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1027 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1028 swp |= WINPOS_MinMaximize( wndPtr, SW_MAXIMIZE, &newPos );
1029 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1030 break;
1032 case SW_SHOWNA:
1033 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1034 /* fall through */
1035 case SW_SHOW:
1036 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1037 break;
1039 case SW_SHOWNOACTIVATE:
1040 swp |= SWP_NOZORDER;
1041 if (GetActiveWindow32()) swp |= SWP_NOACTIVATE;
1042 /* fall through */
1043 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1044 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1045 case SW_RESTORE:
1046 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1048 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1049 swp |= WINPOS_MinMaximize( wndPtr, SW_RESTORE, &newPos );
1050 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1051 break;
1054 showFlag = (cmd != SW_HIDE);
1055 if (showFlag != wasVisible)
1057 SendMessage32A( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1058 if (!IsWindow32( hwnd )) return wasVisible;
1061 if ((wndPtr->dwStyle & WS_CHILD) &&
1062 !IsWindowVisible32( wndPtr->parent->hwndSelf ) &&
1063 (swp & (SWP_NOSIZE | SWP_NOMOVE)) == (SWP_NOSIZE | SWP_NOMOVE) )
1065 /* Don't call SetWindowPos32() on invisible child windows */
1066 if (cmd == SW_HIDE) wndPtr->dwStyle &= ~WS_VISIBLE;
1067 else wndPtr->dwStyle |= WS_VISIBLE;
1069 else
1071 /* We can't activate a child window */
1072 if (wndPtr->dwStyle & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1073 SetWindowPos32( hwnd, HWND_TOP,
1074 newPos.left, newPos.top, newPos.right, newPos.bottom, swp );
1075 if (!IsWindow32( hwnd )) return wasVisible;
1076 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( wndPtr, TRUE );
1079 if (wndPtr->flags & WIN_NEED_SIZE)
1081 /* should happen only in CreateWindowEx() */
1082 int wParam = SIZE_RESTORED;
1084 wndPtr->flags &= ~WIN_NEED_SIZE;
1085 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1086 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1087 SendMessage32A( hwnd, WM_SIZE, wParam,
1088 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1089 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1090 SendMessage32A( hwnd, WM_MOVE, 0,
1091 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1094 return wasVisible;
1098 /***********************************************************************
1099 * GetInternalWindowPos16 (USER.460)
1101 UINT16 WINAPI GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd,
1102 LPPOINT16 ptIcon )
1104 WINDOWPLACEMENT16 wndpl;
1105 if (GetWindowPlacement16( hwnd, &wndpl ))
1107 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1108 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1109 return wndpl.showCmd;
1111 return 0;
1115 /***********************************************************************
1116 * GetInternalWindowPos32 (USER32.244)
1118 UINT32 WINAPI GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd,
1119 LPPOINT32 ptIcon )
1121 WINDOWPLACEMENT32 wndpl;
1122 if (GetWindowPlacement32( hwnd, &wndpl ))
1124 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1125 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1126 return wndpl.showCmd;
1128 return 0;
1131 /***********************************************************************
1132 * GetWindowPlacement16 (USER.370)
1134 BOOL16 WINAPI GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
1136 WND *pWnd = WIN_FindWndPtr( hwnd );
1137 if( pWnd )
1139 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
1140 *(LPPOINT32)&pWnd->rectWindow.left, &pWnd->rectWindow );
1141 wndpl->length = sizeof(*wndpl);
1142 if( pWnd->dwStyle & WS_MINIMIZE )
1143 wndpl->showCmd = SW_SHOWMAXIMIZED;
1144 else
1145 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE )
1146 ? SW_SHOWMINIMIZED : SW_SHOWNORMAL ;
1147 if( pWnd->flags & WIN_RESTORE_MAX )
1148 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1149 else
1150 wndpl->flags = 0;
1151 wndpl->ptMinPosition = lpPos->ptIconPos;
1152 wndpl->ptMaxPosition = lpPos->ptMaxPos;
1153 wndpl->rcNormalPosition = lpPos->rectNormal;
1154 return TRUE;
1156 return FALSE;
1160 /***********************************************************************
1161 * GetWindowPlacement32 (USER32.306)
1163 BOOL32 WINAPI GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *pwpl32 )
1165 if( pwpl32 )
1167 WINDOWPLACEMENT16 wpl;
1168 wpl.length = sizeof(wpl);
1169 if( GetWindowPlacement16( hwnd, &wpl ) )
1171 pwpl32->length = sizeof(*pwpl32);
1172 pwpl32->flags = wpl.flags;
1173 pwpl32->showCmd = wpl.showCmd;
1174 CONV_POINT16TO32( &wpl.ptMinPosition, &pwpl32->ptMinPosition );
1175 CONV_POINT16TO32( &wpl.ptMaxPosition, &pwpl32->ptMaxPosition );
1176 CONV_RECT16TO32( &wpl.rcNormalPosition, &pwpl32->rcNormalPosition );
1177 return TRUE;
1180 return FALSE;
1184 /***********************************************************************
1185 * WINPOS_SetPlacement
1187 static BOOL32 WINPOS_SetPlacement( HWND32 hwnd, const WINDOWPLACEMENT16 *wndpl,
1188 UINT32 flags )
1190 WND *pWnd = WIN_FindWndPtr( hwnd );
1191 if( pWnd )
1193 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
1194 *(LPPOINT32)&pWnd->rectWindow.left, &pWnd->rectWindow );
1196 if( flags & PLACE_MIN ) lpPos->ptIconPos = wndpl->ptMinPosition;
1197 if( flags & PLACE_MAX ) lpPos->ptMaxPos = wndpl->ptMaxPosition;
1198 if( flags & PLACE_RECT) lpPos->rectNormal = wndpl->rcNormalPosition;
1200 if( pWnd->dwStyle & WS_MINIMIZE )
1202 WINPOS_ShowIconTitle( pWnd, FALSE );
1203 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
1204 SetWindowPos32( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
1205 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1207 else if( pWnd->dwStyle & WS_MAXIMIZE )
1209 if( !EMPTYPOINT(lpPos->ptMaxPos) )
1210 SetWindowPos32( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
1211 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1213 else if( flags & PLACE_RECT )
1214 SetWindowPos32( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
1215 lpPos->rectNormal.right - lpPos->rectNormal.left,
1216 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
1217 SWP_NOZORDER | SWP_NOACTIVATE );
1219 ShowWindow32( hwnd, wndpl->showCmd );
1220 if( IsWindow32(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
1222 if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd, TRUE );
1224 /* SDK: ...valid only the next time... */
1225 if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
1227 return TRUE;
1229 return FALSE;
1233 /***********************************************************************
1234 * SetWindowPlacement16 (USER.371)
1236 BOOL16 WINAPI SetWindowPlacement16(HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl)
1238 return WINPOS_SetPlacement( hwnd, wndpl,
1239 PLACE_MIN | PLACE_MAX | PLACE_RECT );
1242 /***********************************************************************
1243 * SetWindowPlacement32 (USER32.518)
1245 BOOL32 WINAPI SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *pwpl32 )
1247 if( pwpl32 )
1249 WINDOWPLACEMENT16 wpl = { sizeof(WINDOWPLACEMENT16),
1250 pwpl32->flags, pwpl32->showCmd, { pwpl32->ptMinPosition.x,
1251 pwpl32->ptMinPosition.y }, { pwpl32->ptMaxPosition.x,
1252 pwpl32->ptMaxPosition.y }, { pwpl32->rcNormalPosition.left,
1253 pwpl32->rcNormalPosition.top, pwpl32->rcNormalPosition.right,
1254 pwpl32->rcNormalPosition.bottom } };
1256 return WINPOS_SetPlacement( hwnd, &wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1258 return FALSE;
1262 /***********************************************************************
1263 * SetInternalWindowPos16 (USER.461)
1265 void WINAPI SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
1266 LPRECT16 rect, LPPOINT16 pt )
1268 if( IsWindow16(hwnd) )
1270 WINDOWPLACEMENT16 wndpl;
1271 UINT32 flags;
1273 wndpl.length = sizeof(wndpl);
1274 wndpl.showCmd = showCmd;
1275 wndpl.flags = flags = 0;
1277 if( pt )
1279 flags |= PLACE_MIN;
1280 wndpl.flags |= WPF_SETMINPOSITION;
1281 wndpl.ptMinPosition = *pt;
1283 if( rect )
1285 flags |= PLACE_RECT;
1286 wndpl.rcNormalPosition = *rect;
1288 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1293 /***********************************************************************
1294 * SetInternalWindowPos32 (USER32.482)
1296 void WINAPI SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
1297 LPRECT32 rect, LPPOINT32 pt )
1299 if( IsWindow32(hwnd) )
1301 WINDOWPLACEMENT16 wndpl;
1302 UINT32 flags;
1304 wndpl.length = sizeof(wndpl);
1305 wndpl.showCmd = showCmd;
1306 wndpl.flags = flags = 0;
1308 if( pt )
1310 flags |= PLACE_MIN;
1311 wndpl.flags |= WPF_SETMINPOSITION;
1312 CONV_POINT32TO16( pt, &wndpl.ptMinPosition );
1314 if( rect )
1316 flags |= PLACE_RECT;
1317 CONV_RECT32TO16( rect, &wndpl.rcNormalPosition );
1319 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1324 /***********************************************************************
1325 * WINPOS_ForceXWindowRaise
1327 * Raise a window on top of the X stacking order, while preserving
1328 * the correct Windows Z order.
1330 static void WINPOS_ForceXWindowRaise( WND* pWnd )
1332 XWindowChanges winChanges;
1333 WND *wndPrev;
1335 /* Raise all windows up to pWnd according to their Z order.
1336 * (it would be easier with sibling-related Below but it doesn't
1337 * work very well with SGI mwm for instance)
1339 winChanges.stack_mode = Above;
1340 while (pWnd)
1342 if (pWnd->window) TSXReconfigureWMWindow( display, pWnd->window, 0,
1343 CWStackMode, &winChanges );
1344 wndPrev = WIN_GetDesktop()->child;
1345 if (wndPrev == pWnd) break;
1346 while (wndPrev && (wndPrev->next != pWnd)) wndPrev = wndPrev->next;
1347 pWnd = wndPrev;
1352 /*******************************************************************
1353 * WINPOS_SetActiveWindow
1355 * SetActiveWindow() back-end. This is the only function that
1356 * can assign active status to a window. It must be called only
1357 * for the top level windows.
1359 BOOL32 WINPOS_SetActiveWindow( HWND32 hWnd, BOOL32 fMouse, BOOL32 fChangeFocus)
1361 CBTACTIVATESTRUCT16* cbtStruct;
1362 WND* wndPtr, *wndTemp;
1363 HQUEUE16 hOldActiveQueue, hNewActiveQueue;
1364 WORD wIconized = 0;
1366 /* paranoid checks */
1367 if( hWnd == GetDesktopWindow32() || hWnd == hwndActive ) return 0;
1369 /* if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
1370 * return 0;
1372 wndPtr = WIN_FindWndPtr(hWnd);
1373 hOldActiveQueue = (pActiveQueue)?pActiveQueue->self : 0;
1375 if( (wndTemp = WIN_FindWndPtr(hwndActive)) )
1376 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1377 else
1378 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
1380 /* call CBT hook chain */
1381 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
1383 LRESULT wRet;
1384 cbtStruct->fMouse = fMouse;
1385 cbtStruct->hWndActive = hwndActive;
1386 wRet = HOOK_CallHooks16( WH_CBT, HCBT_ACTIVATE, (WPARAM16)hWnd,
1387 (LPARAM)SEGPTR_GET(cbtStruct) );
1388 SEGPTR_FREE(cbtStruct);
1389 if (wRet) return wRet;
1392 /* set prev active wnd to current active wnd and send notification */
1393 if ((hwndPrevActive = hwndActive) && IsWindow32(hwndPrevActive))
1395 if (!SendMessage32A( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
1397 if (GetSysModalWindow16() != hWnd) return 0;
1398 /* disregard refusal if hWnd is sysmodal */
1401 #if 1
1402 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
1403 MAKEWPARAM( WA_INACTIVE, wIconized ),
1404 (LPARAM)hWnd );
1405 #else
1406 /* FIXME: must be SendMessage16() because 32A doesn't do
1407 * intertask at this time */
1408 SendMessage16( hwndPrevActive, WM_ACTIVATE, WA_INACTIVE,
1409 MAKELPARAM( (HWND16)hWnd, wIconized ) );
1410 #endif
1412 /* check if something happened during message processing */
1413 if( hwndPrevActive != hwndActive ) return 0;
1416 /* set active wnd */
1417 hwndActive = hWnd;
1419 /* send palette messages */
1420 if (hWnd && SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
1421 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM16)hWnd, 0L );
1423 /* if prev wnd is minimized redraw icon title */
1424 if( IsIconic32( hwndPrevActive ) ) WINPOS_RedrawIconTitle(hwndPrevActive);
1426 /* managed windows will get ConfigureNotify event */
1427 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
1429 /* check Z-order and bring hWnd to the top */
1430 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
1431 if (wndTemp->dwStyle & WS_VISIBLE) break;
1433 if( wndTemp != wndPtr )
1434 SetWindowPos32(hWnd, HWND_TOP, 0,0,0,0,
1435 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1436 if (!IsWindow32(hWnd)) return 0;
1439 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
1441 /* send WM_ACTIVATEAPP if necessary */
1442 if (hOldActiveQueue != hNewActiveQueue)
1444 WND **list, **ppWnd;
1446 if ((list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1448 for (ppWnd = list; *ppWnd; ppWnd++)
1450 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
1452 if ((*ppWnd)->hmemTaskQ == hOldActiveQueue)
1453 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
1454 0, QUEUE_GetQueueTask(hNewActiveQueue) );
1456 HeapFree( SystemHeap, 0, list );
1459 pActiveQueue = (hNewActiveQueue)
1460 ? (MESSAGEQUEUE*) GlobalLock16(hNewActiveQueue) : NULL;
1462 if ((list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1464 for (ppWnd = list; *ppWnd; ppWnd++)
1466 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
1468 if ((*ppWnd)->hmemTaskQ == hNewActiveQueue)
1469 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
1470 1, QUEUE_GetQueueTask( hOldActiveQueue ) );
1472 HeapFree( SystemHeap, 0, list );
1474 if (!IsWindow32(hWnd)) return 0;
1477 if (hWnd)
1479 /* walk up to the first unowned window */
1480 wndTemp = wndPtr;
1481 while (wndTemp->owner) wndTemp = wndTemp->owner;
1482 /* and set last active owned popup */
1483 wndTemp->hwndLastActive = hWnd;
1485 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1486 SendMessage32A( hWnd, WM_NCACTIVATE, TRUE, 0 );
1487 #if 1
1488 SendMessage32A( hWnd, WM_ACTIVATE,
1489 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1490 (LPARAM)hwndPrevActive );
1491 #else
1492 SendMessage16(hWnd, WM_ACTIVATE, (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE,
1493 MAKELPARAM( (HWND16)hwndPrevActive, wIconized) );
1494 #endif
1496 if( !IsWindow32(hWnd) ) return 0;
1499 /* change focus if possible */
1500 if( fChangeFocus && GetFocus32() )
1501 if( WIN_GetTopParent(GetFocus32()) != hwndActive )
1502 FOCUS_SwitchFocus( GetFocus32(),
1503 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
1505 if( !hwndPrevActive && wndPtr &&
1506 wndPtr->window && !(wndPtr->flags & WIN_MANAGED) )
1507 WINPOS_ForceXWindowRaise(wndPtr);
1509 /* if active wnd is minimized redraw icon title */
1510 if( IsIconic32(hwndActive) ) WINPOS_RedrawIconTitle(hwndActive);
1512 return (hWnd == hwndActive);
1515 /*******************************************************************
1516 * WINPOS_ActivateOtherWindow
1518 * Activates window other than pWnd.
1520 BOOL32 WINPOS_ActivateOtherWindow(WND* pWnd)
1522 BOOL32 bRet = 0;
1523 WND* pWndTo = NULL;
1525 if( pWnd->hwndSelf == hwndPrevActive )
1526 hwndPrevActive = 0;
1528 if( hwndActive != pWnd->hwndSelf &&
1529 ( hwndActive || QUEUE_IsExitingQueue(pWnd->hmemTaskQ)) )
1530 return 0;
1532 if( !(pWnd->dwStyle & WS_POPUP) || !(pWnd->owner) ||
1533 !WINPOS_CanActivate((pWndTo = WIN_GetTopParentPtr(pWnd->owner))) )
1535 WND* pWndPtr = WIN_GetTopParentPtr(pWnd);
1537 pWndTo = WIN_FindWndPtr(hwndPrevActive);
1539 while( !WINPOS_CanActivate(pWndTo) )
1541 /* by now owned windows should've been taken care of */
1543 pWndTo = pWndPtr->next;
1544 pWndPtr = pWndTo;
1545 if( !pWndTo ) break;
1549 bRet = WINPOS_SetActiveWindow( pWndTo ? pWndTo->hwndSelf : 0, FALSE, TRUE );
1551 /* switch desktop queue to current active */
1552 if( pWndTo ) WIN_GetDesktop()->hmemTaskQ = pWndTo->hmemTaskQ;
1554 hwndPrevActive = 0;
1555 return bRet;
1558 /*******************************************************************
1559 * WINPOS_ChangeActiveWindow
1562 BOOL32 WINPOS_ChangeActiveWindow( HWND32 hWnd, BOOL32 mouseMsg )
1564 WND *wndPtr = WIN_FindWndPtr(hWnd);
1566 if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE );
1568 if( !wndPtr ) return FALSE;
1570 /* child windows get WM_CHILDACTIVATE message */
1571 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1572 return SendMessage32A(hWnd, WM_CHILDACTIVATE, 0, 0L);
1574 /* owned popups imply owner activation - not sure */
1575 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1576 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1578 if (!(wndPtr = wndPtr->owner)) return FALSE;
1579 hWnd = wndPtr->hwndSelf;
1582 if( hWnd == hwndActive ) return FALSE;
1584 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1585 return FALSE;
1587 /* switch desktop queue to current active */
1588 if( wndPtr->parent == WIN_GetDesktop())
1589 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1591 return TRUE;
1595 /***********************************************************************
1596 * WINPOS_SendNCCalcSize
1598 * Send a WM_NCCALCSIZE message to a window.
1599 * All parameters are read-only except newClientRect.
1600 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1601 * when calcValidRect is TRUE.
1603 LONG WINPOS_SendNCCalcSize( HWND32 hwnd, BOOL32 calcValidRect,
1604 RECT32 *newWindowRect, RECT32 *oldWindowRect,
1605 RECT32 *oldClientRect, WINDOWPOS32 *winpos,
1606 RECT32 *newClientRect )
1608 NCCALCSIZE_PARAMS32 params;
1609 LONG result;
1611 params.rgrc[0] = *newWindowRect;
1612 if (calcValidRect)
1614 params.rgrc[1] = *oldWindowRect;
1615 params.rgrc[2] = *oldClientRect;
1616 params.lppos = winpos;
1618 result = SendMessage32A( hwnd, WM_NCCALCSIZE, calcValidRect,
1619 (LPARAM)&params );
1620 dprintf_win( stddeb, "WINPOS_SendNCCalcSize: %d,%d-%d,%d\n",
1621 params.rgrc[0].left, params.rgrc[0].top,
1622 params.rgrc[0].right, params.rgrc[0].bottom );
1623 *newClientRect = params.rgrc[0];
1624 return result;
1628 /***********************************************************************
1629 * WINPOS_HandleWindowPosChanging16
1631 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1633 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1635 POINT32 maxSize, minTrack;
1636 if (winpos->flags & SWP_NOSIZE) return 0;
1637 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1638 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1640 WINPOS_GetMinMaxInfo( wndPtr, &maxSize, NULL, &minTrack, NULL );
1641 if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1642 if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1643 if (!(wndPtr->dwStyle & WS_MINIMIZE))
1645 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1646 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1649 return 0;
1653 /***********************************************************************
1654 * WINPOS_HandleWindowPosChanging32
1656 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1658 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1660 POINT32 maxSize;
1661 if (winpos->flags & SWP_NOSIZE) return 0;
1662 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1663 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1665 WINPOS_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL );
1666 winpos->cx = MIN( winpos->cx, maxSize.x );
1667 winpos->cy = MIN( winpos->cy, maxSize.y );
1669 return 0;
1673 /***********************************************************************
1674 * WINPOS_MoveWindowZOrder
1676 * Move a window in Z order, invalidating everything that needs it.
1677 * Only necessary for windows without associated X window.
1679 static void WINPOS_MoveWindowZOrder( HWND32 hwnd, HWND32 hwndAfter )
1681 BOOL32 movingUp;
1682 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1684 /* We have two possible cases:
1685 * - The window is moving up: we have to invalidate all areas
1686 * of the window that were covered by other windows
1687 * - The window is moving down: we have to invalidate areas
1688 * of other windows covered by this one.
1691 if (hwndAfter == HWND_TOP)
1693 movingUp = TRUE;
1695 else if (hwndAfter == HWND_BOTTOM)
1697 if (!wndPtr->next) return; /* Already at the bottom */
1698 movingUp = FALSE;
1700 else
1702 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1703 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1705 /* Determine which window we encounter first in Z-order */
1706 pWndCur = wndPtr->parent->child;
1707 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1708 pWndCur = pWndCur->next;
1709 movingUp = (pWndCur == pWndAfter);
1712 if (movingUp)
1714 WND *pWndPrevAfter = wndPtr->next;
1715 WIN_UnlinkWindow( hwnd );
1716 WIN_LinkWindow( hwnd, hwndAfter );
1717 pWndCur = wndPtr->next;
1718 while (pWndCur != pWndPrevAfter)
1720 RECT32 rect = { pWndCur->rectWindow.left,
1721 pWndCur->rectWindow.top,
1722 pWndCur->rectWindow.right,
1723 pWndCur->rectWindow.bottom };
1724 OffsetRect32( &rect, -wndPtr->rectClient.left,
1725 -wndPtr->rectClient.top );
1726 PAINT_RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1727 RDW_FRAME | RDW_ERASE, 0 );
1728 pWndCur = pWndCur->next;
1731 else /* Moving down */
1733 pWndCur = wndPtr->next;
1734 WIN_UnlinkWindow( hwnd );
1735 WIN_LinkWindow( hwnd, hwndAfter );
1736 while (pWndCur != wndPtr)
1738 RECT32 rect = { pWndCur->rectWindow.left,
1739 pWndCur->rectWindow.top,
1740 pWndCur->rectWindow.right,
1741 pWndCur->rectWindow.bottom };
1742 OffsetRect32( &rect, -pWndCur->rectClient.left,
1743 -pWndCur->rectClient.top );
1744 PAINT_RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1745 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1746 pWndCur = pWndCur->next;
1751 /***********************************************************************
1752 * WINPOS_ReorderOwnedPopups
1754 * fix Z order taking into account owned popups -
1755 * basically we need to maintain them above owner window
1757 HWND32 WINPOS_ReorderOwnedPopups(HWND32 hwndInsertAfter,WND* wndPtr,WORD flags)
1759 WND* w = WIN_GetDesktop()->child;
1761 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner )
1763 /* implement "local z-order" between the top and owner window */
1765 HWND32 hwndLocalPrev = HWND_TOP;
1767 if( hwndInsertAfter != HWND_TOP )
1769 while( w != wndPtr->owner )
1771 if (w != wndPtr) hwndLocalPrev = w->hwndSelf;
1772 if( hwndLocalPrev == hwndInsertAfter ) break;
1773 w = w->next;
1775 hwndInsertAfter = hwndLocalPrev;
1779 else if( wndPtr->dwStyle & WS_CHILD ) return hwndInsertAfter;
1781 w = WIN_GetDesktop()->child;
1782 while( w )
1784 if( w == wndPtr ) break;
1786 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1788 SetWindowPos32(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1789 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1790 hwndInsertAfter = w->hwndSelf;
1792 w = w->next;
1795 return hwndInsertAfter;
1798 /***********************************************************************
1799 * WINPOS_SizeMoveClean
1801 * Make window look nice without excessive repainting
1803 * the pain:
1805 * visible regions are in window coordinates
1806 * update regions are in window client coordinates
1807 * client and window rectangles are in parent client coordinates
1809 * FIXME: Move visible and update regions to the same coordinate system
1810 * (either parent client or window). This is a lot of work though.
1812 static UINT32 WINPOS_SizeMoveClean( WND* Wnd, HRGN32 oldVisRgn,
1813 LPRECT32 lpOldWndRect,
1814 LPRECT32 lpOldClientRect, UINT32 uFlags )
1816 HRGN32 newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf,DCX_WINDOW | DCX_CLIPSIBLINGS);
1817 HRGN32 dirtyRgn = CreateRectRgn32(0,0,0,0);
1818 int other, my;
1820 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1821 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1822 Wnd->rectWindow.left, Wnd->rectWindow.top,
1823 Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1824 lpOldWndRect->left, lpOldWndRect->top,
1825 lpOldWndRect->right, lpOldWndRect->bottom,
1826 Wnd->rectClient.left, Wnd->rectClient.top,
1827 Wnd->rectClient.right, Wnd->rectClient.bottom,
1828 lpOldClientRect->left, lpOldClientRect->top,
1829 lpOldClientRect->right,lpOldClientRect->bottom );
1831 if( (lpOldWndRect->right - lpOldWndRect->left) != (Wnd->rectWindow.right - Wnd->rectWindow.left) ||
1832 (lpOldWndRect->bottom - lpOldWndRect->top) != (Wnd->rectWindow.bottom - Wnd->rectWindow.top) )
1833 uFlags |= SMC_DRAWFRAME;
1835 CombineRgn32( dirtyRgn, newVisRgn, 0, RGN_COPY);
1837 if( !(uFlags & SMC_NOCOPY) )
1838 CombineRgn32( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1840 /* map regions to the parent client area */
1842 OffsetRgn32( dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top );
1843 OffsetRgn32( oldVisRgn, lpOldWndRect->left, lpOldWndRect->top );
1845 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1847 other = CombineRgn32(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1849 /* map visible region to the Wnd client area */
1851 OffsetRgn32( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1852 Wnd->rectWindow.top - Wnd->rectClient.top );
1854 /* substract previously invalidated region from the Wnd visible region */
1856 my = (Wnd->hrgnUpdate > 1) ? CombineRgn32( newVisRgn, newVisRgn,
1857 Wnd->hrgnUpdate, RGN_DIFF)
1858 : COMPLEXREGION;
1860 if( uFlags & SMC_NOCOPY ) /* invalidate Wnd visible region */
1862 if (my != NULLREGION)
1863 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1864 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1865 else if(uFlags & SMC_DRAWFRAME)
1866 Wnd->flags |= WIN_NEEDS_NCPAINT;
1868 else /* bitblt old client area */
1870 HDC32 hDC;
1871 int update;
1872 HRGN32 updateRgn;
1873 int xfrom,yfrom,xto,yto,width,height;
1875 if( uFlags & SMC_DRAWFRAME )
1877 /* copy only client area, frame will be redrawn anyway */
1879 xfrom = lpOldClientRect->left; yfrom = lpOldClientRect->top;
1880 xto = Wnd->rectClient.left; yto = Wnd->rectClient.top;
1881 width = lpOldClientRect->right - xfrom; height = lpOldClientRect->bottom - yfrom;
1882 updateRgn = CreateRectRgn32( 0, 0, width, height );
1883 CombineRgn32( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1884 SetRectRgn32( updateRgn, 0, 0, Wnd->rectClient.right - xto,
1885 Wnd->rectClient.bottom - yto );
1887 else
1889 xfrom = lpOldWndRect->left; yfrom = lpOldWndRect->top;
1890 xto = Wnd->rectWindow.left; yto = Wnd->rectWindow.top;
1891 width = lpOldWndRect->right - xfrom; height = lpOldWndRect->bottom - yfrom;
1892 updateRgn = CreateRectRgn32( xto - Wnd->rectClient.left,
1893 yto - Wnd->rectClient.top,
1894 Wnd->rectWindow.right - Wnd->rectClient.left,
1895 Wnd->rectWindow.bottom - Wnd->rectClient.top );
1898 CombineRgn32( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1900 /* substract new visRgn from target rect to get a region that won't be copied */
1902 update = CombineRgn32( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1904 /* Blt valid bits using parent window DC */
1906 if( my != NULLREGION && (xfrom != xto || yfrom != yto) )
1909 /* compute clipping region in parent client coordinates */
1911 OffsetRgn32( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top );
1912 CombineRgn32( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1914 hDC = GetDCEx32( Wnd->parent->hwndSelf, oldVisRgn,
1915 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
1916 DCX_CACHE | DCX_CLIPSIBLINGS);
1918 BitBlt32( hDC, xto, yto, width, height, hDC, xfrom, yfrom, SRCCOPY );
1919 ReleaseDC32( Wnd->parent->hwndSelf, hDC);
1922 if( update != NULLREGION )
1923 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1924 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1925 else if( uFlags & SMC_DRAWFRAME ) Wnd->flags |= WIN_NEEDS_NCPAINT;
1926 DeleteObject32( updateRgn );
1929 /* erase uncovered areas */
1931 if( !(uFlags & SMC_NOPARENTERASE) && (other != NULLREGION ) )
1932 PAINT_RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1933 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1934 DeleteObject32(dirtyRgn);
1935 DeleteObject32(newVisRgn);
1936 return uFlags;
1940 /***********************************************************************
1941 * WINPOS_FindDeskTopXWindow
1943 * Find the actual X window which needs be restacked.
1944 * Used by WINPOS_SetXWindowPos().
1946 static Window WINPOS_FindDeskTopXWindow( WND *wndPtr )
1948 if (!(wndPtr->flags & WIN_MANAGED))
1949 return wndPtr->window;
1950 else
1952 Window window, root, parent, *children;
1953 int nchildren;
1954 window = wndPtr->window;
1955 for (;;)
1957 TSXQueryTree( display, window, &root, &parent,
1958 &children, &nchildren );
1959 TSXFree( children );
1960 if (parent == root)
1961 return window;
1962 window = parent;
1967 /***********************************************************************
1968 * WINPOS_SetXWindowPos
1970 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1972 static void WINPOS_SetXWindowPos( const WINDOWPOS32 *winpos )
1974 XWindowChanges winChanges;
1975 int changeMask = 0;
1976 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1978 if (!(winpos->flags & SWP_NOSIZE))
1980 winChanges.width = winpos->cx;
1981 winChanges.height = winpos->cy;
1982 changeMask |= CWWidth | CWHeight;
1984 /* Tweak dialog window size hints */
1986 if ((wndPtr->flags & WIN_MANAGED) &&
1987 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1989 XSizeHints *size_hints = TSXAllocSizeHints();
1991 if (size_hints)
1993 long supplied_return;
1995 TSXGetWMSizeHints( display, wndPtr->window, size_hints,
1996 &supplied_return, XA_WM_NORMAL_HINTS);
1997 size_hints->min_width = size_hints->max_width = winpos->cx;
1998 size_hints->min_height = size_hints->max_height = winpos->cy;
1999 TSXSetWMSizeHints( display, wndPtr->window, size_hints,
2000 XA_WM_NORMAL_HINTS );
2001 TSXFree(size_hints);
2005 if (!(winpos->flags & SWP_NOMOVE))
2007 winChanges.x = winpos->x;
2008 winChanges.y = winpos->y;
2009 changeMask |= CWX | CWY;
2011 if (!(winpos->flags & SWP_NOZORDER))
2013 winChanges.stack_mode = Below;
2014 changeMask |= CWStackMode;
2016 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
2017 else if (winpos->hwndInsertAfter != HWND_BOTTOM)
2019 WND* insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
2020 Window stack[2];
2022 stack[0] = WINPOS_FindDeskTopXWindow( insertPtr );
2023 stack[1] = WINPOS_FindDeskTopXWindow( wndPtr );
2025 /* for stupid window managers (i.e. all of them) */
2027 TSXRestackWindows(display, stack, 2);
2028 changeMask &= ~CWStackMode;
2031 if (!changeMask) return;
2033 TSXReconfigureWMWindow( display, wndPtr->window, 0, changeMask, &winChanges );
2037 /***********************************************************************
2038 * SetWindowPos (USER.232)
2040 BOOL16 WINAPI SetWindowPos16( HWND16 hwnd, HWND16 hwndInsertAfter,
2041 INT16 x, INT16 y, INT16 cx, INT16 cy, WORD flags)
2043 return SetWindowPos32(hwnd,(INT32)(INT16)hwndInsertAfter,x,y,cx,cy,flags);
2046 /***********************************************************************
2047 * SetWindowPos (USER32.519)
2049 BOOL32 WINAPI SetWindowPos32( HWND32 hwnd, HWND32 hwndInsertAfter,
2050 INT32 x, INT32 y, INT32 cx, INT32 cy, WORD flags)
2052 WINDOWPOS32 winpos;
2053 WND * wndPtr;
2054 RECT32 newWindowRect, newClientRect, oldWindowRect;
2055 HRGN32 visRgn = 0;
2056 HWND32 tempInsertAfter= 0;
2057 int result = 0;
2058 UINT32 uFlags = 0;
2060 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
2061 hwnd, x, y, x+cx, y+cy, flags);
2062 /* Check window handle */
2064 if (hwnd == GetDesktopWindow32()) return FALSE;
2065 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
2067 if(wndPtr->dwStyle & WS_VISIBLE)
2068 flags &= ~SWP_SHOWWINDOW;
2069 else
2071 uFlags |= SMC_NOPARENTERASE;
2072 flags &= ~SWP_HIDEWINDOW;
2073 if (!(flags & SWP_SHOWWINDOW)) flags |= SWP_NOREDRAW;
2076 /* Check for windows that may not be resized
2077 FIXME: this should be done only for Windows 3.0 programs
2078 if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
2079 flags |= SWP_NOSIZE | SWP_NOMOVE;
2081 /* Check dimensions */
2083 if (cx <= 0) cx = 1;
2084 if (cy <= 0) cy = 1;
2086 /* Check flags */
2088 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
2089 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
2090 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
2091 flags |= SWP_NOSIZE; /* Already the right size */
2092 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
2093 flags |= SWP_NOMOVE; /* Already the right position */
2095 /* Check hwndInsertAfter */
2097 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
2099 /* Ignore TOPMOST flags when activating a window */
2100 /* _and_ moving it in Z order. */
2101 if ((hwndInsertAfter == HWND_TOPMOST) ||
2102 (hwndInsertAfter == HWND_NOTOPMOST))
2103 hwndInsertAfter = HWND_TOP;
2105 /* TOPMOST not supported yet */
2106 if ((hwndInsertAfter == HWND_TOPMOST) ||
2107 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
2109 /* hwndInsertAfter must be a sibling of the window */
2110 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
2112 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
2113 if( wnd->parent != wndPtr->parent ) return FALSE;
2114 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
2116 else if (!(wndPtr->window))
2117 /* FIXME: the following optimization is no good for "X-ed" windows */
2118 if (hwndInsertAfter == HWND_TOP)
2119 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
2120 else /* HWND_BOTTOM */
2121 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
2123 /* Fill the WINDOWPOS structure */
2125 winpos.hwnd = hwnd;
2126 winpos.hwndInsertAfter = hwndInsertAfter;
2127 winpos.x = x;
2128 winpos.y = y;
2129 winpos.cx = cx;
2130 winpos.cy = cy;
2131 winpos.flags = flags;
2133 /* Send WM_WINDOWPOSCHANGING message */
2135 if (!(winpos.flags & SWP_NOSENDCHANGING))
2136 SendMessage32A( hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)&winpos );
2138 /* Calculate new position and size */
2140 newWindowRect = wndPtr->rectWindow;
2141 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
2142 : wndPtr->rectClient;
2144 if (!(winpos.flags & SWP_NOSIZE))
2146 newWindowRect.right = newWindowRect.left + winpos.cx;
2147 newWindowRect.bottom = newWindowRect.top + winpos.cy;
2149 if (!(winpos.flags & SWP_NOMOVE))
2151 newWindowRect.left = winpos.x;
2152 newWindowRect.top = winpos.y;
2153 newWindowRect.right += winpos.x - wndPtr->rectWindow.left;
2154 newWindowRect.bottom += winpos.y - wndPtr->rectWindow.top;
2156 OffsetRect32( &newClientRect, winpos.x - wndPtr->rectWindow.left,
2157 winpos.y - wndPtr->rectWindow.top );
2160 winpos.flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
2162 /* Reposition window in Z order */
2164 if (!(winpos.flags & SWP_NOZORDER))
2166 /* reorder owned popups if hwnd is top-level window
2168 if( wndPtr->parent == WIN_GetDesktop() )
2169 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
2170 wndPtr, winpos.flags );
2172 if (wndPtr->window)
2174 WIN_UnlinkWindow( winpos.hwnd );
2175 WIN_LinkWindow( winpos.hwnd, hwndInsertAfter );
2177 else WINPOS_MoveWindowZOrder( winpos.hwnd, hwndInsertAfter );
2180 if ( !wndPtr->window && !(winpos.flags & SWP_NOREDRAW) &&
2181 ((winpos.flags & (SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED))
2182 != (SWP_NOMOVE | SWP_NOSIZE)) )
2183 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
2186 /* Send WM_NCCALCSIZE message to get new client area */
2187 if( (winpos.flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
2189 result = WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
2190 &wndPtr->rectWindow, &wndPtr->rectClient,
2191 &winpos, &newClientRect );
2193 /* FIXME: WVR_ALIGNxxx */
2195 if( newClientRect.left != wndPtr->rectClient.left ||
2196 newClientRect.top != wndPtr->rectClient.top )
2197 winpos.flags &= ~SWP_NOCLIENTMOVE;
2199 if( (newClientRect.right - newClientRect.left !=
2200 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
2201 (newClientRect.bottom - newClientRect.top !=
2202 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
2203 winpos.flags &= ~SWP_NOCLIENTSIZE;
2205 else
2206 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
2207 newClientRect.top != wndPtr->rectClient.top) )
2208 winpos.flags &= ~SWP_NOCLIENTMOVE;
2210 /* Update active DCEs
2211 * TODO: Optimize conditions that trigger DCE update.
2214 if( (((winpos.flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
2215 wndPtr->dwStyle & WS_VISIBLE) ||
2216 (flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
2218 RECT32 rect;
2220 UnionRect32(&rect, &newWindowRect, &wndPtr->rectWindow);
2221 DCE_InvalidateDCE(wndPtr, &rect);
2224 /* change geometry */
2226 oldWindowRect = wndPtr->rectWindow;
2228 if (wndPtr->window)
2230 RECT32 oldClientRect = wndPtr->rectClient;
2232 tempInsertAfter = winpos.hwndInsertAfter;
2234 winpos.hwndInsertAfter = hwndInsertAfter;
2236 /* postpone geometry change */
2238 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
2240 WINPOS_SetXWindowPos( &winpos );
2241 winpos.hwndInsertAfter = tempInsertAfter;
2243 else uFlags |= SMC_SETXPOS;
2245 wndPtr->rectWindow = newWindowRect;
2246 wndPtr->rectClient = newClientRect;
2248 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
2249 if( (oldClientRect.left - oldWindowRect.left !=
2250 newClientRect.left - newWindowRect.left) ||
2251 (oldClientRect.top - oldWindowRect.top !=
2252 newClientRect.top - newWindowRect.top) ||
2253 winpos.flags & SWP_NOCOPYBITS )
2255 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
2256 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
2257 else
2258 if( winpos.flags & SWP_FRAMECHANGED )
2260 WORD wErase = 0;
2261 RECT32 rect;
2263 if( oldClientRect.right > newClientRect.right )
2265 rect.left = newClientRect.right; rect.top = newClientRect.top;
2266 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
2267 wErase = 1;
2268 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
2269 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
2271 if( oldClientRect.bottom > newClientRect.bottom )
2273 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
2274 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
2275 rect.bottom = oldClientRect.bottom;
2276 wErase = 1;
2277 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
2278 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
2280 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
2283 else
2285 RECT32 oldClientRect = wndPtr->rectClient;
2287 wndPtr->rectWindow = newWindowRect;
2288 wndPtr->rectClient = newClientRect;
2290 if( oldClientRect.bottom - oldClientRect.top ==
2291 newClientRect.bottom - newClientRect.top ) result &= ~WVR_VREDRAW;
2293 if( oldClientRect.right - oldClientRect.left ==
2294 newClientRect.right - newClientRect.left ) result &= ~WVR_HREDRAW;
2296 if( !(flags & (SWP_NOREDRAW | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
2298 uFlags |= ((winpos.flags & SWP_NOCOPYBITS) ||
2299 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS)) ? SMC_NOCOPY : 0;
2300 uFlags |= (winpos.flags & SWP_FRAMECHANGED) ? SMC_DRAWFRAME : 0;
2302 if( (winpos.flags & SWP_AGG_NOGEOMETRYCHANGE) != SWP_AGG_NOGEOMETRYCHANGE )
2303 uFlags = WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect,
2304 &oldClientRect, uFlags);
2305 else
2307 /* adjust frame and do not erase parent */
2309 if( winpos.flags & SWP_FRAMECHANGED ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
2310 if( winpos.flags & SWP_NOZORDER ) uFlags |= SMC_NOPARENTERASE;
2313 DeleteObject32(visRgn);
2316 if (flags & SWP_SHOWWINDOW)
2318 wndPtr->dwStyle |= WS_VISIBLE;
2319 if (wndPtr->window)
2321 HWND32 focus, curr;
2323 if( uFlags & SMC_SETXPOS )
2325 WINPOS_SetXWindowPos( &winpos );
2326 winpos.hwndInsertAfter = tempInsertAfter;
2328 TSXMapWindow( display, wndPtr->window );
2330 /* If focus was set to an unmapped window, reset X focus now */
2331 focus = curr = GetFocus32();
2332 while (curr) {
2333 if (curr == hwnd) {
2334 SetFocus32( 0 );
2335 SetFocus32( focus );
2336 break;
2338 curr = GetParent32(curr);
2341 else
2343 if (!(flags & SWP_NOREDRAW))
2344 PAINT_RedrawWindow( winpos.hwnd, NULL, 0,
2345 RDW_INVALIDATE | RDW_ALLCHILDREN |
2346 RDW_FRAME | RDW_ERASENOW | RDW_ERASE, 0 );
2349 else if (flags & SWP_HIDEWINDOW)
2351 wndPtr->dwStyle &= ~WS_VISIBLE;
2352 if (wndPtr->window)
2354 TSXUnmapWindow( display, wndPtr->window );
2355 if( uFlags & SMC_SETXPOS )
2357 WINPOS_SetXWindowPos( &winpos );
2358 winpos.hwndInsertAfter = tempInsertAfter;
2361 else
2363 if (!(flags & SWP_NOREDRAW))
2364 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, &oldWindowRect,
2365 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
2366 RDW_ERASE | RDW_ERASENOW, 0 );
2367 uFlags |= SMC_NOPARENTERASE;
2370 if ((winpos.hwnd == GetFocus32()) ||
2371 IsChild32( winpos.hwnd, GetFocus32()))
2373 /* Revert focus to parent */
2374 SetFocus32( GetParent32(winpos.hwnd) );
2376 if (hwnd == CARET_GetHwnd()) DestroyCaret32();
2378 if (winpos.hwnd == hwndActive)
2379 WINPOS_ActivateOtherWindow( wndPtr );
2382 /* Activate the window */
2384 if (!(flags & SWP_NOACTIVATE))
2385 WINPOS_ChangeActiveWindow( winpos.hwnd, FALSE );
2387 /* Repaint the window */
2389 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
2391 if (!GetCapture32())
2392 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
2394 if (!(flags & SWP_DEFERERASE) && !(uFlags & SMC_NOPARENTERASE) )
2395 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_ALLCHILDREN | RDW_ERASENOW, 0 );
2396 else if( wndPtr->parent == WIN_GetDesktop() && wndPtr->parent->flags & WIN_NEEDS_ERASEBKGND )
2397 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_NOCHILDREN | RDW_ERASENOW, 0 );
2399 /* And last, send the WM_WINDOWPOSCHANGED message */
2401 dprintf_win(stddeb,"\tstatus flags = %04x\n", winpos.flags & SWP_AGG_STATUSFLAGS);
2403 if ( ((winpos.flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
2404 !(winpos.flags & SWP_NOSENDCHANGING))
2405 SendMessage32A( winpos.hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos );
2407 return TRUE;
2411 /***********************************************************************
2412 * BeginDeferWindowPos16 (USER.259)
2414 HDWP16 WINAPI BeginDeferWindowPos16( INT16 count )
2416 return BeginDeferWindowPos32( count );
2420 /***********************************************************************
2421 * BeginDeferWindowPos32 (USER32.8)
2423 HDWP32 WINAPI BeginDeferWindowPos32( INT32 count )
2425 HDWP32 handle;
2426 DWP *pDWP;
2428 if (count <= 0) return 0;
2429 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS32) );
2430 if (!handle) return 0;
2431 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2432 pDWP->actualCount = 0;
2433 pDWP->suggestedCount = count;
2434 pDWP->valid = TRUE;
2435 pDWP->wMagic = DWP_MAGIC;
2436 pDWP->hwndParent = 0;
2437 return handle;
2441 /***********************************************************************
2442 * DeferWindowPos16 (USER.260)
2444 HDWP16 WINAPI DeferWindowPos16( HDWP16 hdwp, HWND16 hwnd, HWND16 hwndAfter,
2445 INT16 x, INT16 y, INT16 cx, INT16 cy,
2446 UINT16 flags )
2448 return DeferWindowPos32( hdwp, hwnd, (INT32)(INT16)hwndAfter,
2449 x, y, cx, cy, flags );
2453 /***********************************************************************
2454 * DeferWindowPos32 (USER32.127)
2456 HDWP32 WINAPI DeferWindowPos32( HDWP32 hdwp, HWND32 hwnd, HWND32 hwndAfter,
2457 INT32 x, INT32 y, INT32 cx, INT32 cy,
2458 UINT32 flags )
2460 DWP *pDWP;
2461 int i;
2462 HDWP32 newhdwp = hdwp;
2463 HWND32 parent;
2464 WND *pWnd;
2466 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2467 if (!pDWP) return 0;
2468 if (hwnd == GetDesktopWindow32()) return 0;
2470 /* All the windows of a DeferWindowPos() must have the same parent */
2471 if (!(pWnd=WIN_FindWndPtr( hwnd ))) {
2472 USER_HEAP_FREE( hdwp );
2473 return 0;
2476 parent = pWnd->parent->hwndSelf;
2477 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
2478 else if (parent != pDWP->hwndParent)
2480 USER_HEAP_FREE( hdwp );
2481 return 0;
2484 for (i = 0; i < pDWP->actualCount; i++)
2486 if (pDWP->winPos[i].hwnd == hwnd)
2488 /* Merge with the other changes */
2489 if (!(flags & SWP_NOZORDER))
2491 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
2493 if (!(flags & SWP_NOMOVE))
2495 pDWP->winPos[i].x = x;
2496 pDWP->winPos[i].y = y;
2498 if (!(flags & SWP_NOSIZE))
2500 pDWP->winPos[i].cx = cx;
2501 pDWP->winPos[i].cy = cy;
2503 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
2504 SWP_NOZORDER | SWP_NOREDRAW |
2505 SWP_NOACTIVATE | SWP_NOCOPYBITS|
2506 SWP_NOOWNERZORDER);
2507 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2508 SWP_FRAMECHANGED);
2509 return hdwp;
2512 if (pDWP->actualCount >= pDWP->suggestedCount)
2514 newhdwp = USER_HEAP_REALLOC( hdwp,
2515 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS32) );
2516 if (!newhdwp) return 0;
2517 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2518 pDWP->suggestedCount++;
2520 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2521 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2522 pDWP->winPos[pDWP->actualCount].x = x;
2523 pDWP->winPos[pDWP->actualCount].y = y;
2524 pDWP->winPos[pDWP->actualCount].cx = cx;
2525 pDWP->winPos[pDWP->actualCount].cy = cy;
2526 pDWP->winPos[pDWP->actualCount].flags = flags;
2527 pDWP->actualCount++;
2528 return newhdwp;
2532 /***********************************************************************
2533 * EndDeferWindowPos16 (USER.261)
2535 BOOL16 WINAPI EndDeferWindowPos16( HDWP16 hdwp )
2537 return EndDeferWindowPos32( hdwp );
2541 /***********************************************************************
2542 * EndDeferWindowPos32 (USER32.172)
2544 BOOL32 WINAPI EndDeferWindowPos32( HDWP32 hdwp )
2546 DWP *pDWP;
2547 WINDOWPOS32 *winpos;
2548 BOOL32 res = TRUE;
2549 int i;
2551 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2552 if (!pDWP) return FALSE;
2553 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2555 if (!(res = SetWindowPos32( winpos->hwnd, winpos->hwndInsertAfter,
2556 winpos->x, winpos->y, winpos->cx,
2557 winpos->cy, winpos->flags ))) break;
2559 USER_HEAP_FREE( hdwp );
2560 return res;
2564 /***********************************************************************
2565 * TileChildWindows (USER.199)
2567 void WINAPI TileChildWindows( HWND16 parent, WORD action )
2569 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
2572 /***********************************************************************
2573 * CascageChildWindows (USER.198)
2575 void WINAPI CascadeChildWindows( HWND16 parent, WORD action )
2577 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);