Exemple #1
0
 /// <inheritdoc/>
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromLogicalTree(e);
     _topLevel = null;
     _popupRoot?.Dispose();
     _popupRoot = null;
 }
Exemple #2
0
        internal static Point GetPosition(Control target, PlacementMode placement, PopupRoot popupRoot, double horizontalOffset, double verticalOffset)
        {
            var zero = default(Point);
            var mode = placement;

            if (target?.GetVisualRoot() == null)
            {
                mode = PlacementMode.Pointer;
            }

            switch (mode)
            {
            case PlacementMode.Pointer:
                if (popupRoot != null)
                {
                    // Scales the Horizontal and Vertical offset to screen co-ordinates.
                    var screenOffset = new Point(horizontalOffset * (popupRoot as ILayoutRoot).LayoutScaling,
                                                 verticalOffset * (popupRoot as ILayoutRoot).LayoutScaling);
                    return((((IInputRoot)popupRoot)?.MouseDevice?.Position ?? default(Point)) + screenOffset);
                }

                return(default(Point));

            case PlacementMode.Bottom:
                return(target?.PointToScreen(new Point(0 + horizontalOffset, target.Bounds.Height + verticalOffset)) ??
                       zero);

            case PlacementMode.Right:
                return(target?.PointToScreen(new Point(target.Bounds.Width + horizontalOffset, 0 + verticalOffset)) ?? zero);

            default:
                throw new InvalidOperationException("Invalid value for Popup.PlacementMode");
            }
        }
Exemple #3
0
        /// <summary>
        /// Opens the popup.
        /// </summary>
        public void Open()
        {
            if (_popupRoot == null)
            {
                _popupRoot = new PopupRoot(DependencyResolver)
                {
                    [~ContentControl.ContentProperty] = this[~ChildProperty],
                    [~WidthProperty]     = this[~WidthProperty],
                    [~HeightProperty]    = this[~HeightProperty],
                    [~MinWidthProperty]  = this[~MinWidthProperty],
                    [~MaxWidthProperty]  = this[~MaxWidthProperty],
                    [~MinHeightProperty] = this[~MinHeightProperty],
                    [~MaxHeightProperty] = this[~MaxHeightProperty],
                };

                ((ISetLogicalParent)_popupRoot).SetParent(this);
            }

            _popupRoot.Position = GetPosition();

            if (_topLevel == null && PlacementTarget != null)
            {
                _topLevel = PlacementTarget.GetSelfAndLogicalAncestors().First(x => x is TopLevel) as TopLevel;
            }

            if (_topLevel != null)
            {
                var window = _topLevel as Window;
                if (window != null)
                {
                    window.Deactivated += WindowDeactivated;
                }
                else
                {
                    var parentPopuproot = _topLevel as PopupRoot;
                    if (parentPopuproot != null && parentPopuproot.Parent != null)
                    {
                        ((Popup)(parentPopuproot.Parent)).Closed += ParentClosed;
                    }
                }
                _topLevel.AddHandler(PointerPressedEvent, PointerPressedOutside, RoutingStrategies.Tunnel);
                _nonClientListener = InputManager.Instance.Process.Subscribe(ListenForNonClientClick);
            }

            PopupRootCreated?.Invoke(this, EventArgs.Empty);

            _popupRoot.Show();

            _ignoreIsOpenChanged = true;
            IsOpen = true;
            _ignoreIsOpenChanged = false;

            Opened?.Invoke(this, EventArgs.Empty);
        }
Exemple #4
0
        /// <inheritdoc/>
        protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
        {
            base.OnDetachedFromLogicalTree(e);
            _topLevel = null;

            if (_popupRoot != null)
            {
                ((ISetLogicalParent)_popupRoot).SetParent(null);
                _popupRoot.Dispose();
                _popupRoot = null;
            }
        }
Exemple #5
0
 private static IControl PopupRootTemplate(PopupRoot control)
 {
     return new ContentPresenter
     {
         Name = "PART_ContentPresenter",
         [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty],
     };
 }
Exemple #6
0
        /// <summary>
        /// Called when the pointer leaves a control with an attached tooltip.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private static void ControlPointerLeave(object sender, PointerEventArgs e)
        {
            var control = (Control)sender;

            if (control == s_current)
            {
                if (s_popup != null)
                {
                    // Clear the ToolTip's Content in case it has control content: this will
                    // reset its visual parent allowing it to be used again.
                    ((ToolTip)s_popup.Content).Content = null;

                    // Dispose of the popup.
                    s_popup.Dispose();
                    s_popup = null;
                }

                s_show.OnNext(null);
            }
        }
Exemple #7
0
        /// <summary>
        /// Shows a tooltip for the specified control.
        /// </summary>
        /// <param name="control">The control.</param>
        private static void ShowToolTip(Control control)
        {
            if (control != null && control.IsVisible && control.GetVisualRoot() != null)
            {
                if (s_popup != null)
                {
                    throw new AvaloniaInternalException("Previous ToolTip not disposed.");
                }

                var cp = MouseDevice.Instance?.GetPosition(control);
                var position = control.PointToScreen(cp ?? new Point(0, 0)) + new Vector(0, 22);

                s_popup = new PopupRoot();
                ((ISetLogicalParent)s_popup).SetParent(control);
                s_popup.Content = new ToolTip { Content = GetTip(control) };
                s_popup.Position = position;
                s_popup.Show();

                s_current = control;
            }
        }
Exemple #8
0
 /// <inheritdoc/>
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromLogicalTree(e);
     _topLevel = null;
     _popupRoot?.Dispose();
     _popupRoot = null;
 }
Exemple #9
0
        /// <summary>
        /// Shows a tooltip for the specified control.
        /// </summary>
        /// <param name="control">The control.</param>
        private static void ShowToolTip(Control control)
        {
            if (control != null && control.IsVisible && control.GetVisualRoot() != null)
            {
                if (s_popup == null)
                {
                    s_popup = new PopupRoot
                    {
                        Content = new ToolTip(),
                    };

                    ((ISetLogicalParent)s_popup).SetParent(control);
                }

                var cp = MouseDevice.Instance?.GetPosition(control);
                var position = control.PointToScreen(cp ?? new Point(0, 0)) + new Vector(0, 22);

                ((ToolTip)s_popup.Content).Content = GetTip(control);
                s_popup.Position = position;
                s_popup.Show();

                s_current = control;
            }
        }
Exemple #10
-1
        /// <summary>
        /// Opens the popup.
        /// </summary>
        public void Open()
        {
            if (_popupRoot == null)
            {
                _popupRoot = new PopupRoot(DependencyResolver)
                {
                    [~ContentControl.ContentProperty] = this[~ChildProperty],
                    [~WidthProperty] = this[~WidthProperty],
                    [~HeightProperty] = this[~HeightProperty],
                    [~MinWidthProperty] = this[~MinWidthProperty],
                    [~MaxWidthProperty] = this[~MaxWidthProperty],
                    [~MinHeightProperty] = this[~MinHeightProperty],
                    [~MaxHeightProperty] = this[~MaxHeightProperty],
                };

                ((ISetLogicalParent)_popupRoot).SetParent(this);
            }

            _popupRoot.Position = GetPosition();

            if (_topLevel == null && PlacementTarget != null)
            {
                _topLevel = PlacementTarget.GetSelfAndLogicalAncestors().First(x => x is TopLevel) as TopLevel;
            }

            if (_topLevel != null)
            {
                _topLevel.Deactivated += TopLevelDeactivated;
                _topLevel.AddHandler(PointerPressedEvent, PointerPressedOutside, RoutingStrategies.Tunnel);
                _nonClientListener = InputManager.Instance.Process.Subscribe(ListenForNonClientClick);
            }

            PopupRootCreated?.Invoke(this, EventArgs.Empty);

            _popupRoot.Show();
            IsOpen = true;
            Opened?.Invoke(this, EventArgs.Empty);
        }
Exemple #11
-1
 /// <inheritdoc/>
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromLogicalTree(e);
     _topLevel = null;
     
     if (_popupRoot != null)
     {
         ((ISetLogicalParent)_popupRoot).SetParent(null);
         _popupRoot.Dispose();
         _popupRoot = null;
     }
 }