![]() |
Scintilla |
Last edited 20/June/2007 NH
There is an overview of the internal design of
Scintilla.
Some notes on using Scintilla.
How to use the Scintilla Edit Control on Windows.
A simple sample using Scintilla from
C++ on Windows.
A simple sample using Scintilla from
Visual Basic.
Bait is a tiny sample using Scintilla
on GTK+.
A detailed description of how to write a lexer, including a
discussion of folding.
How to implement a lexer in the container.
How to implement folding.
The coding style used in Scintilla and SciTE is
worth following if you want to contribute code to Scintilla but is not compulsory.
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.
This documentation describes the individual messages and notifications used by Scintilla. It does not describe how to link them together to form a useful editor. For now, the best way to work out how to develop using Scintilla is to see how SciTE uses it. SciTE exercises most of Scintilla's facilities.
In the descriptions that follow, the messages are described as function calls with zero, one
or two arguments. These two arguments are the standard wParam and
lParam familiar to Windows programmers. These parameters are integers that
are large enough to hold pointers, and the return value is also an integer large enough to contain a
pointer.
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. |
| alpha | Translucency is set using an alpha value. Alpha ranges from 0 (SC_ALPHA_TRANSPARENT) which is completely transparent to 255 (SC_ALPHA_OPAQUE) which is opaque. The value 256 (SC_ALPHA_NOALPHA) is opaque and uses code that is not alpha-aware and may be faster. Not all platforms support translucency and only some Scintilla features implement translucency. The default alpha value for most features is SC_ALPHA_NOALPHA. |
| <unused> | This is an unused argument. Setting it to 0 will ensure compatibility with future enhancements. |
Messages with names of the form SCI_SETxxxxx often have a companion
SCI_GETxxxxx. To save tedious repetition, if the SCI_GETxxxxx message
returns the value set by the SCI_SETxxxxx message, the SET routine is
described and the GET routine is left to your imagination.
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 an index into an array of styles. Style bytes may be split into an index and a set of indicator bits but this use is discouraged and indicators should now use and related calls. The default split is with the index in the low 5 bits and 3 high bits as indicators. This allows 32 fundamental styles, which is enough for most languages, and three independent indicators so that, 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 up to a maximum of 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 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.
SCI_GETTEXT(int length, char *text)
SCI_SETTEXT(<unused>, const char *text)
SCI_SETSAVEPOINT
SCI_GETLINE(int line, char *text)
SCI_REPLACESEL(<unused>, const char
*text)
SCI_SETREADONLY(bool readOnly)
SCI_GETREADONLY
SCI_GETTEXTRANGE(<unused>, TextRange
*tr)
SCI_ALLOCATE(int bytes, <unused>)
SCI_ADDTEXT(int length, const char *s)
SCI_ADDSTYLEDTEXT(int length, cell *s)
SCI_APPENDTEXT(int length, const char *s)
SCI_INSERTTEXT(int pos, const char *text)
SCI_CLEARALL
SCI_CLEARDOCUMENTSTYLE
SCI_GETCHARAT(int position)
SCI_GETSTYLEAT(int position)
SCI_GETSTYLEDTEXT(<unused>, TextRange
*tr)
SCI_SETSTYLEBITS(int bits)
SCI_GETSTYLEBITS
SCI_TARGETASUTF8(<unused>, char *s)
SCI_ENCODEDFROMUTF8(const char *utf8, char *encoded)
SCI_SETLENGTHFORENCODE(int bytes)
SCI_GETTEXT(int length, char *text)
This returns length-1 characters of text from the start of the document plus one
terminating 0 character. To collect all the text in a document, use SCI_GETLENGTH
to get the number of characters in the document (nLen), allocate a character
buffer of length nLen+1 bytes, then call SCI_GETTEXT(nLen+1, char
*text). If the text argument is 0 then the length that should be allocated to store the
entire document is returned.
If you then save the text, you should use SCI_SETSAVEPOINT to mark
the text as unmodified.
See also: , , , ,
SCI_SETTEXT(<unused>, const char *text)
This replaces all the text in the document with the zero terminated text string you pass
in.
SCI_SETSAVEPOINT
This message tells Scintilla that the current state of the document is 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 and notification messages, allowing the container to know if the file
should be considered dirty or not.
See also: ,
SCI_GETLINE(int line, char *text)
This fills the buffer defined by text with the contents of the nominated line (lines start at
0). The buffer is not terminated by a 0 character. It is up to you to make sure that the buffer
is long enough for the text, use . The returned value is the
number of characters copied to the buffer. The returned text includes any end of line
characters. If you ask for a line number outside the range of lines in the document, 0
characters are copied. If the text argument is 0 then the length that should be allocated
to store the entire line is returned.
See also: , , , ,
SCI_REPLACESEL(<unused>, const char *text)
The currently selected text between the anchor
and the current position is replaced by the 0 terminated text string. If the anchor and
current position are the same, the text is inserted at the caret position. The caret is
positioned after the inserted text and the caret is scrolled into view.
SCI_SETREADONLY(bool readOnly)
SCI_GETREADONLY
These messages set and get the read-only flag for the document. If you mark a document as read
only, attempts to modify the text cause the notification.
SCI_GETTEXTRANGE(<unused>, TextRange *tr)
This collects the text between the positions cpMin and cpMax and
copies it to lpstrText (see struct TextRange in
Scintilla.h). If cpMax is -1, text is returned to the end of the
document. The text is 0 terminated, so you must supply a buffer that is at least 1 character
longer than the number of characters you wish to read. The return value is the length of the
returned text not including the terminating 0.
See also: , , , ,
SCI_GETSTYLEDTEXT(<unused>, TextRange *tr)
This collects 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 cpMin and cpMax are copied to lpstrText (see
struct TextRange in Scintilla.h). Two 0 bytes are added to the end of
the text, so the buffer that lpstrText points at must be at least
2*(cpMax-cpMin)+2 bytes long. No check is made for sensible values of
cpMin or cpMax. Positions outside the document return character codes
and style bytes of 0.
See also: , , , ,
SCI_ALLOCATE(int bytes, <unused>)
Allocate a document buffer large enough to store a given number of bytes.
The document will not be made smaller than its current contents.
SCI_ADDTEXT(int length, const char *s)
This inserts the first length characters from the string s
at the current position. This will include any 0's in the string that you might have expected
to stop the insert operation. The current position is set at the end of the inserted text,
but it is not scrolled into view.
SCI_ADDSTYLEDTEXT(int length, cell *s)
This behaves just like SCI_ADDTEXT, but inserts styled text.
SCI_APPENDTEXT(int length, const char *s)
This adds the first length characters from the string s to the end
of the document. This will include any 0's in the string that you might have expected to stop
the operation. The current selection is not changed and the new text is not scrolled into
view.
SCI_INSERTTEXT(int pos, const char *text)
This inserts the zero terminated text string at position pos or at
the current position if pos is -1. If the current position is after the insertion point
then it is moved along with its surrounding text but no scrolling is performed.
SCI_CLEARALL
Unless the document is read-only, this deletes all the text.
SCI_CLEARDOCUMENTSTYLE
When wanting to completely restyle the document, for example after choosing a lexer, the
SCI_CLEARDOCUMENTSTYLE can be used to clear all styling information and reset the
folding state.
SCI_GETCHARAT(int pos)
This returns the character at pos in the document or 0 if pos is
negative or past the end of the document.
SCI_GETSTYLEAT(int pos)
This returns the style at pos in the document, or 0 if pos is
negative or past the end of the document.
SCI_SETSTYLEBITS(int bits)
SCI_GETSTYLEBITS
This pair of routines 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 standard
setting is SCI_SETSTYLEBITS(5).
The number of styling bits needed by the current lexer can be found with
.
TextRange and CharacterRange
These structures are defined to be exactly the same shape as the Win32 TEXTRANGE
and CHARRANGE, so that older code that treats Scintilla as a RichEdit will
work.
struct CharacterRange {
long cpMin;
long cpMax;
};
struct TextRange {
struct CharacterRange chrg;
char *lpstrText;
};
SCI_TARGETASUTF8(<unused>, char *s)
This method retrieves the value of the target encoded as UTF-8 which is the default
encoding of GTK+ so is useful for retrieving text for use in other parts of the user interface,
such as find and replace dialogs. The length of the encoded text in bytes is returned.
SCI_ENCODEDFROMUTF8(const char *utf8, char *encoded)
SCI_SETLENGTHFORENCODE(int bytes)
SCI_ENCODEDFROMUTF8 converts a UTF-8 string into the document's
encoding which is useful for taking the results of a find dialog, for example, and receiving
a string of bytes that can be searched for in the document. Since the text can contain nul bytes,
the SCI_SETLENGTHFORENCODE method can be used to set the
length that will be converted. If set to -1, the length is determined by finding a nul byte.
The length of the converted string is returned.
There are methods to search for text and for regular expressions. The regular expression support is limited and should only be used for simple cases and initial development.
SCI_FINDTEXT(int flags, TextToFind
*ttf)
SCI_SEARCHANCHOR
SCI_SEARCHNEXT(int searchFlags, const char
*text)
SCI_SEARCHPREV(int searchFlags, const char
*text)
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:
SCFIND_MATCHCASE |
A match only occurs with text that matches the case of the search string. |
SCFIND_WHOLEWORD |
A match only occurs if the characters before and after are not word characters. |
SCFIND_WORDSTART |
A match only occurs if the character before is not a word character. |
SCFIND_REGEXP |
The search string should be interpreted as a regular expression. |
SCFIND_POSIX |
Treat regular expression in a more POSIX compatible manner by interpreting bare ( and ) for tagged sections rather than \( and \). |
If SCFIND_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 SCFIND_REGEXP is included, searches are always
from a lower position to a higher position, even if the search range is backwards.
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. |
SCI_FINDTEXT(int searchFlags, TextToFind *ttf)
This message searches for text in the document. It does not use or move the current selection.
The searchFlags argument controls the
search type, which includes regular expression searches.
The TextToFind structure is defined in Scintilla.h; set
chrg.cpMin and chrg.cpMax with the range of positions in the document
to search. If SCFIND_REGEXP is not included in the flags, you can search backwards by
setting chrg.cpMax less than chrg.cpMin. If SCFIND_REGEXP
is included, the search is always forwards (even if chrg.cpMax is less than chrg.cpMin).
Set the lpstrText member of TextToFind to point at a zero terminated
text string holding the search pattern. If your language makes the use of TextToFind
difficult, you should consider using SCI_SEARCHINTARGET instead.
The return value is -1 if the search fails or the position of the start of the found text if
it succeeds. The chrgText.cpMin and chrgText.cpMax members of
TextToFind are filled in with the start and end positions of the found text.
See also:
TextToFind
This structure is defined to have exactly the same shape as the Win32 structure
FINDTEXTEX for old code that treated Scintilla as a RichEdit control.
struct TextToFind {
struct CharacterRange chrg; // range to search
char *lpstrText; // the search pattern (zero terminated)
struct CharacterRange chrgText; // returned as position of matching text
};
SCI_SEARCHANCHOR
SCI_SEARCHNEXT(int searchFlags, const char *text)
SCI_SEARCHPREV(int searchFlags, const char *text)
These messages 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. These three messages send notifications if macro recording is enabled.
SCI_SEARCHANCHOR sets the search start point used by
SCI_SEARCHNEXT and SCI_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 SCI_SEARCHNEXT or
SCI_SEARCHPREV.
SCI_SEARCHNEXT and SCI_SEARCHPREV search for the next and previous
occurrence of the zero terminated search string pointed at by text. The search is modified by
the searchFlags. If you request a regular
expression, SCI_SEARCHPREV finds the first occurrence of the search string in the
document, not the previous one before the anchor point.
The return value is -1 if nothing is found, otherwise the return value is the start position of the matching text. The selection is updated to show the matched text, but is not scrolled into view.
See also: ,
Using ,
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, ie. the range to be replaced. Then call
SCI_REPLACETARGET or SCI_REPLACETARGETRE.
Searching can be performed within the target range with SCI_SEARCHINTARGET,
which uses a counted string to allow searching for null characters. It returns the length of
range or -1 for failure, in which case the target is not moved. The flags used by
SCI_SEARCHINTARGET such as SCFIND_MATCHCASE,
SCFIND_WHOLEWORD, SCFIND_WORDSTART, and SCFIND_REGEXP
can be set with SCI_SETSEARCHFLAGS. SCI_SEARCHINTARGET may be simpler
for some clients to use than , as that requires using a pointer to a
structure.
SCI_SETTARGETSTART(int pos)
SCI_GETTARGETSTART
SCI_SETTARGETEND(int pos)
SCI_GETTARGETEND
SCI_TARGETFROMSELECTION
SCI_SETSEARCHFLAGS(int searchFlags)
SCI_GETSEARCHFLAGS
SCI_SEARCHINTARGET(int length, const char
*text)
SCI_REPLACETARGET(int length, const char
*text)
SCI_REPLACETARGETRE(int length, const char
*text)
SCI_SETTARGETSTART(int pos)
SCI_GETTARGETSTART
SCI_SETTARGETEND(int pos)
SCI_GETTARGETEND
These functions set and return the start and end of the target. When searching in non-regular
expression mode, you can set start greater than end to find the last matching text in the
target rather than the first matching text. The target is also set by a successful
SCI_SEARCHINTARGET.
SCI_TARGETFROMSELECTION
Set the target start and end to the start and end positions of the selection.
SCI_SETSEARCHFLAGS(int searchFlags)
SCI_GETSEARCHFLAGS
These get and set the searchFlags used by
SCI_SEARCHINTARGET. There are several option flags including a simple regular
expression search.
SCI_SEARCHINTARGET(int length, const char *text)
This searches for the first occurrence of a text string in the target defined by
SCI_SETTARGETSTART and SCI_SETTARGETEND. The text string is not zero
terminated; the size is set by length. The search is modified by the search flags
set by SCI_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 -1.
SCI_REPLACETARGET(int length, const char *text)
If length is -1, text is a zero terminated string, otherwise
length sets the number of character to replace the target with.
After replacement, the target range refers to the replacement text.
The return value
is the length of the replacement string.
Note that the recommended way to delete text in the document is to set the target to the text to be removed,
and to perform a replace target with an empty string.
SCI_REPLACETARGETRE(int length, const char *text)
This replaces the target using regular expressions. If length is -1,
text is a zero terminated string, otherwise length is the number of
characters to use. 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.
After replacement, the target range refers to the replacement text.
The return value is the length of the replacement string.
See also:
SCI_SETOVERTYPE(bool overType)
SCI_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.
SCI_GETOVERTYPE returns TRUE (1) if overtyping is active, otherwise
FALSE (0) will be returned. Use SCI_SETOVERTYPE to set the overtype
mode.
SCI_CUT
SCI_COPY
SCI_PASTE
SCI_CLEAR
SCI_CANPASTE
SCI_COPYRANGE(int start, int end)
SCI_COPYTEXT(int length,
const char *text)
SCI_COPYALLOWLINE
SCI_SETPASTECONVERTENDINGS(bool convert)
SCI_GETPASTECONVERTENDINGS
SCI_CUT
SCI_COPY
SCI_PASTE
SCI_CLEAR
SCI_CANPASTE
SCI_COPYALLOWLINE
These commands perform the standard tasks of cutting and copying data to the clipboard,
pasting from the clipboard into the document, and clearing the document.
SCI_CANPASTE returns non-zero 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
SCI_GETSELECTIONSTART()-SCI_GETSELECTIONEND(), which will be non-zero if you can
copy or cut to the clipboard.
GTK+ does not really support SCI_CANPASTE and always returns TRUE
unless the document is read-only.
On X, the clipboard is asynchronous and may require several messages between the destination and source applications. Data from SCI_PASTE will not arrive in the document immediately.
SCI_COPYALLOWLINE works the same as SCI_COPY except that if the
selection is empty then the current line is copied. On Windows, an extra "MSDEVLineSelect" marker
is added to the clipboard which is then used in SCI_PASTE to paste
the whole line before the current line.
SCI_COPYRANGE copies a range of text from the document to
the system clipboard and SCI_COPYTEXT copies a supplied piece of
text to the system clipboard.
SCI_SETPASTECONVERTENDINGS(bool convert)
SCI_GETPASTECONVERTENDINGS
If this property is set then when text is pasted any line ends are converted to match the document's
end of line mode as set with
.
Currently only changeable on Windows. On GTK+ pasted text is always converted.
SCI_SETSTATUS(int status)
SCI_GETSTATUS
If an error occurs, Scintilla may set an internal error number that can be retrieved with
SCI_GETSTATUS. Not currently used but will be in the future. To clear the error
status call SCI_SETSTATUS(0).
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 transactions to make it easier to undo and redo at a sensible
level of detail. Sequences of actions can be combined into transactions that are undone as a unit.
These sequences occur between SCI_BEGINUNDOACTION and
SCI_ENDUNDOACTION messages. These transactions can be nested and only the top-level
sequences are undone as units.
SCI_UNDO
SCI_CANUNDO
SCI_EMPTYUNDOBUFFER
SCI_REDO
SCI_CANREDO
SCI_SETUNDOCOLLECTION(bool
collectUndo)
SCI_GETUNDOCOLLECTION
SCI_BEGINUNDOACTION
SCI_ENDUNDOACTION
SCI_UNDO
SCI_CANUNDO
SCI_UNDO undoes one action, or if the undo buffer has reached a
SCI_ENDUNDOACTION point, all the actions back to the corresponding
SCI_BEGINUNDOACTION.
SCI_CANUNDO returns 0 if there is nothing to undo, and 1 if there is. You would
typically use the result of this message to enable/disable the Edit menu Undo command.
SCI_REDO
SCI_CANREDO
SCI_REDO undoes the effect of the last SCI_UNDO operation.
SCI_CANREDO returns 0 if there is no action to redo and 1 if there are undo
actions to redo. You could typically use the result of this message to enable/disable the Edit
menu Redo command.
SCI_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 notification to be sent to the
container.
See also:
SCI_SETUNDOCOLLECTION(bool collectUndo)
SCI_GETUNDOCOLLECTION
You can control whether Scintilla collects undo information with
SCI_SETUNDOCOLLECTION. Pass in true (1) to collect information and
false (0) to stop collecting. If you stop collection, you should also use
SCI_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.
SCI_BEGINUNDOACTION
SCI_ENDUNDOACTION
Send these two messages to Scintilla to 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.
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). If you use messages, 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.
SCI_GETTEXTLENGTH
SCI_GETLENGTH
SCI_GETLINECOUNT
SCI_GETFIRSTVISIBLELINE
SCI_LINESONSCREEN
SCI_GETMODIFY
SCI_SETSEL(int anchorPos, int currentPos)
SCI_GOTOPOS(int position)
SCI_GOTOLINE(int line)
SCI_SETCURRENTPOS(int position)
SCI_GETCURRENTPOS
SCI_SETANCHOR(int position)
SCI_GETANCHOR
SCI_SETSELECTIONSTART(int position)
SCI_GETSELECTIONSTART
SCI_SETSELECTIONEND(int position)
SCI_GETSELECTIONEND
SCI_SELECTALL
SCI_LINEFROMPOSITION(int position)
SCI_POSITIONFROMLINE(int line)
SCI_GETLINEENDPOSITION(int line)
SCI_LINELENGTH(int line)
SCI_GETCOLUMN(int position)
SCI_FINDCOLUMN(int line, int column)
SCI_POSITIONFROMPOINT(int x, int y)
SCI_POSITIONFROMPOINTCLOSE(int x, int
y)
SCI_POINTXFROMPOSITION(<unused>, int
position)
SCI_POINTYFROMPOSITION(<unused>, int
position)
SCI_HIDESELECTION(bool hide)
SCI_GETSELTEXT(<unused>, char *text)
SCI_GETCURLINE(int textLen, char *text)
SCI_SELECTIONISRECTANGLE
SCI_SETSELECTIONMODE(int mode)
SCI_GETSELECTIONMODE
SCI_GETLINESELSTARTPOSITION(int line)
SCI_GETLINESELENDPOSITION(int line)
SCI_MOVECARETINSIDEVIEW
SCI_WORDENDPOSITION(int position, bool
onlyWordCharacters)
SCI_WORDSTARTPOSITION(int position, bool
onlyWordCharacters)
SCI_POSITIONBEFORE(int position)
SCI_POSITIONAFTER(int position)
SCI_TEXTWIDTH(int styleNumber, const char *text)
SCI_TEXTHEIGHT(int line)
SCI_CHOOSECARETX
SCI_GETTEXTLENGTH
SCI_GETLENGTH
Both these messages return the length of the document in characters.
SCI_GETLINECOUNT
This 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.
SCI_GETFIRSTVISIBLELINE
This returns the line number of the first visible line in the Scintilla view. The first line
in the document is numbered 0. The value is a visible line rather than a document line.
SCI_LINESONSCREEN
This 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.
SCI_GETMODIFY
This returns non-zero if the document is modified and 0 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 ,
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 and notification messages.
SCI_SETSEL(int anchorPos, int currentPos)
This message sets both the anchor and the current position. If currentPos is
negative, it means the end of the document. If anchorPos 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.
SCI_GOTOPOS(int pos)
This removes any selection, sets the caret at pos and scrolls the view to make
the caret visible, if necessary. It is equivalent to
SCI_SETSEL(pos, pos). The anchor position is set the same as the current
position.
SCI_GOTOLINE(int line)
This removes any selection and sets the caret at the start of line number line
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.
SCI_SETCURRENTPOS(int pos)
This sets the current position and creates a selection between the anchor and the current
position. The caret is not scrolled into view.
See also:
SCI_GETCURRENTPOS
This returns the current position.
SCI_SETANCHOR(int pos)
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:
SCI_GETANCHOR
This returns the current anchor position.
SCI_SETSELECTIONSTART(int pos)
SCI_SETSELECTIONEND(int pos)
These 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 these messages.
| anchor | current | |
|---|---|---|
SCI_SETSELECTIONSTART |
pos |
Max(pos, current) |
SCI_SETSELECTIONEND |
Min(anchor, pos) |
pos |
See also:
SCI_GETSELECTIONSTART
SCI_GETSELECTIONEND
These return the start and end of the selection without regard to which end is the current
position and which is the anchor. SCI_GETSELECTIONSTART returns the smaller of the
current position or the anchor position. SCI_GETSELECTIONEND returns the larger of
the two values.
SCI_SELECTALL
This selects all the text in the document. The current position is not scrolled into view.
SCI_LINEFROMPOSITION(int pos)
This message 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.
SCI_POSITIONFROMLINE(int line)
This 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
-1. 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.
SCI_GETLINEENDPOSITION(int line)
This returns the position at the end of the line, before any line end characters. 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 or line >= , the result is undefined.
SCI_LINELENGTH(int line)
This 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 - .
text
buffer. The buffer must be at least
SCI_GETSELECTIONEND()-SCI_GETSELECTIONSTART()+1 bytes long. See also: , , , ,
SCI_GETCURLINE(int textLen, char *text)
This retrieves the text of the line containing the caret and returns the position within the
line of the caret. Pass in char* text pointing at a buffer large enough to hold
the text you wish to retrieve and a terminating 0 character.
Set textLen to the
length of the buffer which must be at least 1 to hold the terminating 0 character.
If the text argument is 0 then the length that should be allocated
to store the entire current line is returned.
See also: , , , ,
SCI_SELECTIONISRECTANGLE
This returns 1 if the current selection is in rectangle mode, 0 if not.
SCI_SETSELECTIONMODE(int mode)
SCI_GETSELECTIONMODE
The two functions set and get the selection mode, which can be
stream (SC_SEL_STREAM=0) or
rectangular (SC_SEL_RECTANGLE=1)
or by lines (SC_SEL_LINES=2).
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 SCI_CANCEL.
The get function returns the current mode even if the selection was made by mouse
or with regular extended moves.
SCI_GETLINESELSTARTPOSITION(int line)
SCI_GETLINESELENDPOSITION(int line)
Retrieve the position of the start and end of the selection at the given line with
INVALID_POSITION returned if no selection on this line.
SCI_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.
SCI_WORDENDPOSITION(int position, bool
onlyWordCharacters)
SCI_WORDSTARTPOSITION(int position, bool
onlyWordCharacters)
These messages 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
. 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 (1) to stop searching at the first
non-word character in the search direction. If onlyWordCharacters is
false (0), 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.. |
SCI_POSITIONBEFORE(int position)
SCI_POSITIONAFTER(int position)
These messages return 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.
SCI_TEXTWIDTH(int styleNumber, const char *text)
This 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.
SCI_TEXTHEIGHT(int line)
This returns the height in pixels of a particular line. Currently all lines are the same
height.
SCI_GETCOLUMN(int pos)
This message 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.
SCI_FINDCOLUMN(int line, int column)
This message 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.
SCI_POSITIONFROMPOINT(int x, int y)
SCI_POSITIONFROMPOINTCLOSE(int x, int y)
SCI_POSITIONFROMPOINT finds the closest character position to a point and
SCI_POSITIONFROMPOINTCLOSE is similar but returns -1 if the point is outside the
window or not close to any characters.
SCI_POINTXFROMPOSITION(<unused>, int pos)
SCI_POINTYFROMPOSITION(<unused>, int pos)
These messages return the x and y display pixel location of text at position pos
in the document.
SCI_HIDESELECTION(bool hide)
The normal state is to make the selection visible by drawing it as set by and . However, if you hide the selection, it
is drawn as normal text.
SCI_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.
This message sets the current x position of the caret as the remembered value.
SCI_LINESCROLL(int column, int line)
SCI_SCROLLCARET
SCI_SETXCARETPOLICY(int caretPolicy, int
caretSlop)
SCI_SETYCARETPOLICY(int caretPolicy, int
caretSlop)
SCI_SETVISIBLEPOLICY(int caretPolicy, int
caretSlop)
SCI_SETHSCROLLBAR(bool visible)
SCI_GETHSCROLLBAR
SCI_SETVSCROLLBAR(bool visible)
SCI_GETVSCROLLBAR
SCI_GETXOFFSET
SCI_SETXOFFSET(int xOffset)
SCI_SETSCROLLWIDTH(int pixelWidth)
SCI_GETSCROLLWIDTH
SCI_SETSCROLLWIDTHTRACKING(bool tracking)
SCI_GETSCROLLWIDTHTRACKING
SCI_SETENDATLASTLINE(bool
endAtLastLine)
SCI_GETENDATLASTLINE
SCI_LINESCROLL(int column, int line)
This will attempt 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:
SCI_SCROLLCARET
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.
SCI_SETXCARETPOLICY(int caretPolicy, int caretSlop)
SCI_SETYCARETPOLICY(int caretPolicy, int caretSlop)
These set the caret policy. The value of caretPolicy is a combination of
CARET_SLOP, CARET_STRICT, CARET_JUMPS and
CARET_EVEN.
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. |
|---|---|
CARET_STRICT |
If set, the policy set by CARET_SLOP is enforced... strictly. The caret
is centred on the display if caretSlop is not set, and cannot go in the UZ
if caretSlop is set. |
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. |
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 reside, 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 | centred on the caret |
| 0 | 1 | - | 0 | Caret is always on top/on right of display | - |
| 0 | 1 | - | 1 | No, caret is always centred | - |
| 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 |
SCI_SETVISIBLEPOLICY(int caretPolicy, int caretSlop)
This determines how the vertical positioning is determined when is
called. It takes VISIBLE_SLOP and VISIBLE_STRICT flags for the policy
parameter. It is similar in operation to .
SCI_SETHSCROLLBAR(bool visible)
SCI_GETHSCROLLBAR
The horizontal scroll bar is only displayed if it is needed for the assumed width.
If you never wish to see it, call
SCI_SETHSCROLLBAR(0). Use SCI_SETHSCROLLBAR(1) to enable it again.
SCI_GETHSCROLLBAR returns the current state. The default state is to display it
when needed.
See also: .
SCI_SETVSCROLLBAR(bool visible)
SCI_GETVSCROLLBAR
By default, the vertical scroll bar is always displayed when required. You can choose to hide
or show it with SCI_SETVSCROLLBAR and get the current state with
SCI_GETVSCROLLBAR.
SCI_SETXOFFSET(int xOffset)
SCI_GETXOFFSET
The xOffset 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:
SCI_SETSCROLLWIDTH(int pixelWidth)
SCI_GETSCROLLWIDTH
For performance, Scintilla does not measure the display width of the document to determine
the properties of the horizontal scroll bar. Instead, an assumed width is used.
These messages set and get the document width in pixels assumed by Scintilla.
The default value is 2000.
To ensure the width of the currently visible lines can be scrolled use
SCI_SETSCROLLWIDTHTRACKING(bool tracking)
SCI_GETSCROLLWIDTHTRACKING
If scroll width tracking is enabled then the scroll width is adjusted to ensure that all of the lines currently
displayed can be completely scrolled. This mode never adjusts the scroll width to be narrower.
SCI_SETENDATLASTLINE(bool endAtLastLine)
SCI_GETENDATLASTLINE
SCI_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.
SCI_SETVIEWWS(int wsMode)
SCI_GETVIEWWS
SCI_SETWHITESPACEFORE(bool
useWhitespaceForeColour, int colour)
SCI_SETWHITESPACEBACK(bool
useWhitespaceBackColour, int colour)
SCI_SETVIEWWS(int wsMode)
SCI_GETVIEWWS
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 centred dots and tab characters
as light arrows pointing to the right. There are also ways to control the display of end of line characters. The two messages set and get the
white space display mode. The wsMode argument can be one of:
SCWS_INVISIBLE |
0 | The normal display mode with white space displayed as an empty background colour. |
|---|---|---|
SCWS_VISIBLEALWAYS |
1 | White space characters are drawn as dots and arrows, |
SCWS_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.
SCI_SETWHITESPACEFORE<(bool useWhitespaceForeColour, int colour)
SCI_SETWHITESPACEBACK(bool useWhitespaceBackColour, int colour)
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 SCI_SETWHITESPACEFORE and
SCI_SETWHITESPACEBACK.
SCI_SETCURSOR(int curType)
SCI_GETCURSOR
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 SCI_SETCURSOR. The curType
argument can be:
SC_CURSORNORMAL |
-1 | The normal cursor is displayed. |
|---|---|---|
SC_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 SC_CURSORWAIT is
usefully controllable. Other values of curType cause a pointer to be displayed.
The SCI_GETCURSOR message returns the last cursor type you set, or
SC_CURSORNORMAL (-1) if you have not set a cursor type.
SCI_SETMOUSEDOWNCAPTURES(bool captures)
SCI_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
SCI_SETMOUSEDOWNCAPTURES(0).
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 SCI_SETEOLMODE message. You can also convert the
entire document to one of these line endings with SCI_CONVERTEOLS. Finally, you
can choose to display the line endings with SCI_SETVIEWEOL.
SCI_SETEOLMODE(int eolMode)
SCI_GETEOLMODE
SCI_CONVERTEOLS(int eolMode)
SCI_SETVIEWEOL(bool visible)
SCI_GETVIEWEOL
SCI_SETEOLMODE(int eolMode)
SCI_GETEOLMODE
SCI_SETEOLMODE sets the characters that are added into the document when the user
presses the Enter key. You can set eolMode to one of SC_EOL_CRLF (0),
SC_EOL_CR (1), or SC_EOL_LF (2). The SCI_GETEOLMODE
message retrieves the current state.
SCI_CONVERTEOLS(int eolMode)
This message changes all the end of line characters in the document to match
eolMode. Valid values are: SC_EOL_CRLF (0), SC_EOL_CR
(1), or SC_EOL_LF (2).
SCI_SETVIEWEOL(bool visible)
SCI_GETVIEWEOL
Normally, the end of line characters are hidden, but SCI_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). SCI_GETVIEWEOL
returns the current state.
The styling messages 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 . 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 command to select
SCLEX_CONTAINER, in which case the container is sent a 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.
SCI_GETENDSTYLED
SCI_STARTSTYLING(int position, int mask)
SCI_SETSTYLING(int length, int style)
SCI_SETSTYLINGEX(int length, const char
*styles)
SCI_SETLINESTATE(int line, int value)
SCI_GETLINESTATE(int line)
SCI_GETMAXLINESTATE
SCI_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 notification message is sent to the
container. The container can send SCI_GETENDSTYLED to work out where it needs to
start styling. Scintilla will always ask to style whole lines.
SCI_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
SCI_STARTSTYLING, send multiple SCI_SETSTYLING messages for each
lexical entity to style.
SCI_SETSTYLING(int length, int style)
This message 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);
SCI_SETSTYLINGEX(int length, const char *styles)
As an alternative to SCI_SETSTYLING, which applies the same style to each byte,
you can use this message 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.
SCI_SETLINESTATE(int line, int value)
SCI_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 SCI_SETLINESTATE to set the integer
value and SCI_GETLINESTATE to get the value.
Changing the value produces a notification.
SCI_GETMAXLINESTATE
This returns the last line that has any line state.
While the style setting messages mentioned above change the style numbers associated with
text, these messages 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 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 STYLE_* constants are
defined.
STYLE_DEFAULT |
32 | This style defines the attributes that all styles receive when the
SCI_STYLECLEARALL message is used. |
|---|---|---|
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 & SC_MASK_FOLDERS is 0. See for more about masks. |
STYLE_BRACELIGHT |
34 | This style sets the attributes used when highlighting braces with the message and when highlighting the corresponding indentation with . |
STYLE_BRACEBAD |
35 | This style sets the display attributes used when marking an unmatched brace with the message. |
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: . |
STYLE_INDENTGUIDE |
37 | This style sets the foreground and background colours used when drawing the indentation guides. |
STYLE_CALLTIP |
38 | Call tips normally use the font attributes defined by STYLE_DEFAULT.
Use of
causes call tips to use this style instead. Only the font face name, font size,
foreground and background colours and character set attributes are used. |
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 38, which reserves space for one future predefined style. |
STYLE_MAX |
127 | This is not a style but is the number of the maximum style that can be set. Styles
between STYLE_LASTPREDEFINED and STYLE_MAX would be appropriate
if you used
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.
SCI_STYLERESETDEFAULT
SCI_STYLECLEARALL
SCI_STYLESETFONT(int styleNumber, char
*fontName)
SCI_STYLEGETFONT(int styleNumber, char *fontName)
SCI_STYLESETSIZE(int styleNumber, int
sizeInPoints)
SCI_STYLEGETSIZE(int styleNumber)
SCI_STYLESETBOLD(int styleNumber, bool
bold)
SCI_STYLEGETBOLD(int styleNumber)
SCI_STYLESETITALIC(int styleNumber, bool
italic)
SCI_STYLEGETITALIC(int styleNumber)
SCI_STYLESETUNDERLINE(int styleNumber, bool
underline)
SCI_STYLEGETUNDERLINE(int styleNumber)
SCI_STYLESETFORE(int styleNumber, int
colour)
SCI_STYLEGETFORE(int styleNumber)
SCI_STYLESETBACK(int styleNumber, int
colour)
SCI_STYLESETBACK(int styleNumber)
SCI_STYLESETEOLFILLED(int styleNumber, bool
eolFilled)
SCI_STYLEGETEOLFILLED(int styleNumber)
SCI_STYLESETCHARACTERSET(int styleNumber,
int charSet)
SCI_STYLEGETCHARACTERSET(int styleNumber)
SCI_STYLESETCASE(int styleNumber, int
caseMode)
SCI_STYLEGETCASE(int styleNumber)
SCI_STYLESETVISIBLE(int styleNumber, bool
visible)
SCI_STYLEGETVISIBLE(int styleNumber)
SCI_STYLESETCHANGEABLE(int styleNumber, bool
changeable)
SCI_STYLEGETCHANGEABLE(int styleNumber)
SCI_STYLESETHOTSPOT(int styleNumber, bool
hotspot)
SCI_STYLEGETHOTSPOT(int styleNumber)
SCI_STYLERESETDEFAULT
This message resets STYLE_DEFAULT to its state when Scintilla was
initialised.
SCI_STYLECLEARALL
This message sets all styles to have the same attributes as 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 STYLE_DEFAULT to the common features of all styles.
2. Use SCI_STYLECLEARALL to copy this to all styles.
3. Set the style attributes that make your lexical styles different.
SCI_STYLESETFONT(int styleNumber, const char *fontName)
SCI_STYLEGETFONT(int styleNumber, char *fontName)
SCI_STYLESETSIZE(int styleNumber, int sizeInPoints)
SCI_STYLEGETSIZE(int styleNumber)
SCI_STYLESETBOLD(int styleNumber, bool bold)
SCI_STYLEGETBOLD(int styleNumber)
SCI_STYLESETITALIC(int styleNumber, bool italic)
SCI_STYLEGETITALIC(int styleNumber)
These messages (plus ) 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, works well with Unicode and is better supported in recent versions of GTK+
but GDK is faster.
Prepend a '!' character to the font name to use Pango.
SCI_STYLESETUNDERLINE(int styleNumber, bool
underline)
SCI_STYLEGETUNDERLINE(int styleNumber)
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.
SCI_STYLESETFORE(int styleNumber, int colour)
SCI_STYLEGETFORE(int styleNumber)
SCI_STYLESETBACK(int styleNumber, int colour)
SCI_STYLEGETBACK(int styleNumber)
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.
SCI_STYLESETEOLFILLED(int styleNumber, bool
eolFilled)
SCI_STYLEGETEOLFILLED(int styleNumber)
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 eolFilled 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.
SCI_STYLESETCHARACTERSET(int styleNumber, int
charSet)
SCI_STYLEGETCHARACTERSET(int styleNumber)
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,
SCI_STYLESETCHARACTERSET(SCE_C_STRING, SC_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 works differently on Windows and GTK+.
The character sets supported on Windows are:
SC_CHARSET_ANSI, SC_CHARSET_ARABIC, SC_CHARSET_BALTIC,
SC_CHARSET_CHINESEBIG5, SC_CHARSET_DEFAULT,
SC_CHARSET_EASTEUROPE, SC_CHARSET_GB2312,
SC_CHARSET_GREEK, SC_CHARSET_HANGUL, SC_CHARSET_HEBREW,
SC_CHARSET_JOHAB, SC_CHARSET_MAC, SC_CHARSET_OEM,
SC_CHARSET_RUSSIAN (code page 1251),
SC_CHARSET_SHIFTJIS, SC_CHARSET_SYMBOL, SC_CHARSET_THAI,
SC_CHARSET_TURKISH, and SC_CHARSET_VIETNAMESE.
The character sets supported on GTK+ are:
SC_CHARSET_ANSI, SC_CHARSET_CYRILLIC (code page 1251),
SC_CHARSET_EASTEUROPE,
SC_CHARSET_GB2312, SC_CHARSET_HANGUL,
SC_CHARSET_RUSSIAN (KOI8-R), SC_CHARSET_SHIFTJIS, and
SC_CHARSET_8859_15.
SCI_STYLESETCASE(int styleNumber, int caseMode)
SCI_STYLEGETCASE(int styleNumber)
The value of caseMode determines how text is displayed. You can set upper case
(SC_CASE_UPPER, 1) or lower case (SC_CASE_LOWER, 2) or display
normally (SC_CASE_MIXED, 0). This does not change the stored text, only how it is
displayed.
SCI_STYLESETVISIBLE(int styleNumber, bool visible)
SCI_STYLEGETVISIBLE(int styleNumber)
Text is normally visible. However, you can completely hide it by giving it a style with the
visible set to 0. This could be used to hide embedded formatting instructions or
hypertext keywords in HTML or XML.
SCI_STYLESETCHANGEABLE(int styleNumber, bool
changeable)
SCI_STYLEGETCHANGEABLE(int styleNumber)
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.
SCI_STYLESETHOTSPOT(int styleNumber, bool
hotspot)
SCI_STYLEGETHOTSPOT(int styleNumber)
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.
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.
SCI_SETSELFORE(bool useSelectionForeColour,
int colour)
SCI_SETSELBACK(bool useSelectionBackColour,
int colour)
SCI_SETSELALPHA(int alpha)
SCI_GETSELALPHA
SCI_SETSELEOLFILLED(bool filled)
SCI_GETSELEOLFILLED
SCI_SETCARETFORE(int colour)
SCI_GETCARETFORE
SCI_SETCARETLINEVISIBLE(bool
show)
SCI_GETCARETLINEVISIBLE
SCI_SETCARETLINEBACK(int colour)
SCI_GETCARETLINEBACK
SCI_SETCARETLINEBACKALPHA(int alpha)
SCI_GETCARETLINEBACKALPHA
SCI_SETCARETPERIOD(int milliseconds)
SCI_GETCARETPERIOD
SCI_SETCARETSTYLE(int style)
SCI_GETCARETSTYLE
SCI_SETCARETWIDTH(int pixels)
SCI_GETCARETWIDTH
SCI_SETHOTSPOTACTIVEFORE(bool useSetting,
int colour)
SCI_GETHOTSPOTACTIVEFORE
SCI_SETHOTSPOTACTIVEBACK(bool useSetting,
int colour)
SCI_GETHOTSPOTACTIVEBACK
SCI_SETHOTSPOTACTIVEUNDERLINE(bool underline)
SCI_GETHOTSPOTACTIVEUNDERLINE
SCI_SETHOTSPOTSINGLELINE(bool singleLine)
SCI_GETHOTSPOTSINGLELINE
SCI_SETCONTROLCHARSYMBOL(int
symbol)
SCI_GETCONTROLCHARSYMBOL
SCI_SETCARETSTICKY(bool useCaretStickyBehaviour)
SCI_GETCARETSTICKY
SCI_TOGGLECARETSTICKY
SCI_SETSELFORE(bool useSelectionForeColour, int colour)
SCI_SETSELBACK(bool useSelectionBackColour, int colour)
You can choose to override the default selection colouring with these two messages. The colour
you provide is used if you set useSelection*Colour to true. If it is
set to false, the default styled colouring is used and the colour
argument has no effect.
SCI_SETSELALPHA(int alpha)
SCI_GETSELALPHA
The selection can be drawn translucently in the selection background colour by
setting an alpha value.
SCI_SETSELEOLFILLED(bool filled)
SCI_GETSELEOLFILLED
The selection can be drawn up to the right hand border by setting this property.
SCI_SETCARETFORE(int colour)
SCI_GETCARETFORE
The colour of the caret can be set with SCI_SETCARETFORE and retrieved with
SCI_CETCARETFORE.
SCI_SETCARETLINEVISIBLE(bool show)
SCI_GETCARETLINEVISIBLE
SCI_SETCARETLINEBACK(int colour)
SCI_GETCARETLINEBACK
SCI_SETCARETLINEBACKALPHA(int alpha)
SCI_GETCARETLINEBACKALPHA
You can choose to make the background colour of the line containing the caret different with
these messages. To do this, set the desired background colour with
SCI_SETCARETLINEBACK, then use SCI_SETCARETLINEVISIBLE(true) to
enable the effect. You can cancel the effect with SCI_SETCARETLINEVISIBLE(false).
The two SCI_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.
The caret line may also be drawn translucently which allows other background colours to show
through. This is done by setting the alpha (translucency) value by calling
SCI_SETCARETLINEBACKALPHA. When the alpha is not SC_ALPHA_NOALPHA,
the caret line is drawn after all other features so will affect the colour of all other features.
SCI_SETCARETPERIOD(int milliseconds)
SCI_GETCARETPERIOD
The rate at which the caret blinks can be set with SCI_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.
SCI_GETCARETPERIOD returns the current setting.
SCI_SETCARETSTYLE(int style)
SCI_GETCARETSTYLE
The style of the caret can be set with SCI_SETCARETSTYLE to be a line caret
(CARETSTYLE_LINE=1), a block caret (CARETSTYLE_BLOCK=2) or to not draw at all
(CARETSTYLE_INVISIBLE=0). The default value is the line caret (CARETSTYLE_LINE=1).
You can determine the current caret style setting using SCI_GETCARETSTYLE.
The block character draws most combining and multibyte character sequences successfully, though some fonts like Thai Fonts (and possibly others) can sometimes appear strange when the cursor is positioned at these characters, which may result in only drawing a part of the cursor character sequence. This is most notable on Windows platforms.
SCI_SETCARETWIDTH(int pixels)
SCI_GETCARETWIDTH
The width of the line caret can be set with SCI_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
SCI_GETCARETWIDTH. A width of 0 makes the caret invisible (added at version
1.50), similar to setting the caret style to CARETSTYLE_INVISIBLE (though not interchangable).
This setting only affects the width of the cursor when the cursor style is set to line caret
mode, it does not affect the width for a block caret.
SCI_SETHOTSPOTACTIVEFORE(bool useHotSpotForeColour, int colour)
SCI_GETHOTSPOTACTIVEFORE
SCI_SETHOTSPOTACTIVEBACK(bool useHotSpotBackColour, int colour)
SCI_GETHOTSPOTACTIVEBACK
SCI_SETHOTSPOTACTIVEUNDERLINE(bool underline)
SCI_GETHOTSPOTACTIVEUNDERLINE
SCI_SETHOTSPOTSINGLELINE(bool singleLine)
SCI_GETHOTSPOTSINGLELINE
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.
SCI_SETCONTROLCHARSYMBOL(int symbol)
SCI_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 SCI_GETCONTROLCHARSYMBOL message.
The default symbol value is 0.
SCI_SETCARETSTICKY(bool useCaretStickyBehaviour)
SCI_GETCARETSTICKY
SCI_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.
There may be up to five 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 . The markers that can be displayed in each margin are set with . 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 notification to the container or selects a line of text.
The margins are numbered 0 to 4. 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.
SCI_SETMARGINTYPEN(int margin, int
type)
SCI_GETMARGINTYPEN(int margin)
SCI_SETMARGINWIDTHN(int margin, int
pixelWidth)
SCI_GETMARGINWIDTHN(int margin)
SCI_SETMARGINMASKN(int margin, int
mask)
SCI_GETMARGINMASKN(int margin)
SCI_SETMARGINSENSITIVEN(int margin, bool
sensitive)
SCI_GETMARGINSENSITIVEN(int
margin)
SCI_SETMARGINLEFT(<unused>, int
pixels)
SCI_GETMARGINLEFT
SCI_SETMARGINRIGHT(<unused>, int
pixels)
SCI_GETMARGINRIGHT
SCI_SETFOLDMARGINCOLOUR(bool useSetting, int colour)
SCI_SETFOLDMARGINHICOLOUR(bool useSetting, int colour)
SCI_SETMARGINTYPEN(int margin, int iType)
SCI_GETMARGINTYPEN(int margin)
These two routines set and get the type of a margin. The margin argument should be 0, 1, 2, 3 or 4.
You can use the predefined constants SC_MARGIN_SYMBOL (0) and
SC_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 next two are used for symbols. You can
also use the constants SC_MARGIN_BACK (2) and SC_MARGIN_FORE (3) for
symbol margins that set their background colour to match the STYLE_DEFAULT background and
foreground colours.
SCI_SETMARGINWIDTHN(int margin, int pixelWidth)
SCI_GETMARGINWIDTHN(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 to get a
suitable width.
SCI_SETMARGINMASKN(int margin, int mask)
SCI_GETMARGINMASKN(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,
SC_MASK_FOLDERS (0xFE000000 or -33554432), 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
& SC_MASK_FOLDERS)==0, the margin background colour is controlled by style 33 ().
You add logical markers to a line with . 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 SCI_SETMARGINMASKN(1, ~SC_MASK_FOLDERS); to
set a folding margin 2 use SCI_SETMARGINMASKN(2, SC_MASK_FOLDERS). This is the
default set by Scintilla. ~SC_MASK_FOLDERS is 0x1FFFFFF in hexadecimal or 33554431
decimal. Of course, you may need to display all 32 symbols in a margin, in which case use
SCI_SETMARGINMASKN(margin, -1).
SCI_SETMARGINSENSITIVEN(int margin, bool
sensitive)
SCI_GETMARGINSENSITIVEN(int margin)
Each of the five margins can be set sensitive or insensitive to mouse clicks. A click in a
sensitive margin sends a 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.
SCI_SETMARGINLEFT(<unused>, int pixels)
SCI_GETMARGINLEFT
SCI_SETMARGINRIGHT(<unused>, int pixels)
SCI_GETMARGINRIGHT
These messages 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.
SCI_SETFOLDMARGINCOLOUR(bool useSetting, int colour)
SCI_SETFOLDMARGINHICOLOUR(bool useSetting, int colour)
These messages 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).
SCI_SETUSEPALETTE(bool
allowPaletteUse)