00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
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
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;
00091 iLabel->SetContainerWindowL(*this);
00092 iLabel->SetRect(rect);
00093 iLabel->SetAlignment(EHCenterVCenter);
00094 iLabel->SetBufferReserveLengthL(200);
00095 iLabel->SetFont(iEikonEnv->AnnotationFont());
00096 iLabel->ActivateL();
00097 }
00098
00099 void CExampleShellContainer::ResetExampleL(CGraphicExampleControl* aExample)
00100 {
00101
00102 delete iExampleControl;
00103
00104 iExampleControl=aExample;
00105
00106 if (!iExampleControl) return;
00107 TRect rect=Rect();
00108 rect.iBr.iY-=KLabelHeight;
00109 rect.Shrink(2,2);
00110 iExampleControl->ConstructL(rect,this,*this);
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& ) const
00138 {
00139 CWindowGc& gc = SystemGc();
00140 gc.SetPenStyle(CGraphicsContext::ENullPen);
00141 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00142 gc.DrawRect(Rect());
00143 }
00144
00145
00146
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
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
00182
00183
00184 CEikAppUi* CExampleShellDocument::CreateAppUiL()
00185 {
00186 return(new(ELeave) CExampleShellAppUi);
00187 }
00188
00189
00190
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
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 }