Date: 02-16-2022
Return to Index
created by gbSnippets
'Each character contained in the Scintilla control is assigned a style number,
'which is simply a number from 0-255 that indicates which attributes Scintilla
'will apply to the character. The following attributes can be set for each
'style number:
' -font name -character set -clickable (hotspot)
' -font size -visible/hidden status -use of bg color to EOL
' -FG color -upper/lower case
' -BG color -read-only
'For each character in the control, Scintilla maintains a byte of data that
'holds the style number. But by default, only 5 bits of the byte are used
'to store the style number, thus limiting the style number to values 0-31.
'Also by default, the other 3 bits of the style byte are used to define which
'indicators (symbols) are displayed with each character. Indicators are
'discussed in another snippet.
'The programmer can choose to allocate more bits to storing the style number,
'up to the 8 bits of the style byte. Allowing all 8 bits to be used as a style
'number would allow up to 256 style numbers (0-255).
'Programmers often find the 32 default style numbers to be adequate for their
'programming needs. However Scintilla development plans are to use all 8 bits
'of the style byte for storing a style number (256 styles) and will handle
'indicators differently (see the snippet on indicators).
'Scintilla has pre-defined the use of style numbers 32-38 for various features,
'and style 39 has been set aside for a future style. The styles 32-38 are
'used by Scintilla as follows:
' 32 - Style_Default - applied to all styles with SCI_StyleClearall
' 33 - Style_LineNumbers - applied to line number and non-folding margins
' 34 - Style_BraceLight - used to highlight matching braces
' 35 - Style_BraceBad - used to highlight unmatched braces
' 36 - Style_ControlChar - used to draw control characters (font size, BIU, char set only)
' 37 - Style_IndentGuide - sets FG/BG color of indentation guides
' 38 - Style_CallTip - optionally applied to call tips, which use Style_Default by default
'You can set attributes for these pre-defined styles, but the styles cannot
'be applied directly to text unless the default 5 bits used to store a style
'number is increased to allow for the larger style number.
'On startup Scintilla sets all styles, except STYLE_LINENUMBER, to black on white
'colors. Style_LineNumber is set to black on gray for displaying line numbers.
'Typically, the style of Scintilla text is set by a lexer but it can also be set by code
'from within the container. With lexing turned off, text that is typed in uses style 0,
'regardless of the style of text on either side of the caret where typing occurs. With
'lexing turned on, text that is typed in uses a style that is controlled by the lexer.
'If the properties of a style are changed, any text that was previously
'displayed with that style will take on the new properties of that style.
'This includes all of the style properties (FG, BG, fontname, size, ...).
'If multiple text colors have been displayed, with varying background colors,
'to set a common background for all characters you must change the background
'for all styles. You can change the background of all styles at one time
'with SCI_StyleClearAll, but this also changes the text color.
'Primary Code:
'Assign the position at which to start styling
SendMessage(hSci, %SCI_StartStyling, iPos, iMask) 'iMask=31 if not changing indicators
'Apply styling to iLen characters
SendMessage(hSci, %SCI_SetStyling, iLen, %Style_Default)
'Compilable Example: (Jose Includes)
'This snippet sets up a style with FG/BG colors of red/yellow, and applies the
'style to the entire document.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "scintilla_gb.inc"
%ID_Sci = 1000
%Style_RedYellow = 0 'any number 0-31 will do
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add "Scintilla", hDlg, %ID_Sci, "", 10,10,180,130, %WS_Child Or %WS_Visible
Control Handle hDlg, %ID_Sci To hSci 'get handle to Scintilla window
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local txt As String
txt = "Select Case var$ 'first line" + $CrLf + "End Select 'last line" + Chr$(0)
Select Case CB.Msg
Case %WM_InitDialog
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-20, Hi(Word, CB.lParam)-20
Case %WM_Destroy
If hLib Then FreeLibrary hLib 'free the Scintilla library
End Select
End Function
Sub InitializeScintilla
Local txt As String
Local iLen As Long
txt = "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + "Else" + $crlf + " x = 0" + $crlf + "End If" + Chr$(0)
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
SendMessage hSci, %SCI_StyleSetFore, %Style_RedYellow, Rgb(255,0,0)
SendMessage hSci, %SCI_StyleSetBack, %Style_RedYellow, Rgb(255,255,0)
SendMessage(hSci, %SCI_StartStyling, 0, 31)
iLen = SendMessage(hSci, %SCI_GetTextLength, 0, 0)
SendMessage(hSci, %SCI_SetStyling, iLen, %Style_Default)
End Sub
'gbs_00634
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm