securitydialogs/simlockui/src/SimLockUIBackgroundControl.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Feb 2010 23:42:03 +0200
branchRCL_3
changeset 5 3b17fc5c9564
parent 1 d5423fbb4f29
child 20 63339781d179
permissions -rw-r--r--
Revision: 201003 Kit: 201007

/*
* ============================================================================
*  Name        : SimLockUIBackgroundControl.cpp
*  Part of     : Sim Lock UI Application
*  Description : Implementation of Sim Lock UI Background
*  Version     :
*  
* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:   Build info file for Ado domain appinstall 
* ============================================================================
*/


// System Includes
#include <coemain.h>
#include <AknsDrawUtils.h>                      // AknsDrawUtils
#include <AknsSkinInstance.h>                   // MAknsSkinInstance
#include <AknsControlContext.h>                 // MAknsControlContext
#include <AknsBasicBackgroundControlContext.h>  // CAknsBasicBackgroundControlContext
#include <aknlayoutscalable_avkon.cdl.h>        // AknLayoutScalable_Avkon
#include <AknUtils.h>                           // AknsUtils

// User Includes
#include "simlockuibackgroundcontrol.h"
#include "simlockisaserverdefinitions.h"
#include <simlockui.rsg>

static const TInt KSkinLayoutOption = 2;

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::NewL
// ---------------------------------------------------------------------------
CSimLockUIBackgroundControl* CSimLockUIBackgroundControl::NewL( const TRect& aRect )
    {
    CSimLockUIBackgroundControl* self = CSimLockUIBackgroundControl::NewLC( aRect );
    CleanupStack::Pop( self );
    return self;
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::NewLC
// ---------------------------------------------------------------------------
CSimLockUIBackgroundControl* CSimLockUIBackgroundControl::NewLC( const TRect& aRect )
    {
    CSimLockUIBackgroundControl* self = new ( ELeave ) CSimLockUIBackgroundControl;
    CleanupStack::PushL( self );
    self->ConstructL( aRect );
    return self;
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::~CSimLockUIBackgroundControl
// ---------------------------------------------------------------------------
CSimLockUIBackgroundControl::~CSimLockUIBackgroundControl()
    {
    delete iBackgroundSkinContext;
    delete iDisplayText;
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::SetBackgroundText
// ---------------------------------------------------------------------------
void CSimLockUIBackgroundControl::SetBackgroundText( HBufC* aText )
    {
    delete iDisplayText;

    iDisplayText = aText;

    DrawDeferred();
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::ConstructL
// ---------------------------------------------------------------------------
void CSimLockUIBackgroundControl::ConstructL( const TRect& aRect )
    {
    // Create a window for this application view
    CreateWindowL();

    iBackgroundSkinContext = CAknsBasicBackgroundControlContext::NewL(
            KAknsIIDQsnBgAreaMain, aRect, EFalse );

    // Set the windows size
    SetRect( aRect );

    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::SizeChanged
// ---------------------------------------------------------------------------
void CSimLockUIBackgroundControl::SizeChanged()
    {
    // Background skin.
    iBackgroundSkinContext->SetRect( Rect() );
    }


// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::Draw
// ---------------------------------------------------------------------------
void CSimLockUIBackgroundControl::Draw( const TRect& /*aRect*/ ) const
    {
    // Draw background skin
    CWindowGc& graphicsContext = SystemGc();
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    MAknsControlContext* controlContext = AknsDrawUtils::ControlContext( this );
    AknsDrawUtils::Background( skin, controlContext, this, graphicsContext, Rect() );

    // Draw background text
    DisplayText( graphicsContext );
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::MopSupplyObject
// ---------------------------------------------------------------------------
TTypeUid::Ptr CSimLockUIBackgroundControl::MopSupplyObject( TTypeUid aId )
    {
    if ( aId.iUid == MAknsControlContext::ETypeId )
        {
        // Return the background skin object
        return MAknsControlContext::SupplyMopObject( aId, iBackgroundSkinContext );
        }

    return CCoeControl::MopSupplyObject( aId );
    }

// ---------------------------------------------------------------------------
// CSimLockUIBackgroundControl::DisplayText
// ---------------------------------------------------------------------------
void CSimLockUIBackgroundControl::DisplayText( CGraphicsContext& aGc ) const
    {
    if ( iDisplayText )
        {
        // Set up text and layout
        TAknLayoutText line;
        TAknTextLineLayout layout = AknLayoutScalable_Avkon::main_pane_empty_t1( KSkinLayoutOption ).LayoutLine();

        line.LayoutText( Rect(), layout );

        // Get color from skin instance.
        TRgb color( line.Color() );

        if ( AknsUtils::AvkonSkinEnabled() )
            {
            TRgb skinColor;

            MAknsSkinInstance* skin = AknsUtils::SkinInstance();

            TInt err = AknsUtils::GetCachedColor( skin,
                                                  skinColor,
                                                  KAknsIIDQsnTextColors,
                                                  EAknsCIQsnTextColorsCG6 );
            if ( err == KErrNone )
                {
                color = skinColor;
                }
            }

        // Actually display the text
        line.DrawText( aGc, *iDisplayText, ETrue, color );
        }
    }

// End of file.