/// <summary>
        /// Changes the caret mode.
        /// </summary>
        /// <param name="mode">The new mode.</param>
        /// <param name="isChanged">True if the mode was changed.</param>
        public virtual void SetCaretMode(CaretModes mode, out bool isChanged)
        {
            isChanged = false;
            ulong OldFocusHash = FocusHash;

            if (CaretMode != mode)
            {
                CaretMode = mode;
                isChanged = true;

                CheckCaretInvariant();
            }

            Debug.Assert(isChanged || OldFocusHash == FocusHash);
        }
Exemplo n.º 2
0
        /// <summary></summary>
        protected virtual void ShowNumberCaret(Point origin, string text, CaretModes mode, int position)
        {
            FormattedNumber fn = FormattedNumber.Parse(text);

            GetNumberCaretParts(fn, position, out string BeforeExponent, out string ExponentString0, out string ExponentString1, out string InvalidText);

            double X = origin.X.Draw;
            double Y = origin.Y.Draw;
            Brush  Brush;

            Brush = GetBrush(BrushSettings.NumberSignificand);
            FormattedText ftSignificand = CreateFormattedText(BeforeExponent, EmSize, Brush);

            X += ftSignificand.WidthIncludingTrailingWhitespace;

            Brush = GetBrush(BrushSettings.NumberExponent);
            FormattedText ftExponent0 = CreateFormattedText(ExponentString0, EmSize, Brush);

            X += ftExponent0.WidthIncludingTrailingWhitespace;
            FormattedText ftExponent1 = CreateFormattedText(ExponentString1, EmSize * SubscriptRatio, Brush);

            X += ftExponent1.WidthIncludingTrailingWhitespace;

            Brush = GetBrush(BrushSettings.NumberInvalid);
            FormattedText ftInvalid = CreateFormattedText(InvalidText, EmSize, Brush);

            X += ftInvalid.WidthIncludingTrailingWhitespace;

            double CaretEmSize;
            double CaretHeight;

            if (position <= fn.SignificandPart.Length || fn.ExponentPart.Length == 0 || position > fn.SignificandPart.Length + 1)
            {
                CaretEmSize = EmSize;
                CaretHeight = LineHeight.Draw;
            }
            else
            {
                CaretEmSize = EmSize * SubscriptRatio;
                CaretHeight = LineHeight.Draw * SubscriptRatio;
            }

            ChangeFlashClockOpacity(isVisible: true);
            ShowNumberCaretParts(fn, mode, position, X, Y, CaretEmSize, CaretHeight);
        }
Exemplo n.º 3
0
        /// <summary></summary>
        protected virtual void ShowNumberCaretParts(FormattedNumber fn, CaretModes mode, int position, double x, double y, double caretEmSize, double caretHeight)
        {
            if (mode == CaretModes.Insertion)
            {
                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + x, PagePadding.Top.Draw + y, InsertionCaretWidth, caretHeight);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretInsertion), GetPen(PenSettings.CaretInsertion), CaretRect);
                WpfDrawingContext.Pop();
            }
            else
            {
                string CaretText;

                if (position < fn.SignificandPart.Length)
                {
                    CaretText = fn.SignificandPart.Substring(position, 1);
                }
                else if (position < fn.SignificandPart.Length + fn.ExponentPart.Length)
                {
                    CaretText = fn.ExponentPart.Substring(position - fn.SignificandPart.Length, 1);
                }
                else
                {
                    CaretText = fn.InvalidText.Substring(position - fn.SignificandPart.Length - fn.ExponentPart.Length, 1);
                }

                FormattedText ftCaret = CreateFormattedText(CaretText, caretEmSize, GetBrush(BrushSettings.CaretOverride));

                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + x, PagePadding.Top.Draw + y, ftCaret.WidthIncludingTrailingWhitespace, caretHeight);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretOverride), GetPen(PenSettings.CaretOverride), CaretRect);
                WpfDrawingContext.Pop();
            }
        }
 public int GetCaretPositionInText(double x, string text, TextStyles textStyle, CaretModes mode, Measure maxTextWidth)
 {
     return(0);
 }
 public void ShowCaret(Point origin, string text, TextStyles textStyle, CaretModes mode, int position)
 {
     Debug.Assert(position >= 0 && ((mode == CaretModes.Insertion && position <= text.Length) || (mode == CaretModes.Override && position < text.Length)));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Get the caret position corresponding to <paramref name="x"/> in <paramref name="text"/>.
        /// </summary>
        /// <param name="x">X-coordinate of the caret location.</param>
        /// <param name="text">The text</param>
        /// <param name="textStyle">The style used to measure <paramref name="text"/>.</param>
        /// <param name="mode">The caret mode.</param>
        /// <param name="maxTextWidth">The maximum width for a line of text. NaN means no limit.</param>
        /// <returns>The position of the caret.</returns>
        public virtual int GetCaretPositionInText(double x, string text, TextStyles textStyle, CaretModes mode, Measure maxTextWidth)
        {
            Brush Brush = GetBrush(StyleToForegroundBrush(textStyle));

            if (textStyle == TextStyles.Comment)
            {
                x += CommentPadding.Left.Draw;
            }

            int Result = 0;

            for (int i = 0; i < text.Length; i++)
            {
                FormattedText ft = CreateFormattedText(text.Substring(0, i + 1), EmSize, Brush);
                if (!maxTextWidth.IsFloating)
                {
                    ft.MaxTextWidth = maxTextWidth.Draw;
                }

                if (ft.WidthIncludingTrailingWhitespace >= x)
                {
                    break;
                }

                Result++;
            }

            return(Result);
        }
Exemplo n.º 7
0
        /// <summary></summary>
        protected virtual void ShowNormalCaret(Point origin, string text, TextStyles textStyle, CaretModes mode, int position)
        {
            string LeftText = text.Substring(0, position);

            Brush         Brush = GetBrush(StyleToForegroundBrush(textStyle));
            FormattedText ft    = CreateFormattedText(LeftText, EmSize, Brush);
            double        X     = origin.X.Draw + ft.WidthIncludingTrailingWhitespace;
            double        Y     = origin.Y.Draw;

            if (textStyle == TextStyles.Comment)
            {
                X += CommentPadding.Left.Draw;
                Y += CommentPadding.Top.Draw;
            }

            ChangeFlashClockOpacity(isVisible: true);

            if (mode == CaretModes.Insertion)
            {
                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + X, PagePadding.Top.Draw + Y, InsertionCaretWidth, LineHeight.Draw);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretInsertion), GetPen(PenSettings.CaretInsertion), CaretRect);
                WpfDrawingContext.Pop();
            }
            else
            {
                string CaretText = text.Substring(position, 1);
                ft = CreateFormattedText(CaretText, EmSize, GetBrush(BrushSettings.CaretOverride));

                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + X, PagePadding.Top.Draw + Y, ft.WidthIncludingTrailingWhitespace, LineHeight.Draw);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretOverride), GetPen(PenSettings.CaretOverride), CaretRect);
                WpfDrawingContext.Pop();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Shows the caret.
        /// </summary>
        /// <param name="origin">Location of the cell with the caret.</param>
        /// <param name="text">The full cell text.</param>
        /// <param name="textStyle">The text style.</param>
        /// <param name="mode">The caret mode.</param>
        /// <param name="position">The position of the caret in <paramref name="text"/>.</param>
        public virtual void ShowCaret(Point origin, string text, TextStyles textStyle, CaretModes mode, int position)
        {
            Debug.Assert(position >= 0 && ((mode == CaretModes.Insertion && position <= text.Length) || (mode == CaretModes.Override && position < text.Length)));
            Debug.Assert(WpfDrawingContext != null);

            if (textStyle == TextStyles.Number)
            {
                ShowNumberCaret(origin, text, mode, position);
            }
            else
            {
                ShowNormalCaret(origin, text, textStyle, mode, position);
            }

            IsLastFocusedFullCell = false;
        }