• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Documents.TextEditor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Windows.Documents.TextEditor的典型用法代码示例。如果您正苦于以下问题:C# TextEditor类的具体用法?C# TextEditor怎么用?C# TextEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TextEditor类属于System.Windows.Documents命名空间,在下文中一共展示了TextEditor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CaretElement

        //-----------------------------------------------------
        // 
        //  Constructors
        //
        //-----------------------------------------------------
 
        #region Constructors
 
        /// <summary> 
        /// Creates new instance of CaretElement.
        /// </summary> 
        /// <param name="textEditor">
        /// TextEditor that owns this Adorner.
        /// </param>
        /// <param name="isBlinkEnabled"> 
        /// Blinking for caret animation. Drag target caret does not need blinking,
        /// </param> 
        internal CaretElement(TextEditor textEditor, bool isBlinkEnabled) : base(textEditor.TextView.RenderScope) 
        {
            Invariant.Assert(textEditor.TextView != null && textEditor.TextView.RenderScope != null, "Assert: textView != null && RenderScope != null"); 

            _textEditor = textEditor;

            // Set the animation whether do it or not. 
            _isBlinkEnabled = isBlinkEnabled;
 
            // caret position 
            _left = 0.0;
            _top = 0.0; 

            // caret dimensions
            _systemCaretWidth = SystemParameters.CaretWidth;
            _height = 0.0; 

            // Set AllowDropProperty as "False" not to inherit the value from the ancestor. 
            AllowDrop = false; 

            _caretElement = new CaretSubElement(); 
            _caretElement.ClipToBounds = false;

            AddVisualChild(_caretElement);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:42,代码来源:CaretElement.cs


示例2: _OnApplyProperty

        internal static void _OnApplyProperty(TextEditor This, DependencyProperty formattingProperty, object propertyValue, bool applyToParagraphs, PropertyValueAction propertyValueAction)
        {
            if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection))
            {
                return;
            }

            // Check whether the property is known
            if (!TextSchema.IsParagraphProperty(formattingProperty) && !TextSchema.IsCharacterProperty(formattingProperty))
            {
                Invariant.Assert(false, "The property '" + formattingProperty.Name + "' is unknown to TextEditor");
                return;
            }

            TextSelection selection = (TextSelection)This.Selection;

            if (TextSchema.IsStructuralCharacterProperty(formattingProperty) &&
                !TextRangeEdit.CanApplyStructuralInlineProperty(selection.Start, selection.End))
            {
                // Ignore structural commands fires in inappropriate context.
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            // Forget previously suggested horizontal position
            TextEditorSelection._ClearSuggestedX(This);

            // Break merged typing sequence
            TextEditorTyping._BreakTypingSequence(This);

            // Apply property
            selection.ApplyPropertyValue(formattingProperty, propertyValue, applyToParagraphs, propertyValueAction);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:34,代码来源:TextEditorCharacters.cs


示例3: CreateFlowDocumentForEditor

		/// <summary>
		/// Creates a flow document from the editor's contents.
		/// </summary>
		public static FlowDocument CreateFlowDocumentForEditor(TextEditor editor)
		{
			IHighlighter highlighter = editor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
			FlowDocument doc = new FlowDocument(ConvertTextDocumentToBlock(editor.Document, highlighter));
			doc.FontFamily = editor.FontFamily;
			doc.FontSize = editor.FontSize;
			return doc;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:11,代码来源:DocumentPrinter.cs


示例4: SetCaretPositionOnMouseEvent

        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Sets the caret in response to a mouse down or mouse up event.
        internal static void SetCaretPositionOnMouseEvent(TextEditor This, Point mouseDownPoint, MouseButton changedButton, int clickCount)
        {
            // Get the character position of the mouse event.
            ITextPointer cursorPosition = This.TextView.GetTextPositionFromPoint(mouseDownPoint, /*snapToText:*/true);

            if (cursorPosition == null)
            {
                // Cursor is between pages in a document viewer.
                MoveFocusToUiScope(This);
                return;
            }

            // Forget previously suggested horizontal position
            TextEditorSelection._ClearSuggestedX(This);

            // Discard typing undo unit merging
            TextEditorTyping._BreakTypingSequence(This);

            // Clear springload formatting
            if (This.Selection is TextSelection)
            {
                ((TextSelection)This.Selection).ClearSpringloadFormatting();
            }

            // Clear flags for forcing word and paragraphexpansion
            // (which should be true only in case of doubleClick+drag or tripleClick+drag)
            This._forceWordSelection = false;
            This._forceParagraphSelection = false;

            if (changedButton == MouseButton.Right || clickCount == 1)
            {
                // If mouse clicked within selection enter dragging mode, otherwise start building a selection
                if (changedButton != MouseButton.Left || !This._dragDropProcess.SourceOnMouseLeftButtonDown(mouseDownPoint))
                {
                    // Mouse down happend outside of current selection
                    // so position the selection at the clicked location.
                    This.Selection.SetSelectionByMouse(cursorPosition, mouseDownPoint);
                }
            }
            else if (clickCount == 2 && (Keyboard.Modifiers & ModifierKeys.Shift) == 0 && This.Selection.IsEmpty)
            {
                // Double click only works when Shift is not pressed
                This._forceWordSelection = true;
                This._forceParagraphSelection = false;
                This.Selection.SelectWord(cursorPosition);
            }
            else if (clickCount == 3 && (Keyboard.Modifiers & ModifierKeys.Shift) == 0)
            {
                // Triple click only works when Shift is not pressed
                if (This.AcceptsRichContent)
                {
                    This._forceParagraphSelection = true;
                    This._forceWordSelection = false;
                    This.Selection.SelectParagraph(cursorPosition);
                }
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:66,代码来源:TextEditorMouse.cs


示例5: GetSpellingErrorAtSelection

        // Returns the error (if any) at the current selection.
        internal static SpellingError GetSpellingErrorAtSelection(TextEditor This)
        {
            if (This.Speller == null)
            {
                return null;
            }

            if (IsSelectionIgnoringErrors(This.Selection))
            {
                // Some selection (large ones in particular) ignore errors.
                return null;
            }

            // If the selection is empty, we want to respect its direction
            // when poking around for spelling errors.
            // If it's non-empty, the selection start direction is always
            // backward, which is the opposite of what we want.
            LogicalDirection direction = This.Selection.IsEmpty ? This.Selection.Start.LogicalDirection : LogicalDirection.Forward;

            char character;
            ITextPointer position = GetNextTextPosition(This.Selection.Start, null /* limit */, direction, out character);
            if (position == null)
            {
                // There is no next character -- flip direction.
                // This is the end-of-document or end-of-paragraph case.
                direction = (direction == LogicalDirection.Forward) ? LogicalDirection.Backward : LogicalDirection.Forward;
                position = GetNextTextPosition(This.Selection.Start, null /* limit */, direction, out character);
            }
            else if (Char.IsWhiteSpace(character))
            {
                // If direction points to whitespace
                //   If the selection is empty
                //     Look in the opposite direction.
                //   Else
                //     If the selection contains non-white space
                //       Look at the first non-white space character forward.
                //     Else
                //       Look in the opposite direction.
                if (This.Selection.IsEmpty)
                {
                    direction = (direction == LogicalDirection.Forward) ? LogicalDirection.Backward : LogicalDirection.Forward;
                    position = GetNextTextPosition(This.Selection.Start, null /* limit */, direction, out character);
                }
                else
                {
                    direction = LogicalDirection.Forward;
                    position = GetNextNonWhiteSpacePosition(This.Selection.Start, This.Selection.End);
                    if (position == null)
                    {
                        direction = LogicalDirection.Backward;
                        position = GetNextTextPosition(This.Selection.Start, null /* limit */, direction, out character);
                    }
                }
            }

            return (position == null) ? null : This.Speller.GetError(position, direction, false /* forceEvaluation */);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:58,代码来源:TextEditorSpelling.cs


示例6: CopyEditorSettings

		public void CopyEditorSettings(TextEditor source)
		{
			string language = source.SyntaxHighlighting != null ? source.SyntaxHighlighting.Name : null;
			editor.TextArea.TextView.LineTransformers.RemoveWhere(x => x is HighlightingColorizer);
			editor.TextArea.TextView.LineTransformers.Insert(0, new CustomizableHighlightingColorizer(source.SyntaxHighlighting.MainRuleSet, CustomizedHighlightingColor.FetchCustomizations(language)));
			CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(editor, CustomizedHighlightingColor.FetchCustomizations(language));
			HighlightingOptions.ApplyToRendering(editor, CustomizedHighlightingColor.FetchCustomizations(language));
			editor.TextArea.TextView.Redraw(); // manually redraw if default elements didn't change but customized highlightings did
		}
开发者ID:rbrunhuber,项目名称:SharpDevelop,代码行数:9,代码来源:DiffControl.xaml.cs


示例7: DecreaseIndentation

        // Decreases the indent level of the Block at selection start. 
        internal static void DecreaseIndentation(TextEditor This)
        {
            TextSelection thisSelection = (TextSelection)This.Selection;
 
            ListItem parentListItem = TextPointerBase.GetListItem(thisSelection.Start);
            ListItem immediateListItem = TextPointerBase.GetImmediateListItem(thisSelection.Start); 
 
            DecreaseIndentation(thisSelection, parentListItem, immediateListItem);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:10,代码来源:TextEditorLists.cs


示例8: EditorHelper

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="t"></param>
 public EditorHelper(TextEditor t)
 {
     textEditor = t;
     t.KeyUp += OnKeyUp;
     CanEat = new bool[ 10 ];
     for ( int i = 0; i < 10; i++ )
     {
         CanEat[ i ] = false;
     }
 }
开发者ID:g4idrijs,项目名称:UltraDemo,代码行数:14,代码来源:EditorHelper.cs


示例9: TextStore

        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        // Creates a new TextStore instance.
        // The interesting initialization is in Attach/Detach.
        internal TextStore(TextEditor textEditor)
        {
            // We have only weak reference to TextEditor so it is free to be GCed.
            _weakTextEditor = new ScopeWeakReference(textEditor);

            // initialize Cookies.
            _threadFocusCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            _editSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            _editCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
            _transitoryExtensionSinkCookie = UnsafeNativeMethods.TF_INVALID_COOKIE;
        }
开发者ID:mind0n,项目名称:hive,代码行数:21,代码来源:TextStore.cs


示例10: EnhancedScrollBar

		public EnhancedScrollBar(TextEditor editor, TextMarkerService textMarkerService, IChangeWatcher changeWatcher)
		{
			if (editor == null)
				throw new ArgumentNullException("editor");
			this.editor = editor;
			this.textMarkerService = textMarkerService;
			this.changeWatcher = changeWatcher;
			
			editor.Loaded += editor_Loaded;
			if (editor.IsLoaded) {
				editor_Loaded(null, null);
			}
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:13,代码来源:EnhancedScrollBar.cs


示例11: BreakPointMargin

        public BreakPointMargin(TextEditor TxEditor)
        {
            this.TxEditor = TxEditor;
            BreakPointList = new List<int>();
            this.HorizontalAlignment = HorizontalAlignment.Left;
            this.VerticalAlignment = VerticalAlignment.Top;
            this.TxEditor.TextArea.TextView.VisualLinesChanged += OnVisualLinesChanged;
            this.RenderSize = new System.Windows.Size( 20, 100 );

            this.Height = 500;
            this.Width = 20;

            this.Background = Brushes.Silver;
        }
开发者ID:g4idrijs,项目名称:UltraDemo,代码行数:14,代码来源:BreakPointMargin.cs


示例12: Speller

        //-----------------------------------------------------
        //
        //  Constructors 
        //
        //----------------------------------------------------- 
 
        #region Constructors
 
        // Creates a new instance.  We have at most one Speller instance
        // per TextEditor.
        internal Speller(TextEditor textEditor)
        { 
            _textEditor = textEditor;
 
            _textEditor.TextContainer.Change += new TextContainerChangeEventHandler(OnTextContainerChange); 

            // Schedule some idle time to start examining the document. 
            if (_textEditor.TextContainer.SymbolCount > 0)
            {
                ScheduleIdleCallback();
            } 

            _defaultCulture = InputLanguageManager.Current != null ? InputLanguageManager.Current.CurrentInputLanguage : 
                                                                     Thread.CurrentThread.CurrentCulture; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:25,代码来源:Speller.cs


示例13: TextSelection

        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        // Contstructor.
        // TextSelection does not have a public constructor.  It is only accessible
        // through TextEditor's Selection property.
        internal TextSelection(TextEditor textEditor)
            : base(textEditor.TextContainer.Start, textEditor.TextContainer.Start)
        {
            ITextSelection thisSelection = (ITextSelection)this;

            Invariant.Assert(textEditor.UiScope != null);

            // Attach the selection to its editor
            _textEditor = textEditor;

            // Initialize active pointers of the selection - anchor and moving pointers
            SetActivePositions(/*AnchorPosition:*/thisSelection.Start, thisSelection.End);

            // Activate selection in case if this control has keyboard focus already
            thisSelection.UpdateCaretAndHighlight();
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:25,代码来源:TextSelection.cs


示例14: CalculateScrollToOriginPosition

        // Helper for UpdateCaretStateWorker -- Calculate the scroll origin position to scroll caret
        // with the scroll origin position so that we can ensure of displaying caret with the wrapped word.
        //
        // There are four cases of different corrdinate by the flow direction on UiScope and Paragraph.
        // UiScope has two flow direction which is LeftToRightflow directioin and another is RightToLeft.
        // Paragraph has also two flow direction which is LeftToRightflow directioin and another is RightToLeft.
        //
        // The below is the example of how horizontal corrdinate and scroll origin value base on the different
        // four cases. So we have to calculate the scroll to origin position base on the case. Simply we can
        // get the scroll to origin value as zero if UiScope and Paragraph's flow direction is the same.
        // Otherwise, the scroll to origin value is the extent width value that is the max width.
        //
        // <<For instance>>
        //  Case 1.
        //      UiScope FlowDirection:              LTR(LeftToRight)
        //      Paragraph FlowDirection:            LTR(LefTToRight)
        //          Horizontal origin:              "Left"
        //          Scroll horizontal origin:       "0"
        //          Wrapping to:                    "Left"
        //              ABC ......
        //              XYZ|
        //
        //  Case 2.
        //      UiScope FlowDirection:              LTR(LeftToRight)
        //      Paragraph FlowDirection:            RTL(RightToLeft)
        //          Horizontal origin:              "Left"
        //          Scroll horizontal origin:       "Max:Extent Width"
        //          Wrapping to:                    "Right"
        //              ......ABC
        //                    XYZ|
        //
        //  Case 3.
        //      UiScope FlowDirection:              RTL(RightToLeft)
        //      Paragraph FlowDirection:            RTL(RightToLeft)
        //          horizontal origin:              "Right"
        //          Scroll horizontal origin:       "0"
        //          Wrapping to:                    "Right"
        //              ......ABC
        //                    XYZ|
        //
        //  Case 4.
        //      UiScope FlowDirection:              RTL(RightToLeft)
        //      Paragraph FlowDirection:            LTR(LefTToRight)
        //          horizontal origin:              "Right"
        //          Scroll horizontal origin:       "Max:Extent Width"
        //          Wrapping to:                    "Left"
        //              ABC ......
        //              XYZ|
        private static double CalculateScrollToOriginPosition(TextEditor textEditor, ITextPointer caretPosition, double horizontalCaretPosition)
        {
            double scrollToOriginPosition = double.NaN;

            if (textEditor.UiScope is TextBoxBase)
            {
                double viewportWidth = ((TextBoxBase)textEditor.UiScope).ViewportWidth;
                double extentWidth = ((TextBoxBase)textEditor.UiScope).ExtentWidth;

                // Calculate the scroll to the origin position position when the horizontal scroll is available
                if (viewportWidth != 0 && extentWidth != 0 && viewportWidth < extentWidth)
                {
                    bool needScrollToOriginPosition = false;

                    // Check whether we need to calculate the scroll origin position to scroll it with the caret
                    // position. If the caret position is out of the current visual viewport area, the scroll
                    // to origin positioin will be calculated to scroll into the origin position first that
                    // ensure of displaying the wrapped word.
                    //
                    // Note that horizontalCaretPosition is always relative to the viewport, not the document.
                    if (horizontalCaretPosition < 0 || horizontalCaretPosition >= viewportWidth)
                    {
                        needScrollToOriginPosition = true;
                    }

                    if (needScrollToOriginPosition)
                    {
                        // Set the scroll original position as zero
                        scrollToOriginPosition = 0;

                        // Get the flow direction of uiScope
                        FlowDirection uiScopeflowDirection = (FlowDirection)textEditor.UiScope.GetValue(FrameworkElement.FlowDirectionProperty);

                        // Get the flow direction of the current paragraph and compare it with uiScope's flow direction.
                        Block paragraphOrBlockUIContainer = (caretPosition is TextPointer) ? ((TextPointer)caretPosition).ParagraphOrBlockUIContainer : null;
                        if (paragraphOrBlockUIContainer != null)
                        {
                            FlowDirection pagraphFlowDirection = paragraphOrBlockUIContainer.FlowDirection;

                            // If the flow direction is different between uiScopoe and paragaph,
                            // the original scroll position is the extent width value.
                            if (uiScopeflowDirection != pagraphFlowDirection)
                            {
                                scrollToOriginPosition = extentWidth;
                            }
                        }

                        // Adjust scroll position by current viewport offset
                        scrollToOriginPosition -= ((TextBoxBase)textEditor.UiScope).HorizontalOffset;
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:TextSelection.cs


示例15: RefreshCaret

        //......................................................
        //
        //  Caret Support
        //
        //......................................................

        // Redraws a caret using current setting for italic - taking springload formatting into account.
        private static void RefreshCaret(TextEditor textEditor, ITextSelection textSelection)
        {
            object fontStylePropertyValue;
            bool italic;

            if (textSelection == null || textSelection.CaretElement == null)
            {
                return;
            }

            // NOTE: We are using GetCurrentValue to take springload formatting into account.
            fontStylePropertyValue = ((TextSelection)textSelection).GetCurrentValue(TextElement.FontStyleProperty);
            italic = (textEditor.AcceptsRichContent && fontStylePropertyValue != DependencyProperty.UnsetValue && (FontStyle)fontStylePropertyValue == FontStyles.Italic);

            textSelection.CaretElement.RefreshCaret(italic);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:23,代码来源:TextSelection.cs


示例16: GetCaretBrush

        // Get the caret brush that is the inverted color from the system window or background color.
        internal static Brush GetCaretBrush(TextEditor textEditor)
        {
            Color backgroundColor;
            ITextSelection focusedTextSelection;
            object backgroundPropertyValue;

            // If TextBoxBase.CaretBrush has been set, use that instead of the default inverting behavior.
            Brush caretBrush = (Brush)textEditor.UiScope.GetValue(TextBoxBase.CaretBrushProperty);
            if (caretBrush != null)
            {
                return caretBrush;
            }

            // Get the default background from the system color or UiScope's background
            backgroundPropertyValue = textEditor.UiScope.GetValue(System.Windows.Controls.Panel.BackgroundProperty);
            if (backgroundPropertyValue != null && backgroundPropertyValue != DependencyProperty.UnsetValue &&
                backgroundPropertyValue is SolidColorBrush)
            {
                backgroundColor = ((SolidColorBrush)backgroundPropertyValue).Color;
            }
            else
            {
                backgroundColor = SystemColors.WindowColor;
            }

            // Get the background color from current selection
            focusedTextSelection = textEditor.Selection;
            if (focusedTextSelection is TextSelection)
            {
                backgroundPropertyValue = ((TextSelection)focusedTextSelection).GetCurrentValue(TextElement.BackgroundProperty);
                if (backgroundPropertyValue != null && backgroundPropertyValue != DependencyProperty.UnsetValue)
                {
                    if (backgroundPropertyValue is SolidColorBrush)
                    {
                        backgroundColor = ((SolidColorBrush)backgroundPropertyValue).Color;
                    }
                }
            }

            // Invert the color to get the caret color from the system window or background color.
            byte r = (byte)~(backgroundColor.R);
            byte g = (byte)~(backgroundColor.G);
            byte b = (byte)~(backgroundColor.B);

            caretBrush = new SolidColorBrush(Color.FromRgb(r, g, b));
            caretBrush.Freeze();
            return caretBrush;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:49,代码来源:TextSelection.cs


示例17: _CreateDataObject

        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.
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:TextEditorCopyPaste.cs


示例18: PasteContentData

        private static bool PasteContentData(TextEditor This, IDataObject dataObject, IDataObject dataObjectToApply, string formatToApply)
        {
            // CF_BITMAP - pasting a single image.
            if (formatToApply == DataFormats.Bitmap && dataObjectToApply is DataObject)
            {
                // This demand is present to explicitly disable RTF independant of any
                // asserts in the confines of partial trust
                // We check unmanaged code instead of all clipboard because in paste
                // there is a high level assert for all clipboard in commandmanager.cs
                if (This.AcceptsRichContent && This.Selection is TextSelection &&
                    SecurityHelper.CheckUnmanagedCodePermission())
                {
                    System.Windows.Media.Imaging.BitmapSource bitmapSource = GetPasteData(dataObjectToApply, DataFormats.Bitmap) as System.Windows.Media.Imaging.BitmapSource;

                    if (bitmapSource != null)
                    {
                        // Pack the image into a WPF container
                        MemoryStream packagedImage = WpfPayload.SaveImage(bitmapSource, WpfPayload.ImageBmpContentType);

                        // Place it onto a data object
                        dataObjectToApply = new DataObject();
                        formatToApply = DataFormats.XamlPackage;
                        dataObjectToApply.SetData(DataFormats.XamlPackage, packagedImage);
                    }
                }
            }

            if (formatToApply == DataFormats.XamlPackage)
            {
                // This demand is present to explicitly disable RTF independant of any
                // asserts in the confines of partial trust
                // We check unmanaged code instead of all clipboard because in paste
                // there is a high level assert for all clipboard in commandmanager.cs
                if (This.AcceptsRichContent && This.Selection is TextSelection &&
                    SecurityHelper.CheckUnmanagedCodePermission())
                {
                    object pastedData = GetPasteData(dataObjectToApply, DataFormats.XamlPackage);

                    MemoryStream pastedMemoryStream = pastedData as MemoryStream;
                    if (pastedMemoryStream != null)
                    {
                        object element = WpfPayload.LoadElement(pastedMemoryStream);
                        if ((element is Section || element is Span) && PasteTextElement(This, (TextElement)element))
                        {
                            return true;
                        }
                        else if (element is FrameworkElement)
                        {
                            ((TextSelection)This.Selection).InsertEmbeddedUIElement((FrameworkElement)element);
                            return true;
                        }
                    }
                }

                // Fall to Xaml:
                dataObjectToApply = dataObject; // go back to source data object
                if (dataObjectToApply.GetDataPresent(DataFormats.Xaml))
                {
                    formatToApply = DataFormats.Xaml;
                }
                else if (SecurityHelper.CheckUnmanagedCodePermission() && dataObjectToApply.GetDataPresent(DataFormats.Rtf))
                {
                    formatToApply = DataFormats.Rtf;
                }
                else if (dataObjectToApply.GetDataPresent(DataFormats.UnicodeText))
                {
                    formatToApply = DataFormats.UnicodeText;
                }
                else if (dataObjectToApply.GetDataPresent(DataFormats.Text))
                {
                    formatToApply = DataFormats.Text;
                }
            }

            if (formatToApply == DataFormats.Xaml)
            {
                if (This.AcceptsRichContent && This.Selection is TextSelection)
                {
                    object pastedData = GetPasteData(dataObjectToApply, DataFormats.Xaml);

                    if (pastedData != null && PasteXaml(This, pastedData.ToString()))
                    {
                        return true;
                    }
                }

                // Fall to Rtf:
                dataObjectToApply = dataObject; // go back to source data object
                if (SecurityHelper.CheckUnmanagedCodePermission() && dataObjectToApply.GetDataPresent(DataFormats.Rtf))
                {
                    formatToApply = DataFormats.Rtf;
                }
                else if (dataObjectToApply.GetDataPresent(DataFormats.UnicodeText))
                {
                    formatToApply = DataFormats.UnicodeText;
                }
                else if (dataObjectToApply.GetDataPresent(DataFormats.Text))
                {
                    formatToApply = DataFormats.Text;
                }
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:TextEditorCopyPaste.cs


示例19: Copy

        internal static void Copy(TextEditor This, bool userInitiated)
        {
            if (userInitiated)
            {
                // Fail silently if the app explicitly denies clipboard access.
                try
                {
                    new UIPermission(UIPermissionClipboard.OwnClipboard).Demand();
                }
                catch (SecurityException)
                {
                    return;
                }
            }
            else if (!SecurityHelper.CallerHasAllClipboardPermission())
            {
                // Fail silently if we don't have clipboard permission.
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            TextEditorTyping._BreakTypingSequence(This);

            if (This.Selection != null && !This.Selection.IsEmpty)
            {
                // Note: _CreateDataObject raises a public event which might throw a recoverable exception.
                DataObject dataObject = TextEditorCopyPaste._CreateDataObject(This, /*isDragDrop:*/false);

                if (dataObject != null)
                {
                    try
                    {
                        // The copy command was not terminated by application
                        // One of reason should be the opening fail of Clipboard by the destroyed hwnd.
                        Clipboard.CriticalSetDataObject(dataObject, true);
                    }
                    catch (ExternalException)
                    {
                        // Clipboard is failed to set the data object.
                        return;
                    }
                }
            }

            // Do not clear springload formatting
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:47,代码来源:TextEditorCopyPaste.cs


示例20: AttachTextEditor

        /// <summary>
        /// Attach TextEditor to Document, if supports text.
        /// </summary>
        private void AttachTextEditor()
        {
            AnnotationService service = AnnotationService.GetService(this); 
            ITextContainer textContainer;

            // This method is called when Document is changing, so need
            // to clear old TextEditor data.
            if (_textEditor != null)
            {
                _textEditor.OnDetach();
                _textEditor = null;
                if (_textView.TextContainer.TextView == _textView)
                {
                    _textView.TextContainer.TextView = null;
                }
                _textView = null;
            }

            if (service != null)
      

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Documents.TextElement类代码示例发布时间:2022-05-26
下一篇:
C# Documents.Table类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap