×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328

    Skin background in custom control

    Hi

    I would like to implement a custom control that shows the currently selected skin's wallpaper in the background.

    In my AppUi class, I am calling BaseConstructL(EAknEnableSkin); to make the app skin aware and in other views, this seems to work.

    And in my Draw() method I have tried this (copied from elsewhere on the forum), but it simply draws a nice white block for the background - nice ;-)

    void CBackVisibleControl::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    MAknsControlContext* cc = AknsDrawUtils::ControlContext(this);
    AknsDrawUtils::Background(skin, cc, this, gc, Rect(), KAknsDrawParamDefault);

    // some more drawing here
    }

    Does anyone have a simple example of a working custom control with the skin's background visible?

    Any help welcome...

    Thanks

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009
    Your prob might get resolved if u add :

    OverrideColorL(EEikColorWindowBackground,TLogicalRgb::ESystemBackgroundColor);

    in the PostLayoutDynInitL().

  3. #3
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328
    Um, there is no PostLayoutDynInitL() in CCoeControl?

    I tried placing OverrideColorL(EEikColorWindowBackground,TLogicalRgb::ESystemBackgroundColor) in my ConstructL and it didn't help - still the white block

    Another similar thread:

    http://discussion.forum.nokia.com/fo...ht=%2Awhite%2A

    Any further ideas?

    Thanks

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    Czech Republic
    Posts
    915
    Do you have this in your Container::ConstructL()
    Code:
    iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );
    and something like this?
    Code:
    TTypeUid::Ptr CSoptaThemesContEdwin::MopSupplyObject(TTypeUid aId)
        {
        if(aId.iUid == MAknsControlContext::ETypeId && iBackGround)
            {
            return MAknsControlContext::SupplyMopObject( aId, iBackGround);
            }
    
        return CCoeControl::MopSupplyObject( aId );
        }
    It is necessary to propagate the right "pointer" to the current skin...

  5. #5
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328
    Thanks Sopta007, I will try that

  6. #6
    Regular Contributor
    Join Date
    Feb 2005
    Posts
    328

    Working example

    Thanks Sopta007, this works!

    The following example simply draws a bitmap in the middle of the screen with the skin background behind it.

    // add to your MMP file

    LIBRARY AknSkins.lib


    //
    // SkinAwareControl.h
    //

    #ifndef __SkinAwareControl_H__
    #define __SkinAwareControl_H__

    // includes
    #include <coecntrl.h>

    // forward declaration
    class CAknsBasicBackgroundControlContext;

    class CSkinAwareControl : public CCoeControl, public MCoeControlObserver
    {
    public:
    static CSkinAwareControl* NewL(const TRect& aRect);
    ~CSkinAwareControl();
    private:
    CSkinAwareControl();
    void ConstructL(const TRect & aRect);
    public:
    // from CCoeControl
    void Draw(const TRect& aRect) const;
    TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
    // from MCoeControlObserver
    void HandleControlEventL(CCoeControl * aControl, TCoeEvent aEventType);
    private:
    // from MObjectProvider
    virtual TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
    private:
    CFbsBitmap iBitmap;
    CAknsBasicBackgroundControlContext* iBackground;
    };

    #endif // __SkinAwareControl_H__



    //
    // SkinAwareControl.cpp
    //

    #include "SkinAwareControl.h"
    #include <aknutils.h>
    #include <AknsDrawUtils.h>
    #include <AknsBasicBackgroundControlContext.h>

    CSkinAwareControl* CSkinAwareControl::NewL(const TRect& aRect)
    {
    CSkinAwareControl* self = new(ELeave) CSkinAwareControl;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    CleanupStack::Pop(self);
    return self;
    }

    CSkinAwareControl::CSkinAwareControl()
    {
    }

    CSkinAwareControl::~CSkinAwareControl()
    {
    delete iBitmap;
    delete iBackground;
    }

    void CSkinAwareControl::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    SetRect(aRect);

    // mbm file holding recorder panel buttons
    _LIT(KSkinAwareAppMbmFile, "\\system\\apps\\SkinAwareApp\\SkinAwareApp.mbm");
    TFileName filename(KSkinAwareAppMbmFile);
    CompleteWithAppPath(filename);

    // load bitmap
    iBitmap = new(ELeave) CFbsBitmap;
    User::LeaveIfError(iBitmap->Load(filename, 0, ETrue));

    // skin background
    iBackground = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMain, Rect(), EFalse);

    ActivateL();
    DrawNow();
    }

    void CSkinAwareControl::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();

    // draw skin backgound
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    MAknsControlContext* cc = AknsDrawUtils::ControlContext(this);
    AknsDrawUtils::Background(skin, cc, this, gc, Rect(), KAknsDrawParamDefault);

    // draw bitmap
    TRect region(aRect);
    aRect.Shrink(10,10);
    gc.DrawBitmap(region, iBitmap);
    }

    TKeyResponse CSkinAwareControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    return EKeyWasNotConsumed;
    }

    void CSkinAwareControl::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/)
    {
    }

    TTypeUid::Ptr CSkinAwareControl::MopSupplyObject(TTypeUid aId)
    {
    if (aId.iUid == MAknsControlContext::ETypeId && iBackground != NULL)
    {
    return MAknsControlContext::SupplyMopObject(aId, iBackground);
    }

    return CCoeControl::MopSupplyObject(aId);
    }
    Last edited by template60; 2005-02-21 at 15:12.

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    1
    I actually have the same problem and the above info REALLY helps!
    Many THANKS!

  8. #8
    Registered User
    Join Date
    May 2005
    Posts
    5
    HI,
    I was getting a problem in skined controls. Actually my control lies in the status pane.
    // skin background
    iBackground = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgAreaMain, Rect(), EFalse);

    So in the above statment i used "KAknsIIDQsnBgAreaStatus" to get the status area skin. Now what happens it draws the skin on the whole status area and also hides the application's icon. Is there a solution for this.

    Thanks.

  9. #9
    Regular Contributor
    Join Date
    Mar 2005
    Posts
    52
    thanks for template60,
    If I want to have a "Grid" control but still have Background image behind it. Its this possible? If possible ,could you please give me some advince to do so. Thanks again

    BestRegard
    JP

  10. #10
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    54

    Re: Skin background in custom control

    hi...
    Can we do that?Grid with a background
    Thanks
    sarayu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×