Date: 02-16-2022
Return to Index
created by gbSnippets
'White space (TABs and spaces) and end-of-line characters can be made visible,
'which can be useful in looking for both unintended or intended white space
'content. As a variation, Scintilla can also display only the white space
'that follows indentation.
'When made visible, white spaces are shown as dots. TABs are shown as arrows.
'The size and FG/BG colors can also be controlled. The color assigned will
'override the color that is usually set by the current lexer.
'Fonts have a "baseline" - the vertical line presenting the base of all
'characters. Ascent/descent are the distances a letter goes above/below
'the baseline. Both ascent and descent can be increased by Scintilla,
'which effectively increases the spaces between lines.
'Primary Code:
'To control visibility, use these messages:
SendMessage hSci, %SCI_SetViewWS, %SCWS_VisibleAlways, 20 'make visible
SendMessage hSci, %SCI_SetViewWS, %SCWS_Invisible, 20 'makes not visible
'Color and size are controlled with these messages:
SendMessage hSci, %SCI_SetWhiteSpaceFore, 1, %Red 'set FG color
SendMessage hSci, %SCI_SetWhiteSpaceFore, 1, %Yellow 'set BG color
SendMessage hSci, %SCI_SetWhiteSpaceSize, 2, 0 'set size
'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 : %ID_BtnC = 1003
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 All", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Small Dots", 10,40,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnC, "Not Visible", 10,70,70,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 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_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
Case %ID_BtnC : TestC
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
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
End Sub
Sub TestA
SendMessage hSci, %SCI_SetWhiteSpaceFore, 1, %Red 'FG color of white space
SendMessage hSci, %SCI_SetWhiteSpaceSize, 2, 0 'size of white space
SendMessage hSci, %SCI_SetViewWS, %SCWS_VisibleAlways, 20 'makes white space visible
SendMessage hSci, %SCI_SetViewEOL, 1, 0 'makes EOL visible
End Sub
Sub TestB
SendMessage hSci, %SCI_SetWhiteSpaceSize, 1, 0
End Sub
Sub TestC
SendMessage hSci, %SCI_SetViewWS, %SCWS_Invisible, 20 'makes white space not visible
SendMessage hSci, %SCI_SetViewEOL, 0, 0 'makes EOL not visible
End Sub
'gbs_00646
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm