Пример #1
0
        /// <summary>
        /// Returns true if the caret is currently positioned at the specified line position.
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        protected bool IsCaretAtLinePosition(LINE_POSITION position)
        {
            _DISPLAY_MOVEUNIT moveUnit;

            if (position == LINE_POSITION.START)
            {
                moveUnit = _DISPLAY_MOVEUNIT.DISPLAY_MOVEUNIT_CurrentLineStart;
            }
            else
            {
                moveUnit = _DISPLAY_MOVEUNIT.DISPLAY_MOVEUNIT_CurrentLineEnd;
            }
            IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document;
            IDisplayPointerRaw  displayPointer, displayPointer2;

            displayServices.CreateDisplayPointer(out displayPointer);
            displayServices.CreateDisplayPointer(out displayPointer2);
            IHTMLCaretRaw caret = GetCaret();

            caret.MoveDisplayPointerToCaret(displayPointer);
            displayPointer2.MoveToPointer(displayPointer);
            displayPointer2.MoveUnit(moveUnit, -1);
            bool areEqual;

            displayPointer2.IsEqualTo(displayPointer, out areEqual);
            return(areEqual);
        }
Пример #2
0
        protected bool IsCaretWithin(Rectangle clientRect)
        {
            IHTMLCaretRaw caret = GetCaret();
            POINT         p;

            caret.GetLocation(out p, true);

            Point pt = new Point(p.x, p.y);

            return(pt.X >= clientRect.X && pt.X <= clientRect.Right && pt.Y >= clientRect.Y && pt.Y <= clientRect.Bottom);
        }
Пример #3
0
 protected virtual void ResetForDocumentComplete()
 {
     htmlCaret = null;
     caretPositionDisplayPointer = null;
 }
 /// <summary>
 /// Positions a MarkupPointer at the specfied caret.
 /// </summary>
 /// <param name="caret"></param>
 /// <param name="p"></param>
 public void MoveMarkupPointerToCaret(IHTMLCaretRaw caret, MarkupPointer p)
 {
     caret.MoveMarkupPointerToCaret(p.PointerRaw);
 }
Пример #5
0
        /// <summary>
        /// Navigates the editor's caret to the next editable region.
        /// </summary>
        /// <param name="direction"></param>
        private bool MoveCaretToNextRegion(MOVE_DIRECTION direction)
        {
            IHTMLElement       nextRegion;
            _ELEMENT_ADJACENCY nextRegionAdjacency;
            bool preserveXLocation;

            if (direction == MOVE_DIRECTION.UP || direction == MOVE_DIRECTION.LEFT)
            {
                nextRegion          = PreviousEditableRegion;
                nextRegionAdjacency = _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd;
                preserveXLocation   = direction == MOVE_DIRECTION.UP;
            }
            else if (direction == MOVE_DIRECTION.DOWN || direction == MOVE_DIRECTION.RIGHT)
            {
                nextRegion          = NextEditableRegion;
                nextRegionAdjacency = _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin;
                preserveXLocation   = direction == MOVE_DIRECTION.DOWN;

                if (nextRegion == null)
                {
                    return(false);
                }

                MarkupPointer selectRegion = EditorContext.MarkupServices.CreateMarkupPointer(nextRegion, nextRegionAdjacency);
                MarkupContext mc           = selectRegion.Right(false);
                if (mc.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope && mc.Element is IHTMLElement3 && SmartContentSelection.SelectIfSmartContentElement(EditorContext, mc.Element) != null)
                {
                    return(true);
                }
            }
            else
            {
                throw new ArgumentException("Unsupported move direction detected: " + direction);
            }

            IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document;
            IDisplayPointerRaw  displayPointer;

            displayServices.CreateDisplayPointer(out displayPointer);
            IHTMLCaretRaw caret = GetCaret();

            caret.MoveDisplayPointerToCaret(displayPointer);

            ILineInfo lineInfo;

            displayPointer.GetLineInfo(out lineInfo);

            if (nextRegion != null)
            {
                MarkupPointer mp = EditorContext.MarkupServices.CreateMarkupPointer(nextRegion, nextRegionAdjacency);

                DisplayServices.TraceMoveToMarkupPointer(displayPointer, mp);
                try
                {
                    caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME);
                    if (preserveXLocation)
                    {
                        POINT caretLocation;
                        caret.GetLocation(out caretLocation, true);
                        caretLocation.x = lineInfo.x;
                        uint hitTestResults;
                        displayPointer.MoveToPoint(caretLocation, _COORD_SYSTEM.COORD_SYSTEM_GLOBAL, nextRegion, 0, out hitTestResults);
                        caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME);
                    }
                    //BEP: using this line causes scrolling	(nextRegion as IHTMLElement2).focus();
                    (nextRegion as IHTMLElement3).setActive();
                    return(true);
                }
                catch (Exception e)
                {
                    Debug.Fail("Unexpected exception in MoveCaretToNextRegion: " + e.ToString());
                }

                caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME);
            }
            return(false);
        }
Пример #6
0
 /// <summary>
 /// Positions a MarkupPointer at the specified caret.
 /// </summary>
 /// <param name="caret"></param>
 /// <param name="p"></param>
 public void MoveMarkupPointerToCaret(IHTMLCaretRaw caret, MarkupPointer p)
 {
     caret.MoveMarkupPointerToCaret(p.PointerRaw);
 }