Code Coverage Statistics for Source File

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

Sequence Point Coverage
N/A
0 of 0
Branch Coverage
N/A
0 of 0
Lines
124
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: 2487 $</version>
6
// </file>
7
8
using System.Drawing;
9
using System.Drawing.Text;
10
using System.Windows.Forms;
11
12
namespace ICSharpCode.TextEditor.Util
13
{
14
	static class TipPainter
15
	{
16
		const float HorizontalBorder = 2;
17
		const float VerticalBorder   = 1;
18
		static RectangleF workingArea = RectangleF.Empty;
19
		
20
		//static StringFormat centerTipFormat = CreateTipStringFormat();
21
		
22
		public static Size GetTipSize(Control control, Graphics graphics, Font font, string description)
23
		{
24
			return GetTipSize(control, graphics, new TipText (graphics, font, description));
25
		}
26
		
27
		public static Size GetTipSize(Control control, Graphics graphics, TipSection tipData)
28
		{
29
			Size tipSize = Size.Empty;
30
			SizeF tipSizeF = SizeF.Empty;
31
			
32
			if (workingArea == RectangleF.Empty) {
33
				Form ownerForm = control.FindForm();
34
				if (ownerForm.Owner != null) {
35
					ownerForm = ownerForm.Owner;
36
				}
37
				
38
				workingArea = Screen.GetWorkingArea(ownerForm);
39
			}
40
			
41
			PointF screenLocation = control.PointToScreen(Point.Empty);
42
			
43
			SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2,
44
			                                workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
45
			
46
			if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
47
				graphics.TextRenderingHint =
48
				TextRenderingHint.AntiAliasGridFit;
49
				
50
				tipData.SetMaximumSize(maxLayoutSize);
51
				tipSizeF = tipData.GetRequiredSize();
52
				tipData.SetAllocatedSize(tipSizeF);
53
				
54
				tipSizeF += new SizeF(HorizontalBorder * 2,
55
				                      VerticalBorder   * 2);
56
				tipSize = Size.Ceiling(tipSizeF);
57
			}
58
			
59
			if (control.ClientSize != tipSize) {
60
				control.ClientSize = tipSize;
61
			}
62
			
63
			return tipSize;
64
		}
65
		
66
		public static Size DrawTip(Control control, Graphics graphics, Font font, string description)
67
		{
68
			return DrawTip(control, graphics, new TipText (graphics, font, description));
69
		}
70
		
71
		public static Size DrawTip(Control control, Graphics graphics, TipSection tipData)
72
		{
73
			Size tipSize = Size.Empty;
74
			SizeF tipSizeF = SizeF.Empty;
75
			
76
			PointF screenLocation = control.PointToScreen(Point.Empty);
77
			
78
			if (workingArea == RectangleF.Empty) {
79
				Form ownerForm = control.FindForm();
80
				if (ownerForm.Owner != null) {
81
					ownerForm = ownerForm.Owner;
82
				}
83
				
84
				workingArea = Screen.GetWorkingArea(ownerForm);
85
			}
86
	
87
			SizeF maxLayoutSize = new SizeF(workingArea.Right - screenLocation.X - HorizontalBorder * 2,
88
			                                workingArea.Bottom - screenLocation.Y - VerticalBorder * 2);
89
			
90
			if (maxLayoutSize.Width > 0 && maxLayoutSize.Height > 0) {
91
				graphics.TextRenderingHint =
92
				TextRenderingHint.AntiAliasGridFit;
93
				
94
				tipData.SetMaximumSize(maxLayoutSize);
95
				tipSizeF = tipData.GetRequiredSize();
96
				tipData.SetAllocatedSize(tipSizeF);
97
				
98
				tipSizeF += new SizeF(HorizontalBorder * 2,
99
				                      VerticalBorder   * 2);
100
				tipSize = Size.Ceiling(tipSizeF);
101
			}
102
			
103
			if (control.ClientSize != tipSize) {
104
				control.ClientSize = tipSize;
105
			}
106
			
107
			if (tipSize != Size.Empty) {
108
				Rectangle borderRectangle = new Rectangle
109
				(Point.Empty, tipSize - new Size(1, 1));
110
				
111
				RectangleF displayRectangle = new RectangleF
112
				(HorizontalBorder, VerticalBorder,
113
				 tipSizeF.Width - HorizontalBorder * 2,
114
				 tipSizeF.Height - VerticalBorder * 2);
115
				
116
				// DrawRectangle draws from Left to Left + Width. A bug? :-/
117
				graphics.DrawRectangle(SystemPens.WindowFrame,
118
				                       borderRectangle);
119
				tipData.Draw(new PointF(HorizontalBorder, VerticalBorder));
120
			}
121
			return tipSize;
122
		}
123
	}
124
}