// Token: 0x06003AE2 RID: 15074 RVA: 0x0010A43B File Offset: 0x0010863B
 internal virtual void SetXmlVirtual(TextElement fragment)
 {
     if (!this.IsTableCellRange)
     {
         TextRangeSerialization.PasteXml(this, fragment);
     }
 }
예제 #2
0
        /// <summary>
        /// Saves the content of the range in the given stream as a WPF payload.
        /// </summary>
        /// <param name="range">
        /// The range whose content is to be serialized.
        /// </param>
        /// <param name="stream">
        /// When the stream is not null, it is a request to unconditionally
        /// creatte WPF package in this stream.
        /// If this parameter is null, then the package is created
        /// only when necessary - when there are images in the range.
        /// The new MemoryStream is created in this case and assigned to this
        /// parameter on exit.
        /// </param>
        /// <param name="useFlowDocumentAsRoot">
        /// </param>
        /// <param name="preserveTextElements">
        /// If set false, custom TextElements will be upcasted to known types.
        /// </param>
        /// <returns>
        /// A xaml part of serialized content.
        /// </returns>
        internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            // Create the wpf package in the stream
            WpfPayload wpfPayload = new WpfPayload(/*package:*/ null);

            // Create a string representing serialized xaml
            StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

            TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements);
            string xamlText = stringWriter.ToString();

            // Decide whether we need to create a package
            if (stream != null || wpfPayload._images != null)
            {
                // There are images in the content. Need to create a package
                if (stream == null)
                {
                    stream = new MemoryStream();
                }

                // Create a package in the stream
                using (wpfPayload.CreatePackage(stream))
                {
                    // Create the entry part for xaml content of the WPF package
                    PackagePart xamlEntryPart = wpfPayload.CreateWpfEntryPart();

                    // Write the part's content
                    Stream xamlPartStream = xamlEntryPart.GetStream();
                    using (xamlPartStream)
                    {
                        StreamWriter xamlPartWriter = new StreamWriter(xamlPartStream);
                        using (xamlPartWriter)
                        {
                            xamlPartWriter.Write(xamlText);
                        }
                    }

                    // Write relationships from xaml entry part to all images
                    wpfPayload.CreateComponentParts(xamlEntryPart);
                }

                Invariant.Assert(wpfPayload._images == null); // must have beed cleared in CreateComponentParts
            }

            return(xamlText);
        }
예제 #3
0
        // Token: 0x06003F1E RID: 16158 RVA: 0x0012055C File Offset: 0x0011E75C
        internal static string SaveRange(ITextRange range, ref Stream stream, bool useFlowDocumentAsRoot, bool preserveTextElements)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }
            WpfPayload    wpfPayload   = new WpfPayload(null);
            StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

            TextRangeSerialization.WriteXaml(xmlWriter, range, useFlowDocumentAsRoot, wpfPayload, preserveTextElements);
            string text = stringWriter.ToString();

            if (stream != null || wpfPayload._images != null)
            {
                if (stream == null)
                {
                    stream = new MemoryStream();
                }
                using (wpfPayload.CreatePackage(stream))
                {
                    PackagePart packagePart = wpfPayload.CreateWpfEntryPart();
                    Stream      stream2     = packagePart.GetStream();
                    using (stream2)
                    {
                        StreamWriter streamWriter = new StreamWriter(stream2);
                        using (streamWriter)
                        {
                            streamWriter.Write(text);
                        }
                    }
                    wpfPayload.CreateComponentParts(packagePart);
                }
                Invariant.Assert(wpfPayload._images == null);
            }
            return(text);
        }
예제 #4
0
        /// <summary>
        /// Creates DataObject for Copy and Drag operations
        /// </summary>
        internal static DataObject _CreateDataObject(TextEditor This, bool isDragDrop)
        {
            DataObject dataObject;

            // Create the data object for drag and drop.
            //  We could provide more extensibility here -
            // by allowing application to create its own DataObject.
            // Without it our extensibility looks inconsistent:
            // the interface IDataObject suggests that you can
            // create your own implementation of it, but you
            // really cannot, because there is no way of
            // using it in our TextEditor.Copy/Drag.
            dataObject = new DataObject();

            // Get plain text and copy it into the data object.
            string textString = This.Selection.Text;

            if (textString != String.Empty)
            {
                // Copy plain text into data object.
                // ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
                if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Text))
                {
                    dataObject.SetData(DataFormats.Text, textString, false);
                }

                // Copy unicode text into data object.
                // ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
                if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.UnicodeText))
                {
                    dataObject.SetData(DataFormats.UnicodeText, textString, false);
                }
            }

            // Get the rtf and xaml text and then copy it into the data object after confirm data format.
            // We do this only if our content is rich
            if (This.AcceptsRichContent)
            {
                Stream wpfContainerMemory = null;
                // null wpfContainerMemory on entry means that container is optional
                // and will be not created when there is no images in the range.

                // Create in-memory wpf package, and serialize the content of selection into it
                string xamlTextWithImages = WpfPayload.SaveRange(This.Selection, ref wpfContainerMemory, /*useFlowDocumentAsRoot:*/ false);

                if (xamlTextWithImages.Length > 0)
                {
                    // ConfirmDataFormatSetting raises a public event - could throw recoverable exception.
                    if (wpfContainerMemory != null && ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.XamlPackage))
                    {
                        dataObject.SetData(DataFormats.XamlPackage, wpfContainerMemory);
                    }

                    // ConfirmDataFormatSetting raises a public event - could throw recoverable exception.
                    if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Rtf))
                    {
                        // Convert xaml to rtf text to set rtf data into data object.
                        string rtfText = ConvertXamlToRtf(xamlTextWithImages, wpfContainerMemory);

                        if (rtfText != String.Empty)
                        {
                            dataObject.SetData(DataFormats.Rtf, rtfText, true);
                        }
                    }

                    // Add a CF_BITMAP if we have only one image selected.
                    Image image = This.Selection.GetUIElementSelected() as Image;
                    if (image != null && image.Source is System.Windows.Media.Imaging.BitmapSource)
                    {
                        dataObject.SetImage((System.Windows.Media.Imaging.BitmapSource)image.Source);
                    }
                }

                // Xaml format is availabe both in Full Trust and in Partial Trust
                // Need to re-serialize xaml to avoid image references within a container:
                StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);
                TextRangeSerialization.WriteXaml(xmlWriter, This.Selection, /*useFlowDocumentAsRoot:*/ false, /*wpfPayload:*/ null);
                string xamlText = stringWriter.ToString();
                //  Use WpfPayload.SaveRangeAsXaml method to produce correct image.Source properties.

                if (xamlText.Length > 0)
                {
                    // ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
                    if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Xaml))
                    {
                        // Place Xaml data onto the dataobject using safe setter
                        dataObject.SetData(DataFormats.Xaml, xamlText, false);
                    }
                }
            }

            // Notify application about our data object preparation completion
            DataObjectCopyingEventArgs dataObjectCopyingEventArgs = new DataObjectCopyingEventArgs(dataObject, /*isDragDrop:*/ isDragDrop);

            This.UiScope.RaiseEvent(dataObjectCopyingEventArgs);
            if (dataObjectCopyingEventArgs.CommandCancelled)
            {
                dataObject = null;
            }

            return(dataObject);
        }
        internal static DataObject _CreateDataObject(TextEditor This, bool isDragDrop)
        {
            new UIPermission(UIPermissionClipboard.AllClipboard).Assert();
            DataObject dataObject;

            try
            {
                dataObject = new DataObject();
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            string text = This.Selection.Text;

            if (text != string.Empty)
            {
                if (TextEditorCopyPaste.ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Text))
                {
                    TextEditorCopyPaste.CriticalSetDataWrapper(dataObject, DataFormats.Text, text);
                }
                if (TextEditorCopyPaste.ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.UnicodeText))
                {
                    TextEditorCopyPaste.CriticalSetDataWrapper(dataObject, DataFormats.UnicodeText, text);
                }
            }
            if (This.AcceptsRichContent)
            {
                if (SecurityHelper.CheckUnmanagedCodePermission())
                {
                    Stream stream = null;
                    string text2  = WpfPayload.SaveRange(This.Selection, ref stream, false);
                    if (text2.Length > 0)
                    {
                        if (stream != null && TextEditorCopyPaste.ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.XamlPackage))
                        {
                            dataObject.SetData(DataFormats.XamlPackage, stream);
                        }
                        if (TextEditorCopyPaste.ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Rtf))
                        {
                            string text3 = TextEditorCopyPaste.ConvertXamlToRtf(text2, stream);
                            if (text3 != string.Empty)
                            {
                                dataObject.SetData(DataFormats.Rtf, text3, true);
                            }
                        }
                    }
                    Image image = This.Selection.GetUIElementSelected() as Image;
                    if (image != null && image.Source is BitmapSource)
                    {
                        dataObject.SetImage((BitmapSource)image.Source);
                    }
                }
                StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);
                TextRangeSerialization.WriteXaml(xmlWriter, This.Selection, false, null);
                string text4 = stringWriter.ToString();
                if (text4.Length > 0 && TextEditorCopyPaste.ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Xaml))
                {
                    TextEditorCopyPaste.CriticalSetDataWrapper(dataObject, DataFormats.Xaml, text4);
                    PermissionSet permissionSet = SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin();
                    string        content       = permissionSet.ToString();
                    TextEditorCopyPaste.CriticalSetDataWrapper(dataObject, DataFormats.ApplicationTrust, content);
                }
            }
            DataObjectCopyingEventArgs dataObjectCopyingEventArgs = new DataObjectCopyingEventArgs(dataObject, isDragDrop);

            This.UiScope.RaiseEvent(dataObjectCopyingEventArgs);
            if (dataObjectCopyingEventArgs.CommandCancelled)
            {
                dataObject = null;
            }
            return(dataObject);
        }
예제 #6
0
        internal static DataObject _CreateDataObject(TextEditor This, bool isDragDrop)
        {
            DataObject dataObject;

            // Create the data object for drag and drop.
            //



            (new UIPermission(UIPermissionClipboard.AllClipboard)).Assert();//BlessedAssert
            try
            {
                dataObject = new DataObject();
            }
            finally
            {
                UIPermission.RevertAssert();
            }

            // Get plain text and copy it into the data object.
            string textString = This.Selection.Text;

            if (textString != String.Empty)
            {
                // Copy plain text into data object.
                // ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
                if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Text))
                {
                    CriticalSetDataWrapper(dataObject, DataFormats.Text, textString);
                }

                // Copy unicode text into data object.
                // ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
                if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.UnicodeText))
                {
                    CriticalSetDataWrapper(dataObject, DataFormats.UnicodeText, textString);
                }
            }

            // Get the rtf and xaml text and then copy it into the data object after confirm data format.
            // We do this only if our content is rich
            if (This.AcceptsRichContent)
            {
                // This ensures that in the confines of partial trust RTF is not enabled.
                // We use unmanaged code permission over clipboard permission since
                // the latter is available in intranet zone and this is something that will
                // fail in intranet too.
                if (SecurityHelper.CheckUnmanagedCodePermission())
                {
                    // In FullTrust we allow all rich formats on the clipboard

                    Stream wpfContainerMemory = null;
                    // null wpfContainerMemory on entry means that container is optional
                    // and will be not created when there is no images in the range.

                    // Create in-memory wpf package, and serialize the content of selection into it
                    string xamlTextWithImages = WpfPayload.SaveRange(This.Selection, ref wpfContainerMemory, /*useFlowDocumentAsRoot:*/ false);

                    if (xamlTextWithImages.Length > 0)
                    {
                        // ConfirmDataFormatSetting raises a public event - could throw recoverable exception.
                        if (wpfContainerMemory != null && ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.XamlPackage))
                        {
                            dataObject.SetData(DataFormats.XamlPackage, wpfContainerMemory);
                        }

                        // ConfirmDataFormatSetting raises a public event - could throw recoverable exception.
                        if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Rtf))
                        {
                            // Convert xaml to rtf text to set rtf data into data object.
                            string rtfText = ConvertXamlToRtf(xamlTextWithImages, wpfContainerMemory);

                            if (rtfText != String.Empty)
                            {
                                dataObject.SetData(DataFormats.Rtf, rtfText, true);
                            }
                        }
                    }

                    // Add a CF_BITMAP if we have only one image selected.
                    Image image = This.Selection.GetUIElementSelected() as Image;
                    if (image != null && image.Source is System.Windows.Media.Imaging.BitmapSource)
                    {
                        dataObject.SetImage((System.Windows.Media.Imaging.BitmapSource)image.Source);
                    }
                }

                // Xaml format is availabe both in Full Trust and in Partial Trust
                // Need to re-serialize xaml to avoid image references within a container:
                StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);
                TextRangeSerialization.WriteXaml(xmlWriter, This.Selection, /*useFlowDocumentAsRoot:*/ false, /*wpfPayload:*/ null);
                string xamlText = stringWriter.ToString();
                //

                if (xamlText.Length > 0)
                {
                    // ConfirmDataFormatSetting rasies a public event - could throw recoverable exception.
                    if (ConfirmDataFormatSetting(This.UiScope, dataObject, DataFormats.Xaml))
                    {
                        // Place Xaml data onto the dataobject using safe setter
                        CriticalSetDataWrapper(dataObject, DataFormats.Xaml, xamlText);

                        // The dataobject itself must hold an information about permission set
                        // of the source appdomain. Set it there:

                        // Package permission set for the current appdomain
                        PermissionSet psCurrentAppDomain            = SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin();
                        string        permissionSetCurrentAppDomain = psCurrentAppDomain.ToString();
                        CriticalSetDataWrapper(dataObject, DataFormats.ApplicationTrust, permissionSetCurrentAppDomain);
                    }
                }
            }

            // Notify application about our data object preparation completion
            DataObjectCopyingEventArgs dataObjectCopyingEventArgs = new DataObjectCopyingEventArgs(dataObject, /*isDragDrop:*/ isDragDrop);

            This.UiScope.RaiseEvent(dataObjectCopyingEventArgs);
            if (dataObjectCopyingEventArgs.CommandCancelled)
            {
                dataObject = null;
            }

            return(dataObject);
        }