예제 #1
0
        private RectangleF CharPositionToClient(Graphics g, TextPointer pos, LayoutSpan span, StyleStack styleStack)
        {
            var iChar = pos.Character;

            styleStack.PushStyle(span.Style);
            var font = styleStack.GetFont(defaultFont);

            var textStub = span.Text.Substring(0, iChar);
            var sz       = MeasureText(g, textStub, font);
            var x        = sz.Width + span.ContentExtent.Left;
            var width    = 1;

            styleStack.PopStyle();

            return(new RectangleF(x, span.ContentExtent.Top, width, span.ContentExtent.Height));
        }
예제 #2
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (Capture && !dragging)
     {
         // We're extending the selection
         var pos = ClientToLogicalPosition(e.Location);
         if (layout.ComparePositions(cursorPos, pos) != 0)
         {
             this.cursorPos = pos;
             Invalidate();
         }
     }
     else
     {
         // Not captured, so rat is just floating over us.
         // Show the right cursor.
         var span = GetSpan(e.Location);
         if (span != null)
         {
             GetStyleStack().PushStyle(StyleClass);
             styleStack.PushStyle(span.Style);
             this.Cursor = styleStack.GetCursor(this);
             styleStack.PopStyle();
             styleStack.PopStyle();
         }
         else
         {
             this.Cursor = Cursors.Default;
         }
         if (span != spanHover)
         {
             if (spanHover != null)
             {
                 SpanLeave.Fire(this, new SpanEventArgs(spanHover));
             }
             spanHover = span;
             if (span != null)
             {
                 SpanEnter.Fire(this, new SpanEventArgs(span));
             }
         }
     }
     base.OnMouseMove(e);
 }
예제 #3
0
        private int GetCharPosition(Graphics g, Point ptClient, LayoutSpan span, StyleStack styleStack)
        {
            var x        = ptClient.X - span.ContentExtent.Left;
            var textStub = span.Text;
            int iLow     = 0;
            int iHigh    = textStub.Length;

            styleStack.PushStyle(span.Style);
            var   font  = styleStack.GetFont(defaultFont);
            var   sz    = MeasureText(g, textStub, font);
            float xLow  = 0;
            float xHigh = sz.Width;

            while (iLow < iHigh - 1)
            {
                int iMid = iLow + (iHigh - iLow) / 2;
                textStub = span.Text.Substring(0, iMid);
                sz       = MeasureText(g, textStub, font);
                if (x < sz.Width)
                {
                    iHigh = iMid;
                    xHigh = sz.Width;
                }
                else
                {
                    iLow = iMid;
                    xLow = sz.Width;
                }
            }
            styleStack.PopStyle();
            var cx = xHigh - xLow;

            if (x - xLow > cx)
            {
                return(iHigh);
            }
            else
            {
                return(iLow);
            }
        }
예제 #4
0
        private int GetCharPosition(Point ptClient, LayoutSpan span)
        {
            var   x        = ptClient.X - span.Extent.Left;
            var   g        = CreateGraphics();
            var   textStub = span.Text;
            int   iLow     = 0;
            int   iHigh    = textStub.Length;
            var   font     = GetFont(span.Style);
            var   sz       = MeasureText(g, textStub, font);
            float xLow     = 0;
            float xHigh    = sz.Width;

            while (iLow < iHigh - 1)
            {
                int iMid = iLow + (iHigh - iLow) / 2;
                textStub = span.Text.Substring(0, iMid);
                sz       = MeasureText(g, textStub, font);
                if (x < sz.Width)
                {
                    iHigh = iMid;
                    xHigh = sz.Width;
                }
                else
                {
                    iLow = iMid;
                    xLow = sz.Width;
                }
            }
            var cx = xHigh - xLow;

            if (x - xLow > cx)
            {
                return(iHigh);
            }
            else
            {
                return(iLow);
            }
        }
예제 #5
0
 public SpanEventArgs(LayoutSpan span)
 {
     this.Span = span;
 }
예제 #6
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();
            }
        }
예제 #7
0
 private int GetCharPosition(Point ptClient, LayoutSpan span)
 {
     var x = ptClient.X - span.Extent.Left;
     var g = CreateGraphics();
     var textStub = span.Text;
     int iLow = 0;
     int iHigh = textStub.Length;
     styleStack.PushStyle(span.Style);
     var font = styleStack.GetFont(this);
     var sz = MeasureText(g, textStub, font);
     float xLow = 0;
     float xHigh = sz.Width;
     while (iLow < iHigh-1)
     {
         int iMid = iLow + (iHigh - iLow) / 2;
         textStub = span.Text.Substring(0, iMid);
         sz = MeasureText(g, textStub, font);
         if (x < sz.Width)
         {
             iHigh = iMid;
             xHigh = sz.Width;
         }
         else
         {
             iLow = iMid;
             xLow = sz.Width;
         }
     }
     styleStack.PopStyle();
     var cx = xHigh - xLow;
     if (x - xLow > cx)
         return iHigh;
     else
         return iLow;
 }
예제 #8
0
        private RectangleF CharPositionToClient(Graphics g, TextPointer pos, LayoutSpan span, StyleStack styleStack)
        {
            var iChar = pos.Character;

            styleStack.PushStyle(span.Style);
            var font = styleStack.GetFont(defaultFont);

            var textStub = span.Text.Substring(0, iChar);
            var sz = MeasureText(g, textStub, font);
            var x = sz.Width + span.ContentExtent.Left;
            var width = 1;

            styleStack.PopStyle();

            return new RectangleF(x, span.ContentExtent.Top, width, span.ContentExtent.Height);
        }
예제 #9
0
 private RectangleF LineExtent(RectangleF rcLine, LayoutSpan[] spans)
 {
     var r = rcLine.Right;
     if (spans.Length > 0)
     {
         r = Math.Max(r, spans[spans.Length - 1].ContentExtent.Right);
     }
     return new RectangleF(rcLine.X, rcLine.Y, r - rcLine.X, rcLine.Height);
 }
예제 #10
0
        private void DestroyPreviewWindow()
        {
            this.previewTimer.Enabled = false;
            if (previewWindow == null)
                return;
            this.mixedCodeDataControl.Controls.Remove(previewWindow);
            szPreview = previewWindow.Size;
            previewWindow.Dispose();
            previewWindow = null;
            insidePreview = false;
            previewSpan = null;
            addressPreview = null;

        }
예제 #11
0
        private void MixedCodeDataControl_SpanEnter(object sender, SpanEventArgs e)
        {
            if (previewWindow != null)
            {
                // Preview window already visible.
                return;
            }

            if (e.Span.Style == null || !e.Span.Style.Contains("dasm-addrText"))
                return;
            this.addressPreview = e.Span.Tag as Address;
            if (this.addressPreview == null)
                return;

            // Start the timer; when it ticks, it will pop up the window.
            this.previewTimer.Enabled = true;
            this.previewSpan = e.Span;
        }
예제 #12
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
                }
            }
예제 #13
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();
                }
            }
예제 #14
0
파일: TextView.cs 프로젝트: uxmal/reko
 public SpanEventArgs(LayoutSpan span)
 {
     this.Span = span;
 }
예제 #15
0
파일: TextView.cs 프로젝트: uxmal/reko
 protected override void OnMouseMove(MouseEventArgs e)
 {
     if (Capture && !dragging)
     {
         // We're extending the selection
         var pos = ClientToLogicalPosition(e.Location);
         if (layout.ComparePositions(cursorPos, pos) != 0)
         {
             this.cursorPos = pos;
             Invalidate();
         }
     }
     else
     {
         // Not captured, so rat is just floating over us.
         // Show the right cursor.
         var span = GetSpan(e.Location);
         if (span != null)
         {
             GetStyleStack().PushStyle(StyleClass);
             styleStack.PushStyle(span.Style);
             this.Cursor = styleStack.GetCursor(this);
             styleStack.PopStyle();
             styleStack.PopStyle();
         }
         else
         {
             this.Cursor = Cursors.Default;
         }
         if (span != spanHover)
         {
             if (spanHover != null)
             {
                 SpanLeave.Fire(this, new SpanEventArgs(spanHover));
             }
             spanHover = span;
             if (span != null)
             {
                 SpanEnter.Fire(this, new SpanEventArgs(span));
             }
         }
     }
     base.OnMouseMove(e);
 }
예제 #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
                }
            }