本文整理汇总了C#中System.Windows.Documents.TextPointer类的典型用法代码示例。如果您正苦于以下问题:C# TextPointer类的具体用法?C# TextPointer怎么用?C# TextPointer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextPointer类属于System.Windows.Documents命名空间,在下文中一共展示了TextPointer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SplitFormattingElement
internal static TextPointer SplitFormattingElement(TextPointer splitPosition, bool keepEmptyFormatting)
{
Invariant.Assert(splitPosition.Parent != null && TextSchema.IsMergeableInline(splitPosition.Parent.GetType()));
Inline inline = (Inline)splitPosition.Parent;
// Create a movable copy of a splitPosition
if (splitPosition.IsFrozen)
{
splitPosition = new TextPointer(splitPosition);
}
if (!keepEmptyFormatting && splitPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
{
// The first part of element is empty. We are allowed to remove empty formatting elements,
// so we can simply move splitPotision outside of the element and we are done
splitPosition.MoveToPosition(inline.ElementStart);
}
else if (!keepEmptyFormatting && splitPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
{
// The second part of element is empty. We are allowed to remove empty formatting elements,
// so we can simply move splitPotision outside of the element and we are done.
splitPosition.MoveToPosition(inline.ElementEnd);
}
else
{
splitPosition = SplitElement(splitPosition);
}
return splitPosition;
}
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:31,代码来源:TextRangeEdit.cs
示例2: Read
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal methods.
/// <summary>
/// Reads the document from the reader into the specified position.
/// </summary>
internal void Read(XmlReader reader, TextPointer position)
{
System.Diagnostics.Debug.Assert(reader != null);
System.Diagnostics.Debug.Assert(position != null);
ReadDocument(reader, position);
}
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:24,代码来源:wordxmlreader.cs
示例3: Resolve
public static TextEffectTarget[] Resolve(TextPointer startPosition, TextPointer endPosition, System.Windows.Media.TextEffect effect)
{
Contract.Requires(endPosition != null);
Contract.Ensures(Contract.Result<System.Windows.Documents.TextEffectTarget[]>() != null);
return default(TextEffectTarget[]);
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:7,代码来源:System.Windows.Documents.TextEffectResolver.cs
示例4: GetPreceedingWordInParagraph
// Helper that returns a word preceeding the passed position in its paragraph,
// wordStartPosition points to the start position of word.
private static string GetPreceedingWordInParagraph(TextPointer position, out TextPointer wordStartPosition)
{
wordStartPosition = null;
string word = String.Empty;
Paragraph paragraph = position.Paragraph;
if (paragraph != null)
{
TextPointer navigator = position;
while (navigator.CompareTo(paragraph.ContentStart) > 0)
{
string runText = navigator.GetTextInRun(LogicalDirection.Backward);
if (runText.Contains(" ")) // Any globalized application would need more sophisticated word break testing.
{
int index = runText.LastIndexOf(" ");
word = runText.Substring(index + 1, runText.Length - index - 1) + word;
wordStartPosition = navigator.GetPositionAtOffset(-1 * (runText.Length - index - 1));
break;
}
else
{
wordStartPosition = navigator;
word = runText + word;
}
navigator = navigator.GetNextContextPosition(LogicalDirection.Backward);
}
}
return word;
}
开发者ID:MicroHealthLLC,项目名称:mCleaner,代码行数:33,代码来源:RichTextBoxEx.cs
示例5: IsPositionNextToWordBreak
// Helper for GetPositionAtWordBoundary.
// Returns true when passed TextPointer is next to a wordBreak in requested direction.
private static bool IsPositionNextToWordBreak(TextPointer position, LogicalDirection wordBreakDirection)
{
bool isAtWordBoundary = false;
// Skip over any formatting.
if (position.GetPointerContext(wordBreakDirection) != TextPointerContext.Text)
{
position = position.GetInsertionPosition(wordBreakDirection);
}
if (position.GetPointerContext(wordBreakDirection) == TextPointerContext.Text)
{
LogicalDirection oppositeDirection = (wordBreakDirection == LogicalDirection.Forward) ?
LogicalDirection.Backward : LogicalDirection.Forward;
char[] runBuffer = new char[1];
char[] oppositeRunBuffer = new char[1];
position.GetTextInRun(wordBreakDirection, runBuffer, /*startIndex*/0, /*count*/1);
position.GetTextInRun(oppositeDirection, oppositeRunBuffer, /*startIndex*/0, /*count*/1);
if (runBuffer[0] == ' ' && !(oppositeRunBuffer[0] == ' '))
{
isAtWordBoundary = true;
}
}
else
{
// If we're not adjacent to text then we always want to consider this position a "word break".
// In practice, we're most likely next to an embedded object or a block boundary.
isAtWordBoundary = true;
}
return isAtWordBoundary;
}
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:37,代码来源:WordBreaker.cs
示例6: Do
/// <summary>
/// Perform the appropriate action for this unit. If this is a parent undo unit, the
/// parent must create an appropriate parent undo unit to contain the redo units.
/// </summary>
public override void Do()
{
UndoManager undoManager;
IParentUndoUnit redo;
TextPointer textPointerTable;
Table table;
undoManager = TopContainer as UndoManager;
redo = null;
textPointerTable = new TextPointer(_textContainer.Start, _cpTable, LogicalDirection.Forward);
table = (Table) textPointerTable.Parent;
_columnWidths[_columnIndex] -= _resizeAmount;
if(_columnIndex < table.ColumnCount - 1)
{
_columnWidths[_columnIndex + 1] += _resizeAmount;
}
if(undoManager != null && undoManager.IsEnabled)
{
redo = new ColumnResizeUndoUnit(textPointerTable, _columnIndex, _columnWidths, -_resizeAmount);
undoManager.Open(redo);
}
TextRangeEditTables.EnsureTableColumnsAreFixedSize(table, _columnWidths);
if(redo != null)
{
undoManager.Close(redo, UndoCloseAction.Commit);
}
}
开发者ID:JianwenSun,项目名称:cc,代码行数:37,代码来源:ColumnResizeUndoUnit.cs
示例7: AnchoredBlock
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
/// <summary>
/// Creates a new AnchoredBlock instance.
/// </summary>
/// <param name="block">
/// Optional child of the new AnchoredBlock, may be null.
/// </param>
/// <param name="insertionPosition">
/// Optional position at which to insert the new AnchoredBlock. May
/// be null.
/// </param>
protected AnchoredBlock(Block block, TextPointer insertionPosition)
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.BeginChange();
}
try
{
if (insertionPosition != null)
{
// This will throw InvalidOperationException if schema validity is violated.
insertionPosition.InsertInline(this);
}
if (block != null)
{
this.Blocks.Add(block);
}
}
finally
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.EndChange();
}
}
}
开发者ID:JianwenSun,项目名称:cc,代码行数:45,代码来源:AnchoredBlock.cs
示例8: DoCore
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
// Called by the undo manager. Restores tree state to its condition
// when the unit was created. Assumes the tree state matches conditions
// just after the unit was created.
public override void DoCore()
{
TextPointer start;
TextPointer end;
TextElement element;
VerifyTreeContentHashCode();
start = new TextPointer(this.TextContainer, this.SymbolOffset, LogicalDirection.Forward);
end = new TextPointer(this.TextContainer, this.SymbolOffset + _symbolCount - 2, LogicalDirection.Forward);
// Insert a new element.
element = (TextElement)Activator.CreateInstance(_type);
element.Reposition(start, end);
// Restore local resources
element.Resources = _resources;
// Move end into the scope of the new element.
end.MoveToNextContextPosition(LogicalDirection.Backward);
// Then restore local property values.
//
this.TextContainer.SetValues(end, ArrayToLocalValueEnumerator(_localValues));
if (element is Table)
{
TextTreeDeleteContentUndoUnit.RestoreColumns((Table)element, _columns);
}
}
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:40,代码来源:TextTreeExtractElementUndoUnit.cs
示例9: Run
/// <summary>
/// Creates a new Run instance.
/// </summary>
/// <param name="text">
/// Optional text content. May be null.
/// </param>
/// <param name="insertionPosition">
/// Optional position at which to insert the new Run. May
/// be null.
/// </param>
public Run(string text, TextPointer insertionPosition)
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.BeginChange();
}
try
{
if (insertionPosition != null)
{
// This will throw InvalidOperationException if schema validity is violated.
insertionPosition.InsertInline(this);
}
if (text != null)
{
// No need to duplicate the string data in TextProperty here. TextContainer will
// set the property to a deferred reference.
this.ContentStart.InsertTextInRun(text);
}
}
finally
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.EndChange();
}
}
}
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:39,代码来源:Run.cs
示例10: GetTextPositionAtOffset
TextPointer GetTextPositionAtOffset(TextPointer position, int characterCount)
{
while (position != null)
{
var context = position.GetPointerContext(LogicalDirection.Forward);
if (context == TextPointerContext.Text)
{
var count = position.GetTextRunLength(LogicalDirection.Forward);
if (characterCount <= count)
{
return position.GetPositionAtOffset(characterCount);
}
characterCount -= count;
}
else if (position.Parent is LineBreak)
{
var count = 2;
if (characterCount <= count)
{
return position.GetPositionAtOffset(characterCount);
}
characterCount -= count;
}
var nextContextPosition = position.GetNextContextPosition(LogicalDirection.Forward);
if (nextContextPosition == null)
return position;
position = nextContextPosition;
}
return position;
}
开发者ID:ElemarJR,项目名称:Jujubas,代码行数:35,代码来源:MainWindow.xaml.cs
示例11: DoCore
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
#region Public Methods
// Called by the undo manager. Restores tree state to its condition
// when the unit was created. Assumes the tree state matches conditions
// just after the unit was created.
public override void DoCore()
{
TextPointer start;
TextPointer end;
TextElement element;
VerifyTreeContentHashCode();
start = new TextPointer(this.TextContainer, this.SymbolOffset, LogicalDirection.Forward);
Invariant.Assert(start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextTree undo unit out of [....] with TextTree.");
element = start.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
if (_deep)
{
// Extract the element and its content.
end = new TextPointer(this.TextContainer, element.TextElementNode, ElementEdge.AfterEnd);
this.TextContainer.DeleteContentInternal(start, end);
}
else
{
// Just extract the element, not its content.
this.TextContainer.ExtractElementInternal(element);
}
}
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:37,代码来源:TextTreeInsertElementUndoUnit.cs
示例12: CompareTo
public int CompareTo (TextPointer position)
{
if (position == null)
throw new ArgumentNullException ("position");
return NativeMethods.text_pointer_compare_to (native, position.native);
}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:TextPointer.cs
示例13: GetPositionAtWordBoundary
/// <summary>
/// 1. When wordBreakDirection = Forward, returns a position at the end of the word,
/// i.e. a position with a wordBreak character (space) following it.
/// 2. When wordBreakDirection = Backward, returns a position at the start of the word,
/// i.e. a position with a wordBreak character (space) preceeding it.
/// 3. Returns null when there is no workbreak in the requested direction.
/// </summary>
private static TextPointer GetPositionAtWordBoundary(TextPointer position, LogicalDirection wordBreakDirection)
{
if (!position.IsAtInsertionPosition)
{
position = position.GetInsertionPosition(wordBreakDirection);
}
TextPointer navigator = position;
while (navigator != null && !IsPositionNextToWordBreak(navigator, wordBreakDirection))
{
navigator = navigator.GetNextInsertionPosition(wordBreakDirection);
}
return navigator;
}
开发者ID:ittray,项目名称:LocalDemo,代码行数:40,代码来源:WordBreaker.cs
示例14: Span
/// <summary>
/// Creates a new Span instance.
/// </summary>
/// <param name="childInline">
/// Optional child Inline for the new Span. May be null.
/// </param>
/// <param name="insertionPosition">
/// Optional position at which to insert the new Span. May be null.
/// </param>
public Span(Inline childInline, TextPointer insertionPosition)
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.BeginChange();
}
try
{
if (insertionPosition != null)
{
// This will throw InvalidOperationException if schema validity is violated.
insertionPosition.InsertInline(this);
}
if (childInline != null)
{
this.Inlines.Add(childInline);
}
}
finally
{
if (insertionPosition != null)
{
insertionPosition.TextContainer.EndChange();
}
}
}
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:36,代码来源:Span.cs
示例15: CompareTo
public int CompareTo(TextPointer position)
{
Contract.Requires(position != null);
Contract.Ensures(-1 <= Contract.Result<int>());
Contract.Ensures(Contract.Result<int>() <= 1);
return default(int);
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:8,代码来源:System.Windows.Documents.TextPointer.cs
示例16: CanMerge
public bool CanMerge(RichTextBox edit, TextPointer insertPosition)
{
if (edit.Document.ContentStart.GetOffsetToPosition(insertPosition) == __OffsetEnd &&
insertPosition.IsAtInsertionPosition)
return true;
return false;
}
开发者ID:fednep,项目名称:UV-Outliner,代码行数:8,代码来源:UndoTextEnter.cs
示例17: SafePositionAtOffset
internal static TextPointer SafePositionAtOffset(FlowDocument document, TextPointer textPointer, int offsetStart)
{
var pointer = textPointer.GetPositionAtOffset(offsetStart);
if (pointer == null)
return document.ContentEnd;
return pointer;
}
开发者ID:fednep,项目名称:UV-Outliner,代码行数:8,代码来源:UndoHelpers.cs
示例18: IsHyperlinkBoundaryCrossed
// Helper that returns true if passed caretPosition and backspacePosition cross a hyperlink end boundary
// (under the assumption that caretPosition and backSpacePosition are adjacent insertion positions).
private static bool IsHyperlinkBoundaryCrossed(TextPointer caretPosition, TextPointer backspacePosition, out Hyperlink backspacePositionHyperlink)
{
Hyperlink caretPositionHyperlink = GetHyperlinkAncestor(caretPosition);
backspacePositionHyperlink = GetHyperlinkAncestor(backspacePosition);
return (caretPositionHyperlink == null && backspacePositionHyperlink != null) ||
(caretPositionHyperlink != null && backspacePositionHyperlink != null && caretPositionHyperlink != backspacePositionHyperlink);
}
开发者ID:MicroHealthLLC,项目名称:mCleaner,代码行数:10,代码来源:RichTextBoxEx.cs
示例19: Select
public void Select (TextPointer anchorPosition, TextPointer movingPosition)
{
if (anchorPosition == null)
throw new ArgumentNullException ("anchorPosition");
if (movingPosition == null)
throw new ArgumentNullException ("movingPosition");
NativeMethods.text_selection_select (native, anchorPosition.native, movingPosition.native);
}
开发者ID:snorp,项目名称:moon,代码行数:9,代码来源:TextSelection.cs
示例20: Write
//------------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
//------------------------------------------------------
//
// Public Properties
//
//------------------------------------------------------
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal methods.
/// <summary>
/// Writes the container into the specified XmlWriter.
/// </summary>
internal void Write(TextPointer start, TextPointer end, XmlWriter writer)
{
System.Diagnostics.Debug.Assert(start != null);
System.Diagnostics.Debug.Assert(end != null);
System.Diagnostics.Debug.Assert(start.CompareTo(end) <= 0);
System.Diagnostics.Debug.Assert(writer != null);
WriteContainer(start, end, writer);
}
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:38,代码来源:wordxmlwriter.cs
注:本文中的System.Windows.Documents.TextPointer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论