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( HWND 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) );
714 if (hwnd == GetFocus())
716 SetFocus( (wndPtr->dwStyle & WS_CHILD)? wndPtr->parent->hwndSelf: 0 );
717 if (hwnd == CARET_GetHwnd()) DestroyCaret();
724 /***********************************************************************
725 * GetInternalWindowPos16 (USER.460)
727 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
729 WINDOWPLACEMENT16 wndpl;
730 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
731 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
732 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
733 return wndpl.showCmd;
737 /***********************************************************************
738 * GetInternalWindowPos32 (USER32.244)
740 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
742 WINDOWPLACEMENT32 wndpl;
743 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
744 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
745 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
746 return wndpl.showCmd;
750 /***********************************************************************
751 * SetInternalWindowPos16 (USER.461)
753 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
754 LPRECT16 rect, LPPOINT16 pt )
756 WINDOWPLACEMENT16 wndpl;
757 WND *wndPtr = WIN_FindWndPtr( hwnd );
759 wndpl.length = sizeof(wndpl);
760 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
761 wndpl.showCmd = showCmd;
762 if (pt) wndpl.ptMinPosition = *pt;
763 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
764 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
765 SetWindowPlacement16( hwnd, &wndpl );
769 /***********************************************************************
770 * SetInternalWindowPos32 (USER32.482)
772 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
773 LPRECT32 rect, LPPOINT32 pt )
775 WINDOWPLACEMENT32 wndpl;
776 WND *wndPtr = WIN_FindWndPtr( hwnd );
778 wndpl.length = sizeof(wndpl);
779 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
780 wndpl.showCmd = showCmd;
781 if (pt) wndpl.ptMinPosition = *pt;
782 if (rect) wndpl.rcNormalPosition = *rect;
783 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
784 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
785 SetWindowPlacement32( hwnd, &wndpl );
789 /***********************************************************************
790 * GetWindowPlacement16 (USER.370)
792 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
794 WND *wndPtr = WIN_FindWndPtr( hwnd );
795 if (!wndPtr) return FALSE;
797 wndpl->length = sizeof(*wndpl);
799 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
800 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
801 wndpl->ptMinPosition = wndPtr->ptIconPos;
802 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
803 wndpl->rcNormalPosition = wndPtr->rectNormal;
808 /***********************************************************************
809 * GetWindowPlacement32 (USER32.306)
811 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
813 WND *wndPtr = WIN_FindWndPtr( hwnd );
814 if (!wndPtr) return FALSE;
816 wndpl->length = sizeof(*wndpl);
818 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
819 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
820 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
821 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
822 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
827 /***********************************************************************
828 * SetWindowPlacement16 (USER.371)
830 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
832 WND *wndPtr = WIN_FindWndPtr( hwnd );
833 if (!wndPtr) return FALSE;
835 if (wndpl->flags & WPF_SETMINPOSITION)
836 wndPtr->ptIconPos = wndpl->ptMinPosition;
837 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
838 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
839 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
840 wndPtr->rectNormal = wndpl->rcNormalPosition;
841 ShowWindow( hwnd, wndpl->showCmd );
846 /***********************************************************************
847 * SetWindowPlacement32 (USER32.518)
849 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
851 WND *wndPtr = WIN_FindWndPtr( hwnd );
852 if (!wndPtr) return FALSE;
854 if (wndpl->flags & WPF_SETMINPOSITION)
855 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
856 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
857 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
858 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
859 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
860 ShowWindow( hwnd, wndpl->showCmd );
865 /*******************************************************************
866 * WINPOS_SetActiveWindow
868 * back-end to SetActiveWindow
870 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus )
872 WND *wndPtr = WIN_FindWndPtr(hWnd);
873 WND *wndTemp = WIN_FindWndPtr(hwndActive);
874 CBTACTIVATESTRUCT16 *cbtStruct;
876 HANDLE hNewActiveQueue;
878 /* FIXME: When proper support for cooperative multitasking is in place
879 * hActiveQ will be global
884 /* paranoid checks */
885 if( hWnd == GetDesktopWindow() || hWnd == hwndActive )
888 if (wndPtr && (GetTaskQueue(0) != wndPtr->hmemTaskQ))
892 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
894 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
896 /* call CBT hook chain */
897 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16)))
900 cbtStruct->fMouse = fMouse;
901 cbtStruct->hWndActive = hwndActive;
902 wRet = HOOK_CallHooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd,
903 (LPARAM)SEGPTR_GET(cbtStruct) );
904 SEGPTR_FREE(cbtStruct);
905 if (wRet) return wRet;
908 /* set prev active wnd to current active wnd and send notification */
909 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
911 if (!SendMessage16( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
913 if (GetSysModalWindow16() != hWnd) return 0;
914 /* disregard refusal if hWnd is sysmodal */
917 SendMessage32A( hwndPrevActive, WM_ACTIVATE,
918 MAKEWPARAM( WA_INACTIVE, wIconized ),
921 /* check if something happened during message processing */
922 if( hwndPrevActive != hwndActive ) return 0;
928 /* send palette messages */
929 if (hWnd && SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
930 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
932 /* if prev wnd is minimized redraw icon title
935 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
937 if(wndTemp->dwStyle & WS_MINIMIZE)
938 RedrawIconTitle(hwndPrevActive);
942 /* managed windows will get ConfigureNotify event */
943 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
945 /* check Z-order and bring hWnd to the top */
946 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
947 if (wndTemp->dwStyle & WS_VISIBLE) break;
949 if( wndTemp != wndPtr )
950 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
951 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
952 if( !IsWindow(hWnd) ) return 0;
957 wndTemp = WIN_FindWndPtr( hwndPrevActive );
958 if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
960 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
962 /* send WM_ACTIVATEAPP if necessary */
963 if (hActiveQ != hNewActiveQueue)
967 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
969 for (ppWnd = list; *ppWnd; ppWnd++)
971 /* Make sure that the window still exists */
972 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
973 if ((*ppWnd)->hmemTaskQ != hActiveQ) continue;
974 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
975 0, QUEUE_GetQueueTask(hNewActiveQueue) );
977 HeapFree( SystemHeap, 0, list );
980 if ((list = WIN_BuildWinArray( WIN_GetDesktop() )))
982 for (ppWnd = list; *ppWnd; ppWnd++)
984 /* Make sure that the window still exists */
985 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
986 if ((*ppWnd)->hmemTaskQ != hNewActiveQueue) continue;
987 SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP,
988 1, QUEUE_GetQueueTask( hActiveQ ) );
990 HeapFree( SystemHeap, 0, list );
992 if (!IsWindow(hWnd)) return 0;
997 /* walk up to the first unowned window */
999 while (wndTemp->owner) wndTemp = wndTemp->owner;
1000 /* and set last active owned popup */
1001 wndTemp->hwndLastActive = hWnd;
1003 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1004 SendMessage16( hWnd, WM_NCACTIVATE, TRUE, 0 );
1005 SendMessage32A( hWnd, WM_ACTIVATE,
1006 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1007 (LPARAM)hwndPrevActive );
1009 if( !IsWindow(hWnd) ) return 0;
1012 /* change focus if possible */
1013 if( fChangeFocus && GetFocus() )
1014 if( WIN_GetTopParent(GetFocus()) != hwndActive )
1015 FOCUS_SwitchFocus( GetFocus(),
1016 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
1018 /* if active wnd is minimized redraw icon title
1021 wndPtr = WIN_FindWndPtr(hwndActive);
1022 if(wndPtr->dwStyle & WS_MINIMIZE)
1023 RedrawIconTitle(hwndActive);
1026 return (hWnd == hwndActive);
1030 /*******************************************************************
1031 * WINPOS_ChangeActiveWindow
1034 BOOL WINPOS_ChangeActiveWindow( HWND hWnd, BOOL mouseMsg )
1036 WND *wndPtr = WIN_FindWndPtr(hWnd);
1038 if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE );
1040 if( !wndPtr ) return FALSE;
1042 /* child windows get WM_CHILDACTIVATE message */
1043 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1044 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1046 /* owned popups imply owner activation - not sure */
1047 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1048 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1050 if (!(wndPtr = wndPtr->owner)) return FALSE;
1051 hWnd = wndPtr->hwndSelf;
1054 if( hWnd == hwndActive ) return FALSE;
1056 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1059 /* switch desktop queue to current active */
1060 if( wndPtr->parent == WIN_GetDesktop())
1061 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1067 /***********************************************************************
1068 * WINPOS_SendNCCalcSize
1070 * Send a WM_NCCALCSIZE message to a window.
1071 * All parameters are read-only except newClientRect.
1072 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1073 * when calcValidRect is TRUE.
1075 LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect,
1076 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1077 RECT16 *oldClientRect, SEGPTR winpos,
1078 RECT16 *newClientRect )
1080 NCCALCSIZE_PARAMS16 *params;
1083 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1084 params->rgrc[0] = *newWindowRect;
1087 params->rgrc[1] = *oldWindowRect;
1088 params->rgrc[2] = *oldClientRect;
1089 params->lppos = winpos;
1091 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1092 (LPARAM)SEGPTR_GET( params ) );
1093 dprintf_win(stddeb, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
1094 (int)params->rgrc[0].top, (int)params->rgrc[0].left,
1095 (int)params->rgrc[0].bottom, (int)params->rgrc[0].right);
1096 *newClientRect = params->rgrc[0];
1097 SEGPTR_FREE(params);
1102 /***********************************************************************
1103 * WINPOS_HandleWindowPosChanging16
1105 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1107 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1110 if (winpos->flags & SWP_NOSIZE) return 0;
1111 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1112 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1114 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1115 winpos->cx = MIN( winpos->cx, maxSize.x );
1116 winpos->cy = MIN( winpos->cy, maxSize.y );
1122 /***********************************************************************
1123 * WINPOS_HandleWindowPosChanging32
1125 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1127 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1130 if (winpos->flags & SWP_NOSIZE) return 0;
1131 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1132 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1134 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1135 winpos->cx = MIN( winpos->cx, maxSize.x );
1136 winpos->cy = MIN( winpos->cy, maxSize.y );
1142 /***********************************************************************
1143 * WINPOS_MoveWindowZOrder
1145 * Move a window in Z order, invalidating everything that needs it.
1146 * Only necessary for windows without associated X window.
1148 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
1151 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1153 /* We have two possible cases:
1154 * - The window is moving up: we have to invalidate all areas
1155 * of the window that were covered by other windows
1156 * - The window is moving down: we have to invalidate areas
1157 * of other windows covered by this one.
1160 if (hwndAfter == HWND_TOP)
1164 else if (hwndAfter == HWND_BOTTOM)
1166 if (!wndPtr->next) return; /* Already at the bottom */
1171 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1172 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1174 /* Determine which window we encounter first in Z-order */
1175 pWndCur = wndPtr->parent->child;
1176 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1177 pWndCur = pWndCur->next;
1178 movingUp = (pWndCur == pWndAfter);
1183 WND *pWndPrevAfter = wndPtr->next;
1184 WIN_UnlinkWindow( hwnd );
1185 WIN_LinkWindow( hwnd, hwndAfter );
1186 pWndCur = wndPtr->next;
1187 while (pWndCur != pWndPrevAfter)
1189 RECT32 rect = { pWndCur->rectWindow.left,
1190 pWndCur->rectWindow.top,
1191 pWndCur->rectWindow.right,
1192 pWndCur->rectWindow.bottom };
1193 OffsetRect32( &rect, -wndPtr->rectClient.left,
1194 -wndPtr->rectClient.top );
1195 PAINT_RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1196 RDW_FRAME | RDW_ERASE, 0 );
1197 pWndCur = pWndCur->next;
1200 else /* Moving down */
1202 pWndCur = wndPtr->next;
1203 WIN_UnlinkWindow( hwnd );
1204 WIN_LinkWindow( hwnd, hwndAfter );
1205 while (pWndCur != wndPtr)
1207 RECT32 rect = { pWndCur->rectWindow.left,
1208 pWndCur->rectWindow.top,
1209 pWndCur->rectWindow.right,
1210 pWndCur->rectWindow.bottom };
1211 OffsetRect32( &rect, -pWndCur->rectClient.left,
1212 -pWndCur->rectClient.top );
1213 PAINT_RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1214 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1215 pWndCur = pWndCur->next;
1220 /***********************************************************************
1221 * WINPOS_ReorderOwnedPopups
1223 * fix Z order taking into account owned popups -
1224 * basically we need to maintain them above owner window
1226 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
1228 WND* w = WIN_GetDesktop();
1232 /* if we are dealing with owned popup...
1234 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner && hwndInsertAfter != HWND_TOP )
1236 BOOL bFound = FALSE;
1237 HWND hwndLocalPrev = HWND_TOP;
1238 HWND hwndNewAfter = 0;
1242 if( !bFound && hwndInsertAfter == hwndLocalPrev )
1243 hwndInsertAfter = HWND_TOP;
1245 if( w->dwStyle & WS_POPUP && w->owner == wndPtr->owner )
1249 if( hwndInsertAfter == HWND_TOP )
1251 hwndInsertAfter = hwndLocalPrev;
1254 hwndNewAfter = hwndLocalPrev;
1257 if( w == wndPtr->owner )
1259 /* basically HWND_BOTTOM */
1260 hwndInsertAfter = hwndLocalPrev;
1263 hwndInsertAfter = hwndNewAfter;
1268 hwndLocalPrev = w->hwndSelf;
1274 /* or overlapped top-level window...
1276 if( !(wndPtr->dwStyle & WS_CHILD) )
1279 if( w == wndPtr ) break;
1281 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1283 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1284 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1285 hwndInsertAfter = w->hwndSelf;
1290 return hwndInsertAfter;
1293 /***********************************************************************
1294 * WINPOS_SizeMoveClean
1296 * Make window look nice without excessive repainting
1300 * visible regions are in window coordinates
1301 * update regions are in window client coordinates
1302 * client and window rectangles are in parent client coordinates
1304 static UINT WINPOS_SizeMoveClean(WND* Wnd, HRGN oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, UINT uFlags )
1306 HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf, DCX_WINDOW | DCX_CLIPSIBLINGS );
1307 HRGN dirtyRgn = CreateRectRgn(0,0,0,0);
1310 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1311 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1312 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1313 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1314 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1315 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1317 if( (lpOldWndRect->right - lpOldWndRect->left) != (Wnd->rectWindow.right - Wnd->rectWindow.left) ||
1318 (lpOldWndRect->bottom - lpOldWndRect->top) != (Wnd->rectWindow.bottom - Wnd->rectWindow.top) )
1319 uFlags |= SMC_DRAWFRAME;
1321 CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY);
1323 if( !(uFlags & SMC_NOCOPY) )
1324 CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1326 /* map regions to the parent client area */
1328 OffsetRgn(dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top);
1329 OffsetRgn(oldVisRgn, lpOldWndRect->left, lpOldWndRect->top);
1331 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1333 other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1335 /* map visible region to the Wnd client area */
1337 OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1338 Wnd->rectWindow.top - Wnd->rectClient.top );
1340 /* substract previously invalidated region from the Wnd visible region */
1342 my = (Wnd->hrgnUpdate > 1)? CombineRgn( newVisRgn, newVisRgn, Wnd->hrgnUpdate, RGN_DIFF)
1345 if( uFlags & SMC_NOCOPY ) /* invalidate Wnd visible region */
1347 if (my != NULLREGION) PAINT_RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1348 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1350 else /* bitblt old client area */
1355 int xfrom,yfrom,xto,yto,width,height;
1357 if( uFlags & SMC_DRAWFRAME )
1359 /* copy only client area, frame will be redrawn anyway */
1361 xfrom = lpOldClientRect->left; yfrom = lpOldClientRect->top;
1362 xto = Wnd->rectClient.left; yto = Wnd->rectClient.top;
1363 width = lpOldClientRect->right - xfrom; height = lpOldClientRect->bottom - yfrom;
1364 updateRgn = CreateRectRgn( 0, 0, width, height );
1365 CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1366 SetRectRgn( updateRgn, 0, 0, Wnd->rectClient.right - xto, Wnd->rectClient.bottom - yto );
1370 xfrom = lpOldWndRect->left; yfrom = lpOldWndRect->top;
1371 xto = Wnd->rectWindow.left; yto = Wnd->rectWindow.top;
1372 width = lpOldWndRect->right - xfrom; height = lpOldWndRect->bottom - yfrom;
1373 updateRgn = CreateRectRgn( xto - Wnd->rectClient.left,
1374 yto - Wnd->rectClient.top,
1375 Wnd->rectWindow.right - Wnd->rectClient.left,
1376 Wnd->rectWindow.bottom - Wnd->rectClient.top );
1379 CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1381 /* substract new visRgn from target rect to get a region that won't be copied */
1383 update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1385 /* Blt valid bits using parent window DC */
1387 if( my != NULLREGION && (xfrom != xto || yfrom != yto) )
1390 /* compute clipping region in parent client coordinates */
1392 OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top);
1393 CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1395 hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS);
1397 BitBlt( hDC, xto, yto, width, height, hDC, xfrom, yfrom, SRCCOPY );
1399 ReleaseDC( Wnd->parent->hwndSelf, hDC);
1402 if( update != NULLREGION )
1403 PAINT_RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1404 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1405 else if( uFlags & SMC_DRAWFRAME ) Wnd->flags |= WIN_NEEDS_NCPAINT;
1406 DeleteObject( updateRgn );
1409 /* erase uncovered areas */
1411 if( !(uFlags & SMC_NOPARENTERASE) && (other != NULLREGION ) )
1412 PAINT_RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1413 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN );
1414 DeleteObject(dirtyRgn);
1415 DeleteObject(newVisRgn);
1420 /***********************************************************************
1421 * WINPOS_ForceXWindowRaise
1423 void WINPOS_ForceXWindowRaise( WND* pWnd )
1425 XWindowChanges winChanges;
1426 WND *wndStop, *wndLast;
1428 if (!pWnd->window) return;
1430 wndLast = wndStop = pWnd;
1431 winChanges.stack_mode = Above;
1432 XReconfigureWMWindow( display, pWnd->window, 0, CWStackMode, &winChanges );
1434 /* Recursively raise owned popups according to their z-order
1435 * (it would be easier with sibling-related Below but it doesn't
1436 * work very well with SGI mwm for instance)
1440 WND *wnd = WIN_GetDesktop()->child;
1442 while (wnd != wndStop)
1444 if (wnd->owner == pWnd &&
1445 (wnd->dwStyle & WS_POPUP) &&
1446 (wnd->dwStyle & WS_VISIBLE))
1452 WINPOS_ForceXWindowRaise( wndLast );
1459 /***********************************************************************
1460 * WINPOS_SetXWindowPos
1462 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1464 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1466 XWindowChanges winChanges;
1468 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1470 if (!(winpos->flags & SWP_NOSIZE))
1472 winChanges.width = winpos->cx;
1473 winChanges.height = winpos->cy;
1474 changeMask |= CWWidth | CWHeight;
1476 /* Tweak dialog window size hints */
1478 if ((wndPtr->flags & WIN_MANAGED) &&
1479 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1481 XSizeHints *size_hints = XAllocSizeHints();
1485 long supplied_return;
1487 XGetWMSizeHints( display, wndPtr->window, size_hints,
1488 &supplied_return, XA_WM_NORMAL_HINTS);
1489 size_hints->min_width = size_hints->max_width = winpos->cx;
1490 size_hints->min_height = size_hints->max_height = winpos->cy;
1491 XSetWMSizeHints( display, wndPtr->window, size_hints,
1492 XA_WM_NORMAL_HINTS );
1497 if (!(winpos->flags & SWP_NOMOVE))
1499 winChanges.x = winpos->x;
1500 winChanges.y = winpos->y;
1501 changeMask |= CWX | CWY;
1503 if (!(winpos->flags & SWP_NOZORDER))
1505 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1506 else winChanges.stack_mode = Below;
1507 if ((winpos->hwndInsertAfter != HWND_TOP) &&
1508 (winpos->hwndInsertAfter != HWND_BOTTOM))
1510 WND * insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1511 winChanges.sibling = insertPtr->window;
1512 changeMask |= CWSibling;
1514 changeMask |= CWStackMode;
1516 if (!changeMask) return;
1517 if (wndPtr->flags & WIN_MANAGED)
1518 XReconfigureWMWindow( display, wndPtr->window, 0,
1519 changeMask, &winChanges );
1520 else XConfigureWindow( display, wndPtr->window, changeMask, &winChanges );
1524 /***********************************************************************
1525 * SetWindowPos (USER.232)
1527 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1528 INT cx, INT cy, WORD flags )
1530 WINDOWPOS16 *winpos;
1532 RECT16 newWindowRect, newClientRect, oldWindowRect;
1534 HWND tempInsertAfter= 0;
1538 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, (%i,%i)-(%i,%i) flags %08x\n",
1539 hwnd, x, y, x+cx, y+cy, flags);
1540 /* Check window handle */
1542 if (hwnd == GetDesktopWindow()) return FALSE;
1543 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1545 if (wndPtr->dwStyle & WS_VISIBLE) flags &= ~SWP_SHOWWINDOW;
1548 uFlags |= SMC_NOPARENTERASE;
1549 flags &= ~SWP_HIDEWINDOW;
1550 if (!(flags & SWP_SHOWWINDOW)) flags |= SWP_NOREDRAW;
1553 /* Check for windows that may not be resized
1554 FIXME: this should be done only for Windows 3.0 programs
1555 if (flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW ) )
1556 flags |= SWP_NOSIZE | SWP_NOMOVE;
1558 /* Check dimensions */
1560 if (cx <= 0) cx = 1;
1561 if (cy <= 0) cy = 1;
1565 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1566 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1567 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1568 flags |= SWP_NOSIZE; /* Already the right size */
1569 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1570 flags |= SWP_NOMOVE; /* Already the right position */
1572 /* Check hwndInsertAfter */
1574 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1576 /* Ignore TOPMOST flags when activating a window */
1577 /* _and_ moving it in Z order. */
1578 if ((hwndInsertAfter == HWND_TOPMOST) ||
1579 (hwndInsertAfter == HWND_NOTOPMOST))
1580 hwndInsertAfter = HWND_TOP;
1582 /* TOPMOST not supported yet */
1583 if ((hwndInsertAfter == HWND_TOPMOST) ||
1584 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1586 /* hwndInsertAfter must be a sibling of the window */
1587 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1589 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1590 if( wnd->parent != wndPtr->parent ) return FALSE;
1591 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1594 if (hwndInsertAfter == HWND_TOP)
1595 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1596 else /* HWND_BOTTOM */
1597 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1599 /* Fill the WINDOWPOS structure */
1601 if (!(winpos = SEGPTR_NEW(WINDOWPOS16))) return FALSE;
1602 winpos->hwnd = hwnd;
1603 winpos->hwndInsertAfter = hwndInsertAfter;
1608 winpos->flags = flags;
1610 /* Send WM_WINDOWPOSCHANGING message */
1612 if (!(flags & SWP_NOSENDCHANGING))
1613 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0,
1614 (LPARAM)SEGPTR_GET(winpos) );
1616 /* Calculate new position and size */
1618 newWindowRect = wndPtr->rectWindow;
1619 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
1620 : wndPtr->rectClient;
1622 if (!(winpos->flags & SWP_NOSIZE))
1624 newWindowRect.right = newWindowRect.left + winpos->cx;
1625 newWindowRect.bottom = newWindowRect.top + winpos->cy;
1627 if (!(winpos->flags & SWP_NOMOVE))
1629 newWindowRect.left = winpos->x;
1630 newWindowRect.top = winpos->y;
1631 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
1632 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
1634 OffsetRect16( &newClientRect, winpos->x - wndPtr->rectWindow.left,
1635 winpos->y - wndPtr->rectWindow.top );
1638 winpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1640 /* Reposition window in Z order */
1642 if (!(winpos->flags & SWP_NOZORDER))
1644 /* reorder owned popups if hwnd is top-level window
1646 if( wndPtr->parent == WIN_GetDesktop() )
1647 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1652 WIN_UnlinkWindow( winpos->hwnd );
1653 WIN_LinkWindow( winpos->hwnd, hwndInsertAfter );
1655 else WINPOS_MoveWindowZOrder( winpos->hwnd, hwndInsertAfter );
1658 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1659 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1660 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1663 /* Send WM_NCCALCSIZE message to get new client area */
1664 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1666 result = WINPOS_SendNCCalcSize( winpos->hwnd, TRUE, &newWindowRect,
1667 &wndPtr->rectWindow, &wndPtr->rectClient,
1668 SEGPTR_GET(winpos), &newClientRect );
1670 /* FIXME: WVR_ALIGNxxx */
1672 if( newClientRect.left != wndPtr->rectClient.left ||
1673 newClientRect.top != wndPtr->rectClient.top )
1674 winpos->flags &= ~SWP_NOCLIENTMOVE;
1676 if( (newClientRect.right - newClientRect.left !=
1677 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1678 (newClientRect.bottom - newClientRect.top !=
1679 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1680 winpos->flags &= ~SWP_NOCLIENTSIZE;
1683 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1684 newClientRect.top != wndPtr->rectClient.top) )
1685 winpos->flags &= ~SWP_NOCLIENTMOVE;
1687 /* Update active DCEs */
1689 if( !(flags & SWP_NOZORDER) || (flags & SWP_HIDEWINDOW) || (flags & SWP_SHOWWINDOW)
1690 || (memcmp(&newWindowRect,&wndPtr->rectWindow,sizeof(RECT16))
1691 && wndPtr->dwStyle & WS_VISIBLE ) )
1695 UnionRect16(&rect,&newWindowRect,&wndPtr->rectWindow);
1696 DCE_InvalidateDCE(wndPtr->parent, &rect);
1699 /* change geometry */
1701 oldWindowRect = wndPtr->rectWindow;
1705 RECT16 oldClientRect = wndPtr->rectClient;
1707 tempInsertAfter = winpos->hwndInsertAfter;
1709 winpos->hwndInsertAfter = hwndInsertAfter;
1711 /* postpone geometry change */
1713 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1715 WINPOS_SetXWindowPos( winpos );
1716 winpos->hwndInsertAfter = tempInsertAfter;
1718 else uFlags |= SMC_SETXPOS;
1720 wndPtr->rectWindow = newWindowRect;
1721 wndPtr->rectClient = newClientRect;
1723 if( !(flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW)) )
1724 if( (oldClientRect.left - oldWindowRect.left !=
1725 newClientRect.left - newWindowRect.left) ||
1726 (oldClientRect.top - oldWindowRect.top !=
1727 newClientRect.top - newWindowRect.top) || winpos->flags & SWP_NOCOPYBITS )
1729 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE |
1730 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 );
1732 if( winpos->flags & SWP_FRAMECHANGED )
1737 if( oldClientRect.right > newClientRect.right )
1739 rect.left = newClientRect.right; rect.top = newClientRect.top;
1740 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1742 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1743 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1745 if( oldClientRect.bottom > newClientRect.bottom )
1747 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1748 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1749 rect.bottom = oldClientRect.bottom;
1751 PAINT_RedrawWindow( wndPtr->hwndSelf, &rect, 0,
1752 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN, 0 );
1754 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1759 RECT16 oldClientRect = wndPtr->rectClient;
1761 wndPtr->rectWindow = newWindowRect;
1762 wndPtr->rectClient = newClientRect;
1764 if( oldClientRect.bottom - oldClientRect.top ==
1765 newClientRect.bottom - newClientRect.top ) result &= ~WVR_VREDRAW;
1767 if( oldClientRect.right - oldClientRect.left ==
1768 newClientRect.right - newClientRect.left ) result &= ~WVR_HREDRAW;
1770 if( !(flags & (SWP_NOREDRAW | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
1772 uFlags |= ((winpos->flags & SWP_NOCOPYBITS) ||
1773 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS)) ? SMC_NOCOPY : 0;
1774 uFlags |= (winpos->flags & SWP_FRAMECHANGED) ? SMC_DRAWFRAME : 0;
1776 if( (winpos->flags & SWP_AGG_NOGEOMETRYCHANGE) != SWP_AGG_NOGEOMETRYCHANGE )
1777 uFlags = WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect,
1778 &oldClientRect, uFlags);
1781 /* adjust frame and do not erase parent */
1783 if( winpos->flags & SWP_FRAMECHANGED ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1784 if( winpos->flags & SWP_NOZORDER ) uFlags |= SMC_NOPARENTERASE;
1787 DeleteObject(visRgn);
1790 if (flags & SWP_SHOWWINDOW)
1792 wndPtr->dwStyle |= WS_VISIBLE;
1795 if( uFlags & SMC_SETXPOS )
1797 WINPOS_SetXWindowPos( winpos );
1798 winpos->hwndInsertAfter = tempInsertAfter;
1800 XMapWindow( display, wndPtr->window );
1804 if (!(flags & SWP_NOREDRAW))
1805 PAINT_RedrawWindow( winpos->hwnd, NULL, 0,
1806 RDW_INVALIDATE | RDW_ALLCHILDREN |
1807 RDW_FRAME | RDW_ERASENOW | RDW_ERASE, 0 );
1810 else if (flags & SWP_HIDEWINDOW)
1812 wndPtr->dwStyle &= ~WS_VISIBLE;
1815 XUnmapWindow( display, wndPtr->window );
1816 if( uFlags & SMC_SETXPOS )
1818 WINPOS_SetXWindowPos( winpos );
1819 winpos->hwndInsertAfter = tempInsertAfter;
1824 if (!(flags & SWP_NOREDRAW))
1826 RECT32 rect = { oldWindowRect.left, oldWindowRect.top,
1827 oldWindowRect.right, oldWindowRect.bottom };
1828 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, &rect, 0,
1829 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE | RDW_ERASENOW, 0);
1831 uFlags |= SMC_NOPARENTERASE;
1834 if ((winpos->hwnd == GetFocus()) || IsChild(winpos->hwnd, GetFocus()))
1835 SetFocus( GetParent32(winpos->hwnd) ); /* Revert focus to parent */
1837 if (winpos->hwnd == hwndActive)
1839 /* Activate previously active window if possible */
1840 HWND newActive = hwndPrevActive;
1841 if (!IsWindow(newActive) || (newActive == winpos->hwnd))
1843 newActive = GetTopWindow( GetDesktopWindow() );
1844 if (newActive == winpos->hwnd)
1845 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1847 WINPOS_ChangeActiveWindow( newActive, FALSE );
1851 /* Activate the window */
1853 if (!(flags & SWP_NOACTIVATE))
1854 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
1856 /* Repaint the window */
1858 if (wndPtr->window) EVENT_Synchronize(); /* Wait for all expose events */
1860 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1862 if (!(flags & SWP_DEFERERASE) && !(uFlags & SMC_NOPARENTERASE) )
1863 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_ALLCHILDREN | RDW_ERASENOW, 0 );
1864 else if( wndPtr->parent == WIN_GetDesktop() && wndPtr->parent->flags & WIN_NEEDS_ERASEBKGND )
1865 PAINT_RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0, RDW_NOCHILDREN | RDW_ERASENOW, 0 );
1867 /* And last, send the WM_WINDOWPOSCHANGED message */
1869 dprintf_win(stddeb,"\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1871 if ( ((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
1872 !(winpos->flags & SWP_NOSENDCHANGING))
1873 SendMessage16( winpos->hwnd, WM_WINDOWPOSCHANGED,
1874 0, (LPARAM)SEGPTR_GET(winpos) );
1876 SEGPTR_FREE(winpos);
1881 /***********************************************************************
1882 * BeginDeferWindowPos (USER.259)
1884 HDWP16 BeginDeferWindowPos( INT count )
1889 if (count <= 0) return 0;
1890 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS16) );
1891 if (!handle) return 0;
1892 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1893 pDWP->actualCount = 0;
1894 pDWP->suggestedCount = count;
1896 pDWP->wMagic = DWP_MAGIC;
1897 pDWP->hwndParent = 0;
1902 /***********************************************************************
1903 * DeferWindowPos (USER.260)
1905 HDWP16 DeferWindowPos( HDWP16 hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
1906 INT cx, INT cy, UINT flags )
1910 HDWP16 newhdwp = hdwp;
1913 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1914 if (!pDWP) return 0;
1915 if (hwnd == GetDesktopWindow()) return 0;
1917 /* All the windows of a DeferWindowPos() must have the same parent */
1919 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
1920 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1921 else if (parent != pDWP->hwndParent)
1923 USER_HEAP_FREE( hdwp );
1927 for (i = 0; i < pDWP->actualCount; i++)
1929 if (pDWP->winPos[i].hwnd == hwnd)
1931 /* Merge with the other changes */
1932 if (!(flags & SWP_NOZORDER))
1934 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1936 if (!(flags & SWP_NOMOVE))
1938 pDWP->winPos[i].x = x;
1939 pDWP->winPos[i].y = y;
1941 if (!(flags & SWP_NOSIZE))
1943 pDWP->winPos[i].cx = cx;
1944 pDWP->winPos[i].cy = cy;
1946 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
1947 SWP_NOZORDER | SWP_NOREDRAW |
1948 SWP_NOACTIVATE | SWP_NOCOPYBITS |
1950 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1955 if (pDWP->actualCount >= pDWP->suggestedCount)
1957 newhdwp = USER_HEAP_REALLOC( hdwp,
1958 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS16) );
1959 if (!newhdwp) return 0;
1960 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1961 pDWP->suggestedCount++;
1963 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1964 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1965 pDWP->winPos[pDWP->actualCount].x = x;
1966 pDWP->winPos[pDWP->actualCount].y = y;
1967 pDWP->winPos[pDWP->actualCount].cx = cx;
1968 pDWP->winPos[pDWP->actualCount].cy = cy;
1969 pDWP->winPos[pDWP->actualCount].flags = flags;
1970 pDWP->actualCount++;
1975 /***********************************************************************
1976 * EndDeferWindowPos (USER.261)
1978 BOOL EndDeferWindowPos( HDWP16 hdwp )
1981 WINDOWPOS16 *winpos;
1985 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1986 if (!pDWP) return FALSE;
1987 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1989 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1990 winpos->x, winpos->y, winpos->cx, winpos->cy,
1991 winpos->flags ))) break;
1993 USER_HEAP_FREE( hdwp );
1998 /***********************************************************************
1999 * TileChildWindows (USER.199)
2001 void TileChildWindows( HWND parent, WORD action )
2003 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
2006 /***********************************************************************
2007 * CascageChildWindows (USER.198)
2009 void CascadeChildWindows( HWND parent, WORD action )
2011 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);