// Token: 0x06003836 RID: 14390 RVA: 0x000FAA28 File Offset: 0x000F8C28 private static void OnResetFormat(object target, ExecutedRoutedEventArgs args) { TextEditor textEditor = TextEditor._GetTextEditor(target); if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection.Start is TextPointer)) { return; } TextEditorTyping._FlushPendingInputItems(textEditor); using (textEditor.Selection.DeclareChangeBlock()) { TextPointer start = (TextPointer)textEditor.Selection.Start; TextPointer end = (TextPointer)textEditor.Selection.End; if (textEditor.Selection.IsEmpty) { TextSegment autoWord = TextRangeBase.GetAutoWord(textEditor.Selection); if (autoWord.IsNull) { ((TextSelection)textEditor.Selection).ClearSpringloadFormatting(); return; } start = (TextPointer)autoWord.Start; end = (TextPointer)autoWord.End; } TextEditorSelection._ClearSuggestedX(textEditor); TextRangeEdit.CharacterResetFormatting(start, end); } }
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); }
/// <summary> /// Cut worker. /// </summary> internal static void Cut(TextEditor This, bool userInitiated) { if (userInitiated) { // Fail silently if the app explicitly denies clipboard access. try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); } catch (SecurityException) { return; } } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection != null && !This.Selection.IsEmpty) { // Copy content onto the clipboard // 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) when(!FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure) { // Clipboard is failed to set the data object. return; } // Delete selected content using (This.Selection.DeclareChangeBlock()) { // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); This.Selection.Text = String.Empty; // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } } }
//------------------------------------------------------ // // 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); } } }
// Common handler for all list editing commands private static void OnListCommand(object target, ExecutedRoutedEventArgs args) { TextEditor This = TextEditor._GetTextEditor(target); if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(This); if (!TextRangeEditLists.IsListOperationApplicable((TextSelection)This.Selection)) { return; } using (This.Selection.DeclareChangeBlock()) { TextSelection thisSelection = (TextSelection)This.Selection; ListItem parentListItem = TextPointerBase.GetListItem(thisSelection.Start); ListItem immediateListItem = TextPointerBase.GetImmediateListItem(thisSelection.Start); List list = parentListItem == null ? null : (List)parentListItem.Parent; // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Execute the command if (args.Command == EditingCommands.ToggleBullets) { ToggleBullets(thisSelection, parentListItem, immediateListItem, list); } else if (args.Command == EditingCommands.ToggleNumbering) { ToggleNumbering(thisSelection, parentListItem, immediateListItem, list); } else if (args.Command == EditingCommands.RemoveListMarkers) { TextRangeEditLists.ConvertListItemsToParagraphs(thisSelection); } else if (args.Command == EditingCommands.IncreaseIndentation) { IncreaseIndentation(thisSelection, parentListItem, immediateListItem); } else if (args.Command == EditingCommands.DecreaseIndentation) { DecreaseIndentation(thisSelection, parentListItem, immediateListItem); } else { Invariant.Assert(false); } } }
// Token: 0x06003874 RID: 14452 RVA: 0x000FCCBC File Offset: 0x000FAEBC private static void OnListCommand(object target, ExecutedRoutedEventArgs args) { TextEditor textEditor = TextEditor._GetTextEditor(target); if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(textEditor); if (!TextRangeEditLists.IsListOperationApplicable((TextSelection)textEditor.Selection)) { return; } using (textEditor.Selection.DeclareChangeBlock()) { TextSelection textSelection = (TextSelection)textEditor.Selection; ListItem listItem = TextPointerBase.GetListItem(textSelection.Start); ListItem immediateListItem = TextPointerBase.GetImmediateListItem(textSelection.Start); List list = (listItem == null) ? null : ((List)listItem.Parent); TextEditorSelection._ClearSuggestedX(textEditor); if (args.Command == EditingCommands.ToggleBullets) { TextEditorLists.ToggleBullets(textSelection, listItem, immediateListItem, list); } else if (args.Command == EditingCommands.ToggleNumbering) { TextEditorLists.ToggleNumbering(textSelection, listItem, immediateListItem, list); } else if (args.Command == EditingCommands.RemoveListMarkers) { TextRangeEditLists.ConvertListItemsToParagraphs(textSelection); } else if (args.Command == EditingCommands.IncreaseIndentation) { TextEditorLists.IncreaseIndentation(textSelection, listItem, immediateListItem); } else if (args.Command == EditingCommands.DecreaseIndentation) { TextEditorLists.DecreaseIndentation(textSelection, listItem, immediateListItem); } else { Invariant.Assert(false); } } }
internal static void Cut(TextEditor This, bool userInitiated) { if (userInitiated) { try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); goto IL_1E; } catch (SecurityException) { return; } } if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } IL_1E: TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection != null && !This.Selection.IsEmpty) { DataObject dataObject = TextEditorCopyPaste._CreateDataObject(This, false); if (dataObject != null) { try { Clipboard.CriticalSetDataObject(dataObject, true); } catch (ExternalException obj) when(!FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure) { return; } using (This.Selection.DeclareChangeBlock()) { TextEditorSelection._ClearSuggestedX(This); This.Selection.Text = string.Empty; if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } } }
// Token: 0x060038DF RID: 14559 RVA: 0x001011BC File Offset: 0x000FF3BC private static void OnTableCommand(object target, ExecutedRoutedEventArgs args) { TextEditor textEditor = TextEditor._GetTextEditor(target); if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(textEditor); TextEditorSelection._ClearSuggestedX(textEditor); if (args.Command == EditingCommands.InsertTable) { ((TextSelection)textEditor.Selection).InsertTable(4, 4); return; } if (args.Command == EditingCommands.InsertRows) { ((TextSelection)textEditor.Selection).InsertRows(1); return; } if (args.Command == EditingCommands.InsertColumns) { ((TextSelection)textEditor.Selection).InsertColumns(1); return; } if (args.Command == EditingCommands.DeleteRows) { ((TextSelection)textEditor.Selection).DeleteRows(); return; } if (args.Command == EditingCommands.DeleteColumns) { ((TextSelection)textEditor.Selection).DeleteColumns(); return; } if (args.Command == EditingCommands.MergeCells) { ((TextSelection)textEditor.Selection).MergeCells(); return; } if (args.Command == EditingCommands.SplitCell) { ((TextSelection)textEditor.Selection).SplitCell(1000, 1000); } }
internal static void Paste(TextEditor This) { if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } if (This.Selection.IsTableCellRange) { return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); IDataObject dataObject; try { dataObject = Clipboard.GetDataObject(); } catch (ExternalException) { dataObject = null; } bool coversEntireContent = This.Selection.CoversEntireContent; if (dataObject != null) { using (This.Selection.DeclareChangeBlock()) { TextEditorSelection._ClearSuggestedX(This); if (TextEditorCopyPaste._DoPaste(This, dataObject, false)) { This.Selection.SetCaretToPosition(This.Selection.End, LogicalDirection.Backward, false, true); if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } } if (coversEntireContent) { This.Selection.ValidateLayout(); } }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods private static void OnTableCommand(object target, ExecutedRoutedEventArgs args) { TextEditor This = TextEditor._GetTextEditor(target); if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection is TextSelection)) { return; } TextEditorTyping._FlushPendingInputItems(This); // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Execute the command if (args.Command == EditingCommands.InsertTable) { ((TextSelection)This.Selection).InsertTable(/*rowCount:*/ 4, /*columnCount:*/ 4); } else if (args.Command == EditingCommands.InsertRows) { ((TextSelection)This.Selection).InsertRows(+1); } else if (args.Command == EditingCommands.InsertColumns) { ((TextSelection)This.Selection).InsertColumns(+1); } else if (args.Command == EditingCommands.DeleteRows) { ((TextSelection)This.Selection).DeleteRows(); } else if (args.Command == EditingCommands.DeleteColumns) { ((TextSelection)This.Selection).DeleteColumns(); } else if (args.Command == EditingCommands.MergeCells) { ((TextSelection)This.Selection).MergeCells(); } else if (args.Command == EditingCommands.SplitCell) { ((TextSelection)This.Selection).SplitCell(1000, 1000); // Split all ways to possible maximum } }
// Token: 0x0600387D RID: 14461 RVA: 0x000FD1BC File Offset: 0x000FB3BC internal static void SetCaretPositionOnMouseEvent(TextEditor This, Point mouseDownPoint, MouseButton changedButton, int clickCount) { ITextPointer textPositionFromPoint = This.TextView.GetTextPositionFromPoint(mouseDownPoint, true); if (textPositionFromPoint == null) { TextEditorMouse.MoveFocusToUiScope(This); return; } TextEditorSelection._ClearSuggestedX(This); TextEditorTyping._BreakTypingSequence(This); if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } This._forceWordSelection = false; This._forceParagraphSelection = false; if (changedButton == MouseButton.Right || clickCount == 1) { if (changedButton != MouseButton.Left || !This._dragDropProcess.SourceOnMouseLeftButtonDown(mouseDownPoint)) { This.Selection.SetSelectionByMouse(textPositionFromPoint, mouseDownPoint); return; } } else { if (clickCount == 2 && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.None && This.Selection.IsEmpty) { This._forceWordSelection = true; This._forceParagraphSelection = false; This.Selection.SelectWord(textPositionFromPoint); return; } if (clickCount == 3 && (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.None && This.AcceptsRichContent) { This._forceParagraphSelection = true; This._forceWordSelection = false; This.Selection.SelectParagraph(textPositionFromPoint); } } }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods // ................................................................ // // Editing Commands: Character Editing // // ................................................................ private static void OnResetFormat(object target, ExecutedRoutedEventArgs args) { TextEditor This = TextEditor._GetTextEditor(target); if (This == null || !This._IsEnabled || This.IsReadOnly || !This.AcceptsRichContent || !(This.Selection.Start is TextPointer)) { return; } TextEditorTyping._FlushPendingInputItems(This); using (This.Selection.DeclareChangeBlock()) { // Positions to clear all inline formatting properties TextPointer startResetFormatPosition = (TextPointer)This.Selection.Start; TextPointer endResetFormatPosition = (TextPointer)This.Selection.End; if (This.Selection.IsEmpty) { TextSegment autoWordRange = TextRangeBase.GetAutoWord(This.Selection); if (autoWordRange.IsNull) { // Clear springloaded formatting ((TextSelection)This.Selection).ClearSpringloadFormatting(); return; } else { // If we have a word, apply reset format to it startResetFormatPosition = (TextPointer)autoWordRange.Start; endResetFormatPosition = (TextPointer)autoWordRange.End; } } // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // Clear all inline formattings TextRangeEdit.CharacterResetFormatting(startResetFormatPosition, endResetFormatPosition); } }
// Token: 0x06003835 RID: 14389 RVA: 0x000FA980 File Offset: 0x000F8B80 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; } if (!TextSchema.IsParagraphProperty(formattingProperty) && !TextSchema.IsCharacterProperty(formattingProperty)) { Invariant.Assert(false, "The property '" + formattingProperty.Name + "' is unknown to TextEditor"); return; } TextSelection textSelection = (TextSelection)This.Selection; if (TextSchema.IsStructuralCharacterProperty(formattingProperty) && !TextRangeEdit.CanApplyStructuralInlineProperty(textSelection.Start, textSelection.End)) { return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorSelection._ClearSuggestedX(This); TextEditorTyping._BreakTypingSequence(This); textSelection.ApplyPropertyValue(formattingProperty, propertyValue, applyToParagraphs, propertyValueAction); }
/// <summary> /// Paste worker. /// </summary> internal static void Paste(TextEditor This) { if (This.Selection.IsTableCellRange) { // We do not support clipboard for table selection so far // Word behavior: When source range is text segment then this segment is pasted // into each table cell overriding its current content. // If source range is table range then it is repeated on target - // cell by cell in circular manner. return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); // Get DataObject from the Clipboard IDataObject dataObject; try { dataObject = Clipboard.GetDataObject(); } catch (ExternalException) { // Clipboard is failed to get the data object. // One of reason should be the opening fail of Clipboard by the destroyed hwnd. dataObject = null; // must re-throw ??? } bool forceLayoutUpdate = This.Selection.CoversEntireContent; if (dataObject != null) { using (This.Selection.DeclareChangeBlock()) { // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // _DoPaste raises a public event -- could raise recoverable exception. if (TextEditorCopyPaste._DoPaste(This, dataObject, /*isDragDrop:*/ false)) { // Collapse selection to the end // Use backward direction to stay oriented towards pasted content This.Selection.SetCaretToPosition(This.Selection.End, LogicalDirection.Backward, /*allowStopAtLineEnd:*/ false, /*allowStopNearSpace:*/ true); // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } // PUBLIC EVENT RAISED HERE AS CHANGEBLOCK CLOSES! } // If we replaced the entire document content, background layout will // kick in. Force it to complete now. if (forceLayoutUpdate) { This.Selection.ValidateLayout(); } }
internal static void Paste(TextEditor This) { // Don't try anything if the caller doesn't have the rights to read from the clipboard... if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } if (This.Selection.IsTableCellRange) { // return; } TextEditorTyping._FlushPendingInputItems(This); TextEditorTyping._BreakTypingSequence(This); // Get DataObject from the Clipboard IDataObject dataObject; try { dataObject = Clipboard.GetDataObject(); } catch (ExternalException) { // Clipboard is failed to get the data object. // One of reason should be the opening fail of Clipboard by the destroyed hwnd. dataObject = null; // } bool forceLayoutUpdate = This.Selection.CoversEntireContent; if (dataObject != null) { using (This.Selection.DeclareChangeBlock()) { // Forget previously suggested horizontal position TextEditorSelection._ClearSuggestedX(This); // _DoPaste raises a public event -- could raise recoverable exception. if (TextEditorCopyPaste._DoPaste(This, dataObject, /*isDragDrop:*/ false)) { // Collapse selection to the end // Use backward direction to stay oriented towards pasted content This.Selection.SetCaretToPosition(This.Selection.End, LogicalDirection.Backward, /*allowStopAtLineEnd:*/ false, /*allowStopNearSpace:*/ true); // Clear springload formatting if (This.Selection is TextSelection) { ((TextSelection)This.Selection).ClearSpringloadFormatting(); } } } // PUBLIC EVENT RAISED HERE AS CHANGEBLOCK CLOSES! } // If we replaced the entire document content, background layout will // kick in. Force it to complete now. if (forceLayoutUpdate) { This.Selection.ValidateLayout(); } }