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

Generated by  doxygen 1.6.2