Editeur de texte

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Editeur de texte

Message par Stefou »

Salut les accros de l'info

J'ai besoins d'un editeur de texte avec toutes les fonctions classiques (couleur, taille police, centrage, retour à la ligne automatique,sauvegarde...)

J'ai commençer à dégrossir cela avec ce que j'ai trouvé de ci de là.

Je travail dans un editor gadget.

Je n'arrive pas à faire le renvoie automatique à la ligne.

Est ce que quelqu'un à déjà un projet de ce genre, bien avancé.


Salut tous et bon week end.
Stefou
Avatar de l’utilisateur
Jacobus
Messages : 1559
Inscription : mar. 06/avr./2004 10:35
Contact :

Message par Jacobus »

Juste après avoir créé ton éditeur tu places l' API suivante de cette façon :

exemple :

Code : Tout sélectionner

EditorGadget(#EDITOR, 5, 30, 775, 420)
 SendMessage_(GadgetID(#EDITOR), #EM_SETTARGETDEVICE, #Null, 0);<<--- retour à la ligne automatique
;ensuite tes items si besoin est
AddGadgetItem(#EDITOR, -1, Texte$ )
AddGadgetItem(#EDITOR, -1, "" )
AddGadgetItem(#EDITOR, -1, Texte$ )
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Message par Stefou »

Merci beaucoup Jacobus.

Je post mon code d'içi peu....

a+ et bonne semaine à tous les travailleurs
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Message par Stefou »

Une première ébauche...

Pour enregistrer le format du texte (couleur, taille), je procede caractère par caractère. Si quelqu'un à une autre solution cela m'interesse.
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Message par Stefou »

Bon voilà c'est quasiment au point.
Je joins le code d'un éditeur de texte avec format du texte : gras, italique, souligné,couleur, fond,..... et enregistrement.

Il n'est pas jolie, mais c'est juste le fait d'avoir les fonctions sous la main.

Reste un bug : la suppression de la couleur de fond intervient seulement apres avoir enregistré et réouvert.

Bonne journée à tous.
Dernière modification par Stefou le mer. 28/févr./2007 10:09, modifié 1 fois.
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Stefou a écrit :Reste un bug : la suppression de la couleur de fond intervient seulement apres avoir enregistré et réouvert.
Il faut ouvrir ton fichier en mode RTF et non en mode texte.
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Bravo, du bon boulot 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

quel lib as tu utiliser

j'arrive pas à le lancer ..
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Message par Stefou »

Super le RTF !!! :D :D :D
En pompant un code de Nico, j'ai refais l'enregistrement et la lecture.

J'ai rajouter un bout de code (encore pompé) pour insérer un tableau en appuyant sur F6

Le bug persiste, je n'arrive pas à colorier le fond d'un texte avec une couleur -1 :
Explication : je colorie le fond de mon texte en rouge, puis apres reflexion je ne veux plus qu'il soit colorier en rouge, il faut donc le décolorier et là je n'y arrive pas !

J'arrive bien à décolorier le texte, mais pas le fond du texte.

a+
Stefou

Code : Tout sélectionner

Global nom_fichier_note_pad$,MaxD,code_fin_sauvegarde_texte$,code_fin_sauvegarde_format$

nom_fichier_note_pad$="text_note_pad.txt" 
code_fin_sauvegarde_texte$="#FIN_TXT#"
code_fin_sauvegarde_format$="#FIN_FORMAT#"


Procedure.b ReadBin(Valeur.l, Position);permet de lire un byte à la position 
     If Valeur & (%1 << Position)
          ProcedureReturn 1
     Else
          ProcedureReturn 0
     EndIf
EndProcedure

Global Dim Couleur_Base(10)
Global Dim Couleur_perso(2,10)
Global Dim Nom_Font.s(1)
Nom_Font(0)="0"
Procedure Initialise_couleur(); couleur de la palette de base
     
     i=0
     Couleur_Base(i)= 0  :  i=i+1
     Couleur_Base(i)= 1  :  i=i+1
     Couleur_Base(i)= $0000FF  :  i=i+1
     Couleur_Base(i)= $00FFFF :  i=i+1
     Couleur_Base(i)= $FF00FF  :  i=i+1
     Couleur_Base(i)= $00FF00  :  i=i+1
     Couleur_Base(i)= $FFFF00  :  i=i+1
     Couleur_Base(i)= $FF0000  :  i=i+1
     Couleur_Base(i)= $008000  :  i=i+1
     
     Couleur_Base(i)= $FFFFFF  :  i=i+1
     
     
     For i=0 To 2
          For j=0 To 9
               Couleur_perso(i,j)=$E26152
          Next
          
     Next
     
EndProcedure
Procedure Test_Font_Doublon(nom_font$);Test si le nom de la police est déjà dans la liste
     For i=1 To Val(Nom_Font(0))
          If Nom_Font(i)=nom_font$
               ProcedureReturn 0
          EndIf
          
     Next
     ProcedureReturn 1
EndProcedure
Procedure Ajout_Nom_Font(nom_font$);Ajoute le nom de la police à la liste des polices
     If Test_Font_Doublon(nom_font$)
          nb_ele=Val(Nom_Font(0))+1
          Redim Nom_Font.s(nb_ele)
          Nom_Font(nb_ele)=nom_font$
          Nom_Font(0)=Str(nb_ele)
     EndIf
     
EndProcedure
Procedure EnumFontFamProc(lpelf.l, lpntm.l, FontType.l, lParam.l)
     Static FontCounter.l
     *lpelf.ENUMLOGFONT = lpelf
     sFontType.s = ""
     TrueType = #False
     If FontType & #DEVICE_FONTTYPE
          sFontType.s + "Device "
     EndIf
     If FontType & #RASTER_FONTTYPE
          sFontType.s + "Raster "
     EndIf
     If FontType & #TRUETYPE_FONTTYPE 
          sFontType.s + "TrueType "
          TrueType = #True
     EndIf
     FontHeight = *lpelf\elfLogFont\lfHeight
     FontWidth = *lpelf\elfLogFont\lfWidth
     FontEscapement = *lpelf\elfLogFont\lfEscapement
     FontOrientation = *lpelf\elfLogFont\lfOrientation
     FontWeight = *lpelf\elfLogFont\lfWeight
     FontItalic = *lpelf\elfLogFont\lfItalic
     FontUnderline = *lpelf\elfLogFont\lfUnderline
     FontStrikeOut = *lpelf\elfLogFont\lfStrikeOut
     FontCharSet = *lpelf\elfLogFont\lfCharSet
     FontOutPrecision = *lpelf\elfLogFont\lfOutPrecision
     FontClipPrecision = *lpelf\elfLogFont\lfClipPrecision
     FontQuality = *lpelf\elfLogFont\lfQuality
     FontPitchAndFamily = *lpelf\elfLogFont\lfPitchAndFamily
     FontName.s = ""
     i = 0
     While *lpelf\elfFullName[i] <>0
          FontName + Chr(*lpelf\elfFullName[i])
          i + 1
     Wend
     FontStyle.s = ""
     i = 0
     While *lpelf\elfStyle[i] <>0
          FontStyle + Chr(*lpelf\elfStyle[i])
          i + 1
     Wend
     If TrueType
          *lpntm1.NEWTEXTMETRIC = lpntm
          MetricHeight = *lpntm1\tmHeight
          MetricAscent = *lpntm1\tmAscent
          MetricDescent = *lpntm1\tmDescent
          MetricInternalLeading = *lpntm1\tmInternalLeading
          MetricExternalLeading = *lpntm1\tmExternalLeading
          MetricAveCharWidth = *lpntm1\tmAveCharWidth
          MetricMaxCharWidth = *lpntm1\tmMaxCharWidth
          MetricWeight = *lpntm1\tmWeight
          MetricOverhang = *lpntm1\tmOverhang
          MetricDigitizedAspectX = *lpntm1\tmDigitizedAspectX
          MetricDigitizedAspectY = *lpntm1\tmDigitizedAspectY
          MetricFirstChar = *lpntm1\tmFirstChar
          MetricLastChar = *lpntm1\tmLastChar
          MetricDefaultChar = *lpntm1\tmDefaultChar
          MetricBreakChar = *lpntm1\tmBreakChar
          MetricItalic = *lpntm1\tmItalic
          MetricUnderlined = *lpntm1\tmUnderlined
          MetricStruckOut = *lpntm1\tmStruckOut
          MetricPitchAndFamily = *lpntm1\tmPitchAndFamily
          MetricCharSet = *lpntm1\tmCharSet
          MetricFlags = *lpntm1\ntmFlags
          MetricSizeEM = *lpntm1\ntmSizeEM
          MetricCellHeight = *lpntm1\ntmCellHeight
          MetricAveWidth = *lpntm1\ntmAveWidth
     Else
          *lpntm2.TEXTMETRIC = lpntm
          MetricHeight = *lpntm2\tmHeight
          MetricAscent = *lpntm2\tmAscent
          MetricDescent = *lpntm2\tmDescent
          MetricInternalLeading = *lpntm2\tmInternalLeading
          MetricExternalLeading = *lpntm2\tmExternalLeading
          MetricAveCharWidth = *lpntm2\tmAveCharWidth
          MetricMaxCharWidth = *lpntm2\tmMaxCharWidth
          MetricWeight = *lpntm2\tmWeight
          MetricOverhang = *lpntm2\tmOverhang
          MetricDigitizedAspectX = *lpntm2\tmDigitizedAspectX
          MetricDigitizedAspectY = *lpntm2\tmDigitizedAspectY
          MetricFirstChar = *lpntm2\tmFirstChar
          MetricLastChar = *lpntm2\tmLastChar
          MetricDefaultChar = *lpntm2\tmDefaultChar
          MetricBreakChar = *lpntm2\tmBreakChar
          MetricItalic = *lpntm2\tmItalic
          MetricUnderlined = *lpntm2\tmUnderlined
          MetricStruckOut = *lpntm2\tmStruckOut
          MetricPitchAndFamily = *lpntm2\tmPitchAndFamily
          MetricCharSet = *lpntm2\tmCharSet
     EndIf
     sFontAttributes.s = ""
     If FontItalic
          sFontAttributes + "I"
     EndIf
     If FontUnderline
          sFontAttributes + "U"
     EndIf
     If FontStrikeOut
          sFontAttributes + "S"
     EndIf
     If sFontAttributes <> ""
          sFontAttributes = "(" + sFontAttributes + ")"
     EndIf
     If lParam
          If FindString(LCase(FontName), LCase(PeekS(lParam)), 1)
               
               nom_font$=FontName
               Debug "***** "+nom_font$
               Ajout_Nom_Font(nom_font$)
          EndIf
     Else
          
          nom_font$=FontName
          Debug "****- "+nom_font$
          Ajout_Nom_Font(nom_font$)
     EndIf
     While WindowEvent()
     Wend
     FontCounter + 1
     ProcedureReturn 1
EndProcedure
Procedure list_font(id_window,id_gadget)
     ClearGadgetItemList(id_gadget)
     Ajout_Nom_Font("//Base//")
     EnumFontFamilies_(GetDC_(WindowID(id_window)), #Null, @EnumFontFamProc(), 0)
     nb_ele=Val(Nom_Font(0))
     Nom_Font(0)=""
     SortArray(Nom_Font(),2)
     For i=1 To nb_ele
          AddGadgetItem(id_gadget,-1,Nom_Font(i))
     Next
     SetGadgetState(id_gadget,0)
     
EndProcedure

Enumeration #PB_Compiler_EnumerationValue
     #note_pad_ID
     #notepade_load
     #notepade_save
     #notepade_zoom
     
     #notepade_alig_gauche
     #notepade_alig_centre
     #notepade_alig_droite
     #notepade_text_plus
     #notepade_text_moins

     #notepade_gras
     #notepade_italique
     #notepade_surligner
     #notepade_barrer
     ;ne pas changer l'ordre d'ici
     #im_coul_texte
     #im_coul_fond
     #im_coul_page
     ;ne pas changer l'ordre a ici
     #notepade_liste_font
EndEnumeration

Procedure Create_palette(id_im,l,h)
     Select id_im
          Case #im_coul_texte
               num_pal=0
          Case #im_coul_fond
               num_pal=1
               
          Case #im_coul_page
               num_pal=2
     EndSelect
     
     CreateImage(id_im,l,h)
     StartDrawing(ImageOutput(id_im))
     Box(0,0,l,h,$C0C0C0)
     For i=0 To 10
          Box(i*l/10,0,l/10-1,h/2-1,$9A9A9A) 
     Next
     Box(1,0+1,l/10-3,h/2-3,$FFFFFF) 
     LineXY(1,0+1,l/10-3,h/2-3,$0000FF)
     For i=1 To 10
          Box(i*l/10+1,0+1,l/10-3,h/2-3,Couleur_Base(i)) 
     Next
     For i=0 To 10
          Box(i*l/10+1,h/2+1,l/10-3,h/2-3,Couleur_perso(num_pal,i)) 
     Next
     StopDrawing()
     SetGadgetState(id_im,ImageID( id_im))
     
EndProcedure
Procedure Dessine_palette()
     ;HideGadget(#note_pad_ID,1)
     x=GadgetX(#note_pad_ID)
     y=GadgetY(#note_pad_ID)+20;+GadgetHeight(#note_pad_ID)+40
     l=GadgetWidth(#note_pad_ID)
     h=GadgetHeight(#note_pad_ID)
     espace=15
     l_pal=l/3-espace
     h_pal=40
     TextGadget(#PB_Any,x,y+h,l_pal,h_pal,"Couleur du texte" )
     TextGadget(#PB_Any,x+l_pal+espace,y+h,l_pal,h_pal,"Couleur du fond du texte" )
     TextGadget(#PB_Any,x+2*l_pal+2*espace,y+h,l_pal,h_pal,"Couleur de la page" )
     ImageGadget(#im_coul_texte,x,y+h+20,l_pal,h_pal,0)
     Create_palette(#im_coul_texte,l_pal,h_pal)
     ImageGadget(#im_coul_fond,x+l_pal+espace,y+h+20,l_pal,h_pal,0)
     Create_palette(#im_coul_fond,l_pal,h_pal)
     ImageGadget(#im_coul_page,x+2*l_pal+2*espace,y+h+20,l_pal,h_pal,0)
     Create_palette(#im_coul_page,l_pal,h_pal)
     TextGadget(#PB_Any,x+l_pal+espace,y+h+20+h_pal,l_pal,20,"Clic droit pour choisir une couleur" )
     
     TextGadget(#PB_Any,x+l_pal+espace,y+h+40+h_pal,l_pal,20,"F6 pour inserer un tableau" )
EndProcedure
Procedure CreateNotepad(x,y,l,h)
     
     pos=x
     
     EditorGadget(#note_pad_ID,x,y+20,l,h-60)
     SendMessage_(GadgetID(#note_pad_ID), #EM_SETTARGETDEVICE, #Null, 0) ;retour à la ligne automatique
     pos=x
     h_g=20
     l_g=40
     ButtonGadget(#notepade_load,pos,y,l_g,h_g,"Ouvrir")
     pos=pos+l_g+2
     l_g=50
     ButtonGadget(#notepade_save,pos,y,l_g,h_g,"Enregistrer")
     pos=pos+l_g+2+5
     l_g=25
     
     ButtonGadget(#notepade_alig_gauche,pos,y,l_g,h_g,"G",#PB_Button_Toggle )
     pos=pos+l_g+2
     ;l_g=40
     ButtonGadget(#notepade_alig_centre,pos,y,l_g,h_g,"C",#PB_Button_Toggle )
     pos=pos+l_g+2
     ;l_g=40
     ButtonGadget(#notepade_alig_droite,pos,y,l_g,h_g,"D",#PB_Button_Toggle )
     l_g=45
     pos=pos+l_g+2
     ButtonGadget(#notepade_text_moins,pos,y,l_g,h_g,"Texte -")
     pos=pos+l_g+2
     ButtonGadget(#notepade_text_plus,pos,y,l_g,h_g,"Texte +")
     
     pos=pos+l_g+2
     l_g=20
     ButtonGadget(#notepade_gras,pos,y,l_g,h_g,"G",#PB_Button_Toggle )
     pos=pos+l_g+2
     ButtonGadget(#notepade_italique,pos,y,l_g,h_g,"I",#PB_Button_Toggle )
     pos=pos+l_g+2
     ButtonGadget(#notepade_surligner,pos,y,l_g,h_g,"S",#PB_Button_Toggle )
     pos=pos+l_g+2
     ButtonGadget(#notepade_barrer,pos,y,l_g,h_g,"B",#PB_Button_Toggle )
     pos=pos+l_g+2
     ComboBoxGadget(#notepade_liste_font,pos,y,160,300 )
     pos=pos+l_g+2
     
     Maxrange=100 
     MaxD=Maxrange/10 +1
     TrackBarGadget(#notepade_zoom, x+l-60, y,60,20, 1, Maxrange ) 
     Dessine_palette()
     
EndProcedure

Procedure Selection_SelectAll(editorgadget)
     range.CHARRANGE\cpMin = 0 
     range\cpMax = -1 
     ProcedureReturn SendMessage_(GadgetID(editorgadget),#EM_EXSETSEL,0,@range) 
EndProcedure
Procedure Selection_Select(Gadget, LineStart.l, CharStart.l, LineEnd.l, CharEnd.l)    
     sel.CHARRANGE 
     sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineStart, 0) + CharStart - 1 
     
     If LineEnd = -1 
          LineEnd = SendMessage_(GadgetID(Gadget), #EM_GETLINECOUNT, 0, 0)-1 
     EndIf 
     sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, LineEnd, 0) 
     
     If CharEnd = -1 
          sel\cpMax + SendMessage_(GadgetID(Gadget), #EM_LINELENGTH, sel\cpMax, 0) 
     Else 
          sel\cpMax + CharEnd - 1 
     EndIf 
     SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel) 
EndProcedure 
  
;- Format par charactere
Procedure Get_Selection_Color(Gadget) 
     
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\dwMask = #CFM_COLOR 
     SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format) 
     ProcedureReturn format\crTextColor
EndProcedure 
Procedure Get_Selection_BackColor(Gadget) 
     
     format.CHARFORMAT2 
     
     format\cbSize = SizeOf(CHARFORMAT2) 
     format\dwMask = $4000000;#CFM_COLOR 

     SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format) 
     ProcedureReturn format\crBackColor
EndProcedure 
Procedure Get_Selection_Taille(Gadget) 
     
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\dwMask = #CFM_SIZE 
     format\yHeight= Taille
     format\crTextColor = Color 
     SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format) 
     ProcedureReturn format\yHeight
EndProcedure 
Procedure Get_Selection_Effect(Gadget) 
     
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\dwMask = #CFM_BOLD 
     SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format)
     ProcedureReturn format\dwEffects
EndProcedure 
Procedure.s Get_Selection_Font(Gadget) 
     
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\dwMask = #CFM_FACE 
     SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format)
     FontName.s=PeekS(@format\szFaceName )
     ProcedureReturn FontName
EndProcedure 
Procedure Set_Selection_Font(Gadget,FontName.s)
     format.CHARFORMAT
     format\cbSize = SizeOf(CHARFORMAT)
     format\dwMask = #CFM_FACE
     PokeS(@format\szFaceName, FontName)
     SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure
Procedure Set_Selection_Effect(Gadget, effect,type) 
     
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\dwMask = effect	
     format\dwEffects = type		
     SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) 
EndProcedure 
Procedure Set_Selection_Taille(Gadget, Taille.l) 
     
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\yHeight= Taille
     format\dwMask = #CFM_SIZE	
     format\crTextColor = Color 
     SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) 
EndProcedure 
Procedure Set_Selection_Color(Gadget, Color.l) 
     
     Debug Color
     format.CHARFORMAT 
     
     format\cbSize = SizeOf(CHARFORMAT) 
     format\dwMask = #CFM_COLOR 
     format\crTextColor = Color 
     SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) 
EndProcedure 
Procedure Set_Selection_BackColor(Gadget, Color.l) 
     Debug "setcolor"
     Debug Color
     format.CHARFORMAT2;_ 
     format\cbSize = SizeOf(CHARFORMAT2);_) 
     format\dwMask = $4000000  ; = #CFM_BACKCOLOR 
     format\crBackColor = Color 
     SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format) 
EndProcedure
     
;- Format par paragraphe
Procedure Get_Selection_paragraphe(Gadget)
     format.PARAFORMAT
     
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_ALIGNMENT
     SendMessage_(GadgetID(Gadget), #EM_GETPARAFORMAT, 0, @format)
     ProcedureReturn format\wAlignment
EndProcedure
Procedure Get_Selection_decallage_gauche(Gadget)
     format.PARAFORMAT
     
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_OFFSETINDENT	
     SendMessage_(GadgetID(Gadget), #EM_GETPARAFORMAT, 0, @format)
     ProcedureReturn format\dxStartIndent
EndProcedure
Procedure Get_Selection_decallage_droite(Gadget)
     format.PARAFORMAT
     
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_RIGHTINDENT	
     SendMessage_(GadgetID(Gadget), #EM_GETPARAFORMAT, 0, @format)
     ProcedureReturn format\dxRightIndent
EndProcedure
Procedure Get_Selection_decallage_gauche_ss_premiere_ligne(Gadget)
     format.PARAFORMAT
     
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_OFFSET
     SendMessage_(GadgetID(Gadget), #EM_GETPARAFORMAT, 0, @format)
     ProcedureReturn format\dxOffset
EndProcedure
     
Procedure Set_Selection_decallage_gauche_ss_premiere_ligne(Gadget,decallage)
     format.PARAFORMAT
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_OFFSET			
     format\dxOffset = decallage
     SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @format) 
EndProcedure
Procedure Set_Selection_decallage_droite(Gadget,decallage)
     format.PARAFORMAT
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_RIGHTINDENT		
     format\dxRightIndent = decallage
     SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @format) 
EndProcedure
Procedure Set_Selection_decallage_gauche(Gadget,decallage)
     format.PARAFORMAT
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_OFFSETINDENT	
     format\dxStartIndent = decallage
     SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @format) 
EndProcedure
Procedure Set_Selection_paragraphe(Gadget,paragraphe)
     format.PARAFORMAT
     format\cbSize = SizeOf(PARAFORMAT) 
     format\dwMask = #PFM_ALIGNMENT
     format\wAlignment = paragraphe
     SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @format) 
EndProcedure

Procedure.s TableauRTF(nbcol,nbligne,largeur)
     result.s = "{\rtf1\trowd"
     For i=1 To nbcol
          result + "\cellx"+Str(i*largeur)
     Next
     For j=1 To nbligne
          result + "\intbl"
          For i=1 To nbcol
               result + "\cell"
          Next
          result + "\row"
     Next
     result + "}"
     ProcedureReturn result
EndProcedure 

Procedure EditorGadgetCursorX(Gadget) 
     ; returns X-Pos of Cursor 
     REG = GadgetID(Gadget) 
     SendMessage_(REG,#EM_EXGETSEL,0,range.CHARRANGE) 
     ProcedureReturn (range\cpMax-(SendMessage_(REG,#EM_LINEINDEX,SendMessage_(REG,#EM_EXLINEFROMCHAR,0,range\cpMin),0))+1) 
EndProcedure 
Procedure EditorGadgetCursorY(Gadget) 
     ; returns Y-Pos of Cursor 
     REG = GadgetID(Gadget) 
     SendMessage_(REG,#EM_EXGETSEL,0,range.CHARRANGE) 
     ProcedureReturn SendMessage_(REG,#EM_EXLINEFROMCHAR,0,range\cpMin)+1 
EndProcedure 
Procedure EditorGadgetCursorPos(Gadget) 
     ; returns relative Position of Cursor 
     SendMessage_(GadgetID(Gadget),#EM_EXGETSEL,0,range.CHARRANGE) 
     ProcedureReturn range\cpMax 
EndProcedure 
Procedure EditorGadgetLocate(Gadget,x,y) 
     ; Set cursor position 
     REG = GadgetID(Gadget) 
     CharIdx = SendMessage_(REG,#EM_LINEINDEX,y-1,0) 
     LLength = SendMessage_(REG,#EM_LINELENGTH,CharIdx,0) 
     If LLength >= x-1 
          CharIdx + x-1 
     EndIf 
     range.CHARRANGE 
     range\cpMin = CharIdx 
     range\cpMax = CharIdx 
     SendMessage_(REG,#EM_EXSETSEL,0,range) 
EndProcedure 

Procedure Write_Format(ligne_debut,ligne_fin,debut,fin,couleur,couleur_fond,Taille,effect,paragraphe,FontName$)
     
     Debug Str(ligne_debut)+" : "+Str(ligne_fin)+" : "+Str(debut)+" : "+Str(fin)+" : "+Str(couleur)+" : "+Str(couleur_fond)+" : "+Str(Taille)+" : "
     WriteLong(0,     ligne_debut)
     WriteLong(0,     ligne_fin)
     WriteLong(0,     debut)
     WriteLong(0,     fin)
     WriteLong(0,     couleur)
     
     If couleur_fond=0
          couleur_fond=-1
     EndIf
     
     WriteLong(0,     couleur_fond)
     WriteLong(0,     Taille)
     WriteLong(0,     effect)
     WriteLong(0,     paragraphe)
     WriteStringN(0,FontName$)
EndProcedure
Procedure sauve_editor1(id_gadget,nom_fichier$) ; procedure plus utilisé, mais je la garde sous le coude !
     Debug "SAUVE"
     ;AddGadgetItem(id_gadget, 0,"")
     If CreateFile(0,nom_fichier$)
          ;{Enregistrement du texte
          WriteStringN(0,GetGadgetText(id_gadget))
          WriteStringN(0,code_fin_sauvegarde_texte$)
          ;}
          
          ;{Enregistrement des parametres bases et de départ
          zoom=GetGadgetState(#notepade_zoom) 
          WriteLong(0,     zoom)
          WriteLong(0,     GetGadgetColor(id_gadget,#PB_Gadget_BackColor))
          ;}
          
          
          format.CHARFORMAT2 
          format\cbSize = SizeOf(CHARFORMAT2) 
          format\dwMask = #CFM_COLOR | #CFM_SIZE |#CFM_BOLD|#CFM_FACE 
          
          Selection_Select(id_gadget, 0, 1, 0, 1) 
          SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format) 
          couleur= format\crTextColor
          couleur_fond= format\crBackColor
          Taille= format\yHeight
          effect=format\dwEffects
          FontName$=PeekS(@format\szFaceName )

          ;WriteLong(0,  der_couleur   )
          ;;WriteLong(0,der_couleur_fond)
          ;WriteLong(0,der_taille)
  
          der_paragraphe=Get_Selection_paragraphe(Gadget)
          paragraphe=der_paragraphe
          
          der_effect=effect
          der_couleur_fond=couleur_fond
          der_couleur=couleur
          der_taille=Taille
          der_FontName$=FontName$
          pos_coul=1
          ligne_coul=0
          
          For i=0 To CountGadgetItems(id_gadget)
               nb_chr=Len( GetGadgetItemText(id_gadget,i,0))
               For j=1 To nb_chr
                    Selection_Select(id_gadget, i, j+1, i, j+1) 
                    SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, #SCF_SELECTION, @format) 
                    FontName$=PeekS(@format\szFaceName )
                    couleur= format\crTextColor
                    couleur_fond= format\crBackColor
                    Taille= format\yHeight
                    effect=format\dwEffects
                    paragraphe=Get_Selection_paragraphe(Gadget)
                    If der_couleur<>couleur Or der_FontName$<>FontName$ Or der_taille<>Taille Or der_couleur_fond<>couleur_fond Or effect<>der_effect Or paragraphe<>der_paragraphe
                         
                         Write_Format(ligne_coul,i,pos_coul,j,der_couleur,der_couleur_fond,der_taille,der_effect,der_paragraphe,der_FontName$)
                         der_paragraphe=paragraphe
                         der_effect=effect
                         der_couleur_fond=couleur_fond
                         der_couleur=couleur
                         der_taille=Taille
                         der_FontName$=FontName$
                         ligne_coul=i
                         pos_coul=j
                    EndIf
                    
               Next
               
          Next
          Write_Format(ligne_coul,i,pos_coul,j,der_couleur,der_couleur_fond,der_taille,der_effect,der_paragraphe,FontName$)
          WriteStringN(0, code_fin_sauvegarde_format$)
          For i=0 To 9
               WriteLong(0,Couleur_Base(i))
          Next
          For i=0 To 2
               For j=0 To 9
                    WriteLong(0,Couleur_perso(i,j))
               Next
          Next
          
          CloseFile(0)
     EndIf
     
EndProcedure
Procedure load_editor1(id_gadget,nom_fichier$) ; procedure plus utilisé, mais je la garde sous le coude !
     Debug "LOAD"
     ;SetGadgetText(id_gadget,"")
     ClearGadgetItemList(id_gadget)
     If  ReadFile(0,nom_fichier$)
          
          Repeat
               ligne$=ReadString(0)
               If ligne$<>code_fin_sauvegarde_texte$
                    AddGadgetItem(id_gadget,-1,ligne$)
               EndIf
               
          Until Loc(0)=Lof(0) Or ligne$=code_fin_sauvegarde_texte$
          ; FileSeek(0,Loc(0)-2)
          ; Debug ReadByte(0)
          ; Debug ReadByte(0)
          zoom=ReadLong(0)
          lRet=SendMessage_(GadgetID(#note_pad_ID),#EM_SetZoom,zoom+10,MaxD) 
          SetGadgetState(#notepade_zoom,zoom) 
          couleur_page=ReadLong(0)
          SetGadgetColor(id_gadget,#PB_Gadget_BackColor,couleur_page)
          Selection_Select(id_gadget, 0, 1, 0, 1) 
          ;Set_Selection_Color(id_gadget,ReadLong(0))
          ;Set_Selection_BackColor(id_gadget,ReadLong(0))
          ;Set_Selection_Taille(id_gadget,ReadLong(0))
          If Loc(0)<>Lof(0)
               Repeat
                    
                    ligne_debut=ReadLong(0)
                    ligne_fin=ReadLong(0)
                    debut=ReadLong(0)
                    fin=ReadLong(0)
                    couleur=ReadLong(0)
                    couleur_fond=ReadLong(0)
                    Taille=ReadLong(0)
                    effect=ReadLong(0)
                    paragraphe=ReadLong(0)
                    FontName$=ReadString(0)
                    Debug Str(ligne_debut)+" : "+Str(ligne_fin)+" : "+Str(debut)+" : "+Str(fin)+" : "+Str(couleur)+" : "+Str(couleur_fond)+" : "+Str(Taille)+" : "
                    
                    Selection_Select(id_gadget, ligne_debut, debut, ligne_fin, fin) 
                    If couleur<>-1
                         Set_Selection_Color(id_gadget,couleur)
                    EndIf
                    If couleur_fond<>-1
                         Set_Selection_BackColor(id_gadget,couleur_fond)
                    EndIf
                    If Taille<>-1
                         Set_Selection_Taille(id_gadget,Taille)
                    EndIf
                    Set_Selection_Effect(id_gadget, effect,effect) 
                    Set_Selection_paragraphe(id_gadget,paragraphe)
                    Debug "setfont"
                    Debug FontName$
                    Set_Selection_Font(id_gadget,FontName$)
                    pos=Loc(0)
                    ligne$=ReadString(0)
                    FileSeek(0,pos)
                    
               Until Loc(0)=Lof(0) Or ligne$= code_fin_sauvegarde_format$
               If Loc(0)<>Lof(0)
                    ligne$=ReadString(0)
                    For i=0 To 9
                         Couleur_Base(i)=ReadLong(0)
                    Next
                    For i=0 To 2
                         For j=0 To 9
                              Couleur_perso(i,j)=ReadLong(0)
                         Next
                    Next
               EndIf
               
               CloseFile(0)
               ;RemoveGadgetItem(id_gadget, 0)
               Selection_Select(id_gadget,0, 0,0, 0) 
               Dessine_palette()
          EndIf
          
     EndIf
     
EndProcedure

Procedure EditCallBack_Ecriture(dwCookie.l, *pbBuff.l, cb.l, *pcb.l)
     If WriteData(0,*pbBuff, cb)
          ProcedureReturn 0
     Else
          ProcedureReturn 1
     EndIf
EndProcedure
Procedure EditCallBack_Lecture(dwCookie.l, *pbBuff.l, cb.l, *pcb.l)
     If ReadFile_(dwCookie, *pbBuff, cb, *pcb, 0)
          ProcedureReturn 0
     Else
          ProcedureReturn 1
     EndIf
EndProcedure 
Procedure sauve_editor(id_gadget,nom_fichier$)
     If nom_fichier$<>""
          If CreateFile(0, nom_fichier$)
               Edit.EDITSTREAM
               Edit\dwCookie=0
               Edit\pfnCallback=@EditCallBack_Ecriture()
               SendMessage_(GadgetID(id_gadget),#EM_STREAMOUT,#SF_RTF,Edit)
               If Edit\dwError=0
                    Debug "L'écriture s'est bien déroulée"
               Else
                    Debug "L'écriture du fichier a provoqué une erreur"
               EndIf
               CloseFile(0)
          EndIf
     EndIf 
     
EndProcedure
Procedure load_editor(id_gadget,nom_fichier$)
    If nom_fichier$<>""
          hFile=OpenFile(1, nom_fichier$)
          Edit.EDITSTREAM
          Edit\dwCookie=hFile
          Edit\pfnCallback=@EditCallBack_Lecture()
          SendMessage_(GadgetID(id_gadget),#EM_STREAMIN,#SF_RTF,Edit)
          If Edit\dwError=0
               Debug "La lecture s'est bien déroulée"
          Else
               Debug "La lecture du fichier a provoqué une erreur"
          EndIf
          CloseFile(1)
     EndIf 
EndProcedure     

Procedure Select_Font(Nom_font.s)
     For i=0 To CountGadgetItems(#notepade_liste_font)
          If Nom_font=GetGadgetItemText(#notepade_liste_font,i,i)
               SetGadgetState(#notepade_liste_font,i)
               ProcedureReturn 1
          EndIf
     Next
     SetGadgetState(#notepade_liste_font,0)
     ProcedureReturn -1
     
EndProcedure

Procedure evenement_notepad(id_window,event )
     Select event
          Case #PB_Event_Gadget; *****************Choix d'un bouton
               
               Select EventGadget()
                    Case #note_pad_ID
                         Select_Font( Get_Selection_Font(Gadget)) 
                         
                         Debug "P:"+Str(Get_Selection_paragraphe(Gadget))+"E:"+Str(Get_Selection_Effect(Gadget))+"C:"+Str(Get_Selection_Color(Gadget))+" BC:"+Str(Get_Selection_BackColor(Gadget) )+" T:"+Str(Get_Selection_Taille(Gadget) )
                         Select Get_Selection_paragraphe(Gadget)
                              Case 0,1
                                   
                                   SetGadgetState(#notepade_alig_gauche,1)
                                   SetGadgetState(#notepade_alig_droite,0)
                                   SetGadgetState(#notepade_alig_centre,0)
                              Case 2
                                   
                                   SetGadgetState(#notepade_alig_gauche,0)
                                   SetGadgetState(#notepade_alig_droite,1)
                                   SetGadgetState(#notepade_alig_centre,0)
                              Case 3
                                   
                                   SetGadgetState(#notepade_alig_gauche,0)
                                   SetGadgetState(#notepade_alig_droite,0)
                                   SetGadgetState(#notepade_alig_centre,1)
                         EndSelect
                         
                         effect=Get_Selection_Effect(Gadget)    
                         If ReadBin(effect, 0)
                              SetGadgetState(#notepade_gras,1)
                         Else
                              SetGadgetState(#notepade_gras,0)
                         EndIf
                         If ReadBin(effect, 1)
                              SetGadgetState(#notepade_italique,1)
                         Else
                              SetGadgetState(#notepade_italique,0)
                         EndIf
                         If ReadBin(effect, 2)
                              SetGadgetState(#notepade_surligner,1)
                         Else
                              SetGadgetState(#notepade_surligner,0)
                         EndIf
                         If ReadBin(effect, 3)
                              SetGadgetState(#notepade_barrer,1)
                         Else
                              SetGadgetState(#notepade_barrer,0)
                         EndIf
                         
                    Case #notepade_load
                         load_editor(#note_pad_ID,nom_fichier_note_pad$)
                            
                    Case #notepade_save
                         sauve_editor(#note_pad_ID,nom_fichier_note_pad$)
                         
                         
                    Case #notepade_zoom
                         Value=GetGadgetState(#notepade_zoom) 
                         lRet=SendMessage_(GadgetID(#note_pad_ID),#EM_SetZoom,Value+10,MaxD) 

                    Case #notepade_alig_gauche
                         Set_Selection_paragraphe(#note_pad_ID,1)
                         
                    Case #notepade_alig_centre
                         Set_Selection_paragraphe(#note_pad_ID,3)
                    Case #notepade_alig_droite
                         Set_Selection_paragraphe(#note_pad_ID,2)
                         
                    Case #notepade_text_moins   
                         Taille= Get_Selection_Taille(#note_pad_ID) 
                         Set_Selection_Taille(#note_pad_ID, 0.8*Taille) 
                    Case #notepade_text_plus
                         Taille= Get_Selection_Taille(#note_pad_ID) 
                         Set_Selection_Taille(#note_pad_ID, 1.2*Taille)  
                         
                    Case #notepade_gras
                         Debug Get_Selection_Effect(#note_pad_ID)
                         If ReadBin(Get_Selection_Effect(#note_pad_ID), 0)=0
                              Set_Selection_Effect(#note_pad_ID, 1,1) 
                         Else
                              Set_Selection_Effect(#note_pad_ID, 1,0) 
                         EndIf
                         
                    Case #notepade_italique
                         If ReadBin(Get_Selection_Effect(#note_pad_ID), 1)=0
                              Set_Selection_Effect(#note_pad_ID, 2,2)
                         Else
                              Set_Selection_Effect(#note_pad_ID, 2,0)
                         EndIf
                         
                    Case #notepade_surligner
                         If ReadBin(Get_Selection_Effect(#note_pad_ID), 2)=0
                              Set_Selection_Effect(#note_pad_ID, 4,4) 
                         Else
                              Set_Selection_Effect(#note_pad_ID, 4,0) 
                         EndIf     
                    Case #notepade_barrer
                         
                         
                         If ReadBin(Get_Selection_Effect(#note_pad_ID), 3)=0
                              Set_Selection_Effect(#note_pad_ID, 8,8) 
                         Else
                              Set_Selection_Effect(#note_pad_ID, 8,0) 
                         EndIf
                         
                    Case #im_coul_texte,#im_coul_fond,#im_coul_page
                         
                         id_palette=EventGadget()
                         num_palette=id_palette-#im_coul_texte
                         num_coul=(WindowMouseX(id_window)-GadgetX(id_palette))/(GadgetWidth(id_palette)/10)
                         Select EventType()
                              Case 0
                                   If  WindowMouseY(id_window)-GadgetY(id_palette)<GadgetHeight(id_palette)/2
                                        couleur=Couleur_Base(num_coul)
                                   Else
                                        couleur=Couleur_perso(num_palette,num_coul)
                                   EndIf
                                   Select id_palette
                                        Case #im_coul_texte
                                             Set_Selection_Color(#note_pad_ID,couleur)
                                             
                                        Case #im_coul_fond
                                             Set_Selection_BackColor(#note_pad_ID,couleur)
                                             
                                        Case #im_coul_page
                                             SetGadgetColor(#note_pad_ID,#PB_Gadget_BackColor,couleur)
                                             
                                   EndSelect
                              Case 1
                                   If  WindowMouseY(id_window)-GadgetY(id_palette)<GadgetHeight(id_palette)/2
                                        Couleur_Base(num_coul)=ColorRequester()
                                   Else
                                        
                                        Couleur_perso(num_palette,num_coul)=ColorRequester()
                                   EndIf
                                   Dessine_palette()
                         EndSelect
                         
                    Case #notepade_liste_font
                         Debug EventType()
                         Select EventType()
                              Case 1 
                                   Debug GetGadgetText(#notepade_liste_font)
                                   Set_Selection_Font(#note_pad_ID,GetGadgetText(#notepade_liste_font))
                         EndSelect
                         
               EndSelect
     EndSelect
EndProcedure
     
     

     
     
OpenWindow(0,0,0,800,600,"Editeur de texte",#PB_Window_SystemMenu  )
CreateGadgetList(WindowID(0))
     
CreateNotepad(30,10,600,500)
list_font(0,#notepade_liste_font)
Initialise_couleur()
Dessine_palette()
;load_editor(#note_pad_ID,nom_fichier_note_pad$)
Repeat
     event=WaitWindowEvent()
     evenement_notepad(0,event )
     Select event
          
          Case #WM_KEYDOWN  ;{touche clavier
               Debug "Appuye touche "+Str(EventwParam())
               id_touche=EventwParam()
               
               Select id_touche
                    Case 116  ;F5 
                         
                    Case 117 ;F6 creation d'un tableau en RTF
                         AddGadgetItem(#note_pad_ID,-1,TableauRTF(5,3,600)) 
                    Case 118
                         
               EndSelect
     EndSelect
     
Until event=#wm_close
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Décolorie le en le coloriant en noir !
Stefou
Messages : 234
Inscription : jeu. 18/janv./2007 14:08

Message par Stefou »

Oui mais t'es grillé directement si l'on change la couleur du fond de la page!
:?
Ou alors je n'ai pas compris ce que tu me dis...

Mais bon si j'ai la solution c'est super, mais cela ne me gene pas trop pour ce que je veux faire...pour l'instant.... 8O
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

quel librairy tu as utiliser ? merci de repondre svp

j'arrive pas à le lancer
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

Moi j'ai pas compris ton problème, j'ai essayé ton éditeur et il travaille bien, on change facilement la couleur du fond de texte à son choix, c'est là que je comprend pas.
bernard13
Messages : 1221
Inscription : mer. 05/janv./2005 21:30

Message par bernard13 »

quand je le lance j'ai un message d'erreur suivant :

Ligne 518 : Invalid name : same as an external command

quel library il faut ?
Avatar de l’utilisateur
Jacobus
Messages : 1559
Inscription : mar. 06/avr./2004 10:35
Contact :

Message par Jacobus »

@Bernard13
Ca veut dire que tu as une librairie qui utilise un même nom de fonction et pas l'inverse. Donc pour compiler le code de stefou il faut soit que tu retires la lib correspondante, soit que tu modifies les noms des fonctions utilisées. A toi de voir ce qui est le plus simple.

Une piste : Vu le sujet, un éditeur de texte, je dirai que tu dois avoir la lib Editor+ de Progi84 installée. Retires la temporairement pour compiler le code, je pense que ce sera le plus simple pour toi.
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
Répondre