Date: 02-16-2022
Return to Index
created by gbSnippets
'Like other controls, Scintilla sends notifications to the container when
'specific events occur. Most are sent via WM_Notify, but a few are sent via
'WM_Command as well.
'When a Window %WM_Notify message is sent, it contains the following information:
wParam 'control ID
lParam 'pointer to Nmhdr structure
'When a Window %WM_Command message is sent, it contains the following information:
wParam 'control ID (lo word) and notification message (hi word)
lParam 'control handle
'PowerBASIC goes one step further and provides the following information as
'part of the CB structure. Regardless of message, the handle, message, wParam
'and lParam information is provided. But when %WM_Command Or %WM_Notify are
'received, other CB elements are filled with the following information:
All Messages WM_Command WM_Notify
CB.Hndl CB.Ctl (Control ID - Lo wParam) CB.Nmcode (notification message)
CB.Msg CB.Ctlmsg (Notificaton Msg - Hi wParam) CB.Nmhdr (pointer to Nmhdr structure)
CB.wParam CB.Nmhdr$ (Nmhdr UDT as dynamic String)
CB.lParam CB.Nmhwnd (Control Handle)
CB.NmID (Control ID)
'The NMHDR structure accompanies each %WM_Notify message, and contains the following
'elements:
Type Nmhdr
hWndFrom As DWord ' Handle of the control sending the message idfrom as Dword
IDFrom As DWord ' Identifier of the control sending the message code as Long
Code As Long ' Notification code
End Type
'So typically, when %WM_Notify is received, a variable is set to contain the Nmhdr
'information like this:
Case %WM_NOTIFY
Local pNMHDR As Nmhdr Ptr
pNMHDR = CB.lParam
'Then, the pNMHDR content can be accessed
iResult = @pNMHDR.Code (same as iResult = CB.Nmcode)
iResult = @pNMHDR.idFrom (same as iResult = CB.NmID)
iResult = @pNMHDR.hWndFrom (same as iResult = CB.Nmhwnd)
'The next few paragraphs discuss the notifications sent by Scintilla, broken
'into various categories.
'Content Change:
'There are 4 notifications which related to a change in text or style in the
'content of the control, sent in this order:
SCEN_Change 'text changes (not style)
*SCN_Modified 'text or styling about to be changed
'cannot modify document in this event
*SCN_CharAdded 'when user types text character (char is found in SCNotification.ch)
'sent before character is styled
SCN_UpdateUI 'text or styling has changed
'or selection range has changed
'use in place of SCN_PosChanged (deprecated)
'The difference between SCEN_Change and SCN_Modified is that SCN_Modified also
'provides access to additional information via a SCNotification structure (see
'further discussion below).
'Focus - %WM_Command
'These two notifications are sent when the Scintilla control gets/loses focus.
SCEN_SetFocus 'when Scintilla receives focus
SCEN_KillFocus 'when Scintilla loses focus
'Clicks (double, margin, hotspot, indicator, calltip) - %WM_Notify
'These notifications are sent as a result of a mouse click action.
SCN_DOUBLECLICK 'double-click in the editor
*SCN_MARGINCLICK 'double-click in a sensitive margin
SCN_HOTSPOTCLICK 'click on sensitive text
SCN_HOTSPOTDOUBLECLICK 'double-click on senstive text
*SCN_INDICATORCLICK 'mouse down/up over text that has an indicator
*SCN_INDICATORRELEASE
SCN_CALLTIPCLICK 'click on displayed call tip text
'Feature Events (autocompletion, userlist, dwelltime, zoom) - %WM_Notify
'There notifications are related to actions
*SCN_AUTOCSELECTION 'item autocompletion list is selected
SCN_AUTOCCANCELLED 'autocompletion list is cancelled
SCN_AUTOCCHARDELETED 'char deleted while autocompletion list is displayed
*SCN_USERLISTSELECTION 'user has selected item in User List
*SCN_DWELLSTART 'after mouse is in one position for dwell period
*SCN_DWELLEND 'when dwell is over
SCN_ZOOM 'text is zoomed (in or out)
'Special Events
SCN_STYLENEEDED 'range of text needs styling
SCN_PAINTED 'painting has just completed
'Misc Events
'All other notifications - miscellaneous actions.
SCN_SAVEPOINTREACHED
SCN_SAVEPOINTLEFT
SCN_MODIFYATTEMPTRO 'user attempts to change text when in read only mode
SCN_KEY 'key is pressed (that Scintilla does not consume)
*SCN_MACRORECORD 'macro recording is started
*SCN_NEEDSHOWN 'returns range of invisible lines that should be made visible
SCN_URIDROPPED 'GTK+ only
'SCNotification Content
'Not all Scintilla notifications provide information via the SCNotification
'structure. Here's a list of the elements of the structure, with indication of
'which notifications return the element.
Type Nmhdr
position 'SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED 'start pos of text/styling change
'SCN_DWELLSTART, SCN_DWELLEND, SCN_CALLTIPCLICK,
'SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK
ch 'SCN_CHARADDED, SCN_KEY
modifiers 'SCN_KEY, SCN_DOUBLECLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK
modificationType 'SCN_MODIFIED
txt 'SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
length 'SCN_MODIFIED 'length of change
linesAdded 'SCN_MODIFIED '# of added lines, negative if zero
message 'SCN_MACRORECORD
wParam 'SCN_MACRORECORD
lParam 'SCN_MACRORECORD
Line 'SCN_MODIFIED, SCN_DOUBLECLICK
foldLevelNow 'SCN_MODIFIED
foldLevelPrev 'SCN_MODIFIED
Margin 'SCN_MARGINCLICK
listType 'SCN_USERLISTSELECTION, SCN_AUTOCSELECTION
x 'SCN_DWELLSTART, SCN_DWELLEND
y 'SCN_DWELLSTART, SCN_DWELLEND
End Type
'The "modificationType" element of the SCNotification structure contains information
'about the type of event which sent the notification.
SC_MOD_INSERTTEXT 'text inserted. position, length, text, linesAdded
SC_MOD_DELETETEXT 'text removed. position, length, text, linesAdded
SC_MOD_CHANGESTYLE 'style change. position, length
SC_MOD_CHANGEFOLD 'fold change. line, foldLevelNow, foldLevelPrev
SC_PERFORMED_USER 'operation was done by user (no arg)
SC_PERFORMED_UNDO 'undo operation (no arg)
SC_PERFORMED_REDO 'redo operation (no arg)
SC_MULTISTEPUNDOREDO 'multi-step undo (no arg)
SC_LASTSTEPINUNDOREDO 'last step in undo/redo (no arg)
SC_MOD_CHANGEMARKER '1 or more markers changed in a line. line#
SC_MOD_BEFOREINSERT 'text about to be inserted. position (f by user, length in cells)
SC_MOD_BEFOREDELETE 'text about to be deleted. position, length
SC_MOD_CHANGEINDICATOR 'indicator add/removed. position, length
SC_MOD_CHANGELINESTATE 'line state changed via SCI_SETLINESTATE. line
SC_MOD_CHANGEMARGIN 'text margin has changed. line
SC_MOD_CHANGEANNOTATION 'annotation changed. line
SC_MULTILINEUNDOREDO 'undo/redo with multi-line changes (no arg)
SC_STARTACTION 'set via SC_PERFORMED_USER action when is 1st/only step in undo. (no arg)
SC_MOD_CONTAINER 'set for actions that container stored in undo stack with SCI_ADDUNDOACTION. token
SC_MODEVENTMASKALL 'mask for valid flags. is default mask set by SCI_SETMODEVENTMASK
'Note that by using the SC_SetModEventMask message, you can control which of these
'events trigger either the SCEN_Change or SCN_Modify messages. For example, to limits
'message to text changes, use this message:
SendMessage hSci, %SCI_SETMODEVENTMASK, %SC_MOD_INSERTTEXT Or %SC_MOD_DELETETEXT, 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_ListBox = 1001 : %ID_Btn = 1002
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,500,300, %WS_OverlappedWindow To hDlg
Control Add ListBox, hDlg, %ID_ListBox, , 10,10,150,130, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %ID_Sci, "", 200,10,180,130, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_Btn, "Clear" ,165,120,35,30, %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
Static iCount 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_Btn : ListBox Reset hDlg, %ID_ListBox
Case %ID_Sci
Select Case CB.Ctlmsg
Case %SCEN_Change : Incr iCount : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " SCEN_Change"
Case %SCEN_SetFocus
Case %SCEN_KillFocus
End Select
End Select
Case %WM_Notify
Select Case CB.NmID
Case %ID_Sci
Incr iCount
Select Case CB.Nmcode
Case %SCN_CharAdded : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " CharAdded"
Case %SCN_Modified : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " Modified"
Case %SCN_UpdateUI : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " UpdateUI"
' Case %SCN_StyleNeeded : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " StyleNeeded"
Case %SCN_Key : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " Key"
' Case %SCN_Painted : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " Painted"
Case %SCN_MarginClick : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " MarginClick"
Case %SCN_DoubleClick : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " DoubleClick"
Case %SCN_HotSpotClick : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " HotSpotClick"
Case %SCN_HotSPotDoubleClick : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " HotSpotDoubleClick"
Case %SCN_IndicatorClick : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " IndicatorClick"
Case %SCN_CallTipClick : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " CallTipClick"
Case %SCN_AutoCSelection : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " AutoCSelection"
Case %SCN_AutoCCancelled : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " AutoCCancelled"
Case %SCN_AutoCCharDeleted : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " AutoCCharDeleted"
Case %SCN_UserListSelection : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " UserListSelection"
Case %SCN_DwellStart : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " DwellStart"
Case %SCN_DwellEnd : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " DwellEnd"
Case %SCN_Zoom : ListBox Insert hDlg, %ID_ListBox, 1, Str$(iCount) + " Zoom"
End Select
End Select
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-20, Hi(Word, CB.lParam)-20
Control Set Size hDlg, %ID_ListBox, 150, 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) 'set text
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20 'set line number margin 0 to width=20
Control Set Focus hDlg, %ID_Sci 'focus
SendMessage hSci, %SCI_SETMODEVENTMASK, %SC_MOD_INSERTTEXT Or %SC_MOD_DELETETEXT, 0
End Sub
'gbs_00681
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm