Date: 02-16-2022
Return to Index
created by gbSnippets
'Scintilla provides support for displaying a small window of text, a "call tip",
'below a specified character position. This is commonly used by source code
'editors to provide the arguments of a function once the user has typed the
'name of the function. The window is a "tip" for a function that the source
'code "calls".
'Used in that way, it serves as a useful reminder to the user what must be
'entered following the function name. The container program decides when to
'display a call tip, so call tips can be used for any purpose the programmer wishes.
'For example, you might display a call tip in response to a SCN_DwellStart
'message and remove it in response to a SCN_DwellEnd message.
'The call tip FG/BG can be set and portions of the call tip can be highlighted, such
'as to let the user know which function argument should be typed next. In the case
'of comma separated arguments, the container application would count commas following
'the function to know which argument to have Scintilla highlight.
'A few other points regarding call tips:
' - default style is STYLE_DEFAULT but can be switched to STYLE_CAlLTIP
' - up/down arrows can be displayed in a call tip (use "\001" or "\002")
' - showing a call tip cancels any active autocompletion list, and vice versa
' - clicking on a call tip sends a SCN_CallTipClick message to the container
' - call tips can be multiline, just add a line ending within the text
'Primary Code:
'Set FG/BG of call tip
SendMessage hSci, %SCI_CallTipSetFore, %Red, 0
SendMessage hSci, %SCI_CallTipSetBack, %Yellow, 0
'Display a call tip
tip = "arg1, arg2, arg3" + $nul
SendMessage hSci, %SCI_CallTipShow, 5, StrPTR(tip)
'Set FG of highlight call tip, then highlight it
SendMessage hSci, %SCI_CallTipSetForeHLT, %Blue, 0
SendMessage hSci, %SCI_CallTipSetHLT, 5,10 'iStart, iEnd+1
'Cancel the call tip
SendMessage hSci, %SCI_CallTipCancel, 0, 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 : %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 Call Tip", 10,10,80,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Cancel Call Tip", 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 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
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
Local tip as String, iPos As Long
tip = "arg1, arg2, arg3" + $nul
iPos = SendMessage( hSci, %SCI_GetCurrentPos, 0, 0) 'get caret position
SendMessage hSci, %SCI_CallTipShow, iPos, StrPTR(tip)
SendMessage hSci, %SCI_CallTipSetForeHLT, %Blue, 0 'highlight FG of call tip
SendMessage hSci, %SCI_CallTipSetFore, %Red, 0 'FG of call tip
SendMessage hSci, %SCI_CallTipSetBack, %Yellow, 0 'BG of call tip
SendMessage hSci, %SCI_CallTipSetHLT, 5,10 'iStart, iEnd+1
Control Redraw hDlg, %ID_Sci
Control Set Focus hDlg, %ID_Sci
End Sub
Sub TestB
SendMessage hSci, %SCI_CallTipCancel, 0, 0
End Sub
'gbs_00657
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm