Ce code reprend ce que j'ai expliqué sur ce post.
La coloration du gadget scintilla est issu du fichier préférence de l'éditeur officiel de Pure Basic.
Le gadget scintilla est à peine traité. Juste le minimum pour mettre en avant la dll SyntaxHilighting.dll.
Je ne traite pas l'indentation du texte, ni du zoom, ni de la recherche, etc....
On peut bien sur se lancer dans un vrai éditeur Pure Basic en se passant du fichier préférence de l'éditeur officiel.EnableExplicit
Enumeration Syntax
#SYNTAX_Text
#SYNTAX_Keyword
#SYNTAX_Comment
#SYNTAX_Constant
#SYNTAX_String
#SYNTAX_Function
#SYNTAX_Asm
#SYNTAX_Operator
#SYNTAX_Structure
#SYNTAX_Number
#SYNTAX_Pointer
#SYNTAX_Separator
#SYNTAX_Label
#SYNTAX_Module
EndEnumeration
Enumeration File
#Dll
EndEnumeration
Enumeration Window
#Mainform
EndEnumeration
Enumeration Gadget
#Editor
EndEnumeration
Global SciPositionStart, *Buffer
Declare CallbackHighlight(*Position, Length, IdColor)
Declare ScintillaCallBack(Gadget.i, *scinotify.SCNotification)
Declare MainForm_Open()
Declare MainForm_Resize()
Procedure CallbackHighlight(*Position, Length, IdColor)
Shared SciPositionStart, *Buffer
ScintillaSendMessage(#Editor, #SCI_STARTSTYLING, (*Position - *Buffer) + SciPositionStart, $1F)
ScintillaSendMessage(#Editor, #SCI_SETSTYLING, Length, IdColor)
EndProcedure
Procedure ScintillaCallBack(Gadget.i, *scinotify.SCNotification)
Protected SciLineNumber
Protected txtr.TEXTRANGE
Protected SciPositionEnd
Shared SciPositionStart, *Buffer
Select *scinotify\nmhdr\code
Case #SCN_STYLENEEDED
SciLineNumber = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, ScintillaSendMessage(Gadget, #SCI_GETENDSTYLED))
SciPositionStart = ScintillaSendMessage(Gadget, #SCI_POSITIONFROMLINE, SciLineNumber)
SciPositionEnd = *scinotify\Position
txtr\chrg\cpMin = SciPositionStart
txtr\chrg\cpMax = SciPositionEnd
txtr\lpstrText = AllocateMemory(SciPositionEnd - SciPositionStart + 1)
*Buffer = txtr\lpstrText
ScintillaSendMessage(Gadget, #SCI_GETTEXTRANGE, 0, txtr)
CallFunction(#Dll, "SyntaxHighlight", *Buffer, SciPositionEnd - SciPositionStart, @CallbackHighlight(), #True)
FreeMemory(*Buffer)
EndSelect
EndProcedure
Procedure MainForm_Open()
Protected Font.s
If OpenWindow(#Mainform, 0, 0, 800, 600, "SyntaxHilighting & Scintilla", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
StickyWindow(#MainForm, #True)
ScintillaGadget(#Editor, 10, 10, 780, 580, @ScintillaCallBack())
;Initialisation du gaget scintilla
ScintillaSendMessage(#Editor, #SCI_SETLEXER, #SCLEX_CONTAINER)
;Ouverture du fichier préférence de l'éditeur officiel de Pure Basic
OpenPreferences(GetEnvironmentVariable("APPDATA") + "\PureBasic\PureBasic.prefs")
PreferenceGroup("Editor")
Font = ReadPreferenceString("EditorFontName", "Courier New")
;Initialisation de la coloration syntaxique du gadget scintilla
;les couleurs seront celles que vous avez définies dans le menu préférence
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE,#STYLE_DEFAULT, $000000)
ScintillaSendMessage(#Editor, #SCI_STYLESETBACK, #STYLE_DEFAULT, ReadPreferenceLong("BackgroundColor", $FFFFFF))
ScintillaSendMessage(#Editor, #SCI_STYLESETFONT, #STYLE_DEFAULT, @Font)
ScintillaSendMessage(#Editor, #SCI_STYLESETSIZE, #STYLE_DEFAULT, ReadPreferenceLong("EditorFontSize", 10))
ScintillaSendMessage(#Editor, #SCI_STYLECLEARALL)
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Text, ReadPreferenceLong("NormalTextColor", 0))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Keyword, ReadPreferenceLong("BasicKeywordColor", $9D030D))
ScintillaSendMessage(#Editor, #SCI_STYLESETBOLD, #SYNTAX_Keyword, #True)
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Comment, ReadPreferenceLong("CommentColor", $6F884A))
ScintillaSendMessage(#Editor, #SCI_STYLESETITALIC, #SYNTAX_Comment, #True)
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Constant, ReadPreferenceLong("ConstantColor", $0B46AE))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_String, ReadPreferenceLong("StringColor", $413C33))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Function, ReadPreferenceLong("PureKeywordColor", $EF303D))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Asm, ReadPreferenceLong("ASMKeywordColor", $400080))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Operator, ReadPreferenceLong("OperatorColor", $0000FF))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Structure, ReadPreferenceLong("StructureColor", $0548B4))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Number, ReadPreferenceLong("NumberColor", $0000FF))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Pointer, ReadPreferenceLong("PointerColor", $0507B4))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Separator, ReadPreferenceLong("SeparatorColor", $000000))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Label, ReadPreferenceLong("LabelColor", $804000))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #SYNTAX_Module, ReadPreferenceLong("ModuleColor", $9D030D))
;Affichage de la colone de numérotation des lignes
ScintillaSendMessage(#Editor, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
ScintillaSendMessage(#Editor, #SCI_SETMARGINWIDTHN, 0, 50)
ScintillaSendMessage(#Editor, #SCI_STYLESETBACK, #STYLE_LINENUMBER, ReadPreferenceLong("LineNumberBackColor", GetSysColor_(15)))
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #STYLE_LINENUMBER, ReadPreferenceLong("LineNumberColor", 0))
ScintillaSendMessage(#Editor, #SCI_SETMARGINWIDTHN, 1, 5)
;Affichage et couleur de la ligne active
ScintillaSendMessage(#Editor, #SCI_SETCARETLINEVISIBLE, #True)
ScintillaSendMessage(#Editor, #SCI_SETCARETLINEBACK, ReadPreferenceLong("CurrentLineColor", 0))
;Les tabulations sont remplacées par des espaces
ScintillaSendMessage(#Editor, #SCI_SETUSETABS, #False)
;Nombre d'espaces pour une tabulation
ScintillaSendMessage(#Editor, #SCI_SETINDENT, 4)
;Affichage du guide d'indentation et affectation d'une couleur
ScintillaSendMessage(#Editor, #SCI_SETINDENTATIONGUIDES, #SC_IV_LOOKFORWARD)
ScintillaSendMessage(#Editor, #SCI_STYLESETFORE, #STYLE_INDENTGUIDE, RGB(154, 205, 50))
RemoveKeyboardShortcut(#Mainform, #PB_Shortcut_Tab)
ClosePreferences()
BindEvent(#PB_Event_SizeWindow, @MainForm_Resize(), #Mainform)
Repeat : Until WaitWindowEvent(100) = #PB_Event_CloseWindow
EndIf
EndProcedure
Procedure MainForm_Resize()
ResizeGadget(#Editor,#PB_Ignore, #PB_Ignore, WindowWidth(#Mainform)-20, WindowHeight(#Mainform)-20)
EndProcedure
;-Start
If Not OpenLibrary(#Dll, #PB_Compiler_Home+"SDK/Syntax Highlighting/SyntaxHilighting.dll")
MessageRequester("Erreur", "Impossible d'ouvir SyntaxHilighting.dll")
End
EndIf
If Not InitScintilla()
MessageRequester("Erreur", "Impossible d'initialiser Scintilla")
End
EndIf
MainForm_Open()