[Home]

wxScintilla API reference

Derived from the Scintilla documentation (edited 3/June/2005 NH)

Introduction

The Windows version of Scintilla is a Windows Control. As such, its primary programming interface is through Windows messages. Early versions of Scintilla emulated much of the API defined by the standard Windows Edit and RichEdit controls but those APIs are now deprecated in favour of Scintilla's own, more consistent API. In addition to messages performing the actions of a normal Edit control, Scintilla allows control of syntax styling, folding, markers, autocompletion and call tips.

The GTK+ version also uses messages in a similar way to the Windows version. This is different to normal GTK+ practice but made it easier to implement rapidly.

In the descriptions that follow, the commands are described as function calls with zero, one or two arguments. These two arguments are the standard wParam and lParam familiar to Windows programmers. Although the commands only use the arguments described, because all messages have two arguments whether Scintilla uses them or not, it is strongly recommended that any unused arguments are set to 0. This allows future enhancement of messages without the risk of breaking existing code. Common argument types are:

bool Arguments expect the values 0 for false and 1 for true.
int Arguments are 32-bit signed integers.
const char * Arguments point at text that is being passed to Scintilla but not modified. The text may be zero terminated or another argument may specify the character count, the description will make this clear.
char * Arguments point at text buffers that Scintilla will fill with text. In some cases, another argument will tell Scintilla the buffer size. In others, you must make sure that the buffer is big enough to hold the requested text. If a NULL pointer (0) is passed then, for SCI_* calls, the length that should be allocated is returned.
colour Colours are set using the RGB format (Red, Green, Blue). The intensity of each colour is set in the range 0 to 255. If you have three such intensities, they are combined as: red | (green << 8) | (blue << 16). If you set all intensities to 255, the colour is white. If you set all intensities to 0, the colour is black. When you set a colour, you are making a request. What you will get depends on the capabilities of the system and the current screen mode.

Contents

o Text retrieval and modification o Searching and replacing o Overtype
o Cut, copy and paste o Error handling o Undo and Redo
o Selection and information o Scrolling and automatic scrolling o White space
o Cursor o Mouse capture o Line endings
o Styling o Style definition o Caret, selection, and hotspot styles
o Margins o Other settings o Brace highlighting
o Tabs and Indentation Guides o Markers o Indicators
o Autocompletion o User lists o Call tips
o Keyboard commands o Key bindings o Popup edit menu
o Macro recording o Printing o Line wrapping
o Multiple views o Folding o Lexer
o Zooming o Long lines o Notifications

Functions with names of the form Set... often have a companion Get.... To save tedious repetition, if the Get... returns the value set by the Set..., the routines are described together.

Text retrieval and modification

Each character in a Scintilla document is followed by an associated byte of styling information. The combination of a character byte and a style byte is called a cell. Style bytes are interpreted as a style index in the low 5 bits and as 3 individual bits of indicators. This allows 32 fundamental styles, which is enough for most languages, and three in dependent indicators. For example, syntax errors, deprecated names and bad indentation could all be displayed at once. The number of bits used for styles can be altered with SetStyleBits up to a maximum of 7 bits (some languages require more bits, e.g. HTML=7 bits). The remaining bits can be used for indicators.

Positions within the Scintilla document refer to a character or the gap before that character. The first character in a document is 0, the second 1 and so on. If a document contains nLen characters, the last character is numbered nLen-1. The caret exists between character positions and can be located from before the first character (0) to after the last character (nLen).

There are places where the caret can not go where two character bytes make up one character. This occurs when a DBCS character from a language like Japanese is included in the document or when line ends are marked with the CP/M standard of a carriage return followed by a line feed. The wxSCI_INVALID_POSITION constant (-1) represents an invalid position within the document.

All lines of text in Scintilla are the same height, and this height is calculated from the largest font in any current style. This restriction is for performance; if lines differed in height then calculations involving positioning of text would require the text to be styled first.

wxString GetText()

Returns all the characters of text from the start of the document. If you then save the text, you should use SetSavePoint to mark the text as unmodified.

See also: GetSelectedText, GetCurLine, GetLine, GetStyledText, GetTextRange

void SetText (const wxString& text)

Replaces all the text in the document with the text string you pass in. Any previous existing text is deleted.

wxString GetLine (int line)

Returns a string with the contents of the nominated line (line numbers start at 0).

See also: GetCurLine, GetSelectedText, GetTextRange, GetStyledText, GetText

void ReplaceSelection (const wxString& text)

The currently selected text between the anchor and the current position is replaced by the text string. If the anchor and current position are the same (meaning no selection), the text is inserted at the caret position. The caret is positioned after the inserted text and the caret is scrolled into view.

void SetReadOnly (bool readOnly)
bool GetReadOnly()

Set and get the read-only flag of the document. If you mark a document as read only, attempts to modify the text will fail and cause the wxEVT_SCI_MODIFYATTEMPTRO notification.

wxString GetTextRange (int startPos, int endPos)

Returns the text between the positions startPos and endPos. If endPos is wxSCI_INVALID_POSITION, text is returned to the end of the document.

See also: GetSelectedText, GetLine, GetCurLine, GetStyledText, GetText

wxMemoryBuffer GetStyledText (int startPos, int endPos)

Returns the styled text into a buffer using two bytes for each cell, with the character at the lower address of each pair and the style byte at the upper address. Characters between the positions startPos and endPos are copied.

See also: GetSelectedText, GetLine, GetCurLine, GetTextRange, GetText

void Allocate (int bytes)

Allocate a document buffer large enough to store a given number of bytes. The document will not be made smaller than its current contents.

Note: Do not use this function if you don't know what you exactly do.

void AddText (const wxString& text)
void AddText (const int length, const wxString& text)

Inserts the string at the current position. The current position is set at the end of the inserted text, but it is not scrolled into view. If you need to add strings with binary values (e.g. Unicode characters), use the form with the length parameter.

void AddStyledText (const wxMemoryBuffer& data)

This behaves just like AddText, but inserts styled text.

void AppendText (const wxString& text)
void AppendText (int length, const wxString& text)

Appends the string at the last position in the document. The current selection is not changed and the new text is not scrolled into view. If you need to add strings with binary values (e.g. Unicode characters), use the form with the length parameter.

void InsertText (int pos, const wxString& text)

Inserts the string at position pos or at the current position if pos is wxSCI_INVALID_POSITION. The current position is set at the end of the inserted text, but it is not scrolled into view.

void ClearAll()

Deletes all the text (unless the document is read-only).

void ClearDocumentStyle()

When wanting to completely restyle the document, for example after choosing a lexer, the ClearDocumentStyle can be used to clear all styling information and reset the folding state.

See also: Colourise

int GetCharAt (int pos)

Returns the character at pos in the document. If pos is negative or past the end of the document, returns 0.

int GetStyleAt (int pos)

Returns the style at pos in the document. If pos is negative or past the end of the document, returns 0.

void SetStyleBits (int bits)
int GetStyleBits

Sets and reads back the number of bits in each cell to use for styling, to a maximum of 7 style bits. The remaining bits can be used as indicators. The default setting is 5 style bits.

Searching

See also: Search and replace using the target

searchFlags

Several of the search routines use flag options, which include a simple regular expression search. Combine the flag options by adding them:

wxSCI_FIND_MATCHCASE A match only occurs with text that matches the case of the search string.
wxSCI_FIND_WHOLEWORD A match only occurs if the characters before and after are not word characters.
wxSCI_FIND_WORDSTART A match only occurs if the character before is not a word character.
wxSCI_FIND_REGEXP The search string should be interpreted as a regular expression.
wxSCI_FIND_POSIX Treat regular expression in a more POSIX compatible manner by interpreting bare (and) for tagged sections rather than \( and \).

If wxSCI_FIND_REGEXP is not included in the searchFlags, you can search backwards to find the previous occurrence of a search string by setting the end of the search range before the start. If wxSCI_FIND_REGEXP is included, searches are always from a lower position to a higher position, even if the search range is awkward.

In a regular expression, special characters interpreted are:

. Matches any character
\( This marks the start of a region for tagging a match.
\) This marks the end of a tagged region.
\n Where n is 1 through 9 refers to the first through ninth tagged region when replacing. For example, if the search string was Fred\([1-9]\)XXX and the replace string was Sam\1YYY, when applied to Fred2XXX this would generate Sam2YYY.
\< This matches the start of a word using Scintilla's definitions of words.
\> This matches the end of a word using Scintilla's definition of words.
\x This allows you to use a character x that would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set.
[...] This indicates a set of characters, for example, [abc] means any of the characters a, b or c. You can also use ranges, for example [a-z] for any lower case character.
[^...] The complement of the characters in the set. For example, [^A-Za-z] means any character except an alphabetic character.
^ This matches the start of a line (unless used inside a set, see above).
$ This matches the end of a line.
* This matches 0 or more times. For example, Sa*m matches Sm, Sam, Saam, Saaam and so on.
+ This matches 1 or more times. For example, Sa+m matches Sam, Saam, Saaam and so on.

int FindText (int minPos, int maxPos, const wxString& text, int flags=0)

FindText performs a straightforward text search through the entire document. The minPos and maxPos arguments specify the range within the Document to search. No surprise, the text argument is a string object containing the string to search for. The flags argument controls the search. You can set maxPos less than minPos to search in reverse. Returns the start position of the found text, or wxSCI_INVALID_POSITION if it isn't found.

See also: SearchInTarget

void SearchAnchor()
int SearchNext (int flags, const wxString& text)
int SearchPrev (int flags, const wxString& text)

These provide relocatable search support. This allows multiple incremental interactive searches to be macro recorded while still setting the selection to found text so the find/select operation is self-contained. They send wxEVT_SCI_MACRORECORD notifications if macro recording is enabled.

SearchAnchor sets the search start point used by SearchNext and SearchPrev to the start of the current selection, that is, the end of the selection that is nearer to the start of the document. You should always call this before calling either of SearchNext or SearchPrev.

SearchNext and SearchPrev search for the next and previous occurrence of the search string pointed at by text. The search is modified by the searchFlags. If you request a regular expression, SearchPrev finds the first occurrence of the search string in the document, not the previous one before the anchor point.

Return value is the start position of the matching text, otherwise wxSCI_INVALID_POSITION if nothing is found. The selection is updated to show the matched text, but is not scrolled into view.

See also: SearchInTarget

Search and replace using the target

Searching can be performed within the target range with SearchInTarget, which uses a counted string to allow searching for null characters. It returns the length of range or wxSCI_INVALID_POSITION if not found, in which case the target is not moved. The flags used by SearchInTarget such as wxSCI_FIND_MATCHCASE, wxSCI_FIND_WHOLEWORD, wxSCI_FIND_WORDSTART, and wxSCI_FIND_REGEXP can be set with SetSearchFlags. SearchInTarget may be simpler for some clients to use than FindText.

Using ReplaceSelection, modifications cause scrolling and other visible changes, which may take some time and cause unwanted display updates. If performing many changes, such as a replace all command, the target can be used instead. First, set the target, i.e. the range to be replaced. Then call ReplaceTarget or ReplaceTargetRE.

void SetTargetStart (int pos)
int GetTargetStart()

void SetTargetEnd (int pos) int GetTargetEnd()

Set and return the start and end of the target. When searching in non-regular expression mode, you can set start position greater than end position to find the last matching text in the target rather than the first matching text. The target is also set by a successful SearchInTarget.

void TargetFromSelection()

Set the target start and end to the start and end positions of the current selection.

void SetSearchFlags (int flags)
int GetSearchFlags()

Set and get the searchFlags used by SearchInTarget. There are several option flags including a simple regular expression search.

int SearchInTarget (const wxString& text)

This searches for the first occurrence of a text string in the target defined by SetTargetStart and SetTargetEnd. The text string is not zero terminated; the size is set by length. The search is modified by the search flags set by SetSearchFlags. If the search succeeds, the target is set to the found text and the return value is the position of the start of the matching text. If the search fails, the result is wxSCI_INVALID_POSITION.

int ReplaceTarget (const wxString& text)

The return value is the length of the replacement string.

int ReplaceTargetRE (const wxString& text)

This replaces the target using regular expressions. The replacement string is formed from the text string with any sequences of \1 through \9 replaced by tagged matches from the most recent regular expression search. The return value is the length of the replacement string.

Overtype

void SetOvertype (bool overtype)
bool GetOvertype()

When overtype is enabled, each typed character replaces the character to the right of the text caret. When overtype is disabled, characters are inserted at the caret. GetOvertype returns true if overtyping is active, otherwise false. Use SetOvertype (true) to set the overtype mode.

Cut, copy and paste

void Cut()
void Copy()
void Paste()
void Clear()
bool CanPaste()

Perform the standard commands of cutting and copying data to the clipboard, pasting from the clipboard into the document, and clearing the document. CanPaste returns true if the document isn't read-only and if the selection doesn't contain protected text. If you need a "can copy" or "can cut", use GetSelectionStart()-GetSelectionEnd(), which will be non-zero if you can copy or cut to the clipboard.

GTK+ does not really support CanPaste and always returns true unless the document is read-only.

void CopyRange (int startPos, int endPos)
void CopyText (int length, const wxString& text)

CopyRange copies a range of text from the document to the system clipboard and CopyText copies a supplied piece of text to the system clipboard.

Error handling

void SetStatus (int status)
int GetStatus()

If an error occurs, Scintilla may set an internal error number that can be retrieved with GetStatus. Not currently used but will be in the future. To clear the error status call SetStatus (0).

Undo and Redo

Scintilla has multiple level undo and redo. It will continue to collect undoable actions until memory runs out. Scintilla saves actions that change the document. Scintilla does not save caret and selection movements, view scrolling and the like. Sequences of typing or deleting are compressed into single actions to make it easier to undo and redo at a sensible level of detail. Sequences of actions can be combined into actions that are undone as a unit. These sequences occur between BeginUndoAction and EndUndoAction. These sequences can be nested and only the top-level sequences are undone as units.

void Undo()

Undo undoes one action, or if the undo buffer has reached a EndUndoAction point, all the actions back to the corresponding BeginUndoAction.

bool CanUndo()

CanUndo returns true if there is nothing to undo, otherwise false. You would typically use the result to enable/disable the Edit menu Undo command.

void Redo()

Redo undoes the effect of the last Undo operation.

bool CanRedo()

CanRedo returns true if there is no action to redo, otherwise false. You could typically use the result to enable/disable the Edit menu Redo command.

void EmptyUndoBuffer()

This command tells Scintilla to forget any saved undo or redo history. It also sets the save point to the start of the undo buffer, so the document will appear to be unmodified. This does not cause the CN_SAVEPOINTREACHED notification to be sent to the container as SetSavePoint does.

void SetSavePoint()

Sets the current state of the document to unmodified. This is usually done when the file is saved or loaded, hence the name "save point". As Scintilla performs undo and redo operations, it notifies the container that it has entered or left the save point with wxEVT_SCI_SAVEPOINTREACHED and wxEVT_SCI_SAVEPOINTLEFT notification messages, allowing the container to know if the file should be considered dirty or not.

void SetUndoCollection (bool collectUndo)
bool GetUndoCollection()

You can control whether Scintilla collects undo information with SetUndoCollection. Pass in true to collect information and false to stop collecting. If you stop collection, you should also use EmptyUndoBuffer to avoid the undo buffer being unsynchronized with the data in the buffer.

You might wish to turn off saving undo information if you use the Scintilla to store text generated by a program (a Log view) or in a display window where text is often deleted and regenerated. This can be done with SetUndoCollection (false).

void BeginUndoAction()
void EndUndoAction()

Mark the beginning and end of a set of operations that you want to undo all as one operation but that you have to generate as several operations. Alternatively, you can use these to mark a set of operations that you do not want to have combined with the preceding or following operations if they are undone.

bool GetModify()

Returns true if the document is modified and false if it is unmodified. The modified status of a document is determined by the undo position relative to the save point. The save point is set by SetSavePoint, usually when you have saved data to a file.

If you need to be notified when the document becomes modified, Scintilla notifies the container that it has entered or left the save point with the wxEVT_SCI_SAVEPOINTREACHED and wxEVT_SCI_SAVEPOINTLEFT notification messages.

Selection and information

Scintilla maintains a selection that stretches between two points, the anchor and the current position. If the anchor and the current position are the same, there is no selected text. Positions in the document range from 0 (before the first character), to the document size (after the last character). There is nothing to stop you setting a position that is in the middle of a CRLF pair, or in the middle of a 2 byte character. However, keyboard commands will not move the caret into such positions.

int GetLength()
int GetTextLength()

Return the length of the document in characters. The use of GetLength is prefered.

int GetLineCount()

Returns the number of lines in the document. An empty document contains 1 line. A document holding only an end of line sequence has 2 lines.

int GetFirstVisibleLine()

Returns the line number of the first visible line in the Scintilla view. The first line in the document is numbered 0.

int LinesOnScreen()

Returns the number of complete lines visible on the screen. With a constant line height, this is the vertical space available divided by the line separation. Unless you arrange to size your window to an integral number of lines, there may be a partial line visible at the bottom of the view.

void SetSelection (int startPos, int endPos)

Sets both the anchor (startPos) and the current position (endPos) and selects the text. If endPos is negative, it means the end of the document. If startPos is negative, it means remove any selection (i.e. set the anchor to the same position as currentPos). The caret is scrolled into view after this operation.

void GotoPos (int pos)

Sets the caret at pos, removes any selection and scrolls the view to make the caret visible, if necessary. It is equivalent to SetSelection (pos, pos). The anchor position is set the same as the current position.

void GotoLine (int line)

Sets the caret at the start of line number line, removes any selection and scrolls the view (if needed) to make it visible. The anchor position is set the same as the current position. If line is outside the lines in the document (first line is 0), the line set is the first or last.

void SetCurrentPos (int pos)

Sets the current position and creates a selection between the anchor and the current position. The caret is not scrolled into view.

See also: EnsureCaretVisible

int GetCurrentPos()

This returns the current position.

void SetAnchor (int posAnchor)

This sets the anchor position and creates a selection between the anchor position and the current position. The caret is not scrolled into view.

See also: EnsureCaretVisible

int GetAnchor()

Returns the current anchor position.

void SetSelectionStart (int pos)
void SetSelectionEnd (int pos)

Set the selection based on the assumption that the anchor position is less than the current position. They do not make the caret visible. The table shows the positions of the anchor and the current position after using either.

anchor current
SetSelectionStart pos Max(pos, current)
SetSelectionEnd Min(anchor, pos) pos

See also: EnsureCaretVisible

int GetSelectionStart()
int GetSelectionEnd()

Return the start and end of the selection without regard to which end is the current position and which is the anchor. GetSelectionStart returns the smaller of the current position or the anchor position. GetSelectionEnd returns the larger of the two values.

void SelectAll()

This selects all the text in the document. The current position is not scrolled into view.

int LineFromPosition (int pos)

Returns the line that contains the position pos in the document. The return value is 0 if pos <= 0. The return value is the last line if pos is beyond the end of the document.

int PositionFromLine (int line)

Returns the document position that corresponds with the start of the line. If line is negative, the position of the line holding the start of the selection is returned. If line is greater than the lines in the document, the return value is wxSCI_INVALID_POSITION. If line is equal to the number of lines in the document (i.e. 1 line past the last line), the return value is the end of the document.

int GetLineEndPosition (int line)

Returns the position at the end of the line, before any line end characters. If line is negative, the result is 0. If line is the last line in the document, (which does not have any end of line characters), the result is the size of the document. If line is negative, the result is wxSCI_INVALID_POSITION. If line is >= GetLineCount(), the result is currently GetLength()-1.

int LineLength (int line)

Returns the length of the line, including any line end characters. If line is negative or beyond the last line in the document, the result is 0. If you want the length of the line not including any end of line characters, use GetLineEndPosition(line) - PositionFromLine(line).

wxString GetSelectedText()

Returns the currently selected text.

See also: GetCurLine, GetLine, GetText, GetStyledText, GetTextRange

wxString GetCurLine (int* linePos=NULL)

Retrieves the text of the line containing the caret and returns the position within the line of the caret.

See also: GetSelectedText, GetLine, GetText, GetStyledText, GetTextRange

bool SelectionIsRectangle()

Returns true if the current selection is in rectangle mode, false if not.

void SetSelectionMode (int mode)
int GetSelectionMode()

Set and get the selection mode, which can be stream (wxSCI_SEL_STREAM=1, default) or rectangular (wxSCI_SEL_RECTANGLE=2) or by lines (wxSCI_SEL_LINES=3). When set in these modes, regular caret moves will extend or reduce the selection, until the mode is cancelled by a call with same value or with Cancel. The get function returns the current mode even if the selection was made by mouse or with regular extended moves.

int GetLineSelStartPosition (int line)
int GetLineSelEndPosition (int line)

Retrieve the position of the start and end of the selection at the given line with wxSCI_INVALID_POSITION returned if no selection on this line.

void MoveCaretInsideView()

If the caret is off the top or bottom of the view, it is moved to the nearest line that is visible to its current position. Any selection is lost.

int WordStartPosition (int pos, bool onlyWordCharacters)
int WordEndPosition (int pos, bool onlyWordCharacters)

Return the start and end of words using the same definition of words as used internally within Scintilla. You can set your own list of characters that count as words with SetWordChars. The position sets the start or the search, which is forwards when searching for the end and backwards when searching for the start.

Set onlyWordCharacters to true to stop searching at the first non-word character in the search direction. If onlyWordCharacters is false, the first character in the search direction sets the type of the search as word or non-word and the search stops at the first non-matching character. Searches are also terminated by the start or end of the document.

If "w" represents word characters and "." represents non-word characters and "|" represents the position and true or false is the state of onlyWordCharacters:

Initial state end, true end, false start, true start, false
..ww..|..ww.. ..ww..|..ww.. ..ww....|ww.. ..ww..|..ww.. ..ww|....ww..
....ww|ww.... ....wwww|.... ....wwww|.... ....|wwww.... ....|wwww....
..ww|....ww.. ..ww|....ww.. ..ww....|ww.. ..|ww....ww.. ..|ww....ww..
..ww....|ww.. ..ww....ww|.. ..ww....ww|.. ..ww....|ww.. ..ww|....ww..

int PositionBefore (int pos)
int PositionAfter (int pos)

Returns the position before and after another position in the document taking into account the current code page. The minimum position returned is 0 and the maximum is the last position in the document. If called with a position within a multi byte character will return the position of the start/end of that character.

int TextWidth (int style, const wxString& text)

Returns the pixel width of a string drawn in the given styleNumber which can be used, for example, to decide how wide to make the line number margin in order to display a given number of numerals.

int TextHeight (int line)

Returns the height in pixels of a particular line. Currently all lines are the same height.

int GetColumn (int pos)

Returns the column number of a position pos within the document taking the width of tabs into account. This returns the column number of the last TAB on the line before pos, plus the number of characters between the last TAB and pos. If there are no TAB characters on the line, the return value is the number of characters up to the position on the line. In both cases, double byte characters count as a single character. This is probably only useful with monospaced fonts.

int FindColumn (int line, int column)

Returns the position of a column on a line taking the width of tabs into account. It treats a multi-byte character as a single column. Column numbers, like lines start at 0.

int PositionFromPoint (wxPoint pt)
int PositionFromPointClose (int x, int y)

PositionFromPoint finds the closest character position to a point and PositionFromPointClose is similar but returns wxSCI_INVALID_POSITION if the point is outside the window or not close to any characters.

void HideSelection (bool hide)

The normal state is to make the selection visible by drawing it as set by SetSelForeground and SetSelBackground. However, if you hide the selection, it is drawn as normal text.

void ChooseCaretX()

Scintilla remembers the x value of the last position horizontally moved to explicitly by the user and this value is then used when moving vertically such as by using the up and down keys. Sets the current x position of the caret as the remembered value.

Scrolling and automatic scrolling

void LineScroll (int columns, int lines)

Attempts to scroll the display by the number of columns and lines that you specify. Positive line values increase the line number at the top of the screen (i.e. they move the text upwards as far as the user is concerned), Negative line values do the reverse.

The column measure is the width of a space in the default style. Positive values increase the column at the left edge of the view (i.e. they move the text leftwards as far as the user is concerned). Negative values do the reverse.

See also: SetXOffset

void EnsureCaretVisible()

If the current position (this is the caret if there is no selection) is not visible, the view is scrolled to make it visible according to the current caret policy.

void SetXCaretPolicy (int caretPolicy, int caretSlop)
void SetYCaretPolicy (int caretPolicy, int caretSlop)

Set the caret policy. The value of caretPolicy is a combination of wxSCI_CARET_SLOP, wxSCI_CARET_STRICT, wxSCI_CARET_JUMPS and wxSCI_CARET_EVEN.

wxSCI_CARET_SLOP If set, we can define a slop value: caretSlop. This value defines an unwanted zone (UZ) where the caret is... unwanted. This zone is defined as a number of pixels near the vertical margins, and as a number of lines near the horizontal margins. By keeping the caret away from the edges, it is seen within its context. This makes it likely that the identifier that the caret is on can be completely seen, and that the current line is seen with some of the lines following it, which are often dependent on that line.
wxSCI_CARET_STRICT If set, the policy set by wxSCI_CARET_SLOP is enforced... strictly. The caret is centered on the display if caretSlop is not set, and cannot go in the UZ if caretSlop is set.
wxSCI_CARET_JUMPS If set, the display is moved more energetically so the caret can move in the same direction longer before the policy is applied again. '3UZ' notation is used to indicate three time the size of the UZ as a distance to the margin.
wxSCI_CARET_EVEN If not set, instead of having symmetrical UZs, the left and bottom UZs are extended up to right and top UZs respectively. This way, we favour the displaying of useful information: the beginning of lines, where most code resides, and the lines after the caret, for example, the body of a function.
slop strict jumps even Caret can go to the margin On reaching limit (going out of visibility
or going into the UZ) display is...
0 0 0 0 Yes moved to put caret on top/on right
0 0 0 1 Yes moved by one position
0 0 1 0 Yes moved to put caret on top/on right
0 0 1 1 Yes centered on the caret
0 1 - 0 Caret is always on top/on right of display -
0 1 - 1 No, caret is always centered -
1 0 0 0 Yes moved to put caret out of the asymmetrical UZ
1 0 0 1 Yes moved to put caret out of the UZ
1 0 1 0 Yes moved to put caret at 3UZ of the top or right margin
1 0 1 1 Yes moved to put caret at 3UZ of the margin
1 1 - 0 Caret is always at UZ of top/right margin -
1 1 0 1 No, kept out of UZ moved by one position
1 1 1 0 No, kept out of UZ moved to put caret at 3UZ of the margin

void SetVisiblePolicy (int visiblePolicy, int visibleSlop)

Determines how the vertical positioning is determined when EnsureVisibleEnforcePolicy is called. It takes wxSCI_VISIBLE_SLOP and wxSCI_VISIBLE_STRICT flags for the policy parameter. It is similar in operation to SetYCaretPolicy(int caretPolicy, int caretSlop).

void SetUseHorizontalScrollBar (bool show)
bool GetUseHorizontalScrollBar()

The horizontal scroll bar is only displayed if it is needed for the assumed width. If you never wish to see it, call SetUseHorizontalScrollBar (false). Use SetUseHorizontalScrollBar (true) to enable it again. GetUseHorizontalScrollBar returns the current state. The default state is to display it when needed.

See also: SetScrollWidth.

void SetUseVerticalScrollBar (bool show)
bool GetUseVerticalScrollBar()

By default, the vertical scroll bar is always displayed when required. You can choose to hide or show it with SetUseVerticalScrollBar and get the current state with GetUseVerticalScrollBar.

void SetXOffset (int newOffset)
int GetXOffset()

The newOffset is the horizontal scroll position in pixels of the start of the text view. A value of 0 is the normal position with the first text column visible at the left of the view.

See also: LineScroll

void SetScrollWidth (int pixels)
int GetScrollWidth()

For performance, Scintilla does not measure the width of the document to determine the properties of the horizontal scroll bar. Instead, an assumed width (2000 pixels) is used. Set and get the document width in pixels so Scintilla can adjust the horizontal scroll bar accordingly.

void SetEndAtLastLine (bool endAtLastLine)
int GetEndAtLastLine()

SetEndAtLastLine sets the scroll range so that maximum scroll position has the last line at the bottom of the view (default). Setting this to false allows scrolling one page below the last line.

White space

void SetViewWhiteSpace (int viewWS)
int GetViewWhiteSpace()

White space can be made visible which may useful for languages in which white space is significant, such as Python. Space characters appear as small centered dots and TAB characters as light arrows pointing to the right. There are also ways to control the display of end of line characters. Set and get the white space display mode. The viewWS argument can be one of:

wxSCI_WS_INVISIBLE 0 The normal display mode with white space displayed as an empty background colour.
wxSCI_WS_VISIBLEALWAYS 1 White space characters are drawn as dots and arrows,
wxSCI_WS_VISIBLEAFTERINDENT 2 White space used for indentation is displayed normally but after the first visible character, it is shown as dots and arrows.

The effect of using any other wsMode value is undefined.

void SetWhitespaceForeground (bool useSetting, const wxColour& fore)
void SetWhitespaceBackground (bool useSetting, const wxColour& back)

By default, the colour of visible white space is determined by the lexer in use. The foreground and/or background colour of all visible white space can be set globally, overriding the lexer's colours with SetWhitespaceForeground and SetWhitespaceBackground.

Cursor

void SetCursorType (int cursorType)
int GetCursorType()

The cursor is normally chosen in a context sensitive way, so it will be different over the margin than when over the text. When performing a slow action, you may wish to change to a wait cursor. You set the cursor type with SetCursorType. The curType argument can be:

wxSCI_CURSORNORMAL -1 The normal cursor is displayed.
wxSCI_CURSORWAIT  4 The wait cursor is displayed when the mouse is over or owned by the Scintilla window.

Cursor values 1 through 7 have defined cursors, but only wxSCI_CURSORWAIT is usefully controllable. Other values of curType cause a pointer to be displayed. The GetCursorType returns the last cursor type you set, or wxSCI_CURSORNORMAL if you have not set a cursor type.

Mouse capture

void SetMouseDownCaptures (bool captures)
bool GetMouseDownCaptures()

When the mouse is pressed inside Scintilla, it is captured so future mouse movement events are sent to Scintilla. This behavior may be turned off with SetMouseDownCaptures (false).

Line endings

Scintilla can interpret any of the three major line end conventions, Macintosh (\r), Unix (\n) and CP/M / DOS / Windows (\r\n). When the user presses the Enter key, one of these line end strings is inserted into the buffer. The default is \r\n in Windows and \n in Unix, but this can be changed with the SetEOLMode. You can also convert the entire document to one of these line endings with ConvertEOLs. Finally, you can choose to display the line endings with SetViewEOL.

void SetEOLMode (int eolMode)
int GetEOLMode()

SetEOLMode sets the characters that are added into the document when the user presses the Enter key. You can set eolMode to one of wxSCI_EOL_CRLF (0), wxSCI_EOL_CR (1), or wxSCI_EOL_LF (2). The GetEOLMode retrieves the current state.

void ConvertEOLs (int eolMode)

Changes all the end of line characters in the document to match eolMode. Valid values are: wxSCI_EOL_CRLF (0), wxSCI_EOL_CR (1), or wxSCI_EOL_LF (2).

void SetViewEOL (bool visible)
bool GetViewEOL()

Normally, the end of line characters are hidden, but SetViewEOL allows you to display (or hide) them by setting visible true (or false). The visible rendering of the end of line characters is similar to (CR), (LF), or (CR)(LF). GetViewEOL returns the current state.

Styling

The styling allow you to assign styles to text. The standard Scintilla settings divide the 8 style bits available for each character into 5 bits (0 to 4 = styles 0 to 31) that set a style and three bits (5 to 7) that define indicators. You can change the balance between styles and indicators with SetStyleBits. If your styling needs can be met by one of the standard lexers, or if you can write your own, then a lexer is probably the easiest way to style your document. If you choose to use the container to do the styling you can use the SetLexer command to select wxSCI_LEX_CONTAINER, in which case the container is sent a wxEVT_SCI_STYLENEEDED notification each time text needs styling for display. As another alternative, you might use idle time to style the document. Even if you use a lexer, you might use the styling commands to mark errors detected by a compiler. The following commands can be used.

int GetEndStyled()

Scintilla keeps a record of the last character that is likely to be styled correctly. This is moved forwards when characters after it are styled and moved backwards if changes are made to the text of the document before it. Before drawing text, this position is checked to see if any styling is needed and, if so, a wxEVT_SCI_STYLENEEDED notification message is sent to the container. The container can send GetEndStyled to work out where it needs to start styling. Scintilla will always ask to style whole lines.

void StartStyling (int pos, int mask)

This prepares for styling by setting the styling position pos to start at and a mask indicating which bits of the style bytes can be set. The mask allows styling to occur over several passes, with, for example, basic styling done on an initial pass to ensure that the text of the code is seen quickly and correctly, and then a second slower pass, detecting syntax errors and using indicators to show where these are. For example, with the standard settings of 5 style bits and 3 indicator bits, you would use a mask value of 31 (0x1f) if you were setting text styles and did not want to change the indicators. After StartStyling, send multiple SetStyling for each lexical entity to style.

void SetStyling (int length, int style)

Sets the style of length characters starting at the styling position and then increases the styling position by length, ready for the next call. If sCell is the style byte, the operation is:
if ((sCell & mask) != style) sCell = (sCell & ~mask) | (style & mask);

void SetStyleBytes (int length, char* styleBytes)

As an alternative to SetStyling, which applies the same style to each byte, you can use this which specifies the styles for each of length bytes from the styling position and then increases the styling position by length, ready for the next call. The length styling bytes pointed at by styles should not contain any bits not set in mask.

void SetLineState (int line, int state)
int GetLineState (int line)

As well as the 8 bits of lexical state stored for each character there is also an integer stored for each line. This can be used for longer lived parse states such as what the current scripting language is in an ASP page. Use SetLineState to set the integer value and GetLineState to get the value.

int GetMaxLineState()

Returns the last line that has any line state.

Style definition

While the style setting mentioned above change the style numbers associated with text, these define how those style numbers are interpreted visually. There are 128 lexer styles that can be set, numbered 0 to STYLEMAX (127). Unless you use SetStyleBits to change the number of style bits, styles 0 to 31 are used to set the text attributes. There are also some predefined numbered styles starting at 32, The following wxSCI_STYLE_... constants are defined.

wxSCI_STYLE_DEFAULT 32 This style defines the attributes that all styles receive when the StyleClearAll is used.
wxSCI_STYLE_LINENUMBER 33 This style sets the attributes of the text used to display line numbers in a line number margin. The background colour set for this style also sets the background colour for all margins that do not have any folding mask bits set. That is, any margin for which mask & wxSCI_MASK_FOLDERS is 0. See SetMarginMask for more about masks.
wxSCI_STYLE_BRACELIGHT 34 This style sets the attributes used when highlighting braces with the BraceHighlight and when highlighting the corresponding indentation with SetHighlightGuide.
wxSCI_STYLE_BRACEBAD 35 This style sets the display attributes used when marking an unmatched brace with the BraceBadLight.
wxSCI_STYLE_CONTROLCHAR 36 This style sets the font used when drawing control characters. Only the font, size, bold, italics, and character set attributes are used and not the colour attributes. See also: SetControlCharSymbol.
wxSCI_STYLE_INDENTGUIDE 37 This style sets the foreground and background colours used when drawing the indentation guides.
wxSCI_STYLE_LASTPREDEFINED 39 To make it easier for client code to discover the range of styles that are predefined, this is set to the style number of the last predefined style. This is currently set to 39 and the last style with an identifier is 37, which reserves space for future predefined styles.
wxSCI_STYLE_MAX 127 This is not a style but is the number of the maximum style that can be set. Styles between wxSCI_STYLE_LASTPREDEFINED and wxSCI_STYLE_MAX would be appropriate if you used SetStyleBits to set more than 5 style bits.

For each style you can set the font name, size and use of bold, italic and underline, foreground and background colour and the character set. You can also choose to hide text with a given style, display all characters as upper or lower case and fill from the last character on a line to the end of the line (for embedded languages). There is also an experimental attribute to make text read-only.

It is entirely up to you how you use styles. If you want to use syntax colouring you might use style 0 for white space, style 1 for numbers, style 2 for keywords, style 3 for strings, style 4 for preprocessor, style 5 for operators, and so on.

void StyleResetDefault()

Resets wxSCI_STYLE_DEFAULT to its state when Scintilla was initialised.

void StyleClearAll()

Sets all styles to have the same attributes as wxSCI_STYLE_DEFAULT. If you are setting up Scintilla for syntax colouring, it is likely that the lexical styles you set will be very similar. One way to set the styles is to:
1. Set wxSCI_STYLE_DEFAULT to the common features of all styles.
2. Use StyleClearAll to copy this to all styles.
3. Set the style attributes that make your lexical styles different.

void StyleSetFont (int styleNum, wxFont& font)
void StyleSetSize (int style, int sizePoints)
void StyleSetBold (int style, bool bold)
void StyleSetItalic (int style, bool italic)

These (plus StyleSetCharacterSet) set the font attributes that are used to match the fonts you request to those available. The fontName is a zero terminated string holding the name of a font. Under Windows, only the first 32 characters of the name are used and the name is not case sensitive. For internal caching, Scintilla tracks fonts by name and does care about the casing of font names, so please be consistent. On GTK+ 2.x, either GDK or Pango can be used to display text. Pango antialiases text and works well with Unicode but GDK is faster. Prepend a '!' character to the font name to use Pango.

void StyleSetUnderline (int style, bool underline)

You can set a style to be underlined. The underline is drawn in the foreground colour. All characters with a style that includes the underline attribute are underlined, even if they are white space.

void StyleSetForeground (int style, const wxColour& fore)
void StyleSetBackground (int style, const wxColour& back)

Text is drawn in the foreground colour. The space in each character cell that is not occupied by the character is drawn in the background colour.

void StyleSetEOLFilled (int style, bool filled)

If the last character in the line has a style with this attribute set, the remainder of the line up to the right edge of the window is filled with the background colour set for the last character. This is useful when a document contains embedded sections in another language such as HTML pages with embedded JavaScript. By setting filled to true and a consistent background colour (different from the background colour set for the HTML styles) to all JavaScript styles then JavaScript sections will be easily distinguished from HTML.

void StyleSetCharacterSet (int style, int characterSet)

You can set a style to use a different character set than the default. The places where such characters sets are likely to be useful are comments and literal strings. For example, StyleSetCharacterSet(SCE_C_STRING, wxwxSCI_CMD_CHARSET_RUSSIAN) would ensure that strings in Russian would display correctly in C and C++ (SCE_C_STRING is the style number used by the C and C++ lexer to display literal strings; it has the value 6). This feature currently only works fully on Windows.

The character sets supported on Windows are:

The character sets supported on GTK+ are:

void StyleSetCase (int style, int caseMode)

The value of caseMode determines how text is displayed. You can set upper case (wxSCI_CASE_UPPER, 1) or lower case (wxSCI_CASE_LOWER, 2) or display normally (wxSCI_CASE_MIXED, 0). This does not change the stored text, only how it is displayed.

void StyleSetVisible (int style, bool visible)

Text is normally visible. However, you can completely hide it by giving it a style with the visible set to false. This could be used to hide embedded formatting instructions or hypertext keywords in HTML or XML.

void StyleSetChangeable (int style, bool changeable)

This is an experimental and incompletely implemented style attribute. The default setting is changeable set true but when set false it makes text read-only. Currently it only stops the caret from being within not-changeable text and does not yet stop deleting a range that contains not-changeable text.

void StyleSetHotSpot (int style, bool hotspot)

This style is used to mark ranges of text that can detect mouse clicks. The cursor changes to a hand over hotspots, and the foreground, and background colours may change and an underline appear to indicate that these areas are sensitive to clicking. This may be used to allow hyperlinks to other documents.

See also: SetHotspotActiveForeground, SetHotspotActiveBackground

Caret, selection, and hotspot styles

The selection is shown by changing the foreground and/or background colours. If one of these is not set then that attribute is not changed for the selection. The default is to show the selection by changing the background to light gray and leaving the foreground the same as when it was not selected. When there is no selection, the current insertion point is marked by the text caret. This is a vertical line that is normally blinking on and off to attract the users attention.

void SetSelForeground (bool useSetting, const wxColour& fore)
void SetSelBackground (bool useSetting, const wxColour& back)

You can choose to override the default selection colouring with these two functions. The colour you provide is used if you set useSetting to true. If it is set to false, the default colour colouring is used and the colour argument has no effect.

void SetCaretForeground (const wxColour& fore)
wxColour GetCaretForeground()

The colour of the caret can be set with SetCaretForeground and retrieved with GetCaretForeground.

void SetCaretLineVisible (bool show)
bool GetCaretLineVisible()
void SetCaretLineBackground (const wxColour& back)
wxColour GetCaretLineBackground()

You can choose to make the background colour of the line containing the caret different. To do this, set the desired background colour with SetCaretLineBackground, then use SetCaretLineVisible (true) to enable the effect. You can cancel the effect with SetCaretLineVisible (false). The two GetCaret... functions return the state and the colour. This form of background colouring has highest priority when a line has markers that would otherwise change the background colour.

void SetCaretPeriod (int milliseconds)
int GetCaretPeriod()

The rate at which the caret blinks can be set with SetCaretPeriod which determines the time in milliseconds that the caret is visible or invisible before changing state. Setting the period to 0 stops the caret blinking. The default value is 500 milliseconds. GetCaretPeriod returns the current setting.

void SetCaretWidth (int pixels)
int GetCaretWidth()

The width of the caret can be set with SetCaretWidth to a value of 0, 1, 2 or 3 pixels. The default width is 1 pixel. You can read back the current width with GetCaretWidth. A width of 0 makes the caret invisible.

void SetHotspotActiveForeground (bool useSetting, const wxColour& fore)
void SetHotspotActiveBackground (bool useSetting, const wxColour& back)
void SetHotspotActiveUnderline (bool underline)
void SetHotspotSingleLine (bool singleLine)

While the cursor hovers over text in a style with the hotspot attribute set, the default colouring can be modified and an underline drawn with these settings. Single line mode stops a hotspot from wrapping onto next line.

See also: StyleSetHotSpot

void SetControlCharSymbol (int symbol)
int GetControlCharSymbol()

By default, Scintilla displays control characters (characters with codes less than 32) in a rounded rectangle as ASCII mnemonics:
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US". These mnemonics come from the early days of signaling, though some are still used (LF = Line Feed, BS = Back Space, CR = Carriage Return, for example).

You can choose to replace these mnemonics by a nominated symbol with an ASCII code in the range 32 to 255. If you set a symbol value less than 32, all control characters are displayed as mnemonics. The symbol you set is rendered in the font of the style set for the character. You can read back the current symbol with the GetControlCharSymbol. The default symbol value is 0.

void SetCaretSticky (bool useCaretStickyBehaviour)
bool GetCaretSticky ()
void ToggleCaretSticky ()

These messages set, get or toggle the caretSticky flag which controls when the last position of the caret on the line is saved. When set to true, the position is not saved when you type a character, a tab, paste the clipboard content or press backspace.

Margins

There may be up to three margins to the left of the text display, plus a gap either side of the text. Each margin can be set to display either symbols or line numbers with SetMarginType. The markers that can be displayed in each margin are set with SetMarginMask. Any markers not associated with a visible margin will be displayed as changes in background colour in the text. A width in pixels can be set for each margin. Margins with a zero width are ignored completely. You can choose if a mouse click in a margin sends a wxEVT_SCI_MARGINCLICK notification to the container or selects a line of text.

The margins are numbered 0 to 2. Using a margin number outside the valid range has no effect. By default, margin 0 is set to display line numbers, but is given a width of 0, so it is hidden. Margin 1 is set to display non-folding symbols and is given a width of 16 pixels, so it is visible. Margin 2 is set to display the folding symbols, but is given a width of 0, so it is hidden. Of course, you can set the margins to be whatever you wish.

void SetMarginType (int margin, int marginType)
int GetMarginType (int margin)

These two routines set and get the type of a margin. The margin argument should be 0, 1 or 2. You can use the predefined constants wxSCI_MARGIN_SYMBOL (0) and wxSCI_MARGIN_NUMBER (1) to set a margin as either a line number or a symbol margin. By convention, margin 0 is used for line numbers and the other two are used for symbols.

void SetMarginWidth (int margin, int pixels)
int GetMarginWidth (int margin)

These routines set and get the width of a margin in pixels. A margin with zero width is invisible. By default, Scintilla sets margin 1 for symbols with a width of 16 pixels, so this is a reasonable guess if you are not sure what would be appropriate. Line number margins widths should take into account the number of lines in the document and the line number style. You could use something like TextWidth (wxSCI_STYLE_LINENUMBER, "_99999") to get a suitable width.

void SetMarginMask (int margin, int mask)
int GetMarginMask (int margin)

The mask is a 32-bit value. Each bit corresponds to one of 32 logical symbols that can be displayed in a margin that is enabled for symbols. There is a useful constant, wxSCI_MASK_FOLDERS (0xFE000000), that is a mask for the 7 logical symbols used to denote folding. You can assign a wide range of symbols and colours to each of the 32 logical symbols, see Markers for more information. If (mask & wxSCI_MASK_FOLDERS)==0, the margin background colour is controlled by style 33 (wxSCI_STYLE_LINENUMBER).

You add logical markers to a line with MarkerAdd. If a line has an associated marker that does not appear in the mask of any margin with a non-zero width, the marker changes the background colour of the line. For example, suppose you decide to use logical marker 10 to mark lines with a syntax error and you want to show such lines by changing the background colour. The mask for this marker is 1 shifted left 10 times (1<<10) which is 0x400. If you make sure that no symbol margin includes 0x400 in its mask, any line with the marker gets the background colour changed.

To set a non-folding margin 1 use SetMarginMask (1, ~wxSCI_MASK_FOLDERS); to set a folding margin 2 use SetMarginMask(2, wxSCI_MASK_FOLDERS). This is the default set by Scintilla. ~wxSCI_MASK_FOLDERS is 0x1FFFFFF in hexadecimal. Of course, you may need to display all 32 symbols in a margin, in which case use SetMarginMask (margin, -1).

void SetMarginSensitive (int margin, bool sensitive)
bool GetMarginSensitive (int margin)

Each of the three margins can be set sensitive or insensitive to mouse clicks. A click in a sensitive margin sends a wxEVT_SCI_MARGINCLICK notification to the container. Margins that are not sensitive act as selection margins which make it easy to select ranges of lines. By default, all margins are insensitive.

void SetMarginLeft (int pixels)
int GetMarginLeft()
void SetMarginRight (int pixels)
int GetMarginRight()

Set and get the width of the blank margin on both sides of the text in pixels. The default is to one pixel on each side.

void SetFoldMarginColour (bool useSetting, const wxColour& back)
void SetFoldMarginHiColour (bool useSetting, const wxColour& fore)

Allow changing the colour of the fold margin and fold margin highlight. On Windows the fold margin colour defaults to ::GetSysColor(COLOR_3DFACE) and the fold margin highlight colour to ::GetSysColor(COLOR_3DHIGHLIGHT).

Other settings

void SetBufferedDraw (bool buffered)
bool GetBufferedDraw()

Turn buffered drawing on or off and report the buffered drawing state. Buffered drawing draws each line into a bitmap rather than directly to the screen and then copies the bitmap to the screen. This avoids flickering although it does take longer. The default is for drawing to be buffered.

void SetTwoPhaseDraw (bool twoPhase)
bool GetTwoPhaseDraw()

Two phase drawing is a better but slower way of drawing text. In single phase drawing each run of characters in one style is drawn along with its background. If a character overhangs the end of a run, such as in "V_" where the "V" is in a different style from the "_", then this can cause the right hand side of the "V" to be overdrawn by the background of the "_" which cuts it off. Two phase drawing fixes this by drawing all the backgrounds first and then drawing the text in transparent mode. Two phase drawing may flicker more than single phase unless buffered drawing is on. The default is for drawing to be two phase.

void SetCodePage (int codePage)
int GetCodePage()

Scintilla has some support for Japanese, Chinese and Korean DBCS. Use this with codePage set to the code page number to set Scintilla to use code page information to ensure double byte characters are treated as one character rather than two. This also stops the caret from moving between the two bytes in a double byte character. Call with codePage set to zero to disable DBCS support. The default is SetCodePage (0).

Code page wxSCI_CP_UTF8 (65001) sets Scintilla into Unicode mode with the document treated as a sequence of characters expressed in UTF-8. The text is converted to the platform's normal Unicode encoding before being drawn by the OS and thus can display Hebrew, Arabic, Cyrillic, and Han characters. Languages which can use two characters stacked vertically in one horizontal space, such as Thai, will mostly work but there are some issues where the characters are drawn separately leading to visual glitches. Bi-directional text is not supported.

On Windows, code page can be set to 932 (Japanese Shift-JIS), 936 (Simplified Chinese GBK), 949 (Korean), and 950 (Traditional Chinese Big5) although these may require installation of language specific support.

On GTK+, code page wxSCI_CP_DBCS (1) sets Scintilla into multi byte character mode as is required for Japanese language processing with the EUC encoding.

For GTK+, the locale should be set to a Unicode locale with a call similar to setlocale (LC_CTYPE, "en_US.UTF-8"). Fonts with an "iso10646" registry should be used in a font set. Font sets are a comma separated list of partial font specifications where each partial font specification can be in the form:
foundry-fontface-charsetregistry-encoding or
fontface-charsetregistry-encoding or
foundry-fontface or
fontface.
An example is "misc-fixed-iso10646-1,*".

Setting codePage to a non-zero value that is not wxSCI_CP_UTF8 is operating system dependent.

void SetWordChars (const wxString& characters)

Scintilla has several functions that operate on words, which are defined to be contiguous sequences of characters from a particular set of characters. Defines which characters are members of that set. The character sets are set to default values before processing this function. For example, if you don't allow '_' in your set of characters use:
SetWordChars (0, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

void SetWhitespaceChars (const wxString& characters)

Similar to SetWordChars, allows the user to define which chars Scintilla considers as whitespace. Setting the whitespace chars allows the user to fine-tune Scintilla's behavior doing such things as moving the cursor to the start or end of a word; for example, by defining punctuation chars as whitespace, they will be skipped over when the user presses ctrl+left or ctrl+right. This function should be called after SetWordChars as it will reset the whitespace characters to the default set.

void SetCharsDefault()

Use the default sets of word and whitespace characters. This sets whitespace to space, TAB and other characters with codes less than 0x20, with word characters set to alphanumeric and '_'.

void SetSCIFocus()

The internal focus flag can be set with SetSCIFocus. This is used by clients that have complex focus requirements such as having their own window that gets the real focus but with the need to indicate that Scintilla has the logical focus.

Brace highlighting

void BraceHighlight (int pos1, int pos2)

Up to two characters can be highlighted in a 'brace highlighting style', which is defined as style number wxSCI_STYLE_BRACELIGHT (34). Use pos1 = pos2 = wxSTC_INVALID_POSITION to remove the highlighting. If you have enabled indent guides, you may also wish to highlight the indent that corresponds with the brace. You can locate the column with GetColumn and highlight the indent with SetHighlightGuide.

void BraceBadLight (int pos)

If there is no matching brace then the brace badlighting style, style wxSCI_STYLE_BRACEBAD (35), can be used to show the brace that is unmatched. Using a position of wxSCI_INVALID_POSITION removes the highlight.

int BraceMatch (int pos)

BraceMatch finds a corresponding matching brace given pos, the position of one brace. The brace characters handled are '(', ')', '[', ']', '{', '}', '<', and '>'. The search is forwards from an opening brace and backwards from a closing brace. If the character at position is not a brace character, or a matching brace cannot be found, the return value is wxSCI_INVALID_POSITION. Otherwise, the return value is the position of the matching brace.

A match only occurs if the style of the matching brace is the same as the starting brace or the matching brace is beyond the end of styling. Nested braces are handled correctly.

It's important to realize that this method does NOT do any highlighting, it just finds the matching brace.

Tabs and Indentation Guides

Indentation (the white space at the start of a line) is often used by programmers to clarify program structure and in some languages, for example Python, it may be part of the language syntax. Tabs are normally used in editors to insert a TAB character or to pad text with spaces up to the next TAB.

Scintilla can be set to treat TAB and backspace in the white space at the start of a line in a special way: inserting a TAB indents the line to the next indent position rather than just inserting a TAB at the current character position and backspace unindents the line rather than deleting a character. Scintilla can also display indentation guides (vertical lines) to help you to generate code.

void SetTabWidth (int tabWidth)
int GetTabWidth()

SetTabWidth sets the size of a TAB as a multiple of the size of a space character in wxSCI_STYLE_DEFAULT. The default TAB width is 8 characters. There are no limits on TAB sizes, but values less than 1 or large values may have undesirable effects.

void SetUseTabs (bool useTabs)
bool GetUseTabs()

SetUseTabs determines whether indentation should be created out of a mixture of tabs and spaces or be based purely on spaces. Set useTabs to false to create all tabs and indents out of spaces. The default is true. You can use GetColumn to get the column of a position taking the width of a TAB into account.

void SetIndent (int indentSize)
int GetIndent()

SetIndent sets the size of indentation in terms of the width of a space in wxSCI_STYLE_DEFAULT. If you set a width of 0, the indent size is the same as the TAB size. There are no limits on indent sizes, but values less than 0 or large values may have undesirable effects.

void SetTabIndents (bool tabIndents)
bool GetTabIndents()
void SetBackSpaceUnIndents (bool bsUnIndents)
bool GetBackSpaceUnIndents()

Inside indentation white space, the TAB and backspace keys can be made to indent and unindent rather than insert a TAB character or delete a character with the SetTabIndents and SetBackSpaceUnIndents functions.

void SetLineIndentation (int line, int indentSize)
int GetLineIndentation (int line)

The amount of indentation on a line can be discovered and set with GetLineIndentation and SetLineIndentation. The indentation is measured in character columns, which correspond to the width of space characters.

int GetLineIndentPosition (int line)

This returns the position at the end of indentation of a line.

void SetIndentationGuides (bool show)
bool GetIndentationGuides()

Indentation guides are dotted vertical lines that appear within indentation white space every indent size columns. They make it easy to see which constructs line up especially when they extend over multiple pages. Style wxSCI_STYLE_INDENTGUIDE (37) is used to specify the foreground and background colour of the indentation guides.

void SetHighlightGuide (int column)
int GetHighlightGuide()

When brace highlighting occurs, the indentation guide corresponding to the braces may be highlighted with the brace highlighting style, wxSCI_STYLE_BRACELIGHT (34). Set column to 0 to cancel this highlight.

Markers

There are 32 markers, numbered 0 to 31, and you can assign any combination of them to each line in the document. Markers appear in the selection margin to the left of the text. If the selection margin is set to zero width, the background colour of the whole line is changed instead. Marker numbers 25 to 31 are used by Scintilla in folding margins, and have symbolic names of the form wxSCI_MARKNUM_...*, for example wxSCI_MARKNUM_FOLDEROPEN.

Marker numbers 0 to 24 have no pre-defined function; you can use them to mark syntax errors or the current point of execution, break points, or whatever you need marking. If you do not need folding, you can use all 32 for any purpose you wish.

Each marker number has a symbol associated with it. You can also set the foreground and background colour for each marker number, so you can use the same symbol more than once with different colouring for different uses. Scintilla has a set of symbols you can assign (wxSCI_MARK_*) or you can use characters. By default, all 32 markers are set to wxSCI_MARK_CIRCLE with a black foreground and a white background.

The markers are drawn in the order of their numbers, so higher numbered markers appear on top of lower numbered ones. Markers try to move with their text by tracking where the start of their line moves. When a line is deleted, its markers are combined, by an OR operation, with the markers of the previous line.

void MarkerDefine (int markerNumber, int markerSymbol)

Associates a marker number in the range 0 to 31 with one of the marker symbols or an ASCII character. The general-purpose marker symbols currently available are:

void MarkerDefineBitmap (int markerNumber, const wxBitmap& bmp)

Markers can be set to pixmaps. Pixmaps use the wxSCI_MARK_PIXMAP marker symbol.

The wxSCI_MARK_BACKGROUND marker changes the background colour of the line only. The wxSCI_MARK_FULLRECT symbol mirrors this, changing only the margin background colour. The wxSCI_MARK_EMPTY symbol is invisible, allowing client code to track the movement of lines. You would also use it if you changed the folding style and wanted one or more of the wxSCI_FOLDERNUM_* markers to have no associated symbol.

There are also marker symbols designed for use in the folding margin in a flattened tree style.

Characters can be used as markers by adding the ASCII value of the character to wxSCI_MARK_CHARACTER (10000). For example, to use 'A' (ASCII code 65) as marker number 1 use MarkerDefine (1, wxSCI_MARK_CHARACTER+65).

The marker numbers wxSCI_MARKNUM_FOLDER and wxSCI_MARKNUM_FOLDEROPEN are used for showing that a fold is present and open or closed. Any symbols may be assigned for this purpose although the (wxSCI_MARK_PLUS, wxSCI_MARK_MINUS) pair or the (wxSCI_MARK_ARROW, wxSCI_MARK_ARROWDOWN) pair are good choices. As well as these two, more assignments are needed for the flattened tree style:
wxSCI_MARKNUM_FOLDEREND, wxSCI_MARKNUM_FOLDERMIDTAIL, wxSCI_MARKNUM_FOLDEROPENMID, wxSCI_MARKNUM_FOLDERSUB, and wxSCI_MARKNUM_FOLDERTAIL. The bits used for folding are specified by wxSCI_MASK_FOLDERS, which is commonly used as an argument to SetMarginMask when defining a margin to be used for folding.

This table shows which wxSCI_MARK_* symbols should be assigned to which wxSCI_MARKNUM_* marker numbers to obtain four folding styles: Arrow (mimics Macintosh), plus/minus shows folded lines as '+' and opened folds as '-', Circle tree, Box tree.

wxSCI_MARKNUM_* Arrow Plus/minus Circle tree Box tree
FOLDEROPEN ARROWDOWN MINUS CIRCLEMINUS BOXMINUS
FOLDER ARROW PLUS CIRCLEPLUS BOXPLUS
FOLDERSUB EMPTY EMPTY VLINE VLINE
FOLDERTAIL EMPTY EMPTY LCORNERCURVE LCORNER
FOLDEREND EMPTY EMPTY CIRCLEPLUSCONNECTED BOXPLUSCONNECTED
FOLDEROPENMID EMPTY EMPTY CIRCLEMINUSCONNECTED BOXMINUSCONNECTED
FOLDERMIDTAIL EMPTY EMPTY TCORNERCURVE TCORNER

void MarkerSetForeground (int markerNumber, const wxColour& fore)
void MarkerSetBackground (int markerNumber, const wxColour& back)

Set the foreground and background colour of a marker number. Default colours for foreground is black, for background is white. Usually but not always the foreground colour is used to outline a marker symbol and the background colour is used to fill the symbol. Sometimes only one colour is used. The background is also used as the text background when the marker isn't displayed as a margin.

int MarkerAdd (int line, int markerNumber)

Adds marker number markerNumber to a line. It returns -1 if this fails (illegal line number, out of memory) or it returns a marker handle number that identifies the added marker. You can use this returned handle with MarkerLineFromHandle to find where a marker is after moving or combining lines and with MarkerDeleteHandle to delete the marker based on its handle. It does not check the value of markerNumber, nor does it check if the line already contains the marker.

void MarkerDelete (int line, int markerNumber)

This searches the given line number for the given marker number and deletes it if it is present. If you added the same marker more than once to the line, this will delete one copy each time it is used. If you pass in a marker number of -1, all markers are deleted from the line.

void MarkerDeleteAll (int markerNumber)

This removes markers of the given number from all lines. If markerNumber is -1, it deletes all markers from all lines.

int MarkerGet (int line)

This returns a 32-bit integer that indicates which markers were present on the line. Bit 0 is set if marker 0 is present, bit 1 for marker 1 and so on.

int MarkerNext (int lineStart, int markerMask)
int MarkerPrevious (int lineStart, int markerMask)

Search efficiently for lines that include a given set of markers. The search starts at line number lineStart and continues forwards to the end of the file (MarkerNext) or backwards to the start of the file (MarkerPrevious). The markerMask argument should have one bit set for each marker you wish to find. Set bit 0 to find marker 0, bit 1 for marker 1 and so on. Returns the line number of the first line that contains one of the markers in markerMask or -1 if no marker is found.

int MarkerLineFromHandle (int handle)

The handle argument is an identifier for a marker returned by MarkerAdd. This function searches the document for the marker with this handle and returns the line number that contains it or wxSCI_INVALID_POSITION if it is not found.

void MarkerDeleteHandle (int handle)

The handle argument is an identifier for a marker returned by MarkerAdd. This function searches the document for the marker with this handle and deletes the marker if it is found.

Indicators

By default, Scintilla organizes the style byte associated with each text byte as 5 bits of style information (for 32 styles) and 3 bits of indicator information for 3 in dependent indicators so that, for example, syntax errors, deprecated names and bad indentation could all be displayed at once. Indicators may be displayed as simple underlines, squiggly underlines, a line of small 'T' shapes, a line of diagonal hatching, a strike-out or a rectangle around the text.

The indicators are set using StartStyling with a wxSCI_INDICS_MASK mask and SetStyling with the values INDIC0_MASK, INDIC1_MASK and INDIC2_MASK.

If you are using indicators in a buffer that has a lexer active (see SetLexer), you must save lexing state information before setting any indicators and restore it afterwards. Use GetEndStyled to retrieve the current "styled to" position and StartStyling to reset the styling position and mask (0x1f in the default layout of 5 style bits and 3 indicator bits) when you are done.

The number of bits used for styles can be altered with SetStyleBits from 0 to 7 bits. The remaining bits can be used for indicators, so there can be from 1 to 8 indicators. However, the wxSCI_INDICS_..._MASK constants defined in Scintilla.h all assume 5 bits of styling information and 3 indicators. If you use a different arrangement, you must define your own constants.

The Indicator... allow you to get and set the visual appearance of the indicators. They all use an indicatorNumber argument in the range 0 to 7 to set the indicator to style. With the default settings, only indicators 0, 1 and 2 will have any visible effect.

void IndicatorSetStyle (int indic, int style)
int IndicatorGetStyle (int indic)

Set and get the style for a particular indicator. The indicator styles currently available are:

Symbol Value Visual effect
INDIC_PLAIN 0 Underlined with a single, straight line.
INDIC_SQUIGGLE 1 A squiggly underline.
INDIC_TT 2 A line of small T shapes.
INDIC_DIAGONAL 3 Diagonal hatching.
INDIC_STRIKE 4 Strike out.
INDIC_HIDDEN 5 An indicator with no visual effect.
INDIC_BOX 6 A rectangle around the text.

The default indicator styles are equivalent to:
IndicatorSetStyle (0, INDIC_SQUIGGLE);
IndicatorSetStyle (1, INDIC_TT);
IndicatorSetStyle (2, INDIC_PLAIN);

void IndicatorSetForeground (int indic, const wxColour& fore)
wxColour IndicatorGetForeground (int indic)

Set and get the colour used to draw an indicator. The default indicator colours are equivalent to:
IndicatorSetForeground (0, 0x007f00); (dark green)
IndicatorSetForeground (1, 0xff0000); (light blue)
IndicatorSetForeground (2, 0x0000ff); (light red)

Autocompletion

Autocompletion displays a list box showing likely identifiers based upon the users typing. The user chooses the currently selected item by pressing the TAB character or another character that is a member of the fillup character set defined with AutoCompSetFillUps. Autocompletion is triggered by your application. For example, in C if you detect that the user has just typed fred. you could look up fred, and if it has a known list of members, you could offer them in an autocompletion list. Alternatively, you could monitor the user's typing and offer a list of likely items once their typing has narrowed down the choice to a reasonable list. As yet another alternative, you could define a key code to activate the list.

To make use of autocompletion you must monitor each character added to the document. See SciTEBase::CharAdded() in SciTEBase.cxx for an example of autocompletion.

void AutoCompShow (int lenEntered, const wxString& itemList)

Causes a list to be displayed. lenEntered is the number of characters of the word already entered and list is the list of words separated by separator characters. The initial separator character is a space but this can be set or got with AutoCompSetSeparator and AutoCompGetSeparator.

The list of words should be in sorted order. If set to ignore case mode with AutoCompSetIgnoreCase, then strings are matched after being converted to upper case. One result of this is that the list should be sorted with the punctuation characters '[', '\', ']', '^', '_', and '`' sorted after letters.

void AutoCompCancel()

Cancels any displayed autocompletion list. When in autocompletion mode, the list should disappear when the user types a character that can not be part of the autocompletion, such as '.', '(' or '[' when typing an identifier. A set of characters that will cancel autocompletion can be specified with AutoCompStops.

bool AutoCompActive()

Returns true if there is an active autocompletion list, otherwise false.

int AutoCompPosStart()

Returns the value of the current position when AutoCompShow started display of the list.

void AutoCompComplete()

Completes an autocompletion operation. Internally, this is caused by clicking TAB, ENTER key;, or one of the characters specified by AutoCompSetFillUps. AutoCompComplete allows you to complete the operation programmatically.

void AutoCompStops (const wxString& characterSet)

The characterSet argument is a string containing a list of characters that will automatically cancel the autocompletion list. When you start the editor, this list is empty.

void AutoCompSetSeparator (int separatorCharacter)
int AutoCompGetSeparator()

These set and get the separator character used to separate words in the AutoCompShow list. The default is the space character.

void AutoCompSelect (const wxString& text)
AutoCompGetCurrent

Selects an item in the autocompletion list. It searches the list of words for the first that matches select. By default, comparisons are case sensitive, but you can change this with AutoCompSetIgnoreCase. The match is character by character for the length of the select string. That is, if select is "Fred" it will match "Frederick" if this is the first item in the list that begins with "Fred". If an item is found, it is selected. If the item is not found, the autocompletion list closes if auto-hide is true (see AutoCompSetAutoHide). The current selection can be retrieved with AutoCompGetCurrent.

void AutoCompSetCancelAtStart (bool cancel)
bool AutoCompGetCancelAtStart()

The default behavior is for the list to be cancelled if the caret moves before the location it was at when the list was displayed. By calling with a false argument, the list is not cancelled until the caret moves before the first character of the word being completed.

void AutoCompSetFillUps (const wxString& characterSet)

If a fillup character is typed with an autocompletion list active, the currently selected item in the list is added into the document, then the fillup character is added. Common fillup characters are '(', '[' and '.' but others are possible depending on the language. By default, no fillup characters are set.

void AutoCompSetChooseSingle (bool chooseSingle)/b>
bool AutoCompGetChooseSingle()

If you use AutoCompSetChooseSingle(1) and a list has only one item, it is automatically added and no list is displayed. The default is to display the list even if there is only a single item.

void AutoCompSetIgnoreCase (bool ignoreCase)
bool AutoCompGetIgnoreCase()

By default, matching of characters to list members is case sensitive. Let you set and get case sensitivity.

void AutoCompSetAutoHide (bool autoHide)
bool AutoCompGetAutoHide()

By default, the list is cancelled if there are no viable matches (the user has typed characters that no longer match a list entry). If you want to keep displaying the original list, set autoHide to false. This also effects AutoCompSelect.

void AutoCompSetDropRestOfWord (bool dropRestOfWord)
bool AutoCompGetDropRestOfWord()

When an item is selected, any word characters following the caret are first erased if dropRestOfWord is set true. The default is false.

void RegisterImage (int type, const wxBitmap& bmp)
void ClearRegisteredImages()
void AutoCompSetTypeSeparator (int separatorCharacter)
int AutoCompGetTypeSeparator()

Autocompletion list items may display an image as well as text. Each image is first registered with an integer type. Then this integer is included in the text of the list separated by a '?' from the text. For example, "fclose?2 fopen" displays image 2 before the string "fclose" and no image before "fopen". The images are in XPM format as is described for MarkerDefineBitmap The set of registered images can be cleared with ClearRegisteredImages and the '?' separator changed with AutoCompSetTypeSeparator.

void AutoCompSetMaxWidth (int characterCount)
int AutoCompGetMaxWidth()

Get or set the maximum number of rows that will be visible in an autocompletion list. If there are more rows in the list, then a vertical scrollbar is shown. The default is 5.

void AutoCompSetMaxHeight (int rowCount)
int AutoCompGetMaxHeight()

Get or set the maximum width of an autocompletion list expressed as the number of characters in the longest item that will be totally visible. If zero (the default) then the list's width is calculated to fit the item with the most characters. Any items that cannot be fully displayed within the available width are indicated by the presence of ellipsis.

User lists

User lists use the same internal mechanisms as autocompletion lists, and all the calls listed for autocompletion work on them; you cannot display a user list at the same time as an autocompletion list is active. They differ in the following respects:
o The AutoCompSetChooseSingle has no effect.
o When the user makes a selection you are sent a wxEVT_SCI_USERLISTSELECTION notification message.

BEWARE: if you have set fillup characters or stop characters, these will still be active with the user list, and may result in items being selected or the user list cancelled due to the user typing into the editor.

void UserListShow (int listType, const wxString& itemList)

The listType parameter is returned to the container as the wParam field of the SCNotification structure. It must be greater than 0 as this is how Scintilla tells the difference between an autocompletion list and a user list. If you have different types of list, for example a list of buffers and a list of macros, you can use listType to tell which one has returned a selection.

Call tips

Call tips are small windows displaying the arguments to a function and are displayed after the user has typed the name of the function. There is some interaction between call tips and autocompletion lists in that showing a call tip cancels any active autocompletion list, and vice versa.

Call tips can highlight part of the text within them. You could use this to highlight the current argument to a function by counting the number of commas (or whatever separator your language uses). See SciTEBase::CharAdded() in SciTEBase.cxx for an example of call tip use.

The mouse may be clicked on call tips and this causes a wxEVT_SCI_CALLTIPCLICK notification to be sent to the container. Small up an down arrows may be displayed within a call tip by, respectively, including the characters '\001', or '\002'. This is useful for showing that there are overloaded variants of one function name and that the user can click on the arrows to cycle through the overloads.

Alternatively, call tips can be displayed when you leave the mouse pointer for a while over a word in response to the wxEVT_SCI_DWELLSTART notification and cancelled in response to wxEVT_SCI_DWELLEND. This method could be used in a debugger to give the value of a variable, or during editing to give information about the word under the pointer.

void CallTipShow (int pos, const wxString& definition)

Starts the process by displaying the call tip window. If a call tip is already active, this has no effect.
posStart is the position in the document at which to align the call tip. The call tip text is aligned to start 1 line below this character.
definition is the call tip text. This can contain multiple lines separated by '\n' (Line Feed, ASCII code 10) characters.

void CallTipCancel()

Cancels any displayed call tip. Scintilla will also cancel call tips for you if you use any keyboard commands that are not compatible with editing the argument list of a function.

bool CallTipActive()

This returns true if a call tip is active, otherwise false.

int CallTipPosAtStart()

Returns the value of the current position when CallTipShow started to display the tip.

void CallTipSetHighlight (int startPos, int endPos)

This sets the region of the call tips text to display in a highlighted style. startPos is the zero-based index into the string of the first character to highlight and endPos is the index of the first character after the highlight. endPos must be greater than startPos; endPos-startPos is the number of characters to highlight. Highlights can extend over line ends if this is required.

Unhighlighted text is drawn in a mid gray. Selected text is drawn in a dark blue. The background is white. These can be changed with CallTipSetBackground, CallTipSetForeground, and CallTipSetForegroundHighlight.

void CallTipSetBackground (const wxColour& back)

The background colour of call tips can be set; the default colour is white. It is not a good idea to set a dark colour as the background as the unselected text is drawn in mid gray and the selected text in a dark blue.

void CallTipSetForeground (const wxColour& fore)

The colour of call tip text can be set; the default colour is mid gray.

void CallTipSetForegroundHighlight (const wxColour& fore)

The colour of highlighted call tip text can be set; the default colour is dark blue.

Keyboard commands

To allow the container application to perform any of the actions available to the user with keyboard, all the keyboard actions are commands. They do not take any parameters. These commands are also used when redefining the key bindings with the CmdKeyAssign.

wxSCI_CMD_LINEDOWN wxSCI_CMD_LINEDOWNEXTEND wxSCI_CMD_LINEDOWNRECTEXTEND wxSCI_CMD_LINESCROLLDOWN
wxSCI_CMD_LINEUP wxSCI_CMD_LINEUPEXTEND wxSCI_CMD_LINEUPRECTEXTEND wxSCI_CMD_LINESCROLLUP
wxSCI_CMD_PARADOWN wxSCI_CMD_PARADOWNEXTEND wxSCI_CMD_PARAUP wxSCI_CMD_PARAUPEXTEND
wxSCI_CMD_CHARLEFT wxSCI_CMD_CHARLEFTEXTEND wxSCI_CMD_CHARLEFTRECTEXTEND
wxSCI_CMD_CHARRIGHT wxSCI_CMD_CHARRIGHTEXTEND wxSCI_CMD_CHARRIGHTRECTEXTEND
wxSCI_CMD_WORDLEFT wxSCI_CMD_WORDLEFTEXTEND wxSCI_CMD_WORDRIGHT wxSCI_CMD_WORDRIGHTEXTEND
wxSCI_CMD_WORDLEFTEND wxSCI_CMD_WORDLEFTENDEXTEND wxSCI_CMD_WORDRIGHTEND wxSCI_CMD_WORDRIGHTENDEXTEND
wxSCI_CMD_WORDPARTLEFT wxSCI_CMD_WORDPARTLEFTEXTEND wxSCI_CMD_WORDPARTRIGHT wxSCI_CMD_WORDPARTRIGHTEXTEND
wxSCI_CMD_HOME wxSCI_CMD_HOMEEXTEND [wxSCI_CMD_HOMERECTEXTEND]
wxSCI_CMD_HOMEDISPLAY wxSCI_CMD_HOMEDISPLAYEXTEND wxSCI_CMD_HOMEWRAP wxSCI_CMD_HOMEWRAPEXTEND
wxSCI_CMD_VCHOME wxSCI_CMD_VCHOMEEXTEND wxSCI_CMD_VCHOMERECTEXTEND
wxSCI_CMD_VCHOMEWRAP wxSCI_CMD_VCHOMEWRAPEXTEND
wxSCI_CMD_LINEEND wxSCI_CMD_LINEENDEXTEND wxSCI_CMD_LINEENDRECTEXTEND
wxSCI_CMD_LINEENDDISPLAY wxSCI_CMD_LINEENDDISPLAYEXTEND wxSCI_CMD_LINEENDWRAP wxSCI_CMD_LINEENDWRAPEXTEND
wxSCI_CMD_DOCUMENTSTART wxSCI_CMD_DOCUMENTSTARTEXTEND wxSCI_CMD_DOCUMENTEND wxSCI_CMD_DOCUMENTENDEXTEND
wxSCI_CMD_PAGEUP wxSCI_CMD_PAGEUPEXTEND wxSCI_CMD_PAGEUPRECTEXTEND
wxSCI_CMD_PAGEDOWN wxSCI_CMD_PAGEDOWNEXTEND wxSCI_CMD_PAGEDOWNRECTEXTEND
wxSCI_CMD_STUTTEREDPAGEUP wxSCI_CMD_STUTTEREDPAGEUPEXTEND
wxSCI_CMD_STUTTEREDPAGEDOWN wxSCI_CMD_STUTTEREDPAGEDOWNEXTEND
wxSCI_CMD_DELETEBACK wxSCI_CMD_DELETEBACKNOTLINE wxSCI_CMD_DELWORDLEFT wxSCI_CMD_DELWORDRIGHT
wxSCI_CMD_DELLINELEFT wxSCI_CMD_DELLINERIGHT wxSCI_CMD_LINEDELETE
wxSCI_CMD_LINECUT wxSCI_CMD_LINECOPY wxSCI_CMD_LINETRANSPOSE wxSCI_CMD_LINEDUPLICATE
wxSCI_CMD_LOWERCASE wxSCI_CMD_UPPERCASE wxSCI_CMD_CANCEL wxSCI_CMD_EDITTOGGLEOVERTYPE
wxSCI_CMD_NEWLINE wxSCI_CMD_FORMFEED wxSCI_CMD_TAB wxSCI_CMD_BACKTAB

The wxSCI_CMD_...EXTEND extend the selection.

The wxSCI_CMD_...RECTEXTEND extend the rectangular selection (and convert regular selection to rectangular one, if any).

The wxSCI_CMD_WORDPART... commands are used to move between word segments marked by capitalisation (aCamelCaseIdentifier) or underscores (an_under_bar_ident).

The wxSCI_CMD_HOME... commands move the caret to the start of the line, while the wxSCI_CMD_VCHOME...commands move the caret to the first non-blank character of the line (ie. just after the indentation) unless it is already there; in this case, it acts as wxSCI_CMD_HOME....

The wxSCI_CMD_[HOME|LINEEND]DISPLAY... commands are used when in line wrap mode to allow movement to the start or end of display lines as opposed to the normal wxSCI_CMD_[HOME|LINEEND] commands which move to the start or end of document lines.

The wxSCI_CMD_[[VC]HOME|LINEEND]WRAP... commands are like their namesakes wxSCI_CMD_[[VC]HOME|LINEEND]... except they behave differently when word-wrap is enabled: They go first to the start / end of the display line, like wxSCI_CMD_[HOME|LINEEND]DISPLAY..., but if the cursor is already at the point, it goes on to the start or end of the document line, as appropriate for wxSCI_CMD_[[VC]HOME|LINEEND]....

Key bindings

There is a default binding of keys to commands that is defined in the table below. This table maps key definitions to wxSCI_CMD_... with no parameters (mostly the keyboard commands discussed above, but any Scintilla command that has no arguments can be mapped). You can change the mapping to suit your own rquirements.

keyDefinition

A key definition contains the key code in the low 16-bits and the key modifiers in the high 16-bits. To combine keyCode and keyMod set:
keyDefinition = keyCode + (keyMod << 16)

The key code is a visible or control character or a key from the wxSCI_KEY_... enumeration, which contains:

The modifiers are a combination of zero or more of wxSCI_SCMOD_ALT, wxSCI_SCMOD_CTRL, and wxSCI_SCMOD_SHIFT. If you are building a table, you might want to use wxSCI_SCMOD_NULL to mean no modifiers.

Key Modifiers Command
DOWN NULL LINEDOWN
DOWN SHIFT LINEDOWNEXTEND
DOWN
DOWN CTRL LINESCROLLDOWN
DOWN ALT+SHIFT LINEDOWNRECTEXTEND
UP NULL LINEUP
UP SHIFT LINEUPEXTEND
UP CTRL LINESCROLLUP
UP ALT+SHIFT LINEUPRECTEXTEND
LEFT NULL CHARLEFT
LEFT SHIFT CHARLEFTEXTEND
LEFT CTRL WORDLEFT
LEFT CTRL+SHIFT WORDLEFTEXTEND
LEFT ALT+SHIFT CHARLEFTRECTEXTEND
RIGHT NULL CHARRIGHT
RIGHT SHIFT CHARRIGHTEXTEND
RIGHT CTRL WORDRIGHT
RIGHT CTRL+SHIFT WORDRIGHTEXTEND
RIGHT ALT+SHIFT CHARRIGHTRECTEXTEND
HOME NULL VCHOME
HOME SHIFT VCHOMEEXTEND
HOME ALT+SHIFT VCHOMERECTEXTEND
HOME CTRL DOCUMENTSTART
HOME CTRL+SHIFT DOCUMENTSTARTEXTEND
HOME ALT HOMEDISPLAY
END NULL LINEEND
END SHIFT LINEENDEXTEND
END ALT+SHIFT LINEENDRECTEXTEND
END CTRL DOCUMENTEND
END CTRL+SHIFT DOCUMENTENDEXTEND
END ALT LINEENDDISPLAY
PRIOR NULL PAGEUP
PRIOR SHIFT PAGEUPEXTEND
PRIOR ALT+SHIFT PAGEUPRECTEXTEND
NEXT NULL PAGEDOWN
NEXT SHIFT PAGEDOWNEXTEND
NEXT ALT+SHIFT PAGEDOWNRECTEXTEND
'[' CTRL PARAUP
'[' CTRL+SHIFT PARAUPEXTEND
']' CTRL PARADOWN
']' CTRL+SHIFT PARADOWNEXTEND
'/' CTRL WORDPARTLEFT
'/' CTRL+SHIFT WORDPARTLEFTEXTEND
'\' CTRL WORDPARTRIGHT
'\' CTRL+SHIFT WORDPARTRIGHTEXTEND
DELETE NULL CLEAR
DELETE SHIFT CUT
DELETE CTRL DELWORDRIGHT
DELETE CTRL+SHIFT DELLINERIGHT
INSERT NULL EDITTOGGLEOVERTYPE
INSERT SHIFT PASTE
INSERT CTRL COPY
ESCAPE NULL CANCEL
BACK NULL DELETEBACK
BACK SHIFT DELETEBACK
BACK CTRL DELWORDLEFT
BACK ALT UNDO
BACK CTRL+SHIFT DELLINELEFT
TAB NULL TAB
TAB SHIFT BACKTAB
RETURN NULL NEWLINE
RETURN SHIFT NEWLINE
ADD CTRL ZOOMIN
SUBTRACT CTRL ZOOMOUT
DIVIDE CTRL SETZOOM
'A' CTRL SELECTALL
'C' CTRL COPY
'D' CTRL LINEDUPLICATE
'L' CTRL LINECUT
'L' CTRL+SHIFT LINEDELETE
'T' CTRL LINETRANSPOSE
'T' CTRL+SHIFT LINECOPY
'U' CTRL LOWERCASE
'U' CTRL UPPERCASE
'V' CTRL PASTE
'X' CTRL CUT
'Y' CTRL REDO
'Z' CTRL UNDO

Note: The entries 'D', 'L', 'T', 'U' seldom fits anyones need, so simply remove them with CmdKeyClear if you don't need them.

void CmdKeyAssign (int key, int modifiers, int cmd)

Assigns the given key definition to a Scintilla command identified by cmd. cmd can be any wxSCI_... command that has no arguments.

void CmdKeyClear (int key, int modifiers)

Makes the given key definition do nothing by assigning the action wxSCI_SCMOD_NULL to it.

void CmdKeyClearAll()

This command removes all keyboard command mapping by setting an empty mapping table.

Popup edit menu

void UsePopUp (bool allowPopUp)

Clicking the right button on the mouse pops up a short default editing menu. This may be turned off with UsePopUp (false). If you turn it off, context menu commands will not be handled by Scintilla, so the parent of the Scintilla window will have the opportunity to handle it.

Macro recording

Start and stop macro recording mode. In macro recording mode, actions are reported to the container through wxEVT_SCI_MACRORECORD notifications. It is then up to the container to record these actions for future replay.

void StartRecord()
void StopRecord()

Turn macro recording on and off.

Printing

On Windows FormatRange can be used to draw the text onto a display context which can include a printer display context. Printed output shows text styling as on the screen, but it hides all margins except a line number margin. All special marker effects are removed and the selection and caret are hidden.

int FormatRange (bool doDraw, int startPos, int endPos, wxDC* draw, wxDC* target, wxRect renderRect, wxRect pageRect)

This call allows Windows users to render a range of text into a device context. If you use this for printing, you will probably want to arrange a page header and footer; Scintilla does not do this for you. Renders a range of text into a rectangular area and returns the position in the document of the next character to print.

doDraw controls if any output is done. Set this to false if you are paginating (for example, if you use this with MFC you will need to paginate in OnBeginPrinting() before you output each page.

draw and target should both be set to the device context handle of the output device (usually a printer). If you print to a metafile these will not be the same as Windows metafiles (unlike extended metafiles) do not implement the full API for returning information. In this case, set hdcTarget to the screen DC.
pageRect is the rectangle {0, 0, maxX, maxY} where maxX+1 and maxY+1 are the number of physically printable pixels in x and y.
renderRect is the rectangle to render the text in (which will, of course, fit within the rectangle defined by pageRect).
startPos and endPos define the start position and maximum position of characters to output.

When printing, the most tedious part is always working out what the margins should be to allow for the non-printable area of the paper and printing a header and footer. If you look at the printing code in SciTE, you will find that most of it is taken up with this. The loop that causes Scintilla to render text is quite simple if you strip out all the margin, non-printable area, header and footer code.

void SetPrintMagnification (int magnification)
int GetPrintMagnification()

GetPrintMagnification lets you to print at a different size than the screen font. magnification is the number of points to add to the size of each screen font. A value of -3 or -4 gives reasonably small print. You can get this value with GetPrintMagnification.

void SetPrintColourMode (int mode)
int GetPrintColourMode()

Set and get the method used to render coloured text on a printer that is probably using white paper. It is especially important to consider the treatment of colour if you use a dark or black screen background. Printing white on black uses up toner and ink very many times faster than the other way around. You can set the mode to one of:

Symbol Value Purpose
wxSCI_PRINT_NORMAL 0 Print using the current screen colours. This is the default.
wxSCI_PRINT_INVERTLIGHT 1 If you use a dark screen background this saves ink by inverting the light value of all colours and printing on a white background.
wxSCI_PRINT_BLACKONWHITE 2 Print all text as black on a white background.
wxSCI_PRINT_COLOURONWHITE 3 Everything prints in its own colour on a white background.
wxSCI_PRINT_COLOURONWHITEDEFAULTBG 4 Everything prints in its own colour on a white background except that line numbers use their own background colour.

void SetPrintWrapMode (int mode)
int GetPrintWrapMode()

These two functions get and set the printer wrap mode. mode can be set to wxSCI_WRAP_NONE (0) or wxSCI_WRAP_WORD (1). The default is wxSCI_WRAP_WORD, which wraps printed output so that all characters fit into the print rectangle. If you set wxSCI_WRAP_NONE, each line of text generates one line of output and the line is truncated if it is too long to fit into the print area.

Multiple views

A Scintilla window and the document that it displays are separate entities. When you create a new window, you also create a new, empty document. Each document has a reference count that is initially set to 1. The document also has a list of the Scintilla windows that are linked to it so when any window changes the document, all other windows in which it appears are notified to cause them to update. The system is arranged in this way so that you can work with many documents in a single Scintilla window and so you can display a single document in multiple windows (for use with splitter windows).

Although these use document *pDoc, to ensure compatibility with future releases of Scintilla you should treat pDoc as an opaque void*. That is, you can use and store the pointer as described in this section but you should not dereference it.

void* GetDocPointer()

This returns a pointer to the document currently in use by the window. It has no other effect.

void SetDocPointer (void* docPointer)

Does the following:
1. It removes the current window from the list held by the current document.
2. It reduces the reference count of the current document by 1.
3. If the reference count reaches 0, the document is deleted.
4. pDoc is set as the new document for the window.
5. If pDoc was 0, a new, empty document is created and attached to the window.

void* CreateDocument()

Creates a new, empty document and returns a pointer to it. This document is not selected into the editor and starts with a reference count of 1. This means that you have ownership of it and must either reduce its reference count by 1 after using SetDocPointer so that the Scintilla window owns it or you must make sure that you reduce the reference count by 1 with ReleaseDocument before you close the application to avoid memory leaks.

void AddRefDocument (void* docPointer)

This increases the reference count of a document by 1. If you want to replace the current document in the Scintilla window and take ownership of the current document, for example if you are editing many documents in one window, do the following:
1. Use GetDocPointer() to get a pointer to the document, pDoc.
2. Use AddRefDocument (pDoc) to increment the reference count.
3. Use SetDocPointer (pNewDoc) to set a different document or SetDocPointer (0) to set a new, empty document.

void ReleaseDocument (void* docPointer)

Reduces the reference count of the document identified by pDoc. pDoc must be the result of GetDocPointer or CreateDocument and must point at a document that still exists. If you call this on a document with a reference count of 1 that is still attached to a Scintilla window, bad things will happen. To keep the world spinning in its orbit you must balance each call to CreateDocument or AddRefDocument with a call to ReleaseDocument.

Folding

The fundamental operation in folding is making lines invisible or visible. Line visibility is a property of the view rather than the document so each view may be displaying a different set of lines. From the point of view of the user, lines are hidden and displayed using fold points. Generally, the fold points of a document are based on the hierarchical structure of the document contents. In Python, the hierarchy is determined by indentation and in C++ by brace characters. This hierarchy can be represented within a Scintilla document object by attaching a numeric "fold level" to each line. The fold level is most easily set by a lexer.

It is up to your code to set the connection between user actions and folding and unfolding. See the sample how they are used. You will also need to use markers and a folding margin to complete your folding implementation. The "fold" property should be set to "1" with SetProperty("fold", "1") to enable folding.

int VisibleFromDocLine (int line)

When some lines are folded, then a particular line in the document may be displayed at a different position to its document position. If no lines are folded, it returns docLine. Otherwise, this returns the display line (counting the very first visible line as 0). The display line of an invisible line is the same as the previous visible line. The display line number of the first line in the document is 0. If there is folding and docLine is outside the range of lines in the document, the return value is -1. Lines can occupy more than one display line if they wrap.

int DocLineFromVisible (int lineDisplay)

When some lines are hidden, then a particular line in the document may be displayed at a different position to its document position. Returns the document line number that corresponds to a display line (counting the display line of the first line in the document as 0). If displayLine is less than or equal to 0, the result is 0. If displayLine is greater than or equal to the number of displayed lines, the result is the number of lines in the document.

void ShowLines (int lineStart, int lineEnd)
void HideLines (int lineStart, int lineEnd)
bool GetLineVisible (int line)

The first two mark a range of lines as visible or invisible and then redraw the display. The third reports on the visible state of a line and returns true if it is visible, otherwise false. These have no effect on fold levels or fold flags.

void SetFoldLevel (int line, int level)
int GetFoldLevel (int line)

Set and get a 32-bit value that contains the fold level of a line and some flags associated with folding. The fold level is a number in the range 0 to wxSCI_FOLDLEVELNUMBERMASK (4095). However, the initial fold level is set to wxSCI_FOLDLEVELBASE (1024) to allow unsigned arithmetic on folding levels. There are two addition flag bits. wxSCI_FOLDLEVELWHITEFLAG indicates that the line is blank and allows it to be treated slightly different then its level may indicate. For example, blank lines should generally not be fold points. wxSCI_FOLDLEVELHEADERFLAG indicates that the line is a header (fold point).

Use GetFoldLevel(line) & wxSCI_FOLDLEVELNUMBERMASK to get the fold level of a line. Likewise, use GetFoldLevel(line) & wxSCI_FOLDLEVEL*FLAG to get the state of the flags. To set the fold level you must or in the associated flags. For instance, to set the level to thisLevel and mark a line as being a fold point use: SetFoldLevel(line, thisLevel | wxSCI_FOLDLEVELHEADERFLAG).

If you use a lexer, you should not need to use SetFoldLevel as this is far better handled by the lexer. You will need to use GetFoldLevel to decide how to handle user folding requests. If you do change the fold levels, the folding margin will update to match your changes.

void SetFoldFlags (int flags)

In addition to showing markers in the folding margin, you can indicate folds to the user by drawing lines in the text area. The lines are drawn in the foreground colour set for wxSCI_STYLE_DEFAULT. Bits set in flags determine where folding lines are drawn:

Value Effect
1 Experimental - draw boxes if expanded
2 Draw above if expanded
4 Draw above if not expanded
8 Draw below if expanded
16 Draw below if not expanded
64 display hexadecimal fold levels in line margin to aid debugging of folding. This feature needs to be redesigned to be sensible.

Causes the display to redraw.

int GetLastChild (int line, int level)

Searches for the next line after line, that has a folding level that is less than or equal to level and then returns the previous line number. If you set level to -1, level is set to the folding level of line line. If line is a fold point, GetLastChild(from, -1) returns the last line that would be in made visible or hidden by toggling the fold state.

int GetFoldParent (int line)

Returns the line number of the first line before line that is marked as a fold point with wxSCI_FOLDLEVELHEADERFLAG and has a fold level less than the line. If no line is found, or if the header flags and fold levels are inconsistent, the return value is -1.

void ToggleFold (int line)

Each fold point may be either expanded, displaying all its child lines, or contracted, hiding all the child lines. Toggles the folding state of the given line as long as it has the wxSCI_FOLDLEVELHEADERFLAG set. Takes care of folding or expanding all the lines that depend on the line. The display updates afterwards.

void SetFoldExpanded (int line, bool expanded)
bool GetFoldExpanded (int line)

Set and get the expanded state of a single line. The set has no effect on the visible state of the line or any lines that depend on it. It does change the markers in the folding margin. If you ask for the expansion state of a line that is outside the document, the result is false.

If you just want to toggle the fold state of one line and handle all the lines that are dependent on it, it is much easier to use ToggleFold. You would use the SetFoldExpanded to process many folds without updating the display until you had finished.

EnsureVisible(int line)
void EnsureVisibleEnforcePolicy (int line)

A line may be hidden because more than one of its parent lines is contracted. Both travels up the fold hierarchy, expanding any contracted folds until they reach the top level. The line will then be visible. If you use EnsureVisibleEnforcePolicy, the vertical caret policy set by SetVisiblePolicy is then applied.

Line wrapping

By default, Scintilla does not wrap lines of text. If you enable line wrapping, lines wider than the window width are continued on the following lines. Lines are broken after space or TAB characters or between runs of different styles. If this is not possible because a word in one style is wider than the window then the break occurs after the last character that completely fits on the line. The horizontal scroll bar does not appear when wrap mode is on.

For wrapped lines Scintilla can draw visual flags (little arrows) at end of a a subline of a wrapped line and at begin of the next subline. These can be enabled individually, but if Scintilla draws the visual flag at begin of the next subline this subline will be indented by one char. Independent from drawing a visual flag at the begin the subline can have an indention.

Much of the time used by Scintilla is spent on laying out and drawing text. The same text layout calculations may be performed many times even when the data used in these calculations does not change. To avoid these unnecessary calculations in some circumstances, the line layout cache can store the results of the calculations. The cache is invalidated whenever the underlying data, such as the contents or styling of the document changes. Caching the layout of the whole document has the most effect, making dynamic line wrap as much as 20 times faster but this requires 7 times the memory required by the document contents plus around 80 bytes per line.

Wrapping is not performed immediately there is a change but is delayed until the display is redrawn. This delay improves peformance by allowing a set of changes to be performed and then wrapped and displayed once. Because of this, some operations may not occur as expected. If a file is read and the scroll position moved to a particular line in the text, such as occurs when a container tries to restore a previous editing session, then the scroll position will have been determined before wrapping so an unexpected range of text will be displayed. To scroll to the position correctly, delay the scroll until the wrapping has been performed by waiting for an initial wxEVT_SCI_PAINTED notification.

void SetWrapMode (int mode)
int GetWrapMode()

Set wrapMode to wxSCI_WRAP_WORD (1) to enable line wrapping and to wxSCI_WRAP_NONE to disable line wrapping.

void SetWrapVisualFlags (int wrapVisualFlags)
int GetWrapVisualFlags()

You can enable the drawing of visual flags to indicate a line is wrapped. Bits set in wrapVisualFlags determine which visual flags are drawn.

Symbol Value Effect
wxSCI_WRAPVISUALFLAG_NONE 0 No visual flags
wxSCI_WRAPVISUALFLAG_END 1 Visual flag at end of subline of a wrapped line.
wxSCI_WRAPVISUALFLAG_START 2 Visual flag at begin of subline of a wrapped line. Subline is indented by at least 1 to make room for the flag.

SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation)
int GetWrapVisualFlagsLocation()

You can set wether the visual flags to indicate a line is wrapped are drawn near the border or near the text. Bits set in wrapVisualFlagsLocation set the location to near the text for the corresponding visual flag.

Symbol Value Effect
wxSCI_WRAPVISUALFLAGLOC_DEFAULT 0 Visual flags drawn near border
wxSCI_WRAPVISUALFLAGLOC_END_BY_TEXT 1 Visual flag at end of subline drawn near text
wxSCI_WRAPVISUALFLAGLOC_START_BY_TEXT 2 Visual flag at begin of subline drawn near text

void SetWrapStartIndent (int indent)
int GetWrapStartIndent()

SetWrapStartIndent sets the size of indentation of sublines for wrapped lines in terms of the width of a space in wxSCI_STYLE_DEFAULT. There are no limits on indent sizes, but values less than 0 or large values may have undesirable effects. The indention of sublines is in dependent of visual flags, but if wxSCI_WRAPVISUALFLAG_START is set an indent of at least 1 is used.

void SetLayoutCache (int mode)
int GetLayoutCache()

You can set cacheMode to one of the symbols in the table:

Symbol Value Layout cached for these lines
SC_CACHE_NONE 0 No lines are cached.
SC_CACHE_CARET 1 The line containing the text caret. This is the default.
SC_CACHE_PAGE 2 Visible lines plus the line containing the caret.
SC_CACHE_DOCUMENT 3 All lines in the document.

void LinesSplit (int pixels)

Split a range of lines indicated by the target into lines that are at most pixels wide. Splitting occurs on word boundaries wherever possible in a similar manner to line wrapping. When pixels is 0 then the width of the window is used.

void LinesJoin()

Join a range of lines indicated by the target into one line by removing line end characters. Where this would lead to no space between words, an extra space is inserted.

int WrapCount (int line)

Document lines can occupy more than one display line if they wrap and this returns the number of display lines needed to wrap a document line.

Zooming

Scintilla incorporates a "zoom factor" that lets you make all the text in the document larger or smaller in steps of one point. The displayed point size never goes below 2, whatever zoom factor you set. You can set zoom factors in the range -10 to +20 points.

void ZoomIn()
void ZoomOut()

ZoomIn increases the zoom factor by one point if the current zoom factor is less than 20 points. ZoomOut decreases the zoom factor by one point if the current zoom factor is greater than -10 points.

void SetZoom (int zoom)
int GetZoom()

Set and get the zoom factor directly. There is no limit set on the factors you can set, so limiting yourself to -10 to +20 to match the incremental zoom functions is a good idea.

Long lines

You can choose to mark lines that exceed a given length by drawing a vertical line or by colouring the background of characters that exceed the set length.

void SetEdgeMode (int mode)
int GetEdgeMode()

Set and get the mode used to display long lines. You can set one of the values in the table:

Symbol Value Long line display mode
wxSCI_EDGE_NONE 0 Long lines are not marked. This is the default state.
wxSCI_EDGE_LINE 1 A vertical line is drawn at the column number set by SetEdgeColumn. This works well for monospaced fonts. The line is drawn at a position based on the width of a space character in wxSCI_STYLE_DEFAULT, so it may not work very well if your styles use proportional fonts or if your style have varied font sizes or you use a mixture of bold, italic and normal text.
wxSCI_EDGE_BACKGROUND 2 The background colour of characters after the column limit is changed to the colour set by SetEdgeColour. This is recommended for proportional fonts.

void SetEdgeColumn (int column)
int GetEdgeColumn()

Set and get the column number at which to display the long line marker. When drawing lines, the column sets a position in units of the width of a space character in wxSCI_STYLE_DEFAULT. When setting the background colour, the column is a character count (allowing for tabs) into the line.

void SetEdgeColour (const wxColour& colour)
wxColour GetEdgeColour()

Set and get the colour of the marker used to show that a line has exceeded the length set by SetEdgeColumn.

Lexer

If you define the symbol SCI_LEXER when building Scintilla, (this is sometimes called the SciLexer version of Scintilla), lexing support for a wide range programming languages is included. If you want to set styling and fold points for an unsupported language you can either do this in the container or better still, write your own lexer following the pattern of one of the existing ones.

Scintilla also supports external lexers. These are DLLs (on Windows) or .so modules (on GTK+/Linux) that export four functions: GetLexerCount, GetLexerName, Lex and Fold. See externalLexer.cxx for more.

void SetLexer (int lexer)
int GetLexer()

You can select the lexer to use with an integer code from the wxSCI_LEX_* enumeration in Scintilla.h. There are two codes in this sequence that do not use lexers:
wxSCI_LEX_NULL to select no lexing action and wxSCI_LEX_CONTAINER which sends the wxEVT_SCI_STYLENEEDED notification to the container whenever a range of text needs to be styled. You cannot use the wxSCI_LEX_AUTOMATIC value; this identifies additional external lexers that Scintilla assigns unused lexer numbers to.

void SetLexerLanguage (const wxString& language)

Lets you select a lexer by name, and is the only method if you are using an external lexer or if you have written a lexer module for a language of your own and do not wish to assign it an explicit lexer number. To select an existing lexer, set name to match the (case sensitive) name given to the module, for example "ada" or "python", not "Ada" or "Python". To locate the name for the built-in lexers, open the relevant Lex*.cxx file and search for LexerModule. The third argument in the LexerModule constructor is the name to use.

To test if your lexer assignment worked, use GetLexer before and after setting the new lexer to see if the lexer number changed.

void Colourise (int startPos, int endPos)

This forces the current lexer or the container (if the lexer is set to wxSCI_LEX_CONTAINER) to style the document between startPos and endPos. If endPos is wxSCI_INVALID_POSITION, the document is styled from startPos to the end. If the "fold" property is set to "1" and your lexer or container supports folding, fold levels are also set. Causes a redraw.

void SetProperty (const wxString& key, const wxString& value)

You can communicate settings to lexers with keyword:value string pairs. There is no limit to the number of keyword pairs you can set, other than available memory. key is a case sensitive keyword, value is a string that is associated with the keyword. If there is already a value string associated with the keyword, it is replaced. If you pass a zero length string, nothing is done. Both key and value are used without modification; extra spaces at the beginning or end of key are significant.

The value string can refer to other keywords. For example, SetProperty ("foldTimes10", "$(fold)0") stores the string "$(fold)0", but when this is accessed, the $(fold) is replaced by the value of the "fold" keyword (or by nothing if this keyword does not exist).

Currently the "fold" property is defined for most of the lexers to set the fold structure if set to "1". wxSCI_LEX_PYTHON understands "TAB.timmy.whinge.level" as a setting that determines how to indicate bad indentation. Most keywords have values that are interpreted as integers. Search the lexer sources for GetPropertyInt to see how properties are used.

void GetProperty (const wxString& key, wxString& value)

Lookup a keyword:value pair using the specified key; if found, copy the value to the user-supplied buffer and return the length (not including the terminating 0). If not found, copy an empty string to the buffer and return 0.

Note that "keyword replacement" as described in SetProperty will not be performed.

If the value argument is 0 then the length that should be allocated to store the value is returned; again, the terminating 0 is not included.

void GetPropertyExpanded (const wxString& key, wxString& value)

Lookup a keyword:value pair using the specified key; if found, copy the value to the user-supplied buffer and return the length (not including the terminating 0). If not found, copy an empty string to the buffer and return 0.

Note that "keyword replacement" as described in SetProperty will not be performed.

If the value argument is 0 then the length that should be allocated to store the value (including any indicated keyword replacement) is returned; again, the terminating 0 is not included.

int GetPropertyInt (const wxString& key)

Lookup a keyword:value pair using the specified key; if found, interpret the value as an integer and return it. If not found (or the value is not a number) then return 0.

Note that "keyword replacement" as described in SetProperty will not be performed.

void SetKeyWords (int keywordSet, const wxString& keyWords)

You can set up to 9 lists of keywords for use by the current lexer. keyWordSet can be 0 to 8 (actually 0 to wxSCI_KEYWORDSET_MAX) and selects which keyword list to replace. keyWordList is a list of keywords separated by spaces, tabs, "\n" or "\r" or any combination of these. It is expected that the keywords will be composed of standard ASCII printing characters, but there is nothing to stop you using any non-separator character codes from 1 to 255 (except common sense).

How these keywords are used is entirely up to the lexer. Some languages, such as HTML may contain embedded languages, VBScript and JavaScript are common for HTML. For HTML, key word set 0 is for HTML, 1 is for JavaScript and 2 is for VBScript, 3 is for Python, 4 is for PHP and 5 is for SGML and DTD keywords. Review the lexer code to see examples of keyword list. A fully conforming lexer sets the fourth argument of the LexerModule constructor to be a list of strings that describe the uses of the keyword lists.

Alternatively, you might use set 0 for general keywords, set 1 for keywords that cause indentation and set 2 for keywords that cause unindentation. Yet again, you might have a simple lexer that colours keywords and you could change languages by changing the keywords in set 0. There is nothing to stop you building your own keyword lists into the lexer, but this means that the lexer must be rebuilt if more keywords are added.

Notifications

Notifications are sent (fired) from the Scintilla control to its container when an event has occurred that may interest the container. Notifications are sent using the WM_NOTIFY message on Windows and the "notify" signal on GTK+.

The notification messages that your container can choose to handle and the messages associated with them are:

The following functions are associated with these notifications:

The following additional notifications are sent using the WM_COMMAND message on Windows and the "Command" signal on GTK+ to emulate the Windows Edit control:

wxEVT_SCI_STYLENEEDED

If you used SetLexer(wxSCI_LEX_CONTAINER) to make the container act as the lexer, you will receive this notification when Scintilla is about to display or print text that requires styling. You are required to style the text from the line that contains the position returned by GetEndStyled up to the position passed in SCNotification.position. Symbolically, you need code of the form:

  startPos = GetEndStyled()
  lineNumber = LineFromPosition(startPos);
  startPos = PositionFromLine(lineNumber);
  MyStyleRoutine(startPos, SCNotification.position);

wxEVT_SCI_CHARADDED

This is sent when the user types an ordinary text character (as opposed to a command character) that is entered into the text. The container can use this to decide to display a call tip or an auto completion list. The character is in SCNotification.ch.

wxEVT_SCI_SAVEPOINTREACHED
wxEVT_SCI_SAVEPOINTLEFT

Sent to the container when the save point is entered or left, allowing the container to display a "document dirty" indicator and change its menus.

See also: SetSavePoint, GetModify

wxEVT_SCI_MODIFYATTEMPTRO

When in read-only mode, this notification is sent to the container if the user tries to change the text. This can be used to check the document out of a version control system. You can set the read-only state of a document with SetReadOnly.

wxEVT_SCI_KEY

Reports all keys pressed. Used on GTK+ because of some problems with keyboard focus and is not sent by the Windows version. SCNotification.ch holds the key code and SCNotification.modifiers holds the modifiers. This notification is sent if the modifiers include SCMOD_ALT or SCMOD_CTRL and the key code is less than 256.

wxEVT_SCI_DOUBLECLICK

The mouse button was double clicked in editor. There is no additional information.

wxEVT_SCI_UPDATEUI

Either the text or styling of the document has changed or the selection range has changed. Now would be a good time to update any container UI elements that depend on document or view state. This was previously called wxEVT_SCI_CHECKBRACE because a common use is to check whether the caret is next to a brace and set highlights on this brace and its corresponding matching brace. This also replaces wxEVT_SCI_POSCHANGED, which is now deprecated.

wxEVT_SCI_MODIFIED

This notification is sent when the text or styling of the document changes or is about to change. You can set a mask for the notifications that are sent to the container with SetModEventMask. The notification structure contains information about what changed, how the change occurred and whether this changed the number of lines in the document. No modifications may be performed while in a wxEVT_SCI_MODIFIED event. The SCNotification fields used are:

Field Usage
modificationType A set of flags that identify the change(s) made. See the next table.
position Start position of a text or styling change. Set to 0 if not used.
length Length of the change in cells or characters when the text or styling changes. Set to 0 if not used.
linesAdded Number of added lines. If negative, the number of deleted lines. Set to 0 if not used or no lines added or deleted.
text Valid for text changes, not for style changes. If we are collecting undo information this holds a pointer to the text that is handed to the Undo system, otherwise it is zero.
line The line number at which a fold level or marker change occurred. This is 0 if unused.
foldLevelNow The new fold level applied to the line or 0 if this field is unused.
foldLevelPrev The previous folding level of the line or 0 if this field is unused.

The SCNotification.modificationType field has bits set to tell you what has been done. The wxSCI_MOD_* bits correspond to actions. The wxSCI_PERFORMED_... bits tell you if the action was done by the user, or the result of Undo or Redo of a previous action.

Symbol Value Meaning SCNotification fields
wxSCI_MOD_INSERTTEXT 0x01 Text has been inserted into the document. position, length, linesAdded
wxSCI_MOD_DELETETEXT 0x02 Text has been removed from the document. position, length, linesAdded
wxSCI_MOD_CHANGESTYLE 0x04 A style change has occurred. position, length
wxSCI_MOD_CHANGEFOLD 0x08 A folding change has occurred. line, foldLevelNow, foldLevelPrev
wxSCI_PERFORMED_USER 0x10 Information: the operation was done by the user. None
wxSCI_PERFORMED_UNDO 0x20 Information: this was the result of an Undo. None
wxSCI_PERFORMED_REDO 0x40 Information: this was the result of a Redo. None
wxSCI_MULTISTEPUNDOREDO 0x80 This is part of a multi-step Undo or Redo. None
wxSCI_LASTSTEPINUNDOREDO 0x100 This is the final step in an Undo or Redo. None
wxSCI_MOD_CHANGEMARKER 0x200 One or more markers has changed in a line. line
wxSCI_MOD_BEFOREINSERT 0x400 Text is about to be inserted into the document. position, length
wxSCI_MOD_BEFOREDELETE 0x800 Text is about to be deleted from the document. position, length
wxSCI_LASTLINEUNDOREDO 0x1000 This is part of an Undo or Redo with multi-line changes. None
wxSCI_MODEVENTMASKALL 0x1FFF This is a mask for all valid flags. This is the default mask state set by SetModEventMask. None

wxEVT_SCI_CHANGE

wxEVT_SCI_CHANGE (768) is fired when the text (not the style) of the document changes. This notification is sent using the WM_COMMAND message on Windows and the "Command" signal on GTK+ as this is the behavior of the standard Edit control (wxEVT_SCI_CHANGE has the same value as the Windows Edit control EN_CHANGE). No other information is sent. If you need more detailed information use wxEVT_SCI_MODIFIED. You can filter the types of changes you are notified about with SetModEventMask.

void SetModEventMask (int mask)
int GetModEventMask()

Set and get an event mask that determines which document change events are notified to the container with wxEVT_SCI_MODIFIED and wxEVT_SCI_CHANGE. For example, a container may decide to see only notifications about changes to text and not styling changes by calling SetModEventMask(wxSCI_MOD_INSERTTEXT|wxSCI_MOD_DELETETEXT).

The possible notification types are the same as the modificationType bit flags used by wxEVT_SCI_MODIFIED: wxSCI_MOD_INSERTTEXT, wxSCI_MOD_DELETETEXT, wxSCI_MOD_CHANGESTYLE, wxSCI_MOD_CHANGEFOLD, wxSCI_PERFORMED_USER, wxSCI_PERFORMED_UNDO, wxSCI_PERFORMED_REDO, wxSCI_MULTISTEPUNDOREDO, wxSCI_LASTSTEPINUNDOREDO, wxSCI_MOD_CHANGEMARKER, wxSCI_MOD_BEFOREINSERT, wxSCI_MOD_BEFOREDELETE, wxSCI_MULTILINEUNDOREDO and wxSCI_MODEVENTMASKALL.

wxEVT_SCI_MACRORECORD

The StartRecord and StopRecord enable and disable macro recording. When enabled, each time a recordable change occurs, the wxEVT_SCI_MACRORECORD notification is sent to the container. It is up to the container to record the action. To see the complete list that are recordable, search the Scintilla source Editor.cxx for Editor::NotifyMacroRecord. The fields of SCNotification set in this notification are:

Field Usage
message The command that caused the notification.
wParam The value of wParam in the .
lParam The value of lParam in the .

wxEVT_SCI_MARGINCLICK

This notification tells the container that the mouse was clicked inside a margin that was marked as sensitive (see SetMarginSensitive). This can be used to perform folding or to place breakpoints. The following SCNotification fields are used:

Field Usage
modifiers The appropriate combination of SCI_SHIFT, SCI_CTRL and SCI_ALT to indicate the keys that were held down at the time of the margin click.
position The position of the start of the line in the document that corresponds to the margin click.
margin The margin number that was clicked.

wxEVT_SCI_NEEDSHOWN

Scintilla has determined that a range of lines that is currently invisible should be made visible. An example of where this may be needed is if the end of line of a contracted fold point is deleted. This message is sent to the container in case it wants to make the line visible in some unusual way such as making the whole document visible. Most containers will just ensure each line in the range is visible by calling EnsureVisible. The position and length fields of SCNotification indicate the range of the document that should be made visible. The container code will be similar to the following code skeleton:

    firstLine = LineFromPosition (scn.position)
    lastLine = LineFromPosition (scn.position+scn.length-1)
    for line = lineStart to lineEnd do EnsureVisible (line) next

wxEVT_SCI_PAINTED

Painting has just been done. Useful when you want to update some other widgets based on a change in Scintilla, but want to have the paint occur first to appear more responsive. There is no other information in SCNotification.

wxEVT_SCI_USERLISTSELECTION

The user has selected an item in a user list. The SCNotification fields used are:

Field Usage
wParam This is set to the listType parameter from the UserListShow that initiated the list.
text The text of the selection.

wxEVT_SCI_URIDROPPED

Only on the GTK+ version. Indicates that the user has dragged a URI such as a file name or Web address onto Scintilla. The container could interpret this as a request to open the file. The text field of SCNotification points at the URI text.

wxEVT_SCI_DWELLSTART
wxEVT_SCI_DWELLEND

wxEVT_SCI_DWELLSTART is generated when the user keeps the mouse in one position for the dwell period (see SetMouseDwellTime). wxEVT_SCI_DWELLEND is generated after a wxEVT_SCI_DWELLSTART and the mouse is moved or other activity such as key press indicates the dwell is over. Both notifications set the same fields in SCNotification:

Field Usage
position This is the nearest position in the document to the position where the mouse pointer was lingering.
x, y Where the pointer lingered. The position field is set to PositionFromPointClose(x, y).

void SetMouseDwellTime (int periodMilliseconds)
int GetMouseDwellTime()

Set and get the time the mouse must sit still, in milliseconds, to generate a wxEVT_SCI_DWELLSTART notification. If set to wxSCI_TIME_FOREVER, the default, no dwell events are generated.

wxEVT_SCI_ZOOM

This notification is generated when the user zooms the display using the keyboard or the SetZoom method is called. This notification can be used to recalculate positions, such as the width of the line number margin to maintain sizes in terms of characters rather than pixels. SCNotification has no additional information.

wxEVT_SCI_HOTSPOTCLICK
wxEVT_SCI_HOTSPOTDOUBLECLICK

These notifications are generated when the user clicks or double clicks on text that is in a style with the hotspot attribute set. This notification can be used to link to variable definitions or web pages. The position field is set the text position of the click or double click and the modifiers field set to the key modifiers held down in a similar manner to wxEVT_SCI_KEY.

wxEVT_SCI_CALLTIPCLICK

This notification is generated when the user clicks on a calltip. This notification can be used to display the next function prototype when a function name is overloaded with different arguments. The position field is set to 1 if the click is in an up arrow, 2 if in a down arrow, and 0 if elsewhere.

[Home]