00001 00002 00003 // INCLUDE FILES 00004 #include <coemain.h> 00005 #include <EIKENV.H> 00006 00007 #include <eikdef.h> 00008 #include <coeaui.h> 00009 #include "txtviewerdoc.h" 00010 #include "EIKAPPUI.H" 00011 #include <aknutils.h> //LayoutUtils 00012 00013 //Messaging related 00014 00015 #include <mtclreg.h> 00016 #include <mtuireg.h> 00017 #include <MTUDREG.H> 00018 #include <MTUIREG.H> 00019 #include <msvids.h> 00020 #include <TXTRICH.H> 00021 00022 #include <MTCLBASE.H> // SwitchCurrentEntryL 00023 00024 00025 #include "TxtViewerAppView.h" 00026 #include "TxtViewerAppUi.h" 00027 #include "../../Client/inc/txclient.h" 00028 #include "../../UI/inc/txtu.h" 00029 00030 const TInt KNumberOfLines = 5; 00031 const TInt KTextLimit = 100; 00032 00033 00034 00035 void CTxtViewerAppView::Notify() 00036 { 00037 // Change CBA if we are not editing 00038 CEikButtonGroupContainer* container = iEikonEnv->AppUiFactory()->Cba(); 00039 00040 if (!OpenedForEditing()) 00041 { 00042 container->SetCommandSetL(R_AVKON_SOFTKEYS_BACK); 00043 } 00044 else 00045 { 00046 container->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK); 00047 } 00048 00049 container->DrawDeferred(); 00050 00051 // Create a window for this application view 00052 CreateWindowL(); 00053 00054 // Initialize component array 00055 InitComponentArrayL(); // call once 00056 00057 // Create a new editor 00058 iEditor = new(ELeave) CEikRichTextEditor; 00059 00060 // Add editor to the array 00061 Components().AppendLC(iEditor); 00062 00063 TBool edit = OpenedForEditing(); 00064 00065 00066 TInt editorflags(0); 00067 00068 if (edit) 00069 { 00070 editorflags=0; 00071 } 00072 else 00073 { 00074 editorflags=EEikEdwinReadOnly; 00075 } 00076 00077 00078 iEditor->ConstructL( this, KNumberOfLines, KTextLimit, 00079 editorflags, EGulFontControlAll, EGulNoSymbolFonts ); 00080 00081 // Create a scrollbar for it 00082 iEditor->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 00083 CEikScrollBarFrame::EOn ); 00084 00085 // Editor off the cleanup stack 00086 CleanupStack::Pop(iEditor); 00087 00088 iEditor->SetContainerWindowL(*this); 00089 iEditor->SetFocus(ETrue); 00090 00091 TRect rect; 00092 00093 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect ); 00094 iEditor->SetRect( TRect(TPoint(0,0),rect.Size()) ); 00095 iEditor->ActivateL(); 00096 00097 // Set the windows size 00098 SetRect(rect); 00099 00100 // Activate the window, which makes it ready to be drawn 00101 ActivateL(); 00102 00103 InitializeMTMsL(); 00104 00105 LoadBodyL(); 00106 } 00107 // ============================ MEMBER FUNCTIONS =============================== 00108 00109 // ----------------------------------------------------------------------------- 00110 // CTxtViewerAppView::NewL() 00111 // Two-phased constructor. 00112 // ----------------------------------------------------------------------------- 00113 // 00114 CTxtViewerAppView* CTxtViewerAppView::NewL( const TRect& aRect ) 00115 { 00116 CTxtViewerAppView* self = CTxtViewerAppView::NewLC( aRect ); 00117 CleanupStack::Pop( self ); 00118 return self; 00119 } 00120 00121 // ----------------------------------------------------------------------------- 00122 // CTxtViewerAppView::NewLC() 00123 // Two-phased constructor. 00124 // ----------------------------------------------------------------------------- 00125 // 00126 CTxtViewerAppView* CTxtViewerAppView::NewLC( const TRect& aRect ) 00127 { 00128 CTxtViewerAppView* self = new ( ELeave ) CTxtViewerAppView; 00129 CleanupStack::PushL( self ); 00130 self->ConstructL( aRect ); 00131 return self; 00132 } 00133 00134 // ----------------------------------------------------------------------------- 00135 // CTxtViewerAppView::ConstructL() 00136 // Symbian 2nd phase constructor can leave. 00137 // ----------------------------------------------------------------------------- 00138 // 00139 void CTxtViewerAppView::ConstructL( const TRect& /*aRect*/ ) 00140 { 00141 } 00142 00143 // ----------------------------------------------------------------------------- 00144 // CTxtViewerAppView::LoadBodyL() 00145 // Load message body to the editor. 00146 // ----------------------------------------------------------------------------- 00147 // 00148 00149 void CTxtViewerAppView::LoadBodyL() 00150 { 00151 TMsvId id= EntryId(); 00152 00153 // Switch context 00154 iClientMtm->SwitchCurrentEntryL(id); 00155 00156 // Set state to editing 00157 iStore=iClientMtm->Entry().EditStoreL(); 00158 00159 // Get editor's CRichBox object 00160 CRichText* body = iEditor->RichText(); 00161 00162 // Restore CRichText to body 00163 iStore->RestoreBodyTextL(*body); 00164 00165 00166 delete iStore; 00167 iStore = NULL; 00168 00169 iEditor->HandleTextChangedL(); 00170 } 00171 // ----------------------------------------------------------------------------- 00172 // CTxtViewerAppView::SaveBodyL() 00173 // Saves message body to the stream. 00174 // ----------------------------------------------------------------------------- 00175 // 00176 00177 void CTxtViewerAppView::SaveBodyL() 00178 { 00179 TMsvId id= EntryId(); 00180 00181 // Switch context 00182 iClientMtm->SwitchCurrentEntryL(id); 00183 00184 // Set state to editing 00185 iStore=iClientMtm->Entry().EditStoreL(); 00186 00187 // Get editor's CRichBox object 00188 CRichText* text = iEditor->RichText(); 00189 00190 // _LIT(KText,"some message text"); 00191 00192 // text->InsertL(0,KText); 00193 00194 // Store CRichText in body 00195 iStore->StoreBodyTextL(*text); 00196 00197 iStore->CommitL(); 00198 00199 delete iStore; 00200 00201 iStore=NULL; 00202 } 00203 00204 // ----------------------------------------------------------------------------- 00205 // CTxtViewerAppView::CTxtViewerAppView() 00206 // C++ default constructor can NOT contain any code, that might leave. 00207 // ----------------------------------------------------------------------------- 00208 // 00209 CTxtViewerAppView::CTxtViewerAppView() 00210 { 00211 // No implementation required 00212 } 00213 00214 00215 // ----------------------------------------------------------------------------- 00216 // CTxtViewerAppView::OfferKeyEventL 00217 // Pass key events to the editor 00218 // ----------------------------------------------------------------------------- 00219 // 00220 TKeyResponse CTxtViewerAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent, 00221 TEventCode aType ) 00222 { 00223 // Redirect keyevents to controls 00224 if ( iEditor ) 00225 { 00226 return iEditor->OfferKeyEventL( aKeyEvent, aType ); 00227 } 00228 00229 return EKeyWasNotConsumed; 00230 } 00231 00232 00233 TMsvId CTxtViewerAppView::EntryId() 00234 { 00235 00236 // Get Id from the document 00237 CEikonEnv* env = CEikonEnv::Static(); 00238 00239 CTxtViewerAppUi* appui = static_cast<CTxtViewerAppUi*>(env->AppUi()); 00240 00241 CTxtViewerDocument* doc = appui->Document(); 00242 00243 return doc->Id(); 00244 00245 } 00246 00247 TBool CTxtViewerAppView::OpenedForEditing() 00248 { 00249 // Get Id from the document 00250 CEikonEnv* env = CEikonEnv::Static(); 00251 00252 CTxtViewerAppUi* appui = static_cast<CTxtViewerAppUi*>(env->AppUi()); 00253 00254 CTxtViewerDocument* doc = appui->Document(); 00255 00256 return doc->OpenedForEditing(); 00257 00258 } 00259 00260 00261 void CTxtViewerAppView::InitializeMTMsL() 00262 { 00263 00264 00265 // Create a session to the message server 00266 iSession = CMsvSession::OpenSyncL(iOb); 00267 //CleanupStack::PushL(session); 00268 00269 // Get ui and client registries 00270 iClientReg = CClientMtmRegistry::NewL(*iSession); 00271 00272 iUiReg = CMtmUiRegistry::NewL(*iSession); 00273 00274 // Check if that type is available otherwise leave 00275 if(!iClientReg->IsPresent(KUidMsgTypeText)) User::Leave(KErrNotFound); 00276 00277 // try to create ui mtm and client mtm instances 00278 iClientMtm = (CTextMtmClient*)iClientReg->NewMtmL(KUidMsgTypeText); 00279 00280 iUiMtm = (CTextMtmUi*)iUiReg->NewMtmUiL(*iClientMtm ); 00281 00282 TMsvId id= EntryId(); 00283 00284 // Switch context 00285 iClientMtm->SwitchCurrentEntryL(id); 00286 00287 // Set state to editing 00288 iStore=iClientMtm->Entry().EditStoreL(); 00289 00290 00291 // Create a body for the message if body is missing 00292 if (!iStore->HasBodyTextL()) 00293 { 00294 // Create CRichText object 00295 CRichText* body = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(), 00296 iEikonEnv->SystemCharFormatLayerL()); 00297 CleanupStack::PushL(body); 00298 00299 // Store CRichText in body 00300 iStore->StoreBodyTextL(*body); 00301 iStore->CommitL(); 00302 00303 CleanupStack::PopAndDestroy(); // body 00304 } 00305 00306 delete iStore; 00307 iStore=NULL; 00308 } 00309 00310 // ----------------------------------------------------------------------------- 00311 // CTxtViewerAppView::~CTxtViewerAppView() 00312 // Destructor. 00313 // ----------------------------------------------------------------------------- 00314 // 00315 CTxtViewerAppView::~CTxtViewerAppView() 00316 { 00317 delete iStore; 00318 delete iClientMtm; 00319 delete iUiMtm; 00320 delete iUiReg; 00321 delete iClientReg; 00322 delete iSession; 00323 00324 00325 } 00326 00327 // ----------------------------------------------------------------------------- 00328 // CTxtViewerAppView::Draw() 00329 // Draws the display. 00330 // ----------------------------------------------------------------------------- 00331 // 00332 void CTxtViewerAppView::Draw( const TRect& /*aRect*/ ) const 00333 { 00334 } 00335 00336 // ----------------------------------------------------------------------------- 00337 // CTxtViewerAppView::SizeChanged() 00338 // Called by framework when the view size is changed. 00339 // ----------------------------------------------------------------------------- 00340 // 00341 void CTxtViewerAppView::SizeChanged() 00342 { 00343 TRect rect; 00344 00345 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect ); 00346 00347 iEditor->SetRect( TRect( TPoint(0,0),rect.Size()) ); 00348 00349 DrawNow(); 00350 } 00351 00352 void CTxtViewerAppView::ExportToFileL( const TDes& aFileName ) 00353 { 00354 RFileWriteStream myFileWriteStream; 00355 00356 myFileWriteStream.Open( CCoeEnv::Static()->FsSession(), aFileName , EFileWrite ); 00357 00358 myFileWriteStream.PushL(); 00359 00360 // Get editor's CRichBox object 00361 CRichText* text = iEditor->RichText(); 00362 00363 text->ExternalizePlainTextL( myFileWriteStream ); 00364 00365 myFileWriteStream.CommitL(); 00366 00367 myFileWriteStream.Close(); 00368 00369 myFileWriteStream.Pop(); 00370 } 00371 // End of File
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.