2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 using System.Windows.Forms;
34 using System.ComponentModel;
39 /// Used in conjuction with ritch text box to display lone numbers
42 Category("Containers"),
43 Description("Used in conjuction with ritch text box to display lone numbers")]
44 public partial class LineNumberPanel : Control
46 private RRichTextBox rtb;
47 private SolidBrush brush;
50 /// Associated ritch text box control
52 [Category("Behavior")]
53 public RRichTextBox RTB
59 return new RRichTextBox();
71 rtb.VScroll -= new EventHandler(rtb_InvalidateNumbers);
72 rtb.TextChanged -= new EventHandler(rtb_InvalidateNumbers);
73 rtb.Resize -= new EventHandler(rtb_InvalidateNumbers);
76 rtb.VScroll += new EventHandler(rtb_InvalidateNumbers);
77 rtb.TextChanged += new EventHandler(rtb_InvalidateNumbers);
78 rtb.Resize += new EventHandler(rtb_InvalidateNumbers);
82 void rtb_InvalidateNumbers(object sender, EventArgs e)
87 public LineNumberPanel()
91 ControlStyles.DoubleBuffer |
92 ControlStyles.UserPaint |
93 ControlStyles.AllPaintingInWmPaint,
98 brush = new SolidBrush(ForeColor);
101 protected override void OnPaint(PaintEventArgs e)
109 Graphics g = e.Graphics;
110 brush.Color = ForeColor;
111 if (rtb.Lines.Length < 3)
113 font_height = rtb.Font.Height + 1.5f;
117 font_height = rtb.GetPositionFromCharIndex(rtb.GetFirstCharIndexFromLine(2)).Y - rtb.GetPositionFromCharIndex(rtb.GetFirstCharIndexFromLine(1)).Y;
120 Point pos = new Point(0, (int)(g.VisibleClipBounds.Y + font_height / 3));
121 int first_index, first_line, first_line_y;
122 first_index = rtb.GetCharIndexFromPosition(pos);
123 first_line = rtb.GetLineFromCharIndex(first_index);
124 first_line_y = 1 + rtb.GetPositionFromCharIndex(first_index).Y;
129 int total_lines = rtb.GetLineFromCharIndex(Int32.MaxValue) + 1;
130 StringFormat align = new StringFormat(StringFormatFlags.NoWrap);
131 align.Alignment = StringAlignment.Far;
132 align.LineAlignment = StringAlignment.Center;
135 while (y < g.VisibleClipBounds.Y + g.VisibleClipBounds.Height)
137 SizeF tSize = g.MeasureString(i.ToString(), rtb.Font);
139 if (maxWidth < (int)tSize.Width)
141 maxWidth = (int)tSize.Width;
144 y = first_line_y - 1 + font_height * (i - first_line - 1);
145 x = Width - (int)tSize.Width - 5;
147 if (i <= total_lines)
149 g.DrawString((i).ToString(), rtb.Font, brush, x, y);
156 if (Width != (maxWidth + 13))
158 Width = maxWidth + 13;
164 protected override void OnPaintBackground(PaintEventArgs pevent)
166 pevent.Graphics.Clear(BackColor);