Completed
Last Updated: 31 Mar 2015 06:51 by ADMIN
ADMIN
Stefan
Created on: 24 Dec 2014 10:47
Category: RichTextEditor
Type: Bug Report
1
FIX. RadRichTextEditor - pasting link, copied from outlook causes exception
Description and workaround:
It appears that Outlook produces different RTF contents when using its different Copy commands. In some cases the RTF string produced by Outlook contains empty spans which is not a valid element in our implementation. To handle that case, you can subscribe to the CommandExecuting event to capture the Paste command before it was executed, strip the empty spans, and then modify the clipboard contents with a valid RTF string. 

Additionally, when you try to delete the text of pasted hyperlinks using backspace, an exception will be thrown at some point (for example, after pasting the link \\server\folder1\somefile.txt and deleting the dot).

The following code snippet demonstrates how to handle deleting pasted links:
        Private Sub radRichTextEditor1_CommandExecuting(sender As Object, e As CommandExecutingEventArgs) Handles radRichTextEditor1.CommandExecuting
             If TypeOf e.Command Is DeleteCommand 
                Me.RadRichTextEditor1.RichTextBoxElement.InvalidateMeasure(true)
                Me.RadRichTextEditor1.RichTextBoxElement.UpdateLayout()
            End If
        End Sub

The following code snippet demonstrates how to handle removing empty spans:

Private Sub radRichTextEditor1_CommandExecuting(sender As Object, e As CommandExecutingEventArgs) Handles radRichTextEditor1.CommandExecuting
    If Not (TypeOf e.Command Is PasteCommand) Then
        Return
    End If
  
    Dim docString As String = Nothing
    Dim docObj As Object = Clipboard.GetData("Rich Text Format")
  
    If docObj IsNot Nothing AndAlso docObj.[GetType]() = GetType(String) Then
        docString = DirectCast(docObj, String)
    End If
  
    Dim document As RadDocument = Nothing
    Using stream As New MemoryStream()
        Dim writer As New StreamWriter(stream)
        writer.Write(docString)
        writer.Flush()
        stream.Seek(0, SeekOrigin.Begin)
        Try
            document = New RtfFormatProvider().Import(stream)
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine("Error reading document from clipboard:" & vbLf + ex.ToString())
        End Try
    End Using
  
    If document IsNot Nothing Then
        Dim emptySpans As New List(Of Span)()
        For Each span As var In document.EnumerateChildrenOfType(Of Span)()
            If [String].IsNullOrEmpty(span.Text) Then
                emptySpans.Add(span)
            End If
        Next
  
        If emptySpans.Count = 0 Then
            Return
        End If
  
        For Each span As var In emptySpans
            span.Parent.Children.Remove(span)
        Next
  
        Dim modifiedRtf As String = New RtfFormatProvider().Export(document)
  
        Clipboard.SetData("Rich Text Format", modifiedRtf)
    End If
End Sub
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
5 comments
ADMIN
Ivan Todorov
Posted on: 27 Feb 2015 09:25
Hi Darren,
We are already aware of this (Michael has reported it) and threfore the item was reopened. The description was updated with the workaround - handling the DeleteCommand. This will be addressed in the service pack which is expected at the beginning of April.
Darren
Posted on: 26 Feb 2015 22:51
When I used the fix for the error with backspace, I received the following exception, and the text area turns into a large red X.

************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Telerik.WinControls.RichTextEditor.UI.TextBlock.DrawRunGDI(Run run, RunLayoutInfo runInfo, Single fontSizeScale, PointF location, NativeTextRenderer renderer)
   at Telerik.WinControls.RichTextEditor.UI.TextBlock.DrawGdi(Single angle, Graphics nativeGraphics, Single fontSizeScale)
   at Telerik.WinControls.RichTextEditor.UI.TextBlock.PaintElement(IGraphics graphics, Single angle, SizeF scale)
   at Telerik.WinControls.RadElement.DoOwnPaint(IGraphics graphics, Single angle, SizeF scale)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChild(RadElement child, IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at Telerik.WinControls.UI.RadRichTextEditor.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Attached Files:
Michael
Posted on: 25 Feb 2015 19:42
I've updated to UI for WinForms Q1 2015 and this is still broken.  Once while pasting it looked like it might work but the text display became very corrupted with letters overlapping each other and then it still crashed.

Very easy to duplicate.  Type this test in Outlook 2013 and press enter so it makes it a hyperlink:
\\server\file1\file2\file3\file4]file5.txt

Copy the link (control + c or right click or control + insert, doesn't matter) and paste into the control (control + v or right click, doesn't matter (side note: why doesn't shift + insert doesn't work as paste in this control?))

Click anywhere in the link text and start typing backspace.  It will crash, always.  Depending on where you start, you'll get to hit backspace a couple of times before it crashes: when you do, you'll see the text formatting get screwed up with characters overwriting each other.

Can this ticket be re-opened?  It is not fixed.
ADMIN
Ivan Todorov
Posted on: 09 Feb 2015 12:42
Hi Darren,
Basically, when you copy something from outlook, it puts to the clipboard the content encoded in the RTF format. How exactly will the content look like depends on the internal implementation of Outlook and it might be different across different Outlook versions. Can you please confirm which version of Outlook are you using (I've been testing this with Outlook 2013). On my end there is always one empty span when pasting. Additionally, on my end the event from the workaround fires in both cases (either using ctrl+V or the context menu). As there seem to be a few inconsistencies, it would be best if you could send us the sample project you are using for testing. You can do this in the original ticket related to this item. 
Darren
Posted on: 04 Feb 2015 22:44
The event in this workaround doesn't seem to fire if the context menu is used. If Ctrl-V is used, it fires but the same error is still occurring. I walked through the event in debug, and there does not appear to be any blank spans in document.EnumeratedChildrenOfType(Of Span). Is there possibly another very similar problem that may be occurring when pasting a hyperlink from Outlook?