Hide

SftTabs/DLL 6.5 - Tab Control

Display
Print

SFTTABS_DRAWINFO Structure

The SFTTABS_DRAWINFO structure is passed to an application defined callback routine which can calculate the size or paint the tab labels.

typedef struct tagTabsDrawInfo {
#define SFTTABS_DI_CALC 0
#define SFTTABS_DI_PAINT 1
    int style;         // callback function
    HDC hDC;           // device context
    RECT DrawRect;     // Drawing rectangle
    HFONT hFont;       // suggested font
    HFONT hFontNorm;   // tab control font
    HFONT hFontBold;   // tab control font for bold tabs
    HFONT hFontBoldUL; // tab control font for bold tabs, underlined for flyby highlighting
    HFONT hFontNormUL; // tab control font, underlined for flyby highlighting
    int gap; // suggested gap size
    BOOL fTextDropped; // Tab text should be dropped
    int topTabs; // dual tabs, number of tabs on top/left
    BOOL fActive;      // tab is the active tab
    BOOL fHighlight;   // flyby highlighting for tab
    BOOL fFocus;       // tab has focus
    COLORREF colorBg;  // background color
    COLORREF colorFg;  // foreground color
    COLORREF color1;   // usually used for black border
    COLORREF color2;   // usually used for shadow lines
    COLORREF color3;   // usually used for highlight lines
    COLORREF color4;   // usually used for somewhat highlighted lines
    // new in 6.0
    RECT AvailableRect;// available (maximum) area or empty to calc best fit
    int iRealTab;      // real tab index
    BOOL fShowAccel;   // TRUE if kbd.accell (underscore) is to be displayed
} SFTTABS_DRAWINFO, * LPSFTTABS_DRAWINFO;
typedef const SFTTABS_DRAWINFO * LPCSFTTABS_DRAWINFO;

Members

style

The style member indicates the purpose of the current call to the drawing callback routine. style can be one of the following values:

SFTTABS_DI_CALC - The callback is called to determine the required size of the tab label. The DrawRect member must be updated to reflect the tab label size (in pixels). No other fields of this structure should be modified.

SFTTABS_DI_PAINT - The callback is called to paint the tab label at the coordinates described by the DrawRect member. Painting must occur within the boundaries of DrawRect. There is no automatic clipping if the application draws outside of the given area. No other fields of this structure should be modified.

Additional values - Reserved for future used.

hDC

The device context used to calculate or paint the tab label.

DrawRect

If the style member indicates that the callback should provide the dimensions of the tab label (SFTTABS_DI_CALC), the DrawRect member must be updated by the callback with the calculated size of the tab label. If an empty rectangle is returned, the drawing callback will not be called to paint the tab label and the tab is painted by the tab control. If the style member indicates that the callback should paint the tab label (SFTTABS_DI_PAINT), the DrawRect member contains the coordinates of the tab label.

hFont

The suggested font for the tab label. This font is derived from the tab control's font (defined using WM_SETFONT or CWnd::SetFont) and is rotated if necessary (for vertical tabs) and is bold (if the tab is the current tab and the SFTTABS_CONTROL structure defines fBoldFont as TRUE) and has the underline attribute (if the tab is the target of flyby highlighting).

hFontNorm

The tab control's default font. It is defined using WM_SETFONT or CWnd::SetFont and is rotated if necessary (for vertical tabs).

hFontBold

A font derived from the tab control's default font (defined using WM_SETFONT or CWnd::SetFont). It is rotated if necessary (for vertical tabs) and has the bold attribute.

hFontBoldUL

A font derived from the tab control's default font (defined using WM_SETFONT or CWnd::SetFont). It is rotated if necessary (for vertical tabs) and has the bold and underline attributes.

hFontNormUL

A font derived from the tab control's default font (defined using WM_SETFONT or CWnd::SetFont). It is rotated if necessary (for vertical tabs) and has the underline attribute.

gap

The suggested gap size (in pixels) to separate picture and text components.

fTextDropped

If the fDropText member of the SFTTABS_CONTROL structure is set to TRUE, the tab control may drop the tab text for all tabs. If tab text has been dropped, the fTextDropped member is set to TRUE, otherwise it is FALSE.

topTabs

Defines the number of tabs on top (left) in a dual tab control.

fActive

TRUE indicates that the tab is the current tab, otherwise fActive is FALSE.

fHighlight

TRUE indicates that the tab is the target of flyby highlighting, otherwise fHighlight is FALSE.

fFocus

TRUE indicates that the tab is the current tab and that the tab control has the input focus, otherwise fFocus is FALSE.

colorBg

The background color of the tab control. The color provided here is merely a suggested color. It is not necessary to use this color.

colorFg

The foreground color of the tab control. The color provided here is merely a suggested color. It is not necessary to use this color.

color1

The color used to draw the lines indicating the tab control border. The color provided here is merely a suggested color. It is not necessary to use this color.

color2

The color used to draw the lines away from the light source, indicating a shadow. The color provided here is merely a suggested color. It is not necessary to use this color.

color3

The color used to draw the lines directly exposed to the light source, indicating a highlight. The color provided here is merely a suggested color. It is not necessary to use this color.

color4

The color used to draw the lines somewhat exposed to the light source. The color provided here is merely a suggested color. It is not necessary to use this color.

AvailableRect

If the style member indicates that the callback should provide the dimensions of the tab label (SFTTABS_DI_CALC), the AvailableRect member contains the maximum available area for the tab contents. AvailableRect may be empty, in which case there is no space restriction. The callback provides the exact size (preferably smaller or equal to AvailableRect) in the DrawRect member.

If the style member indicates that the callback should paint the tab label (SFTTABS_DI_PAINT), the AvailableRect member is not used.

iRealTab

The tab index of the tab, for which the callback is called. This is not necessarily the same index as the iTab argument of the callback SFTTABS_DRAWTABPROC. The iTab argument does not take hidden tabs into account, so it cannot be used when hidden tabs are present. iRealTab should be used exclusively.

fShowAccel

TRUE if keyboard accelerators (underlined keyboard shortcuts in tab labels) are currently displayed, otherwise FALSE.

Comments

The SFTTABS_DRAWINFO structure is passed to an application defined callback routine which can calculate the size or paint the tab labels.

A drawing callback is defined using SetDrawTabCallback.

Tab controls calculate the size of each tab based on tab control settings (defined using SFTTABS_CONTROL and SFTTABS_TAB structures). When a drawing callback is used, the callback is used to determine the required size of the tab label (DrawRect). In this case, the callback is called and a style value of SFTTABS_DI_CALC is passed. If an empty rectangle is returned, the drawing callback will not be called to paint the tab label and the tab is painted by the tab control. The callback may be called multiple times to determine the tab size, before and after tabs are painted.

When a drawing callback is called to paint a tab, a style value of SFTTABS_DI_PAINT is passed. The callback can then paint the tab label in the area described by DrawRect.

Example

C++

void CSampleDlg::DrawOneTab(int iTab, LPSFTTABS_DRAWINFO lpDrawInfo)
{
    if (iTab == 1) { /* only handle the second tab */

        SFTTABS_TAB Tab;
        // get tab attributes
        m_Tab.GetTabInfo(iTab, &Tab);

        CDC dc;
        dc.Attach(lpDrawInfo->hDC);

        switch (lpDrawInfo->style) {
        case SFTTABS_DI_CALC: {
            // calculate the size of the label
            CFont* tFont = (CFont*) dc.SelectObject(lpDrawInfo->hFont);
            dc.DrawText(Tab.lpszText, -1, &lpDrawInfo->DrawRect, DT_CALCRECT|DT_SINGLELINE);
            // allow extra space for border
            ::InflateRect(&lpDrawInfo->DrawRect, 2, 2);
            break;
         }
        case SFTTABS_DI_PAINT: {
            // paint label
            CBrush brFill, brFrame;
            COLORREF color;
            int mode;
            // select the background color as defined for the tab
            if (lpDrawInfo->fActive)
                color = Tab.colorBgSel;
            else
                color = Tab.colorBg;
            // translate to real color (if using system colors) or use default
            // tab control color if no tab color defined
            color = TrColor(color, RGB(255,255,255)); // or lpDrawInfo->colorBg
            // If the tab control has the input focus, use a solid background
            if (lpDrawInfo->fFocus)
                brFill.CreateSolidBrush(color);
            else
                brFill.CreateHatchBrush(HS_FDIAGONAL, color);
            dc.FillRect(&lpDrawInfo->DrawRect, &brFill);

            if (lpDrawInfo->fHighlight) {
                // use flyby color, because tab is highlighted
                color = TrColor(Tab.colorFlybyFg, RGB(0,0,128));
                brFrame.CreateSolidBrush(color);
                // draw double frame
                dc.FrameRect(&lpDrawInfo->DrawRect, &brFrame);
                ::InflateRect(&lpDrawInfo->DrawRect, -1, -1);
                dc.FrameRect(&lpDrawInfo->DrawRect, &brFrame);
            } else {
                // select the foreground color as defined for the tab
                if (lpDrawInfo->fActive)
                    color = Tab.colorFgSel;
                else
                    color = Tab.colorFg;
                // translate to real color (if using system colors) or use default
                // tab control color if no tab color defined
                color = TrColor(color, lpDrawInfo->colorFg);
                // frame the area
                brFrame.CreateSolidBrush(TrColor(lpDrawInfo->fActive ? Tab.colorFgSel : Tab.colorFg, lpDrawInfo->colorFg));
                dc.FrameRect(&lpDrawInfo->DrawRect, &brFrame);
            }
            // Use the foreground color to draw the text
            if (lpDrawInfo->fActive)
                color = Tab.colorFgSel;
            else
                color = Tab.colorFg;
            color = TrColor(color, lpDrawInfo->colorFg);
            ::InflateRect(&lpDrawInfo->DrawRect, -1, -1);
            CFont* tFont = (CFont*) dc.SelectObject(lpDrawInfo->hFont);
            mode = dc.SetBkMode(TRANSPARENT);
            dc.DrawText(Tab.lpszText, -1, &lpDrawInfo->DrawRect, DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_WORD_ELLIPSIS);
            dc.SetBkMode(mode);

            // Draw a focus ring
            if (lpDrawInfo->fFocus)
                dc.DrawFocusRect(&lpDrawInfo->DrawRect);

            break;
         }
        }
        dc.Detach();
    }
}

See Also C/C++ API | C++ Classes | Notifications


Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.