examples/SFExamples/Graphics_Images/src/GraphicsMainView.cpp

00001 /*
00002 Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */ 
00029 
00030 // INCLUDES
00031 
00032 #include "ControlsContainer.h"
00033 #include "ImageContainer.h"
00034 #include "AnimationContainer.h"
00035 #include "BitmapContainer.h"
00036 #include "AboutContainer.h"
00037 
00038 #include "GraphicsMainView.h"
00039 #include "GraphicsExternalInterface.h"
00040 #include <GraphicsImages.rsg>
00041 #include "Graphics.hrh"
00042 
00043 
00044 
00045 // MEMBER FUNCTIONS
00046 
00047 // --------------------------------------------------------------------------
00048 // Two-phase constructor
00049 // --------------------------------------------------------------------------
00050 CGraphicsMainView* CGraphicsMainView::NewLC(CGraphicsAppUi& aAppUi)
00051         {
00052         CGraphicsMainView* self = new (ELeave) CGraphicsMainView(aAppUi);
00053         CleanupStack::PushL(self);
00054         self->ConstructL();
00055         return self;
00056         }
00057 /*
00058 -----------------------------------------------------------------------------
00059 -----------------------------------------------------------------------------
00060 */ 
00061 CGraphicsMainView* CGraphicsMainView::NewL(CGraphicsAppUi& aAppUi)
00062         {
00063         CGraphicsMainView* self = CGraphicsMainView::NewLC(aAppUi);
00064         CleanupStack::Pop();
00065         return self;
00066         }
00067 // --------------------------------------------------------------------------
00068 // Default constructor
00069 // --------------------------------------------------------------------------
00070 CGraphicsMainView::CGraphicsMainView(CGraphicsAppUi& aAppUi)
00071         {
00072         }
00073 
00074 // --------------------------------------------------------------------------
00075 // Destructor
00076 // --------------------------------------------------------------------------
00077 CGraphicsMainView::~CGraphicsMainView()
00078         {
00079         delete iAppContainer;
00080         delete iMySplashContainer;
00081         }
00082 
00083 // --------------------------------------------------------------------------
00084 // Second phase constructor
00085 // --------------------------------------------------------------------------
00086 void CGraphicsMainView::ConstructL()
00087         {
00088         CreateWindowL();        
00089         
00090     TRect rect;
00091     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00092     SetRect(rect);
00093     
00094         ActivateL();
00095         
00096         iMySplashContainer = CMySplashContainer::NewL(*this);
00097 
00098         DrawNow();
00099         }
00100 
00101 
00102 /*
00103 -----------------------------------------------------------------------------
00104 -----------------------------------------------------------------------------
00105 */ 
00106 void CGraphicsMainView::HandleResourceChange(TInt aType)
00107         {
00108     if ( aType==KEikDynamicLayoutVariantSwitch )
00109         {       
00110         TRect rect;
00111         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00112         SetRect(rect);
00113     
00114         if(iAppContainer)
00115                 {
00116                 iAppContainer->SetRect(rect);
00117                 }
00118         }
00119 
00120         CCoeControl::HandleResourceChange(aType);
00121         }
00122 
00123 
00124 /*
00125 -----------------------------------------------------------------------------
00126 -----------------------------------------------------------------------------
00127 */ 
00128 void CGraphicsMainView::SplashTimeIsUpL(void)
00129 {
00130         ChangeViewL(EImagesexampleBitmap);
00131         
00132         // delete splash container
00133         delete iMySplashContainer;
00134         iMySplashContainer = NULL;
00135 }
00136 // --------------------------------------------------------------------------
00137 // Second phase constructor
00138 // --------------------------------------------------------------------------
00139 void CGraphicsMainView::ChangeViewL(TInt aView )
00140         {
00141         TRect clientR(CEikonEnv::Static()->EikAppUi()->ClientRect());
00142 
00143         CCoeControl* newContainer(NULL);
00144         TInt err(KErrNone);
00145 
00146         // New containers are made first
00147         // and any leave is catched with the TRAP
00148         
00149         switch ( aView )
00150                 {
00151                 case EImagesexampleImage:       
00152                         {
00153                         TFindFile imageFile(CCoeEnv::Static()->FsSession());
00154                         if(KErrNone == imageFile.FindByDir(KTxImage1, KNullDesC))
00155                                 {       //requires image
00156                                 //thus if it is not found the container is not constructed
00157                                 newContainer = CImageContainer::NewL(clientR,imageFile.File());
00158                                 }
00159                         }
00160                         break;
00161                 case EImagesexampleAnimation:
00162                         {
00163                         TFindFile aniFile(CCoeEnv::Static()->FsSession());
00164                         if(KErrNone == aniFile.FindByDir(KTxAnimation1, KNullDesC))
00165                                 {       //requires animation gif file
00166                                 //thus if it is not found the container is not constructed
00167                                 newContainer = CAnimationContainer::NewL(clientR,aniFile.File());
00168                                 }
00169                         }
00170                         break;
00171                 case EImagesexampleControls:
00172                         newContainer = CControlsContainer::NewL(clientR);
00173                         break;
00174                 case EImagesexampleBitmap:
00175                         newContainer = CBitmapContainer::NewL(clientR);
00176                         break;
00177                 case EImagesexampleAbout:
00178                         newContainer = CAboutContainer::NewL(clientR);
00179                         break;
00180                 }
00181 
00182         // If TRAP catched a leave we abort the change
00183         if(err != KErrNone)
00184                 {
00185                 delete newContainer;
00186                 newContainer = NULL;
00187                 }
00188 
00189         if(newContainer)// if all was well we proceed
00190                 {
00191                 // delete old and set new one 
00192                 delete iAppContainer;
00193                 iAppContainer = newContainer;
00194                 }               
00195                 
00196         DrawNow();
00197         }
00198 
00199 
00200 /*
00201 -----------------------------------------------------------------------------
00202 normal CCoeControl functions, see SDK documentation
00203 -----------------------------------------------------------------------------
00204 */ 
00205 void CGraphicsMainView::Draw( const TRect& /*aRect*/ ) const
00206         {
00207         CWindowGc& gc = SystemGc();
00208         gc.Clear();
00209         }
00210 
00211 
00212 /*
00213 -----------------------------------------------------------------------------
00214 normal key handling function for CCoeControl, gets all key events
00215 when this container is on focus (and it has been added to the control stack)
00216 -----------------------------------------------------------------------------
00217 */
00218 TKeyResponse CGraphicsMainView::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
00219         {
00220         TKeyResponse  myRet = EKeyWasNotConsumed;
00221         
00222         if(iAppContainer)
00223         {
00224         iAppContainer->OfferKeyEventL(aKeyEvent,aType);
00225         }
00226 
00227         return myRet;
00228         }
00229 /*
00230 -----------------------------------------------------------------------------
00231 normal CCoeControl functions, see SDK documentation
00232 -----------------------------------------------------------------------------
00233 */ 
00234 TInt CGraphicsMainView::CountComponentControls() const
00235         {
00236         if(iAppContainer)
00237                 {
00238                 return 1;
00239                 }
00240         else
00241                 {
00242                 return 0;
00243                 }
00244         }
00245 /*
00246 -----------------------------------------------------------------------------
00247 normal CCoeControl functions, see SDK documentation
00248 -----------------------------------------------------------------------------
00249 */ 
00250 CCoeControl* CGraphicsMainView::ComponentControl( TInt /*aIndex */) const
00251         {
00252         return iAppContainer;
00253         }
00254         
00255 // End of File

Generated by  doxygen 1.6.2