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 :

Quel style est utilisé pour les onglets ?


Sujet :

Composants VCL Delphi

  1. #1
    Membre expérimenté Avatar de franckcl
    Homme Profil pro
    Developpeur Delphi
    Inscrit en
    Septembre 2004
    Messages
    516
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Developpeur Delphi
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Septembre 2004
    Messages : 516
    Par défaut Quel style est utilisé pour les onglets ?
    Bonjour,

    Je n'arrive pas à trouver quel style est utilisé pour dessiner le fond des onglets des TTabSheet d'un Pagecontrol.

    Je pensais qu'il s'agissait de clHighlight lorsque l'onglet est selectionné et clWindow en normal mais à priori non, comment trouver cette information, j'ai essayé de voir dans Vcl.ComCtrls mais je ne vois rien.

    merci

  2. #2
    Expert éminent
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    14 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 14 198
    Par défaut
    Avec le style, StyleServices.GetElementDetails version TThemedTab
    et ainsi que clWindowFrame, si style faut appeler GetSystemColor

    Un code que j'avais écrit il y a quelques années, cela peut t'inspirer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    {$IF CompilerVersion = CompilerVersionXE2}
      /// <summary>The TSLTTabControlStyleHookFix corrige la gestion des ImageIndex du Vcl.ComCtrls.TPageControl qui malgré l'update 4 conserve un bug</summary>
      /// <seealso href="http://www.developpez.net/forums/d1203440/environnements-developpement/delphi/edi/xe2-vcl-themes-pagecontrol-ondrawtab/">[XE2] Vcl.themes et PageControl.OnDrawTab</seealso>
      /// <seealso href="http://qc.embarcadero.com/wc/qcmain.aspx?d=101346">TPageControl draw incorrect image index in TTabSheet(s) when VCL Styles is active</seealso>
      TSLTTabControlStyleHookFix = class(TTabControlStyleHook)
      protected
        procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
      end;
    {$IFEND}
    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
    {$IF CompilerVersion = CompilerVersionXE2}
     
    { TSLTTabControlStyleHookFix }
     
    //------------------------------------------------------------------------------
    procedure TSLTTabControlStyleHookFix.DrawTab(Canvas: TCanvas; Index: Integer);
     
      // Code original privé : TTabControlStyleHook.AngleTextOut ; Fichier : Vcl.ComCtrls ; Ligne : 29912 !
      procedure AngleTextOut(Canvas: TCanvas; Angle: Integer; X, Y: Integer; const Text: string);
      var
        NewFontHandle, OldFontHandle: hFont;
        LogRec: TLogFont;
      begin
        GetObject(Canvas.Font.Handle, SizeOf(LogRec), Addr(LogRec));
        LogRec.lfEscapement := Angle * 10;
        LogRec.lfOrientation := LogRec.lfEscapement;
        NewFontHandle := CreateFontIndirect(LogRec);
        OldFontHandle := SelectObject(Canvas.Handle, NewFontHandle);
        SetBkMode(Canvas.Handle, TRANSPARENT);
        Canvas.TextOut(X, Y, Text);
        NewFontHandle := SelectObject(Canvas.Handle, OldFontHandle);
        DeleteObject(NewFontHandle);
      end;
     
    // Code original protégé : TTabControlStyleHook.DrawTab ; Fichier : Vcl.ComCtrls ; Ligne : 29928 !
    var
      R, LayoutR, GlyphR: TRect;
      ImageWidth, ImageHeight, ImageStep, TX, TY: Integer;
      DrawState: TThemedTab;
      Details: TThemedElementDetails;
      ThemeTextColor: TColor;
      FImageIndex: Integer;
    begin
      // SLT : dimensions des images récupérées uniquement lorsque cela sera vraiment utile !
     
      R := TabRect[Index];
      if R.Left < 0 then Exit;
     
      if TabPosition in [tpTop, tpBottom] then
      begin
        if Index = TabIndex then
          InflateRect(R, 0, 2);
      end
      else if Index = TabIndex then
        Dec(R.Left, 2) else Dec(R.Right, 2);
     
      Canvas.Font.Assign(TCustomTabControlHack(Control).Font);
      LayoutR := R;
      DrawState := ttTabDontCare;
      case TabPosition of
        tpTop:
          begin
            if Index = TabIndex then
              DrawState := ttTabItemSelected
            else if (Index = HotTabIndex) and MouseInControl then
              DrawState := ttTabItemHot
            else
              DrawState := ttTabItemNormal;
          end;
        tpLeft:
          begin
            if Index = TabIndex then
              DrawState := ttTabItemLeftEdgeSelected
            else if (Index = HotTabIndex) and MouseInControl then
              DrawState := ttTabItemLeftEdgeHot
            else
              DrawState := ttTabItemLeftEdgeNormal;
          end;
        tpBottom:
          begin
            if Index = TabIndex then
              DrawState := ttTabItemBothEdgeSelected
            else if (Index = HotTabIndex) and MouseInControl then
              DrawState := ttTabItemBothEdgeHot
            else
              DrawState := ttTabItemBothEdgeNormal;
          end;
        tpRight:
          begin
            if Index = TabIndex then
              DrawState := ttTabItemRightEdgeSelected
            else if (Index = HotTabIndex) and MouseInControl then
              DrawState := ttTabItemRightEdgeHot
            else
              DrawState := ttTabItemRightEdgeNormal;
          end;
      end;
     
      if StyleServices.Available then
      begin
        Details := StyleServices.GetElementDetails(DrawState);
        StyleServices.DrawElement(Canvas.Handle, Details, R);
      end;
     
      { Image }
     
      // SLT : Il faut récupérer l'index image avant de récupérer les dimensions !
      // Surtout si la liste d'image a un nombre inférieur d'image au nombre d'onglet !
      // Sinon, la position de l'image est mal centrée tout comme le texte (impacte sur LayoutR)
      if Control is TCustomTabControl then
        FImageIndex := TCustomTabControlHack(Control).GetImageIndex(Index)
      else
        FImageIndex := Index;
     
      if (Images <> nil) and (FImageIndex >= 0) and (FImageIndex < Images.Count) then
      begin
        // SLT : dimensions récupérées au moment opportun (code original dans fichier : Vcl.ComCtrls ; ligne 29939)
        ImageWidth := Images.Width;
        ImageHeight := Images.Height;
        ImageStep := 3;
     
        GlyphR := LayoutR;
        case TabPosition of
          tpTop, tpBottom:
            begin
              GlyphR.Left := GlyphR.Left + ImageStep;
              GlyphR.Right := GlyphR.Left + ImageWidth;
              LayoutR.Left := GlyphR.Right;
              GlyphR.Top := GlyphR.Top + (GlyphR.Bottom - GlyphR.Top) div 2 - ImageHeight div 2;
              if (TabPosition = tpTop) and (Index = TabIndex) then
                OffsetRect(GlyphR, 0, -1)
              else if (TabPosition = tpBottom) and (Index = TabIndex) then
                OffsetRect(GlyphR, 0, 1);
            end;
          tpLeft:
            begin
              GlyphR.Bottom := GlyphR.Bottom - ImageStep;
              GlyphR.Top := GlyphR.Bottom - ImageHeight;
              LayoutR.Bottom := GlyphR.Top;
              GlyphR.Left := GlyphR.Left + (GlyphR.Right - GlyphR.Left) div 2 - ImageWidth div 2;
            end;
          tpRight:
            begin
              GlyphR.Top := GlyphR.Top + ImageStep;
              GlyphR.Bottom := GlyphR.Top + ImageHeight;
              LayoutR.Top := GlyphR.Bottom;
              GlyphR.Left := GlyphR.Left + (GlyphR.Right - GlyphR.Left) div 2 - ImageWidth div 2;
            end;
        end;
        if StyleServices.Available then
          StyleServices.DrawIcon(Canvas.Handle, Details, GlyphR, Images.Handle, FImageIndex);
      end;
     
      { Text }
      if StyleServices.Available then
      begin
        if (TabPosition = tpTop) and (Index = TabIndex) then
          OffsetRect(LayoutR, 0, -1)
        else if (TabPosition = tpBottom) and (Index = TabIndex) then
          OffsetRect(LayoutR, 0, 1);
     
        if TabPosition = tpLeft then
        begin
          TX := LayoutR.Left + (LayoutR.Right - LayoutR.Left) div 2 -
            Canvas.TextHeight(Tabs[Index]) div 2;
          TY := LayoutR.Top + (LayoutR.Bottom - LayoutR.Top) div 2 +
            Canvas.TextWidth(Tabs[Index]) div 2;
         if StyleServices.GetElementColor(Details, ecTextColor, ThemeTextColor) then
           Canvas.Font.Color := ThemeTextColor;
          AngleTextOut(Canvas, 90, TX, TY, Tabs[Index]);
        end
        else if TabPosition = tpRight then
        begin
          TX := LayoutR.Left + (LayoutR.Right - LayoutR.Left) div 2 +
            Canvas.TextHeight(Tabs[Index]) div 2;
          TY := LayoutR.Top + (LayoutR.Bottom - LayoutR.Top) div 2 -
            Canvas.TextWidth(Tabs[Index]) div 2;
          if StyleServices.GetElementColor(Details, ecTextColor, ThemeTextColor)
          then
            Canvas.Font.Color := ThemeTextColor;
          AngleTextOut(Canvas, -90, TX, TY, Tabs[Index]);
        end
        else
          DrawControlText(Canvas, Details, Tabs[Index], LayoutR, DT_VCENTER or DT_CENTER or DT_SINGLELINE  or DT_NOCLIP);
      end;
    end;
     
    {$IFEND}
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  3. #3
    Membre émérite
    Avatar de Cirec
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    467
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 467
    Par défaut
    Bonjour,

    j'ai eut ce problème et je l'ai résolu d'une manière un peu différente
    en utilisant, comme le dit ShaiLeTroll, GetSystemColor:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    (* pour avoir la bonne couleur de texte quand les thèmes sont activées*)
      if not StyleServices.IsSystemStyle then
        Canvas.Font.Color := StyleServices.GetSystemColor(clWindowText);
    Cordialement,

    @+

Discussions similaires

  1. [Java] Quel OS est utilisé dans les entreprises ?
    Par vinou33 dans le forum Débuter avec Java
    Réponses: 3
    Dernier message: 12/02/2015, 10h56
  2. [Joomla!] Quel est le layout utilisé pour les annonces sur le site officiel?
    Par _skip dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 0
    Dernier message: 07/06/2010, 12h40
  3. Savoir quel module est utilisé pour tel matériel
    Par Fluxy dans le forum Matériel
    Réponses: 4
    Dernier message: 06/10/2008, 10h51
  4. [EasyPHP] Est ce que EasyPHP est gratuit pour les entreprises ?
    Par lenouvo dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 16
    Dernier message: 27/10/2005, 16h14
  5. Quel style de DirectX pour un jeu 2D ?
    Par delire8 dans le forum DirectX
    Réponses: 34
    Dernier message: 31/07/2003, 01h47

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