/// <summary>The base class of text box colorizer.</summary>
class
GuiTextBoxColorizerBase
:
public
Object
,
public
virtual
ICommonTextEditCallback
{
public
:
typedef
collections
::
Array
<
elements
::
text
::
ColorEntry
>
ColorArray
;
protected
:
elements
::
GuiColorizedTextElement
*
element
;
SpinLock
*
elementModifyLock
;
volatile
vint
colorizedLineCount
;
volatile
bool
isColorizerRunning
;
volatile
bool
isFinalizing
;
SpinLock
colorizerRunningEvent
;
static
void
ColorizerThreadProc
(
void
*
argument
);
void
StartColorizer
();
void
StopColorizer
(
bool
forever
);
void
StopColorizerForever
();
public
:
/// <summary>Create a colorrizer.</summary>
GuiTextBoxColorizerBase
();
~
GuiTextBoxColorizerBase
();
void
Attach
(
elements
::
GuiColorizedTextElement
*
_element
,
SpinLock
&
_elementModifyLock
,
compositions
::
GuiGraphicsComposition
*
_ownerComposition
,
vuint
editVersion
)
override
;
void
Detach
()
override
;
void
TextEditPreview
(
TextEditPreviewStruct
&
arguments
)
override
;
void
TextEditNotify
(
const
TextEditNotifyStruct
&
arguments
)
override
;
void
TextCaretChanged
(
const
TextCaretChangedStruct
&
arguments
)
override
;
void
TextEditFinished
(
vuint
editVersion
)
override
;
void
RestartColorizer
();
/// <summary>Get the lexical analyzer start state for the first line.</summary>
/// <returns>The lexical analyzer start state for the first line.</returns>
virtual
vint
GetLexerStartState
()=
0
;
/// <summary>Get the context sensitive start state for the first line.</summary>
/// <returns>The context sensitive start state for the first line.</returns>
virtual
vint
GetContextStartState
()=
0
;
/// <summary>Colorizer one line with a start state.</summary>
/// <param name="lineIndex">Line index.</param>
/// <param name="text">Text buffer.</param>
/// <param name="colors">Color index buffer. The index should be in [0 .. [M:vl.presentation.controls.GuiTextBoxColorizerBase.GetColors]()-1].</param>
/// <param name="length">The length of the buffer.</param>
/// <param name="lexerState">The lexical analyzer state for this line. After executing this function, the new value of this argument indicates the new state.</param>
/// <param name="contextState">The context sensitive state for this line. After executing this function, the new value of this argument indicates the new state.</param>
virtual
void
ColorizeLineWithCRLF
(
vint
lineIndex
,
const
wchar_t
*
text
,
vuint32_t
*
colors
,
vint
length
,
vint
&
lexerState
,
vint
&
contextState
)=
0
;
/// <summary>Get the supported colors ordered by their indices.</summary>
/// <returns>The supported colors ordered by their indices.</returns>
/// <summary>Add a token type. Call [M:vl.presentation.controls.GuiTextBoxRegexColorizer.Setup] after finishing all configuration.</summary>
/// <returns>Returns the token index of this token. Returns -1 if this operation failed.</returns>
/// <param name="regex">The regular expression for this token type.</param>
/// <param name="color">The color for this token type.</param>
vint
AddToken
(
const
WString
&
regex
,
elements
::
text
::
ColorEntry
color
);
/// <summary>Add an extra token type. Call [M:vl.presentation.controls.GuiTextBoxRegexColorizer.Setup] after finishing all configuration.</summary>
/// <returns>Returns the extra token index of this token. The token index for this token is regex-token-count + extra-token-index Returns -1 if this operation failed.</returns>
/// <param name="color">The color for this token type.</param>
vint
AddExtraToken
(
elements
::
text
::
ColorEntry
color
);
/// <summary>Clear all token color settings.</summary>
void
ClearTokens
();
/// <summary>Setup the colorizer. After that, the colorizer cannot be changed.</summary>
void
Setup
();
/// <summary>Callback function to set context sensitive state and change token accordingly.</summary>
/// <param name="lineIndex">Line index.</param>
/// <param name="text">Text buffer.</param>
/// <param name="start">The start position of the token.</param>
/// <param name="length">The length of the token.</param>
/// <param name="token">The token type. After executing this function, the new value of this argument indicates the new token type.</param>
/// <param name="contextState">The context sensitive state. After executing this function, the new value of this argument indicates the new state.</param>