Ejemplo n.º 1
0
        /// <summary>
        /// Deactivates the specified command stream's activated link, if it has one.
        /// </summary>
        /// <param name="stream">The command stream to update.</param>
        /// <param name="element">The element that owns the command stream.</param>
        /// <returns><see langword="true"/> if the command stream's link was deactivated; otherwise, <see langword="false"/>.</returns>
        public static Boolean DeactivateTextLink(TextLayoutCommandStream stream, UIElement element)
        {
            Contract.Require(element, nameof(element));

            if (stream == null || element.View == null)
            {
                return(false);
            }

            return(element.View.Resources.TextRenderer.DeactivateLink(stream));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Activates any link at the current cursor position within the specified command stream.
        /// </summary>
        /// <param name="stream">The command stream to update.</param>
        /// <param name="element">The element that owns the command stream.</param>
        /// <param name="data">The event metadata for the routed event which prompted the link activation.</param>
        /// <returns><see langword="true"/> if the command stream's link was deactivated; otherwise, <see langword="false"/>.</returns>
        public static Boolean ActivateTextLink(TextLayoutCommandStream stream, UIElement element, RoutedEventData data)
        {
            Contract.Require(element, nameof(element));

            if (stream == null || element.View == null || !element.View.Resources.TextRenderer.ActivateLinkAtCursor(stream))
            {
                return(false);
            }

            element.Focus();
            element.CaptureMouse();

            data.Handled = true;
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the cache which contains the element's laid-out text.
        /// </summary>
        /// <param name="availableSize">The amount of space in which the element's text can be laid out.</param>
        private void UpdateTextLayoutCache(Size2D availableSize)
        {
            if (textLayoutCommands != null)
            {
                textLayoutCommands.Clear();
            }

            if (View == null)
            {
                return;
            }

            var content = Content;

            var contentElement = content as UIElement;

            if (contentElement == null)
            {
                if (textLayoutCommands == null)
                {
                    textLayoutCommands = new TextLayoutCommandStream();
                }

                var font      = GetValue <SourcedResource <UltravioletFont> >(TextElement.FontProperty);
                var fontStyle = GetValue <UltravioletFontStyle>(TextElement.FontStyleProperty);
                if (font.IsLoaded)
                {
                    var availableSizeInPixels = Display.DipsToPixels(availableSize);

                    var cursorpos = textLayoutCommands.CursorPosition;

                    var textRenderingMode = TextOptions.GetTextRenderingMode(this);
                    var textScript        = TextOptions.GetTextScript(this);
                    var textLanguage      = TextOptions.GetTextLanguage(this);
                    var textDirection     = FlowDirection == FlowDirection.RightToLeft ? TextDirection.RightToLeft : TextDirection.LeftToRight;

                    var options  = (textRenderingMode == TextRenderingMode.Shaped) ? TextLayoutOptions.Shape : TextLayoutOptions.None;
                    var flags    = LayoutUtil.ConvertAlignmentsToTextFlags(HorizontalAlignment, VerticalAlignment);
                    var settings = new TextLayoutSettings(font,
                                                          (Int32)Math.Ceiling(availableSizeInPixels.Width),
                                                          (Int32)Math.Ceiling(availableSizeInPixels.Height), flags, options, textDirection, textScript, fontStyle, null, textLanguage);

                    View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings);
                    View.Resources.TextRenderer.UpdateCursor(textLayoutCommands, cursorpos);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the cache which contains the element's laid-out text.
        /// </summary>
        /// <param name="availableSize">The amount of space in which the element's text can be laid out.</param>
        private void UpdateTextLayoutCache(Size2D availableSize)
        {
            if (textLayoutCommands != null)
            {
                textLayoutCommands.Clear();
            }

            if (View == null || containingControl == null)
            {
                return;
            }

            var content = Content;

            var contentElement = content as UIElement;

            if (contentElement == null)
            {
                if (textLayoutCommands == null)
                {
                    textLayoutCommands = new TextLayoutCommandStream();
                }

                var font = containingControl.Font;
                if (font.IsLoaded)
                {
                    var availableSizeInPixels = Display.DipsToPixels(availableSize);

                    var cursorpos = textLayoutCommands.CursorPosition;

                    var flags    = LayoutUtil.ConvertAlignmentsToTextFlags(HorizontalAlignment, VerticalAlignment);
                    var settings = new TextLayoutSettings(font,
                                                          (Int32)Math.Ceiling(availableSizeInPixels.Width),
                                                          (Int32)Math.Ceiling(availableSizeInPixels.Height), flags, containingControl.FontStyle);

                    View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings);
                    View.Resources.TextRenderer.UpdateCursor(textLayoutCommands, cursorpos);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes any link at the current cursor position within the specified command stream.
        /// </summary>
        /// <param name="stream">The command stream to update.</param>
        /// <param name="element">The element that owns the command stream.</param>
        /// <param name="data">The event metadata for the routed event which prompted the link execution.</param>
        public static Boolean ExecuteTextLink(TextLayoutCommandStream stream, UIElement element, RoutedEventData data)
        {
            Contract.Require(element, nameof(element));

            if (stream == null || element.View == null)
            {
                return(false);
            }

            if (stream.ActiveLinkIndex.HasValue)
            {
                element.ReleaseMouseCapture();
            }

            if (!element.View.Resources.TextRenderer.ExecuteActivatedLink(stream))
            {
                return(false);
            }

            data.Handled = true;
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates the position of the cursor within the specified command stream.
        /// </summary>
        /// <param name="stream">The command stream to update.</param>
        /// <param name="element">The element that owns the command stream.</param>
        /// <param name="position">The position of the input device.</param>
        public static void UpdateLinkCursor(TextLayoutCommandStream stream, UIElement element, Point2D?position)
        {
            Contract.Require(element, nameof(element));

            if (stream == null || element.View == null)
            {
                return;
            }

            var positionDips = position;
            var positionPixs = positionDips.HasValue ? (Point2)element.View.Display.DipsToPixels(positionDips.Value) : (Point2?)null;

            if (positionDips.HasValue && (element.IsMouseOver || element.IsMouseCaptured))
            {
                element.View.Resources
                .TextRenderer.UpdateCursor(stream, positionPixs);
            }
            else
            {
                element.View.Resources
                .TextRenderer.UpdateCursor(stream, null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Updates the cache which contains the element's laid-out text.
        /// </summary>
        /// <param name="availableSize">The amount of space in which the element's text can be laid out.</param>
        private void UpdateTextLayoutCache(Size2D availableSize)
        {
            if (textLayoutCommands != null)
            {
                textLayoutCommands.Clear();
            }

            if (View == null || containingControl == null)
            {
                return;
            }

            var content = Content;

            var contentElement = content as UIElement;

            if (contentElement == null)
            {
                if (textLayoutCommands == null)
                {
                    textLayoutCommands = new TextLayoutCommandStream();
                }

                var font = containingControl.Font;
                if (font.IsLoaded)
                {
                    var availableSizeInPixels = Display.DipsToPixels(availableSize);

                    var settings = new TextLayoutSettings(font,
                                                          (Int32)Math.Ceiling(availableSizeInPixels.Width),
                                                          (Int32)Math.Ceiling(availableSizeInPixels.Height), TextFlags.Standard, containingControl.FontStyle);

                    View.Resources.TextRenderer.CalculateLayout(textParserResult, textLayoutCommands, settings);
                }
            }
        }