コード例 #1
0
        public Rectangle GetCaretPosition(IGraphics gr, SelectionPoint sp, CaretDirection d)
        {
            if (rootBlock == null)
            {
                return(Rectangle.Empty);
            }

            CaretPositionInfo cpi = new CaretPositionInfo();

            rootBlock.GetCaretPosition(gr, 0, 0, sp, ref cpi);
            if (d == CaretDirection.LTR)
            {
                cpi.UseSecondary = true;
            }

            return(cpi.ToRectangle());
        }
コード例 #2
0
ファイル: textlayout.cs プロジェクト: jugglingcats/XEditNet
        public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
        {
            // TODO: M: this is very innefficient since it is called for all text nodes during search
            if (!ContainsSelectionPoint(sp))
            {
                cpi.UpdateLocation(x + Width, y, Height, CaretSetting.Fallback);
                return;
            }

            TextSelectionPoint tsp = (TextSelectionPoint)sp;

            CaretSetting mode = CaretSetting.Absolute;

            gr.PushFont(gr.GetFontHandle(style.FontDesc));
            try
            {
                int n = tsp.Index - start;
                if (n < 0)
                {
                    // position is not in visible part of the string, it's
                    // in whitespace that has been trimmed.
                    cpi.UseSecondary = true;
                    return;
                }
                else if (tsp.Index == 0)
                {
                    // caret can be put somewhere else if necessary
                    // TODO: L: this is a bit simplistic - will be wrong if text nodes are
                    //			split and first node ends with space and ends a line (!)
                    mode = CaretSetting.Accurate;
                }

                string text = Text;

                if (n > text.Length)
                {
                    // TODO: L: not sure exactly when this happens
                    n = text.Length;
                }

                text = ProcessText(text.Substring(0, n));

                int w = gr.MeasureText(text).Width;
                cpi.UpdateLocation(x + w, y, Height, mode);
            }
            finally
            {
                gr.PopFont();
            }
        }
コード例 #3
0
ファイル: Image.cs プロジェクト: jugglingcats/XEditNet
 public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
 {
     if (ContainsSelectionPoint(sp))
     {
         cpi.UpdateLocation(x, y, Height, CaretSetting.Accurate);
     }
     else
     {
         cpi.UpdateLocation(x + Width, y, Height, CaretSetting.Fallback);
     }
 }