IVsHiColorItem Interface
Provides support for returning a full 24-bit color value.
Namespace: Microsoft.VisualStudio.TextManager.Interop
Assembly: Microsoft.VisualStudio.TextManager.Interop.8.0 (in Microsoft.VisualStudio.TextManager.Interop.8.0.dll)
Syntax
'宣言
<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
The IVsHiColorItem type exposes the following members.
Methods
Name | Description | |
---|---|---|
GetColorData | Retrieves the RGB value for the specified element. |
Top
Remarks
This interface is used to provide support for 24-bit or high color values. It is implemented on the same class that implements the IVsColorableItem or IVsPackageDefinedTextMarkerType interfaces.
Notes to Implementers
If support for high color values is needed, this interface must be implemented on the same class that implements the IVsColorableItem or IVsPackageDefinedTextMarkerType interfaces.
Notes to Callers
If this interface can be obtained from an object that implements the IVsColorableItem or IVsPackageDefinedTextMarkerType interface, then that object is advertising support for high color values. Call the GetColorData method to get the RGB values for the individual foreground, background, and line colors. If the GetColorData method returns an error, gracefully fall back to accessing the colors on the original IVsColorableItem or IVsPackageDefinedTextMarkerType interfaces.
Examples
Here is an example in managed code of how to implement the IVsHiColorItem interface and instantiate it. Note how a set of red, green, and blue values is converted to a COLORREF in the MyRGB constructor. This example is from a language service.
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))
};
}
}
}