1. Enable skins support in our application by calling apps AppUi base constructor:
void CMyAppUi::ConstructL()
{
BaseConstructL(EAknEnableSkin);
...
}
2. We will require a specific context to hold the skin bitmap for your control.
CAknsBasicBackgroundControlContext* iBgContext;
3. Initialise context to a reference of the background bitmap:
void CMyAppView::ConstructL()
{
...
iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,aRect,ETrue);
...
}
4. Don't forget to call the context destructor:
void CSkinDemoAppView::~CSkinDemoAppView()
{
...
delete iBgContext;
...
}
5. As we are ready with a context that has the backgoround that we want to use in all controls. This is done throgh MOP relationship and we need to override the MopSupplyObject():
TTypeUid::Ptr CMyAppView::MopSupplyObject(TTypeUid aId)
{
if (iBgContext )
{
return MAknsControlContext::SupplyMopObject( aId, iBgContext );
}
return CCoeControl::MopSupplyObject(aId);
}
6. Each control Draw now be updated to display the skin as background:
void CMyAppView::Draw(const TRect& aRect) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Redraw the background using the default skin
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
AknsDrawUtils::Background( skin, cc, this, gc, aRect );
...
}
and
void CMyAppView::SizeChanged()
{
if(iBgContext)
{
iBgContext->SetRect(Rect());
if ( &Window() )
{
iBgContext->SetParentPos( PositionRelativeToScreen() );
}
}
}
7. Now we are ready so if we have to use it in a list box then we can use as below.
ListBox->ItemDrawer()->ColumnData()->SetSkinEnabledL(ETrue)
Header Files: AknsDrawUtils.h, AknsBasicBackgroundControlContext.h
Lib Files: aknskins.lib aknskinsrv.lib
note:
1. Nokia has introduced skin support only in S60 v2.
2. Unfortunately, the Skin API is not very well documented and may not be compatible in S60 3rd Edition
No comments:
Post a Comment