examples/ForumNokia/Symbian_OS_Basics_Lab_Exercises_v3_1/Lab_04309.cb1/solution/src/AOLabTextFlashContainer.cpp

00001 // Copyright (c) 2006 Nokia Corporation.
00002 
00003 #include "AOLabTextFlashContainer.h"
00004 #include "ActiveTimer.h"
00005 #include <eiklabel.h>
00006 
00007 _LIT(KHelloText, "Hello");
00008 _LIT(KWorldText, "World");
00009 
00010 const TInt KTimeoutValue = 2000000;
00011 
00012 
00013 // Constructs a container for this application
00014 CAOLabTextFlashContainer* CAOLabTextFlashContainer::NewL(const TRect& aRect)
00015         {
00016         CAOLabTextFlashContainer* self = new ( ELeave ) CAOLabTextFlashContainer();
00017     CleanupStack::PushL(self);
00018     self->ConstructL(aRect);
00019     CleanupStack::Pop(self);
00020     
00021     return self;
00022         }
00023         
00024         
00025 // Symbian 2nd phase constructor
00026 void CAOLabTextFlashContainer::ConstructL(const TRect& aRect)
00027     {
00028     CreateWindowL();
00029 
00030     iTopLabel = new (ELeave) CEikLabel;
00031     iTopLabel->SetContainerWindowL(*this);
00032     iTopLabel->SetTextL(KHelloText);
00033 
00034     iBottomLabel = new (ELeave) CEikLabel;
00035     iBottomLabel->SetContainerWindowL(*this);
00036     iBottomLabel->SetTextL(KWorldText);
00037 
00038     iActiveTimer = CActiveTimer::NewL(*this);
00039     iIsVisible = ETrue;
00040 
00041     SetRect(aRect);
00042     ActivateL();
00043     }
00044 
00045 
00046 // C++ Destructor
00047 CAOLabTextFlashContainer::~CAOLabTextFlashContainer()
00048     {
00049     delete iActiveTimer;
00050     delete iTopLabel;
00051     delete iBottomLabel;
00052     }
00053 
00054 
00055 // Called by framework when the view size is changed
00056 void CAOLabTextFlashContainer::SizeChanged()
00057     {
00058     iTopLabel->SetExtent( TPoint(0,0), TSize(Rect().Width(), Rect().Height()/2));
00059     iBottomLabel->SetExtent( TPoint(0,Rect().Height()/2), TSize(Rect().Width(),Rect().Height()/2));
00060     }
00061 
00062 
00063 // Returns the number of controls inside this container
00064 TInt CAOLabTextFlashContainer::CountComponentControls() const
00065     {
00066     return 2;
00067     }
00068 
00069 
00070 // Gets an indexed component of this compound control
00071 CCoeControl* CAOLabTextFlashContainer::ComponentControl(TInt aIndex) const
00072     {
00073     switch ( aIndex )
00074         {
00075         case 0:
00076             return iTopLabel;
00077         case 1:
00078             return iBottomLabel;
00079         default:
00080             return NULL;
00081         }
00082     }
00083 
00084 
00085 // Draw a grey rectangle that fills the client area of the screen
00086 void CAOLabTextFlashContainer::Draw(const TRect& aRect) const
00087     {
00088     CWindowGc& gc = SystemGc();
00089     
00090     gc.SetPenStyle(CGraphicsContext::ENullPen);
00091     gc.SetBrushColor(KRgbGray);
00092     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00093     gc.DrawRect(aRect);
00094     }
00095       
00096       
00097 // Starts the text flashing
00098 void CAOLabTextFlashContainer::FlashingText()
00099     {
00100     iTopLabel->SetTextL(KHelloText);
00101     iBottomLabel->SetTextL(KWorldText);
00102     DrawNow();
00103         
00104     if (!iIsFlashing)
00105         {
00106         iIsVisible = ETrue;
00107         iIsFlashing = ETrue;
00108         iActiveTimer->After(KTimeoutValue);
00109         }
00110     }
00111 
00112 
00113 // Stops the text flashing
00114 void CAOLabTextFlashContainer::StopFlashing()
00115     {
00116     if (iIsFlashing)
00117         {
00118         iIsFlashing = EFalse;
00119         iActiveTimer->Cancel();
00120         }
00121         
00122     iTopLabel->MakeVisible(ETrue);
00123     iBottomLabel->MakeVisible(ETrue);
00124     }
00125 
00126 
00127 // Callback function when the active object timer completes 
00128 void CAOLabTextFlashContainer::TimerComplete(TInt aError)
00129     {
00130     if (KErrNone == aError)
00131         {
00132         iIsVisible = !iIsVisible;
00133         iActiveTimer->After(KTimeoutValue);
00134         }
00135     else
00136         {
00137         iIsVisible = ETrue;
00138         iIsFlashing = EFalse;
00139         }
00140         
00141     iTopLabel->MakeVisible(iIsVisible);
00142     iBottomLabel->MakeVisible(iIsVisible);
00143     }
00144 
00145 // End of File  

Generated by  doxygen 1.6.2