Procs : Format RTF et EditorGadget

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Ollivier
Messages : 4197
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Procs : Format RTF et EditorGadget

Message par Ollivier »

Voici quelques procédures assez bien expliquées pour faire faire fonctionner le format RTF dans un EditorGadget. Dans les dernières procédures, il s'agit de fonctions pour afficher et modifier une doc selon la présentation MSDN.

Les procédures s'appellent de bas en haut.

(La syntaxe RTF vient d'Octavius, donc merci à lui)

Code : Tout sélectionner

Procedure.S RTF(Type.L, Text.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;   Procédure qui décore la chaîne.d'entrée Text
;     Type = 1: "{Sortie}" = RTF("Entrée") >> Décore avec une paire d'accolades
;     Type = 2: Décore la chaîne d'entrée des ressources nécessaires pour le format RTF
;               Spécialement conçu pour un SetGadgetText()
;
;               Prépare une table succinte de fonte:
;                   0 : Tahoma
;                   1 : Arial
;                   2 : Courier New
;
;               Prépare une table type de couleurs
;                   0  : Noir
;                   1  : Bleu
;                   2  : Vert
;                   3  : Cyan
;                   4  : Rouge
;                   5  : Magenta
;                   6  : Marron
;                   7  : Gris
;                   8  : Gris
;                   9  : Bleu clair
;                   10 : Vert clair
;                   11 : Cyan clair
;                   12 : Rouge clair
;                   13 : Magenta clair
;                   14 : Jaune
;                   15 : Blanc
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Static Used.L
    Static FontTable.S
    Static ColorTable.S

    Protected l.L
    Protected r.L
    Protected v.L
    Protected b.L
    Protected S.S = Text    

    If Used = 0
        FontTable = "{\fonttbl{\f0\fswiss\fprq2\fcharset0 Tahoma;}{\f1\fswiss\fcharset0 Arial;}{\f2\fswiss\fcharset0 Courier New}}"
        ColorTable = "{\colortbl ;"
        For i = 1 To 15
            l = ((i & 8) >> 3) * 128
            r = l + ((i & 4) >> 2) * 127
            v = l + ((i & 2) >> 1) * 127
            b = l + (i & 1) * 127
            ColorTable + "\red" + Str(r) + "\green" + Str(v) + "\blue" + Str(b) + ";"
        Next
        ColorTable + "}"
        Used = 1
    EndIf
    
    If Type = 2: S = "\rtf1\ansi{\deflang1036}" + FontTable + ColorTable + S: Type = 1: EndIf
    If Type = 1: S = "{" + S + "}": EndIf
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S RC(n.L = 1, Alinea = 0)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;   RC() insère un retour chariot
;   RC(n) insère n retour chariot <=> donc passe n-1 lignes
;   RC(1, 10) retourne à la ligne avec un alinéa de 10 espaces
;   La sortie de RC() est une chaîne au format RTF
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Protected S.S    
    Protected i.L
    
    S = ""
    
    For i = 1 To n
        S + "\par " + Space(Alinea)
    Next
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Coul(V.L, E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF de la couleur V (Cf table des couleurs dans RTF() )
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S

    S = "\cf" + Str(V) + " " + E + "\cf0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Size(V.L, E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF de la taille V
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S

    S = "\fs" + Str(V) + " " + E + "\fs0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Gras(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF avec les attributs GRAS
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Protected S.S

    S = "\b" + E + "\b0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Ital(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF avec les attributs ITALIQUE
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S

    S = "\i" + E + "\i0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Courier(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF avec la police COURIER
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S

    S = "\f2" + E + "\f0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Tahoma(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF avec la police TAHOMA
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Protected S.S

    S = "\f1" + E + "\f0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Verdana(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Décore la chaîne d'entrée E au format RTF avec la police VERDANA
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Protected S.S

    S = "\f0" + E + "\f0"
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Para(E.S, W.L, Alinea.L)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Transforme la chaîne E au format RTF de telle sorte que la chaîne de sortie respectent
; tous les retours chariot et les alinea nécessaires spécifiés dans:
; * l'entrée W.L (Width) = Largeur du paragraphe (en caractères)
; * l'entrée Alinea.L = Largeur de la marge gauche du paragraphe (valeur en espaces)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Protected S.S
    Protected Count.L
    Protected Insert.L
    Protected Char.S
    Protected A.L
    
    S = ""
    Insert = 0
    Count = 0
        
    For i = 1 To Len(E)
        
        A = Asc(Mid(E, i, 1) )
        Char = Chr(A)
        
        Count + 1
        If Count > W
        
            Count = 0
            Insert = 1
        
        EndIf
        
        If Insert
        
            If A = 32
            
               Char = RC(1, Alinea)
               Insert = 0
                               
            EndIf
        
        EndIf
        
        S + Char
        
    Next

    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Params(Titre$, E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;   Elabore l'affichage au format RTF de la syntaxe de la fonction spécifiée dans la fiche
;   avec chacun de ses paramètres étalés l'un sous l'autre.
;
;   Le nom de fonction correspond au titre de la fiche (Entrée Titre$). Le suffixe «_» y est ajouté.
;   La paire de parenthèses est ajoutée.
;   La largeur de l'alinéa respecté est en fonction de la longueur du nom de la fonction.
;
;   La chaîne d'entrée E doit suivre exactement la syntaxe des point-virgule («;») comme suit:
;      Nom_du_paramètre1;Définition_du_paramètre1;
;      Nom_du_paramètre2;Définition_du_paramètre2;
;      Nom_du_paramètre3;Définition_du_paramètre3;
;       ...
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S
    Protected Alinea.L
    Protected Fin.L
    Protected Virg.S
    
    Alinea = Len(Titre$) + 2
    S = ""
    Fin = CountString(E, ";") / 2
    
    For i = 1 To Fin
        If i = Fin: Virg = "": Else: Virg = "," + RC(1, Alinea): EndIf
        S + Str(i) + ": " + StringField(E, ((i - 1) * 2) + 1, ";") + Virg
    Next
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S DefParam(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;   Elabore l'affichage au format RTF des différents paramètres numérotés suivis de leur
;     définition
;
;
;   La largeur de l'alinéa respecté pour chaque paragraphe de chaque définition est en 
;     fonction de la longueur du nom du plus grand des paramètres
;
;   La chaîne d'entrée E doit suivre la syntaxe des point-virgule («;») expliquée dans
;     la fonction Params()
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S
    Protected Alinea.L
    Protected Fin.L
    Protected Virg.S
    Protected Largest.L
    Protected Length.L
    
    Alinea = Len(Titre$) + 3
    S = ""
    Fin = CountString(E, ";") / 2
    
    Largest = 0
    For i = 1 To Fin
        Length = Len(StringField(E, ((i - 1) * 2) + 1, ";") )
        If Length > Largest
            Largest = Length
        EndIf        
    Next
    
    For i = 1 To Fin
        S + Str(i) + ": " + Gras(Courier(StringField(E, ((i - 1) * 2) + 1, ";") ) ) + RC(1, Largest)
        S + Para(StringField(E, ((i - 1) * 2) + 2, ";"), 40, Largest) + RC(2)
    Next
    
    S = Size(20, S)
    
    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure.S Fiche(Titre$, DLL$, Def$, Syntax$)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;   Elabore la fiche sous forme d'une chaîne de sortie au format RTF à partir de ses 
;     différents constituants (Titre, nom de la DLL, Définition de la fonction, Paramètres, 
;     et définition des paramètres)
;
;   Aucune décoration n'est nécessaire pour Titre$, DLL$ et Def$
;
;   La chaîne d'entrée Syntax$ doit respecter les décorations expliquées dans la fonction
;     Params()
;
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    Protected Text$
    Text$ = ""
    Text$ = Coul(2, Gras(Size(32, Titre$) ) ) + Chr(9)
    Text$ + Ital(Size(32, "(" + DLL$ + ")" + RC(2) ) )
    Text$ + Verdana(Size(20, Para(Def$, 50, 0) + RC(3) ) )
    Text$ + Courier(Size(20, Coul(3, Titre$ + "_(" ) ) )
    Text$ + Courier(Size(20, Coul(12, Params(Titre$, Syntax$) ) + Coul(3, ")") + RC(3) ) )
    Text$ + DefParam(Syntax$)
    ProcedureReturn Text$
EndProcedure

Code : Tout sélectionner

Procedure ChangeFiche(SubCard.L, Titre.S, DLL.S, Def.S, Syntax.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Met à jour l'intégralité d'un EditorGadget (SetGadgetText) dont le n° est spécifié par 
; l'entrée SubCard
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    SetGadgetText(SubCard,RTF(2, Fiche(Titre, DLL, Def, Syntax) ) )
    
EndProcedure

Code : Tout sélectionner

Procedure.S TriC(E.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Fonction plus puissante que Trim() pour l'importation depuis le presse-papier
; (Vire TOUT ce qui fait ch... autour (à gauche et à droite) d'une expression)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected S.S
    Protected i.L
    Protected Fin.L
    Protected A.L
    
    S = ""
    
    Fin = Len(E)    
    For i = 1 To Fin
    
        A = Asc(Mid(E, i, 1) )
        If A > 32
            S = Right(E, (Fin - i) + 1)
            Break
        EndIf
    
    Next
    
    Fin = Len(S)    
    For i = Fin To 1 Step -1
    
        A = Asc(Mid(S, i, 1) )
        If A > 32
            S = Left(S, i)
            Break
        EndIf
    
    Next

    ProcedureReturn S
EndProcedure

Code : Tout sélectionner

Procedure ImporteFiche(Gadget.L, Impor.S)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Prend la chaîne d'entrée Impor.S, la formate en RTF et l'affiche dans EditorGadget
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected Titre.S
    Protected DLL.S
    Protected Def.S
    Protected Syntax.S
    Protected Param.S
    Protected i.L

    Titre = TriC(StringField(Impor, 1, Chr(13) ) )
    DLL = TriC(StringField(Impor, 2, Chr(13) ) )
    Def = TriC(StringField(Impor, 3, Chr(13) ) )
    i = 4
    Syntax = ""

    Repeat
        Param = TriC(StringField(Impor, i, Chr(13) ) )
        If LCase(Left(Param, 5) ) = "[tag]"
            Break
        EndIf

        If Len(Param) > 0
            Syntax + Param
        EndIf
        i + 1

    ForEver

    ChangeFiche(Gadget, Titre, DLL, Def, Syntax)
    
EndProcedure
Dernière modification par Ollivier le sam. 22/sept./2007 15:38, modifié 3 fois.
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

belle synthese :D Merci :)
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Message par Ar-S »

Une balise "code" par procédure, un bel espace, c'est très lisible, de beaux petits commentaires, merci à Ollivier . :P
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

.......
Dernière modification par Backup le mar. 19/août/2014 13:16, modifié 1 fois.
Ollivier
Messages : 4197
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Message par Ollivier »

Houlà! c'est intéressant ta pêche! Par contre, il va falloir mettre quelques commentaires en tête de chaque procédures pour saisir l'importance de leur fonction. Sinon, j'avais besoin d'un petit outil (qui existe déjà ptêt, j'en sais rien) pour dispatcher et afficher une chaîne en hexa:
(utilise les procédures RTF plus haut)

Code : Tout sélectionner

Procedure WatchStrHex(E.S, W.L = 16)
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;   Affiche la chaîne d'entrée en hexa en vue de son analyse
;  
;   Entrées :
;             E.S chaîne à afficher
;             W.L nombre de caractères par ligne
;_____________________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    Protected i.L
    Protected A.L
    Protected Fin.L
    Protected Hexa.S
    Protected Watch.S
    
    Protected MainW.L
    Protected MainH.L
    Protected Marg.L
    Protected MenuH.L
    Protected MainWin.L
    Protected SubCard.L
    Protected Card.S
    Protected UnitHexa.S
    Protected Unit.S
    Protected Count.L
    
    Static Exit.L
    
    Fin = Len(E)
    Hexa = ""
    Watch = ""
    Card = ""

    For i = 1 To Fin
    
        A = Asc(Mid(E, i, 1) )
        
        UnitHexa = RSet(Hex(A), 2, "0")
        Unit = Chr(A)
        
        If A <= 31
            UnitHexa = Coul(12, UnitHexa)
            Unit = Coul(12, Chr(9 * 16 + 5) )
        EndIf
              
        Hexa + UnitHexa + " "
        
        Watch + Unit
        
        Count + 1
        
        If (Count => W) Or (i = Fin)

            Count = 0        
            Card + Hexa + " >> " + Watch + RC()
            Hexa = ""
            Watch = ""
            
        EndIf
        
    Next
    Card = Courier(Size(16, Card) )

    MainW = 400
    MainH = 300
    Marg = 10
    
    MainWin = OpenWindow(-1, 0, 0, MainW, MainH, "String viewer", $00CF0001 | $1000000)
  
    If MainWin
  
        MenuH = 0

        CreateGadgetList(WindowID(MainWin) )

        SubCard = EditorGadget(-1, Marg, Marg, MainW - Marg * 2, MainH - Marg * 2 - MenuH)

        MainW.L = WindowWidth(MainWin)
        MainH.L = WindowHeight(MainWin)
                          
        ResizeGadget(SubCard, Marg, Marg, MainW - Marg * 2, MainH - Marg * 2 - MenuH)
        
        SetGadgetText(SubCard, RTF(2, Card) )
 
        Exit = 0
        Repeat
      
            eWindow = WaitWindowEvent()
            aWindow = EventWindow()
          
            Select aWindow
          
                Case MainWin
                
                    Select eWindow
                  
                        Case #PB_Event_CloseWindow: Exit = 1
                      
                        Case #PB_Event_SizeWindow
                      
                            MainW.L = WindowWidth(MainWin)
                            MainH.L = WindowHeight(MainWin)
                          
                            ResizeGadget(SubCard, Marg, Marg, MainW - Marg * 2, MainH - Marg * 2 - MenuH)
                      
                            Case #PB_Event_Gadget     : eGadget = EventGadget()
                      
                    EndSelect
                  
            EndSelect
          
        Until Exit & 1
      
    EndIf
    

    

EndProcedure
Répondre