示例#1
0
        public static bool? IsBold(TextRange range)
        {
            if (range.GetPropertyValue(MyEdit.FontWeightProperty) == DependencyProperty.UnsetValue)
                return null;

            return (FontWeight)range.GetPropertyValue(MyEdit.FontWeightProperty) == FontWeights.Bold;
        }
示例#2
0
        public static bool? IsItalic(TextRange range)
        {
            if (range.GetPropertyValue(Control.FontStyleProperty) == DependencyProperty.UnsetValue)
                return null;

            return (FontStyle)range.GetPropertyValue(MyEdit.FontStyleProperty) == FontStyles.Italic;
        }
示例#3
0
        private void cmdBold_Click(object sender, RoutedEventArgs e)
        {
            if (richTextBox.Selection.Text == "")
            {
                FontWeight fontWeight = richTextBox.Selection.Start.Paragraph.FontWeight;
                if (fontWeight == FontWeights.Bold)
                    fontWeight = FontWeights.Normal;
                else
                    fontWeight = FontWeights.Bold;

                richTextBox.Selection.Start.Paragraph.FontWeight = fontWeight;
            }
            else
            {
            Object obj = richTextBox.Selection.GetPropertyValue(TextElement.FontWeightProperty);
            if (obj == DependencyProperty.UnsetValue)
            {
                TextRange range = new TextRange(richTextBox.Selection.Start,
                    richTextBox.Selection.Start);
                obj = range.GetPropertyValue(TextElement.FontWeightProperty);
            }

            FontWeight fontWeight = (FontWeight)obj;

            if (fontWeight == FontWeights.Bold)
              fontWeight = FontWeights.Normal;
            else
              fontWeight = FontWeights.Bold;

            richTextBox.Selection.ApplyPropertyValue(
              TextElement.FontWeightProperty, fontWeight);
            }
        }
示例#4
0
        void SetDecorations(swd.TextRange range, sw.TextDecorationCollection decorations, bool value)
        {
            var existingDecorations = range.GetPropertyValue(swd.Inline.TextDecorationsProperty) as sw.TextDecorationCollection;

            if (existingDecorations != null)
            {
                existingDecorations = new sw.TextDecorationCollection(existingDecorations);
            }
            if (value)
            {
                existingDecorations = existingDecorations ?? new sw.TextDecorationCollection();
                existingDecorations.Add(decorations);
            }
            else if (existingDecorations != null)
            {
                foreach (var decoration in decorations)
                {
                    if (existingDecorations.Contains(decoration))
                    {
                        existingDecorations.Remove(decoration);
                    }
                }
                if (existingDecorations.Count == 0)
                {
                    existingDecorations = null;
                }
            }
            range.ApplyPropertyValue(swd.Inline.TextDecorationsProperty, existingDecorations);
        }
示例#5
0
        public static bool? GetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation)
        {
            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) == DependencyProperty.UnsetValue)
                return null;

            TextDecorationCollection decorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);

            if (decorations == null)
                return false;

            foreach (TextDecoration decoration in decorations)
            {
                if (decoration.Location == decorationLocation)
                    return true;
            }

            return false;
        }
示例#6
0
 bool HasDecorations(swd.TextRange range, sw.TextDecorationCollection decorations, bool useRealPropertyValue = true)
 {
     swd.TextRange realRange;
     sw.TextDecorationCollection existingDecorations;
     if (useRealPropertyValue)
     {
         existingDecorations = range.GetRealPropertyValue(swd.Inline.TextDecorationsProperty, out realRange) as sw.TextDecorationCollection;
     }
     else
     {
         existingDecorations = range.GetPropertyValue(swd.Inline.TextDecorationsProperty) as sw.TextDecorationCollection;
     }
     return(existingDecorations != null && decorations.All(r => existingDecorations.Contains(r)));
 }
示例#7
0
 public FontProperties(TextRange range)
 {
     __FontWeight = range.GetPropertyValue(RichTextBox.FontWeightProperty);
     __FontSize = range.GetPropertyValue(RichTextBox.FontSizeProperty);
     __FontStyle = range.GetPropertyValue(RichTextBox.FontStyleProperty);
     __TextDecorations = range.GetPropertyValue(TextBlock.TextDecorationsProperty) as TextDecorationCollection;
     __FontFamily = range.GetPropertyValue(RichTextBox.FontFamilyProperty) as FontFamily;
     __ForegroundColor = range.GetPropertyValue(RichTextBox.ForegroundProperty) as Brush;
 }
示例#8
0
        private void RichTextControl_SelectionChanged(object sender, RoutedEventArgs e)
        {
            // markierten Text holen
            var selectionRange = new TextRange(RichTextControl.Selection.Start, RichTextControl.Selection.End);

            ToolStripButtonBold.IsChecked = selectionRange.GetPropertyValue(FontWeightProperty).ToString() == "Bold";

            ToolStripButtonItalic.IsChecked = selectionRange.GetPropertyValue(FontStyleProperty).ToString() == "Italic";

            ToolStripButtonUnderline.IsChecked = Equals(
                selectionRange.GetPropertyValue(Inline.TextDecorationsProperty), TextDecorations.Underline);

            ToolStripButtonStrikeout.IsChecked = Equals(
                selectionRange.GetPropertyValue(Inline.TextDecorationsProperty), TextDecorations.Strikethrough);

            if (selectionRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).ToString() == "Left")
            {
                ToolStripButtonAlignLeft.IsChecked = true;
            }

            if (selectionRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).ToString() == "Center")
            {
                ToolStripButtonAlignCenter.IsChecked = true;
            }

            if (selectionRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).ToString() == "Right")
            {
                ToolStripButtonAlignRight.IsChecked = true;
            }

            // Sub-, Superscript Buttons setzen
            try
            {
                switch ((BaselineAlignment) selectionRange.GetPropertyValue(Inline.BaselineAlignmentProperty))
                {
                    case BaselineAlignment.Subscript:
                        ToolStripButtonSubscript.IsChecked = true;
                        ToolStripButtonSuperscript.IsChecked = false;
                        break;

                    case BaselineAlignment.Superscript:
                        ToolStripButtonSubscript.IsChecked = false;
                        ToolStripButtonSuperscript.IsChecked = true;
                        break;

                    default:
                        ToolStripButtonSubscript.IsChecked = false;
                        ToolStripButtonSuperscript.IsChecked = false;
                        break;
                }
            }
            catch (Exception)
            {
                ToolStripButtonSubscript.IsChecked = false;
                ToolStripButtonSuperscript.IsChecked = false;
            }

            // Get selected font and height and update selection in ComboBoxes
            Fonttype.SelectedValue = selectionRange.GetPropertyValue(FlowDocument.FontFamilyProperty).ToString();
            Fontheight.SelectedValue = selectionRange.GetPropertyValue(FlowDocument.FontSizeProperty).ToString();

            // Ausgabe der Zeilennummer
            AktZeile = Zeilennummer();

            // Ausgabe der Spaltennummer
            AktSpalte = Spaltennummer();
        }
		void RichTextBox_SelectionChanged(object sender, RoutedEventArgs e)
		{
			TextRange selectionRange = new TextRange(RichTextControl.Selection.Start, RichTextControl.Selection.End);
            
			/*if ( string.IsNullOrEmpty(selectionRange.Text))
			{
				ToolStripComboTextColor.Background = _oldTextColor;
				ToolStripComboBackColor.Background = _oldBackColor;
			//} else {
				_oldTextColor = ToolStripComboTextColor.Background;
				_oldBackColor = ToolStripComboBackColor.Background;
				ToolStripComboTextColor.Background = (Brush)selectionRange.GetPropertyValue(FlowDocument.ForegroundProperty);
				ToolStripComboBackColor.Background = (Brush)selectionRange.GetPropertyValue(FlowDocument.BackgroundProperty);
			//}*/
			
            if (selectionRange.GetPropertyValue(FontWeightProperty).ToString() == "Bold")
            {
                ToolStripButtonBold.IsChecked = true;
            }
            else
            {
                ToolStripButtonBold.IsChecked = false;
            }

            if (selectionRange.GetPropertyValue(FontStyleProperty).ToString() == "Italic")
            {
                ToolStripButtonItalic.IsChecked = true;
            }
            else
            {
                ToolStripButtonItalic.IsChecked = false;
            }

            if (selectionRange.GetPropertyValue(Inline.TextDecorationsProperty) == TextDecorations.Underline)
            {
                ToolStripButtonUnderline.IsChecked = true;
            }
            else
            {
                ToolStripButtonUnderline.IsChecked = false;
            }

            if (selectionRange.GetPropertyValue(Inline.TextDecorationsProperty) == TextDecorations.Strikethrough)
            {
                ToolStripButtonStrikeout.IsChecked = true;
            }
            else
            {
                ToolStripButtonStrikeout.IsChecked = false;
            } 

            if (selectionRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).ToString() == "Left")
            {
                ToolStripButtonAlignLeft.IsChecked = true;
                ToolStripButtonAlignCenter.IsChecked = false;
                ToolStripButtonAlignRight.IsChecked = false;
            }

            if (selectionRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).ToString() == "Center")
            {
                ToolStripButtonAlignLeft.IsChecked = false;
                ToolStripButtonAlignCenter.IsChecked = true;
                ToolStripButtonAlignRight.IsChecked = false;
            }

            if (selectionRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).ToString() == "Right")
            {
                ToolStripButtonAlignLeft.IsChecked = false;
                ToolStripButtonAlignCenter.IsChecked = false;
                ToolStripButtonAlignRight.IsChecked = true;
            }
            
            // Sub-, Superscript Buttons setzen
            try
            {                
                switch ((BaselineAlignment)selectionRange.GetPropertyValue(Inline.BaselineAlignmentProperty))
                {
                    case BaselineAlignment.Subscript:
                        ToolStripButtonSubscript.IsChecked = true;
                        ToolStripButtonSuperscript.IsChecked = false;
                        break;

                    case BaselineAlignment.Superscript:
                        ToolStripButtonSubscript.IsChecked = false;
                        ToolStripButtonSuperscript.IsChecked = true;
                        break;

                    default:
                        ToolStripButtonSubscript.IsChecked = false;
                        ToolStripButtonSuperscript.IsChecked = false;
                        break;
                }
            }
            catch (Exception) 
            {
                ToolStripButtonSubscript.IsChecked = false;
                ToolStripButtonSuperscript.IsChecked = false;
            }                    

            // Get selected font and height and update selection in ComboBoxes
            Fonttype.SelectedValue = selectionRange.GetPropertyValue(FlowDocument.FontFamilyProperty).ToString();
            Fontheight.SelectedValue = selectionRange.GetPropertyValue(FlowDocument.FontSizeProperty).ToString();
		}
示例#10
0
        public BufferCell GetCell(TextPointer position, LogicalDirection direction)
        {
            TextRange range = null;
            try
            {
                range = new TextRange(position, position.GetPositionAtOffset(1, direction));

                return new BufferCell(
                        (range.IsEmpty || range.Text[0] == '\n') ? ' ' : range.Text[0],
                        ConsoleColorFromBrush((Brush)range.GetPropertyValue(TextElement.ForegroundProperty)),
                        ConsoleColorFromBrush((Brush)range.GetPropertyValue(TextElement.BackgroundProperty)),
                        BufferCellType.Complete);
            }
            catch
            {
                return new BufferCell();
            }
        }
示例#11
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = this.TargetRichTextBox;

            TextRange tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            //int startIndex = rtbx.Text.Length;
            //rtbx.SelectionStart = startIndex;
            //rtbx.SelectionBackColor = GetColorFromString(rule.BackgroundColor, rtbx.BackColor);
            //rtbx.SelectionColor = GetColorFromString(rule.FontColor, rtbx.ForeColor);
            //rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ rule.Style);
            //rtbx.AppendText(logMessage + "\n");
            //rtbx.SelectionLength = rtbx.Text.Length - rtbx.SelectionStart;

            //// find word to color
            //foreach (RichTextBoxWordColoringRule wordRule in this.WordColoringRules)
            //{
            //    MatchCollection mc = wordRule.CompiledRegex.Matches(rtbx.Text, startIndex);
            //    foreach (Match m in mc)
            //    {
            //        rtbx.SelectionStart = m.Index;
            //        rtbx.SelectionLength = m.Length;
            //        rtbx.SelectionBackColor = GetColorFromString(wordRule.BackgroundColor, rtbx.BackColor);
            //        rtbx.SelectionColor = GetColorFromString(wordRule.FontColor, rtbx.ForeColor);
            //        rtbx.SelectionFont = new Font(rtbx.SelectionFont, rtbx.SelectionFont.Style ^ wordRule.Style);
            //    }
            //}

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > this.MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                //rtbx.Select(rtbx.TextLength, 0);
                rtbx.ScrollToEnd();
            }
        }
示例#12
0
        /// <summary>
        /// Sets the toolbar.
        /// </summary>
        private void SetToolbar()
        {
            // Set font family combo
            var textRange = new TextRange(TextBox.Selection.Start, TextBox.Selection.End);
            var fontFamily = textRange.GetPropertyValue(TextElement.FontFamilyProperty);
            FontFamilyCombo.SelectedItem = fontFamily;

            // Set font size combo
            var fontSize = textRange.GetPropertyValue(TextElement.FontSizeProperty);
            FontSizeCombo.Text = fontSize.ToString();

            // Set Font buttons
            if (!String.IsNullOrEmpty(textRange.Text))
            {
                BoldButton.IsChecked = textRange.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Bold);
                ItalicButton.IsChecked = textRange.GetPropertyValue(TextElement.FontStyleProperty).Equals(FontStyles.Italic);
                var prop = textRange.GetPropertyValue(Inline.TextDecorationsProperty);
                if( prop!= null)
                    UnderlineButton.IsChecked = textRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Underline);
            }

            // Set Alignment buttons
            LeftButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Left);
            CenterButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Center);
            RightButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Right);
            JustifyButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Justify);
        }
示例#13
0
        private void UpdateFontSettings(TextRange range)
        {
            double fontSize = -1;
            if (range.GetPropertyValue(TextBlock.FontSizeProperty) != DependencyProperty.UnsetValue)
                fontSize = (double)range.GetPropertyValue(TextBlock.FontSizeProperty);

            FontFamily fontFamily = range.GetPropertyValue(Run.FontFamilyProperty) as FontFamily;

            __FontParametersChanging = true;
            try
            {
                TextSettingsSetFontSize(fontSize);
                TextSettingsSetFontFamily(fontFamily);
            }
            finally
            {
                __FontParametersChanging = false;
            }

            SolidColorBrush fontBrush = Brushes.Black;
            if (range.GetPropertyValue(ForegroundProperty) != DependencyProperty.UnsetValue)
                fontBrush = (SolidColorBrush)range.GetPropertyValue(ForegroundProperty);

            SelectColorBorder.Background = fontBrush;

            FontBold.IsChecked = TextRangeHelpers.IsBold(range);
            FontItalic.IsChecked = TextRangeHelpers.IsItalic(range);
            FontUnderline.IsChecked = TextRangeHelpers.GetTextDecorationOnSelection(range, TextDecorationLocation.Underline);
            FontStrikethrough.IsChecked = TextRangeHelpers.GetTextDecorationOnSelection(range, TextDecorationLocation.Strikethrough);
        }
示例#14
0
        private SolidColorBrush SelectColor(MyEdit edit, TextRange range)
        {
            SolidColorBrush currentBrush = Brushes.Black;
            SolidColorBrush newBrush = null;
            if (range.GetPropertyValue(ForegroundProperty) != DependencyProperty.UnsetValue)
            {
                currentBrush = (SolidColorBrush)range.GetPropertyValue(ForegroundProperty);
            }

            ColorPickerDialog colorPicker = new ColorPickerDialog();
            colorPicker.Owner = this;

            colorPicker.cPicker.SelectedColor = currentBrush.Color;
            if (colorPicker.ShowDialog() == true)
            {
                newBrush = new SolidColorBrush(colorPicker.cPicker.SelectedColor);
                if (edit != null)
                {
                    edit.ApplyUndoAwarePropertyValue(range, ForegroundProperty, newBrush);
                }
                else
                {

                    ApplyUndoEnabledPropertyValue(OutlinerTree.SelectedItem, ForegroundProperty, newBrush);
                }
            }

            UpdateFontSettings(range);
            return newBrush;
        }
        /// <summary>
        /// Processes selection changed event.
        /// </summary>
        private void ProcessSelectionChanged()
        {
            if (this.htmlEditorViewModel == null)
                return;

            TextRange tr = new TextRange(this.Selection.Start, this.Selection.End);
            if (tr.GetPropertyValue(FontWeightProperty).ToString() == "Bold")
            {
                if (!this.htmlEditorViewModel.IsSelectionTextBold)
                    this.htmlEditorViewModel.IsSelectionTextBold = true;
            }
            else
            {
                if (this.htmlEditorViewModel.IsSelectionTextBold)
                    this.htmlEditorViewModel.IsSelectionTextBold = false;
            }

            if (tr.GetPropertyValue(FontStyleProperty).ToString() == "Italic")
            {
                if (!htmlEditorViewModel.IsSelectionTextItalic)
                    this.htmlEditorViewModel.IsSelectionTextItalic = true;
            }
            else
            {
                if (htmlEditorViewModel.IsSelectionTextItalic)
                    this.htmlEditorViewModel.IsSelectionTextItalic = false;
            }

            bool bHandledUnderline = false;
            TextDecorationCollection col = tr.GetPropertyValue(Inline.TextDecorationsProperty) as TextDecorationCollection;
            if (col != null)
            {

                foreach (TextDecoration decoration in col)
                    if (decoration == TextDecorations.Underline[0])
                    {
                        bHandledUnderline = true;
                        if (!this.htmlEditorViewModel.IsSelectionTextUnderlined)
                            this.htmlEditorViewModel.IsSelectionTextUnderlined = true;
                        break;
                    }
            }
            if (!bHandledUnderline)
                if (this.htmlEditorViewModel.IsSelectionTextUnderlined)
                    this.htmlEditorViewModel.IsSelectionTextUnderlined = false;

            // alignment
            object alignmentObj = tr.GetPropertyValue(Paragraph.TextAlignmentProperty);
            if (alignmentObj != null)
            {
                TextAlignment alignment = (TextAlignment)alignmentObj;
                bool bAlignLeft = false;
                bool bAlignCenter = false;
                bool bAlignRight = false;
                bool bAlignJustify = false;
                if (alignment == System.Windows.TextAlignment.Left)
                    bAlignLeft = true;
                else if (alignment == System.Windows.TextAlignment.Center)
                    bAlignCenter = true;
                else if (alignment == System.Windows.TextAlignment.Right)
                    bAlignRight = true;
                else if (alignment == System.Windows.TextAlignment.Justify)
                    bAlignJustify = true;

                if (htmlEditorViewModel.IsSelectionAlignedLeft != bAlignLeft)
                    htmlEditorViewModel.IsSelectionAlignedLeft = bAlignLeft;
                if (htmlEditorViewModel.IsSelectionAlignedCenter != bAlignCenter)
                    htmlEditorViewModel.IsSelectionAlignedCenter = bAlignCenter;
                if (htmlEditorViewModel.IsSelectionAlignedRight != bAlignRight)
                    htmlEditorViewModel.IsSelectionAlignedRight = bAlignRight;
                if (htmlEditorViewModel.IsSelectionAlignedJustified != bAlignJustify)
                    htmlEditorViewModel.IsSelectionAlignedJustified = bAlignJustify;
            }

            updateSelectionPropertiesPending = false;
        }
      public BufferCell[,] GetBufferContents(Rectangle rectangle)
      {
         BufferCell[,] bufferCells = new BufferCell[(rectangle.Top - rectangle.Bottom), (rectangle.Right - rectangle.Left)];
         try
         {
            int cur =
               (int)
               ((_next.ElementEnd.GetCharacterRect(LogicalDirection.Backward).Bottom +
                 ScrollViewer.ContentVerticalOffset)/
                (Double.IsNaN(Document.LineHeight) ? Document.FontSize : Document.LineHeight));
            int count;
            TextPointer next,
                        end,
                        start =
                           _next.ElementEnd.GetNextContextPosition(LogicalDirection.Backward).GetLineStartPosition(
                              rectangle.Bottom - cur, out count);
            if (start != null)
            {
               for (int ln = 0; ln <= rectangle.Top - rectangle.Bottom; ln++)
               {
                  next = start.GetLineStartPosition(1);
                  start = start.GetPositionAtOffset(rectangle.Left);
                  // if there's text on this line after that char
                  if (start.GetOffsetToPosition(next) <= 0)
                  {
                     // no output on this line
                     continue;
                  }

                  end = start.GetPositionAtOffset(1);
                  int c = 0, width = rectangle.Right - rectangle.Left;
                  while (end.GetOffsetToPosition(next) <= 0 && c < width)
                  {
                     var character = new TextRange(start, end);
                     bufferCells[ln, c++] = new BufferCell(character.Text[0],
                                                           _brushes.ConsoleColorFromBrush(
                                                              character.GetPropertyValue(ForegroundProperty) as Brush),
                                                           _brushes.ConsoleColorFromBrush(
                                                              character.GetPropertyValue(BackgroundProperty) as Brush),
                                                           BufferCellType.Complete);

                     end = end.GetPositionAtOffset(1);
                  }
                  for (; c < width; c++)
                  {
                     bufferCells[ln, c] = new BufferCell(' ', ForegroundColor, BackgroundColor, BufferCellType.Complete);
                  }
                  start = next;
               }
            }
         } catch( Exception ex )
         {
            this.Write( _brushes.ErrorForeground, _brushes.ErrorBackground, ex.Message);
         }
         return bufferCells;
      }
        /// <summary>
        /// Sets the toolbar.
        /// </summary>
        private void SetToolbar()
        {
            // Set font family combo
            var textRange = new TextRange(TextBox.Selection.Start, TextBox.Selection.End);
            var fontFamily = textRange.GetPropertyValue(TextElement.FontFamilyProperty);
            FontFamilyCombo.SelectedItem = fontFamily.ToString();   // @EDITED only works with the string representation

            // Set font size combo
            if (textRange.GetPropertyValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue) {
                var fontSize = textRange.GetPropertyValue(TextElement.FontSizeProperty);
                FontSizeCombo.Text = fontSize.ToString();
            }
            else {
                FontSizeCombo.Text = "";
            }

            // Set Font buttons @TODO FIX => doesn't work
            if (!String.IsNullOrEmpty(textRange.Text))
            {
                BoldButton.IsChecked = textRange.GetPropertyValue(TextElement.FontWeightProperty).Equals(FontWeights.Bold);
                ItalicButton.IsChecked = textRange.GetPropertyValue(TextElement.FontStyleProperty).Equals(FontStyles.Italic);
                UnderlineButton.IsChecked = textRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Underline);
            }

            // Set Alignment buttons
            LeftButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Left);
            CenterButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Center);
            RightButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Right);
            JustifyButton.IsChecked = textRange.GetPropertyValue(FlowDocument.TextAlignmentProperty).Equals(TextAlignment.Justify);

            // @EDITED Set font color chip
            if (textRange.GetPropertyValue(ForegroundProperty) != DependencyProperty.UnsetValue) {
                // Set the selected text's color as current chip color (converting hex to rgb).
                // WPF contains a built-in value converter that will recognize the ForegroundProperty's hex as a SolidColorBrush.
                var brush = (SolidColorBrush)(textRange.GetPropertyValue(ForegroundProperty));
                fontColor.Color = brush.Color;  // rgb color of the brush
            }
            else {
                // If multicolored text is selected set a neutral chip color (transparent)
                fontColor.Color = Color.FromArgb(0, 0, 0, 0);
            }
        }
示例#18
0
        public static void SetTextDecorationOnSelection(TextRange range, TextDecorationLocation decorationLocation, TextDecorationCollection newTextDecorations, bool value)
        {
            TextDecorationCollection decorations = new TextDecorationCollection();
            if (range.GetPropertyValue(TextBlock.TextDecorationsProperty) != DependencyProperty.UnsetValue)
            {
                TextDecorationCollection oldDecorations = (TextDecorationCollection)range.GetPropertyValue(TextBlock.TextDecorationsProperty);
                if (oldDecorations != null)
                    decorations.Add(oldDecorations);
            }

            if (value == true)
            {
                bool underlineAlreadyFound = false;
                foreach (TextDecoration decoration in decorations)
                {
                    if (decoration.Location == decorationLocation)
                    {
                        underlineAlreadyFound = true;
                        break;
                    }
                }

                if (!underlineAlreadyFound)
                {
                    decorations.Add(newTextDecorations);
                    range.ApplyPropertyValue(TextBlock.TextDecorationsProperty, decorations);
                }
            }
            else
            {
                for (int i = 0; i < decorations.Count; i++)
                {
                    if (decorations[i].Location == decorationLocation)
                    {
                        decorations.RemoveAt(i);
                        break;
                    }
                }

                range.ApplyPropertyValue(TextBlock.TextDecorationsProperty, decorations);
            }
        }
示例#19
0
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = TargetRichTextBox;

            var scrolledToEnd =
                AutoScroll
                && (TargetRichTextBox.VerticalOffset + TargetRichTextBox.ViewportHeight) >= (TargetRichTextBox.ExtentHeight - .1);

            var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            if (MaxLines > 0)
            {
                while (rtbx.Document.Blocks.Count - 1 > MaxLines)
                {
                    rtbx.Document.Blocks.Remove(rtbx.Document.Blocks.FirstBlock);
                }
            }

            if (AutoScroll && scrolledToEnd)
            {
                rtbx.ScrollToEnd();
            }
        }
示例#20
0
        public bool HasSameStyle(TextRange range)
        {
            if (CompareBrushes(__ForegroundColor, range.GetPropertyValue(TextBlock.ForegroundProperty) as Brush))
                return false;

            if (__FontWeight != range.GetPropertyValue(RichTextBox.FontWeightProperty))
                return false;

            if (__FontSize != range.GetPropertyValue(RichTextBox.FontSizeProperty))
                return false;

            if (__FontStyle != range.GetPropertyValue(RichTextBox.FontStyleProperty))
                return false;

            if (CompareDecorations(__TextDecorations, range.GetPropertyValue(TextBlock.TextDecorationsProperty) as TextDecorationCollection))
                return false;

            if (__FontFamily != range.GetPropertyValue(RichTextBox.FontFamilyProperty))
                return false;

            return true;
        }
        private void SendTheMessageToRichTextBox(string logMessage, WpfRichTextBoxRowColoringRule rule)
        {
            System.Windows.Controls.RichTextBox rtbx = TargetRichTextBox;

            var tr = new TextRange(rtbx.Document.ContentEnd, rtbx.Document.ContentEnd);
            tr.Text = logMessage + "\n";
            tr.ApplyPropertyValue(TextElement.ForegroundProperty,
                new SolidColorBrush(GetColorFromString(rule.FontColor, (Brush)tr.GetPropertyValue(TextElement.ForegroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.BackgroundProperty,
                new SolidColorBrush(GetColorFromString(rule.BackgroundColor, (Brush)tr.GetPropertyValue(TextElement.BackgroundProperty)))
            );
            tr.ApplyPropertyValue(TextElement.FontStyleProperty, rule.Style);
            tr.ApplyPropertyValue(TextElement.FontWeightProperty, rule.Weight);

            if (this.MaxLines > 0)
            {
                this.lineCount++;
                if (this.lineCount > MaxLines)
                {
                    tr = new TextRange(rtbx.Document.ContentStart, rtbx.Document.ContentEnd);
                    tr.Text.Remove(0, tr.Text.IndexOf('\n'));
                    this.lineCount--;
                }
            }

            if (this.AutoScroll)
            {
                rtbx.ScrollToEnd();
            }
        }
示例#22
0
        //
        // Nach dem Laden des Control
        //
        private void RTFEditor_Loaded(object sender, RoutedEventArgs e)
        {
            // Schrifttypen- und -größen-Initialisierung
            var range = new TextRange(RichTextControl.Selection.Start, RichTextControl.Selection.End);
            Fonttype.SelectedValue = range.GetPropertyValue(FlowDocument.FontFamilyProperty).ToString();
            Fontheight.SelectedValue = range.GetPropertyValue(FlowDocument.FontSizeProperty).ToString();

            // aktuelle Zeilen- und Spaltenpositionen angeben
            AktZeile = Zeilennummer();
            AktSpalte = Spaltennummer();

            RichTextControl.Focus();
        }