Archived:How to retrieve grid text color from the current theme on Symbian
Article Metadata
Compatibility
Article
Overview
How to retrieve grid text color from the current theme
Description
The text color for custom grids (CAknGrid) can be retrieved from the current theme. Setting the grid text color is slightly different for S60 2nd Edition and 3rd Edition devices.
Solution
S60 2nd Edition:
Normal and highlighted text colors can be set in the SizeChanged() function of the CCoeControl-derived container (that owns the grid). The following code demonstrates this:
TRgb textColor; // text color when not highlighted
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG9 );
TRgb highlightColor; // text color when highlighted
AknsUtils::GetCachedColor( skin, highlightColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 );
iGrid->ItemDrawer()->SetTextColor( textColor ); // iGrid is of type CAknGrid
iGrid->ItemDrawer()->SetHighlightedTextColor( highlightColor );
However, ItemDrawer()->SetTextColor() cannot be used for S60 3rd Edition and higher.
S60 3rd Edition:
Set the color of a CFormattedCellListBoxData object. This can be done as follows:
TRgb textColor; // text color when not highlighted
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG9 );
TRgb highlightColor; // text color when highlighted
AknsUtils::GetCachedColor( skin, highlightColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG11 );
CFormattedCellListBoxData::TColors colors;
colors.iText = textColor;
colors.iHighlightedText = highlightColor;
iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL( 0, colors );
iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL( 1, colors );
iGrid->ItemDrawer()->FormattedCellData()->SetSubCellColorsL( 3, colors );
The above code has to be added to the SizeChanged() function of the grid, otherwise the default SizeChanged() implementation will override the custom settings. Also note that the SetUpFormTextCell() method of grid has to be called before trying to set the text colors.


(no comments yet)