ScintillaGadget() pas à pas

Informations pour bien débuter en PureBasic
kwandjeen
Messages : 204
Inscription : dim. 16/juil./2006 21:44

Re: ScintillaGadget() pas à pas

Message par kwandjeen »

Super Falsam. Je n'avais jamais pris le temps de regarder cette librairie et c'est pas mal pour ne pas utiliser l'api windows.
Je me suis fait une librairie pour utiliser l' EditorGadget mais avec scintilla cela devient multipalteforme.
Dès que j'ai un peu de temps je regarde pour modifier ça.

Encore bravo Falsam
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: ScintillaGadget() pas à pas

Message par falsam »

ScintillaGadget() et le SDK Syntax Highlighting

Peut être avez vous envie de coder un IDE PureBasic sur mesure. Je vous propose un code de freak (Fantaisy Software) fraîchement publié sur le forum anglophone montrant comment utiliser ScintillaGadget() avec le SDK Syntax Highlighting.


Le parser s'occupant de la coloration syntaxique de l'IDE Officiel est disponible dans la dll SyntaxHilighting.dll.

Code : Tout sélectionner

; Color values returned in the Dll callback
;
Enumeration
  #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

; Define protype for the dll function
;
Prototype SyntaxHighlight(*Buffer, Length, *Callback, Asm)
Global SyntaxHighlight.SyntaxHighlight

; Callback for the syntax parser
;
Procedure ColorCallback(*Position, Length, Color)
  ScintillaSendMessage(0, #SCI_SETSTYLING, Length, Color)
EndProcedure

; Callback for scintilla events
;
Procedure ScintillaCallback(Gadget, *scinotify.SCNotification)
  Protected LastStyled, Range.TextRange

  ; This event indicates that new coloring is needed. The #SCI_GETENDSTYLED message and *scinotify\position indicate the range to color
  If *scinotify\nmhdr\code = #SCN_STYLENEEDED
  
    ; calculate the range to color
    ; always start coloring at the line start 
    LastStyled = ScintillaSendMessage(Gadget, #SCI_GETENDSTYLED)
    Range\chrg\cpMin = ScintillaSendMessage(Gadget, #SCI_POSITIONFROMLINE, ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, LastStyled))
    Range\chrg\cpMax = *scinotify\position
    Range\lpstrText = AllocateMemory(Range\chrg\cpMax - Range\chrg\cpMin + 1)
    
    If Range\lpstrText
      ; retrieve the text range
      ScintillaSendMessage(Gadget, #SCI_GETTEXTRANGE, 0, @Range)   
      
      ; start coloring
      ScintillaSendMessage(Gadget, #SCI_STARTSTYLING, Range\chrg\cpMin, $FF)   
      
      ; call the parser function in the dll
      ; the callback above will apply the colors to the returned tokens      
      SyntaxHighlight(Range\lpstrText, Range\chrg\cpMax - Range\chrg\cpMin, @ColorCallback(), #False)      
      
      FreeMemory(Range\lpstrText)
    EndIf
    
  EndIf  
EndProcedure


If InitScintilla() And OpenLibrary(0, #PB_Compiler_Home + "SDK\Syntax Highlighting\SyntaxHilighting.dll")

  ; get the syntax parser function
  SyntaxHighlight = GetFunction(0, "SyntaxHighlight")

  ; create window and gadget
  OpenWindow(0, 0, 0, 640, 480, "Tiny Editor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget)
  ScintillaGadget(0, 0, 0, 640, 480, @ScintillaCallback())
  
  ; Important: tell the gadget to send the #SCN_STYLENEEDED notification to the callback if coloring is needed
  ScintillaSendMessage(0, #SCI_SETLEXER, #SCLEX_CONTAINER)
  
  ; Enable line numbers
  ScintillaSendMessage(0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
      
  ; Set common style info
  Define *FontName = AllocateMemory(StringByteLength("Courier New", #PB_Ascii) + 1)
  If *FontName
    PokeS(*FontName, "Courier New", -1, #PB_Ascii)
    ScintillaSendMessage(0, #SCI_STYLESETFONT, #STYLE_DEFAULT, *FontName)    
    FreeMemory(*FontName)
  EndIf  
  ScintillaSendMessage(0, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 12) 
  ScintillaSendMessage(0, #SCI_STYLESETBACK, #SCI_STYLESETFORE, 0)
  ScintillaSendMessage(0, #SCI_STYLESETBACK, #STYLE_DEFAULT, $DFFFFF)
  ScintillaSendMessage(0, #SCI_STYLECLEARALL)
    
  ; Set individual colors
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Text, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Keyword, $666600)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Comment, $AAAA00)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Constant, $724B92)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_String, $FF8000)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Function, $666600)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Asm, $DFFFFF)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Operator, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Structure, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Number, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Pointer, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Separator, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Label, 0)
  ScintillaSendMessage(0, #SCI_STYLESETFORE, #SYNTAX_Module, 0)
  ScintillaSendMessage(0, #SCI_STYLESETBOLD, #SYNTAX_Keyword, #True)
  
  ; Minimalistic event loop
  Define Event
  Repeat 
    Event = WaitWindowEvent()
    If Event = #PB_Event_SizeWindow
      ResizeGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
    EndIf
  Until Event = #PB_Event_CloseWindow

Else
  MessageRequester("Error", "Cannot load scintilla or parser dll")
EndIf
Lien : http://www.purebasic.fr/english/viewtop ... 57#p459057
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Re: ScintillaGadget() pas à pas

Message par djes »

Excellent ! Merci !
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: ScintillaGadget() pas à pas

Message par GallyHC »

bonjour,

Ce sera surement très utile et à moi en premier. Merci Mr Falsam.

GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: ScintillaGadget() pas à pas

Message par microdevweb »

A première vue je ne voie pas l'usage de tes shortcut

Code : Tout sélectionner

        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_B, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_G, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_E, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_R, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_O, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_P, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_Q, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_S, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_F, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_H, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_K, 0)
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_W, 0)  
        AddKeyboardShortcut(gIdWindow, #PB_Shortcut_Control+#PB_Shortcut_N, 0)
Note: j'attaque le développement de l'éditeur de code, et ton tuto est vraiment utile :wink:
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: ScintillaGadget() pas à pas

Message par falsam »

microdevweb a écrit :A première vue je ne voie pas l'usage de tes shortcut
C'est balot tu n'as pas quotté le commentaire qui allait avec :wink:
;-Neutraliser les caractéres spéciaux
AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_B, 0)
...
...
Comme indiqué dans le commentaire du tuto 01, ces shortcut permettent de neutraliser les caractères spéciaux.

Commente par exemple la ligne AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_G, 0) et presses simultanément les touches Ctrl + G
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: ScintillaGadget() pas à pas

Message par microdevweb »

Pour compléter le très bon tuto de falsam, voici une manière de récupérer les mot clé PureBasic (réaliser par falsam également)

Code : Tout sélectionner

CompilerIf #PB_Compiler_Unicode
  CompilerError "Décocher l'option unicode dans les options du compilateur"
CompilerEndIf

Define.s Result

Define.i CompilerRequester = RunProgram(#PB_Compiler_Home+"compilers\pbcompiler.exe","/STANDBY","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide)
Define.s InsComplete,keyWord
Define.i N
If CompilerRequester 
  If ProgramRunning(CompilerRequester)
    WriteProgramStringN(CompilerRequester, "FUNCTIONLIST") ;Options possible "FUNCTIONLIST", "STRUCTURELIST", "CONSTANTLIST", "INTERFACELIST"
    While Not FindString(result, "OUTPUT" + #TAB$ + "COMPLETE")
        N+1
        result  = ReadProgramString(CompilerRequester)
        If N>3 And result<>"OUTPUT	COMPLETE"
            keyWord+RTrim(StringField(StringField(result,1,"-"),1,"("))+"|"
        EndIf
    Wend
    CloseProgram(CompilerRequester)  
  EndIf 
EndIf
CreateFile(0,"PbKeyWord.txt",#PB_Unicode)
WriteString(0,keyWord,#PB_Unicode)
Par après on peut extraire les mot clé PureBasic

Exemple:

Code : Tout sélectionner

Restore PbKeyWord
Read.s KeyWord


DataSection
    PbKeyWord:
    IncludeBinary "PbKeyWord.txt"
EndDataSection
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: ScintillaGadget() pas à pas

Message par microdevweb »

Voila je me suis permis de modifier le code de falsam, les mots clés sont stockés dans une Db en mémoire et seul les mots avec le même début seront proposé dans l'autocomplétion

1ère Etape Charger les mot clé de Pb

Code : Tout sélectionner

CompilerIf #PB_Compiler_Unicode
  CompilerError "Décocher l'option unicode dans les options du compilateur"
CompilerEndIf

Define.s Result

Define.i CompilerRequester = RunProgram(#PB_Compiler_Home+"compilers\pbcompiler.exe","/STANDBY","",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide)
Define.s InsComplete,keyWord
Define.i N
If CompilerRequester 
  If ProgramRunning(CompilerRequester)
    WriteProgramStringN(CompilerRequester, "FUNCTIONLIST") ;Options possible "FUNCTIONLIST", "STRUCTURELIST", "CONSTANTLIST", "INTERFACELIST"
    While Not FindString(result, "OUTPUT" + #TAB$ + "COMPLETE")
        N+1
        result  = ReadProgramString(CompilerRequester)
        If N>3 And result<>"OUTPUT	COMPLETE"
            keyWord+RTrim(StringField(StringField(result,1,"-"),1,"("))
            keyWord+Chr(10)
        EndIf
    Wend
    CloseProgram(CompilerRequester)  
  EndIf 
EndIf
CreateFile(0,"PbKeyWord.txt",#PB_Unicode)
WriteString(0,keyWord,#PB_Unicode)
2ème Etape le code de scintilla (éditer pour correction dans la procédure KeyWord)

Code : Tout sélectionner

;Coloration Syntaxique & Pliage de code

EnableExplicit
UseSQLiteDatabase()
Enumeration Highlight
    #Style_Space
    #Style_Comment
    #Style_NonKeyword
    #Style_Keyword
    #Style_FoldKeyword
    #Style_Constant
    #Style_String
    #Style_Integer
    #Style_Operator
    
    #Style_FoldKeywordUp
    #Style_FoldKeywordDown
EndEnumeration

Enumeration Form
    #Mainform
    #StatusBar
EndEnumeration

Enumeration Menu
    #MainMenu
    #Quit
EndEnumeration

Enumeration Gadget  
    #Editor
EndEnumeration

Enumeration Db
    #Db
EndEnumeration

;-Déclaration variable et procédures 
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_SizeGadget

;Scintilla 
Global SciPos.l, SciLine.l, SciCol.l, SciIndent.l

;Liste des mots clés et définition du séparateur
Global KeyWord.s="ButtonGadget|TextGadget|If|EndIf|Enumeration|EndEnumeration|Procedure|EndProcedure|Select|EndSelect|Case|Default"
Global KeyWordFoldingUp.s = "Procedure|Enumeration|If"
Global KeyWordfoldingDown.s = "EndProcedure|EndEnumeration|EndIf"
Global KeyWordSep.s = "|"
; Pour mémoriser le mot encoder
Global CurrentWord.s
;-Plan de l'application
Declare Start()

Declare MainFormShow() 
Declare MainFormResize()
Declare MainFormClose()

Declare ScintillaCallBack(Gadget, *scinotify.SCNotification)
Declare ScintillaProperties(Gadget)
Declare ScintillaGetLineEndPosition(Gadget, Line)
Declare ScintillaLineFromPosition(Gadget, Pos)

Declare KeyWord(Key.s)
Declare Highlight(Gadget.l, EndPos.l)
Declare  LoadKeyWord()
Declare MakeKeyword(txt.s)

LoadKeyWord()
Start()

;Début
Procedure LoadKeyWord()
    ; Création de la Base de donnée en mémoire
    If OpenDatabase(#Db,":memory:","","")=0
        MessageRequester("DataBase Error","Can not create DataBase")
        End
    EndIf
    Protected query$
    query$="CREATE TABLE keyword("
    query$+"name TEXT)"
    ; Création de la table des mots clés
    If DatabaseUpdate(#Db,query$)=0
        MessageRequester("DataBase Error",DatabaseError())
        End
    EndIf
    ; Chargement des mots clés
    Protected Word.s
    Restore PbKeyWord
    Read.s Word
    Protected N,Nb
    Nb=CountString(Word,Chr(10))
    For N=1 To Nb+1
        query$="INSERT INTO keyword (name) VALUES ("+Chr(34)+StringField(Word,N,Chr(10))+Chr(34)+")"
        If DatabaseUpdate(#Db,query$)=0
            MessageRequester("DataBase Error",DatabaseError())
            End
        EndIf
    Next
    ;Ajout d'autre mot clé non listé
    Word="If|EndIf|Enumeration|EndEnumeration|Procedure|EndProcedure|Select|EndSelect|Case|Default"
    Nb=CountString(Word,"|")
    For N=1 To Nb+1
        query$="INSERT INTO keyword (name) VALUES ("+Chr(34)+StringField(Word,N,"|")+Chr(34)+")"
        If DatabaseUpdate(#Db,query$)=0
            MessageRequester("DataBase Error",DatabaseError())
            End
        EndIf
    Next
EndProcedure

Procedure Start()
    MainFormShow()
    
    BindEvent(#PB_Event_SizeWindow, @MainFormResize(), #MainForm)
    BindEvent(#PB_Event_CloseWindow, @MainFormClose(), #MainForm)
    
    BindMenuEvent(#MainMenu, #Quit, @MainFormClose())
    
    Repeat : WaitWindowEvent(10) : ForEver
EndProcedure

;-
;- U.T. Fenetres, Menu, Gadgets
Procedure MainFormShow()  
    OpenWindow(#MainForm,  0,  0, 1024, 768, "ScintillaGadget : Autocompletion", WindowStyle)
    
    ;Barre de status
    If CreateStatusBar(#StatusBar,WindowID(#Mainform))
        AddStatusBarField(150)
        AddStatusBarField(450) 
    EndIf 
    
    ;Evite le scintillement du Scintilla gadget lors du redimentionnement de la fenetre 
    SmartWindowRefresh(#Mainform, #True)
    
    ;Menu de l'application
    CreateMenu(#mainmenu,WindowID(#MainForm))
    MenuTitle("Fichier")
    MenuItem(#Quit,"Quitter")
    
    If InitScintilla()
        ;@ScintillaCallBack() est une procédure callback qui recevra  les évènements émis par ScintillaGadget
        ScintillaGadget(#Editor, 10, 40, 1004, 668, @ScintillaCallBack())
        ScintillaProperties(#Editor)
        SetActiveGadget(#Editor)
    EndIf
    
    ;Neutraliser la touche TAB et les caractéres spéciaux
    RemoveKeyboardShortcut(#Mainform, #PB_Shortcut_Tab)
    
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_B, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_G, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_E, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_R, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_O, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_P, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_Q, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_S, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_F, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_H, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_K, 0)
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_W, 0)  
    AddKeyboardShortcut(#Mainform, #PB_Shortcut_Control+#PB_Shortcut_N, 0)
EndProcedure

;Redimensionnement de la fenetre principale
Procedure MainFormResize()
    ResizeGadget(#Editor, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-20, WindowHeight(#Mainform)-100)
EndProcedure

Procedure MainFormClose()
    End
EndProcedure

;-
;- U.T. Utilitaire
Procedure MakeUTF8Text(Text.s)
    Static Buffer.s
    Buffer = Space(StringByteLength(Text, #PB_UTF8) + 1)
    PokeS(@buffer, text, -1, #PB_UTF8)
    ProcedureReturn @buffer
EndProcedure

;-
;- U.T. Scintilla
Procedure ScintillaCallBack(Gadget, *scinotify.SCNotification)
    Protected SciCurrentPos, SciWordStartPos
    Select *scinotify\nmhdr\code        
        Case #SCN_CHARADDED
            
            ;Indentation
            If *scinotify\ch = 13 ;Touche entrée
                                  ;Determination de l'indentation : SciIndent retourne le numéro de colonne  
                SciIndent = ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTATION, SciLine)
                
                ;Mise en place dans la nouvelle ligne indenté : Passage à la ligne suivante et positionnement à la colonne précédente 
                ScintillaSendMessage(Gadget, #SCI_SETLINEINDENTATION, SciLIne+1, SciIndent)
                
                ;Vous avez pressé la touche entrée mais sans indentation : Le curseur ne passera pas à la ligne suivante.
                ;On va forcer le passage à la ligne en insérant la longueur de #CRLF
                If SciIndent=0 
                    SciPos = SciPos + Len(#CRLF$)
                EndIf
                
                ;Positionnement du curseur 
                ScintillaSendMessage(Gadget, #SCI_GOTOPOS, SciPos+SciIndent)
            EndIf  
            
            ;Autocomplétion
            Select *scinotify\ch
                Case 'a' To 'z'         
                    CurrentWord+Chr(*scinotify\ch)
                    ;Affichage du mot selectionné si autocomplétion
                    SciCurrentPos = ScintillaSendMessage(Gadget, #SCI_GETCURRENTPOS)
                    SciWordStartPos = ScintillaSendMessage(Gadget, #SCI_WORDSTARTPOSITION, SciCurrentPos, 1)
                    MakeKeyword(CurrentWord)
                    ScintillaSendMessage(Gadget, #SCI_AUTOCSHOW, SciCurrentPos - SciWordStartPos, MakeUTF8Text(KeyWord))
                Default
                    CurrentWord=""
            EndSelect
            
        Case #SCN_STYLENEEDED
            Highlight(Gadget, *scinotify\position)
            
        Case #SCN_MARGINCLICK
            ScintillaSendMessage(Gadget, #SCI_TOGGLEFOLD, ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, *scinotify\Position))
            
    EndSelect
    
    ;Determination de la position à l'intérieur de la chaine scintilla  
    SciPos = ScintillaSendMessage(Gadget, #SCI_GETANCHOR)
    
    ;Determination de la ligne en cours 
    SciLine = ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, SciPos)
    
    ;Determination de la colonne en cours
    SciCol = ScintillaSendMessage(Gadget, #SCI_GETCOLUMN, SciPos)
    
    ;Determination de l'indentation
    SciIndent = ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTATION, SciLine)
    
    ;Affichage du numéro de ligne/colonne dans la barre de status
    StatusBarText(#StatusBar, 1, "Line : " +Str(SciLine+1)+ "  Col : "+Str(SciCol+1), #PB_StatusBar_Center)  
EndProcedure

;Customisation de l'éditeur
Procedure ScintillaProperties(Gadget)
    ;Style par defaut du gadget scintilla (Couleur de fond et de caractére, police .....)
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_DEFAULT, RGB(0, 0, 0))           ;Couleur des caracteres du ScintillaGadget
    ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(250, 250, 210))     ;Couleur de fond du ScintillaGadget
    ScintillaSendMessage(Gadget, #SCI_STYLESETFONT,#STYLE_DEFAULT, @"Lucida Console")       ;Police à utiliser 
    ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 10)                     ;Taille de la police
    ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL)
    
    ;Activation et couleur de la ligne en cours d'édition
    ScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, #True)
    ScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK, RGB(255, 228, 181))
    
    ;Les tabulations sont remplacées par des espaces 
    ScintillaSendMessage(Gadget, #SCI_SETUSETABS, #False)
    
    ;Nombre d'espaces pour une tabulation
    ScintillaSendMessage(Gadget, #SCI_SETINDENT, 4)
    
    ;Affichage de la colone de numérotation des lignes
    ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)                
    ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 0, 50)                               ;Largeur de la colonne
    ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, RGB(169, 169, 169))  ;Couleur de fond 
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, RGB(250, 250, 210))  ;Couleur des numéros
    
    ;Affichage de la colonne de pliages de code
    ScintillaSendMessage(Gadget, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS)
    ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 2, 20)
    ScintillaSendMessage(Gadget, #SCI_SETMARGINSENSITIVEN, 2, #True)
    
    ;Parametres de la liste d'autocomplétion des mots clés 
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETMAXHEIGHT, 40)
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETMAXWIDTH, 150)
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETAUTOHIDE, #True)
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETCHOOSESINGLE, #True)
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETIGNORECASE, #True)
    
    ;Caractére séparant chaque mot de la liste des mots clés
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETSEPARATOR, Asc(KeyWordSep))
    
    ;Caractére sélectionnant le mot de la liste d'autocomplétion
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETFILLUPS, 0, @" ")
    
    ;Tri de la liste d'autocomplétion
    ScintillaSendMessage(Gadget, #SCI_AUTOCSETORDER, #SC_ORDER_PERFORMSORT) 
    
    ;Coloration syntaxique
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Comment, RGB(0, 187, 0))
    ScintillaSendMessage(Gadget, #SCI_STYLESETITALIC, #Style_Comment, 1)
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_NonKeyword, RGB(0, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Keyword, RGB(0, 102, 102))
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Constant, RGB(169, 64, 147))
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_String, RGB(255, 139, 37))
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Integer, RGB(255, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #Style_Operator, RGB(205, 92, 92))
    
    ;Choix des icones de pliages du code 
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN, #SC_MARK_CIRCLEMINUS)
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDER, #SC_MARK_CIRCLEPLUS)
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERSUB, #SC_MARK_VLINE)
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERTAIL, #SC_MARK_LCORNERCURVE)
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEREND, #SC_MARK_CIRCLEPLUSCONNECTED)
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPENMID, #SC_MARK_CIRCLEMINUSCONNECTED)
    ScintillaSendMessage(Gadget, #SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERMIDTAIL, #SC_MARK_TCORNERCURVE)
    
    ;Couleur des icones de pliages de code
    ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDER, RGB(255, 255, 255))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDER, RGB(0, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETFORE, #SC_MARKNUM_FOLDEROPEN, RGB(255, 255, 255))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPEN, RGB(0, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDEROPENMID, RGB(0, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERSUB, RGB(0, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERTAIL, RGB(0, 0, 0))
    ScintillaSendMessage(Gadget, #SCI_MARKERSETBACK, #SC_MARKNUM_FOLDERMIDTAIL, RGB(0, 0, 0))
EndProcedure

Procedure ScintillaGetLineEndPosition(Gadget, Line)
    ProcedureReturn ScintillaSendMessage(Gadget, #SCI_GETLINEENDPOSITION, Line)
EndProcedure

Procedure ScintillaLineFromPosition(gadget, Pos)
    ProcedureReturn ScintillaSendMessage(Gadget, #SCI_LINEFROMPOSITION, Pos)
EndProcedure

;-
;- U.T. Coloration syntaxique
Procedure KeyWord(Key.s)
    Protected n
    
    If Key=""
        ProcedureReturn -1
    EndIf
    
    For n = 1 To CountString(KeyWordFoldingUp, KeyWordSep) + 1
        If LCase(StringField(KeyWordFoldingUp, n, KeyWordSep)) = LCase(Key)
            ProcedureReturn #Style_FoldKeywordUp
        EndIf
    Next
    
    For n=1 To CountString(KeyWordFoldingDown, KeyWordSep) + 1
        If LCase(StringField(KeyWordFoldingDown, n, KeyWordSep)) = LCase(Key)
            ProcedureReturn #Style_FoldKeywordDown
        EndIf
    Next
    Protected query$="SELECT name FROM keyword WHERE name LIKE"+Chr(34)+"%"+Key+"%"+Chr(34)
    If DatabaseQuery(#Db,query$)=0
        MessageRequester("DataBase Error",DatabaseError())
        ProcedureReturn -1
    EndIf
    If NextDatabaseRow(#Db)
        ProcedureReturn #Style_Keyword
    EndIf
EndProcedure


Procedure Highlight(Gadget.l, EndPos.l)
    Protected Level = #SC_FOLDLEVELBASE, Char.i, keyword.s, StyleID.i
    Protected ThisLevel.i = Level
    Protected NextLevel.i = Level
    Protected CurrentPos.i = 0, EndLinePos.i,  LineNumber.i, StartKeyword.i
    
    EndPos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, EndPos))
    ScintillaSendMessage(Gadget, #SCI_STARTSTYLING, CurrentPos, $1F | #INDICS_MASK)
    
    While CurrentPos <= EndPos
        Char = ScintillaSendMessage(Gadget, #SCI_GETCHARAT, CurrentPos)
        
        Select Char
            Case Asc(#LF$)
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_NonKeyword)
                ScintillaSendMessage(Gadget, #SCI_SETFOLDLEVEL, LineNumber , ThisLevel)
                ThisLevel = NextLevel
                LineNumber + 1
                
            Case '+', '-', '/', '*', '=', '>', '<'
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_Operator)
                
            Case '0' To '9'
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_Integer)
                
            Case 'a' To 'z', 'A' To 'Z', '{', '}'
                EndLinePos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, currentpos))
                keyword = Chr(char)
                
                While currentpos < EndLinePos
                    currentpos + 1
                    char = ScintillaSendMessage(Gadget, #SCI_GETCHARAT, currentpos)
                    If Not ((char >= 'a' And char <= 'z') Or (char >= 'A' And char <= 'Z') Or char = '_'Or (char >= '0' And char <= '9'))
                        currentpos-1
                        Break
                    EndIf
                    keyword + Chr(char)
                Wend
                
                Select KeyWord(keyword)
                    Case #Style_FoldKeywordUp
                        StyleID = #Style_Keyword
                        ThisLevel | #SC_FOLDLEVELHEADERFLAG
                        NextLevel + 1
                        
                    Case #Style_FoldKeywordDown
                        StyleID = #Style_Keyword
                        NextLevel - 1
                        If NextLevel < #SC_FOLDLEVELBASE
                            NextLevel = #SC_FOLDLEVELBASE
                        EndIf
                        
                    Case #Style_Keyword
                        StyleID = #Style_Keyword
                        
                    Default
                        StyleID = #Style_NonKeyword
                        
                EndSelect
                
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, Len(keyword), StyleID)
                
            Case '"'
                EndLinePos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, currentpos))
                StartKeyword = 1
                While currentpos < EndLinePos
                    currentpos + 1
                    StartKeyword + 1
                    If ScintillaSendMessage(Gadget, #SCI_GETCHARAT, currentpos) = '"'
                        Break
                    EndIf
                Wend
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, StartKeyword, #Style_String)
                
            Case ';'
                EndLinePos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, currentpos))
                StartKeyword = 1
                While currentpos < EndLinePos
                    currentpos + 1
                    StartKeyword + 1
                Wend
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, StartKeyword, #Style_Comment)
                
            Case 9, ' '
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_Space)
                
            Case '#'
                EndLinePos = ScintillaGetLineEndPosition(Gadget, ScintillaLineFromPosition(Gadget, currentpos))
                StartKeyword = 1
                While currentpos < EndLinePos
                    currentpos + 1
                    char = ScintillaSendMessage(Gadget, #SCI_GETCHARAT, currentpos)
                    If Not ((char >= 'a' And char <= 'z') Or (char >= 'A' And char <= 'Z') Or char = '_' Or (char >= '0' And char <= '9'))
                        currentpos-1
                        Break
                    EndIf
                    StartKeyword + 1
                Wend
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, StartKeyword, #Style_Constant)
                
            Default
                ScintillaSendMessage(Gadget, #SCI_SETSTYLING, 1, #Style_NonKeyword)
                
        EndSelect
        currentpos+1
    Wend 
EndProcedure

;Fabrique la liste de mot
Procedure MakeKeyword(txt.s)
    Protected query$
    query$="SELECT name FROM keyword WHERE name LIKE "+Chr(34)+txt+"%"+Chr(34)
    If DatabaseQuery(#Db,query$)=0
        MessageRequester("DataBase Error",DatabaseError())
        ProcedureReturn 
    EndIf
    KeyWord="|"
    While NextDatabaseRow(#Db)
        KeyWord+GetDatabaseString(#Db,0)+"|"
    Wend
EndProcedure

DataSection
    PbKeyWord:
    IncludeBinary "PbKeyWord.txt"
EndDataSection
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Répondre