Exemplo n.º 1
0
        /// <summary>
        /// Computes the layout of all visible text spans and stores them the
        /// member variable 'visibleLines'. This includes a final partial item on the end.
        /// </summary>
        /// <param name="g"></param>
        protected void ComputeLayout(Graphics g)
        {
            float cyLine = GetLineHeight();

            this.visibleLines = new SortedList <float, LayoutLine>();
            SizeF szClient = new SizeF(ClientSize);
            var   rcLine   = new RectangleF(0, 0, szClient.Width, cyLine);

            // Get the lines.
            int cVisibleLines = (int)Math.Ceiling(szClient.Height / cyLine);
            var lines         = model != null?model.GetLineSpans(cVisibleLines) : new LineSpan[0];

            int iLine = 0;

            while (rcLine.Top < szClient.Height &&
                   iLine < lines.Length)
            {
                var line = lines[iLine];
                var ll   = new LayoutLine(line.Position)
                {
                    Extent = rcLine,
                    Spans  = ComputeSpanLayouts(line.TextSpans, rcLine, g)
                };
                this.visibleLines.Add(rcLine.Top, ll);
                ++iLine;
                rcLine.Offset(0, cyLine);
            }
        }
Exemplo n.º 2
0
 private LayoutSpan FindSpan(Point ptClient, LayoutLine line)
 {
     foreach (var span in line.Spans)
     {
         if (span.ContentExtent.Contains(ptClient))
         {
             return(span);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        private RectangleF SpanPositionToClient(Graphics g, TextPointer pos, LayoutLine line, StyleStack styleStack)
        {
            var iSpan = pos.Span;

            if (iSpan < 0 || iSpan >= line.Spans.Length)
            {
                return(line.Extent);
            }
            var span = line.Spans[iSpan];

            return(CharPositionToClient(g, pos, span, styleStack));
        }
Exemplo n.º 4
0
        private void PaintLine(LayoutLine line, Graphics g)
        {
            foreach (var span in line.Spans)
            {
                var text = span.Text;

                var font = GetFont(span.Style);
                var fg   = GetForeground(span.Style);
                var bg   = GetBackground(span.Style);
                g.FillRectangle(bg, span.Extent);
                g.DrawString(text, font, fg, span.Extent, stringFormat);
            }
        }
Exemplo n.º 5
0
        private TextPointer FindSpanPosition(Graphics g, Point ptClient, LayoutLine line, StyleStack styleStack)
        {
            int iSpan = 0;

            foreach (var span in line.Spans)
            {
                if (span.ContentExtent.Contains(ptClient))
                {
                    int iChar = GetCharPosition(g, ptClient, span, styleStack);
                    return(new TextPointer(line.Position, iSpan, iChar));
                }
                ++iSpan;
            }
            return(new TextPointer(line.Position, iSpan, 0));
        }
Exemplo n.º 6
0
            public void AddLayoutLine(LineSpan line, ref RectangleF rcLine /* put in state */)
            {
                float cyLine = MeasureLineHeight(line);

                rcLine.Height = cyLine;
                var spans = ComputeSpanLayouts(line.TextSpans, rcLine);
                var ll    = new LayoutLine(line.Position)
                {
                    Extent = LineExtent(rcLine, spans),
                    Spans  = spans,
                };

                this.visibleLines.Add(rcLine.Top, ll);
                rcLine.Offset(0, cyLine);
            }
Exemplo n.º 7
0
        private TextPointer FindSpanPosition(Point ptClient, LayoutLine line)
        {
            int iSpan = 0;

            foreach (var span in line.Spans)
            {
                if (span.Extent.Contains(ptClient))
                {
                    int iChar = GetCharPosition(ptClient, span);
                    return(new TextPointer
                    {
                        Line = line.Position,
                        Span = iSpan,
                        Character = iChar
                    });
                }
                ++iSpan;
            }
            return(new TextPointer {
                Line = line.Position, Span = iSpan, Character = 0
            });
        }
Exemplo n.º 8
0
        private void PaintLine(LayoutLine line)
        {
            this.line = line;

            // Paint the last piece of the line
            RectangleF rcTrailer = line.Extent;
            float      xMax      = 0;

            if (line.Spans.Length > 0)
            {
                xMax = line.Spans[line.Spans.Length - 1].ContentExtent.Right;
            }
            var cx = extent.Width - xMax;

            if (cx > 0)
            {
                rcTrailer.X     = xMax;
                rcTrailer.Width = cx;
                graphics.FillRectangle(
                    styleStack.GetBackground(defaultBgColor),
                    rcTrailer);
            }

            for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
            {
                this.span = line.Spans[iSpan];
                this.styleStack.PushStyle(span.Style);
                var pos = new TextPointer(line.Position, iSpan, 0);

                var insideSelection =
                    outer.ComparePositions(selStart, pos) <= 0 &&
                    outer.ComparePositions(pos, selEnd) < 0;

                this.fg   = styleStack.GetForegroundColor(defaultFgColor);
                this.bg   = styleStack.GetBackground(defaultBgColor);
                this.font = styleStack.GetFont(defaultFont);

                this.rcContent = span.ContentExtent;
                this.rcTotal   = span.PaddedExtent;
                if (!insideSelection)
                {
                    if (selStart.Line == line.Position && selStart.Span == iSpan)
                    {
                        // Selection starts inside the current span. Write
                        // any unselected text first.
                        if (selStart.Character > 0)
                        {
                            DrawTextSegment(0, selStart.Character, false);
                        }
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            // Select all the way to the end of the span.
                            DrawTrailingTextSegment(selStart.Character, true);
                        }
                    }
                    else
                    {
                        // Not in selection at all.
                        DrawText(span.Text, false);
                    }
                }
                else
                {
                    // Inside selection. Does it end?
                    if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                    {
                        // Selection ends inside the current span. Write
                        // selected text.
                        DrawTextSegment(0, selEnd.Character, true);
                        DrawTrailingTextSegment(selEnd.Character, false);
                    }
                    else
                    {
                        DrawText(span.Text, true);
                    }
                }

#if DEBUG
                var text = span.Text;
                if (line.Position == selStart.Line &&
                    iSpan == selStart.Span)
                {
                    var textFrag = text.Substring(0, selStart.Character);
                    var sz       = outer.MeasureText(graphics, textFrag, font);
                    graphics.FillRectangle(
                        Brushes.Red,
                        span.ContentExtent.Left + sz.Width, line.Extent.Top,
                        1, line.Extent.Height);
                }
                if (line.Position == selEnd.Line &&
                    iSpan == selEnd.Span)
                {
                    var textFrag = text.Substring(0, selEnd.Character);
                    var sz       = outer.MeasureText(graphics, textFrag, font);
                    graphics.FillRectangle(
                        Brushes.Blue,
                        span.ContentExtent.Left + sz.Width, line.Extent.Top,
                        1, line.Extent.Height);
                }
#endif
                styleStack.PopStyle();
            }
        }
Exemplo n.º 9
0
 private TextPointer FindSpanPosition(Point ptClient, LayoutLine line)
 {
     int iSpan = 0;
     foreach (var span in line.Spans)
     {
         if (span.Extent.Contains(ptClient))
         {
             int iChar = GetCharPosition(ptClient, span);
             return new TextPointer
             {
                 Line = line.Position,
                 Span = iSpan,
                 Character = iChar
             };
         }
         ++iSpan;
     }
     return new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };
 }
Exemplo n.º 10
0
 private LayoutSpan FindSpan(Point ptClient, LayoutLine line)
 {
     foreach (var span in line.Spans)
     {
         if (span.Extent.Contains(ptClient))
             return span;
     }
     return null;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Computes the layout of all visible text spans and stores them the 
        /// member variable 'visibleLines'. This includes a final partial item on the end.
        /// </summary>
        /// <param name="g"></param>
        protected void ComputeLayout(Graphics g)
        {
            GetStyleStack().PushStyle(StyleClass);
            this.visibleLines = new SortedList<float, LayoutLine>();
            SizeF szClient = new SizeF(ClientSize);
            var rcLine = new RectangleF(0, 0, szClient.Width, 0);

            // Get the lines.
            object oldPos = null;
            var m = model ?? new EmptyEditorModel();
            oldPos = model.CurrentPosition;
            var lines = m.GetLineSpans(1);
            while (rcLine.Top < szClient.Height && 
                   lines != null && lines.Length == 1)
            {
                var line = lines[0];
                float cyLine = MeasureLineHeight(line);
                rcLine.Height = cyLine;
                var ll = new LayoutLine(line.Position) { 
                    Extent = rcLine,
                    Spans = ComputeSpanLayouts(line.TextSpans, rcLine, g)
                };
                this.visibleLines.Add(rcLine.Top, ll);
                lines = m.GetLineSpans(1);
                rcLine.Offset(0, cyLine);
            }
            GetStyleStack().PopStyle();
            model.MoveToLine(oldPos, 0);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Computes the layout of all visible text spans and stores them the 
        /// member variable 'visibleLines'. This includes a final partial item on the end.
        /// </summary>
        /// <param name="g"></param>
        protected void ComputeLayout(Graphics g)
        {
            float cyLine = GetLineHeight();
            this.visibleLines = new SortedList<float, LayoutLine>();
            SizeF szClient = new SizeF(ClientSize);
            var rcLine = new RectangleF(0, 0, szClient.Width, cyLine);

            // Get the lines.
            int cVisibleLines = (int) Math.Ceiling(szClient.Height / cyLine);
            var lines = model != null ? model.GetLineSpans(cVisibleLines) : new LineSpan[0];
            int iLine = 0;
            while (rcLine.Top < szClient.Height &&
                   iLine < lines.Length)
            {
                var line = lines[iLine];
                var ll = new LayoutLine(line.Position) {
                    Extent = rcLine,
                    Spans = ComputeSpanLayouts(line.TextSpans, rcLine, g)
                };
                this.visibleLines.Add(rcLine.Top, ll);
                ++iLine;
                rcLine.Offset(0, cyLine);
            }
        }
Exemplo n.º 13
0
 public void AddLayoutLine(LineSpan line, ref RectangleF rcLine /* put in state */)
 {
     float cyLine = MeasureLineHeight(line);
     rcLine.Height = cyLine;
     var spans = ComputeSpanLayouts(line.TextSpans, rcLine);
     var ll = new LayoutLine(line.Position)
     {
         Extent = LineExtent(rcLine, spans),
         Spans = spans,
     };
     this.visibleLines.Add(rcLine.Top, ll);
     rcLine.Offset(0, cyLine);
 }
Exemplo n.º 14
0
 private RectangleF SpanPositionToClient(Graphics g, TextPointer pos, LayoutLine line, StyleStack styleStack)
 {
     var iSpan = pos.Span;
     if (iSpan < 0 || iSpan >= line.Spans.Length)
         return line.Extent;
     var span = line.Spans[iSpan];
     return CharPositionToClient(g, pos, span, styleStack);
 }
Exemplo n.º 15
0
 private TextPointer FindSpanPosition(Graphics g, Point ptClient, LayoutLine line, StyleStack styleStack)
 {
     int iSpan = 0;
     foreach (var span in line.Spans)
     {
         if (span.ContentExtent.Contains(ptClient))
         {
             int iChar = GetCharPosition(g, ptClient, span, styleStack);
             return new TextPointer
             {
                 Line = line.Position,
                 Span = iSpan,
                 Character = iChar
             };
         }
         ++iSpan;
     }
     return new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };
 }
Exemplo n.º 16
0
            private void PaintLine(LayoutLine line)
            {
                for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
                {
                    this.span = line.Spans[iSpan];
                    var pos = new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };

                    var insideSelection =
                        outer.ComparePositions(selStart, pos) <= 0 &&
                        outer.ComparePositions(pos, selEnd) < 0;

                    this.fg = outer.GetForegroundColor(span.Style);
                    this.bg = outer.GetBackground(span.Style);
                    this.font = outer.GetFont(span.Style);

                    this.rcText = span.Extent;
                    if (!insideSelection)
                    {
                        if (selStart.Line == line.Position && selStart.Span == iSpan)
                        {
                            // Selection starts inside the current span. Write
                            // any unselected text first.
                            if (selStart.Character > 0)
                            {
                                DrawTextSegment(0, selStart.Character, false);
                            }
                            if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                            {
                                // Selection ends inside the current span. Write
                                // selected text.
                                DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                                if (selEnd.Character < span.Text.Length)
                                {
                                    // If there is trailing unselected text, display that.
                                    DrawTrailingTextSegment(selEnd.Character, false);
                                }
                            }
                            else
                            {
                                // Select all the way to the end of the span.
                                DrawTrailingTextSegment(selStart.Character, true);
                            }
                        }
                        else
                        {
                            // Not in selection at all.
                            DrawText(span.Text, false);
                        }
                    }
                    else
                    {
                        // Inside selection. Does it end?
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(0, selEnd.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            DrawText(span.Text, true);
                        }
                    }

                #if DEBUG
                    var text = span.Text;
                    if (line.Position == selStart.Line &&
                        iSpan == selStart.Span)
                    {
                        var textFrag = text.Substring(0, selStart.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Red,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                    if (line.Position == selEnd.Line &&
                        iSpan == selEnd.Span)
                    {
                        var textFrag = text.Substring(0, selEnd.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Blue,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                #endif
                }
            }
Exemplo n.º 17
0
            private void PaintLine(LayoutLine line)
            {
                // Paint the last piece of the line
                RectangleF rcTrailer = line.Extent;
                float xMax = 0;
                if (line.Spans.Length > 0)
                {
                    xMax = line.Spans[line.Spans.Length - 1].Extent.Right;
                }
                var cx = outer.ClientRectangle.Right - xMax;
                if (cx > 0)
                {
                    rcTrailer.X = xMax;
                    rcTrailer.Width = cx;
                    graphics.FillRectangle(
                        styleStack.GetBackground(outer),
                        rcTrailer);
                }

                for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
                {
                    this.span = line.Spans[iSpan];
                    this.styleStack.PushStyle(span.Style);
                    var pos = new TextPointer { Line = line.Position, Span = iSpan, Character = 0 };

                    var insideSelection =
                        outer.ComparePositions(selStart, pos) <= 0 &&
                        outer.ComparePositions(pos, selEnd) < 0;

                    this.fg = styleStack.GetForegroundColor(outer);
                    this.bg = styleStack.GetBackground(outer);
                    this.font = styleStack.GetFont(outer);

                    this.rcText = span.Extent;
                    if (!insideSelection)
                    {
                        if (selStart.Line == line.Position && selStart.Span == iSpan)
                        {
                            // Selection starts inside the current span. Write
                            // any unselected text first.
                            if (selStart.Character > 0)
                            {
                                DrawTextSegment(0, selStart.Character, false);
                            }
                            if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                            {
                                // Selection ends inside the current span. Write
                                // selected text.
                                DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                                DrawTrailingTextSegment(selEnd.Character, false);
                            }
                            else
                            {
                                // Select all the way to the end of the span.
                                DrawTrailingTextSegment(selStart.Character, true);
                            }
                        }
                        else
                        {
                            // Not in selection at all.
                            DrawText(span.Text, false);
                        }
                    }
                    else
                    {
                        // Inside selection. Does it end?
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(0, selEnd.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            DrawText(span.Text, true);
                        }
                    }

#if DEBUG
                    var text = span.Text;
                    if (line.Position == selStart.Line &&
                        iSpan == selStart.Span)
                    {
                        var textFrag = text.Substring(0, selStart.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Red,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                    if (line.Position == selEnd.Line &&
                        iSpan == selEnd.Span)
                    {
                        var textFrag = text.Substring(0, selEnd.Character);
                        var sz = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Blue,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
#endif
                    styleStack.PopStyle();
                }
            }
Exemplo n.º 18
0
            private void PaintLine(LayoutLine line)
            {
                for (int iSpan = 0; iSpan < line.Spans.Length; ++iSpan)
                {
                    this.span = line.Spans[iSpan];
                    var pos = new TextPointer {
                        Line = line.Position, Span = iSpan, Character = 0
                    };

                    var insideSelection =
                        outer.ComparePositions(selStart, pos) <= 0 &&
                        outer.ComparePositions(pos, selEnd) < 0;

                    this.fg   = outer.GetForegroundColor(span.Style);
                    this.bg   = outer.GetBackground(span.Style);
                    this.font = outer.GetFont(span.Style);

                    this.rcText = span.Extent;
                    if (!insideSelection)
                    {
                        if (selStart.Line == line.Position && selStart.Span == iSpan)
                        {
                            // Selection starts inside the current span. Write
                            // any unselected text first.
                            if (selStart.Character > 0)
                            {
                                DrawTextSegment(0, selStart.Character, false);
                            }
                            if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                            {
                                // Selection ends inside the current span. Write
                                // selected text.
                                DrawTextSegment(selStart.Character, selEnd.Character - selStart.Character, true);
                                if (selEnd.Character < span.Text.Length)
                                {
                                    // If there is trailing unselected text, display that.
                                    DrawTrailingTextSegment(selEnd.Character, false);
                                }
                            }
                            else
                            {
                                // Select all the way to the end of the span.
                                DrawTrailingTextSegment(selStart.Character, true);
                            }
                        }
                        else
                        {
                            // Not in selection at all.
                            DrawText(span.Text, false);
                        }
                    }
                    else
                    {
                        // Inside selection. Does it end?
                        if (selEnd.Line == line.Position && selEnd.Span == iSpan)
                        {
                            // Selection ends inside the current span. Write
                            // selected text.
                            DrawTextSegment(0, selEnd.Character, true);
                            DrawTrailingTextSegment(selEnd.Character, false);
                        }
                        else
                        {
                            DrawText(span.Text, true);
                        }
                    }

#if DEBUG
                    var text = span.Text;
                    if (line.Position == selStart.Line &&
                        iSpan == selStart.Span)
                    {
                        var textFrag = text.Substring(0, selStart.Character);
                        var sz       = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Red,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
                    if (line.Position == selEnd.Line &&
                        iSpan == selEnd.Span)
                    {
                        var textFrag = text.Substring(0, selEnd.Character);
                        var sz       = outer.MeasureText(graphics, textFrag, font);
                        graphics.FillRectangle(
                            Brushes.Blue,
                            span.Extent.Left + sz.Width, line.Extent.Top,
                            1, line.Extent.Height);
                    }
#endif
                }
            }
Exemplo n.º 19
0
        private void PaintLine(LayoutLine line, Graphics g)
        {
            foreach (var span in line.Spans)
            {
                var text = span.Text;

                var font = GetFont(span.Style);
                var fg = GetForeground(span.Style);
                var bg = GetBackground(span.Style);
                g.FillRectangle(bg, span.Extent);
                g.DrawString(text, font, fg, span.Extent, stringFormat);
            }
        }