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"
22 #include "nonclient.h"
24 /* #define DEBUG_WIN */
27 #define SWP_AGG_NOGEOMETRYCHANGE \
28 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
29 #define SWP_AGG_NOPOSCHANGE \
30 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
31 #define SWP_AGG_STATUSFLAGS \
32 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
34 #define SMC_NOCOPY 0x0001
35 #define SMC_NOPARENTERASE 0x0002
36 #define SMC_DRAWFRAME 0x0004
37 #define SMC_SETXPOS 0x0008
39 /* ----- external functions ----- */
41 extern void FOCUS_SwitchFocus( HWND , HWND );
42 extern HRGN DCE_GetVisRgn( HWND, WORD );
43 extern HWND CARET_GetHwnd();
44 extern BOOL DCE_InvalidateDCE(WND*, RECT16* );
46 /* ----- internal variables ----- */
48 static HWND hwndActive = 0; /* Currently active window */
49 static HWND hwndPrevActive = 0; /* Previously active window */
51 /***********************************************************************
54 * Find a suitable place for an iconic window.
55 * The new position is stored into wndPtr->ptIconPos.
57 void WINPOS_FindIconPos( HWND32 hwnd )
60 short x, y, xspacing, yspacing;
61 WND * wndPtr = WIN_FindWndPtr( hwnd );
63 if (!wndPtr || !wndPtr->parent) return;
64 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
65 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
66 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
67 (wndPtr->ptIconPos.y >= rectParent.top) &&
68 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
69 return; /* The icon already has a suitable position */
71 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
72 y = rectParent.bottom;
75 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
77 /* Check if another icon already occupies this spot */
78 WND *childPtr = wndPtr->parent->child;
81 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
83 if ((childPtr->rectWindow.left < x + xspacing) &&
84 (childPtr->rectWindow.right >= x) &&
85 (childPtr->rectWindow.top <= y) &&
86 (childPtr->rectWindow.bottom > y - yspacing))
87 break; /* There's a window in there */
89 childPtr = childPtr->next;
93 /* No window was found, so it's OK for us */
94 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
95 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
104 /***********************************************************************
105 * ArrangeIconicWindows (USER.170)
107 UINT ArrangeIconicWindows( HWND parent )
111 INT x, y, xspacing, yspacing;
113 GetClientRect16( parent, &rectParent );
115 y = rectParent.bottom;
116 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
117 hwndChild = GetWindow( parent, GW_CHILD );
120 if (IsIconic( hwndChild ))
122 SetWindowPos( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
123 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
124 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
125 if (x <= rectParent.right - xspacing) x += xspacing;
132 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
138 /***********************************************************************
139 * GetWindowRect16 (USER.32)
141 void GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
143 WND * wndPtr = WIN_FindWndPtr( hwnd );
146 *rect = wndPtr->rectWindow;
147 if (wndPtr->dwStyle & WS_CHILD)
148 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
152 /***********************************************************************
153 * GetWindowRect32 (USER.32)
155 void GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
157 WND * wndPtr = WIN_FindWndPtr( hwnd );
160 CONV_RECT16TO32( &wndPtr->rectWindow, rect );
161 if (wndPtr->dwStyle & WS_CHILD)
162 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
166 /***********************************************************************
167 * GetClientRect16 (USER.33)
169 void GetClientRect16( HWND16 hwnd, LPRECT16 rect )
171 WND * wndPtr = WIN_FindWndPtr( hwnd );
173 rect->left = rect->top = rect->right = rect->bottom = 0;
176 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
177 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
182 /***********************************************************************
183 * GetClientRect32 (USER32.219)
185 void GetClientRect32( HWND32 hwnd, LPRECT32 rect )
187 WND * wndPtr = WIN_FindWndPtr( hwnd );
189 rect->left = rect->top = rect->right = rect->bottom = 0;
192 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
193 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
198 /*******************************************************************
199 * ClientToScreen16 (USER.28)
201 BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
203 MapWindowPoints16( hwnd, 0, lppnt, 1 );
208 /*******************************************************************
209 * ClientToScreen32 (USER32.51)
211 BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
213 MapWindowPoints32( hwnd, 0, lppnt, 1 );
218 /*******************************************************************
219 * ScreenToClient16 (USER.29)
221 void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
223 MapWindowPoints16( 0, hwnd, lppnt, 1 );
227 /*******************************************************************
228 * ScreenToClient32 (USER32.446)
230 void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
232 MapWindowPoints32( 0, hwnd, lppnt, 1 );
236 /***********************************************************************
237 * WINPOS_WindowFromPoint
239 * Find the window and hittest for a given point.
241 INT16 WINPOS_WindowFromPoint( POINT16 pt, WND **ppWnd )
244 INT16 hittest = HTERROR;
250 wndPtr = WIN_GetDesktop()->child;
255 /* If point is in window, and window is visible, and it */
256 /* is enabled (or it's a top-level window), then explore */
257 /* its children. Otherwise, go to the next window. */
259 if ((wndPtr->dwStyle & WS_VISIBLE) &&
260 (!(wndPtr->dwStyle & WS_DISABLED) ||
261 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
262 (x >= wndPtr->rectWindow.left) &&
263 (x < wndPtr->rectWindow.right) &&
264 (y >= wndPtr->rectWindow.top) &&
265 (y < wndPtr->rectWindow.bottom))
267 *ppWnd = wndPtr; /* Got a suitable window */
269 /* If window is minimized or disabled, return at once */
270 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
271 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
273 /* If point is not in client area, ignore the children */
274 if ((x < wndPtr->rectClient.left) ||
275 (x >= wndPtr->rectClient.right) ||
276 (y < wndPtr->rectClient.top) ||
277 (y >= wndPtr->rectClient.bottom)) break;
279 x -= wndPtr->rectClient.left;
280 y -= wndPtr->rectClient.top;
281 wndPtr = wndPtr->child;
283 else wndPtr = wndPtr->next;
286 /* If nothing found, return the desktop window */
289 *ppWnd = WIN_GetDesktop();
293 /* Send the WM_NCHITTEST message (only if to the same task) */
294 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
295 hittest = (INT)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
296 MAKELONG( pt.x, pt.y ) );
297 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
299 /* If no children found in last search, make point relative to parent*/
302 x += (*ppWnd)->rectClient.left;
303 y += (*ppWnd)->rectClient.top;
306 /* Restart the search from the next sibling */
307 wndPtr = (*ppWnd)->next;
308 *ppWnd = (*ppWnd)->parent;
313 /*******************************************************************
314 * WindowFromPoint16 (USER.30)
316 HWND16 WindowFromPoint16( POINT16 pt )
319 WINPOS_WindowFromPoint( pt, &pWnd );
320 return pWnd->hwndSelf;
324 /*******************************************************************
325 * WindowFromPoint32 (USER32.581)
327 HWND32 WindowFromPoint32( POINT32 pt )
331 CONV_POINT32TO16( &pt, &pt16 );
332 WINPOS_WindowFromPoint( pt16, &pWnd );
333 return (HWND32)pWnd->hwndSelf;
337 /*******************************************************************
338 * ChildWindowFromPoint16 (USER.191)
340 HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
342 /* pt is in the client coordinates */
344 WND* wnd = WIN_FindWndPtr(hwndParent);
349 /* get client rect fast */
350 rect.top = rect.left = 0;
351 rect.right = wnd->rectClient.right - wnd->rectClient.left;
352 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
354 if (!PtInRect16( &rect, pt )) return 0;
359 if (PtInRect16( &wnd->rectWindow, pt )) return wnd->hwndSelf;
366 /*******************************************************************
367 * ChildWindowFromPoint32 (USER32.)
369 HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
372 CONV_POINT32TO16( &pt, &pt16 );
373 return (HWND32)ChildWindowFromPoint16( hwndParent, pt16 );
377 /*******************************************************************
378 * WINPOS_GetWinOffset
380 * Calculate the offset between the origin of the two windows. Used
381 * to implement MapWindowPoints.
383 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
388 offset->x = offset->y = 0;
389 if (hwndFrom == hwndTo ) return;
391 /* Translate source window origin to screen coords */
394 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
396 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
399 while (wndPtr->parent)
401 offset->x += wndPtr->rectClient.left;
402 offset->y += wndPtr->rectClient.top;
403 wndPtr = wndPtr->parent;
407 /* Translate origin to destination window coords */
410 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
412 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
415 while (wndPtr->parent)
417 offset->x -= wndPtr->rectClient.left;
418 offset->y -= wndPtr->rectClient.top;
419 wndPtr = wndPtr->parent;
425 /*******************************************************************
426 * MapWindowPoints16 (USER.258)
428 void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
429 LPPOINT16 lppt, UINT16 count )
433 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
443 /*******************************************************************
444 * MapWindowPoints32 (USER32.385)
446 void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
447 LPPOINT32 lppt, UINT32 count )
451 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
461 /***********************************************************************
464 BOOL IsIconic(HWND hWnd)
466 WND * wndPtr = WIN_FindWndPtr(hWnd);
467 if (wndPtr == NULL) return FALSE;
468 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
472 /***********************************************************************
473 * IsZoomed (USER.272)
475 BOOL IsZoomed(HWND hWnd)
477 WND * wndPtr = WIN_FindWndPtr(hWnd);
478 if (wndPtr == NULL) return FALSE;
479 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
483 /*******************************************************************
484 * GetActiveWindow (USER.60)
486 HWND GetActiveWindow()
492 /*******************************************************************
493 * SetActiveWindow (USER.59)
495 HWND SetActiveWindow( HWND hwnd )
497 HWND prev = hwndActive;
498 WND *wndPtr = WIN_FindWndPtr( hwnd );
500 if (!wndPtr || (wndPtr->dwStyle & WS_DISABLED) ||
501 !(wndPtr->dwStyle & WS_VISIBLE)) return 0;
503 WINPOS_SetActiveWindow( hwnd, 0, 0 );
508 /***********************************************************************
509 * BringWindowToTop (USER.45)
511 BOOL BringWindowToTop( HWND hwnd )
513 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
517 /***********************************************************************
518 * MoveWindow (USER.56)
520 BOOL MoveWindow( HWND hwnd, short x, short y, short cx, short cy, BOOL repaint)
522 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
523 if (!repaint) flags |= SWP_NOREDRAW;
524 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
525 hwnd, x, y, cx, cy, repaint );
526 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
530 /***********************************************************************
531 * ShowWindow (USER.42)
533 BOOL ShowWindow( HWND hwnd, int cmd )
535 WND * wndPtr = WIN_FindWndPtr( hwnd );
536 BOOL32 wasVisible, showFlag;
539 short x = 0, y = 0, cx = 0, cy = 0;
541 if (!wndPtr) return FALSE;
543 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
545 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
550 if (!wasVisible) return FALSE;
551 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
552 SWP_NOACTIVATE | SWP_NOZORDER;
555 case SW_SHOWMINNOACTIVE:
556 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
558 case SW_SHOWMINIMIZED:
559 swpflags |= SWP_SHOWWINDOW;
562 swpflags |= SWP_FRAMECHANGED;
563 if (!(wndPtr->dwStyle & WS_MINIMIZE))
565 if (wndPtr->dwStyle & WS_MAXIMIZE)
567 wndPtr->flags |= WIN_RESTORE_MAX;
568 wndPtr->dwStyle &= ~WS_MAXIMIZE;
572 wndPtr->flags &= ~WIN_RESTORE_MAX;
573 wndPtr->rectNormal = wndPtr->rectWindow;
575 wndPtr->dwStyle |= WS_MINIMIZE;
576 WINPOS_FindIconPos( hwnd );
577 x = wndPtr->ptIconPos.x;
578 y = wndPtr->ptIconPos.y;
579 cx = SYSMETRICS_CXICON;
580 cy = SYSMETRICS_CYICON;
581 swpflags |= SWP_NOCOPYBITS;
583 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
586 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
587 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
588 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
590 /* Store the current position and find the maximized size */
591 if (!(wndPtr->dwStyle & WS_MINIMIZE))
592 wndPtr->rectNormal = wndPtr->rectWindow;
594 NC_GetMinMaxInfo( hwnd, &maxSize,
595 &wndPtr->ptMaxPos, NULL, NULL );
596 x = wndPtr->ptMaxPos.x;
597 y = wndPtr->ptMaxPos.y;
599 if( wndPtr->dwStyle & WS_MINIMIZE )
600 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L ) )
602 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
605 else swpflags |= SWP_NOCOPYBITS;
609 wndPtr->dwStyle &= ~WS_MINIMIZE;
610 wndPtr->dwStyle |= WS_MAXIMIZE;
612 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
616 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
619 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
622 case SW_SHOWNOACTIVATE:
623 swpflags |= SWP_NOZORDER;
624 if (GetActiveWindow()) swpflags |= SWP_NOACTIVATE;
626 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
627 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
629 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
631 if (wndPtr->dwStyle & WS_MINIMIZE)
633 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L) )
635 swpflags |= SWP_NOSIZE | SWP_NOMOVE;
638 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
639 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
640 wndPtr->dwStyle &= ~WS_MINIMIZE;
641 if (wndPtr->flags & WIN_RESTORE_MAX)
643 /* Restore to maximized position */
644 NC_GetMinMaxInfo( hwnd, &maxSize, &wndPtr->ptMaxPos,
646 x = wndPtr->ptMaxPos.x;
647 y = wndPtr->ptMaxPos.y;
650 wndPtr->dwStyle |= WS_MAXIMIZE;
652 else /* Restore to normal position */
654 x = wndPtr->rectNormal.left;
655 y = wndPtr->rectNormal.top;
656 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
657 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
659 swpflags |= SWP_NOCOPYBITS;
661 else if (wndPtr->dwStyle & WS_MAXIMIZE)
663 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
664 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
665 wndPtr->dwStyle &= ~WS_MAXIMIZE;
666 x = wndPtr->rectNormal.left;
667 y = wndPtr->rectNormal.top;
668 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
669 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
671 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
675 showFlag = (cmd != SW_HIDE);
676 if (showFlag != wasVisible)
678 SendMessage16( hwnd, WM_SHOWWINDOW, showFlag, 0 );
679 if (!IsWindow( hwnd )) return wasVisible;
682 if ((wndPtr->dwStyle & WS_CHILD) &&
683 !IsWindowVisible( wndPtr->parent->hwndSelf ) &&
684 (swpflags & SWP_NOSIZE) && (swpflags & SWP_NOMOVE))
686 /* Don't call SetWindowPos() on invisible child windows */
687 if (cmd == SW_HIDE) wndPtr->dwStyle &= ~WS_VISIBLE;
688 else wndPtr->dwStyle |= WS_VISIBLE;
692 /* We can't activate a child window */
693 if (wndPtr->dwStyle & WS_CHILD)
694 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
695 SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
696 if (!IsWindow( hwnd )) return wasVisible;
699 if (wndPtr->flags & WIN_NEED_SIZE)
701 /* should happen only in CreateWindowEx() */
702 int wParam = SIZE_RESTORED;
704 wndPtr->flags &= ~WIN_NEED_SIZE;
705 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
706 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
707 SendMessage16( hwnd, WM_SIZE, wParam,
708 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
709 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
710 SendMessage16( hwnd, WM_MOVE, 0,
711 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
718 /***********************************************************************
719 * GetInternalWindowPos16 (USER.460)
721 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
723 WINDOWPLACEMENT16 wndpl;
724 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
725 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
726 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
727 return wndpl.showCmd;
731 /***********************************************************************
732 * GetInternalWindowPos32 (USER32.244)
734 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
736 WINDOWPLACEMENT32 wndpl;
737 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
738 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
739 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
740 return wndpl.showCmd;
744 /***********************************************************************
745 * SetInternalWindowPos16 (USER.461)
747 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
748 LPRECT16 rect, LPPOINT16 pt )
750 WINDOWPLACEMENT16 wndpl;
751 WND *wndPtr = WIN_FindWndPtr( hwnd );
753 wndpl.length = sizeof(wndpl);
754 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
755 wndpl.showCmd = showCmd;
756 if (pt) wndpl.ptMinPosition = *pt;
757 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
758 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
759 SetWindowPlacement16( hwnd, &wndpl );
763 /***********************************************************************
764 * SetInternalWindowPos32 (USER32.482)
766 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
767 LPRECT32 rect, LPPOINT32 pt )
769 WINDOWPLACEMENT32 wndpl;
770 WND *wndPtr = WIN_FindWndPtr( hwnd );
772 wndpl.length = sizeof(wndpl);
773 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
774 wndpl.showCmd = showCmd;
775 if (pt) wndpl.ptMinPosition = *pt;
776 if (rect) wndpl.rcNormalPosition = *rect;
777 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
778 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
779 SetWindowPlacement32( hwnd, &wndpl );
783 /***********************************************************************
784 * GetWindowPlacement16 (USER.370)
786 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
788 WND *wndPtr = WIN_FindWndPtr( hwnd );
789 if (!wndPtr) return FALSE;
791 wndpl->length = sizeof(*wndpl);
793 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
794 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
795 wndpl->ptMinPosition = wndPtr->ptIconPos;
796 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
797 wndpl->rcNormalPosition = wndPtr->rectNormal;
802 /***********************************************************************
803 * GetWindowPlacement32 (USER32.306)
805 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
807 WND *wndPtr = WIN_FindWndPtr( hwnd );
808 if (!wndPtr) return FALSE;
810 wndpl->length = sizeof(*wndpl);
812 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
813 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
814 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
815 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
816 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
821 /***********************************************************************
822 * SetWindowPlacement16 (USER.371)
824 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
826 WND *wndPtr = WIN_FindWndPtr( hwnd );
827 if (!wndPtr) return FALSE;
829 if (wndpl->flags & WPF_SETMINPOSITION)
830 wndPtr->ptIconPos = wndpl->ptMinPosition;
831 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
832 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
833 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
834 wndPtr->rectNormal = wndpl->rcNormalPosition;
835 ShowWindow( hwnd, wndpl->showCmd );
840 /***********************************************************************
841 * SetWindowPlacement32 (USER32.518)
843 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
845 WND *wndPtr = WIN_FindWndPtr( hwnd );
846 if (!wndPtr) return FALSE;
848 if (wndpl->flags & WPF_SETMINPOSITION)
849 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
850 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
851 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
852 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
853 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
854 ShowWindow( hwnd, wndpl->showCmd );
859 /*******************************************************************
860 * WINPOS_SetActiveWindow
862 * back-end to SetActiveWindow
864 BOOL32 WINPOS_SetActiveWindow( HWND32 hWnd, BOOL32 fMouse, BOOL32 fChangeFocus)
866 WND *wndPtr = WIN_FindWndPtr(hWnd);
867 WND *wndTemp = WIN_FindWndPtr(hwndActive);
868 CBTACTIVATESTRUCT16 *cbtStruct;
870 HANDLE hNewActiveQueue;
872 /* FIXME: When proper support for cooperative multitasking is in place
873 * hActiveQ will be global
878 /* paranoid checks */
879 if( hWnd == GetDesktopWindow() || hWnd == hwndActive )
882 if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
886 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
888 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
890 /* call CBT hook chain */
891 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
894 cbtStruct->fMouse = fMouse;
895 cbtStruct->hWndActive = hwndActive;
896 wRet = HOOK_CallHooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd,
897 (LPARAM)SEGPTR_GET(cbtStruct) );
898 SEGPTR_FREE(cbtStruct);
899 if (wRet) return wRet;
902 /* set prev active wnd to current active wnd and send notification */
903 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
905 if (!SendMessage16( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
907 if (GetSysModalWindow16() != hWnd) return 0;
908 /* disregard refusal if hWnd is sysmodal */
911 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
912 MAKEWPARAM( WA_INACTIVE, wIconized ),
915 /* check if something happened during message processing */
916 if( hwndPrevActive != hwndActive ) return 0;
922 /* send palette messages */
923 if (hWnd && SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
924 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
926 /* if prev wnd is minimized redraw icon title
929 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
931 if(wndTemp->dwStyle & WS_MINIMIZE)
932 RedrawIconTitle(hwndPrevActive);
936 /* managed windows will get ConfigureNotify event */
937 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
939 /* check Z-order and bring hWnd to the top */
940 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
941 if (wndTemp->dwStyle & WS_VISIBLE) break;
943 if( wndTemp != wndPtr )
944 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
945 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
946 if( !IsWindow(hWnd) ) return 0;
951 wndTemp = WIN_FindWndPtr( hwndPrevActive );
952 if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
954 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
956 /* send WM_ACTIVATEAPP if necessary */
957 if (hActiveQ != hNewActiveQueue)
961 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
963 for (ppWnd = list; *ppWnd; ppWnd++)
965 /* Make sure that the window still exists */
966 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
967 if ((*ppWnd)->hmemTaskQ != hActiveQ) continue;
968 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
969 0, QUEUE_GetQueueTask(hNewActiveQueue) );
971 HeapFree( SystemHeap, 0, list );
974 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
976 for (ppWnd = list; *ppWnd; ppWnd++)
978 /* Make sure that the window still exists */
979 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
980 if ((*ppWnd)->hmemTaskQ != hNewActiveQueue) continue;
981 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
982 1, QUEUE_GetQueueTask( hActiveQ ) );
984 HeapFree( SystemHeap, 0, list );
986 if (!IsWindow(hWnd)) return 0;
991 /* walk up to the first unowned window */
993 while (wndTemp->owner) wndTemp = wndTemp->owner;
994 /* and set last active owned popup */
995 wndTemp->hwndLastActive = hWnd;
997 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
998 SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
999 SendMessage32A( hWnd, WM_ACTIVATE,
1000 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1001 (LPARAM)hwndPrevActive );
1003 if( !IsWindow(hWnd) ) return 0;
1006 /* change focus if possible */
1007 if( fChangeFocus && GetFocus32() )
1008 if( WIN_GetTopParent(GetFocus32()) != hwndActive )
1009 FOCUS_SwitchFocus( GetFocus32(),
1010 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
1012 /* if active wnd is minimized redraw icon title
1015 wndPtr = WIN_FindWndPtr(hwndActive);
1016 if(wndPtr->dwStyle & WS_MINIMIZE)
1017 RedrawIconTitle(hwndActive);
1020 return (hWnd == hwndActive);
1024 /*******************************************************************
1025 * WINPOS_ChangeActiveWindow
1028 BOOL32 WINPOS_ChangeActiveWindow( HWND32 hWnd, BOOL32 mouseMsg )
1030 WND *wndPtr = WIN_FindWndPtr(hWnd);
1032 if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE );
1034 if( !wndPtr ) return FALSE;
1036 /* child windows get WM_CHILDACTIVATE message */
1037 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1038 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1040 /* owned popups imply owner activation - not sure */
1041 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1042 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1044 if (!(wndPtr = wndPtr->owner)) return FALSE;
1045 hWnd = wndPtr->hwndSelf;
1048 if( hWnd == hwndActive ) return FALSE;
1050 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1053 /* switch desktop queue to current active */
1054 if( wndPtr->parent == WIN_GetDesktop())
1055 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1061 /***********************************************************************
1062 * WINPOS_SendNCCalcSize
1064 * Send a WM_NCCALCSIZE message to a window.
1065 * All parameters are read-only except newClientRect.
1066 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1067 * when calcValidRect is TRUE.
1069 LONG WINPOS_SendNCCalcSize( HWND32 hwnd, BOOL32 calcValidRect,
1070 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1071 RECT16 *oldClientRect, SEGPTR winpos,
1072 RECT16 *newClientRect )
1074 NCCALCSIZE_PARAMS16 *params;
1077 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1078 params->rgrc[0] = *newWindowRect;
1081 params->rgrc[1] = *oldWindowRect;
1082 params->rgrc[2] = *oldClientRect;
1083 params->lppos = winpos;
1085 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1086 (LPARAM)SEGPTR_GET( params ) );
1087 dprintf_win(stddeb, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
1088 (int)params->rgrc[0].top, (int)params->rgrc[0].left,
1089 (int)params->rgrc[0].bottom, (int)params->rgrc[0].right);
1090 *newClientRect = params->rgrc[0];
1091 SEGPTR_FREE(params);
1096 /***********************************************************************
1097 * WINPOS_HandleWindowPosChanging16
1099 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1101 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1104 if (winpos->flags & SWP_NOSIZE) return 0;
1105 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1106 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1108 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1109 winpos->cx = MIN( winpos->cx, maxSize.x );
1110 winpos->cy = MIN( winpos->cy, maxSize.y );
1116 /***********************************************************************
1117 * WINPOS_HandleWindowPosChanging32
1119 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1121 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1124 if (winpos->flags & SWP_NOSIZE) return 0;
1125 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1126 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1128 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1129 winpos->cx = MIN( winpos->cx, maxSize.x );
1130 winpos->cy = MIN( winpos->cy, maxSize.y );
1136 /***********************************************************************
1137 * WINPOS_MoveWindowZOrder
1139 * Move a window in Z order, invalidating everything that needs it.
1140 * Only necessary for windows without associated X window.
1142 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
1145 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1147 /* We have two possible cases:
1148 * - The window is moving up: we have to invalidate all areas
1149 * of the window that were covered by other windows
1150 * - The window is moving down: we have to invalidate areas
1151 * of other windows covered by this one.
1154 if (hwndAfter == HWND_TOP)
1158 else if (hwndAfter == HWND_BOTTOM)
1160 if (!wndPtr->next) return; /* Already at the bottom */
1165 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1166 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1168 /* Determine which window we encounter first in Z-order */
1169 pWndCur = wndPtr->parent->child;
1170 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1171 pWndCur = pWndCur->next;
1172 movingUp = (pWndCur == pWndAfter);
1177 WND *pWndPrevAfter = wndPtr->next;
1178 WIN_UnlinkWindow( hwnd );
1179 WIN_LinkWindow( hwnd, hwndAfter );
1180 pWndCur = wndPtr->next;
1181 while (pWndCur != pWndPrevAfter)
1183 RECT32 rect = { pWndCur->rectWindow.left,
1184 pWndCur->rectWindow.top,
1185 pWndCur->rectWindow.right,
1186 pWndCur->rectWindow.bottom };
1187 OffsetRect32( &rect, -wndPtr->rectClient.left,
1188 -wndPtr->rectClient.top );
1189 PAINT_RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1190 RDW_FRAME | RDW_ERASE, 0 );
1191 pWndCur = pWndCur->next;
1194 else /* Moving down */
1196 pWndCur = wndPtr->next;
1197 WIN_UnlinkWindow( hwnd );
1198 WIN_LinkWindow( hwnd, hwndAfter );
1199 while (pWndCur != wndPtr)
1201 RECT32 rect = { pWndCur->rectWindow.left,
1202 pWndCur->rectWindow.top,
1203 pWndCur->rectWindow.right,
1204 pWndCur->rectWindow.bottom };
1205 OffsetRect32( &rect, -pWndCur->rectClient.left,
1206 -pWndCur->rectClient.top );
1207 PAINT_RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1208 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1209 pWndCur = pWndCur->next;
1214 /***********************************************************************
1215 * WINPOS_ReorderOwnedPopups
1217 * fix Z order taking into account owned popups -
1218 * basically we need to maintain them above owner window
1220 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
1222 WND* w = WIN_GetDesktop();
1226 /* if we are dealing with owned popup...
1228 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner && hwndInsertAfter != HWND_TOP )
1230 BOOL bFound = FALSE;
1231 HWND hwndLocalPrev = HWND_TOP;
1232 HWND hwndNewAfter = 0;
1236 if( !bFound && hwndInsertAfter == hwndLocalPrev )
1237 hwndInsertAfter = HWND_TOP;
1239 if( w->dwStyle & WS_POPUP && w->owner == wndPtr->owner )
1243 if( hwndInsertAfter == HWND_TOP )
1245 hwndInsertAfter = hwndLocalPrev;
1248 hwndNewAfter = hwndLocalPrev;
1251 if( w == wndPtr->owner )
1253 /* basically HWND_BOTTOM */
1254 hwndInsertAfter = hwndLocalPrev;
1257 hwndInsertAfter = hwndNewAfter;
1262 hwndLocalPrev = w->hwndSelf;
1268 /* or overlapped top-level window...
1270 if( !(wndPtr->dwStyle & WS_CHILD) )
1273 if( w == wndPtr ) break;
1275 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1277 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1278 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1279 hwndInsertAfter = w->hwndSelf;
1284 return hwndInsertAfter;
1287 /***********************************************************************
1288 * WINPOS_SizeMoveClean
1290 * Make window look nice without excessive repainting
1294 * visible regions are in window coordinates
1295 * update regions are in window client coordinates
1296 * client and window rectangles are in parent client coordinates
1298 static UINT WINPOS_SizeMoveClean(WND* Wnd, HRGN oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, UINT uFlags )
1300 HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf, DCX_WINDOW | DCX_CLIPSIBLINGS );
1301 HRGN dirtyRgn = CreateRectRgn(0,0,0,0);
1304 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1305 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1306 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1307 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1308 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1309 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1311 if( (lpOldWndRect->right - lpOldWndRect->left) != (Wnd->rectWindow.right - Wnd->rectWindow.left) ||
1312 (lpOldWndRect->bottom - lpOldWndRect->top) != (Wnd->rectWindow.bottom - Wnd->rectWindow.top) )
1313 uFlags |= SMC_DRAWFRAME;
1315 CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY);
1317 if( !(uFlags & SMC_NOCOPY) )
1318 CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1320 /* map regions to the parent client area */
1322 OffsetRgn(dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top);
1323 OffsetRgn(oldVisRgn, lpOldWndRect->left, lpOldWndRect->top);
1325 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1327 other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1329 /* map visible region to the Wnd client area */
1331 OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1332 Wnd->rectWindow.top - Wnd->rectClient.top );
1334 /* substract previously invalidated region from the Wnd visible region */
1336 my = (Wnd->hrgnUpdate > 1)? CombineRgn( newVisRgn, newVisRgn, Wnd->hrgnUpdate, RGN_DIFF)
1339 if( uFlags & SMC_NOCOPY ) /* invalidate Wnd visible region */
1341 if (my != NULLREGION) PAINT_RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1342 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1344 else /* bitblt old client area */
1349 int xfrom,yfrom,xto,yto,width,height;
1351 if( uFlags & SMC_DRAWFRAME )
1353 /* copy only client area, frame will be redrawn anyway */
1355 xfrom = lpOldClientRect->left; yfrom = lpOldClientRect->top;
1356 xto = Wnd->rectClient.left; yto = Wnd->rectClient.top;
1357 width = lpOldClientRect->right - xfrom; height = lpOldClientRect->bottom - yfrom;
1358 updateRgn = CreateRectRgn( 0, 0, width, height );
1359 CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1360 SetRectRgn( updateRgn, 0, 0, Wnd->rectClient.right - xto, Wnd->rectClient.bottom - yto );
1364 xfrom = lpOldWndRect->left; yfrom = lpOldWndRect->top;
1365 xto = Wnd->rectWindow.left; yto = Wnd->rectWindow.top;
1366 width = lpOldWndRect->right - xfrom; height = lpOldWndRect->bottom - yfrom;
1367 updateRgn = CreateRectRgn( xto - Wnd->rectClient.left,
1368 yto - Wnd->rectClient.top,
1369 Wnd->rectWindow.right - Wnd->rectClient.left,
1370 Wnd->rectWindow.bottom - Wnd->rectClient.top );
1373 CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1375 /* substract new visRgn from target rect to get a region that won't be copied */
1377 update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1379 /* Blt valid bits using parent window DC */
1381 if( my != NULLREGION && (xfrom != xto || yfrom != yto) )
1384 /* compute clipping region in parent client coordinates */
1386 OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top);
1387 CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1389 hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS);
1391 BitBlt( hDC, xto, yto, width, height, hDC, xfrom, yfrom, SRCCOPY );
1393 ReleaseDC( Wnd->parent->hwndSelf, hDC);
1396 if( update != NULLREGION )
1397 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1398 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1399 else if( uFlags & SMC_DRAWFRAME ) Wnd->flags |= WIN_NEEDS_NCPAINT;
1400 DeleteObject( updateRgn );
1403 /* erase uncovered areas */
1405 if( !(uFlags & SMC_NOPARENTERASE) && (other != NULLREGION ) )
1406 PAINT_RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1407 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1408 DeleteObject(dirtyRgn);
1409 DeleteObject(newVisRgn);
1414 /***********************************************************************
1415 * WINPOS_ForceXWindowRaise
1417 void WINPOS_ForceXWindowRaise( WND* pWnd )
1419 XWindowChanges winChanges;
1420 WND *wndStop, *wndLast;
1422 if (!pWnd->window) return;
1424 wndLast = wndStop = pWnd;
1425 winChanges.stack_mode = Above;
1426 XReconfigureWMWindow( display, pWnd->window, 0, CWStackMode, &winChanges );
1428 /* Recursively raise owned popups according to their z-order
1429 * (it would be easier with sibling-related Below but it doesn't
1430 * work very well with SGI mwm for instance)
1434 WND *wnd = WIN_GetDesktop()->child;
1436 while (wnd != wndStop)
1438 if (wnd->owner == pWnd &&
1439 (wnd->dwStyle & WS_POPUP) &&
1440 (wnd->dwStyle & WS_VISIBLE))
1446 WINPOS_ForceXWindowRaise( wndLast );
1453 /***********************************************************************
1454 * WINPOS_SetXWindowPos
1456 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1458 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1460 XWindowChanges winChanges;
1462 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1464 if (!(winpos->flags & SWP_NOSIZE))
1466 winChanges.width = winpos->cx;
1467 winChanges.height = winpos->cy;
1468 changeMask |= CWWidth | CWHeight;
1470 /* Tweak dialog window size hints */
1472 if ((wndPtr->flags & WIN_MANAGED) &&
1473 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1475 XSizeHints *size_hints = XAllocSizeHints();
1479 long supplied_return;
1481 XGetWMSizeHints( display, wndPtr->window, size_hints,
1482 &supplied_return, XA_WM_NORMAL_HINTS);
1483 size_hints->min_width = size_hints->max_width = winpos->cx;
1484 size_hints->min_height = size_hints->max_height = winpos->cy;
1485 XSetWMSizeHints( display, wndPtr->window, size_hints,
1486 XA_WM_NORMAL_HINTS );
1491 if (!(winpos->flags & SWP_NOMOVE))
1493 winChanges.x = winpos->x;
1494 winChanges.y = winpos->y;
1495 changeMask |= CWX | CWY;
1497 if (!(winpos->flags & SWP_NOZORDER))
1499 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1500 else winChanges.stack_mode = Below;
1501 if ((winpos->hwndInsertAfter != HWND_TOP) &&
1502 (winpos->hwndInsertAfter != HWND_BOTTOM))
1504 WND * insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1505 winChanges.sibling = insertPtr->window;
1506 changeMask |= CWSibling;
1508 changeMask |= CWStackMode;
1510 if (!changeMask) return;
1511 if (wndPtr->flags & WIN_MANAGED)
1512 XReconfigureWMWindow( display, wndPtr->window, 0,
1513 changeMask, &winChanges );
1514 else XConfigureWindow( display, wndPtr->window, changeMask, &winChanges );
1518 /***********************************************************************
1519 * SetWindowPos (USER.232)
1521 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1522 INT cx, INT cy, WORD flags )
1524 WINDOWPOS16 *winpos;
1526 RECT16 newWindowRect, newClientRect, oldWindowRect;
1528 HWND tempInsertAfter= 0;
1532 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
1533 hwnd, x, y, x+cx, y+cy, flags);
1534 /* Check window handle */
1536 if (hwnd == GetDesktopWindow()) return FALSE;
1537 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1539 if (wndPtr->dwStyle & WS_VISIBLE) flags &= ~SWP_SHOWWINDOW;
1542 uFlags |= SMC_NOPARENTERASE;
1543 flags &= ~SWP_HIDEWINDOW;
1544 if (!(flags & SWP_SHOWWINDOW)) flags |= SWP_NOREDRAW;
1547 /* Check for windows that may not be resized
1548 FIXME: this should be done only for Windows 3.0 programs
1549 if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
1550 flags |= SWP_NOSIZE | SWP_NOMOVE;
1552 /* Check dimensions */
1554 if (cx <= 0) cx = 1;
1555 if (cy <= 0) cy = 1;
1559 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1560 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1561 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1562 flags |= SWP_NOSIZE; /* Already the right size */
1563 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1564 flags |= SWP_NOMOVE; /* Already the right position */
1566 /* Check hwndInsertAfter */
1568 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1570 /* Ignore TOPMOST flags when activating a window */
1571 /* _and_ moving it in Z order. */
1572 if ((hwndInsertAfter == HWND_TOPMOST) ||
1573 (hwndInsertAfter == HWND_NOTOPMOST))
1574 hwndInsertAfter = HWND_TOP;
1576 /* TOPMOST not supported yet */
1577 if ((hwndInsertAfter == HWND_TOPMOST) ||
1578 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1580 /* hwndInsertAfter must be a sibling of the window */
1581 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1583 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1584 if( wnd->parent != wndPtr->parent ) return FALSE;
1585 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1588 if (hwndInsertAfter == HWND_TOP)
1589 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1590 else /* HWND_BOTTOM */
1591 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1593 /* Fill the WINDOWPOS structure */
1595 if (!(winpos = SEGPTR_NEW(WINDOWPOS16))) return FALSE;
1596 winpos->hwnd = hwnd;
1597 winpos->hwndInsertAfter = hwndInsertAfter;
1602 winpos->flags = flags;
1604 /* Send WM_WINDOWPOSCHANGING message */
1606 if (!(flags & SWP_NOSENDCHANGING))
1607 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0,
1608 (LPARAM)SEGPTR_GET(winpos) );
1610 /* Calculate new position and size */
1612 newWindowRect = wndPtr->rectWindow;
1613 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1614 : wndPtr->rectClient;
1616 if (!(winpos->flags & SWP_NOSIZE))
1618 newWindowRect.right = newWindowRect.left + winpos->cx;
1619 newWindowRect.bottom = newWindowRect.top + winpos->cy;
1621 if (!(winpos->flags & SWP_NOMOVE))
1623 newWindowRect.left = winpos->x;
1624 newWindowRect.top = winpos->y;
1625 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
1626 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
1628 OffsetRect16( &newClientRect, winpos->x - wndPtr->rectWindow.left,
1629 winpos->y - wndPtr->rectWindow.top );
1632 winpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1634 /* Reposition window in Z order */
1636 if (!(winpos->flags & SWP_NOZORDER))
1638 /* reorder owned popups if hwnd is top-level window
1640 if( wndPtr->parent == WIN_GetDesktop() )
1641 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1646 WIN_UnlinkWindow( winpos->hwnd );
1647 WIN_LinkWindow( winpos->hwnd, hwndInsertAfter );
1649 else WINPOS_MoveWindowZOrder( winpos->hwnd, hwndInsertAfter );
1652 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1653 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1654 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1657 /* Send WM_NCCALCSIZE message to get new client area */
1658 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1660 result = WINPOS_SendNCCalcSize( winpos->hwnd, TRUE, &newWindowRect,
1661 &wndPtr->rectWindow, &wndPtr->rectClient,
1662 SEGPTR_GET(winpos), &newClientRect );
1664 /* FIXME: WVR_ALIGNxxx */
1666 if( newClientRect.left != wndPtr->rectClient.left ||
1667 newClientRect.top != wndPtr->rectClient.top )
1668 winpos->flags &= ~SWP_NOCLIENTMOVE;
1670 if( (newClientRect.right - newClientRect.left !=
1671 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1672 (newClientRect.bottom - newClientRect.top !=
1673 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1674 winpos->flags &= ~SWP_NOCLIENTSIZE;
1677 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1678 newClientRect.top != wndPtr->rectClient.top) )
1679 winpos->flags &= ~SWP_NOCLIENTMOVE;
1681 /* Update active DCEs */
1683 if( !(flags & SWP_NOZORDER) || (flags & SWP_HIDEWINDOW) || (flags & SWP_SHOWWINDOW)
1684 || (memcmp(&newWindowRect,&wndPtr->rectWindow,sizeof(RECT16))
1685 && wndPtr->dwStyle & WS_VISIBLE ) )
1689 UnionRect16(&rect,&newWindowRect,&wndPtr->rectWindow);
1690 DCE_InvalidateDCE(wndPtr->parent, &rect);
1693 /* change geometry */
1695 oldWindowRect = wndPtr->rectWindow;
1699 RECT16 oldClientRect = wndPtr->rectClient;
1701 tempInsertAfter = winpos->hwndInsertAfter;
1703 winpos->hwndInsertAfter = hwndInsertAfter;
1705 /* postpone geometry change */
1707 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1709 WINPOS_SetXWindowPos( winpos );
1710 winpos->hwndInsertAfter = tempInsertAfter;
1712 else uFlags |= SMC_SETXPOS;
1714 wndPtr->rectWindow = newWindowRect;
1715 wndPtr->rectClient = newClientRect;
1717 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1718 if( (oldClientRect.left - oldWindowRect.left !=
1719 newClientRect.left - newWindowRect.left) ||
1720 (oldClientRect.top - oldWindowRect.top !=
1721 newClientRect.top - newWindowRect.top) || winpos->flags & SWP_NOCOPYBITS )
1723 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
1724 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1726 if( winpos->flags & SWP_FRAMECHANGED )
1731 if( oldClientRect.right > newClientRect.right )
1733 rect.left = newClientRect.right; rect.top = newClientRect.top;
1734 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1736 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1737 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1739 if( oldClientRect.bottom > newClientRect.bottom )
1741 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1742 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1743 rect.bottom = oldClientRect.bottom;
1745 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1746 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1748 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1753 RECT16 oldClientRect = wndPtr->rectClient;
1755 wndPtr->rectWindow = newWindowRect;
1756 wndPtr->rectClient = newClientRect;
1758 if( oldClientRect.bottom - oldClientRect.top ==
1759 newClientRect.bottom - newClientRect.top ) result &= ~WVR_VREDRAW;
1761 if( oldClientRect.right - oldClientRect.left ==
1762 newClientRect.right - newClientRect.left ) result &= ~WVR_HREDRAW;
1764 if( !(flags & (SWP_NOREDRAW | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
1766 uFlags |= ((winpos->flags & SWP_NOCOPYBITS) ||
1767 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS)) ? SMC_NOCOPY : 0;
1768 uFlags |= (winpos->flags & SWP_FRAMECHANGED) ? SMC_DRAWFRAME : 0;
1770 if( (winpos->flags & SWP_AGG_NOGEOMETRYCHANGE) != SWP_AGG_NOGEOMETRYCHANGE )
1771 uFlags = WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect,
1772 &oldClientRect, uFlags);
1775 /* adjust frame and do not erase parent */
1777 if( winpos->flags & SWP_FRAMECHANGED ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1778 if( winpos->flags & SWP_NOZORDER ) uFlags |= SMC_NOPARENTERASE;
1781 DeleteObject(visRgn);
1784 if (flags & SWP_SHOWWINDOW)
1786 wndPtr->dwStyle |= WS_VISIBLE;
1789 if( uFlags & SMC_SETXPOS )
1791 WINPOS_SetXWindowPos( winpos );
1792 winpos->hwndInsertAfter = tempInsertAfter;
1794 XMapWindow( display, wndPtr->window );
1798 if (!(flags & SWP_NOREDRAW))
1799 PAINT_RedrawWindow( winpos->hwnd, NULL, 0,
1800 RDW_INVALIDATE | RDW_ALLCHILDREN |
1801 RDW_FRAME | RDW_ERASENOW | RDW_ERASE, 0 );
1804 else if (flags & SWP_HIDEWINDOW)
1806 wndPtr->dwStyle &= ~WS_VISIBLE;
1809 XUnmapWindow( display, wndPtr->window );
1810 if( uFlags & SMC_SETXPOS )
1812 WINPOS_SetXWindowPos( winpos );
1813 winpos->hwndInsertAfter = tempInsertAfter;
1818 if (!(flags & SWP_NOREDRAW))
1820 RECT32 rect = { oldWindowRect.left, oldWindowRect.top,
1821 oldWindowRect.right, oldWindowRect.bottom };
1822 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, &rect, 0,
1823 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE | RDW_ERASENOW, 0);
1825 uFlags |= SMC_NOPARENTERASE;
1828 if ((winpos->hwnd == GetFocus32()) ||
1829 IsChild( winpos->hwnd, GetFocus32()))
1831 /* Revert focus to parent */
1832 SetFocus32( GetParent32(winpos->hwnd) );
1834 if (hwnd == CARET_GetHwnd()) DestroyCaret();
1836 if (winpos->hwnd == hwndActive)
1838 /* Activate previously active window if possible */
1839 HWND newActive = hwndPrevActive;
1840 if (!IsWindow(newActive) || (newActive == winpos->hwnd))
1842 newActive = GetTopWindow( GetDesktopWindow() );
1843 if (newActive == winpos->hwnd)
1844 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1846 WINPOS_ChangeActiveWindow( newActive, FALSE );
1850 /* Activate the window */
1852 if (!(flags & SWP_NOACTIVATE))
1853 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
1855 /* Repaint the window */
1857 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
1859 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1861 if (!(flags & SWP_DEFERERASE) && !(uFlags & SMC_NOPARENTERASE) )
1862 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_ALLCHILDREN | RDW_ERASENOW, 0 );
1863 else if( wndPtr->parent == WIN_GetDesktop() && wndPtr->parent->flags & WIN_NEEDS_ERASEBKGND )
1864 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_NOCHILDREN | RDW_ERASENOW, 0 );
1866 /* And last, send the WM_WINDOWPOSCHANGED message */
1868 dprintf_win(stddeb,"\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1870 if ( ((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
1871 !(winpos->flags & SWP_NOSENDCHANGING))
1872 SendMessage16( winpos->hwnd, WM_WINDOWPOSCHANGED,
1873 0, (LPARAM)SEGPTR_GET(winpos) );
1875 SEGPTR_FREE(winpos);
1880 /***********************************************************************
1881 * BeginDeferWindowPos (USER.259)
1883 HDWP16 BeginDeferWindowPos( INT count )
1888 if (count <= 0) return 0;
1889 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS16) );
1890 if (!handle) return 0;
1891 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1892 pDWP->actualCount = 0;
1893 pDWP->suggestedCount = count;
1895 pDWP->wMagic = DWP_MAGIC;
1896 pDWP->hwndParent = 0;
1901 /***********************************************************************
1902 * DeferWindowPos (USER.260)
1904 HDWP16 DeferWindowPos( HDWP16 hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
1905 INT cx, INT cy, UINT flags )
1909 HDWP16 newhdwp = hdwp;
1912 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1913 if (!pDWP) return 0;
1914 if (hwnd == GetDesktopWindow()) return 0;
1916 /* All the windows of a DeferWindowPos() must have the same parent */
1918 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
1919 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1920 else if (parent != pDWP->hwndParent)
1922 USER_HEAP_FREE( hdwp );
1926 for (i = 0; i < pDWP->actualCount; i++)
1928 if (pDWP->winPos[i].hwnd == hwnd)
1930 /* Merge with the other changes */
1931 if (!(flags & SWP_NOZORDER))
1933 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1935 if (!(flags & SWP_NOMOVE))
1937 pDWP->winPos[i].x = x;
1938 pDWP->winPos[i].y = y;
1940 if (!(flags & SWP_NOSIZE))
1942 pDWP->winPos[i].cx = cx;
1943 pDWP->winPos[i].cy = cy;
1945 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
1946 SWP_NOZORDER | SWP_NOREDRAW |
1947 SWP_NOACTIVATE | SWP_NOCOPYBITS |
1949 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1954 if (pDWP->actualCount >= pDWP->suggestedCount)
1956 newhdwp = USER_HEAP_REALLOC( hdwp,
1957 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS16) );
1958 if (!newhdwp) return 0;
1959 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1960 pDWP->suggestedCount++;
1962 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1963 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1964 pDWP->winPos[pDWP->actualCount].x = x;
1965 pDWP->winPos[pDWP->actualCount].y = y;
1966 pDWP->winPos[pDWP->actualCount].cx = cx;
1967 pDWP->winPos[pDWP->actualCount].cy = cy;
1968 pDWP->winPos[pDWP->actualCount].flags = flags;
1969 pDWP->actualCount++;
1974 /***********************************************************************
1975 * EndDeferWindowPos (USER.261)
1977 BOOL EndDeferWindowPos( HDWP16 hdwp )
1980 WINDOWPOS16 *winpos;
1984 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1985 if (!pDWP) return FALSE;
1986 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1988 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1989 winpos->x, winpos->y, winpos->cx, winpos->cy,
1990 winpos->flags ))) break;
1992 USER_HEAP_FREE( hdwp );
1997 /***********************************************************************
1998 * TileChildWindows (USER.199)
2000 void TileChildWindows( HWND parent, WORD action )
2002 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
2005 /***********************************************************************
2006 * CascageChildWindows (USER.198)
2008 void CascadeChildWindows( HWND parent, WORD action )
2010 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);