Me voila à nouveau avec un mal de tête mais avec un code fonctionnel.
Il est possible nativement de zoomer sur le texte (Control + molette) et j'essaye de modifier la largeur de la marge en fonction de ce zoom mais helas le calcul n'est apparemment pas bon. Si quelqu'un pouvait jeter un oeil.... merci.
Le recalcul de la marge se trouve dans la procédure ScintillaCallback() après Case #SCN_ZOOM.
Code : Tout sélectionner
EnableExplicit
Enumeration
#File
#Mainform
#MainMenu
#New
#Open
#Save
#SaveAs
#Quit
#Editor
#StatusBar
EndEnumeration
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_SizeGadget
Global SciPos.l, SciLine.l, SciCol.l, SciIndent.l, SciFile.s, SciText.s
Global SciLineCount, SciMarginSize, SciMarginSizeDefault, SciCurrentZoom, SciZoom
Global Result.l, FileLenght.l, *MemoryID, ModeView.b=1
;- U.T. Scintilla
;Initialisation de la DLL Scintilla.
;Attention : SciLexer.dll doit etre present dans le meme dossier que votre programme
;ou bien dans un dossier dont vous aurez indiqué le chemin.
Procedure ScintillaInit()
If Not InitScintilla("SciLexer.dll")
MessageRequester("Information", "SciLexer.dll doit etre present dans le même dossier que votre programme")
End
EndIf
EndProcedure
;CallBack qui recevra les evenements emis par le gadget Scintilla
;*scinotify pointe vers une structure comportant les informations sur l'évènement:
;Voir le bas de cette page http://www.scintilla.org/ScintillaDoc.html
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
Select *scinotify\nmhdr\code
Case #SCN_DOUBLECLICK
Case #SCN_MODIFIED
;Quel est le facteur de zoom actuel.
;Rappel : On peut changer la taille de la police de caractére (Ctrl + Molette de la souris)
SciZoom = ScintillaSendMessage(Gadget, #SCI_GETZOOM, 0)
;Quel est la taille de la marge actuelle
SciMarginSize = ScintillaSendMessage(Gadget, #SCI_GETMARGINWIDTHN, 0)
;Nombre de lignes
SciLineCount = ScintillaSendMessage(gadget, #SCI_GETLINECOUNT,0)
;Ajustement de la marge en fonction du nombre de ligne
SciMarginSize = Len(Str(SciLineCount)) * (12 + Abs(SciZoom)*5/100)
;On applique
If SciMarginSize > SciMarginSizeDefault
ScintillaSendMessage(#Editor, #SCI_SETMARGINWIDTHN, 0, SciMarginSize)
EndIf
Case #SCN_CHARADDED
;Il y a t'il une indentation à faire aprés avoir presser la touche Entrée ?
If *scinotify\ch = 13
;Determination de l'indentation
SciIndent = ScintillaSendMessage(Gadget, #SCI_GETLINEINDENTATION, SciLine)
;Mise en place dans la nouvelle ligne de l'indentation de la ligne précédente
ScintillaSendMessage(Gadget, #SCI_SETLINEINDENTATION, SciLIne+1, SciIndent)
;Positionnement du curseur d'edition sur la nouvelle ligne
;Si pas d'indentation alors on ajoute 2 à la variable SciPos sinon pas de passage à la ligne
;ça fait bricolage mais je n'ai pas trouvé mieux.
;Pourquoi 2 ? parce que le passage à la ligne est composée de CR+LF
If SciIndent=0
SciPos=SciPos+2
EndIf
;Positionnement du curseur
ScintillaSendMessage(Gadget, #SCI_GOTOPOS, SciPos+SciIndent)
EndIf
Case #SCN_ZOOM
;Recalcul de la marge gauche afin de lire correctement les numéros de lignes
SciZoom = ScintillaSendMessage(Gadget, #SCI_GETZOOM, 0)
SciMarginSize = ScintillaSendMessage(Gadget, #SCI_GETMARGINWIDTHN, 0)
If SciZoom >= SciCurrentZoom
SciMarginSize = Round(SciMarginSize * (1 + Abs(SciZoom)/100), #PB_Round_Up)
Else
SciMarginSize = Round(SciMarginSize / (1 + Abs(SciZoom)/100), #PB_Round_Down)
EndIf
ScintillaSendMessage(#Editor, #SCI_SETMARGINWIDTHN, 0, SciMarginSize)
SciCurrentZoom = SciZoom
Default
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,0,"Line : " +Str(SciLine+1)+ " Col : "+Str(SciCol+1), #PB_StatusBar_Center)
EndProcedure
;Chargement d'un lexer et paramétrage de la coloration syntaxique
Procedure SetScintillaProperties(Gadget)
SciMarginSizeDefault = 40
;Chargement du dictionnaire PureBasic
ScintillaSendMessage(Gadget, #SCI_SETLEXER, #SCLEX_PUREBASIC)
;Style par defaut du gadget scintilla
;ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_DEFAULT, RGB(0, 0, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_DEFAULT, RGB(250, 250, 210))
ScintillaSendMessage(Gadget, #SCI_STYLESETFONT,#STYLE_DEFAULT,@"Verdana")
ScintillaSendMessage(Gadget, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 11)
ScintillaSendMessage(Gadget, #SCI_STYLECLEARALL)
;Affichage de la colone de numérotation des lignes
ScintillaSendMessage(Gadget, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER) ;
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 0, SciMarginSizeDefault)
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #STYLE_LINENUMBER, RGB(169, 169, 169))
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_LINENUMBER, RGB(250, 250, 210))
;Margin Mask Folder
ScintillaSendMessage(Gadget, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS)
ScintillaSendMessage(Gadget, #SCI_SETMARGINWIDTHN, 2, 15)
;Affichage et couleur de la ligne active
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEVISIBLE, #True)
ScintillaSendMessage(Gadget, #SCI_SETCARETLINEBACK, RGB(238, 232, 170))
;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 du guide d'indentation et affectation d'une couleur
ScintillaSendMessage(Gadget, #SCI_SETINDENTATIONGUIDES, #SC_IV_LOOKFORWARD)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #STYLE_INDENTGUIDE, RGB(154, 205, 50))
;coloration syntaxique (Prefixe #SCE_B pour les attribut du lexer Pure Basic & Blitz Basic)
;Pour chacune des spécifications, on va définir
;.La couleur de texte (#SCI_STYLESETFORE)
;.La couleur de fond (#SCI_STYLESETBACK)
;Texte par defaut
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_DEFAULT, RGB(0, 255, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_DEFAULT, RGB(250, 250, 210))
;Commentaire
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_COMMENT, RGB(46, 139, 87))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_COMMENT, RGB(250, 250, 210))
ScintillaSendMessage(Gadget, #SCI_STYLESETBOLD, #SCE_B_COMMENT, #True)
;Mot clé Pure Basic (je ne sais pas si la liste des mots est complete)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_IDENTIFIER, RGB(0, 0, 205))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_IDENTIFIER, RGB(250, 250, 210))
;Assembleur
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_ASM, RGB(0, 0, 205))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_ASM, RGB(250, 250, 210))
;Constant Pure Basic
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_CONSTANT, RGB(255, 0, 255))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_CONSTANT, RGB(250, 250, 210))
;Nombre
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_NUMBER, RGB(255, 0, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_NUMBER, RGB(250, 250, 210))
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_HEXNUMBER, RGB(255, 0, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_HEXNUMBER, RGB(250, 250, 210))
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_BINNUMBER, RGB(127, 255, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_BINNUMBER, RGB(250, 250, 210))
;Opérateur
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_OPERATOR, RGB(255, 0, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_OPERATOR, RGB(250, 250, 210))
;Chaine entre guillemet
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_STRING, RGB(184, 134, 11))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_STRING, RGB(250, 250, 210))
;Label (Data Section)
ScintillaSendMessage(Gadget, #SCI_STYLESETFORE, #SCE_B_LABEL, RGB(255, 140, 0))
ScintillaSendMessage(Gadget, #SCI_STYLESETBACK, #SCE_B_LABEL, RGB(250, 250, 210))
EndProcedure
;-
;- U.T. Fenetres, Menu, Gadgets
;Affichage de la fenetre principale de l'application
Procedure MainFormShow()
OpenWindow(#MainForm, 0, 0, 800, 600, "Pure Basic Editor", WindowStyle)
;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(#New,"Nouveau")
MenuItem(#Open,"Ouvrir")
MenuItem(#Save,"Enregistre")
MenuItem(#SaveAs,"Enregistrer Sous")
MenuBar()
MenuItem(#Quit,"Quitter")
;@ScintillaCallBack() correspond à l'adresse de la procédure
;qui recevra les évènements émis par le contrôle.
ScintillaGadget(#Editor, 10, 40, 790, 590, @ScintillaCallBack())
CreateStatusBar(#StatusBar,WindowID(#Mainform))
AddStatusBarField(150)
AddStatusBarField(450)
RemoveKeyboardShortcut(#Mainform, #PB_Shortcut_Tab)
;Affectation des touches de racourcis à aucun évènement menu
;tant qu'elles ne servent à rien afin d'éviter l'insertion des caracteres spéciaux
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)
StatusBarText(#StatusBar,1,"Nouveau document")
SetActiveGadget(#Editor)
EndProcedure
;Redimensionnement de la fenetre principale
Procedure MainFormResize()
ResizeGadget(#Editor, #PB_Ignore, #PB_Ignore, WindowWidth(#MainForm)-30, WindowHeight(#Mainform)-130)
EndProcedure
;-
;- U.T. Fichiers
;Nouveau document
Procedure NewFile()
ScintillaSendMessage(#Editor, #SCI_SETTEXT, 0, @"")
StatusBarText(#StatusBar,1,"Nouveau document")
EndProcedure
;Ouverture d'un fichier
Procedure LoadFile()
SciFile=OpenFileRequester("Ouvrir un fichier", "", "Pure Basic (*.pb)|*.pb|All files (*.*)|*.*", 0)
If SciFile
StatusBarText(#StatusBar,1,SciFile)
If ReadFile(#File, SciFile)
FileLenght = Lof(#file)
*MemoryID = AllocateMemory(FileLenght)
If *MemoryID
ReadData(#File, *MemoryID, FileLenght)
ScintillaSendMessage(#Editor, #SCI_SETTEXT, 0, *MemoryID)
FreeMemory(*MemoryID)
EndIf
CloseFile(#File)
EndIf
EndIf
EndProcedure
;Sauvegarde d'un fichier sous
Procedure SaveFileAs()
SciFile=SaveFileRequester("Sauvegarder un fichier sous", "", "Pure Basic (*.pb)|*.pb|All files (*.*)|*.*", 0)
If SciFile
If GetExtensionPart(SciFile)=""
SciFile=SciFile+".pb"
EndIf
StatusBarText(#StatusBar,1,SciFile)
If CreateFile(#File, SciFile)
FileLenght = ScintillaSendMessage(#Editor, #SCI_GETLENGTH)+1
*MemoryID = AllocateMemory(FileLenght)
If *MemoryID
ScintillaSendMessage(#Editor, #SCI_GETTEXT, FileLenght, *MemoryID)
WriteData(#File, *MemoryID, FileLenght)
FreeMemory(*MemoryID)
EndIf
CloseFile(#File)
EndIf
EndIf
EndProcedure
;Sauvegarde d'un fichier
Procedure SaveFile()
If SciFile<>""
If CreateFile(#File, SciFile)
FileLenght = ScintillaSendMessage(#Editor, #SCI_GETLENGTH)+1
*MemoryID = AllocateMemory(FileLenght)
If *MemoryID
ScintillaSendMessage(#Editor, #SCI_GETTEXT, FileLenght, *MemoryID)
WriteData(#File, *MemoryID, FileLenght)
FreeMemory(*MemoryID)
EndIf
CloseFile(#File)
EndIf
Else
SaveFileAs()
EndIf
EndProcedure
;-
;-Debut du traitement
ScintillaInit()
MainFormShow()
SetScintillaProperties(#Editor)
;-Boucle évenementielle
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
Select EventMenu()
Case #new
NewFile()
Case #Open
LoadFile()
Case #Save
SaveFile()
Case #SaveAs
SaveFileAs()
Case #Quit
End
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
Case #PB_Event_SizeWindow
MainFormResize()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
J'ajoute un lien de téléchargement qui contient le code ainsi que la dll Scintilla qui contient l'ensemble des lexer dont celui de Pure Basic.
Le lexer Pure Basic n'est pas au point et tu va devoir faire du BugWare dans la procédure ScintillaCallBack() pour forcer la coloration syntaxique. J'y reviendrais peut être plus tard. Tu as déjà de quoi faire