00001
00002
00003
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>
00012
00013
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>
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
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
00052 CreateWindowL();
00053
00054
00055 InitComponentArrayL();
00056
00057
00058 iEditor = new(ELeave) CEikRichTextEditor;
00059
00060
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
00082 iEditor->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
00083 CEikScrollBarFrame::EOn );
00084
00085
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
00098 SetRect(rect);
00099
00100
00101 ActivateL();
00102
00103 InitializeMTMsL();
00104
00105 LoadBodyL();
00106 }
00107
00108
00109
00110
00111
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
00123
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
00136
00137
00138
00139 void CTxtViewerAppView::ConstructL( const TRect& )
00140 {
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 void CTxtViewerAppView::LoadBodyL()
00150 {
00151 TMsvId id= EntryId();
00152
00153
00154 iClientMtm->SwitchCurrentEntryL(id);
00155
00156
00157 iStore=iClientMtm->Entry().EditStoreL();
00158
00159
00160 CRichText* body = iEditor->RichText();
00161
00162
00163 iStore->RestoreBodyTextL(*body);
00164
00165
00166 delete iStore;
00167 iStore = NULL;
00168
00169 iEditor->HandleTextChangedL();
00170 }
00171
00172
00173
00174
00175
00176
00177 void CTxtViewerAppView::SaveBodyL()
00178 {
00179 TMsvId id= EntryId();
00180
00181
00182 iClientMtm->SwitchCurrentEntryL(id);
00183
00184
00185 iStore=iClientMtm->Entry().EditStoreL();
00186
00187
00188 CRichText* text = iEditor->RichText();
00189
00190
00191
00192
00193
00194
00195 iStore->StoreBodyTextL(*text);
00196
00197 iStore->CommitL();
00198
00199 delete iStore;
00200
00201 iStore=NULL;
00202 }
00203
00204
00205
00206
00207
00208
00209 CTxtViewerAppView::CTxtViewerAppView()
00210 {
00211
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 TKeyResponse CTxtViewerAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
00221 TEventCode aType )
00222 {
00223
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
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
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
00266 iSession = CMsvSession::OpenSyncL(iOb);
00267
00268
00269
00270 iClientReg = CClientMtmRegistry::NewL(*iSession);
00271
00272 iUiReg = CMtmUiRegistry::NewL(*iSession);
00273
00274
00275 if(!iClientReg->IsPresent(KUidMsgTypeText)) User::Leave(KErrNotFound);
00276
00277
00278 iClientMtm = (CTextMtmClient*)iClientReg->NewMtmL(KUidMsgTypeText);
00279
00280 iUiMtm = (CTextMtmUi*)iUiReg->NewMtmUiL(*iClientMtm );
00281
00282 TMsvId id= EntryId();
00283
00284
00285 iClientMtm->SwitchCurrentEntryL(id);
00286
00287
00288 iStore=iClientMtm->Entry().EditStoreL();
00289
00290
00291
00292 if (!iStore->HasBodyTextL())
00293 {
00294
00295 CRichText* body = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(),
00296 iEikonEnv->SystemCharFormatLayerL());
00297 CleanupStack::PushL(body);
00298
00299
00300 iStore->StoreBodyTextL(*body);
00301 iStore->CommitL();
00302
00303 CleanupStack::PopAndDestroy();
00304 }
00305
00306 delete iStore;
00307 iStore=NULL;
00308 }
00309
00310
00311
00312
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
00329
00330
00331
00332 void CTxtViewerAppView::Draw( const TRect& ) const
00333 {
00334 }
00335
00336
00337
00338
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
00361 CRichText* text = iEditor->RichText();
00362
00363 text->ExternalizePlainTextL( myFileWriteStream );
00364
00365 myFileWriteStream.CommitL();
00366
00367 myFileWriteStream.Close();
00368
00369 myFileWriteStream.Pop();
00370 }
00371