-
Notifications
You must be signed in to change notification settings - Fork 1
/
Indicator.cs
303 lines (276 loc) · 12.5 KB
/
Indicator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// ***********************************************************************
// Assembly : Zeroit.Framework.CodeBox
// Author : ZEROIT
// Created : 03-19-2019
//
// Last Modified By : ZEROIT
// Last Modified On : 01-05-2019
// ***********************************************************************
// <copyright file="Indicator.cs" company="Zeroit Dev">
// This program is for creating a Code Editor control.
// Copyright © 2017 Zeroit Dev Technologies
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// You can contact me at zeroitdevnet@gmail.com or zeroitdev@outlook.com
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Drawing;
namespace Zeroit.Framework.CodeBox
{
/// <summary>
/// Represents an indicator in a <see cref="Scintilla" /> control.
/// </summary>
public class Indicator
{
#region Fields
private readonly ZeroitCodeExplorer Scintilla;
#endregion Fields
#region Constants
/// <summary>
/// An OR mask to use with <see cref="Scintilla.IndicatorValue" /> and <see cref="IndicatorFlags.ValueFore" /> to indicate
/// that the user-defined indicator value should be treated as a RGB color.
/// </summary>
public const int ValueBit = NativeMethods.SC_INDICVALUEBIT;
/// <summary>
/// An AND mask to use with <see cref="Indicator.ValueAt" /> to retrieve the user-defined value as a RGB color when being treated as such.
/// </summary>
public const int ValueMask = NativeMethods.SC_INDICVALUEMASK;
#endregion Constants
#region Methods
/// <summary>
/// Given a document position which is filled with this indicator, will return the document position
/// where the use of this indicator ends.
/// </summary>
/// <param name="position">A zero-based document position using this indicator.</param>
/// <returns>The zero-based document position where the use of this indicator ends.</returns>
/// <remarks>
/// Specifying a <paramref name="position" /> which is not filled with this indicator will cause this method
/// to return the end position of the range where this indicator is not in use (the negative space). If this
/// indicator is not in use anywhere within the document the return value will be 0.
/// </remarks>
public int End(int position)
{
position = Helpers.Clamp(position, 0, Scintilla.TextLength);
position = Scintilla.Lines.CharToBytePosition(position);
position = Scintilla.DirectMessage(NativeMethods.SCI_INDICATOREND, new IntPtr(Index), new IntPtr(position)).ToInt32();
return Scintilla.Lines.ByteToCharPosition(position);
}
/// <summary>
/// Given a document position which is filled with this indicator, will return the document position
/// where the use of this indicator starts.
/// </summary>
/// <param name="position">A zero-based document position using this indicator.</param>
/// <returns>The zero-based document position where the use of this indicator starts.</returns>
/// <remarks>
/// Specifying a <paramref name="position" /> which is not filled with this indicator will cause this method
/// to return the start position of the range where this indicator is not in use (the negative space). If this
/// indicator is not in use anywhere within the document the return value will be 0.
/// </remarks>
public int Start(int position)
{
position = Helpers.Clamp(position, 0, Scintilla.TextLength);
position = Scintilla.Lines.CharToBytePosition(position);
position = Scintilla.DirectMessage(NativeMethods.SCI_INDICATORSTART, new IntPtr(Index), new IntPtr(position)).ToInt32();
return Scintilla.Lines.ByteToCharPosition(position);
}
/// <summary>
/// Returns the user-defined value for the indicator at the specified position.
/// </summary>
/// <param name="position">The zero-based document position to get the indicator value for.</param>
/// <returns>The user-defined value at the specified <paramref name="position" />.</returns>
public int ValueAt(int position)
{
position = Helpers.Clamp(position, 0, Scintilla.TextLength);
position = Scintilla.Lines.CharToBytePosition(position);
return Scintilla.DirectMessage(NativeMethods.SCI_INDICATORVALUEAT, new IntPtr(Index), new IntPtr(position)).ToInt32();
}
#endregion Methods
#region Properties
/// <summary>
/// Gets or sets the alpha transparency of the indicator.
/// </summary>
/// <returns>
/// The alpha transparency ranging from 0 (completely transparent)
/// to 255 (no transparency). The default is 30.
/// </returns>
public int Alpha
{
get
{
return Scintilla.DirectMessage(NativeMethods.SCI_INDICGETALPHA, new IntPtr(Index)).ToInt32();
}
set
{
value = Helpers.Clamp(value, 0, 255);
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETALPHA, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets or sets the indicator flags.
/// </summary>
/// <returns>
/// A bitwise combination of the <see cref="IndicatorFlags" /> enumeration.
/// The default is <see cref="IndicatorFlags.None" />.
/// </returns>
public IndicatorFlags Flags
{
get
{
return (IndicatorFlags)Scintilla.DirectMessage(NativeMethods.SCI_INDICGETFLAGS, new IntPtr(Index));
}
set
{
int flags = (int)value;
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETFLAGS, new IntPtr(Index), new IntPtr(flags));
}
}
/// <summary>
/// Gets or sets the color used to draw an indicator.
/// </summary>
/// <returns>The Color used to draw an indicator. The default varies.</returns>
/// <remarks>Changing the <see cref="ForeColor" /> property will reset the <see cref="HoverForeColor" />.</remarks>
/// <seealso cref="HoverForeColor" />
public Color ForeColor
{
get
{
var color = Scintilla.DirectMessage(NativeMethods.SCI_INDICGETFORE, new IntPtr(Index)).ToInt32();
return ColorTranslator.FromWin32(color);
}
set
{
var color = ColorTranslator.ToWin32(value);
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETFORE, new IntPtr(Index), new IntPtr(color));
}
}
/// <summary>
/// Gets or sets the color used to draw an indicator when the mouse or caret is over an indicator.
/// </summary>
/// <returns>
/// The Color used to draw an indicator.
/// By default, the hover style is equal to the regular <see cref="ForeColor" />.
/// </returns>
/// <remarks>Changing the <see cref="ForeColor" /> property will reset the <see cref="HoverForeColor" />.</remarks>
/// <seealso cref="ForeColor" />
public Color HoverForeColor
{
get
{
var color = Scintilla.DirectMessage(NativeMethods.SCI_INDICGETHOVERFORE, new IntPtr(Index)).ToInt32();
return ColorTranslator.FromWin32(color);
}
set
{
var color = ColorTranslator.ToWin32(value);
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETHOVERFORE, new IntPtr(Index), new IntPtr(color));
}
}
/// <summary>
/// Gets or sets the indicator style used when the mouse or caret is over an indicator.
/// </summary>
/// <returns>
/// One of the <see cref="Zeroit.Framework.CodeBox.IndicatorStyle" /> enumeration values.
/// By default, the hover style is equal to the regular <see cref="Style" />.
/// </returns>
/// <remarks>Changing the <see cref="Style" /> property will reset the <see cref="HoverStyle" />.</remarks>
/// <seealso cref="Style" />
public IndicatorStyle HoverStyle
{
get
{
return (IndicatorStyle)Scintilla.DirectMessage(NativeMethods.SCI_INDICGETHOVERSTYLE, new IntPtr(Index));
}
set
{
var style = (int)value;
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETHOVERSTYLE, new IntPtr(Index), new IntPtr(style));
}
}
/// <summary>
/// Gets the zero-based indicator index this object represents.
/// </summary>
/// <returns>The indicator definition index within the <see cref="IndicatorCollection" />.</returns>
public int Index { get; private set; }
/// <summary>
/// Gets or sets the alpha transparency of the indicator outline.
/// </summary>
/// <returns>
/// The alpha transparency ranging from 0 (completely transparent)
/// to 255 (no transparency). The default is 50.
/// </returns>
public int OutlineAlpha
{
get
{
return Scintilla.DirectMessage(NativeMethods.SCI_INDICGETOUTLINEALPHA, new IntPtr(Index)).ToInt32();
}
set
{
value = Helpers.Clamp(value, 0, 255);
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETOUTLINEALPHA, new IntPtr(Index), new IntPtr(value));
}
}
/// <summary>
/// Gets or sets the indicator style.
/// </summary>
/// <returns>One of the <see cref="Zeroit.Framework.CodeBox.IndicatorStyle" /> enumeration values. The default varies.</returns>
/// <remarks>Changing the <see cref="Style" /> property will reset the <see cref="HoverStyle" />.</remarks>
/// <seealso cref="HoverStyle" />
public IndicatorStyle Style
{
get
{
return (IndicatorStyle)Scintilla.DirectMessage(NativeMethods.SCI_INDICGETSTYLE, new IntPtr(Index));
}
set
{
var style = (int)value;
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETSTYLE, new IntPtr(Index), new IntPtr(style));
}
}
/// <summary>
/// Gets or sets whether indicators are drawn under or over text.
/// </summary>
/// <returns>true to draw the indicator under text; otherwise, false. The default is false.</returns>
/// <remarks>Drawing indicators under text requires <see cref="Phases.One" /> or <see cref="Phases.Multiple" /> drawing.</remarks>
public bool Under
{
get
{
return (Scintilla.DirectMessage(NativeMethods.SCI_INDICGETUNDER, new IntPtr(Index)) != IntPtr.Zero);
}
set
{
var under = (value ? new IntPtr(1) : IntPtr.Zero);
Scintilla.DirectMessage(NativeMethods.SCI_INDICSETUNDER, new IntPtr(Index), under);
}
}
#endregion Properties
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Indicator" /> class.
/// </summary>
/// <param name="Scintilla">The <see cref="Scintilla" /> control that created this indicator.</param>
/// <param name="index">The index of this style within the <see cref="IndicatorCollection" /> that created it.</param>
public Indicator(ZeroitCodeExplorer Scintilla, int index)
{
this.Scintilla = Scintilla;
Index = index;
}
#endregion Constructors
}
}