Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\HighlightingStrategy\TextWord.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
236
|
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="Mike Krüger" email="mike@icsharpcode.net"/> |
|
5 |
// <version>$Revision: 1965 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
using System.Diagnostics; |
|
10 |
using System.Drawing; |
|
11 |
||
12 |
namespace ICSharpCode.TextEditor.Document |
|
13 |
{ |
|
14 |
public enum TextWordType { |
|
15 |
Word, |
|
16 |
Space, |
|
17 |
Tab |
|
18 |
} |
|
19 |
||
20 |
/// <summary> |
|
21 |
/// This class represents single words with color information, two special versions of a word are |
|
22 |
/// spaces and tabs. |
|
23 |
/// </summary> |
|
24 |
public class TextWord |
|
25 |
{ |
|
26 |
HighlightColor color; |
|
27 |
LineSegment line; |
|
28 |
IDocument document; |
|
29 |
||
30 |
int offset; |
|
31 |
int length; |
|
32 |
||
33 |
public sealed class SpaceTextWord : TextWord |
|
34 |
{ |
|
35 |
public SpaceTextWord() |
|
36 |
{ |
|
37 |
length = 1; |
|
38 |
} |
|
39 |
||
40 |
public SpaceTextWord(HighlightColor color) |
|
41 |
{ |
|
42 |
length = 1; |
|
43 |
base.SyntaxColor = color; |
|
44 |
} |
|
45 |
||
46 |
public override Font GetFont(FontContainer fontContainer) |
|
47 |
{ |
|
48 |
return null; |
|
49 |
} |
|
50 |
||
51 |
public override TextWordType Type { |
|
52 |
get { |
|
53 |
return TextWordType.Space; |
|
54 |
} |
|
55 |
} |
|
56 |
public override bool IsWhiteSpace { |
|
57 |
get { |
|
58 |
return true; |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
public sealed class TabTextWord : TextWord |
|
64 |
{ |
|
65 |
public TabTextWord() |
|
66 |
{ |
|
67 |
length = 1; |
|
68 |
} |
|
69 |
public TabTextWord(HighlightColor color) |
|
70 |
{ |
|
71 |
length = 1; |
|
72 |
base.SyntaxColor = color; |
|
73 |
} |
|
74 |
||
75 |
public override Font GetFont(FontContainer fontContainer) |
|
76 |
{ |
|
77 |
return null; |
|
78 |
} |
|
79 |
||
80 |
public override TextWordType Type { |
|
81 |
get { |
|
82 |
return TextWordType.Tab; |
|
83 |
} |
|
84 |
} |
|
85 |
public override bool IsWhiteSpace { |
|
86 |
get { |
|
87 |
return true; |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
static TextWord spaceWord = new SpaceTextWord(); |
|
93 |
static TextWord tabWord = new TabTextWord(); |
|
94 |
||
95 |
bool hasDefaultColor; |
|
96 |
||
97 |
public static TextWord Space { |
|
98 |
get { |
|
99 |
return spaceWord; |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
public static TextWord Tab { |
|
104 |
get { |
|
105 |
return tabWord; |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
public int Offset { |
|
110 |
get { |
|
111 |
return offset; |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
public int Length { |
|
116 |
get { |
|
117 |
return length; |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
/// <summary> |
|
122 |
/// Splits the <paramref name="word"/> into two parts: the part before <paramref name="pos"/> is assigned to |
|
123 |
/// the reference parameter <paramref name="word"/>, the part after <paramref name="pos"/> is returned. |
|
124 |
/// </summary> |
|
125 |
public static TextWord Split(ref TextWord word, int pos) |
|
126 |
{ |
|
127 |
#if DEBUG |
|
128 |
if (word.Type != TextWordType.Word) |
|
129 |
throw new ArgumentException("word.Type must be Word"); |
|
130 |
if (pos <= 0) |
|
131 |
throw new ArgumentOutOfRangeException("pos", pos, "pos must be > 0"); |
|
132 |
if (pos >= word.Length) |
|
133 |
throw new ArgumentOutOfRangeException("pos", pos, "pos must be < word.Length"); |
|
134 |
#endif |
|
135 |
TextWord after = new TextWord(word.document, word.line, word.offset + pos, word.length - pos, word.color, word.hasDefaultColor); |
|
136 |
word = new TextWord(word.document, word.line, word.offset, pos, word.color, word.hasDefaultColor); |
|
137 |
return after; |
|
138 |
} |
|
139 |
||
140 |
public bool HasDefaultColor { |
|
141 |
get { |
|
142 |
return hasDefaultColor; |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
public virtual TextWordType Type { |
|
147 |
get { |
|
148 |
return TextWordType.Word; |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
public string Word { |
|
153 |
get { |
|
154 |
if (document == null) { |
|
155 |
return String.Empty; |
|
156 |
} |
|
157 |
return document.GetText(line.Offset + offset, length); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
public virtual Font GetFont(FontContainer fontContainer) |
|
162 |
{ |
|
163 |
return color.GetFont(fontContainer); |
|
164 |
} |
|
165 |
||
166 |
public Color Color { |
|
167 |
get { |
|
168 |
if (color == null) |
|
169 |
return Color.Black; |
|
170 |
else |
|
171 |
return color.Color; |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
public bool Bold { |
|
176 |
get { |
|
177 |
if (color == null) |
|
178 |
return false; |
|
179 |
else |
|
180 |
return color.Bold; |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
public bool Italic { |
|
185 |
get { |
|
186 |
if (color == null) |
|
187 |
return false; |
|
188 |
else |
|
189 |
return color.Italic; |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
public HighlightColor SyntaxColor { |
|
194 |
get { |
|
195 |
return color; |
|
196 |
} |
|
197 |
set { |
|
198 |
Debug.Assert(value != null); |
|
199 |
color = value; |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
public virtual bool IsWhiteSpace { |
|
204 |
get { |
|
205 |
return false; |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
protected TextWord() |
|
210 |
{ |
|
211 |
} |
|
212 |
||
213 |
// TAB |
|
214 |
public TextWord(IDocument document, LineSegment line, int offset, int length, HighlightColor color, bool hasDefaultColor) |
|
215 |
{ |
|
216 |
Debug.Assert(document != null); |
|
217 |
Debug.Assert(line != null); |
|
218 |
Debug.Assert(color != null); |
|
219 |
||
220 |
this.document = document; |
|
221 |
this.line = line; |
|
222 |
this.offset = offset; |
|
223 |
this.length = length; |
|
224 |
this.color = color; |
|
225 |
this.hasDefaultColor = hasDefaultColor; |
|
226 |
} |
|
227 |
||
228 |
/// <summary> |
|
229 |
/// Converts a <see cref="TextWord"/> instance to string (for debug purposes) |
|
230 |
/// </summary> |
|
231 |
public override string ToString() |
|
232 |
{ |
|
233 |
return "[TextWord: Word = " + Word + ", Color = " + Color + "]"; |
|
234 |
} |
|
235 |
} |
|
236 |
} |