Ejemplo n.º 1
0
        public void PointToChar(int ichBase, IVwGraphics vg, Rect rcSrc, Rect rcDst, Point tdClickPosition,
                                out int ichOut, out bool fAssocPrev)
        {
            LastPointToCharArgs = new PointToCharArgs()
            {
                IchBase = ichBase, Vg = vg, RcSrc = rcSrc, RcDst = rcDst, ClickPosition = tdClickPosition
            };
            int xpos = tdClickPosition.X + rcSrc.left - rcDst.left;             // Enhance: not sure this is right for rcDst, and ignores zoom
            int ich  = 0;

            fAssocPrev = false;
            if (xpos < 0)
            {
                ichOut = ich + ichBase;
                return;
            }
            int lastCharWidth = 0;

            while (xpos >= 0 & ich < Length)
            {
                lastCharWidth = FakeRenderEngine.CharWidth(Text[ich]);
                xpos         -= lastCharWidth;
                ich++;
            }
            if (xpos >= 0 && ich > 0)
            {
                fAssocPrev = true;                 // click to right of last char
                {
                    ichOut = ich + ichBase;
                    return;
                }
            }
            // We clicked somewhere in the last character, of width lastCharWidth.
            // If we clicked in the first half of it, treat as a click before it.
            // -xpos is the distance we clicked left of its right edge.
            if ((-xpos) < lastCharWidth / 2)
            {
                fAssocPrev = true;                 // click on right half, return current index and assoc prev
            }
            else if (ich > 0)
            {
                ich--;                 // click on left half, return previous index and assoc prev false.
            }
            ichOut = ich + ichBase;
        }
Ejemplo n.º 2
0
 public void PositionsOfIP(int ichBase, IVwGraphics _vg, Rect rcSrc, Rect rcDst, int ich, bool fAssocPrev, LgIPDrawMode dm,
                           out Rect rectPrimary, out Rect rectSecondary, out bool fPrimaryHere, out bool fSecHere)
 {
     LastPosIpCall           = new MockSegment.PositionsOfIpArgs();
     LastPosIpCall.IchBase   = ichBase;
     LastPosIpCall.Graphics  = _vg;
     LastPosIpCall.RcSrc     = rcSrc;
     LastPosIpCall.RcDst     = rcDst;
     LastPosIpCall.Ich       = ich;
     LastPosIpCall.AssocPrev = fAssocPrev;
     LastPosIpCall.DrawMode  = dm;
     if (NextPosIpResult != null)
     {
         rectPrimary   = NextPosIpResult.RectPrimary;
         rectSecondary = new Rect();       // NextPosIpResult.RectSecondary;
         fPrimaryHere  = NextPosIpResult.PrimaryHere;
         fSecHere      = false;            // NextPosIpResult.SecHere;
     }
     else
     {
         rectPrimary   = new Rect(0, 0, 0, 0);
         rectSecondary = new Rect(0, 0, 0, 0);
         fSecHere      = false;
         if (ich < ichBase || ich > ichBase + Length)
         {
             fPrimaryHere = false;
             return;
         }
         fPrimaryHere = true;                 // useful result when we don't care to prepare for this call.
         int width = 0;
         for (int i = 0; i < ich - ichBase; i++)
         {
             width += FakeRenderEngine.CharWidth(Text[i]);
         }
         rectPrimary = PaintTransform.ConvertToPaint(new Rect(width - 1, 0, width + 1, Height),
                                                     rcSrc, rcDst);
     }
 }