Scintilla pour les débutants [RESOLU]

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Jeff
Messages : 72
Inscription : sam. 13/mai/2006 18:09

Scintilla pour les débutants [RESOLU]

Message par Jeff »

bonjour à tous,

J'ai lu dans les forums que la nouvelle version de PB avait de nouvelles fonctionnalités relative à scintilla. par contre je n'ai pas vu de code montrant son utilisation concrète

Avez-vous des exemples ?

Merci d'avance à la comunauté :lol:

@

JF
Dernière modification par Jeff le mar. 26/juin/2007 20:29, modifié 1 fois.
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

extrait d'un exemple de ts_soft.

Code : Tout sélectionner

;http://www.purebasic.fr/german/viewtopic.php?t=13234, merci ts-soft.

;Pour récupérer l'aide de scintilla au format chm , merci kai.
;http://www.kaispage.de/content/download/Scintilla.chm
EnableExplicit

If InitScintilla("scintilla.dll") = #False 
  MessageRequester("Erreur","Scintilla.DLL n'a pas pu être chargé",0) 
  End 
EndIf

Enumeration; Gadgets
  #SciID
EndEnumeration

Procedure ScintillaCallBack(EditorGadget.l, *scinotify.SCNotification)
  If *scinotify\nmhdr\code = #SCN_STYLENEEDED
    ScintillaSendMessage(EditorGadget, #SCI_LINEFROMPOSITION, ScintillaSendMessage(EditorGadget, #SCI_GETENDSTYLED))
 EndIf
EndProcedure

Procedure CreatePBSource()
  Protected WFlags.l = #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SystemMenu | #PB_Window_SizeGadget
  Protected temp.s
  If OpenWindow(1, #PB_Ignore, 0, 640, 480, "Tests avec Scintilla", WFlags)
    CreateGadgetList(WindowID(1))
    ScintillaGadget(#SciID, 20, 20, 600, 440, @ScintillaCallBack())
    
    ScintillaSendMessage(#SciID, #SCI_STYLESETBACK, #STYLE_DEFAULT, $BEFCFD) ; Couleur de fond
    temp = "Lucida BlackLetter"
    ScintillaSendMessage(#SciID, #SCI_STYLESETFONT, #STYLE_DEFAULT, @temp) ; Police
    ScintillaSendMessage(#SciID, #SCI_STYLESETSIZE, #STYLE_DEFAULT, 24)    ; Taille police
    ScintillaSendMessage(#SciID, #SCI_STYLECLEARALL)
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, 0, $FF0000)            ;Couleur du texte 
    ScintillaSendMessage(#SciID, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)
    ScintillaSendMessage(#SciID, #SCI_SETMARGINWIDTHN, 0, 40) ; Largeur Marge
    ScintillaSendMessage(#SciID, #SCI_STYLESETBACK, #STYLE_LINENUMBER, #Gray) ;Couleur de la marge
    ScintillaSendMessage(#SciID, #SCI_STYLESETFORE, #STYLE_LINENUMBER, #Yellow) ;Couleur Texte de la marge
    ProcedureReturn 1
  EndIf
  ProcedureReturn 0
EndProcedure

If CreatePBSource()
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow : Break
    EndSelect
  ForEver 
EndIf
http://purebasic.developpez.com/
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

ha bah j'etais en train d'etudier la chose :lol:

voici ou j'en etais !

je ne suis pas arrivé a lui faire colorer certain mot clef !! :?

Code : Tout sélectionner



; SendMessage_(hScintilla,#SCI_StyleSetFore,#STYLE_DEFAULT,RGB(250,250,250)) ; couleur de la police
; SendMessage_(hScintilla,#SCI_STYLESETBACK,#STYLE_DEFAULT,RGB(40,40,80)) ; couleur du fond
; SendMessage_(hScintilla,#SCI_STYLECLEARALL,0,0);
; SendMessage_(hScintilla,#SCI_StyleSetFore,1,RGB(0,250,0)); définti une liste de couleur comme en rtf
; SendMessage_(hScintilla,#SCI_StyleSetFore,2,RGB(0,250,250));
; SendMessage_(hScintilla,#SCI_StyleSetFore,3,RGB(250,250,0));
; SendMessage_(hScintilla,#SCI_StyleSetFore,4,RGB(250,100,0));
; SendMessage_(hScintilla,#SCI_STYLESETBACK,#STYLE_LINENUMBER,RGB(80,80,160)) ; fond
; SendMessage_(hScintilla,#SCI_StyleSetFore,#STYLE_LINENUMBER,RGB(250,250,250)); écriture
; SendMessage_(hScintilla,#SCI_SETMARGINWIDTHN,0,30);  Affiche les numero des lignes
; SendMessage_(hScintilla,#SCI_SETSELBACK,#True,RGB(0,100,150)); Détermine la couleur de fond de la sélection
; SendMessage_(hScintilla,#SCI_SETSELFORE,#False,0); La couleur du texte sélectionné est inchangée
; SendMessage_(hScintilla,#SCI_SETCARETFORE,RGB(250,200,100),0); Couleur du curseur
; SendMessage_(hScintilla,#SCI_SETCARETWIDTH,2,0); Largeur du curseur
; SendMessage_(hScintilla,#SCI_SETINDENTATIONGUIDES,#True,0) ; Affiche le guide d'indentation
; SendMessage_(hScintilla,#SCI_SETINDENT,8,0) ; Détermine la longueur de la tabulation

; SendMessage_(hScintilla,#SCI_INSERTTEXT,-1,Texte$) ; insère le texte à la fin !
; For t=1 To 6
    ; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,t,8) ; indente  le texte de 8 espaces
; Next
; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,2,16)
; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,4,16)
; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,6,16)
 ; 
; SendMessage_(hScintilla,#SCI_STARTSTYLING,9,$FF);x=début de la coloration y=??
; SendMessage_(hScintilla,#SCI_SETSTYLING,8,1) ;x=nombre de caractère y : numéro de couleur dans le dico
; SendMessage_(hScintilla,#SCI_STARTSTYLING,29,$FF)
; SendMessage_(hScintilla,#SCI_SETSTYLING,7,2)
; SendMessage_(hScintilla,#SCI_STARTSTYLING,40,$FF)
; SendMessage_(hScintilla,#SCI_SETSTYLING,213,4)
; SendMessage_(hScintilla,#SCI_STARTSTYLING,266,$FF)
; SendMessage_(hScintilla,#SCI_SETSTYLING,7,4)
 ; 
; SendMessage_(hScintilla,#SCI_SETMARGINSENSITIVEN,1,#True); active le folding
; SendMessage_(hScintilla,#SCI_SETMARGINMASKN,1,~#SC_MASK_FOLDERS);masque la couleur différente du folding
; SendMessage_(hScintilla,#SCI_MARKERDEFINE,0,#SC_MARK_ARROW) ; définit la fleche pour le droite (replié)
; SendMessage_(hScintilla,#SCI_MARKERDEFINE,1,#SC_MARK_ARROWDOWN) ; définti la fleche pour le bas (déplié)
 ; 
; SendMessage_(hScintilla,#SCI_SETFOLDFLAGS,8,1)
; SendMessage_(hScintilla,#SCI_SETFOLDLEVEL,0,#SC_FOLDLEVELHEADERFLAG)
; SendMessage_(hScintilla,#SCI_MARKERADD,0,0) ; ajoute le petit triangle : y0 triangle pointé vers la gauche 1vers le bas
; SendMessage_(hScintilla,#SCI_HIDELINES,1,6); Cacher des lignes : ligne de départ, ombre de lignes
; SendMessage_(hScintilla,#SCI_SETFOLDEXPANDED,1,1); x ? y fait une ligne endessous du folder 




DeclareDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
;- Window Constants
;
Enumeration
    #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
    #Editor_0
    #Button_0
    #Button_1
    #Button_2
    #Button_3
EndEnumeration

If  InitScintilla("D:\purebasic4\Compilers\Scintilla.dll")=0 ; on charge la dll
    MessageRequester("erreur","trouve pas la dll scintilla", #PB_MessageRequester_Ok  )
    End
EndIf




Procedure Open_Window_0()
    If OpenWindow(#Window_0, 357, 1, 499, 670, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
        If CreateGadgetList(WindowID(#Window_0)) 
            ScintillaGadget(#Editor_0, 20, 70, 460, 570, @ScintillaCallBack())
            ButtonGadget(#Button_0, 20, 20, 90, 30, "coul fond")
            ButtonGadget(#Button_1, 150, 20, 90, 30, "numero")
            ButtonGadget(#Button_2, 280, 20, 90, 30, "coul curs")
            ButtonGadget(#Button_3, 400, 20, 80, 30, "indent ligne 1") 
        EndIf
    EndIf
EndProcedure
Open_Window_0()

ScintillaSendMessage(#Editor_0, #SCI_STYLESETFORE, 0, $FF0000) ; couleur du text

Repeat ; Start of the event loop
  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
  
  GadgetID = EventGadget() ; Is it a gadget event?
  
  EventType = EventType() ; The event type
  
  ;You can place code here, and use the result as parameters for the procedures
  
  If Event = #PB_Event_Gadget
    
    If GadgetID = #Editor_0
      
    ElseIf GadgetID = #Button_0 ;on envoi un message de colorisation pour voir  
        ScintillaSendMessage(#Editor_0, #SCI_STYLESETBACK,#STYLE_DEFAULT,RGB(40,40,80)) ; couleur du fond
    ElseIf GadgetID = #Button_1 
        ScintillaSendMessage(#Editor_0,  #SCI_SETMARGINWIDTHN,0,30) ; active les numero de ligne !!!  
    ElseIf GadgetID = #Button_2
        ScintillaSendMessage(#Editor_0,#SCI_SETCARETWIDTH,5); Largeur du curseur
        ScintillaSendMessage(#Editor_0,  #SCI_SETCARETFORE,RGB(250,0,0)); couleur du curseur 
    ElseIf GadgetID = #Button_3 
        ScintillaSendMessage(#Editor_0,#SCI_SETLINEINDENTATION,1,8) ; indente  le texte de la ligne 1 de 8 espaces) 
    EndIf
    
  EndIf
  
Until Event = #PB_Event_CloseWindow ; End of the event loop

End
;


ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
    ;
    ; The ProcedureDLL declaration is important for the callback to work correctly on MacOSX,
    ; on all other OS it has no effect.
    ;
EndProcedure

Dernière modification par Backup le mar. 26/juin/2007 17:45, modifié 1 fois.
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

Comme Jeff j'avais besoin d'un exemple, ça tombe bien, donc merci à vous deux.
juste une chose, Comtois, tu utilises "scintilla.dll" et toi Dobro "SciLexer.dll", quel est al différence ?

d'avance merci :D
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

Message par wolfjeremy »

J'ai des erreur sur le nombre de parametre dans vos deux codes :? :cry:
Avatar de l’utilisateur
flaith
Messages : 1487
Inscription : jeu. 07/avr./2005 1:06
Localisation : Rennes
Contact :

Message par flaith »

wolfjeremy a écrit :J'ai des erreur sur le nombre de parametre dans vos deux codes :? :cry:
ca marche nickel pour moi, tu utilises bien la 4.10 ?
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

flaith a écrit :Comme Jeff j'avais besoin d'un exemple, ça tombe bien, donc merci à vous deux.
juste une chose, Comtois, tu utilises "scintilla.dll" et toi Dobro "SciLexer.dll", quel est al différence ?

d'avance merci :D
c'est la même dll !! elle a ete renommé pour Purebasic
en "SciLexer.dll" :D

comme elle est fourni avec tout les Japbe sous ce nom (voir dans le dossier de Purebasic ici pour moi ("D:\purebasic4\japbe4\SciLexer.dll"):D), j'ai gardé celui ci

mais son vrai nom c'est bien "scintilla.dll" !! :D

elle est présente sous le nom de scintilla dans le dossier
"compilers" de Purbasic 4.00

ps : je suis parti de cette discussion sur le forum
http://www.purebasic.fr/french/viewtopi ... =scintilla

a l'époque les appel étaient fait a l'aide de ; SendMessage_()

ex :

Code : Tout sélectionner

; SendMessage_(hScintilla,#SCI_StyleSetFore,#STYLE_DEFAULT,RGB(250,250,250)) ; couleur de la police
j'ai donc repiqué les constantes pour les appliquers a la nouvelle fonction du PureBasic !! :D

je n'arrive pas a trouver comment on indique a Scintilla la liste des mots clefs a colorer en Bleu par exemple 8O

doit y avoir un truc, mais je comprend pas !!
la doc du site de scintilla , n'est pas explicite du tout sur ce sujet !! :)

j'ai presque envie d'utiliser scintilla pour mon PureGolo3D :D

[Reedit]
voila j'ai reposter mon code pour qu'il utilise Scintilla du Purebasic
au lieu de Scilexter de JAPBE
[/Reedit]
wolfjeremy
Messages : 1202
Inscription : sam. 31/déc./2005 23:52

Message par wolfjeremy »

flaith a écrit :
wolfjeremy a écrit :J'ai des erreur sur le nombre de parametre dans vos deux codes :? :cry:
ca marche nickel pour moi, tu utilises bien la 4.10 ?
ha oui zut, j'ai la beta 1, faut que je passe à la 2.
Jeff
Messages : 72
Inscription : sam. 13/mai/2006 18:09

Message par Jeff »

Merci à tous

C'est exactement ce que je cherchais :P

@+

JF
gnozal
Messages : 832
Inscription : mar. 07/déc./2004 17:35
Localisation : France
Contact :

Message par gnozal »

Dobro a écrit :c'est la même dll !! elle a ete renommé pour Purebasic en "SciLexer.dll" :D
C'est presque la même chose.
Effectivement, scintilla.dll dans \Compilers et SciLexer.dll dans \jaPBe sont la même DLL, cependant la DLL officielle SciLexer.dll fournie avec SciTe ( http://prdownloads.sourceforge.net/scin ... p?download ) est plus complète, car elle intègre de nombreux 'lexers' pour différents languages.
Je n'ai pas choisi cette version pour jaPBe car il est optimisé pour PB, mais si on veut utiliser Scintilla pour d'autres languages que PB autant utiliser un lexer déjà existant.
Exemple (adapté d'un exemple du forum allemand) :

Code : Tout sélectionner

;
; Use Existing Lexer With Scintilla
;
; Here an example for VB
; ! Important : use SciLexer from SciTe download !
;
Procedure SetStyle(id,style,fore,back,bold=-1,italic=-1,Size=0,font.s="")
  ;
  ScintillaSendMessage(id,#SCI_STYLESETFORE, style, fore)
  ScintillaSendMessage(id,#SCI_STYLESETBACK, style, back)
  ;
  If italic > -1
    ScintillaSendMessage(id,#SCI_STYLESETITALIC, style, italic)
  EndIf
  If bold > -1
    ScintillaSendMessage(id,#SCI_STYLESETBOLD, style, bold)
  EndIf
  If Size > 0
    ScintillaSendMessage(id,#SCI_STYLESETSIZE, style, Size)
  EndIf
  If font
    ScintillaSendMessage(id,#SCI_STYLESETFONT, style, @font)
  EndIf
  ;
EndProcedure
;
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
  
  Protected line = ScintillaSendMessage(Gadget,#SCI_LINEFROMPOSITION,*scinotify\Position)
  
  If *scinotify\margin = 1
    ScintillaSendMessage(Gadget,#SCI_TOGGLEFOLD, line, 0)
  EndIf
  
EndProcedure
;
Procedure NewSciGadget(id,x,y,cx,cy,cb=0)
  Protected Gadget , keyword.s
  Static Init
  ;
  If Not Init
    InitScintilla("scilexer")
  EndIf
  ;
  Gadget = ScintillaGadget(id,x,y,cx,cy,cb)
  If id <> #PB_Any
    Gadget = id
  EndIf
  ; default lexer --> set to VB
  ScintillaSendMessage(Gadget,#SCI_SETLEXER,#SCLEX_VB)
  ScintillaSendMessage(Gadget,#SCI_SETSTYLEBITS, 5)
  ;{ Available lexers
  ; #SCLEX_CONTAINER = 0
  ; #SCLEX_NULL = 1
  ; #SCLEX_PYTHON = 2
  ; #SCLEX_CPP = 3
  ; #SCLEX_HTML = 4
  ; #SCLEX_XML = 5
  ; #SCLEX_PERL = 6
  ; #SCLEX_SQL = 7
  ; #SCLEX_VB = 8
  ; #SCLEX_PROPERTIES = 9
  ; #SCLEX_ERRORLIST = 10
  ; #SCLEX_MAKEFILE = 11
  ; #SCLEX_BATCH = 12
  ; #SCLEX_XCODE = 13
  ; #SCLEX_LATEX = 14
  ; #SCLEX_LUA = 15
  ; #SCLEX_DIFF = 16
  ; #SCLEX_CONF = 17
  ; #SCLEX_PASCAL = 18
  ; #SCLEX_AVE = 19
  ; #SCLEX_ADA = 20
  ; #SCLEX_LISP = 21
  ; #SCLEX_RUBY = 22
  ; #SCLEX_EIFFEL = 23
  ; #SCLEX_EIFFELKW = 24
  ; #SCLEX_TCL = 25
  ; #SCLEX_NNCRONTAB = 26
  ; #SCLEX_BULLANT = 27
  ; #SCLEX_VBSCRIPT = 28
  ; #SCLEX_BAAN = 31
  ; #SCLEX_MATLAB = 32
  ; #SCLEX_SCRIPTOL = 33
  ; #SCLEX_ASM = 34
  ; #SCLEX_CPPNOCASE = 35
  ; #SCLEX_FORTRAN = 36
  ; #SCLEX_F77 = 37
  ; #SCLEX_CSS = 38
  ; #SCLEX_POV = 39
  ; #SCLEX_LOUT = 40
  ; #SCLEX_ESCRIPT = 41
  ; #SCLEX_PS = 42
  ; #SCLEX_NSIS = 43
  ; #SCLEX_MMIXAL = 44
  ; #SCLEX_CLW = 45
  ; #SCLEX_CLWNOCASE = 46
  ; #SCLEX_LOT = 47
  ; #SCLEX_YAML = 48
  ; #SCLEX_TEX = 49
  ; #SCLEX_METAPOST = 50
  ; #SCLEX_POWERBASIC = 51
  ; #SCLEX_FORTH = 52
  ; #SCLEX_ERLANG = 53
  ; #SCLEX_OCTAVE = 54
  ; #SCLEX_MSSQL = 55
  ; #SCLEX_VERILOG = 56
  ; #SCLEX_KIX = 57
  ; #SCLEX_GUI4CLI = 58
  ; #SCLEX_SPECMAN = 59
  ; #SCLEX_AU3 = 60
  ; #SCLEX_APDL = 61
  ; #SCLEX_BASH = 62
  ; #SCLEX_ASN1 = 63
  ; #SCLEX_VHDL = 64
  ; #SCLEX_CAML = 65
  ; #SCLEX_BLITZBASIC = 66
  ; #SCLEX_PUREBASIC = 67
  ; #SCLEX_HASKELL = 68
  ; #SCLEX_PHPSCRIPT = 69
  ; #SCLEX_TADS3 = 70
  ; #SCLEX_REBOL = 71
  ; #SCLEX_SMALLTALK = 72
  ; #SCLEX_FLAGSHIP = 73
  ; #SCLEX_CSOUND = 74
  ; #SCLEX_FREEBASIC = 75
  ;}
  ;
  SetStyle(Gadget,#STYLE_DEFAULT, #Black, #White,#PB_Default,#PB_Default,10, "courier new")
  ScintillaSendMessage(Gadget,#SCI_STYLECLEARALL)
  ;
  ; keywords
  keyword = "addressof alias and as attribute base begin binary boolean byref byte byval call case compare "
  keyword + "const currency date decimal declare defbool defbyte defint deflng defcur defsng defdbl defdec "
  keyword + "defdate defstr defobj defvar dim do double each else elseif empty end enum eqv erase error "
  keyword + "event exit explicit false for friend function get gosub goto if imp implements in input integer "
  keyword + "is len let lib like load lock long loop lset me mid midb mod new next not nothing null object "
  keyword + "on option optional or paramarray preserve print private property public raiseevent randomize "
  keyword + "redim rem resume return rset seek select set single static step stop string sub then time to "
  keyword + "true type typeof unload until variant wend while with withevents xor"
  ;
  ScintillaSendMessage(Gadget,#SCI_SETKEYWORDS,0,@keyword)
  SetStyle(Gadget,#SCE_B_KEYWORD  , #Blue   , #White,#True)
  ;
  ScintillaSendMessage(Gadget,#SCI_SETKEYWORDS,1,@"option explicit")
  SetStyle(Gadget,#SCE_B_KEYWORD2 , #Red    , #White,#True)
  ;
  ScintillaSendMessage(Gadget,#SCI_SETKEYWORDS,2,@"glloq")
  SetStyle(Gadget,#SCE_B_KEYWORD3 , $FFFFFF , $C0C0C0)
  ;
  SetStyle(Gadget,#SCE_B_NUMBER   , #Red    , #White)
  SetStyle(Gadget,#SCE_B_COMMENT  , $C0C0C0  , #White)
  ;
  ;line number
  ScintillaSendMessage(Gadget,#SCI_SETMARGINWIDTHN, 0, 30)
  ;
  ; folding
  ScintillaSendMessage(Gadget,#SCI_SETPROPERTY, @"fold", @"1")
  ;
  ScintillaSendMessage(Gadget,#SCI_SETMARGINTYPEN,  1, #SC_MARGIN_SYMBOL)
  ScintillaSendMessage(Gadget,#SCI_SETMARGINMASKN,  1, #SC_MASK_FOLDERS)
  ScintillaSendMessage(Gadget,#SCI_SETMARGINWIDTHN, 1, 20)
  ;
  ScintillaSendMessage(Gadget,#SCI_SETMARGINSENSITIVEN, 1, 1)
  ;
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPEN     , #SC_MARK_MINUS)
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDER         , #SC_MARK_PLUS)
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERSUB      , #SC_MARK_EMPTY)
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERTAIL     , #SC_MARK_EMPTY)
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEREND      , #SC_MARK_EMPTY)
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDEROPENMID  , #SC_MARK_EMPTY)
  ScintillaSendMessage(Gadget,#SCI_MARKERDEFINE, #SC_MARKNUM_FOLDERMIDTAIL  , #SC_MARK_EMPTY)
  ;
EndProcedure
;
Procedure Main()
  Protected hwnd
  ;
  hwnd = OpenWindow(0,#PB_Ignore,#PB_Ignore,640,480,"leer",#WS_OVERLAPPEDWINDOW)
  SmartWindowRefresh(0,1)
  CreateGadgetList(hwnd)
  ;
  NewSciGadget(0,0,0,640,480,@ScintillaCallBack())
  ; Test code
  text.s = "Function test()"        + #lf$
  text.s + "  ' glloq"               + #lf$
  text.s + "  Dim glloq as Integer " + #lf$
  text.s + "End Function "          + #lf$
  SetGadgetText(0,text+#lf$+text)
  ; Events
  Repeat
    event = WaitWindowEvent()
    If event = #PB_Event_SizeWindow
      ResizeGadget(0,#PB_Ignore,#PB_Ignore,WindowWidth(0),WindowHeight(0))
    EndIf
  Until event = #PB_Event_CloseWindow
  ;
EndProcedure
;
Main()
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

j'ai voulu adapter a mon exemple !

d'apres ce que j'ai compris on creer une chaine contenant les mots a colorer
ex :

Code : Tout sélectionner

 key.s="goto print next"
puis on balance a la dll l'adresse de la chaine style :

Code : Tout sélectionner

ScintillaSendMessage(#Editor_0,#SCI_SETKEYWORDS,0,@key.s) ; on envoi l'adresse des mots clef pour coloration
ensuite on donne l'ordre de coloration avec

Code : Tout sélectionner

SetStyle(#Editor_0,#SCE_B_KEYWORD , #Red  , #White,#True) ; en principe active la coloration !!!!!!
seulement ça marche pas ! :?

mon exemple : () voir les ligne 96--->

Code : Tout sélectionner


; SendMessage_(hScintilla,#SCI_StyleSetFore,#STYLE_DEFAULT,RGB(250,250,250)) ; couleur de la police
; SendMessage_(hScintilla,#SCI_STYLESETBACK,#STYLE_DEFAULT,RGB(40,40,80)) ; couleur du fond
; SendMessage_(hScintilla,#SCI_STYLECLEARALL,0,0);
; SendMessage_(hScintilla,#SCI_StyleSetFore,1,RGB(0,250,0)); définti une liste de couleur comme en rtf
; SendMessage_(hScintilla,#SCI_StyleSetFore,2,RGB(0,250,250));
; SendMessage_(hScintilla,#SCI_StyleSetFore,3,RGB(250,250,0));
; SendMessage_(hScintilla,#SCI_StyleSetFore,4,RGB(250,100,0));
; SendMessage_(hScintilla,#SCI_STYLESETBACK,#STYLE_LINENUMBER,RGB(80,80,160)) ; fond
; SendMessage_(hScintilla,#SCI_StyleSetFore,#STYLE_LINENUMBER,RGB(250,250,250)); écriture
; SendMessage_(hScintilla,#SCI_SETMARGINWIDTHN,0,30);  Affiche les numero des lignes
; SendMessage_(hScintilla,#SCI_SETSELBACK,#True,RGB(0,100,150)); Détermine la couleur de fond de la sélection
; SendMessage_(hScintilla,#SCI_SETSELFORE,#False,0); La couleur du texte sélectionné est inchangée
; SendMessage_(hScintilla,#SCI_SETCARETFORE,RGB(250,200,100),0); Couleur du curseur
; SendMessage_(hScintilla,#SCI_SETCARETWIDTH,2,0); Largeur du curseur
; SendMessage_(hScintilla,#SCI_SETINDENTATIONGUIDES,#True,0) ; Affiche le guide d'indentation
; SendMessage_(hScintilla,#SCI_SETINDENT,8,0) ; Détermine la longueur de la tabulation

; SendMessage_(hScintilla,#SCI_INSERTTEXT,-1,Texte$) ; insère le texte à la fin !
; For t=1 To 6
    ; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,t,8) ; indente  le texte de 8 espaces
; Next
; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,2,16)
; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,4,16)
; SendMessage_(hScintilla,#SCI_SETLINEINDENTATION,6,16)
 ; 
; SendMessage_(hScintilla,#SCI_STARTSTYLING,9,$FF);x=début de la coloration y=??
; SendMessage_(hScintilla,#SCI_SETSTYLING,8,1) ;x=nombre de caractère y : numéro de couleur dans le dico
; SendMessage_(hScintilla,#SCI_STARTSTYLING,29,$FF)
; SendMessage_(hScintilla,#SCI_SETSTYLING,7,2)
; SendMessage_(hScintilla,#SCI_STARTSTYLING,40,$FF)
; SendMessage_(hScintilla,#SCI_SETSTYLING,213,4)
; SendMessage_(hScintilla,#SCI_STARTSTYLING,266,$FF)
; SendMessage_(hScintilla,#SCI_SETSTYLING,7,4)
 ; 
; SendMessage_(hScintilla,#SCI_SETMARGINSENSITIVEN,1,#True); active le folding
; SendMessage_(hScintilla,#SCI_SETMARGINMASKN,1,~#SC_MASK_FOLDERS);masque la couleur différente du folding
; SendMessage_(hScintilla,#SCI_MARKERDEFINE,0,#SC_MARK_ARROW) ; définit la fleche pour le droite (replié)
; SendMessage_(hScintilla,#SCI_MARKERDEFINE,1,#SC_MARK_ARROWDOWN) ; définti la fleche pour le bas (déplié)
 ; 
; SendMessage_(hScintilla,#SCI_SETFOLDFLAGS,8,1)
; SendMessage_(hScintilla,#SCI_SETFOLDLEVEL,0,#SC_FOLDLEVELHEADERFLAG)
; SendMessage_(hScintilla,#SCI_MARKERADD,0,0) ; ajoute le petit triangle : y0 triangle pointé vers la gauche 1vers le bas
; SendMessage_(hScintilla,#SCI_HIDELINES,1,6); Cacher des lignes : ligne de départ, ombre de lignes
; SendMessage_(hScintilla,#SCI_SETFOLDEXPANDED,1,1); x ? y fait une ligne endessous du folder 


;ScintillaSendMessage(Gadget,#SCI_SETKEYWORDS,0,@keyword)
;SetStyle(Gadget,#SCE_B_KEYWORD  , #Blue   , #White,#True) 

DeclareDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
Declare  SetStyle(id,style,fore,back,bold=-1,italic=-1,Size=0,font.s="")
;- Window Constants
;
Enumeration
    #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
    #Editor_0
    #Button_0
    #Button_1
    #Button_2
    #Button_3
EndEnumeration

If  InitScintilla("D:\purebasic4\japbe4\SciLexer.dll")=0 ; on charge la dll
    MessageRequester("erreur","trouve pas la dll scintilla", #PB_MessageRequester_Ok  )
    End
EndIf





Procedure Open_Window_0()
    If OpenWindow(#Window_0, 357, 1, 499, 670, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
        SmartWindowRefresh(0,1) 
        If CreateGadgetList(WindowID(#Window_0)) 
            ScintillaGadget(#Editor_0, 20, 70, 460, 570, @ScintillaCallBack()) 
            ButtonGadget(#Button_0, 20, 20, 90, 30, "coul fond")
            ButtonGadget(#Button_1, 150, 20, 90, 30, "numero")
            ButtonGadget(#Button_2, 280, 20, 90, 30, "coul curs")
            ButtonGadget(#Button_3, 400, 20, 80, 30, "indent ligne 1") 
        EndIf
    EndIf
EndProcedure
Open_Window_0()

; ScintillaSendMessage(#Editor_0,#SCI_SETLEXER,#SCLEX_VB)
; ScintillaSendMessage(#Editor_0,#SCI_SETSTYLEBITS, 5) 

key.s="goto print for next " ; on defini les mots clef a colorer en rouge
ScintillaSendMessage(#Editor_0,#SCI_SETKEYWORDS,0,@key.s) ; on envoi l'adresse des mots clef pour coloration
SetStyle(#Editor_0,#SCE_B_KEYWORD , #Red  , #White,#True) ; en principe active la coloration !!!!!! <------------------------- hum !!


; ScintillaSendMessage(#Editor_0, #SCI_STYLESETFORE, 0, $0) ; couleur du text
; ScintillaSendMessage(#Editor_0, #SCI_STYLESETBACK,#STYLE_DEFAULT,RGB(255,255,150)) ; couleur du fond
SetStyle(#Editor_0,#STYLE_DEFAULT, #Black, #White,#PB_Default,#PB_Default,10, "courier new") 
ScintillaSendMessage(#Editor_0,#SCI_STYLECLEARALL) ; on efface tout


Repeat ; Start of the event loop  
    Event = WaitWindowEvent() ; This line waits until an event is received from Windows 
    WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures 
    GadgetID = EventGadget() ; Is it a gadget event? 
    EventType = EventType() ; The event type 
    ;You can place code here, and use the result as parameters for the procedures 
    If Event = #PB_Event_Gadget 
        If GadgetID = #Editor_0 
        ElseIf GadgetID = #Button_0 ;on envoi un message de colorisation pour voir  
            ScintillaSendMessage(#Editor_0, #SCI_STYLESETBACK,#STYLE_DEFAULT,RGB(40,40,80)) ; couleur du fond
        ElseIf GadgetID = #Button_1 
            ScintillaSendMessage(#Editor_0,  #SCI_SETMARGINWIDTHN,0,30) ; active les numero de ligne !!!  
        ElseIf GadgetID = #Button_2
            ScintillaSendMessage(#Editor_0,#SCI_SETCARETWIDTH,3); Largeur du curseur
            ScintillaSendMessage(#Editor_0,  #SCI_SETCARETFORE,RGB(250,0,0)); couleur du curseur 
        ElseIf GadgetID = #Button_3 
            ScintillaSendMessage(#Editor_0,#SCI_SETLINEINDENTATION,1,8) ; indente  le texte de la ligne 1 de 8 espaces) 
        EndIf
        
    EndIf 
Until Event = #PB_Event_CloseWindow ; End of the event loop

End
;


ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification)
    ;
    ; The ProcedureDLL declaration is important for the callback to work correctly on MacOSX,
    ; on all other OS it has no effect. 
    
    
EndProcedure
Procedure SetStyle(id,style,fore,back,bold=-1,italic=-1,Size=0,font.s="")
    ;
    ScintillaSendMessage(id,#SCI_STYLESETFORE, style, fore)
    ScintillaSendMessage(id,#SCI_STYLESETBACK, style, back)
    ;
    If italic > -1
        ScintillaSendMessage(id,#SCI_STYLESETITALIC, style, italic)
    EndIf
    If bold > -1
        ScintillaSendMessage(id,#SCI_STYLESETBOLD, style, bold)
    EndIf
    If Size > 0
        ScintillaSendMessage(id,#SCI_STYLESETSIZE, style, Size)
    EndIf
    If font
        ScintillaSendMessage(id,#SCI_STYLESETFONT, style, @font)
    EndIf
    ;
EndProcedure 
Répondre