Date: 02-16-2022
Return to Index
created by gbSnippets
'Scintilla supports 5 margins, 0-4. Each can be set to display line numbers
'or symbols. Setting a margin to display symbols means that the margin will
'display the symbol associated with a marker, where each margin may be set
'to display any combination of 32 markers (numbered 0-31).
'A marker has associated with it a symbol, whose FG/BG colors and alpha can
'be set. The Scintilla built-in marker symbols are:
SC_MARK_CIRCLE SC_MARK_ROUNDRECT SC_MARK_ARROW SC_MARK_SMALLRECT
SC_MARK_SHORTARROW SC_MARK_EMPTY SC_MARK_ARROWDOWN SC_MARK_MINUS
SC_MARK_PLUS SC_MARK_ARROWS SC_MARK_DOTDOTDOT SC_MARK_EMPTY
SC_MARK_BACKGROUND SC_MARK_LEFTRECT SC_MARK_FULLRECT SC_MARK_UNDERLINE
'By default, all markers are set to the SC_Mark_Circle symbol.
'There is also a set of built-in symbols used in folding margins. Those are
'covered in the snippet on source code folding.
'There are a few special markers, whose action is as follows:
SC_Mark_Background 'sets BG color of line
SC_Mark_FullRect 'sets BG color of margin
SC_Mark_Underline 'underline the text in the line
'In addition to the symbol list above, a margin may use any character from
'the current font. This is done by using the ASCII value of the character
'in a SC_MarkerDefine statement.
'An application may also supply an image, in XPM format, to use as a marker
'symbol. See the Scintilla Help documentation for more information on this option.
'Primary Code:
'The basic two steps in using markers are:
SCI_MarkerDefine 'define the symbol associated with a marker
SCI_MarkerAdd 'add a marker to a line
'Markers may also be deleted (individually or all at once), and Scintilla
'provides some ability to search for lines which have a specified marker.
'Even though a marker has been assigned a symbol and added to a line, the
'symbol will not show until the marker is assigned to a margin(s) with
'SCI_SetMarginMaskN. The following messages are commonly used to set
'which markers are to be shown in a particular margin.
SCI_SetMarginMaskN(1,-1) 'all symbols
SCI_SetMarginMaskN(1,SC_Mask_Folders) 'folding symbols only
SCI_SetMarginMaskN(1, Not SC_Mask_Folders) 'non-folding symbols only
'By default, margin 0 is set to show line numbers, margin 1 is set to show
'non-folding symbols, and margin 3 is set to show folding symbols.
'If a non-visible margin is set to show a marker, the marker will change the background
'of the line.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "scintilla_gb.inc"
%ID_Sci = 1000 : %ID_BtnA = 1001 : %ID_BtnB = 1002
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,300,460, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "PushA", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "PushB", 10,40,70,20, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %ID_Sci, "", 100,10,180,440, %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
Select Case CB.Msg
Case %WM_InitDialog
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
End Select
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-110, 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, i As Long
txt = "SC_Mark_Circle"
txt = txt + $CrLf + "SC_Mark_RoundRect"
txt = txt + $CrLf + "SC_Mark_Arrow"
txt = txt + $CrLf + "SC_Mark_SmallRect"
txt = txt + $CrLf + "SC_Mark_ShortArrow"
txt = txt + $CrLf + "SC_Mark_Empty"
txt = txt + $CrLf + "SC_Mark_ArrowDown"
txt = txt + $CrLf + "SC_Mark_Minus"
txt = txt + $CrLf + "SC_Mark_Plus"
txt = txt + $CrLf + "SC_Mark_Arrows"
txt = txt + $CrLf + "SC_Mark_DotDotDot"
txt = txt + $CrLf + "SC_Mark_BackGround"
txt = txt + $CrLf + "SC_Mark_LeftRect"
txt = txt + $CrLf + "SC_Mark_FullRect"
txt = txt + $CrLf + "SC_Mark_UnderLine"
For i = 15 To 31
txt = txt + $CrLf + Chr$(i+50) : SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
Next i
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
'make all margins isible
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 'by default, shows line numbers
SendMessage hSci, %SCI_SetMarginWidthN, 1, 30 'by default, shows symbols
End Sub
Sub TestA
Local i As Long
For i = 0 to 31
SendMessage hSci, %SCI_SetMarginMaskN, 1,-1 'all symbols allowed
SendMessage hSci, %SCI_MarkerAdd, i, i 'line, marker#
Next i
End Sub
Sub TestB
Local i As Long
SendMessage hSci, %SCI_MarkerDeleteAll, -1, 0 'remove markers from lines
'define all 32 markers
SendMessage hSci, %SCI_MarkerDefine, 0,%SC_MARK_CIRCLE
SendMessage hSci, %SCI_MarkerDefine, 1,%SC_MARK_ROUNDRECT
SendMessage hSci, %SCI_MarkerDefine, 2,%SC_MARK_ARROW
SendMessage hSci, %SCI_MarkerDefine, 3,%SC_MARK_SMALLRECT
SendMessage hSci, %SCI_MarkerDefine, 4,%SC_MARK_SHORTARROW
SendMessage hSci, %SCI_MarkerDefine, 5,%SC_MARK_EMPTY
SendMessage hSci, %SCI_MarkerDefine, 6,%SC_MARK_ARROWDOWN
SendMessage hSci, %SCI_MarkerDefine, 7,%SC_MARK_MINUS
SendMessage hSci, %SCI_MarkerDefine, 8,%SC_MARK_PLUS
SendMessage hSci, %SCI_MarkerDefine, 9,%SC_MARK_ARROWS
SendMessage hSci, %SCI_MarkerDefine, 10,%SC_MARK_DOTDOTDOT
SendMessage hSci, %SCI_MarkerDefine, 11,%SC_MARK_BACKGROUND
SendMessage hSci, %SCI_MarkerDefine, 12,%SC_MARK_LEFTRECT
SendMessage hSci, %SCI_MarkerDefine, 13,%SC_MARK_FULLRECT
SendMessage hSci, %SCI_MarkerDefine, 14,%SC_MARK_UNDERLINE
For i = 15 To 31
SendMessage hSci, %SCI_MarkerDefine, i, %SC_MARK_CHARACTER+i+50
Next i
'add 1 marker to each line
For i = 0 To 31
SendMessage hSci, %SCI_SetMarginMaskN, 1,-1 'all symbols allowed
SendMessage hSci, %SCI_MarkerAdd, i, i 'line, marker#
Next i
'set background of background marker to red
SendMessage hSci, %SCI_MarkerSetBack, 11, Rgb(220,220,220) 'gray background
End Sub
'gbs_00643
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm