상속: TextElement
 protected override void _AddLineImpl( Inline inline )
 {
     FlowDocument.Blocks.Add( new Paragraph( inline ) {
         Background = Brushes.MediumBlue,
         Foreground = Brushes.White,
     } );
 }
예제 #2
0
        /// <summary>
        /// Creates a new Span instance.
        /// </summary>
        /// <param name="childInline">
        /// Optional child Inline for the new Span.  May be null.
        /// </param>
        /// <param name="insertionPosition">
        /// Optional position at which to insert the new Span.  May be null.
        /// </param>
        public Span(Inline childInline, TextPointer insertionPosition)
        {
            if (insertionPosition != null)
            {
                insertionPosition.TextContainer.BeginChange();
            }
            try
            {
                if (insertionPosition != null)
                {
                    // This will throw InvalidOperationException if schema validity is violated.
                    insertionPosition.InsertInline(this);
                }

                if (childInline != null)
                {
                    this.Inlines.Add(childInline);
                }
            }
            finally
            {
                if (insertionPosition != null)
                {
                    insertionPosition.TextContainer.EndChange();
                }
            }
        }
예제 #3
0
        private static void OnHtmlTextChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            // Go ahead and return out if we set the property on something other than a textblock, or set a value that is not a string.
            var txtBox = depObj as TextBlock;
            if(txtBox == null)
                return;
            if(!(e.NewValue is string))
                return;
            var html = e.NewValue as string;
            string xaml;
            InlineCollection xamLines;

            try {

                xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, false);
                xamLines = ((Paragraph)((Section)System.Windows.Markup.XamlReader.Parse(xaml)).Blocks.FirstBlock).Inlines;

            } catch {
                // There was a problem parsing the html, return out.
                return;
            }
            // Create a copy of the Inlines and add them to the TextBlock.
            Inline[] newLines = new Inline[xamLines.Count];
            xamLines.CopyTo(newLines, 0);

            txtBox.Inlines.Clear();
            foreach(var l in newLines) {
                txtBox.Inlines.Add(l);
            }
        }
예제 #4
0
        private Inline[] GetInlines()
        {
            Inline[] inlines = new Inline[3];

            Match firstMatch = _result.TextMatches[0];
            string sourceText = _result.SourceText;

            int startIndex = Math.Max(0, firstMatch.Index - CHARS_TO_INCLUDE);
            string prev = sourceText.Substring(startIndex, firstMatch.Index - startIndex);
            inlines[0] = new Run()
            {
                Text = prev,
                Foreground = new SolidColorBrush(Colors.Gray)
            };

            string match = firstMatch.Value;
            inlines[1] = new Run()
            {
                Text = match,
                Foreground = (Brush)App.Current.Resources["PhoneForegroundBrush"]
            };

            startIndex = firstMatch.Index + firstMatch.Value.Length;
            int length = Math.Min(sourceText.Length - startIndex, CHARS_TO_INCLUDE);
            string after = sourceText.Substring(startIndex, length);
            inlines[2] = new Run()
            {
                Text = after,
                Foreground = new SolidColorBrush(Colors.Gray)
            };

            return inlines;
        }
예제 #5
0
        public InlineTweetView(Inline body, Tweet tweet)
            : this()
        {
            _tweet = tweet;
            _body.Inlines.Add(body);

            DataContext = this;
        }
        public static Inline Insert(this Inline inline, Inline inlineToAdd)
        {
            var span = inline as Span ?? new Span(inline);

            span.Inlines.Add(inlineToAdd);

            return span;
        }
        public static Inline Append(this Inline inline, Inline inlineToAdd)
        {
            var span = new Span(inline);

            span.Inlines.Add(inlineToAdd);

            return span;
        }
예제 #8
0
		void routeHyperlinks(Inline inl)
		{
			if (inl is Hyperlink)
				(inl as Hyperlink).RequestNavigate += (s, e) => App.Current.OnRequestNavigate(s, e);

			if (inl is Span)
				foreach (var sub in (inl as Span).Inlines)
					routeHyperlinks(sub);
		}
예제 #9
0
        public TerminalControl()
        {
            InitializeComponent();

            caretInline = Input.Inlines.LastInline;

            RTB.PreviewMouseDown += OnControlMouseDown;
            //TextReceiver.TextChanged += TextChanged;
        }
        public static void AddIfNotNull(this InlineCollection inlineCollection, Inline inline)
        {
            if (inline == null)
            {
                return;
            }

            inlineCollection.Add(inline);
        }
예제 #11
0
파일: Paragraph.cs 프로젝트: JianwenSun/cc
        /// <summary>
        /// Paragraph constructor.
        /// </summary>
        public Paragraph(Inline inline)
            : base()
        {
            if (inline == null)
            {
                throw new ArgumentNullException("inline");
            }

            this.Inlines.Add(inline);
        }
예제 #12
0
파일: Repl.xaml.cs 프로젝트: jflam/repl-lib
 public Inline InsertInspectedResult(Inline position, object obj)
 {
     LoadInspector(obj);
     object result = _rubyEngine.InvokeMember(obj, "as_xaml");
     if (result is MutableString) {
         return InsertColorizedCode(position, result.ToString());
     } else {
         throw new NotImplementedError("do not have mechanism to insert UIElement in middle of flow document yet");
     }
 }
예제 #13
0
        public static TextPointer RemoveHyperlink(TextPointer start)
        {
            var backspacePosition = start.GetNextInsertionPosition(LogicalDirection.Backward);
            Hyperlink hyperlink;
            if (backspacePosition == null || !IsHyperlinkBoundaryCrossed(start, backspacePosition, out hyperlink))
            {
                return null;
            }

            // Remember caretPosition with forward gravity. This is necessary since we are going to delete
            // the hyperlink element preceeding caretPosition and after deletion current caretPosition
            // (with backward gravity) will follow content preceeding the hyperlink.
            // We want to remember content following the hyperlink to set new caret position at.

            var newCaretPosition = start.GetPositionAtOffset(0, LogicalDirection.Forward);

            // Deleting the hyperlink is done using logic below.

            // 1. Copy its children Inline to a temporary array.
            var hyperlinkChildren = hyperlink.Inlines;
            var inlines = new Inline[hyperlinkChildren.Count];
            hyperlinkChildren.CopyTo(inlines, 0);

            // 2. Remove each child from parent hyperlink element and insert it after the hyperlink.
            for (int i = inlines.Length - 1; i >= 0; i--)
            {
                hyperlinkChildren.Remove(inlines[i]);
                hyperlink.SiblingInlines.InsertAfter(hyperlink, inlines[i]);
            }

            // 3. Apply hyperlink's local formatting properties to inlines (which are now outside hyperlink scope).
            var localProperties = hyperlink.GetLocalValueEnumerator();
            var inlineRange = new TextRange(inlines[0].ContentStart, inlines[inlines.Length - 1].ContentEnd);

            while (localProperties.MoveNext())
            {
                var property = localProperties.Current;
                var dp = property.Property;
                object value = property.Value;

                if (!dp.ReadOnly &&
                    dp != Inline.TextDecorationsProperty && // Ignore hyperlink defaults.
                    dp != TextElement.ForegroundProperty &&
                    dp != BaseUriHelper.BaseUriProperty &&
                    !IsHyperlinkProperty(dp))
                {
                    inlineRange.ApplyPropertyValue(dp, value);
                }
            }

            // 4. Delete the (empty) hyperlink element.
            hyperlink.SiblingInlines.Remove(hyperlink);

            return newCaretPosition;
        }
예제 #14
0
        public static Inline Append(this Inline inline, Inline inlineToAdd)
        {
            Argument.IsNotNull(() => inline);
            Argument.IsNotNull(() => inlineToAdd);

            var span = new Span(inline);

            span.Inlines.Add(inlineToAdd);

            return span;
        }
 private static void LookupHyperlinks(Inline inline)
 {
     if (inline is Hyperlink)
     {
         var hyperlink = ((Hyperlink) inline);
         hyperlink.RequestNavigate += HyperlinkRequestNavigate;
     }
     if (inline is Span)
         foreach (Inline subInline in ((Span) inline).Inlines)
             LookupHyperlinks(subInline);
 }
예제 #16
0
 public Inline FormatInlineForID(Inline inline, int id)
 {
     if (id == 1)
     {
         inline.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 255, 127, 53));
     }
     else if (id == 2)
     {
         inline.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 255, 170, 53));
     }
     return inline;
 }
 public AlliSharpMessageBox(string title, Inline[] customMessage)
 {
     InitializeComponent();
     this.Title = title;
     tbMessage.Inlines.Clear();
     foreach (Inline il in customMessage)
     {
         tbMessage.Inlines.Add(il);
     }
     System.Media.SystemSounds.Asterisk.Play();
     this.ShowDialog();
 }
 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var result = base.Convert(value, targetType, parameter, culture);
     var list = result as Inline[];
     if (list?.LastOrDefault() is LineBreak)
     {
         var newList = new Inline[list.Length - 1];
         Array.Copy(list, newList, list.Length - 1);
         return newList;
     }
     return result;
 }
예제 #19
0
        private static void RecreateInlines(TextBlock t, Inline prefix, IEnumerable<Inline> list)
        {
            t.Inlines.Clear();

            if (prefix != null)
                t.Inlines.Add(prefix);
            foreach (var i in list)
            {
                t.Inlines.Add(i);
            }

            t.InvalidateMeasure();
        }
예제 #20
0
파일: InlineTest.cs 프로젝트: dfr0/moon
		static public void CheckTextBlockInherited (Inline i)
		{
			Assert.AreEqual ("Portable User Interface", i.FontFamily.Source, "FontFamily");
			Assert.AreEqual (11, i.FontSize, "FontSize");
			Assert.AreEqual (DependencyProperty.UnsetValue, i.ReadLocalValue(Inline.FontSizeProperty), "FontSize local value");

			Assert.AreEqual (FontStretches.Normal, i.FontStretch, "FontStretch");
			Assert.AreEqual (FontStyles.Normal, i.FontStyle, "FontStyle");
			Assert.AreEqual (FontWeights.Normal, i.FontWeight, "FontWeight");

			Assert.IsNotNull (i.Foreground, "Foreground");
			Assert.AreEqual (Colors.Black, (i.Foreground as SolidColorBrush).Color, "Foreground.Color");
			Assert.AreEqual ("en-us", i.Language.IetfLanguageTag, "Language");
			Assert.IsNull (i.TextDecorations, "TextDecorations");
		}
예제 #21
0
        public static void InsertAtOffset(RichTextBox rtb, Inline inline, int targetOffset)
        {
            int currentOffset = 0;
            while (true)
            {
                TextPointer currentPosition = rtb.ContentStart.GetPositionAtOffset(currentOffset, LogicalDirection.Forward);
                if (currentPosition == null) break;

                currentOffset += 1;
                if (currentOffset == targetOffset)
                {
                    rtb.Selection.Select(currentPosition, currentPosition);
                    rtb.Selection.Insert(inline);
                    break;
                }
            }
        }
예제 #22
0
        private static void OnXamlStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextBlock tb = d as TextBlock;
            if(tb == null)
                return;

            string xamlString = e.NewValue as string;
            if(string.IsNullOrEmpty(xamlString))
                return;

            InlineCollection inlineCollection = CreateInlineCollection(xamlString);
            if(inlineCollection == null || inlineCollection.Count == 0)
                return;

            Inline[] inlines = new Inline[inlineCollection.Count];
            inlineCollection.CopyTo(inlines, 0);

            PopulateTextBlockInlines(tb, inlines);
        }
예제 #23
0
        private static void PopulateTextBlockInlines(TextBlock tb, Inline[] inlines)
        {
            if (inlines == null || inlines.Length == 0 || tb == null)
                return;

            tb.Inlines.Clear();
            foreach (var inline in inlines)
            {
                var hyperLink = inline as Hyperlink;
                if (hyperLink != null)
                    hyperLink.Click += (sender, args) =>
                    {
                        var hl = (Hyperlink)sender;
                        Process.Start(hl.NavigateUri.ToString());
                    };

                tb.Inlines.Add(inline);
            }
        }
예제 #24
0
        public static bool RequiresSpace(Inline lastInline, Inline nextInline)
        {
            var requiresSpace = true;
            var nextRun = nextInline as Run;
            var nextInlineFirstCharacter = nextRun == null ? '\0' : (nextRun.Text ?? string.Empty).FirstOrDefault();

            if (lastInline == null)
                requiresSpace = RequiresSpace('\0', nextInlineFirstCharacter);

            var lineBreak = lastInline as LineBreak;
            if (lineBreak != null)
                requiresSpace = RequiresSpace('\n', nextInlineFirstCharacter);

            var run = lastInline as Run;
            if (run != null)
                requiresSpace = !string.IsNullOrEmpty(run.Text) && RequiresSpace(run.Text.Last(), nextInlineFirstCharacter);

            return requiresSpace;
        }
예제 #25
0
        /// <summary> Convert a string into an array of inline containing plain text and hyperlinks </summary>
        public static Inline[] CreateInlineTextWithLinks(string sText, EventHandler<System.Windows.RoutedEventArgs> ClickMethod)
        {
            Paragraph para = new Paragraph();
            int iURLPos = 0;
            char[] EndOfURL = new char[] { ' ', ',' };
            const string HTTP = "http://";

            do {
                // Search for a url
                iURLPos = sText.IndexOf(HTTP, StringComparison.CurrentCultureIgnoreCase);

                if (iURLPos == -1)  // No url found so just add the text
                    para.Inlines.Add(sText);

                if (iURLPos > -1) {
                    // Add normal text up to the point of the url
                    para.Inlines.Add(sText.Substring(0, iURLPos));

                    // Find the length of the url
                    int iURLLength = sText.IndexOfAny(EndOfURL, iURLPos) - iURLPos;

                    // iEndOfURLPos < 0 means url was at the end of the text, so calculate based on text length
                    if (iURLLength < 0) iURLLength = sText.Length - iURLPos;

                    // Create the hyperlink
                    string sHyper = sText.Substring(iURLPos, iURLLength);

                    if (sHyper == HTTP)
                        para.Inlines.Add(sHyper);
                    else
                        para.Inlines.Add(CreateHyperLink(sHyper, sHyper, ClickMethod));

                    // Shorten text to the end of the url onwards
                    sText = sText.Substring(iURLPos + iURLLength);
                }
            } while (iURLPos != -1);

            Inline[] lines = new Inline[para.Inlines.Count];
            para.Inlines.CopyTo(lines, 0);

            return lines;
        }
예제 #26
0
 private void ProcessForHighlights(Inline item)
 {
     if (Object.Equals(RedlineTextBuilder.ChangeTag,item.Tag))
         m_currentlyInAChange = true;
     if (item is Run)
     {
         ProcessRun(item as Run);
     }
     else if (item is Span)
     {
         Span sp = item as Span;
         Inline subItem = sp.Inlines.FirstInline;
         while (subItem != null)
         {
             ProcessForHighlights(subItem);
             subItem = subItem.NextInline;
         }
     }
     if (Object.Equals(RedlineTextBuilder.ChangeTag,item.Tag))
         m_currentlyInAChange = false;
 }
예제 #27
0
 public void FormatInline(FlowDocument doc, Inline inline, StringBuilder buf, int indent)
 {
     // indent
      buf.Append (' ', indent);
      buf.AppendFormat (
     "{0} {1} to {2}",
     inline.GetType ().Name + inline.GetHashCode (),
     inline.ContentStart.CompareTo (doc.ContentStart),
     inline.ContentEnd.CompareTo (doc.ContentStart));
      if (inline is Run)
      {
     buf.Append ("  \"" + ((Run)inline).Text + "\"");
      }
      buf.AppendLine ();
      if (inline is Underline)
      {
     FormatInlines (doc, ((Underline)inline).Inlines,  buf, indent + 3);
      }
      if (inline is Italic)
      {
     FormatInlines (doc, ((Italic)inline).Inlines,  buf, indent + 3);
      }
 }
 public DocTree(Inline element, int row, int column)
     : this()
 {
     Element = element;
     Row = row; Column = column;
 }
예제 #29
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Documents.Bold" /> class, taking a specified <see cref="T:System.Windows.Documents.Inline" /> object as the initial contents of the new <see cref="T:System.Windows.Documents.Bold" />.</summary>
 /// <param name="childInline">An <see cref="T:System.Windows.Documents.Inline" /> object specifying the initial contents of the new <see cref="T:System.Windows.Documents.Bold" />.</param>
 // Token: 0x06002B11 RID: 11025 RVA: 0x000C4509 File Offset: 0x000C2709
 public Bold(Inline childInline) : base(childInline)
 {
 }
예제 #30
0
 public Span(Inline childInline)
 {
 }
예제 #31
0
 public Span(Inline childInline, TextPointer insertionPosition)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Documents.Underline" /> class, taking a specified <see cref="T:System.Windows.Documents.Inline" /> object as the initial contents of the new <see cref="T:System.Windows.Documents.Underline" />.</summary>
 /// <param name="childInline">An <see cref="T:System.Windows.Documents.Inline" /> object specifying the initial contents of the new <see cref="T:System.Windows.Documents.Underline" />.</param>
 // Token: 0x06003EE9 RID: 16105 RVA: 0x000C4509 File Offset: 0x000C2709
 public Underline(Inline childInline) : base(childInline)
 {
 }
예제 #33
0
 public Paragraph(Inline inline)
 {
     Contract.Ensures(0 <= this.Inlines.Count);
 }
 private void AddElementToCollection(Inline elm, InlineCollection coll)
 {
     if (elm is InlineParaGraph)
     {
         //coll.Add(new LineBreak());
         coll.Add(new LineBreak());
     }
     else if (elm is Table)
     {
         coll.Add(new LineBreak());
     }
     else
         coll.Add(elm);
 }
 public Bold(Inline childInline)
 {
 }
 public Bold(Inline childInline, TextPointer insertionPosition)
 {
 }
 public Underline(Inline childInline, TextPointer insertionPosition)
 {
 }
 public Underline(Inline childInline)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Documents.Hyperlink" /> class, taking a specified <see cref="T:System.Windows.Documents.Inline" /> object as the initial contents of the new <see cref="T:System.Windows.Documents.Hyperlink" />.</summary>
 /// <param name="childInline">An <see cref="T:System.Windows.Documents.Inline" /> object specifying the initial contents of the new <see cref="T:System.Windows.Documents.Hyperlink" />.</param>
 // Token: 0x0600301D RID: 12317 RVA: 0x000D89F6 File Offset: 0x000D6BF6
 public Hyperlink(Inline childInline) : base(childInline)
 {
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Documents.Hyperlink" /> class, taking a specified <see cref="T:System.Windows.Documents.Inline" /> object as the initial contents of the new <see cref="T:System.Windows.Documents.Hyperlink" />, and a <see cref="T:System.Windows.Documents.TextPointer" /> specifying an insertion position for the new <see cref="T:System.Windows.Documents.Hyperlink" />.</summary>
 /// <param name="childInline">An <see cref="T:System.Windows.Documents.Inline" /> object specifying the initial contents of the new <see cref="T:System.Windows.Documents.Hyperlink" />.  This parameter may be <see langword="null" />, in which case no <see cref="T:System.Windows.Documents.Inline" /> is inserted.</param>
 /// <param name="insertionPosition">A <see cref="T:System.Windows.Documents.TextPointer" /> specifying an insertion position at which to insert the <see cref="T:System.Windows.Documents.Hyperlink" /> element after it is created, or <see langword="null" /> for no automatic insertion.</param>
 // Token: 0x0600301E RID: 12318 RVA: 0x000D8A06 File Offset: 0x000D6C06
 public Hyperlink(Inline childInline, TextPointer insertionPosition) : base(childInline, insertionPosition)
 {
 }
예제 #41
0
        private static string GetStringFromInline(Inline currentInline)
        {
            var lineBreak = currentInline as LineBreak;
            if (lineBreak != null)
            {
                return Environment.NewLine;
            }

            var run = currentInline as Run;
            if (run == null)
            {
                return null;
            }

            return run.Text;
        }
 public Hyperlink(Inline childInline)
 {
 }