IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants VCL Delphi Discussion :

Ajouter des évènements MouseEnter/MouseLeave à TBitBtnWithColor


Sujet :

Composants VCL Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé

    Homme Profil pro
    Informaticien retraité
    Inscrit en
    Mars 2010
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2010
    Messages : 369
    Billets dans le blog
    1
    Par défaut Ajouter des évènements MouseEnter/MouseLeave à TBitBtnWithColor
    Tout d'abord, je souhaite un heureux Noël à tous !

    Je code avec Delphi 6 PE, et je suis en train de réaliser un composant utilisant une simulation de TBitBtn avec une propriété Color, réalisé par un descendant de TButton. Voici son origine: http://https://github.com/maerlyn/ol...nWithColor.pas
    Ca fonctionne très bien et je peux changer la couleur du BitBtn à ma guise.

    Maintenant, je voudrais déclencher certaines actions lors du survol d'un tel bouton, comme changer sa dimension, ses attributs de police etc.
    J'ai bien compris qu'il vallait créer es évènements MouseEnter et MouseLeave en interceptant les messages CM_xxx correspondants.
    Je fait comme ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
      TBitBtnWithColor = class(TButton)
      private
        FCanvas: TCanvas;
        FColor: TColor;
        FGlyph: Pointer;
        FStyle: TButtonStyle;
        FKind: TBitBtnWithColorKind;
        FLayout: TButtonLayout;
        FSpacing: Integer;
        FMargin: Integer;
        IsFocused: Boolean;
        FModifiedGlyph: Boolean;
     
        procedure CNMeasureItem(var Message: TWMMeasureItem); message CN_MEASUREITEM;
        procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
        procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
        procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
        procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
     
    procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;              // <===
    procedure MouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;              // <===
     
        procedure DrawItem(const DrawItemStruct: TDrawItemStruct);
        procedure SetColor(Value: TColor);
        procedure SetGlyph(Value: TBitmap);
        function GetGlyph: TBitmap;
        function GetNumGlyphs: TNumGlyphs;
        procedure SetNumGlyphs(Value: TNumGlyphs);
    ...
    $et j'ai ajouté les procédures simples pour le moment:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    ...
     
    procedure TBitBtnWithColor.MouseEnter(var Msg: TMessage);
    begin
    showmessage('Enter');
      Font.Style := Font.Style + [fsBold, fsItalic];
      Invalidate;
    end;
     
    procedure TBitBtnWithColor.MouseLeave(var Msg: TMessage);
    begin
    showmessage('Leave');
      Font.Style := Font.Style - [fsBold, fsItalic];
      Invalidate;
    end;
     
    ...
    J'ai bien conscience que ces nouveaux évènements sont alors hard-codés dans le composant et non paramétrables. Il faudra créer des propriétés OnMouseEnter/OnMouseLeav pour cela, mais ça viendra plus tard.

    Pour le moment, mon problème est tout smplement que l'évènement MouseEnter ne se déclenche pas, quoi que je fasse. Tel que je l'ai codé, je ne comprends pas pourquoi la procédure TBitBtnWithColor.MouseEnter n'est pas appelée lorsque je fais glisser le curseur sur un de ces boutons. Qu'est-ce que j'ai oublié ?

    EDIT

    Est-ce que je dois "hooker" la WNDPROC de mon bouton pour intercepter ces messages CM_MOUSEENTER/CM_MOUSELEAVE ?

  2. #2
    Membre Expert

    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2007
    Messages
    3 530
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 530
    Par défaut
    pas besoin de recoder ce qui existe !
    Il suffit de rajouter en published si c'est juste pour "activer" les propériétés héritées
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    property OnMouseEnter;
    property OnMouseLeave;
    Sinon, avec ta méthode, il faut déclencher les évènements quand c'est nécessaire.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    unit UCustomPanel;
     
    interface
     
    uses
      System.SysUtils, System.Classes, Vcl.Controls, Vcl.ExtCtrls, Vcl.Graphics, Vcl.Forms,
      Winapi.Messages;
     
    type
      PanelPerso = class(TCustomPanel)
      published
        procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
      RegisterComponents('Perso', [PanelPerso]);
    end;
     
    { PanelPerso }
     
    procedure PanelPerso.MouseEnter(var Msg: TMessage);
    begin
      BorderStyle := bsSingle;
      BorderWidth := 3;
      inherited;
    end;
     
    end.

  3. #3
    Membre éclairé

    Homme Profil pro
    Informaticien retraité
    Inscrit en
    Mars 2010
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2010
    Messages : 369
    Billets dans le blog
    1
    Par défaut
    Le compilateur refuse cela:
    Nom : aa1.JPG
Affichages : 171
Taille : 34,9 Ko

  4. #4
    Membre Expert

    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2007
    Messages
    3 530
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 530
    Par défaut
    J'ai mis un exemple plus simple.

    Après, je n'ai pas fais gaffe qu'il s'agit e D6. Je fais ça sur une version plus récente.

  5. #5
    Membre Expert

    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2007
    Messages
    3 530
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 530
    Par défaut
    autre exemple basé sur un TButton

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
     
    unit UButtonPerso;
     
    interface
     
    uses
      System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, Vcl.Graphics,
      Winapi.Messages;
     
    type
      TButtonPerso = class(TCustomButton)
      private
        { Déclarations privées }
      protected
        { Déclarations protégées }
      public
        { Déclarations publiques }
      published
        procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
        procedure MouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
        property Caption;
      end;
     
    procedure Register;
     
    implementation
     
    procedure Register;
    begin
      RegisterComponents('Perso', [TButtonPerso]);
    end;
     
    { TButtonPerso }
     
    procedure TButtonPerso.MouseEnter(var Msg: TMessage);
    begin
      Font.Style := Font.Style + [fsBold, fsItalic];
      inherited;
    end;
     
    procedure TButtonPerso.MouseLeave(var Msg: TMessage);
    begin
      Font.Style := [];
      inherited;
    end;
     
    end.

  6. #6
    Membre éclairé

    Homme Profil pro
    Informaticien retraité
    Inscrit en
    Mars 2010
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2010
    Messages : 369
    Billets dans le blog
    1
    Par défaut
    Merci, Papy214, de te pencher sur mon problème.

    Malheureusement, ton code semble conçu pour D7, pas pour D6.
    Ceci entraîne plusieurs conséquences. Je passe sur les noms des modiles dans la clause USES - c'était facile.
    Le composant TCustomButton est inconnu - je l'ai remplacé par TButton.
    La compilation se passe bien, dès lors.
    Je peux créer de tels boutons qui s'affichent bien.
    Mais, les évènements MouseEnter et MouseLeave ne se déclenchent pas.
    J'ai inséré un message dans ces procédures, mais ce message ne vient jamais:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    procedure TButtonPerso.MouseEnter(var Msg: TMessage);
    begin
    showmessage('Enter');
      Font.Style := Font.Style + [fsBold, fsItalic];
      inherited;
    end;
     
    procedure TButtonPerso.MouseLeave(var Msg: TMessage);
    begin
    showmessage('Leave');
      Font.Style := [];
      inherited;
    end;
    D'ailleurs, tel que tu l'asproposé, c'est exactement ce que j'ai codé et qui ne marche pas non plus.

    Je cherche en ce moment à "hooker" la WndProc de ces boutons via l'API SetWindowLong, pour y intercepter les messages CM_MOUSEENTER et MOUSELEAVE, tout en passant le reste à la WndProc d'origine. Je verrai bien ce ue cela donne.

    Je rendrai compte des résultats dès que possible...

  7. #7
    Membre Expert

    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2007
    Messages
    3 530
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 530
    Par défaut
    Tu devrais mettre ici le code entier pour qu'on puisse tester la totalité

  8. #8
    Membre éclairé

    Homme Profil pro
    Informaticien retraité
    Inscrit en
    Mars 2010
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2010
    Messages : 369
    Billets dans le blog
    1
    Par défaut
    Je suis pessimiste.

    Je ne pense pas que dans Delphi 6 PE, je puisse recevoir des messages CM_MOUSEENTER et CM_MOUSELEAVE sur un descendant de TButton.

    Voici ce que j'ai fait:

    Comme j'airai une multitude de boutons de ce genre à traiter, je crée une TStringList triée contenant une ligne par bouton, dont chacune a le format suivant;
    HHHHHHHH=aaaaaaaaaaaaaa
    avec HHHHHHHH = valeur du handle du bouton en hexa sur 8 caractères
    aaaaaaaaaaaaa = l'adresse de la WndProc d'origine pour le bouton concerné

    J'installe le hook de la manière suivante, en ajoutant une méthode WinHook à mon composant TMyBitBtn:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
    // Dans la définition du composant:
      ...
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        procedure Click; override;
        procedure Hookwin(hnd: HWND);             // <==========
        procedure UnhookWin(hnd: HWND);         // <==========
      published
      ...
     
    // dans la section Implementation de l'unité contenant le composant:
     
    // procédure provisoire juste pour identifier la réception des messages CM_MOUSEENYER et CM_MOUSELEAVE
    function HookWndProc(hWnd : HWND; Msg : Cardinal; WParam : WPARAM; LParam: LPARAM): UINT; stdcall;
    var
      old: integer;
    begin
         case Msg of
           CM_MOUSEENTER: begin
                            showmessage('Enter');
                          end;
           CM_MOUSELEAVE: begin
                            showmessage('Leave');
                          end;
         end;
         old := StrToInt(MyBitBtnHookOldProc.Values[IntToHex(hWnd,8)]);
         Result := CallWindowProc(Pointer(old), hWnd, Msg, wParam, lParam);
    end;
     
    // méthode pour installer le hook
    procedure TBitBtnWithColor.HookWin(hnd: HWND);
    begin
         if OldWndProc<>0 then exit;                               // déjà hooké ?
         OldWndProc := GetWindowLong(hnd, GWL_WNDPROC);
         if not assigned(MyBitBtnHookOldProc) then begin
           MyBitBtnHookOldProc := TStringList.Create;
           MyBitBtnHookOldProc.Sorted := true;
         end;
         MyBitBtnHookOldProc.Add(inttohex(hnd,8)+'='+inttostr(OldWndProc));
         SetWindowLong(hnd, GWL_WNDPROC, LongInt(@HookWndProc));
    end;
     
    méthode pour supprimer le hool
    procedure TBitBtnWithColor.UnhookWin(hnd: HWND);
    begin
         SetWindowLong(hnd, GWL_WNDPROC, LongInt(OldWndProc));
         if assigned(MyBitBtnHookOldProc) then MyBitBtnHookOldProc.Delete(MyBitBtnHookOldProc.IndexOfName(IntToHex(hnd,8)));
         OldWndProc := 0;
    end;
    Le hook est installé juste après la création dynamique du bouton, de la manière suivante;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
      btn := TMyBitBtn.Create(self);
      btn.Height := fButtonHeight;
      btn.Width := fButtonWidth;
      btn.Caption := fTabLabels.Strings[0];
      if self.Handle<>0 then  btn.ParentWindow := self.Handle;            // placer le nouveau bouton dans l'objet TKGFTab
      btn.OnClick := OnClick;
      btn.Tag := 0;                                                       // mémoriser l'indice de la page dans le bouton
     
      btn.Hookwin(btn.Handle);     // <========= installer le hook
    Voilà. Tout fonctionne, et j'utilise cette techniue ailleurs, sans difficulté. Le hook est bien installé, et j'ai debuggé à l'entrée de HookWndProc que la procédure est bien appelée et reçoit des messages. Elle en reçoit de toute sortes, mais PAS les deux messages qui m'intéressent. Ils ne sont jamais reçus.

    J'en conclus que CM_MOUSEENTER et CM_MOUSELEAVE ne sont pas générés pour un descendant de TButton. Est-ce que mon diagnostic est le bon ? Est-ce qu'il y a un moyen de contourner cela ?

    EDIT

    J'ai essayé d'utiliser un descendant de Tanel au lieu d'un TButton, mais là non plus, je ne reçois pas ces messages.

  9. #9
    Membre éclairé

    Homme Profil pro
    Informaticien retraité
    Inscrit en
    Mars 2010
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2010
    Messages : 369
    Billets dans le blog
    1
    Par défaut
    Voici un code condensé (sans la partie hook) qui, selon la documentation, est supposé marcher:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    uses Windows, Messages, Classes, Controls, Forms, Graphics, StdCtrls,     Dialogs,
      ExtCtrls, CommCtrl;
     
    type
      TButtonPerso = class(TButton)
      private
        { Déclarations privées }
      protected
        { Déclarations protégées }
      public
        { Déclarations publiques }
      published
        procedure MouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
        procedure MouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
        property Caption;
      end;
     
    Implementation
     
    procedure TButtonPerso.MouseEnter(var Msg: TMessage);
    begin
    showmessage('Enter');
      Font.Style := Font.Style + [fsBold, fsItalic];
      inherited;
    end;
     
    procedure TButtonPerso.MouseLeave(var Msg: TMessage);
    begin
    showmessage('Leave');
      Font.Style := Font.Style - [fsBold, fsItalic];
      inherited;
    end;
    Créer des boutons de ce type marche sans problème, mais les messages concernés ne sont jamais réçus.
    Et remplacer TButton par TPanel marche aussi, mais avec le même manque de messages.

    En fait, toute ma construction avec he hook de WndProc ne servait qu'à une seule chose: intercepter tous les messages arrivant dans mon composant pour comprendre ce qui arrive et n'arrive pas. Et c'est clair: les messahes CM_MOUSEENTER et CM_MOUSELEAVE n'arrivent jaais.

    J'ai tenté de les intercepter au niveau supérieur, dans le composant servant de parent à ces boutons (il s'agit d'un descendant de TPanel). Ma là encore, aucun de ces deux messages, ni concernant mes boutons, ni même concernant le TPanel lui-même.

  10. #10
    Membre Expert

    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2007
    Messages
    3 530
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 530
    Par défaut
    Je ne sais pas ce qu'il en est de Delphi 6 PE mais j'ai retrouvé une doc de Delphi 6 "standard" qui donne en exemple :

    TSpecialPanel = class(TPanel)
    protected
    procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
    end;

    procedure TSpecialPanel.CMMouseEnter(var Msg: TMessage);
    begin
    inherited;
    Color := clWhite;
    end;

    procedure TSpecialPanel.CMMouseLeave(var Msg: TMessage);
    begin
    inherited;
    Color := clBtnFace;
    end;

    This component handles the custom messages by turning the panel white when the mouse has
    entered the component’s surface area and then turns the color back to clBtnFace when the
    mouse leaves. You’ll find an example of this code on the CD under the directory CustMessage.
    C'est à se demander s'il n'y a pas autre chose qui coince dans l'utilisation du composant :-(

  11. #11
    Membre éclairé

    Homme Profil pro
    Informaticien retraité
    Inscrit en
    Mars 2010
    Messages
    369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien retraité
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2010
    Messages : 369
    Billets dans le blog
    1
    Par défaut
    J'ai trouvé !

    Il n'y a en effet aucun moyen de recevoir ces messages CM_MOUSEENTER et CM_MOUSELEAVE. Dommage...

    Mais j'ai trouvé une solution en utilisant l'évènement ON_MOUSEMOVE qui est curieusement présent pour un descendant de TButton.

    Je déclare un évènement ONMouseMobe pour chacun de ces boutons (il y en a potentiellement des dizaines dans une form). C'est toujours la même routine - il n'y a pas de routine OnMouseMove spécifiue par bouton. Conséuence: cette routine doit être réentrante (juste une précaution de codage à prendre).

    J'ajoute une propriété Hoovering de type boolean à chacun de ces boutons. Au début de la routine OnMouseMove, on teste cette propriété et on fait EXIT si sa valeur est true. Sinon, on la positionne à true et on poursuit le traitement. Ceci "sécurise" un peu le traitement de l'évènemenc, quoi que ce ne soit pas absolu. Cependant, même en glissant la souris rapidement, je n'ai pas constaté de problème, de cette manière.

    Le composant parent de ces boutons est un descendant de TPanel, auquel j'ai ajouté une propriété TabHooverButton (valeur integer). Elle contient la valeur de Sender du dernier bouton en survol. Donc, dans la routine OnMouseMove des boutons, je commence par tester si la propriété TabHooverButton de son parent est zéro. Si ce n'est pas le cas, je remets ce "bouton précédent" en état (sans attributs de police). Ensuite, je mémorise le Sender actuel dans cette propriété du parent et change les attributs de police du bouton actuel en gras etitalique.

    Effet visuel obtenu:
    lors du survol des boutons, les textes se mettent en gras et en italiue pour le bouton concerné, et ce marquage passe d'un bouton à l'autre. C'est exactement l'effet que je voulais obtenir. Bien entendu, au lieu de ces effets de police, on pourrait changer l'intensité de la couleur du boution, changer légèrement sa dimension etc.

    L'abblication de tout cela est un objet composé de ma conception implémentant un ensemble d'onglets et de pages associés aux onglets qui pour leur part sont représentés par les boutons. Les onglets peuvent être positionnés en haut, à gauche, en bas ou à droite des pages. Si les onglets sont troop nombreux pour tenir sur une seule ligne selon les dimensions des pages, on peut avoir des onglets sur plusieurs lignes, les dimensions des pages s'ajustant autmatiquement. La position des onglets peut être changée dynamiquement, par programme. Chaue page peut recevoir n'importe quel composant visuel, y compris un de ces mêmes contrôles à onglets. En voici un exemple:
    Nom : aa1.JPG
Affichages : 145
Taille : 19,6 Ko

    Pour cela, j'ai légèrement adapté l'objet TButttonWithColor dont l'origine est ici:
    https://github.com/maerlyn/old-delph...nWithColor.pas
    Voici la version modifiée:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    {*******************************************************}
    {            Button with Color property                 }
    { Version:   1.0                                        }
    { E-Mail:    info@utilmind.com                          }
    { Home Page: www.utilmind.com                           }
    { Created:   September 18, 1999                         }
    { Modified:  September 18, 1999                         }
    { Legal:     Copyright (c) 1999, UtilMind Solutions     }
    {*******************************************************}
    { This component is FREEWARE. Enjoy with it but please  }
    { don't ask us about support. However, if you have      }
    { found a way how to improve the TDotFrame - we shall   }
    { be grateful for sent examples.                        }
    {*******************************************************}
     
    // origine: https://github.com/maerlyn/old-delphi-codes/blob/master/_KOMPONENSEK/ButtonWithColor.pas
     
    unit KGF_unit_ButtonWithColor;
     
    {$S-,W-,R-}
    {$C PRELOAD}
     
    interface
     
    uses Windows, Messages, Classes, Controls, Forms, Graphics, StdCtrls,     Dialogs,
      ExtCtrls, CommCtrl;
     
    type
      TButtonLayout = (blGlyphLeft, blGlyphRight, blGlyphTop, blGlyphBottom);
      TButtonState = (bsUp, bsDisabled, bsDown, bsExclusive);
      TButtonStyle = (bsAutoDetect, bsWin31, bsNew);
      TNumGlyphs = 1..4;
     
      TBitBtnWithColorKind = (bkCustom, bkOK, bkCancel, bkHelp, bkYes, bkNo, bkClose,
        bkAbort, bkRetry, bkIgnore, bkAll);
     
      TBitBtnWithColor = class(TButton)
      private
        FCanvas: TCanvas;
        FColor: TColor;
        FGlyph: Pointer;
        FStyle: TButtonStyle;
        FKind: TBitBtnWithColorKind;
        FLayout: TButtonLayout;
        FSpacing: Integer;
        FMargin: Integer;
        IsFocused: Boolean;
        FModifiedGlyph: Boolean;
        fOldWndProc: LongInt;
     
        procedure CNMeasureItem(var Message: TWMMeasureItem); message CN_MEASUREITEM;
        procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
        procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
        procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
        procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
     
        procedure DrawItem(const DrawItemStruct: TDrawItemStruct);
        procedure SetColor(Value: TColor);
        procedure SetGlyph(Value: TBitmap);
        function GetGlyph: TBitmap;
        function GetNumGlyphs: TNumGlyphs;
        procedure SetNumGlyphs(Value: TNumGlyphs);
     
        procedure GlyphChanged(Sender: TObject);
        function IsCustom: Boolean;
        function IsCustomCaption: Boolean;
        procedure SetStyle(Value: TButtonStyle);
        procedure SetKind(Value: TBitBtnWithColorKind);
        function GetKind: TBitBtnWithColorKind;
        procedure SetLayout(Value: TButtonLayout);
        procedure SetSpacing(Value: Integer);
        procedure SetMargin(Value: Integer);
      protected
        procedure CreateHandle; override;
        procedure CreateParams(var Params: TCreateParams); override;
        function GetPalette: HPALETTE; override;
        procedure SetButtonStyle(ADefault: Boolean); override;
     
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        procedure Click; override;
      published
        property Cancel stored IsCustom;
        property Caption stored IsCustomCaption;
        property Color: TColor read FColor write SetColor;    
        property Default stored IsCustom;
        property Enabled;
        property Glyph: TBitmap read GetGlyph write SetGlyph stored IsCustom;
        property Kind: TBitBtnWithColorKind read GetKind write SetKind default bkCustom;
        property Layout: TButtonLayout read FLayout write SetLayout default blGlyphLeft;
        property Margin: Integer read FMargin write SetMargin default -1;
        property ModalResult stored IsCustom;
        property NumGlyphs: TNumGlyphs read GetNumGlyphs write SetNumGlyphs stored IsCustom default 1;
        property ParentShowHint;
        property ShowHint;
        property Style: TButtonStyle read FStyle write SetStyle default bsAutoDetect;
        property Spacing: Integer read FSpacing write SetSpacing default 4;
        property TabOrder;
        property TabStop;
        property Visible;
        property OnEnter;
        property OnExit;
        property OldWndProc: LongInt read fOldWndProc write fOldWndProc;
      end;
     
    function DrawButtonFace(Canvas: TCanvas; const Client: TRect;
      BevelWidth: Integer; Style: TButtonStyle; IsRounded, IsDown,
      IsFocused: Boolean; FColor: TColor): TRect;
     
    procedure Register;
     
    implementation
     
    uses Consts, SysUtils;
     
    {$R *.RES}
     
    { TBitBtnWithColor data }
    const
      SOKButton = 61508;
      SCancelButton = 61509;
      SYesButton = 61510;
      SNoButton = 61511;
      SHelpButton = 61512;
      SCloseButton = 61513;
      SIgnoreButton = 61514;
      SRetryButton = 61515;
      SAbortButton = 61516;
      SAllButton = 61517;
     
      BitBtnResNames: array[TBitBtnWithColorKind] of PChar = (
        nil, 'BBCOK', 'BBCCANCEL', 'BBCHELP', 'BBCYES', 'BBCNO', 'BBCCLOSE',
        'BBCABORT', 'BBCRETRY', 'BBCIGNORE', 'BBCALL');
      BitBtnCaptions: array[TBitBtnWithColorKind] of Word = (
        0, SOKButton, SCancelButton, SHelpButton, SYesButton, SNoButton,
        SCloseButton, SAbortButton, SRetryButton, SIgnoreButton,
        SAllButton);
      BitBtnModalResults: array[TBitBtnWithColorKind] of TModalResult = (
        0, mrOk, mrCancel, 0, mrYes, mrNo, 0, mrAbort, mrRetry, mrIgnore,
        mrAll);
     
    var
      BitBtnGlyphs: array[TBitBtnWithColorKind] of TBitmap;
     
     
    { DrawButtonFace - returns the remaining usable area inside the Client rect.}
    function DrawButtonFace(Canvas: TCanvas; const Client: TRect;
      BevelWidth: Integer; Style: TButtonStyle; IsRounded, IsDown,
      IsFocused: Boolean; FColor: TColor): TRect;
    var
      NewStyle: Boolean;
      R: TRect;
      DC: THandle;
    begin
      NewStyle := ((Style = bsAutoDetect) and NewStyleControls) or (Style = bsNew);
     
      R := Client;
      with Canvas do
      begin
        if NewStyle then
        begin
          Brush.Color := FColor;
          Brush.Style := bsSolid;
          DC := Canvas.Handle;    { Reduce calls to GetHandle }
     
          if IsDown then
          begin    { DrawEdge is faster than Polyline }
            DrawEdge(DC, R, BDR_SUNKENINNER, BF_TOPLEFT);              { black     }
            DrawEdge(DC, R, BDR_SUNKENOUTER, BF_BOTTOMRIGHT);          { btnhilite }
            Dec(R.Bottom);
            Dec(R.Right);
            Inc(R.Top);
            Inc(R.Left);
            DrawEdge(DC, R, BDR_SUNKENOUTER, BF_TOPLEFT or BF_MIDDLE); { btnshadow }
          end
          else
          begin
            DrawEdge(DC, R, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);          { black }
            Dec(R.Bottom);
            Dec(R.Right);
            DrawEdge(DC, R, BDR_RAISEDINNER, BF_TOPLEFT);              { btnhilite }
            Inc(R.Top);
            Inc(R.Left);
            DrawEdge(DC, R, BDR_RAISEDINNER, BF_BOTTOMRIGHT or BF_MIDDLE); { btnshadow }
          end;
        end
        else
        begin
          Pen.Color := clWindowFrame;
          Brush.Color := FColor;
          Brush.Style := bsSolid;
          Rectangle(R.Left, R.Top, R.Right, R.Bottom);
     
          { round the corners - only applies to Win 3.1 style buttons }
          if IsRounded then
          begin
            Pixels[R.Left, R.Top] := FColor;
            Pixels[R.Left, R.Bottom - 1] := FColor;
            Pixels[R.Right - 1, R.Top] := FColor;
            Pixels[R.Right - 1, R.Bottom - 1] := FColor;
          end;
     
          if IsFocused then
          begin
            InflateRect(R, -1, -1);
            Brush.Style := bsClear;
            Rectangle(R.Left, R.Top, R.Right, R.Bottom);
          end;
     
          InflateRect(R, -1, -1);
          if not IsDown then
            Frame3D(Canvas, R, clBtnHighlight, clBtnShadow, BevelWidth)
          else
          begin
            Pen.Color := clBtnShadow;
            PolyLine([Point(R.Left, R.Bottom - 1), Point(R.Left, R.Top),
              Point(R.Right, R.Top)]);
          end;
        end;
      end;
     
      Result := Rect(Client.Left + 1, Client.Top + 1,
        Client.Right - 2, Client.Bottom - 2);
      if IsDown then OffsetRect(Result, 1, 1);
    end;
     
    function GeTBitBtnWithColorGlyph(Kind: TBitBtnWithColorKind): TBitmap;
    begin
      if BitBtnGlyphs[Kind] = nil then
      begin
        BitBtnGlyphs[Kind] := TBitmap.Create;
        BitBtnGlyphs[Kind].Handle := LoadBitmap(HInstance, BitBtnResNames[Kind]);
      end;
      Result := BitBtnGlyphs[Kind];
    end;
     
    type
      TGlyphList = class(TImageList)
      private
        Used: TBits;
        FCount: Integer;
        function AllocateIndex: Integer;
      public
        constructor Create(AWidth, AHeight: Integer);
        destructor Destroy; override;
        function Add(Image, Mask: TBitmap): Integer;
        function AddMasked(Image: TBitmap; MaskColor: TColor): Integer;
        procedure Delete(Index: Integer);
        property Count: Integer read FCount;
      end;
     
      TGlyphCache = class
      private
        GlyphLists: TList;
      public
        constructor Create;
        destructor Destroy; override;
        function GetList(AWidth, AHeight: Integer): TGlyphList;
        procedure ReturnList(List: TGlyphList);
        function Empty: Boolean;
      end;
     
      TButtonGlyph = class
      private
        FOriginal: TBitmap;
        FGlyphList: TGlyphList;
        FIndexs: array[TButtonState] of Integer;
        FTransparentColor: TColor;
        FNumGlyphs: TNumGlyphs;
        FOnChange: TNotifyEvent;
        procedure GlyphChanged(Sender: TObject);
        procedure SetGlyph(Value: TBitmap);
        procedure SetNumGlyphs(Value: TNumGlyphs);
        procedure Invalidate;
        function CreateButtonGlyph(State: TButtonState; FColor: TColor): Integer;
        procedure DrawButtonGlyph(Canvas: TCanvas; X, Y: Integer;
          State: TButtonState; FColor: TColor);
        procedure DrawButtonText(Canvas: TCanvas; const Caption: string;
          TextBounds: TRect; State: TButtonState);
        procedure CalcButtonLayout(Canvas: TCanvas; const Client: TRect;
          const Caption: string; Layout: TButtonLayout; Margin, Spacing: Integer;
          var GlyphPos: TPoint; var TextBounds: TRect);
      public
        constructor Create;
        destructor Destroy; override;
        { return the text rectangle }
        function Draw(Canvas: TCanvas; const Client: TRect;
          const Caption: string; Layout: TButtonLayout; Margin, Spacing: Integer;
          State: TButtonState; FColor: TColor): TRect;
        property Glyph: TBitmap read FOriginal write SetGlyph;
        property NumGlyphs: TNumGlyphs read FNumGlyphs write SetNumGlyphs;
        property OnChange: TNotifyEvent read FOnChange write FOnChange;
      end;
     
    { TGlyphList }
     
    constructor TGlyphList.Create(AWidth, AHeight: Integer);
    begin
      inherited CreateSize(AWidth, AHeight);
      Used := TBits.Create;
    end;
     
    destructor TGlyphList.Destroy;
    begin
      Used.Free;
      inherited Destroy;
    end;
     
    function TGlyphList.AllocateIndex: Integer;
    begin
      Result := Used.OpenBit;
      if Result >= Used.Size then
      begin
        Result := inherited Add(nil, nil);
        Used.Size := Result + 1;
      end;
      Used[Result] := True;
    end;
     
    function TGlyphList.Add(Image, Mask: TBitmap): Integer;
    begin
      Result := AllocateIndex;
      Replace(Result, Image, Mask);
      Inc(FCount);
    end;
     
    function TGlyphList.AddMasked(Image: TBitmap; MaskColor: TColor): Integer;
    begin
      Result := AllocateIndex;
      ReplaceMasked(Result, Image, MaskColor);
      Inc(FCount);
    end;
     
    procedure TGlyphList.Delete(Index: Integer);
    begin
      if Used[Index] then
      begin
        Dec(FCount);
        Used[Index] := False;
      end;
    end;
     
    { TGlyphCache }
     
    constructor TGlyphCache.Create;
    begin
      inherited Create;
      GlyphLists := TList.Create;
    end;
     
    destructor TGlyphCache.Destroy;
    begin
      GlyphLists.Free;
      inherited Destroy;
    end;
     
    function TGlyphCache.GetList(AWidth, AHeight: Integer): TGlyphList;
    var
      I: Integer;
    begin
      for I := GlyphLists.Count - 1 downto 0 do
      begin
        Result := GlyphLists[I];
        with Result do
          if (AWidth = Width) and (AHeight = Height) then Exit;
      end;
      Result := TGlyphList.Create(AWidth, AHeight);
      GlyphLists.Add(Result);
    end;
     
    procedure TGlyphCache.ReturnList(List: TGlyphList);
    begin
      if List = nil then Exit;
      if List.Count = 0 then
      begin
        GlyphLists.Remove(List);
        List.Free;
      end;
    end;
     
    function TGlyphCache.Empty: Boolean;
    begin
      Result := GlyphLists.Count = 0;
    end;
     
    var
      GlyphCache: TGlyphCache = nil;
     
    { TButtonGlyph }
     
    constructor TButtonGlyph.Create;
    var
      I: TButtonState;
    begin
      inherited Create;
      FOriginal := TBitmap.Create;
      FOriginal.OnChange := GlyphChanged;
      FTransparentColor := clOlive;
      FNumGlyphs := 1;
      for I := Low(I) to High(I) do
        FIndexs[I] := -1;
      if GlyphCache = nil then GlyphCache := TGlyphCache.Create;
    end;
     
    destructor TButtonGlyph.Destroy;
    begin
      FOriginal.Free;
      Invalidate;
      if Assigned(GlyphCache) and GlyphCache.Empty then
      begin
        GlyphCache.Free;
        GlyphCache := nil;
      end;
      inherited Destroy;
    end;
     
    procedure TButtonGlyph.Invalidate;
    var
      I: TButtonState;
    begin
      for I := Low(I) to High(I) do
      begin
        if FIndexs[I] <> -1 then FGlyphList.Delete(FIndexs[I]);
        FIndexs[I] := -1;
      end;
      GlyphCache.ReturnList(FGlyphList);
      FGlyphList := nil;
    end;
     
    procedure TButtonGlyph.GlyphChanged(Sender: TObject);
    begin
      if Sender = FOriginal then
      begin
        FTransparentColor := FOriginal.TransparentColor;
        Invalidate;
        if Assigned(FOnChange) then FOnChange(Self);
      end;
    end;
     
    procedure TButtonGlyph.SetGlyph(Value: TBitmap);
    var
      Glyphs: Integer;
    begin
      Invalidate;
      FOriginal.Assign(Value);
      if (Value <> nil) and (Value.Height > 0) then
      begin
        FTransparentColor := Value.TransparentColor;
        if Value.Width mod Value.Height = 0 then
        begin
          Glyphs := Value.Width div Value.Height;
          if Glyphs > 4 then Glyphs := 1;
          SetNumGlyphs(Glyphs);
        end;
      end;
    end;
     
    procedure TButtonGlyph.SetNumGlyphs(Value: TNumGlyphs);
    begin
      if (Value <> FNumGlyphs) and (Value > 0) then
      begin
        Invalidate;
        FNumGlyphs := Value;
      end;
    end;
     
    function TButtonGlyph.CreateButtonGlyph(State: TButtonState; FColor: TColor): Integer;
    const
      ROP_DSPDxax = $00E20746;
    var
      TmpImage, MonoBmp: TBitmap;
      IWidth, IHeight: Integer;
      IRect, ORect: TRect;
      I: TButtonState;
      DestDC: HDC;
    begin
      if (State = bsDown) and (NumGlyphs < 3) then State := bsUp;
      Result := FIndexs[State];
      if Result <> -1 then Exit;
      if (FOriginal.Width or FOriginal.Height) = 0 then Exit;
      IWidth := FOriginal.Width div FNumGlyphs;
      IHeight := FOriginal.Height;
      if FGlyphList = nil then
      begin
        if GlyphCache = nil then GlyphCache := TGlyphCache.Create;
        FGlyphList := GlyphCache.GetList(IWidth, IHeight);
      end;
      TmpImage := TBitmap.Create;
      try
        TmpImage.Width := IWidth;
        TmpImage.Height := IHeight;
        IRect := Rect(0, 0, IWidth, IHeight);
        TmpImage.Canvas.Brush.Color := FColor;
        I := State;
        if Ord(I) >= NumGlyphs then I := bsUp;
        ORect := Rect(Ord(I) * IWidth, 0, (Ord(I) + 1) * IWidth, IHeight);
        case State of
          bsUp, bsDown:
            begin
              TmpImage.Canvas.BrushCopy(IRect, FOriginal, ORect, FTransparentColor);
              FIndexs[State] := FGlyphList.Add(TmpImage, nil);
            end;
          bsExclusive:
            begin
              TmpImage.Canvas.CopyRect(IRect, FOriginal.Canvas, ORect);
              FIndexs[State] := FGlyphList.AddMasked(TmpImage, FTransparentColor);
            end;
          bsDisabled:
            begin
              MonoBmp := TBitmap.Create;
              try
                if NumGlyphs > 1 then
                with TmpImage.Canvas do
                begin    { Change white & gray to clBtnHighlight and clBtnShadow }
                  CopyRect(IRect, FOriginal.Canvas, ORect);
                  MonoBmp.Width := IWidth;
                  MonoBmp.Height := IHeight;
                  MonoBmp.Monochrome := True;
     
                  { Convert white to clBtnHighlight }
                  FOriginal.Canvas.Brush.Color := clWhite;
                  MonoBmp.Canvas.CopyRect(IRect, FOriginal.Canvas, ORect);
                  Brush.Color := clBtnHighlight;
                  DestDC := Handle;
                  SetTextColor(DestDC, clBlack);
                  SetBkColor(DestDC, clWhite);
                  BitBlt(DestDC, 0, 0, IWidth, IHeight,
                         MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
     
                  { Convert gray to clBtnShadow }
                  FOriginal.Canvas.Brush.Color := clGray;
                  MonoBmp.Canvas.CopyRect(IRect, FOriginal.Canvas, ORect);
                  Brush.Color := clBtnShadow;
                  DestDC := Handle;
                  SetTextColor(DestDC, clBlack);
                  SetBkColor(DestDC, clWhite);
                  BitBlt(DestDC, 0, 0, IWidth, IHeight,
                         MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
     
                  { Convert transparent color to FColor }
                  FOriginal.Canvas.Brush.Color := ColorToRGB(FTransparentColor);
                  MonoBmp.Canvas.CopyRect(IRect, FOriginal.Canvas, ORect);
                  Brush.Color := FColor;
                  DestDC := Handle;
                  SetTextColor(DestDC, clBlack);
                  SetBkColor(DestDC, clWhite);
                  BitBlt(DestDC, 0, 0, IWidth, IHeight,
                         MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
                end
                else
                begin
                  { Create a disabled version }
                  with MonoBmp do
                  begin
                    Assign(FOriginal);
                    Canvas.Brush.Color := clBlack;
                    Width := IWidth;
                    if Monochrome then
                    begin
                      Canvas.Font.Color := clWhite;
                      Monochrome := False;
                      Canvas.Brush.Color := clWhite;
                    end;
                    Monochrome := True;
                  end;
                  with TmpImage.Canvas do
                  begin
                    Brush.Color := FColor;
                    FillRect(IRect);
                    Brush.Color := clBtnHighlight;
                    SetTextColor(Handle, clBlack);
                    SetBkColor(Handle, clWhite);
                    BitBlt(Handle, 1, 1, IWidth, IHeight,
                      MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
                    Brush.Color := clBtnShadow;
                    SetTextColor(Handle, clBlack);
                    SetBkColor(Handle, clWhite);
                    BitBlt(Handle, 0, 0, IWidth, IHeight,
                      MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
                  end;
                end;
                FIndexs[State] := FGlyphList.Add(TmpImage, nil);
              finally
                MonoBmp.Free;
              end;
           end;
        end;
      finally
        TmpImage.Free;
      end;
      Result := FIndexs[State];
      FOriginal.Dormant;
    end;
     
    procedure TButtonGlyph.DrawButtonGlyph(Canvas: TCanvas; X, Y: Integer;
      State: TButtonState; FColor: TColor);
    var
      Index: Integer;
    begin
      if FOriginal = nil then Exit;
      if (FOriginal.Width = 0) or (FOriginal.Height = 0) then Exit;
      Index := CreateButtonGlyph(State, FColor);
      if State = bsExclusive then
        ImageList_DrawEx(FGlyphList.Handle, Index, Canvas.Handle, X, Y, 0, 0,
          clNone, clNone, ILD_Transparent)
      else
        ImageList_DrawEx(FGlyphList.Handle, Index, Canvas.Handle, X, Y, 0, 0,
          ColorToRGB(FColor), clNone, ILD_Normal);
    end;
     
    procedure TButtonGlyph.DrawButtonText(Canvas: TCanvas; const Caption: string;
      TextBounds: TRect; State: TButtonState);
    begin
      with Canvas do
      begin
        Brush.Style := bsClear;
        if State = bsDisabled then
        begin
          OffsetRect(TextBounds, 1, 1);
          Font.Color := clWhite;
          DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, 0);
          OffsetRect(TextBounds, -1, -1);
          Font.Color := clDkGray;
          DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, 0);
        end else
          DrawText(Handle, PChar(Caption), Length(Caption), TextBounds,
            DT_CENTER or DT_VCENTER or DT_SINGLELINE);
      end;
    end;
     
    procedure TButtonGlyph.CalcButtonLayout(Canvas: TCanvas; const Client: TRect;
      const Caption: string; Layout: TButtonLayout; Margin, Spacing: Integer;
      var GlyphPos: TPoint; var TextBounds: TRect);
    var
      TextPos: TPoint;
      ClientSize, GlyphSize, TextSize: TPoint;
      TotalSize: TPoint;
    begin
      { calculate the item sizes }
      ClientSize := Point(Client.Right - Client.Left, Client.Bottom -
        Client.Top);
     
      if FOriginal <> nil then
        GlyphSize := Point(FOriginal.Width div FNumGlyphs, FOriginal.Height) else
        GlyphSize := Point(0, 0);
     
      if Length(Caption) > 0 then
      begin
        TextBounds := Rect(0, 0, Client.Right - Client.Left, 0);
        DrawText(Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CALCRECT);
        TextSize := Point(TextBounds.Right - TextBounds.Left, TextBounds.Bottom -
          TextBounds.Top);
      end
      else
      begin
        TextBounds := Rect(0, 0, 0, 0);
        TextSize := Point(0,0);
      end;
     
      { If the layout has the glyph on the right or the left, then both the
        text and the glyph are centered vertically.  If the glyph is on the top
        or the bottom, then both the text and the glyph are centered horizontally.}
      if Layout in [blGlyphLeft, blGlyphRight] then
      begin
        GlyphPos.Y := (ClientSize.Y - GlyphSize.Y + 1) div 2;
        TextPos.Y := (ClientSize.Y - TextSize.Y + 1) div 2;
      end
      else
      begin
        GlyphPos.X := (ClientSize.X - GlyphSize.X + 1) div 2;
        TextPos.X := (ClientSize.X - TextSize.X + 1) div 2;
      end;
     
      { if there is no text or no bitmap, then Spacing is irrelevant }
      if (TextSize.X = 0) or (GlyphSize.X = 0) then
        Spacing := 0;
     
      { adjust Margin and Spacing }
      if Margin = -1 then
      begin
        if Spacing = -1 then
        begin
          TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
          if Layout in [blGlyphLeft, blGlyphRight] then
            Margin := (ClientSize.X - TotalSize.X) div 3
          else
            Margin := (ClientSize.Y - TotalSize.Y) div 3;
          Spacing := Margin;
        end
        else
        begin
          TotalSize := Point(GlyphSize.X + Spacing + TextSize.X, GlyphSize.Y +
            Spacing + TextSize.Y);
          if Layout in [blGlyphLeft, blGlyphRight] then
            Margin := (ClientSize.X - TotalSize.X + 1) div 2
          else
            Margin := (ClientSize.Y - TotalSize.Y + 1) div 2;
        end;
      end
      else
      begin
        if Spacing = -1 then
        begin
          TotalSize := Point(ClientSize.X - (Margin + GlyphSize.X), ClientSize.Y -
            (Margin + GlyphSize.Y));
          if Layout in [blGlyphLeft, blGlyphRight] then
            Spacing := (TotalSize.X - TextSize.X) div 2
          else
            Spacing := (TotalSize.Y - TextSize.Y) div 2;
        end;
      end;
     
      case Layout of
        blGlyphLeft:
          begin
            GlyphPos.X := Margin;
            TextPos.X := GlyphPos.X + GlyphSize.X + Spacing;
          end;
        blGlyphRight:
          begin
            GlyphPos.X := ClientSize.X - Margin - GlyphSize.X;
            TextPos.X := GlyphPos.X - Spacing - TextSize.X;
          end;
        blGlyphTop:
          begin
            GlyphPos.Y := Margin;
            TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
          end;
        blGlyphBottom:
          begin
            GlyphPos.Y := ClientSize.Y - Margin - GlyphSize.Y;
            TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
          end;
      end;
     
      { fixup the result variables }
      Inc(GlyphPos.X, Client.Left);
      Inc(GlyphPos.Y, Client.Top);
      OffsetRect(TextBounds, TextPos.X + Client.Left, TextPos.Y + Client.Top);
    end;
     
    function TButtonGlyph.Draw(Canvas: TCanvas; const Client: TRect;
      const Caption: string; Layout: TButtonLayout; Margin, Spacing: Integer;
      State: TButtonState; FColor: TColor): TRect;
    var
      GlyphPos: TPoint;
    begin
      CalcButtonLayout(Canvas, Client, Caption, Layout, Margin, Spacing,
        GlyphPos, Result);
      DrawButtonGlyph(Canvas, GlyphPos.X, GlyphPos.Y, State, FColor);
      DrawButtonText(Canvas, Caption, Result, State);
    end;
     
    { TBitBtnWithColor }
     
    constructor TBitBtnWithColor.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FGlyph := TButtonGlyph.Create;
      TButtonGlyph(FGlyph).OnChange := GlyphChanged;
      FCanvas := TCanvas.Create;
      FColor := clBtnFace;
      FStyle := bsAutoDetect;
      FKind := bkCustom;
      FLayout := blGlyphLeft;
      FSpacing := 4;
      FMargin := -1;
    end;
     
    destructor TBitBtnWithColor.Destroy;
    begin
      TButtonGlyph(FGlyph).Free;
      FCanvas.Free;
      inherited Destroy;
    end;
     
    procedure TBitBtnWithColor.CreateHandle;
    var
      State: TButtonState;
    begin
      if Enabled then
        State := bsUp
      else
        State := bsDisabled;
      inherited CreateHandle;
      TButtonGlyph(FGlyph).CreateButtonGlyph(State, FColor);
    end;
     
    procedure TBitBtnWithColor.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      with Params do Style := Style or BS_OWNERDRAW;
    end;
     
    procedure TBitBtnWithColor.SetButtonStyle(ADefault: Boolean);
    begin
      if ADefault <> IsFocused then
      begin
        IsFocused := ADefault;
        Refresh;
      end;
    end;
     
    procedure TBitBtnWithColor.Click;
    var
      Form: TForm;
      Control: TWinControl;
    begin
      case FKind of
        bkClose:
          begin
            Form := TForm(GetParentForm(Self));
            if Form <> nil then Form.Close
            else inherited Click;
          end;
        bkHelp:
          begin
            Control := Self;
            while (Control <> nil) and (Control.HelpContext = 0) do
              Control := Control.Parent;
            if Control <> nil then Application.HelpContext(Control.HelpContext)
            else inherited Click;
          end;
        else
          inherited Click;
      end;
    end;
     
    procedure TBitBtnWithColor.CNMeasureItem(var Message: TWMMeasureItem);
    begin
      with Message.MeasureItemStruct^ do
      begin
        itemWidth := Width;
        itemHeight := Height;
      end;
    end;
     
    procedure TBitBtnWithColor.CNDrawItem(var Message: TWMDrawItem);
    begin
      DrawItem(Message.DrawItemStruct^);
    end;
     
    procedure TBitBtnWithColor.DrawItem(const DrawItemStruct: TDrawItemStruct);
    var
      IsDown, IsDefault: Boolean;
      State: TButtonState;
      R: TRect;
    begin
      FCanvas.Handle := DrawItemStruct.hDC;
      R := ClientRect;
     
      with DrawItemStruct do
      begin
        IsDown := itemState and ODS_SELECTED <> 0;
        IsDefault := itemState and ODS_FOCUS <> 0;
     
        if not Enabled then State := bsDisabled
        else if IsDown then State := bsDown
        else State := bsUp;
      end;
     
      { DrawFrameControl doesn't allow for drawing a button as the
          default button, so it must be done here. }
      if IsFocused or IsDefault then
      begin
        FCanvas.Pen.Color := clWindowFrame;
        FCanvas.Pen.Width := 1;
        FCanvas.Brush.Style := bsClear;
        FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
     
        { DrawFrameControl must draw within this border }
        InflateRect(R, -1, -1);
      end;
     
      { DrawFrameControl does not draw a pressed button correctly }
      if IsDown then
      begin
        FCanvas.Pen.Color := clBtnShadow;
        FCanvas.Pen.Width := 1;
        FCanvas.Brush.Color := FColor;
        FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
        InflateRect(R, -1, -1);
      end
      else
       with FCanvas do
       begin
         DrawEdge(Handle, R, BDR_RAISEDINNER or BDR_RAISEDOUTER, BF_RECT or BF_ADJUST);
         FCanvas.Pen.Color := FColor;
         FCanvas.Pen.Width := 1;
         FCanvas.Brush.Color := FColor;
         FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
         InflateRect(R, -1, -1);
       end;
     
      if IsFocused then
      begin
        R := ClientRect;
        InflateRect(R, -1, -1);
      end;
     
      FCanvas.Font := Self.Font;
      if IsDown then
        OffsetRect(R, 1, 1);
      TButtonGlyph(FGlyph).Draw(FCanvas, R, Caption, FLayout,
        FMargin, FSpacing, State, FColor);
     
      if IsFocused then
      begin
        R := ClientRect;
        InflateRect(R, -4, -4);
        FCanvas.Pen.Color := clWindowFrame;
        FCanvas.Brush.Color := FColor;
        DrawFocusRect(FCanvas.Handle, R);
      end;
     
      FCanvas.Handle := 0;
    end;
     
    procedure TBitBtnWithColor.CMFontChanged(var Message: TMessage);
    begin
      inherited;
      Invalidate;
    end;
     
    procedure TBitBtnWithColor.CMEnabledChanged(var Message: TMessage);
    begin
      inherited;
      Invalidate;
    end;
     
    procedure TBitBtnWithColor.WMLButtonDblClk(var Message: TWMLButtonDblClk);
    begin
      Perform(WM_LBUTTONDOWN, Message.Keys, Longint(Message.Pos));
    end;
     
    function TBitBtnWithColor.GetPalette: HPALETTE;
    begin
      Result := Glyph.Palette;
    end;
     
    procedure TBitBtnWithColor.SetColor(Value: TColor);
    begin
      if FColor <> Value then
      begin
        FColor := Value;
        SetGlyph(Glyph);
        Invalidate;
      end;
    end;
     
    procedure TBitBtnWithColor.SetGlyph(Value: TBitmap);
    begin
      TButtonGlyph(FGlyph).Glyph := Value as TBitmap;
      FModifiedGlyph := True;
      Invalidate;
    end;
     
    function TBitBtnWithColor.GetGlyph: TBitmap;
    begin
      Result := TButtonGlyph(FGlyph).Glyph;
    end;
     
    procedure TBitBtnWithColor.GlyphChanged(Sender: TObject);
    begin
      Invalidate;
    end;
     
    function TBitBtnWithColor.IsCustom: Boolean;
    begin
      Result := Kind = bkCustom;
    end;
     
    procedure TBitBtnWithColor.SetStyle(Value: TButtonStyle);
    begin
      if Value <> FStyle then
      begin
        FStyle := Value;
        Invalidate;
      end;
    end;
     
    procedure TBitBtnWithColor.SetKind(Value: TBitBtnWithColorKind);
    begin
      if Value <> FKind then
      begin
        if Value <> bkCustom then
        begin
          Default := Value in [bkOK, bkYes];
          Cancel := Value in [bkCancel, bkNo];
     
          if ((csLoading in ComponentState) and (Caption = '')) or
            (not (csLoading in ComponentState)) then
          begin
            if BitBtnCaptions[Value] > 0 then
              Caption := LoadStr(BitBtnCaptions[Value]);
          end;
     
          ModalResult := BitBtnModalResults[Value];
          TButtonGlyph(FGlyph).Glyph := GeTBitBtnWithColorGlyph(Value);
          NumGlyphs := 2;
          FModifiedGlyph := False;
        end;
        FKind := Value;
        Invalidate;
      end;
    end;
     
    function TBitBtnWithColor.IsCustomCaption: Boolean;
    begin
      Result := CompareStr(Caption, LoadStr(BitBtnCaptions[FKind])) <> 0;
    end;
     
    function TBitBtnWithColor.GetKind: TBitBtnWithColorKind;
    begin
      if FKind <> bkCustom then
        if ((FKind in [bkOK, bkYes]) xor Default) or
          ((FKind in [bkCancel, bkNo]) xor Cancel) or
          (ModalResult <> BitBtnModalResults[FKind]) or
          FModifiedGlyph then
          FKind := bkCustom;
      Result := FKind;
    end;
     
    procedure TBitBtnWithColor.SetLayout(Value: TButtonLayout);
    begin
      if FLayout <> Value then
      begin
        FLayout := Value;
        Invalidate;
      end;
    end;
     
    function TBitBtnWithColor.GetNumGlyphs: TNumGlyphs;
    begin
      Result := TButtonGlyph(FGlyph).NumGlyphs;
    end;
     
    procedure TBitBtnWithColor.SetNumGlyphs(Value: TNumGlyphs);
    begin
      if Value < 0 then Value := 1
      else if Value > 4 then Value := 4;
      if Value <> TButtonGlyph(FGlyph).NumGlyphs then
      begin
        TButtonGlyph(FGlyph).NumGlyphs := Value;
        Invalidate;
      end;
    end;
     
    procedure TBitBtnWithColor.SetSpacing(Value: Integer);
    begin
      if FSpacing <> Value then
      begin
        FSpacing := Value;
        Invalidate;
      end;
    end;
     
    procedure TBitBtnWithColor.SetMargin(Value: Integer);
    begin
      if (Value <> FMargin) and (Value >= - 1) then
      begin
        FMargin := Value;
        Invalidate;
      end;
    end;
     
    procedure DestroyLocals; far;
    var
      I: TBitBtnWithColorKind;
    begin
      for I := Low(TBitBtnWithColorKind) to High(TBitBtnWithColorKind) do
        BitBtnGlyphs[I].Free;
    end;
     
    procedure Register;
    begin
      RegisterComponents('UtilMind', [TBitBtnWithColor]);
    end;
     
    initialization
      FillChar(BitBtnGlyphs, SizeOf(BitBtnGlyphs), 0);
    finalization
      DestroyLocals;
    end.
    Et voici le composant que j'ai bâti avec ces boutons:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    1424
    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    1452
    1453
    1454
    1455
    1456
    1457
    1458
    1459
    1460
    1461
    1462
    1463
    1464
    1465
    1466
    1467
    1468
    1469
    1470
    1471
    1472
    1473
    1474
    1475
    1476
    1477
    1478
    1479
    1480
    1481
    1482
    1483
    1484
    1485
    1486
    1487
    1488
    1489
    1490
    1491
    1492
    1493
    1494
    1495
    1496
    1497
    1498
    1499
    1500
    1501
    1502
    1503
    1504
    1505
    1506
    1507
    1508
    1509
    1510
    1511
    1512
    1513
    1514
    1515
    1516
    1517
    1518
    1519
    1520
    1521
    1522
    1523
    1524
    1525
    1526
    1527
    1528
    1529
    1530
    1531
    1532
    1533
    1534
    1535
    1536
    1537
    1538
    1539
    1540
    1541
    1542
    1543
    1544
    1545
    1546
    1547
    1548
    1549
    1550
    1551
    1552
    1553
    1554
    1555
    1556
    1557
    1558
    1559
    1560
    1561
    1562
    1563
    1564
    1565
    1566
    1567
    1568
    1569
    1570
    1571
    1572
    1573
    1574
    1575
    1576
    1577
    1578
    1579
    1580
    1581
    1582
    1583
    1584
    1585
    1586
    1587
    1588
    1589
    1590
    1591
    1592
    1593
    1594
    1595
    1596
    1597
    1598
    1599
    1600
    1601
    1602
    1603
    1604
    1605
    1606
    1607
    1608
    1609
    1610
    1611
    1612
    1613
    1614
    1615
    1616
    1617
    1618
    1619
    1620
    1621
    1622
    1623
    1624
    1625
    1626
    1627
    1628
    1629
    1630
    1631
    1632
    1633
    1634
    1635
    1636
    1637
    1638
    1639
    1640
    1641
    1642
    1643
    1644
    1645
    1646
    1647
    1648
    1649
    1650
    1651
    1652
    1653
    1654
    1655
    1656
    1657
    1658
    1659
    1660
    1661
    1662
    1663
    1664
    1665
    1666
    1667
    1668
    1669
    1670
    unit KGF_TAB_Component;
     
    {
       This unit includes a Panoramic wrapper for the KGFTab component.
       It's presence is selectable by conditional compilation, using the PanoramicWrapper symbol.
       The Panoramic wrapper is just an add-on built on top of the KGFTab control. The control
       itself is fully operational without the wrapper. The wrapper exports the following functions:
           CreateKGFTab, ConfigureKGFTab, DeleteKGFTab and GetKGFTabHandles
     
       A special unit implementing buttons with color attribute is added by the conditional compiler ColorButton symbol.
       From this unit, the TBitBtnWithColor object is used thus allowing to manage the colors of the buttons.
       Just remove the symbol to eliminate the dependancy and fall back to standard TBitBtn.
     
       KGFTab is a visual composed control implementing a tabbed interface.
       Basically, the clickable tabs are implemented by standard TBitBtn buttons.
       The associated pages are standard TPanel controls.
     
       Called directly from Delphi, any Delphi control can be directly placed into these pages.
       Via the Panoramic wrapper, this is not possible. TWincontrol descendants can be placed
       using their ParentWindow handle with the handle of the desired TKGFTab page (TPanel object).
       Controls without a handle (like TImage aso) must be placed on a TPanel of same size, and this
       TPanel can than be placed into a TKGFTab page in standard way. A TLabel control is better
       replaced by a well dimensioned TPanel which can be inserted freely. By the way, the same
       restrictions apply if the TKGFTab control is placed into a DLL. When placed into a packet or
       compiled directly with the source program there is no problem.
     
       A special method of a TKGFTab object is Configure. This method can process a script accessing
       virtually all methods and functionalities of the TKGFTab object, thus acheiving 2 mail goals:
         1. ability to configure the control at runtime without programming
         2. effectively reducing the number of dedicated functions to manage the control
       The second point is particlarly interresting for use by a third party language where a whole set of
       dedicated fonctions and procédures would be required. The process is comparable to an SQL script
       in database managment.
     
       A method allows to specify a handle (typically the mainform handle) where the component will send
       via SEND_MESSAGE a USER_EVENT identifying an occurd action (actually "selection of a tab")
       and the number of the concerned tab.
       The WParam word contains $xxyynnnn where xx=18 (KGFTab) and yy=01 (selection of a tab=) and nnnn=numéro de la page TAB
       The LParam word contains l'objet KGFTab (résultar de la fonction CreateKGFTag)
     
       Actually, the following scripting commands are available (insensibles à la casse):
       (les signes <...> indiquent la plade d'une valeur numérique ou textuelle, selon les circonstances)
       Les paramères sont séparées par des virgules et la commande est terminée par un sémicolon.
       Tout ce qui suit un ";" est ignoré et considéré comme commentaire.
            parent,<handle>;                      handle de l'objet dans lequel le TKGFTab doit apparaître
            left,<position>;                      position gauche en pixels du TKGFTab
            top,<position>;                       position haute en pixels du TKGFTab
            width,<dimension>;                    largeur en pixels du TKGFTab
            height,<dimension>;                   hauteur en pixels du TKGFTab
            label,<ind>,<libellé>;                index et libelle d'un bouton existant
            addtab,<libellé>;                     libellé du nouveau bouton
            inserttab,<ind>,<libellé>;            index d'un bouton existant pour l'insertion et le nouveau libellé
            deletetab,<Ind>;                      index du bouton et de la feuille à supprimer
            glyph,<ind>,<fichier>;                index (0...3) de la partie du glupf à charger par l'image dans le fichier
            buttonglyph,<ind>;                    index du bouton dans lequel installer le glyph assemblé avec 4 images
            tabpagehandles;                       (retourne la liste des handles des pages)
            buttonheight,<dimension>;             hauteur des boutons
            buttonwidth,<dimension>;              largeur des boutons
            buttonposition,<choix>;               choix de la position des boutons (0...3)
            tabcolor,<ind>,<couleur>;             index d'une page et sa culeur de fond (RGB en hexa précédé par un "$")
            tabactivate,<ind>,<état>;             index d'une page et  etat d'activation (1=inactive  <>0 = active)
            multirow,<choix>;                     gérer les boutons sur lignes/clonnes multiples  0=désactivé   1=activé
            glyphsize,<dimension>;                définir la taille des icônes (défaut: 16 pixels)
            userevent,<handle>;                   définir le handle de destination pour l'envoi d'u USER_EVENT
            insertcontrol,<ind>,<handle>;         insérer dans la page ind le contrôle dont le handle est indiqué
            buttoncolor,<ind>,<couleur>           index d'un bouton et sa couleur de fond
       De façon interne, un TKGFTab contient 4 petites images invisibles servant à construire un glyph.
       Il faut charger les 4 images par des fichiers BMP toutes de la même dimension ( 16 x 16  par exemple), commande "glyph"
       Lorsque les 4 images sont chargées, on peut charger le glyph par la commande "buttonglyph"
       Les positions possibles des boutons sont 0=Top  1=Left  2=Bottom  3=Right
       Les couleurs sont par exemple:   $FF pour Rouge, $FF0000 pour Bleu, etc
     
    }
     
    {$define PanoramicWrapper}
    {$define ColorButton}
     
    interface
     
      uses
        Windows, forms, SysUtils, Controls, Classes, ExtCtrls, StdCtrls, Buttons,
        Contnrs, Graphics, StrUtils, Messages    , Dialogs
    {$ifdef ColorButton}
        , KGF_unit_ButtonWithColor    // Copyright (c) 1999, UtilMind Solutions
    {$endif}
    {$ifdef PanoramicWrapper}
       , KGF_unit_data
    {$endif}
       ;
     
    const
      CM_PANORAMIC_USER = WM_USER + 3000;    // commande pour SendMessage pour déclencher le ON_USER_EVENT de Panoramic
      UserEventKGFTab               = $18000000; // identifiant dans WParam
        UserEventTabSelect                         = $00010000; // clic dans un bouton d'un TAB ou sélection par programme
     
    {$ifdef PanoramicWrapper}
    {$else}
    var
      PCompiledMode: boolean;
    {$endif}
     
    const StringParameterMethod = 2;
     
    type
      TButtonPosition = (bpTop, bpLeft, bpBottom, bpRight);     // position des boutons par rapport aux pages
     
    {
      Cette classe permet de regrouper des boutons pour le traitement du survol.
      Elle sera enregistrée dans KGFTab et est valable pour tous les boutons de ce KGFTab.
      TMyBitBTN n'est pas conçu pour être utilisé en-dehors d'un composant TKGFTab,
      sauf à créer explicitement un TPseudoContainer pour chaque ensemble cohérent de boutons
      afin de gérer correctementn les transitions de survol.
    }
    type
      TPseudoContainer = class
      private
        fHoverButton: integer;
      published
        property HoverButton: integer read fHoverButton write fHoverButton;
      end;
     
    {
      TMyBitBtn est exactement TBitBtn, avec une méthode pour construire le glyph et une propriété de couleur pour le bouton.
    }
    {$ifdef ColorButton}
    type TMyBitBtn = class(TBitBtnWithColor)
    {$else}
    type TMyBitBtn = class(TBitBtn)
    {$endif}
      private
        fKGFTab: integer;
        fOldColor: TColor;
        fHoovering: boolean;
      published
        property KGFTab: integer read fKGFTab write fKGFTab;
        property OldColor: TColor read fOldColor write fOldColor;
        property Hoovering: boolean read fHoovering write fHoovering;
        function SetGlyph(gs: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;
        constructor Create(AOwner: TComponent); override;
        Destructor  Destroy; override;
        procedure MyBtnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    end;
     
    {
       Définition du contrôle TKGFTab
    }
    type
      TKGFTab = class(TPanel)
        private
          fKGFTabHandle: HWND;                                          // handle de cet objet
          fTabIndex: integer;                                           // index de l'onglet sélectionné
          fTabLabels: TStringList;                                      // liste des libellés des boutons (sera sprrimé plus tard)
          fButtons: TObjectList;                                        // liste des boutons, dans l'ordre
          fSheets: TObjectList;                                         // liste des pages (dans l'ordre)
          fButtonPosition: TButtonPosition;                             // position des boutons (haut, gauche, bas, droite)
          fButtonHeight: integer;                                       // hauteur de tous les boutons
          fButtonWidth: integer;                                        // largeur de tous les boutons
          fMultiRowButtons: boolean;                                    // flag "permettre l'organisation des boutons en lignes multiples"
          fGlyphSize: integer;                                          // hauteur et largeur d'une icône des glyphs
          fUserEventHandle: HWND;                                       // handle pour l'envoi d'un USER_EVENT
          fPseudoContainer: TPseudoContainer;                           // serrt à regrouper les boutons pour le survom
          procedure SetTabIndex(aIndex: integer);                       // méthode: sélection et affichage d'un onglet avec sa page
          procedure OnClick(Sender: TObject);                           // évènement: clic sur les boutons représentant les onglets
          procedure SetButtonPosition(aPosition: TButtonPosition);      // méthode: changer le positionnement des boutons
          procedure SetButtonHeight(aHeight: integer);                  // méthode: changer la hauteur des boutons
          procedure SetButtonWidth(aWidth: integer);                    // méthode: changer la largeur des boutons
          procedure SetMultiRowButtons(aMode: boolean);                 // méthode gérer le mode de boutons en lignes multiples
        published
          property KGFTabHandle: HWND read fKGFTabHandle write fKGFTabHandle;
          property TabIndex: integer read fTabIndex write SetTabIndex;
          property ButtonPosition: TButtonPosition read fButtonPosition write SetButtonPosition;
          property ButtonHeight: integer read fButtonHeight write SetButtonHeight;
          property ButtonWidth: integer read fButtonWidth write SetButtonWidth;
          property MultiRowButtons: boolean read fMultiRowButtons write SetMultiRowButtons;
          property GlyphSize: integer read fGlyphSize write fGlyphSize;
          property UserEventHandle: HWND read fUserEventHandle write fUserEventHandle;
          property PseudoContainer: TPseudoContainer read fPseudoContainer write fPseudoContainer;
          procedure SetTabLabel(aIndex: integer; aLabel: string);       // méthode: changer un libellé d'un onglet (bouton)
          procedure AddTab(aLabel: string);                             // méthode; ajouter un onglet (bouton et page)
          procedure InsertTab(aIndex: integer; aLabel: string);         // méthode; insérer un onglet (bouton et page)
          procedure DeleteTab(aIndex: integer);                         // méthode; supprimer un onglet (bouton et page)
          procedure Refresh;                                            // méthode: réafficher le cotrôle (après reconfiguration)
          function SetButtonGlyph(aIndex: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;  // méthode: construire le glyphe d'un bouton
          function Configure(n: integer; aScript: TStrings): integer;   // méthode: exécution d'un script pour configurer le contrôle
          function GetTabPageHandles: string;                           // méthode: retourner la liste des handles des pages (provisoire)
          constructor Create(AOwner: TComponent); override;
          Destructor  Destroy; override;
      end;
     
    {$ifdef PanoramicWrapper}             // doit être défini UNIQUEMENT si ce module est utilisé dans KGF.dmm avec un programmePanoramic !
    var
      TempForm: TForm;
     
    function CreateKGFTab(hDest: HWND): integer; stdcall;
    function ConfigureKGFTab(KT: TKGFTab; aScript: integer): integer; stdcall;
    {$endif}
     
    implementation
     
    procedure TMyBitBtn.MyBtnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
      if TMyBitBtn(Sender).Hoovering then exit;
      if not assigned(TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer) then exit;
      TMyBitBtn(Sender).Hoovering := true;
      if TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton<>0 then
        if TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton<>integer(Sender) then
            TMyBitBtn(TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton).Font.Style := [];
     
      TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton := integer(Sender);
      TMyBitBtn(Sender).Font.Style := [fsBold, fsItalic];
      TMyBitBtn(Sender).Hoovering := false;
    end;
     
     
    {
       Les 3 procédures suivantes sont utilisées dans le cadre du wrapper Panoramic.
       Mais elles peuvent servir partiellement dans un environnement généraL;
       C'est pourquoi les parties spécifiques à Panoramic ont été entourées de compilation conditionnelle.
       procédures et fonctions:
         Délay    attente de quelques milli-secondes, nécessaire dans certains cas
         CopyStringToPanoramic     procédure envoyant un string à une destination généralisée
         GetStringFromPanoramic    fonction récupérant un string à partir d'une origine généralisée
       Une origine ou destination "généralisée" est une valeur entière pouvant être, indifféremment:
         - adresse une variable string
              adr(text$) en Panoramic
              une valeur PString en Delphi
         - le handle d'un objet TMemo
         - le handle d'un objet TListBox
    }
    procedure Delay(AMSecs: Cardinal);
    var
      iStop : cardinal;
    begin
      iStop := GetTickCount + AMsecs;
      while GetTickCount < iStop do
      begin
        Forms.Application.ProcessMessages;    // <=================== où est "Application" ?
        sleep(1);
      end
    end;   
     
    // procédure compatible avec la version compilée de PANORAMIC
    //   s   = string (éventuellement multi-ligne) à envoyer à Panoramic
    //   par = identifiant de destination   soit ADR(s$)    soit HANDLE(memo%)
      procedure CopyStringToPanoramic(s: string; par: integer);
      var
        p1, p2: pchar;
        n, p: integer;
        memo: TMemo;
        s1, s2: string;
        control: TWinControl;
        pi, po: pbyte;
        zero: byte;
     
        function GetClassName(Handle: THandle): String;
        var
          Buffer: array[0..MAX_PATH] of Char;
        begin
          Windows.GetClassName(Handle, @Buffer, MAX_PATH);
          Result := String(Buffer);
        end;
     
      begin
        if par=0 then exit;
        try
          memo := TMemo(par);
          if memo.ClassName='TMemo' then begin
            s1 := s;
            memo.Text := trim(s1+' ');
            exit;
          end;
        except
        end;
     
        try
          if GetClassName(par)='TMemo' then begin
            s1 := s;
            SendMessage(par,WM_SETTEXT,0,integer(pchar(s1)));
            exit;
          end;
        except
        end;
     
        try
          if GetClassName(par)='TListBox' then begin
            SendMessage(par,LB_RESETCONTENT,0,0);
            s1 := s + #13#10;
            while s1<>'' do begin
              p := pos(#13#10,s1);
              if p>0 then begin
                s2 := LeftStr(s1,p-1);
                s1 := MidStr(s1,p+2,Length(s1));
                SendMessage(par,LB_ADDSTRING,0,integer(pchar(s2)));
              end;
            end;
            if s1<>'' then SendMessage(par,LB_ADDSTRING,0,integer(pchar(s1)));
            exit;
          end;
        except
        end;
     
        zero := 0;
        p1 := @zero;
        n := length(s);
        if n>0 then p1 := @s[1];
    {$ifdef PanoramicWrapper}
        if PCompiledMode then begin
          // mode compilé
          pi := pbyte(@s[1]);
    {$if StringParameterMethod=1}
          po := pbyte(par);                         // méthode V1 (Jack): ADR(s$) pointe vers l'adresse du premier caractère
    {$else}
          po := pbyte(pinteger(par)^);              // méthode V2 (Jack): ADR(s$) pointe vers un mot contenant l'adresse du premier caractère
    {$ifend}
          while po^<>0 do begin
            if pi^<>0 then begin
              po^ := pi^;
              inc(po);
              inc(pi);
            end else begin
              po^ := 32;
              inc(po);
            end;
          end;
        end else begin
    {$endif}
          //mode interprété
          if n>0 then p1 := pchar(@s[1]);
          p2 := pchar(pinteger(par)^);
          while p2^<>#0 do begin
            if n>0 then begin
                     if p1<>#0 then p2^ := p1^
                               else dec(p2);
                   end else begin
                     p2^ := #32;
                   end;
            inc(p1);
            inc(p2);
            dec(n);
          end;
    {$ifdef PanoramicWrapper}
        end;
    {$endif}
      end;
     
    // fonction compatible avec la version compilée de PANORAMIC
    //   par = identifiant de destination   soit ADR(s$)    soit HANDLE(memo%)
      function GetStringFromPanoramic(par: integer): string;
      var
        n, Len, cnt, i: integer;
        memo: TMemo;
        lb: TListBox;
        s1, s2: string;
        pb: pbyte;
        pi: pinteger;
     
        function GetClassName(Handle: THandle): String;
        var
          Buffer: array[0..MAX_PATH] of Char;
        begin
          Windows.GetClassName(Handle, @Buffer, MAX_PATH);
          Result := String(Buffer);
        end;
     
      begin
        result := '';
        if par=0 then exit;
        try
          memo := TMemo(par);
          if memo.ClassName='TMemo' then begin
            result := memo.Text;
            exit;
          end;
        except
        end;
     
        try
          if GetClassName(par)='TMemo' then begin
     
            Len := SendMessage(par, WM_GETTEXTLENGTH, 0, 0);
            if Len>0 then begin
              SetLength(s1, Len+1);
              Len := SendMessage(par, WM_GETTEXT, Len+1, LPARAM(PChar(s1)));
              delay(100);
              SetLength(s1, Len);
            end;
     
            result := Trim(s1);
            exit;
          end;
        except
        end;
     
        try
          if GetClassName(par)='TListBox' then begin
     
            cnt := SendMessage(par, LB_GETCOUNT, 0, 0);
            s1 := '';
            if cnt<>LB_ERR then begin
              for i:=0 to cnt-1 do begin
                s2 := '';
                Len := SendMessage(par, LB_GETTEXTLEN, i, 0);
                if Len>0 then begin
                  SetLength(s2, Len+1);
                  SendMessage(par, LB_GETTEXT, i, LPARAM(PChar(s2)));
                  delay(100);
                  s1 := s1 + Trim(s2) + #13#10;
                end else begin
                  s1 := s1 + #13#10;
                end;
              end;
            end;
     
            result := Trim(s1);
            exit;
          end;
        except
        end;
     
    {$ifdef PanoramicWrapper}
        if PCompiledMode then begin
          cnt := 0;
    {$if StringParameterMethod=1}
          pb := pbyte(par);                         // méthode V1 (Jack): ADR(s$) pointe vers l'adresse du premier caractère
    {$else}
          if pinteger(par)^<>0 then begin
            pb := pbyte(pinteger(par)^);              // méthode V2 (Jack): ADR(s$) pointe vers un mot contenant l'adresse du premier caractère
    {$ifend}
            while pb^<>0 do begin
              inc(pb);
              inc(cnt);
            end;
          end;
          SetLength(result,cnt);
          if cnt>0 then begin
            pb := pbyte(pinteger(par)^);
            for i:=1 to cnt do begin
              result[i] := chr(pb^);
              inc(pb);
            end;
          end;
        end else begin
          result := pstring(par)^;
        end;
    {$else}
        result := pstring(par)^;
    {$endif}
      end;
     
    {
       fin des 3 procédures spécifiques à l'environnement Panoramic
    }
     
     
     
     
    function TMyBitBtn.SetGlyph(gs: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;
    // dimensions Delphi d'un TBitBtn par défaut: 25 x 75 pixels, tous ajustavles.
    // les icônes sont placées dans un Glyph avec 4 images carrées distinctes de dimensions identiques.
    // la longueur d'un côté est éterminé par la hauteur de la première bitmap.
    // le glyphe a donc les dimensions (hauteur) sur (4 x hauteur).
    var
      n, ng: integer;
      bmp, bmp1: TBitmap;
      rct: TRect;
    begin
      result := false;
      if not assigned(aImage1) then exit;                            //  au moins la première bitmap doit exieter !
      if aImage1.ClassName<>'TImage' then exit;
      n := aImage1.Height;                                           //  prendre la hauteur
      if n<>aImage1.Width then exit;                                 //  l'mage doit être carrée
      ng := 1;                                                       //  ici, on a la première image
     
      if assigned(aImage2) then begin                                //  les autres images doivent avoir les mêmes dimensions
        if aImage2.ClassName<>'TImage' then exit;
        if (aImage2.Height=n) and (aImage2.Width=n) then begin
          ng := 2;
          if assigned(aImage3) then begin
            if aImage3.ClassName<>'TImage' then exit;
            if (aImage3.Height=n) and (aImage3.Width=n) then begin
              ng := 3;
              if assigned(aImage4) then begin
              if aImage4.ClassName<>'TImage' then exit;
                if (aImage4.Height=n) and (aImage4.Width=n) then  ng := 4;
              end;
            end;
          end;
        end;
      end;
     
      // copier les images dans le glyph
      bmp1 := TBitmap.Create;
      bmp1.Width := gs * ng;
      bmp1.Height := gs;
      bmp1.PixelFormat := pf24bit ;
     
      if n>=1 then begin
        bmp := TBitmap.Create;                             // bitmap temporaire
        bmp.PixelFormat := pf24bit ;
        Bmp.Assign(aImage1.Picture.Graphic);
        rct := Rect(0,0,gs-1,gs-1);                          // rectangle cible pour l'image 1
        bmp1.Canvas.StretchDraw(rct,bmp);
        bmp.Free;
      end;
     
      if n>=2 then  begin
        bmp := TBitmap.Create;                             // bitmap temporaire
        bmp.PixelFormat := pf24bit ;
        Bmp.Assign(aImage2.Picture.Graphic);
        rct := Rect(gs,0,2*gs-1,gs-1);                        // rectangle cible pour l'image 2
        bmp1.Canvas.StretchDraw(rct,bmp);
        bmp.Free;
      end;
     
      if n>=3 then  begin
        bmp := TBitmap.Create;                             // bitmap temporaire
        bmp.PixelFormat := pf24bit ;
        Bmp.Assign(aImage3.Picture.Graphic);
        rct := Rect(2*gs,0,3*gs-1,gs-1);                      // rectangle cible pour l'image 3
        bmp1.Canvas.StretchDraw(rct,bmp);
        bmp.Free;
      end;
     
      if n>=4 then begin
        bmp := TBitmap.Create;                             // bitmap temporaire
        bmp.PixelFormat := pf24bit ;
        Bmp.Assign(aImage4.Picture.Graphic);
        rct := Rect(3*gs,0,4*gs-1,gs-1);                     // rectangle cible pour l'image 4
        bmp1.Canvas.StretchDraw(rct,bmp);
        bmp.Free;
      end;
     
     
      Glyph.Assign(bmp1);
      NumGlyphs := ng;
      bmp1.Free;
      result := true;
    end;
     
    {
    icônes dans le bitmap d'un glyph (toutes de la même taille):
      Premier   - Haut       - Cette image apparaît quand le bouton n'est pas sélectionné (l'état normal d'un bouton). Cette image est aussi utilisée lorsque le bouton détient la focalisation (par exemple, si vous le sélectionnez au moyen de la touche tab). Dans ce cas, un rectangle de focalisation est dessiné autour du bouton. S'il n'y a pas d'autres images dans le bitmap, les boutons bitmaps utilisent aussi cette image pour tous les autres états.
      Second    - Désactivé  - Cette image apparaît, en général, estompée, pour indiquer que le bouton ne peut être sélectionné.
      Troisième - Cliqué     - Cette image apparaît quand le bouton est cliqué. L'image de l'état haut réapparaît quand l'utilisateur relâche le bouton de la souris.
      Quatrième - Bas        - Cette image apparaît quand le bouton reste enfoncé, indiquant qu'il reste sélectionné.
    }
     
    constructor TMyBitBtn.Create(AOwner: TComponent);
    begin
      inherited Create(aOwner);
      fKGFTab := integer(aOwner);
      self.Layout := blGlyphLeft;                    // le glyph est forcé sur le côté gauche du bouton.
      OldColor := Color;                             // mémoriser la couleur d'origine
      fHoovering := false;
      OnMouseMove := MyBtnMouseMove;
    end;
     
    Destructor  TMyBitBtn.Destroy;
    begin
      OnMouseMove := nil;
      inherited;
    end;
     
    // création de l'objet TKGFTab
    constructor TKGFTab.Create(AOwner: TComponent);
    var
      btn: TMyBitBtn;
      sht: TPanel;
    begin
      inherited Create(nil);                                                        // créer l'objet selon le modèle TPanel
      if assigned(AOwner) then  self.ParentWindow := TWinControl(aOwner).Handle;    // et le faire apparaître dans l'objet cible
      fKGFTabHandle := self.Handle;
    {$ifdef PanoramicWrapper}
    {$else}
      PCompiledMode := false;
    {$endif}
      // installer les valeurs par défaut
      fButtonPosition := bpTop;                      // boutons en haut
      fButtonHeight := 25;                           // dimensions s'un TBitBtn par défaut
      fButtonWidth := 75;
      fGlyphSize := 16;                              // dimensions par défaut des icônes des glyphs
      fTabLabels := TStringList.Create;
      fTabLabels.Add('Default');                     // ajouter un onglet par défaut avec son bouton
      fButtons := TObjectList.Create;
      fButtons.OwnsObjects := true;                  // les listes des boutons et pages "possèdent" leurs objets
      fSheets := TObjectList.Create;
      fSheets.OwnsObjects := true;
      fPseudoContainer := TPseudoContainer.Create;
      fPseudoContainer.HoverButton := 0;             // actuellement, pas de bouton en survol
      Width := 300;                                  // dimensions par défaut de l'objet TKGFTab
      Height := 200;
     
      // creation du bouton de la page par défaut
      btn := TMyBitBtn.Create(self);
      btn.Height := fButtonHeight;
      btn.Width := fButtonWidth;
      btn.Caption := fTabLabels.Strings[0];
      if self.Handle<>0 then  btn.ParentWindow := self.Handle;            // placer le nouveau bouton dans l'objet TKGFTab
      btn.OnClick := OnClick;
      btn.Tag := 0;                                                       // mémoriser l'indice de la page dans le bouton
     
      fButtons.Add(btn);
     
      // création de la page par défaut
      sht := TPanel.Create(self);
      sht.ParentWindow := self.Handle;                                   // placer la nouvelle page dans l'objet TKGFTab
      case ButtonPosition of
        bpTop:    begin
                    sht.Top := btn.Height;
                    sht.Left := 0;
                    sht.Width := Width;
                    sht.Height := Height - btn.Height;
                  end;
        bpLeft:   begin
                    sht.Top := 0;
                    sht.Left := btn.Width;
                    sht.Width := Width - sht.Left;
                    sht.Height := Height;
                  end;
        bpBottom: begin
                    sht.Top := 0;
                    sht.Left := 0;
                    sht.Width := Width;
                    sht.Height := Height - btn.Height;
                  end;
        bpRight:  begin
                    sht.Top := 0;
                    sht.Left := 0;
                    sht.Width := Width - btn.Width;
                    sht.Height := Height;
                  end;
      end;     
      fSheets.Add(sht);
     
      fTabIndex := 0;                                            // sélectionner l'unique page
     
    end;
     
    destructor TKGFTab.Destroy;
    begin
      fTabLabels.Clear;
      fTabLabels.Free;
      fTabLabels := nil;
      fButtons.Free;
      fButtons := nil;
      fSheets.Free;
      fSheets := nil;
      fPseudoContainer.Free;
      inherited;
    end;
     
    // évènement appelé lors d'un click sur un des boutons de page pour faire apparaître cette page
    procedure TKGFTab.OnClick(Sender: TObject);
    var
      n, res, WP, LP: integer;
    begin
      n := TMyBitBtn(Sender).Tag;                                              // ici, on sait quelle page est associée
      if n<>fTabIndex then begin                                               // uniquement si la page actuelle n'est pas celle quiest ciblée
        TPanel(fSheets.Items[fTabIndex]).Visible := false;                     // cacher la page actuellement visible
        TPanel(fSheets.Items[n]).Visible := true;                              // montrer la page ciblée
        TMyBitBtn(fButtons.Items[n]).SetFocus;                                 // et sélectionner le bouton associé
        fTabIndex := n;
        if TKGFTab(TMyBitBtn(Sender).KGFTab).fUserEventHandle<>0 then begin    // est-ce qu'il faut envoyer un USER_EVENT ?
          WP := UserEventKGFTab or UserEventTabSelect or TMyBitBtn(Sender).Tag;   // signaler origine KGFTab cause sélection
          LP := TMyBitBtn(Sender).KGFTab;                                      // donner l'identifiant du KGFTab à l'origine de l'évènement
          res := SendMessage(fUserEventHandle, CM_PANORAMIC_USER, WP, LP);     // envoyer le USER_EVENT
        end;
      end;
    end;
     
    // sélectionner un onglet et une page par programme
    procedure TKGFTab.SetTabIndex(aIndex: integer);
    begin
      if aIndex<0 then exit;
      if aIndex>=fSheets.Count then exit;
      if aIndex=fTabIndex then exit;
      if not TMyBitBtn(fButtons.Items[aIndex]).Enabled then exit;
      TPanel(fSheets.Items[fTabIndex]).Visible := false;
      TPanel(fSheets.Items[aIndex]).Visible := true;
      TMyBitBtn(fButtons.Items[aIndex]).SetFocus;
      fTabIndex := aIndex;
    end;
     
    // changer le libellé d'un bouton
    procedure TKGFTab.SetTabLabel(aIndex: integer; aLabel: string);
    begin
      if aIndex<0 then exit;
      if aIndex>=fSheets.Count then exit;
      fTabLabels.Delete(aIndex);
      fTabLabels.Insert(aIndex,aLabel);
      TMyBitBtn(fButtons.Items[aIndex]).Caption := aLabel;
    end;
     
    // ajouter un nouvel onglet
    procedure TKGFTab.AddTab(aLabel: string);
    var
      btn: TMyBitBtn;
      sht: TPanel;
      n: integer;
    begin
      fTabLabels.Add(aLabel);
     
      // créer le nouveau bouton
      btn := TMyBitBtn.Create(self);
      btn.Height := fButtonHeight;
      btn.Width := fButtonWidth;
      btn.Caption := aLabel;
      btn.ParentWindow := self.Handle;
      btn.OnClick := OnClick;
      n := fButtons.Count;
      btn.Tag := n;                        // mémoriser l'indexe (l'identification) de ce bouton
     
      fButtons.Add(btn);
     
      // créer la nouvelle page
      sht := TPanel.Create(self);
      sht.ParentWindow := self.Handle;
     
      sht.Visible := false;                                  // cacher le nouvel onglet
      fSheets.Add(sht);
      Refresh;
     
      TMyBitBtn(fButtons.Items[fTabIndex]).SetFocus;         // réactiver l'onglet actuellement ciblé
    end;
     
    // insérer un nouvel onglet en position aIndex
    procedure TKGFTab.InsertTab(aIndex: integer; aLabel: string);
    var
      btn: TMyBitBtn;
      sht: TPanel;
      n, i: integer;
    begin
      n := fButtons.Count;
      if aIndex<0 then exit;
      if aIndex>=n then exit;
     
      fTabLabels.Insert(aIndex,aLabel);
     
      btn := TMyBitBtn.Create(self);
      btn.Height := fButtonHeight;
      btn.Width := fButtonWidth;
      btn.Caption := aLabel;
      btn.ParentWindow := self.Handle;
      btn.OnClick := OnClick;
      btn.Tag := aindex;
     
      if aIndex<=fTabIndex then  fTabIndex := fTabIndex + 1;
      fButtons.Insert(aIndex,btn);
     
      sht := TPanel.Create(self);
      sht.ParentWindow := self.Handle;
     
      sht.Visible := false;
      fSheets.Insert(aIndex,sht);
      for i:=0 to fSheets.Count-1 do TMyBitBtn(fButtons.Items[i]).Tag := i;
      Refresh;
     
      TMyBitBtn(fButtons.Items[fTabIndex]).SetFocus;
    end;
     
    // supprimer un onglet avec son bouton et sa page
    procedure TKGFTab.DeleteTab(aIndex: integer);
    var
      n, i, d: integer;
    begin
      n := fButtons.Count;
      if n<0 then exit;
      if aIndex<0 then exit;
      if aIndex>=n then exit;
     
      fTabLabels.Delete(aIndex);
     
      n := fButtons.Count;
      fButtons.Delete(aIndex);
      n := n - 1;
     
      fSheets.Delete(aIndex);
      if fTabIndex>=n then begin
        fTabIndex := n-1;
      end else begin
        fTabIndex := -1;
      end;
      if n>0 then begin
        for i:=0 to n-1 do begin
          TMyBitBtn(fButtons.Items[fTabIndex]).Tag := i;
          if i=fTabIndex then TMyBitBtn(fButtons.Items[fTabIndex]).SetFocus;
        end;
      end;
      Refresh;
    end;
     
    // créer le glyp d'un bouton à partir de 4 images (icônes) de dimensions identiques
    function TKGFTab.SetButtonGlyph(aIndex: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;
    begin
      result := false;
      if (aIndex<0) or (aIndex>=fButtons.Count) then exit;
      result := TMyBitBtn(fButtons.Items[aIndex]).SetGlyph(fGlyphSize,aImage1, aImage2, aImage3, aImage4);
    end;
     
    {
      Cette méthode permet de scripter la configuration d'un objet KGFTab.
      Toutes les méthodes sont accessibles via le script.
      Elles sont accédées par des "commandes" sous forme d'une seule ligne dans le script.
      Chaque commande est composée d'un mot-cle suivi de paramètres séparés par des ","
      et terminés par un ";". Ce qui suit le ";" est considéré comme comentaire.
      Les commandes sont insensibles à la casse.
      Format général:    commende,par1,...,parn;
      Exemple:  Left,100;
                ; ajout de nouveaux TABs
                AddTab,text;
                InsertTab,3,Autre text;    insérer un TAB devant le 4ème TAB
      Un tel script peut être passé par la partie Strings d'un TStringList ou d'un TMemo.
      Toutes les commandes seront exécutées dans l'ordre. Le script est interrompue à
      la première erreur. Le résultat de la fonction est 0 en cas de terminaison normale,
      ou n>=1 en cas d'erreur. Alors, cette valeur indique le numéro de la ligne en erreur du script.
      Chaque commande individuelle est implémentée par une procédure locale.
    }
    function TKGFTab.Configure(n: integer; aScript: TStrings): integer;
    var
      i, p: integer;
      err: boolean;
      cmd, command, params: string;
      GlyphNames: array [0..3] of string;
     
      procedure C_Parent(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        if opt=0 then exit;
        self.ParentWindow := TWinControl(opt).Handle;
        err := false;
      end;
     
      procedure C_Left(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.Left := opt;
        err := false;
      end;
     
      procedure C_Top(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.Top := opt;
        err := false;
      end;
     
      procedure C_Width(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.Width := opt;
        err := false;
        Refresh;
      end;
     
      procedure C_Height(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.Height := opt;
        err := false;
        Refresh;
      end;
     
      procedure C_Label(par: string);
      var
        p, ind: integer;
        s, spar: string;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        self.SetTabLabel(ind,spar);
        err := false;
      end;
     
      procedure C_AddTab(par: string);
      var
        p: integer;
        s: string;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        s := LeftStr(par,Length(par)-1);
        self.AddTab(s);
        err := false;
      end;
     
      procedure C_InsertTab(par: string);
      var
        p, ind: integer;
        s, spar: string;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        self.InsertTab(ind,spar);
        err := false;
      end;
     
      procedure C_DeleteTab(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.DeleteTab(opt);
        err := false;
      end;
     
    {  procedure C_InsertControl(par: string);
      var
        p, ind: integer;
        s, spar: string;
        ct: TControl;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        try
          ct := TControl(StrToInt(spar));
        except
          exit;
        end;
        self.InsertControl(ind,ct);
        err := false;
      end;  }
     
      procedure C_Glyph(par: string);
      var
        p, ind: integer;
        s, spar: string;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>3) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        GlyphNames[ind] := spar;
        err := false;
      end;
     
      procedure C_ButtonGlyph(par: string);
      var
        ind, i: integer;
        s, spar: string;
        img0, img1, img2, img3: TImage;
      begin
        err := true;
        for i:=0 to 3 do begin
          if GlyphNames[i]='' then exit;
          if not FileExists(GlyphNames[i]) then exit;
        end;
        if Length(par)<2 then exit;
        s := LeftStr(par,Length(par)-1);
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        img0 := TImage.Create(nil);
        img0.Width := fGlyphSize;
        img0.Height := fGlyphSize;
        img0.Picture.LoadFromFile(GlyphNames[0]);
        img1 := TImage.Create(nil);
        img1.Width := fGlyphSize;
        img1.Height := fGlyphSize;
        img1.Picture.LoadFromFile(GlyphNames[1]);
        img2 := TImage.Create(nil);
        img2.Width := fGlyphSize;
        img2.Height := fGlyphSize;
        img2.Picture.LoadFromFile(GlyphNames[2]);
        img3 := TImage.Create(nil);
        img3.Width := fGlyphSize;
        img3.Height := fGlyphSize;
        img3.Picture.LoadFromFile(GlyphNames[3]);
        if self.SetButtonGlyph(ind,img0,img1,img2,img3) then err := false;
        img0.Free;
        img1.Free;
        img2.Free;
        img3.Free;
      end;
     
      procedure C_TabPageHandles(par: string);
    //  var
    //    s, spar : string;
      begin
        err := true;
        if Length(par)<>1 then exit;
        {s := } self.GetTabPageHandles();
        err := false;
      end;
     
      procedure C_ButtonHeight(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.fButtonHeight := opt;
        Refresh;
        err := false;
      end;
     
      procedure C_ButtonWidth(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.fButtonWidth := opt;
        Refresh;
        err := false;
      end;
     
      procedure C_ButtonPosition(par: string);
      var
        p, opt: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        p := pos(',',par);
        if p>0 then exit;
        try
          opt := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        if (opt<0) or (opt>3) then exit;
        self.SetButtonPosition(TButtonPosition(opt));
        err := false;
      end;
     
      procedure C_TabColor(par: string);
      var
        p, ind: integer;
        s, spar: string;
        clr: TColor;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        try
          clr := TColor(StrToInt(spar));
        except
          exit;
        end;
        TPanel(self.fSheets.Items[ind]).Color := clr;
        err := false;
      end;
     
      procedure C_TabActivate(par: string);
      var
        p, ind, act: integer;
        s, spar: string;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        try
          act := StrToInt(spar);
        except
          exit;
        end;
        TMyBitBtn(self.fButtons.Items[ind]).Enabled := (act <> 0);
        err := false;
      end;
     
      procedure C_MultiRow(par: string);
      var
        p, ind, act: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        if pos(',',par)>0 then exit;
        try
          act := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.fMultiRowButtons := (act <> 0);
        err := false;
        Refresh;
      end;
     
      procedure C_GlyphSize(par: string);
      var
        p, ind, act: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        if pos(',',par)>0 then exit;
        try
          act := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        if (act<8) or (act>64) then exit;
        self.fGlyphSize := act;
        err := false;
        Refresh;
      end;
     
      procedure C_UserEvent(par: string);
      var
        p, ind, act: integer;
      begin
        err := true;
        if Length(par)<2 then exit;
        if pos(',',par)>0 then exit;
        try
          act := StrToInt(LeftStr(par,Length(par)-1));
        except
          exit;
        end;
        self.fUSerEventHandle := act;
        err := false;
        Refresh;
      end;
     
      procedure C_InsertControl(par: string);
      var
        p, ind, act: integer;
        s, spar: string;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fSheets.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        try
          act := StrToInt(spar);
        except
          exit;
        end;
        Windows.SetParent(act,TPanel(fSheets[ind]).Handle);
        err := false;
      end;
     
    {$ifdef ColorButton}
      procedure C_ButtonColor(par: string);
      var
        p, ind, act: integer;
        s, spar: string;
        clr: TColor;
      begin
        err := true;
        if Length(par)<4 then exit;
        p := pos(',',par);
        if p=0 then exit;
        s := LeftStr(par,p-1);
        spar := MidStr(par,p+1,Length(par));
        try
          ind := StrToInt(s);
        except
          exit;
        end;
        if (ind<0) or (ind>=fButtons.Count) then exit;
        if pos(',',spar)>0 then exit;
        spar := LeftStr(spar,Length(spar)-1);
        try
          act := StrToInt(spar);
          if act=-1 then clr := tMyBitBtn(fButtons[ind]).OldColor
                    else clr := TColor(act); 
        except
          exit;
        end;
        TMyBitBtn(fButtons[ind]).Color := clr;
        err := false;
      end;
    {$endif}
     
    // procédure principale pour le tratement du script
    begin
      result := -1;                                                 // script manquant
      if n<=0 then exit;
      for i:=0 to n-1 do begin
        err := false;                                               // supposer "commande correcte"
        result := i+1;                                              // retourner le numéro de ligne en cas d'erreur
        cmd := aScript.Strings[i];                                  // prendre une ligne de commande
        p := Pos(';',cmd);                                          // chercher la fin de la comande
        if p=0 then exit;                                           // syntaxe invalide ?
        if p<Length(cmd) then cmd := LeftStr(cmd,p);                // ignorer le commentaire
        if cmd<>';' then begin                                      // ignorer les lignes vides
          // identifier le mot-clé de la commande
          p := pos(',',cmd);
          if p=0 then begin
            command := LowerCase(LeftStr(cmd,Length(cmd)-1));
            params := ';';
          end else begin
            command := LowerCase(LeftStr(cmd,p-1));
            params := MidStr(cmd,p+1,300);
          end;
          // appel des procédures spécifiques pour chaque commande
          if command='parent' then C_Parent(params);
          if command='left' then C_Left(params);
          if command='top' then C_Top(params);
          if command='width' then C_Width(params);
          if command='height' then C_Height(params);
          if command='label' then C_Label(params);
          if command='addtab' then C_AddTab(params);
          if command='inserttab' then C_InsertTab(params);
          if command='deletetab' then C_DeleteTab(params);
          if command='insertcontrol' then C_InsertControl(params);
          if command='glyph' then C_Glyph(params);
          if command='buttonglyph' then C_ButtonGlyph(params);
          if command='tabhandles' then C_TabPageHandles(params);
          if command='buttonheight' then C_ButtonHeight(params);
          if command='buttonwidth' then C_ButtonWidth(params);
          if command='buttonposition' then C_Buttonposition(params);
          if command='tabcolor' then C_TabColor(params);
          if command='tabActivate' then C_TabActivate(params);
          if command='multirow' then C_MultiRow(params);
          if command='glyphsize' then C_GlyphSize(params);
          if command='userevent' then C_UserEvent(params);
          if command='insertcontrol' then C_InsertControl(params);
    {$ifdef ColorButton}
          if command='buttoncolor' then C_ButtonColor(params);
    {$endif}
     
          if err then exit;                                         // commande en erreur ? abandonner l'analyse
        end;
      end;
      result := 0;
    end;
     
    // cette méthode réaffiche l'ensemble de l'objet TKGFTab (après un changement des paramètres de cofiguration)
    procedure TKGFTab.Refresh;
    var
      n, i: integer;
      nBoutons, nSheets, maxbtn: integer;    // limites
      xTop, xLeft, nbtn: integer;            // situation dynamique en cours de traitement
    begin
      nBoutons := fButtons.Count;   // nombre de boutons au total
      nsheets := fSheets.Count;     // nombre de pages au total
      maxbtn:= 3000;                // nombre maxi de boutons par ligne
      nbtn := 0;                    // nombre de boutons dans la ligne actuelle
      case ButtonPosition of
        bpTop:  begin
                  if fMultiRowButtons then maxbtn := Trunc(Width / ButtonWidth);
                  if nBoutons>0 then begin
                    xLeft := - ButtonWidth;
                    xTop := 0;
                    for i:=0 to nBoutons-1 do begin
                      TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
                      TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
                      if fMultiRowButtons then begin
                        if nbtn>=maxbtn then begin
                          nbtn := 0;
                          xtop := xtop + ButtonHeight;
                          xLeft := 0;
                        end else begin
                          xLeft := xLeft + ButtonWidth;
                        end;
                      end else begin
                        xTop := 0;
                        xLeft := i * ButtonWidth;
                      end;
                      TMyBitBtn(fButtons.Items[i]).Left := xLeft;
                      TMyBitBtn(fButtons.Items[i]).Top := xTop;
                      nbtn := nbtn + 1;
                    end;
                  end;
                  if nsheets>0 then begin
                    xTop := TMyBitBtn(fButtons.Items[nBoutons-1]).Top;
                    for i:=0 to nsheets-1 do begin
                      TPanel(fSheets.Items[i]).Left := 0;
                      TPanel(fSheets.Items[i]).Top := xTop + TMyBitBtn(fButtons.Items[nBoutons-1]).Height;
                      TPanel(fSheets.Items[i]).Width := self.Width;
                      TPanel(fSheets.Items[i]).Height := self.Height - xTop;
                    end;
                  end;
                end;
        bpLeft: begin
                  if fMultiRowButtons then maxbtn := Trunc(Height / ButtonHeight);
                  if nBoutons>0 then begin
                    xLeft := 0;
                    xTop := - ButtonHeight;
                    for i:=0 to nBoutons-1 do begin
                      TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
                      TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
                      if fMultiRowButtons then begin
                        if nbtn>=maxbtn then begin
                          nbtn := 0;
                          xleft := xLeft + ButtonWidth;
                          xTop := 0;
                        end else begin
                          xTop := xTop + ButtonHeight;
                        end;
                      end else begin
                        xLeft := 0;
                        xTop := i * ButtonHeight;
                      end;
                      TMyBitBtn(fButtons.Items[i]).Left := xLeft;
                      TMyBitBtn(fButtons.Items[i]).Top := xTop;
                      nbtn := nbtn + 1;
                    end;
                  end;
                  if nsheets>0 then begin
                    xLeft := TMyBitBtn(fButtons.Items[nBoutons-1]).Left + TMyBitBtn(fButtons.Items[nBoutons-1]).Width;
                    for i:=0 to nsheets-1 do begin
                      TPanel(fSheets.Items[i]).Left := xLeft;
                      TPanel(fSheets.Items[i]).Top := 0;
                      TPanel(fSheets.Items[i]).Width := self.Width - xLeft;
                      TPanel(fSheets.Items[i]).Height := self.Height;
                    end;
                  end;
                end;
        bpBottom:  begin
                  if fMultiRowButtons then maxbtn := Trunc(Width / ButtonWidth);
                  if nBoutons>0 then begin
                    xLeft := - ButtonWidth;
                    xTop := height - ButtonHeight;
                    for i:=0 to nBoutons-1 do begin
                      TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
                      TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
                      if fMultiRowButtons then begin
                        if nbtn>=maxbtn then begin
                          nbtn := 0;
                          xtop := xtop - ButtonHeight;
                          xLeft := 0;
                        end else begin
                          xLeft := xLeft + ButtonWidth;
                        end;
                      end else begin
                        xTop := Height - ButtonHeight;
                        xLeft := i * ButtonWidth;
                      end;
                      TMyBitBtn(fButtons.Items[i]).Left := xLeft;
                      TMyBitBtn(fButtons.Items[i]).Top := xTop;
                      nbtn := nbtn + 1;
                    end;
                  end;
                  if nsheets>0 then begin
                    xTop := TMyBitBtn(fButtons.Items[nBoutons-1]).Top;
                    for i:=0 to nsheets-1 do begin
                      TPanel(fSheets.Items[i]).Left := 0;
                      TPanel(fSheets.Items[i]).Top := 0;
                      TPanel(fSheets.Items[i]).Width := self.Width;
                      TPanel(fSheets.Items[i]).Height := xTop;
                    end;
                  end;
                end;
        bpRight: begin
                  if fMultiRowButtons then maxbtn := Trunc(Height / ButtonHeight);
                  if nBoutons>0 then begin
                    xLeft := Width - ButtonWidth;
                    xTop := - ButtonHeight;
                    for i:=0 to nBoutons-1 do begin
                      TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
                      TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
                      if fMultiRowButtons then begin
                        if nbtn>=maxbtn then begin
                          nbtn := 0;
                          xleft := xLeft - ButtonWidth;
                          xTop := 0;
                        end else begin
                          xTop := xTop + ButtonHeight;
                        end;
                      end else begin
                        xTop := i * ButtonHeight;
                      end;
                      TMyBitBtn(fButtons.Items[i]).Left := xLeft;
                      TMyBitBtn(fButtons.Items[i]).Top := xTop;
                      nbtn := nbtn + 1;
                    end;
                  end;
                  if nsheets>0 then begin
                    xLeft := TMyBitBtn(fButtons.Items[nBoutons-1]).Left;
                    for i:=0 to nsheets-1 do begin
                      TPanel(fSheets.Items[i]).Left := 0;
                      TPanel(fSheets.Items[i]).Top := 0;
                      TPanel(fSheets.Items[i]).Width := xLeft;
                      TPanel(fSheets.Items[i]).Height := self.Height;
                    end;
                  end;
                end;
      end;
    end;
     
    // déplacer les boutons (haut, gauche, bas, droite)
    procedure TKGFTab.SetButtonPosition(aPosition: TButtonPosition);
    begin
       fButtonPosition := aPosition;
       Refresh;
    end;
     
    // adapter la hauteur des boutons
    procedure TKGFTab.SetButtonHeight(aHeight: integer);
    var
      n, i: integer;
    begin
      if fButtonHeight=aHeight then exit;
      if (aHeight<18) or (aHeight>66) then exit;
      fButtonHeight := aHeight;
      Refresh;
    end;
     
    // adapter la largeur des boutons
    procedure TKGFTab.SetButtonWidth(aWidth: integer);
    var
      n, i: integer;
    begin
      if fButtonWidth=aWidth then exit;
      if (aWidth<18) or (aWidth>250) then exit;
      fButtonWidth := aWidth;
      Refresh;
    end;
     
    // gérer le mode de boutons en lignes multiples
    procedure TKGFTab.SetMultiRowButtons(aMode: boolean);
    begin
      if MultiRowButtons<>aMode then begin
        fMultiRowButtons := aMode;
        Refresh;
      end;
    end;
     
    // retourner la liste des handles des pages du TKGFTab.
    // Ceci servira pour placer des objets dans les pages si le contrôle est dans une DLL, par exemple
    function TKGFTab.GetTabPageHandles: string;
    var
      n, i: integer;
      s: string;
    begin
      n := fSheets.Count;
      s := '';
      if n>0 then begin
        for i:=0 to n-1 do s := s + IntToStr(TPanel(fSheets.Items[i]).Handle) + #13#10;
      end;
      result := s;
    end;
     
     
     
    {
       *************************************************************
       *************************************************************
       **************** Interface PANORAMIC ************************
       *************************************************************
       *************************************************************
    }
    {$ifdef PanoramicWrapper}
     
    function CreateKGFTab(hDest: HWND): integer; stdcall; export;
    var
      KT: TKGFTab;
    begin
      result := 0;
      try
        if hDest=0 then exit;
        TempForm := TForm.Create(nil);          // nécessaire !
        TempForm.Visible := false;              // nécessaire !
        KT := TKGFTab.Create(TempForm);
        KT.ParentWindow := hDest;
        result := integer(KT);
      except
      end;
    end;
    exports CreateKGFTab;
     
    function ConfigureKGFTab(KT: TKGFTab; aScript: integer): integer; stdcall; export;
    var
      sl: TStringList;
    begin
      result := -1;
      try
        if not assigned(KT) then exit;
        if KT.ClassName<>'TKGFTab' then exit;
        if aScript=0 then exit;
        sl := TStringList.Create;
        sl.Text := GetStringFromPanoramic(aScript);
        result := KT.Configure(sl.Count,sl);
        sl.Free;
      except
        if assigned(sl) then sl.Free;
      end;
    end;
    exports ConfigureKGFTab;
     
    function DeleteKGFTab(KT: TKGFTab): integer; stdcall; export;
    begin
      result := integer(KT);
      try
        if not assigned(KT) then exit;
        if KT.ClassName<>'TKGFTab' then exit;
        KT.Free;
        result := 0;
      except
      end;
    end;
    exports DeleteKGFTab;
     
    function GetKGFTabPageHandles(KT: TKGFTab; dest: integer): integer; stdcall; export;
    var
      s: string;
    begin
      result := -1;
      try
        if not assigned(KT) then exit;
        if KT.ClassName<>'TKGFTab' then exit;
        s := KT.GetTabPageHandles;
        CopyStringToPanoramic(s,dest);
        result := 0;
      except
      end;
    end;
    exports GetKGFTabPageHandles;
     
    function GetKGFTabHandle(KT: TKGFTab): integer; stdcall; export;
    begin
      result := 0;
      try
        if not assigned(KT) then exit;
        if KT.ClassName<>'TKGFTab' then exit;
        result := KT.KGFTabHandle;
      except
      end;
    end;
    exports GetKGFTabHandle;
     
    {$endif}
     
    end.
    Ce dernier module contient un wrapper pour l'accex par le langage de programmation Panoramic (un clône de Basic), mais TKGFTab est parfaitemnt utilisable en Delphi directement.

    La particularité de ce composant est la possibilité de le "scripter" en lui passant le contenu d'un TMemo avsc des commandes agissant sur les propriétés de l'objet.

    Je remercie tous ceux qui ont pris la peine de chercher une solution à mon problème et je suis heureux de pouvoir signaler que j'ai trouvé une solution opérationnelle !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajouter des chemins dans la variable PATH
    Par Righetto Dominique dans le forum Linux
    Réponses: 7
    Dernier message: 21/03/2004, 17h38
  2. [VBA-E] Ajouter des fonctions dans Excel
    Par Clezio dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 06/03/2004, 01h18
  3. Ajouter des contrôles dans la palette des contrôles.
    Par WOLO Laurent dans le forum MFC
    Réponses: 4
    Dernier message: 22/01/2004, 08h27
  4. Réponses: 5
    Dernier message: 13/11/2003, 16h57
  5. Réponses: 1
    Dernier message: 02/01/2003, 12h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo