examples/ForumNokia/ThreadExample/src/threadappview.cpp

00001 /*
00002 * ============================================================================
00003 *  Name     : CThreadAppView from CThreadAppView.h
00004 *  Part of  : Thread
00005 *  Created  : 04.02.2005 by Forum Nokia
00006 *  Version  : 1.0
00007 *  Copyright: Nokia Corporation
00008 * ============================================================================
00009 */
00010 
00011 // INCLUDES
00012 #include <coemain.h>
00013 #include "ThreadAppView.h"
00014 #include "ThreadAnimation.h"
00015 #include <barsread.h> //TResourceReader
00016 #include <thread.rsg>
00017 
00018 #include <w32std.h>
00019 
00021 #define KEditorPosition TPoint(0,55) 
00022 
00023 CThreadAppView* CThreadAppView::NewL(const TRect& aRect)
00024     {
00025     CThreadAppView* self = CThreadAppView::NewLC(aRect);
00026     CleanupStack::Pop(self);
00027     return self;
00028     }
00029 
00030 CThreadAppView* CThreadAppView::NewLC(const TRect& aRect)
00031     {
00032     CThreadAppView* self = new (ELeave) CThreadAppView;
00033     CleanupStack::PushL(self);
00034     self->ConstructL(aRect);
00035     return self;
00036     }
00037 
00038 // ----------------------------------------------------------------------------
00039 // CThreadAppView::CThreadAppView()
00040 //
00041 // constructor
00042 // ----------------------------------------------------------------------------
00043 CThreadAppView::CThreadAppView()
00044     {
00045     }
00046 
00047 // ----------------------------------------------------------------------------
00048 // CThreadAppView::~CThreadAppView()
00049 //
00050 // destructor
00051 // ----------------------------------------------------------------------------
00052 CThreadAppView::~CThreadAppView()
00053     {
00054     delete iRte;
00055 
00056     //delete all animations
00057     delete iAnimationOne;
00058 
00059     delete iAnimationTwo;
00060 
00061     delete iAnimationThree;
00062     }
00063 
00064 // ----------------------------------------------------------------------------
00065 // CThreadAppView::ConstructL(const TRect& aRect)
00066 //
00067 // Standard EPOC 2nd phase constructor
00068 // ----------------------------------------------------------------------------
00069 void CThreadAppView::ConstructL(const TRect& aRect)
00070     {
00071     // Create a window for this application view
00072     CreateWindowL();
00073 
00074     //instantiate rich text editor
00075     iRte = CRichTextEditorRTE::NewL(*this);
00076         
00077     // Set the windows size
00078     SetRect(aRect);
00079     
00080     // Activate the window, which makes it ready to be drawn
00081     ActivateL();
00082 
00083     //Reads an animation resource from a resource file 
00084     TResourceReader reader;
00085     iCoeEnv->CreateResourceReaderLC(reader, R_ANIMATION_THREAD_ONE_DATA);
00086 
00087     //create animation based on reader 
00088     iAnimationOne = CThreadAnimation::NewL(reader, Window());
00089     CleanupStack::PopAndDestroy(); //reader
00090 
00091     TResourceReader readerTwo;
00092     iCoeEnv->CreateResourceReaderLC(readerTwo, R_ANIMATION_THREAD_TWO_DATA); 
00093     iAnimationTwo = CThreadAnimation::NewL(readerTwo, Window());
00094     CleanupStack::PopAndDestroy(); //readerTwo
00095 
00096     TResourceReader readerThree;
00097     iCoeEnv->CreateResourceReaderLC(readerThree, R_ANIMATION_THREAD_THREE_DATA);
00098     iAnimationThree = CThreadAnimation::NewL(readerThree, Window());
00099     CleanupStack::PopAndDestroy(); //readerThree
00100     }
00101 
00102 // ----------------------------------------------------------------------------
00103 // CThreadAppView::DrawText(const TDesC& aText)
00104 //
00105 // Draw text on the screen, uses rich text editor.
00106 // ----------------------------------------------------------------------------
00107 void CThreadAppView::DrawText(const TDesC& aText)
00108     {
00109     iRte->AddTextL(aText);
00110     }
00111 
00112 // ----------------------------------------------------------------------------
00113 // CThreadAppView::Draw(const TRect& aRect) const
00114 //
00115 // Draw this application's view to the screen
00116 // ----------------------------------------------------------------------------
00117 void CThreadAppView::Draw(const TRect& aRect) const
00118     {
00119     // Get the standard graphics context 
00120     CWindowGc& gc = SystemGc();
00121     gc.Clear(aRect);
00122     }
00123 
00124 // ----------------------------------------------------------------------------
00125 // CThreadAppView::SizeChanged()
00126 //
00127 // called by framework when the view size is changed
00128 // ----------------------------------------------------------------------------
00129 void CThreadAppView::SizeChanged()
00130     {
00131     iRte->SetExtent(KEditorPosition, Window().Size());    
00132     }
00133 
00134 // ----------------------------------------------------------------------------
00135 // TInt CThreadAppView::CountComponentControls() const
00136 //
00137 // Called by the framework in compound controls 
00138 // ----------------------------------------------------------------------------
00139 TInt CThreadAppView::CountComponentControls() const
00140     {
00141     return 1; // return number of controls inside this container
00142     }
00143 
00144 // ----------------------------------------------------------------------------
00145 // CCoeControl* CThreadAppView::ComponentControl(TInt aIndex) const
00146 //
00147 // Called by the framework in compound controls 
00148 // ----------------------------------------------------------------------------
00149 CCoeControl* CThreadAppView::ComponentControl(TInt aIndex) const
00150     {
00151     switch (aIndex)
00152         {
00153     case 0:
00154         return iRte;
00155     default:
00156         return NULL;
00157         }
00158     }
00159 
00160 // ----------------------------------------------------------------------------
00161 // TKeyResponse CThreadAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
00162 //              TEventCode aType)
00163 //
00164 // Called by the framework whenever a key event occurs. 
00165 // Passes the key event to the editor if it is not null, otherwise returns
00166 // EKeyWasNotConsumed
00167 // ----------------------------------------------------------------------------
00168 TKeyResponse CThreadAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00169     {
00170     if (iRte)
00171         {
00172         return iRte->OfferKeyEventL(aKeyEvent, aType);
00173         }
00174     else 
00175         {
00176         return CCoeControl::OfferKeyEventL(aKeyEvent, aType);
00177         }
00178     }

Generated by  doxygen 1.6.2