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