首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian英文资料 >> User Interface >> 文章正文
Enable Skin support in your Symbian OS applications
作者:佚名    文章来源:不详    更新时间:2006-5-16 23:35:10

Nokia has introduced skin support in S60 v2. For various reasons, including compatibility with S60 v1 and thus older devices, this support is not enabled by default: your application will display a not so original white background unless you code it differently.

A nice and user-friendly way to behave is to use the mobile theme skin as a background for your application. Unless very badly documented in the SDK so far, this is not that complex for most applications. Here is an example implementation.

Application UI

The impact in your application UI is quite limited. All you have to do is to enable skins when calling the AppUi base constructor:

// ConstructL is called by the application framework
void CSkinDemoAppUi::ConstructL()
{
 BaseConstructL(EAknEnableSkin);
 ...
}

Application View

As you may have guessed, the main changes will be in your view and containers. The changes here may vary from simple to rather complex depending on what your are trying to achieve. Unfortunately, the Skin API is not very well documented and everything here is not always compatible in S60 3rd Edition... [1]

First, 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 CSkinDemoAppView::ConstructL()
{
 ...
 iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,aRect,ETrue);
 ...
}

Don’t forget to call the corresponding destructor:

void CSkinDemoAppView::~CSkinDemoAppView()
{
 ...
 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 CSkinDemoAppView::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 CSkinDemoAppView::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 );

 ...
}

If your control contains a listbox, you can enable skin behind the items by calling:

iListBox->ItemDrawer()->ColumnData()->SetSkinEnabledL(ETrue)

MMP File

And finally, you need to link against the Avkon Skin libraries. Add the following line in your MMP file:

LIBRARY aknskins.lib aknskinsrv.lib

Download

Below you will find two samples project. One simple application created with the Codewarrior wizard without any skin support and its counterpart with skin support added.

 
SkinDemo.sis (No Skin)

 
SkinDemo (No Skin) Source code

 
SkinDemo2.sis (With Skin)

 
SkinDemo (With Skin) Source code



[1] But if you have the equivalent for 3rd edition... feel free to mail me so that I can update the page!

相关文章:
Observer Pattern in Symbian application
Change the application language at runtime for Series 60 3rd Ed.
How to detect if an application is launched by user or the startup list
Carbide.c++: Setting up On Target Debugging
Tips & code samples for Sony Ericsson’s UIQ 3 based phones
How to let a DLL know which application uses it
Tracking down memory leaks
Obtain IMEI number of your symbian phone from Your Go-DB application
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号