Share via


IBabelService::GetColorInfo Method

Retrieves color information for a custom color class.

HRESULT GetColorInfo ( 
   ColorClass index,
   BSTR* description,
   BSTR* style
);

Parameters

  • index
    [in] Specifies the color class for which to get information.

  • description
    [out] Returns a string containing the description of the color class, for example, "HTML Keyword". This description is shown in the Options dialog box in the Fonts and Colors category.

  • style
    [out] Returns a string containing the Cascade Style Sheet (CSS) style information for the color class, for example, "color: blue; font-weight: bold". See the "Supported CSS Styles" section in this topic.

Return Value

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

This method is only called if the RequestStockColors registry entry is set to 0 in the registry. If this method is called with a value in the index parameter that is less than the value returned by IBabelService::ColorCount Method, then the GetColorInfo method returns the following:

  • A description of the color class (for example, "keyword") in the description parameter.

  • Style information for the color class in the style parameter. For example, a value of color: blue; font-weight: bold might be returned in this parameter.

The default Babel implementation of this method calls the StdService::getColorInfo method to return a list of ColorInfo items which is then searched for the specified ColorClass entry. Your implementation of the Service class (which derives from the StdService class) can override the getColorInfo method to return a list of color classes for your language (the ColorInfo structure and ColorClass type are defined in the Babel\common\stdservice.h file). See How to: Enable Syntax Coloring for more details.

If you implement the IBabelService Interface yourself, you can store the color information in whatever form you need to. Just return a description and a CSS style for the requested color class from the GetColorInfo method.

Supported CSS Styles

Currently, only a subset of the standard Cascade Style Sheet (CSS) style values is supported. The following table lists the CSS values that are available for use in the style parameter. All other values are ignored by Babel.

Property

Values

font-weight

default

normal

bold

bolder

lighter

100

200

300

400

500

600

700

800

900

text-decoration

default

normal

line-through

strike-through

color

background-color

default

normal

auto

selected

inactive

plaintext

margin (note: background-color only)

black

white

maroon

darkgreen

brown

darkblue

purple

aquamarine

lightgray

darkgray

red

green

yellow

blue

magenta

cyan

lime

aqua

fuschia

gray

silver

olive

teal

navy

text-kind

default

normal

humantext (see Note below)

programtext

Note

The humantext value is used for non-program text, such as strings and comments. In Visual Studio, this value is used by search and navigation commands.

Example

This is a simple example of an implementation of this method. It uses the ColorInfo structure defined in the stdservice.h file to define the colors.

HRESULT MyBabelService::GetColorInfo(ColorClass index,
                                     BSTR *description,
                                     BSTR *style)
{
    static ColorInfo defaultColorInfoTable[] =
    {
        { ClassKeyword,     "Keyword",    "color: blue"  },
        { ClassComment,     "Comment",    "color: darkgreen; text-kind: humantext" },
        { ClassIdentifier,  "Identifier", "" },
        { ClassString,      "String",     "color: purple" },
        { ClassNumber,      "Number",     "" },
        { ColorClassEnd,    "Text",       "" }
    };

    OLECHAR buffer[MaxStr+1];
    ColorInfo *info = defaultColorInfoTable;
    while (info->colorClass != ColorClassEnd )
    {
        if (info->colorClass == colorClass)
        {
             break;
        }
        info++;
    }
    
    HRESULT hr = S_OK;
    if (description != NULL)
    {
        if (info->description == NULL)
        {
            hr = E_FAIL;
            goto Error;
        }
        mbstowcs( buffer, info->description, MaxStr ); buffer[MaxStr] = 0;
        *description = SysAllocString( buffer );
        if ((*description) == NULL)
        {
            hr = E_OUTOFMEMORY;
        }
    }

    if (hr == S_OK && style != NULL)
    {
        if (info->style == NULL)
        {
            if (description)
            {
                 SysFreeString(*description);
                 *description = NULL;
            }
            hr = E_FAIL;
        }
        else
        {
            mbstowcs( buffer, info->style, MaxStr ); buffer[MaxStr] = 0;
            *style = SysAllocString( buffer );
            if ((*style) == NULL)
            {
                if (description)
                {
                     SysFreeString(*description);
                     *description = NULL;
                }
                hr = E_OUTOFMEMORY;
            }
        }
    }
    return hr;
}

See Also

Concepts

How to: Enable Syntax Coloring

Reference

IBabelService Interface

IBabelService::ColorCount Method