Enable Skin Support in Views/Containers
Article Metadata
Code Example
Article
You need to create a specific context to hold the skin bitmap for your control. Do this by adding the following data member to your view/container class:
CAknsBasicBackgroundControlContext* iBgContext;
And initialize properly in the corresponding ConstructL(), initialise a reference to the background bitmap:
#include <AknsDrawUtils.h>
#include <AknsBasicBackgroundControlContext.h>
void CYourAppView::ConstructL()
{
iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,aRect,ETrue);
}
Call the corresponding destructor.
void CYourAppView::~CYourAppView()
{
delete iBgContext;
}
This context shall be passed to the child controls so that they can redisplay themselves correctly. This is done throgh MOP relationship and you then need to override the MopSupplyObject() primitive as follow:
TTypeUid::Ptr CYourAppView::MopSupplyObject(TTypeUid aId)
{
if (iBgContext )
{
return MAknsControlContext::SupplyMopObject( aId, iBgContext );
}
return CCoeControl::MopSupplyObject(aId);
}
Each control Draw primitive shall now be updated to display the skin as background:
// Draw this application's view to the screen
void CYourAppView::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 );
...
}
void CYourAppView::SizeChanged()
{
if(iBgContext)
{
iBgContext->SetRect(Rect());
if ( &Window() )
{
iBgContext->SetParentPos( PositionRelativeToScreen() );
}
}
}
If your control contains a listbox, you can enable skin behind the items by calling:
iListBox->ItemDrawer()->ColumnData()->SetSkinEnabledL(ETrue)
Link against.
LIBRARY aknskins.lib aknskinsrv.lib
Full example
File:Otoncyvg(EdwinVerticalAlign).zip Tested on S60 3rd Edition FP2 emulator.


Amrok90 -
If you use some label and want it's background to be consistent with the theme and with the background of the parent controller, change the parameters in this function:
void CYourAppView::SizeChanged() {
if(iBgContext) { iBgContext->SetRect(Rect()); if ( &Window() ) { iBgContext->SetParentPos( PositionRelativeToScreen() ); } }}
this way:
1)here
iBgContext->SetRect(Rect());
change to
iBgContext->SetRect(Parent()->Rect());
2)here
change to
(or here it may be iBgContext->SetParentPos( Parent()->Rect().iTl ); (parent's top left point)).
Amrok90 -
I've tried this code in different situations and found out that setting the rect of background to whole screen is the best option:
CMyAppUi *appUi = (CMyAppUi*)iEikonEnv->AppUi(); iBgContext->SetRect(appUi->ApplicationRect());
In this case the TL has to be 0, 0.amrok90 12:51, 14 February 2012 (EET)