SymbianER

symbian application developers' zone

Using Theme in an Application Bookmark this page on deli.cio.us

This article can tell you how to write a enable skins application.
You can use theme in an Application after version in S60 Platform 2nd Edition. the following content will tell you how to do these step by step.

Link against aknskins.lib and include files

Add the libray named aknskins.lib in SkinSample.mmp
 
Code:
LIBRARY aknskins.lib // link against aknskins.lib
Add two include files in SkinExampleContainer.h
 
Code:
#include <AknsDrawUtils.h>// add this inlcude file skin
#include <AknsBasicBackgroundControlContext.h> //add this inlcude file skin
 
Enabling skins in AppUi


Code:
/* In SkinExampleAppUi.cpp */
void CSkinExampleAppUi::ConstructL()
    {
    BaseConstructL( EAknEnableSkin );//Construct a enalbe skin
    .....
    }

new and delete a MAknsControlContext class in Container class

Add a MAknsControlContext class in container class


Code:
/* In skinExampleContainer.h */
class CSkinExampleContainer : public CCoeControl, MCoeControlObserver
{
 ....  
  private:
  MAknsControlContext* iBackGround; // for skins support 
}
 
/* In SkinExapleContainer.cpp */ 
void CSkinExampleContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
 
    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    iLabel->SetTextL( _L("Skin Example") );
 
    SetRect(aRect);
    iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );// new a background
    ActivateL();
    }
 
Delete iBackGroud

Code:
// Destructor
CSkinExampleContainer::~CSkinExampleContainer()
    {
   .....

 delete iBackGround;
    }
 

Draw the background bitmap using Skin library

Code:
/* In SkinExapleContainer.cpp */
void CSkinExampleContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
 // draw background
 MAknsSkinInstance* skin = AknsUtils::SkinInstance();//new
 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );//new
    AknsDrawUtils::Background( skin, cc, this, gc, aRect );//new
    }
 

MObjectProvider Chains

MObjectProvider interface can be used to make object instances available to child controls.
MopSupplyObject returns a pointer based on the given UID.

Code:
/* In SkinExapleContainer.cpp */
TTypeUid::Ptr CSkinExampleContainer::MopSupplyObject(TTypeUid aId)
    {
    if(aId.iUid == MAknsControlContext::ETypeId && iBackGround)
        {
        return MAknsControlContext::SupplyMopObject( aId, iBackGround);
        }
 
    return CCoeControl::MopSupplyObject( aId );
    }

If you like this post then please consider subscribing to my full feed RSS. You can also subscribe by Email and have new posts sent directly to your inbox.

Post A Comment:

Recent Entries

Site Search

Recent Entries

Subscribe

    Enter your email address:

    Delivered by FeedBurner

Feeds

    Subscribe in Rojo
    Add to Google

    Subscribe in Bloglines
    Subscribe in NewsGator Online
    Add to Technorati Favorites
    Add symbianer-Symbian S60 Uiq Mobile Examples Codes to Newsburst from CNET News.com

    Add to My AOL
    Subscribe in FeedLounge
    Add to netvibes
    Add to The Free Dictionary
    Add to Bitty Browser
    Add to Plusmo
    Subscribe in NewsAlloy
    Add symbianer-Symbian S60 Uiq Mobile Examples Codes to ODEO
    Subscribe in podnova
    Add to Pageflakes

    Technology Blogs - Blog Top Sites

Communities


English Version Mobile Symbianer PowerBy SymbianER
Copyright 2006-2008 www.symbianer.com All Rights Reserved.