2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
10 #include <X11/Xatom.h>
11 #include "sysmetrics.h"
19 #include "stackframe.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 /* ----- external functions ----- */
37 extern void FOCUS_SwitchFocus( HWND , HWND );
38 extern HRGN DCE_GetVisRgn( HWND, WORD );
39 extern HWND CARET_GetHwnd();
40 extern BOOL DCE_InvalidateDCE(WND*, RECT16* );
42 /* ----- internal variables ----- */
44 static HWND hwndActive = 0; /* Currently active window */
45 static HWND hwndPrevActive = 0; /* Previously active window */
47 /***********************************************************************
50 * Find a suitable place for an iconic window.
51 * The new position is stored into wndPtr->ptIconPos.
53 void WINPOS_FindIconPos( HWND hwnd )
56 short x, y, xspacing, yspacing;
57 WND * wndPtr = WIN_FindWndPtr( hwnd );
59 if (!wndPtr || !wndPtr->parent) return;
60 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
61 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
62 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
63 (wndPtr->ptIconPos.y >= rectParent.top) &&
64 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
65 return; /* The icon already has a suitable position */
67 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
68 y = rectParent.bottom;
71 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
73 /* Check if another icon already occupies this spot */
74 WND *childPtr = wndPtr->parent->child;
77 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
79 if ((childPtr->rectWindow.left < x + xspacing) &&
80 (childPtr->rectWindow.right >= x) &&
81 (childPtr->rectWindow.top <= y) &&
82 (childPtr->rectWindow.bottom > y - yspacing))
83 break; /* There's a window in there */
85 childPtr = childPtr->next;
89 /* No window was found, so it's OK for us */
90 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
91 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
100 /***********************************************************************
101 * ArrangeIconicWindows (USER.170)
103 UINT ArrangeIconicWindows( HWND parent )
107 INT x, y, xspacing, yspacing;
109 GetClientRect16( parent, &rectParent );
111 y = rectParent.bottom;
112 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
113 hwndChild = GetWindow( parent, GW_CHILD );
116 if (IsIconic( hwndChild ))
118 SetWindowPos( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
119 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
120 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
121 if (x <= rectParent.right - xspacing) x += xspacing;
128 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
134 /***********************************************************************
135 * GetWindowRect16 (USER.32)
137 void GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
139 WND * wndPtr = WIN_FindWndPtr( hwnd );
142 *rect = wndPtr->rectWindow;
143 if (wndPtr->dwStyle & WS_CHILD)
144 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
148 /***********************************************************************
149 * GetWindowRect32 (USER.32)
151 void GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
153 WND * wndPtr = WIN_FindWndPtr( hwnd );
156 CONV_RECT16TO32( &wndPtr->rectWindow, rect );
157 if (wndPtr->dwStyle & WS_CHILD)
158 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
162 /***********************************************************************
163 * GetClientRect16 (USER.33)
165 void GetClientRect16( HWND16 hwnd, LPRECT16 rect )
167 WND * wndPtr = WIN_FindWndPtr( hwnd );
169 rect->left = rect->top = rect->right = rect->bottom = 0;
172 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
173 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
178 /***********************************************************************
179 * GetClientRect32 (USER32.219)
181 void GetClientRect32( HWND32 hwnd, LPRECT32 rect )
183 WND * wndPtr = WIN_FindWndPtr( hwnd );
185 rect->left = rect->top = rect->right = rect->bottom = 0;
188 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
189 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
194 /*******************************************************************
195 * ClientToScreen16 (USER.28)
197 BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
199 MapWindowPoints16( hwnd, 0, lppnt, 1 );
204 /*******************************************************************
205 * ClientToScreen32 (USER32.51)
207 BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
209 MapWindowPoints32( hwnd, 0, lppnt, 1 );
214 /*******************************************************************
215 * ScreenToClient16 (USER.29)
217 void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
219 MapWindowPoints16( 0, hwnd, lppnt, 1 );
223 /*******************************************************************
224 * ScreenToClient32 (USER32.446)
226 void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
228 MapWindowPoints32( 0, hwnd, lppnt, 1 );
232 /***********************************************************************
233 * WINPOS_WindowFromPoint
235 * Find the window and hittest for a given point.
237 INT16 WINPOS_WindowFromPoint( POINT16 pt, WND **ppWnd )
240 INT16 hittest = HTERROR;
246 wndPtr = WIN_GetDesktop()->child;
251 /* If point is in window, and window is visible, and it */
252 /* is enabled (or it's a top-level window), then explore */
253 /* its children. Otherwise, go to the next window. */
255 if ((wndPtr->dwStyle & WS_VISIBLE) &&
256 (!(wndPtr->dwStyle & WS_DISABLED) ||
257 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
258 (x >= wndPtr->rectWindow.left) &&
259 (x < wndPtr->rectWindow.right) &&
260 (y >= wndPtr->rectWindow.top) &&
261 (y < wndPtr->rectWindow.bottom))
263 *ppWnd = wndPtr; /* Got a suitable window */
265 /* If window is minimized or disabled, return at once */
266 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
267 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
269 /* If point is not in client area, ignore the children */
270 if ((x < wndPtr->rectClient.left) ||
271 (x >= wndPtr->rectClient.right) ||
272 (y < wndPtr->rectClient.top) ||
273 (y >= wndPtr->rectClient.bottom)) break;
275 x -= wndPtr->rectClient.left;
276 y -= wndPtr->rectClient.top;
277 wndPtr = wndPtr->child;
279 else wndPtr = wndPtr->next;
282 /* If nothing found, return the desktop window */
285 *ppWnd = WIN_GetDesktop();
289 /* Send the WM_NCHITTEST message (only if to the same task) */
290 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
291 hittest = (INT)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
292 MAKELONG( pt.x, pt.y ) );
293 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
295 /* If no children found in last search, make point relative to parent*/
298 x += (*ppWnd)->rectClient.left;
299 y += (*ppWnd)->rectClient.top;
302 /* Restart the search from the next sibling */
303 wndPtr = (*ppWnd)->next;
304 *ppWnd = (*ppWnd)->parent;
309 /*******************************************************************
310 * WindowFromPoint16 (USER.30)
312 HWND16 WindowFromPoint16( POINT16 pt )
315 WINPOS_WindowFromPoint( pt, &pWnd );
316 return pWnd->hwndSelf;
320 /*******************************************************************
321 * WindowFromPoint32 (USER32.581)
323 HWND32 WindowFromPoint32( POINT32 pt )
327 CONV_POINT32TO16( &pt, &pt16 );
328 WINPOS_WindowFromPoint( pt16, &pWnd );
329 return (HWND32)pWnd->hwndSelf;
333 /*******************************************************************
334 * ChildWindowFromPoint16 (USER.191)
336 HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
338 /* pt is in the client coordinates */
340 WND* wnd = WIN_FindWndPtr(hwndParent);
345 /* get client rect fast */
346 rect.top = rect.left = 0;
347 rect.right = wnd->rectClient.right - wnd->rectClient.left;
348 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
350 if (!PtInRect16( &rect, pt )) return 0;
355 if (PtInRect16( &wnd->rectWindow, pt )) return wnd->hwndSelf;
362 /*******************************************************************
363 * ChildWindowFromPoint32 (USER32.)
365 HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
368 CONV_POINT32TO16( &pt, &pt16 );
369 return (HWND32)ChildWindowFromPoint16( hwndParent, pt16 );
373 /*******************************************************************
374 * WINPOS_GetWinOffset
376 * Calculate the offset between the origin of the two windows. Used
377 * to implement MapWindowPoints.
379 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
384 offset->x = offset->y = 0;
385 if (hwndFrom == hwndTo ) return;
387 /* Translate source window origin to screen coords */
390 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
392 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
395 while (wndPtr->parent)
397 offset->x += wndPtr->rectClient.left;
398 offset->y += wndPtr->rectClient.top;
399 wndPtr = wndPtr->parent;
403 /* Translate origin to destination window coords */
406 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
408 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
411 while (wndPtr->parent)
413 offset->x -= wndPtr->rectClient.left;
414 offset->y -= wndPtr->rectClient.top;
415 wndPtr = wndPtr->parent;
421 /*******************************************************************
422 * MapWindowPoints16 (USER.258)
424 void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
425 LPPOINT16 lppt, UINT16 count )
429 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
439 /*******************************************************************
440 * MapWindowPoints32 (USER32.385)
442 void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
443 LPPOINT32 lppt, UINT32 count )
447 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
457 /***********************************************************************
460 BOOL IsIconic(HWND hWnd)
462 WND * wndPtr = WIN_FindWndPtr(hWnd);
463 if (wndPtr == NULL) return FALSE;
464 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
468 /***********************************************************************
469 * IsZoomed (USER.272)
471 BOOL IsZoomed(HWND hWnd)
473 WND * wndPtr = WIN_FindWndPtr(hWnd);
474 if (wndPtr == NULL) return FALSE;
475 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
479 /*******************************************************************
480 * GetActiveWindow (USER.60)
482 HWND GetActiveWindow()
488 /*******************************************************************
489 * SetActiveWindow (USER.59)
491 HWND SetActiveWindow( HWND hwnd )
493 HWND prev = hwndActive;
494 WND *wndPtr = WIN_FindWndPtr( hwnd );
496 if (!wndPtr || (wndPtr->dwStyle & WS_DISABLED) ||
497 !(wndPtr->dwStyle & WS_VISIBLE)) return 0;
499 WINPOS_SetActiveWindow( hwnd, 0, 0 );
504 /***********************************************************************
505 * BringWindowToTop (USER.45)
507 BOOL BringWindowToTop( HWND hwnd )
509 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
513 /***********************************************************************
514 * MoveWindow (USER.56)
516 BOOL MoveWindow( HWND hwnd, short x, short y, short cx, short cy, BOOL repaint)
518 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
519 if (!repaint) flags |= SWP_NOREDRAW;
520 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
521 hwnd, x, y, cx, cy, repaint );
522 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
526 /***********************************************************************
527 * ShowWindow (USER.42)
529 BOOL ShowWindow( HWND hwnd, int cmd )
531 WND * wndPtr = WIN_FindWndPtr( hwnd );
532 BOOL32 wasVisible, showFlag;
535 short x = 0, y = 0, cx = 0, cy = 0;
537 if (!wndPtr) return FALSE;
539 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
541 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
546 if (!wasVisible) return FALSE;
547 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
548 SWP_NOACTIVATE | SWP_NOZORDER;
551 case SW_SHOWMINNOACTIVE:
552 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
554 case SW_SHOWMINIMIZED:
555 swpflags |= SWP_SHOWWINDOW;
558 swpflags |= SWP_FRAMECHANGED;
559 if (!(wndPtr->dwStyle & WS_MINIMIZE))
561 if (wndPtr->dwStyle & WS_MAXIMIZE)
563 wndPtr->flags |= WIN_RESTORE_MAX;
564 wndPtr->dwStyle &= ~WS_MAXIMIZE;
568 wndPtr->flags &= ~WIN_RESTORE_MAX;
569 wndPtr->rectNormal = wndPtr->rectWindow;
571 wndPtr->dwStyle |= WS_MINIMIZE;
572 WINPOS_FindIconPos( hwnd );
573 x = wndPtr->ptIconPos.x;
574 y = wndPtr->ptIconPos.y;
575 cx = SYSMETRICS_CXICON;
576 cy = SYSMETRICS_CYICON;
578 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
581 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
582 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
583 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
585 /* Store the current position and find the maximized size */
586 if (!(wndPtr->dwStyle & WS_MINIMIZE))
587 wndPtr->rectNormal = wndPtr->rectWindow;
589 NC_GetMinMaxInfo( hwnd, &maxSize,
590 &wndPtr->ptMaxPos, NULL, NULL );
591 x = wndPtr->ptMaxPos.x;
592 y = wndPtr->ptMaxPos.y;
594 if( wndPtr->dwStyle & WS_MINIMIZE )
595 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L ) )
597 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
603 wndPtr->dwStyle &= ~WS_MINIMIZE;
604 wndPtr->dwStyle |= WS_MAXIMIZE;
606 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
610 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
613 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
616 case SW_SHOWNOACTIVATE:
617 swpflags |= SWP_NOZORDER;
618 if (GetActiveWindow()) swpflags |= SWP_NOACTIVATE;
620 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
621 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
623 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
625 if (wndPtr->dwStyle & WS_MINIMIZE)
627 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L) )
629 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
632 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
633 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
634 wndPtr->dwStyle &= ~WS_MINIMIZE;
635 if (wndPtr->flags & WIN_RESTORE_MAX)
637 /* Restore to maximized position */
638 NC_GetMinMaxInfo( hwnd, &maxSize, &wndPtr->ptMaxPos,
640 x = wndPtr->ptMaxPos.x;
641 y = wndPtr->ptMaxPos.y;
644 wndPtr->dwStyle |= WS_MAXIMIZE;
646 else /* Restore to normal position */
648 x = wndPtr->rectNormal.left;
649 y = wndPtr->rectNormal.top;
650 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
651 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
654 else if (wndPtr->dwStyle & WS_MAXIMIZE)
656 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
657 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
658 wndPtr->dwStyle &= ~WS_MAXIMIZE;
659 x = wndPtr->rectNormal.left;
660 y = wndPtr->rectNormal.top;
661 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
662 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
664 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
668 showFlag = (cmd != SW_HIDE);
669 if (showFlag != wasVisible)
671 SendMessage16( hwnd, WM_SHOWWINDOW, showFlag, 0 );
672 if (!IsWindow( hwnd )) return wasVisible;
675 if ((wndPtr->dwStyle & WS_CHILD) &&
676 !IsWindowVisible( wndPtr->parent->hwndSelf ) &&
677 (swpflags & SWP_NOSIZE) && (swpflags & SWP_NOMOVE))
679 /* Don't call SetWindowPos() on invisible child windows */
680 if (cmd == SW_HIDE) wndPtr->dwStyle &= ~WS_VISIBLE;
681 else wndPtr->dwStyle |= WS_VISIBLE;
685 /* We can't activate a child window */
686 if (wndPtr->dwStyle & WS_CHILD) swpflags |= SWP_NOACTIVATE;
687 SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
688 if (!IsWindow( hwnd )) return wasVisible;
691 if (wndPtr->flags & WIN_NEED_SIZE)
693 /* should happen only in CreateWindowEx() */
694 int wParam = SIZE_RESTORED;
696 wndPtr->flags &= ~WIN_NEED_SIZE;
697 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
698 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
699 SendMessage16( hwnd, WM_SIZE, wParam,
700 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
701 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
702 SendMessage16( hwnd, WM_MOVE, 0,
703 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
706 if (hwnd == GetFocus())
708 SetFocus( (wndPtr->dwStyle & WS_CHILD)? wndPtr->parent->hwndSelf: 0 );
709 if (hwnd == CARET_GetHwnd()) DestroyCaret();
716 /***********************************************************************
717 * GetInternalWindowPos16 (USER.460)
719 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
721 WINDOWPLACEMENT16 wndpl;
722 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
723 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
724 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
725 return wndpl.showCmd;
729 /***********************************************************************
730 * GetInternalWindowPos32 (USER32.244)
732 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
734 WINDOWPLACEMENT32 wndpl;
735 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
736 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
737 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
738 return wndpl.showCmd;
742 /***********************************************************************
743 * SetInternalWindowPos16 (USER.461)
745 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
746 LPRECT16 rect, LPPOINT16 pt )
748 WINDOWPLACEMENT16 wndpl;
749 WND *wndPtr = WIN_FindWndPtr( hwnd );
751 wndpl.length = sizeof(wndpl);
752 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
753 wndpl.showCmd = showCmd;
754 if (pt) wndpl.ptMinPosition = *pt;
755 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
756 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
757 SetWindowPlacement16( hwnd, &wndpl );
761 /***********************************************************************
762 * SetInternalWindowPos32 (USER32.482)
764 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
765 LPRECT32 rect, LPPOINT32 pt )
767 WINDOWPLACEMENT32 wndpl;
768 WND *wndPtr = WIN_FindWndPtr( hwnd );
770 wndpl.length = sizeof(wndpl);
771 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
772 wndpl.showCmd = showCmd;
773 if (pt) wndpl.ptMinPosition = *pt;
774 if (rect) wndpl.rcNormalPosition = *rect;
775 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
776 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
777 SetWindowPlacement32( hwnd, &wndpl );
781 /***********************************************************************
782 * GetWindowPlacement16 (USER.370)
784 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
786 WND *wndPtr = WIN_FindWndPtr( hwnd );
787 if (!wndPtr) return FALSE;
789 wndpl->length = sizeof(*wndpl);
791 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
792 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
793 wndpl->ptMinPosition = wndPtr->ptIconPos;
794 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
795 wndpl->rcNormalPosition = wndPtr->rectNormal;
800 /***********************************************************************
801 * GetWindowPlacement32 (USER32.306)
803 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
805 WND *wndPtr = WIN_FindWndPtr( hwnd );
806 if (!wndPtr) return FALSE;
808 wndpl->length = sizeof(*wndpl);
810 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
811 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
812 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
813 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
814 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
819 /***********************************************************************
820 * SetWindowPlacement16 (USER.371)
822 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
824 WND *wndPtr = WIN_FindWndPtr( hwnd );
825 if (!wndPtr) return FALSE;
827 if (wndpl->flags & WPF_SETMINPOSITION)
828 wndPtr->ptIconPos = wndpl->ptMinPosition;
829 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
830 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
831 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
832 wndPtr->rectNormal = wndpl->rcNormalPosition;
833 ShowWindow( hwnd, wndpl->showCmd );
838 /***********************************************************************
839 * SetWindowPlacement32 (USER32.518)
841 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
843 WND *wndPtr = WIN_FindWndPtr( hwnd );
844 if (!wndPtr) return FALSE;
846 if (wndpl->flags & WPF_SETMINPOSITION)
847 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
848 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
849 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
850 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
851 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
852 ShowWindow( hwnd, wndpl->showCmd );
857 /*******************************************************************
858 * WINPOS_SetActiveWindow
860 * back-end to SetActiveWindow
862 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus )
864 WND *wndPtr = WIN_FindWndPtr(hWnd);
865 WND *wndTemp = WIN_FindWndPtr(hwndActive);
866 CBTACTIVATESTRUCT16 *cbtStruct;
869 /* FIXME: When proper support for cooperative multitasking is in place
870 * hActiveQ will be global
875 /* paranoid checks */
876 if( !hWnd || hWnd == GetDesktopWindow() || hWnd == hwndActive )
879 if( GetTaskQueue(0) != wndPtr->hmemTaskQ )
883 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
885 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
887 /* call CBT hook chain */
888 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
891 cbtStruct->fMouse = fMouse;
892 cbtStruct->hWndActive = hwndActive;
893 wRet = HOOK_CallHooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd,
894 (LPARAM)SEGPTR_GET(cbtStruct) );
895 SEGPTR_FREE(cbtStruct);
896 if (wRet) return wRet;
899 /* set prev active wnd to current active wnd and send notification */
900 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
902 if (!SendMessage16( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
904 if (GetSysModalWindow16() != hWnd) return 0;
905 /* disregard refusal if hWnd is sysmodal */
908 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
909 MAKEWPARAM( WA_INACTIVE, wIconized ),
912 /* check if something happened during message processing */
913 if( hwndPrevActive != hwndActive ) return 0;
919 /* send palette messages */
920 if( SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L) )
921 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
923 /* if prev wnd is minimized redraw icon title
926 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
928 if(wndTemp->dwStyle & WS_MINIMIZE)
929 RedrawIconTitle(hwndPrevActive);
933 /* managed windows will get ConfigureNotify event */
934 if (!(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
936 /* check Z-order and bring hWnd to the top */
937 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
938 if (wndTemp->dwStyle & WS_VISIBLE) break;
940 if( wndTemp != wndPtr )
941 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
942 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
945 if( !IsWindow(hWnd) ) return 0;
949 wndTemp = WIN_FindWndPtr( hwndPrevActive );
950 if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
953 /* send WM_ACTIVATEAPP if necessary */
954 if (hActiveQ != wndPtr->hmemTaskQ)
958 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
960 for (ppWnd = list; *ppWnd; ppWnd++)
962 /* Make sure that the window still exists */
963 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
964 if ((*ppWnd)->hmemTaskQ != hActiveQ) continue;
965 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
966 0, QUEUE_GetQueueTask(wndPtr->hmemTaskQ) );
968 HeapFree( SystemHeap, 0, list );
971 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
973 for (ppWnd = list; *ppWnd; ppWnd++)
975 /* Make sure that the window still exists */
976 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
977 if ((*ppWnd)->hmemTaskQ != wndPtr->hmemTaskQ) continue;
978 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
979 1, QUEUE_GetQueueTask( hActiveQ ) );
981 HeapFree( SystemHeap, 0, list );
983 if (!IsWindow(hWnd)) return 0;
986 /* walk up to the first unowned window */
988 while (wndTemp->owner) wndTemp = wndTemp->owner;
989 /* and set last active owned popup */
990 wndTemp->hwndLastActive = hWnd;
992 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
993 SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
994 SendMessage32A( hWnd, WM_ACTIVATE,
995 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
996 (LPARAM)hwndPrevActive );
998 if( !IsWindow(hWnd) ) return 0;
1000 /* change focus if possible */
1001 if( fChangeFocus && GetFocus() )
1002 if( WIN_GetTopParent(GetFocus()) != hwndActive )
1003 FOCUS_SwitchFocus( GetFocus(),
1004 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
1006 /* if active wnd is minimized redraw icon title
1009 wndPtr = WIN_FindWndPtr(hwndActive);
1010 if(wndPtr->dwStyle & WS_MINIMIZE)
1011 RedrawIconTitle(hwndActive);
1014 return (hWnd == hwndActive);
1018 /*******************************************************************
1019 * WINPOS_ChangeActiveWindow
1022 BOOL WINPOS_ChangeActiveWindow( HWND hWnd, BOOL mouseMsg )
1024 WND *wndPtr = WIN_FindWndPtr(hWnd);
1026 if( !wndPtr ) return FALSE;
1028 /* child windows get WM_CHILDACTIVATE message */
1029 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1030 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1032 /* owned popups imply owner activation - not sure */
1033 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1034 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1036 if (!(wndPtr = wndPtr->owner)) return FALSE;
1037 hWnd = wndPtr->hwndSelf;
1040 if( hWnd == hwndActive ) return FALSE;
1042 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1045 /* switch desktop queue to current active */
1046 if( wndPtr->parent == WIN_GetDesktop())
1047 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1053 /***********************************************************************
1054 * WINPOS_SendNCCalcSize
1056 * Send a WM_NCCALCSIZE message to a window.
1057 * All parameters are read-only except newClientRect.
1058 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1059 * when calcValidRect is TRUE.
1061 LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect,
1062 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1063 RECT16 *oldClientRect, SEGPTR winpos,
1064 RECT16 *newClientRect )
1066 NCCALCSIZE_PARAMS16 *params;
1069 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1070 params->rgrc[0] = *newWindowRect;
1073 params->rgrc[1] = *oldWindowRect;
1074 params->rgrc[2] = *oldClientRect;
1075 params->lppos = winpos;
1077 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1078 (LPARAM)SEGPTR_GET( params ) );
1079 dprintf_win(stddeb, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
1080 (int)params->rgrc[0].top, (int)params->rgrc[0].left,
1081 (int)params->rgrc[0].bottom, (int)params->rgrc[0].right);
1082 *newClientRect = params->rgrc[0];
1083 SEGPTR_FREE(params);
1088 /***********************************************************************
1089 * WINPOS_HandleWindowPosChanging16
1091 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1093 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1096 if (winpos->flags & SWP_NOSIZE) return 0;
1097 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1098 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1100 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1101 winpos->cx = MIN( winpos->cx, maxSize.x );
1102 winpos->cy = MIN( winpos->cy, maxSize.y );
1108 /***********************************************************************
1109 * WINPOS_HandleWindowPosChanging32
1111 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1113 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1116 if (winpos->flags & SWP_NOSIZE) return 0;
1117 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1118 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1120 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1121 winpos->cx = MIN( winpos->cx, maxSize.x );
1122 winpos->cy = MIN( winpos->cy, maxSize.y );
1128 /***********************************************************************
1129 * WINPOS_MoveWindowZOrder
1131 * Move a window in Z order, invalidating everything that needs it.
1132 * Only necessary for windows without associated X window.
1134 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
1137 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1139 /* We have two possible cases:
1140 * - The window is moving up: we have to invalidate all areas
1141 * of the window that were covered by other windows
1142 * - The window is moving down: we have to invalidate areas
1143 * of other windows covered by this one.
1146 if (hwndAfter == HWND_TOP)
1150 else if (hwndAfter == HWND_BOTTOM)
1152 if (!wndPtr->next) return; /* Already at the bottom */
1157 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1158 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1160 /* Determine which window we encounter first in Z-order */
1161 pWndCur = wndPtr->parent->child;
1162 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1163 pWndCur = pWndCur->next;
1164 movingUp = (pWndCur == pWndAfter);
1169 WND *pWndPrevAfter = wndPtr->next;
1170 WIN_UnlinkWindow( hwnd );
1171 WIN_LinkWindow( hwnd, hwndAfter );
1172 pWndCur = wndPtr->next;
1173 while (pWndCur != pWndPrevAfter)
1175 RECT16 rect = pWndCur->rectWindow;
1176 OffsetRect16( &rect, -wndPtr->rectClient.left,
1177 -wndPtr->rectClient.top );
1178 RedrawWindow16( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1179 RDW_FRAME | RDW_ERASE );
1180 pWndCur = pWndCur->next;
1183 else /* Moving down */
1185 pWndCur = wndPtr->next;
1186 WIN_UnlinkWindow( hwnd );
1187 WIN_LinkWindow( hwnd, hwndAfter );
1188 while (pWndCur != wndPtr)
1190 RECT16 rect = wndPtr->rectWindow;
1191 OffsetRect16( &rect, -pWndCur->rectClient.left,
1192 -pWndCur->rectClient.top );
1193 RedrawWindow16( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1194 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
1195 pWndCur = pWndCur->next;
1200 /***********************************************************************
1201 * WINPOS_ReorderOwnedPopups
1203 * fix Z order taking into account owned popups -
1204 * basically we need to maintain them above owner window
1206 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
1208 WND* w = WIN_GetDesktop();
1212 /* if we are dealing with owned popup...
1214 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner && hwndInsertAfter != HWND_TOP )
1216 BOOL bFound = FALSE;
1217 HWND hwndLocalPrev = HWND_TOP;
1218 HWND hwndNewAfter = 0;
1222 if( !bFound && hwndInsertAfter == hwndLocalPrev )
1223 hwndInsertAfter = HWND_TOP;
1225 if( w->dwStyle & WS_POPUP && w->owner == wndPtr->owner )
1229 if( hwndInsertAfter == HWND_TOP )
1231 hwndInsertAfter = hwndLocalPrev;
1234 hwndNewAfter = hwndLocalPrev;
1237 if( w == wndPtr->owner )
1239 /* basically HWND_BOTTOM */
1240 hwndInsertAfter = hwndLocalPrev;
1243 hwndInsertAfter = hwndNewAfter;
1248 hwndLocalPrev = w->hwndSelf;
1254 /* or overlapped top-level window...
1256 if( !(wndPtr->dwStyle & WS_CHILD) )
1259 if( w == wndPtr ) break;
1261 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1263 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1264 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1265 hwndInsertAfter = w->hwndSelf;
1270 return hwndInsertAfter;
1273 /***********************************************************************
1274 * WINPOS_SizeMoveClean
1276 * Make window look nice without excessive repainting
1280 * visible regions are in window coordinates
1281 * update regions are in window client coordinates
1282 * client and window rectangles are in parent client coordinates
1284 static void WINPOS_SizeMoveClean(WND* Wnd, HRGN oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, BOOL bNoCopy )
1286 HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf, DCX_WINDOW | DCX_CLIPSIBLINGS );
1287 HRGN dirtyRgn = CreateRectRgn(0,0,0,0);
1290 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1291 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1292 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1293 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1294 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1295 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1297 CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY);
1301 HRGN hRgn = CreateRectRgn( lpOldClientRect->left - lpOldWndRect->left, lpOldClientRect->top - lpOldWndRect->top,
1302 lpOldClientRect->right - lpOldWndRect->left, lpOldClientRect->bottom - lpOldWndRect->top);
1303 CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1304 CombineRgn( newVisRgn, newVisRgn, hRgn, RGN_AND );
1308 /* map regions to the parent client area */
1310 OffsetRgn(dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top);
1311 OffsetRgn(oldVisRgn, lpOldWndRect->left, lpOldWndRect->top);
1313 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1315 other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1317 /* map visible region to the Wnd client area */
1319 OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1320 Wnd->rectWindow.top - Wnd->rectClient.top );
1322 /* substract previously invalidated region from the Wnd visible region */
1324 my = (Wnd->hrgnUpdate > 1)? CombineRgn( newVisRgn, newVisRgn, Wnd->hrgnUpdate, RGN_DIFF)
1327 if( bNoCopy ) /* invalidate Wnd visible region */
1329 if (my != NULLREGION) RedrawWindow32( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1330 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1332 else /* bitblt old client area */
1340 updateRgn = CreateRectRgn( 0,0, Wnd->rectClient.right - Wnd->rectClient.left,
1341 Wnd->rectClient.bottom - Wnd->rectClient.top );
1343 /* clip visible region with client rect */
1345 my = CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1347 /* substract result from client rect to get region that won't be copied */
1349 update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1351 /* Blt valid bits using parent window DC */
1353 if( my != NULLREGION )
1355 int xfrom = lpOldClientRect->left;
1356 int yfrom = lpOldClientRect->top;
1357 int xto = Wnd->rectClient.left;
1358 int yto = Wnd->rectClient.top;
1360 /* check if we can skip copying */
1362 if( xfrom != xto || yfrom != yto )
1364 /* compute clipping region in parent client coordinates */
1366 OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top);
1367 CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1369 hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS);
1371 BitBlt(hDC, xto, yto, lpOldClientRect->right - lpOldClientRect->left,
1372 lpOldClientRect->bottom - lpOldClientRect->top,
1373 hDC, xfrom, yfrom, SRCCOPY );
1375 ReleaseDC( Wnd->parent->hwndSelf, hDC);
1379 if( update != NULLREGION )
1380 RedrawWindow32( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1381 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1382 DeleteObject( updateRgn );
1385 /* erase uncovered areas */
1387 if( other != NULLREGION )
1388 RedrawWindow32( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1389 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1391 DeleteObject(dirtyRgn);
1392 DeleteObject(newVisRgn);
1396 /***********************************************************************
1397 * WINPOS_ForceXWindowRaise
1399 void WINPOS_ForceXWindowRaise( WND* pWnd )
1401 XWindowChanges winChanges;
1402 WND *wndStop, *wndLast;
1404 if (!pWnd->window) return;
1406 wndLast = wndStop = pWnd;
1407 winChanges.stack_mode = Above;
1408 XReconfigureWMWindow( display, pWnd->window, 0, CWStackMode, &winChanges );
1410 /* Recursively raise owned popups according to their z-order
1411 * (it would be easier with sibling-related Below but it doesn't
1412 * work very well with SGI mwm for instance)
1416 WND *wnd = WIN_GetDesktop()->child;
1418 while (wnd != wndStop)
1420 if (wnd->owner == pWnd &&
1421 (wnd->dwStyle & WS_POPUP) &&
1422 (wnd->dwStyle & WS_VISIBLE))
1428 WINPOS_ForceXWindowRaise( wndLast );
1435 /***********************************************************************
1436 * WINPOS_SetXWindowPos
1438 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1440 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1442 XWindowChanges winChanges;
1444 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1446 if (!(winpos->flags & SWP_NOSIZE))
1448 winChanges.width = winpos->cx;
1449 winChanges.height = winpos->cy;
1450 changeMask |= CWWidth | CWHeight;
1452 /* Tweak dialog window size hints */
1454 if ((wndPtr->flags & WIN_MANAGED) &&
1455 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1457 XSizeHints *size_hints = XAllocSizeHints();
1461 long supplied_return;
1463 XGetWMSizeHints( display, wndPtr->window, size_hints,
1464 &supplied_return, XA_WM_NORMAL_HINTS);
1465 size_hints->min_width = size_hints->max_width = winpos->cx;
1466 size_hints->min_height = size_hints->max_height = winpos->cy;
1467 XSetWMSizeHints( display, wndPtr->window, size_hints,
1468 XA_WM_NORMAL_HINTS );
1473 if (!(winpos->flags & SWP_NOMOVE))
1475 winChanges.x = winpos->x;
1476 winChanges.y = winpos->y;
1477 changeMask |= CWX | CWY;
1479 if (!(winpos->flags & SWP_NOZORDER))
1481 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1482 else winChanges.stack_mode = Below;
1483 if ((winpos->hwndInsertAfter != HWND_TOP) &&
1484 (winpos->hwndInsertAfter != HWND_BOTTOM))
1486 WND * insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1487 winChanges.sibling = insertPtr->window;
1488 changeMask |= CWSibling;
1490 changeMask |= CWStackMode;
1492 if (!changeMask) return;
1493 if (wndPtr->flags & WIN_MANAGED)
1494 XReconfigureWMWindow( display, wndPtr->window, 0,
1495 changeMask, &winChanges );
1496 else XConfigureWindow( display, wndPtr->window, changeMask, &winChanges );
1500 /***********************************************************************
1501 * SetWindowPos (USER.232)
1503 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1504 INT cx, INT cy, WORD flags )
1508 RECT16 newWindowRect, newClientRect;
1512 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
1513 hwnd, x, y, x+cx, y+cy, flags);
1514 /* Check window handle */
1516 if (hwnd == GetDesktopWindow()) return FALSE;
1517 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1519 if (wndPtr->dwStyle & WS_VISIBLE) flags &= ~SWP_SHOWWINDOW;
1522 flags &= ~SWP_HIDEWINDOW;
1523 if (!(flags & SWP_SHOWWINDOW)) flags |= SWP_NOREDRAW;
1526 /* Check for windows that may not be resized
1527 FIXME: this should be done only for Windows 3.0 programs
1528 */ if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
1529 flags |= SWP_NOSIZE | SWP_NOMOVE;
1531 /* Check dimensions */
1533 if (cx <= 0) cx = 1;
1534 if (cy <= 0) cy = 1;
1538 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1539 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1540 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1541 flags |= SWP_NOSIZE; /* Already the right size */
1542 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1543 flags |= SWP_NOMOVE; /* Already the right position */
1545 /* Check hwndInsertAfter */
1547 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1549 /* Ignore TOPMOST flags when activating a window */
1550 /* _and_ moving it in Z order. */
1551 if ((hwndInsertAfter == HWND_TOPMOST) ||
1552 (hwndInsertAfter == HWND_NOTOPMOST))
1553 hwndInsertAfter = HWND_TOP;
1555 /* TOPMOST not supported yet */
1556 if ((hwndInsertAfter == HWND_TOPMOST) ||
1557 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1559 /* hwndInsertAfter must be a sibling of the window */
1560 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1562 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1563 if( wnd->parent != wndPtr->parent ) return FALSE;
1564 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1567 if (hwndInsertAfter == HWND_TOP)
1568 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1569 else /* HWND_BOTTOM */
1570 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1572 /* Fill the WINDOWPOS structure */
1575 winpos.hwndInsertAfter = hwndInsertAfter;
1580 winpos.flags = flags;
1582 /* Send WM_WINDOWPOSCHANGING message */
1584 if (!(flags & SWP_NOSENDCHANGING))
1585 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1587 /* Calculate new position and size */
1589 newWindowRect = wndPtr->rectWindow;
1590 newClientRect = wndPtr->rectClient;
1592 if (!(winpos.flags & SWP_NOSIZE))
1594 newWindowRect.right = newWindowRect.left + winpos.cx;
1595 newWindowRect.bottom = newWindowRect.top + winpos.cy;
1597 if (!(winpos.flags & SWP_NOMOVE))
1599 newWindowRect.left = winpos.x;
1600 newWindowRect.top = winpos.y;
1601 newWindowRect.right += winpos.x - wndPtr->rectWindow.left;
1602 newWindowRect.bottom += winpos.y - wndPtr->rectWindow.top;
1604 OffsetRect16( &newClientRect, winpos.x - wndPtr->rectWindow.left,
1605 winpos.y - wndPtr->rectWindow.top );
1608 winpos.flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1610 /* Reposition window in Z order */
1612 if (!(winpos.flags & SWP_NOZORDER))
1614 /* reorder owned popups if hwnd is top-level window
1616 if( wndPtr->parent == WIN_GetDesktop() )
1617 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1622 WIN_UnlinkWindow( winpos.hwnd );
1623 WIN_LinkWindow( winpos.hwnd, hwndInsertAfter );
1625 else WINPOS_MoveWindowZOrder( winpos.hwnd, hwndInsertAfter );
1628 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1629 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1630 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1633 /* Send WM_NCCALCSIZE message to get new client area */
1634 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1636 result = WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
1637 &wndPtr->rectWindow, &wndPtr->rectClient,
1638 MAKE_SEGPTR(&winpos), &newClientRect );
1640 /* FIXME: WVR_ALIGNxxx */
1642 if( newClientRect.left != wndPtr->rectClient.left ||
1643 newClientRect.top != wndPtr->rectClient.top )
1644 winpos.flags &= ~SWP_NOCLIENTMOVE;
1646 if( (newClientRect.right - newClientRect.left !=
1647 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1648 (newClientRect.bottom - newClientRect.top !=
1649 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1650 winpos.flags &= ~SWP_NOCLIENTSIZE;
1653 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1654 newClientRect.top != wndPtr->rectClient.top) )
1655 winpos.flags &= ~SWP_NOCLIENTMOVE;
1657 /* Update active DCEs */
1659 if( !(flags & SWP_NOZORDER) || (flags & SWP_HIDEWINDOW) || (flags & SWP_SHOWWINDOW)
1660 || (memcmp(&newWindowRect,&wndPtr->rectWindow,sizeof(RECT16))
1661 && wndPtr->dwStyle & WS_VISIBLE ) )
1665 UnionRect16(&rect,&newWindowRect,&wndPtr->rectWindow);
1666 DCE_InvalidateDCE(wndPtr->parent, &rect);
1669 /* Perform the moving and resizing */
1673 RECT16 oldWindowRect = wndPtr->rectWindow;
1674 RECT16 oldClientRect = wndPtr->rectClient;
1676 HWND bogusInsertAfter = winpos.hwndInsertAfter;
1678 winpos.hwndInsertAfter = hwndInsertAfter;
1679 WINPOS_SetXWindowPos( &winpos );
1681 wndPtr->rectWindow = newWindowRect;
1682 wndPtr->rectClient = newClientRect;
1683 winpos.hwndInsertAfter = bogusInsertAfter;
1685 /* FIXME: should do something like WINPOS_SizeMoveClean */
1687 if( (oldClientRect.left - oldWindowRect.left !=
1688 newClientRect.left - newWindowRect.left) ||
1689 (oldClientRect.top - oldWindowRect.top !=
1690 newClientRect.top - newWindowRect.top) )
1692 RedrawWindow32( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
1693 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
1695 if( winpos.flags & SWP_FRAMECHANGED )
1700 if( oldClientRect.right > newClientRect.right )
1702 rect.left = newClientRect.right; rect.top = newClientRect.top;
1703 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1705 RedrawWindow32( wndPtr->hwndSelf, &rect, 0,
1706 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN );
1708 if( oldClientRect.bottom > newClientRect.bottom )
1710 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1711 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1712 rect.bottom = oldClientRect.bottom;
1714 RedrawWindow32( wndPtr->hwndSelf, &rect, 0,
1715 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN );
1717 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1722 RECT16 oldWindowRect = wndPtr->rectWindow;
1723 RECT16 oldClientRect = wndPtr->rectClient;
1725 wndPtr->rectWindow = newWindowRect;
1726 wndPtr->rectClient = newClientRect;
1728 if( !(flags & SWP_NOREDRAW) )
1730 BOOL bNoCopy = (flags & SWP_NOCOPYBITS) ||
1731 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS);
1733 if( (winpos.flags & SWP_AGG_NOGEOMETRYCHANGE) != SWP_AGG_NOGEOMETRYCHANGE )
1734 /* optimize cleanup by BitBlt'ing where possible */
1736 WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect, &oldClientRect, bNoCopy);
1738 if( winpos.flags & SWP_FRAMECHANGED )
1739 RedrawWindow32( winpos.hwnd, NULL, 0, RDW_NOCHILDREN | RDW_FRAME );
1742 DeleteObject(visRgn);
1745 if (flags & SWP_SHOWWINDOW)
1747 wndPtr->dwStyle |= WS_VISIBLE;
1750 XMapWindow( display, wndPtr->window );
1754 if (!(flags & SWP_NOREDRAW))
1755 RedrawWindow32( winpos.hwnd, NULL, 0,
1756 RDW_INVALIDATE | RDW_ALLCHILDREN |
1757 RDW_FRAME | RDW_ERASE );
1760 else if (flags & SWP_HIDEWINDOW)
1762 wndPtr->dwStyle &= ~WS_VISIBLE;
1765 XUnmapWindow( display, wndPtr->window );
1769 if (!(flags & SWP_NOREDRAW))
1770 RedrawWindow16( wndPtr->parent->hwndSelf, &wndPtr->rectWindow, 0,
1771 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1774 if ((winpos.hwnd == GetFocus()) || IsChild(winpos.hwnd, GetFocus()))
1775 SetFocus( GetParent(winpos.hwnd) ); /* Revert focus to parent */
1777 if (winpos.hwnd == hwndActive)
1779 /* Activate previously active window if possible */
1780 HWND newActive = hwndPrevActive;
1781 if (!IsWindow(newActive) || (newActive == winpos.hwnd))
1783 newActive = GetTopWindow( GetDesktopWindow() );
1784 if (newActive == winpos.hwnd)
1785 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1787 WINPOS_ChangeActiveWindow( newActive, FALSE );
1791 /* Activate the window */
1793 if (!(flags & SWP_NOACTIVATE))
1794 WINPOS_ChangeActiveWindow( winpos.hwnd, FALSE );
1796 /* Repaint the window */
1798 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
1800 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1802 if (!(flags & SWP_DEFERERASE))
1803 RedrawWindow32( wndPtr->parent->hwndSelf, NULL, 0,
1804 RDW_ALLCHILDREN | RDW_ERASENOW );
1806 /* And last, send the WM_WINDOWPOSCHANGED message */
1808 dprintf_win(stddeb,"\tstatus flags = %04x\n", winpos.flags & SWP_AGG_STATUSFLAGS);
1810 if ( ((winpos.flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
1811 !(winpos.flags & SWP_NOSENDCHANGING))
1812 SendMessage16( winpos.hwnd, WM_WINDOWPOSCHANGED,
1813 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1819 /***********************************************************************
1820 * BeginDeferWindowPos (USER.259)
1822 HDWP16 BeginDeferWindowPos( INT count )
1827 if (count <= 0) return 0;
1828 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS16) );
1829 if (!handle) return 0;
1830 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1831 pDWP->actualCount = 0;
1832 pDWP->suggestedCount = count;
1834 pDWP->wMagic = DWP_MAGIC;
1835 pDWP->hwndParent = 0;
1840 /***********************************************************************
1841 * DeferWindowPos (USER.260)
1843 HDWP16 DeferWindowPos( HDWP16 hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
1844 INT cx, INT cy, UINT flags )
1848 HDWP16 newhdwp = hdwp;
1851 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1852 if (!pDWP) return 0;
1853 if (hwnd == GetDesktopWindow()) return 0;
1855 /* All the windows of a DeferWindowPos() must have the same parent */
1857 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
1858 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1859 else if (parent != pDWP->hwndParent)
1861 USER_HEAP_FREE( hdwp );
1865 for (i = 0; i < pDWP->actualCount; i++)
1867 if (pDWP->winPos[i].hwnd == hwnd)
1869 /* Merge with the other changes */
1870 if (!(flags & SWP_NOZORDER))
1872 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1874 if (!(flags & SWP_NOMOVE))
1876 pDWP->winPos[i].x = x;
1877 pDWP->winPos[i].y = y;
1879 if (!(flags & SWP_NOSIZE))
1881 pDWP->winPos[i].cx = cx;
1882 pDWP->winPos[i].cy = cy;
1884 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
1885 SWP_NOZORDER | SWP_NOREDRAW |
1886 SWP_NOACTIVATE | SWP_NOCOPYBITS |
1888 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1893 if (pDWP->actualCount >= pDWP->suggestedCount)
1895 newhdwp = USER_HEAP_REALLOC( hdwp,
1896 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS16) );
1897 if (!newhdwp) return 0;
1898 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1899 pDWP->suggestedCount++;
1901 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1902 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1903 pDWP->winPos[pDWP->actualCount].x = x;
1904 pDWP->winPos[pDWP->actualCount].y = y;
1905 pDWP->winPos[pDWP->actualCount].cx = cx;
1906 pDWP->winPos[pDWP->actualCount].cy = cy;
1907 pDWP->winPos[pDWP->actualCount].flags = flags;
1908 pDWP->actualCount++;
1913 /***********************************************************************
1914 * EndDeferWindowPos (USER.261)
1916 BOOL EndDeferWindowPos( HDWP16 hdwp )
1919 WINDOWPOS16 *winpos;
1923 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1924 if (!pDWP) return FALSE;
1925 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1927 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1928 winpos->x, winpos->y, winpos->cx, winpos->cy,
1929 winpos->flags ))) break;
1931 USER_HEAP_FREE( hdwp );
1936 /***********************************************************************
1937 * TileChildWindows (USER.199)
1939 void TileChildWindows( HWND parent, WORD action )
1941 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
1944 /***********************************************************************
1945 * CascageChildWindows (USER.198)
1947 void CascadeChildWindows( HWND parent, WORD action )
1949 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);