本文整理汇总了C#中System.Windows.Documents.TextEditor类的典型用法代码示例。如果您正苦于以下问题:C# TextEditor类的具体用法?C# TextEditor怎么用?C# TextEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextEditor类属于System.Windows.Documents命名空间,在下文中一共展示了TextEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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 */);
}
示例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
}
示例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);
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}
}
//.........这里部分代码省略.........
示例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);
}