GetLastHit() public method

public GetLastHit ( ) : HitInfo
return HitInfo
Example #1
0
        void SetupStartHitPoint(CssBoxHitChain startChain, ITextService textService)
        {
            //find global location of start point
            HitInfo startHit = startChain.GetLastHit();

            //-----------------------------
            _startHitRun          = null;
            _startHitRunCharIndex = 0;
            switch (startHit.hitObjectKind)
            {
            case HitObjectKind.Run:
            {
                CssRun run = (CssRun)startHit.hitObject;
                //-------------------------------------------------------
                int sel_index;
                int sel_offset;
                run.FindSelectionPoint(textService,
                                       startHit.localX,
                                       out sel_index,
                                       out sel_offset);
                _startHitRunCharIndex = sel_index;
                //modify hitpoint
                _startHitHostLine = (CssLineBox)startChain.GetHitInfo(startChain.Count - 2).hitObject;
                _startLineBeginSelectionAtPixel = (int)(run.Left + sel_offset);
                _startHitRun = run;
            }
            break;

            case HitObjectKind.LineBox:
            {
                _startHitHostLine = (CssLineBox)startHit.hitObject;
                _startLineBeginSelectionAtPixel = startHit.localX;
                //make global
            }
            break;

            case HitObjectKind.CssBox:
            {
                CssBox box = (CssBox)startHit.hitObject;
                //find first nearest line at point
                CssLineBox startHitLine = FindNearestLine(box, startChain.RootGlobalY, 5);
                _startLineBeginSelectionAtPixel = 0;
                if (startHitLine != null)
                {
                    _startHitHostLine = startHitLine;
                }
                else
                {
                    //if not found?
                    _startHitHostLine = null;
                }
            }
            break;

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Example #2
0
        static bool IsOnTheSameLine(CssBoxHitChain startChain, CssBoxHitChain endChain)
        {
            CssLineBox startLineBox = GetLine(startChain.GetLastHit());
            CssLineBox endLineBox   = GetLine(endChain.GetLastHit());

            return(startLineBox != null && startLineBox == endLineBox);
        }
Example #3
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, ITextService textService)
        {
            //find global location of end point
            HitInfo    endHit        = endChain.GetLastHit();
            int        xposOnEndLine = 0;
            CssLineBox endline       = null;

            //find endline first
            _endHitRunCharIndex = 0;
            _endHitRun          = null;
            switch (endHit.hitObjectKind)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case HitObjectKind.Run:
            {
                CssRun endRun = (CssRun)endHit.hitObject;
#if DEBUG
                //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                //{
                //}
                if (endHit.localX > 23)
                {
                }
                System.Diagnostics.Debug.WriteLine(endHit.localX);
#endif
                endRun.FindSelectionPoint(textService,
                                          endHit.localX,
                                          out int run_sel_index,
                                          out int run_sel_offset);
                endline             = endRun.HostLine;
                xposOnEndLine       = (int)(endRun.Left + run_sel_offset);
                _endHitRunCharIndex = run_sel_index;

#if DEBUG
                System.Diagnostics.Debug.WriteLine(_endHitRunCharIndex);
#endif
                _endHitRun = endRun;
            }
            break;

            case HitObjectKind.LineBox:
            {
                endline       = (CssLineBox)endHit.hitObject;
                xposOnEndLine = endHit.localX;
            }
            break;

            case HitObjectKind.CssBox:
            {
                CssBox hitBox = (CssBox)endHit.hitObject;
                endline       = FindNearestLine(hitBox, endChain.RootGlobalY, 5);
                xposOnEndLine = endHit.localX;
            }
            break;
            }

#if DEBUG
            if (xposOnEndLine == 0)
            {
            }
#endif

            //----------------------------------
            _selectedLines = new List <CssLineBox>();
            if (_startHitHostLine == endline)
            {
                _selectedLines.Add(endline);
                _startHitHostLine.Select(_startLineBeginSelectionAtPixel, xposOnEndLine,
                                         _startHitRun, _startHitRunCharIndex,
                                         _endHitRun, _endHitRunCharIndex);
                return; //early exit here ***
            }
            //----------------------------------
            //select on different line
            LineWalkVisitor lineWalkVisitor = null;

            if (FindCommonGround(startChain, endChain, out int breakAtLevel) && breakAtLevel > 0)
            {
                CssBlockRun hitBlockRun = endChain.GetHitInfo(breakAtLevel).hitObject as CssBlockRun;
                //multiple select
                //1. first part
                if (hitBlockRun != null)
                {
                    _startHitHostLine.Select(_startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                                             _startHitRun, _startHitRunCharIndex,
                                             _endHitRun, _endHitRunCharIndex);
                    _selectedLines.Add(_startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    _startHitHostLine.SelectPartialToEnd(_startLineBeginSelectionAtPixel, _startHitRun, _startHitRunCharIndex);
                    _selectedLines.Add(_startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(_startHitHostLine);
                }
            }
            else
            {
                _startHitHostLine.SelectPartialToEnd(_startLineBeginSelectionAtPixel, _startHitRun, _startHitRunCharIndex);
                _selectedLines.Add(_startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(_startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);

#if DEBUG
            int dbugExpectedId = 1;
#endif
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
#if DEBUG
                //System.Diagnostics.Debug.WriteLine("sel:" + linebox.dbugId);
                if (dbugExpectedId != linebox.dbugId)
                {
                }
                dbugExpectedId++;
#endif
                switch (lineCoverage)
                {
                case LineCoverage.EndLine:
                    {
                        //found end line
                        linebox.SelectPartialFromStart(xposOnEndLine, _endHitRun, _endHitRunCharIndex);
                        _selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.PartialLine:
                    {
                        linebox.SelectPartialFromStart((int)partialLineRun.Right, _endHitRun, _endHitRunCharIndex);
                        _selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.FullLine:
                    {
                        //check if hitpoint is in the line area
                        linebox.SelectFull();
                        _selectedLines.Add(linebox);
                    }
                    break;
                }
            });
        }
Example #4
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, ITextService ifonts)
        {
            //find global location of end point
            HitInfo    endHit         = endChain.GetLastHit();
            int        xposOnEndLine  = 0;
            CssLineBox endline        = null;
            int        run_sel_offset = 0;

            //find endline first
            this.endHitRunCharIndex = 0;
            this.endHitRun          = null;
            switch (endHit.hitObjectKind)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case HitObjectKind.Run:
            {
                CssRun endRun = (CssRun)endHit.hitObject;
                //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                //{
                //}

                int run_sel_index;
                endRun.FindSelectionPoint(ifonts,
                                          endHit.localX,
                                          out run_sel_index,
                                          out run_sel_offset);
                endline                 = endRun.HostLine;
                xposOnEndLine           = (int)(endRun.Left + run_sel_offset);
                this.endHitRunCharIndex = run_sel_index;
                this.endHitRun          = endRun;
            }
            break;

            case HitObjectKind.LineBox:
            {
                endline       = (CssLineBox)endHit.hitObject;
                xposOnEndLine = endHit.localX;
            }
            break;

            case HitObjectKind.CssBox:
            {
                CssBox hitBox = (CssBox)endHit.hitObject;
                endline       = FindNearestLine(hitBox, endChain.RootGlobalY, 5);
                xposOnEndLine = endHit.localX;
            }
            break;
            }

#if DEBUG
            if (xposOnEndLine == 0)
            {
            }
#endif

            //----------------------------------
            this.selectedLines = new List <CssLineBox>();
            if (startHitHostLine == endline)
            {
                this.selectedLines.Add(endline);
                startHitHostLine.Select(startLineBeginSelectionAtPixel, xposOnEndLine,
                                        this.startHitRun, this.startHitRunCharIndex,
                                        this.endHitRun, this.endHitRunCharIndex);
                return; //early exit here ***
            }
            //----------------------------------
            //select on different line
            LineWalkVisitor lineWalkVisitor = null;
            int             breakAtLevel;
            if (FindCommonGround(startChain, endChain, out breakAtLevel) && breakAtLevel > 0)
            {
                var hit1        = endChain.GetHitInfo(breakAtLevel).hitObject;
                var hitBlockRun = hit1 as CssBlockRun;
                //multiple select
                //1. first part
                if (hitBlockRun != null)
                {
                    startHitHostLine.Select(startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                                            this.startHitRun, this.startHitRunCharIndex,
                                            this.endHitRun, this.endHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
                }
            }
            else
            {
                startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                selectedLines.Add(this.startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
                switch (lineCoverage)
                {
                case LineCoverage.EndLine:
                    {
                        //found end line
                        linebox.SelectPartialFromStart(xposOnEndLine, this.endHitRun, this.endHitRunCharIndex);
                        selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.PartialLine:
                    {
                        linebox.SelectPartialFromStart((int)partialLineRun.Right, this.endHitRun, this.endHitRunCharIndex);
                        selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.FullLine:
                    {
                        //check if hitpoint is in the line area
                        linebox.SelectFull();
                        selectedLines.Add(linebox);
                    }
                    break;
                }
            });
        }
Example #5
0
 static bool IsOnTheSameLine(CssBoxHitChain startChain, CssBoxHitChain endChain)
 {
     CssLineBox startLineBox = GetLine(startChain.GetLastHit());
     CssLineBox endLineBox = GetLine(endChain.GetLastHit());
     return startLineBox != null && startLineBox == endLineBox;
 }
Example #6
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, IFonts ifonts)
        {
            //find global location of end point 
            HitInfo endHit = endChain.GetLastHit();
            int xposOnEndLine = 0;
            CssLineBox endline = null;
            int run_sel_offset = 0;
            //find endline first
            this.endHitRunCharIndex = 0;
            this.endHitRun = null;
            switch (endHit.hitObjectKind)
            {
                default:
                    {
                        throw new NotSupportedException();
                    }
                case HitObjectKind.Run:
                    {
                        CssRun endRun = (CssRun)endHit.hitObject;
                        //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                        //{
                        //}

                        int run_sel_index;
                        endRun.FindSelectionPoint(ifonts,
                             endHit.localX,
                             out run_sel_index,
                             out run_sel_offset);
                        endline = endRun.HostLine;
                        xposOnEndLine = (int)(endRun.Left + run_sel_offset);
                        this.endHitRunCharIndex = run_sel_index;
                        this.endHitRun = endRun;
                    }
                    break;
                case HitObjectKind.LineBox:
                    {
                        endline = (CssLineBox)endHit.hitObject;
                        xposOnEndLine = endHit.localX;
                    }
                    break;
                case HitObjectKind.CssBox:
                    {
                        CssBox hitBox = (CssBox)endHit.hitObject;
                        endline = FindNearestLine(hitBox, endChain.RootGlobalY, 5);
                        xposOnEndLine = endHit.localX;
                    }
                    break;
            }

#if DEBUG
            if (xposOnEndLine == 0)
            {
            }
#endif

            //----------------------------------
            this.selectedLines = new List<CssLineBox>();
            if (startHitHostLine == endline)
            {
                this.selectedLines.Add(endline);
                startHitHostLine.Select(startLineBeginSelectionAtPixel, xposOnEndLine,
                        this.startHitRun, this.startHitRunCharIndex,
                        this.endHitRun, this.endHitRunCharIndex);
                return; //early exit here ***
            }
            //---------------------------------- 
            //select on different line 
            LineWalkVisitor lineWalkVisitor = null;
            int breakAtLevel;
            if (FindCommonGround(startChain, endChain, out breakAtLevel) && breakAtLevel > 0)
            {
                var hit1 = endChain.GetHitInfo(breakAtLevel).hitObject;
                var hitBlockRun = hit1 as CssBlockRun;
                //multiple select 
                //1. first part        
                if (hitBlockRun != null)
                {
                    startHitHostLine.Select(startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                     this.startHitRun, this.startHitRunCharIndex,
                     this.endHitRun, this.endHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                    selectedLines.Add(this.startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
                }
            }
            else
            {
                startHitHostLine.SelectPartialToEnd(startLineBeginSelectionAtPixel, this.startHitRun, this.startHitRunCharIndex);
                selectedLines.Add(this.startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
                switch (lineCoverage)
                {
                    case LineCoverage.EndLine:
                        {
                            //found end line  
                            linebox.SelectPartialFromStart(xposOnEndLine, this.endHitRun, this.endHitRunCharIndex);
                            selectedLines.Add(linebox);
                        }
                        break;
                    case LineCoverage.PartialLine:
                        {
                            linebox.SelectPartialFromStart((int)partialLineRun.Right, this.endHitRun, this.endHitRunCharIndex);
                            selectedLines.Add(linebox);
                        }
                        break;
                    case LineCoverage.FullLine:
                        {
                            //check if hitpoint is in the line area
                            linebox.SelectFull();
                            selectedLines.Add(linebox);
                        }
                        break;
                }
            });
        }
Example #7
0
 void SetupStartHitPoint(CssBoxHitChain startChain, IFonts ifonts)
 {
     //find global location of start point
     HitInfo startHit = startChain.GetLastHit();
     //-----------------------------
     this.startHitRun = null;
     this.startHitRunCharIndex = 0;
     switch (startHit.hitObjectKind)
     {
         case HitObjectKind.Run:
             {
                 CssRun run = (CssRun)startHit.hitObject;
                 //-------------------------------------------------------
                 int sel_index;
                 int sel_offset;
                 run.FindSelectionPoint(ifonts,
                      startHit.localX,
                      out sel_index,
                      out sel_offset);
                 this.startHitRunCharIndex = sel_index;
                 //modify hitpoint
                 this.startHitHostLine = (CssLineBox)startChain.GetHitInfo(startChain.Count - 2).hitObject;
                 this.startLineBeginSelectionAtPixel = (int)(run.Left + sel_offset);
                 this.startHitRun = run;
             }
             break;
         case HitObjectKind.LineBox:
             {
                 this.startHitHostLine = (CssLineBox)startHit.hitObject;
                 this.startLineBeginSelectionAtPixel = startHit.localX;
                 //make global            
             }
             break;
         case HitObjectKind.CssBox:
             {
                 CssBox box = (CssBox)startHit.hitObject;
                 //find first nearest line at point   
                 CssLineBox startHitLine = FindNearestLine(box, startChain.RootGlobalY, 5);
                 this.startLineBeginSelectionAtPixel = 0;
                 if (startHitLine != null)
                 {
                     this.startHitHostLine = startHitLine;
                 }
                 else
                 {
                     //if not found?
                     this.startHitHostLine = null;
                 }
             }
             break;
         default:
             {
                 throw new NotSupportedException();
             }
     }
 }