diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/txtshell_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/txtshell_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,234 @@ + + + + +TB9.2 Example Applications: examples/AppFramework/txtshell/txtshell.cpp Source File + + + + + +

examples/AppFramework/txtshell/txtshell.cpp

00001 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
+00002 // All rights reserved.
+00003 // This component and the accompanying materials are made available
+00004 // under the terms of "Eclipse Public License v1.0"
+00005 // which accompanies this distribution, and is available
+00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00007 //
+00008 // Initial Contributors:
+00009 // Nokia Corporation - initial contribution.
+00010 //
+00011 // Contributors:
+00012 //
+00013 // Description:
+00014 //
+00015 
+00016 #include <e32keys.h>
+00017 
+00018 #include <coemain.h>
+00019 
+00020 #include <eikenv.h>
+00021 #include <eikdef.h>
+00022 #include <eikon.hrh>
+00023 #include <eiklabel.h>
+00024 #include <eikstart.h>
+00025 
+00026 #include <txtshell.rsg>
+00027 #include "txtshell.hrh"
+00028 #include "txtshell.h"
+00029 
+00030 //
+00031 // TExampleShellModel
+00032 //
+00033 
+00034 TExampleShellModel::TExampleShellModel()
+00035         {
+00036         iLibrary=KNullDesC;
+00037         }
+00038 
+00039 TBool TExampleShellModel::Differs(const TExampleShellModel* aCompare) const
+00040         {
+00041         return((*(TInt32*)this)!=(*(TInt32*)aCompare));
+00042         }
+00043 
+00044 //
+00045 // class CExampleShellContainer
+00046 //
+00047 
+00048 void CExampleShellContainer::ConstructL(const TRect& aRect, TExampleShellModel* aModel)
+00049     {
+00050         iModel=aModel;
+00051     CreateWindowL();
+00052     Window().SetShadowDisabled(ETrue);
+00053     iContext=this;
+00054         iBrushStyle=CGraphicsContext::ESolidBrush;
+00055     iBrushColor=KRgbWhite;
+00056     SetRect(aRect);
+00057         CreateLabelL();
+00058     ActivateL();
+00059     }
+00060 
+00061 CExampleShellContainer::~CExampleShellContainer()
+00062     {
+00063         delete iExampleControl;
+00064         delete iLabel;
+00065     }
+00066     
+00067 TInt CExampleShellContainer::CountComponentControls() const
+00068         {
+00069         return 1 + (iExampleControl ? 1 : 0);
+00070         }
+00071 
+00072 CCoeControl* CExampleShellContainer::ComponentControl(TInt aIndex) const
+00073         {
+00074         switch (aIndex)
+00075                 {
+00076         case 0: return iLabel;
+00077         case 1: return iExampleControl;
+00078         default: return 0;
+00079                 };
+00080         }
+00081 
+00082 const TInt KLabelHeight=20;
+00083 
+00084 void CExampleShellContainer::CreateLabelL()
+00085         {
+00086         iLabel=new (ELeave) CEikLabel;
+00087         TRect rect=Rect();
+00088         rect.iTl.iY=rect.iBr.iY-KLabelHeight; // make it bottom 20 pixels
+00089         iLabel->SetContainerWindowL(*this);
+00090         iLabel->SetRect(rect);
+00091         iLabel->SetAlignment(EHCenterVCenter); // center text
+00092         iLabel->SetBufferReserveLengthL(200); // nice long buffer
+00093         iLabel->SetFont(iEikonEnv->AnnotationFont());
+00094         iLabel->ActivateL(); // now ready
+00095         }
+00096 
+00097 void CExampleShellContainer::ResetExampleL(CGraphicExampleControl* aExample)
+00098         {
+00099         // get rid of old control
+00100         delete iExampleControl;
+00101         // set up new one
+00102         iExampleControl=aExample;
+00103         // if non-zero, then carry on
+00104         if (!iExampleControl) return;
+00105         TRect rect=Rect(); // get our rect
+00106         rect.iBr.iY-=KLabelHeight; // make way for label
+00107         rect.Shrink(2,2); // shrink it a bit
+00108         iExampleControl->ConstructL(rect,this,*this); // construct, giving rect, observer, and parent
+00109         }
+00110 
+00111 void CExampleShellContainer::NotifyGraphicExampleFinished()
+00112         {
+00113         _LIT(KStatus,"example finished");
+00114         NotifyStatus(KStatus);
+00115         }
+00116 
+00117 void CExampleShellContainer::NotifyStatus(const TDesC& aMessage)
+00118         {
+00119         TRAPD(err,iLabel->SetTextL(aMessage));
+00120         if(err)
+00121                 {
+00122                 return;
+00123                 }       
+00124         if (IsActivated()) iLabel->DrawNow();
+00125         }
+00126 
+00127 TKeyResponse CExampleShellContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
+00128     {
+00129         if      (iExampleControl)
+00130                 return iExampleControl->OfferKeyEventL(aKeyEvent,aType);
+00131         else
+00132                 return EKeyWasNotConsumed;
+00133     }
+00134 
+00135 void CExampleShellContainer::Draw(const TRect& /*aRect*/) const
+00136         {
+00137         CWindowGc& gc = SystemGc();
+00138         gc.SetPenStyle(CGraphicsContext::ENullPen);
+00139         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
+00140         gc.DrawRect(Rect());
+00141         }
+00142 
+00143 //
+00144 // CExampleShellAppUi
+00145 //
+00146 
+00147 void CExampleShellAppUi::ConstructL()
+00148     {
+00149         _LIT(KStatus,"initialized");
+00150     BaseConstructL();
+00151         iModel=((CExampleShellDocument*)iDocument)->Model();
+00152     iContainer=new(ELeave) CExampleShellContainer;
+00153     iContainer->ConstructL(ClientRect(),iModel);
+00154         iContainer->NotifyStatus(KStatus);
+00155         // add container to stack; enables key event handling.
+00156         AddToStackL(iContainer);
+00157     }
+00158 
+00159 void CExampleShellAppUi::HandleCommandL(TInt aCommand)
+00160         {
+00161         switch (aCommand)
+00162                 {
+00163         case EExampleShellSelectGlobal:
+00164                 iContainer->ResetExampleL(new (ELeave) CGlobalControl);
+00165                 return;
+00166         case EExampleShellSelectRich:
+00167                 iContainer->ResetExampleL(new (ELeave) CRichControl);
+00168                 return;
+00169         case EExampleShellSelectStyled:
+00170                 iContainer->ResetExampleL(new (ELeave) CStyleControl);
+00171                 return;
+00172         case EExampleShellSelectView:
+00173                 iContainer->ResetExampleL(new (ELeave) CViewControl);
+00174                 return;
+00175         case EEikCmdExit:
+00176                 Exit();
+00177                 return;
+00178                 }
+00179         }
+00180 
+00181 CExampleShellAppUi::~CExampleShellAppUi()
+00182         {
+00183         RemoveFromStack(iContainer);
+00184     delete iContainer;
+00185         }
+00186 
+00187 //
+00188 // CExampleShellDocument
+00189 //
+00190 
+00191 CEikAppUi* CExampleShellDocument::CreateAppUiL()
+00192         {
+00193     return(new(ELeave) CExampleShellAppUi);
+00194         }
+00195 
+00196 //
+00197 // CExampleShellApplication
+00198 //
+00199 
+00200 TUid CExampleShellApplication::AppDllUid() const
+00201         {
+00202         return KUidExampleShellApp;
+00203         }
+00204 
+00205 CApaDocument* CExampleShellApplication::CreateDocumentL()
+00206         {
+00207         return new(ELeave) CExampleShellDocument(*this);
+00208         }
+00209 
+00210 LOCAL_C CApaApplication* NewApplication()
+00211         {
+00212         return new CExampleShellApplication;
+00213         }
+00214         
+00215 GLDEF_C TInt E32Main()
+00216         {
+00217         return EikStart::RunApplication(NewApplication);
+00218         }
+
+
Generated by  + +doxygen 1.6.2
+ +