/// <summary> /// Copy worker. /// </summary> internal static void Copy(TextEditor This, bool userInitiated) { 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) when(!FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure) { // Clipboard is failed to set the data object. return; } } } // Do not clear springload formatting }
internal bool SourceOnMouseMove(Point mouseMovePoint) { // Not allow the initiating DragDrop operation without the unmanaged code permission. // We chose to use this over clipboard because this was causing issues in LocalIntranet // which has similar restrictions as internet but has clipboard permission if (!_dragStarted || !SecurityHelper.CheckUnmanagedCodePermission()) { return(false); // false means that drag is not involved at all - selection extension should continue } // Check the mouse drag to start DragDrop operation. if (!InitialThresholdCrossed(mouseMovePoint)) { return(true); // true means that drag is in progress, even though not yet started - so selection should not extend } ITextSelection selection = _textEditor.Selection; // NOTE: This calls OnMouseMove recursively; // but because UiScope.IsMouseCaptured is false already, // we'll return with no actions // This is the first move in drag-drop gesture. // Execure the whole drag-drop ssequence: returns after the drop _dragStarted = false; // Execute OLE drag-drop process (synchronousely) // ---------------------------------------------- // Set the original text range to delete it with DragDropEffects.Move effect. _dragSourceTextRange = new TextRange(selection.Start, selection.End); // Prepare data object (including side effects from application customization) // Note: _CreateDataObject raises a public event which might throw a recoverable exception. IDataObject dataObject = TextEditorCopyPaste._CreateDataObject(_textEditor, /*isDragDrop:*/ true); if (dataObject != null) // null would mean that application cancelled the command { // SourceDoDragDrop(selection, dataObject); // Release mouse capture, because DoDragDrop is taking // a mouse resposibility from now on. // ReleaseMouseCapture shouldn't call before calling DoDragDroop // that cause the generating WM_MOUSELEAVE message by system // (xxxCapture xxxCancelMouseMoverTracking) that appear MouseLeave // event during DragDrop event. _textEditor.UiScope.ReleaseMouseCapture(); return(true); // true means that drag is in progress. Selection should not extend. } else { // The DragDrop process has been terminated by application custom code // return(false); } }
/// <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(); } } } } }
/// <summary> /// Copy worker. /// </summary> 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) when(!FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure) { // Clipboard is failed to set the data object. return; } } } // Do not clear springload formatting }
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(); } } } } }
internal bool SourceOnMouseMove(Point mouseMovePoint) { if (!this._dragStarted || !SecurityHelper.CheckUnmanagedCodePermission()) { return(false); } if (!this.InitialThresholdCrossed(mouseMovePoint)) { return(true); } ITextSelection selection = this._textEditor.Selection; this._dragStarted = false; this._dragSourceTextRange = new TextRange(selection.Start, selection.End); IDataObject dataObject = TextEditorCopyPaste._CreateDataObject(this._textEditor, true); if (dataObject != null) { this.SourceDoDragDrop(selection, dataObject); this._textEditor.UiScope.ReleaseMouseCapture(); return(true); } return(false); }
internal static void Copy(TextEditor This, bool userInitiated) { if (userInitiated) { try { new UIPermission(UIPermissionClipboard.OwnClipboard).Demand(); goto IL_1B; } catch (SecurityException) { return; } } if (!SecurityHelper.CallerHasAllClipboardPermission()) { return; } IL_1B: 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) { } } } }