Date: 02-16-2022
Return to Index
created by gbSnippets
'For many programmer, indentation can simply be TAB or spaces - the amount of white space
'at the left of a line is simply a matter of how many keys you press. With Scintilla you
'can set the size of a TAB (default is 8 spaces, of Style_Default), which provides a means
'of controlling the size of indentation.
'But Scintilla can provide even greater control over indentation, In particular, you can
'define an indent size (number of Style_Default spaces), then display vertical lines every
'indent size. This helps you visually identify blocks of code.
'Scintilla offers several other features to control indentation.
'1. TAB/Backspace keys can be set to indent/un-indent (in indentation area only)
'2. Automatically convert TABs to spaces (in indentation area only)
'3. Set indentation independently for each line
'4. Control how many indentation lines are displayed, based on existing content
'Scintilla has also reserved a style for indentation lines, Style_ IndentGuide, which
'allow yous to style messages to modify guide attributes, such as FG/BG.
'One additional, useful feature, is that when brace highlighting is used the indentation
'guides can be set to use the brace highlighting style - making the set of related
'feastures the same color.
'Primary Code:
'To set the indent size (in spaces of Style_Default), use this code:
SendMessage hSci, %SCI_SetIndent, 20, 0
'To force the TAB/Backspace keys to indent/unindent within white space area, use these:
SendMessage hSci, %SCI_SetTABIndents, 1, 0
SendMessage hSci, %SCI_SetBackspaceUnindents, 1, 0
'And to set indentation, use this code:
SendMessage hSci, %SCI_SetLineIndentation, 0, 20*1 'line#, indentation amount
'To set the indentation guide FG color, use this:
SendMessage hSci, %SCI_StyleSetFore, %Style_IndentGuide, %Red
'And to set the depth of indentation lines, use this line of code. There are several
'options, but SC_IV_LookBoth is typically used.
SendMessage hSci, %SCI_SetIndentationGuides, %SC_IV_LookBoth, 0
'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
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 "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
txt = "If x = 2 Then" + $CrLf
txt = txt + "'do nothing" + $CrLf
txt = txt + "Else" + $CrLf
txt = txt + "x = 0" + $CrLf
txt = txt + "End If" + Chr$(0)
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
'set indent size to 10 spaces
SendMessage hSci, %SCI_SetIndent, 20, 0
'force TAB/Backspace to indent/unindent within white space area
SendMessage hSci, %SCI_SetTABIndents, 1, 0
SendMessage hSci, %SCI_SetBackspaceUnindents, 1, 0
'set line indentation
SendMessage hSci, %SCI_SetLineIndentation, 0, 20*1
SendMessage hSci, %SCI_SetLineIndentation, 1, 40*1
SendMessage hSci, %SCI_SetLineIndentation, 2, 20*1
SendMessage hSci, %SCI_SetLineIndentation, 3, 40*1
SendMessage hSci, %SCI_SetLineIndentation, 4, 20*1
'set indent line FG color to red
SendMessage hSci, %SCI_StyleSetFore, %Style_IndentGuide, %Red
'show indentation lines beyond currently typed text
SendMessage hSci, %SCI_SetIndentationGuides, %SC_IV_LookBoth, 0 'show indentation lines beyond currently typed text
End Sub
'gbs_00645
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm