Exemple #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);
        }
Exemple #2
0
        protected IHTMLCaretRaw GetCaret()
        {
            IHTMLCaretRaw       caret;
            IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document;

            displayServices.GetCaret(out caret);
            return(caret);
        }
 public SpellingHighlighter(ISpellingChecker spellingChecker, IHighlightRenderingServicesRaw highlightRenderingServices,
                            IDisplayServicesRaw displayServices, IMarkupServicesRaw markupServices, IHTMLDocument4 htmlDocument)
 {
     _spellingChecker = spellingChecker;
     _highlightRenderingServices = highlightRenderingServices;
     _displayServices = displayServices;
     _markupServicesRaw = markupServices;
     _markupServices = new MshtmlMarkupServices(_markupServicesRaw);
     _htmlDocument = htmlDocument;
     _tracker = new HighlightSegmentTracker();
     //the timer to handle interleaving of spell ghecking
     _timer = new SpellingTimer(TIMER_INTERVAL);
     _timer.Start();
     _timer.Tick += new EventHandler(_timer_Tick);
     _workerQueue = new Queue();
 }
 public SpellingHighlighter(ISpellingChecker spellingChecker, IHighlightRenderingServicesRaw highlightRenderingServices,
                            IDisplayServicesRaw displayServices, IMarkupServicesRaw markupServices, IHTMLDocument4 htmlDocument)
 {
     _spellingChecker            = spellingChecker;
     _highlightRenderingServices = highlightRenderingServices;
     _displayServices            = displayServices;
     _markupServicesRaw          = markupServices;
     _markupServices             = new MshtmlMarkupServices(_markupServicesRaw);
     _htmlDocument = htmlDocument;
     _tracker      = new HighlightSegmentTracker();
     //the timer to handle interleaving of spell checking
     _timer = new SpellingTimer(TIMER_INTERVAL);
     _timer.Start();
     _timer.Tick += new EventHandler(_timer_Tick);
     _workerQueue = new Queue();
 }
Exemple #5
0
        private bool ShouldNavigateOutOfEditField(IHTMLElement selectedEditField, Keys keyCode)
        {
            Debug.Assert(keyCode == Keys.Up || keyCode == Keys.Down);

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

            IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document;
            MarkupRange         editFieldRange  = EditorContext.MarkupServices.CreateMarkupRange(selectedEditField, false);
            // If we're navigating up, then position a display pointer on the top line.
            // If we're going down, then position a display pointer on the bottom line.
            IDisplayPointerRaw displayPointer;

            displayServices.CreateDisplayPointer(out displayPointer);
            DisplayServices.TraceMoveToMarkupPointer(displayPointer, keyCode == Keys.Up ? editFieldRange.Start : editFieldRange.End);

            // Now determine if the display pointer is in the top/bottom line rect.
            return(IsCaretWithin(GetLineRect(selectedEditField, displayPointer)));
        }
Exemple #6
0
        public TextStyles(MarkupPointer markupPointer)
        {
            if (markupPointer == null)
            {
                throw new ArgumentNullException("markupPointer");
            }

            if (!markupPointer.Positioned)
            {
                throw new ArgumentException("markupPointer must be positioned.");
            }

            IHTMLDocument2      document        = markupPointer.Container.Document;
            IDisplayServicesRaw displayServices = (IDisplayServicesRaw)document;
            IHTMLComputedStyle  computedStyle;

            displayServices.GetComputedStyle(markupPointer.PointerRaw, out computedStyle);

            MarkupPointer = markupPointer;
            ComputedStyle = computedStyle;
        }
Exemple #7
0
        /// <summary>
        /// Returns the bounds of line that the pointer is positioned within in client-based coordinates.
        /// </summary>
        /// <param name="pointer"></param>
        /// <returns></returns>
        protected Rectangle GetLineClientRectangle(MarkupPointer pointer)
        {
            //getting the line associated with a pointer is a little complicated because the
            //ILineInfo for the pointer position only returns information based on the font
            //exactly at that position.  It does not take the max font height of the line into
            //account, so we need to that manually.  To do this, we get the LineInfo at each
            //point in the line where the line height may change by moving a markup pointer
            //in to each element declared on the line.

            IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document;

            //position a display pointer on the same line as the markup pointer
            IDisplayPointerRaw displayPointer;

            displayServices.CreateDisplayPointer(out displayPointer);
            DisplayServices.TraceMoveToMarkupPointer(displayPointer, pointer);

            //position a markup pointer at the end of the line
            MarkupPointer pLineEnd = pointer.Clone();

            displayPointer.MoveUnit(_DISPLAY_MOVEUNIT.DISPLAY_MOVEUNIT_CurrentLineEnd, 0);
            displayPointer.PositionMarkupPointer(pLineEnd.PointerRaw);

            //position a markup pointer at the start of the line
            MarkupPointer pLineStart = pointer.Clone();

            displayPointer.MoveUnit(_DISPLAY_MOVEUNIT.DISPLAY_MOVEUNIT_CurrentLineStart, 0);
            displayPointer.PositionMarkupPointer(pLineStart.PointerRaw);

            //calculate the maximum rectangle taken up by any text on this line by walking
            //the lineStart pointer to the lineEnd pointer and calculating a max rectangle
            //at each step.
            Rectangle lineRect = GetLineRect(HTMLElement, displayPointer);

            pLineStart.Right(true);
            while (pLineStart.IsLeftOfOrEqualTo(pLineEnd))
            {
                Rectangle dpLineRect;
                try
                {
                    displayPointer.MoveToMarkupPointer(pLineStart.PointerRaw, null);
                    dpLineRect = GetLineRect(HTMLElement, displayPointer);
                }
                catch (COMException e)
                {
                    if (e.ErrorCode == IE_CTL_E.INVALIDLINE)
                    {
                        // http://msdn.microsoft.com/en-us/library/aa752674(VS.85).aspx
                        // IDisplayPointer::MoveToMarkupPointer will return an error (CTL_E_INVALIDLINE),
                        // if the markup pointer is in a line whose nearest layout element *is not a flow layout element*.
                        dpLineRect = GetLineRect(pLineStart.CurrentScope);

                        // We also want to skip past the entire current scope...
                        pLineStart.MoveAdjacentToElement(pLineStart.CurrentScope, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd);
                    }
                    else
                    {
                        Trace.Fail("Exception thrown in GetLineClientRectangle: " + e.ToString());
                        throw;
                    }
                }

                lineRect.Y = Math.Min(dpLineRect.Y, lineRect.Y);
                if (lineRect.Bottom < dpLineRect.Bottom)
                {
                    lineRect.Height += dpLineRect.Bottom - lineRect.Bottom;
                }

                pLineStart.Right(true);
            }

            //return the line rectangle
            return(lineRect);
        }
Exemple #8
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);
        }