Exemple #1
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)
            {
                var cp = (control.GetVisualRoot() as IInputRoot)?.MouseDevice?.GetPosition(control);

                if (cp.HasValue && control.IsVisible && new Rect(control.Bounds.Size).Contains(cp.Value))
                {
                    var position = control.PointToScreen(cp.Value) + new Vector(0, 22);

                    if (s_popup == null)
                    {
                        s_popup         = new PopupRoot();
                        s_popup.Content = new ToolTip();
                    }
                    else
                    {
                        ((ISetLogicalParent)s_popup).SetParent(null);
                    }

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

                    s_current = control;
                }
            }
        }
Exemple #2
0
        private void InternalSetContent(UIElement value)
        {
            if (_main == null)
            {
                _rootBorder = new Border();
                _fullWindow = new Border()
                {
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Visibility          = Visibility.Collapsed
                };
                _popupRoot = new PopupRoot();

                _main = new Grid()
                {
                    Children =
                    {
                        _rootBorder,
                        _fullWindow,
                        _popupRoot
                    }
                };

                ApplicationActivity.Instance?.SetContentView(_main);
            }

            _rootBorder.Child = _content = value;
        }
Exemple #3
0
        private void HidePopupRootIfVisible()
        {
            if (_isVisible)
            {
                //---------------------
                // If the popup being closed is the one with the highest zIndex, we decrement it to reduce the chances of reaching the maximum value:
                //---------------------
                int closingPopupZIndex = Canvas.GetZIndex(_popupRoot);
                if (closingPopupZIndex == _currentZIndex)
                {
                    --_currentZIndex;
                }

                //---------------------
                // Hide the PopupRoot:
                //---------------------
                var popupRoot = _popupRoot;
                popupRoot.INTERNAL_LinkedPopup = null;
                popupRoot.Content = null;
                INTERNAL_PopupsManager.RemovePopupRoot(popupRoot);
                _popupRoot = null;
                _isVisible = false;
            }
            else
            {
                // The popup is already hidden.
            }
        }
Exemple #4
0
        private void InternalSetContent(UIElement content)
        {
            if (_window == null)
            {
                _rootBorder       = new Border();
                _rootScrollViewer = new ScrollViewer()
                {
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                    VerticalScrollMode            = ScrollMode.Disabled,
                    HorizontalScrollMode          = ScrollMode.Disabled,
                    Content = _rootBorder
                };
                _popupRoot = new PopupRoot();
                _window    = new Grid()
                {
                    Children =
                    {
                        _rootScrollViewer,
                        _popupRoot
                    }
                };
            }

            _rootBorder.Child = _content = content;
            if (content != null)
            {
                WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setRootContent(\"{_window.HtmlId}\");");
            }
            else
            {
                WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setRootContent();");
            }
        }
Exemple #5
0
 private static IControl PopupRootTemplate(PopupRoot control)
 {
     return(new ContentPresenter
     {
         Name = "PART_ContentPresenter",
         [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty],
     });
 }
Exemple #6
0
 private static IControl PopupRootTemplate(PopupRoot control, INameScope scope)
 {
     return(new ContentPresenter
     {
         Name = "PART_ContentPresenter",
         [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty],
     }.RegisterInNameScope(scope));
 }
Exemple #7
0
 private void EnsurePopupRoot()
 {
     if (PopupRoot == null)
     {
         PopupRoot = new PopupRoot();
         Canvas.SetZIndex(PopupRoot, PopupZIndex);
     }
 }
        internal static void OnClickOnPopupOrWindow(object sender, PointerRoutedEventArgs e)
#endif
        {
            // Note: If a popup has StayOpen=True, the value of "StayOpen" of its parents is ignored.
            // In other words, the parents of a popup that has StayOpen=True will always stay open
            // regardless of the value of their "StayOpen" property.

            HashSet2 <Popup> listOfPopupThatMustBeClosed = new HashSet2 <Popup>();
            List <PopupRoot> popupRootList = new List <PopupRoot>();

            foreach (object obj in GetAllRootUIElements())
            {
                if (obj is PopupRoot)
                {
                    PopupRoot root = (PopupRoot)obj;
                    popupRootList.Add(root);

                    if (root.INTERNAL_LinkedPopup != null)
                    {
                        listOfPopupThatMustBeClosed.Add(root.INTERNAL_LinkedPopup);
                    }
                }
            }

            // We determine which popup needs to stay open after this click
            foreach (PopupRoot popupRoot in popupRootList)
            {
                if (popupRoot.INTERNAL_LinkedPopup != null)
                {
                    // We must prevent all the parents of a popup to be closed when:
                    // - this popup is set to StayOpen
                    // - or the click happend in this popup

                    Popup popup = popupRoot.INTERNAL_LinkedPopup;

                    if (popup.StayOpen || sender == popupRoot)
                    {
                        do
                        {
                            if (!listOfPopupThatMustBeClosed.Contains(popup))
                            {
                                break;
                            }

                            listOfPopupThatMustBeClosed.Remove(popup);

                            popup = popup.ParentPopup;
                        } while (popup != null);
                    }
                }
            }

            foreach (Popup popup in listOfPopupThatMustBeClosed)
            {
                popup.CloseFromAnOutsideClick();
            }
        }
Exemple #9
0
 private void Close()
 {
     if (_popup != null)
     {
         _popup.Content = null;
         _popup.Hide();
         _popup = null;
     }
 }
Exemple #10
0
 public void Show()
 {
     if (FrameX == null)
     {
         return;
     }
     FrameX.Attach(this);
     PopupRoot.Open();
     ShowAnimation.Begin();
 }
Exemple #11
0
        private void ShowPopupRootIfNotAlreadyVisible()
        {
            if (!_isVisible)
            {
                //---------------------
                // Show the PopupRoot:
                //---------------------

                var child = this.Child;

                // Get the window that is supposed to contain the popup:
                Window parentWindow = GetParentWindowOfPopup();

                // Create the popup root:
                var popupRoot = INTERNAL_PopupsManager.CreateAndAppendNewPopupRoot(parentWindow);
                _popupRoot = popupRoot;
                _popupRoot.INTERNAL_LinkedPopup = this;
                UpdatePopupParent();

                // Clear the previous content if any:
                if (_outerBorder != null)
                {
                    _outerBorder.Child = null;
                }

                // Calculate the position of the parent of the popup, in case that the popup is in the Visual Tree:
                _referencePosition = CalculateReferencePosition(parentWindow) ?? new Point();

                // We make it transparent to clicks only if either the popup has a false "IsHitTestVisible", or the content of the popup has a false "IsHitTestVisible":
                bool transparentToClicks = (!this.IsHitTestVisible) || (child is FrameworkElement && !((FrameworkElement)child).IsHitTestVisible);

                // Create a surrounding border to enable positioning and alignment:
                _outerBorder = new Border()
                {
                    Margin = new Thickness(_referencePosition.X + this.HorizontalOffset, _referencePosition.Y + this.VerticalOffset, 0d, 0d),
                    Child  = child,
                    HorizontalAlignment = this.HorizontalContentAlignment,
                    VerticalAlignment   = this.VerticalContentAlignment,
                    INTERNAL_ForceEnableAllPointerEvents = INTERNAL_AllowDisableClickTransparency && !transparentToClicks, // This is here because we set "pointerEvents='none' to the PopupRoot, so we need to re-enable pointer events in the children (unless we have calculated that the popup should be "transparentToClicks").
                };

                // Make sure that after the OuterBorder raises the Loaded event, the PopupRoot also raises the Loaded event:
                _outerBorder.Loaded += (s, e) => { popupRoot.INTERNAL_RaiseLoadedEvent(); };

                popupRoot.Content = _outerBorder;
                _isVisible        = true;
                // Show the popup in front of any potential previously displayed popup:
                PutPopupInFront();
            }
            else
            {
                // The popup is already visible.
            }
        }
Exemple #12
0
        private void Open(Control control)
        {
            Close();

            _popup = new PopupRoot {
                Content = this
            };
            ((ISetLogicalParent)_popup).SetParent(control);
            _popup.Position = Popup.GetPosition(control, GetPlacement(control), _popup,
                                                GetHorizontalOffset(control), GetVerticalOffset(control));
            _popup.Show();
        }
Exemple #13
0
 /// <summary>
 /// The default template for the <see cref="PopupRoot"/> control.
 /// </summary>
 /// <param name="control">The control being styled.</param>
 /// <returns>The root of the instantiated template.</returns>
 public static Control Template(PopupRoot control)
 {
     return new Border
     {
         [~Border.BackgroundProperty] = control[~PopupRoot.BackgroundProperty],
         Child = new ContentPresenter
         {
             Name = "contentPresenter",
             [~ContentPresenter.ContentProperty] = control[~PopupRoot.ContentProperty],
         }
     };
 }
Exemple #14
0
 /// <summary>
 /// The default template for the <see cref="PopupRoot"/> control.
 /// </summary>
 /// <param name="control">The control being styled.</param>
 /// <returns>The root of the instantiated template.</returns>
 public static Control Template(PopupRoot control)
 {
     return(new Border
     {
         [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty],
         Child = new ContentPresenter
         {
             Name = "contentPresenter",
             [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty],
         }
     });
 }
Exemple #15
0
        private void InternalSetContent(UIElement content)
        {
            if (_window == null)
            {
                _rootBorder       = new Border();
                _rootScrollViewer = new ScrollViewer()
                {
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                    VerticalScrollMode            = ScrollMode.Disabled,
                    HorizontalScrollMode          = ScrollMode.Disabled,
                    Content = _rootBorder
                };
                _popupRoot       = new PopupRoot();
                FocusVisualLayer = new Canvas();
                _window          = new Grid()
                {
                    IsVisualTreeRoot = true,
                    Children         =
                    {
                        _rootScrollViewer,
                        _popupRoot,
                        FocusVisualLayer
                    }
                };
            }

            _rootBorder.Child = _content = content;
            if (content != null)
            {
                if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded && !_window.IsLoaded)
                {
                    UIElement.LoadingRootElement(_window);
                }

                WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setRootContent({_window.HtmlId});");

                if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded && !_window.IsLoaded)
                {
                    UIElement.RootElementLoaded(_window);
                }
            }
            else
            {
                WebAssemblyRuntime.InvokeJS($"Uno.UI.WindowManager.current.setRootContent();");

                if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded && _window.IsLoaded)
                {
                    UIElement.RootElementUnloaded(_window);
                }
            }
        }
Exemple #16
0
        private static void DisposeTooltip()
        {
            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;
            }
        }
 public PopupRootAutomationPeer(PopupRoot owner)
     : base(owner)
 {
     if (owner.IsVisible)
     {
         StartTrackingFocus();
     }
     else
     {
         owner.Opened += OnOpened;
     }
     owner.Closed += OnClosed;
 }
Exemple #18
0
        static void Popup_PopupMoved(object sender, EventArgs e)
        {
            Popup     popup     = (Popup)sender;
            PopupRoot popupRoot = popup.PopupRoot;

            // Hide the popup if the parent element is not visible (for example, if the user scrolls and the TextBox becomes hidden under another control, cf. ZenDesk #628):
            if (popup.PlacementTarget is FrameworkElement && popupRoot != null)
            {
                bool isParentVisible = INTERNAL_PopupsManager.IsPopupParentVisibleOnScreen(popup);

                popupRoot.Visibility = (isParentVisible ? Visibility.Visible : Visibility.Collapsed);
            }
        }
Exemple #19
0
        private PopupRoot CreateTarget()
        {
            var result = new PopupRoot
            {
                Template = new FuncControlTemplate <PopupRoot>(_ =>
                                                               new ContentPresenter
                {
                    Name = "PART_ContentPresenter",
                }),
            };

            result.ApplyTemplate();

            return(result);
        }
        private PopupRoot CreateTarget(TopLevel popupParent)
        {
            var result = new PopupRoot(popupParent, popupParent.PlatformImpl.CreatePopup())
            {
                Template = new FuncControlTemplate <PopupRoot>((parent, scope) =>
                                                               new ContentPresenter
                {
                    Name = "PART_ContentPresenter",
                    [!ContentPresenter.ContentProperty] = parent[!PopupRoot.ContentProperty],
                }.RegisterInNameScope(scope)),
            };

            result.ApplyTemplate();

            return(result);
        }
Exemple #21
0
        private PopupRoot CreateTarget()
        {
            var result = new PopupRoot
            {
                Template = new FuncControlTemplate <PopupRoot>(parent =>
                                                               new ContentPresenter
                {
                    Name = "PART_ContentPresenter",
                    [!ContentPresenter.ContentProperty] = parent[!PopupRoot.ContentProperty],
                }),
            };

            result.ApplyTemplate();

            return(result);
        }
Exemple #22
0
 private void HidePopupRootIfVisible()
 {
     if (_isVisible)
     {
         //---------------------
         // Hide the PopupRoot:
         //---------------------
         var popupRoot = _popupRoot;
         popupRoot.INTERNAL_LinkedPopup = null;
         popupRoot.Content = null;
         INTERNAL_PopupsManager.RemovePopupRoot(popupRoot);
         _popupRoot = null;
         _isVisible = false;
     }
     else
     {
         // The popup is already hidden.
     }
 }
Exemple #23
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);
            }
        }
        public static void RemovePopupRoot(PopupRoot popupRoot)
        {
            string uniquePopupRootIdentifier = popupRoot.INTERNAL_UniqueIndentifier;

            if (PopupRootIdentifierToInstance.ContainsKey(uniquePopupRootIdentifier))
            {
                Window parentWindow = popupRoot.INTERNAL_ParentWindow;

                //--------------------------------------
                // Stop listening to clicks anywhere in the popup (this was used to close other popups that are not supposed to stay open):
                //--------------------------------------

#if MIGRATION
                popupRoot.RemoveHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(INTERNAL_PopupsManager.OnClickOnPopupOrWindow));
#else
                popupRoot.RemoveHandler(UIElement.PointerPressedEvent, new PointerEventHandler(INTERNAL_PopupsManager.OnClickOnPopupOrWindow));
#endif

                //--------------------------------------
                // Remove from the DOM:
                //--------------------------------------

                CSHTML5.Interop.ExecuteJavaScriptAsync(
                    @"
var popupRoot = document.getElementByIdSafe($0);
$1.removeChild(popupRoot);
", uniquePopupRootIdentifier, parentWindow.INTERNAL_RootDomElement);

                //--------------------------------------
                // Remove from the list of popups:
                //--------------------------------------

                PopupRootIdentifierToInstance.Remove(uniquePopupRootIdentifier);
            }
            else
            {
                throw new Exception("No PopupRoot with the following identifier was found: " + uniquePopupRootIdentifier + ". Please contact support.");
            }
        }
Exemple #25
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       = (control.GetVisualRoot() as IInputRoot)?.MouseDevice?.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 #26
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)
            {
                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;
            }
        }
 public static void Close(this PopupRoot window) => window.Hide();
Exemple #28
0
 private void CloseAnimation_OnCompleted(object sender, object e)
 {
     PopupRoot.Close();
     FrameX?.Deattach(this);
 }
        public static PopupRoot CreateAndAppendNewPopupRoot(Window parentWindow)
        {
            // Generate a unique identifier for the PopupRoot:
            CurrentPopupRootIndentifier++;
            string uniquePopupRootIdentifier = "INTERNAL_Cshtml5_PopupRoot_" + CurrentPopupRootIndentifier.ToString();

            //--------------------------------------
            // Create a DIV for the PopupRoot in the DOM tree:
            //--------------------------------------

            CSHTML5.Interop.ExecuteJavaScriptAsync(
                @"
var popupRoot = document.createElement('div');
popupRoot.setAttribute('id', $0);
popupRoot.style.position = 'absolute';
popupRoot.style.width = '100%';
popupRoot.style.height = '100%';
popupRoot.style.overflowX = 'hidden';
popupRoot.style.overflowY = 'hidden';
popupRoot.style.pointerEvents = 'none';
$1.appendChild(popupRoot);
", uniquePopupRootIdentifier, parentWindow.INTERNAL_RootDomElement);

            //--------------------------------------
            // Get the PopupRoot DIV:
            //--------------------------------------

            object popupRootDiv;

#if OPENSILVER
            if (true)
#elif BRIDGE
            if (Interop.IsRunningInTheSimulator)
#endif
            { popupRootDiv = new INTERNAL_HtmlDomElementReference(uniquePopupRootIdentifier, null); }
            else
            {
                popupRootDiv = Interop.ExecuteJavaScriptAsync("document.getElementByIdSafe($0)", uniquePopupRootIdentifier);
            }

            //--------------------------------------
            // Create the C# class that points to the PopupRoot DIV:
            //--------------------------------------

            var popupRoot = new PopupRoot(uniquePopupRootIdentifier, parentWindow);
            popupRoot.INTERNAL_OuterDomElement
                  = popupRoot.INTERNAL_InnerDomElement
                  = popupRootDiv;

            //--------------------------------------
            // Listen to clicks anywhere in the popup (this is used to close other popups that are not supposed to stay open):
            //--------------------------------------

#if MIGRATION
            popupRoot.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(INTERNAL_PopupsManager.OnClickOnPopupOrWindow), true);
#else
            popupRoot.AddHandler(UIElement.PointerPressedEvent, new PointerEventHandler(INTERNAL_PopupsManager.OnClickOnPopupOrWindow), true);
#endif

            //--------------------------------------
            // Remember the PopupRoot for later use:
            //--------------------------------------

            PopupRootIdentifierToInstance.Add(uniquePopupRootIdentifier, popupRoot);

            return(popupRoot);
        }
Exemple #30
0
 // Token: 0x060027A0 RID: 10144 RVA: 0x000B2FD9 File Offset: 0x000B11D9
 public PopupRootAutomationPeer(PopupRoot owner) : base(owner)
 {
 }
Exemple #31
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)
            {
                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.HasValue ? cp.Value : new Point(0, 0)) + new Vector(0, 22);

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

                s_current = control;
            }
        }