×
Namespaces

Variants
Actions

Archived:Why does MAknsSkinInstance::GetCachedItemData() return NULL?

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Why does MAknsSkinInstance::GetCachedItemData() return NULL?

Article Metadata
Compatibility
Platform(s): S60 3rd Edition
S60 3rd Edition, FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Article
Created: User:Technical writer 2 (04 Jul 2007)
Last edited: hamishwillee (27 Sep 2012)

Description

The skin server in S60 provides a way to construct a bitmap (CFbsBitmap) of default skin elements.
The bitmap is typically obtained from the skin as follows:

 #include <aknsskininstance.h>
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
CAknsItemData* skinItem = skin->GetCachedItemData( someUID, EAknsITBitmap );
if( skinItem != NULL )
{
CFbsBitmap* bitmap = static_cast<CAknsBitmapItemData*>(skinItem)->Bitmap();
}

The above approach works fine for skin items that are bitmaps (EAknsITBitmap) or masked bitmaps (EAknsITMaskedBitmap). However, this is not true for all skin items. For example, if someUID in the above code is set to one of the following values:

KAknsIIDQsnBgAreaMainIdle,
KAknsIIDQsnBgScreenIdle,
KAknsIIDQsnBgScreen

GetCachedItemData() would return NULL as these UIDs do not correspond to bitmaps, but to items of type EAknsITEffectQueue.

If a skinnable element in a theme is of type EAknsITEffectQueue, it means that the item supports effects. Effects are one of the main features of scalable UI. When a skin item supports effects, it means that the item can have multiple layers. Each layer can be an image or it can be image/pixel manipulation scheme that acts on previous layer(s). The effects may be programmed to change over time, and even the first (background) layer can refer to another skin element.

Because of this, it is not possible for the MAknsSkinInstance to return a single CFbsBitmap instance for skin items of type EAknsITEffectQueue. This solution describes what applications should do in such situations.

Solution

The solution is to use AknsDrawUtils.

  1. If the application needs to draw the current (background) skin content within one of its controls (derived from CCoeControl), then it can use AknsDrawUtils::Background():
     // Create a background context (in ConstructL(), as a class member)
    iSkinContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );
    Then, in the Draw() function:
    CWindowGc& gc = SystemGc();
    TRect rect = Rect();
    gc.Clear( rect );
    AknsDrawUtils::Background( AknsUtils::SkinInstance(), iSkinContext, this, gc, rect );
  2. If the application needs a bitmap instance, then AknsDrawUtils::DrawBackground() can be used to draw the current skin content on to a CFbsBitGc:
    // Create an off-screen bitmap and context (CFbsBitGc)
    // Also remember to take care of destruction / cleanup during leaves
    CFbsBitmap* offScreenBitmap = new (ELeave) CFbsBitmap();
    User::LeaveIfError( offScreenBitmap->Create( aSize, aDisplayMode ) );
    CFbsBitGc* bitGc = 0;
    CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( offScreenBitmap );
    User::LeaveIfError( bitmapDevice->CreateContext( bitGc ) );
     
    // Draw the content on the off-screen bitmap
    AknsDrawUtils::DrawBackground( AknsUtils::SkinInstance(), iSkinContext, this, *bitGc,TPoint(0,0), rect, KAknsDrawParamDefault );
     
    // offScreenBitmap now contains current skin content
This page was last modified on 27 September 2012, at 09:16.
31 page views in the last 30 days.
×