Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 11:54, 8 December 2007.

Drawing skins in container

From Forum Nokia Wiki


The CSkinnedContainer implementation illustrates how to draw skins in a CCoeControl derived container in the S60 platform.

The iBgContext is the CAknsBasicBackgroundControlContext which is used to draw the skin on the control's background. To draw on a different screen area you could change KAknsIIDQsnBgScreen identify to the background you would like to use with your container.

Note that for the skins to work properly you need to enable skins first. Usually this is done in Application user interface class' ConstructL() method by calling the ConstructL() method with CAknAppUi::EAknEnableSkin parameter.

SkinnedContainer.cpp

CSkinnedContainer::~CSkinnedContainer()
{
	delete iBgContext;
	iBgContext = NULL;
}   
 
CSkinnedContainer* CSkinnedContainer::NewL(void)
    {
    CSkinnedContainer* self = new(ELeave)CSkinnedContainer();
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
    }
 
void CSkinnedContainer::ConstructL(void)
    {
    CreateWindowL();
 
	// make first with no size at all
	iBgContext = CAknsBasicBackgroundControlContext::NewL(
		KAknsIIDQsnBgScreen,TRect(0,0,1,1), ETrue);
	// Setting rect will cause SizeChanged to be called
	// and iBgContext size & position is updated accordingly.
	SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
 
	ActivateL();
	DrawNow();
}
 
void CSkinnedContainer::SizeChanged()
{
	if ( iBgContext )
	{
		iBgContext->SetRect(Rect());
 
		if ( &Window() )
		{
			iBgContext->SetParentPos( PositionRelativeToScreen() );
		}
	}
}
 
 
void CSkinnedContainer::HandleResourceChange(TInt aType)
{
	TRect rect;
 
    if ( aType==KEikDynamicLayoutVariantSwitch )
    {    
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
    }
 
	CCoeControl::HandleResourceChange(aType);
}
 
 
TTypeUid::Ptr CSkinnedContainer::MopSupplyObject(TTypeUid aId)
{	
	if (iBgContext)
	{
		return MAknsControlContext::SupplyMopObject(aId, iBgContext );
	}
	
	return CCoeControl::MopSupplyObject(aId);
}
 
 
void CSkinnedContainer::Draw(const TRect& aRect) const
{
	CWindowGc& gc = SystemGc();
    
    // draw background skin first.
  	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
	AknsDrawUtils::Background( skin, iBgContext, this, gc, aRect );
}

SkinnedContainer.h

#include <coecntrl.h>       // CCoeControl
#include <AknsBasicBackgroundControlContext.h> 
#include <aknsdrawutils.h>
#include <aknscontrolcontext.h>
#include <AknsSkinInstance.h>
#include <aknsutils.h>
 
 
class CSkinnedContainer : public CCoeControl
    {
public:
	static CSkinnedContainer* NewL(void);
	~CSkinnedContainer();
protected:
	TTypeUid::Ptr MopSupplyObject(TTypeUid aId); // 
private:
	virtual void SizeChanged();
	virtual void HandleResourceChange(TInt aType);
    void ConstructL(void);
	void Draw(const TRect& aRect) const;
private:
	CAknsBasicBackgroundControlContext*	iBgContext; 
};
Related Discussions
Thread Thread Starter Forum Replies Last Post
I created button CEikTextButton but it is not displayed sirmic General Symbian C++ 3 2008-03-03 11:44
Asynchronous drawing sadysta Symbian Media (Graphics & Sounds) 3 2008-05-16 08:19
Findbox problem N90 mateen_maldar Symbian User Interface 2 2006-04-13 06:47
Enable skin kayem General Symbian C++ 2 2007-11-29 08:35
Drawing View fcobsb Mobile Java General 0 2003-11-03 20:20
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX