Share via


IVsHiColorItem, interface

Fournit la prise en charge de retourner une valeur de couleur 24 bits complète.

Espace de noms :  Microsoft.VisualStudio.TextManager.Interop
Assembly :  Microsoft.VisualStudio.TextManager.Interop.8.0 (dans Microsoft.VisualStudio.TextManager.Interop.8.0.dll)

Syntaxe

'Déclaration
<InterfaceTypeAttribute()> _
<GuidAttribute("16C240B3-4773-43C2-932A-1E8DD2F6F0F8")> _
Public Interface IVsHiColorItem
[InterfaceTypeAttribute()]
[GuidAttribute("16C240B3-4773-43C2-932A-1E8DD2F6F0F8")]
public interface IVsHiColorItem
[InterfaceTypeAttribute()]
[GuidAttribute(L"16C240B3-4773-43C2-932A-1E8DD2F6F0F8")]
public interface class IVsHiColorItem
[<InterfaceTypeAttribute()>]
[<GuidAttribute("16C240B3-4773-43C2-932A-1E8DD2F6F0F8")>]
type IVsHiColorItem =  interface end
public interface IVsHiColorItem

Le type IVsHiColorItem expose les membres suivants.

Méthodes

  Nom Description
Méthode publique GetColorData Extrait la valeur RVB pour l'élément spécifié.

Début

Notes

Cette interface est utilisée pour fournir la prise en charge des valeurs 24 bits ou de 65536 couleurs. Ils sont implémentés sur la même classe qui implémente les interfaces d'IVsColorableItem ou d'IVsPackageDefinedTextMarkerType.

Remarques à l'attention des implémenteurs

Si la prise en charge des valeurs de 65536 couleurs est nécessaire, cette interface doit être implémentée sur la même classe qui implémente les interfaces d'IVsColorableItem ou d'IVsPackageDefinedTextMarkerType.

Remarques à l'attention des appelants

Si cette interface peut être obtenu à partir d'un objet qui implémente IVsColorableItem ou interface d'IVsPackageDefinedTextMarkerType, ensuite cet objet publie la prise en charge des valeurs de 65536 couleurs. Appelez la méthode d'GetColorData pour obtenir les valeurs RVB pour les différents premier plan, arrière-plan, et couleurs de ligne. Si la méthode d'GetColorData retourne une erreur, retombez correctement à accéder aux couleurs sur IVsColorableItem ou les interfaces d'origine d'IVsPackageDefinedTextMarkerType.

Exemples

Voici un exemple en code managé d'implémenter l'interface d'IVsHiColorItem et l'instancier. Remarque comment un ensemble de valeurs rouges, vertes, et bleu est converti à COLORREF dans le constructeur d'MyRGB. Cet exemple est d'un service de langage.

using Microsoft.VisualStudio.TextManager.Interop;

namespace MyNamespace
{
    internal struct MyRGB
    {
        public uint ColorRef;

        public MyRGB(int r, int g, int b)
        {
            ColorRef = (uint)System.Drawing.ColorTranslator.ToWin32(
                                 System.Drawing.Color.FromArgb(r, g, b));
        }
        public MyRGB(bool fInvalid)
        {
            ColorRef = unchecked((uint)-1);
        }

        public bool IsValid()
        {
            return ColorRef != unchecked((uint)-1);
        }
    }


    internal class MyColorItem : IVsColorableItem, IVsHiColorItem
    {
        // Indicates that the returned RGB value is really an index
        // into a predefined list of colors.
        private const uint COLOR_INDEXED = 0x01000000;

        //==========================================================
        // Private fields.
        private COLORINDEX foreColor;
        private COLORINDEX backColor;
        private FONTFLAGS  fontFlags;
        private MyRGB      foreRGB;
        private MyRGB      backRGB;
        private string     name;
        private string     displayName;

        //==========================================================
        // Public constructors.

        public MyColorItem(string name,
                           string displayName,
                           COLORINDEX foreColor,
                           COLORINDEX backColor,
                           FONTFLAGS fontFlags)
        {
            this.name        = name;
            this.displayName = displayName;
            this.foreColor   = foreColor;
            this.backColor   = backColor;
            this.fontFlags   = fontFlags;
            this.foreRGB     = new MyRGB(false);
            this.backRGB     = new MyRGB(false);
        }

        public MyColorItem(string name,
                           string displayName,
                           COLORINDEX foreColor,
                           COLORINDEX backColor,
                           FONTFLAGS fontFlags,
                           MyRGB foreRGB,
                           MyRGB backRGB)
        {
            this.name        = name;
            this.displayName = displayName;
            this.foreColor   = foreColor;
            this.backColor   = backColor;
            this.fontFlags   = fontFlags;
            this.foreRGB     = foreRGB;
            this.backRGB     = backRGB;
        }

        //==========================================================
        // IVsColorableItem methods.
        #region IVsColorableItem Members

        int IVsColorableItem.GetDefaultColors(COLORINDEX[] piForeground,
                                              COLORINDEX[] piBackground)
        {
            int retval = VSConstants.E_POINTER;
            if (piForeground != null)
            {
                piForeground[0] = this.foreColor;
                retval = VSConstants.S_OK;
            }
            if (piBackground != null)
            {
                piBackground[0] = this.backColor;
            }
            return retval;
        }

        int IVsColorableItem.GetDefaultFontFlags(out uint pdwFontFlags)
        {
            pdwFontFlags = (uint)this.fontFlags;
            return VSConstants.S_OK;
        }

        int IVsColorableItem.GetDisplayName(out string pbstrName)
        {
            pbstrName = this.displayName;
            return VSConstants.S_OK;
        }

        #endregion


        //==========================================================
        // IVsHiColorItem methods.
        #region IVsHiColorItem Members

        int IVsHiColorItem.GetColorData(int cdElement, out uint pcrColor)
        {
            int retval = VSConstants.E_NOTIMPL;
            pcrColor = 0;

            switch ((__tagVSCOLORDATA)cdElement)
            {
                case __tagVSCOLORDATA.CD_BACKGROUND:
                    pcrColor = this.backRGB.IsValid() ?
                                   this.backRGB.ColorRef :
                                   (uint)backColor | COLOR_INDEXED;
                    retval = VSConstants.S_OK;
                    break;

                case __tagVSCOLORDATA.CD_FOREGROUND:
                case __tagVSCOLORDATA.CD_LINECOLOR:
                    pcrColor = this.foreRGB.IsValid() ?
                                   this.foreRGB.ColorRef :
                                   (uint)foreColor | COLOR_INDEXED;
                    retval = VSConstants.S_OK;
                    break;

                default:
                    retval = VSConstants.E_INVALIDARG;
                    break;
            }
            return retval;
        }

        #endregion
    }


    //==============================================================
    // Example of how to instantiate the MyColorItem class.

    public class MyLanguageService
    {
        private ColorableItem[] colorableItemsList;

        public MyLanguageService()
        {
            colorableItemsList = {
                new MyColorableItem("MyLanguage- Text",
                                    "MyLanguage- Text",
                                    COLORINDEX.CI_SYSPLAINTEXT_FG,
                                    COLORINDEX.CI_SYSPLAINTEXT_BK,
                                    FONTFLAGS.FF_BOLD),

                new MyColorableItem("MyLanguage- Keyword",
                                    "MyLanguage- Keyword",
                                    COLORINDEX.CI_MAROON,
                                    COLORINDEX.CI_SYSPLAINTEXT_BK,
                                    FONTFLAGS.FF_BOLD,
                                    new MyRGB(192,64,0),
                                    new MyRGB(false)),

                new MyColorableItem("MyLanguage- Operator",
                                    "MyLanguage- Operator",
                                    COLORINDEX.CI_DARKBLUE,
                                    COLORINDEX.CI_BLUE,
                                    FONTFLAGS.FF_PLAIN,
                                    new MyRGB(0,64,192),
                                    new MyRGB(128,128,255))
            };
        }
    }
}

Voir aussi

Référence

Microsoft.VisualStudio.TextManager.Interop, espace de noms