本文整理汇总了C#中OpenLiveWriter.Mshtml.MarkupRange类的典型用法代码示例。如果您正苦于以下问题:C# MarkupRange类的具体用法?C# MarkupRange怎么用?C# MarkupRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MarkupRange类属于OpenLiveWriter.Mshtml命名空间,在下文中一共展示了MarkupRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToFormattedHtml
public static String ToFormattedHtml(MshtmlMarkupServices markupServices, MarkupRange bounds)
{
StringBuilder sb = new StringBuilder();
HtmlWriter xmlWriter = new HtmlWriter(sb);
PrintHtml(xmlWriter, markupServices, bounds);
return sb.ToString();
}
示例2: Init
private void Init(IHTMLDocument document, MshtmlMarkupServices markupServices, MarkupRange selectionRange, MarkupRangeFilter filter, DamageFunction damageFunction, bool expandRange)
{
// save references
this.htmlDocument = document;
this.markupServices = markupServices;
this.selectionRange = selectionRange;
this.filter = filter;
this.damageFunction = damageFunction;
// If the range is already the body, don't expand it or else it will be the whole document
if (expandRange)
ExpandRangeToWordBoundaries(selectionRange);
// initialize pointer to beginning of selection range
MarkupPointer wordStart = MarkupServices.CreateMarkupPointer(selectionRange.Start);
MarkupPointer wordEnd = MarkupServices.CreateMarkupPointer(selectionRange.Start);
//create the range for holding the current word.
//Be sure to set its gravity so that it stays around text that get replaced.
currentWordRange = MarkupServices.CreateMarkupRange(wordStart, wordEnd);
currentWordRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
currentWordRange.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
currentVirtualPosition = currentWordRange.End.Clone();
}
示例3: TypographicCharacterHandler
public TypographicCharacterHandler(MarkupRange currentSelection, InsertHtml insertHtml, IBlogPostImageEditingContext imageEditingContext, IHTMLElement postBodyElement, char c, string htmlText, MarkupPointer blockBoundary)
{
_currentSelection = currentSelection.Clone();
_currentSelection.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
_currentSelection.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
_insertHtml = insertHtml;
_imageEditingContext = imageEditingContext;
_postBodyElement = postBodyElement;
this.c = c;
this.htmlText = htmlText;
this.blockBoundary = blockBoundary;
}
示例4: PrintHtml
private static void PrintHtml(HtmlWriter writer, MshtmlMarkupServices MarkupServices, MarkupRange bounds)
{
//create a range to span a single position while walking the doc
MarkupRange range = MarkupServices.CreateMarkupRange();
range.Start.MoveToPointer(bounds.Start);
range.End.MoveToPointer(bounds.Start);
//create a context that can be reused while walking the document.
MarkupContext context = new MarkupContext();
//move the range.End to the right and print out each element along the way
range.End.Right(true, context);
while (context.Context != _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_None && range.Start.IsLeftOf(bounds.End))
{
string text = null;
if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_Text)
{
//if this is a text context, then get the text that is between the start and end points.
text = range.HtmlText;
//the range.HtmlText operation sometimes returns the outer tags for a text node,
//so we need to strip the tags.
//FIXME: if the Right/Left operations returned the available text value, this wouldn't be necessary.
if (text != null)
text = StripSurroundingTags(text);
}
else if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope)
{
string htmlText = range.HtmlText;
if (context.Element.innerHTML == null && htmlText != null && htmlText.IndexOf(" ") != -1)
{
//HACK: Under these conditions, there was a was an invisible NBSP char in the
//document that is not detectable by walking through the document with MarkupServices.
//So, we force the text of the element to be the char to ensure that the
//whitespace that was visible in the editor is visible in the final document.
text = " ";
}
}
//print the context.
printContext(writer, context, text, range);
//move the start element to the spot where the end currently is so tht there is
//only ever a single difference in position
range.Start.MoveToPointer(range.End);
//move the end to the next position
range.End.Right(true, context);
}
}
示例5: ApplyBlockStyle
private void ApplyBlockStyle(_ELEMENT_TAG_ID styleTagId, MarkupRange selection, MarkupRange maximumBounds, MarkupRange postOpSelection)
{
Debug.Assert(selection != maximumBounds, "selection and maximumBounds must be distinct objects");
SelectionPositionPreservationCookie selectionPreservationCookie = null;
//update the range cling and gravity so it will stick with the re-arranged block content
selection.Start.PushCling(false);
selection.Start.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Left);
selection.End.PushCling(false);
selection.End.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);
try
{
if (selection.IsEmpty())
{
//nothing is selected, so expand the selection to cover the entire parent block element
IHTMLElementFilter stopFilter =
ElementFilters.CreateCompoundElementFilter(ElementFilters.BLOCK_ELEMENTS,
new IHTMLElementFilter(IsSplitStopElement));
MovePointerLeftUntilRegionBreak(selection.Start, stopFilter, maximumBounds.Start);
MovePointerRightUntilRegionBreak(selection.End, stopFilter, maximumBounds.End);
}
using (IUndoUnit undo = _editor.CreateSelectionUndoUnit(selection))
{
selectionPreservationCookie = SelectionPositionPreservationHelper.Save(_markupServices, postOpSelection, selection);
if (selection.IsEmptyOfContent())
{
ApplyBlockFormatToEmptySelection(selection, styleTagId, maximumBounds);
}
else
{
ApplyBlockFormatToContentSelection(selection, styleTagId, maximumBounds);
}
undo.Commit();
}
}
finally
{
selection.Start.PopCling();
selection.Start.PopGravity();
selection.End.PopCling();
selection.End.PopGravity();
}
if (!SelectionPositionPreservationHelper.Restore(selectionPreservationCookie, selection, selection.Clone()))
selection.ToTextRange().select();
}
示例6: KeepSourceFormatting
public KeepSourceFormatting(MarkupRange sourceRange, MarkupRange destinationRange)
{
Debug.Assert(sourceRange.Start.Container.GetOwningDoc() == destinationRange.Start.Container.GetOwningDoc(),
"Ranges must share an owning document!");
if (sourceRange == null)
{
throw new ArgumentNullException("sourceRange");
}
if (!sourceRange.Positioned)
{
throw new ArgumentException("sourceRange must be positioned.");
}
if (sourceRange.Start.IsRightOf(sourceRange.End))
{
throw new ArgumentException("sourceRange start must be before range end.");
}
if (destinationRange == null)
{
throw new ArgumentNullException("destinationRange");
}
if (!destinationRange.Positioned)
{
throw new ArgumentException("destinationRange must be positioned.");
}
if (destinationRange.Start.IsRightOf(destinationRange.End))
{
throw new ArgumentException("destinationRange start must be before range end.");
}
this.sourceDocument = sourceRange.Start.Container.Document;
this.sourceMarkupServices = new MshtmlMarkupServices((IMarkupServicesRaw)this.sourceDocument);
this.sourceRange = sourceRange.Clone();
this.sourceRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
this.sourceRange.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
this.destinationDocument = destinationRange.Start.Container.Document;
this.destinationMarkupServices = new MshtmlMarkupServices((IMarkupServicesRaw)this.destinationDocument);
this.destinationRange = destinationRange.Clone();
this.destinationRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
this.destinationRange.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
}
示例7: OleUndoUnit
public OleUndoUnit(MshtmlMarkupServices markupServices, MarkupRange selection)
{
_markupServices = markupServices;
//serialize the current position of the markup pointers so that they can be restored if
//the DOM gets rolled back into the same state via an undo/redo operation.
if (selection != null && selection.Positioned)
{
IMarkupPointer2Raw pointer2StartRaw = selection.Start.PointerRaw as IMarkupPointer2Raw;
IMarkupPointer2Raw pointer2EndRaw = selection.End.PointerRaw as IMarkupPointer2Raw;
pointer2StartRaw.GetMarkupPosition(out _startPosition);
pointer2EndRaw.GetMarkupPosition(out _endPosition);
pointer2StartRaw.GetContainer(out _markupContainer);
}
_description = "OleUndoUnit" + Guid.NewGuid().ToString();
Undo = true;
}
示例8: TableSelection
public TableSelection(MarkupRange markupRange)
{
// calculate the begin and end cells
IHTMLTableCell beginCell;
IHTMLTableCell endCell;
ArrayList selectedCells;
FindCellRange(markupRange, out selectedCells, out beginCell, out endCell);
// see if the two cells have a single containing table
IHTMLTable table = GetSelectedTable(beginCell, endCell, markupRange) as IHTMLTable;
// if we have a table then calculate the rest of our states
if (table != null)
{
// validate the table selection
if (ValidateTableSelection(table, markupRange, out _entireTableSelected))
{
_table = table;
_beginCell = beginCell;
_endCell = endCell;
// filter selected cells to only include direct descendents of this table (no
// cells from nested tables)
_selectedCells = new ArrayList();
foreach (IHTMLElement cell in selectedCells)
if (HTMLElementHelper.ElementsAreEqual(TableHelper.GetContainingTableElement(cell) as IHTMLElement, _table as IHTMLElement))
_selectedCells.Add(cell);
_hasContiguousSelection = !HTMLElementHelper.ElementsAreEqual(_beginCell as IHTMLElement, _endCell as IHTMLElement);
_beginRow = GetContainingRowForCell(beginCell);
_endRow = GetContainingRowForCell(endCell);
_beginColumn = new HTMLTableColumn(_table, beginCell);
_endColumn = new HTMLTableColumn(_table, endCell);
}
}
}
示例9: GetSelectedChildEditField
public static IHTMLElement GetSelectedChildEditField(IHTMLElement parent, MarkupRange selection)
{
if (selection == null || !selection.Positioned)
{
Trace.Fail("Selection is invalid!");
return null;
}
IHTMLElement element = selection.ParentElement();
if (element == null || !HTMLElementHelper.IsChildOrSameElement(parent, element))
return null;
do
{
if (InlineEditField.IsEditField(element))
return element;
element = element.parentElement;
} while (element != null && element.sourceIndex != parent.sourceIndex);
return null;
}
示例10: GetParentContainerBlockWidth
public static int GetParentContainerBlockWidth(MarkupRange markupRange)
{
IHTMLElement2 parentBlock = markupRange.Start.GetParentElement(ElementFilters.BLOCK_OR_TABLE_CELL_ELEMENTS) as IHTMLElement2;
if (parentBlock != null)
{
// TODO: we would like to always clientWidth here however for an empty block element this will
// be zero. So in this case we use scrollWidth which should be a proxy except in the case where
// the parent element has a horizontal scroll bar (in which case we may insert a table which
// is worst case too narrow). What we "should" do is insert and remove some bogus content
// within the block elemet to force its clientWidth to the right value.
int blockWidth = parentBlock.clientWidth;
if (blockWidth == 0)
blockWidth = parentBlock.scrollWidth;
return blockWidth;
}
else
{
return 0;
}
}
示例11: ApplyBlockFormatToContentSelection
private void ApplyBlockFormatToContentSelection(MarkupRange selection, _ELEMENT_TAG_ID styleTagId, MarkupRange maximumBounds)
{
MarkupRange[] stylableBlockRegions = GetSelectableBlockRegions(selection);
if (stylableBlockRegions.Length > 0)
{
//
// We want to make sure that the selection reflects only the
// blocks that were changed. Unposition the start and end
// pointers and then make sure they cover the stylable block
// regions, no more, no less.
selection.Start.Unposition();
selection.End.Unposition();
foreach (MarkupRange range in stylableBlockRegions)
{
ApplyBlockStyleToRange(styleTagId, range, maximumBounds);
if (!selection.Start.Positioned || range.Start.IsLeftOf(selection.Start))
selection.Start.MoveToPointer(range.Start);
if (!selection.End.Positioned || range.End.IsRightOf(selection.End))
selection.End.MoveToPointer(range.End);
}
}
}
示例12: FixupSegment
public FixupSegment(MarkupRange rangeToFixup, TextStyle sourceTextStyle)
{
if (rangeToFixup == null)
{
throw new ArgumentNullException("rangeToFixup");
}
if (!rangeToFixup.Positioned)
{
throw new ArgumentException("rangeToFixup must be positioned!");
}
if (sourceTextStyle == null)
{
throw new ArgumentNullException("sourceTextStyle");
}
SourceTextStyle = sourceTextStyle;
RangeToFixup = rangeToFixup.Clone();
// We want the RangeToFixup to stick with the text its wrapped around.
RangeToFixup.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
RangeToFixup.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
}
示例13: ExpandDamageToPreviousWord
private void ExpandDamageToPreviousWord(MarkupRange damageRange)
{
MarkupRange previousWordRange = damageRange.Clone();
previousWordRange.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_PREVWORDBEGIN);
// If we were already at the first word in the document, moving to the previous word would have put the
// MarkupPointer outside the body element.
if (previousWordRange.Start.GetParentElement(ElementFilters.BODY_ELEMENT) != null)
{
previousWordRange.Collapse(true);
previousWordRange.End.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_NEXTWORDEND);
if (!previousWordRange.IsEmpty() && !_editorControl.IgnoreRangeForSpellChecking(previousWordRange))
{
damageRange.Start.MoveToPointer(previousWordRange.Start);
}
}
}
示例14: ExpandDamageToAdjacentWords
private void ExpandDamageToAdjacentWords(MarkupRange damageRange)
{
ExpandDamageToPreviousWord(damageRange);
ExpandDamageToNextWord(damageRange);
}
示例15: Reset
public void Reset()
{
damageQueue.Clear();
_wordHelper = new MarkupServicesWordHelper(_mshtmlEditor.MshtmlControl.MarkupServices);
_currentSelectionDamage = _mshtmlEditor.MshtmlControl.MarkupServices.CreateMarkupRange();
_currentSelectionDamage.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
_currentSelectionDamage.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;
}