Date: 02-16-2022
Return to Index
created by gbSnippets
'Scintilla supports 5 margins, numbered 0-4. Each can independently be set to display
'line numbers, symbols, or application-defined text. All are located on the left side
'of the control. Additionally, a controllable gap is maintained on both sides of the
'text. The gap is set to 1 pixel by default.
'In addition to the type of information displayed (line numbers, symbols, or text),
'the following margin attributes can also be set:
' - right justification (text)
' - color (foreground and background)
' - width (in pixels)
' - clickable, also called "sensitive" (by default, margins do not respond to mouse clicks)
'By default, clicking on any margin will highlight the entire line. Each margin can
'also be set sensitive to mouse clicks, in which case clicking the margin will send a
'SCN_MarginClick message to the container.
'Margins which are not sensitive (clickable) are referred to as selection margins.
'By default, margins 0-2 are given the following width and display attributes. A margin
'with zero width is not displayed.
' margin display width
' 0 line numbers 0 (not visible)
' 1 symbols 16 (visible)
' 2 symbols 0 (not visible)
'Margins which are declared as symbol margins can display any of up to 32 logical
'symbols, corresponding to to each bit of a 32-bit mask that can be set for each
'margin. If a bit is set in the mask, then the symbol margin can display the symbol
'corresponding to that bit.
'Bits 25-31 of the mask are used by Scintilla to correspond to the 7 logical symbols
'that denote folding. If these bits are set, the margin is known as a folding margin.
'You can set all 7 folding bits at one time using the %SC_Mask_Folder equate.
'Bits 0-24 of the mask may be associated with any symbol. See the snippet on markers
'(another name for symbols) for information on how to assign symbols to margins.
'Since each margin can be set independently, you can set all 5 margins to display,
'for example, line numbers. In that case, all 5 margins display the same thing - line
'numbers. Likewise, you can set all 5 margins to display text or right-justified text.
'But since only a single margin text string can be assigned per line, all text or
'right-justified text margins would display the same content.
'Each symbol margin, however, can have its own symbol mask. So multiple margins can be
'defined as symbol margins and still display different content.
'Setting margin FG/BG colors is handled differently depending on the type of margin.
'Line Number Margin - FG/BG color defined by Style_LineNumber
'Text Margin - BG color defaults to Style_LineNumber BG color
'Symbol Margin (non-folding) - defaults to Syle_Default FG/BG colors. Use SC_Margin_Back/Fore to change.
'Symbol Margin (folding) - defaults to system 3DFace/3DHighLight colors. Change with SetFoldMarginColour/SetFoldMarginHiColor
'Primary Code:
'Set width to 20 pixels
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
'Set display type (margin 0 in these examples)
SendMessage hSci, %SCI_SetMarginTypeN, 0, %SC_Margin_Number 'line numbers
SendMessage hSci, %SCI_SetMarginTypeN, 0, %SC_Margin_Symbol 'symbols
SendMessage hSci, %SCI_SetMarginTypeN, 0, %SC_Margin_Text 'text
SendMessage hSci, %SCI_SetMarginTypeN, 0, %SC_Margin_RText 'right-justified text
'Set FG/BG colors (margin 1 in these examples)
SendMessage hSci, %SCI_SetMarginTypeN, 1, %SC_Margin_Back
SendMessage hSci, %SCI_SetMarginTypeN, 1, %SC_Margin_Fore
'Compilable Example: (Jose Includes)
'This example shows/hides margins, changes margin colors, and sets a margin
'to respond to a mouse click.
#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,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "Show Margins", 10,10,80,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Hide Margins", 10,40,80,20, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %ID_Sci, "", 100,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 pNSC As SCNotification Ptr ' // Scintilla notification messages
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_NOTIFY
Select Case CB.NmID
Case %ID_SCi
pNSC = CB.lParam
Select Case @pNSC.hdr.Code
Case %SCN_MarginClick : MsgBox "I've been clicked!"
End Select
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
'change Style_Default FG/BG
SendMessage hSci, %SCI_StyleSetFore, %Style_Default, %Red
SendMessage hSci, %SCI_StyleSetBack, %Style_Default, %Yellow
'default text
' 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)
End Sub
Sub TestA
Local txt As String
'make margins 0-3 visible
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
SendMessage hSci, %SCI_SetMarginWidthN, 1, 20
SendMessage hSci, %SCI_SetMarginWidthN, 2, 20
SendMessage hSci, %SCI_SetMarginWidthN, 3, 20
'set type of margins 0-3
SendMessage hSci, %SCI_SetMarginTypeN, 0, %SC_Margin_Number
SendMessage hSci, %SCI_SetMarginTypeN, 1, %SC_Margin_Symbol
SendMessage hSci, %SCI_SetMarginTypeN, 2, %SC_Margin_Text
SendMessage hSci, %SCI_SetMarginTypeN, 3, %SC_Margin_RText
'put some content in margins 1,2,3
txt = "M2"
SendMessage hSci, %SCI_MarginSetText, 2, StrPTR(txt)
txt = "M3"
SendMessage hSci, %SCI_MarginSetText, 3, StrPTR(txt)
'set margin 2 to use the Style_Default colors
' SendMessage hSci, %SCI_SetMarginTypeN, 0, %SC_Margin_Back
' SendMessage hSci, %SCI_SetMarginTypeN, 1, %SC_Margin_Back
' SendMessage hSci, %SCI_SetMarginTypeN, 2, %SC_Margin_Back
'make margin 0 clickable
SendMessage hSci, %SCI_SetMarginSensitiveN, 0, 1
'set left gap margin to 10 pixels
SendMessage hSci, %SCI_SetMarginLeft, 0, 10
End Sub
Sub TestB
'hide margins 0-3 by setting width to zero
SendMessage hSci, %SCI_SetMarginWidthN, 0, 0
End Sub
'gbs_00635
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm