本文整理汇总了C#中ITextPointer.GetFrozenPointer方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.GetFrozenPointer方法的具体用法?C# ITextPointer.GetFrozenPointer怎么用?C# ITextPointer.GetFrozenPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextPointer
的用法示例。
在下文中一共展示了ITextPointer.GetFrozenPointer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpellingError
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
// Creates a new instance.
internal SpellingError(Speller speller, ITextPointer start, ITextPointer end)
{
Invariant.Assert(start.CompareTo(end) < 0);
_speller = speller;
_start = start.GetFrozenPointer(LogicalDirection.Forward);
_end = end.GetFrozenPointer(LogicalDirection.Backward);
}
示例2: TextContainerChangeEventArgs
internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange, DependencyProperty property, bool affectsRenderOnly)
{
_textPosition = textPosition.GetFrozenPointer(LogicalDirection.Forward);
_count = count;
_charCount = charCount;
_textChange = textChange;
_property = property;
_affectsRenderOnly = affectsRenderOnly;
}
示例3: TextSegment
/// <summary>
/// Constructor.
/// </summary>
/// <param name="startPosition">
/// Position preceeding the TextSegment's content.
/// </param>
/// <param name="endPosition">
/// Position following the TextSegment's content.
/// </param>
/// <param name="preserveLogicalDirection">
/// Whether preserves LogicalDirection of start and end positions.
/// </param>
internal TextSegment(ITextPointer startPosition, ITextPointer endPosition, bool preserveLogicalDirection)
{
ValidationHelper.VerifyPositionPair(startPosition, endPosition);
if (startPosition.CompareTo(endPosition) == 0)
{
// To preserve segment emptiness
// we use the same instance of a pointer
// for both segment ends.
_start = startPosition.GetFrozenPointer(startPosition.LogicalDirection);
_end = _start;
}
else
{
Invariant.Assert(startPosition.CompareTo(endPosition) < 0);
_start = startPosition.GetFrozenPointer(preserveLogicalDirection ? startPosition.LogicalDirection : LogicalDirection.Backward);
_end = endPosition.GetFrozenPointer(preserveLogicalDirection ? endPosition.LogicalDirection : LogicalDirection.Forward);
}
}
示例4: Run
internal Run(ITextPointer position, RunType runType)
{
_position = position.GetFrozenPointer(LogicalDirection.Backward);
_runType = runType;
}
示例5: TextMap
// Creates a new instance.
// contextStart/End refer to the whole run of text.
// contentStart/End are a subset of the text, which is what
// the engine will actually tag with errors.
// The space between context and content is used by the engine
// to correctly analyze multiple word phrase like "Los Angeles"
// that could otherwise be truncated and incorrectly tagged.
internal TextMap(ITextPointer contextStart, ITextPointer contextEnd,
ITextPointer contentStart, ITextPointer contentEnd)
{
ITextPointer position;
int maxChars;
int inlineCount;
int runCount;
int i;
int distance;
Invariant.Assert(contextStart.CompareTo(contentStart) <= 0);
Invariant.Assert(contextEnd.CompareTo(contentEnd) >= 0);
_basePosition = contextStart.GetFrozenPointer(LogicalDirection.Backward);
position = contextStart.CreatePointer();
maxChars = contextStart.GetOffsetToPosition(contextEnd);
_text = new char[maxChars];
_positionMap = new int[maxChars+1];
_textLength = 0;
inlineCount = 0;
_contentStartOffset = 0;
_contentEndOffset = 0;
// Iterate over the run, building up a matching plain text buffer
// and a table that tells us how to map back to the original text.
while (position.CompareTo(contextEnd) < 0)
{
if (position.CompareTo(contentStart) == 0)
{
_contentStartOffset = _textLength;
}
if (position.CompareTo(contentEnd) == 0)
{
_contentEndOffset = _textLength;
}
switch (position.GetPointerContext(LogicalDirection.Forward))
{
case TextPointerContext.Text:
runCount = position.GetTextRunLength(LogicalDirection.Forward);
runCount = Math.Min(runCount, _text.Length - _textLength);
runCount = Math.Min(runCount, position.GetOffsetToPosition(contextEnd));
position.GetTextInRun(LogicalDirection.Forward, _text, _textLength, runCount);
for (i = _textLength; i < _textLength + runCount; i++)
{
_positionMap[i] = i + inlineCount;
}
distance = position.GetOffsetToPosition(contentStart);
if (distance >= 0 && distance <= runCount)
{
_contentStartOffset = _textLength + position.GetOffsetToPosition(contentStart);
}
distance = position.GetOffsetToPosition(contentEnd);
if (distance >= 0 && distance <= runCount)
{
_contentEndOffset = _textLength + position.GetOffsetToPosition(contentEnd);
}
position.MoveByOffset(runCount);
_textLength += runCount;
break;
case TextPointerContext.ElementStart:
case TextPointerContext.ElementEnd:
if (IsAdjacentToFormatElement(position))
{
// Filter out formatting tags from the plain text.
inlineCount++;
}
else
{
// Stick in a word break to account for the block element.
_text[_textLength] = ' ';
_positionMap[_textLength] = _textLength + inlineCount;
_textLength++;
}
position.MoveToNextContextPosition(LogicalDirection.Forward);
break;
case TextPointerContext.EmbeddedElement:
_text[_textLength] = '\xf8ff'; // Unicode private use.
_positionMap[_textLength] = _textLength + inlineCount;
_textLength++;
position.MoveToNextContextPosition(LogicalDirection.Forward);
break;
//.........这里部分代码省略.........
示例6: GetLineIndexFromPosition
/// <summary>
/// <see cref="ITextView.GetBackspaceCaretUnitPosition"/>
/// </summary>
ITextPointer ITextView.GetBackspaceCaretUnitPosition(ITextPointer position)
{
Invariant.Assert(this.IsLayoutValid);
Invariant.Assert(Contains(position));
// Special case document start.
if (position.Offset == 0)
{
return position.GetFrozenPointer(LogicalDirection.Forward);
}
int lineIndex = GetLineIndexFromPosition(position, LogicalDirection.Backward);
CharacterHit sourceCharacterHit = new CharacterHit(position.Offset, 0);
CharacterHit backspaceCharacterHit;
using (TextBoxLine line = GetFormattedLine(lineIndex))
{
backspaceCharacterHit = line.GetBackspaceCaretCharacterHit(sourceCharacterHit);
}
LogicalDirection logicalDirection;
if (backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength == _lineMetrics[lineIndex].Offset)
{
// Going backward brought us to the start of a line, context must be backward for previous line
if (lineIndex == 0)
{
// First line, so we will stay forward.
logicalDirection = LogicalDirection.Forward;
}
else
{
logicalDirection = LogicalDirection.Backward;
}
}
else
{
logicalDirection = (backspaceCharacterHit.TrailingLength > 0) ? LogicalDirection.Backward : LogicalDirection.Forward;
}
ITextPointer backspaceUnitPosition = _host.TextContainer.CreatePointerAtOffset(backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength, logicalDirection);
backspaceUnitPosition.Freeze();
return backspaceUnitPosition;
}
示例7: if
/// <summary>
/// <see cref="ITextView.GetNextCaretUnitPosition"/>
/// </summary>
ITextPointer ITextView.GetNextCaretUnitPosition(ITextPointer position, LogicalDirection direction)
{
Invariant.Assert(this.IsLayoutValid);
Invariant.Assert(Contains(position));
// Special case document start/end.
if (position.Offset == 0 && direction == LogicalDirection.Backward)
{
return position.GetFrozenPointer(LogicalDirection.Forward);
}
else if (position.Offset == _host.TextContainer.SymbolCount && direction == LogicalDirection.Forward)
{
return position.GetFrozenPointer(LogicalDirection.Backward);
}
int lineIndex = GetLineIndexFromPosition(position);
CharacterHit sourceCharacterHit = new CharacterHit(position.Offset, 0);
CharacterHit nextCharacterHit;
using (TextBoxLine line = GetFormattedLine(lineIndex))
{
if (direction == LogicalDirection.Forward)
{
// Get the next caret position from the line
nextCharacterHit = line.GetNextCaretCharacterHit(sourceCharacterHit);
}
else
{
// Get previous caret position from the line
nextCharacterHit = line.GetPreviousCaretCharacterHit(sourceCharacterHit);
}
}
// Determine logical direction for next caret index and create TextPointer from it.
LogicalDirection logicalDirection;
if (nextCharacterHit.FirstCharacterIndex + nextCharacterHit.TrailingLength == _lineMetrics[lineIndex].EndOffset &&
direction == LogicalDirection.Forward)
{
// Going forward brought us to the end of a line, context must be forward for next line.
if (lineIndex == _lineMetrics.Count - 1)
{
// Last line so context must stay backward.
logicalDirection = LogicalDirection.Backward;
}
else
{
logicalDirection = LogicalDirection.Forward;
}
}
else if (nextCharacterHit.FirstCharacterIndex + nextCharacterHit.TrailingLength == _lineMetrics[lineIndex].Offset &&
direction == LogicalDirection.Backward)
{
// Going backward brought us to the start of a line, context must be backward for previous line.
if (lineIndex == 0)
{
// First line, so we will stay forward.
logicalDirection = LogicalDirection.Forward;
}
else
{
logicalDirection = LogicalDirection.Backward;
}
}
else
{
logicalDirection = (nextCharacterHit.TrailingLength > 0) ? LogicalDirection.Backward : LogicalDirection.Forward;
}
ITextPointer nextCaretUnitPosition = _host.TextContainer.CreatePointerAtOffset(nextCharacterHit.FirstCharacterIndex + nextCharacterHit.TrailingLength, logicalDirection);
nextCaretUnitPosition.Freeze();
return nextCaretUnitPosition;
}
示例8: AdjustMovingPositionForSelectDownByLine
// Helper for OnSelectDownByLine. Updates the selection moving position
// during select down by line.
private static void AdjustMovingPositionForSelectDownByLine(TextEditor This, ITextPointer newMovingPosition, ITextPointer originalMovingPosition, double suggestedX)
{
int newComparedToOld = newMovingPosition.CompareTo(originalMovingPosition);
// Note: we compare orientations of equal positions to handle a case
// when original position was at the end of line (after its linebreak with backward orientation)
// as a result of Shift+End selection; and the new position is in the beginning of the next line,
// which is essentially the same position but oriented differently.
// In such a case the new position is good enough to go there.
// We certainly don't want to go to the end of the document in this case.
if (newComparedToOld > 0 || newComparedToOld == 0 && newMovingPosition.LogicalDirection != originalMovingPosition.LogicalDirection)
{
// We have another line in a given direction; move to it
// If the destination exactly preceeds a line break, expand to include
// the line break if we haven't reached our desired suggestedX.
if (TextPointerBase.IsNextToAnyBreak(newMovingPosition, LogicalDirection.Forward) ||
newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null)
{
double newPositionX = GetAbsoluteXOffset(This.TextView, newMovingPosition);
FlowDirection paragraphFlowDirection = GetScopingParagraphFlowDirection(newMovingPosition);
FlowDirection controlFlowDirection = This.UiScope.FlowDirection;
if ((paragraphFlowDirection == controlFlowDirection && newPositionX < suggestedX) ||
(paragraphFlowDirection != controlFlowDirection && newPositionX > suggestedX))
{
newMovingPosition = newMovingPosition.GetInsertionPosition(LogicalDirection.Forward);
newMovingPosition = newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward);
// If we're at the last Paragraph, move to document end to include
// the final paragraph break.
if (newMovingPosition == null)
{
newMovingPosition = originalMovingPosition.TextContainer.End;
}
newMovingPosition = newMovingPosition.GetFrozenPointer(LogicalDirection.Backward);
}
}
ExtendSelectionAndBringIntoView(newMovingPosition, This);
}
else
{
// Remember where we were so that we can return if a line up follows.
if (This._NextLineAdvanceMovingPosition == null)
{
This._NextLineAdvanceMovingPosition = originalMovingPosition;
This._IsNextLineAdvanceMovingPositionAtDocumentHead = false;
}
// No more lines in this direction. Move to end of current line.
newMovingPosition = GetPositionAtLineEnd(originalMovingPosition);
if (newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null)
{
// Move to the final implicit line at end-of-doc.
newMovingPosition = newMovingPosition.TextContainer.End;
}
ExtendSelectionAndBringIntoView(newMovingPosition, This);
}
}
示例9: SetCompositionPositions
// Set composition string to TextComposition.
internal void SetCompositionPositions(ITextPointer start, ITextPointer end, string text)
{
Invariant.Assert(start != null);
Invariant.Assert(end != null);
Invariant.Assert(text != null);
// We need to have another instances of TextPointer since we don't want to
// freeze original TextPointers.
_compositionStart = start.GetFrozenPointer(LogicalDirection.Backward);
_compositionEnd = end.GetFrozenPointer(LogicalDirection.Forward);
_resultStart = null;
_resultEnd = null;
this.Text = String.Empty;
this.CompositionText = text;
// We must cache integer offsets -- public listeners won't expect
// them to float like TextPointers if the document changes.
_offset = (_compositionStart == null) ? -1 : _compositionStart.Offset;
_length = (_compositionStart == null) ? -1 : _compositionStart.GetOffsetToPosition(_compositionEnd);
}