Exemplo n.º 1
0
		// Remove InlineObjectRun.Element from TextLayer.
		// Caller of RemoveInlineObjectRun will remove it from inlineObjects collection.
		void RemoveInlineObjectRun(InlineObjectRun ior)
		{
			if (ior.Element.IsKeyboardFocusWithin) {
				// When the inline element that has the focus is removed, WPF will reset the
				// focus to the main window without raising appropriate LostKeyboardFocus events.
				// To work around this, we manually set focus to the next focusable parent.
				UIElement element = textView;
				while (element != null && !element.Focusable) {
					element = VisualTreeHelper.GetParent(element) as UIElement;
				}
				if (element != null)
					Keyboard.Focus(element);
			}
			ior.VisualLine = null;
			RemoveVisualChild(ior.Element);
		}
Exemplo n.º 2
0
 public override TextRun GetTextRun(int textSourceCharacterIndex)
 {
     try
     {
         foreach (VisualLineElement element in VisualLine.Elements)
         {
             if (textSourceCharacterIndex >= element.VisualColumn &&
                 textSourceCharacterIndex < element.VisualColumn + element.VisualLength)
             {
                 int     relativeOffset = textSourceCharacterIndex - element.VisualColumn;
                 TextRun run            = element.CreateTextRun(textSourceCharacterIndex, this);
                 if (run == null)
                 {
                     throw new ArgumentNullException(element.GetType().Name + ".CreateTextRun");
                 }
                 if (run.Length == 0)
                 {
                     throw new ArgumentException("The returned TextRun must not have length 0.", element.GetType().Name + ".Length");
                 }
                 if (relativeOffset + run.Length > element.VisualLength)
                 {
                     throw new ArgumentException("The returned TextRun is too long.", element.GetType().Name + ".CreateTextRun");
                 }
                 InlineObjectRun inlineRun = run as InlineObjectRun;
                 if (inlineRun != null)
                 {
                     inlineRun.VisualLine        = VisualLine;
                     VisualLine.hasInlineObjects = true;
                     TextView.AddInlineObject(inlineRun);
                 }
                 return(run);
             }
         }
         if (TextView.Options.ShowEndOfLine && textSourceCharacterIndex == VisualLine.VisualLength)
         {
             return(CreateTextRunForNewLine());
         }
         return(new TextEndOfParagraph(1));
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 3
0
 // Remove InlineObjectRun.Element from TextLayer.
 // Caller of RemoveInlineObjectRun will remove it from inlineObjects collection.
 void RemoveInlineObjectRun(InlineObjectRun ior)
 {
     if (ior.Element.IsKeyboardFocusWithin)
     {
         // When the inline element that has the focus is removed, WPF will reset the
         // focus to the main window without raising appropriate LostKeyboardFocus events.
         // To work around this, we manually set focus to the next focusable parent.
         UIElement element = textView;
         while (element != null && !element.Focusable)
         {
             element = VisualTreeHelper.GetParent(element) as UIElement;
         }
         if (element != null)
         {
             Keyboard.Focus(element);
         }
     }
     ior.VisualLine = null;
     RemoveVisualChild(ior.Element);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a new inline object.
 /// </summary>
 internal void AddInlineObject(InlineObjectRun inlineObject)
 {
     inlineObjects.Add(inlineObject);
     AddVisualChild(inlineObject.Element);
     inlineObject.Element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds a new inline object.
 /// </summary>
 internal void AddInlineObject(InlineObjectRun inlineObject)
 {
     inlineObjects.Add(inlineObject);
     AddVisualChild(inlineObject.Element);
     inlineObject.Element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
 }