private static bool IsRightOf(this IMarkupPointer p1, IMarkupPointer p2)
        {
            int flag;

            p1.IsRightOf(p2, out flag);
            return(flag == NativeMethods.BOOL_TRUE);
        }
 public static bool compareLt(
     IMarkupPointer p1,
     IMarkupPointer p2)
 {
     int flag;
     p1.IsLeftOf(p2, out flag);
     return flag == NativeMethods.BOOL_TRUE;
 }
 public static bool compareGte(
     IMarkupPointer p1,
     IMarkupPointer p2)
 {
     int flag;
     p1.IsRightOfOrEqualTo(p2, out flag);
     return flag == NativeMethods.BOOL_TRUE;
 }
 public static bool CompareE(
     IMarkupPointer p1,
     IMarkupPointer p2)
 {
     int flag;
     p1.IsEqualTo(p2, out flag);
     return flag == NativeMethods.BOOL_TRUE;
 }
Exemple #5
0
        public static bool compareLt(
            IMarkupPointer p1,
            IMarkupPointer p2)
        {
            int flag;

            p1.IsLeftOf(p2, out flag);
            return(flag == NativeMethods.BOOL_TRUE);
        }
Exemple #6
0
        public static bool compareGte(
            IMarkupPointer p1,
            IMarkupPointer p2)
        {
            int flag;

            p1.IsRightOfOrEqualTo(p2, out flag);
            return(flag == NativeMethods.BOOL_TRUE);
        }
Exemple #7
0
        public static bool CompareE(
            IMarkupPointer p1,
            IMarkupPointer p2)
        {
            int flag;

            p1.IsEqualTo(p2, out flag);
            return(flag == NativeMethods.BOOL_TRUE);
        }
 public static void CheckSwap(ref IMarkupPointer mpStart, ref IMarkupPointer mpEnd)
 {
     if (mpStart.IsRightOf(mpEnd))
     {
         var tmp = mpStart;
         mpStart = mpEnd;
         mpEnd = tmp;
     }
 }
 public static void CheckSwap(ref IMarkupPointer mpStart, ref IMarkupPointer mpEnd)
 {
     if (mpStart.IsRightOf(mpEnd))
     {
         var tmp = mpStart;
         mpStart = mpEnd;
         mpEnd   = tmp;
     }
 }
        /// <summary>
        /// Gets the current selection.
        /// </summary>
        /// <param name="selectionMPStart">The selection MP start.</param>
        /// <param name="selectionMPEnd">The selection MP end.</param>
        public void GetCurrentSelection(
            out IMarkupPointer selectionMPStart,
            out IMarkupPointer selectionMPEnd)
        {
            // get markup container of the whole document.
            var mc = (IMarkupContainer)DomDocument;

            // get the markup services.
            var ms = (IMarkupServices)DomDocument;

            // create two markup pointers.
            ms.CreateMarkupPointer(out selectionMPStart);
            ms.CreateMarkupPointer(out selectionMPEnd);

            selectionMPStart.MoveToContainer(mc, NativeMethods.BOOL_TRUE);
            selectionMPEnd.MoveToContainer(mc, NativeMethods.BOOL_TRUE);

            // --
            // position start and end pointers around the current selection.

            IHTMLSelectionObject selection = DomDocument.selection;

            string st = selection.type.ToLowerInvariant();

            if (st == @"none")
            {
                var ds = (IDisplayServices)DomDocument;

                IHTMLCaret caret;
                ds.GetCaret(out caret);

                caret.MoveMarkupPointerToCaret(selectionMPStart);
                caret.MoveMarkupPointerToCaret(selectionMPEnd);

                // set gravity, as in "Introduction to Markup Services" in MSDN.
                selectionMPStart.SetGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);
            }
            else if (st == @"text")
            {
                // MoveToSelectionAnchor does only work with "text" selections.
                var selectionText = DomDocument.selection;

                var range = (IHTMLTxtRange)selectionText.createRange();

                ms.MovePointersToRange(range, selectionMPStart, selectionMPEnd);

                // swap if wrong direction.
                if (compareGt(selectionMPStart, selectionMPEnd))
                {
                    var tmp = selectionMPStart;
                    selectionMPStart = selectionMPEnd;
                    selectionMPEnd = tmp;
                }

                // set gravity, as in "Introduction to Markup Services" in MSDN.
                selectionMPStart.SetGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);
            }
            else if (st == @"control")
            {
                // MoveToSelectionAnchor does only work with "text" selections.
                var selectionControl = DomDocument.selection;

                var range = selectionControl.createRange()
                    as IHTMLControlRange;

                // Strangly, range was null sometimes.
                // E.g. when I resized a table (=control selection)
                // and then did an undo.
                if (range != null)
                {
                    if (range.length > 0)
                    {
                        var start = range.item(0);
                        var end = range.item(range.length - 1);

                        selectionMPStart.MoveAdjacentToElement(
                            start,
                            _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin);
                        selectionMPEnd.MoveAdjacentToElement(
                            end,
                            _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
                    }
                }
            }
            else
            {
                // is there yet another selection type?
                //Debug.Assert(false);
            }
        }
 private static bool IsRightOf(this IMarkupPointer p1, IMarkupPointer p2)
 {
     int flag;
     p1.IsRightOf(p2, out flag);
     return flag == NativeMethods.BOOL_TRUE;
 }
        public void GetCurrentSelection(
            out IMarkupPointer selectionMPStart,
            out IMarkupPointer selectionMPEnd)
        {
            if (!EverInitialized)
            {
                selectionMPStart = null;
                selectionMPEnd   = null;
                return;
            }

            // get markup container of the whole document.
            var mc = (IMarkupContainer)DomDocument;

            // get the markup services.
            var ms = (IMarkupServices)DomDocument;

            // create two markup pointers.
            ms.CreateMarkupPointer(out selectionMPStart);
            ms.CreateMarkupPointer(out selectionMPEnd);

            selectionMPStart.MoveToContainer(mc, NativeMethods.BOOL_TRUE);
            selectionMPEnd.MoveToContainer(mc, NativeMethods.BOOL_TRUE);

            // --
            // position start and end pointers around the current selection.

            var selection = DomDocument.selection;

            var st = selection.type.ToLowerInvariant();

            switch (st)
            {
            case @"none":
            {
                var ds = (IDisplayServices)DomDocument;

                IHTMLCaret caret;
                ds.GetCaret(out caret);

                caret.MoveMarkupPointerToCaret(selectionMPStart);
                caret.MoveMarkupPointerToCaret(selectionMPEnd);

                // Set gravity, as in "Introduction to Markup Services" in MSDN.
                // http://msdn.microsoft.com/en-us/library/bb508514(v=vs.85).aspx
                selectionMPStart.SetGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);
            }
            break;

            case @"text":
            {
                // MoveToSelectionAnchor does only work with "text" selections.
                var selectionText = DomDocument.selection;

                var range = (IHTMLTxtRange)selectionText.createRange();

                ms.MovePointersToRange(range, selectionMPStart, selectionMPEnd);

                // swap if wrong direction.
                if (compareGt(selectionMPStart, selectionMPEnd))
                {
                    var tmp = selectionMPStart;
                    selectionMPStart = selectionMPEnd;
                    selectionMPEnd   = tmp;
                }

                // Set gravity, as in "Introduction to Markup Services" in MSDN.
                // http://msdn.microsoft.com/en-us/library/bb508514(v=vs.85).aspx
                selectionMPStart.SetGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);
            }
            break;

            case @"control":
            {
                // MoveToSelectionAnchor does only work with "text" selections.
                var selectionControl = DomDocument.selection;

                var range = selectionControl.createRange() as IHTMLControlRange;

                // Strangly, range was null sometimes.
                // E.g. when I resized a table (=control selection)
                // and then did an undo.
                if (range?.length > 0)
                {
                    var start = range.item(0);
                    var end   = range.item(range.length - 1);

                    selectionMPStart.MoveAdjacentToElement(
                        start,
                        _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin);
                    selectionMPEnd.MoveAdjacentToElement(
                        end,
                        _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
                }
            }
            break;
            }
        }