Code Coverage Statistics for Source File

c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Util\TipText.cs

Sequence Point Coverage
N/A
0 of 0
Branch Coverage
N/A
0 of 0
Lines
183
Highlight: Uncovered Code Covered Code
L V Source
1
// <file>
2
//     <copyright see="prj:///doc/copyright.txt"/>
3
//     <license see="prj:///doc/license.txt"/>
4
//     <owner name="none" email=""/>
5
//     <version>$Revision: 2561 $</version>
6
// </file>
7
8
using System;
9
using System.Drawing;
10
11
namespace ICSharpCode.TextEditor.Util
12
{
13
	class CountTipText: TipText
14
	{
15
		float triHeight = 10;
16
		float triWidth  = 10;
17
		
18
		public CountTipText(Graphics graphics, Font font, string text) : base(graphics, font, text)
19
		{
20
		}
21
		
22
		void DrawTriangle(float x, float y, bool flipped)
23
		{
24
			Brush brush = BrushRegistry.GetBrush(Color.FromArgb(192, 192, 192));
25
			base.Graphics.FillRectangle(brush, new RectangleF(x, y, triHeight, triHeight));
26
			float triHeight2 = triHeight / 2;
27
			float triHeight4 = triHeight / 4;
28
			brush = Brushes.Black;
29
			if (flipped) {
30
				base.Graphics.FillPolygon(brush, new PointF[] {
31
				                          	new PointF(x,                y + triHeight2 - triHeight4),
32
				                          	new PointF(x + triWidth / 2, y + triHeight2 + triHeight4),
33
				                          	new PointF(x + triWidth,     y + triHeight2 - triHeight4),
34
				                          });
35
				
36
			} else {
37
				base.Graphics.FillPolygon(brush, new PointF[] {
38
				                          	new PointF(x,                y +  triHeight2 + triHeight4),
39
				                          	new PointF(x + triWidth / 2, y +  triHeight2 - triHeight4),
40
				                          	new PointF(x + triWidth,     y +  triHeight2 + triHeight4),
41
				                          });
42
			}
43
		}
44
		
45
		public Rectangle DrawingRectangle1;
46
		public Rectangle DrawingRectangle2;
47
		
48
		public override void Draw(PointF location)
49
		{
50
			if (tipText != null && tipText.Length > 0) {
51
				base.Draw(new PointF(location.X + triWidth + 4, location.Y));
52
				DrawingRectangle1 = new Rectangle((int)location.X + 2,
53
				                                  (int)location.Y + 2,
54
				                                  (int)(triWidth),
55
				                                  (int)(triHeight));
56
				DrawingRectangle2 = new Rectangle((int)(location.X + base.AllocatedSize.Width - triWidth  - 2),
57
				                                  (int)location.Y + 2,
58
				                                  (int)(triWidth),
59
				                                  (int)(triHeight));
60
				DrawTriangle(location.X + 2, location.Y + 2, false);
61
				DrawTriangle(location.X + base.AllocatedSize.Width - triWidth  - 2, location.Y + 2, true);
62
			}
63
		}
64
		
65
		protected override void OnMaximumSizeChanged()
66
		{
67
			if (IsTextVisible()) {
68
				SizeF tipSize = Graphics.MeasureString
69
					(tipText, tipFont, MaximumSize,
70
					 GetInternalStringFormat());
71
				tipSize.Width += triWidth * 2 + 8;
72
				SetRequiredSize(tipSize);
73
			} else {
74
				SetRequiredSize(SizeF.Empty);
75
			}
76
		}
77
		
78
	}
79
	
80
	class TipText: TipSection
81
	{
82
		protected StringAlignment horzAlign;
83
		protected StringAlignment vertAlign;
84
		protected Color           tipColor;
85
		protected Font            tipFont;
86
		protected StringFormat    tipFormat;
87
		protected string          tipText;
88
		
89
		public TipText(Graphics graphics, Font font, string text):
90
			base(graphics)
91
		{
92
			tipFont = font; tipText = text;
93
			if (text != null && text.Length > short.MaxValue)
94
				throw new ArgumentException("TipText: text too long (max. is " + short.MaxValue + " characters)", "text");
95
			
96
			Color               = SystemColors.InfoText;
97
			HorizontalAlignment = StringAlignment.Near;
98
			VerticalAlignment   = StringAlignment.Near;
99
		}
100
		
101
		public override void Draw(PointF location)
102
		{
103
			if (IsTextVisible()) {
104
				RectangleF drawRectangle = new RectangleF(location, AllocatedSize);
105
				
106
				Graphics.DrawString(tipText, tipFont,
107
				                    BrushRegistry.GetBrush(Color),
108
				                    drawRectangle,
109
				                    GetInternalStringFormat());
110
			}
111
		}
112
		
113
		protected StringFormat GetInternalStringFormat()
114
		{
115
			if (tipFormat == null) {
116
				tipFormat = CreateTipStringFormat(horzAlign, vertAlign);
117
			}
118
			
119
			return tipFormat;
120
		}
121
		
122
		protected override void OnMaximumSizeChanged()
123
		{
124
			base.OnMaximumSizeChanged();
125
			
126
			if (IsTextVisible()) {
127
				SizeF tipSize = Graphics.MeasureString
128
					(tipText, tipFont, MaximumSize,
129
					 GetInternalStringFormat());
130
				
131
				SetRequiredSize(tipSize);
132
			} else {
133
				SetRequiredSize(SizeF.Empty);
134
			}
135
		}
136
		
137
		static StringFormat CreateTipStringFormat(StringAlignment horizontalAlignment, StringAlignment verticalAlignment)
138
		{
139
			StringFormat format = (StringFormat)StringFormat.GenericTypographic.Clone();
140
			format.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.MeasureTrailingSpaces;
141
			// note: Align Near, Line Center seemed to do something before
142
			
143
			format.Alignment     = horizontalAlignment;
144
			format.LineAlignment = verticalAlignment;
145
			
146
			return format;
147
		}
148
		
149
		protected bool IsTextVisible()
150
		{
151
			return tipText != null && tipText.Length > 0;
152
		}
153
		
154
		public Color Color {
155
			get {
156
				return tipColor;
157
			}
158
			set {
159
				tipColor = value;
160
			}
161
		}
162
		
163
		public StringAlignment HorizontalAlignment {
164
			get {
165
				return horzAlign;
166
			}
167
			set {
168
				horzAlign = value;
169
				tipFormat = null;
170
			}
171
		}
172
		
173
		public StringAlignment VerticalAlignment {
174
			get {
175
				return vertAlign;
176
			}
177
			set {
178
				vertAlign = value;
179
				tipFormat = null;
180
			}
181
		}
182
	}
183
}