Beispiel #1
0
        // Token: 0x0600386A RID: 14442 RVA: 0x000FC8DC File Offset: 0x000FAADC
        internal static void OnDragEnter(object sender, DragEventArgs e)
        {
            e.Handled = true;
            TextEditor textEditor = TextEditor._GetTextEditor(sender);

            if (textEditor == null)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            if (!textEditor._IsEnabled || textEditor.TextView == null || textEditor.TextView.RenderScope == null)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            if (e.Data == null)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            if (TextEditorCopyPaste.GetPasteApplyFormat(textEditor, e.Data) == string.Empty)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            if (!textEditor.TextView.Validate(e.GetPosition(textEditor.TextView.RenderScope)))
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            textEditor._dragDropProcess.TargetOnDragEnter(e);
        }
        // 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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        /// <summary>
        /// ToggleUnderline command event handler.
        /// </summary>
        private static void OnToggleUnderline(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);

            object propertyValue = ((TextSelection)This.Selection).GetCurrentValue(Inline.TextDecorationsProperty);
            TextDecorationCollection textDecorations = propertyValue != DependencyProperty.UnsetValue ? (TextDecorationCollection)propertyValue : null;

            TextDecorationCollection toggledTextDecorations;

            if (!TextSchema.HasTextDecorations(textDecorations))
            {
                toggledTextDecorations = TextDecorations.Underline;
            }
            else if (!textDecorations.TryRemove(TextDecorations.Underline, out toggledTextDecorations))
            {
                // TextDecorations.Underline was not present, so add it
                toggledTextDecorations.Add(TextDecorations.Underline);
            }

            TextEditorCharacters._OnApplyProperty(This, Inline.TextDecorationsProperty, toggledTextDecorations);
        }
        /// <summary>
        /// An event reporting that the drag leave during drag-and-drop operation.
        /// </summary>
        internal static void OnDragLeave(object sender, DragEventArgs e)
        {
            // Consider event handled
            e.Handled = true;

            TextEditor This = TextEditor._GetTextEditor(sender);

            if (This == null)
            {
                return;
            }

            //
            // Remove UI feedback here if UI is specified on DragEnter.
            //
            // Ignore the event if the editor has been detached from its scope
            if (!This._IsEnabled)
            {
                e.Effects = DragDropEffects.None;
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);
            if (!This.TextView.Validate(e.GetPosition(This.TextView.RenderScope)))
            {
                return;
            }
        }
Beispiel #6
0
        /// <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
        }
        // Token: 0x0600383D RID: 14397 RVA: 0x000FAEB0 File Offset: 0x000F90B0
        private static void OnDecreaseFontSize(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 (textEditor.Selection.IsEmpty)
            {
                double num = (double)((TextSelection)textEditor.Selection).GetCurrentValue(TextElement.FontSizeProperty);
                if (num == 0.0)
                {
                    return;
                }
                if (num > 0.75)
                {
                    num -= 0.75;
                    if (num < 0.75)
                    {
                        num = 0.75;
                    }
                    TextEditorCharacters._OnApplyProperty(textEditor, TextElement.FontSizeProperty, num);
                    return;
                }
            }
            else
            {
                TextEditorCharacters._OnApplyProperty(textEditor, TextElement.FontSizeProperty, 0.75, false, PropertyValueAction.DecreaseByAbsoluteValue);
            }
        }
Beispiel #8
0
        //------------------------------------------------------
        //
        //  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);
                }
            }
        }
Beispiel #9
0
        /// <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();
                        }
                    }
                }
            }
        }
Beispiel #10
0
        // 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: 0x06003837 RID: 14391 RVA: 0x000FAB18 File Offset: 0x000F8D18
        private static void OnToggleBold(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);
            object     currentValue = ((TextSelection)textEditor.Selection).GetCurrentValue(TextElement.FontWeightProperty);
            FontWeight fontWeight   = (currentValue != DependencyProperty.UnsetValue && (FontWeight)currentValue == FontWeights.Bold) ? FontWeights.Normal : FontWeights.Bold;

            TextEditorCharacters._OnApplyProperty(textEditor, TextElement.FontWeightProperty, fontWeight);
        }
        // Token: 0x0600383B RID: 14395 RVA: 0x000FAD64 File Offset: 0x000F8F64
        private static void OnToggleSuperscript(object sender, ExecutedRoutedEventArgs args)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(sender);

            if (textEditor == null || !textEditor._IsEnabled || textEditor.IsReadOnly || !textEditor.AcceptsRichContent || !(textEditor.Selection is TextSelection))
            {
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            FontVariants fontVariants = (FontVariants)((TextSelection)textEditor.Selection).GetCurrentValue(Typography.VariantsProperty);

            fontVariants = ((fontVariants == FontVariants.Superscript) ? FontVariants.Normal : FontVariants.Superscript);
            TextEditorCharacters._OnApplyProperty(textEditor, Typography.VariantsProperty, fontVariants);
        }
Beispiel #13
0
        /// <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
        }
        // 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);
                }
            }
        }
Beispiel #15
0
        // Token: 0x0600386C RID: 14444 RVA: 0x000FCA44 File Offset: 0x000FAC44
        internal static void OnDragLeave(object sender, DragEventArgs e)
        {
            e.Handled = true;
            TextEditor textEditor = TextEditor._GetTextEditor(sender);

            if (textEditor == null)
            {
                return;
            }
            if (!textEditor._IsEnabled)
            {
                e.Effects = DragDropEffects.None;
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            textEditor.TextView.Validate(e.GetPosition(textEditor.TextView.RenderScope));
        }
        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();
                        }
                    }
                }
            }
        }
Beispiel #17
0
        // 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);
            }
        }
        /// <summary>
        /// An event reporting that the drag enter during drag-and-drop operation.
        /// </summary>
        internal static void OnDragEnter(object sender, DragEventArgs e)
        {
            // Consider event handled
            e.Handled = true;

            TextEditor This = TextEditor._GetTextEditor(sender);

            if (This == null)
            {
                e.Effects = DragDropEffects.None;
                return;
            }

            // Ignore the event if the editor has been detached from its scope
            if (!This._IsEnabled || This.TextView == null || This.TextView.RenderScope == null)
            {
                e.Effects = DragDropEffects.None;
                return;
            }

            // If there's no supported data available, don't allow the drag-and-drop.
            if (e.Data == null)
            {
                e.Effects = DragDropEffects.None;
                return;
            }

            // Ignore the event if there isn't the dropable(pasteable) data format
            if (TextEditorCopyPaste.GetPasteApplyFormat(This, e.Data) == string.Empty)
            {
                e.Effects = DragDropEffects.None;
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            if (!This.TextView.Validate(e.GetPosition(This.TextView.RenderScope)))
            {
                e.Effects = DragDropEffects.None;
                return;
            }

            This._dragDropProcess.TargetOnDragEnter(e);
        }
        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();
            }
        }
Beispiel #20
0
        //------------------------------------------------------
        //
        //  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
            }
        }
Beispiel #21
0
        /// <summary>
        /// ToggleItalic command event handler.
        /// </summary>
        private static void OnToggleItalic(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);

            object    propertyValue = ((TextSelection)This.Selection).GetCurrentValue(TextElement.FontStyleProperty);
            FontStyle fontStyle     = (propertyValue != DependencyProperty.UnsetValue && (FontStyle)propertyValue == FontStyles.Italic) ? FontStyles.Normal : FontStyles.Italic;

            TextEditorCharacters._OnApplyProperty(This, TextElement.FontStyleProperty, fontStyle);

            // Update the caret to show it as italic or normal caret.
            This.Selection.RefreshCaret();
        }
Beispiel #22
0
        // Token: 0x0600386D RID: 14445 RVA: 0x000FCA98 File Offset: 0x000FAC98
        internal static void OnDrop(object sender, DragEventArgs e)
        {
            TextEditor textEditor = TextEditor._GetTextEditor(sender);

            if (textEditor == null)
            {
                return;
            }
            if (!textEditor._IsEnabled)
            {
                return;
            }
            TextEditorTyping._FlushPendingInputItems(textEditor);
            if (!textEditor.TextView.Validate(e.GetPosition(textEditor.TextView.RenderScope)))
            {
                return;
            }
            textEditor._dragDropProcess.TargetOnDrop(e);
        }
        // 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);
                }
            }
        }
Beispiel #24
0
        //------------------------------------------------------
        //
        //  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);
        }
Beispiel #26
0
        /// <summary>
        /// IncreaseFontSize command event handler
        /// </summary>
        private static void OnIncreaseFontSize(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 (This.Selection.IsEmpty)
            {
                // Springload an increased font size
                double fontSize = (double)((TextSelection)This.Selection).GetCurrentValue(TextElement.FontSizeProperty);
                if (fontSize == 0.0)
                {
                    return; // no characters available for font operation
                }

                if (fontSize < TextEditorCharacters.MaxFontPoint)
                {
                    fontSize += TextEditorCharacters.OneFontPoint;
                    if (fontSize > TextEditorCharacters.MaxFontPoint)
                    {
                        fontSize = TextEditorCharacters.MaxFontPoint;
                    }

                    // The limiting constant is taken from Word UI - it suggests to choose font size from a range between 1 and 1638.
                    TextEditorCharacters._OnApplyProperty(This, TextElement.FontSizeProperty, fontSize);
                }
            }
            else
            {
                // Apply font size in incremental mode to a nonempty selection
                TextEditorCharacters._OnApplyProperty(This, TextElement.FontSizeProperty, OneFontPoint, /*applyToParagraphs:*/ false, PropertyValueAction.IncreaseByAbsoluteValue);
            }
        }
        /// <summary>
        /// An event reporting that the drop happened.
        /// </summary>
        internal static void OnDrop(object sender, DragEventArgs e)
        {
            TextEditor This = TextEditor._GetTextEditor(sender);

            if (This == null)
            {
                return;
            }

            // Ignore the event if the editor has been detached from its scope
            if (!This._IsEnabled)
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);
            if (!This.TextView.Validate(e.GetPosition(This.TextView.RenderScope)))
            {
                return;
            }

            This._dragDropProcess.TargetOnDrop(e);
        }
        // Token: 0x06003839 RID: 14393 RVA: 0x000FAC48 File Offset: 0x000F8E48
        private static void OnToggleUnderline(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);
            object currentValue = ((TextSelection)textEditor.Selection).GetCurrentValue(Inline.TextDecorationsProperty);
            TextDecorationCollection textDecorationCollection = (currentValue != DependencyProperty.UnsetValue) ? ((TextDecorationCollection)currentValue) : null;
            TextDecorationCollection underline;

            if (!TextSchema.HasTextDecorations(textDecorationCollection))
            {
                underline = TextDecorations.Underline;
            }
            else if (!textDecorationCollection.TryRemove(TextDecorations.Underline, out underline))
            {
                underline.Add(TextDecorations.Underline);
            }
            TextEditorCharacters._OnApplyProperty(textEditor, Inline.TextDecorationsProperty, underline);
        }
        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)
                    {
                    }
                }
            }
        }
Beispiel #30
0
        /// <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();
            }
        }