examples/Graphics/Fonts/FontsShell.cpp

00001 /*
00002 Copyright (c) 2000-2010 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 
00031 #include <e32keys.h>
00032 
00033 #include <coemain.h>
00034 
00035 #include <eikenv.h>
00036 #include <eikdef.h>
00037 #include <eikon.hrh>
00038 #include <eiklabel.h>
00039 #include <eikstart.h>
00040 
00041 #include <fontsshell.rsg>
00042 #include "FontsShell.hrh"
00043 #include "FontsShell.h"
00044 #include "FontsGraphicsControl.h"
00045 
00046 //
00047 // TExampleShellModel
00048 //
00049 
00050 TExampleShellModel::TExampleShellModel()
00051         {
00052         iLibrary=KNullDesC;
00053         }
00054 
00055 TBool TExampleShellModel::Differs(const TExampleShellModel* aCompare) const
00056         {
00057         return((*(TInt32*)this)!=(*(TInt32*)aCompare));
00058         }
00059 
00060 //
00061 // class CExampleShellContainer
00062 //
00063 
00064 void CExampleShellContainer::ConstructL(const TRect& aRect, TExampleShellModel* aModel)
00065     {
00066         iModel=aModel;
00067     CreateWindowL();
00068     Window().SetShadowDisabled(ETrue);
00069     iContext=this;
00070         iBrushStyle=CGraphicsContext::ESolidBrush;
00071     iBrushColor=KRgbWhite;
00072     SetRect(aRect);
00073         CreateLabelL();
00074     ActivateL();
00075     }
00076 
00077 CExampleShellContainer::~CExampleShellContainer()
00078     {
00079         delete iExampleControl;
00080         delete iLabel;
00081     }
00082     
00083 TInt CExampleShellContainer::CountComponentControls() const
00084         {
00085         return 1 + (iExampleControl ? 1 : 0);
00086         }
00087 
00088 CCoeControl* CExampleShellContainer::ComponentControl(TInt aIndex) const
00089         {
00090         switch (aIndex)
00091                 {
00092         case 0: return iLabel;
00093         case 1: return iExampleControl;
00094         default: return 0;
00095                 };
00096         }
00097 
00098 const TInt KLabelHeight=20;
00099 
00100 void CExampleShellContainer::CreateLabelL()
00101         {
00102         iLabel=new (ELeave) CEikLabel;
00103         TRect rect=Rect();
00104         rect.iTl.iY=rect.iBr.iY-KLabelHeight; // make it bottom 20 pixels
00105         iLabel->SetContainerWindowL(*this);
00106         iLabel->SetRect(rect);
00107         iLabel->SetAlignment(EHCenterVCenter); // center text
00108         iLabel->SetBufferReserveLengthL(200); // nice long buffer
00109         iLabel->SetFont(iEikonEnv->AnnotationFont());
00110         iLabel->ActivateL(); // now ready
00111         }
00112 
00113 void CExampleShellContainer::ResetExampleL(CGraphicExampleControl* aExample)
00114         {
00115         // get rid of old control
00116         delete iExampleControl;
00117         // set up new one
00118         iExampleControl=aExample;
00119         // if non-zero, then carry on
00120         if (!iExampleControl) return;
00121         TRect rect=Rect(); // get our rect
00122         rect.iBr.iY-=KLabelHeight; // make way for label
00123         rect.Shrink(2,2); // shrink it a bit
00124         iExampleControl->ConstructL(rect,this,*this); // construct, giving rect and observer
00125         }
00126 
00127 _LIT(KTxtFinished,"example finished");
00128 void CExampleShellContainer::NotifyGraphicExampleFinished()
00129         {
00130         NotifyStatus(KTxtFinished);
00131         }
00132 
00133 void CExampleShellContainer::NotifyStatus(const TDesC& aMessage)
00134         {
00135         TRAPD(err,iLabel->SetTextL(aMessage));
00136         if(err)
00137                 {
00138                 return;
00139                 }       
00140         if (IsActivated()) iLabel->DrawNow();
00141         }
00142 
00143 TKeyResponse CExampleShellContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00144     {
00145         if      (iExampleControl)
00146                 return iExampleControl->OfferKeyEventL(aKeyEvent,aType);
00147         else
00148                 return EKeyWasNotConsumed;
00149     }
00150 
00151 void CExampleShellContainer::Draw(const TRect& /*aRect*/) const
00152         {
00153         CWindowGc& gc = SystemGc();
00154         gc.SetPenStyle(CGraphicsContext::ENullPen);
00155         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00156         gc.DrawRect(Rect());
00157         }
00158 
00159 //
00160 // CExampleShellAppUi
00161 //
00162 
00163 _LIT(KTxtInitialized,"initialized");
00164 void CExampleShellAppUi::ConstructL()
00165     {
00166     BaseConstructL();
00167         iModel=((CExampleShellDocument*)iDocument)->Model();
00168     iContainer=new(ELeave) CExampleShellContainer;
00169     iContainer->ConstructL(ClientRect(),iModel);
00170         iContainer->NotifyStatus(KTxtInitialized);
00171         // add container to stack; enables key event handling.
00172         AddToStackL(iContainer);
00173     }
00174 
00175 void CExampleShellAppUi::HandleCommandL(TInt aCommand)
00176         {
00177         switch (aCommand)
00178                 {
00179         case EExampleShellSelectHello:
00180                 iContainer->ResetExampleL(new (ELeave) CHelloControl);
00181                 return;
00182         case EExampleShellSelectFont:
00183                 iContainer->ResetExampleL(new (ELeave) CFontControl);
00184                 return;
00185         case EEikCmdExit:
00186                 Exit();
00187                 return;
00188                 }
00189         }
00190 
00191 CExampleShellAppUi::~CExampleShellAppUi()
00192         {
00193         RemoveFromStack(iContainer);
00194     delete iContainer;
00195         }
00196 
00197 //
00198 // CExampleShellDocument
00199 //
00200 
00201 CEikAppUi* CExampleShellDocument::CreateAppUiL()
00202         {
00203     return(new(ELeave) CExampleShellAppUi);
00204         }
00205 
00206 //
00207 // CExampleShellApplication
00208 //
00209 
00210 TUid CExampleShellApplication::AppDllUid() const
00211         {
00212         return KUidExampleShellApp;
00213         }
00214 
00215 CApaDocument* CExampleShellApplication::CreateDocumentL()
00216         {
00217         return new(ELeave) CExampleShellDocument(*this);
00218         }
00219 
00220 //
00221 // EXPORTed functions
00222 //
00223 
00224 EXPORT_C CApaApplication* NewApplication()
00225         {
00226         return new CExampleShellApplication;
00227         }
00228 
00229 GLDEF_C TInt E32Main()
00230         {
00231         return EikStart::RunApplication(NewApplication);
00232         }

Generated by  doxygen 1.6.2