2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
8 #define NO_TRANSITION_TYPES
10 #include <X11/Xutil.h>
11 #include <X11/Xatom.h>
12 #include "sysmetrics.h"
23 #include "nonclient.h"
25 /* #define DEBUG_WIN */
28 #define SWP_AGG_NOGEOMETRYCHANGE \
29 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
30 #define SWP_AGG_NOPOSCHANGE \
31 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
32 #define SWP_AGG_STATUSFLAGS \
33 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
35 #define SMC_NOCOPY 0x0001
36 #define SMC_NOPARENTERASE 0x0002
37 #define SMC_DRAWFRAME 0x0004
38 #define SMC_SETXPOS 0x0008
40 /* ----- external functions ----- */
42 extern void FOCUS_SwitchFocus( HWND32 , HWND32 );
43 extern HRGN32 DCE_GetVisRgn( HWND32, WORD );
44 extern HWND32 CARET_GetHwnd();
45 extern BOOL32 DCE_InvalidateDCE(WND*, RECT16* );
47 /* ----- internal variables ----- */
49 static HWND32 hwndActive = 0; /* Currently active window */
50 static HWND32 hwndPrevActive = 0; /* Previously active window */
52 extern MESSAGEQUEUE* pActiveQueue;
54 /***********************************************************************
57 void WINPOS_CheckActive( HWND32 hwnd )
59 if( hwnd == hwndPrevActive ) hwndPrevActive = 0;
60 if( hwnd == hwndActive )
63 dprintf_win(stddeb,"\tattempt to activate destroyed window!\n");
67 /***********************************************************************
70 * Find a suitable place for an iconic window.
71 * The new position is stored into wndPtr->ptIconPos.
73 void WINPOS_FindIconPos( HWND32 hwnd )
76 short x, y, xspacing, yspacing;
77 WND * wndPtr = WIN_FindWndPtr( hwnd );
79 if (!wndPtr || !wndPtr->parent) return;
80 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
81 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
82 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
83 (wndPtr->ptIconPos.y >= rectParent.top) &&
84 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
85 return; /* The icon already has a suitable position */
87 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
88 y = rectParent.bottom;
91 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
93 /* Check if another icon already occupies this spot */
94 WND *childPtr = wndPtr->parent->child;
97 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
99 if ((childPtr->rectWindow.left < x + xspacing) &&
100 (childPtr->rectWindow.right >= x) &&
101 (childPtr->rectWindow.top <= y) &&
102 (childPtr->rectWindow.bottom > y - yspacing))
103 break; /* There's a window in there */
105 childPtr = childPtr->next;
109 /* No window was found, so it's OK for us */
110 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
111 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
120 /***********************************************************************
121 * ArrangeIconicWindows (USER32.6)
123 UINT16 ArrangeIconicWindows16( HWND16 parent) {
124 return ArrangeIconicWindows32(parent);
126 /***********************************************************************
127 * ArrangeIconicWindows (USER.170)
129 UINT32 ArrangeIconicWindows32( HWND32 parent )
133 INT32 x, y, xspacing, yspacing;
135 GetClientRect32( parent, &rectParent );
137 y = rectParent.bottom;
138 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
139 hwndChild = GetWindow32( parent, GW_CHILD );
142 if (IsIconic32( hwndChild ))
144 SetWindowPos32( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
145 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
146 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE );
147 if (x <= rectParent.right - xspacing) x += xspacing;
154 hwndChild = GetWindow32( hwndChild, GW_HWNDNEXT );
160 /***********************************************************************
161 * GetWindowRect16 (USER.32)
163 void GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
165 WND * wndPtr = WIN_FindWndPtr( hwnd );
168 *rect = wndPtr->rectWindow;
169 if (wndPtr->dwStyle & WS_CHILD)
170 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
174 /***********************************************************************
175 * GetWindowRect32 (USER.32)
177 void GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
179 WND * wndPtr = WIN_FindWndPtr( hwnd );
182 CONV_RECT16TO32( &wndPtr->rectWindow, rect );
183 if (wndPtr->dwStyle & WS_CHILD)
184 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
188 /***********************************************************************
189 * GetClientRect16 (USER.33)
191 void GetClientRect16( HWND16 hwnd, LPRECT16 rect )
193 WND * wndPtr = WIN_FindWndPtr( hwnd );
195 rect->left = rect->top = rect->right = rect->bottom = 0;
198 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
199 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
204 /***********************************************************************
205 * GetClientRect32 (USER32.219)
207 void GetClientRect32( HWND32 hwnd, LPRECT32 rect )
209 WND * wndPtr = WIN_FindWndPtr( hwnd );
211 rect->left = rect->top = rect->right = rect->bottom = 0;
214 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
215 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
220 /*******************************************************************
221 * ClientToScreen16 (USER.28)
223 BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
225 MapWindowPoints16( hwnd, 0, lppnt, 1 );
230 /*******************************************************************
231 * ClientToScreen32 (USER32.51)
233 BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
235 MapWindowPoints32( hwnd, 0, lppnt, 1 );
240 /*******************************************************************
241 * ScreenToClient16 (USER.29)
243 void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
245 MapWindowPoints16( 0, hwnd, lppnt, 1 );
249 /*******************************************************************
250 * ScreenToClient32 (USER32.446)
252 void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
254 MapWindowPoints32( 0, hwnd, lppnt, 1 );
258 /***********************************************************************
259 * WINPOS_WindowFromPoint
261 * Find the window and hittest for a given point.
263 INT16 WINPOS_WindowFromPoint( WND* wndScope, POINT16 pt, WND **ppWnd )
266 INT16 hittest = HTERROR;
272 wndPtr = wndScope->child;
277 /* If point is in window, and window is visible, and it */
278 /* is enabled (or it's a top-level window), then explore */
279 /* its children. Otherwise, go to the next window. */
281 if ((wndPtr->dwStyle & WS_VISIBLE) &&
282 (!(wndPtr->dwStyle & WS_DISABLED) ||
283 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
284 (x >= wndPtr->rectWindow.left) &&
285 (x < wndPtr->rectWindow.right) &&
286 (y >= wndPtr->rectWindow.top) &&
287 (y < wndPtr->rectWindow.bottom))
289 *ppWnd = wndPtr; /* Got a suitable window */
291 /* If window is minimized or disabled, return at once */
292 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
293 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
295 /* If point is not in client area, ignore the children */
296 if ((x < wndPtr->rectClient.left) ||
297 (x >= wndPtr->rectClient.right) ||
298 (y < wndPtr->rectClient.top) ||
299 (y >= wndPtr->rectClient.bottom)) break;
301 x -= wndPtr->rectClient.left;
302 y -= wndPtr->rectClient.top;
303 wndPtr = wndPtr->child;
305 else wndPtr = wndPtr->next;
308 /* If nothing found, return the scope window */
312 if( pt.x >= (wndScope->rectClient.left - wndScope->rectWindow.left) &&
313 pt.x >= (wndScope->rectClient.top - wndScope->rectWindow.top ) &&
314 pt.x <= (wndScope->rectClient.right - wndScope->rectWindow.left) &&
315 pt.x <= (wndScope->rectClient.bottom - wndScope->rectWindow.top ) )
317 if( pt.x < 0 || pt.y < 0 ||
318 pt.x > (wndScope->rectWindow.right - wndScope->rectWindow.left) ||
319 pt.y > (wndScope->rectWindow.bottom - wndScope->rectWindow.top ) )
321 return HTCAPTION; /* doesn't matter in this case */
324 /* Send the WM_NCHITTEST message (only if to the same task) */
325 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
326 hittest = (INT16)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
327 MAKELONG( pt.x, pt.y ) );
328 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
330 /* If no children found in last search, make point relative to parent*/
333 x += (*ppWnd)->rectClient.left;
334 y += (*ppWnd)->rectClient.top;
337 /* Restart the search from the next sibling */
338 wndPtr = (*ppWnd)->next;
339 *ppWnd = (*ppWnd)->parent;
344 /*******************************************************************
345 * WindowFromPoint16 (USER.30)
347 HWND16 WindowFromPoint16( POINT16 pt )
350 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt, &pWnd );
351 return pWnd->hwndSelf;
355 /*******************************************************************
356 * WindowFromPoint32 (USER32.581)
358 HWND32 WindowFromPoint32( POINT32 pt )
362 CONV_POINT32TO16( &pt, &pt16 );
363 WINPOS_WindowFromPoint( WIN_GetDesktop(), pt16, &pWnd );
364 return (HWND32)pWnd->hwndSelf;
368 /*******************************************************************
369 * ChildWindowFromPoint16 (USER.191)
371 HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
373 /* pt is in the client coordinates */
375 WND* wnd = WIN_FindWndPtr(hwndParent);
380 /* get client rect fast */
381 rect.top = rect.left = 0;
382 rect.right = wnd->rectClient.right - wnd->rectClient.left;
383 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
385 if (!PtInRect16( &rect, pt )) return 0;
390 if (PtInRect16( &wnd->rectWindow, pt )) return wnd->hwndSelf;
397 /*******************************************************************
398 * ChildWindowFromPoint32 (USER32.)
400 HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
403 CONV_POINT32TO16( &pt, &pt16 );
404 return (HWND32)ChildWindowFromPoint16( hwndParent, pt16 );
408 /*******************************************************************
409 * WINPOS_GetWinOffset
411 * Calculate the offset between the origin of the two windows. Used
412 * to implement MapWindowPoints.
414 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
419 offset->x = offset->y = 0;
420 if (hwndFrom == hwndTo ) return;
422 /* Translate source window origin to screen coords */
425 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
427 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
430 while (wndPtr->parent)
432 offset->x += wndPtr->rectClient.left;
433 offset->y += wndPtr->rectClient.top;
434 wndPtr = wndPtr->parent;
438 /* Translate origin to destination window coords */
441 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
443 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
446 while (wndPtr->parent)
448 offset->x -= wndPtr->rectClient.left;
449 offset->y -= wndPtr->rectClient.top;
450 wndPtr = wndPtr->parent;
456 /*******************************************************************
457 * MapWindowPoints16 (USER.258)
459 void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
460 LPPOINT16 lppt, UINT16 count )
464 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
474 /*******************************************************************
475 * MapWindowPoints32 (USER32.385)
477 void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
478 LPPOINT32 lppt, UINT32 count )
482 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
492 /***********************************************************************
495 BOOL16 IsIconic16(HWND16 hWnd)
497 return IsIconic32(hWnd);
499 /***********************************************************************
500 * IsIconic (USER32.344)
502 BOOL32 IsIconic32(HWND32 hWnd)
504 WND * wndPtr = WIN_FindWndPtr(hWnd);
505 if (wndPtr == NULL) return FALSE;
506 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
510 /***********************************************************************
511 * IsZoomed (USER.272)
513 BOOL16 IsZoomed16(HWND16 hWnd)
515 return IsZoomed32(hWnd);
517 /***********************************************************************
518 * IsZoomed (USER32.351)
520 BOOL32 IsZoomed32(HWND32 hWnd)
522 WND * wndPtr = WIN_FindWndPtr(hWnd);
523 if (wndPtr == NULL) return FALSE;
524 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
528 /*******************************************************************
529 * GetActiveWindow (USER.60)
531 HWND16 GetActiveWindow16(void)
533 return GetActiveWindow32();
535 /*******************************************************************
536 * GetActiveWindow (USER32.204)
538 HWND32 GetActiveWindow32(void)
544 /*******************************************************************
545 * WINPOS_IsGoodEnough
547 static BOOL32 WINPOS_IsGoodEnough(WND* pWnd)
549 return (pWnd) ? ((!(pWnd->dwStyle & WS_DISABLED) &&
550 pWnd->dwStyle & WS_VISIBLE ) ? TRUE : FALSE) : FALSE;
554 /*******************************************************************
555 * SetActiveWindow (USER.59)
557 HWND16 SetActiveWindow16( HWND16 hwnd )
559 return SetActiveWindow32(hwnd);
561 /*******************************************************************
562 * SetActiveWindow (USER.59)
564 HWND32 SetActiveWindow32( HWND32 hwnd )
566 HWND32 prev = hwndActive;
567 WND *wndPtr = WIN_FindWndPtr( hwnd );
569 if ( !WINPOS_IsGoodEnough(wndPtr) ) return 0;
571 WINPOS_SetActiveWindow( hwnd, 0, 0 );
576 /***********************************************************************
577 * BringWindowToTop (USER.45)
579 BOOL16 BringWindowToTop16( HWND16 hwnd )
581 return BringWindowToTop32(hwnd);
583 /***********************************************************************
584 * BringWindowToTop (USER32.10)
586 BOOL32 BringWindowToTop32( HWND32 hwnd )
588 return SetWindowPos32( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
592 /***********************************************************************
593 * MoveWindow (USER.56)
596 HWND16 hwnd, INT16 x, INT16 y, INT16 cx, INT16 cy, BOOL16 repaint
598 return MoveWindow32(hwnd,x,y,cx,cy,repaint);
600 /***********************************************************************
601 * MoveWindow (USER32.398)
604 HWND32 hwnd, INT32 x, INT32 y, INT32 cx, INT32 cy, BOOL32 repaint
606 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
607 if (!repaint) flags |= SWP_NOREDRAW;
608 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
609 hwnd, x, y, cx, cy, repaint );
610 return SetWindowPos32( hwnd, 0, x, y, cx, cy, flags );
613 /***********************************************************************
614 * ShowWindow (USER.42)
616 BOOL16 ShowWindow16( HWND16 hwnd, INT16 cmd )
618 return ShowWindow32(hwnd,cmd);
620 /***********************************************************************
621 * ShowWindow (USER.42)
623 BOOL32 ShowWindow32( HWND32 hwnd, INT32 cmd )
625 WND * wndPtr = WIN_FindWndPtr( hwnd );
626 BOOL32 wasVisible, showFlag;
629 short x = 0, y = 0, cx = 0, cy = 0;
631 if (!wndPtr) return FALSE;
633 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
635 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
640 if (!wasVisible) return FALSE;
641 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
642 SWP_NOACTIVATE | SWP_NOZORDER;
645 case SW_SHOWMINNOACTIVE:
646 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
648 case SW_SHOWMINIMIZED:
649 swpflags |= SWP_SHOWWINDOW;
652 swpflags |= SWP_FRAMECHANGED;
653 if (!(wndPtr->dwStyle & WS_MINIMIZE))
655 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
658 if (wndPtr->dwStyle & WS_MAXIMIZE)
660 wndPtr->flags |= WIN_RESTORE_MAX;
661 wndPtr->dwStyle &= ~WS_MAXIMIZE;
665 wndPtr->flags &= ~WIN_RESTORE_MAX;
666 wndPtr->rectNormal = wndPtr->rectWindow;
668 wndPtr->dwStyle |= WS_MINIMIZE;
669 WINPOS_FindIconPos( hwnd );
670 x = wndPtr->ptIconPos.x;
671 y = wndPtr->ptIconPos.y;
672 cx = SYSMETRICS_CXICON;
673 cy = SYSMETRICS_CYICON;
674 swpflags |= SWP_NOCOPYBITS;
676 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
679 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
680 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
681 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
683 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
686 /* Store the current position and find the maximized size */
687 if (!(wndPtr->dwStyle & WS_MINIMIZE))
688 wndPtr->rectNormal = wndPtr->rectWindow;
690 NC_GetMinMaxInfo( wndPtr, &maxSize,
691 &wndPtr->ptMaxPos, NULL, NULL );
692 x = wndPtr->ptMaxPos.x;
693 y = wndPtr->ptMaxPos.y;
695 if( wndPtr->dwStyle & WS_MINIMIZE )
696 if( !SendMessage32A( hwnd, WM_QUERYOPEN, 0, 0L ) )
698 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
701 else swpflags |= SWP_NOCOPYBITS;
705 wndPtr->dwStyle &= ~WS_MINIMIZE;
706 wndPtr->dwStyle |= WS_MAXIMIZE;
708 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
712 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
715 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
718 case SW_SHOWNOACTIVATE:
719 swpflags |= SWP_NOZORDER;
720 if (GetActiveWindow32()) swpflags |= SWP_NOACTIVATE;
722 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
723 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
725 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
727 if (wndPtr->dwStyle & WS_MINIMIZE)
729 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
732 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L) )
734 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
737 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
738 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
739 wndPtr->dwStyle &= ~WS_MINIMIZE;
740 if (wndPtr->flags & WIN_RESTORE_MAX)
742 /* Restore to maximized position */
743 NC_GetMinMaxInfo( wndPtr, &maxSize, &wndPtr->ptMaxPos,
745 x = wndPtr->ptMaxPos.x;
746 y = wndPtr->ptMaxPos.y;
749 wndPtr->dwStyle |= WS_MAXIMIZE;
751 else /* Restore to normal position */
753 x = wndPtr->rectNormal.left;
754 y = wndPtr->rectNormal.top;
755 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
756 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
758 swpflags |= SWP_NOCOPYBITS;
760 else if (wndPtr->dwStyle & WS_MAXIMIZE)
762 if( HOOK_CallHooks16( WH_CBT, HCBT_MINMAX, hwnd, cmd) )
765 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
766 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
767 wndPtr->dwStyle &= ~WS_MAXIMIZE;
768 x = wndPtr->rectNormal.left;
769 y = wndPtr->rectNormal.top;
770 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
771 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
773 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
777 showFlag = (cmd != SW_HIDE);
778 if (showFlag != wasVisible)
780 SendMessage16( hwnd, WM_SHOWWINDOW, showFlag, 0 );
781 if (!IsWindow( hwnd )) return wasVisible;
784 if ((wndPtr->dwStyle & WS_CHILD) &&
785 !IsWindowVisible32( wndPtr->parent->hwndSelf ) &&
786 (swpflags & SWP_NOSIZE) && (swpflags & SWP_NOMOVE))
788 /* Don't call SetWindowPos32() on invisible child windows */
789 if (cmd == SW_HIDE) wndPtr->dwStyle &= ~WS_VISIBLE;
790 else wndPtr->dwStyle |= WS_VISIBLE;
794 /* We can't activate a child window */
795 if (wndPtr->dwStyle & WS_CHILD)
796 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
797 SetWindowPos32( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
798 if (!IsWindow( hwnd )) return wasVisible;
801 if (wndPtr->flags & WIN_NEED_SIZE)
803 /* should happen only in CreateWindowEx() */
804 int wParam = SIZE_RESTORED;
806 wndPtr->flags &= ~WIN_NEED_SIZE;
807 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
808 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
809 SendMessage16( hwnd, WM_SIZE, wParam,
810 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
811 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
812 SendMessage16( hwnd, WM_MOVE, 0,
813 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
820 /***********************************************************************
821 * GetInternalWindowPos16 (USER.460)
823 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
825 WINDOWPLACEMENT16 wndpl;
826 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
827 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
828 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
829 return wndpl.showCmd;
833 /***********************************************************************
834 * GetInternalWindowPos32 (USER32.244)
836 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
838 WINDOWPLACEMENT32 wndpl;
839 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
840 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
841 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
842 return wndpl.showCmd;
846 /***********************************************************************
847 * SetInternalWindowPos16 (USER.461)
849 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
850 LPRECT16 rect, LPPOINT16 pt )
852 WINDOWPLACEMENT16 wndpl;
853 WND *wndPtr = WIN_FindWndPtr( hwnd );
855 wndpl.length = sizeof(wndpl);
856 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
857 wndpl.showCmd = showCmd;
858 if (pt) wndpl.ptMinPosition = *pt;
859 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
860 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
861 SetWindowPlacement16( hwnd, &wndpl );
865 /***********************************************************************
866 * SetInternalWindowPos32 (USER32.482)
868 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
869 LPRECT32 rect, LPPOINT32 pt )
871 WINDOWPLACEMENT32 wndpl;
872 WND *wndPtr = WIN_FindWndPtr( hwnd );
874 wndpl.length = sizeof(wndpl);
875 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
876 wndpl.showCmd = showCmd;
877 if (pt) wndpl.ptMinPosition = *pt;
878 if (rect) wndpl.rcNormalPosition = *rect;
879 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
880 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
881 SetWindowPlacement32( hwnd, &wndpl );
885 /***********************************************************************
886 * GetWindowPlacement16 (USER.370)
888 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
890 WND *wndPtr = WIN_FindWndPtr( hwnd );
891 if (!wndPtr) return FALSE;
893 wndpl->length = sizeof(*wndpl);
895 wndpl->showCmd = IsZoomed16(hwnd) ? SW_SHOWMAXIMIZED :
896 (IsIconic16(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
897 wndpl->ptMinPosition = wndPtr->ptIconPos;
898 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
899 wndpl->rcNormalPosition = wndPtr->rectNormal;
904 /***********************************************************************
905 * GetWindowPlacement32 (USER32.306)
907 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
909 WND *wndPtr = WIN_FindWndPtr( hwnd );
910 if (!wndPtr) return FALSE;
912 wndpl->length = sizeof(*wndpl);
914 wndpl->showCmd = IsZoomed32(hwnd) ? SW_SHOWMAXIMIZED :
915 (IsIconic32(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
916 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
917 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
918 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
923 /***********************************************************************
924 * SetWindowPlacement16 (USER.371)
926 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
928 WND *wndPtr = WIN_FindWndPtr( hwnd );
929 if (!wndPtr) return FALSE;
931 if (wndpl->flags & WPF_SETMINPOSITION)
932 wndPtr->ptIconPos = wndpl->ptMinPosition;
933 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
934 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
935 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
936 wndPtr->rectNormal = wndpl->rcNormalPosition;
937 ShowWindow16( hwnd, wndpl->showCmd );
942 /***********************************************************************
943 * SetWindowPlacement32 (USER32.518)
945 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
947 WND *wndPtr = WIN_FindWndPtr( hwnd );
948 if (!wndPtr) return FALSE;
950 if (wndpl->flags & WPF_SETMINPOSITION)
951 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
952 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
953 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
954 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
955 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
956 ShowWindow32( hwnd, wndpl->showCmd );
961 /***********************************************************************
962 * WINPOS_ForceXWindowRaise
964 * Raise a window on top of the X stacking order, while preserving
965 * the correct Windows Z order.
967 static void WINPOS_ForceXWindowRaise( WND* pWnd )
969 XWindowChanges winChanges;
972 /* Raise all windows up to pWnd according to their Z order.
973 * (it would be easier with sibling-related Below but it doesn't
974 * work very well with SGI mwm for instance)
976 winChanges.stack_mode = Above;
979 if (pWnd->window) XReconfigureWMWindow( display, pWnd->window, 0,
980 CWStackMode, &winChanges );
981 wndPrev = WIN_GetDesktop()->child;
982 if (wndPrev == pWnd) break;
983 while (wndPrev && (wndPrev->next != pWnd)) wndPrev = wndPrev->next;
989 /*******************************************************************
990 * WINPOS_SetActiveWindow
992 * back-end to SetActiveWindow
994 BOOL32 WINPOS_SetActiveWindow( HWND32 hWnd, BOOL32 fMouse, BOOL32 fChangeFocus)
996 WND *wndPtr = WIN_FindWndPtr(hWnd);
997 WND *wndTemp = WIN_FindWndPtr(hwndActive);
998 CBTACTIVATESTRUCT16 *cbtStruct;
1000 HQUEUE16 hOldActiveQueue = (pActiveQueue)?pActiveQueue->self:0;
1001 HQUEUE16 hNewActiveQueue;
1003 /* paranoid checks */
1004 if( hWnd == GetDesktopWindow32() || hWnd == hwndActive )
1007 /* if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
1012 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1014 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
1016 /* call CBT hook chain */
1017 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
1020 cbtStruct->fMouse = fMouse;
1021 cbtStruct->hWndActive = hwndActive;
1022 wRet = HOOK_CallHooks16( WH_CBT, HCBT_ACTIVATE, (WPARAM16)hWnd,
1023 (LPARAM)SEGPTR_GET(cbtStruct) );
1024 SEGPTR_FREE(cbtStruct);
1025 if (wRet) return wRet;
1028 /* set prev active wnd to current active wnd and send notification */
1029 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
1031 if (!SendMessage16( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
1033 if (GetSysModalWindow16() != hWnd) return 0;
1034 /* disregard refusal if hWnd is sysmodal */
1037 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
1038 MAKEWPARAM( WA_INACTIVE, wIconized ),
1041 /* check if something happened during message processing */
1042 if( hwndPrevActive != hwndActive ) return 0;
1045 /* set active wnd */
1048 /* send palette messages */
1049 if (hWnd && SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
1050 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM16)hWnd, 0L );
1052 /* if prev wnd is minimized redraw icon title
1053 if( hwndPrevActive )
1055 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
1057 if(wndTemp->dwStyle & WS_MINIMIZE)
1058 RedrawIconTitle(hwndPrevActive);
1062 /* managed windows will get ConfigureNotify event */
1063 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
1065 /* check Z-order and bring hWnd to the top */
1066 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
1067 if (wndTemp->dwStyle & WS_VISIBLE) break;
1069 if( wndTemp != wndPtr )
1070 SetWindowPos32(hWnd, HWND_TOP, 0,0,0,0,
1071 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1072 if( !IsWindow(hWnd) ) return 0;
1075 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
1077 /* send WM_ACTIVATEAPP if necessary */
1078 if (hOldActiveQueue != hNewActiveQueue)
1080 WND **list, **ppWnd;
1082 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
1084 for (ppWnd = list; *ppWnd; ppWnd++)
1086 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
1088 if ((*ppWnd)->hmemTaskQ == hOldActiveQueue)
1089 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
1090 0, QUEUE_GetQueueTask(hNewActiveQueue) );
1092 HeapFree( SystemHeap, 0, list );
1095 pActiveQueue = (hNewActiveQueue)
1096 ? (MESSAGEQUEUE*) GlobalLock16(hNewActiveQueue) : NULL;
1098 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
1100 for (ppWnd = list; *ppWnd; ppWnd++)
1102 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
1104 if ((*ppWnd)->hmemTaskQ == hNewActiveQueue)
1105 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
1106 1, QUEUE_GetQueueTask( hOldActiveQueue ) );
1108 HeapFree( SystemHeap, 0, list );
1110 if (!IsWindow(hWnd)) return 0;
1115 /* walk up to the first unowned window */
1117 while (wndTemp->owner) wndTemp = wndTemp->owner;
1118 /* and set last active owned popup */
1119 wndTemp->hwndLastActive = hWnd;
1121 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1122 SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
1123 SendMessage32A( hWnd, WM_ACTIVATE,
1124 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1125 (LPARAM)hwndPrevActive );
1127 if( !IsWindow(hWnd) ) return 0;
1130 /* change focus if possible */
1131 if( fChangeFocus && GetFocus32() )
1132 if( WIN_GetTopParent(GetFocus32()) != hwndActive )
1133 FOCUS_SwitchFocus( GetFocus32(),
1134 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
1136 if( !hwndPrevActive && wndPtr &&
1137 wndPtr->window && !(wndPtr->flags & WIN_MANAGED) )
1138 WINPOS_ForceXWindowRaise(wndPtr);
1140 /* if active wnd is minimized redraw icon title
1143 wndPtr = WIN_FindWndPtr(hwndActive);
1144 if(wndPtr->dwStyle & WS_MINIMIZE)
1145 RedrawIconTitle(hwndActive);
1148 return (hWnd == hwndActive);
1151 /*******************************************************************
1152 * WINPOS_ActivateOtherWindow
1154 * DestroyWindow() helper. pWnd must be a top-level window.
1156 BOOL32 WINPOS_ActivateOtherWindow(WND* pWnd)
1161 if( pWnd->hwndSelf == hwndPrevActive )
1164 if( hwndActive != pWnd->hwndSelf &&
1165 ( hwndActive || QUEUE_IsDoomedQueue(pWnd->hmemTaskQ)) )
1168 if( pWnd->dwStyle & WS_POPUP &&
1169 WINPOS_IsGoodEnough( pWnd->owner ) ) pWndTo = pWnd->owner;
1172 WND* pWndPtr = pWnd;
1174 pWndTo = WIN_FindWndPtr(hwndPrevActive);
1176 while( !WINPOS_IsGoodEnough(pWndTo) )
1178 /* by now owned windows should've been taken care of */
1180 pWndTo = pWndPtr->next;
1182 if( !pWndTo ) return 0;
1186 bRet = WINPOS_SetActiveWindow( pWndTo->hwndSelf, FALSE, TRUE );
1188 /* switch desktop queue to current active */
1189 if( pWndTo->parent == WIN_GetDesktop())
1190 WIN_GetDesktop()->hmemTaskQ = pWndTo->hmemTaskQ;
1196 /*******************************************************************
1197 * WINPOS_ChangeActiveWindow
1200 BOOL32 WINPOS_ChangeActiveWindow( HWND32 hWnd, BOOL32 mouseMsg )
1202 WND *wndPtr = WIN_FindWndPtr(hWnd);
1204 if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE );
1206 if( !wndPtr ) return FALSE;
1208 /* child windows get WM_CHILDACTIVATE message */
1209 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1210 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1212 /* owned popups imply owner activation - not sure */
1213 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1214 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1216 if (!(wndPtr = wndPtr->owner)) return FALSE;
1217 hWnd = wndPtr->hwndSelf;
1220 if( hWnd == hwndActive ) return FALSE;
1222 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1225 /* switch desktop queue to current active */
1226 if( wndPtr->parent == WIN_GetDesktop())
1227 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1233 /***********************************************************************
1234 * WINPOS_SendNCCalcSize
1236 * Send a WM_NCCALCSIZE message to a window.
1237 * All parameters are read-only except newClientRect.
1238 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1239 * when calcValidRect is TRUE.
1241 LONG WINPOS_SendNCCalcSize( HWND32 hwnd, BOOL32 calcValidRect,
1242 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1243 RECT16 *oldClientRect, SEGPTR winpos,
1244 RECT16 *newClientRect )
1246 NCCALCSIZE_PARAMS16 *params;
1249 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1250 params->rgrc[0] = *newWindowRect;
1253 params->rgrc[1] = *oldWindowRect;
1254 params->rgrc[2] = *oldClientRect;
1255 params->lppos = winpos;
1257 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1258 (LPARAM)SEGPTR_GET( params ) );
1259 dprintf_win( stddeb, "WINPOS_SendNCCalcSize: %d,%d-%d,%d\n",
1260 params->rgrc[0].left, params->rgrc[0].top,
1261 params->rgrc[0].right, params->rgrc[0].bottom );
1262 *newClientRect = params->rgrc[0];
1263 SEGPTR_FREE(params);
1268 /***********************************************************************
1269 * WINPOS_HandleWindowPosChanging16
1271 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1273 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1276 if (winpos->flags & SWP_NOSIZE) return 0;
1277 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1278 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1280 NC_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL );
1281 winpos->cx = MIN( winpos->cx, maxSize.x );
1282 winpos->cy = MIN( winpos->cy, maxSize.y );
1288 /***********************************************************************
1289 * WINPOS_HandleWindowPosChanging32
1291 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1293 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1296 if (winpos->flags & SWP_NOSIZE) return 0;
1297 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1298 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1300 NC_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL );
1301 winpos->cx = MIN( winpos->cx, maxSize.x );
1302 winpos->cy = MIN( winpos->cy, maxSize.y );
1308 /***********************************************************************
1309 * WINPOS_MoveWindowZOrder
1311 * Move a window in Z order, invalidating everything that needs it.
1312 * Only necessary for windows without associated X window.
1314 static void WINPOS_MoveWindowZOrder( HWND32 hwnd, HWND32 hwndAfter )
1317 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1319 /* We have two possible cases:
1320 * - The window is moving up: we have to invalidate all areas
1321 * of the window that were covered by other windows
1322 * - The window is moving down: we have to invalidate areas
1323 * of other windows covered by this one.
1326 if (hwndAfter == HWND_TOP)
1330 else if (hwndAfter == HWND_BOTTOM)
1332 if (!wndPtr->next) return; /* Already at the bottom */
1337 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1338 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1340 /* Determine which window we encounter first in Z-order */
1341 pWndCur = wndPtr->parent->child;
1342 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1343 pWndCur = pWndCur->next;
1344 movingUp = (pWndCur == pWndAfter);
1349 WND *pWndPrevAfter = wndPtr->next;
1350 WIN_UnlinkWindow( hwnd );
1351 WIN_LinkWindow( hwnd, hwndAfter );
1352 pWndCur = wndPtr->next;
1353 while (pWndCur != pWndPrevAfter)
1355 RECT32 rect = { pWndCur->rectWindow.left,
1356 pWndCur->rectWindow.top,
1357 pWndCur->rectWindow.right,
1358 pWndCur->rectWindow.bottom };
1359 OffsetRect32( &rect, -wndPtr->rectClient.left,
1360 -wndPtr->rectClient.top );
1361 PAINT_RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1362 RDW_FRAME | RDW_ERASE, 0 );
1363 pWndCur = pWndCur->next;
1366 else /* Moving down */
1368 pWndCur = wndPtr->next;
1369 WIN_UnlinkWindow( hwnd );
1370 WIN_LinkWindow( hwnd, hwndAfter );
1371 while (pWndCur != wndPtr)
1373 RECT32 rect = { pWndCur->rectWindow.left,
1374 pWndCur->rectWindow.top,
1375 pWndCur->rectWindow.right,
1376 pWndCur->rectWindow.bottom };
1377 OffsetRect32( &rect, -pWndCur->rectClient.left,
1378 -pWndCur->rectClient.top );
1379 PAINT_RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1380 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1381 pWndCur = pWndCur->next;
1386 /***********************************************************************
1387 * WINPOS_ReorderOwnedPopups
1389 * fix Z order taking into account owned popups -
1390 * basically we need to maintain them above owner window
1392 HWND32 WINPOS_ReorderOwnedPopups(HWND32 hwndInsertAfter,WND* wndPtr,WORD flags)
1394 WND* w = WIN_GetDesktop()->child;
1396 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner )
1398 /* implement "local z-order" between the top and owner window */
1400 HWND32 hwndLocalPrev = HWND_TOP;
1402 if( hwndInsertAfter != HWND_TOP )
1404 while( w != wndPtr->owner )
1406 if (w != wndPtr) hwndLocalPrev = w->hwndSelf;
1407 if( hwndLocalPrev == hwndInsertAfter ) break;
1410 hwndInsertAfter = hwndLocalPrev;
1414 else if( wndPtr->dwStyle & WS_CHILD ) return hwndInsertAfter;
1416 w = WIN_GetDesktop()->child;
1419 if( w == wndPtr ) break;
1421 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1423 SetWindowPos32(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1424 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1425 hwndInsertAfter = w->hwndSelf;
1430 return hwndInsertAfter;
1433 /***********************************************************************
1434 * WINPOS_SizeMoveClean
1436 * Make window look nice without excessive repainting
1440 * visible regions are in window coordinates
1441 * update regions are in window client coordinates
1442 * client and window rectangles are in parent client coordinates
1444 static UINT32 WINPOS_SizeMoveClean(WND* Wnd, HRGN32 oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, UINT32 uFlags )
1446 HRGN32 newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf,DCX_WINDOW | DCX_CLIPSIBLINGS);
1447 HRGN32 dirtyRgn = CreateRectRgn32(0,0,0,0);
1450 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1451 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1452 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1453 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1454 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1455 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1457 if( (lpOldWndRect->right - lpOldWndRect->left) != (Wnd->rectWindow.right - Wnd->rectWindow.left) ||
1458 (lpOldWndRect->bottom - lpOldWndRect->top) != (Wnd->rectWindow.bottom - Wnd->rectWindow.top) )
1459 uFlags |= SMC_DRAWFRAME;
1461 CombineRgn32( dirtyRgn, newVisRgn, 0, RGN_COPY);
1463 if( !(uFlags & SMC_NOCOPY) )
1464 CombineRgn32( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1466 /* map regions to the parent client area */
1468 OffsetRgn32( dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top );
1469 OffsetRgn32( oldVisRgn, lpOldWndRect->left, lpOldWndRect->top );
1471 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1473 other = CombineRgn32(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1475 /* map visible region to the Wnd client area */
1477 OffsetRgn32( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1478 Wnd->rectWindow.top - Wnd->rectClient.top );
1480 /* substract previously invalidated region from the Wnd visible region */
1482 my = (Wnd->hrgnUpdate > 1) ? CombineRgn32( newVisRgn, newVisRgn,
1483 Wnd->hrgnUpdate, RGN_DIFF)
1486 if( uFlags & SMC_NOCOPY ) /* invalidate Wnd visible region */
1488 if (my != NULLREGION)
1489 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1490 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1491 else if(uFlags & SMC_DRAWFRAME)
1492 Wnd->flags |= WIN_NEEDS_NCPAINT;
1494 else /* bitblt old client area */
1499 int xfrom,yfrom,xto,yto,width,height;
1501 if( uFlags & SMC_DRAWFRAME )
1503 /* copy only client area, frame will be redrawn anyway */
1505 xfrom = lpOldClientRect->left; yfrom = lpOldClientRect->top;
1506 xto = Wnd->rectClient.left; yto = Wnd->rectClient.top;
1507 width = lpOldClientRect->right - xfrom; height = lpOldClientRect->bottom - yfrom;
1508 updateRgn = CreateRectRgn32( 0, 0, width, height );
1509 CombineRgn32( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1510 SetRectRgn( updateRgn, 0, 0, Wnd->rectClient.right - xto, Wnd->rectClient.bottom - yto );
1514 xfrom = lpOldWndRect->left; yfrom = lpOldWndRect->top;
1515 xto = Wnd->rectWindow.left; yto = Wnd->rectWindow.top;
1516 width = lpOldWndRect->right - xfrom; height = lpOldWndRect->bottom - yfrom;
1517 updateRgn = CreateRectRgn32( xto - Wnd->rectClient.left,
1518 yto - Wnd->rectClient.top,
1519 Wnd->rectWindow.right - Wnd->rectClient.left,
1520 Wnd->rectWindow.bottom - Wnd->rectClient.top );
1523 CombineRgn32( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1525 /* substract new visRgn from target rect to get a region that won't be copied */
1527 update = CombineRgn32( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1529 /* Blt valid bits using parent window DC */
1531 if( my != NULLREGION && (xfrom != xto || yfrom != yto) )
1534 /* compute clipping region in parent client coordinates */
1536 OffsetRgn32( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top );
1537 CombineRgn32( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1539 hDC = GetDCEx32( Wnd->parent->hwndSelf, oldVisRgn,
1540 DCX_KEEPCLIPRGN | DCX_INTERSECTRGN |
1541 DCX_CACHE | DCX_CLIPSIBLINGS);
1543 BitBlt32( hDC, xto, yto, width, height, hDC, xfrom, yfrom, SRCCOPY );
1544 ReleaseDC32( Wnd->parent->hwndSelf, hDC);
1547 if( update != NULLREGION )
1548 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1549 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1550 else if( uFlags & SMC_DRAWFRAME ) Wnd->flags |= WIN_NEEDS_NCPAINT;
1551 DeleteObject32( updateRgn );
1554 /* erase uncovered areas */
1556 if( !(uFlags & SMC_NOPARENTERASE) && (other != NULLREGION ) )
1557 PAINT_RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1558 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1559 DeleteObject32(dirtyRgn);
1560 DeleteObject32(newVisRgn);
1565 /***********************************************************************
1566 * WINPOS_FindDeskTopXWindow
1568 * Find the actual X window which needs be restacked.
1569 * Used by WINPOS_SetXWindowPos().
1571 static Window WINPOS_FindDeskTopXWindow( WND *wndPtr )
1573 if (!(wndPtr->flags & WIN_MANAGED))
1574 return wndPtr->window;
1577 Window window, root, parent, *children;
1579 window = wndPtr->window;
1582 XQueryTree( display, window, &root, &parent,
1583 &children, &nchildren );
1592 /***********************************************************************
1593 * WINPOS_SetXWindowPos
1595 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1597 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1599 XWindowChanges winChanges;
1601 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1603 if (!(winpos->flags & SWP_NOSIZE))
1605 winChanges.width = winpos->cx;
1606 winChanges.height = winpos->cy;
1607 changeMask |= CWWidth | CWHeight;
1609 /* Tweak dialog window size hints */
1611 if ((wndPtr->flags & WIN_MANAGED) &&
1612 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1614 XSizeHints *size_hints = XAllocSizeHints();
1618 long supplied_return;
1620 XGetWMSizeHints( display, wndPtr->window, size_hints,
1621 &supplied_return, XA_WM_NORMAL_HINTS);
1622 size_hints->min_width = size_hints->max_width = winpos->cx;
1623 size_hints->min_height = size_hints->max_height = winpos->cy;
1624 XSetWMSizeHints( display, wndPtr->window, size_hints,
1625 XA_WM_NORMAL_HINTS );
1630 if (!(winpos->flags & SWP_NOMOVE))
1632 winChanges.x = winpos->x;
1633 winChanges.y = winpos->y;
1634 changeMask |= CWX | CWY;
1636 if (!(winpos->flags & SWP_NOZORDER))
1638 winChanges.stack_mode = Below;
1639 changeMask |= CWStackMode;
1641 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1642 else if (winpos->hwndInsertAfter != HWND_BOTTOM)
1644 WND* insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1647 stack[0] = WINPOS_FindDeskTopXWindow( insertPtr );
1648 stack[1] = WINPOS_FindDeskTopXWindow( wndPtr );
1650 /* for stupid window managers (i.e. all of them) */
1652 XRestackWindows(display, stack, 2);
1653 changeMask &= ~CWStackMode;
1656 if (!changeMask) return;
1658 XReconfigureWMWindow( display, wndPtr->window, 0, changeMask, &winChanges );
1662 /***********************************************************************
1663 * SetWindowPos (USER.232)
1665 BOOL16 SetWindowPos16( HWND16 hwnd, HWND16 hwndInsertAfter, INT16 x, INT16 y,
1666 INT16 cx, INT16 cy, WORD flags )
1668 return SetWindowPos32(hwnd,(INT32)(INT16)hwndInsertAfter,x,y,cx,cy,flags);
1671 /***********************************************************************
1672 * SetWindowPos (USER32.519)
1674 BOOL32 SetWindowPos32( HWND32 hwnd, HWND32 hwndInsertAfter, INT32 x, INT32 y,
1675 INT32 cx, INT32 cy, WORD flags )
1677 WINDOWPOS16 *winpos;
1679 RECT16 newWindowRect, newClientRect, oldWindowRect;
1681 HWND32 tempInsertAfter= 0;
1685 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
1686 hwnd, x, y, x+cx, y+cy, flags);
1687 /* Check window handle */
1689 if (hwnd == GetDesktopWindow32()) return FALSE;
1690 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1692 if (wndPtr->dwStyle & WS_VISIBLE) flags &= ~SWP_SHOWWINDOW;
1695 uFlags |= SMC_NOPARENTERASE;
1696 flags &= ~SWP_HIDEWINDOW;
1697 if (!(flags & SWP_SHOWWINDOW)) flags |= SWP_NOREDRAW;
1700 /* Check for windows that may not be resized
1701 FIXME: this should be done only for Windows 3.0 programs
1702 if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
1703 flags |= SWP_NOSIZE | SWP_NOMOVE;
1705 /* Check dimensions */
1707 if (cx <= 0) cx = 1;
1708 if (cy <= 0) cy = 1;
1712 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1713 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1714 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1715 flags |= SWP_NOSIZE; /* Already the right size */
1716 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1717 flags |= SWP_NOMOVE; /* Already the right position */
1719 /* Check hwndInsertAfter */
1721 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1723 /* Ignore TOPMOST flags when activating a window */
1724 /* _and_ moving it in Z order. */
1725 if ((hwndInsertAfter == HWND_TOPMOST) ||
1726 (hwndInsertAfter == HWND_NOTOPMOST))
1727 hwndInsertAfter = HWND_TOP;
1729 /* TOPMOST not supported yet */
1730 if ((hwndInsertAfter == HWND_TOPMOST) ||
1731 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1733 /* hwndInsertAfter must be a sibling of the window */
1734 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1736 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1737 if( wnd->parent != wndPtr->parent ) return FALSE;
1738 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1740 else if (!(wndPtr->window))
1741 /* FIXME: the following optimization is no good for "X-ed" windows */
1742 if (hwndInsertAfter == HWND_TOP)
1743 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1744 else /* HWND_BOTTOM */
1745 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1747 /* Fill the WINDOWPOS structure */
1749 if (!(winpos = SEGPTR_NEW(WINDOWPOS16))) return FALSE;
1750 winpos->hwnd = hwnd;
1751 winpos->hwndInsertAfter = hwndInsertAfter;
1756 winpos->flags = flags;
1758 /* Send WM_WINDOWPOSCHANGING message */
1760 if (!(flags & SWP_NOSENDCHANGING))
1761 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0,
1762 (LPARAM)SEGPTR_GET(winpos) );
1764 /* Calculate new position and size */
1766 newWindowRect = wndPtr->rectWindow;
1767 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1768 : wndPtr->rectClient;
1770 if (!(winpos->flags & SWP_NOSIZE))
1772 newWindowRect.right = newWindowRect.left + winpos->cx;
1773 newWindowRect.bottom = newWindowRect.top + winpos->cy;
1775 if (!(winpos->flags & SWP_NOMOVE))
1777 newWindowRect.left = winpos->x;
1778 newWindowRect.top = winpos->y;
1779 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
1780 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
1782 OffsetRect16( &newClientRect, winpos->x - wndPtr->rectWindow.left,
1783 winpos->y - wndPtr->rectWindow.top );
1786 winpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1788 /* Reposition window in Z order */
1790 if (!(winpos->flags & SWP_NOZORDER))
1792 /* reorder owned popups if hwnd is top-level window
1794 if( wndPtr->parent == WIN_GetDesktop() )
1795 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1800 WIN_UnlinkWindow( winpos->hwnd );
1801 WIN_LinkWindow( winpos->hwnd, hwndInsertAfter );
1803 else WINPOS_MoveWindowZOrder( winpos->hwnd, hwndInsertAfter );
1806 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1807 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1808 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1811 /* Send WM_NCCALCSIZE message to get new client area */
1812 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1814 result = WINPOS_SendNCCalcSize( winpos->hwnd, TRUE, &newWindowRect,
1815 &wndPtr->rectWindow, &wndPtr->rectClient,
1816 SEGPTR_GET(winpos), &newClientRect );
1818 /* FIXME: WVR_ALIGNxxx */
1820 if( newClientRect.left != wndPtr->rectClient.left ||
1821 newClientRect.top != wndPtr->rectClient.top )
1822 winpos->flags &= ~SWP_NOCLIENTMOVE;
1824 if( (newClientRect.right - newClientRect.left !=
1825 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1826 (newClientRect.bottom - newClientRect.top !=
1827 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1828 winpos->flags &= ~SWP_NOCLIENTSIZE;
1831 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1832 newClientRect.top != wndPtr->rectClient.top) )
1833 winpos->flags &= ~SWP_NOCLIENTMOVE;
1835 /* Update active DCEs */
1837 if( !(flags & SWP_NOZORDER) || (flags & SWP_HIDEWINDOW) || (flags & SWP_SHOWWINDOW)
1838 || (memcmp(&newWindowRect,&wndPtr->rectWindow,sizeof(RECT16))
1839 && wndPtr->dwStyle & WS_VISIBLE ) )
1843 UnionRect16(&rect,&newWindowRect,&wndPtr->rectWindow);
1844 DCE_InvalidateDCE(wndPtr->parent, &rect);
1847 /* change geometry */
1849 oldWindowRect = wndPtr->rectWindow;
1853 RECT16 oldClientRect = wndPtr->rectClient;
1855 tempInsertAfter = winpos->hwndInsertAfter;
1857 winpos->hwndInsertAfter = hwndInsertAfter;
1859 /* postpone geometry change */
1861 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1863 WINPOS_SetXWindowPos( winpos );
1864 winpos->hwndInsertAfter = tempInsertAfter;
1866 else uFlags |= SMC_SETXPOS;
1868 wndPtr->rectWindow = newWindowRect;
1869 wndPtr->rectClient = newClientRect;
1871 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1872 if( (oldClientRect.left - oldWindowRect.left !=
1873 newClientRect.left - newWindowRect.left) ||
1874 (oldClientRect.top - oldWindowRect.top !=
1875 newClientRect.top - newWindowRect.top) || winpos->flags & SWP_NOCOPYBITS )
1877 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
1878 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1880 if( winpos->flags & SWP_FRAMECHANGED )
1885 if( oldClientRect.right > newClientRect.right )
1887 rect.left = newClientRect.right; rect.top = newClientRect.top;
1888 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1890 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1891 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1893 if( oldClientRect.bottom > newClientRect.bottom )
1895 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1896 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1897 rect.bottom = oldClientRect.bottom;
1899 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1900 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1902 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1907 RECT16 oldClientRect = wndPtr->rectClient;
1909 wndPtr->rectWindow = newWindowRect;
1910 wndPtr->rectClient = newClientRect;
1912 if( oldClientRect.bottom - oldClientRect.top ==
1913 newClientRect.bottom - newClientRect.top ) result &= ~WVR_VREDRAW;
1915 if( oldClientRect.right - oldClientRect.left ==
1916 newClientRect.right - newClientRect.left ) result &= ~WVR_HREDRAW;
1918 if( !(flags & (SWP_NOREDRAW | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
1920 uFlags |= ((winpos->flags & SWP_NOCOPYBITS) ||
1921 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS)) ? SMC_NOCOPY : 0;
1922 uFlags |= (winpos->flags & SWP_FRAMECHANGED) ? SMC_DRAWFRAME : 0;
1924 if( (winpos->flags & SWP_AGG_NOGEOMETRYCHANGE) != SWP_AGG_NOGEOMETRYCHANGE )
1925 uFlags = WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect,
1926 &oldClientRect, uFlags);
1929 /* adjust frame and do not erase parent */
1931 if( winpos->flags & SWP_FRAMECHANGED ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1932 if( winpos->flags & SWP_NOZORDER ) uFlags |= SMC_NOPARENTERASE;
1935 DeleteObject32(visRgn);
1938 if (flags & SWP_SHOWWINDOW)
1940 wndPtr->dwStyle |= WS_VISIBLE;
1943 if( uFlags & SMC_SETXPOS )
1945 WINPOS_SetXWindowPos( winpos );
1946 winpos->hwndInsertAfter = tempInsertAfter;
1948 XMapWindow( display, wndPtr->window );
1952 if (!(flags & SWP_NOREDRAW))
1953 PAINT_RedrawWindow( winpos->hwnd, NULL, 0,
1954 RDW_INVALIDATE | RDW_ALLCHILDREN |
1955 RDW_FRAME | RDW_ERASENOW | RDW_ERASE, 0 );
1958 else if (flags & SWP_HIDEWINDOW)
1960 wndPtr->dwStyle &= ~WS_VISIBLE;
1963 XUnmapWindow( display, wndPtr->window );
1964 if( uFlags & SMC_SETXPOS )
1966 WINPOS_SetXWindowPos( winpos );
1967 winpos->hwndInsertAfter = tempInsertAfter;
1972 if (!(flags & SWP_NOREDRAW))
1974 RECT32 rect = { oldWindowRect.left, oldWindowRect.top,
1975 oldWindowRect.right, oldWindowRect.bottom };
1976 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, &rect, 0,
1977 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE | RDW_ERASENOW, 0);
1979 uFlags |= SMC_NOPARENTERASE;
1982 if ((winpos->hwnd == GetFocus32()) ||
1983 IsChild32( winpos->hwnd, GetFocus32()))
1985 /* Revert focus to parent */
1986 SetFocus32( GetParent32(winpos->hwnd) );
1988 if (hwnd == CARET_GetHwnd()) DestroyCaret();
1990 if (winpos->hwnd == hwndActive)
1992 /* Activate previously active window if possible */
1993 HWND32 newActive = hwndPrevActive;
1994 if (!IsWindow(newActive) || (newActive == winpos->hwnd))
1996 newActive = GetTopWindow32( GetDesktopWindow32() );
1997 if (newActive == winpos->hwnd)
1998 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
2000 WINPOS_ChangeActiveWindow( newActive, FALSE );
2004 /* Activate the window */
2006 if (!(flags & SWP_NOACTIVATE))
2007 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
2009 /* Repaint the window */
2011 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
2013 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
2015 if (!(flags & SWP_DEFERERASE) && !(uFlags & SMC_NOPARENTERASE) )
2018 CONV_RECT16TO32( &oldWindowRect, &rect );
2019 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, (wndPtr->flags & WIN_SAVEUNDER_OVERRIDE)
2020 ? &rect : NULL, 0, RDW_ALLCHILDREN | RDW_ERASENOW |
2021 ((wndPtr->flags & WIN_SAVEUNDER_OVERRIDE) ? RDW_INVALIDATE : 0), 0 );
2022 wndPtr->flags &= ~WIN_SAVEUNDER_OVERRIDE;
2024 else if( wndPtr->parent == WIN_GetDesktop() && wndPtr->parent->flags & WIN_NEEDS_ERASEBKGND )
2025 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_NOCHILDREN | RDW_ERASENOW, 0 );
2027 /* And last, send the WM_WINDOWPOSCHANGED message */
2029 dprintf_win(stddeb,"\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
2031 if ( ((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
2032 !(winpos->flags & SWP_NOSENDCHANGING))
2033 SendMessage16( winpos->hwnd, WM_WINDOWPOSCHANGED,
2034 0, (LPARAM)SEGPTR_GET(winpos) );
2036 SEGPTR_FREE(winpos);
2041 /***********************************************************************
2042 * BeginDeferWindowPos16 (USER.259)
2044 HDWP16 BeginDeferWindowPos16( INT16 count )
2046 return BeginDeferWindowPos32( count );
2050 /***********************************************************************
2051 * BeginDeferWindowPos32 (USER32.8)
2053 HDWP32 BeginDeferWindowPos32( INT32 count )
2058 if (count <= 0) return 0;
2059 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS32) );
2060 if (!handle) return 0;
2061 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
2062 pDWP->actualCount = 0;
2063 pDWP->suggestedCount = count;
2065 pDWP->wMagic = DWP_MAGIC;
2066 pDWP->hwndParent = 0;
2071 /***********************************************************************
2072 * DeferWindowPos16 (USER.260)
2074 HDWP16 DeferWindowPos16( HDWP16 hdwp, HWND16 hwnd, HWND16 hwndAfter,
2075 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags )
2077 return DeferWindowPos32( hdwp, hwnd, (INT32)(INT16)hwndAfter,
2078 x, y, cx, cy, flags );
2082 /***********************************************************************
2083 * DeferWindowPos32 (USER32.127)
2085 HDWP32 DeferWindowPos32( HDWP32 hdwp, HWND32 hwnd, HWND32 hwndAfter,
2086 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags )
2090 HDWP32 newhdwp = hdwp;
2093 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2094 if (!pDWP) return 0;
2095 if (hwnd == GetDesktopWindow32()) return 0;
2097 /* All the windows of a DeferWindowPos() must have the same parent */
2099 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
2100 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
2101 else if (parent != pDWP->hwndParent)
2103 USER_HEAP_FREE( hdwp );
2107 for (i = 0; i < pDWP->actualCount; i++)
2109 if (pDWP->winPos[i].hwnd == hwnd)
2111 /* Merge with the other changes */
2112 if (!(flags & SWP_NOZORDER))
2114 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
2116 if (!(flags & SWP_NOMOVE))
2118 pDWP->winPos[i].x = x;
2119 pDWP->winPos[i].y = y;
2121 if (!(flags & SWP_NOSIZE))
2123 pDWP->winPos[i].cx = cx;
2124 pDWP->winPos[i].cy = cy;
2126 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
2127 SWP_NOZORDER | SWP_NOREDRAW |
2128 SWP_NOACTIVATE | SWP_NOCOPYBITS |
2130 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
2135 if (pDWP->actualCount >= pDWP->suggestedCount)
2137 newhdwp = USER_HEAP_REALLOC( hdwp,
2138 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS32) );
2139 if (!newhdwp) return 0;
2140 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
2141 pDWP->suggestedCount++;
2143 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
2144 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
2145 pDWP->winPos[pDWP->actualCount].x = x;
2146 pDWP->winPos[pDWP->actualCount].y = y;
2147 pDWP->winPos[pDWP->actualCount].cx = cx;
2148 pDWP->winPos[pDWP->actualCount].cy = cy;
2149 pDWP->winPos[pDWP->actualCount].flags = flags;
2150 pDWP->actualCount++;
2155 /***********************************************************************
2156 * EndDeferWindowPos16 (USER.261)
2158 BOOL16 EndDeferWindowPos16( HDWP16 hdwp )
2160 return EndDeferWindowPos32( hdwp );
2164 /***********************************************************************
2165 * EndDeferWindowPos32 (USER32.172)
2167 BOOL32 EndDeferWindowPos32( HDWP32 hdwp )
2170 WINDOWPOS32 *winpos;
2174 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
2175 if (!pDWP) return FALSE;
2176 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
2178 if (!(res = SetWindowPos32( winpos->hwnd, winpos->hwndInsertAfter,
2179 winpos->x, winpos->y, winpos->cx,
2180 winpos->cy, winpos->flags ))) break;
2182 USER_HEAP_FREE( hdwp );
2187 /***********************************************************************
2188 * TileChildWindows (USER.199)
2190 void TileChildWindows( HWND16 parent, WORD action )
2192 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
2195 /***********************************************************************
2196 * CascageChildWindows (USER.198)
2198 void CascadeChildWindows( HWND16 parent, WORD action )
2200 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);