S60MMFLabContainer.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:4k
- // Copyright (c) 2006 Nokia Corporation.
- // INCLUDE FILES
- #include "S60MMFLabContainer.h"
- #include <aknsdrawutils.h>
- #include <eiklabel.h> // for example label control
- #include <aknsbasicbackgroundcontrolcontext.h>
- #include <aknutils.h>
- // ================= MEMBER FUNCTIONS =======================
- // ---------------------------------------------------------
- // CS60MMFLabContainer::ConstructL(const TRect& aRect)
- // EPOC two phased constructor
- // ---------------------------------------------------------
- //
- void CS60MMFLabContainer::ConstructL(const TRect& aRect, const TDesC& aLabel)
- {
- CreateWindowL();
- iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,aRect,ETrue);
-
- iLabel = new (ELeave) CEikLabel;
- iLabel->SetContainerWindowL( *this );
- iLabel->SetTextL( aLabel );
-
- SetRect(aRect);
- ActivateL();
- }
- // Destructor
- CS60MMFLabContainer::~CS60MMFLabContainer()
- {
- delete iLabel;
- delete iBgContext;
- }
- // ---------------------------------------------------------
- // CS60MMFLabContainer::SizeChanged()
- // Called by framework when the view size is changed
- // ---------------------------------------------------------
- //
- void CS60MMFLabContainer::SizeChanged()
- {
- TRect rect;
- AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
- iBgContext->SetRect(rect);
- SetLabelL(*iLabel->Text());
- }
- // ---------------------------------------------------------
- // CS60MMFLabContainer::CountComponentControls() const
- // ---------------------------------------------------------
- //
- TInt CS60MMFLabContainer::CountComponentControls() const
- {
- return 1; // return nbr of controls inside this container
- }
- // ---------------------------------------------------------
- // CS60MMFLabContainer::ComponentControl(TInt aIndex) const
- // ---------------------------------------------------------
- //
- CCoeControl* CS60MMFLabContainer::ComponentControl(TInt aIndex) const
- {
- switch ( aIndex )
- {
- case 0:
- return iLabel;
- default:
- return NULL;
- }
- }
- // ---------------------------------------------------------
- // CS60MMFLabContainer::Draw(const TRect& aRect) const
- // ---------------------------------------------------------
- //
- void CS60MMFLabContainer::Draw(const TRect& aRect) const
- {
- 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 );
- }
- // ---------------------------------------------------------
- // CS60MMFLabContainer::HandleControlEventL(
- // CCoeControl* aControl,TCoeEvent aEventType)
- // ---------------------------------------------------------
- //
- void CS60MMFLabContainer::HandleControlEventL(
- CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
- {
- // TODO: Add your control event handler code here
- }
- void CS60MMFLabContainer::SetLabelL(const TDesC& aLabel)
- {
- TPtrC text = aLabel;
- TSize minSize = iLabel->CalcMinimumSize(text);
- TInt minHeight = minSize.iHeight;
- minSize.iHeight = 2*minHeight;
-
- iLabel->SetTextL(aLabel);
- iLabel->SetExtent( TPoint(minHeight, minHeight), minSize );
- }
- TTypeUid::Ptr CS60MMFLabContainer::MopSupplyObject(TTypeUid aId)
- {
- if (iBgContext )
- {
- return MAknsControlContext::SupplyMopObject( aId, iBgContext );
- }
-
- return CCoeControl::MopSupplyObject(aId);
- }
- // End of File