Coloring and Text Styling

Each language supported by Scintilla has an associated lexical analyzer, which understands that language. It is responsible for examining the text contained in the control and determining, with the help of up to nine keyword tables, which characters in the text make up a keyword, numeric literal, string literal, or a comment, and setting appropriate style information about that text.

Each character of text has an associated byte of style information, which includes a style number and up to three indicator bits. Each language specifies its own table of style numbers. For example, the JADE lexer uses style SCE_JAD_KEYWORD (12) for keywords such as if, while, and endif, and style SCE_JAD_COMMENTLINE (7) for line-based comments beginning with a double slash (//).

Each character in a line of text is displayed using the attributes associated with its style number. The style attributes include font, font size, bold, italic, foreground color, and background color. The indicator bits provide an additional way to highlight text independent of the basic styling. Indicator bits can highlight a section of text with a red wavy underline symbol, to indicate a syntax error without overriding keyword coloring.

Style numbers in the range 32 (STYLE_DEFAULT) through 39 provide style attributes for non-text-related items such as line numbers. You can use style 32 (STYLE_DEFAULT) to initialize all possible styles (in the range zero through 127) to a common setting before language-specific style settings are applied.

The clearAllStyles method initializes the default style to the attributes specified on the control (that is, the fontName, fontSize, fontBold, fontItalic, fontUnderline, foreColor, and backColor property values) and then copies the default style to all other styles. The setStyleAttributes method alters one or more of the attributes of a specific style. The copyDefaultToAllStyles method copies the default style to all other styles.

The changeKeywords method can set one of the nine keyword lists to a specified list of words (separated by whitespace). It can also add or delete one or more words from a specified list and it can set all of the keyword lists to language-specific entries taken from the application and global setting tables.

The applySettings method loads the text styles table and the keywords lists with entries taken from the application and global settings tables, which are specific to the current language.

The minimum code required to have the text styled according to a fully supported language (for example, C++) is as follows.

control-name.language := SCLEX_CPP;
control-name.applySettings();
control-name.restyleText();