mobilemessaging/unieditor/application/src/UniEditorAppUi.cpp
changeset 0 72b543305e3a
child 1 d09ac5c1e252
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Provides Uni Editor App UI methods. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19  
       
    20 // ========== INCLUDE FILES ================================
       
    21 
       
    22 // Symbian OS
       
    23 #include <apmstd.h>                 // TDataType, KMaxDataTypeLength 
       
    24 #include <data_caging_path_literals.hrh> 
       
    25 #include <eiklbv.h>
       
    26 
       
    27 // Messaging
       
    28 #include <msvapi.h>
       
    29 #include <msvuids.h>                // Msgs Uids
       
    30 #include <msvstd.hrh>               // KUidMsvMessageEntryValue
       
    31 #include <mtmdef.h>                 // TMsvPartList
       
    32 #include <mtmuidef.hrh>             // EMtmUiFlagEditorPreferEmbedded
       
    33 #include <MtmExtendedCapabilities.hrh>  // function id of MessageInfo
       
    34 
       
    35 // Eikon
       
    36 #include <eikedwin.h>               // Editor TextLenght etc
       
    37 #include <eikrted.h>                // for CEikRichTextEditor
       
    38 #include <eikcolib.h>
       
    39 #include <DocumentHandler.h>
       
    40 
       
    41 // Avkon
       
    42 #include <aknenv.h>
       
    43 #include <aknnavi.h>
       
    44 #include <aknnavide.h>              // CAknNavigationDecorator
       
    45 #include <aknnavilabel.h>
       
    46 #include <aknEditStateIndicator.h> 
       
    47 #include <AknIndicatorContainer.h> 
       
    48 #include <akntitle.h>
       
    49 #include <aknclearer.h>
       
    50 #include <AknsConstants.h>
       
    51 #include <AknInfoPopupNoteController.h>
       
    52 #include <akninputblock.h>            // for CAknInputBlock
       
    53 #include <aknbutton.h>
       
    54 
       
    55 #include <aknlayoutscalable_apps.cdl.h>
       
    56 #include <aknlayoutscalable_avkon.cdl.h>
       
    57 
       
    58 #include <aknnotewrappers.h>        // CAknNoteWrappers
       
    59 #include <aknnotedialog.h>          // CAknNoteDialog
       
    60 #include <AknQueryDialog.h>         // CAknQueryDialog
       
    61 #include <AknWaitDialog.h>          // CAknWaitDialog
       
    62 #include <akncheckboxsettingpage.h>     // also CSelectionItemList and CSelectableItem
       
    63 #include <aknsettingpage.h>         // for Priority bit dialog
       
    64 #include <aknradiobuttonsettingpage.h>
       
    65 #include <akntoolbar.h>
       
    66 #include <akntoolbarextension.h>
       
    67 #include <AknIconArray.h>           // CAknIconArray
       
    68 #include <avkon.mbg>                // 
       
    69 #include <AknStatuspaneUtils.h>     // AknStatuspaneUtils
       
    70 #include <AknUtils.h>
       
    71 
       
    72 #include <AknFepGlobalEnums.h>              // Global Fep enums (ELatin, ENumber)
       
    73 #include <AknFepInternalCRKeys.h>
       
    74 
       
    75 // Misc
       
    76 #include <txtrich.h>                // for CRichText
       
    77 #include <badesca.h>                // CDesC16Array
       
    78 #include <barsread.h>               // TResReader
       
    79 
       
    80 // MUIU
       
    81 #include <MuiuOperationWait.h>      // CMuiuOperationWait
       
    82 #include <MuiuMsvUiServiceUtilities.h>  //Disk space check, offline check
       
    83 #include <muiumsvuiserviceutilitiesinternal.h> 
       
    84 
       
    85 #include <fileprotectionresolver.h>
       
    86 
       
    87 // Common components
       
    88 #include <StringLoader.h>           // for StringLoader (load and foramt strings from resources)
       
    89 #include <AiwGenericParam.h>        // CAiwGenericParamList
       
    90 
       
    91 // Base editor 
       
    92 #include <MsgRecipientItem.h>       // for CMsgRecipientItem
       
    93 #include <MsgAttachmentUtils.h>     // for MsgAttachmentUtils
       
    94 #include <MsgBaseControl.h>         // for CMsgBaseControl
       
    95 #include <MsgBodyControl.h>         // for CMsgBodyControl
       
    96 #include <MsgAddressControl.h>      // for CMsgAddressControl
       
    97 #include <MsgEditorView.h>          // for CMsgEditorView
       
    98 #include <MsgEditor.hrh>            // for TMsgIndicatorFlags
       
    99 #include <msgimagecontrol.h>        // for CMsgImageControl
       
   100 #include <MsgAttachmentModel.h>     // for CMsgAttachmentModel
       
   101 #include <MsgEditorCommon.h>
       
   102 
       
   103 #include <MsgEditorAppUiExtension.h>// for iMsgEditorAppUiExtension
       
   104 #include <MsgEditorSettingCacheUpdatePlugin.h>
       
   105 
       
   106 // MmsEngine
       
   107 #include <mmsgenutils.h>
       
   108 
       
   109 // Features
       
   110 #include <featmgr.h>    
       
   111 #include <messagingvariant.hrh>
       
   112 
       
   113 #include <centralrepository.h>    // link against centralrepository.lib
       
   114 #include <messaginginternalcrkeys.h> // for Central Repository keys
       
   115 #include <CoreApplicationUIsSDKCRKeys.h>
       
   116 
       
   117 #include <RCustomerServiceProfileCache.h>   // CSP bits
       
   118 
       
   119 // HELP
       
   120 #include <hlplch.h>
       
   121 #include <csxhelp/unif.hlp.hrh>
       
   122 
       
   123 // SMIL Player
       
   124 #include <MMediaFactoryFileInfo.h>
       
   125 #include <SmilPlayerDialog.h>
       
   126 
       
   127 // Other SMIL stuff
       
   128 #include <gmxmldocument.h>
       
   129 
       
   130 // MsgMedia
       
   131 #include <MsgMimeTypes.h>
       
   132 #include <MsgAudioInfo.h>
       
   133 #include <MsgVideoInfo.h>
       
   134 #include <MsgImageInfo.h>
       
   135 #include <MsgTextInfo.h>
       
   136 #include <MsgMediaResolver.h>
       
   137 #include <MsgMedia.hrh>
       
   138 #include <MmsConformance.h>
       
   139 
       
   140 // Resource identifiers
       
   141 #include <UniEditor.rsg>
       
   142 #include <MsgEditorAppUi.rsg>
       
   143 
       
   144 
       
   145 #include "UniSendingSettings.h"
       
   146 #include "UniPluginApi.h"
       
   147 #include "UniSmsPlugin.h"
       
   148 #include "UniClientMtm.h"
       
   149 
       
   150 /// UniEditor other component
       
   151 #include "uniutils.h"               // Object type flags, MBM filename
       
   152 #include <uniutils.mbg>  
       
   153 #include <unimsventry.h>          
       
   154 #include "unislideloader.h"
       
   155 #include "unidatautils.h"
       
   156 #include "uniobjectlist.h"
       
   157 #include "unidatamodel.h"             // CUniDataModel
       
   158 #include "unismilmodel.h"           // CUniSmilModel
       
   159 #include "unimodelconst.h"          // Uni constants
       
   160 #include "uniobjectsmodel.h"        // Model part of the objects view 
       
   161 #include "unitextobject.h"
       
   162 #include "unimimeinfo.h"
       
   163 #include "uniobjectsviewdialog.h"
       
   164 #include "unidrminfo.h"
       
   165 
       
   166 // This must be included after unidatamodel.h as both GMXMParserxxx and this define KNewLine
       
   167 #include <aknconsts.h>              // KAvkonBitmapFile
       
   168 
       
   169 // UniEditor application
       
   170 #include "UniEditorApp.h"           // To get app UID
       
   171 #include "UniEditorEnum.h"          // Panic codes
       
   172 #include "UniEditorApp.hrh"            // application specific commands
       
   173 #include "UniEditorAppUi.h"         // MmsEditorAppUi class
       
   174 #include "UniEditorHeader.h"
       
   175 #include "UniEditorChangeSlideOperation.h"
       
   176 #include "UniEditorInsertOperation.h"
       
   177 #include "UniEditorLaunchOperation.h"
       
   178 #include "UniEditorSaveOperation.h"
       
   179 #include "UniEditorSendOperation.h"
       
   180 #include "UniEditorVCardOperation.h"
       
   181 #include "UniEditorAddHeaderDialog.h"
       
   182 #include "UniSendingSettingsDialog.h"
       
   183 #include "UniEditorLogging.h"
       
   184 
       
   185 #include <gsmuelem.h>     // Turkish SMS-PREQ2265 specific
       
   186 // ========== LOCAL CONSTANTS AND MACROS ===================
       
   187 
       
   188 // SMS related
       
   189 
       
   190 // Character count used in unicode check buffer
       
   191 const TInt KUnicodeCheckChars = 10;
       
   192 
       
   193 // Downwards arrow with tip leftwards
       
   194 // This does not count as unconvertible character as it will be
       
   195 // replaced by paragraph separator or line feed by UI
       
   196 const TUint KSmsDownwardsArrowLeft = 0x21B2;
       
   197 
       
   198 const TInt  KSmsEdPDUInfoCalcReplaceCharacterCount = 2;
       
   199 const TUint KSmsEdUnicodeLFSupportedByBasicPhones = 0x000A;
       
   200 const TUint KSmsEnterCharacter = 0x2029;
       
   201 const TUint KSmsSpaceCharacter = 0x0020;
       
   202 // Unicode char codes for GSM 03.38 7 bit ext table characters 
       
   203 const TUint KUniEdEuroSymbol = 0x20ac;
       
   204 const TUint KUniEdLeftSquareBracket = 0x5b;
       
   205 const TUint KUniEdReverseSolidus = 0x5c;
       
   206 const TUint KUniEdRightSquareBracket = 0x5d;
       
   207 const TUint KUniEdCircumflexAccent = 0x5e;
       
   208 const TUint KUniEdLeftCurlyBracket = 0x7b;
       
   209 const TUint KUniEdVerticalLine = 0x7c;
       
   210 const TUint KUniEdRightCurlyBracket = 0x7d;
       
   211 const TUint KUniEdTilde = 0x7e;
       
   212 const TUid  KUniEditorAppId = { 0x102072D8 };
       
   213 
       
   214 // Amount of chars reserved for msg length and message count indication text
       
   215 const TInt KMsgLengthIndicationBuffer = 64;
       
   216 
       
   217 // Bytes. Estimated disk space needed in addition to filesize when file is created as an attachment.
       
   218 const TInt  KUniAttachmentOverhead          = 1024; 
       
   219 
       
   220 // Some functions determine and return the info note 
       
   221 // resource id at error situations. When not determined
       
   222 // this value is returned.  
       
   223 const TInt  KUniInvalidResourceId           = -1;   
       
   224 
       
   225 // Non-empty par tag + one media object takes ~90 bytes
       
   226 const TInt  KEmptySlideSize                 = 90;  
       
   227 
       
   228 // Kilobyte is 1024 not 1000 bytes 
       
   229 const TInt  KBytesInKilo                    = 1024; 
       
   230 
       
   231 // Kilobyte limit when to stop showing message size
       
   232 // with kilo accuracy 
       
   233 const TInt  KOneDigitLimit                  = 10;   
       
   234 
       
   235 // BodyText + subject, needed when counted the message size
       
   236 const TInt KUniEdNumberOfEditors            = 2; 
       
   237 
       
   238 // Extra length added to SMS length when there's subject
       
   239 const TInt KUniEdExtraLenCausedBySubject    = 2; 
       
   240 
       
   241 const TInt KUniEdMaxSubjectLen              = 40;
       
   242 
       
   243 // For creation of checkbox list
       
   244 _LIT(KItemStart, "1\t");                    
       
   245 
       
   246 // Exiting in launch. Let this time to show error notes
       
   247 const TInt  KDelayedExitShort = 100000;
       
   248 
       
   249 // ========== MODULE DATA STRUCTURES =======================
       
   250 
       
   251 // ========== LOCAL FUNCTION PROTOTYPES ====================
       
   252 
       
   253 // ========== LOCAL FUNCTIONS ==============================
       
   254 
       
   255 // ========== MEMBER FUNCTIONS ==============================
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CUniEditorAppUi::CUniEditorAppUi
       
   259 // C++ default constructor can NOT contain any code, that
       
   260 // might leave.
       
   261 // ---------------------------------------------------------
       
   262 //
       
   263 CUniEditorAppUi::CUniEditorAppUi() :   
       
   264     iDisplaySize( -1 ),
       
   265     iWaitResId( -1 ),
       
   266     iOriginalSlide( -1 ),
       
   267     iNextFocus( EMsgComponentIdNull ),
       
   268     iEditorFlags( EShowInfoPopups ),
       
   269     iMskResId( R_UNIEDITOR_OPTIONS_CLOSE )
       
   270     {
       
   271     }
       
   272     
       
   273 // ---------------------------------------------------------
       
   274 // CUniEditorAppUi::ConstructL
       
   275 // Second phase contructor
       
   276 // NOTE: Don't call here any function that uses iMtm 
       
   277 //       and/or iSmilModel members, because they are 
       
   278 //       initialized at LaunchViewL.
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 void CUniEditorAppUi::ConstructL()
       
   282     {
       
   283     // We don't have any app ui if launched from idle
       
   284     if ( iEikonEnv->EikAppUi() )
       
   285         {
       
   286         ActivateInputBlockerL( NULL );
       
   287         }
       
   288         
       
   289     CMsgEditorAppUi::ConstructL();
       
   290 
       
   291 	SetKeyEventFlags( EDisableSendKeyShort | EDisableSendKeyLong );
       
   292     SetCloseWithEndKey( ETrue );
       
   293     
       
   294     FeatureManager::InitializeLibL();
       
   295     
       
   296     // Get supported features from feature manager.    
       
   297     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   298         {
       
   299         iSupportedFeatures |= EUniFeatureHelp;
       
   300         }
       
   301     if ( FeatureManager::FeatureSupported( KFeatureIdOfflineMode ) )
       
   302         {
       
   303         iSupportedFeatures |= EUniFeatureOffline;
       
   304         }
       
   305     if ( FeatureManager::FeatureSupported( KFeatureIdDrmFull ) )
       
   306         {
       
   307         iSupportedFeatures |= EUniFeatureDrmFull;
       
   308         }
       
   309     if ( FeatureManager::FeatureSupported( KFeatureIdCamera ) )
       
   310         {
       
   311         iSupportedFeatures |= EUniFeatureCamcorder;
       
   312         }
       
   313     if ( FeatureManager::FeatureSupported( KFeatureIdJapanese ) )
       
   314         {
       
   315         iSupportedFeatures |= EUniFeatureJapanese;
       
   316         }
       
   317     //Turkish SMS-PREQ2265 specific
       
   318     if( FeatureManager::FeatureSupported( KFeatureIdNltSupport ) )
       
   319         {
       
   320         iNLTFeatureSupport = ETrue;
       
   321         }
       
   322     else
       
   323         {
       
   324         iNLTFeatureSupport = EFalse;
       
   325         }
       
   326     
       
   327     FeatureManager::UnInitializeLib();
       
   328 
       
   329     iMuiuSettRepository = CRepository::NewL( KCRUidMuiuSettings );
       
   330 
       
   331     TInt featureBitmask = 0;
       
   332     
       
   333     CRepository* repository = CRepository::NewL( KCRUidMuiuVariation );
       
   334     repository->Get( KMuiuMmsFeatures, featureBitmask );
       
   335     
       
   336     if ( featureBitmask & KMmsFeatureIdEditorSubjectField )
       
   337         {
       
   338         iSupportedFeatures |= EUniFeatureSubject;
       
   339         }
       
   340         
       
   341     if ( featureBitmask & KMmsFeatureIdPrioritySupport )
       
   342         {
       
   343         iSupportedFeatures |= EUniFeaturePriority;
       
   344         }    
       
   345     
       
   346     iInputTxtLangRepository = CRepository::NewL(  KCRUidAknFep   );     
       
   347     iNotifyHandler = CCenRepNotifyHandler::NewL( *this,
       
   348                                                  *iInputTxtLangRepository,                                                 
       
   349                                                  CCenRepNotifyHandler::EIntKey,
       
   350                                                  KAknFepInputTxtLang );
       
   351     featureBitmask = 0;    
       
   352     repository->Get( KMuiuUniEditorFeatures, featureBitmask );
       
   353     
       
   354     if ( featureBitmask & KUniEditorFeatureIdHideMsgTypeChangedPopup )
       
   355         {
       
   356         iEditorFlags &= ~EShowInfoPopups;
       
   357         }    
       
   358         
       
   359     if ( featureBitmask & KUniEditorFeatureIdHideSizeCounter )
       
   360         {
       
   361         iEditorFlags |= EHideSizeCounter;
       
   362         }    
       
   363     if ( featureBitmask & KUniEditorFeatureIdHideMessageTypeOption )
       
   364 		{
       
   365 		iEditorFlags |= EHideMessageTypeOption;
       
   366 		}     
       
   367     repository->Get( KMuiuSmsFeatures, featureBitmask );
       
   368     
       
   369     if ( featureBitmask & KSmsFeatureIdShowConcatenatedQuery )
       
   370         {
       
   371         iEditorFlags |= EShowSmsSentInManyParts;
       
   372         }  
       
   373        
       
   374     delete repository;  
       
   375     
       
   376     iNotifyHandler->StartListeningL();    
       
   377     // Disable task swapper from options menu during launch
       
   378     MenuBar()->SetMenuType( CEikMenuBar::EMenuOptionsNoTaskSwapper );
       
   379     
       
   380     iTitleSms = StringLoader::LoadL( R_UNIEDITOR_TITLE_SMS, iCoeEnv );    
       
   381     iTitleMms = StringLoader::LoadL( R_UNIEDITOR_TITLE_MMS, iCoeEnv );    
       
   382     
       
   383     // Load msg length format string from resource
       
   384     iSmsLengthFormatBuffer = StringLoader::LoadL( R_UNIEDITOR_SMS_LENGTH, iCoeEnv );
       
   385     iMmsLengthFormatBuffer = StringLoader::LoadL( R_UNIEDITOR_MMS_LENGTH, iCoeEnv );
       
   386 
       
   387     CEikStatusPane* statusPane = StatusPane();
       
   388     
       
   389     // Set generic title text as message type is not known yet.
       
   390     HBufC* titleString = StringLoader::LoadLC( R_UNIEDITOR_TITLE, iCoeEnv );    
       
   391         
       
   392     iTitlePane = static_cast<CAknTitlePane*>( statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   393     iTitlePane->SetTextL( titleString->Des(), ETrue );
       
   394     
       
   395     CleanupStack::PopAndDestroy( titleString );
       
   396     
       
   397     iNaviPane = static_cast<CAknNavigationControlContainer*>( statusPane->ControlL( 
       
   398                                                                 TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   399     
       
   400     iNaviDecorator = iNaviPane->CreateEditorIndicatorContainerL();
       
   401     
       
   402     TParse fileParse;
       
   403     fileParse.Set( KUniUtilsMBMFileName, &KDC_APP_BITMAP_DIR, NULL );
       
   404 
       
   405     iIconSms = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   406                                           KAknsIIDQgnPropMceSmsTitle,
       
   407                                           fileParse.FullName(),
       
   408                                           EMbmUniutilsQgn_prop_mce_sms_title,
       
   409                                           EMbmUniutilsQgn_prop_mce_sms_title_mask );
       
   410 
       
   411     iIconMms = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   412                                           KAknsIIDQgnPropMceMmsTitle,
       
   413                                           fileParse.FullName(),
       
   414                                           EMbmUniutilsQgn_prop_mce_mms_title,
       
   415                                           EMbmUniutilsQgn_prop_mce_mms_title_mask );
       
   416     
       
   417     SetTitleIconsSizeL();
       
   418     
       
   419     if ( Document()->CreationMode() == EMmsCreationModeWarning )
       
   420         {
       
   421         iEditorFlags |= EShowGuidedConf;
       
   422         }
       
   423         
       
   424     // Prepare to launch msgeditorview to display the message
       
   425     if ( !iEikonEnv->StartedAsServerApp() )
       
   426         {
       
   427         Document()->PrepareToLaunchL( this );
       
   428         }
       
   429 
       
   430     iScreenClearer = CAknLocalScreenClearer::NewLC( ETrue );
       
   431     CleanupStack::Pop( iScreenClearer );        
       
   432 	CreateFixedToolbarL( ETrue);
       
   433     
       
   434     // Priority must be lower than the priority of iWrappedWaitDialog
       
   435     // Constructed here to ensure exit on low memory situations.
       
   436     iIdle = CPeriodic::NewL( EPriorityNormal - 1 );
       
   437     
       
   438 #ifdef RD_SCALABLE_UI_V2
       
   439     if ( AknLayoutUtils::PenEnabled() )
       
   440         {
       
   441             User::LeaveIfError( iPeninputServer.Connect() );
       
   442             iPeninputServer.AddPenUiActivationHandler( this, EPluginInputModeAll );
       
   443             iPrevSmsLength = -1;    
       
   444             iMsgLenToVKB = ETrue; 
       
   445         }
       
   446 #endif
       
   447     }
       
   448 
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CUniEditorAppUi::~CUniEditorAppUi
       
   452 // Destructor
       
   453 // ---------------------------------------------------------
       
   454 //
       
   455 CUniEditorAppUi::~CUniEditorAppUi()
       
   456     {
       
   457     iEditorFlags |= EEditorExiting;
       
   458     
       
   459     if ( iView )
       
   460         {
       
   461         // To prevent focus changes caused by input blocker deletion & toolbar extension
       
   462         // closing.
       
   463         iEikonEnv->EikAppUi()->RemoveFromStack( iView );
       
   464         
       
   465         if ( iEditorFlags & ELaunchSuccessful )
       
   466             {    
       
   467             TInt id( EMsgComponentIdNull );
       
   468             
       
   469             // remember input mode:
       
   470             // observer does not get event, if editor is closed 
       
   471             CMsgBaseControl* ctrl = iView->FocusedControl();  // ctrl can be NULL.
       
   472             if ( ctrl )
       
   473                 {
       
   474                 id = ctrl->ControlId();
       
   475                 if ( iHeader &&  
       
   476                      !iHeader->IsAddressControl( id ) )
       
   477                     {
       
   478                     id = EMsgComponentIdNull;
       
   479                     }
       
   480                 }
       
   481                 
       
   482             if ( id == EMsgComponentIdNull )
       
   483                 { 
       
   484                 id = EMsgComponentIdTo;
       
   485                 }
       
   486             
       
   487             CUniBaseHeader::THeaderFields headerField = CUniBaseHeader::EHeaderAddressTo;
       
   488             
       
   489             if ( id == EMsgComponentIdCc )
       
   490                 {
       
   491                 headerField = CUniBaseHeader::EHeaderAddressCc;
       
   492                 }
       
   493             else if ( id == EMsgComponentIdBcc )
       
   494                 {
       
   495                 headerField = CUniBaseHeader::EHeaderAddressBcc;
       
   496                 }
       
   497             
       
   498             CMsgAddressControl* rec = 
       
   499                 iHeader ? static_cast<CMsgAddressControl*>( iHeader->AddressControl( headerField ) ) :
       
   500                         NULL;
       
   501 
       
   502             if ( rec ) 
       
   503                 {
       
   504                 TInt inputMode = rec->Editor().AknEditorCurrentInputMode();
       
   505                 
       
   506                 if ( iMuiuSettRepository )
       
   507                     {
       
   508                     iMuiuSettRepository->Set( KMuiuToInputMode, inputMode );
       
   509                     }
       
   510                 }
       
   511             }
       
   512         }
       
   513     
       
   514     delete iLaunchOperation;
       
   515     delete iSaveOperation;
       
   516     delete iSendOperation;
       
   517     delete iInsertOperation;
       
   518     delete iChangeSlideOperation;
       
   519     delete iVCardOperation;
       
   520     
       
   521     delete iParser;
       
   522     delete iDom;
       
   523     
       
   524     delete iInputBlocker;
       
   525 
       
   526 #ifdef RD_SCALABLE_UI_V2
       
   527     if ( AknLayoutUtils::PenEnabled() )
       
   528          {
       
   529           iPeninputServer.Close();
       
   530          }
       
   531 #endif
       
   532     
       
   533     delete iTitleSms;
       
   534     delete iTitleMms;
       
   535 
       
   536     delete iIconSms;
       
   537     delete iIconMms;
       
   538     
       
   539     delete iSmsLengthFormatBuffer;
       
   540     delete iMmsLengthFormatBuffer;
       
   541     
       
   542     delete iPopupNote;
       
   543     delete iPopupChangedMmsBuffer;
       
   544     delete iPopupChangedSmsBuffer;
       
   545     
       
   546     delete iMuiuSettRepository;
       
   547 
       
   548     delete iWaitDialog;
       
   549     delete iIdle;
       
   550 
       
   551     delete iInsertingMedia;
       
   552     delete iHeader;
       
   553     delete iSlideLoader;
       
   554     delete iScreenClearer;
       
   555 
       
   556     delete iDocHandler;
       
   557     delete iStoredBodyControl;
       
   558     
       
   559     delete iFixedToolbar;
       
   560     if( iNotifyHandler )
       
   561         {
       
   562          iNotifyHandler->StopListening();         
       
   563           delete iNotifyHandler;
       
   564          }
       
   565     
       
   566    if(iInputTxtLangRepository)
       
   567     {
       
   568     delete iInputTxtLangRepository;
       
   569     }
       
   570   if(iNLTFeatureSupport)
       
   571     {   
       
   572     delete iPrevBuffer;
       
   573     }
       
   574 
       
   575     delete iPopupSmsSizeAboveLimitBuffer;
       
   576     delete iPopupSmsSizeBelowLimitBuffer;
       
   577    
       
   578     }
       
   579 
       
   580 // ---------------------------------------------------------
       
   581 // CUniEditorAppUi::LaunchViewL
       
   582 //
       
   583 // Called by the document when application view launch should be
       
   584 // started.
       
   585 // ---------------------------------------------------------
       
   586 //
       
   587 void CUniEditorAppUi::LaunchViewL()
       
   588     {
       
   589 
       
   590     // Initialize these members here.
       
   591     iMtm = &( Document()->Mtm() );
       
   592 
       
   593     const TMsvEntry& entry = Document()->Entry();
       
   594     if ( entry.iType.iUid != KUidMsvMessageEntryValue )
       
   595         {
       
   596         // Fixing: JHUA-5SCF8W
       
   597         // Backup / Restore restarts editor without proper
       
   598         // context. Leave with KErrGeneral.
       
   599         User::Leave( KErrGeneral );
       
   600         }
       
   601         
       
   602     if ( entry.Parent() != KMsvDraftEntryIdValue )
       
   603         {
       
   604         User::Leave( KErrNotSupported );
       
   605         }
       
   606     if ( !( Document()->LaunchFlags() & EMsgCreateNewMessage ) )
       
   607         {
       
   608         TRAPD( error, iMtm->LoadMessageL() );
       
   609         if ( error )
       
   610             {
       
   611             if ( error != KErrNoMemory &&
       
   612                  error != KErrDiskFull )
       
   613                 {
       
   614                 ShowErrorNoteL( R_UNIEDITOR_ERROR_MSG_CORRUPT, ETrue );
       
   615                 }
       
   616             User::Leave( error );
       
   617             }
       
   618         }    
       
   619     
       
   620     Document()->SetMessageType();
       
   621 
       
   622     if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
   623         {
       
   624         Document()->SetCreationMode( EMmsCreationModeFree );
       
   625         
       
   626         if ( iFixedToolbar )
       
   627             {
       
   628             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarAddRecipient, ETrue, EFalse );
       
   629             }
       
   630         }
       
   631     
       
   632     iView = CMsgEditorView::NewL( *this, CMsgEditorView::EMsgDoNotUseDefaultBodyControl );
       
   633     iView->SetEdwinObserverL( this );
       
   634     
       
   635 
       
   636     iLaunchOperation = CUniEditorLaunchOperation::NewL( *this,
       
   637                                                         *this,
       
   638                                                         *Document(),
       
   639                                                         *iView,
       
   640                                                         *this,
       
   641                                                         FsSession() );
       
   642 
       
   643     iLaunchOperation->Launch();
       
   644     }
       
   645 
       
   646 // ---------------------------------------------------------
       
   647 // CUniEditorAppUi::FinalizeLaunchL
       
   648 //
       
   649 // Performs all the last actions before editor launch ends.
       
   650 // ---------------------------------------------------------
       
   651 //
       
   652 void CUniEditorAppUi::FinalizeLaunchL()
       
   653     {
       
   654     iSmilModel = &Document()->DataModel()->SmilModel();
       
   655     iHeader = iLaunchOperation->DetachHeader();
       
   656     iSlideLoader = iLaunchOperation->DetachSlideLoader();
       
   657     
       
   658     SetMessageTypeLockingL();
       
   659     
       
   660     TInt headersVariation = iHeader->AddHeadersVariation();
       
   661 
       
   662     if ( Document()->EmailOverSmsSupported() ||
       
   663          ( headersVariation & EUniFeatureSubject && 
       
   664            !( headersVariation & EUniFeatureSubjectConfigurable ) ) )
       
   665         { 
       
   666         // Enable subject in SMS when it's not selectable in additional headers
       
   667         // and when EmailOverSms is supported
       
   668         iEditorFlags |= ESubjectOkInSms;
       
   669         }
       
   670     
       
   671     SetAddressSize();
       
   672     SetSubjectSize();
       
   673     
       
   674     // "Remember input mode" feature
       
   675     TInt inputMode = EAknEditorNumericInputMode;
       
   676     if ( iMuiuSettRepository->Get( KMuiuToInputMode, inputMode ) != KErrNone )
       
   677         {
       
   678         inputMode = EAknEditorNumericInputMode;
       
   679         }
       
   680 
       
   681     SetInputModeToAddressFields( inputMode );
       
   682     
       
   683     CheckLockedSmsWithAttaL();
       
   684     
       
   685     if ( iSupportedFeatures & EUniFeatureJapanese &&
       
   686          Document()->MessageType() != EUniForward )
       
   687         {
       
   688         // Image first layout is always used in Japanese variant when dealing
       
   689         // with any other messages than those that where originally forwarded by user.
       
   690         // With forwarded messages the original layout is kept unchanged.
       
   691         ChangeOrderL( EUniImageFirst );
       
   692         iSmilModel->SetLayoutL( EUniImageFirst );
       
   693         }
       
   694     
       
   695     TMsgControlId focusedControlId = ResolveLaunchFocusedControlL();
       
   696             
       
   697     iView->ExecuteL( ClientRect(), focusedControlId );
       
   698   
       
   699     delete iScreenClearer;
       
   700     iScreenClearer = NULL;
       
   701     
       
   702     CEikStatusPane* statusPane = StatusPane();
       
   703     
       
   704     if ( focusedControlId == EMsgComponentIdBody )
       
   705         {
       
   706         BodyCtrl()->SetCursorPosL( BodyCtrlEditor()->TextLength() );
       
   707         }
       
   708     
       
   709     if( iNLTFeatureSupport )
       
   710         {
       
   711         iPrevBuffer = NULL;
       
   712         //Turskish SMS-PREQ2265 specific
       
   713         TSmsEncoding alternateEncodingType;
       
   714         TUniMessageCharSetSupport charSet;
       
   715         TInt inputLang = iAvkonEnv->SettingCache().InputLanguage();
       
   716         CUniEditorDocument* doc = Document();
       
   717         
       
   718         alternateEncodingType = doc->GetLanguageSpecificAltEncodingType(inputLang);
       
   719         charSet = doc->CharSetSupport();
       
   720         
       
   721         doc->SetAlternativeEncodingType(alternateEncodingType);
       
   722         if(SmsPlugin())
       
   723             {
       
   724             //Initialize corresponding language alternative encoding types and character set selected
       
   725             SmsPlugin()->SetEncodingSettings(EFalse, alternateEncodingType, charSet);
       
   726             }
       
   727         }
       
   728     
       
   729     CheckBodyForMessageTypeL();
       
   730     CheckHeaderForMessageTypeL();
       
   731     
       
   732     SetOrRemoveMaxSizeInEdwin();
       
   733     
       
   734     InitNaviPaneL();
       
   735     SetTitleL();
       
   736     if ( Document()->MessageType() == EUniSendUi )
       
   737         {
       
   738         // Show invalid contact notes and verify unvalidated addresses.
       
   739         iHeader->ShowInvalidContactNotesL();
       
   740         
       
   741         TBool unused;
       
   742         VerifyAddressesL( unused );
       
   743         }
       
   744         
       
   745     if ( iEditorFlags & EShowInfoPopups )
       
   746         {
       
   747         iPopupNote = CAknInfoPopupNoteController::NewL();
       
   748         iPopupNote->SetTimeDelayBeforeShow( 0 );
       
   749         iPopupNote->SetTimePopupInView( 3000 );
       
   750 
       
   751         iPopupChangedMmsBuffer = StringLoader::LoadL( R_UNIEDITOR_POPUP_MSG_CHANGED_MMS, iCoeEnv );
       
   752         iPopupChangedSmsBuffer = StringLoader::LoadL( R_UNIEDITOR_POPUP_MSG_CHANGED_SMS, iCoeEnv );
       
   753 
       
   754         //Korean Req: 415-5434        
       
   755         iPopupSmsSizeAboveLimitBuffer = StringLoader::LoadL( R_UNIEDITOR_POPUP_SMS_SIZE_ABOVE_LIMIT, Document()->SmsSizeWarningBytes(), iCoeEnv );
       
   756         iPopupSmsSizeBelowLimitBuffer = StringLoader::LoadL( R_UNIEDITOR_POPUP_SMS_SIZE_UNDER_LIMIT, Document()->SmsSizeWarningBytes(), iCoeEnv );
       
   757 
       
   758         }
       
   759 
       
   760     CheckMaxRecipientsAndShowNoteL();
       
   761     
       
   762     // Enable task swapper to options menu after launch has been completed.
       
   763     MenuBar()->SetMenuType( CEikMenuBar::EMenuOptions );
       
   764     
       
   765     UpdateToolbarL();
       
   766     
       
   767     iEditorFlags |= ELaunchSuccessful;
       
   768     }
       
   769     
       
   770 // ---------------------------------------------------------
       
   771 // CUniEditorAppUi::ShowLaunchNotesL
       
   772 //
       
   773 // Tries to resolve correct note(s) to be shown when editor is
       
   774 // launched. First disables showing of guided conformance note if
       
   775 // message is forwarded with non-conformant content as viewer should
       
   776 // be responsible of showing this. After this goes through 
       
   777 // error list and sets correct error resource depending of 
       
   778 // editor mode and message content. Priority & plural solving
       
   779 // is performed on SetErrorResource function. Some notes can
       
   780 // be grouped together so that if error notes from different
       
   781 // groups are set then general error note should be shown instead.
       
   782 // After correct error note resource is resolved then notes 
       
   783 // related to conformance are shown. Do note that there is 
       
   784 // a EShowGuidedConf flag that controls the visibility of guided
       
   785 // note. After this if still appropriate and specified
       
   786 // error note is shown to user.
       
   787 // ---------------------------------------------------------
       
   788 //
       
   789 void CUniEditorAppUi::ShowLaunchNotesL( TBool& aShutDown )
       
   790     {
       
   791     TInt errRes( KErrNotFound );
       
   792     
       
   793     if ( Document()->LaunchFlags() & EMsgForwardMessage &&
       
   794          ( Document()->UpdatedNonConformantCount() > 0 || 
       
   795            Document()->DataModel()->SmilType() == ETemplateSmil ||
       
   796            Document()->DataModel()->SmilType() == E3GPPSmil ) )
       
   797         {
       
   798         iEditorFlags &= ~EShowGuidedConf;
       
   799         }
       
   800     
       
   801     // Tells whether message has files included.
       
   802     TBool containsFiles = Document()->DataModel()->ObjectList().Count() > 0 || 
       
   803                           Document()->DataModel()->AttachmentList().Count() > 0;
       
   804     
       
   805     TBool useRModeStrings = Document()->CreationModeUserChangeable() &&
       
   806                             Document()->CreationMode() == EMmsCreationModeRestricted;
       
   807     
       
   808     CArrayFixFlat<TInt>* errors = iLaunchOperation->GetErrors();
       
   809     
       
   810     if ( Document()->DataModel()->ParseResult() & EObjectRemoved )
       
   811         {
       
   812         SetErrorResource( errRes, R_UNIEDITOR_INFO_MAX_SLIDES_SOME );
       
   813         }
       
   814     
       
   815     for ( TInt i = 0; i < errors->Count(); i++ )
       
   816         {
       
   817         switch ( errors->At( i ) )
       
   818             {
       
   819             case KUniLaunchAbortPresRestricted:
       
   820                 {
       
   821                 // Set only for 3GPP or template SMIL presentations when creation
       
   822                 // mode is restricted.
       
   823                 if ( useRModeStrings )
       
   824                     {
       
   825                     SetErrorResource( errRes, R_UNIEDITOR_ERROR_RMODE_CANNOT_OPEN );
       
   826                     }
       
   827                 else
       
   828                     {
       
   829                     SetErrorResource( errRes, R_UNIEDITOR_ERROR_CANNOT_OPEN );
       
   830                     }
       
   831                     
       
   832                 break;
       
   833                 }
       
   834             case KUniLaunchPresGuided:
       
   835                 {
       
   836                 // Set only for 3GPP or template SMIL presentations when creation
       
   837                 // mode is guided.
       
   838                 SetErrorResource( errRes, R_UNIEDITOR_QUEST_GUIDED_PRESENTATION );
       
   839                 break;
       
   840                 }
       
   841             case EUniProcessImgOutOfMemory:
       
   842             case EUniProcessImgOutOfDisk:
       
   843             case EUniProcessImgNotFound:
       
   844             case EUniProcessImgNonConformant:
       
   845             case EUniProcessImgScalingFailed:
       
   846             case EUniProcessImgCompressFailed:
       
   847             case EUniProcessImgCouldNotScale:
       
   848                 {                
       
   849                 if ( useRModeStrings )
       
   850                     {
       
   851                     SetErrorResource( errRes, R_UNIEDITOR_INFO_RMODE_SCALING_FAILED );
       
   852                     }
       
   853                 else
       
   854                     {
       
   855                     SetErrorResource( errRes, R_UNIEDITOR_INFO_SCALING_FAILED );
       
   856                     }    
       
   857                 break;
       
   858                 }
       
   859             case EUniSendUiUnsupported:
       
   860                 {                
       
   861                 if ( containsFiles )
       
   862                     {
       
   863                     if ( useRModeStrings )
       
   864                         {
       
   865                         SetErrorResource( errRes, R_UNIEDITOR_INFO_RMODE_SOME_NOT_SUPPORTED );
       
   866                         }
       
   867                     else
       
   868                         {
       
   869                         SetErrorResource( errRes, R_UNIEDITOR_INFO_SOME_NOT_SUPPORTED );
       
   870                         }   
       
   871                     }
       
   872                 else
       
   873                     {
       
   874                     if ( useRModeStrings )
       
   875                         {
       
   876                         SetErrorResource( errRes, R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT );
       
   877                         }
       
   878                     else
       
   879                         {
       
   880                         SetErrorResource( errRes, R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT );
       
   881                         }   
       
   882                     }
       
   883                 break;
       
   884                 }
       
   885             case EUniSendUiForbidden:
       
   886                 {
       
   887                 // Note showing should be handled by SendUI in this case.
       
   888                 break;
       
   889                 }
       
   890             case EUniSendUiTooBig:
       
   891                 {
       
   892                 if ( containsFiles )
       
   893                     {
       
   894                     SetErrorResource( errRes, R_UNIEDITOR_INFO_OBJECT_SEND_AS_TOO_BIG );
       
   895                     }
       
   896                 else
       
   897                     {
       
   898                     SetErrorResource( errRes, R_UNIEDITOR_INFO_OBJECT_TOO_BIG );
       
   899                     }
       
   900                     
       
   901                 break;
       
   902                 }
       
   903             case EUniEditorExit:
       
   904             case EUniProcessImgUserAbort:
       
   905                 {
       
   906                 // Program error or user has selected to abort image processing at some stage.
       
   907                 // -> shutdown immediatelly.
       
   908                 aShutDown = ETrue;  
       
   909                 return;
       
   910                 }
       
   911             default:
       
   912                 {
       
   913                 // e.g leave in startup 
       
   914                 break;
       
   915                 }
       
   916             }
       
   917         }
       
   918         
       
   919     if ( errRes == R_UNIEDITOR_ERROR_CANNOT_OPEN ||
       
   920          errRes == R_UNIEDITOR_ERROR_RMODE_CANNOT_OPEN )
       
   921         {
       
   922         // Message cannot be opened.
       
   923         ShowConfirmableInfoL( errRes );
       
   924         
       
   925         aShutDown = ETrue;
       
   926         return;
       
   927         }   
       
   928     else if ( errRes == R_UNIEDITOR_INFO_OBJECT_TOO_BIG ||
       
   929               errRes == R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT ||
       
   930               errRes == R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECTS ||
       
   931               errRes == R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT ||
       
   932               errRes == R_UNIEDITOR_INFO_UNSUPPORTED_OBJECTS )
       
   933         {
       
   934         ShowInformationNoteL( errRes, ETrue );
       
   935         
       
   936         aShutDown = ETrue;
       
   937         return;
       
   938         }
       
   939     else if ( errRes == R_UNIEDITOR_INFO_OBJECT_SEND_AS_TOO_BIG || 
       
   940               errRes == R_UNIEDITOR_INFO_RMODE_SOME_NOT_SUPPORTED ||
       
   941               errRes == R_UNIEDITOR_INFO_SOME_NOT_SUPPORTED )
       
   942         {
       
   943         ShowInformationNoteL( errRes, ETrue );
       
   944         }
       
   945     else if ( errRes == R_UNIEDITOR_INFO_MAX_SLIDES_SOME )
       
   946         {
       
   947         ShowConfirmableInfoL( errRes );
       
   948         }
       
   949     
       
   950     if ( errRes == R_UNIEDITOR_QUEST_GUIDED_PRESENTATION )
       
   951         {
       
   952         if ( !ShowGuidedModeConfirmationQueryL( errRes ) ) 
       
   953             {
       
   954             aShutDown = ETrue;
       
   955             }
       
   956         }
       
   957     else
       
   958         {
       
   959         if ( Document()->CreationMode() != EMmsCreationModeFree )
       
   960             {
       
   961             TInt nonConformantObjects = iLaunchOperation->ParseResult();
       
   962             
       
   963             if ( nonConformantObjects > 0 )
       
   964                 {
       
   965                 if ( Document()->CreationMode() == EMmsCreationModeRestricted )
       
   966                     {
       
   967                     if ( Document()->CreationModeUserChangeable() )
       
   968                         {
       
   969                         ShowConfirmableInfoL( R_UNIEDITOR_ERROR_RMODE_CANNOT_OPEN );
       
   970                         }
       
   971                     else
       
   972                         {
       
   973                         ShowConfirmableInfoL( R_UNIEDITOR_ERROR_CANNOT_OPEN );
       
   974                         }
       
   975                         
       
   976                     aShutDown = ETrue;
       
   977                     return;
       
   978                     }
       
   979                 else if ( Document()->SuperDistributableObjectCount() == 0 ||  
       
   980                           Document()->MessageType() != EUniSendUi )
       
   981                     {
       
   982                     // Not shown if DRM note has been shown already by SendUi.
       
   983                     TInt confRes( KErrNotFound );
       
   984                     
       
   985                     if ( Document()->Saved() )
       
   986                         {
       
   987                         confRes = R_UNIEDITOR_QUEST_GUIDED_INC_OBJ;
       
   988                         if ( nonConformantObjects > 1 )
       
   989                             {
       
   990                             confRes = R_UNIEDITOR_QUEST_GUIDED_INC_OBJS;
       
   991                             }
       
   992                         }
       
   993                     else
       
   994                         {
       
   995                         confRes = R_UNIEDITOR_QUEST_GUIDED_OBJ;
       
   996                         if ( nonConformantObjects > 1 )
       
   997                             {
       
   998                             confRes = R_UNIEDITOR_QUEST_GUIDED_OBJS;
       
   999                             }
       
  1000                         }
       
  1001                     
       
  1002                     if ( !ShowGuidedModeConfirmationQueryL( confRes ) ) 
       
  1003                         {
       
  1004                         // Query not accepted
       
  1005                         aShutDown = ETrue;
       
  1006                         return;
       
  1007                         }
       
  1008                     }
       
  1009                 }
       
  1010             }
       
  1011         }
       
  1012         
       
  1013     if ( errRes == R_UNIEDITOR_INFO_RMODE_SCALING_FAILED ||
       
  1014          errRes == R_UNIEDITOR_INFO_SCALING_FAILED )
       
  1015         {
       
  1016         ShowInformationNoteL( errRes, ETrue );
       
  1017         }
       
  1018     }
       
  1019 
       
  1020 // ---------------------------------------------------------
       
  1021 // CUniEditorAppUi::InsertPresentation
       
  1022 // ---------------------------------------------------------
       
  1023 //
       
  1024 void CUniEditorAppUi::InsertPresentationL( TBool aEditable )
       
  1025     {
       
  1026     if ( Document()->DataModel()->SmilType() != EMmsSmil )
       
  1027         {
       
  1028         //Delete body control. OK if dooesn't exist.
       
  1029         iView->DeleteControlL( EMsgComponentIdBody );
       
  1030         
       
  1031         CMsgImageControl* imgCtrl = CMsgImageControl::NewL( *iView,
       
  1032                                                             this );
       
  1033         CleanupStack::PushL( imgCtrl );
       
  1034         
       
  1035         TAknsItemID id = KAknsIIDQgnGrafMmsUnedit;
       
  1036         TInt icon = EMbmUniutilsQgn_graf_mms_unedit;
       
  1037         TInt mask = EMbmUniutilsQgn_graf_mms_unedit_mask;
       
  1038 
       
  1039         if ( aEditable )
       
  1040             {
       
  1041             id.Set( KAknsIIDQgnGrafMmsEdit );
       
  1042             icon = EMbmUniutilsQgn_graf_mms_edit;
       
  1043             mask = EMbmUniutilsQgn_graf_mms_edit_mask;
       
  1044             }
       
  1045 
       
  1046         TParse fileParse;
       
  1047         fileParse.Set( KUniUtilsMBMFileName, &KDC_APP_BITMAP_DIR, NULL );
       
  1048         imgCtrl->LoadIconL( fileParse.FullName(), id, icon, mask );
       
  1049         
       
  1050         TAknLayoutRect iconLayout;
       
  1051         iconLayout.LayoutRect( MsgEditorCommons::MsgDataPane(),
       
  1052                                AknLayoutScalable_Apps::msg_data_pane_g4().LayoutLine() );
       
  1053         
       
  1054         imgCtrl->SetIconSizeL( iconLayout.Rect().Size() );
       
  1055         
       
  1056         //Draw it
       
  1057         imgCtrl->SetIconVisible( ETrue );
       
  1058         iView->AddControlL( imgCtrl, EMsgComponentIdImage, EMsgFirstControl, EMsgBody );
       
  1059 
       
  1060         CleanupStack::Pop( imgCtrl );
       
  1061         }
       
  1062     else
       
  1063         {
       
  1064         User::Leave( KErrNotSupported );
       
  1065         }
       
  1066     }
       
  1067 
       
  1068 // ---------------------------------------------------------
       
  1069 // CUniEditorAppUi::MsgLengthToNavipaneL
       
  1070 // ---------------------------------------------------------
       
  1071 //
       
  1072 void CUniEditorAppUi::MsgLengthToNavipaneL( TBool aForceDraw )
       
  1073     {
       
  1074     UNILOGGER_WRITE( "-> CUniEditorAppUi::MsgLengthToNavipaneL" );
       
  1075     
       
  1076     TBuf<KMsgLengthIndicationBuffer> sizeString;
       
  1077 
       
  1078     // If message is SMS type, iSmsBodyLength + iSmsSubjectLnegth will be used as length
       
  1079     // If EUnicodeMode is set, they will be handled as unicode length
       
  1080     if ( !( iEditorFlags & EHideSizeCounter ) )
       
  1081         { 
       
  1082         CUniEditorDocument* doc = Document();
       
  1083         
       
  1084         // It's ok to show the counter
       
  1085         if ( doc->UniState() == EUniSms )
       
  1086             {
       
  1087            
       
  1088             CUniDataModel* model = doc->DataModel();           
       
  1089                        
       
  1090          
       
  1091                 TInt charsLeft,msgsParts;
       
  1092                 TInt lengthOne = 0;
       
  1093                 TInt lengthMany = 0;
       
  1094                 
       
  1095                 doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  1096                 TInt maxSmsCharacters = doc->AbsoluteMaxSmsCharacters();
       
  1097                 TInt maxSmsParts = doc->AbsoluteMaxSmsParts();
       
  1098                  
       
  1099                 if ( maxSmsCharacters <= 0 )
       
  1100                     {
       
  1101                     // No absolute maximum characters defined -> Calculate
       
  1102                     // character maximum using maximum SMS part limit.
       
  1103                     maxSmsCharacters = maxSmsParts * lengthMany;
       
  1104                     }
       
  1105                 CalculateSMSMsgLen(charsLeft,msgsParts);
       
  1106                 if( model->ObjectList().Count() == 0 &&
       
  1107                     model->AttachmentList().Count() == 1 &&
       
  1108                     iSmilModel->SlideCount() == 1 &&
       
  1109                     iSmsSubjectLength == 0)
       
  1110                         {
       
  1111                      
       
  1112                          sizeString.AppendNum( msgsParts );                        
       
  1113                         
       
  1114                         }
       
  1115                 else if ( maxSmsCharacters <= lengthOne )
       
  1116                     {
       
  1117                     // Maximum less or equal to length of
       
  1118                     // one part -> show only characters left value.
       
  1119                     sizeString.AppendNum( charsLeft );
       
  1120                     }
       
  1121                 else
       
  1122                     {
       
  1123                     HBufC* tempBuf = iSmsLengthFormatBuffer;
       
  1124 
       
  1125                     if ( AknLayoutUtils::LayoutMirrored() )
       
  1126                         { 
       
  1127                         // Add the RTL marker in the format buffer
       
  1128                         tempBuf = iSmsLengthFormatBuffer->AllocL();
       
  1129                         tempBuf = tempBuf->ReAllocL( tempBuf->Length() + 2 );
       
  1130                         CleanupStack::PushL( tempBuf );
       
  1131                         TPtr tempPtr = tempBuf->Des();
       
  1132                         TChar KUniRLMUnicode( 0x200F ); // Right to Left Marker
       
  1133                         TBuf<1> charBuf;
       
  1134                         charBuf.Append(KUniRLMUnicode);
       
  1135                         tempPtr.Insert( 4, charBuf );
       
  1136                         tempPtr.Insert( 9, charBuf );
       
  1137                         }
       
  1138 
       
  1139                     StringLoader::Format( sizeString, tempBuf->Des(), 0, charsLeft );
       
  1140 
       
  1141                     if( tempBuf != iSmsLengthFormatBuffer )
       
  1142                         {
       
  1143                         CleanupStack::PopAndDestroy( tempBuf );
       
  1144                         }
       
  1145                         
       
  1146                     HBufC* temp = sizeString.AllocLC();
       
  1147                     
       
  1148                     StringLoader::Format( sizeString, *temp, 1, msgsParts );
       
  1149 
       
  1150                     CleanupStack::PopAndDestroy( temp );
       
  1151                     }
       
  1152                 iEditorFlags |= ESmsCounterShownLast;
       
  1153                 
       
  1154                 // Now the string is in buf     
       
  1155                 
       
  1156 #ifdef RD_SCALABLE_UI_V2
       
  1157                 if ( ( AknLayoutUtils::PenEnabled() && iPrevSmsLength != charsLeft ) || ( AknLayoutUtils::PenEnabled() &&  aForceDraw ))
       
  1158                     {
       
  1159                     if(!(iPrevSmsLength == -1 && !UpdateMsgLenToPenInput() ) ) // converted from MMS back to SMS
       
  1160                         {                     
       
  1161 	                    iPrevSmsLength = charsLeft;
       
  1162 	                    iPeninputServer.UpdateAppInfo( sizeString, EAppIndicatorMsg );
       
  1163                         }
       
  1164                     }
       
  1165 #endif
       
  1166                
       
  1167             // Reset this so that MMS size is drawn when it's shown next time
       
  1168             iDisplaySize = 0; 
       
  1169             }
       
  1170         else
       
  1171             { 
       
  1172             // OK we are dealing with MMS now
       
  1173             // Just take the size of the whole message and show it in the navipane
       
  1174             TInt bytes = MessageSizeInBytes();   
       
  1175 
       
  1176             TInt integer = iDisplaySize / 10;
       
  1177             TInt fragment = iDisplaySize % 10;
       
  1178 
       
  1179             CreateMmsNaviSizeStringL(      bytes,      sizeString,
       
  1180                                         integer,    fragment );
       
  1181 
       
  1182             TInt tempDispSize = integer * 10 + fragment;
       
  1183 
       
  1184             if ( !aForceDraw && iDisplaySize == tempDispSize && !( iEditorFlags & ESmsCounterShownLast ) )
       
  1185                 {
       
  1186                 // No changes to navipane
       
  1187                 return;
       
  1188                 }
       
  1189 #ifdef RD_SCALABLE_UI_V2
       
  1190             if (  AknLayoutUtils::PenEnabled() && (iEditorFlags & ESmsCounterShownLast ))
       
  1191                 {
       
  1192                      iPeninputServer.UpdateAppInfo( KNullDesC, EAppIndicatorMsg );
       
  1193                      iPrevSmsLength = -1;
       
  1194                 }
       
  1195 #endif
       
  1196 
       
  1197             iEditorFlags &= ~ESmsCounterShownLast;
       
  1198             iDisplaySize = tempDispSize;
       
  1199         
       
  1200             }
       
  1201         }
       
  1202 
       
  1203     // Update both Edwin indicator pane and navi indicator pane
       
  1204     MAknEditingStateIndicator* editIndi = iAvkonEnv->EditingStateIndicator();
       
  1205     
       
  1206     CAknIndicatorContainer* naviIndi = 
       
  1207         static_cast<CAknIndicatorContainer*>( iNaviDecorator->DecoratedControl() );
       
  1208     
       
  1209     if( editIndi )
       
  1210         {
       
  1211         CAknIndicatorContainer* indiContainer = editIndi->IndicatorContainer();
       
  1212         if ( indiContainer )
       
  1213             {
       
  1214             if( iEditorFlags & EHideSizeCounter )
       
  1215                 { 
       
  1216                 // Just hide it
       
  1217                 indiContainer->SetIndicatorState(TUid::Uid(EAknNaviPaneEditorIndicatorMessageLength), 
       
  1218                         EAknIndicatorStateOff);
       
  1219                 }
       
  1220             else
       
  1221                 {
       
  1222                 indiContainer->SetIndicatorValueL(TUid::Uid(EAknNaviPaneEditorIndicatorMessageLength), sizeString);
       
  1223                 indiContainer->SetIndicatorState(TUid::Uid(EAknNaviPaneEditorIndicatorMessageLength), 
       
  1224                         EAknIndicatorStateOn);
       
  1225                 }            
       
  1226             }
       
  1227         }
       
  1228         
       
  1229     if( naviIndi )
       
  1230         {
       
  1231         if( iEditorFlags & EHideSizeCounter )
       
  1232             { 
       
  1233             // Just hide it
       
  1234             naviIndi->SetIndicatorState(TUid::Uid(EAknNaviPaneEditorIndicatorMessageLength), 
       
  1235                     EAknIndicatorStateOff);
       
  1236             }
       
  1237         else
       
  1238             {
       
  1239             naviIndi->SetIndicatorValueL(TUid::Uid(EAknNaviPaneEditorIndicatorMessageLength), sizeString);
       
  1240             naviIndi->SetIndicatorState(TUid::Uid(EAknNaviPaneEditorIndicatorMessageLength), 
       
  1241                         EAknIndicatorStateOn);
       
  1242             }
       
  1243         }
       
  1244     
       
  1245     UNILOGGER_WRITE( "<- CUniEditorAppUi::MsgLengthToNavipaneL" );
       
  1246     }
       
  1247 
       
  1248 // ---------------------------------------------------------
       
  1249 // CUniEditorAppUi::CalculateSMSMsgLen
       
  1250 // ---------------------------------------------------------
       
  1251 //
       
  1252 void CUniEditorAppUi::CalculateSMSMsgLen(TInt& charsLeft, TInt& msgsParts)
       
  1253     {
       
  1254     CUniEditorDocument* doc = Document();
       
  1255     if ( doc->UniState() == EUniSms ) 
       
  1256         {
       
  1257         CUniDataModel* model = doc->DataModel();
       
  1258         TInt lengthOne = 0;
       
  1259         TInt lengthMany = 0;
       
  1260         
       
  1261         doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  1262         
       
  1263         TInt totalLen = iSmsBodyLength + iSmsSubjectLength;
       
  1264 
       
  1265         if ( doc->EmailOverSmsSupported()  )
       
  1266             { 
       
  1267             // Email over Sms so get the longest email address from To field
       
  1268             TInt emailLen = iHeader->LongestEmailAddress();
       
  1269             if ( emailLen > 0 )
       
  1270                 { 
       
  1271                 // increase by one so that the separator sign is included too
       
  1272                 emailLen++;
       
  1273                 }
       
  1274                 
       
  1275             totalLen += emailLen;
       
  1276             }
       
  1277         
       
  1278         TInt maxSmsCharacters = doc->AbsoluteMaxSmsCharacters();
       
  1279         TInt maxSmsParts = doc->AbsoluteMaxSmsParts();
       
  1280         
       
  1281         if ( maxSmsCharacters <= 0 )
       
  1282             {                    
       
  1283             maxSmsCharacters = maxSmsParts * lengthMany;
       
  1284             }
       
  1285             
       
  1286         TInt thisPartChars = 0;
       
  1287         TInt maxThisPartChars = 0;
       
  1288    
       
  1289         if( iNLTFeatureSupport )
       
  1290             {
       
  1291             //Turkish SMS-PREQ2265 specific
       
  1292             msgsParts = iNumOfPDUs;
       
  1293             maxThisPartChars = iCharsLeft;
       
  1294             thisPartChars = totalLen;
       
  1295 
       
  1296             if(msgsParts > 1)
       
  1297                 {
       
  1298                 // More characters than one SMS segment.                    
       
  1299                 // Calculate characters that are located on this part.
       
  1300                 thisPartChars = lengthMany - maxThisPartChars;
       
  1301                 }                
       
  1302             }
       
  1303         else
       
  1304             {
       
  1305             if ( totalLen <= lengthOne )
       
  1306                 {
       
  1307                 // Less or equal characters than one SMS segment.
       
  1308                 
       
  1309                 // All the characters are located in this part
       
  1310                 thisPartChars = totalLen;
       
  1311                 
       
  1312                 maxThisPartChars = lengthOne - thisPartChars;
       
  1313                 msgsParts = 1;
       
  1314                 }
       
  1315             else
       
  1316                 {
       
  1317                 // More characters than one SMS segment.
       
  1318                 
       
  1319                 // Calculate characters that are located on
       
  1320                 // this part.
       
  1321                 thisPartChars = totalLen % lengthMany;
       
  1322                 
       
  1323                 if ( thisPartChars == 0 )
       
  1324                     {
       
  1325                     // Last part has maximum characters.
       
  1326                     thisPartChars = lengthMany;
       
  1327                     }
       
  1328                     
       
  1329                 maxThisPartChars = lengthMany - thisPartChars;
       
  1330                 
       
  1331                 msgsParts = totalLen / lengthMany;
       
  1332                 if ( thisPartChars != lengthMany )
       
  1333                     { 
       
  1334                     // Chars in this part so lets add one part.
       
  1335                     msgsParts++;
       
  1336                     }
       
  1337                 }                
       
  1338             }
       
  1339              
       
  1340         if ( totalLen <= maxSmsCharacters )
       
  1341             { 
       
  1342             // Calculate the characters left in this part.
       
  1343             charsLeft = maxSmsCharacters -  ( msgsParts - 1 ) * lengthMany - thisPartChars;
       
  1344             // Bound check.
       
  1345             charsLeft = Min( charsLeft, maxThisPartChars );
       
  1346             }
       
  1347         else
       
  1348             { 
       
  1349             // More than max -> show -xx(yy)
       
  1350             charsLeft = maxSmsCharacters - totalLen;
       
  1351             }
       
  1352         if( model->ObjectList().Count() == 0 &&
       
  1353             model->AttachmentList().Count() == 1 &&
       
  1354             iSmilModel->SlideCount() == 1 &&
       
  1355             iSmsSubjectLength == 0)
       
  1356             {                     
       
  1357             charsLeft =  msgsParts;                        
       
  1358             }      
       
  1359         }
       
  1360     }
       
  1361     
       
  1362 
       
  1363 // ---------------------------------------------------------
       
  1364 // CUniEditorAppUi::HandleCommandL
       
  1365 // ---------------------------------------------------------
       
  1366 //
       
  1367 void CUniEditorAppUi::HandleCommandL( TInt aCommand )
       
  1368     {
       
  1369     if ( iFixedToolbar )
       
  1370         {
       
  1371         SetFixedToolbarDimmed();
       
  1372         }
       
  1373      if ( !IsLaunched() || ( iEditorFlags & ( EEditorClosing | EEditorExiting ) ) )
       
  1374         {
       
  1375         if ( aCommand == EEikCmdExit )
       
  1376             {           
       
  1377             TRAPD( error, DoHandleCommandL( EEikCmdExit ) );
       
  1378             User::LeaveIfError(error);                     
       
  1379             }
       
  1380         }   
       
  1381      else
       
  1382         {                
       
  1383         TRAPD( error, DoHandleCommandL( aCommand ) );
       
  1384         
       
  1385         if ( iFixedToolbar )
       
  1386             {
       
  1387             UpdateToolbarL();
       
  1388             }
       
  1389         
       
  1390         User::LeaveIfError( error );
       
  1391         }
       
  1392     }
       
  1393 
       
  1394 // ---------------------------------------------------------
       
  1395 // CUniEditorAppUi::DoHandleCommandL
       
  1396 // ---------------------------------------------------------
       
  1397 //
       
  1398 void CUniEditorAppUi::DoHandleCommandL( TInt aCommand )
       
  1399     {
       
  1400     if ( !IsLaunched() || ( iEditorFlags & ( EEditorClosing | EEditorExiting | EMsgEditInProgress ) ) )
       
  1401         {
       
  1402         if ( aCommand != EEikCmdExit )
       
  1403             {
       
  1404             // Do not handle other than exit command if application has not
       
  1405             // finished launching.
       
  1406             return;
       
  1407             }
       
  1408         }
       
  1409 
       
  1410     switch (aCommand)
       
  1411         {
       
  1412         // Main options menu commands
       
  1413         case EUniCmdViewImage:
       
  1414         case EUniCmdPlayAudio:
       
  1415         case EUniCmdPlayVideo:
       
  1416         case EUniCmdPlaySvg:
       
  1417         case EUniCmdPlayPres:
       
  1418             {
       
  1419             PlayFocusedItemL();
       
  1420             break;
       
  1421             }
       
  1422         case EUniCmdRemovePres:
       
  1423             {
       
  1424             RemoveTemplateL();
       
  1425             break;
       
  1426             }
       
  1427         case EUniCmdSendSMS:
       
  1428         case EUniCmdSendMMS:
       
  1429             {
       
  1430             if ( iHeader->HasRecipients() > 0 )
       
  1431                 {
       
  1432                 // has addresses -> Send
       
  1433                 DoUserSendL();
       
  1434                 }
       
  1435             else
       
  1436                 {
       
  1437                 DoUserAddRecipientL();
       
  1438                 }
       
  1439             break;
       
  1440             }
       
  1441         case EUniCmdAddRecipient:
       
  1442             {
       
  1443             DoUserAddRecipientL();
       
  1444             break;
       
  1445             }
       
  1446         case EUniCmdAddRecipientMSK:
       
  1447             {
       
  1448             // Call this function so that check name functionality is called first
       
  1449             DoSelectionKeyL();
       
  1450             break;
       
  1451             }
       
  1452         case EUniCmdInsertMedia:
       
  1453             {
       
  1454             DoUserInsertMediaL();
       
  1455             break;
       
  1456             }
       
  1457         case EUniCmdInsertTemplateText:
       
  1458             {
       
  1459             DoUserInsertTextL( ETemplateText );
       
  1460             break;
       
  1461             }
       
  1462         case EUniCmdInsertNote:
       
  1463             {
       
  1464             DoUserInsertTextL( EMemoText );
       
  1465             break;
       
  1466             }
       
  1467         case EUniCmdPlaceTextFirst:
       
  1468             {
       
  1469             DoUserChangeOrderL( EUniTextFirst );
       
  1470             break;
       
  1471             }
       
  1472         case EUniCmdPlaceTextSecond:
       
  1473             {
       
  1474             DoUserChangeOrderL( EUniImageFirst );
       
  1475             break;
       
  1476             }
       
  1477         case EUniCmdMovePage:
       
  1478             {
       
  1479             DoUserMoveOrSelectPageL( ETrue );
       
  1480             break;
       
  1481             }
       
  1482         case EUniCmdSelectPage:
       
  1483             {
       
  1484             DoUserMoveOrSelectPageL( EFalse );
       
  1485             break;
       
  1486             }
       
  1487         case EUniCmdAddHeaders:
       
  1488             {
       
  1489             DoUserAddHeadersL();
       
  1490             break;
       
  1491             }
       
  1492         case EUniCmdObjects:
       
  1493             {
       
  1494             DoUserObjectsViewL( EFalse );
       
  1495             break;
       
  1496             }
       
  1497         case EUniCmdObjectsAttachment:
       
  1498             {
       
  1499             DoUserObjectsViewL( ETrue );
       
  1500             break;
       
  1501             }
       
  1502         case EUniCmdSendingOptions:
       
  1503             {
       
  1504             DoUserSendingOptionsL();
       
  1505             break;
       
  1506             }
       
  1507         case EUniCmdMessageInfo:
       
  1508             {
       
  1509             DoUserMessageInfoL();
       
  1510             break;
       
  1511             }
       
  1512         case EUniCmdRemovePage:
       
  1513             {
       
  1514             DoUserRemoveSlideL();
       
  1515             break;
       
  1516             }
       
  1517         case EUniCmdRemoveText:
       
  1518             {
       
  1519             RemoveCurrentTextObjectL();
       
  1520             break;
       
  1521             }
       
  1522         case EUniCmdChangePriority:
       
  1523             {
       
  1524             DoEditMmsPriorityL();
       
  1525             break;        
       
  1526             }
       
  1527         case EUniCmdRemoveImage:
       
  1528             {
       
  1529             DoUserRemoveMediaL( EMsgComponentIdImage, EUniRegionImage );
       
  1530             break;
       
  1531             }
       
  1532         case EUniCmdRemoveAudio:
       
  1533             {
       
  1534             DoUserRemoveMediaL( EMsgComponentIdAudio, EUniRegionAudio );
       
  1535             break;
       
  1536             }
       
  1537         case EUniCmdRemoveVideo:
       
  1538             {
       
  1539             DoUserRemoveMediaL( EMsgComponentIdVideo, EUniRegionImage );
       
  1540             break;
       
  1541             }
       
  1542         case EUniCmdRemoveSvg:
       
  1543             {
       
  1544             DoUserRemoveMediaL( EMsgComponentIdSvg, EUniRegionImage );
       
  1545             break;
       
  1546             }
       
  1547         case EMsgDispSizeAutomatic:
       
  1548         case EMsgDispSizeLarge:
       
  1549         case EMsgDispSizeNormal:
       
  1550         case EMsgDispSizeSmall:
       
  1551             {
       
  1552             HandleLocalZoomChangeL( (TMsgCommonCommands)aCommand );
       
  1553             break;
       
  1554             }
       
  1555         case EEikCmdExit:
       
  1556             {
       
  1557             RemoveWaitNote();
       
  1558             ExitAndSaveL();
       
  1559             break;
       
  1560             }
       
  1561         case EAknSoftkeyClose:
       
  1562             {
       
  1563             DoBackSaveL();
       
  1564             break;
       
  1565             }
       
  1566         case EAknCmdHelp:
       
  1567             {
       
  1568             LaunchHelpL();
       
  1569             break;
       
  1570             }
       
  1571         default:
       
  1572             {
       
  1573             CMsgEditorAppUi::HandleCommandL(aCommand);
       
  1574             break;
       
  1575             }
       
  1576         }
       
  1577     }
       
  1578 
       
  1579 // ---------------------------------------------------------
       
  1580 // CUniEditorAppUi::EditorObserver
       
  1581 // ---------------------------------------------------------
       
  1582 //
       
  1583 void CUniEditorAppUi::EditorObserver( TMsgEditorObserverFunc aFunc, 
       
  1584                                       TAny* aArg1, 
       
  1585                                       TAny* aArg2, 
       
  1586                                       TAny* aArg3)
       
  1587     {
       
  1588     TRAPD( error, DoEditorObserverL( aFunc, aArg1, aArg2, aArg3 ) );
       
  1589     if ( error == KLeaveExit )
       
  1590         {
       
  1591         User::Leave( KLeaveExit );
       
  1592         }
       
  1593     }
       
  1594 
       
  1595 // ---------------------------------------------------------
       
  1596 // CUniEditorAppUi::DoEditorObserverL
       
  1597 // ---------------------------------------------------------
       
  1598 //
       
  1599 void CUniEditorAppUi::DoEditorObserverL( TMsgEditorObserverFunc aFunc, 
       
  1600                                          TAny* aArg1, 
       
  1601                                          TAny* aArg2, 
       
  1602                                          TAny* aArg3)
       
  1603     {
       
  1604     
       
  1605     UNILOGGER_WRITE( "-> CUniEditorAppUi::DoEditorObserverL" );
       
  1606     TInt slides = iSmilModel->SlideCount();
       
  1607     TInt currSlide = Document()->CurrentSlide();
       
  1608 
       
  1609     switch( aFunc )
       
  1610         {
       
  1611         case EMsgScrollParts:
       
  1612             {
       
  1613             TInt* parts = static_cast<TInt*>( aArg1 );
       
  1614             *parts = slides;
       
  1615             break;
       
  1616             }
       
  1617         case MMsgEditorObserver::EMsgHandleFocusChange:
       
  1618             {
       
  1619             TMsgFocusEvent* event = static_cast<TMsgFocusEvent*>( aArg1 );
       
  1620             TMsgAfterFocusEventFunc* after = static_cast<TMsgAfterFocusEventFunc*>( aArg2 );
       
  1621             TInt* currPart = static_cast<TInt*>( aArg3 );
       
  1622 
       
  1623             *after = EMsgAfterFocusNone;
       
  1624             UNILOGGER_WRITE( "-> DoEditorObserverL ->MMsgEditorObserver::EMsgHandleFocusChange " );
       
  1625             
       
  1626             switch ( *event )
       
  1627                 {
       
  1628                 case EMsgFocusAtBottom:
       
  1629                     {
       
  1630                     UNILOGGER_WRITE( "-> DoEditorObserverL ->EMsgFocusAtBottom ");
       
  1631                     if ( currSlide + 1 < slides )
       
  1632                         {
       
  1633 #ifdef RD_SCALABLE_UI_V2
       
  1634                         DoUserChangeSlideL( *currPart );
       
  1635                         *after = EMsgCursorToBodyBeginning;
       
  1636                         *currPart = Document()->CurrentSlide();
       
  1637 #else
       
  1638                         DoUserChangeSlideL( currSlide + 1 );
       
  1639                         *after = EMsgCursorToBodyBeginning;
       
  1640                         *currPart = currSlide + 1;
       
  1641 #endif
       
  1642                         }
       
  1643                     break;
       
  1644                     }
       
  1645                 case EMsgFocusAtTop:
       
  1646                     {
       
  1647                      UNILOGGER_WRITE( "-> DoEditorObserverL ->EMsgFocusAtTop ");
       
  1648                     if ( currSlide > 0 )
       
  1649                         {
       
  1650 #ifdef RD_SCALABLE_UI_V2
       
  1651                         DoUserChangeSlideL( *currPart );
       
  1652                         *after = EMsgCursorToBodyEnd;
       
  1653                         *currPart = Document()->CurrentSlide();
       
  1654 #else
       
  1655                          DoUserChangeSlideL( currSlide - 1 );
       
  1656                         *after = EMsgCursorToBodyEnd;
       
  1657                         *currPart = currSlide - 1;
       
  1658 #endif
       
  1659                         }
       
  1660                     break;
       
  1661                     }
       
  1662                 case EMsgFocusMovingFrom:
       
  1663                     {
       
  1664                     UNILOGGER_WRITE( "-> DoEditorObserverL ->EMsgFocusMovingFrom ");
       
  1665                     TInt id( EMsgComponentIdNull );
       
  1666                     CMsgBaseControl* ctrl = iView->FocusedControl();  // ctrl can be NULL.
       
  1667                     if ( !ctrl )
       
  1668                         {
       
  1669                         break;
       
  1670                         }
       
  1671 
       
  1672                     id = ctrl->ControlId();
       
  1673                     if ( id == EMsgComponentIdAudio ||
       
  1674                          id == EMsgComponentIdImage ||
       
  1675                          id == EMsgComponentIdVideo )
       
  1676                         {
       
  1677                         break;
       
  1678                         }
       
  1679 
       
  1680                     // not in first slide -> return
       
  1681                     if ( currSlide > 0 )
       
  1682                         {
       
  1683                         break;
       
  1684                         }
       
  1685                         
       
  1686                     if ( iHeader &&  
       
  1687                          iHeader->IsAddressControl( id ) )
       
  1688                         {
       
  1689                         // We are moving from address control -> set max edwin sizes..
       
  1690                         SetOrRemoveMaxSizeInEdwin();
       
  1691                         
       
  1692                         CMsgAddressControl* rec = iView ? 
       
  1693                             static_cast<CMsgAddressControl*>( iView->ControlById( id ) ) :
       
  1694                             NULL;
       
  1695 
       
  1696                         if ( rec ) 
       
  1697                             {
       
  1698                             TInt inputMode = rec->Editor().AknEditorCurrentInputMode();
       
  1699                             SetInputModeToAddressFields( inputMode );
       
  1700                             }
       
  1701                         }
       
  1702                     break;
       
  1703                     }
       
  1704                 case EMsgFocusMovedTo:
       
  1705                     {
       
  1706                     UNILOGGER_WRITE( "-> DoEditorObserverL ->EMsgFocusMovedTo ");
       
  1707                     TInt id( EMsgComponentIdNull );
       
  1708                     CMsgBaseControl* ctrl = iView->FocusedControl();  // ctrl can be NULL.
       
  1709                     if ( !ctrl )
       
  1710                         {
       
  1711                         break;
       
  1712                         }
       
  1713                     
       
  1714                     id = ctrl->ControlId();
       
  1715                     if ( id == EMsgComponentIdAudio ||
       
  1716                          id == EMsgComponentIdImage ||
       
  1717                          id == EMsgComponentIdVideo ||
       
  1718                          id == EMsgComponentIdAttachment ||
       
  1719                          id == EMsgComponentIdSvg )
       
  1720                         {
       
  1721                         iNaviPane->PushL( *iNaviDecorator );
       
  1722                         }
       
  1723                         
       
  1724                     UpdateMiddleSoftkeyL();
       
  1725                     break;
       
  1726                     }
       
  1727                 case EMsgFocusToBody:
       
  1728                 case EMsgFocusToHeader:
       
  1729                     {
       
  1730                     UNILOGGER_WRITE( "-> DoEditorObserverL ->EMsgFocusToBody or EMsgFocusToHeader  ");
       
  1731                     
       
  1732                     SmsMsgLenToPenInputL();
       
  1733                     UpdateMiddleSoftkeyL(); // fallthrough
       
  1734                     break;
       
  1735                     }
       
  1736                 default:
       
  1737                     {
       
  1738                     break;
       
  1739                     }
       
  1740                 }
       
  1741             break;
       
  1742             }
       
  1743         case MMsgEditorObserver::EMsgControlPointerEvent:
       
  1744             {
       
  1745             TPointerEvent* event = static_cast<TPointerEvent*>( aArg2 );
       
  1746             CMsgBaseControl* control = static_cast<CMsgBaseControl*>( aArg1 );
       
  1747 
       
  1748             if ( event->iType == TPointerEvent::EButton1Down )
       
  1749                 {
       
  1750                 iFocusedControl = control && control->IsFocused() ? control : NULL;
       
  1751                 }
       
  1752             else if ( event->iType == TPointerEvent::EButton1Up )
       
  1753                 {
       
  1754                 if ( control && 
       
  1755                      iFocusedControl == control &&
       
  1756                      ( control->ControlId() == EMsgComponentIdAudio ||
       
  1757                        control->ControlId() == EMsgComponentIdImage ||
       
  1758                        control->ControlId() == EMsgComponentIdVideo ||
       
  1759                        control->ControlId() == EMsgComponentIdAttachment ||
       
  1760                        control->ControlId() == EMsgComponentIdSvg ) )
       
  1761                     {
       
  1762                     DoSelectionKeyL();
       
  1763                     }
       
  1764                 }
       
  1765             break;
       
  1766             }
       
  1767         case MMsgEditorObserver::EMsgButtonEvent:
       
  1768             {
       
  1769             CMsgBaseControl* control = static_cast<CMsgBaseControl*>( aArg1 );
       
  1770             
       
  1771             if ( control &&
       
  1772                  ( control->ControlId() != EMsgComponentIdAttachment ||
       
  1773                    iFocusedControl != control ) )
       
  1774                 {
       
  1775                 DoSelectionKeyL();
       
  1776                 }
       
  1777             break;
       
  1778             }
       
  1779         default:
       
  1780             {
       
  1781             // Other events not handled.
       
  1782             break;
       
  1783             }
       
  1784         }
       
  1785     }
       
  1786 
       
  1787 // ---------------------------------------------------------
       
  1788 // CUniEditorAppUi::FetchFileL
       
  1789 // ---------------------------------------------------------
       
  1790 //
       
  1791 TBool CUniEditorAppUi::FetchFileL( MsgAttachmentUtils::TMsgAttachmentFetchType aFetchType )
       
  1792     {
       
  1793     // do not start if()ing. Sets parameter always
       
  1794     TAiwVariant sizeLimit( Document()->MaxMessageSize() 
       
  1795                             - ( MessageSizeInBytes() + KUniAttachmentOverhead ) );
       
  1796     TAiwGenericParam sizeLimitParam( EGenericParamMMSSizeLimit, sizeLimit );
       
  1797 
       
  1798     CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
       
  1799     paramList->AppendL( sizeLimitParam );
       
  1800     
       
  1801     CDesCArrayFlat* files = new( ELeave ) CDesC16ArrayFlat( 1 );
       
  1802     CleanupStack::PushL( files );
       
  1803     
       
  1804     TBool fetchOK = MsgAttachmentUtils::FetchFileL( aFetchType,
       
  1805                                                     *files,
       
  1806                                                     paramList,
       
  1807                                                     EFalse, // disk space checked in VerifySelectionL or CUniEditorInsertOperation, if image scaled/compressed
       
  1808                                                     EFalse,
       
  1809                                                     this );
       
  1810 
       
  1811     switch ( aFetchType )
       
  1812         {
       
  1813         case MsgAttachmentUtils::ENewImage:
       
  1814         case MsgAttachmentUtils::ENewAudio:
       
  1815         case MsgAttachmentUtils::ENewVideo:
       
  1816         case MsgAttachmentUtils::ENote:
       
  1817             {
       
  1818             if ( fetchOK )
       
  1819                 {
       
  1820                 TFileName* fileName = new( ELeave ) TFileName;
       
  1821                 CleanupStack::PushL( fileName );
       
  1822     
       
  1823                 if ( files->MdcaCount() > 0 )
       
  1824                     {
       
  1825                     *fileName = files->MdcaPoint( 0 );
       
  1826                     }
       
  1827                     
       
  1828                 // Something was fetched
       
  1829                 __ASSERT_DEBUG( !iInsertingMedia, Panic( EUniIllegalMediaObject ) );
       
  1830                 fetchOK = CreateMediaInfoForInsertL( iInsertingType, *fileName ) ? ETrue : 
       
  1831                                                                                    EFalse;
       
  1832                 CleanupStack::PopAndDestroy( fileName );
       
  1833                 }
       
  1834             break;
       
  1835             }
       
  1836         case MsgAttachmentUtils::EImage:
       
  1837         case MsgAttachmentUtils::EAudio:
       
  1838         case MsgAttachmentUtils::EVideo:
       
  1839         case MsgAttachmentUtils::ESVG:
       
  1840         default:
       
  1841             {
       
  1842             // CreateMediaInfoForInsertL is called in VeritySelectionL
       
  1843             break;
       
  1844             }
       
  1845         }
       
  1846     
       
  1847     CleanupStack::PopAndDestroy( 2, paramList );    // + files
       
  1848     
       
  1849     return fetchOK;
       
  1850     }
       
  1851 
       
  1852 // ---------------------------------------------------------
       
  1853 // CUniEditorAppUi::VerifySelectionL
       
  1854 // ---------------------------------------------------------
       
  1855 //
       
  1856 TBool CUniEditorAppUi::VerifySelectionL( const MDesCArray* aSelectedFiles )
       
  1857     {
       
  1858     CAknInputBlock::NewLC();
       
  1859 
       
  1860     TBool ret = EFalse;
       
  1861     if ( aSelectedFiles->MdcaCount() == 1 )
       
  1862         {
       
  1863         __ASSERT_DEBUG( !iInsertingMedia, Panic( EUniIllegalMediaObject ) );
       
  1864         if ( CreateMediaInfoForInsertL( iInsertingType, aSelectedFiles->MdcaPoint( 0 ) ) )
       
  1865             {
       
  1866             ret = ETrue;
       
  1867             }
       
  1868         }
       
  1869     
       
  1870     CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  1871     return ret;
       
  1872     }
       
  1873 
       
  1874 // ---------------------------------------------------------
       
  1875 // CUniEditorAppUi::DynInitToolbarL
       
  1876 // ---------------------------------------------------------
       
  1877 //
       
  1878 void CUniEditorAppUi::DynInitToolbarL( TInt aResourceId, CAknToolbar* aToolbar )
       
  1879     {
       
  1880     if ( aResourceId == EUniCmdFixedToolbarInsert )
       
  1881         {
       
  1882         CAknToolbarExtension* extension = aToolbar->ToolbarExtension();
       
  1883         
       
  1884         if ( iSmilModel )
       
  1885             {
       
  1886             if ( iSmilModel->SlideCount() >= iSmilModel->MaxSlideCount() )
       
  1887                 {
       
  1888                 if ( ObjectsAvailable() & ( EUniImageFlag |  EUniSvgFlag | EUniVideoFlag ) )
       
  1889                     {
       
  1890                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertImage, ETrue );
       
  1891                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewImage, ETrue );
       
  1892                     }
       
  1893                else
       
  1894                     {
       
  1895                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertImage, EFalse );
       
  1896                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewImage, EFalse );
       
  1897                     }
       
  1898                     
       
  1899                 if ( ObjectsAvailable() & ( EUniImageFlag |  EUniSvgFlag | EUniVideoFlag | EUniAudioFlag ) )
       
  1900                     {
       
  1901                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertVideo, ETrue );
       
  1902                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewVideo, ETrue );
       
  1903                     }
       
  1904                 else
       
  1905                     {
       
  1906                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertVideo, EFalse );
       
  1907                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewVideo, EFalse );
       
  1908                     }
       
  1909                 
       
  1910                 if ( ObjectsAvailable() & ( EUniVideoFlag | EUniAudioFlag | EUniSvgFlag ) )
       
  1911                     {
       
  1912                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertAudio, ETrue );
       
  1913                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewAudio, ETrue );
       
  1914                     }
       
  1915                 else 
       
  1916                     {
       
  1917                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertAudio, EFalse );
       
  1918                     SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewAudio, EFalse );
       
  1919                     }
       
  1920                 
       
  1921                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertSlide, ETrue );
       
  1922                 }
       
  1923             else 
       
  1924                 {
       
  1925                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertImage, EFalse );
       
  1926                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewImage, EFalse );
       
  1927                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertVideo, EFalse );
       
  1928                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewVideo, EFalse );
       
  1929                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertAudio, EFalse );
       
  1930                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewAudio, EFalse );
       
  1931                 SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtInsertSlide, EFalse );                
       
  1932                 }
       
  1933             }
       
  1934         
       
  1935         if ( !( iSupportedFeatures & EUniFeatureCamcorder ) )
       
  1936             {
       
  1937             SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewImage, ETrue );
       
  1938             SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewVideo, ETrue );
       
  1939             }
       
  1940 
       
  1941         if ( Document()->CreationMode() == EMmsCreationModeRestricted )
       
  1942              {
       
  1943              SetExtensionButtonDimmed( extension, EUniCmdFixedToolbarExtNewSmil, ETrue );             
       
  1944              }
       
  1945         }
       
  1946     }
       
  1947 
       
  1948 // ---------------------------------------------------------
       
  1949 // CUniEditorAppUi::OfferToolbarEventL
       
  1950 // ---------------------------------------------------------
       
  1951 //        
       
  1952 void CUniEditorAppUi::OfferToolbarEventL( TInt aCommand )
       
  1953     {
       
  1954     if ( iFixedToolbar )
       
  1955         {
       
  1956         iFixedToolbar->ToolbarExtension()->SetShown( EFalse );
       
  1957         }
       
  1958             
       
  1959     TRAPD( error, DoOfferToolbarEventL( aCommand ) );
       
  1960             
       
  1961     User::LeaveIfError( error );
       
  1962     }
       
  1963 
       
  1964         
       
  1965 // ---------------------------------------------------------
       
  1966 // CUniEditorAppUi::DoOfferToolbarEventL
       
  1967 // ---------------------------------------------------------
       
  1968 //        
       
  1969 void CUniEditorAppUi::DoOfferToolbarEventL( TInt aCommand )
       
  1970     {
       
  1971     switch( aCommand )
       
  1972         {
       
  1973         case EUniCmdFixedToolbarSend:
       
  1974             {
       
  1975             DoHandleCommandL( EUniCmdSendSMS );
       
  1976             break;
       
  1977             }
       
  1978         case EUniCmdFixedToolbarInsert:
       
  1979             {
       
  1980             DoHandleCommandL( EUniCmdInsertMedia );
       
  1981             break;
       
  1982             }
       
  1983         case EUniCmdFixedToolbarAddRecipient:
       
  1984             {
       
  1985             DoHandleCommandL( EUniCmdAddRecipient );
       
  1986             break;
       
  1987             }
       
  1988         case EUniCmdFixedToolbarExtInsertImage:
       
  1989             {
       
  1990             DoUserInsertImageL( MsgAttachmentUtils::EImage );
       
  1991             break;
       
  1992             }
       
  1993         case EUniCmdFixedToolbarExtInsertVideo:
       
  1994             {
       
  1995             DoUserInsertVideoL( MsgAttachmentUtils::EVideo );
       
  1996             break;
       
  1997             }
       
  1998         case EUniCmdFixedToolbarExtInsertAudio:
       
  1999             {
       
  2000             DoUserInsertAudioL( MsgAttachmentUtils::EAudio );
       
  2001             break;
       
  2002             }
       
  2003         case EUniCmdFixedToolbarExtNewImage:
       
  2004             {
       
  2005             DoUserInsertImageL( MsgAttachmentUtils::ENewImage );
       
  2006             break;
       
  2007             }
       
  2008         case EUniCmdFixedToolbarExtNewVideo:
       
  2009             {
       
  2010             DoUserInsertVideoL( MsgAttachmentUtils::ENewVideo );
       
  2011             break;
       
  2012             }
       
  2013         case EUniCmdFixedToolbarExtNewAudio:
       
  2014             {
       
  2015             DoUserInsertAudioL( MsgAttachmentUtils::ENewAudio );
       
  2016             break;
       
  2017             }
       
  2018         case EUniCmdFixedToolbarExtInsertSlide:
       
  2019             {
       
  2020             DoUserInsertSlideL();
       
  2021             break;
       
  2022             }
       
  2023         case EUniCmdFixedToolbarExtInsertTemplate:
       
  2024             {
       
  2025             DoUserInsertTextL( ETemplateText );
       
  2026             break;
       
  2027             }
       
  2028         case EUniCmdFixedToolbarExtInsertNote:
       
  2029             {
       
  2030             DoUserInsertTextL( EMemoText );
       
  2031             break;
       
  2032             }
       
  2033         case EUniCmdFixedToolbarExtInsertvCard:
       
  2034             {
       
  2035             DoUserInsertVCardL();
       
  2036             break;
       
  2037             }
       
  2038         case EUniCmdFixedToolbarExtOther:
       
  2039             {
       
  2040             DoToolbarInsertOtherL();
       
  2041             break;
       
  2042             }
       
  2043         default:
       
  2044             {
       
  2045             break;
       
  2046             }
       
  2047         }
       
  2048     }
       
  2049 
       
  2050 // ---------------------------------------------------------
       
  2051 // CUniEditorAppUi::HandleServerAppExit
       
  2052 // ---------------------------------------------------------
       
  2053 // 
       
  2054 void CUniEditorAppUi::HandleServerAppExit( TInt /*aReason*/ )
       
  2055     {
       
  2056     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  2057 
       
  2058     if ( ctrl )
       
  2059         {
       
  2060         TUniRegion region = EUniRegionImage;
       
  2061         
       
  2062         switch ( ctrl->ControlId() )
       
  2063             {
       
  2064             case EMsgComponentIdAudio:
       
  2065                 {
       
  2066                 region = EUniRegionAudio;
       
  2067                 // Fallthrough.
       
  2068                 }
       
  2069             case EMsgComponentIdVideo:
       
  2070                 {
       
  2071                 CUniObject* object = iSmilModel->GetObject( Document()->CurrentSlide(), region );
       
  2072                 
       
  2073                 if ( object->DrmInfo() )
       
  2074                     {
       
  2075                     object->DrmInfo()->FreezeRights();
       
  2076                     }
       
  2077                 
       
  2078                 TRAP_IGNORE( iSlideLoader->UpdateControlIconL( 
       
  2079                                                   *static_cast<CMsgMediaControl*>( ctrl ), 
       
  2080                                                   object ) );
       
  2081                 ctrl->DrawNow();
       
  2082                 break;
       
  2083                 }
       
  2084             default:
       
  2085                 {
       
  2086                 break;
       
  2087                 }
       
  2088             }
       
  2089         }
       
  2090     iEditorFlags &= ~EMsgEditInProgress;
       
  2091     DeactivateInputBlocker();
       
  2092     }
       
  2093 
       
  2094 // ---------------------------------------------------------
       
  2095 // CUniEditorAppUi::HandleEdwinEventL
       
  2096 //
       
  2097 // Performs character counter updating if neccessary. This is needed
       
  2098 // for supporting on-screen keyboard. Normally character input
       
  2099 // is handled already on OfferKeyEventL function but it does no
       
  2100 // harm to do it here again. Character input is not handled if editor
       
  2101 // is not fully launched or it is about to close. Modified flag is turned
       
  2102 // on here since control state change event that should turn it on might 
       
  2103 // come after this event and HandleCharInputL will not work correctly if 
       
  2104 // modified flag is not set. Text update event is expected to come only
       
  2105 // in such cases that control is modified.
       
  2106 // ---------------------------------------------------------
       
  2107 //
       
  2108 void CUniEditorAppUi::HandleEdwinEventL( CEikEdwin* /*aEdwin*/, TEdwinEvent aEventType )
       
  2109     {
       
  2110     if ( aEventType == MEikEdwinObserver::EEventTextUpdate &&
       
  2111          !( iEditorFlags & EEditorClosing ||
       
  2112             iEditorFlags & EEditorExiting ) &&
       
  2113          IsLaunched() )
       
  2114         {
       
  2115         CMsgBaseControl* focusedControl = iView->FocusedControl();
       
  2116         if ( focusedControl )
       
  2117             {
       
  2118             focusedControl->SetModified( ETrue );
       
  2119             
       
  2120             HandleCharInputL();            
       
  2121             }
       
  2122         }
       
  2123     }
       
  2124 
       
  2125 // ---------------------------------------------------------
       
  2126 // CUniEditorAppUi::HandleEntryMovedL
       
  2127 // ---------------------------------------------------------
       
  2128 //
       
  2129 void CUniEditorAppUi::HandleEntryMovedL( TMsvId /*aOldParent*/, TMsvId /*aNewParent*/ )
       
  2130     {
       
  2131     }
       
  2132 
       
  2133 // ---------------------------------------------------------
       
  2134 // CUniEditorAppUi::HandleKeyEventL
       
  2135 // ---------------------------------------------------------
       
  2136 //
       
  2137 TKeyResponse CUniEditorAppUi::HandleKeyEventL( const TKeyEvent& aKeyEvent, 
       
  2138                                                TEventCode aType )
       
  2139     {
       
  2140     if ( !IsLaunched() )
       
  2141         {
       
  2142         // Still launching
       
  2143         return EKeyWasNotConsumed;
       
  2144         }
       
  2145         
       
  2146     if ( !IsDisplayingMenuOrDialog() &&
       
  2147          !( iEditorFlags & EEditorClosing ||
       
  2148             iEditorFlags & EEditorExiting ) )
       
  2149         {
       
  2150         switch ( aKeyEvent.iCode )
       
  2151             {
       
  2152             case EKeyEnter:
       
  2153                 {
       
  2154                 if ( DoEnterKeyL() )
       
  2155                     {
       
  2156                     return EKeyWasConsumed;
       
  2157                     }
       
  2158                 break;
       
  2159                 }
       
  2160             case EKeyOK:
       
  2161                 {
       
  2162                 // Selection key: Show context menus
       
  2163                 DoSelectionKeyL();
       
  2164                 return EKeyWasConsumed;
       
  2165                 }
       
  2166             case EKeyYes:
       
  2167                 {
       
  2168                 // CallCreationKey: Send message if recipients.
       
  2169                 //                  Otherwise fetch recipients
       
  2170                 if ( iHeader->HasRecipients() )
       
  2171                     {
       
  2172                     // has addresses -> Send
       
  2173                     DoUserSendL();
       
  2174                     }
       
  2175                 else
       
  2176                     {
       
  2177                     DoUserAddRecipientL();
       
  2178                     }
       
  2179                 return EKeyWasConsumed;
       
  2180                 }
       
  2181             case EKeyBackspace:
       
  2182             case EKeyDelete:
       
  2183                 {
       
  2184                 CMsgBaseControl* ctrl = iView->FocusedControl();
       
  2185                 if ( ctrl )
       
  2186                     {
       
  2187                     switch( ctrl->ControlId() )
       
  2188                         {
       
  2189                         case EMsgComponentIdImage:
       
  2190                             {
       
  2191                             switch ( Document()->DataModel()->SmilType() )
       
  2192                                 {
       
  2193                                 case ETemplateSmil:
       
  2194                                 case E3GPPSmil:
       
  2195                                     {
       
  2196                                     // focus is on SMIL presentation icon
       
  2197                                     RemoveTemplateL();
       
  2198                                     break;
       
  2199                                     }
       
  2200                                 default:
       
  2201                                     {
       
  2202                                     // real image
       
  2203                                     DoUserRemoveMediaL( EMsgComponentIdImage, EUniRegionImage );
       
  2204                                     break;
       
  2205                                     }
       
  2206                                 }
       
  2207                                 
       
  2208                             return EKeyWasConsumed;
       
  2209                             }
       
  2210                         case EMsgComponentIdAudio:
       
  2211                             {
       
  2212                             DoUserRemoveMediaL( EMsgComponentIdAudio, EUniRegionAudio );
       
  2213                             return EKeyWasConsumed;
       
  2214                             }
       
  2215                         case EMsgComponentIdVideo:
       
  2216                             {
       
  2217                             DoUserRemoveMediaL( EMsgComponentIdVideo, EUniRegionImage );
       
  2218                             return EKeyWasConsumed;
       
  2219                             }
       
  2220                         case EMsgComponentIdSvg:
       
  2221                             {
       
  2222                             DoUserRemoveMediaL( EMsgComponentIdSvg, EUniRegionImage );
       
  2223                             return EKeyWasConsumed;
       
  2224                             }
       
  2225                         default:
       
  2226                             {
       
  2227                             break;
       
  2228                             }
       
  2229                         }
       
  2230                     }
       
  2231                 break;
       
  2232                 }
       
  2233             default:
       
  2234                 {
       
  2235                 break;
       
  2236                 }
       
  2237             }
       
  2238             
       
  2239         switch ( aKeyEvent.iScanCode )
       
  2240             {
       
  2241             case EStdKeyUpArrow:
       
  2242             case EStdKeyDownArrow:
       
  2243             case EStdKeyLeftArrow:
       
  2244             case EStdKeyRightArrow:
       
  2245             case EStdKeyDevice1: // Close key                
       
  2246             case EStdKeyRightShift: // Shift
       
  2247             case EStdKeyApplication0: // Task switching
       
  2248                 {
       
  2249                 return CMsgEditorAppUi::HandleKeyEventL( aKeyEvent, aType );
       
  2250                 }
       
  2251             default:
       
  2252                 {
       
  2253                 break;
       
  2254                 }
       
  2255             }
       
  2256 
       
  2257         TKeyResponse resp = CMsgEditorAppUi::HandleKeyEventL( aKeyEvent, aType );
       
  2258 
       
  2259         if ( aType == EEventKeyUp )
       
  2260             {
       
  2261             // Check if character inserted to controls
       
  2262             HandleCharInputL();
       
  2263             }
       
  2264 
       
  2265         return resp;
       
  2266         }
       
  2267     else
       
  2268         {
       
  2269         return CMsgEditorAppUi::HandleKeyEventL(aKeyEvent, aType);
       
  2270         }
       
  2271     }
       
  2272 
       
  2273 // ---------------------------------------------------------
       
  2274 // CUniEditorAppUi::HandleCharInputL
       
  2275 // Updates model
       
  2276 // ---------------------------------------------------------
       
  2277 //
       
  2278 void CUniEditorAppUi::HandleCharInputL()
       
  2279     {
       
  2280     if ( IsLaunched() )
       
  2281         {
       
  2282         CMsgBaseControl* ctrl = iView->FocusedControl();
       
  2283         TBool changed = EFalse;
       
  2284 
       
  2285         if ( ctrl )
       
  2286             {
       
  2287             switch ( ctrl->ControlId() )
       
  2288                 {
       
  2289                 case EMsgComponentIdTo:
       
  2290                 case EMsgComponentIdCc:
       
  2291                 case EMsgComponentIdBcc:
       
  2292                     {
       
  2293                     if ( ctrl->IsModified() )
       
  2294                         {
       
  2295                         Document()->SetHeaderModified( ETrue );
       
  2296                         CheckHeaderForMessageTypeL();
       
  2297                         changed = ETrue;
       
  2298                         }
       
  2299                     SetAddressSize();
       
  2300                     break;
       
  2301                     }
       
  2302                 case EMsgComponentIdSubject:
       
  2303                     {
       
  2304                     if ( ctrl->IsModified() )
       
  2305                         {
       
  2306                         Document()->SetHeaderModified( ETrue );
       
  2307                         changed = ETrue;
       
  2308                         }
       
  2309                         
       
  2310                     SetSubjectSize();
       
  2311                     CheckBodyForMessageTypeL();
       
  2312                     CheckMaxSmsSizeAndShowNoteL();
       
  2313                     SetOrRemoveMaxSizeInEdwin();
       
  2314                     break;
       
  2315                     }
       
  2316                 case EMsgComponentIdBody:
       
  2317                     {
       
  2318                     if ( ctrl->IsModified() )
       
  2319                         {
       
  2320                         UpdateSmilTextAttaL();
       
  2321                         Document()->SetBodyModified( ETrue );
       
  2322                         CheckBodyForMessageTypeL();
       
  2323                         CheckMaxSmsSizeAndShowNoteL();
       
  2324                         SetOrRemoveMaxSizeInEdwin();
       
  2325                         changed = ETrue;
       
  2326                         }
       
  2327                     break;
       
  2328                     }
       
  2329                 default:
       
  2330                     {
       
  2331                     // Text control not focused.
       
  2332                     break;
       
  2333                     }
       
  2334                 }
       
  2335             }
       
  2336             
       
  2337         if ( changed )
       
  2338             {
       
  2339             MsgLengthToNavipaneL();
       
  2340             }
       
  2341         }
       
  2342     }
       
  2343 
       
  2344 // ---------------------------------------------------------
       
  2345 // CUniEditorAppUi::HandleForegroundEventL
       
  2346 // 
       
  2347 // Updates navipane at editor start when launched from 
       
  2348 // ---------------------------------------------------------
       
  2349 //
       
  2350 void CUniEditorAppUi::HandleForegroundEventL( TBool aForeground )
       
  2351     {
       
  2352     UNILOGGER_WRITE( "-> CUniEditorAppUi::HandleForegroundEventL" );
       
  2353     
       
  2354     CAknAppUi::HandleForegroundEventL( aForeground );
       
  2355     
       
  2356     if ( IsLaunched() &&
       
  2357          aForeground && 
       
  2358          !IsDisplayingDialog() &&
       
  2359          !( iEditorFlags & ( EEditorExiting | EEditorClosing ) ) )
       
  2360         {
       
  2361         // This must be init.. not MsgLen... Otherwise returning
       
  2362         // from embedded app loses msglength
       
  2363         InitNaviPaneL();
       
  2364         }
       
  2365     
       
  2366     UNILOGGER_WRITE( "-> CUniEditorAppUi::HandleForegroundEventL" );
       
  2367     }
       
  2368 
       
  2369 // ---------------------------------------------------------
       
  2370 // CUniEditorAppUi::UpdateSmilTextAttaL
       
  2371 // 
       
  2372 // NOTE: This function should only be called when text is 
       
  2373 //       added/removed to/from bodycontrol.
       
  2374 // ---------------------------------------------------------
       
  2375 //
       
  2376 void CUniEditorAppUi::UpdateSmilTextAttaL()
       
  2377     {
       
  2378     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  2379     
       
  2380     TInt slideNum = Document()->CurrentSlide();
       
  2381     if ( slideNum < 0 || slideNum >= iSmilModel->SlideCount() )
       
  2382         {
       
  2383         return;
       
  2384         }
       
  2385     
       
  2386     // Update smilmodel
       
  2387     if ( !BodyCtrl() || 
       
  2388          BodyCtrl()->TextContent().DocumentLength() == 0 )
       
  2389         {
       
  2390         // Body control does not exist or it is empty
       
  2391         CUniObject* obj = iSmilModel->GetObject( slideNum, EUniRegionText );
       
  2392         if ( obj )
       
  2393             {
       
  2394             // If there is text atta in presentation it should be removed.
       
  2395             // Note: Text atta is not removed from store at this point (removed in save)
       
  2396             iSmilModel->RemoveObjectL( slideNum, obj );
       
  2397             }
       
  2398         }
       
  2399     else
       
  2400         {
       
  2401         // Text added -> see if model already has text atta
       
  2402         if ( !iSmilModel->GetObject( slideNum, EUniRegionText ) )
       
  2403             {
       
  2404             if ( !iSmilModel->IsSlide( slideNum ) )
       
  2405                 {
       
  2406                 // Add slide
       
  2407                 iSmilModel->AddSlideL( slideNum );
       
  2408                 }
       
  2409             iSmilModel->AddTextObjectL( slideNum,
       
  2410                                         &( BodyCtrl()->Editor() ) );
       
  2411             }
       
  2412         }
       
  2413     }
       
  2414 
       
  2415 // ---------------------------------------------------------
       
  2416 // CUniEditorAppUi::DynInitMenuPaneL
       
  2417 // ---------------------------------------------------------
       
  2418 //
       
  2419 void CUniEditorAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
  2420     {
       
  2421     // Confirm app is running properly (needed atleast now)
       
  2422     if ( !IsLaunched() )
       
  2423         {
       
  2424         // If not, hide everything and return
       
  2425         TInt amountOfItems = aMenuPane->NumberOfItemsInPane();
       
  2426         if ( amountOfItems )
       
  2427             {
       
  2428             aMenuPane->DeleteBetweenMenuItems( 0, amountOfItems-1 );
       
  2429             }
       
  2430         return;
       
  2431         }
       
  2432 
       
  2433     TUint32 objects = ObjectsAvailable();
       
  2434 
       
  2435     switch ( aResourceId ) 
       
  2436         {
       
  2437         case R_UNIEDITOR_MAIN_MENU:
       
  2438             {
       
  2439             // Features always visible:
       
  2440             // EEikCmdExit
       
  2441             // EUniCmdSendingOptions
       
  2442             // EUniCmdMessageInfo
       
  2443 
       
  2444             // Features checked commonly
       
  2445             if ( !( iSupportedFeatures & EUniFeatureHelp ) )
       
  2446                 { 
       
  2447                 // Help
       
  2448                 aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
  2449                 }
       
  2450                 
       
  2451             // Features in locked SMS mode
       
  2452             if ( IsHardcodedSms() )
       
  2453                 { 
       
  2454                 // Dim these items always in locked SMS mode
       
  2455                 aMenuPane->SetItemDimmed( EUniCmdViewImage, ETrue );
       
  2456                 aMenuPane->SetItemDimmed( EUniCmdPlayAudio, ETrue );
       
  2457                 aMenuPane->SetItemDimmed( EUniCmdPlayVideo, ETrue );
       
  2458                 aMenuPane->SetItemDimmed( EUniCmdPlayPres, ETrue );
       
  2459                 aMenuPane->SetItemDimmed( EUniCmdPlaySvg, ETrue );
       
  2460                 aMenuPane->SetItemDimmed( EUniCmdPlayPreview, ETrue );
       
  2461                 aMenuPane->SetItemDimmed( EUniCmdSendMMS, ETrue );
       
  2462                 aMenuPane->SetItemDimmed( EUniCmdInsertMedia, ETrue );
       
  2463                 aMenuPane->SetItemDimmed( EUniCmdPlaceTextFirst, ETrue );
       
  2464                 aMenuPane->SetItemDimmed( EUniCmdPlaceTextSecond, ETrue );
       
  2465                 aMenuPane->SetItemDimmed( EUniCmdMovePage, ETrue );
       
  2466                 aMenuPane->SetItemDimmed( EUniCmdSelectPage, ETrue );
       
  2467                 aMenuPane->SetItemDimmed( EUniCmdChangePriority, ETrue );
       
  2468                 
       
  2469                 if ( Document()->DataModel()->ObjectList().Count() == 0 &&
       
  2470                      Document()->DataModel()->AttachmentList().Count() == 0 )
       
  2471                     {   
       
  2472                     // If no objects -> hide the option
       
  2473                     aMenuPane->SetItemDimmed( EUniCmdObjects, ETrue );
       
  2474                     }
       
  2475                 
       
  2476                 if ( !Document()->EmailOverSmsSupported() ||
       
  2477                      ( iHeader &&  
       
  2478                        !( iHeader->AddHeadersVariation() & EUniFeatureSubjectConfigurable ) ) )
       
  2479                     { 
       
  2480                     // Locked SMS and no email over sms or email over SMS without selectable subject.
       
  2481                     aMenuPane->SetItemDimmed( EUniCmdAddHeaders, ETrue );
       
  2482                     }
       
  2483                 
       
  2484                 if ( !BodyCtrl() )
       
  2485                     {
       
  2486                     aMenuPane->SetItemDimmed( EUniCmdRemoveSubmenu, ETrue );                    
       
  2487                     aMenuPane->SetItemDimmed( EUniCmdInsertSubmenu, ETrue );
       
  2488                     }
       
  2489                 else if ( BodyCtrlEditor()->TextLength() == 0 )
       
  2490                     {
       
  2491                     aMenuPane->SetItemDimmed( EUniCmdRemoveSubmenu, ETrue );                    
       
  2492                     }
       
  2493                 }
       
  2494             else if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
  2495                 {
       
  2496                 // MMS upload message
       
  2497                 aMenuPane->SetItemDimmed( EUniCmdInsertSubmenu, ETrue );
       
  2498                 aMenuPane->SetItemDimmed( EUniCmdAddHeaders, ETrue );
       
  2499                 aMenuPane->SetItemDimmed( EUniCmdAddRecipient, ETrue );                                    
       
  2500                 aMenuPane->SetItemDimmed( EUniCmdChangePriority, ETrue );
       
  2501                 
       
  2502                 if ( Document()->DataModel()->ObjectList().Count() == 0 &&
       
  2503                      Document()->DataModel()->AttachmentList().Count() == 0 )
       
  2504                     {   
       
  2505                     // If no objects -> hide the option
       
  2506                     aMenuPane->SetItemDimmed( EUniCmdObjects, ETrue );
       
  2507                     }
       
  2508                     
       
  2509                 DynInitFocusedMediaBasedOptionsL( aMenuPane );
       
  2510                 }
       
  2511             else 
       
  2512                 {
       
  2513                 // It's automatic mode
       
  2514                 aMenuPane->SetItemDimmed( EUniCmdInsertSubmenu, ETrue );
       
  2515                 
       
  2516                 if ( Document()->DataModel()->ObjectList().Count() == 0 &&
       
  2517                      Document()->DataModel()->AttachmentList().Count() == 0 )
       
  2518                     {   // If no objects -> hide the option
       
  2519                     aMenuPane->SetItemDimmed( EUniCmdObjects, ETrue );
       
  2520                     }
       
  2521                     
       
  2522                 if ( Document()->UniState() == EUniSms )
       
  2523                     {
       
  2524                     // It's currently a SMS message
       
  2525                     aMenuPane->SetItemDimmed( EUniCmdViewImage, ETrue );
       
  2526                     aMenuPane->SetItemDimmed( EUniCmdPlayAudio, ETrue );
       
  2527                     aMenuPane->SetItemDimmed( EUniCmdPlayVideo, ETrue );
       
  2528                     aMenuPane->SetItemDimmed( EUniCmdPlayPres, ETrue );
       
  2529                     aMenuPane->SetItemDimmed( EUniCmdPlaySvg, ETrue );
       
  2530                     aMenuPane->SetItemDimmed( EUniCmdPlayPreview, ETrue );
       
  2531                     aMenuPane->SetItemDimmed( EUniCmdSendMMS, ETrue );
       
  2532                     aMenuPane->SetItemDimmed( EUniCmdPlaceTextFirst, ETrue );
       
  2533                     aMenuPane->SetItemDimmed( EUniCmdPlaceTextSecond, ETrue );
       
  2534                     aMenuPane->SetItemDimmed( EUniCmdPlayPreview, ETrue );                    
       
  2535                     aMenuPane->SetItemDimmed( EUniCmdMovePage, ETrue );  
       
  2536                     aMenuPane->SetItemDimmed( EUniCmdSelectPage, ETrue );                    
       
  2537                     aMenuPane->SetItemDimmed( EUniCmdChangePriority, ETrue );
       
  2538                     if ( !BodyCtrlEditor() || BodyCtrlEditor()->TextLength() == 0 )
       
  2539                         {
       
  2540                         aMenuPane->SetItemDimmed( EUniCmdRemoveSubmenu, ETrue );                    
       
  2541                         }
       
  2542                     }
       
  2543                 else
       
  2544                     { 
       
  2545                     // It's currently a MMS message
       
  2546 					/*
       
  2547                      * Do not show "Sending Options" menu item if:
       
  2548                      * 1. It is a MMS and
       
  2549                      * 2. The feature flag MpMessagingHideMessageTypeId is set
       
  2550                      * This is because when we are composing a MMS, 
       
  2551                      * "Character Support" option is not displayed in "Sending Options"
       
  2552                      * and because of this flag, we are not going to show "Message Type"
       
  2553                      * option as well - resulting in an empty "Sendings Options" dialog.
       
  2554                      * Therefore, it was decided to hide this menu option when
       
  2555                      * composing a MMS (if flag is defined)
       
  2556                      */
       
  2557                     if ( iEditorFlags & EHideMessageTypeOption ||
       
  2558                          iMtm->MessageTypeLocking() == EUniMessageTypeLocked )
       
  2559                         {
       
  2560                         // Also, if message is permanently locked ( to mms ) -> no sending options
       
  2561                         aMenuPane->SetItemDimmed( EUniCmdSendingOptions, ETrue );
       
  2562                         }
       
  2563                         
       
  2564                     if ( !(iSupportedFeatures & EUniFeaturePriority) )
       
  2565                         {
       
  2566                         aMenuPane->SetItemDimmed( EUniCmdChangePriority, ETrue );
       
  2567                         }
       
  2568                         
       
  2569                     // Always visible in MMS message:
       
  2570                     // EUniCmdAddRecipient
       
  2571                     if ( iHeader &&  
       
  2572                          !iHeader->AddHeadersVariation() )
       
  2573                         {
       
  2574                         aMenuPane->SetItemDimmed( EUniCmdAddHeaders, ETrue );
       
  2575                         }
       
  2576                         
       
  2577                     DynInitFocusedMediaBasedOptionsL( aMenuPane );
       
  2578                     }
       
  2579                 }
       
  2580             break;
       
  2581             }
       
  2582         case R_UNIEDITOR_REMOVE_SUBMENU:
       
  2583             {
       
  2584             // Remove submenu is visible only for MMS SMIL messages
       
  2585             if ( !( objects & EUniImageFlag &&
       
  2586                     Document()->DataModel()->SmilType() == EMmsSmil ) )
       
  2587                 {
       
  2588                 aMenuPane->SetItemDimmed( EUniCmdRemoveImage, ETrue );
       
  2589                 }
       
  2590             if ( !( objects & EUniAudioFlag ) ) 
       
  2591                 {
       
  2592                 aMenuPane->SetItemDimmed( EUniCmdRemoveAudio, ETrue );
       
  2593                 }
       
  2594             if ( !( objects & EUniVideoFlag ) ) 
       
  2595                 {
       
  2596                 aMenuPane->SetItemDimmed( EUniCmdRemoveVideo, ETrue );
       
  2597                 }
       
  2598             if ( !( objects & EUniTextFlag ) ) 
       
  2599                 {
       
  2600                 aMenuPane->SetItemDimmed( EUniCmdRemoveText, ETrue );
       
  2601                 }
       
  2602             if ( !( objects & EUniSvgFlag ) ) 
       
  2603                 {
       
  2604                 aMenuPane->SetItemDimmed( EUniCmdRemoveSvg, ETrue );
       
  2605                 }
       
  2606                 
       
  2607             if ( Document()->DataModel()->SmilType() != ETemplateSmil &&
       
  2608                  Document()->DataModel()->SmilType() != E3GPPSmil )
       
  2609                 {
       
  2610                 aMenuPane->SetItemDimmed( EUniCmdRemovePres, ETrue );
       
  2611                 }
       
  2612                 
       
  2613             if ( iSmilModel->SlideCount() <= 1 )
       
  2614                 {
       
  2615                 aMenuPane->SetItemDimmed( EUniCmdRemovePage, ETrue );
       
  2616                 }
       
  2617                 
       
  2618             break;
       
  2619             }
       
  2620         case R_UNIEDITOR_CONTEXT_MENU:
       
  2621             {
       
  2622             if ( Document()->UniState() == EUniSms )
       
  2623                 {
       
  2624                 aMenuPane->SetItemDimmed( EUniCmdSendMMS, ETrue );
       
  2625                 }
       
  2626             else
       
  2627                 {
       
  2628                 aMenuPane->SetItemDimmed( EUniCmdSendSMS, ETrue );
       
  2629                 }
       
  2630             
       
  2631             if ( IsHardcodedSms() )
       
  2632                 {
       
  2633                 aMenuPane->SetItemDimmed( EUniCmdInsertMedia, ETrue );
       
  2634                 }
       
  2635             
       
  2636             if ( !( iSupportedFeatures & EUniFeatureJapanese ) ||
       
  2637                  iSmilModel->SlideCount() <= 1 )
       
  2638                 {
       
  2639                 // Only shown on Japanese variant.
       
  2640                 aMenuPane->SetItemDimmed( EUniCmdSelectPage, ETrue );
       
  2641                 }
       
  2642             
       
  2643             break;
       
  2644             }
       
  2645         case R_UNIEDITOR_ZOOM_SUBMENU:
       
  2646             {
       
  2647             TInt zoomLevel = KErrGeneral;
       
  2648             iMsgEditorAppUiExtension->iSettingCachePlugin.GetValue( KAknLocalZoomLayoutSwitch, 
       
  2649                                                                     zoomLevel );
       
  2650             switch ( zoomLevel )
       
  2651                 {
       
  2652                 case EAknUiZoomAutomatic:
       
  2653                     {
       
  2654                     aMenuPane->SetItemButtonState( EMsgDispSizeAutomatic,
       
  2655                                                    EEikMenuItemSymbolOn );
       
  2656                     break;
       
  2657                     }
       
  2658                 case EAknUiZoomNormal:
       
  2659                     {
       
  2660                     aMenuPane->SetItemButtonState( EMsgDispSizeNormal,
       
  2661                                                    EEikMenuItemSymbolOn );
       
  2662                     break;
       
  2663                     }
       
  2664                 case EAknUiZoomSmall:
       
  2665                     {
       
  2666                     aMenuPane->SetItemButtonState( EMsgDispSizeSmall,
       
  2667                                                    EEikMenuItemSymbolOn );
       
  2668                     break;
       
  2669                     }
       
  2670                 case EAknUiZoomLarge:
       
  2671                     {
       
  2672                     aMenuPane->SetItemButtonState( EMsgDispSizeLarge,
       
  2673                                                    EEikMenuItemSymbolOn );
       
  2674                     break;
       
  2675                     }
       
  2676                 default:
       
  2677                     {
       
  2678                     break;
       
  2679                     }
       
  2680                 }
       
  2681             break;
       
  2682             }
       
  2683         default:
       
  2684             {
       
  2685             break;
       
  2686             }
       
  2687         }
       
  2688     }
       
  2689 
       
  2690 // ---------------------------------------------------------
       
  2691 // CUniEditorAppUi::DynInitFocusedMediaBasedOptionsL
       
  2692 // ---------------------------------------------------------
       
  2693 //
       
  2694 void CUniEditorAppUi::DynInitFocusedMediaBasedOptionsL( CEikMenuPane* aMenuPane )
       
  2695     {
       
  2696     // Lets dim all the context sensitive options first
       
  2697     aMenuPane->SetItemDimmed( EUniCmdViewImage, ETrue );                    
       
  2698     aMenuPane->SetItemDimmed( EUniCmdPlayAudio, ETrue );                    
       
  2699     aMenuPane->SetItemDimmed( EUniCmdPlayVideo, ETrue );                    
       
  2700     aMenuPane->SetItemDimmed( EUniCmdPlayPres, ETrue );
       
  2701     aMenuPane->SetItemDimmed( EUniCmdPlayPreview, ETrue );                    
       
  2702     aMenuPane->SetItemDimmed( EUniCmdSendSMS, ETrue );
       
  2703     aMenuPane->SetItemDimmed( EUniCmdPlaySvg, ETrue );
       
  2704                                     
       
  2705     if ( iView && iView->FocusedControl() )
       
  2706         { 
       
  2707         // And then dim one of them if necessary
       
  2708         switch ( iView->FocusedControl()->ControlId() )
       
  2709             {
       
  2710             case EMsgComponentIdImage:
       
  2711                 {
       
  2712                 if ( Document()->DataModel()->SmilType() == E3GPPSmil )
       
  2713                     { 
       
  2714                     // Non-editable pres
       
  2715                     aMenuPane->SetItemDimmed( EUniCmdPlayPres, EFalse );                                    
       
  2716                     }
       
  2717                 else if( Document()->DataModel()->SmilType() == ETemplateSmil )
       
  2718                     { 
       
  2719                     // Editable press
       
  2720                     aMenuPane->SetItemDimmed( EUniCmdPlayPres, EFalse );                                    
       
  2721                     }
       
  2722                 else
       
  2723                     { 
       
  2724                     // Real image
       
  2725                     aMenuPane->SetItemDimmed( EUniCmdViewImage, EFalse );
       
  2726                     }
       
  2727                 break;                            
       
  2728                 }
       
  2729             case EMsgComponentIdAudio:
       
  2730                 {
       
  2731                 aMenuPane->SetItemDimmed( EUniCmdPlayAudio, EFalse );
       
  2732                 break;                            
       
  2733                 }
       
  2734             case EMsgComponentIdVideo:
       
  2735                 {
       
  2736                 aMenuPane->SetItemDimmed( EUniCmdPlayVideo, EFalse );
       
  2737                 break; 
       
  2738                 }
       
  2739             case EMsgComponentIdSvg:
       
  2740                 {
       
  2741                 aMenuPane->SetItemDimmed( EUniCmdPlaySvg, EFalse );
       
  2742                 break;
       
  2743                 }
       
  2744             default:
       
  2745                 {
       
  2746                 break; 
       
  2747                 }
       
  2748             }
       
  2749         }
       
  2750 
       
  2751     if ( Document()->DataModel()->SmilType() != EMmsSmil ) 
       
  2752         { 
       
  2753         // It's 3GPP presentation
       
  2754         aMenuPane->SetItemDimmed( EUniCmdInsertMedia, ETrue );
       
  2755         aMenuPane->SetItemDimmed( EUniCmdPlaceTextFirst, ETrue );
       
  2756         aMenuPane->SetItemDimmed( EUniCmdPlaceTextSecond, ETrue );
       
  2757         }
       
  2758     else if ( iSupportedFeatures & EUniFeatureJapanese )
       
  2759         {
       
  2760         // Not shown on japanese variant ever.
       
  2761         aMenuPane->SetItemDimmed( EUniCmdPlaceTextFirst, ETrue );
       
  2762         aMenuPane->SetItemDimmed( EUniCmdPlaceTextSecond, ETrue );        
       
  2763         }
       
  2764     else
       
  2765         {
       
  2766         if ( iSmilModel->Layout() == EUniImageFirst )
       
  2767             {
       
  2768             aMenuPane->SetItemDimmed( EUniCmdPlaceTextSecond, ETrue );
       
  2769             }
       
  2770         else
       
  2771             {
       
  2772             aMenuPane->SetItemDimmed( EUniCmdPlaceTextFirst, ETrue );
       
  2773             }
       
  2774         }
       
  2775 
       
  2776     if ( Document()->DataModel()->SmilType() != EMmsSmil || 
       
  2777          iSmilModel->SlideCount() <= 1 )
       
  2778         { 
       
  2779         // No move if not MmsSmil or only one page
       
  2780         aMenuPane->SetItemDimmed( EUniCmdMovePage, ETrue );
       
  2781         aMenuPane->SetItemDimmed( EUniCmdSelectPage, ETrue );
       
  2782         }
       
  2783     else if ( !( iSupportedFeatures & EUniFeatureJapanese ) )
       
  2784         {
       
  2785         // Only shown on Japanese variant.
       
  2786         aMenuPane->SetItemDimmed( EUniCmdSelectPage, ETrue );
       
  2787         }
       
  2788     
       
  2789     if( Document()->DataModel()->SmilType() == EMmsSmil &&
       
  2790         Document()->DataModel()->ObjectList().Count() == 0 && 
       
  2791         iSmilModel->SlideCount() == 1 )
       
  2792         {
       
  2793         aMenuPane->SetItemDimmed( EUniCmdRemoveSubmenu, ETrue );
       
  2794         }
       
  2795     }
       
  2796 
       
  2797 // ---------------------------------------------------------
       
  2798 // CUniEditorAppUi::IsMessageEmpty
       
  2799 // ---------------------------------------------------------
       
  2800 //
       
  2801 TBool CUniEditorAppUi::IsMessageEmpty() const 
       
  2802     {
       
  2803     TBool smil = EFalse;
       
  2804     if ( Document()->DataModel()->SmilType() != EMmsSmil &&
       
  2805          Document()->DataModel()->SmilList().Count() > 0 )
       
  2806         {
       
  2807         smil = ETrue;
       
  2808         }
       
  2809     return !smil &&
       
  2810            IsHeaderEmpty() &&
       
  2811            IsBodyEmpty() &&
       
  2812            Document()->DataModel()->AttachmentList().Count() == 0;
       
  2813     }
       
  2814 
       
  2815 
       
  2816 // ---------------------------------------------------------
       
  2817 // CUniEditorAppUi::DoUserSendL
       
  2818 //
       
  2819 // Message must be unlocked before coming here.
       
  2820 // ---------------------------------------------------------
       
  2821 //
       
  2822 void CUniEditorAppUi::DoUserSendL()
       
  2823     {
       
  2824     // Force FEP Update done only when SMIL is not 3GPP SMIL
       
  2825     if ( Document()->DataModel()->SmilType() == EMmsSmil )
       
  2826         {
       
  2827         if ( BodyCtrl() )
       
  2828             {
       
  2829             BodyCtrl()->SetFocus( EFalse );
       
  2830             }
       
  2831             
       
  2832         iCoeEnv->SyncNotifyFocusObserversOfChangeInFocus();
       
  2833         }
       
  2834     
       
  2835     TUniState currentState = Document()->UniState();
       
  2836     
       
  2837     TBool modified( EFalse );
       
  2838     if ( !VerifyAddressesL( modified ) )
       
  2839         {
       
  2840         // Invalid recipient found  -> abort sending.
       
  2841         return;
       
  2842         }
       
  2843     
       
  2844     if ( modified &&
       
  2845          currentState != Document()->UniState() )
       
  2846         {
       
  2847         if ( !ShowConfirmationQueryL( R_UNIEDITOR_MSG_TYPE_CHANGED_WHILE_SENDING ) )
       
  2848             {
       
  2849             return;
       
  2850             }
       
  2851         }
       
  2852     
       
  2853     // Check MMS message size
       
  2854     if ( TUint( MessageSizeInBytes() ) > Document()->MaxMessageSize() )
       
  2855         {
       
  2856         TInt maxInKilos = ( Document()->MaxMessageSize() + KBytesInKilo - 1 ) / KBytesInKilo;
       
  2857         HBufC* string = StringLoader::LoadLC( R_UNIEDITOR_SEND_BIG_TEXT, 
       
  2858                                               maxInKilos, 
       
  2859                                               iCoeEnv );
       
  2860                                               
       
  2861         CAknInformationNote* note = new ( ELeave ) CAknInformationNote();
       
  2862         note->ExecuteLD( *string );
       
  2863         CleanupStack::PopAndDestroy( string );
       
  2864         return;
       
  2865         }
       
  2866 
       
  2867     // Check the max sms size
       
  2868     CheckMaxSmsSizeAndShowNoteL( ETrue );
       
  2869 
       
  2870     if( iEditorFlags & EMaxSmsSizeNoteShown )
       
  2871         { 
       
  2872         // This flag was set by the funtion call above and it means an error note was shown to user
       
  2873         return;
       
  2874         }
       
  2875 
       
  2876     if( !CheckMaxRecipientsAndShowNoteL( ETrue ) )
       
  2877         { 
       
  2878         // Too many recipients. Info was shown so just return
       
  2879         return;
       
  2880         }
       
  2881     
       
  2882     CUniEditorPlugin* plugin = NULL;
       
  2883     TInt resourceId = NULL;
       
  2884     
       
  2885     // Get the plugin
       
  2886     if( Document()->UniState() == EUniSms )
       
  2887         {
       
  2888         plugin = SmsPlugin();
       
  2889         resourceId = R_QTN_MSG_WAIT_SENDING_SMS;
       
  2890         
       
  2891         // Ask if it's ok to send the message in N parts
       
  2892         if( !ConfirmSmsSendInMultiplePartsL() )
       
  2893             {
       
  2894             return;
       
  2895             }
       
  2896         }
       
  2897     else
       
  2898         {
       
  2899         plugin = MmsPlugin();
       
  2900         resourceId = R_QTN_MSG_WAIT_SENDING_MMS;
       
  2901         }
       
  2902 
       
  2903     if( plugin )
       
  2904         {
       
  2905         TBool checkEmailSettings = EFalse;
       
  2906         if( Document()->EmailOverSmsSupported() && iHeader->LongestEmailAddress() )
       
  2907             {
       
  2908             checkEmailSettings = ETrue;
       
  2909             }
       
  2910         
       
  2911         if ( iFixedToolbar && !plugin->IsServiceValidL() )
       
  2912             {
       
  2913             iFixedToolbar->HideItemsAndDrawOnlyBackground( ETrue );
       
  2914             }
       
  2915         
       
  2916         iEditorFlags |= EToolbarHidden;
       
  2917         CleanupStack::PushL( TCleanupItem( EnableFixedToolbar, this ) );
       
  2918         if (!plugin->IsServiceValidL())
       
  2919         	{
       
  2920         		SetKeyEventFlags(0);
       
  2921         	}
       
  2922             
       
  2923         CleanupStack::PushL( TCleanupItem( DisableSendKey, this ) );
       
  2924         
       
  2925         iMsgLenToVKB = EFalse;
       
  2926         TBool serviceValid( plugin->ValidateServiceL( checkEmailSettings ) );
       
  2927         
       
  2928         CleanupStack::PopAndDestroy(2); //DisableSendKey,EnableFixedToolbar
       
  2929         
       
  2930         if( !serviceValid )
       
  2931             { 
       
  2932             // Settings are not valid (AP/SC missing)
       
  2933             iMsgLenToVKB = ETrue;
       
  2934             return;
       
  2935             }
       
  2936         }
       
  2937     else
       
  2938         {
       
  2939         // The plugin is not ok -> cannot send the message
       
  2940         return;
       
  2941         }
       
  2942 
       
  2943     if( IsPhoneOfflineL() )
       
  2944         {
       
  2945         resourceId = R_QTN_WAIT_MSG_SAVED_OUTBOX;
       
  2946         }
       
  2947 
       
  2948     iSendOperation = CUniEditorSendOperation::NewL( *this,
       
  2949                                                     *Document(),
       
  2950                                                     *iHeader,
       
  2951                                                     *plugin,
       
  2952                                                     *iView,
       
  2953                                                     FsSession() );
       
  2954     ActivateInputBlockerL( iSendOperation );
       
  2955     
       
  2956     ShowWaitNoteL( resourceId ); 
       
  2957 
       
  2958     iEditorFlags |= EEditorClosing;
       
  2959 
       
  2960     iSendOperation->Send();
       
  2961     }
       
  2962 
       
  2963 
       
  2964 // ---------------------------------------------------------
       
  2965 // CUniEditorAppUi::DoMsgSaveExitL
       
  2966 // Exit from option menu 
       
  2967 // ---------------------------------------------------------
       
  2968 //
       
  2969 void CUniEditorAppUi::DoMsgSaveExitL() 
       
  2970     {
       
  2971     if ( CAknEnv::AppWithShutterRunning() )
       
  2972         {
       
  2973         iEditorFlags |= ERunAppShutterAtExit;
       
  2974         }
       
  2975     
       
  2976     delete iLaunchOperation;
       
  2977     iLaunchOperation = NULL;
       
  2978     
       
  2979     delete iSendOperation;
       
  2980     iSendOperation = NULL;
       
  2981     
       
  2982     delete iInsertOperation;
       
  2983     iInsertOperation = NULL;        
       
  2984     
       
  2985     delete iChangeSlideOperation;
       
  2986     iChangeSlideOperation = NULL;
       
  2987     
       
  2988     delete iVCardOperation;
       
  2989     iVCardOperation = NULL;
       
  2990     
       
  2991     if ( IsMessageEmpty() )
       
  2992         {
       
  2993         DeleteCurrentEntryL();
       
  2994         }
       
  2995     else if ( ( Document()->Modified() || 
       
  2996                 Document()->PrevSaveType() < EClosingSave ) && 
       
  2997               CanSaveMessageL() )
       
  2998         {
       
  2999         // Needs saving
       
  3000         if ( IsForeground() )
       
  3001             {
       
  3002             TInt resId = Document()->Saved() ? R_QTN_UNI_WAIT_SAVING_MESSAGE : 
       
  3003                                                R_QTN_UNI_WAIT_SAVING_MESSAGE_NEW;
       
  3004             // Cannot trap call below.
       
  3005             DoSaveL( EClosingSave );
       
  3006             iEditorFlags |= EEditorClosing;
       
  3007             
       
  3008             ShowWaitNoteL( resId );
       
  3009             }
       
  3010         else
       
  3011             {
       
  3012             TInt err(KErrNone);
       
  3013             TRAP( err, DoSaveL( EClosingSave ) );
       
  3014             }
       
  3015             
       
  3016         BeginActiveWait( iSaveOperation );
       
  3017         if ( iEditorFlags & ERunAppShutterAtExit )
       
  3018             {
       
  3019             RunAppShutter();
       
  3020             }
       
  3021         }
       
  3022     }
       
  3023 
       
  3024 // ---------------------------------------------------------
       
  3025 // CUniEditorAppUi::ExitAndSaveL
       
  3026 // ---------------------------------------------------------
       
  3027 //
       
  3028 void CUniEditorAppUi::ExitAndSaveL()
       
  3029     {
       
  3030     if ( iEditorFlags & EEditorClosing )
       
  3031         {
       
  3032         Exit( EAknSoftkeyClose );
       
  3033         return;
       
  3034         }
       
  3035         
       
  3036     if ( CAknEnv::AppWithShutterRunning() )
       
  3037         {
       
  3038         iEditorFlags |= ERunAppShutterAtExit;
       
  3039         }
       
  3040         
       
  3041     if ( iEditorFlags & ELaunchSuccessful &&  
       
  3042          Document()->MediaAvailable() )
       
  3043         {
       
  3044         DoMsgSaveExitL();
       
  3045         }
       
  3046         
       
  3047     Exit(); 
       
  3048     }
       
  3049 
       
  3050 // ---------------------------------------------------------
       
  3051 // CUniEditorAppUi::DoBackSaveL
       
  3052 // Back button implementation
       
  3053 // ---------------------------------------------------------
       
  3054 //
       
  3055 void CUniEditorAppUi::DoBackSaveL()
       
  3056     {
       
  3057     if ( IsMessageEmpty() ) 
       
  3058         {
       
  3059         if ( iMtm->Entry().Entry().Visible() )
       
  3060             {
       
  3061             ShowInformationNoteL( R_UNIEDITOR_INFO_DELETED, ETrue );
       
  3062             }
       
  3063         DeleteAndExitL();
       
  3064         }
       
  3065     else
       
  3066         {
       
  3067         TInt closeVal = ShowCloseQueryL();
       
  3068         if ( closeVal == EMsgCloseCancel )
       
  3069             {
       
  3070             return;
       
  3071             }
       
  3072         else if ( closeVal == EMsgCloseDelete )
       
  3073             {
       
  3074             ReleaseImage( ETrue );
       
  3075             DeleteAndExitL();
       
  3076             }
       
  3077         else // closeVal == EMsgCloseSave
       
  3078             {
       
  3079             // Message has data
       
  3080             if ( Document()->Modified() || Document()->PrevSaveType() < EClosingSave )
       
  3081                 {
       
  3082                 if ( CanSaveMessageL() )
       
  3083                     {
       
  3084                     TInt resId = Document()->Saved() ? R_QTN_UNI_WAIT_SAVING_MESSAGE : 
       
  3085                                                        R_QTN_UNI_WAIT_SAVING_MESSAGE_NEW;
       
  3086                     DoSaveL( EClosingSave );
       
  3087                     iEditorFlags |= EEditorClosing;
       
  3088                     
       
  3089                     ShowWaitNoteL( resId );
       
  3090                     }
       
  3091                 else
       
  3092                     {
       
  3093                     if ( ShowConfirmationQueryL( R_UNIEDITOR_QUEST_CLOSE_OOD ) )
       
  3094                         {
       
  3095                         // Exit without saving.
       
  3096                         Exit( EAknSoftkeyClose );
       
  3097                         }
       
  3098                     //else nothing.
       
  3099                     }
       
  3100                 }
       
  3101             else
       
  3102                 {
       
  3103                 // No changes -> just go away.
       
  3104                 Exit( EAknSoftkeyClose );
       
  3105                 }
       
  3106             }
       
  3107         }
       
  3108     }   
       
  3109 
       
  3110 // ---------------------------------------------------------
       
  3111 // CUniEditorAppUi::CanSaveMessageL
       
  3112 // Checks whether there's enough diskspace to save the
       
  3113 // message.
       
  3114 // ---------------------------------------------------------
       
  3115 //
       
  3116 TBool CUniEditorAppUi::CanSaveMessageL() const
       
  3117     {
       
  3118     TInt bytes = Document()->AddressSize() + Document()->SubjectSize();
       
  3119     
       
  3120     if ( Document()->DataModel()->SmilType() == EMmsSmil )
       
  3121         {
       
  3122         bytes += Document()->DataModel()->ObjectList().SpaceNeededForSaveAll();
       
  3123         bytes += Document()->DataModel()->AttachmentList().SpaceNeededForSaveAll();
       
  3124         bytes += iSmilModel->SmilComposeSize();
       
  3125         }
       
  3126         
       
  3127     return !( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( Document()->Session(),
       
  3128                                                                    bytes ) );
       
  3129     }
       
  3130 
       
  3131 // ---------------------------------------------------------
       
  3132 // CUniEditorAppUi::DoSaveL
       
  3133 // Saves message to OUTBOX.
       
  3134 // Message should be unlocked before coming here.
       
  3135 // ---------------------------------------------------------
       
  3136 //
       
  3137 void CUniEditorAppUi::DoSaveL( TUniSaveType aSaveType ) 
       
  3138     {
       
  3139     if ( iSaveOperation && 
       
  3140          iSaveOperation->IsActive() )
       
  3141         {
       
  3142         // To avoid starting save operation when there is already one running.
       
  3143         return;
       
  3144         }
       
  3145         
       
  3146     if ( !CanSaveMessageL() )
       
  3147         {
       
  3148         User::Leave( KErrDiskFull );
       
  3149         }
       
  3150 
       
  3151     delete iSaveOperation;
       
  3152     iSaveOperation = NULL;
       
  3153     iSaveOperation = CUniEditorSaveOperation::NewL(
       
  3154         *this,
       
  3155         *Document(),
       
  3156         *iHeader,
       
  3157         *iView,
       
  3158         FsSession() );
       
  3159     
       
  3160     iSaveOperation->Save( aSaveType );
       
  3161     
       
  3162     ActivateInputBlockerL( iSaveOperation );
       
  3163     }
       
  3164 
       
  3165 // ---------------------------------------------------------
       
  3166 // CUniEditorAppUi::VerifyAddressesL
       
  3167 //
       
  3168 // Walks thru addresses in addresscontrol and counts errors. 
       
  3169 // If unverified address is valid, marks it validated (verified now). 
       
  3170 // Stops to first error.
       
  3171 // ---------------------------------------------------------
       
  3172 //
       
  3173 TBool CUniEditorAppUi::VerifyAddressesL( TBool& aModified )
       
  3174     {
       
  3175     if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
  3176         {
       
  3177         // Don't check the recipient in "Upload" case.
       
  3178         return ETrue;
       
  3179         }
       
  3180         
       
  3181     iCoeEnv->SyncNotifyFocusObserversOfChangeInFocus();
       
  3182     
       
  3183     aModified = EFalse;
       
  3184 
       
  3185     TBool retVal = iHeader->VerifyAddressesL( aModified, AcceptEmailAddresses() );
       
  3186 
       
  3187     if ( aModified )
       
  3188         {
       
  3189         Document()->SetHeaderModified( ETrue );
       
  3190         CheckHeaderForMessageTypeL();
       
  3191         
       
  3192         SetAddressSize();
       
  3193         MsgLengthToNavipaneL();
       
  3194         }
       
  3195 
       
  3196     if ( !retVal )
       
  3197         {        
       
  3198         //We'll get here if there's illegal addresses
       
  3199         //when selecting send from not-first slide 
       
  3200         for (TInt i = CUniEditorHeader::EHeaderAddressTo; 
       
  3201             i <= CUniEditorHeader::EHeaderAddressBcc; i++ )
       
  3202             { 
       
  3203             TBool jumpOut( EFalse );
       
  3204             if ( iHeader->AddressControl( static_cast<CUniEditorHeader::THeaderFields>( i ) ) )               
       
  3205                 {
       
  3206                 // Search first invalid address
       
  3207                 CMsgRecipientArray* recipients = iHeader->AddressControl( static_cast<CUniEditorHeader::THeaderFields>( i ) )->GetRecipientsL();
       
  3208                 TInt addrCnt = recipients->Count();
       
  3209 
       
  3210                 for ( TInt k = 0; k < addrCnt ; k++ )
       
  3211                     {
       
  3212                     CMsgRecipientItem* addrItem = recipients->At(k);
       
  3213                     
       
  3214                     if (    addrItem 
       
  3215                         &&  !addrItem->IsValidated() )
       
  3216                         {     
       
  3217                         iNextFocus =  iHeader->AddressControlId( 
       
  3218                                         static_cast<CUniEditorHeader::THeaderFields>( i ) );
       
  3219                         if ( Document()->CurrentSlide() )
       
  3220                             {
       
  3221                             DoUserChangeSlideL( 0 );
       
  3222                             }
       
  3223                         else
       
  3224                             {
       
  3225                             DoSetFocusL();
       
  3226                             }
       
  3227                             
       
  3228                         TInt ret = iHeader->AddressControl( static_cast<CUniEditorHeader::THeaderFields> (i ) )
       
  3229                                         ->HighlightUnvalidatedStringL();
       
  3230                         if ( !ret )
       
  3231                             {
       
  3232                             // highlight succeeded
       
  3233                             jumpOut = ETrue;
       
  3234                             break;
       
  3235                             }
       
  3236                         // else - highlight failed. Should not occur...
       
  3237                         }
       
  3238                     }
       
  3239                     // else - recipient OK. Continue searching
       
  3240                 if ( jumpOut )
       
  3241                     {
       
  3242                     break;
       
  3243                     }
       
  3244                 }
       
  3245             // else - address control does not exist
       
  3246             }
       
  3247         }
       
  3248     // else - addresses OK
       
  3249 
       
  3250     return retVal;
       
  3251     }
       
  3252 
       
  3253 // ---------------------------------------------------------
       
  3254 // CUniEditorAppUi::DoUserMoveOrSelectPageL
       
  3255 // ---------------------------------------------------------
       
  3256 //
       
  3257 void CUniEditorAppUi::DoUserMoveOrSelectPageL( TBool aMovePage )
       
  3258     {
       
  3259     // Create listbox    
       
  3260     CAknSingleGraphicPopupMenuStyleListBox* listBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox;
       
  3261     CleanupStack::PushL( listBox );
       
  3262     
       
  3263     // Create popup
       
  3264     CAknPopupList* popup = CAknPopupList::NewL(  listBox, 
       
  3265                                                  R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT, 
       
  3266                                                  AknPopupLayouts::EMenuGraphicWindow );
       
  3267     CleanupStack::PushL( popup );
       
  3268 
       
  3269     // Construct listbox
       
  3270     listBox->ConstructL( popup, CEikListBox::ELeftDownInViewRect );
       
  3271     listBox->CreateScrollBarFrameL( ETrue );
       
  3272     listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
  3273                                                         CEikScrollBarFrame::EAuto );
       
  3274     
       
  3275     if( iSmilModel->SlideCount() > 6 )
       
  3276         {
       
  3277         listBox->CreateScrollBarFrameL( ETrue );
       
  3278         listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
  3279                                                             CEikScrollBarFrame::EAuto );
       
  3280         }
       
  3281   
       
  3282     TInt oldSlide = Document()->CurrentSlide();
       
  3283 
       
  3284     // Set title    
       
  3285     HBufC* title = NULL;
       
  3286     if ( aMovePage )
       
  3287         {
       
  3288         title = StringLoader::LoadLC( R_UNI_MOVE_PAGE_TITLE, oldSlide+1, iCoeEnv );
       
  3289         }
       
  3290     else
       
  3291         {
       
  3292         title = StringLoader::LoadLC( R_UNI_SELECT_PAGE_TITLE, iCoeEnv );
       
  3293         }
       
  3294     popup->SetTitleL( title->Des() );
       
  3295     CleanupStack::PopAndDestroy( title );
       
  3296 
       
  3297     CAknIconArray* iconArray = RadioButtonArrayL();
       
  3298     listBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray ); // FormattedCellData owns
       
  3299 
       
  3300     listBox->HandleItemAdditionL();
       
  3301 
       
  3302     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 5 );
       
  3303     CleanupStack::PushL( array );
       
  3304     
       
  3305     for ( TInt i = 0; i < iSmilModel->SlideCount(); i++ )
       
  3306         {
       
  3307         HBufC* buf = StringLoader::LoadLC( R_UNIEDITOR_MOVE_PAGE, i + 1, iCoeEnv );
       
  3308 
       
  3309         TBuf<20> itemString;
       
  3310         if( oldSlide == i )
       
  3311             { // This one is selected
       
  3312             itemString.AppendNum( 1 );
       
  3313             }
       
  3314         else
       
  3315             {
       
  3316             itemString.AppendNum( 0 );
       
  3317             }
       
  3318         itemString.Append( _L("\t") );
       
  3319         itemString.Append( buf->Des() );
       
  3320         array->AppendL( itemString );
       
  3321         
       
  3322         CleanupStack::PopAndDestroy( buf );
       
  3323         buf = NULL;
       
  3324         }
       
  3325 
       
  3326     CTextListBoxModel* model = listBox->Model();
       
  3327     model->SetItemTextArray( array );
       
  3328     model->SetOwnershipType( ELbmOwnsItemArray );
       
  3329     CleanupStack::Pop( array ); // model owns it now
       
  3330 
       
  3331     listBox->SetCurrentItemIndexAndDraw( oldSlide );
       
  3332 
       
  3333     TInt result = popup->ExecuteLD();
       
  3334 
       
  3335     if ( result )
       
  3336         {
       
  3337         // OK, user chose a new page
       
  3338         TInt newSlide = listBox->CurrentItemIndex();
       
  3339          
       
  3340         if( oldSlide != newSlide )
       
  3341             {
       
  3342             if ( aMovePage )
       
  3343                 {
       
  3344                 iSmilModel->MoveSlideL( Document()->CurrentSlide(), newSlide );
       
  3345                 }
       
  3346 
       
  3347             //Set current slide to invalid in order
       
  3348             //to prevent false events coming to wrong slides
       
  3349             Document()->SetCurrentSlide( -1 );
       
  3350             iView->SetScrollParts( iSmilModel->SlideCount() );
       
  3351             iView->SetCurrentPart( newSlide );
       
  3352 
       
  3353             DoUserChangeSlideL( newSlide );
       
  3354             
       
  3355             if ( aMovePage )
       
  3356                 {
       
  3357                 Document()->SetBodyModified( ETrue );
       
  3358                 }
       
  3359             }
       
  3360         }
       
  3361 
       
  3362     CleanupStack::Pop(); // for popup
       
  3363     CleanupStack::PopAndDestroy( listBox );
       
  3364     }
       
  3365 
       
  3366 // ---------------------------------------------------------
       
  3367 // CUniEditorAppUi::DoUserObjectsViewL
       
  3368 // ---------------------------------------------------------
       
  3369 //
       
  3370 void CUniEditorAppUi::DoUserObjectsViewL( TBool aFocusAttachments )
       
  3371     {
       
  3372     CUniObjectsModel& objectsViewModel =
       
  3373         static_cast<CUniObjectsModel&>( Document()->AttachmentModel() );
       
  3374 
       
  3375     CAknInputBlock::NewLC();
       
  3376 
       
  3377     if ( Document()->DataModel()->SmilType() == EMmsSmil && 
       
  3378          Document()->BodyModified() )
       
  3379         {
       
  3380         delete iSaveOperation;
       
  3381         iSaveOperation = NULL;
       
  3382         
       
  3383         iSaveOperation = CUniEditorSaveOperation::NewL(
       
  3384             *this,
       
  3385             *Document(),
       
  3386             *iHeader,
       
  3387             *iView,
       
  3388             FsSession() );
       
  3389         
       
  3390         
       
  3391         // Save current slide text object as content needs to be up-to-date when
       
  3392         // it is opened from object's view.
       
  3393         CUniObject* textObject = iSmilModel->GetObject( Document()->CurrentSlide(), EUniRegionText );
       
  3394         if ( textObject )
       
  3395             {
       
  3396             iSaveOperation->SaveL( *textObject );
       
  3397             BeginActiveWait( iSaveOperation );
       
  3398             }
       
  3399         }
       
  3400 
       
  3401     CMsgBaseControl* imageBase = iView->ControlById( EMsgComponentIdImage );
       
  3402     if ( imageBase )
       
  3403         {
       
  3404         //Close image file (share flag conflict)
       
  3405         CMsgImageControl* imageControl =
       
  3406             static_cast<CMsgImageControl*>( imageBase );
       
  3407         //Closes image, no matter if animation or not
       
  3408         imageControl->Stop();
       
  3409         //No need to reopen image file
       
  3410         }
       
  3411 
       
  3412     iOriginalSlide = Document()->CurrentSlide();
       
  3413   
       
  3414     TUniObjectsDialogExitCmd dlgRet = EUniObjectsViewBack;
       
  3415     // Flag is also used to judge whether toolbar update is done 
       
  3416     iEditorFlags |= EDoNotUpdateTitlePane;
       
  3417     
       
  3418     CUniObjectsViewDialog::TUniObjectsDialogType dialogType;
       
  3419     if ( Document()->DataModel()->SmilType() == EMmsSmil )
       
  3420         {
       
  3421         dialogType = CUniObjectsViewDialog::EEditor;
       
  3422         }
       
  3423     else
       
  3424         {
       
  3425         dialogType = CUniObjectsViewDialog::EForward;
       
  3426         }
       
  3427     
       
  3428     TInt focusedItemIndex = -1;
       
  3429     if ( aFocusAttachments )
       
  3430         {
       
  3431         TInt objectCount = Document()->DataModel()->ObjectList().Count();
       
  3432         if ( objectCount == 0 )
       
  3433             {
       
  3434             focusedItemIndex = 1;
       
  3435             }
       
  3436         else
       
  3437             {
       
  3438             focusedItemIndex = objectCount;
       
  3439             }
       
  3440         }
       
  3441     
       
  3442     if ( iFixedToolbar )
       
  3443         {
       
  3444         SetFixedToolbarDimmed();
       
  3445         }
       
  3446     
       
  3447     CleanupStack::PushL( TCleanupItem( UpdateFixedToolbar, this ) );
       
  3448    	SetKeyEventFlags(0);
       
  3449     
       
  3450     CleanupStack::PushL( TCleanupItem( DisableSendKey, this ) );
       
  3451     
       
  3452     CUniObjectsViewDialog::ObjectsViewL(
       
  3453             dialogType, 
       
  3454             objectsViewModel,
       
  3455             iEikonEnv,
       
  3456             dlgRet,
       
  3457             *Document()->DataModel(),
       
  3458             focusedItemIndex );
       
  3459     
       
  3460     CleanupStack::PopAndDestroy(2); //DisableSendKey,EnableFixedToolbar
       
  3461     
       
  3462     iEditorFlags &= ~EDoNotUpdateTitlePane;
       
  3463 
       
  3464     Document()->SetCurrentSlide( iOriginalSlide );
       
  3465     iOriginalSlide = -1;
       
  3466 
       
  3467     // Check if msg type was changed
       
  3468     CheckBodyForMessageTypeL(); 
       
  3469     
       
  3470     // Update navipane here instead of AddObjectL callback otherwise it 
       
  3471     // gets drawn while in objectsview
       
  3472     UpdateIndicatorIconsL();
       
  3473     
       
  3474     CheckLockedSmsWithAttaL();
       
  3475     
       
  3476     CleanupStack::PopAndDestroy(); // CAknInputBlock
       
  3477     
       
  3478     objectsViewModel.Reset();
       
  3479     MsgLengthToNavipaneL( ETrue );
       
  3480     }
       
  3481 
       
  3482 // ---------------------------------------------------------
       
  3483 // CUniEditorAppUi::DoUserAddRecipientL
       
  3484 // Fetch an address from phonebook
       
  3485 // ---------------------------------------------------------
       
  3486 //
       
  3487 void CUniEditorAppUi::DoUserAddRecipientL()
       
  3488     {
       
  3489     TBool invalid = EFalse;
       
  3490     // We remove this flag so that it can be shown after the adding operation
       
  3491     iEditorFlags &= ~EMaxRecipientShown;
       
  3492 
       
  3493 	if(iEditorFlags & EMsgEditInProgress)
       
  3494         {
       
  3495         return;
       
  3496         }
       
  3497     if ( iFixedToolbar )
       
  3498         {
       
  3499         SetFixedToolbarDimmed();    
       
  3500         }
       
  3501 
       
  3502     iEditorFlags |= (EMsgEditInProgress);
       
  3503     CleanupStack::PushL( TCleanupItem( UpdateFixedToolbar, this ) );
       
  3504     
       
  3505     SetKeyEventFlags(0);    
       
  3506     CleanupStack::PushL( TCleanupItem( DisableSendKey, this ) );
       
  3507     // add to current control or To control
       
  3508     TBool addressesAdded(EFalse);
       
  3509     TRAP_IGNORE( addressesAdded = iHeader->AddRecipientL(  iView->FocusedControl(), 
       
  3510                                                     iView, 
       
  3511                                                     AcceptEmailAddresses(),
       
  3512                                                     invalid ));
       
  3513     
       
  3514     CleanupStack::PopAndDestroy(2);//DisableSendKey,UpdateFixedToolbar
       
  3515     iEditorFlags &= ~EMsgEditInProgress;
       
  3516 
       
  3517     TInt focused = iHeader->FocusedAddressField( iView->FocusedControl() );
       
  3518 
       
  3519     if ( addressesAdded )
       
  3520         {
       
  3521         Document()->SetHeaderModified( ETrue );
       
  3522 
       
  3523         if ( Document()->CurrentSlide() )
       
  3524             {
       
  3525             // Addresses were (tried to be) added
       
  3526             // -> Change to first slide
       
  3527             iNextFocus = EMsgComponentIdTo;
       
  3528             DoUserChangeSlideL( 0 );
       
  3529             }
       
  3530 
       
  3531         SetAddressSize(); 
       
  3532         MsgLengthToNavipaneL();
       
  3533         
       
  3534         if ( focused == KErrNotFound ||
       
  3535              iEditorFlags & ELockedSmsWithAtta )
       
  3536             {
       
  3537             if ( focused != CUniBaseHeader::EHeaderAddressTo )
       
  3538                 {
       
  3539                 // Focus was not in address control -> Move it
       
  3540                 iView->SetFocus( EMsgComponentIdTo );
       
  3541                 }
       
  3542                 
       
  3543             // Set bodytext cursor location to start of the text
       
  3544             CMsgBodyControl* bodyCtrl = BodyCtrl();
       
  3545             if ( bodyCtrl )
       
  3546                 {
       
  3547                 bodyCtrl->SetCursorPosL( 0 );
       
  3548                 }
       
  3549             focused = CUniBaseHeader::EHeaderAddressTo;
       
  3550             }
       
  3551         else 
       
  3552             {
       
  3553         // Increase by one so it will be in the next field
       
  3554             switch( focused+1 )
       
  3555                 {
       
  3556                 case CUniBaseHeader::EHeaderAddressCc:
       
  3557                     {
       
  3558                     if( iHeader->AddressControl( CUniBaseHeader::EHeaderAddressCc ) )
       
  3559                         {
       
  3560                         iView->SetFocus( EMsgComponentIdCc );
       
  3561                         break;
       
  3562                         }
       
  3563                     } // otherwise fall through
       
  3564                 case CUniBaseHeader::EHeaderAddressBcc:
       
  3565                     {
       
  3566                     if( iHeader->AddressControl( CUniBaseHeader::EHeaderAddressBcc ) )
       
  3567                         {
       
  3568                         iView->SetFocus( EMsgComponentIdBcc );
       
  3569                         break;
       
  3570                         }
       
  3571                     } // otherwise fall through
       
  3572                 case CUniBaseHeader::EHeaderSubject:
       
  3573                     {
       
  3574                     if( iHeader->SubjectControl() )
       
  3575                         {
       
  3576                         iView->SetFocus( EMsgComponentIdSubject );
       
  3577                         break;
       
  3578                         }
       
  3579                     } // otherwise fall through
       
  3580                 default:
       
  3581                     {
       
  3582                     if ( Document()->DataModel()->SmilType() == EMmsSmil )
       
  3583                         {
       
  3584                         iView->SetFocus( EMsgComponentIdBody );                    
       
  3585                         
       
  3586                         // Set bodytext cursor location to end of the text
       
  3587                         CMsgBodyControl* bodyCtrl = BodyCtrl();
       
  3588                         if ( bodyCtrl )
       
  3589                             {
       
  3590                             bodyCtrl->SetCursorPosL( bodyCtrl->Editor().TextLength() );
       
  3591                             }
       
  3592                         }
       
  3593                     else
       
  3594                         {
       
  3595                         iView->SetFocus( EMsgComponentIdImage );
       
  3596                         }
       
  3597                     }
       
  3598                 }
       
  3599             }
       
  3600         }
       
  3601     // Check max recipients anyway
       
  3602     CheckHeaderForMessageTypeL();
       
  3603     MsgLengthToNavipaneL();
       
  3604 
       
  3605     CheckMaxRecipientsAndShowNoteL();
       
  3606 
       
  3607     if( iEditorFlags & EMaxRecipientShown && addressesAdded )
       
  3608         { // A note was shown so return the focus back to the original location
       
  3609         TInt returnFocusTo = EMsgComponentIdTo;
       
  3610         if( focused == CUniBaseHeader::EHeaderAddressCc )
       
  3611             {
       
  3612             returnFocusTo = EMsgComponentIdCc;
       
  3613             }
       
  3614         else if( focused == CUniBaseHeader::EHeaderAddressBcc )
       
  3615             {
       
  3616             returnFocusTo = EMsgComponentIdBcc;
       
  3617             }
       
  3618         iView->SetFocus( returnFocusTo );
       
  3619         }
       
  3620     }
       
  3621 
       
  3622 // ---------------------------------------------------------
       
  3623 // CUniEditorAppUi::DoUserMessageInfoL
       
  3624 // 
       
  3625 // Invokes message info from UI MTM.
       
  3626 // Message must be unlocked before coming here.
       
  3627 // ---------------------------------------------------------
       
  3628 //
       
  3629 void CUniEditorAppUi::DoUserMessageInfoL()
       
  3630     {
       
  3631     CUniEditorDocument* doc = Document();
       
  3632     
       
  3633     CUniMtmUi& uiMtm = doc->MtmUiL();
       
  3634 
       
  3635     CAknInputBlock::NewLC();
       
  3636 
       
  3637     iHeader->CopyHeadersToMtmL( doc->HeaderModified(),
       
  3638                                 ETrue );
       
  3639 
       
  3640     // Lets put the current message type into TMsvEntry
       
  3641     TMsvEntry tEntry = doc->Entry();
       
  3642 
       
  3643     TUniMessageCurrentType curType = EUniMessageCurrentTypeSms;
       
  3644     if( doc->UniState() == EUniMms )
       
  3645         {
       
  3646         curType = EUniMessageCurrentTypeMms;
       
  3647         
       
  3648         CUniEditorPlugin* mmsPlugin = doc->MmsPlugin();
       
  3649             
       
  3650         if ( mmsPlugin )
       
  3651             {
       
  3652             TUniSendingSettings settings;
       
  3653             mmsPlugin->GetSendingSettingsL( settings );
       
  3654             switch ( settings.iPriority )
       
  3655                 {
       
  3656                 case TUniSendingSettings::EUniPriorityHigh:
       
  3657                     {
       
  3658                     tEntry.SetPriority( EMsvHighPriority );
       
  3659                     break;
       
  3660                     }
       
  3661                 case TUniSendingSettings::EUniPriorityLow:
       
  3662                     {
       
  3663                     tEntry.SetPriority( EMsvLowPriority );
       
  3664                     break;
       
  3665                     }
       
  3666                 default:
       
  3667                     {
       
  3668                     tEntry.SetPriority( EMsvMediumPriority );
       
  3669                     break;
       
  3670                     }
       
  3671                 }
       
  3672             }
       
  3673         }
       
  3674 
       
  3675     TUniMsvEntry::SetCurrentMessageType( tEntry, curType );
       
  3676     
       
  3677     doc->CurrentEntry().ChangeL( tEntry );
       
  3678     
       
  3679     if ( !iMtm->Entry().HasStoreL() )
       
  3680         {
       
  3681         iMtm->SaveMessageL();
       
  3682         }
       
  3683     
       
  3684     // Pack message size
       
  3685     TInt sizeInKilos = ( MessageSizeInBytes() + KBytesInKilo - 1 ) / KBytesInKilo;
       
  3686     TPckgBuf<TInt> param( sizeInKilos );
       
  3687 
       
  3688     //These are not used! They just have to be there
       
  3689     CMsvEntrySelection* selection = new ( ELeave ) CMsvEntrySelection;
       
  3690     CleanupStack::PushL( selection );
       
  3691 
       
  3692     CMsvSingleOpWatcher* watch = CMsvSingleOpWatcher::NewLC( *Document() );
       
  3693     CMsvOperation* op = uiMtm.InvokeAsyncFunctionL(
       
  3694         KMtmUiFunctionMessageInfo,
       
  3695         *selection,
       
  3696         watch->iStatus,
       
  3697         param );
       
  3698     CleanupStack::Pop(); // watch
       
  3699     Document()->AddSingleOperationL( op, watch );
       
  3700 
       
  3701     CleanupStack::PopAndDestroy( 2 ); // selection, CAknInputBlock
       
  3702 
       
  3703     MsgLengthToNavipaneL();
       
  3704     }
       
  3705 
       
  3706 // ---------------------------------------------------------
       
  3707 // CUniEditorAppUi::DoUserSendingOptionsL
       
  3708 // 
       
  3709 // Invokes Sending Options from UI MTM.
       
  3710 // ---------------------------------------------------------
       
  3711 //
       
  3712 void CUniEditorAppUi::DoUserSendingOptionsL()
       
  3713     {
       
  3714     TInt flags = 0;
       
  3715 
       
  3716     TUniSendingSettings settings;
       
  3717     
       
  3718     CUniEditorPlugin* plugin = SmsPlugin();
       
  3719 
       
  3720     TBool currentlyLockedToSms = EFalse;
       
  3721 
       
  3722     if( plugin )
       
  3723         { 
       
  3724         // This should be available as if it's not -> sending options not available
       
  3725         plugin->GetSendingSettingsL( settings );
       
  3726         }
       
  3727 
       
  3728     //TUniSendingSettings::TUniMessageType origMessageType = settings.iMessageType;
       
  3729     
       
  3730     if( iMtm->MessageTypeLocking() == EUniMessageTypeLocked )
       
  3731         { 
       
  3732         // Pre-locked to SMS (We never get here in permanent MMS)
       
  3733         flags |= EUniSettingsPermanentSms;
       
  3734         currentlyLockedToSms = ETrue;
       
  3735         }
       
  3736     else if( iMtm->MessageTypeSetting() == EUniMessageTypeSettingSms && 
       
  3737              settings.iMessageType != TUniSendingSettings::EUniMessageTypeAutomatic &&
       
  3738              settings.iMessageType != TUniSendingSettings::EUniMessageTypeMultimedia )
       
  3739         { 
       
  3740         // msg type is temporarily locked to sms
       
  3741         currentlyLockedToSms = ETrue;
       
  3742         }
       
  3743     else
       
  3744         { 
       
  3745         if( iMtm->MessageTypeSetting() == EUniMessageTypeSettingMms )
       
  3746             {
       
  3747             settings.iMessageType = TUniSendingSettings::EUniMessageTypeMultimedia;
       
  3748             }
       
  3749         else if( iMtm->MessageTypeSetting() == EUniMessageTypeSettingAutomatic )
       
  3750             {
       
  3751             settings.iMessageType = TUniSendingSettings::EUniMessageTypeAutomatic;
       
  3752             }
       
  3753         }
       
  3754 
       
  3755     CUniEditorDocument* doc = Document();
       
  3756 
       
  3757     if ( !( IsBodySmsCompatibleL( EFalse ) && iHeader->IsHeaderSmsL() ) )
       
  3758         {
       
  3759         flags |= EUniSettingsContentNeedsMms;
       
  3760         }
       
  3761       
       
  3762     TUniSendingSettings::TUniCharSupport origCharSet = TUniSendingSettings::EUniCharSupportReduced;
       
  3763       
       
  3764     settings.iCharSupport = TUniSendingSettings::EUniCharSupportReduced;
       
  3765     
       
  3766     if ( doc->CharSetSupport() == EUniMessageCharSetFullLocked ||
       
  3767          doc->CharSetSupport() == EUniMessageCharSetReducedLocked )
       
  3768         {
       
  3769         flags |= EUniSettingsHideCharSet;
       
  3770         }
       
  3771     else if( doc->CharSetSupport() == EUniMessageCharSetFull )
       
  3772         {
       
  3773         settings.iCharSupport = TUniSendingSettings::EUniCharSupportFull;
       
  3774         origCharSet = TUniSendingSettings::EUniCharSupportFull;
       
  3775         }
       
  3776 
       
  3777     if( !( doc->CSPBits() & RMobilePhone::KCspProtocolID ) )
       
  3778         {
       
  3779         flags |= EUniSettingsCSPBitsOn;
       
  3780         }
       
  3781 
       
  3782     if ( iEditorFlags & EHideMessageTypeOption )
       
  3783         {
       
  3784         flags |= EUniSettingsHideMessageTypeOption;
       
  3785         }
       
  3786     TUniState oldState = doc->UniState();
       
  3787   
       
  3788     CUniSendingSettingsDialog::TUniExitCode exitCode = CUniSendingSettingsDialog::EUniBack;
       
  3789     
       
  3790     CUniSendingSettingsDialog* dlg = new ( ELeave ) CUniSendingSettingsDialog( flags, settings, exitCode, *iTitlePane );
       
  3791     CleanupStack::PushL( dlg );
       
  3792     
       
  3793     dlg->ConstructL( R_UNI_SENDINGSETTINGS_DIALOG_MENUBAR );
       
  3794 
       
  3795     // Flag is also used to judge whether toolbar update is done 
       
  3796     iEditorFlags |= EDoNotUpdateTitlePane;
       
  3797     
       
  3798     CleanupStack::Pop( dlg );
       
  3799     
       
  3800     if ( iFixedToolbar )
       
  3801         {
       
  3802         SetFixedToolbarDimmed();
       
  3803         }
       
  3804     
       
  3805   
       
  3806     CleanupStack::PushL( TCleanupItem( UpdateFixedToolbar, this ) );
       
  3807     SetKeyEventFlags(0);    
       
  3808     CleanupStack::PushL( TCleanupItem( DisableSendKey, this ) );  
       
  3809     
       
  3810     dlg->ExecuteLD( R_UNI_SENDINGSETTINGS_DIALOG );
       
  3811     
       
  3812     CleanupStack::PopAndDestroy(2); //DisableSendKey,UpdateFixedToolbar
       
  3813     
       
  3814     iEditorFlags &= ~EDoNotUpdateTitlePane;
       
  3815 
       
  3816     // Now store the changed settings into sms plugin if it exists
       
  3817     // (there's no need to save them in mms plugin as user cannot change anything there)
       
  3818     if( plugin )
       
  3819         {
       
  3820         plugin->SetSendingSettingsL( settings );
       
  3821         }
       
  3822 
       
  3823     TBool unhideConfigurableFields = EFalse;
       
  3824 
       
  3825     if ( !( flags & EUniSettingsHideCharSet ) )
       
  3826         { 
       
  3827         // Ok, it was possible to change the charset in the first place
       
  3828         if ( settings.iCharSupport != origCharSet )
       
  3829             { 
       
  3830             // CharSet has changed -> create new converter
       
  3831             TUniMessageCharSetSupport charSetSupport = EUniMessageCharSetFull;
       
  3832             if ( settings.iCharSupport == TUniSendingSettings::EUniCharSupportReduced )
       
  3833                 {
       
  3834                 charSetSupport = EUniMessageCharSetReduced;
       
  3835                 } 
       
  3836             doc->CreateCharConverterL( charSetSupport ); 
       
  3837             if( iNLTFeatureSupport )
       
  3838                 {
       
  3839                	iSettingsChanged = ETrue;                
       
  3840                 //Turkish SMS-PREQ2265 specific
       
  3841                 if(plugin)
       
  3842                     {
       
  3843                     //Update the new charset support selected by user.
       
  3844                     //Reset uniCode mode flag to EFalse(Restarts encoding algorithm in smsPlugin for optimal length calculation) 
       
  3845                     plugin->SetEncodingSettings(EFalse, doc->AlternativeEncodingType(), charSetSupport); 
       
  3846                     }                
       
  3847                 }
       
  3848             }
       
  3849         }
       
  3850 
       
  3851     // Now lets see the msg type changes
       
  3852 
       
  3853     if( iMtm->MessageTypeLocking() == EUniMessageTypeLocked )
       
  3854         { 
       
  3855         // First lets handle pre locked sms
       
  3856         // no operation here because the msg type does not change
       
  3857         // but just the bit in the message settings
       
  3858         }
       
  3859     else if( settings.iMessageType == TUniSendingSettings::EUniMessageTypeAutomatic )
       
  3860         { 
       
  3861         // Message type is now automatic
       
  3862         iMtm->SetMessageTypeSetting( EUniMessageTypeSettingAutomatic );
       
  3863         
       
  3864         if ( IsBodySmsCompatibleL() )
       
  3865             {
       
  3866             doc->SetBodyUniState( EUniSms );
       
  3867             }
       
  3868         else
       
  3869             {
       
  3870             doc->SetBodyUniState( EUniMms );
       
  3871             }
       
  3872         
       
  3873         if ( iHeader->IsHeaderSmsL() )
       
  3874             {
       
  3875             doc->SetHeaderUniState( EUniSms );
       
  3876             }
       
  3877         else
       
  3878             {            
       
  3879             doc->SetHeaderUniState( EUniMms );
       
  3880             }
       
  3881     
       
  3882         if ( currentlyLockedToSms )
       
  3883             { 
       
  3884             // Show the fields again
       
  3885             unhideConfigurableFields = ETrue;
       
  3886             }
       
  3887         }
       
  3888     else if ( settings.iMessageType == TUniSendingSettings::EUniMessageTypeMultimedia )
       
  3889         {
       
  3890         iMtm->SetMessageTypeSetting( EUniMessageTypeSettingMms );
       
  3891         if ( IsBodySmsCompatibleL() )
       
  3892             {
       
  3893             doc->SetBodyUniState( EUniSms );
       
  3894             }
       
  3895         else
       
  3896             {
       
  3897             doc->SetBodyUniState( EUniMms );
       
  3898             }
       
  3899             
       
  3900         if ( currentlyLockedToSms )
       
  3901             { 
       
  3902             // Show the fields again
       
  3903             unhideConfigurableFields = ETrue;
       
  3904             }
       
  3905         }
       
  3906     else
       
  3907         { 
       
  3908         // Settings is one of the sms conversions (none, fax, pager)
       
  3909         if ( iMtm->MessageTypeSetting() != EUniMessageTypeSettingSms )
       
  3910             {
       
  3911             iMtm->SetMessageTypeSetting( EUniMessageTypeSettingSms );
       
  3912             // Also remove those additional headers that need to be removed
       
  3913             TInt removeHeaders( 0 ); 
       
  3914             if ( iHeader->AddressControl( CUniBaseHeader::EHeaderAddressCc ) )
       
  3915                 {
       
  3916                 removeHeaders |= EUniFeatureCc;
       
  3917                 }
       
  3918             if ( iHeader->AddressControl( CUniBaseHeader::EHeaderAddressBcc ) )
       
  3919                 {
       
  3920                 removeHeaders |= EUniFeatureBcc;
       
  3921                 }
       
  3922             if ( !(iEditorFlags & ESubjectOkInSms ) && iHeader->SubjectControl() )
       
  3923                 {
       
  3924                 removeHeaders |= EUniFeatureSubject;
       
  3925                 }
       
  3926             iHeader->AddHeadersDeleteL( removeHeaders, EFalse );
       
  3927             }
       
  3928         // We can change this here because if it was not then SMS/Fax/Pager would not have been available in options
       
  3929         // This is needed here in case SMS soft and hard limits are different so we have to "hardcode" the type to SMS
       
  3930         doc->SetBodyUniState( EUniSms );
       
  3931         doc->SetHeaderUniState( EUniSms );
       
  3932         }
       
  3933 
       
  3934     if ( unhideConfigurableFields )
       
  3935         { 
       
  3936         // Read the current situation
       
  3937         TInt addHeaders = iHeader->AddHeadersConfigL();
       
  3938         // Add them to header
       
  3939         iHeader->AddHeadersAddL( addHeaders );
       
  3940         }
       
  3941 
       
  3942     if ( oldState != doc->UniState() )
       
  3943         {  
       
  3944          // If the state is not the same anymore, show popup
       
  3945         UpdateIndicatorIconsL();
       
  3946         ShowPopupNoteL( doc->UniState() == EUniMms ? ETrue : EFalse );
       
  3947         }
       
  3948     
       
  3949     CheckLockedSmsWithAttaL();
       
  3950     
       
  3951     UpdateToolbarL();
       
  3952     
       
  3953     SetTitleL();
       
  3954     MsgLengthToNavipaneL();
       
  3955 
       
  3956     // Removes or sets the max size according to the settings
       
  3957     SetOrRemoveMaxSizeInEdwin();
       
  3958     
       
  3959     if ( exitCode != CUniSendingSettingsDialog::EUniBack )
       
  3960         {
       
  3961         CAknAppUi::ProcessCommandL( EAknCmdExit );
       
  3962         return;
       
  3963         }
       
  3964 
       
  3965     UpdateMiddleSoftkeyL();
       
  3966     UpdateIndicatorIconsL();
       
  3967     }
       
  3968 
       
  3969 // ---------------------------------------------------------
       
  3970 // CUniEditorAppUi::DoUserInsertMediaL
       
  3971 // ---------------------------------------------------------
       
  3972 //
       
  3973 void CUniEditorAppUi::DoUserInsertMediaL()
       
  3974     {
       
  3975     RArray<TInt> disabledItems;
       
  3976     CleanupClosePushL( disabledItems );
       
  3977     
       
  3978     TBool svgFetchDisabled( EFalse );   
       
  3979     if ( Document()->CreationMode() == EMmsCreationModeRestricted )
       
  3980         {
       
  3981         svgFetchDisabled = ETrue;
       
  3982         }
       
  3983     
       
  3984 //    if ( svgFetchDisabled )
       
  3985 //        {
       
  3986 //        disabledItems.Append( EUniCmdInsertMediaSVG );
       
  3987 //        }
       
  3988     
       
  3989 
       
  3990     if ( !( iSupportedFeatures & EUniFeatureCamcorder ) )
       
  3991         {
       
  3992         disabledItems.Append( EUniCmdInsertMediaNewVideo );
       
  3993         disabledItems.Append( EUniCmdInsertMediaNewImage );
       
  3994         }
       
  3995     
       
  3996     TInt selectedIndex( 0 );
       
  3997     CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
  3998     dlg->PrepareLC( R_UNIEDITOR_INSERT_QUERY );
       
  3999     
       
  4000     CEikFormattedCellListBox* listbox = dlg->ListControl()->Listbox();
       
  4001     CDesCArray* itemArray = static_cast<CDesCArray*>( listbox->Model()->ItemTextArray() );
       
  4002     
       
  4003     if ( disabledItems.Count() > 0 )
       
  4004         {
       
  4005         for ( TInt currentItem = 0; currentItem < disabledItems.Count(); currentItem++ )
       
  4006             {
       
  4007             itemArray->Delete( disabledItems[ currentItem ] );
       
  4008             listbox->HandleItemRemovalL();
       
  4009             }
       
  4010         }
       
  4011         
       
  4012     if ( dlg->RunLD() )
       
  4013         {
       
  4014         for ( TInt currentItem = disabledItems.Count() - 1; currentItem >= 0 ; currentItem-- )
       
  4015             {
       
  4016             if ( selectedIndex >= disabledItems[ currentItem ] )
       
  4017                 {
       
  4018                 selectedIndex++;
       
  4019                 }
       
  4020             }
       
  4021                 
       
  4022         switch ( selectedIndex )    
       
  4023             {
       
  4024             case EUniCmdInsertMediaImage:
       
  4025                 {
       
  4026                 DoUserInsertImageL( MsgAttachmentUtils::EImage );
       
  4027                 break;
       
  4028                 } 
       
  4029             case EUniCmdInsertMediaNewImage:
       
  4030                 {
       
  4031                 DoUserInsertImageL( MsgAttachmentUtils::ENewImage );
       
  4032                 break;
       
  4033                 } 
       
  4034             case EUniCmdInsertMediaVideo:
       
  4035                 {
       
  4036                 DoUserInsertVideoL( MsgAttachmentUtils::EVideo );
       
  4037                 break;
       
  4038                 } 
       
  4039             case EUniCmdInsertMediaNewVideo:
       
  4040                 {
       
  4041                 DoUserInsertVideoL( MsgAttachmentUtils::ENewVideo );
       
  4042                 break;
       
  4043                 } 
       
  4044             case EUniCmdInsertMediaAudio:
       
  4045                 {
       
  4046                 DoUserInsertAudioL( MsgAttachmentUtils::EAudio );
       
  4047                 break;
       
  4048                 } 
       
  4049             case EUniCmdInsertMediaNewAudio:
       
  4050                 {
       
  4051                 DoUserInsertAudioL( MsgAttachmentUtils::ENewAudio );
       
  4052                 break;
       
  4053                 } 
       
  4054             case EUniCmdInsertMediavCard:
       
  4055                 {
       
  4056                 DoUserInsertVCardL();
       
  4057                 break;
       
  4058                 }
       
  4059             case EUniCmdInsertMediaSlide:
       
  4060                 {
       
  4061                 DoUserInsertSlideL();
       
  4062                 break;
       
  4063                 }
       
  4064             case EUniCmdInsertMediaNote:
       
  4065                 {
       
  4066                 DoUserInsertTextL( EMemoText );
       
  4067                 break;
       
  4068                 }
       
  4069             case EUniCmdInsertMediaTextAtta:
       
  4070                 {
       
  4071                 DoUserInsertOtherFileL( ETextFile );
       
  4072                 break;
       
  4073                 }
       
  4074             case EUniCmdInsertMediaTemplate:
       
  4075                 {
       
  4076                 DoUserInsertTextL( ETemplateText );
       
  4077                 break;
       
  4078                 }
       
  4079 //            case EUniCmdInsertMediaSVG:
       
  4080 //                {
       
  4081 //                DoUserInsertSvgL();
       
  4082 //                break;
       
  4083 //                }
       
  4084             case EUniCmdInsertMediaOtherFile:
       
  4085                 {
       
  4086                 DoUserInsertOtherFileL( EOtherFile );
       
  4087                 break;
       
  4088                 }
       
  4089             default: 
       
  4090                 {
       
  4091                 __ASSERT_DEBUG( EFalse, Panic( EUniUnsupportedCommand ) );
       
  4092                 break;
       
  4093                 }
       
  4094             }
       
  4095         }
       
  4096         
       
  4097     CleanupStack::PopAndDestroy( &disabledItems );
       
  4098     }
       
  4099 
       
  4100 // ---------------------------------------------------------
       
  4101 // CUniEditorAppUi::DoStartInsertL
       
  4102 // ---------------------------------------------------------
       
  4103 //
       
  4104 void CUniEditorAppUi::DoStartInsertL( TBool aAddSlide, TBool aAddAsAttachment )
       
  4105     {
       
  4106     if ( aAddSlide &&
       
  4107          iSmilModel->MaxSlideCountReached() )
       
  4108        {
       
  4109        ShowConfirmableInfoL( R_UNIEDITOR_INFO_MAX_SLIDES_ALL );
       
  4110        iEditorFlags &= ~EMsgEditInProgress;
       
  4111        }
       
  4112    else
       
  4113        {
       
  4114         if ( !iInsertOperation )
       
  4115             {
       
  4116             iInsertOperation = CUniEditorInsertOperation::NewL(
       
  4117                 *this,
       
  4118                 *Document(),
       
  4119                 *iHeader,
       
  4120                 *iSlideLoader,
       
  4121                 *iView,
       
  4122                 FsSession() );
       
  4123             }
       
  4124         
       
  4125         if ( aAddSlide )
       
  4126             {
       
  4127             iEditorFlags |= EInsertAddsSlide;
       
  4128             }
       
  4129         else
       
  4130             {
       
  4131             iEditorFlags &= ~EInsertAddsSlide;
       
  4132             }
       
  4133             
       
  4134         ShowWaitNoteL( R_QTN_UNI_WAIT_INSERTING );
       
  4135         
       
  4136         iInsertOperation->Insert(
       
  4137             iInsertingMedia,
       
  4138             aAddSlide,
       
  4139             aAddAsAttachment );
       
  4140         
       
  4141         ActivateInputBlockerL( iInsertOperation );
       
  4142         
       
  4143         iInsertingMedia = NULL;
       
  4144        }
       
  4145        // Enable the toolbar since inputblockers will take care now
       
  4146       if( iFixedToolbar )
       
  4147         {
       
  4148         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  4149         }
       
  4150     }
       
  4151 
       
  4152 
       
  4153 // ---------------------------------------------------------
       
  4154 // CreateMediaInfoForInsertL
       
  4155 // ---------------------------------------------------------
       
  4156 //
       
  4157 TBool CUniEditorAppUi::CreateMediaInfoForInsertL( TMsgMediaType aMediaType,
       
  4158                                                   const TDesC& aFileName )
       
  4159     {
       
  4160     RFile file = Document()->DataModel()->MediaResolver().FileHandleL( aFileName );
       
  4161     CleanupClosePushL( file );
       
  4162     
       
  4163     delete iInsertingMedia;
       
  4164     iInsertingMedia = NULL;
       
  4165     
       
  4166     iInsertingMedia = Document()->DataModel()->MediaResolver().CreateMediaInfoL( file );
       
  4167 
       
  4168     Document()->DataModel()->MediaResolver().ParseInfoDetailsL( iInsertingMedia, file );
       
  4169     
       
  4170     TMmsConformance conformance = 
       
  4171         Document()->DataModel()->MmsConformance().MediaConformance( *iInsertingMedia );
       
  4172     
       
  4173     CleanupStack::PopAndDestroy( &file );
       
  4174     
       
  4175     TInt errResId = KUniInvalidResourceId;
       
  4176     TInt confStatus = conformance.iConfStatus;
       
  4177 
       
  4178     // Supported type check
       
  4179     if ( confStatus & EMmsConfNokNotSupported ||
       
  4180         ( Document()->CreationMode() == EMmsCreationModeRestricted &&
       
  4181           confStatus & EMmsConfNokFreeModeOnly ) )
       
  4182         {
       
  4183         errResId = R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT;
       
  4184         if( Document()->CreationModeUserChangeable() &&
       
  4185            !Document()->CreationMode() )
       
  4186             {
       
  4187             errResId = R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT;
       
  4188             }
       
  4189         }
       
  4190     else if ( confStatus & EMmsConfNokDRM )
       
  4191         {
       
  4192         // DRM check
       
  4193         errResId = R_UNIEDITOR_INFO_SEND_FORBID_1;
       
  4194         }
       
  4195     else if ( aMediaType != EMsgMediaUnknown && 
       
  4196               iInsertingMedia->MediaType() != aMediaType )
       
  4197         {
       
  4198         // Keep this after DRM check!
       
  4199         errResId = R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT;
       
  4200         if( Document()->CreationModeUserChangeable() &&
       
  4201             !Document()->CreationMode() )
       
  4202             {
       
  4203             errResId = R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT;
       
  4204             }
       
  4205         }
       
  4206     else if ( !conformance.iCanAdapt &&
       
  4207         ( confStatus & EMmsConfNokTooBig ||
       
  4208         TUint( MessageSizeInBytes() + iInsertingMedia->FileSize() )
       
  4209         > Document()->MaxMessageSize() ) )
       
  4210         {
       
  4211         // File is too big and it cannot be adapted (e.g. scaled down)
       
  4212         errResId = R_UNIEDITOR_INFO_OBJECT_TOO_BIG;
       
  4213         }
       
  4214 
       
  4215     if ( errResId != KUniInvalidResourceId )
       
  4216         {
       
  4217         delete iInsertingMedia;
       
  4218         iInsertingMedia = NULL;
       
  4219         ShowInformationNoteL( errResId, EFalse );
       
  4220         return EFalse;
       
  4221         }
       
  4222 
       
  4223     if ( MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( Document()->Session(),
       
  4224                                                               iInsertingMedia->FileSize() ) )
       
  4225         {
       
  4226          delete iInsertingMedia;
       
  4227          iInsertingMedia = NULL;       
       
  4228          ShowConfirmableInfoL( R_UNIEDITOR_NOT_ENOUGH_MEMORY );
       
  4229          return EFalse;             
       
  4230         }
       
  4231         
       
  4232     return ETrue;
       
  4233     }
       
  4234 
       
  4235 // ---------------------------------------------------------
       
  4236 // CUniEditorAppUi::SuperDistributionCheckForInsertL
       
  4237 // ---------------------------------------------------------
       
  4238 //
       
  4239 TBool CUniEditorAppUi::SuperDistributionCheckForInsertL()
       
  4240     {
       
  4241     // SuperDistribution check & query
       
  4242     if ( iSupportedFeatures & EUniFeatureDrmFull &&
       
  4243          iInsertingMedia->Protection() & EFileProtSuperDistributable )
       
  4244         {
       
  4245         if ( !ShowConfirmationQueryL( R_UNIEDITOR_QUEST_SEND_WO_RIGHTS ) )
       
  4246             {
       
  4247             delete iInsertingMedia;
       
  4248             iInsertingMedia = NULL;
       
  4249             return EFalse;
       
  4250             }
       
  4251         }
       
  4252     return ETrue;
       
  4253     }
       
  4254 
       
  4255 // ---------------------------------------------------------
       
  4256 // CUniEditorAppUi::CheckMediaInfoForInsertL
       
  4257 // ---------------------------------------------------------
       
  4258 //
       
  4259 TBool CUniEditorAppUi::CheckMediaInfoForInsertL()
       
  4260     {
       
  4261     __ASSERT_DEBUG( iInsertingMedia, Panic( EUniNullPointer ) );
       
  4262 
       
  4263     TMmsConformance conformance = 
       
  4264         Document()->DataModel()->MmsConformance().MediaConformance( *iInsertingMedia );
       
  4265     
       
  4266     TInt errResId = KUniInvalidResourceId;
       
  4267     TInt confStatus = conformance.iConfStatus;
       
  4268     
       
  4269     // In "free" mode user can insert images that are larger by dimensions than allowed by conformance
       
  4270     if ( Document()->CreationMode() != EMmsCreationModeRestricted )
       
  4271         {
       
  4272         //Mask "Corrupted" away in free & guided mode.
       
  4273         confStatus &= ~EMmsConfNokCorrupt;
       
  4274         
       
  4275         // If user answers yes to Guided mode confirmation query he/she moves to free mode
       
  4276         if ( ( confStatus & ( EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded ) ) &&
       
  4277              !( confStatus & ~( EMmsConfNokFreeModeOnly | EMmsConfNokScalingNeeded ) ) )
       
  4278             {
       
  4279             if ( iInsertingMedia->Protection() & EFileProtSuperDistributable )
       
  4280                 {
       
  4281                 // SuperDistribution not checked here
       
  4282                 // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode
       
  4283                 confStatus &= ~EMmsConfNokFreeModeOnly;
       
  4284                 confStatus &= ~EMmsConfNokScalingNeeded;
       
  4285                 }
       
  4286             else if ( ShowGuidedModeConfirmationQueryL( R_UNIEDITOR_QUEST_GUIDED_OBJ ) )
       
  4287                 {
       
  4288                 // Guided query accepted.
       
  4289                 // Mask "FreeModeOnly" and "ScalingNeeded" away in free mode
       
  4290                 confStatus &= ~EMmsConfNokFreeModeOnly;
       
  4291                 confStatus &= ~EMmsConfNokScalingNeeded;
       
  4292                 }
       
  4293             else
       
  4294                 {
       
  4295                 // Guided query not accepted. Stop insertion.
       
  4296                 delete iInsertingMedia;
       
  4297                 iInsertingMedia = NULL;
       
  4298                 return EFalse;
       
  4299                 }
       
  4300             }
       
  4301         }
       
  4302 
       
  4303     if ( confStatus & EMmsConfNokTooBig ||
       
  4304         TUint( MessageSizeInBytes() + iInsertingMedia->FileSize() )
       
  4305         > Document()->MaxMessageSize() )
       
  4306         {
       
  4307         // Size check
       
  4308         errResId = R_UNIEDITOR_INFO_OBJECT_TOO_BIG;
       
  4309         }
       
  4310     else if ( confStatus != EMmsConfOk )
       
  4311         {
       
  4312         // Sanity check
       
  4313         errResId = R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT;
       
  4314         if( Document()->CreationModeUserChangeable() &&
       
  4315             !Document()->CreationMode() )
       
  4316             {
       
  4317             errResId = R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT;
       
  4318             }
       
  4319         }
       
  4320 
       
  4321     if ( errResId != KUniInvalidResourceId )
       
  4322         {
       
  4323         delete iInsertingMedia;
       
  4324         iInsertingMedia = NULL;
       
  4325         ShowInformationNoteL( errResId, EFalse );
       
  4326         return EFalse;
       
  4327         }
       
  4328         
       
  4329     return ETrue;
       
  4330     }
       
  4331 
       
  4332 
       
  4333 // ---------------------------------------------------------
       
  4334 // CUniEditorAppUi::DoUserInsertSlideL
       
  4335 // ---------------------------------------------------------
       
  4336 //
       
  4337 void CUniEditorAppUi::DoUserInsertSlideL()
       
  4338     {
       
  4339     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4340 
       
  4341     if ( TUint( MessageSizeInBytes() + KEmptySlideSize ) > Document()->MaxMessageSize() )
       
  4342         {
       
  4343         ShowConfirmableInfoL( R_UNIEDITOR_INFO_OBJECT_TOO_BIG );
       
  4344         }
       
  4345     else if ( iSmilModel->MaxSlideCountReached() )
       
  4346         {
       
  4347         ShowConfirmableInfoL( R_UNIEDITOR_INFO_MAX_SLIDES_ALL );
       
  4348         }
       
  4349     else
       
  4350         {
       
  4351         TInt index = Document()->CurrentSlide() + 1;
       
  4352         iSmilModel->AddSlideL( index );
       
  4353         Document()->SetBodyModified( ETrue );
       
  4354         DoUserChangeSlideL( index );
       
  4355         }
       
  4356     }
       
  4357 
       
  4358 // ---------------------------------------------------------
       
  4359 // CUniEditorAppUi::DoUserRemoveSlideL
       
  4360 // ---------------------------------------------------------
       
  4361 //
       
  4362 void CUniEditorAppUi::DoUserRemoveSlideL()
       
  4363     {
       
  4364     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4365 
       
  4366     if ( ShowConfirmationQueryL( R_UNIEDITOR_QUEST_REMOVE_PAGE ) ) 
       
  4367         {
       
  4368         DoRemoveSlideL();
       
  4369         }
       
  4370         
       
  4371     Document()->SetBodyModified( ETrue ); 
       
  4372     }
       
  4373 
       
  4374 // ---------------------------------------------------------
       
  4375 // CUniEditorAppUi::DoRemoveSlideL
       
  4376 // ---------------------------------------------------------
       
  4377 //
       
  4378 void CUniEditorAppUi::DoRemoveSlideL()
       
  4379     {
       
  4380     TInt currSlide = Document()->CurrentSlide();
       
  4381     TMsgControlId focusedControl( EMsgComponentIdNull );
       
  4382     
       
  4383     if( Document()->DataModel()->SmilType() == EMmsSmil &&
       
  4384         ( currSlide == 0 || currSlide == 1 ) )
       
  4385         { 
       
  4386         if ( Document()->DataModel()->SmilType() == EMmsSmil )
       
  4387             {
       
  4388             CMsgAddressControl* to = iHeader->AddressControl( CUniEditorHeader::EHeaderAddressTo );
       
  4389             CMsgAddressControl* cc = iHeader->AddressControl( CUniEditorHeader::EHeaderAddressCc );
       
  4390             CMsgAddressControl* bcc = iHeader->AddressControl( CUniEditorHeader::EHeaderAddressBcc );
       
  4391             
       
  4392             if( to && to->GetRecipientsL()->Count() == 0 )
       
  4393                 {
       
  4394                 focusedControl = EMsgComponentIdTo;
       
  4395                 }
       
  4396             else if( cc && cc->GetRecipientsL()->Count() == 0 )
       
  4397                 {
       
  4398                 focusedControl = EMsgComponentIdCc;
       
  4399                 }
       
  4400             else if( bcc && bcc->GetRecipientsL()->Count() == 0 )
       
  4401                 {
       
  4402                 focusedControl = EMsgComponentIdBcc;
       
  4403                 }
       
  4404             else if( iSupportedFeatures & EUniFeatureSubject &&
       
  4405                      SubjectCtrl() &&
       
  4406                      SubjectCtrl()->TextContent().DocumentLength() == 0 )
       
  4407                 {
       
  4408                 focusedControl = EMsgComponentIdSubject;
       
  4409                 }
       
  4410             }
       
  4411         }
       
  4412     
       
  4413     TInt objCount = iSmilModel->SlideObjectCount( currSlide );
       
  4414     ReleaseImage( ETrue );
       
  4415     
       
  4416     for ( TInt i = 0; i < objCount; i++ )
       
  4417         {
       
  4418         iSmilModel->RemoveObjectByIndexL( currSlide, 0 );
       
  4419         }
       
  4420     iSmilModel->RemoveSlide( currSlide );
       
  4421     TInt nextSlide = currSlide;
       
  4422     if ( nextSlide )
       
  4423         {
       
  4424         nextSlide--;
       
  4425         }
       
  4426     //Set current slide to invalid in order
       
  4427     //to prevent false events coming to wrong slides
       
  4428     Document()->SetCurrentSlide( -1 );
       
  4429     iView->SetScrollParts( iSmilModel->SlideCount() );
       
  4430     iView->SetCurrentPart( nextSlide );
       
  4431     iNextFocus = focusedControl;
       
  4432     DoUserChangeSlideL( nextSlide );
       
  4433     }
       
  4434 
       
  4435 // ---------------------------------------------------------
       
  4436 // CUniEditorAppUi::DoUserChangeSlideL
       
  4437 //
       
  4438 // If change is made from first slide containing address fields into
       
  4439 // some other slide and address control is currently focused set
       
  4440 // the current input mode into all address fields. This enables
       
  4441 // correct input mode to be used if focus is set to different
       
  4442 // address field when returning to first slide and also if
       
  4443 // message is closed from different slide.
       
  4444 // After input mode is set operation is created if necessary and
       
  4445 // activated.
       
  4446 // ---------------------------------------------------------
       
  4447 //
       
  4448 void CUniEditorAppUi::DoUserChangeSlideL( TInt aSlideNum )
       
  4449     {
       
  4450     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4451     
       
  4452     CMsgBaseControl* ctrl = iView->FocusedControl();  // ctrl can be NULL.
       
  4453     if ( ctrl &&
       
  4454          Document()->CurrentSlide() == 0 &&
       
  4455          iHeader->IsAddressControl( ctrl->ControlId() ) )
       
  4456         {
       
  4457         SetInputModeToAddressFields( static_cast<CMsgAddressControl*>( ctrl )->Editor().AknEditorCurrentInputMode() );
       
  4458         }
       
  4459     
       
  4460     if ( !iChangeSlideOperation )
       
  4461         {
       
  4462         iChangeSlideOperation = CUniEditorChangeSlideOperation::NewL(
       
  4463             *this,
       
  4464             *Document(),
       
  4465             *iHeader,
       
  4466             *iSlideLoader,
       
  4467             *iView,
       
  4468             FsSession() );
       
  4469         }
       
  4470     
       
  4471     iChangeSlideOperation->ChangeSlide(  aSlideNum );
       
  4472 
       
  4473     iNextSlide = aSlideNum;
       
  4474     
       
  4475     iScreenClearer = CAknLocalScreenClearer::NewLC( EFalse );
       
  4476     CleanupStack::Pop();
       
  4477     iScreenClearer->SetExtent( iScreenClearer->Position(), ClientRect().Size() );
       
  4478     
       
  4479     ShowWaitNoteL( R_QTN_UNI_WAIT_SLIDE_CHANGE );
       
  4480     
       
  4481     ActivateInputBlockerL( iChangeSlideOperation );
       
  4482         
       
  4483     BeginActiveWait( iChangeSlideOperation );
       
  4484     }
       
  4485 
       
  4486 
       
  4487 // ---------------------------------------------------------
       
  4488 // CUniEditorAppUi::DoSetFocusL
       
  4489 // ---------------------------------------------------------
       
  4490 //
       
  4491 void CUniEditorAppUi::DoSetFocusL()
       
  4492     {
       
  4493     // 1. to To: control, if empty and exists
       
  4494     // 2. if not empty, to Subject: control, if empty and exists
       
  4495     // 3. otherwise to body    
       
  4496     TMsgControlId focusedControl( EMsgComponentIdTo );
       
  4497     if ( iNextFocus != EMsgComponentIdNull )
       
  4498         {
       
  4499         // iNextFocus is set when changing slide
       
  4500         focusedControl = iNextFocus;
       
  4501         iNextFocus = EMsgComponentIdNull;
       
  4502         }
       
  4503     else
       
  4504         {
       
  4505         // To first empty field. Cc and Bcc are not supported here
       
  4506         CMsgAddressControl* to = ToCtrl();
       
  4507         
       
  4508         if ( Document()->DataModel()->SmilType() == EMmsSmil &&  
       
  4509              ( !to || 
       
  4510                to->GetRecipientsL()->Count() > 0 ) )
       
  4511             {
       
  4512             // No To-control or there are recipients
       
  4513             // -> focus to end of bodytext or to Subject field if empty
       
  4514             focusedControl = EMsgComponentIdBody;
       
  4515             if ( iSupportedFeatures & EUniFeatureSubject )
       
  4516                 {
       
  4517                 CMsgExpandableControl* subj = SubjectCtrl();
       
  4518                 if ( subj && 
       
  4519                      subj->TextContent().DocumentLength() == 0 )
       
  4520                     {
       
  4521                     focusedControl = EMsgComponentIdSubject;
       
  4522                     }
       
  4523                 }
       
  4524             
       
  4525             if ( !BodyCtrl() )
       
  4526                 {
       
  4527                 focusedControl = EMsgComponentIdTo;
       
  4528                 }
       
  4529                 
       
  4530             if ( focusedControl == EMsgComponentIdBody )
       
  4531                 {
       
  4532                 BodyCtrl()->SetCursorPosL( BodyCtrlEditor()->TextLength() );
       
  4533                 }
       
  4534             }
       
  4535         }
       
  4536     iView->SetFocus( focusedControl );
       
  4537     }
       
  4538 
       
  4539 // ---------------------------------------------------------
       
  4540 // CUniEditorAppUi::SetTitleL
       
  4541 // ---------------------------------------------------------
       
  4542 //
       
  4543 void CUniEditorAppUi::SetTitleL()
       
  4544     {
       
  4545     // If titlepane exists -> set the right title
       
  4546     HBufC* titleString = Document()->UniState() == EUniMms ? iTitleMms : 
       
  4547                                                              iTitleSms;
       
  4548     iTitlePane->SetTextL( titleString->Des(), ETrue );
       
  4549         
       
  4550     CGulIcon* image = Document()->UniState() == EUniMms? iIconMms : 
       
  4551                                                          iIconSms;
       
  4552     
       
  4553     // Create duplicates of the icon to be used
       
  4554     CFbsBitmap* bitmap = new( ELeave ) CFbsBitmap();
       
  4555     CleanupStack::PushL( bitmap );
       
  4556     
       
  4557     CFbsBitmap* bitmapMask = new( ELeave ) CFbsBitmap();
       
  4558     CleanupStack::PushL( bitmapMask );
       
  4559     
       
  4560     User::LeaveIfError( bitmap->Duplicate( image->Bitmap()->Handle() ) );
       
  4561     User::LeaveIfError( bitmapMask->Duplicate( image->Mask()->Handle() ) );
       
  4562 
       
  4563     iTitlePane->SetSmallPicture( bitmap, bitmapMask, ETrue );
       
  4564     iTitlePane->DrawNow();
       
  4565     
       
  4566     CleanupStack::Pop( 2, bitmap );
       
  4567     }
       
  4568 
       
  4569 // ---------------------------------------------------------
       
  4570 // CUniEditorAppUi::DoUserInsertImageL
       
  4571 // ---------------------------------------------------------
       
  4572 //
       
  4573 void CUniEditorAppUi::DoUserInsertImageL( MsgAttachmentUtils::TMsgAttachmentFetchType aFetchType )
       
  4574     {
       
  4575     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4576     
       
  4577     if( iFixedToolbar )
       
  4578         {
       
  4579         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );    
       
  4580         }
       
  4581     iInsertingType = EMsgMediaImage;
       
  4582     
       
  4583     TBool fetchFile( ETrue );
       
  4584     TBool enabletoolbarext = ETrue;
       
  4585     while ( fetchFile )
       
  4586         {
       
  4587         fetchFile = EFalse;
       
  4588         iEditorFlags |= EMsgEditInProgress;
       
  4589         TBool stat= EFalse;
       
  4590         TRAPD(Err,stat = FetchFileL( aFetchType ));
       
  4591          if (Err == KErrNone && stat)        
       
  4592             {
       
  4593             if ( SuperDistributionCheckForInsertL() )
       
  4594                 {
       
  4595                 // CheckMediaInfoForInsertL() done in CUniEditorInsertOperation
       
  4596                 TBool addSlide = EFalse;
       
  4597                 if ( ObjectsAvailable() & 
       
  4598                     ( EUniImageFlag | EUniVideoFlag | EUniSvgFlag ) )
       
  4599                     {
       
  4600                     addSlide = ETrue;
       
  4601                     }
       
  4602 
       
  4603                 DoStartInsertL( addSlide, EFalse );
       
  4604                 enabletoolbarext = EFalse;
       
  4605                 }
       
  4606             else
       
  4607                 {
       
  4608                 fetchFile = ETrue;
       
  4609                 }
       
  4610             }
       
  4611          else
       
  4612             {
       
  4613             iEditorFlags &= ~EMsgEditInProgress;           
       
  4614             }
       
  4615         }
       
  4616         if(enabletoolbarext)
       
  4617             {
       
  4618                 //Enable the insert toolbar 
       
  4619             if( iFixedToolbar )
       
  4620                 {
       
  4621                 iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  4622                 }
       
  4623             }
       
  4624                                  
       
  4625     }
       
  4626 
       
  4627 // ---------------------------------------------------------
       
  4628 // CUniEditorAppUi::DoUserInsertVideoL
       
  4629 // ---------------------------------------------------------
       
  4630 //
       
  4631 void CUniEditorAppUi::DoUserInsertVideoL( MsgAttachmentUtils::TMsgAttachmentFetchType  aFetchType )
       
  4632     {
       
  4633     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4634     
       
  4635    if( iFixedToolbar )
       
  4636         {
       
  4637         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );    
       
  4638         }
       
  4639     iInsertingType = EMsgMediaVideo;
       
  4640     
       
  4641     TBool fetchFile( ETrue );
       
  4642     TBool enabletoolbarext = ETrue;
       
  4643     while ( fetchFile )
       
  4644         {
       
  4645         fetchFile = EFalse;
       
  4646         iEditorFlags |= EMsgEditInProgress;
       
  4647         TBool stat= EFalse;
       
  4648         TRAPD(Err,stat = FetchFileL( aFetchType ));
       
  4649         if (Err == KErrNone && stat)        
       
  4650             {
       
  4651             if ( SuperDistributionCheckForInsertL() )
       
  4652                 {
       
  4653                 if ( CheckMediaInfoForInsertL() )
       
  4654                     {
       
  4655                     TBool addSlide = EFalse;
       
  4656                 
       
  4657                     if ( ObjectsAvailable() & 
       
  4658                         ( EUniAudioFlag | EUniImageFlag | EUniVideoFlag | EUniSvgFlag ) )
       
  4659                         {
       
  4660                         addSlide = ETrue;
       
  4661                         }
       
  4662                     DoStartInsertL( addSlide, EFalse );
       
  4663                     enabletoolbarext = EFalse;
       
  4664                     }
       
  4665                 else
       
  4666                     {
       
  4667                      iEditorFlags &= ~EMsgEditInProgress;
       
  4668                     }
       
  4669                 }
       
  4670             else
       
  4671                 {
       
  4672                 fetchFile = ETrue;
       
  4673                 }
       
  4674             }
       
  4675         else
       
  4676             {
       
  4677             iEditorFlags &= ~EMsgEditInProgress;
       
  4678             }
       
  4679         }
       
  4680       if(enabletoolbarext)
       
  4681             {
       
  4682                 //Enable the insert toolbar 
       
  4683             if( iFixedToolbar )
       
  4684                 {
       
  4685             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  4686                 }
       
  4687             }
       
  4688                          
       
  4689     }
       
  4690 
       
  4691 // ---------------------------------------------------------
       
  4692 // CUniEditorAppUi::DoUserInsertAudioL
       
  4693 // ---------------------------------------------------------
       
  4694 //
       
  4695 void CUniEditorAppUi::DoUserInsertAudioL( MsgAttachmentUtils::TMsgAttachmentFetchType aFetchType )
       
  4696     {
       
  4697     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4698     
       
  4699    if( iFixedToolbar )
       
  4700         {
       
  4701         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );    
       
  4702         }
       
  4703     iInsertingType = EMsgMediaAudio;
       
  4704     
       
  4705     TBool fetchFile( ETrue );
       
  4706     TBool enabletoolbarext = ETrue;
       
  4707     while ( fetchFile )
       
  4708         {
       
  4709         fetchFile = EFalse;
       
  4710         iEditorFlags |= EMsgEditInProgress;
       
  4711         TBool stat= EFalse;
       
  4712         TRAPD(Err,stat = FetchFileL( aFetchType ));
       
  4713         if (Err == KErrNone && stat)        
       
  4714             {
       
  4715             if ( SuperDistributionCheckForInsertL() )
       
  4716                 {
       
  4717                 if ( CheckMediaInfoForInsertL() )
       
  4718                     {
       
  4719                     TBool addSlide = EFalse;
       
  4720                     if ( ObjectsAvailable() & 
       
  4721                         ( EUniAudioFlag | EUniVideoFlag | EUniSvgFlag ) )
       
  4722                         {
       
  4723                         addSlide = ETrue;
       
  4724                         }
       
  4725                     DoStartInsertL( addSlide, EFalse );
       
  4726                     enabletoolbarext = EFalse ; 
       
  4727                     }
       
  4728                 else
       
  4729                     {
       
  4730                      iEditorFlags &= ~EMsgEditInProgress;
       
  4731                     }
       
  4732                 }
       
  4733             else
       
  4734                 {
       
  4735                 fetchFile = ETrue;
       
  4736                 }
       
  4737             }
       
  4738          else
       
  4739             {
       
  4740             iEditorFlags &= ~EMsgEditInProgress;
       
  4741             }
       
  4742         }
       
  4743         if(enabletoolbarext)
       
  4744             {
       
  4745                 //Enable the insert toolbar 
       
  4746             if( iFixedToolbar )
       
  4747                 {
       
  4748             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  4749                 }
       
  4750             }
       
  4751                          
       
  4752     }
       
  4753 
       
  4754 // ---------------------------------------------------------
       
  4755 // CUniEditorAppUi::DoUserInsertTextL
       
  4756 // ---------------------------------------------------------
       
  4757 //
       
  4758 void CUniEditorAppUi::DoUserInsertTextL( TUniEditorInsertTextType aType )
       
  4759     {
       
  4760     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4761     TInt err( KErrNone );
       
  4762     TInt errResId = KUniInvalidResourceId;
       
  4763     TInt sizeLimit( Document()->MaxMessageSize() - MessageSizeInBytes() ); 
       
  4764 
       
  4765      if( iFixedToolbar ) 
       
  4766         {
       
  4767         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );    
       
  4768         }
       
  4769     if ( aType == ETemplateText )
       
  4770         {
       
  4771         InsertTemplateL();
       
  4772         }
       
  4773     else
       
  4774         {
       
  4775         err = InsertTextMemoL( sizeLimit );
       
  4776         }
       
  4777         
       
  4778     if( iFixedToolbar )
       
  4779         {
       
  4780         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, EFalse );    
       
  4781         }
       
  4782     if ( err == KErrOverflow)
       
  4783         {
       
  4784         errResId = R_UNIEDITOR_INFO_OBJECT_TOO_BIG;
       
  4785         ShowConfirmableInfoL( errResId );
       
  4786         }
       
  4787     else
       
  4788         {
       
  4789     UpdateSmilTextAttaL();
       
  4790     
       
  4791     Document()->SetBodyModified( ETrue );
       
  4792     CheckBodyForMessageTypeL();
       
  4793     
       
  4794     MsgLengthToNavipaneL();
       
  4795     CheckMaxSmsSizeAndShowNoteL();
       
  4796     SetOrRemoveMaxSizeInEdwin();
       
  4797         }
       
  4798     }
       
  4799 
       
  4800 // ---------------------------------------------------------
       
  4801 // CUniEditorAppUi::DoUserInsertOtherFileL
       
  4802 // ---------------------------------------------------------
       
  4803 //
       
  4804 void CUniEditorAppUi::DoUserInsertOtherFileL( TUniEditorInsertOtherType aType )
       
  4805     {
       
  4806     TBool addAttachment( EFalse );
       
  4807      if( iFixedToolbar )
       
  4808         {
       
  4809         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );    
       
  4810         }
       
  4811     
       
  4812     TBool enabletoolbarext = ETrue;
       
  4813     if ( aType == ETextFile )
       
  4814         {
       
  4815         iInsertingType = EMsgMediaText;
       
  4816         TBool stat= EFalse;
       
  4817         TRAPD(Err,stat = FetchFileL( MsgAttachmentUtils::ENote ));
       
  4818         if (Err == KErrNone && stat)  
       
  4819             {            
       
  4820             addAttachment = ETrue;
       
  4821             }
       
  4822         }
       
  4823     else
       
  4824         {
       
  4825         TFileName* fileName = new( ELeave ) TFileName;
       
  4826         CleanupStack::PushL( fileName );
       
  4827             
       
  4828         if ( MsgAttachmentUtils::FetchAnyFileL( *fileName, *iEikonEnv ) )
       
  4829             {
       
  4830             Document()->DataModel()->MediaResolver().SetCharacterSetRecognition( ETrue );
       
  4831             
       
  4832             TRAPD( error, CreateMediaInfoForInsertL( EMsgMediaUnknown, *fileName ) );
       
  4833             
       
  4834             Document()->DataModel()->MediaResolver().SetCharacterSetRecognition( EFalse );
       
  4835             
       
  4836             User::LeaveIfError( error );
       
  4837             
       
  4838             addAttachment = ETrue;
       
  4839             }
       
  4840         
       
  4841         CleanupStack::PopAndDestroy( fileName );
       
  4842         }
       
  4843   
       
  4844     if ( addAttachment && iInsertingMedia )
       
  4845         {
       
  4846         iInsertingType = iInsertingMedia->MediaType();
       
  4847         if (    SuperDistributionCheckForInsertL() )
       
  4848             {
       
  4849             // CheckMediaInfoForInsertL() for images done in CUniEditorInsertOperation
       
  4850             if (    iInsertingType == EMsgMediaImage
       
  4851                 ||  CheckMediaInfoForInsertL() )
       
  4852                 {
       
  4853                 TBool addSlide( EFalse );
       
  4854                 TBool addAsAttachment( ETrue );
       
  4855                                 
       
  4856                 if ( iInsertingType != EMsgMediaText &&
       
  4857                      iInsertingType != EMsgMediaXhtml && 
       
  4858                      iSmilModel->IsSupportedMediaType( iInsertingType ) )
       
  4859                     {
       
  4860                     addAsAttachment = EFalse;
       
  4861                     if ( ( ( iInsertingType == EMsgMediaImage || 
       
  4862                              iInsertingType == EMsgMediaVideo ||
       
  4863                              iInsertingType == EMsgMediaAnimation ||
       
  4864                              iInsertingType == EMsgMediaSvg ) &&
       
  4865                            ( ObjectsAvailable() & ( EUniImageFlag | EUniVideoFlag | EUniSvgFlag ) ) )||
       
  4866                          ( iInsertingType == EMsgMediaAudio &&
       
  4867                            ( ObjectsAvailable() & ( EUniAudioFlag | EUniVideoFlag | EUniSvgFlag ) ) ) )
       
  4868                         {
       
  4869                         addSlide = ETrue;
       
  4870                         }
       
  4871                     }
       
  4872                 DoStartInsertL( addSlide, addAsAttachment );
       
  4873                 enabletoolbarext = EFalse ; 
       
  4874                 }
       
  4875             }
       
  4876         }
       
  4877         if(enabletoolbarext)
       
  4878             {
       
  4879             if( iFixedToolbar )
       
  4880                 {
       
  4881                 iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  4882                 }
       
  4883             }
       
  4884     }
       
  4885 
       
  4886 // ---------------------------------------------------------
       
  4887 // CUniEditorAppUi::DoUserInsertVCardL
       
  4888 // ---------------------------------------------------------
       
  4889 //
       
  4890 void CUniEditorAppUi::DoUserInsertVCardL()
       
  4891     {
       
  4892     if ( !iVCardOperation )
       
  4893         {
       
  4894         iVCardOperation = CUniEditorVCardOperation::NewL( *this,
       
  4895                                                           *Document(),
       
  4896                                                           FsSession() );
       
  4897         }
       
  4898     
       
  4899     if ( iFixedToolbar )
       
  4900         {
       
  4901           iFixedToolbar->HideItem( EUniCmdFixedToolbarSend, ETrue, ETrue );
       
  4902           iFixedToolbar->HideItem( EUniCmdFixedToolbarAddRecipient, ETrue, ETrue );        
       
  4903           iFixedToolbar->HideItem( EUniCmdFixedToolbarInsert, ETrue, ETrue );      
       
  4904         }
       
  4905 
       
  4906     iEditorFlags |= EToolbarHidden;
       
  4907     
       
  4908     iVCardOperation->Start();    
       
  4909         
       
  4910     ActivateInputBlockerL( iVCardOperation );
       
  4911     }
       
  4912 
       
  4913 // ---------------------------------------------------------
       
  4914 // CUniEditorAppUi::DoUserInsertSvgL
       
  4915 // ---------------------------------------------------------
       
  4916 //
       
  4917 //void CUniEditorAppUi::DoUserInsertSvgL()
       
  4918 //    {
       
  4919 //    __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  4920 //    
       
  4921 //     if( iFixedToolbar ) 
       
  4922 //        {
       
  4923 //        iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );    
       
  4924 //        }
       
  4925 //    iInsertingType = EMsgMediaSvg;
       
  4926 //    
       
  4927 //    TBool fetchFile( ETrue );
       
  4928 //    TBool enabletoolbarext = ETrue;
       
  4929 //    while ( fetchFile )
       
  4930 //        {
       
  4931 //        fetchFile = EFalse;
       
  4932 //        TBool stat= EFalse;
       
  4933 //        TRAPD(Err,stat = FetchFileL( MsgAttachmentUtils::ESVG ));
       
  4934 //        if (Err == KErrNone && stat)  
       
  4935 //            {
       
  4936 //            if ( SuperDistributionCheckForInsertL() )
       
  4937 //                {
       
  4938 //                if ( CheckMediaInfoForInsertL() )
       
  4939 //                    {
       
  4940 //                    TBool addSlide = EFalse;
       
  4941 //                    if ( ObjectsAvailable() & 
       
  4942 //                        ( EUniAudioFlag | EUniVideoFlag | EUniImageFlag | EUniSvgFlag ) )
       
  4943 //                        {
       
  4944 //                        addSlide = ETrue;
       
  4945 //                        }
       
  4946 //                    
       
  4947 //                    DoStartInsertL( addSlide, EFalse );
       
  4948 //                    enabletoolbarext = EFalse; 
       
  4949 //                    }
       
  4950 //                }
       
  4951 //            else
       
  4952 //                {
       
  4953 //                fetchFile = ETrue;
       
  4954 //                }
       
  4955 //            }
       
  4956 //        }
       
  4957 //        if(enabletoolbarext)
       
  4958 //            {
       
  4959 //                //Enable the insert toolbar 
       
  4960 //            if( iFixedToolbar )
       
  4961 //                {
       
  4962 //                iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  4963 //                }
       
  4964 //            }
       
  4965 //    }
       
  4966     
       
  4967 // ---------------------------------------------------------
       
  4968 // CUniEditorAppUi::InitNaviPaneL
       
  4969 // Draws navipane.
       
  4970 // ---------------------------------------------------------
       
  4971 //
       
  4972 void CUniEditorAppUi::InitNaviPaneL()
       
  4973     {
       
  4974     UNILOGGER_WRITE( "-> CUniEditorAppUi::InitNaviPaneL" );
       
  4975     
       
  4976     UpdateIndicatorIconsL();
       
  4977     
       
  4978     TInt charsLeft = 0;
       
  4979     TInt msgsParts = 0;               
       
  4980     CalculateSMSMsgLen(charsLeft,msgsParts);
       
  4981     iPrevSmsLength = charsLeft;
       
  4982     MsgLengthToNavipaneL( EFalse );            
       
  4983     
       
  4984     UNILOGGER_WRITE( "<- CUniEditorAppUi::InitNaviPaneL" );
       
  4985     }
       
  4986 
       
  4987 // ---------------------------------------------------------
       
  4988 // CUniEditorAppUi::UpdateIndicatorIconsL
       
  4989 //
       
  4990 // ---------------------------------------------------------
       
  4991 //
       
  4992 void CUniEditorAppUi::UpdateIndicatorIconsL()
       
  4993     {
       
  4994     UNILOGGER_WRITE( "-> CUniEditorAppUi::UpdateIndicatorIconsL" );
       
  4995     
       
  4996     TInt priorityHigh;
       
  4997     TInt priorityLow;
       
  4998 
       
  4999     if( Document()->UniState() == EUniSms )
       
  5000         { 
       
  5001         UNILOGGER_WRITE( "-> CUniEditorAppUi::UpdateIndicatorIconsL SMS" );
       
  5002         
       
  5003         // If dealing with SMS -> disable them
       
  5004         priorityHigh = EAknIndicatorStateOff;
       
  5005         priorityLow = EAknIndicatorStateOff;
       
  5006         }
       
  5007     else 
       
  5008         {
       
  5009         TUniSendingSettings settings;
       
  5010         CUniEditorPlugin* plugin = MmsPlugin();
       
  5011 
       
  5012         if ( plugin )
       
  5013             {
       
  5014             plugin->GetSendingSettingsL( settings );
       
  5015             }
       
  5016 
       
  5017         if ( settings.iPriority == TUniSendingSettings::EUniPriorityLow )
       
  5018             {
       
  5019             priorityHigh = EAknIndicatorStateOff;
       
  5020             priorityLow = EAknIndicatorStateOn;
       
  5021             }
       
  5022         else if ( settings.iPriority == TUniSendingSettings::EUniPriorityHigh )
       
  5023             {
       
  5024             priorityHigh = EAknIndicatorStateOn;
       
  5025             priorityLow = EAknIndicatorStateOff;
       
  5026             }
       
  5027         else
       
  5028             {
       
  5029             priorityHigh = EAknIndicatorStateOff;
       
  5030             priorityLow = EAknIndicatorStateOff;
       
  5031             }
       
  5032         }
       
  5033     
       
  5034     if ( iSupportedFeatures & EUniFeaturePriority) 
       
  5035         {
       
  5036         UNILOGGER_WRITE( "-> CUniEditorAppUi::UpdateIndicatorIconsL priority" );
       
  5037         
       
  5038         MAknEditingStateIndicator* editIndi = iAvkonEnv->EditingStateIndicator();
       
  5039         
       
  5040         CAknIndicatorContainer* naviIndi = 
       
  5041             static_cast<CAknIndicatorContainer*>( iNaviDecorator->DecoratedControl() );
       
  5042     
       
  5043         // Update the Edwin indicator pane
       
  5044         if ( editIndi )
       
  5045             {
       
  5046             CAknIndicatorContainer* indiContainer = editIndi->IndicatorContainer();
       
  5047             if ( indiContainer )
       
  5048                 {
       
  5049                 indiContainer->SetIndicatorState( TUid::Uid(EAknNaviPaneEditorIndicatorMcePriorityHigh), 
       
  5050                                                   priorityHigh );
       
  5051                 indiContainer->SetIndicatorState( TUid::Uid(EAknNaviPaneEditorIndicatorMcePriorityLow), 
       
  5052                                                   priorityLow );
       
  5053                 }
       
  5054             }
       
  5055             
       
  5056         // Update the navi indicator pane
       
  5057         if ( naviIndi )
       
  5058             {
       
  5059             naviIndi->SetIndicatorState( TUid::Uid(EAknNaviPaneEditorIndicatorMcePriorityHigh), 
       
  5060                                          priorityHigh );
       
  5061             naviIndi->SetIndicatorState( TUid::Uid(EAknNaviPaneEditorIndicatorMcePriorityLow), 
       
  5062                                          priorityLow );
       
  5063             }
       
  5064 
       
  5065         }
       
  5066     
       
  5067     UNILOGGER_WRITE( "<- CUniEditorAppUi::UpdateIndicatorIconsL" );
       
  5068     }
       
  5069 
       
  5070 // ---------------------------------------------------------
       
  5071 // CUniEditorAppUi::ShowInformationNoteL
       
  5072 // ---------------------------------------------------------
       
  5073 //
       
  5074 void CUniEditorAppUi::ShowInformationNoteL( TInt aResourceID, TBool aWaiting )
       
  5075     {
       
  5076     HBufC* prompt = NULL;
       
  5077     
       
  5078     switch ( aResourceID )
       
  5079         {
       
  5080         case R_UNIEDITOR_INFO_OBJECT_TOO_BIG:
       
  5081         case R_UNIEDITOR_INFO_OBJECT_SEND_AS_TOO_BIG:
       
  5082             {
       
  5083             // These are not anymore information notes
       
  5084             ShowConfirmableInfoL( aResourceID );
       
  5085             return;
       
  5086             }
       
  5087         default:
       
  5088             {
       
  5089             prompt = StringLoader::LoadLC( aResourceID, iCoeEnv );
       
  5090             break;
       
  5091             }
       
  5092         }
       
  5093 
       
  5094     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( aWaiting );
       
  5095     note->ExecuteLD( *prompt );
       
  5096     
       
  5097     CleanupStack::PopAndDestroy( prompt );
       
  5098     }
       
  5099 
       
  5100 // ---------------------------------------------------------
       
  5101 // CUniEditorAppUi::ShowErrorNoteL
       
  5102 // ---------------------------------------------------------
       
  5103 //
       
  5104 void CUniEditorAppUi::ShowErrorNoteL( TInt aResourceID, TBool aWaiting )
       
  5105     {
       
  5106     HBufC* prompt = StringLoader::LoadLC( aResourceID, iCoeEnv );
       
  5107     
       
  5108     CAknErrorNote* note = new ( ELeave ) CAknErrorNote( aWaiting );
       
  5109     note->ExecuteLD( *prompt );
       
  5110     
       
  5111     CleanupStack::PopAndDestroy( prompt );
       
  5112     }
       
  5113 
       
  5114 // ---------------------------------------------------------
       
  5115 // CUniEditorAppUi::ShowConfirmationQueryL
       
  5116 // ---------------------------------------------------------
       
  5117 //
       
  5118 TInt CUniEditorAppUi::ShowConfirmationQueryL( TInt aResourceID )
       
  5119     {
       
  5120     HBufC* prompt = StringLoader::LoadLC( aResourceID, iCoeEnv );
       
  5121     
       
  5122     TInt retVal = ShowConfirmationQueryL( *prompt );
       
  5123     
       
  5124     CleanupStack::PopAndDestroy( prompt );
       
  5125     
       
  5126     return retVal;
       
  5127     }
       
  5128 
       
  5129 // ---------------------------------------------------------
       
  5130 // CUniEditorAppUi::ShowConfirmationQueryL
       
  5131 // ---------------------------------------------------------
       
  5132 TInt CUniEditorAppUi::ShowConfirmationQueryL( const TDesC& aText ) const
       
  5133     {
       
  5134     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  5135     return dlg->ExecuteLD( R_UNIEDITOR_CONFIRMATION_QUERY, aText );    
       
  5136     }
       
  5137 
       
  5138 // ---------------------------------------------------------
       
  5139 // CUniEditorAppUi::ShowConfirmationNoQuestionQueryL
       
  5140 // ---------------------------------------------------------
       
  5141 TInt CUniEditorAppUi::ShowConfirmationNoQuestionQueryL( const TDesC& aText ) const
       
  5142     {
       
  5143     // Utilize OK and CANCEL softkeys in confirmation query. Required when 
       
  5144     // the query does not include a question.
       
  5145     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  5146     return dlg->ExecuteLD( R_UNIEDITOR_CONFIRMATION_NO_QUESTION_QUERY, aText );    
       
  5147     }
       
  5148 
       
  5149 // ---------------------------------------------------------
       
  5150 // CUniEditorAppUi::ShowConfirmableInfoL
       
  5151 // ---------------------------------------------------------
       
  5152 //
       
  5153 TInt CUniEditorAppUi::ShowConfirmableInfoL( TInt aResourceID )
       
  5154     {
       
  5155     HBufC* prompt = NULL;
       
  5156     
       
  5157     switch ( aResourceID )
       
  5158         {
       
  5159         case R_UNIEDITOR_INFO_OBJECT_TOO_BIG:
       
  5160         case R_UNIEDITOR_INFO_OBJECT_SEND_AS_TOO_BIG:
       
  5161             {
       
  5162             TInt maxInKilos = ( Document()->MaxMessageSize() + KBytesInKilo - 1 ) / KBytesInKilo;
       
  5163             prompt = StringLoader::LoadLC( aResourceID, maxInKilos, iCoeEnv  );
       
  5164             break;
       
  5165             }
       
  5166         case R_UNIEDITOR_INFO_MAX_SLIDES_ALL:
       
  5167         case R_UNIEDITOR_INFO_MAX_SLIDES_SOME:
       
  5168             {
       
  5169             prompt = StringLoader::LoadLC( aResourceID, Document()->DataModel()->SmilModel().MaxSlideCount(), iCoeEnv  );            
       
  5170             break;
       
  5171             }
       
  5172         default:
       
  5173             {
       
  5174             prompt = StringLoader::LoadLC( aResourceID, iCoeEnv );
       
  5175             break;
       
  5176             }
       
  5177         }
       
  5178         
       
  5179     TInt retVal = KErrNone;
       
  5180     switch ( aResourceID )
       
  5181         {
       
  5182         case R_UNIEDITOR_ERROR_RMODE_CANNOT_OPEN:
       
  5183             retVal = ShowConfirmableInfoErrorL( *prompt );
       
  5184             break;        
       
  5185         default:
       
  5186             retVal = ShowConfirmableInfoL( *prompt );
       
  5187         }
       
  5188         
       
  5189     CleanupStack::PopAndDestroy( prompt );
       
  5190     return retVal;
       
  5191     }
       
  5192 
       
  5193 // ---------------------------------------------------------
       
  5194 // CUniEditorAppUi::ShowConfirmableInfoL
       
  5195 // ---------------------------------------------------------
       
  5196 //
       
  5197 TInt CUniEditorAppUi::ShowConfirmableInfoL( const TDesC& aText ) const
       
  5198     {
       
  5199     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  5200     return dlg->ExecuteLD( R_UNIEDITOR_CONFIRMABLE_INFO, aText );
       
  5201     }
       
  5202 
       
  5203 // ---------------------------------------------------------
       
  5204 // CUniEditorAppUi::ShowConfirmableInfoErrorL
       
  5205 // ---------------------------------------------------------
       
  5206 //
       
  5207 TInt CUniEditorAppUi::ShowConfirmableInfoErrorL( const TDesC& aText ) const
       
  5208     {
       
  5209     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
  5210     return dlg->ExecuteLD( R_UNIEDITOR_CONFIRMABLE_INFO_ERROR, aText );
       
  5211     }
       
  5212 
       
  5213 // ---------------------------------------------------------
       
  5214 // CUniEditorAppUi::ShowGuidedModeConfirmationQueryL
       
  5215 // ---------------------------------------------------------
       
  5216 //
       
  5217 TInt CUniEditorAppUi::ShowGuidedModeConfirmationQueryL( TInt aResourceID )
       
  5218     {
       
  5219     TInt retVal = EFalse;
       
  5220     if ( iEditorFlags & EShowGuidedConf )
       
  5221         {
       
  5222         TInt waitResId( KErrNotFound );
       
  5223         if ( iWaitDialog )
       
  5224             {
       
  5225             // Remove wait note for the confirmation query duration.
       
  5226             waitResId = iWaitResId;
       
  5227             RemoveWaitNote();
       
  5228             }
       
  5229             
       
  5230         retVal = ShowConfirmationQueryL( aResourceID );
       
  5231         
       
  5232         if ( retVal )
       
  5233             {
       
  5234             iEditorFlags &= ~EShowGuidedConf;
       
  5235             }
       
  5236             
       
  5237         if ( waitResId != KErrNotFound )
       
  5238             {
       
  5239             // Set the wait not again visible after confirmation query is shown
       
  5240             // if it was visible before.
       
  5241             ShowWaitNoteL( waitResId );
       
  5242             }
       
  5243         }
       
  5244     else
       
  5245         {
       
  5246         retVal = ( Document()->CreationMode() != EMmsCreationModeRestricted );
       
  5247         }
       
  5248         
       
  5249     return retVal;
       
  5250     }
       
  5251 
       
  5252 
       
  5253 // ---------------------------------------------------------
       
  5254 // CUniEditorAppUi::ShowWaitNoteL
       
  5255 // ---------------------------------------------------------
       
  5256 //
       
  5257 TBool CUniEditorAppUi::ShowWaitNoteL( TInt aResourceId )
       
  5258     {
       
  5259     TInt waitNoteResource = R_UNIEDITOR_WAIT_NOTE;
       
  5260     TBool waitNoteDelayOff = EFalse;
       
  5261     
       
  5262     if ( aResourceId == R_QTN_MSG_WAIT_SENDING_MMS )
       
  5263         {
       
  5264         waitNoteResource = R_UNIEDITOR_WAIT_NOTE_MMS_ICON;
       
  5265         }
       
  5266     else if ( aResourceId == R_QTN_MSG_WAIT_SENDING_SMS )
       
  5267         {
       
  5268         waitNoteResource = R_UNIEDITOR_WAIT_NOTE_SMS_ICON;
       
  5269         }
       
  5270         
       
  5271     HBufC* string = NULL;
       
  5272 
       
  5273     switch ( aResourceId )
       
  5274         {
       
  5275         case R_QTN_MSG_WAIT_SENDING_MMS:
       
  5276         case R_QTN_MSG_WAIT_SENDING_SMS:
       
  5277         case R_QTN_WAIT_MSG_SAVED_OUTBOX:
       
  5278         case R_QTN_UNI_WAIT_SAVING_MESSAGE_NEW:
       
  5279             {
       
  5280             waitNoteDelayOff = ETrue;
       
  5281             }
       
  5282         case R_QTN_UNI_WAIT_OPENING_EDITOR:
       
  5283         case R_QTN_UNI_WAIT_SAVING_MESSAGE:
       
  5284         case R_QTN_UNI_WAIT_INSERTING:
       
  5285             {
       
  5286             string = StringLoader::LoadLC( aResourceId, iCoeEnv );
       
  5287             break;
       
  5288             }
       
  5289         case R_QTN_UNI_WAIT_SLIDE_CHANGE:
       
  5290             {
       
  5291             CArrayFixFlat<TInt>* array = new ( ELeave ) CArrayFixFlat<TInt>( 2 );
       
  5292             CleanupStack::PushL( array );
       
  5293             
       
  5294             array->AppendL( iNextSlide + 1 );
       
  5295             array->AppendL( iSmilModel->SlideCount() );
       
  5296             
       
  5297             string = StringLoader::LoadL( R_QTN_UNI_WAIT_SLIDE_CHANGE,
       
  5298                                           *array,
       
  5299                                           iCoeEnv );
       
  5300             
       
  5301             CleanupStack::PopAndDestroy( array );
       
  5302             CleanupStack::PushL( string );
       
  5303             break;
       
  5304             }
       
  5305         default:
       
  5306             {
       
  5307             break;
       
  5308             }
       
  5309         }
       
  5310 
       
  5311     iWaitDialog = new( ELeave ) CAknWaitDialog( reinterpret_cast<CEikDialog**>( &iWaitDialog ),
       
  5312                                                 waitNoteDelayOff );
       
  5313     iWaitDialog->SetTextL( *string );
       
  5314     CleanupStack::PopAndDestroy( string ); 
       
  5315     
       
  5316     iWaitDialog->SetCallback( this );
       
  5317     
       
  5318     iWaitResId = aResourceId;
       
  5319     
       
  5320     iWaitDialog->PrepareLC( waitNoteResource );
       
  5321     return iWaitDialog->RunLD();
       
  5322     }
       
  5323 
       
  5324 // ---------------------------------------------------------
       
  5325 // CUniEditorAppUi::DialogDismissedL
       
  5326 //
       
  5327 // This is a bit tricky. DialogDismissedL is called when wait dialog
       
  5328 // is really dismissed from the screen. Wait dialog is not neccessary
       
  5329 // dismmissed at once the ProcessFinishedL function is called. This 
       
  5330 // is because of some minimum delayes etc. tied to the visibility of
       
  5331 // wait dialog. But this more complex than that as wait dialog can be dismissed
       
  5332 // by end key or escape key from the screen before the operation has really been
       
  5333 // completed or cancelled. This needs to be taken into account here.
       
  5334 // ---------------------------------------------------------
       
  5335 //
       
  5336 void CUniEditorAppUi::DialogDismissedL( TInt dismissed )
       
  5337     {
       
  5338     if ( dismissed == EAknSoftkeyDone )
       
  5339         {
       
  5340         switch ( iWaitResId )
       
  5341             {
       
  5342             case R_QTN_MSG_WAIT_SENDING_MMS:
       
  5343             case R_QTN_MSG_WAIT_SENDING_SMS:
       
  5344             case R_QTN_WAIT_MSG_SAVED_OUTBOX:
       
  5345                 {
       
  5346                 DoSendComplete2ndPhase();
       
  5347                 break;
       
  5348                 }
       
  5349             case R_QTN_UNI_WAIT_SAVING_MESSAGE_NEW:
       
  5350             case R_QTN_UNI_WAIT_SAVING_MESSAGE:
       
  5351                 {
       
  5352                 DoSavingComplete2ndPhase();
       
  5353                 break;
       
  5354                 }
       
  5355             case R_QTN_UNI_WAIT_OPENING_EDITOR:
       
  5356             case R_QTN_UNI_WAIT_INSERTING:
       
  5357                 {
       
  5358                 break;
       
  5359                 }
       
  5360             case R_QTN_UNI_WAIT_SLIDE_CHANGE:
       
  5361                 {
       
  5362                 break;
       
  5363                 }
       
  5364             default:
       
  5365                 {
       
  5366                 break;
       
  5367                 }
       
  5368             }
       
  5369         }
       
  5370     else if ( dismissed == EEikBidCancel )
       
  5371         {
       
  5372         iWaitDialog = NULL;
       
  5373         }
       
  5374     }
       
  5375 
       
  5376 // ---------------------------------------------------------
       
  5377 // CUniEditorAppUi::RemoveWaitNote
       
  5378 // ---------------------------------------------------------
       
  5379 //
       
  5380 void CUniEditorAppUi::RemoveWaitNote()
       
  5381     {
       
  5382     delete iWaitDialog;
       
  5383     iWaitDialog = NULL;
       
  5384     iWaitResId = -1;
       
  5385     }
       
  5386 
       
  5387 // ---------------------------------------------------------
       
  5388 // CUniEditorAppUi::SetAddressSize
       
  5389 // ---------------------------------------------------------
       
  5390 //
       
  5391 void CUniEditorAppUi::SetAddressSize()
       
  5392     {
       
  5393     if ( !iView )
       
  5394         {
       
  5395         return;
       
  5396         }
       
  5397     
       
  5398     TInt tempBytes( 0 );
       
  5399     TInt entryCnt( 0 );
       
  5400     TInt sizeInBytes( 0 );
       
  5401     for ( TInt i = CUniEditorHeader::EHeaderAddressTo; 
       
  5402           i <= CUniEditorHeader::EHeaderAddressBcc; 
       
  5403           i++ )
       
  5404         {    
       
  5405         if ( iHeader->AddressControl( static_cast<CUniEditorHeader::THeaderFields> (i) ) )
       
  5406             {
       
  5407             iHeader->AddressControl( 
       
  5408                 static_cast<CUniEditorHeader::THeaderFields> (i) )->GetSizeOfAddresses( entryCnt, 
       
  5409                                                                                         tempBytes );
       
  5410             sizeInBytes += tempBytes;
       
  5411             }
       
  5412         }
       
  5413         
       
  5414     Document()->SetAddressSize( sizeInBytes );
       
  5415     }
       
  5416 
       
  5417 // ---------------------------------------------------------
       
  5418 // CUniEditorAppUi::SetSubjectSize
       
  5419 // ---------------------------------------------------------
       
  5420 //
       
  5421 void CUniEditorAppUi::SetSubjectSize()
       
  5422     {
       
  5423     if ( !iView )
       
  5424         {
       
  5425         return;
       
  5426         }
       
  5427         
       
  5428     CMsgExpandableControl* subj = iHeader->SubjectControl();
       
  5429     
       
  5430     if ( subj )
       
  5431         {
       
  5432         TPtrC subject = subj->TextContent().Read( 0, subj->TextContent().DocumentLength() );
       
  5433         Document()->SetSubjectSize( CUniDataUtils::UTF8Size( subject ) );
       
  5434         } 
       
  5435         else
       
  5436         {
       
  5437         Document()->SetSubjectSize( 0 );
       
  5438         }
       
  5439     }
       
  5440 
       
  5441 // ---------------------------------------------------------
       
  5442 // CUniEditorAppUi::RemoveObjectL
       
  5443 // 
       
  5444 // Intended to be called from Objectsview. Updates screen
       
  5445 // when object removed in Objectsview. Objectsview has already
       
  5446 // delete atta from msgstore if needed.
       
  5447 // ---------------------------------------------------------
       
  5448 //
       
  5449 void CUniEditorAppUi::RemoveObjectL( TUniRegion aRegion, 
       
  5450                                      TUniLayout aLayout )
       
  5451     {
       
  5452     if ( iOriginalSlide != -1 && 
       
  5453          Document()->CurrentSlide() != iOriginalSlide )
       
  5454         {
       
  5455         //nothing to do if the modified slide is not
       
  5456         //visible
       
  5457         return;
       
  5458         }
       
  5459 
       
  5460     TBool removeCtrlFocused( EFalse ); 
       
  5461     CMsgBaseControl* ctrl = NULL;
       
  5462     TInt ctrlType = EMsgComponentIdNull;
       
  5463     
       
  5464     switch ( aRegion )
       
  5465         {
       
  5466         case EUniRegionImage:
       
  5467             {
       
  5468             ctrl = iView->RemoveControlL( EMsgComponentIdImage );
       
  5469             if( !ctrl )
       
  5470                 { // Also video clip is located in image region so if no image -> check video control
       
  5471                 ctrl = iView->RemoveControlL( EMsgComponentIdVideo );
       
  5472                 }
       
  5473             if ( !ctrl )
       
  5474                 { // Also SVG presentation is located in image region so if no image -> check SVG control
       
  5475                 ctrl = iView->RemoveControlL( EMsgComponentIdSvg );
       
  5476                 }
       
  5477             
       
  5478             if( ctrl )
       
  5479                 {
       
  5480                 removeCtrlFocused = ctrl->IsFocused();
       
  5481                 ctrlType = ctrl->ControlId();
       
  5482                 }
       
  5483                 
       
  5484             delete ctrl;
       
  5485             break;
       
  5486             }
       
  5487         case EUniRegionAudio:
       
  5488             {
       
  5489             ctrl = iView->RemoveControlL( EMsgComponentIdAudio );
       
  5490             
       
  5491             if( ctrl )
       
  5492                 {
       
  5493                 removeCtrlFocused = ctrl->IsFocused();
       
  5494                 ctrlType = ctrl->ControlId();
       
  5495                 }
       
  5496                 
       
  5497             delete ctrl;
       
  5498             break;
       
  5499             }
       
  5500         case EUniRegionText:
       
  5501             {
       
  5502             // Clear control content
       
  5503             ctrl = BodyCtrl();
       
  5504             
       
  5505             if ( ctrl )
       
  5506                 {
       
  5507                 ctrl->Reset();
       
  5508                 ctrlType = ctrl->ControlId();
       
  5509                 }
       
  5510                 
       
  5511             // Move control position if needed. Move focus & cursor position
       
  5512             CMsgImageControl* imgCtrl = ImageCtrl();
       
  5513 
       
  5514             if ( imgCtrl && ( aLayout == EUniTextFirst ) )
       
  5515                 {
       
  5516                 // Move text control after the image. Cursor loc in text should be ok.
       
  5517                 CMsgBaseControl* bodyCtrl = iView->RemoveControlL( EMsgComponentIdBody );
       
  5518                 iView->AddControlL( bodyCtrl, EMsgComponentIdBody, EMsgAppendControl, EMsgBody );
       
  5519                 }
       
  5520             break;
       
  5521             }
       
  5522         case EUniRegionUnresolved:
       
  5523         default:
       
  5524             {
       
  5525             // Should never be here!
       
  5526             __ASSERT_DEBUG( EFalse, Panic( EUniIllegalComponentType ) );
       
  5527             break;
       
  5528             }
       
  5529         }   
       
  5530         
       
  5531     if ( ( aRegion == EUniRegionImage || 
       
  5532            aRegion == EUniRegionAudio ) )
       
  5533         {
       
  5534         // Change focus to the beginning that scroll bar is updated
       
  5535         // and text editor area removes extra lines
       
  5536         if ( ToCtrl() )
       
  5537             {
       
  5538             iView->SetFocus( EMsgComponentIdTo );
       
  5539             }
       
  5540         else if ( iView->ControlById( EMsgComponentIdAudio ) )
       
  5541             {
       
  5542             //Audio is always first
       
  5543             iView->SetFocus( EMsgComponentIdAudio );
       
  5544             }
       
  5545         else if ( iSmilModel->Layout() == EUniImageFirst &&  
       
  5546                   ImageCtrl() )
       
  5547             {
       
  5548             // should not be need to update focus anymore
       
  5549             iView->SetFocus( EMsgComponentIdImage );
       
  5550             }    
       
  5551         else 
       
  5552             {
       
  5553             // should not be need to update focus anymore
       
  5554             iView->SetFocus( EMsgComponentIdBody );
       
  5555             }
       
  5556 
       
  5557         CMsgBaseControl* focusedControl = iView->FocusedControl();
       
  5558         if ( focusedControl )
       
  5559             {
       
  5560             if ( removeCtrlFocused &&  
       
  5561                  focusedControl->ControlId() != EMsgComponentIdImage &&  
       
  5562                  ctrlType == EMsgComponentIdAudio &&  
       
  5563                  iSmilModel->Layout() == EUniImageFirst &&  
       
  5564                  ImageCtrl() )
       
  5565                 {
       
  5566                 iView->SetFocus( EMsgComponentIdImage );
       
  5567                 }
       
  5568             else  if ( focusedControl->ControlId() != EMsgComponentIdBody )
       
  5569                 {
       
  5570                 iView->SetFocus( EMsgComponentIdBody );            
       
  5571                 }
       
  5572 
       
  5573             if ( ctrlType == EMsgComponentIdAudio &&  
       
  5574                  focusedControl->ControlId() == EMsgComponentIdImage )
       
  5575                 {
       
  5576                 // Set focus here so that imagecontrol will draw navipane if focused.
       
  5577                 iView->FocusedControl()->SetFocus( ETrue, EDrawNow );
       
  5578                 }
       
  5579             }
       
  5580         }
       
  5581     }
       
  5582 
       
  5583 // ---------------------------------------------------------
       
  5584 // CUniEditorAppUi::DoUserChangeOrderL
       
  5585 // ---------------------------------------------------------
       
  5586 //
       
  5587 void CUniEditorAppUi::DoUserChangeOrderL( TUniLayout aLayout )
       
  5588     {
       
  5589     // Both image and video are located in image region so there's only need to check it
       
  5590     CUniObject* img = iSmilModel->GetObject( Document()->CurrentSlide(), EUniRegionImage );
       
  5591 
       
  5592     if ( img )
       
  5593         {
       
  5594         CAknLocalScreenClearer::NewLC( EFalse );
       
  5595         
       
  5596         ChangeOrderL( aLayout );
       
  5597         
       
  5598         CleanupStack::PopAndDestroy(); //clearer
       
  5599         }
       
  5600 
       
  5601     iSmilModel->SetLayoutL( aLayout );
       
  5602     Document()->SetBodyModified( ETrue );
       
  5603     if ( !img )
       
  5604         {
       
  5605         TInt noteId = ( aLayout == EUniTextFirst ) ? R_UNIEDITOR_CONF_TEXTS_FIRST : 
       
  5606                                                      R_UNIEDITOR_CONF_TEXTS_SECOND;
       
  5607         ShowInformationNoteL( noteId, EFalse );
       
  5608         }
       
  5609     }
       
  5610 
       
  5611 // ---------------------------------------------------------
       
  5612 // CUniEditorAppUi::ChangeOrderL
       
  5613 // 
       
  5614 // Intended to be called from Objectsview. Updates screen
       
  5615 // when object order changed. SmilModel should already 
       
  5616 // contain correct layout. Also called by AppUi
       
  5617 // ---------------------------------------------------------
       
  5618 //
       
  5619 void CUniEditorAppUi::ChangeOrderL( TUniLayout aLayout )
       
  5620     {
       
  5621     TInt focusedId = EMsgComponentIdNull;
       
  5622     if ( iView && iView->FocusedControl() )
       
  5623         {
       
  5624         focusedId = iView->FocusedControl()->ControlId();
       
  5625         }
       
  5626         
       
  5627     TInt index = EMsgAppendControl;
       
  5628     CMsgBaseControl* ctrl = iView->RemoveControlL( EMsgComponentIdBody ); // Does not leave
       
  5629 
       
  5630     if ( ctrl ) 
       
  5631         {
       
  5632         switch( aLayout )
       
  5633             {
       
  5634             case EUniImageFirst:
       
  5635                 {
       
  5636                 index = EMsgAppendControl;
       
  5637                 break;
       
  5638                 }
       
  5639             case EUniTextFirst:
       
  5640                 {
       
  5641                 if ( iView->ControlById ( EMsgComponentIdAudio ) )
       
  5642                     {
       
  5643                     index = EMsgFirstControl + 1;
       
  5644                     }
       
  5645                 else
       
  5646                     {
       
  5647                     index = EMsgFirstControl;
       
  5648                     }
       
  5649                 break;
       
  5650                 }
       
  5651             case EUniUndefinedLayout:
       
  5652             default:
       
  5653                 {
       
  5654                 __ASSERT_DEBUG( EFalse, Panic( EUniIllegalLayout ) );
       
  5655                 break;
       
  5656                 }
       
  5657             }
       
  5658             
       
  5659         iView->AddControlL( ctrl, EMsgComponentIdBody, index, EMsgBody );
       
  5660         }
       
  5661     
       
  5662     if ( !( iHeader->IsAddressControl( focusedId ) ||  
       
  5663             focusedId == EMsgComponentIdSubject ||
       
  5664             focusedId == EMsgComponentIdAttachment ) &&
       
  5665          iEditorFlags & ELaunchSuccessful )
       
  5666         {
       
  5667         SetFocusToBodyBeginningL();
       
  5668         }
       
  5669     //else -> keep focus as is
       
  5670     }
       
  5671 
       
  5672 // ---------------------------------------------------------
       
  5673 // CUniEditorAppUi::ReleaseImage
       
  5674 // 
       
  5675 // If there is image control, sets image lock according 
       
  5676 // to parameter. Otherwise does nothing.
       
  5677 // ---------------------------------------------------------
       
  5678 //
       
  5679 void CUniEditorAppUi::ReleaseImage( TBool aRelease )
       
  5680     {
       
  5681     CMsgImageControl* ctrl = ImageCtrl();
       
  5682     
       
  5683     if ( ctrl && aRelease )
       
  5684         {
       
  5685         ctrl->SetImageFileClosed();
       
  5686         }
       
  5687     }
       
  5688 
       
  5689 // ---------------------------------------------------------
       
  5690 // CUniEditorAppUi::MessageSizeInBytes
       
  5691 // ---------------------------------------------------------
       
  5692 //
       
  5693 TInt CUniEditorAppUi::MessageSizeInBytes()
       
  5694     {
       
  5695     TBool useEstimate = EFalse;
       
  5696     
       
  5697     if ( Document()->DataModel()->SmilType() == EMmsSmil &&
       
  5698         ( Document()->BodyModified() || 
       
  5699           iEditorFlags & EUseEstimatedSmilSize ) )
       
  5700         {
       
  5701         useEstimate = ETrue;
       
  5702         iEditorFlags |= EUseEstimatedSmilSize;
       
  5703         }
       
  5704 
       
  5705     TInt size = Document()->MessageSize( useEstimate );
       
  5706     CEikRichTextEditor* bodyEditor = BodyCtrlEditor();
       
  5707     
       
  5708     if ( bodyEditor )
       
  5709         {
       
  5710         TInt limit = ( TUint( size ) >= Document()->MaxMessageSize() ) ? 
       
  5711             BodyCtrl()->TextContent().DocumentLength() : 
       
  5712             KMaxTInt;
       
  5713         bodyEditor->SetTextLimit( limit );
       
  5714         }
       
  5715     return size;
       
  5716     }
       
  5717 
       
  5718 // ---------------------------------------------------------
       
  5719 // CUniEditorAppUi::DoSelectionKeyL
       
  5720 // ---------------------------------------------------------
       
  5721 //
       
  5722 void CUniEditorAppUi::DoSelectionKeyL()
       
  5723     {
       
  5724     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  5725 
       
  5726     if ( ctrl )
       
  5727         {
       
  5728         switch ( ctrl->ControlId() )
       
  5729             {
       
  5730             case EMsgComponentIdTo:
       
  5731             case EMsgComponentIdCc:
       
  5732             case EMsgComponentIdBcc:
       
  5733                 {
       
  5734                 if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
  5735                     {
       
  5736                     break;
       
  5737                     }
       
  5738                     
       
  5739                 // Check is there any recipients in address ctrl
       
  5740                 TBool modified = EFalse;
       
  5741                 if ( iHeader->HasRecipients() )
       
  5742                     {
       
  5743                     // Recipients found. Verify addresses.
       
  5744                     if ( !VerifyAddressesL( modified ) )
       
  5745                         {
       
  5746                         // Illegal address found.
       
  5747                         modified = ETrue;
       
  5748                         }
       
  5749                     }
       
  5750                     
       
  5751                 if ( !modified )//else
       
  5752                     {
       
  5753                     // Nothing changed on the UI. Open PhoneBook.
       
  5754                     DoUserAddRecipientL();
       
  5755                     }
       
  5756                     
       
  5757                 break;
       
  5758                 }
       
  5759             case EMsgComponentIdAttachment:
       
  5760                 {
       
  5761                 DoUserObjectsViewL( ETrue );                
       
  5762                 break;
       
  5763                 }
       
  5764             case EMsgComponentIdImage:
       
  5765                 {
       
  5766                 if ( Document()->DataModel()->SmilType() == E3GPPSmil )
       
  5767                     {
       
  5768                     // focus is on "no-edit" SMIL icon
       
  5769                     PlayPresentationL();
       
  5770                     break;
       
  5771                     } 
       
  5772                 if( Document()->DataModel()->SmilType() == ETemplateSmil )
       
  5773                     {
       
  5774                     break;
       
  5775                     }
       
  5776                 // Otherwise fallthrough
       
  5777                 }
       
  5778             case EMsgComponentIdVideo:
       
  5779             case EMsgComponentIdAudio:
       
  5780             case EMsgComponentIdSvg:
       
  5781                 {
       
  5782                 PlayFocusedItemL();
       
  5783                 break;
       
  5784                 }
       
  5785             case EMsgComponentIdBody:
       
  5786                 {
       
  5787                 MenuBar()->SetMenuTitleResourceId( R_UNIEDITOR_CONTEXT_MENUBAR );
       
  5788                 MenuBar()->SetMenuType(CEikMenuBar::EMenuContext);
       
  5789                 
       
  5790                 TRAPD( err, MenuBar()->TryDisplayMenuBarL() ); 
       
  5791                 
       
  5792                 MenuBar()->SetMenuTitleResourceId( R_UNIEDITOR_MENUBAR );
       
  5793                 MenuBar()->SetMenuType(CEikMenuBar::EMenuOptions);
       
  5794                 
       
  5795                 User::LeaveIfError( err );                
       
  5796                 break;
       
  5797                 }
       
  5798             case EMsgComponentIdSubject:
       
  5799             default:
       
  5800                 {
       
  5801                 break;
       
  5802                 }
       
  5803             }
       
  5804         }
       
  5805     }
       
  5806 
       
  5807 // ---------------------------------------------------------
       
  5808 // CUniEditorAppUi::SetErrorResource
       
  5809 //
       
  5810 // This is a function where error id priorities
       
  5811 // can be defined.
       
  5812 // ---------------------------------------------------------
       
  5813 //
       
  5814 void CUniEditorAppUi::SetErrorResource( TInt& aStoreId, TInt aNewId )
       
  5815     {
       
  5816     if ( ErrorPriority( aNewId ) >= ErrorPriority( aStoreId ) )
       
  5817         {
       
  5818         if ( ( aStoreId == R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT ||  
       
  5819                aStoreId == R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT ) &&
       
  5820              ( aNewId == R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT ||  
       
  5821                aNewId == R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT ||  
       
  5822                aNewId == R_UNIEDITOR_INFO_UNSUPPORTED_OBJECTS ||  
       
  5823                aNewId == R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECTS ) )
       
  5824             {
       
  5825             // Set plural
       
  5826             aStoreId = R_UNIEDITOR_INFO_UNSUPPORTED_OBJECTS;
       
  5827             if ( Document()->CreationModeUserChangeable() &&
       
  5828                  !Document()->CreationMode() )
       
  5829                 {
       
  5830                 aStoreId = R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECTS;
       
  5831                 }
       
  5832             }
       
  5833         else if ( aStoreId == R_UNIEDITOR_QUEST_GUIDED_OBJ &&
       
  5834                   ( aNewId == R_UNIEDITOR_QUEST_GUIDED_OBJ ||
       
  5835                     aNewId == R_UNIEDITOR_QUEST_GUIDED_OBJS ) )
       
  5836             {
       
  5837             // Set plural
       
  5838             aStoreId = R_UNIEDITOR_QUEST_GUIDED_OBJS;
       
  5839             }
       
  5840         else if ( aStoreId == R_UNIEDITOR_QUEST_GUIDED_INC_OBJ &&
       
  5841                   ( aNewId == R_UNIEDITOR_QUEST_GUIDED_INC_OBJ ||
       
  5842                     aNewId == R_UNIEDITOR_QUEST_GUIDED_INC_OBJS ) )
       
  5843             {
       
  5844             // Set plural
       
  5845             aStoreId = R_UNIEDITOR_QUEST_GUIDED_INC_OBJS;
       
  5846             }
       
  5847         else if ( aStoreId != -1 && 
       
  5848                   aStoreId != aNewId )
       
  5849             {
       
  5850             aStoreId = aNewId;
       
  5851             }
       
  5852         else
       
  5853             {
       
  5854             aStoreId = aNewId;
       
  5855             }
       
  5856         }
       
  5857     }
       
  5858     
       
  5859 // ---------------------------------------------------------
       
  5860 // CUniEditorAppUi::ErrorPriority
       
  5861 //
       
  5862 // This is a function where error id priorities
       
  5863 // can be defined.
       
  5864 // ---------------------------------------------------------
       
  5865 //
       
  5866 TInt CUniEditorAppUi::ErrorPriority( TInt aErrorId )
       
  5867     {
       
  5868     TInt priority = 0;
       
  5869     
       
  5870     switch ( aErrorId )
       
  5871         {
       
  5872         case R_UNIEDITOR_INFO_SEND_FORBID_1:
       
  5873             {
       
  5874             priority++; // Fallthrough
       
  5875             }
       
  5876         case R_UNIEDITOR_INFO_OBJECT_TOO_BIG:
       
  5877         case R_UNIEDITOR_INFO_OBJECT_SEND_AS_TOO_BIG:
       
  5878             {
       
  5879             priority++; // Fallthrough
       
  5880             }
       
  5881         case R_UNIEDITOR_INFO_MAX_SLIDES_SOME:
       
  5882         case R_UNIEDITOR_INFO_MAX_SLIDES_ALL:
       
  5883             {
       
  5884             priority++; // Fallthrough
       
  5885             }
       
  5886         case R_UNIEDITOR_QUEST_GUIDED_PRESENTATION:
       
  5887         case R_UNIEDITOR_ERROR_CANNOT_OPEN:
       
  5888         case R_UNIEDITOR_ERROR_RMODE_CANNOT_OPEN:
       
  5889             {
       
  5890             priority++; // Fallthrough
       
  5891             }
       
  5892         case R_UNIEDITOR_QUEST_GUIDED_OBJ:
       
  5893         case R_UNIEDITOR_QUEST_GUIDED_OBJS:
       
  5894             {
       
  5895             priority++; // Fallthrough
       
  5896             }
       
  5897         case R_UNIEDITOR_QUEST_GUIDED_INC_OBJ:
       
  5898         case R_UNIEDITOR_QUEST_GUIDED_INC_OBJS:
       
  5899             {
       
  5900             priority++; // Fallthrough
       
  5901             }
       
  5902         case R_UNIEDITOR_INFO_SCALING_FAILED:
       
  5903         case R_UNIEDITOR_INFO_RMODE_SCALING_FAILED:
       
  5904             {
       
  5905             priority++; // Fallthrough
       
  5906             }
       
  5907         case R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT:
       
  5908         case R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT:
       
  5909         case R_UNIEDITOR_INFO_UNSUPPORTED_OBJECTS:
       
  5910         case R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECTS:
       
  5911         case R_UNIEDITOR_INFO_SOME_NOT_SUPPORTED:
       
  5912         case R_UNIEDITOR_INFO_RMODE_SOME_NOT_SUPPORTED:
       
  5913             {
       
  5914             priority++;
       
  5915             break;
       
  5916             }
       
  5917         default:
       
  5918             {
       
  5919             break;
       
  5920             }
       
  5921         }
       
  5922         
       
  5923     return priority;
       
  5924     }
       
  5925     
       
  5926 // ---------------------------------------------------------
       
  5927 // CUniEditorAppUi::IsPhoneOfflineL
       
  5928 // ---------------------------------------------------------
       
  5929 //
       
  5930 TBool CUniEditorAppUi::IsPhoneOfflineL() const
       
  5931     {
       
  5932     if ( iSupportedFeatures & EUniFeatureOffline )
       
  5933         {    
       
  5934         return MsvUiServiceUtilitiesInternal::IsPhoneOfflineL();
       
  5935         }
       
  5936     else
       
  5937         {
       
  5938         return EFalse;
       
  5939         }       
       
  5940     }
       
  5941 
       
  5942 // ---------------------------------------------------------
       
  5943 // CUniEditorAppUi::LaunchHelpL
       
  5944 // ---------------------------------------------------------
       
  5945 //
       
  5946 void CUniEditorAppUi::LaunchHelpL()
       
  5947     {
       
  5948     // activate Help application
       
  5949     if ( iSupportedFeatures & EUniFeatureHelp )
       
  5950         {
       
  5951         CArrayFix<TCoeHelpContext>* helpContext = AppHelpContextL();
       
  5952         HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), helpContext );
       
  5953         }
       
  5954     }
       
  5955 
       
  5956 // ---------------------------------------------------------
       
  5957 // CUniEditorAppUi::HelpContextL
       
  5958 // ---------------------------------------------------------
       
  5959 //
       
  5960 CArrayFix<TCoeHelpContext>* CUniEditorAppUi::HelpContextL() const
       
  5961     {
       
  5962     CArrayFix<TCoeHelpContext>* array = new( ELeave ) CArrayFixFlat<TCoeHelpContext>( 1 );
       
  5963     CleanupStack::PushL( array ); 
       
  5964   
       
  5965     array->AppendL(TCoeHelpContext(KUniEditorAppId, KUNIFIED_HLP_EDITOR()));
       
  5966     
       
  5967     CleanupStack::Pop( array );
       
  5968     return array;
       
  5969     }
       
  5970 
       
  5971 
       
  5972 // ---------------------------------------------------------
       
  5973 // CUniEditorAppUi::PlayPresentationL
       
  5974 // ---------------------------------------------------------
       
  5975 //
       
  5976 void CUniEditorAppUi::PlayPresentationL()
       
  5977     {
       
  5978     RFile smilFile = Document()->DataModel()->SmilList().GetSmilFileByIndexL( 0 );
       
  5979     if ( !iParser )
       
  5980         {        
       
  5981         iParser = CMDXMLParser::NewL( this );
       
  5982         }
       
  5983     
       
  5984     iParser->ParseFile( smilFile );
       
  5985     // Continues in ParseFileCompleteL
       
  5986     
       
  5987     ActivateInputBlockerL( iParser );
       
  5988     }
       
  5989 
       
  5990 // ---------------------------------------------------------
       
  5991 // CUniEditorAppUi::ParseFileCompleteL
       
  5992 // ---------------------------------------------------------
       
  5993 //
       
  5994 void CUniEditorAppUi::ParseFileCompleteL()
       
  5995     {
       
  5996     // Detach the dom from parser
       
  5997     if ( iDom )
       
  5998         {
       
  5999         delete iDom;
       
  6000         iDom = NULL;
       
  6001         }
       
  6002         
       
  6003     iDom = iParser->DetachXMLDoc();
       
  6004 
       
  6005     // Delete inputBlocker
       
  6006     DeactivateInputBlocker();
       
  6007 
       
  6008     // Start playing the presentation    
       
  6009     DoCompletePlayPresentationL();
       
  6010     }
       
  6011 
       
  6012 // ---------------------------------------------------------
       
  6013 // CUniEditorAppUi::PlayPresentationL
       
  6014 //
       
  6015 // First go through every object in the presentation to find out
       
  6016 // whether audio should be enabled. After this launch SMIL player.
       
  6017 // ---------------------------------------------------------
       
  6018 //
       
  6019 void CUniEditorAppUi::DoCompletePlayPresentationL()
       
  6020     {
       
  6021     TBool audio = EFalse;
       
  6022     CUniObjectList& objects = Document()->DataModel()->ObjectList();
       
  6023     TInt count = objects.Count();
       
  6024     while ( count-- )
       
  6025         {
       
  6026         CUniObject* object = objects.GetByIndex( count );
       
  6027         TMsgMediaType media = object->MediaType();
       
  6028         
       
  6029         if ( media == EMsgMediaAudio )
       
  6030             {
       
  6031             audio = ETrue;
       
  6032             break;
       
  6033             }
       
  6034         else if ( media == EMsgMediaVideo )
       
  6035             {
       
  6036             CMsgVideoInfo* info = static_cast<CMsgVideoInfo*>( object->MediaInfo() );
       
  6037             if ( !info ||
       
  6038                  info->IsAudio() )
       
  6039                 {
       
  6040                 audio = ETrue;
       
  6041                 break;
       
  6042                 }
       
  6043             }
       
  6044         }
       
  6045         
       
  6046     CSmilPlayerDialog* smilPlayer = CSmilPlayerDialog::NewL( iDom,
       
  6047                                                              &objects,
       
  6048                                                              KNullDesC(),
       
  6049                                                              ETrue,
       
  6050                                                              audio );
       
  6051     
       
  6052     if ( iFixedToolbar )
       
  6053         {
       
  6054         iFixedToolbar->SetToolbarVisibility(EFalse, EFalse);
       
  6055         }
       
  6056     
       
  6057     iEditorFlags |= EToolbarHidden;
       
  6058     CleanupStack::PushL( TCleanupItem( EnableFixedToolbar, this ) );
       
  6059     
       
  6060     SetKeyEventFlags(0);
       
  6061     
       
  6062     CleanupStack::PushL( TCleanupItem( DisableSendKey, this ) );
       
  6063     smilPlayer->ExecuteLD();
       
  6064     
       
  6065     CleanupStack::PopAndDestroy(2);// DisableSendKey,EnableFixedToolbar
       
  6066     
       
  6067     if ( iFixedToolbar )
       
  6068         {
       
  6069         iFixedToolbar->SetToolbarVisibility(ETrue, EFalse);
       
  6070         }
       
  6071     // re-calculate all pos and dimensions of layout's widgets, after
       
  6072     // status pane is set back to usual and fixed-toolbar is made visible.
       
  6073     HandleResourceChangeL(KEikDynamicLayoutVariantSwitch);
       
  6074     }
       
  6075 
       
  6076 // ---------------------------------------------------------
       
  6077 // CUniEditorAppUi::RemoveTemplateL
       
  6078 // 
       
  6079 // First confirms the operation from user. After user has 
       
  6080 // confirmed the operation remove all the objects and SMILs
       
  6081 // from the message. Enable toolbar and set modified flag on. 
       
  6082 // Then replace the presentation icon with body text control and add
       
  6083 // single slide is no slides exists. Finally check the message type and
       
  6084 // update statuspane according to current message type.
       
  6085 // ---------------------------------------------------------
       
  6086 //
       
  6087 void CUniEditorAppUi::RemoveTemplateL()
       
  6088     {
       
  6089     if ( ShowConfirmationQueryL( R_UNIEDITOR_QUEST_REMOVE_TEMPLATE ) )
       
  6090         {
       
  6091         CUniObjectList& objectList = Document()->DataModel()->ObjectList();
       
  6092         objectList.RemoveAllObjectsL();
       
  6093         
       
  6094         CMsvStore* editStore = Document()->Mtm().Entry().EditStoreL();
       
  6095         CleanupStack::PushL( editStore );            
       
  6096         Document()->DataModel()->SmilList().RemoveSmilL( *editStore );
       
  6097         editStore->CommitL();
       
  6098         CleanupStack::PopAndDestroy( editStore );
       
  6099 
       
  6100         Document()->DataModel()->SetSmilType( EMmsSmil );
       
  6101         
       
  6102         UpdateToolbarL();
       
  6103         
       
  6104         Document()->SetBodyModified( ETrue );
       
  6105 
       
  6106         // Delete icon
       
  6107         iView->DeleteControlL( EMsgComponentIdImage );  // Does not leave
       
  6108         
       
  6109         // Add body
       
  6110         CMsgBodyControl* bodyC = CMsgBodyControl::NewL(iView);
       
  6111         CleanupStack::PushL( bodyC );
       
  6112         
       
  6113         iView->AddControlL( bodyC, EMsgComponentIdBody, EMsgAppendControl, EMsgBody );
       
  6114         
       
  6115         CleanupStack::Pop( bodyC );
       
  6116         
       
  6117         iView->SetFocus( EMsgComponentIdBody );
       
  6118 
       
  6119         if ( !iSmilModel->SlideCount() )
       
  6120             {
       
  6121             iSmilModel->AddSlideL();
       
  6122             }
       
  6123             
       
  6124         CheckBodyForMessageTypeL();
       
  6125         InitNaviPaneL();
       
  6126         SetTitleL();
       
  6127         }
       
  6128     }
       
  6129 
       
  6130 // ---------------------------------------------------------
       
  6131 // CUniEditorAppUi::SetFocusToBodyBeginningL
       
  6132 // ---------------------------------------------------------
       
  6133 //
       
  6134 void CUniEditorAppUi::SetFocusToBodyBeginningL()
       
  6135     {
       
  6136     if ( ToCtrl() )
       
  6137         {
       
  6138         // Set focus always first to "To" in order to 
       
  6139         // make "To" field visible
       
  6140         iView->SetFocus( EMsgComponentIdTo );
       
  6141         }
       
  6142         
       
  6143     if ( BodyCtrl() )
       
  6144         {
       
  6145         BodyCtrl()->SetCursorPosL( 0 );
       
  6146         }
       
  6147         
       
  6148     TBool focusId = EMsgComponentIdBody;
       
  6149     
       
  6150     if ( iView->ControlById( EMsgComponentIdAudio ) )
       
  6151         {
       
  6152         //Audio is always first
       
  6153         focusId = EMsgComponentIdAudio;
       
  6154         } 
       
  6155     // When this is called from DoUserChangerOrderL the new layout is not
       
  6156     // yet updated in SmilModel -> that's why the if's below seem to be mixed
       
  6157     else if ( iSmilModel->Layout() == EUniTextFirst &&
       
  6158               iView->ControlById( EMsgComponentIdImage ) )
       
  6159         {
       
  6160         focusId = EMsgComponentIdImage;
       
  6161         }
       
  6162     else if ( iSmilModel->Layout() == EUniTextFirst &&
       
  6163               iView->ControlById( EMsgComponentIdVideo ) )
       
  6164         {
       
  6165         focusId = EMsgComponentIdVideo;
       
  6166         }
       
  6167     //else -> EMsgComponentIdBody
       
  6168 
       
  6169     iView->SetFocus( focusId );
       
  6170     }
       
  6171 
       
  6172 // ---------------------------------------------------------
       
  6173 // CUniEditorAppUi::DoInsertCompleteL
       
  6174 // ---------------------------------------------------------
       
  6175 //
       
  6176 void CUniEditorAppUi::DoInsertCompleteL( TUniEditorOperationEvent aEvent )
       
  6177     {
       
  6178     // focus and cursor positions handling
       
  6179     TBool insertedAsAttachment = EFalse;
       
  6180     
       
  6181     if ( aEvent == EUniEditorOperationComplete )
       
  6182         {  
       
  6183         if ( iInsertOperation->IsAddedAsAttachment() )
       
  6184             {
       
  6185             Document()->SetHeaderModified( ETrue );
       
  6186             insertedAsAttachment = ETrue;
       
  6187             }
       
  6188         else
       
  6189             {
       
  6190            SetFocusToBodyBeginningL();
       
  6191             
       
  6192             switch ( iInsertingType )
       
  6193                 {
       
  6194                 case EMsgMediaImage:
       
  6195                     {
       
  6196                     // Set focus always first to the image control...
       
  6197                     iView->SetFocus( EMsgComponentIdImage );
       
  6198                     break;
       
  6199                     }
       
  6200                 case EMsgMediaAudio:
       
  6201                     {
       
  6202                     // Set focus always first to the audio control
       
  6203                     iView->SetFocus( EMsgComponentIdAudio );
       
  6204                     break;
       
  6205                     }
       
  6206                 case EMsgMediaVideo:
       
  6207                     {
       
  6208                     // Set focus always first to the audio control
       
  6209                     iView->SetFocus( EMsgComponentIdVideo );
       
  6210                     break;
       
  6211                     }
       
  6212                 case EMsgMediaSvg:
       
  6213                     {
       
  6214                     // Set focus always first to the audio control
       
  6215                     iView->SetFocus( EMsgComponentIdSvg );
       
  6216                     break;
       
  6217                     }
       
  6218                 default:
       
  6219                     {
       
  6220                     // nothing to do
       
  6221                     break;
       
  6222                     }
       
  6223                 } 
       
  6224             }
       
  6225             
       
  6226         iInsertingType = EMsgMediaUnknown;
       
  6227         }
       
  6228         
       
  6229     TUniState oldState = Document()->UniState();
       
  6230     DoInsertComplete2ndPhaseL();
       
  6231     
       
  6232     // Lit up display backlight in case it has gone off due to a long operation
       
  6233     User::ResetInactivityTime();
       
  6234     
       
  6235     if( insertedAsAttachment && 
       
  6236         ( oldState == Document()->UniState() ||  
       
  6237           !iPopupNote ) )
       
  6238         {   
       
  6239         // The message type did not change or change popup note is not shown
       
  6240         // so show the attachment added note
       
  6241         ShowInformationNoteL( R_UNIEDITOR_QTN_UNIFIED_ATTACHMENT_ADDED, EFalse );
       
  6242         }
       
  6243     
       
  6244     }
       
  6245 
       
  6246 // ---------------------------------------------------------
       
  6247 // CUniEditorAppUi::DoInsertComplete2ndPhaseL
       
  6248 // ---------------------------------------------------------
       
  6249 //
       
  6250 void CUniEditorAppUi::DoInsertComplete2ndPhaseL()
       
  6251     {
       
  6252     RemoveWaitNote();
       
  6253     
       
  6254     delete iScreenClearer;
       
  6255     iScreenClearer = NULL;
       
  6256     
       
  6257     CheckBodyForMessageTypeL();
       
  6258     SetTitleL();
       
  6259     InitNaviPaneL();
       
  6260     ShowInsertErrorsL();
       
  6261     }
       
  6262 
       
  6263 // ---------------------------------------------------------
       
  6264 // CUniEditorAppUi::ShowInsertErrorsL
       
  6265 // ---------------------------------------------------------
       
  6266 //
       
  6267 void CUniEditorAppUi::ShowInsertErrorsL()
       
  6268     {
       
  6269     TInt errRes( KErrNotFound );
       
  6270     
       
  6271     CArrayFixFlat<TInt>* errors = iInsertOperation->GetErrors();
       
  6272     
       
  6273     for ( TInt i = 0; i < errors->Count(); i++ )
       
  6274         {
       
  6275         switch ( errors->At( i ) )
       
  6276             {
       
  6277             case EUniProcessImgOutOfMemory:
       
  6278             case EUniProcessImgOutOfDisk:
       
  6279             case EUniProcessImgNotFound:
       
  6280             case EUniProcessImgNonConformant:
       
  6281             case EUniProcessImgScalingFailed:
       
  6282             case EUniProcessImgCompressFailed:
       
  6283             case EUniProcessImgCouldNotScale:
       
  6284                 {
       
  6285                 if( Document()->CreationModeUserChangeable() &&
       
  6286                     Document()->CreationMode() == EMmsCreationModeRestricted )
       
  6287                     {
       
  6288                     SetErrorResource( errRes, R_UNIEDITOR_INFO_RMODE_SCALING_FAILED );
       
  6289                     }
       
  6290                 else
       
  6291                     {
       
  6292                     SetErrorResource( errRes, R_UNIEDITOR_INFO_SCALING_FAILED );
       
  6293                     }
       
  6294                 break;
       
  6295                 }
       
  6296             case EUniInsertTooBig:
       
  6297                 {
       
  6298                 SetErrorResource( errRes, R_UNIEDITOR_INFO_OBJECT_TOO_BIG );
       
  6299                 break;
       
  6300                 }
       
  6301             case EUniProcessImgUserAbort:
       
  6302             case EUniInsertUserGuidedAbort:
       
  6303                 {
       
  6304                 return;
       
  6305                 }
       
  6306             case EUniInsertNotSupported:
       
  6307             case EUniInsertSlideChangeFailed:
       
  6308                 {
       
  6309                 if( Document()->CreationModeUserChangeable() &&
       
  6310                     Document()->CreationMode() == EMmsCreationModeRestricted )
       
  6311                     {
       
  6312                     SetErrorResource( errRes, R_UNIEDITOR_INFO_RMODE_UNSUPPORTED_OBJECT );
       
  6313                     }
       
  6314                 else
       
  6315                     {
       
  6316                     SetErrorResource( errRes, R_UNIEDITOR_INFO_UNSUPPORTED_OBJECT );
       
  6317                     }
       
  6318                 break;
       
  6319                 }
       
  6320             default:
       
  6321                 {
       
  6322                 break;
       
  6323                 }
       
  6324             }
       
  6325         }
       
  6326         
       
  6327     if ( errRes != KErrNotFound )
       
  6328         {
       
  6329         ShowInformationNoteL( errRes, EFalse );
       
  6330         }
       
  6331     }
       
  6332 
       
  6333 // ---------------------------------------------------------
       
  6334 // CUniEditorAppUi::EditorOperationEvent
       
  6335 //
       
  6336 // This is marked as non-leaving function since this is leaving with
       
  6337 // KLeaveExit only (also Exit() is not leaving even if it is leaving).
       
  6338 // ---------------------------------------------------------
       
  6339 //
       
  6340 void CUniEditorAppUi::EditorOperationEvent( TUniEditorOperationType aOperation,
       
  6341                                             TUniEditorOperationEvent aEvent )
       
  6342     {
       
  6343     if ( iEditorFlags & EEditorExiting )
       
  6344         {
       
  6345         // Do not handle any event if we are exiting from editor.
       
  6346         return;
       
  6347         }
       
  6348     
       
  6349     if ( aEvent == EUniEditorOperationComplete ||  
       
  6350          aEvent == EUniEditorOperationError ||
       
  6351          aEvent == EUniEditorOperationCancel )
       
  6352         {
       
  6353         DeactivateInputBlocker();
       
  6354         iEditorFlags &= ~EMsgEditInProgress;   
       
  6355         
       
  6356         if ( aEvent == EUniEditorOperationCancel &&
       
  6357              aOperation != EUniEditorOperationSend )
       
  6358             {
       
  6359             // Operation by operation should be considered what is proper action 
       
  6360             // in Cancel situation. Send operation handles the removing of wait note
       
  6361             // correctly. When this is done with all operations operation checking
       
  6362             // can be removed.
       
  6363             EndActiveWait();
       
  6364             RemoveWaitNote();
       
  6365         
       
  6366             delete iScreenClearer;
       
  6367             iScreenClearer = NULL;
       
  6368             }    
       
  6369         }
       
  6370         
       
  6371     TRAPD( error, DoEditorOperationEventL( aOperation, aEvent ) );
       
  6372     if ( error != KErrNone )
       
  6373         {
       
  6374         // Handle operation handling error.
       
  6375         if ( error == KLeaveExit )
       
  6376             {
       
  6377             // Leaving with KLeaveExit does not make function leavable. See Exit()
       
  6378             User::Leave( error );
       
  6379             }
       
  6380         else 
       
  6381             {
       
  6382             iEikonEnv->HandleError( error );
       
  6383             
       
  6384             if ( aOperation == EUniEditorOperationLaunch )
       
  6385                 {
       
  6386                 Exit( EAknSoftkeyClose );
       
  6387                 }
       
  6388             }
       
  6389         }
       
  6390     }
       
  6391 
       
  6392 // ---------------------------------------------------------
       
  6393 // CUniEditorAppUi::DoEditorOperationEventL
       
  6394 // ---------------------------------------------------------
       
  6395 //
       
  6396 void CUniEditorAppUi::DoEditorOperationEventL( TUniEditorOperationType aOperation,
       
  6397                                                TUniEditorOperationEvent aEvent )
       
  6398     {
       
  6399     switch ( aOperation )
       
  6400         {
       
  6401         case EUniEditorOperationChangeSlide:
       
  6402             {
       
  6403             DoChangeSlideCompleteL();
       
  6404             break;
       
  6405             }
       
  6406         case EUniEditorOperationInsert:
       
  6407             {
       
  6408             if ( aEvent == EUniEditorOperationProcessing )
       
  6409                 {
       
  6410                 if ( iEditorFlags & EInsertAddsSlide )
       
  6411                     {
       
  6412                     iScreenClearer = CAknLocalScreenClearer::NewLC( EFalse );
       
  6413                     CleanupStack::Pop();
       
  6414                     }
       
  6415                 }
       
  6416             else
       
  6417                 {
       
  6418                 DoInsertCompleteL( aEvent );
       
  6419                 }
       
  6420             break;
       
  6421             }
       
  6422         case EUniEditorOperationLaunch:
       
  6423             {
       
  6424             if ( aEvent == EUniEditorOperationComplete )
       
  6425                 {
       
  6426                 DoLaunchCompleteL();
       
  6427                 }
       
  6428             else
       
  6429                 {
       
  6430                 DoDelayedExit( 0 );
       
  6431                 iEditorFlags |= EEditorClosing;
       
  6432                 }
       
  6433             break;
       
  6434             }
       
  6435         case EUniEditorOperationSave:
       
  6436             {
       
  6437             DoSaveCompleteL();
       
  6438             break;
       
  6439             }
       
  6440         case EUniEditorOperationSend:
       
  6441             {
       
  6442             DoSendCompleteL();
       
  6443             break;
       
  6444             }
       
  6445         case EUniEditorOperationVCard:
       
  6446             {
       
  6447             DoVCardCompleteL();
       
  6448             break;
       
  6449             }
       
  6450         case EUniEditorOperationPreview:
       
  6451             {
       
  6452             // Expecting 'processing' but in case of error, other states are aacceptable, too.
       
  6453             RemoveWaitNote();
       
  6454             break;
       
  6455             }
       
  6456         default:
       
  6457             {
       
  6458             // nothing to do
       
  6459             break;
       
  6460             }
       
  6461         }
       
  6462     }
       
  6463     
       
  6464 // ---------------------------------------------------------
       
  6465 // CUniEditorAppUi::EditorOperationQuery
       
  6466 // ---------------------------------------------------------
       
  6467 //
       
  6468 TBool CUniEditorAppUi::EditorOperationQuery( TUniEditorOperationType aOperation,
       
  6469                                              TUniEditorOperationQuery aQuery )
       
  6470     {
       
  6471     TBool ret( EFalse );
       
  6472     TRAP_IGNORE( ret = DoEditorOperationQueryL( aOperation, aQuery ) );
       
  6473     return ret;
       
  6474     }
       
  6475 
       
  6476 // ---------------------------------------------------------
       
  6477 // CUniEditorAppUi::DoEditorOperationQueryL
       
  6478 // ---------------------------------------------------------
       
  6479 //
       
  6480 TBool CUniEditorAppUi::DoEditorOperationQueryL( TUniEditorOperationType /*aOperation*/,
       
  6481                                                 TUniEditorOperationQuery aQuery )
       
  6482     {
       
  6483     switch ( aQuery )
       
  6484         {
       
  6485         case EMEOQueryGuidedInsertLarge:
       
  6486             {
       
  6487             return ShowGuidedModeConfirmationQueryL( R_UNIEDITOR_QUEST_INSERT_LARGE );
       
  6488             }
       
  6489         case EMEOQueryGuidedObject:
       
  6490             {
       
  6491             return ShowGuidedModeConfirmationQueryL( R_UNIEDITOR_QUEST_GUIDED_OBJ );
       
  6492             }
       
  6493         default:
       
  6494             {
       
  6495             break;
       
  6496             }
       
  6497         }
       
  6498     return ETrue;
       
  6499     }
       
  6500 
       
  6501 // ---------------------------------------------------------
       
  6502 // CUniEditorAppUi::DoChangeSlideCompleteL
       
  6503 // ---------------------------------------------------------
       
  6504 //
       
  6505 void CUniEditorAppUi::DoChangeSlideCompleteL()
       
  6506     {
       
  6507     EndActiveWait();
       
  6508     RemoveWaitNote();
       
  6509     
       
  6510     if ( iChangeSlideOperation->GetErrors()->Count() )
       
  6511         {
       
  6512         delete iScreenClearer;
       
  6513         iScreenClearer = NULL;
       
  6514         
       
  6515         ExitAndSaveL();
       
  6516         }
       
  6517     else
       
  6518         {
       
  6519         DoSetFocusL();
       
  6520         
       
  6521         delete iScreenClearer;
       
  6522         iScreenClearer = NULL;
       
  6523         
       
  6524         CheckBodyForMessageTypeL();
       
  6525         SetTitleL();
       
  6526         InitNaviPaneL();
       
  6527         }
       
  6528     }
       
  6529 
       
  6530 // ---------------------------------------------------------
       
  6531 // CUniEditorAppUi::DoLaunchCompleteL
       
  6532 //
       
  6533 // First removes wait note from the screen. After this launch 
       
  6534 // relating note processing is done and if lanch should be aborted
       
  6535 // immediatelly performs delayed exit (i.e. starts idle timer
       
  6536 // to call Exit() function on it's callback). Rest of the launching
       
  6537 // related processing is done at the FinalizeLaunch function.
       
  6538 // ---------------------------------------------------------
       
  6539 //
       
  6540 void CUniEditorAppUi::DoLaunchCompleteL()
       
  6541     {
       
  6542     // Does no harm to call this even if no wait note is set.
       
  6543     RemoveWaitNote();        
       
  6544 
       
  6545     TBool shutDown( EFalse );
       
  6546     ShowLaunchNotesL( shutDown );
       
  6547     
       
  6548     if ( shutDown )
       
  6549         {
       
  6550         // Avoid direct Exit(). It causes actually leaving with -1003. 
       
  6551         // If non-conformant object is sent from sendui and user is not
       
  6552         // willing to allow free moded Exit() was called previously and
       
  6553         // caused CMmsEditorLaunchOperation to leave, because this function
       
  6554         // is called inside RunL()
       
  6555         // give time to show notes
       
  6556         DoDelayedExit( KDelayedExitShort );
       
  6557         iEditorFlags |= EEditorClosing;
       
  6558         }
       
  6559     else
       
  6560         {
       
  6561         FinalizeLaunchL();
       
  6562         }
       
  6563     }
       
  6564 
       
  6565 // ---------------------------------------------------------
       
  6566 // CUniEditorAppUi::DoDelayedExit
       
  6567 // ---------------------------------------------------------
       
  6568 //
       
  6569 void CUniEditorAppUi::DoDelayedExit( TInt aDelayTime )
       
  6570     {
       
  6571     iIdle->Cancel();
       
  6572     iIdle->Start( aDelayTime,
       
  6573                   aDelayTime, 
       
  6574                   TCallBack( DelayedExitL, this ));
       
  6575     }
       
  6576 
       
  6577 // ---------------------------------------------------------
       
  6578 // CUniEditorAppUi::DelayedExit
       
  6579 // ---------------------------------------------------------
       
  6580 //
       
  6581 TInt CUniEditorAppUi::DelayedExitL( TAny* aThis )
       
  6582     {
       
  6583     UNILOGGER_WRITE( "-> CUniEditorAppUi::DelayedExitL" );
       
  6584     
       
  6585     CUniEditorAppUi* editor = static_cast<CUniEditorAppUi*>( aThis );
       
  6586     editor->ExitAndSaveL();
       
  6587     
       
  6588     UNILOGGER_WRITE( "<- CUniEditorAppUi::DelayedExitL" );
       
  6589     
       
  6590     return KErrNone;
       
  6591     }
       
  6592 
       
  6593 // ---------------------------------------------------------
       
  6594 // CUniEditorAppUi::DoSaveCompleteL
       
  6595 // ---------------------------------------------------------
       
  6596 //
       
  6597 void CUniEditorAppUi::DoSaveCompleteL()
       
  6598     {
       
  6599     UNILOGGER_WRITE( "-> CUniEditorAppUi::DoSaveCompleteL" );
       
  6600 
       
  6601     if ( iWaitDialog )
       
  6602         {
       
  6603         // Processing continued at DialogDismissedL when wait note
       
  6604         // has dismissed itself.
       
  6605         iWaitDialog->ProcessFinishedL();
       
  6606         }    
       
  6607     else
       
  6608         {
       
  6609         DoSavingComplete2ndPhase();
       
  6610         }
       
  6611     
       
  6612     UNILOGGER_WRITE( "<- CUniEditorAppUi::DoSaveCompleteL" );
       
  6613     }
       
  6614     
       
  6615 // ---------------------------------------------------------
       
  6616 // CUniEditorAppUi::DoSavingComplete2ndPhase
       
  6617 // ---------------------------------------------------------
       
  6618 //
       
  6619 void CUniEditorAppUi::DoSavingComplete2ndPhase()
       
  6620     {
       
  6621     //TODO: Update prev save type!
       
  6622     CMDXMLDocument* dom = iSaveOperation->DetachDom();
       
  6623     if ( dom )
       
  6624         {
       
  6625         Document()->DataModel()->SetDom( dom );
       
  6626         }
       
  6627 
       
  6628     EndActiveWait();
       
  6629     
       
  6630     if ( iEditorFlags & EEditorClosing )
       
  6631         {
       
  6632         if ( Document()->UniState() == EUniMms )
       
  6633             {              
       
  6634             CUniEditorPlugin* mmsPlugin = Document()->MmsPlugin();  
       
  6635             TRAP_IGNORE(mmsPlugin->ConvertToL( Document()->Mtm().Entry().EntryId()));
       
  6636             }
       
  6637         else if ( Document()->UniState() == EUniSms )
       
  6638             {
       
  6639             CUniEditorPlugin* smsPlugin = Document()->SmsPlugin();  
       
  6640             TRAP_IGNORE(smsPlugin->ConvertToL( Document()->Mtm().Entry().EntryId()));            
       
  6641             }
       
  6642             
       
  6643         DoDelayedExit( 0 );
       
  6644         }
       
  6645     }
       
  6646 
       
  6647 // ---------------------------------------------------------
       
  6648 // CUniEditorAppUi::DoSendCompleteL
       
  6649 //
       
  6650 // Sending operation completed. If wait note is still available
       
  6651 // (i.e. it is not cancelled from the screen by some external event)
       
  6652 // we call ProcessFinishedL so that prosessing is finished. Otherwise 
       
  6653 // we have to complete the operation by ourself.
       
  6654 // ---------------------------------------------------------
       
  6655 //
       
  6656 void CUniEditorAppUi::DoSendCompleteL()
       
  6657     {
       
  6658     UNILOGGER_WRITE( "-> CUniEditorAppUi::DoSendCompleteL" );
       
  6659 
       
  6660     if ( iWaitDialog )
       
  6661         {
       
  6662         // Processing continued at DialogDismissedL when wait note
       
  6663         // has dismissed itself.
       
  6664         iWaitDialog->ProcessFinishedL();
       
  6665         }    
       
  6666     else
       
  6667         {
       
  6668         DoSendComplete2ndPhase();
       
  6669         }
       
  6670     
       
  6671     UNILOGGER_WRITE( "<- CUniEditorAppUi::DoSendCompleteL" );
       
  6672     }
       
  6673 
       
  6674 // ---------------------------------------------------------
       
  6675 // CUniEditorAppUi::DoSendComplete2ndPhase
       
  6676 //
       
  6677 // Performs the real send operation completing code.
       
  6678 // ---------------------------------------------------------
       
  6679 //
       
  6680 void CUniEditorAppUi::DoSendComplete2ndPhase()
       
  6681     {
       
  6682     UNILOGGER_WRITE( "-> CUniEditorAppUi::DoSendComplete2ndPhase" );
       
  6683 
       
  6684     // Get errors from send operation
       
  6685     CArrayFixFlat<TInt>* errors = iSendOperation->GetErrors();
       
  6686     
       
  6687     if ( errors->Count() > 0 )
       
  6688         {
       
  6689         iEikonEnv->HandleError( errors->At( 0 ) );
       
  6690         iEditorFlags &= ~EEditorClosing;
       
  6691         return;
       
  6692         }
       
  6693         
       
  6694     DoDelayedExit( 0 );
       
  6695     
       
  6696     UNILOGGER_WRITE( "<- CUniEditorAppUi::DoSendComplete2ndPhase" );
       
  6697     }
       
  6698 
       
  6699 // ---------------------------------------------------------
       
  6700 // CUniEditorAppUi::DoVCardCompleteL
       
  6701 // ---------------------------------------------------------
       
  6702 //
       
  6703 void CUniEditorAppUi::DoVCardCompleteL()
       
  6704     {
       
  6705     if ( iFixedToolbar )
       
  6706         {
       
  6707           iFixedToolbar->HideItem( EUniCmdFixedToolbarSend, EFalse, ETrue );
       
  6708           iFixedToolbar->HideItem( EUniCmdFixedToolbarAddRecipient, EFalse, ETrue );        
       
  6709           iFixedToolbar->HideItem( EUniCmdFixedToolbarInsert, EFalse, ETrue );    
       
  6710         }
       
  6711     
       
  6712     iEditorFlags &= ~EToolbarHidden;
       
  6713     
       
  6714     TInt addedVCardCount = iVCardOperation->AddedVCardCount();
       
  6715     TBool oldState = Document()->UniState();
       
  6716 
       
  6717     // Update navipane and type of message        
       
  6718     CheckBodyForMessageTypeL();
       
  6719     MsgLengthToNavipaneL();
       
  6720     if (AknLayoutUtils::PenEnabled() )
       
  6721         {
       
  6722            iPeninputServer.UpdateAppInfo( KNullDesC, EAppIndicatorMsg );    
       
  6723         }
       
  6724     
       
  6725     if ( addedVCardCount > 0 )
       
  6726         {
       
  6727         Document()->SetHeaderModified( ETrue );
       
  6728         }
       
  6729     
       
  6730     if ( !( oldState != Document()->UniState() && iPopupNote ) )
       
  6731         {
       
  6732         // Popup note is not shown, so we can show error or attachment(s)
       
  6733         // added note. When popup note is not shown, it doesn't matter
       
  6734         // whether message type was changed or not.
       
  6735         CArrayFixFlat<TInt>* errors = iVCardOperation->GetErrors();
       
  6736         
       
  6737         if ( errors->Count() )
       
  6738             {
       
  6739             for ( TInt i = 0; i < errors->Count(); i++ )
       
  6740                 {
       
  6741                 if ( errors->At( i ) == EUniInsertTooBig )
       
  6742                     {
       
  6743                     // Tell user that one or more vCards could not be inserted.
       
  6744                     addedVCardCount > 0 ?
       
  6745                         ShowInformationNoteL( R_UNIEDITOR_INFO_OBJECT_SEND_AS_TOO_BIG, EFalse ) :
       
  6746                         ShowInformationNoteL( R_UNIEDITOR_INFO_OBJECT_TOO_BIG, EFalse );
       
  6747                     break;
       
  6748                     }
       
  6749                 }
       
  6750             }
       
  6751         else if ( addedVCardCount > 0 )
       
  6752             {
       
  6753             // Show attachment(s) added note if no errors.
       
  6754             addedVCardCount == 1 ? 
       
  6755                 ShowInformationNoteL( R_UNIEDITOR_QTN_UNIFIED_ATTACHMENT_ADDED, EFalse ) :
       
  6756                 ShowInformationNoteL( R_UNIEDITOR_QTN_UNIFIED_ATTACHMENTS_ADDED, EFalse );
       
  6757             }
       
  6758         }
       
  6759     }
       
  6760 
       
  6761 // ---------------------------------------------------------
       
  6762 // CUniEditorAppUi::BeginActiveWait
       
  6763 // ---------------------------------------------------------
       
  6764 //
       
  6765 void CUniEditorAppUi::BeginActiveWait( CUniEditorOperation* aOperation )
       
  6766     {
       
  6767     if( iWait.IsStarted() )
       
  6768         {
       
  6769         // If there is data in recipient and body text fields,
       
  6770         // presentation is created and read key is pressed in smil editor,
       
  6771         // smil editor dialog is dismissed and change slide operation starts
       
  6772         // in NewTemplateL() ( any kind error code is not supplied).
       
  6773         // After that Exit comes to editor HandleCommandL, which would cause start of
       
  6774         // save operation. Change slide operation must be terminated first.
       
  6775         if ( iActiveOperation )
       
  6776             {
       
  6777             iActiveOperation->Cancel();
       
  6778             }
       
  6779         return;
       
  6780         }
       
  6781         
       
  6782     iActiveOperation = aOperation;
       
  6783     iWait.Start();
       
  6784     }
       
  6785 
       
  6786 // ---------------------------------------------------------
       
  6787 // CUniEditorAppUi::EndActiveWait
       
  6788 // ---------------------------------------------------------
       
  6789 //
       
  6790 void CUniEditorAppUi::EndActiveWait()
       
  6791     {
       
  6792     if( !iWait.IsStarted() )
       
  6793         {
       
  6794         return;
       
  6795         }
       
  6796         
       
  6797     iWait.AsyncStop();
       
  6798     iActiveOperation = NULL;
       
  6799     }
       
  6800 
       
  6801 // ---------------------------------------------------------
       
  6802 // CUniEditorAppUi::ObjectsAvailable
       
  6803 // ---------------------------------------------------------
       
  6804 //
       
  6805 TUint32 CUniEditorAppUi::ObjectsAvailable()
       
  6806     {
       
  6807     TUint32 objects = EUniNoneFlag;
       
  6808     if ( BodyCtrl() && BodyCtrl()->TextContent().DocumentLength() )
       
  6809         {
       
  6810         // This flag is not currently used for anything.
       
  6811         objects |= EUniTextFlag;
       
  6812         }
       
  6813     if ( iView->ControlById( EMsgComponentIdAudio ) )
       
  6814         {
       
  6815         objects |= EUniAudioFlag;
       
  6816         }
       
  6817     if ( iView->ControlById( EMsgComponentIdImage ) )
       
  6818         {
       
  6819         objects |= EUniImageFlag;
       
  6820         }
       
  6821     if ( iView->ControlById( EMsgComponentIdVideo ) )
       
  6822         {
       
  6823         objects |= EUniVideoFlag;
       
  6824         }
       
  6825     if ( iView->ControlById( EMsgComponentIdSvg ) )
       
  6826         {
       
  6827         objects |= EUniSvgFlag;
       
  6828         }
       
  6829     return objects;
       
  6830     }
       
  6831 
       
  6832 
       
  6833 // ---------------------------------------------------------
       
  6834 // CUniEditorAppUi::DoUserAddHeadersL
       
  6835 // ---------------------------------------------------------
       
  6836 //
       
  6837 void CUniEditorAppUi::DoUserAddHeadersL()
       
  6838     {
       
  6839     if ( !iHeader )
       
  6840         {
       
  6841         return;
       
  6842         }
       
  6843     
       
  6844     TInt headersVariation = iHeader->AddHeadersVariation();
       
  6845     TInt headersConfig = 0;
       
  6846     
       
  6847     // Check which fields are visible:
       
  6848     
       
  6849     // TInt headersConfig = iHeader->AddHeadersConfigL();
       
  6850     if ( iHeader->SubjectControl() )
       
  6851         {
       
  6852         headersConfig |= EUniFeatureSubject;
       
  6853         }
       
  6854     if ( iHeader->AddressControl( CUniBaseHeader::EHeaderAddressCc ) )
       
  6855         {
       
  6856         headersConfig |= EUniFeatureCc;
       
  6857         }
       
  6858     if ( iHeader->AddressControl( CUniBaseHeader::EHeaderAddressBcc ) )
       
  6859         {
       
  6860         headersConfig |= EUniFeatureBcc;
       
  6861         }
       
  6862 
       
  6863     if ( IsHardcodedSms() && Document()->EmailOverSmsSupported() )
       
  6864         { 
       
  6865         // Locked SMS and EmailOverSms -> enable only subject field
       
  6866         if ( headersVariation & EUniFeatureSubjectConfigurable )
       
  6867             {
       
  6868             headersVariation = EUniFeatureSubject;
       
  6869             headersVariation |= EUniFeatureSubjectConfigurable;
       
  6870             }
       
  6871         else
       
  6872             {
       
  6873             // Should not happen as add headers command should be invisible at this case.
       
  6874             headersVariation = EUniFeatureSubject;
       
  6875             }
       
  6876         }
       
  6877 
       
  6878     // Contains indexes of additional header flags in
       
  6879     // headersIn array; KErrNotFound if not visible in the UI
       
  6880     // index: 0 = CC, 1 = BCC, 3 = subject
       
  6881     CArrayFixFlat<TInt>* indexes = new( ELeave ) CArrayFixFlat<TInt>( 3 );
       
  6882     CleanupStack::PushL( indexes );
       
  6883     
       
  6884     CListBoxView::CSelectionIndexArray* headersOut = 
       
  6885                                     new( ELeave ) CArrayFixFlat<TInt>( 3 );
       
  6886     CleanupStack::PushL( headersOut );
       
  6887 
       
  6888     CListBoxView::CSelectionIndexArray* headersIn = 
       
  6889                                     new( ELeave ) CArrayFixFlat<TInt>( 3 );
       
  6890     CleanupStack::PushL( headersIn );
       
  6891     
       
  6892     CUniEditorAddHeaderDialog* dlg = new( ELeave ) CUniEditorAddHeaderDialog( headersOut );
       
  6893     
       
  6894     // Pushes the dialog into stack
       
  6895     dlg->PrepareLC( R_UNIEDITOR_ADD_HEADERS_LIST_QUERY );
       
  6896 
       
  6897     // Order matters. See Pop below
       
  6898     CDesCArrayFlat* headerStringsIn = new( ELeave ) CDesCArrayFlat( 3 );
       
  6899     CleanupStack::PushL( headerStringsIn );
       
  6900     
       
  6901     TInt index( 0 );
       
  6902     for ( TInt i = 0; i < 3; i++ )
       
  6903         {
       
  6904         TInt flag( EUniFeatureCc );
       
  6905         TInt resource( R_UNIEDITOR_QTN_MSG_HEADERS_CC );
       
  6906         
       
  6907         if ( i == 1 )
       
  6908             {
       
  6909             flag = EUniFeatureBcc;
       
  6910             resource = R_UNIEDITOR_QTN_MSG_HEADERS_BCC;
       
  6911             }
       
  6912         else if ( i == 2 )
       
  6913             {
       
  6914             flag = EUniFeatureSubjectConfigurable;
       
  6915             resource = R_UNIEDITOR_QTN_MSG_HEADERS_SUBJECT;
       
  6916             }
       
  6917         
       
  6918         if ( headersVariation & flag )
       
  6919             {
       
  6920             HBufC* fieldTemp = StringLoader::LoadLC( resource, iCoeEnv );
       
  6921             
       
  6922             // We need to add the "1\"
       
  6923             HBufC* fieldBuf = HBufC::NewMaxLC( fieldTemp->Des().Length() + 2 );
       
  6924 
       
  6925             TPtr field = fieldBuf->Des();
       
  6926             field.Copy( KItemStart );
       
  6927             field.Append( fieldTemp->Des() );
       
  6928             
       
  6929             // FieldBuf will be owned by headersIn 
       
  6930             headerStringsIn->AppendL( field );
       
  6931 
       
  6932             CleanupStack::PopAndDestroy( 2, fieldTemp );  //  + fieldBuf  
       
  6933             
       
  6934             if ( flag == EUniFeatureSubjectConfigurable )
       
  6935                 {
       
  6936                 flag = EUniFeatureSubject;
       
  6937                 }
       
  6938             
       
  6939             if ( headersConfig & flag )
       
  6940                 {   
       
  6941                 // Mark it selected
       
  6942                 dlg->ListBox()->View()->SelectItemL( index );
       
  6943                 headersIn->AppendL( ETrue );
       
  6944                 }
       
  6945             else
       
  6946                 {
       
  6947                 headersIn->AppendL( EFalse );
       
  6948                 }
       
  6949                 
       
  6950             indexes->AppendL( index );
       
  6951             index++;
       
  6952             }
       
  6953         else
       
  6954             {
       
  6955             indexes->AppendL( KErrNotFound );
       
  6956             }
       
  6957         }
       
  6958         
       
  6959     dlg->SetItemTextArray( headerStringsIn );
       
  6960     dlg->SetOwnershipType( ELbmOwnsItemArray );
       
  6961     CleanupStack::Pop( headerStringsIn );
       
  6962 
       
  6963     if ( dlg->RunLD() )
       
  6964         {
       
  6965         TInt newSelectionHeaders( 0 ); 
       
  6966         TInt removeHeaders( 0 ); 
       
  6967         TInt removeHeadersWithWarning( 0 ); 
       
  6968         TInt addHeaders( 0 ); 
       
  6969 
       
  6970         TInt countItems( headersOut->Count() );
       
  6971 
       
  6972         // Check if the out selection is the same as in selection
       
  6973         TBool theSame = ETrue;
       
  6974 
       
  6975         index = 0;
       
  6976         for ( TInt i = 0; i < 3; i++ )
       
  6977             {
       
  6978             if ( indexes->At( i ) != KErrNotFound )
       
  6979                 { 
       
  6980                 // i was one of the choices available in the dialog
       
  6981                 if ( headersIn->At( index ) )
       
  6982                     { 
       
  6983                     // It was originally selected
       
  6984                     if ( countItems < 1 )
       
  6985                         {
       
  6986                         theSame = EFalse;
       
  6987                         }
       
  6988                         
       
  6989                     TBool foundIt = EFalse;
       
  6990                     for ( TInt j = 0; j < countItems; j++ )
       
  6991                         { 
       
  6992                         // Lets see the current selection
       
  6993                         if ( headersOut->At( j ) == index )
       
  6994                             { 
       
  6995                             // It's selected after the dialog
       
  6996                             foundIt = ETrue;
       
  6997                             }
       
  6998                         }
       
  6999                         
       
  7000                     if ( !foundIt )
       
  7001                         { 
       
  7002                         // Originally it was selected so it's not the same selection anymore
       
  7003                         theSame = EFalse;
       
  7004                         }
       
  7005                     }
       
  7006                 else
       
  7007                     { 
       
  7008                     // It was originally not selected
       
  7009                     TBool foundIt = EFalse;
       
  7010                     for ( TInt j = 0; j < countItems; j++ )
       
  7011                         { 
       
  7012                         // Lets see the current selection
       
  7013                         if ( headersOut->At( j ) == index )
       
  7014                             { 
       
  7015                             // It's selected after the dialog
       
  7016                             foundIt = ETrue;
       
  7017                             }
       
  7018                         }
       
  7019                         
       
  7020                     if ( foundIt )
       
  7021                         { 
       
  7022                         // Originally it was not selected so it's not the same selection anymore
       
  7023                         theSame = EFalse;
       
  7024                         }
       
  7025                     }
       
  7026                 index++;                
       
  7027                 }
       
  7028             }
       
  7029             
       
  7030         CleanupStack::PopAndDestroy( headersIn );
       
  7031 
       
  7032         if ( theSame )
       
  7033             { 
       
  7034             // no changes were done so don't proceed with this..
       
  7035             // we return here so that we don't save incorrect configuration
       
  7036             // it might happen for example if we have opened reply to all and there are 
       
  7037             // unselected fields used in the replied message
       
  7038             CleanupStack::PopAndDestroy( 2, indexes ); // + headersOut
       
  7039             return;
       
  7040             }
       
  7041         
       
  7042         // Indicates selected fields
       
  7043         CArrayFixFlat<TInt>* indexesOut = new( ELeave ) CArrayFixFlat<TInt>( 3 );
       
  7044         CleanupStack::PushL( indexesOut );
       
  7045         
       
  7046         indexesOut->AppendL( EFalse );
       
  7047         indexesOut->AppendL( EFalse );
       
  7048         indexesOut->AppendL( EFalse );
       
  7049         
       
  7050         for ( TInt i = 0; i < countItems; i++ )
       
  7051             {
       
  7052             TInt selected = headersOut->At(i);
       
  7053             for ( TInt j = 0; j < 3; j++ )
       
  7054                 {
       
  7055                 if ( indexes->At( j ) == selected )
       
  7056                     {
       
  7057                     indexesOut->At( j ) = ETrue;
       
  7058                     break;
       
  7059                     }
       
  7060                 }
       
  7061             }
       
  7062 
       
  7063         AddHeadersCollectStatisticsL( *indexesOut,
       
  7064                                       headersVariation,
       
  7065                                       newSelectionHeaders,
       
  7066                                       removeHeaders,
       
  7067                                       removeHeadersWithWarning,
       
  7068                                       addHeaders );
       
  7069                                       
       
  7070         CleanupStack::PopAndDestroy( indexesOut );
       
  7071         
       
  7072         TInt countRemove = AddHeadersCount( removeHeadersWithWarning );
       
  7073         
       
  7074         TInt res ( 0 );
       
  7075         if ( countRemove > 1 )
       
  7076             {
       
  7077             res = R_UNIEDITOR_QTN_MSG_QRY_HEADERS_REMOVE;
       
  7078             }
       
  7079         else if ( countRemove == 1 )
       
  7080             {
       
  7081             res = R_UNIEDITOR_QTN_MSG_QRY_HEADER_REMOVE;
       
  7082             }
       
  7083             
       
  7084         if ( res )
       
  7085             {
       
  7086             // Confirmation specified for header removing
       
  7087             if ( ShowConfirmationQueryL( res ) )
       
  7088                 {
       
  7089                 // Remove all headers 
       
  7090                 iHeader->AddHeadersDeleteL( removeHeaders, ETrue );
       
  7091                 Document()->SetHeaderModified( ETrue );
       
  7092                 SetAddressSize();
       
  7093                 SetSubjectSize();
       
  7094                 }
       
  7095             else
       
  7096                 {
       
  7097                 // Remove empty headers
       
  7098                 removeHeaders &= ( ~removeHeadersWithWarning );
       
  7099                 
       
  7100                 if ( removeHeaders )
       
  7101                     { 
       
  7102                     // Still something left to delete
       
  7103                     iHeader->AddHeadersDeleteL( removeHeaders, ETrue );
       
  7104                     }
       
  7105                     
       
  7106                 // But keep the ones that have some content
       
  7107                 newSelectionHeaders |= removeHeadersWithWarning;
       
  7108                 }
       
  7109             }
       
  7110         else if ( removeHeaders )
       
  7111             {
       
  7112             // Remove one or more headers but none of the removed do not contain any data
       
  7113             iHeader->AddHeadersDeleteL( removeHeaders, EFalse );            
       
  7114             }
       
  7115 
       
  7116         iHeader->SaveAddHeadersConfigL( newSelectionHeaders );
       
  7117         
       
  7118         // Add new headers
       
  7119         if ( addHeaders )
       
  7120             {
       
  7121             iHeader->AddHeadersAddL(addHeaders);
       
  7122             }    
       
  7123             
       
  7124          // Change focus
       
  7125         if ( addHeaders || removeHeaders )
       
  7126             {
       
  7127             iNextFocus = EMsgComponentIdNull;
       
  7128             
       
  7129             // Add headers override removing
       
  7130             if ( addHeaders )
       
  7131                 {
       
  7132                 if ( addHeaders & EUniFeatureCc )
       
  7133                     {
       
  7134                     iNextFocus = EMsgComponentIdCc;
       
  7135                     }
       
  7136                 else if ( addHeaders & EUniFeatureBcc )
       
  7137                     {
       
  7138                     iNextFocus = EMsgComponentIdBcc;
       
  7139                     }
       
  7140                 else if ( addHeaders & EUniFeatureSubject )
       
  7141                     {
       
  7142                     iNextFocus = EMsgComponentIdSubject;
       
  7143                     }
       
  7144                 }
       
  7145             else
       
  7146                 {
       
  7147                 CUniEditorHeader::THeaderFields start( CUniEditorHeader::EHeaderAddressBcc );
       
  7148                 
       
  7149                 if ( removeHeaders & EUniFeatureSubject )
       
  7150                     {
       
  7151                     start = CUniEditorHeader::EHeaderAddressBcc;
       
  7152                     }                
       
  7153                 else if ( removeHeaders & EUniFeatureBcc )
       
  7154                     {
       
  7155                     start = CUniEditorHeader::EHeaderAddressCc;
       
  7156                     }
       
  7157                 else if ( removeHeaders & EUniFeatureCc )
       
  7158                     {
       
  7159                     start = CUniEditorHeader::EHeaderAddressTo;
       
  7160                     }
       
  7161                     
       
  7162                 // Search for the first existing header
       
  7163                 for ( TInt i = start; i >= CUniEditorHeader::EHeaderAddressTo; i-- )
       
  7164                     {
       
  7165                     if ( iHeader->AddressControl( static_cast<CUniBaseHeader::THeaderFields> ( i ) ) )
       
  7166                         {
       
  7167                         iNextFocus = iHeader->AddressControlId( 
       
  7168                                                     static_cast<CUniBaseHeader::THeaderFields> ( i ) );
       
  7169                         break;
       
  7170                         }
       
  7171                     }
       
  7172                 }
       
  7173                 
       
  7174             if ( ToCtrl() )
       
  7175                 {
       
  7176                 DoSetFocusL();
       
  7177                 }
       
  7178             else
       
  7179                 { 
       
  7180                 DoUserChangeSlideL( 0 );
       
  7181                 }
       
  7182                 
       
  7183             CheckHeaderForMessageTypeL();
       
  7184             
       
  7185             // Also iSmsSubjectLength needs updating..
       
  7186             CheckBodyForMessageTypeL();
       
  7187             MsgLengthToNavipaneL();
       
  7188             }
       
  7189         }
       
  7190     else
       
  7191         {
       
  7192         CleanupStack::PopAndDestroy( headersIn );
       
  7193         }
       
  7194         
       
  7195     CleanupStack::PopAndDestroy( 2, indexes ); // + headersOut
       
  7196     }
       
  7197                                             
       
  7198 
       
  7199 // ---------------------------------------------------------
       
  7200 // CUniEditorAppUi::AddHeadersRemovedWithDataFlags
       
  7201 // ---------------------------------------------------------
       
  7202 //
       
  7203 void CUniEditorAppUi::AddHeadersCollectStatisticsL( CArrayFix<TInt>& aIndexesOut, 
       
  7204                                                     TInt aVariation,
       
  7205                                                     TInt& aNewSelectionFlags,
       
  7206                                                     TInt& aRemoveFlags,
       
  7207                                                     TInt& aRemoveWarningFlags,
       
  7208                                                     TInt& aAddFlags ) const
       
  7209     {        
       
  7210     // now we know selected ones 
       
  7211     for ( TInt i = 0; i < 3; i++ )  // maximum three three
       
  7212         {
       
  7213         if (i == 0 || i == 1 )
       
  7214             {
       
  7215             CMsgAddressControl* control = NULL;                
       
  7216             TInt flag = EUniFeatureCc;
       
  7217             if ( i == 0 )
       
  7218                 {
       
  7219                 control = iHeader->AddressControl( 
       
  7220                     static_cast<CUniBaseHeader::THeaderFields> 
       
  7221                         (CUniBaseHeader::EHeaderAddressCc) );
       
  7222                 }
       
  7223             else if ( i == 1 )
       
  7224                 {
       
  7225                 flag = EUniFeatureBcc;
       
  7226                 control = iHeader->AddressControl( 
       
  7227                     static_cast<CUniBaseHeader::THeaderFields> 
       
  7228                         (CUniBaseHeader::EHeaderAddressBcc) );
       
  7229                 }
       
  7230             
       
  7231             if ( !aIndexesOut[i] )
       
  7232                 {
       
  7233                 if ( control )
       
  7234                     {
       
  7235                     aRemoveFlags |= flag;
       
  7236                     CMsgRecipientArray* recipients = control->GetRecipientsL();
       
  7237                     if (    recipients 
       
  7238                        &&   recipients->Count() )
       
  7239                         {
       
  7240                         aRemoveWarningFlags |= flag;
       
  7241                         }
       
  7242                     // else - control, no recipients, no selection => remove
       
  7243                     }
       
  7244                 // else - no control, no selection => status quo
       
  7245                 }
       
  7246             else
       
  7247                 {
       
  7248                 aNewSelectionFlags |= flag;
       
  7249                 if ( !control )
       
  7250                     {
       
  7251                     // no control, selection
       
  7252                     aAddFlags |= flag;
       
  7253                     }
       
  7254                 // else - control and selection => status quo
       
  7255                 }
       
  7256             }
       
  7257         else if ( i== 2 )
       
  7258             {
       
  7259             if( aVariation & EUniFeatureSubject && aVariation & EUniFeatureSubjectConfigurable )
       
  7260                 { // OK, subject field supported and configured
       
  7261                 CMsgExpandableControl* subject = iHeader->SubjectControl();
       
  7262                 if ( !aIndexesOut[i] )
       
  7263                     {
       
  7264                     if ( subject )
       
  7265                         {
       
  7266                         aRemoveFlags |= EUniFeatureSubject;
       
  7267                         if ( subject->TextContent().DocumentLength() )
       
  7268                             {
       
  7269                             aRemoveWarningFlags |= EUniFeatureSubject;
       
  7270                             }
       
  7271                         // else - control, no subject text, no selection => remove
       
  7272                         }
       
  7273                     // else - no control, no selection => status quo
       
  7274                     }
       
  7275                 else
       
  7276                     {
       
  7277                     aNewSelectionFlags |= EUniFeatureSubject;
       
  7278                     if ( !subject )
       
  7279                         {
       
  7280                         // no control, selection
       
  7281                         aAddFlags |= EUniFeatureSubject;
       
  7282                         }
       
  7283                     // else - control and selection => status quo
       
  7284                     }
       
  7285                 }
       
  7286             }
       
  7287         }
       
  7288     }
       
  7289 
       
  7290 // ---------------------------------------------------------
       
  7291 // CUniEditorAppUi::AddHeadersCount
       
  7292 // ---------------------------------------------------------
       
  7293 //
       
  7294 TInt CUniEditorAppUi::AddHeadersCount( TInt aFlag ) const
       
  7295     {
       
  7296     TInt count( 0 );
       
  7297     if ( aFlag & EUniFeatureCc )
       
  7298         {
       
  7299         count++;
       
  7300         }
       
  7301     if ( aFlag & EUniFeatureBcc )
       
  7302         {
       
  7303         count++;
       
  7304         }
       
  7305     if ( aFlag & EUniFeatureSubject )
       
  7306         {
       
  7307         count++;
       
  7308         }
       
  7309     return count;
       
  7310     }
       
  7311 
       
  7312 // ---------------------------------------------------------
       
  7313 // CUniEditorAppUi::SetCursorPositionsForInsertL
       
  7314 // ---------------------------------------------------------
       
  7315 //
       
  7316 void CUniEditorAppUi::SetCursorPositionsForInsertL()
       
  7317     {
       
  7318     // Set body control cursor position, so that scrolling after
       
  7319     // insert goes ok.
       
  7320     if ( BodyCtrl() )
       
  7321         {
       
  7322         TInt cursorPos = iSmilModel->Layout() == EUniImageFirst ? 0 : 
       
  7323                                                                   BodyCtrlEditor()->TextLength(); 
       
  7324         BodyCtrl()->SetCursorPosL( cursorPos );
       
  7325         }
       
  7326     }
       
  7327 
       
  7328 // ---------------------------------------------------------
       
  7329 // CUniEditorAppUi::DoUserRemoveMediaL
       
  7330 // ---------------------------------------------------------
       
  7331 //
       
  7332 void CUniEditorAppUi::DoUserRemoveMediaL( TMsgControlId aMediaControlId,
       
  7333                                           TUniRegion aRegion )
       
  7334     {
       
  7335     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  7336 
       
  7337     CMsgBaseControl* ctrl = iView->ControlById( aMediaControlId );
       
  7338     CUniObject* obj = iSmilModel->GetObject( Document()->CurrentSlide(), aRegion );
       
  7339 
       
  7340     __ASSERT_DEBUG( ( ctrl && obj ), Panic( EUniNullPointer ) );
       
  7341     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  7342 
       
  7343     TUint32 objects = ObjectsAvailable(); 
       
  7344 
       
  7345     TParsePtrC fileN( obj->MediaInfo()->FullFilePath() );
       
  7346 
       
  7347     HBufC* queryText = StringLoader::LoadLC( R_UNIEDITOR_QUEST_REMOVE_COMMON, fileN.NameAndExt() );
       
  7348 
       
  7349     if ( ShowConfirmationQueryL( *queryText ) ) 
       
  7350         {  
       
  7351         iSmilModel->RemoveObjectL( Document()->CurrentSlide(), obj );
       
  7352         Document()->SetBodyModified( ETrue );
       
  7353 
       
  7354         TBool removeCtrlFocused = ctrl->IsFocused();
       
  7355 
       
  7356         // Delete icon
       
  7357         iView->DeleteControlL( ctrl->ControlId() );
       
  7358         
       
  7359         MsgLengthToNavipaneL();
       
  7360 
       
  7361         // Change focus to the beginning that scroll bar is updated
       
  7362         // and text editor area removes extra lines
       
  7363         if ( ToCtrl() )
       
  7364             {
       
  7365             iView->SetFocus( EMsgComponentIdTo );
       
  7366             }
       
  7367         else if ( iView->ControlById( EMsgComponentIdAudio ) )
       
  7368             {
       
  7369             //Audio is always first
       
  7370             iView->SetFocus( EMsgComponentIdAudio );
       
  7371             }
       
  7372         else if ( iSmilModel->Layout() == EUniImageFirst &&  
       
  7373                   ImageCtrl() )
       
  7374             {
       
  7375             // should not be need to update focus anymore
       
  7376             iView->SetFocus( EMsgComponentIdImage );
       
  7377             }    
       
  7378         else 
       
  7379             {
       
  7380             // should not be need to update focus anymore
       
  7381             iView->SetFocus( EMsgComponentIdBody );
       
  7382             }
       
  7383  
       
  7384         // Put focus back to right place
       
  7385         CMsgBaseControl* focusedControl = iView->FocusedControl();
       
  7386         if ( focusedControl )
       
  7387             {
       
  7388             if ( removeCtrlFocused &&  
       
  7389                  focusedControl->ControlId() != EMsgComponentIdImage &&  
       
  7390                  iSmilModel->Layout() == EUniImageFirst &&  
       
  7391                  ImageCtrl() )
       
  7392                 {
       
  7393                 iView->SetFocus( EMsgComponentIdImage );
       
  7394                 }
       
  7395             else if ( removeCtrlFocused &&        
       
  7396                       aMediaControlId == EMsgComponentIdAudio && 
       
  7397                       iSmilModel->Layout() == EUniImageFirst && 
       
  7398                       ImageCtrl() )
       
  7399                 {
       
  7400                 iView->SetFocus( EMsgComponentIdImage );
       
  7401                 }
       
  7402             else if ( focusedControl->ControlId() != EMsgComponentIdBody )
       
  7403                 {
       
  7404                 CMsgBodyControl* bodyCtrl = BodyCtrl();
       
  7405                 if ( bodyCtrl && 
       
  7406                      aRegion == EUniRegionImage && 
       
  7407                      ( objects & EUniVideoFlag | removeCtrlFocused ) )
       
  7408                     { 
       
  7409                     if ( iSmilModel->Layout() == EUniImageFirst )
       
  7410                         {
       
  7411                         // If video was removed, always place the cursor in the end
       
  7412                         bodyCtrl->SetCursorPosL( 0 );
       
  7413                         }
       
  7414                     else
       
  7415                         {
       
  7416                         // If video was removed, always place the cursor in the end
       
  7417                         bodyCtrl->SetCursorPosL( bodyCtrl->Editor().TextLength() );
       
  7418                         }
       
  7419                     }
       
  7420                 
       
  7421                 // Needs to be done after cursor setting to ensure that view is 
       
  7422                 // showing the correct position.
       
  7423                 iView->SetFocus( EMsgComponentIdBody );
       
  7424                 }
       
  7425 
       
  7426             if ( focusedControl->ControlId() == EMsgComponentIdImage )
       
  7427                 {
       
  7428                 // Set focus here so that imagecontrol will draw navipane if focused.
       
  7429                 iView->FocusedControl()->SetFocus( ETrue, EDrawNow );
       
  7430                 }
       
  7431             }
       
  7432         }
       
  7433         
       
  7434     CleanupStack::PopAndDestroy( queryText );
       
  7435     CheckBodyForMessageTypeL();
       
  7436     MsgLengthToNavipaneL();
       
  7437     }
       
  7438 
       
  7439 // ---------------------------------------------------------
       
  7440 // CUniEditorAppUi::RemoveCurrentTextObjectL
       
  7441 // ---------------------------------------------------------
       
  7442 //
       
  7443 void CUniEditorAppUi::RemoveCurrentTextObjectL()
       
  7444     {
       
  7445     __ASSERT_DEBUG( Document()->DataModel()->SmilType() == EMmsSmil, Panic( EUniIllegalSmilType ) );
       
  7446     
       
  7447     if ( ShowConfirmationQueryL( R_UNIEDITOR_QUEST_REMOVE_TEXT ) ) 
       
  7448         {
       
  7449         if ( BodyCtrl() || 
       
  7450              BodyCtrl()->TextContent().DocumentLength() )
       
  7451             {
       
  7452             BodyCtrl()->Reset();
       
  7453             
       
  7454             Document()->SetBodyModified( ETrue );
       
  7455             
       
  7456             UpdateSmilTextAttaL();
       
  7457             }
       
  7458         
       
  7459         CheckBodyForMessageTypeL();
       
  7460         MsgLengthToNavipaneL();
       
  7461         SetOrRemoveMaxSizeInEdwin();
       
  7462         }
       
  7463     }
       
  7464 
       
  7465 // ---------------------------------------------------------
       
  7466 // CUniEditorAppUi::MsgAsyncControlStateChanged
       
  7467 // ---------------------------------------------------------
       
  7468 //
       
  7469 void CUniEditorAppUi::MsgAsyncControlStateChanged( CMsgBaseControl& /*aControl*/,
       
  7470                                                    TMsgAsyncControlState /*aNewState*/,
       
  7471                                                    TMsgAsyncControlState /*aOldState*/ )
       
  7472     {
       
  7473     // OK to leave this empty, needed only in Viewer side
       
  7474     }
       
  7475 
       
  7476 // ---------------------------------------------------------
       
  7477 // CUniEditorAppUi::MsgAsyncControlResourceChanged
       
  7478 // ---------------------------------------------------------
       
  7479 //
       
  7480 void CUniEditorAppUi::MsgAsyncControlResourceChanged( CMsgBaseControl& aControl, TInt aType )
       
  7481     {
       
  7482     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  7483         {
       
  7484         if ( aControl.ControlType() == EMsgImageControl )
       
  7485             {
       
  7486             CMsgImageControl& imageControl = static_cast<CMsgImageControl&>( aControl );
       
  7487             
       
  7488             if ( imageControl.IconBitmapId() == EMbmUniutilsQgn_graf_mms_unedit ||
       
  7489                  imageControl.IconBitmapId() == EMbmUniutilsQgn_graf_mms_edit )
       
  7490                 {
       
  7491                 // 3GPP icons layout setting needs to be handled by ourself
       
  7492                 TAknLayoutRect iconLayout;
       
  7493                 iconLayout.LayoutRect( MsgEditorCommons::MsgDataPane(),
       
  7494                                        AknLayoutScalable_Apps::msg_data_pane_g4().LayoutLine() );
       
  7495                 
       
  7496                 TRAP_IGNORE( imageControl.SetIconSizeL( iconLayout.Rect().Size() ) );
       
  7497                 }
       
  7498             }
       
  7499         }
       
  7500     }
       
  7501 
       
  7502 // ---------------------------------------------------------
       
  7503 // CUniEditorAppUi::HandleResourceChangeL
       
  7504 // ---------------------------------------------------------
       
  7505 //
       
  7506 void CUniEditorAppUi::HandleResourceChangeL( TInt aType )
       
  7507     {
       
  7508     // Base class call must be first
       
  7509     CMsgEditorAppUi::HandleResourceChangeL(aType);
       
  7510     
       
  7511     if ( iHeader )
       
  7512         {
       
  7513         iHeader->HandleResourceChange( aType );
       
  7514         }
       
  7515     
       
  7516     if ( aType == KEikDynamicLayoutVariantSwitch && IsLaunched() )
       
  7517         { 
       
  7518         // Resize the title icon
       
  7519         CreateFixedToolbarL( EFalse );
       
  7520         
       
  7521         if( !( iEditorFlags & EDoNotUpdateTitlePane ) )
       
  7522             {
       
  7523             UpdateToolbarL();
       
  7524 
       
  7525             SetTitleIconsSizeL();
       
  7526             
       
  7527             // Redraw it again
       
  7528             SetTitleL();
       
  7529             }        
       
  7530         }
       
  7531     else if ( aType == KAknsMessageSkinChange )
       
  7532         {
       
  7533         TParse fileParse;
       
  7534         fileParse.Set( KUniUtilsMBMFileName, &KDC_APP_BITMAP_DIR, NULL );
       
  7535         
       
  7536         delete iIconSms;
       
  7537         iIconSms = NULL;
       
  7538         iIconSms = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
  7539                 KAknsIIDQgnPropMceSmsTitle,
       
  7540                 fileParse.FullName(),
       
  7541                 EMbmUniutilsQgn_prop_mce_sms_title,
       
  7542                 EMbmUniutilsQgn_prop_mce_sms_title_mask );
       
  7543 
       
  7544         delete iIconMms;
       
  7545         iIconMms = NULL;
       
  7546         iIconMms = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
  7547                         KAknsIIDQgnPropMceMmsTitle,
       
  7548                         fileParse.FullName(),
       
  7549                         EMbmUniutilsQgn_prop_mce_mms_title,
       
  7550                         EMbmUniutilsQgn_prop_mce_mms_title_mask );
       
  7551         
       
  7552         SetTitleIconsSizeL();
       
  7553         
       
  7554         if ( IsLaunched() && !( iEditorFlags & EDoNotUpdateTitlePane ) )
       
  7555             {
       
  7556             SetTitleL();
       
  7557             }
       
  7558         }
       
  7559     }
       
  7560 
       
  7561 // ---------------------------------------------------------
       
  7562 // CUniEditorAppUi::IsBodySmsCompatibleL
       
  7563 // ---------------------------------------------------------
       
  7564 //
       
  7565 TBool CUniEditorAppUi::IsBodySmsCompatibleL( TBool aInAutoMode /*= ETrue*/ )
       
  7566     {
       
  7567     CUniEditorDocument* doc = Document();
       
  7568 
       
  7569     CUniDataModel* model = doc->DataModel();
       
  7570 
       
  7571     if ( Document()->DataModel()->SmilType() != EMmsSmil )
       
  7572         { // There's 3GPP presentation or something else..
       
  7573         return EFalse;
       
  7574         }
       
  7575 
       
  7576     // This sets iSmsLength and possible unicode character mode
       
  7577     CheckSmsSizeAndUnicodeL();
       
  7578 
       
  7579     if( model->ObjectList().Count() == 0 &&
       
  7580         model->AttachmentList().Count() == 1 &&
       
  7581         iSmilModel->SlideCount() == 1 &&
       
  7582         iSmsSubjectLength == 0)
       
  7583         {
       
  7584         CUniObject* obj = model->AttachmentList().GetByIndex( 0 );
       
  7585         if ( obj &&  
       
  7586              obj->MimeType().Length() > 0 &&   
       
  7587              ( obj->MimeType().CompareF( KMsgMimeVCard ) == 0 ||  
       
  7588 #if defined (__I_CAL_SUPPORT) && defined (RD_MESSAGING_ICAL_IMPORT)
       
  7589                obj->MimeType().CompareF( KMsgMimeICal ) == 0 ||
       
  7590 #endif
       
  7591                obj->MimeType().CompareF( KMsgMimeVCal ) == 0 ) )
       
  7592             { 
       
  7593             // There's only either VCard, VCal or ICal if it is supported.
       
  7594             iSmsBodyLength = obj->Size();
       
  7595             
       
  7596             TInt maxParts = doc->MaxSmsParts();
       
  7597              if( !aInAutoMode )
       
  7598                 { // Checking if the message fits in "absolute maximum"
       
  7599                 maxParts = doc->AbsoluteMaxSmsParts();
       
  7600                 }
       
  7601             TInt lengthOne( 0 );
       
  7602             TInt lengthMany( 0 );    
       
  7603             doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  7604             return (iSmsBodyLength > lengthMany * maxParts )?  EFalse :  ETrue;
       
  7605             }
       
  7606         }
       
  7607     
       
  7608     if( model->ObjectList().Count() > 1 ||
       
  7609         model->AttachmentList().Count() > 0 ||
       
  7610         iSmilModel->SlideCount() > 1 )
       
  7611         { // If more than 1 object or an attachment or a slide -> MMS
       
  7612         return EFalse;
       
  7613         }
       
  7614     // OK, there's just one object
       
  7615     
       
  7616     if( model->ObjectList().Count() == 1 &&
       
  7617         model->ObjectList().GetByIndex(0)->MediaType() != EMsgMediaText )
       
  7618         { // Just one object and it's not text -> MMS
       
  7619         return EFalse;
       
  7620         }
       
  7621         
       
  7622     // Lets check the length of the body
       
  7623     if( !(iEditorFlags & ESubjectOkInSms ) && iSmsSubjectLength > 0 )
       
  7624         {
       
  7625         return EFalse;
       
  7626         }
       
  7627     
       
  7628     TInt lengthOne( 0 );
       
  7629     TInt lengthMany( 0 );
       
  7630     
       
  7631     doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  7632 
       
  7633     TInt maxLen = lengthOne;
       
  7634 
       
  7635     TInt maxParts = doc->MaxSmsParts();
       
  7636     
       
  7637     if( !aInAutoMode )
       
  7638         { // Checking if the message fits in "absolute maximum"
       
  7639         maxParts = doc->AbsoluteMaxSmsParts();
       
  7640         }
       
  7641   
       
  7642     if( maxParts > 1 )
       
  7643         {
       
  7644         maxLen = maxParts*lengthMany;
       
  7645         }
       
  7646     
       
  7647     if ( doc->AbsoluteMaxSmsCharacters() > 0 )
       
  7648         {
       
  7649         maxLen = doc->AbsoluteMaxSmsCharacters();
       
  7650         }
       
  7651     
       
  7652     TInt emailAddrLen = iHeader->LongestEmailAddress();
       
  7653     
       
  7654     if( emailAddrLen )
       
  7655         {
       
  7656         emailAddrLen++; // one extra char needed by separator char
       
  7657         }
       
  7658 
       
  7659     if( iSmsBodyLength + iSmsSubjectLength + emailAddrLen <= maxLen )
       
  7660         {
       
  7661         //Korean Req: 415-5434
       
  7662         //get the size limit in bytes
       
  7663         TInt warnCharLength = doc->SmsSizeWarningBytes();
       
  7664 
       
  7665         if( warnCharLength > 0 )
       
  7666             {
       
  7667             //convert the size limit w.r.t characters based on encoding type
       
  7668             if ( doc->UnicodeCharacterMode() )
       
  7669                 {
       
  7670                 warnCharLength =  warnCharLength / 2 ;
       
  7671                 }
       
  7672             else
       
  7673                 {
       
  7674                 warnCharLength = (warnCharLength * 8) / 7;
       
  7675                 }
       
  7676             
       
  7677             if( iSmsBodyLength + iSmsSubjectLength + emailAddrLen > warnCharLength )
       
  7678                 {
       
  7679                 //show "limit exceed" note if not shown already
       
  7680                 if( !( iEditorFlags & ESmsSizeWarningNoteShown ) )
       
  7681                     {
       
  7682                     //set the bit to indicate limit exceeded and note shown
       
  7683                     iEditorFlags |= ESmsSizeWarningNoteShown;
       
  7684                     if( iPopupNote )
       
  7685                         {
       
  7686                         iPopupNote->SetTextL( iPopupSmsSizeAboveLimitBuffer->Des() );
       
  7687                         iPopupNote->ShowInfoPopupNote();
       
  7688                         }
       
  7689                     }
       
  7690                 }
       
  7691             else
       
  7692                 {
       
  7693                 //show "back to below limit" note if not shown already(only in case of size transiton from above limit to below limit)
       
  7694                 if( iEditorFlags & ESmsSizeWarningNoteShown )
       
  7695                     {
       
  7696                     //reset the bit to indicate size is below limit and note for transition is showed
       
  7697                     iEditorFlags &= ~ESmsSizeWarningNoteShown;
       
  7698                     if( iPopupNote )
       
  7699                         {
       
  7700                         iPopupNote->SetTextL( iPopupSmsSizeBelowLimitBuffer->Des() );
       
  7701                         iPopupNote->ShowInfoPopupNote();
       
  7702                         }                
       
  7703                     }
       
  7704                 }          
       
  7705             }
       
  7706         
       
  7707         return ETrue;
       
  7708         }
       
  7709   
       
  7710     // text (body + possible subject) is too long -> body is not sms compatible
       
  7711     return EFalse;  
       
  7712     }
       
  7713 
       
  7714 // ---------------------------------------------------------
       
  7715 // CUniEditorAppUi::CheckSmsSizeAndUnicodeL
       
  7716 // ---------------------------------------------------------
       
  7717 //
       
  7718 void CUniEditorAppUi::CheckSmsSizeAndUnicodeL()
       
  7719     {
       
  7720     UNILOGGER_WRITE_TIMESTAMP("CUniEditorAppUi::CheckSmsSizeAndUnicodeL Start <<<---- ");
       
  7721     CUniEditorDocument* doc = Document();
       
  7722 
       
  7723     if( iNLTFeatureSupport )
       
  7724         {
       
  7725         //Turkish SMS-PREQ2265 specific
       
  7726         TInt numOfPDUs = 0, numOfRemainingChars = 0, subjectLength = 0;
       
  7727         TBool unicodeMode = EFalse;
       
  7728         TSmsEncoding alternativeEncodingType;
       
  7729         CUniEditorPlugin* plugin = NULL;
       
  7730        
       
  7731         plugin = SmsPlugin();
       
  7732         if ( plugin )
       
  7733             { 
       
  7734             HBufC* editorTxt = NULL;
       
  7735             
       
  7736             if ( BodyCtrlEditor() )
       
  7737                 {
       
  7738                 editorTxt = BodyCtrlEditor()->GetTextInHBufL();
       
  7739                 }
       
  7740 
       
  7741             //Concatenate subject buffer and body buffer before calculating PDU info.
       
  7742             if ( SubjectCtrlEditor() )
       
  7743                 {
       
  7744                 HBufC* subjectTxt = SubjectCtrlEditor()->GetTextInHBufL();
       
  7745                 if( subjectTxt )
       
  7746                     {
       
  7747                     if( editorTxt )
       
  7748                         {
       
  7749                         CleanupStack::PushL( subjectTxt );
       
  7750                         //If both, body text and suject text is present
       
  7751                         //Reallocate editor text to include subject buffer and additional chars for subject 
       
  7752                         TInt reallocLength;
       
  7753                         reallocLength = editorTxt->Length() + subjectTxt->Length() + KUniEdExtraLenCausedBySubject;
       
  7754                         editorTxt = editorTxt->ReAllocL(reallocLength);
       
  7755                         
       
  7756                         //Modify the editor text to insert subject buffer and additional chars at the begining
       
  7757                         //Buffer Format is:: "(subject...)body..."
       
  7758                         TPtr editorBuffPtr = editorTxt->Des();
       
  7759                         subjectLength = 0;
       
  7760                         editorBuffPtr.Insert(subjectLength, _L("("));
       
  7761                         subjectLength += 1;
       
  7762                         editorBuffPtr.Insert(subjectLength, *subjectTxt);
       
  7763                         subjectLength += subjectTxt->Length();
       
  7764                         editorBuffPtr.Insert(subjectLength, _L(")"));
       
  7765                         subjectLength += 1;
       
  7766                         //total subject length is actual subject + extra chars '(' and ')'
       
  7767                         CleanupStack::PopAndDestroy( subjectTxt );                    
       
  7768                         }
       
  7769                     else
       
  7770                         {
       
  7771                         //if only subject text is present                   
       
  7772                         //Modify subject buffer directly                    
       
  7773                         //Reallocate subject text to include subject buffer and additional chars for subject 
       
  7774                         subjectLength = subjectTxt->Length() + KUniEdExtraLenCausedBySubject;
       
  7775                         subjectTxt = subjectTxt->ReAllocL(subjectLength);
       
  7776 
       
  7777                         //Modify the editor text to insert additional chars at the begining and end 
       
  7778                         //Buffer Format is:: "(subject...)"
       
  7779                         TPtr subjectBuffPtr = subjectTxt->Des();
       
  7780                         subjectBuffPtr.Insert(0, _L("("));
       
  7781                         //total subject length is actual subject + extra chars '(' and ')'
       
  7782                         subjectBuffPtr.Insert(subjectLength - 1, _L(")"));
       
  7783                         //Use subject buffer as editor buffer
       
  7784                         editorTxt = subjectTxt;
       
  7785                         }
       
  7786                     }
       
  7787                 }
       
  7788             
       
  7789             if ( editorTxt )
       
  7790                 {
       
  7791                 TPtr inputBuff = editorTxt->Des();
       
  7792                 TInt buffLength = editorTxt->Length();
       
  7793                 TInt prevBuffLength = 0;
       
  7794                 //replace enter char(enter will be downgraded anyways) with space, before calculating PDU info.
       
  7795                 //This char will be later replaced with line feed or paragraph separator
       
  7796                 TBuf<KSmsEdPDUInfoCalcReplaceCharacterCount> replaceChars;
       
  7797                 replaceChars.Zero();
       
  7798                 replaceChars.Append( KSmsEnterCharacter );
       
  7799                 replaceChars.Append( KSmsDownwardsArrowLeft );
       
  7800                 AknTextUtils::ReplaceCharacters(
       
  7801                     inputBuff, 
       
  7802                     replaceChars, 
       
  7803                     KSmsEdUnicodeLFSupportedByBasicPhones );
       
  7804                 if( iPrevBuffer )
       
  7805                     {
       
  7806                     prevBuffLength = iPrevBuffer->Length();
       
  7807                     if(( prevBuffLength == buffLength )&&(!iSettingsChanged) )
       
  7808                     {
       
  7809                         UNILOGGER_WRITE_TIMESTAMP("CUniEditorAppUi::CheckSmsSizeAndUnicodeL Compare Start <<<---- ");                        
       
  7810                         if( iPrevBuffer->Compare(*editorTxt) == 0 )
       
  7811                             {
       
  7812                             UNILOGGER_WRITE_TIMESTAMP("CUniEditorAppUi::CheckSmsSizeAndUnicodeL Compare TRUE End ---->>> ");                        
       
  7813                             /* Identical buffer, previously calculated values are good enough
       
  7814                              * Hence do nothing. 
       
  7815                              */
       
  7816                             delete iPrevBuffer;
       
  7817                             iPrevBuffer = editorTxt;
       
  7818                             return;
       
  7819                     }
       
  7820                         UNILOGGER_WRITE_TIMESTAMP("CUniEditorAppUi::CheckSmsSizeAndUnicodeL Compare FALSE End ---->>> ");                        
       
  7821                         }
       
  7822                     }
       
  7823                 //This char will be later replaced with line feed or paragraph separator
       
  7824 	          if( buffLength <= prevBuffLength )
       
  7825                     {
       
  7826         	  	//Reset the settings back, in case if any unicode/turkish chars were entered and erased 
       
  7827             	       	//or if entry type is T9 method(multiple key presses to get different chars)
       
  7828     	               	plugin->SetEncodingSettings(EFalse, doc->AlternativeEncodingType(), doc->CharSetSupport());
       
  7829                     }                
       
  7830                 //Call the plugin SMS adaptation API to get PDU Info
       
  7831                 plugin->GetNumPDUsL( inputBuff, numOfRemainingChars, numOfPDUs, unicodeMode, alternativeEncodingType);
       
  7832                 
       
  7833                 //save current buffer 
       
  7834                 delete iPrevBuffer;
       
  7835                 iPrevBuffer = editorTxt;
       
  7836                 iSettingsChanged = EFalse;
       
  7837                 }
       
  7838             else
       
  7839                 {
       
  7840                 //Reset the settings back, in case if any unicode chars were entered and erased
       
  7841                 plugin->SetEncodingSettings(EFalse, doc->AlternativeEncodingType(), doc->CharSetSupport());
       
  7842                 // Bodytext is zero -> check input language
       
  7843                 delete iPrevBuffer;
       
  7844                 iPrevBuffer = NULL;
       
  7845                 TInt inputLang = iAvkonEnv->SettingCache().InputLanguage();
       
  7846                 switch ( inputLang )
       
  7847                     {
       
  7848                     case ELangArabic:
       
  7849                     case ELangHebrew:
       
  7850                     case ELangThai:
       
  7851                     case ELangVietnamese:
       
  7852                     case ELangFarsi:
       
  7853                     case ELangHindi:
       
  7854                     case ELangUrdu:
       
  7855                     case ELangRussian:
       
  7856                     case ELangBulgarian:
       
  7857                     case ELangUkrainian:
       
  7858                     case ELangTaiwanChinese:
       
  7859                     case ELangHongKongChinese:
       
  7860                     case ELangPrcChinese:
       
  7861                     case ELangJapanese:
       
  7862                         {
       
  7863                         // If the InputLanguage is one of above,
       
  7864                         // we must check the current input mode too 
       
  7865                         if ( BodyCtrlEditor() )
       
  7866                             {
       
  7867                             if ( BodyCtrlEditor()->AknEditorCurrentInputMode() == 
       
  7868                                                                 EAknEditorHalfWidthTextInputMode )
       
  7869                                 {
       
  7870                                 //Unicode Not required. Characters are within western text set.
       
  7871                                 unicodeMode = EFalse;
       
  7872                                 }
       
  7873                             else
       
  7874                                 {
       
  7875                                 //Unicode Mode
       
  7876                                 unicodeMode = ETrue;
       
  7877                                 }       
       
  7878                             }                        
       
  7879                         break;
       
  7880                         }
       
  7881                     default:
       
  7882                         {
       
  7883                         break; 
       
  7884                         }
       
  7885                     }
       
  7886                 }
       
  7887             }        
       
  7888         TInt lengthOne = 0;
       
  7889         TInt lengthMany = 0;
       
  7890 
       
  7891         doc->SetUnicodeCharacterMode( unicodeMode );    
       
  7892         doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  7893 
       
  7894         if(numOfPDUs == 0)
       
  7895             {
       
  7896             //Empty buffer, need to calculate correct values of "num of PDUs" and "remaining characters" on our own.
       
  7897             numOfPDUs = 1;
       
  7898             numOfRemainingChars = lengthOne;
       
  7899             }
       
  7900         iNumOfPDUs = numOfPDUs;
       
  7901         iCharsLeft = numOfRemainingChars;
       
  7902 
       
  7903         if(iNumOfPDUs == 1)
       
  7904             {
       
  7905             iSmsBodyLength = lengthOne - iCharsLeft - subjectLength;
       
  7906             }
       
  7907         else
       
  7908             {
       
  7909             iSmsBodyLength = lengthMany*iNumOfPDUs - iCharsLeft - subjectLength;
       
  7910             }
       
  7911         
       
  7912         iSmsSubjectLength = subjectLength;
       
  7913         
       
  7914         }
       
  7915     else
       
  7916         {
       
  7917         TInt extendedChars = 0;
       
  7918         TInt extendedBodyChars = 0;
       
  7919         TInt extendedSubjectChars = 0;
       
  7920         TBool westernText = ETrue;
       
  7921 
       
  7922         CCnvCharacterSetConverter* conv = doc->CharConverter();    
       
  7923 
       
  7924         if ( conv )
       
  7925             { 
       
  7926             for( TInt index = 0; index < KUniEdNumberOfEditors; index++ )
       
  7927                 {
       
  7928                 HBufC* editorTxt = NULL;
       
  7929                 extendedChars = 0;
       
  7930                 
       
  7931                 if ( index == 0 )
       
  7932                     {
       
  7933                     if ( BodyCtrlEditor() )
       
  7934                         {
       
  7935                         editorTxt = BodyCtrlEditor()->GetTextInHBufL();
       
  7936                         }
       
  7937                     }
       
  7938                 else
       
  7939                     {
       
  7940                     if ( SubjectCtrlEditor() )
       
  7941                         {
       
  7942                         editorTxt = SubjectCtrlEditor()->GetTextInHBufL();
       
  7943                         }
       
  7944                     }
       
  7945 
       
  7946                 if ( editorTxt )
       
  7947                     {
       
  7948                     CleanupStack::PushL( editorTxt );
       
  7949                     
       
  7950                     TPtr string = editorTxt->Des();
       
  7951                     TUint uChar;
       
  7952                     TBuf8<KUnicodeCheckChars> notUsed;
       
  7953 
       
  7954                     TPtrC remainderOfInputString( string );
       
  7955                     
       
  7956                     for ( TInt i = 0; i < remainderOfInputString.Length(); i++ )
       
  7957                         {
       
  7958                         uChar = TUint( remainderOfInputString[i] );
       
  7959                         switch ( uChar )
       
  7960                             {
       
  7961                             case KUniEdLeftSquareBracket:
       
  7962                             case KUniEdReverseSolidus:
       
  7963                             case KUniEdRightSquareBracket:
       
  7964                             case KUniEdCircumflexAccent:
       
  7965                             case KUniEdLeftCurlyBracket:
       
  7966                             case KUniEdVerticalLine:
       
  7967                             case KUniEdRightCurlyBracket:
       
  7968                             case KUniEdTilde:
       
  7969                             case KUniEdEuroSymbol:
       
  7970                                 {
       
  7971                                 extendedChars++;
       
  7972                                 break;
       
  7973                                 }
       
  7974                             default:
       
  7975                                 {
       
  7976                                 break;
       
  7977                                 }
       
  7978                             }
       
  7979                         }
       
  7980                     
       
  7981                     // This is needed in case there's KSmsDownwardsArrowLeft in the end and no other unicode chars
       
  7982                     TBool unicodeWasInUse = EFalse;
       
  7983                     
       
  7984                     while ( remainderOfInputString.Length() )
       
  7985                         {
       
  7986                         TInt numberOfUnconvertibleCharacters = 0;
       
  7987                         const TInt returnValue = conv->ConvertFromUnicode( notUsed,
       
  7988                                                                            remainderOfInputString, 
       
  7989                                                                            numberOfUnconvertibleCharacters );
       
  7990 
       
  7991                         if ( numberOfUnconvertibleCharacters > 0 )
       
  7992                                 {
       
  7993                                 for ( TInt i = 0; 
       
  7994                                       i < remainderOfInputString.Length() && numberOfUnconvertibleCharacters > 0;
       
  7995                                       i++ )
       
  7996                                     {
       
  7997                                     uChar = TUint(remainderOfInputString[i]);
       
  7998                                     if ( uChar == KSmsDownwardsArrowLeft )
       
  7999                                         {
       
  8000                                         // these will be converted to paragraph separators later
       
  8001                                         numberOfUnconvertibleCharacters--; 
       
  8002                                         if ( doc->UnicodeCharacterMode() )
       
  8003                                             {
       
  8004                                             unicodeWasInUse = ETrue;
       
  8005                                             }
       
  8006                                         }
       
  8007                                     }
       
  8008                                 }
       
  8009                                 
       
  8010                         if ( returnValue < 0 || 
       
  8011                              numberOfUnconvertibleCharacters > 0 || 
       
  8012                              ( unicodeWasInUse && 
       
  8013                                numberOfUnconvertibleCharacters == 0 ) ) 
       
  8014                             {
       
  8015                             // if there was an error in trying to do the conversion, or if there was an
       
  8016                             // unconvertible character (e.g. a Chinese character)
       
  8017                             westernText = EFalse;
       
  8018                             break;
       
  8019                             }
       
  8020                             
       
  8021                         remainderOfInputString.Set( remainderOfInputString.Right( returnValue ) );
       
  8022                         }
       
  8023 
       
  8024                     if ( index == 0 )
       
  8025                         {
       
  8026                         extendedBodyChars = extendedChars;
       
  8027                         }
       
  8028                     else
       
  8029                         {
       
  8030                         extendedSubjectChars = extendedChars;
       
  8031                         }
       
  8032                         
       
  8033                     CleanupStack::PopAndDestroy( editorTxt );
       
  8034                     }
       
  8035                 else if ( index == 0 )
       
  8036                     { 
       
  8037                     // Bodytext is zero -> check input language
       
  8038                     TInt inputLang = iAvkonEnv->SettingCache().InputLanguage();
       
  8039                     switch ( inputLang )
       
  8040                         {
       
  8041                         case ELangArabic:
       
  8042                         case ELangHebrew:
       
  8043                         case ELangThai:
       
  8044                         case ELangVietnamese:
       
  8045                         case ELangFarsi:
       
  8046                         case ELangHindi:
       
  8047                         case ELangUrdu:
       
  8048                         case ELangRussian:
       
  8049                         case ELangBulgarian:
       
  8050                         case ELangUkrainian:
       
  8051                         case ELangTaiwanChinese:
       
  8052                         case ELangHongKongChinese:
       
  8053                         case ELangPrcChinese:
       
  8054                         case ELangJapanese:
       
  8055                             {
       
  8056                             // If the InputLanguage is one of above,
       
  8057                             // we must check the current input mode too 
       
  8058                             if ( BodyCtrlEditor() )
       
  8059                                 {
       
  8060                                 if ( BodyCtrlEditor()->AknEditorCurrentInputMode() == 
       
  8061                                                                     EAknEditorHalfWidthTextInputMode )
       
  8062                                     {
       
  8063                                     westernText = ETrue;
       
  8064                                     }
       
  8065                                 else
       
  8066                                     {
       
  8067                                     westernText = EFalse;
       
  8068                                     }       
       
  8069                                 }                        
       
  8070                             break;
       
  8071                             }
       
  8072                         default:
       
  8073                             {
       
  8074                             break; 
       
  8075                             }
       
  8076                         }
       
  8077                     }            
       
  8078                 }
       
  8079                 // Now we have westernText and extendedChars set
       
  8080             }
       
  8081             
       
  8082         if ( westernText )
       
  8083             {
       
  8084             // Might not infact change the unicode character mode
       
  8085             // if maximum SMS character limit is set that forces
       
  8086             // the mode to be always unicode.
       
  8087             doc->SetUnicodeCharacterMode( EFalse );
       
  8088             }
       
  8089         else
       
  8090             {
       
  8091             // Unicode mode
       
  8092             doc->SetUnicodeCharacterMode( ETrue );
       
  8093             
       
  8094             // We need unicode so discard extended chars
       
  8095             extendedBodyChars = 0; 
       
  8096             extendedSubjectChars = 0;
       
  8097             }
       
  8098 
       
  8099         static_cast<CUniSmsPlugin*>( SmsPlugin() )->SetUnicodeMode( doc->UnicodeCharacterMode() );
       
  8100         
       
  8101         if ( BodyCtrlEditor() )
       
  8102             {
       
  8103             iSmsBodyLength = BodyCtrlEditor()->TextLength() + extendedBodyChars;
       
  8104             }
       
  8105         else
       
  8106             {
       
  8107             iSmsBodyLength = 0;
       
  8108             }
       
  8109             
       
  8110         iSmsSubjectLength = 0;
       
  8111         
       
  8112         if( SubjectCtrlEditor() && 
       
  8113             SubjectCtrlEditor()->TextLength() )
       
  8114             { 
       
  8115             // EmailOverSms is supported if when end up here
       
  8116             iSmsSubjectLength = SubjectCtrlEditor()->TextLength() 
       
  8117                                 + extendedSubjectChars
       
  8118                                 + KUniEdExtraLenCausedBySubject; // the extra because of '(' and ')'
       
  8119             }        
       
  8120         }
       
  8121     UNILOGGER_WRITE_TIMESTAMP("CUniEditorAppUi::CheckSmsSizeAndUnicodeL End ---->>> ");
       
  8122     }
       
  8123 
       
  8124 // ---------------------------------------------------------
       
  8125 // CUniEditorAppUi::CheckHeaderForMessageTypeL
       
  8126 // ---------------------------------------------------------
       
  8127 //
       
  8128 void CUniEditorAppUi::CheckHeaderForMessageTypeL()
       
  8129     {
       
  8130     CUniEditorDocument* doc = Document();
       
  8131     
       
  8132     if( iMtm->MessageTypeSetting() != EUniMessageTypeSettingAutomatic )
       
  8133         { // We are in locked mode so refresh email addr length and return
       
  8134         iHeader->RefreshLongestEmailAddressL();
       
  8135         return;
       
  8136         }
       
  8137 
       
  8138     // We are in automatic mode so lets check everything
       
  8139     TUniState oldState = doc->UniState();
       
  8140 
       
  8141     if( iHeader->IsHeaderSmsL() )
       
  8142         {   // Set current header state as sms
       
  8143         doc->SetHeaderUniState( EUniSms );
       
  8144         }
       
  8145     else
       
  8146         {   // Set current header state as mms
       
  8147         doc->SetHeaderUniState( EUniMms );
       
  8148         }
       
  8149 
       
  8150     if( oldState != doc->UniState() )
       
  8151         {   // If the state is not the same anymore, update title and show popup
       
  8152         SetTitleL();
       
  8153         UpdateIndicatorIconsL();
       
  8154         ShowPopupNoteL( doc->UniState()==EUniMms?ETrue:EFalse );
       
  8155         UpdateToolbarL();
       
  8156         }
       
  8157     }
       
  8158 
       
  8159 // ---------------------------------------------------------
       
  8160 // CUniEditorAppUi::CheckBodyForMessageTypeL
       
  8161 // ---------------------------------------------------------
       
  8162 //
       
  8163 void CUniEditorAppUi::CheckBodyForMessageTypeL()
       
  8164     {
       
  8165     CUniEditorDocument* doc = Document();
       
  8166     
       
  8167     TUniMessageTypeSetting setting = iMtm->MessageTypeSetting();
       
  8168 
       
  8169     if( IsHardcodedSms() )
       
  8170         { // Just update iSmsLength and possible unicode mode
       
  8171         CheckSmsSizeAndUnicodeL();
       
  8172         return;
       
  8173         }
       
  8174     
       
  8175     if( setting == EUniMessageTypeSettingMms )
       
  8176         { // We are in locked mode so just leave
       
  8177         UpdateToolbarL();
       
  8178         return;
       
  8179         }
       
  8180 
       
  8181     TUniState oldState = doc->UniState();
       
  8182 
       
  8183     if( IsBodySmsCompatibleL() )
       
  8184         {   // Set current body state as sms
       
  8185         doc->SetBodyUniState( EUniSms );
       
  8186         }
       
  8187     else
       
  8188         {   // Set current body state as mms
       
  8189         doc->SetBodyUniState( EUniMms );
       
  8190         }
       
  8191 
       
  8192     if( oldState != doc->UniState() )
       
  8193         {   // If the state is not the same anymore, update title and show popup
       
  8194         SetTitleL();
       
  8195         UpdateIndicatorIconsL();
       
  8196         ShowPopupNoteL( doc->UniState()==EUniMms?ETrue:EFalse );
       
  8197         UpdateToolbarL();
       
  8198         
       
  8199         if( iNLTFeatureSupport )
       
  8200             {
       
  8201             //Turkish SMS-PREQ2265 specific
       
  8202             if(doc->UniState() == EUniSms)
       
  8203                 {
       
  8204                 //If the new state is SMS, Reset the SMS Settings and update the message length info 
       
  8205                 if(doc->SmsPlugin())
       
  8206                     {
       
  8207                     doc->SmsPlugin()->SetEncodingSettings(EFalse, doc->AlternativeEncodingType(), doc->CharSetSupport());
       
  8208                     }
       
  8209                 //Force to recalculate the SMS PDU info
       
  8210                 CheckSmsSizeAndUnicodeL();
       
  8211                 MsgLengthToNavipaneL( );
       
  8212                 }
       
  8213             }
       
  8214         }
       
  8215     }
       
  8216 
       
  8217 // ----------------------------------------------------
       
  8218 // CUniEditorAppUi::CreateMmsNaviSizeStringL
       
  8219 // 
       
  8220 // Rounds always up
       
  8221 // 0.00000 -> 0
       
  8222 // 0.00001 -> 0.1
       
  8223 // ..
       
  8224 // 0.10000 -> 0.1
       
  8225 // 0.10001 -> 0.2
       
  8226 // ..
       
  8227 // 9.89999 -> 9.9
       
  8228 // 9.90000 -> 9.9
       
  8229 // 9.90001 -> 10
       
  8230 //
       
  8231 // ----------------------------------------------------
       
  8232 //
       
  8233 void CUniEditorAppUi::CreateMmsNaviSizeStringL( const TInt aSizeInBytes,
       
  8234                                                 TDes& aSize,
       
  8235                                                 TInt& aInteger,
       
  8236                                                 TInt& aFragment )
       
  8237     {
       
  8238     aSize.Zero();
       
  8239 
       
  8240     // Integer part
       
  8241     aInteger = aSizeInBytes / KBytesInKilo;
       
  8242     // Up rounded fragment part -> can be 10:
       
  8243     aFragment = ( ( aSizeInBytes % KBytesInKilo ) * 10 + KBytesInKilo - 1) / KBytesInKilo;
       
  8244 
       
  8245     if ( aFragment >= 10 )
       
  8246         {
       
  8247         aInteger++;
       
  8248         aFragment = 0;
       
  8249         }
       
  8250 
       
  8251     if ( aInteger >= KOneDigitLimit )
       
  8252         {
       
  8253         // Show msg size without one digit accuracy
       
  8254         if ( aFragment )
       
  8255             {
       
  8256             aInteger++;
       
  8257             aFragment = 0;
       
  8258             }
       
  8259         MsgAttachmentUtils::FileSizeToStringL( aSize, aInteger * KBytesInKilo, ETrue );
       
  8260         }
       
  8261     else if ( aInteger != 0 || aFragment != 0 )
       
  8262         {
       
  8263         // There is some content and size is between 0 - 10 kB
       
  8264         TLocale loc;
       
  8265         TBuf<1> sep;
       
  8266         sep.Append( loc.DecimalSeparator() );
       
  8267 
       
  8268         StringLoader::Format( aSize, *iMmsLengthFormatBuffer, 0, aInteger );
       
  8269         HBufC* temp = aSize.AllocLC();
       
  8270         StringLoader::Format( aSize, *temp, 2, aFragment );
       
  8271         CleanupStack::PopAndDestroy();
       
  8272         temp = aSize.AllocLC();
       
  8273         StringLoader::Format( aSize, *temp, 1, sep );
       
  8274         CleanupStack::PopAndDestroy();
       
  8275         temp = NULL;
       
  8276         }
       
  8277     else
       
  8278         {
       
  8279         // Empty msg
       
  8280         MsgAttachmentUtils::FileSizeToStringL( aSize, 0, ETrue );
       
  8281         }
       
  8282     }
       
  8283                                         
       
  8284 // ---------------------------------------------------------
       
  8285 // CUniEditorAppUi::DoToolbarInsertOtherL
       
  8286 // ---------------------------------------------------------
       
  8287 //
       
  8288 void CUniEditorAppUi::DoToolbarInsertOtherL()
       
  8289     {
       
  8290     RArray<TInt> disabledItems;
       
  8291     CleanupClosePushL( disabledItems );
       
  8292     
       
  8293     TInt toolbarResourceId( KErrNotFound );
       
  8294     
       
  8295     if ( AknLayoutUtils::PenEnabled() )
       
  8296         {
       
  8297         toolbarResourceId = R_UNIEDITOR_INSERT_OTHER_QUERY;
       
  8298 
       
  8299 //        if ( Document()->CreationMode() == EMmsCreationModeRestricted )
       
  8300 //            {
       
  8301 //            disabledItems.Append( EUniCmdToolbarOtherFetchSVG );
       
  8302 //            }        
       
  8303         }    
       
  8304     
       
  8305     TInt selectedIndex( 0 );
       
  8306     CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selectedIndex );
       
  8307     dlg->PrepareLC( toolbarResourceId );
       
  8308     
       
  8309     CEikFormattedCellListBox* listbox = dlg->ListControl()->Listbox();
       
  8310     CDesCArray* itemArray = static_cast<CDesCArray*>( listbox->Model()->ItemTextArray() );
       
  8311     
       
  8312     if ( disabledItems.Count() > 0 )
       
  8313         {
       
  8314         for ( TInt currentItem = 0; currentItem < disabledItems.Count(); currentItem++ )
       
  8315             {
       
  8316             itemArray->Delete( disabledItems[ currentItem ] );
       
  8317             listbox->HandleItemRemovalL();
       
  8318             }
       
  8319         }
       
  8320         
       
  8321     if ( dlg->RunLD() )
       
  8322         {
       
  8323         for ( TInt currentItem = disabledItems.Count() - 1; currentItem >= 0 ; currentItem-- )
       
  8324             {
       
  8325             if ( selectedIndex >= disabledItems[ currentItem ] )
       
  8326                 {
       
  8327                 selectedIndex++;
       
  8328                 }
       
  8329             }
       
  8330         
       
  8331         switch ( selectedIndex )    
       
  8332             {
       
  8333 //            case EUniCmdToolbarOtherFetchSVG:
       
  8334 //                {
       
  8335 //                DoUserInsertSvgL();
       
  8336 //                break;
       
  8337 //                }
       
  8338             case EUniCmdToolbarOtherFetchTextAtta:
       
  8339                 {
       
  8340                 DoUserInsertOtherFileL( ETextFile );
       
  8341                 break;
       
  8342                 }
       
  8343             case EUniCmdToolbarOtherFetchOtherFiles:
       
  8344                 {
       
  8345                 DoUserInsertOtherFileL( EOtherFile );
       
  8346                 break;
       
  8347                 }
       
  8348             default:
       
  8349                 {
       
  8350                 __ASSERT_DEBUG( EFalse, Panic( EUniUnsupportedCommand ) );
       
  8351                 break;
       
  8352                 }
       
  8353             }
       
  8354         }
       
  8355         
       
  8356     CleanupStack::PopAndDestroy( &disabledItems );
       
  8357     }
       
  8358 
       
  8359 // ---------------------------------------------------------
       
  8360 // CUniEditorAppUi::ShowListQueryL
       
  8361 // ---------------------------------------------------------
       
  8362 //
       
  8363 TBool CUniEditorAppUi::ShowListQueryL( TInt aResourceID, TInt& aSelectedIndex ) const
       
  8364     {
       
  8365     CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &aSelectedIndex );
       
  8366     dlg->PrepareLC( aResourceID );
       
  8367     return dlg->RunLD();
       
  8368     }
       
  8369 
       
  8370 // ---------------------------------------------------------
       
  8371 // CUniEditorAppUi::HidePopupNote
       
  8372 // ---------------------------------------------------------
       
  8373 //
       
  8374 void CUniEditorAppUi::HidePopupNote()
       
  8375     {
       
  8376     if( iPopupNote )
       
  8377         {
       
  8378         iPopupNote->HideInfoPopupNote();    
       
  8379         }
       
  8380     }
       
  8381     
       
  8382 // ---------------------------------------------------------
       
  8383 // CUniEditorAppUi::ShowPopupNoteL
       
  8384 // ---------------------------------------------------------
       
  8385 //
       
  8386 void CUniEditorAppUi::ShowPopupNoteL( TBool aMms )
       
  8387     {
       
  8388     if( iPopupNote )
       
  8389         {
       
  8390         iPopupNote->SetTextL( aMms? iPopupChangedMmsBuffer->Des():
       
  8391                                     iPopupChangedSmsBuffer->Des() );
       
  8392         iPopupNote->ShowInfoPopupNote();
       
  8393         }
       
  8394     }
       
  8395  
       
  8396 // ---------------------------------------------------------
       
  8397 // CUniEditorAppUi::PlayFocusedItemL
       
  8398 // ---------------------------------------------------------
       
  8399 //
       
  8400 void CUniEditorAppUi::PlayFocusedItemL()
       
  8401     {
       
  8402     if ( Document()->DataModel()->SmilType() == E3GPPSmil ||
       
  8403          Document()->DataModel()->SmilType() == ETemplateSmil )
       
  8404         { 
       
  8405         // There's presentation focused -> play it        
       
  8406         PlayPresentationL();
       
  8407         return;
       
  8408         }
       
  8409 
       
  8410     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  8411 
       
  8412     TUniRegion region = EUniRegionImage;
       
  8413 
       
  8414     if ( ctrl )
       
  8415         {
       
  8416         switch ( ctrl->ControlId() )
       
  8417             {
       
  8418             case EMsgComponentIdAudio:
       
  8419                 {
       
  8420                 region = EUniRegionAudio;
       
  8421                 }
       
  8422             case EMsgComponentIdImage:
       
  8423             case EMsgComponentIdVideo:
       
  8424             case EMsgComponentIdSvg:
       
  8425                 {
       
  8426                 CUniObject* obj = iSmilModel->GetObject( Document()->CurrentSlide(), region );
       
  8427                 
       
  8428                 if( obj->Corrupted() )
       
  8429                     { // Object is corrupt -> just show note
       
  8430                     ShowInformationNoteL( R_UNIEDITOR_CANNOT_OPEN_CORRUPT, EFalse );
       
  8431                     }
       
  8432                 else
       
  8433                     {
       
  8434                     RFile file = CUniDataUtils::GetAttachmentFileL( Document()->DataModel()->Mtm(), obj->AttachmentId() );
       
  8435                     CleanupClosePushL( file );
       
  8436                     TDataType dataType( obj->MimeType() );
       
  8437                     
       
  8438                     if ( !iDocHandler )
       
  8439                         {
       
  8440                         iDocHandler = CDocumentHandler::NewL( iEikonEnv->Process() );
       
  8441                         iDocHandler->SetExitObserver( this );
       
  8442                         }
       
  8443                     
       
  8444                     if ( obj->DrmInfo() )
       
  8445                         {
       
  8446                         obj->DrmInfo()->ReleaseRights();
       
  8447                         }
       
  8448                     
       
  8449                    // Since Activating input blockers will block the command CEIkCmdEXit. So used the flag 
       
  8450                    //ActivateInputBlockerL( NULL );
       
  8451                     iEditorFlags |= EMsgEditInProgress;
       
  8452                     TRAPD(ret,iDocHandler->OpenFileEmbeddedL( file, dataType ));
       
  8453                     
       
  8454                     CleanupStack::PopAndDestroy( &file );
       
  8455                     
       
  8456                     if(ret != KErrNone)
       
  8457                         {
       
  8458                          iEditorFlags &= ~EMsgEditInProgress;   
       
  8459                          //  DeactivateInputBlocker();
       
  8460                         }
       
  8461                     }
       
  8462                 break;
       
  8463                 }
       
  8464             default:
       
  8465                 {
       
  8466                 break;
       
  8467                 }
       
  8468             }
       
  8469         }
       
  8470     }
       
  8471 
       
  8472 // ---------------------------------------------------------
       
  8473 // CUniEditorAppUi::CheckMaxSmsSizeAndShowNoteL
       
  8474 // ---------------------------------------------------------
       
  8475 //
       
  8476 void CUniEditorAppUi::CheckMaxSmsSizeAndShowNoteL( TBool aSendCheck /*= EFalse*/ )
       
  8477     {
       
  8478     CUniEditorDocument* doc = Document();
       
  8479 
       
  8480     if( !aSendCheck )
       
  8481         {
       
  8482         if( !IsHardcodedSms() )
       
  8483             { // Just return
       
  8484             iEditorFlags &= ~EMaxSmsSizeNoteShown;
       
  8485             return;
       
  8486             }
       
  8487         }
       
  8488     else
       
  8489         {
       
  8490         if( Document()->UniState() != EUniSms )
       
  8491             { // UniState is MMS -> just return
       
  8492             iEditorFlags &= ~EMaxSmsSizeNoteShown;
       
  8493             return;
       
  8494             }
       
  8495         }
       
  8496     
       
  8497     TInt lengthOne( 0 );
       
  8498     TInt lengthMany( 0 );
       
  8499     
       
  8500     doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  8501 
       
  8502     TInt maxLen = lengthOne;
       
  8503   
       
  8504     if( doc->AbsoluteMaxSmsParts() > 1 )
       
  8505         {
       
  8506         maxLen = doc->AbsoluteMaxSmsParts()*lengthMany;
       
  8507         }
       
  8508     
       
  8509     if ( doc->AbsoluteMaxSmsCharacters() > 0 )
       
  8510         {
       
  8511         maxLen = doc->AbsoluteMaxSmsCharacters();
       
  8512         }
       
  8513     
       
  8514     TInt totalLen = iSmsBodyLength + iSmsSubjectLength;
       
  8515 
       
  8516     if( doc->EmailOverSmsSupported() )
       
  8517         {
       
  8518         // This length is needed by recipient and subject separator chars
       
  8519         TInt separatorLen = 0;
       
  8520 
       
  8521         TInt emailAddrLen = iHeader->LongestEmailAddress();
       
  8522         
       
  8523         if( emailAddrLen )
       
  8524             {
       
  8525             separatorLen++; // one extra char needed by separator char
       
  8526             }
       
  8527 
       
  8528         totalLen += emailAddrLen + separatorLen;
       
  8529         }
       
  8530 
       
  8531     if( totalLen <= maxLen-1 )
       
  8532         { // Length is under the max size -> just return
       
  8533         iEditorFlags &= ~EMaxSmsSizeNoteShown;
       
  8534         return;
       
  8535         }
       
  8536 
       
  8537     if( !aSendCheck && iEditorFlags & EMaxSmsSizeNoteShown )
       
  8538         { // The note has been shown -> just return
       
  8539         return;                
       
  8540         }
       
  8541 
       
  8542     iEditorFlags |= EMaxSmsSizeNoteShown;
       
  8543     
       
  8544     if( totalLen == maxLen )
       
  8545         { 
       
  8546         if( aSendCheck )
       
  8547             { // SMS is max length so it can still be sent
       
  8548             iEditorFlags &= ~EMaxSmsSizeNoteShown;
       
  8549             return;
       
  8550             }
       
  8551         else
       
  8552             { 
       
  8553             if( iEditorFlags & EShowSmsSizeNoteNextTime )
       
  8554                 {
       
  8555                 // Show "Cannot add text"
       
  8556                 ShowConfirmableInfoL( R_UNIEDITOR_SMS_LENGTH_EXCEEDED );
       
  8557                 // We remove this flag already now
       
  8558                 iEditorFlags &= ~EShowSmsSizeNoteNextTime;
       
  8559                 }
       
  8560             else
       
  8561                 {
       
  8562                 // Show the note next time
       
  8563                 iEditorFlags |= EShowSmsSizeNoteNextTime;
       
  8564                 // Remove this as it's not shown already
       
  8565                 iEditorFlags &= ~EMaxSmsSizeNoteShown;                
       
  8566                 }
       
  8567             }
       
  8568         }
       
  8569     else if( totalLen == maxLen+1 )
       
  8570         { // Show "Cannot send. Remove 1"
       
  8571         ShowConfirmableInfoL( R_UNIEDITOR_SMS_LENGTH_EXCEEDED_1 );
       
  8572         }
       
  8573     else
       
  8574         { // Show "Cannot send. Remove N"
       
  8575         if( doc->UnicodeCharacterMode() )
       
  8576             {
       
  8577             ShowConfirmableInfoL( R_UNIEDITOR_SMS_LENGTH_EXCEEDED_MANY_UNICODE );
       
  8578             }
       
  8579         else
       
  8580             {
       
  8581             TInt howMany = totalLen - maxLen;
       
  8582             HBufC* warningString = 
       
  8583                 StringLoader::LoadLC( R_UNIEDITOR_SMS_LENGTH_EXCEEDED_MANY, howMany, iCoeEnv );
       
  8584             ShowConfirmableInfoL( *warningString );
       
  8585             CleanupStack::PopAndDestroy( warningString );
       
  8586             }
       
  8587 
       
  8588         }
       
  8589     }
       
  8590  
       
  8591 // ---------------------------------------------------------
       
  8592 // CUniEditorAppUi::SetOrRemoveMaxSizeInEdwin
       
  8593 // ---------------------------------------------------------
       
  8594 //
       
  8595 void CUniEditorAppUi::SetOrRemoveMaxSizeInEdwin()
       
  8596     {
       
  8597     CUniEditorDocument* doc = Document();
       
  8598     
       
  8599     if( !IsHardcodedSms() )
       
  8600         { 
       
  8601         // No max limit so set the max TInt
       
  8602         if( BodyCtrlEditor() )
       
  8603             {
       
  8604             BodyCtrlEditor()->SetTextLimit( KMaxTInt );
       
  8605             }
       
  8606         return;
       
  8607         }
       
  8608         
       
  8609     // OK, message type is SMS
       
  8610     
       
  8611     TInt lengthOne( 0 );
       
  8612     TInt lengthMany( 0 );
       
  8613     
       
  8614     doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  8615 
       
  8616     TInt maxLen = lengthOne;
       
  8617   
       
  8618     if( doc->AbsoluteMaxSmsParts() > 1 )
       
  8619         {
       
  8620         maxLen = doc->AbsoluteMaxSmsParts()*lengthMany;
       
  8621         }
       
  8622     
       
  8623     if ( doc->AbsoluteMaxSmsCharacters() > 0 )
       
  8624         {
       
  8625         maxLen = doc->AbsoluteMaxSmsCharacters();
       
  8626         }
       
  8627     
       
  8628     CEikEdwin* bodyEd = BodyCtrlEditor();
       
  8629     CEikEdwin* subjEd = SubjectCtrlEditor();
       
  8630     
       
  8631     if( !bodyEd )
       
  8632         { 
       
  8633         // There's no body editor available -> just return
       
  8634         return;
       
  8635         }
       
  8636 
       
  8637     // This length is needed by recipient and subject separator chars
       
  8638     TInt separatorLen = 0;
       
  8639 
       
  8640     TInt emailAddrLen = iHeader->LongestEmailAddress();
       
  8641     
       
  8642     if( emailAddrLen )
       
  8643         {
       
  8644         separatorLen++; // one extra char needed by separator char
       
  8645         }
       
  8646 
       
  8647     // Max subject length is maxLen decreased by longest email address and body length
       
  8648     TInt maxSubjectLen = maxLen - emailAddrLen - iSmsBodyLength - separatorLen;
       
  8649     
       
  8650     if( maxSubjectLen > KUniEdMaxSubjectLen )
       
  8651         {
       
  8652         maxSubjectLen = KUniEdMaxSubjectLen;
       
  8653         }
       
  8654 
       
  8655     // Max body length is maxLen decreased by longest email address and subject length
       
  8656     TInt maxBodyLen = maxLen - emailAddrLen - iSmsSubjectLength - separatorLen;
       
  8657     
       
  8658     if( bodyEd->TextLength() > maxBodyLen )
       
  8659         { 
       
  8660         // If there's already too long body field -> increase the limit to avoid panic in edwin
       
  8661         maxBodyLen = bodyEd->TextLength();
       
  8662         }
       
  8663     
       
  8664     bodyEd->SetTextLimit( maxBodyLen );
       
  8665     
       
  8666     if( subjEd )
       
  8667         {
       
  8668         if( subjEd->TextLength() > maxSubjectLen )
       
  8669             { 
       
  8670             // If there's already too long subject field -> increase the limit to avoid panic in edwin
       
  8671             maxSubjectLen = subjEd->TextLength();
       
  8672             }
       
  8673         subjEd->SetTextLimit( maxSubjectLen );
       
  8674         }
       
  8675     }
       
  8676 
       
  8677 // ---------------------------------------------------------
       
  8678 // CUniEditorAppUi::CheckMaxRecipientsAndShowNoteL
       
  8679 // ---------------------------------------------------------
       
  8680 //
       
  8681 TBool CUniEditorAppUi::CheckMaxRecipientsAndShowNoteL( TBool aSendCheck /*= EFalse*/ )
       
  8682     {
       
  8683     
       
  8684     TInt maxRecipients = 0;
       
  8685     
       
  8686     CUniEditorDocument* doc = Document();
       
  8687     
       
  8688     TUniState state = doc->UniState();
       
  8689     
       
  8690     if( IsHardcodedSms() )
       
  8691         {
       
  8692         maxRecipients = doc->MaxSmsRecipients();
       
  8693         }
       
  8694     else
       
  8695         {
       
  8696         maxRecipients = doc->MaxMmsRecipients();
       
  8697         }
       
  8698     
       
  8699     TInt recipientCount = 0;
       
  8700     
       
  8701     CMsgAddressControl* addrCntrl = ToCtrl();
       
  8702     
       
  8703     if( addrCntrl )
       
  8704         {
       
  8705         recipientCount = addrCntrl->GetRecipientsL()->Count();
       
  8706         }
       
  8707     
       
  8708     if( state == EUniMms ) // If the current state is mms,
       
  8709         { // add also possible CC and BCC recipients
       
  8710         addrCntrl = iView->ControlById( EMsgComponentIdCc )?
       
  8711             static_cast<CMsgAddressControl*>(iView->ControlById( EMsgComponentIdCc ) ):NULL;
       
  8712         if( addrCntrl )
       
  8713             {
       
  8714             recipientCount += addrCntrl->GetRecipientsL()->Count();
       
  8715             }
       
  8716         addrCntrl = iView->ControlById( EMsgComponentIdBcc )?
       
  8717             static_cast<CMsgAddressControl*>(iView->ControlById( EMsgComponentIdBcc ) ):NULL;
       
  8718         if( addrCntrl )
       
  8719             {
       
  8720             recipientCount += addrCntrl->GetRecipientsL()->Count();
       
  8721             }
       
  8722         }
       
  8723 
       
  8724     if( recipientCount <= maxRecipients )
       
  8725         { // ok number of recipients
       
  8726         iEditorFlags &= ~EMaxRecipientShown;
       
  8727         return ETrue;
       
  8728         }
       
  8729         
       
  8730 /* This is to be removed from UI spec (max recipients reached
       
  8731     if( !aSendCheck )
       
  8732         {
       
  8733         if( iEditorFlags & EMaxRecipientShown )
       
  8734             { // Note is already shown
       
  8735             return EFalse;
       
  8736             }
       
  8737         if( recipientCount == maxRecipients )
       
  8738             {
       
  8739             ShowConfirmableInfoL( R_UNIEDITOR_MAX_RECIPIENTS_REACHED );
       
  8740             iEditorFlags |= EMaxRecipientShown;
       
  8741             return EFalse;
       
  8742             }
       
  8743         }
       
  8744   
       
  8745         
       
  8746     if( recipientCount == maxRecipients )
       
  8747         { // This time aSendCheck is certainly ETrue so no note is needed
       
  8748         return ETrue;
       
  8749         }*/
       
  8750   
       
  8751     if( iEditorFlags & EMaxRecipientShown && !aSendCheck )
       
  8752         { // Note is already shown and this is not send check
       
  8753         return EFalse;
       
  8754         }
       
  8755     
       
  8756     iEditorFlags |= EMaxRecipientShown;
       
  8757     
       
  8758     TInt waitRes( KErrNotFound );
       
  8759     
       
  8760     if ( iWaitDialog )
       
  8761         {
       
  8762         waitRes = iWaitResId;
       
  8763         RemoveWaitNote();
       
  8764         }   
       
  8765     
       
  8766     if( recipientCount == maxRecipients + 1 )
       
  8767         {
       
  8768         ShowConfirmableInfoL( R_UNIEDITOR_MAX_RECIPIENTS_EXCEEDED_1 );
       
  8769         }
       
  8770     else
       
  8771         {
       
  8772         HBufC* warningString = 
       
  8773             StringLoader::LoadLC( R_UNIEDITOR_MAX_RECIPIENTS_EXCEEDED_MANY, 
       
  8774                                   recipientCount - maxRecipients, 
       
  8775                                   iCoeEnv );
       
  8776             
       
  8777         ShowConfirmableInfoL( *warningString );
       
  8778         
       
  8779         CleanupStack::PopAndDestroy( warningString );
       
  8780         }
       
  8781     
       
  8782     if ( waitRes != KErrNotFound )
       
  8783         {
       
  8784         ShowWaitNoteL( waitRes );
       
  8785         }
       
  8786     
       
  8787     return EFalse;
       
  8788     }
       
  8789 
       
  8790 // ---------------------------------------------------------
       
  8791 // CUniEditorAppUi::UpdateMiddleSoftkeyL
       
  8792 // ---------------------------------------------------------
       
  8793 //
       
  8794 void CUniEditorAppUi::UpdateMiddleSoftkeyL()
       
  8795     {
       
  8796     /* This is just a placeholder so far */
       
  8797     TInt resId = 0;
       
  8798 
       
  8799     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  8800 
       
  8801     if ( ctrl )
       
  8802         {
       
  8803         switch ( ctrl->ControlId() )
       
  8804             {
       
  8805             case EMsgComponentIdTo:
       
  8806             case EMsgComponentIdCc:
       
  8807             case EMsgComponentIdBcc:
       
  8808                 {
       
  8809                    if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
  8810                     {
       
  8811                     break;
       
  8812                     }
       
  8813                 
       
  8814                 resId = R_UNI_MSK_BUTTON_ADD;
       
  8815                 }
       
  8816                 break;
       
  8817             case EMsgComponentIdAttachment:
       
  8818                 {
       
  8819                 resId = R_UNI_MSK_BUTTON_OBJECTS;
       
  8820                 break;
       
  8821                 }
       
  8822             case EMsgComponentIdImage:
       
  8823                 if ( Document()->DataModel()->SmilType() == E3GPPSmil )
       
  8824                     { // focus is on "no-edit" SMIL icon
       
  8825                     resId = R_UNI_MSK_BUTTON_PLAY_PRES;
       
  8826                     } 
       
  8827                 else
       
  8828                     { // ordinary image
       
  8829                     resId = R_UNI_MSK_BUTTON_VIEW_IMAGE;
       
  8830                     }
       
  8831                 break;
       
  8832             case EMsgComponentIdVideo:
       
  8833                 {
       
  8834                 resId = R_UNI_MSK_BUTTON_PLAY_VIDEO;
       
  8835                 break;
       
  8836                 }
       
  8837             case EMsgComponentIdAudio:
       
  8838                 {
       
  8839                 resId = R_UNI_MSK_BUTTON_PLAY_AUDIO;
       
  8840                 break;
       
  8841                 }
       
  8842             case EMsgComponentIdSvg:
       
  8843                 {
       
  8844                 resId = R_UNI_MSK_BUTTON_PLAY_SVG;
       
  8845                 break;
       
  8846                 }
       
  8847             case EMsgComponentIdBody:
       
  8848                 {
       
  8849                 resId = R_UNI_MSK_BUTTON_CONTEXT_MENU;
       
  8850                 MenuBar()->SetContextMenuTitleResourceId( R_UNIEDITOR_CONTEXT_MENUBAR );
       
  8851                 break;
       
  8852                 }
       
  8853 
       
  8854             case EMsgComponentIdSubject:
       
  8855             default:
       
  8856                 break;
       
  8857             }
       
  8858         }
       
  8859 
       
  8860     if ( resId != iMskResId )
       
  8861         {
       
  8862         const TInt KMskPosition = 3;
       
  8863         CEikButtonGroupContainer* cba = Cba();
       
  8864         if( resId != 0 )
       
  8865             {
       
  8866             cba->SetCommandL( KMskPosition, resId );
       
  8867             }
       
  8868         else
       
  8869             { // nullify the command
       
  8870             cba->SetCommandL( KMskPosition, 0, KNullDesC() );
       
  8871             }
       
  8872         cba->DrawNow();
       
  8873         iMskResId = resId;
       
  8874         }
       
  8875     return;
       
  8876     }
       
  8877 
       
  8878 // ---------------------------------------------------------
       
  8879 // CUniEditorAppUi::SetInputModeToAddressFields
       
  8880 // ---------------------------------------------------------
       
  8881 //
       
  8882 void CUniEditorAppUi::SetInputModeToAddressFields( TInt aInputMode )
       
  8883     {
       
  8884     for (TInt i = CUniEditorHeader::EHeaderAddressTo; 
       
  8885         i <= CUniEditorHeader::EHeaderAddressBcc; i++ )
       
  8886         {    
       
  8887         if ( iHeader &&  
       
  8888              iHeader->AddressControl( static_cast<CUniEditorHeader::THeaderFields> (i) ) )
       
  8889             {
       
  8890             iHeader->AddressControl( 
       
  8891                 static_cast<CUniEditorHeader::THeaderFields> (i) )
       
  8892                     ->Editor().SetAknEditorCurrentInputMode( aInputMode );
       
  8893             }
       
  8894         }
       
  8895     
       
  8896     }
       
  8897 
       
  8898 // ---------------------------------------------------------
       
  8899 // CUniEditorAppUi::DoEditMmsPriorityL
       
  8900 // ---------------------------------------------------------
       
  8901 //
       
  8902 void CUniEditorAppUi::DoEditMmsPriorityL()
       
  8903     {
       
  8904 
       
  8905     TUniSendingSettings settings;
       
  8906     CUniEditorPlugin* plugin = MmsPlugin();
       
  8907 
       
  8908     if( plugin )
       
  8909         {
       
  8910         plugin->GetSendingSettingsL( settings );
       
  8911         }
       
  8912 
       
  8913     TInt currentlySelected = 0;
       
  8914     switch( settings.iPriority )
       
  8915         {
       
  8916         case TUniSendingSettings::EUniPriorityNormal:
       
  8917             currentlySelected = 1;
       
  8918             break;
       
  8919         case TUniSendingSettings::EUniPriorityLow:
       
  8920             currentlySelected = 2;
       
  8921             break;
       
  8922         default:
       
  8923             break;
       
  8924         }
       
  8925     
       
  8926     // Create listbox    
       
  8927     CAknSingleGraphicPopupMenuStyleListBox* listBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox;
       
  8928     CleanupStack::PushL( listBox );
       
  8929     
       
  8930     // Create popup
       
  8931     CAknPopupList* popup = CAknPopupList::NewL( 
       
  8932                 listBox, 
       
  8933                 R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT, 
       
  8934                 AknPopupLayouts::EMenuGraphicWindow );
       
  8935     CleanupStack::PushL( popup );
       
  8936 
       
  8937     // Construct listbox
       
  8938     listBox->ConstructL( popup, CEikListBox::ELeftDownInViewRect );
       
  8939     listBox->CreateScrollBarFrameL( ETrue );
       
  8940     listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
  8941                                                       CEikScrollBarFrame::EAuto );
       
  8942   
       
  8943     // Set title    
       
  8944     HBufC* title = StringLoader::LoadLC( R_UNIEDITOR_PRIORITY_TITLE, iCoeEnv );
       
  8945     popup->SetTitleL( title->Des() );
       
  8946     CleanupStack::PopAndDestroy( title );
       
  8947 
       
  8948     CAknIconArray* iconArray = RadioButtonArrayL();
       
  8949     listBox->ItemDrawer()->FormattedCellData()->SetIconArray( iconArray ); // FormattedCellData owns
       
  8950 
       
  8951     listBox->HandleItemAdditionL();
       
  8952 
       
  8953     TResourceReader reader;
       
  8954     iEikonEnv->CreateResourceReaderLC( reader, R_UNI_PRIORITY_LIST );
       
  8955     
       
  8956     CDesCArrayFlat* items = new ( ELeave ) CDesCArrayFlat( KSettingsGranularity );
       
  8957     CleanupStack::PushL( items );
       
  8958 
       
  8959     // Get the labels from resources
       
  8960     const TInt count = reader.ReadInt16();
       
  8961 
       
  8962     for ( TInt loop = 0; loop < count; loop++ )
       
  8963         {
       
  8964         HBufC* label = reader.ReadHBufCL();        
       
  8965         CleanupStack::PushL( label );
       
  8966         TPtr pLabel = label->Des();
       
  8967         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( pLabel );
       
  8968         
       
  8969         TBuf<20> itemString;
       
  8970         if( currentlySelected == loop )
       
  8971             { // This one is selected
       
  8972             itemString.AppendNum( 1 );
       
  8973             }
       
  8974         else
       
  8975             {
       
  8976             itemString.AppendNum( 0 );
       
  8977             }
       
  8978 
       
  8979         itemString.Append( _L("\t") );
       
  8980         itemString.Append( pLabel );
       
  8981         items->AppendL( itemString );
       
  8982         
       
  8983         CleanupStack::PopAndDestroy( label );
       
  8984         label = NULL;
       
  8985         }
       
  8986 
       
  8987     CTextListBoxModel* model = listBox->Model();
       
  8988     model->SetItemTextArray( items );
       
  8989     model->SetOwnershipType( ELbmOwnsItemArray );
       
  8990     CleanupStack::Pop( items ); // model owns it now
       
  8991     CleanupStack::PopAndDestroy(); // reader 
       
  8992 
       
  8993     listBox->SetCurrentItemIndexAndDraw( currentlySelected );
       
  8994 
       
  8995     TInt result = popup->ExecuteLD();
       
  8996 
       
  8997     if( result )
       
  8998         {
       
  8999         // OK, user chose the priority bit
       
  9000         switch( listBox->CurrentItemIndex() )
       
  9001             {
       
  9002             case 0:
       
  9003                 {
       
  9004                 settings.iPriority = TUniSendingSettings::EUniPriorityHigh;
       
  9005                 break;
       
  9006                 }
       
  9007             case 1:
       
  9008                 {
       
  9009                 settings.iPriority = TUniSendingSettings::EUniPriorityNormal;
       
  9010                 break;
       
  9011                 }
       
  9012             default:
       
  9013                 {
       
  9014                 settings.iPriority = TUniSendingSettings::EUniPriorityLow;
       
  9015                 break;
       
  9016                 }
       
  9017             }
       
  9018             
       
  9019         if( plugin )
       
  9020             {
       
  9021             plugin->SetSendingSettingsL( settings );
       
  9022             }
       
  9023             
       
  9024         UpdateIndicatorIconsL();
       
  9025         }
       
  9026     CleanupStack::Pop(); // for popup
       
  9027     CleanupStack::PopAndDestroy( listBox ); 
       
  9028     }
       
  9029 
       
  9030 // ---------------------------------------------------------
       
  9031 // CUniEditorAppUi::RadioButtonArrayL
       
  9032 // ---------------------------------------------------------
       
  9033 //
       
  9034 CAknIconArray* CUniEditorAppUi::RadioButtonArrayL()
       
  9035     {
       
  9036     TFileName* fileName = new( ELeave ) TFileName;
       
  9037     CleanupStack::PushL( fileName );
       
  9038     
       
  9039     fileName->Copy( KAvkonBitmapFile );
       
  9040 
       
  9041     CAknIconArray* iconArray = new (ELeave) CAknIconArray( 2 );
       
  9042     CleanupStack::PushL( iconArray ); 
       
  9043 
       
  9044     CFbsBitmap* bitmap = NULL;
       
  9045     CFbsBitmap* mask = NULL;
       
  9046     CGulIcon* icon = NULL;
       
  9047 
       
  9048     TAknsItemID skinId = KAknsIIDQgnPropRadiobuttOff;
       
  9049     TInt bitmapId = EMbmAvkonQgn_prop_radiobutt_off;
       
  9050 
       
  9051     AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
  9052                             skinId,
       
  9053                             bitmap,
       
  9054                             mask,
       
  9055                             *fileName,
       
  9056                             bitmapId,
       
  9057                             bitmapId+1 );
       
  9058         
       
  9059     CleanupStack::PushL( bitmap );
       
  9060     CleanupStack::PushL( mask );
       
  9061     icon = CGulIcon::NewL( bitmap, mask );
       
  9062     CleanupStack::Pop( 2, bitmap );
       
  9063     CleanupStack::PushL( icon ); 
       
  9064     iconArray->AppendL( icon );
       
  9065     CleanupStack::Pop();   // icon
       
  9066 
       
  9067     skinId = KAknsIIDQgnPropRadiobuttOn;
       
  9068     bitmapId = EMbmAvkonQgn_prop_radiobutt_on;
       
  9069 
       
  9070     AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
  9071                             skinId,
       
  9072                             bitmap,
       
  9073                             mask,
       
  9074                             *fileName,
       
  9075                             bitmapId,
       
  9076                             bitmapId+1 );
       
  9077         
       
  9078     CleanupStack::PushL( bitmap );
       
  9079     CleanupStack::PushL( mask );
       
  9080     
       
  9081     icon = CGulIcon::NewL( bitmap, mask );
       
  9082     CleanupStack::Pop( 2 );
       
  9083     CleanupStack::PushL( icon ); 
       
  9084     
       
  9085     iconArray->AppendL( icon );
       
  9086     CleanupStack::Pop();   // icon
       
  9087 
       
  9088     CleanupStack::Pop( iconArray );
       
  9089     CleanupStack::PopAndDestroy( fileName );
       
  9090     return iconArray;
       
  9091     }
       
  9092 
       
  9093 
       
  9094 // ---------------------------------------------------------
       
  9095 // CUniEditorAppUi::ConfirmSmsSendInMultiplePartsL
       
  9096 // ---------------------------------------------------------
       
  9097 //
       
  9098 TBool CUniEditorAppUi::ConfirmSmsSendInMultiplePartsL()
       
  9099     {
       
  9100     // If it's variated off -> return ETrue
       
  9101     if( !( iEditorFlags & EShowSmsSentInManyParts ) )
       
  9102         {
       
  9103         return ETrue;
       
  9104         }
       
  9105     
       
  9106     CUniEditorDocument* doc = Document();
       
  9107     
       
  9108     TInt lengthOne( 0 );
       
  9109     TInt lengthMany( 0 );
       
  9110     
       
  9111     doc->SmsCharacterLimits( lengthOne, lengthMany );
       
  9112 
       
  9113     TInt totalLen = iSmsBodyLength + iSmsSubjectLength;
       
  9114 
       
  9115     if ( doc->EmailOverSmsSupported() )
       
  9116         {
       
  9117         // This length is needed by recipient and subject separator chars
       
  9118         TInt separatorLen = 0;
       
  9119 
       
  9120         TInt emailAddrLen = iHeader->LongestEmailAddress();
       
  9121         
       
  9122         if( emailAddrLen )
       
  9123             {
       
  9124             separatorLen++; // one extra char needed by separator char
       
  9125             }
       
  9126 
       
  9127         totalLen += emailAddrLen + separatorLen;
       
  9128         }
       
  9129 
       
  9130     if( totalLen <= lengthOne )
       
  9131         { // All fits in one message -> return ETrue
       
  9132         return ETrue;
       
  9133         }
       
  9134 
       
  9135     TInt messages = totalLen/lengthMany;
       
  9136     
       
  9137     if( totalLen%lengthMany )
       
  9138         { // If remainder is not zero -> add one
       
  9139         messages++;
       
  9140         }
       
  9141 
       
  9142     HBufC* qry = StringLoader::LoadLC( R_UNIEDITOR_SMS_SEND_MULTIPLE_PARTS, messages );
       
  9143     
       
  9144     if( ShowConfirmationNoQuestionQueryL( *qry ) )
       
  9145         {
       
  9146         CleanupStack::PopAndDestroy( qry );
       
  9147         return ETrue;
       
  9148         }
       
  9149         
       
  9150     CleanupStack::PopAndDestroy( qry );
       
  9151     return EFalse;
       
  9152     }
       
  9153 
       
  9154 // ---------------------------------------------------------
       
  9155 // CUniEditorAppUi::SetTitleIconsSizeL
       
  9156 //
       
  9157 // Sets the correct size from LAF for title MMS & SMS title icons
       
  9158 // ---------------------------------------------------------
       
  9159 //
       
  9160 void CUniEditorAppUi::SetTitleIconsSizeL()
       
  9161     {
       
  9162     SetTitleIconSizeL( iIconSms->Bitmap() );
       
  9163     SetTitleIconSizeL( iIconMms->Bitmap() );    
       
  9164     }
       
  9165  
       
  9166 // ---------------------------------------------------------
       
  9167 // CUniEditorAppUi::AcceptEmailAddresses
       
  9168 // ---------------------------------------------------------
       
  9169 //
       
  9170 TBool CUniEditorAppUi::AcceptEmailAddresses()
       
  9171     {
       
  9172     TBool retVal = ETrue;
       
  9173 
       
  9174     if( IsHardcodedSms() && !Document()->EmailOverSmsSupported() )
       
  9175         { // We are in locked SMS mode and no email over sms -> accept only numbers
       
  9176           retVal = EFalse;
       
  9177         }
       
  9178 
       
  9179     return retVal;
       
  9180     }
       
  9181 
       
  9182 // ---------------------------------------------------------
       
  9183 // CUniEditorAppUi::IsHardcodedSms
       
  9184 // ---------------------------------------------------------
       
  9185 //
       
  9186 TBool CUniEditorAppUi::IsHardcodedSms()
       
  9187     {
       
  9188     TBool hardSms = EFalse;
       
  9189 
       
  9190     if( iMtm->MessageTypeLocking() == EUniMessageTypeLocked )
       
  9191         { // the message type is pre-locked
       
  9192         if( iMtm->MessageTypeSetting() == EUniMessageTypeSettingSms )
       
  9193             { // to sms
       
  9194             hardSms = ETrue;
       
  9195             }
       
  9196         }
       
  9197     else if( iMtm->MessageTypeSetting() == EUniMessageTypeSettingSms )
       
  9198            { // message is not pre-locked, but manually locked to sms
       
  9199            hardSms = ETrue;
       
  9200            }
       
  9201 
       
  9202     return hardSms;    
       
  9203     }
       
  9204 
       
  9205 // ---------------------------------------------------------
       
  9206 // CUniEditorAppUi::ResolveLaunchFocusedControlL
       
  9207 // 
       
  9208 // Resolves the control id of control that should be focused after
       
  9209 // launch. Normal case is that first existing and empty control from To, Subject,
       
  9210 // body text control and image control is focused in this order.
       
  9211 //
       
  9212 // Exeptions to this is:
       
  9213 //
       
  9214 // Reply -> Body text field always focused.
       
  9215 // Locked SMS with vCard/vCal -> To address field always focused.
       
  9216 // ---------------------------------------------------------
       
  9217 //
       
  9218 TMsgControlId CUniEditorAppUi::ResolveLaunchFocusedControlL()
       
  9219     {
       
  9220     TMsgControlId result = EMsgComponentIdNull;
       
  9221     
       
  9222     if ( Document()->MessageType() == EUniReply )
       
  9223         {
       
  9224         result = EMsgComponentIdBody;
       
  9225         }
       
  9226     else if ( iEditorFlags & ELockedSmsWithAtta )
       
  9227         {
       
  9228         result = EMsgComponentIdTo;
       
  9229         }
       
  9230     else
       
  9231         {
       
  9232         CMsgAddressControl* toControl = ToCtrl();
       
  9233     
       
  9234         if ( toControl &&
       
  9235              toControl->GetRecipientsL()->Count() == 0 )
       
  9236             {
       
  9237             result = EMsgComponentIdTo;
       
  9238             }
       
  9239         else
       
  9240             {
       
  9241             if ( iSupportedFeatures & EUniFeatureSubject )
       
  9242                 {
       
  9243                 CMsgExpandableControl* subj = SubjectCtrl();
       
  9244                 if ( subj && 
       
  9245                      subj->TextContent().DocumentLength() == 0 )
       
  9246                     {
       
  9247                     result = EMsgComponentIdSubject;
       
  9248                     }
       
  9249                 }
       
  9250             
       
  9251             if ( result == EMsgComponentIdNull )
       
  9252                 {
       
  9253                 if ( BodyCtrl() )
       
  9254                     {
       
  9255                     result = EMsgComponentIdBody;
       
  9256                     }
       
  9257                 else if ( ImageCtrl() )
       
  9258                     {
       
  9259                     result = EMsgComponentIdImage;
       
  9260                     }
       
  9261                 
       
  9262                 }
       
  9263             }
       
  9264         }
       
  9265         
       
  9266     return result;
       
  9267     }
       
  9268  
       
  9269 // ---------------------------------------------------------
       
  9270 // CUniEditorAppUi::SetMessageTypeLockingL
       
  9271 // ---------------------------------------------------------
       
  9272 //
       
  9273 void CUniEditorAppUi::SetMessageTypeLockingL()
       
  9274     {
       
  9275     if ( SmsPlugin() && !MmsPlugin() )
       
  9276         { 
       
  9277         // Sms found, no mms
       
  9278         iMtm->SetMessageTypeSetting( EUniMessageTypeSettingSms );
       
  9279         iMtm->SetMessageTypeLocking( EUniMessageTypeLocked );
       
  9280         }
       
  9281     else if ( !SmsPlugin() && MmsPlugin() )
       
  9282         { 
       
  9283         // Mms found, no sms
       
  9284         iMtm->SetMessageTypeSetting( EUniMessageTypeSettingMms );
       
  9285         iMtm->SetMessageTypeLocking( EUniMessageTypeLocked );
       
  9286         }
       
  9287     else
       
  9288         { 
       
  9289         // If we are here, both sms and mms exist
       
  9290         if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
  9291             { 
       
  9292             // If opening upload message -> lock is as mms
       
  9293             iMtm->SetMessageTypeSetting( EUniMessageTypeSettingMms );
       
  9294             iMtm->SetMessageTypeLocking( EUniMessageTypeLocked );
       
  9295             }
       
  9296         else
       
  9297             {
       
  9298             if ( iMtm->MessageTypeLocking() == EUniMessageTypeLockingNotSet )
       
  9299                 { 
       
  9300                 // It's not yet set -> check the settings of SMS conversion
       
  9301                 iMtm->SetMessageTypeLocking( EUniMessageTypeNotLocked );
       
  9302                 
       
  9303                 TUniSendingSettings settings;
       
  9304                 SmsPlugin()->GetSendingSettingsL( settings );
       
  9305 
       
  9306                 if ( settings.iMessageType == TUniSendingSettings::EUniMessageTypeFax  ||
       
  9307                      settings.iMessageType == TUniSendingSettings::EUniMessageTypePaging )
       
  9308                     { 
       
  9309                     // It's temporary locked to sms sub type (fax or pager)
       
  9310                     iMtm->SetMessageTypeSetting( EUniMessageTypeSettingSms );
       
  9311                     }
       
  9312                 else
       
  9313                     { 
       
  9314                     // Otherwise set it to automatic
       
  9315                     iMtm->SetMessageTypeSetting( EUniMessageTypeSettingAutomatic );
       
  9316                     }
       
  9317                 }
       
  9318             }
       
  9319         }
       
  9320     }
       
  9321  
       
  9322 // ---------------------------------------------------------
       
  9323 // CUniEditorAppUi::ActivateInputBlockerL
       
  9324 // ---------------------------------------------------------
       
  9325 //
       
  9326 void CUniEditorAppUi::ActivateInputBlockerL( CActive* aActiveObjectToCancel )
       
  9327     {
       
  9328     delete iInputBlocker;
       
  9329     iInputBlocker = NULL;
       
  9330     
       
  9331     iInputBlocker = CAknInputBlock::NewLC();    
       
  9332     CleanupStack::Pop( iInputBlocker );
       
  9333     
       
  9334     if ( aActiveObjectToCancel )
       
  9335         {
       
  9336         iInputBlocker->SetCancelActive( aActiveObjectToCancel );
       
  9337         }
       
  9338     }
       
  9339  
       
  9340 // ---------------------------------------------------------
       
  9341 // CUniEditorAppUi::DeactivateInputBlocker
       
  9342 // ---------------------------------------------------------
       
  9343 //
       
  9344 void CUniEditorAppUi::DeactivateInputBlocker()
       
  9345     {
       
  9346     if ( iInputBlocker )
       
  9347         {
       
  9348         iInputBlocker->SetCancelActive( NULL );    
       
  9349         delete iInputBlocker;
       
  9350         iInputBlocker = NULL;
       
  9351         }
       
  9352     }
       
  9353 
       
  9354 // ---------------------------------------------------------
       
  9355 // CUniEditorAppUi::UpdateToolbarL
       
  9356 // ---------------------------------------------------------
       
  9357 //
       
  9358 void CUniEditorAppUi::UpdateToolbarL()
       
  9359     {
       
  9360     if ( iFixedToolbar )
       
  9361         {
       
  9362         iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarSend, EFalse, EFalse );
       
  9363         
       
  9364         if ( TUniMsvEntry::IsMmsUpload( Document()->Entry() ) )
       
  9365             {
       
  9366             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarAddRecipient, ETrue, EFalse );
       
  9367             }
       
  9368         else
       
  9369             {
       
  9370             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarAddRecipient, EFalse, EFalse );
       
  9371             }
       
  9372         
       
  9373         if ( IsHardcodedSms() ||
       
  9374              ( Document()->UniState() == EUniMms &&
       
  9375                Document()->DataModel()->SmilType() != EMmsSmil ) )
       
  9376 
       
  9377             {
       
  9378             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, EFalse );
       
  9379             }
       
  9380         else
       
  9381             {
       
  9382             iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, EFalse, EFalse );
       
  9383             }
       
  9384         
       
  9385         iFixedToolbar->DrawNow();
       
  9386         }
       
  9387     }
       
  9388 
       
  9389 // ---------------------------------------------------------
       
  9390 // CUniEditorAppUi::CheckLockedSmsWithAttaL
       
  9391 // 
       
  9392 // Checks whether message is on locked SMS state with single
       
  9393 // vCard or vCal attachment. In this state text is not allowed
       
  9394 // to be entered into message. First performs state detection.
       
  9395 // If we are on locked SMS with attachment state focus is 
       
  9396 // moved away from subject or body control. Then both subject and
       
  9397 // body text controls are removed. If we are not in locked SMS
       
  9398 // with attachment state subject and body text ccontrol are added
       
  9399 // if appropriate (i.e. they have been removed due to locked SMS
       
  9400 // with attachment state and has not yet been added).
       
  9401 // ---------------------------------------------------------
       
  9402 //
       
  9403 void CUniEditorAppUi::CheckLockedSmsWithAttaL()
       
  9404     {
       
  9405     CUniDataModel* model = Document()->DataModel();
       
  9406     
       
  9407     TBool lockedSmsWithAtta( EFalse );
       
  9408     
       
  9409     if ( IsHardcodedSms() &&
       
  9410          model->AttachmentList().Count() == 1 )
       
  9411         {
       
  9412         CUniObject* obj = model->AttachmentList().GetByIndex( 0 );
       
  9413         if ( obj &&  
       
  9414              obj->MimeType().Length() > 0 &&   
       
  9415              ( obj->MimeType().CompareF( KMsgMimeVCard  ) == 0 || 
       
  9416 #if defined (__I_CAL_SUPPORT) && defined (RD_MESSAGING_ICAL_IMPORT)
       
  9417                obj->MimeType().CompareF( KMsgMimeICal  ) == 0 ||
       
  9418 #endif
       
  9419                obj->MimeType().CompareF( KMsgMimeVCal  ) == 0 ) )
       
  9420             {
       
  9421             lockedSmsWithAtta = ETrue;
       
  9422             }
       
  9423         } 
       
  9424     
       
  9425     if ( lockedSmsWithAtta )
       
  9426         {
       
  9427         iEditorFlags |= ELockedSmsWithAtta;
       
  9428         
       
  9429         CMsgBaseControl* focusedCtrl = iView->FocusedControl();
       
  9430         if ( focusedCtrl && 
       
  9431              ( focusedCtrl->ControlId() == EMsgComponentIdSubject ||
       
  9432                focusedCtrl->ControlId() == EMsgComponentIdBody ) )
       
  9433             {
       
  9434             iView->SetFocus( EMsgComponentIdTo );
       
  9435             }
       
  9436         
       
  9437         if ( iEditorFlags & ESubjectOkInSms &&
       
  9438              SubjectCtrl() )
       
  9439             {
       
  9440             iHeader->AddHeadersDeleteL( EUniFeatureSubject, EFalse );
       
  9441             }
       
  9442     
       
  9443         if ( !iStoredBodyControl )
       
  9444             {   
       
  9445             iStoredBodyControl = iView->RemoveControlL( EMsgComponentIdBody );
       
  9446             }
       
  9447         }
       
  9448     else
       
  9449         {  
       
  9450         if ( iEditorFlags & ELockedSmsWithAtta )
       
  9451             {
       
  9452             if ( iEditorFlags & ESubjectOkInSms &&
       
  9453                  !SubjectCtrl() )
       
  9454                 {
       
  9455                 // Determine if subject field is needed if subject is ok in SMS 
       
  9456                 // and there is no subject field.
       
  9457                 TInt headersVariation = iHeader->AddHeadersVariation();
       
  9458                 TInt headerConfig = iHeader->AddHeadersConfigL();
       
  9459                 
       
  9460                 if ( !( headersVariation & EUniFeatureSubjectConfigurable ) ||
       
  9461                       ( headersVariation & EUniFeatureSubject &&
       
  9462                         headerConfig & EUniFeatureSubject ) )
       
  9463                     {
       
  9464                     // Insert subject to SMS if it is always visible or selected
       
  9465                     // and configured on.
       
  9466                     iHeader->AddHeadersAddL( EUniFeatureSubject );
       
  9467                     }
       
  9468                 }
       
  9469             
       
  9470             if ( iStoredBodyControl )
       
  9471                 {   
       
  9472                 iView->AddControlL( iStoredBodyControl, EMsgComponentIdBody, EMsgFirstControl, EMsgBody );
       
  9473                 iStoredBodyControl = NULL;
       
  9474                 }
       
  9475             }
       
  9476         
       
  9477         iEditorFlags &= ~ELockedSmsWithAtta;
       
  9478         }
       
  9479     }
       
  9480      
       
  9481 
       
  9482 // ---------------------------------------------------------
       
  9483 // CUniEditorAppUi::SetFixedToolbarDimmed
       
  9484 // ---------------------------------------------------------
       
  9485 // 
       
  9486 void CUniEditorAppUi::SetFixedToolbarDimmed()
       
  9487     {
       
  9488     iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarSend, ETrue, ETrue );
       
  9489     iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarAddRecipient, ETrue, ETrue );        
       
  9490     iFixedToolbar->SetItemDimmed( EUniCmdFixedToolbarInsert, ETrue, ETrue );
       
  9491     }
       
  9492 
       
  9493 // ---------------------------------------------------------
       
  9494 // CUniEditorAppUi::EnableFixedToolbar
       
  9495 // ---------------------------------------------------------
       
  9496 // 
       
  9497 void CUniEditorAppUi::EnableFixedToolbar( TAny* aAny )
       
  9498     {
       
  9499     static_cast<CUniEditorAppUi*>( aAny )->DoEnableFixedToolbar();
       
  9500     }
       
  9501 // ---------------------------------------------------------
       
  9502 // CUniEditorAppUi::UpdateFixedToolbar
       
  9503 // ---------------------------------------------------------
       
  9504 // 
       
  9505 void CUniEditorAppUi::UpdateFixedToolbar( TAny* aAny )
       
  9506     {
       
  9507     static_cast<CUniEditorAppUi*>( aAny )->DoUpdateFixedToolbar();      
       
  9508     }
       
  9509 // ---------------------------------------------------------
       
  9510 // CUniEditorAppUi::DisableSendKey
       
  9511 // ---------------------------------------------------------
       
  9512 // 
       
  9513 void CUniEditorAppUi::DisableSendKey(TAny* aAny)
       
  9514 {
       
  9515 	static_cast<CUniEditorAppUi*>( aAny )->SetKeyEventFlags( EDisableSendKeyShort | EDisableSendKeyLong );
       
  9516 }
       
  9517 
       
  9518 // CUniEditorAppUi::CreateFixedToolbarL
       
  9519 // ---------------------------------------------------------
       
  9520 // 
       
  9521 void CUniEditorAppUi::CreateFixedToolbarL( TBool aSetDimmed )
       
  9522     {
       
  9523 #ifdef RD_SCALABLE_UI_V2
       
  9524     if ( AknLayoutUtils::PenEnabled() )
       
  9525         {        
       
  9526         if ( !iFixedToolbar )
       
  9527             {
       
  9528             iFixedToolbar = CAknToolbar::NewL( R_UNIEDITOR_TOOLBAR );
       
  9529             iFixedToolbar->SetToolbarObserver( this );            
       
  9530             
       
  9531              if ( aSetDimmed )
       
  9532                 {
       
  9533                 SetFixedToolbarDimmed();
       
  9534                 }
       
  9535             if ( !( iEditorFlags & EToolbarHidden ) )
       
  9536                 {
       
  9537                 iFixedToolbar->SetToolbarVisibility( ETrue, EFalse );
       
  9538                 }
       
  9539             }
       
  9540         
       
  9541         CEikAppUiFactory* appUiFactory = static_cast<CEikAppUiFactory*>( iEikonEnv->AppUiFactory() );
       
  9542         
       
  9543         CAknToolbar* oldFixedToolbar = appUiFactory->CurrentFixedToolbar();
       
  9544         if ( oldFixedToolbar != iFixedToolbar )
       
  9545             {
       
  9546             oldFixedToolbar->HideItemsAndDrawOnlyBackground( ETrue );
       
  9547             appUiFactory->SetViewFixedToolbar( iFixedToolbar );     
       
  9548             }
       
  9549         
       
  9550        
       
  9551         }
       
  9552     else
       
  9553         {
       
  9554         static_cast<CEikAppUiFactory*>( iEikonEnv->AppUiFactory() )->SetViewFixedToolbar( NULL );
       
  9555         
       
  9556         delete iFixedToolbar;
       
  9557         iFixedToolbar = NULL;
       
  9558         }
       
  9559 #endif // RD_SCALABLE_UI_V2
       
  9560     }
       
  9561 
       
  9562 // ---------------------------------------------------------
       
  9563 // CUniEditorAppUi::SetExtensionButtonDimmed
       
  9564 // ---------------------------------------------------------
       
  9565 // 
       
  9566 void CUniEditorAppUi::SetExtensionButtonDimmed( CAknToolbarExtension* aExtension, 
       
  9567                                                 TInt aButtonId, 
       
  9568                                                 TBool aDimmed )
       
  9569     { 
       
  9570     CAknButton* buttonControl = static_cast<CAknButton*>( aExtension->ControlOrNull( aButtonId ) );
       
  9571     if ( buttonControl &&
       
  9572          buttonControl->IsDimmed() != aDimmed )
       
  9573         {
       
  9574         buttonControl->SetDimmed( aDimmed );             
       
  9575         }
       
  9576     }
       
  9577 
       
  9578 // ---------------------------------------------------------
       
  9579 // CUniEditorAppUi::DoEnableFixedToolbar
       
  9580 // ---------------------------------------------------------
       
  9581 //
       
  9582 void CUniEditorAppUi::DoEnableFixedToolbar()
       
  9583     {
       
  9584     if ( iFixedToolbar )
       
  9585         {
       
  9586         iFixedToolbar->HideItemsAndDrawOnlyBackground( EFalse );
       
  9587         }
       
  9588     
       
  9589     iEditorFlags &= ~EToolbarHidden;
       
  9590     }
       
  9591 
       
  9592 // ---------------------------------------------------------
       
  9593 // CUniEditorAppUi::DoUpdateFixedToolbar
       
  9594 // Update the Toolbar which was dimmed while launching
       
  9595 // the Dialog 
       
  9596 // ---------------------------------------------------------
       
  9597 //
       
  9598 void CUniEditorAppUi::DoUpdateFixedToolbar()
       
  9599     {
       
  9600      UpdateToolbarL();    
       
  9601     }
       
  9602 // ---------------------------------------------------------
       
  9603 // CUniEditorAppUi::DoEnterKeyL
       
  9604 //
       
  9605 // Performs a special handling for enter key when certain control is
       
  9606 // focused. Enter key presses are mapped to selection key presses in
       
  9607 // thse controls.
       
  9608 // ---------------------------------------------------------
       
  9609 // 
       
  9610 TBool CUniEditorAppUi::DoEnterKeyL()
       
  9611     {
       
  9612     TBool result( EFalse );
       
  9613     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  9614 
       
  9615     if ( ctrl )
       
  9616         {
       
  9617         switch ( ctrl->ControlId() )
       
  9618             {
       
  9619             case EMsgComponentIdAttachment:
       
  9620             case EMsgComponentIdImage:
       
  9621             case EMsgComponentIdVideo:
       
  9622             case EMsgComponentIdAudio:
       
  9623             case EMsgComponentIdSvg:
       
  9624                 {
       
  9625                 DoSelectionKeyL();
       
  9626                 result = ETrue;
       
  9627                 break;
       
  9628                 }
       
  9629             default:
       
  9630                 {
       
  9631                 break;
       
  9632                 }
       
  9633             }
       
  9634         }
       
  9635     
       
  9636     return result;
       
  9637     }
       
  9638 
       
  9639 // ---------------------------------------------------------
       
  9640 // CUniEditorAppUi::HandleNotifyInt
       
  9641 // ---------------------------------------------------------
       
  9642 //
       
  9643 void CUniEditorAppUi::HandleNotifyInt( TUint32 /*aId*/, TInt /*aNewValue*/ )
       
  9644     {
       
  9645     if( iNLTFeatureSupport )
       
  9646         {
       
  9647         //Turkish SMS-PREQ2265 specific
       
  9648         //Get the new lang id and corresponding alternative encoding if any
       
  9649         CUniEditorDocument *doc = Document();
       
  9650         TInt inputLang;
       
  9651               
       
  9652         //Update the setting cache, so that new language id is returned correctly
       
  9653         iAvkonEnv->SettingCache().Update(KEikInputLanguageChange);
       
  9654         inputLang = iAvkonEnv->SettingCache().InputLanguage();
       
  9655         iSettingsChanged = ETrue;
       
  9656         
       
  9657         TSmsEncoding alternateEncoding = doc->GetLanguageSpecificAltEncodingType(inputLang);
       
  9658         
       
  9659         doc->SetAlternativeEncodingType(alternateEncoding);
       
  9660         //Reset unicode mode to False and set the corresponding language alternative encoding type accordingly
       
  9661         if(doc->SmsPlugin())
       
  9662             {
       
  9663             doc->SmsPlugin()->SetEncodingSettings(EFalse, alternateEncoding, doc->CharSetSupport());
       
  9664             }        
       
  9665         }
       
  9666 	//TODO :: Should add check size and show note???
       
  9667     TRAP_IGNORE(
       
  9668         {
       
  9669         CheckSmsSizeAndUnicodeL();
       
  9670         MsgLengthToNavipaneL();
       
  9671         } );
       
  9672     }
       
  9673 
       
  9674 #ifdef RD_SCALABLE_UI_V2
       
  9675 // ---------------------------------------------------------
       
  9676 // CUniEditorAppUi::OnPeninputUiActivated
       
  9677 // ---------------------------------------------------------
       
  9678 // 
       
  9679 void CUniEditorAppUi::OnPeninputUiActivated()
       
  9680     {
       
  9681     TRAP_IGNORE( SmsMsgLenToPenInputL() );
       
  9682     }
       
  9683 
       
  9684 // ---------------------------------------------------------
       
  9685 // CUniEditorAppUi::OnPeninputUiDeactivated
       
  9686 // ---------------------------------------------------------
       
  9687 //
       
  9688 void CUniEditorAppUi::OnPeninputUiDeactivated()
       
  9689     {
       
  9690      if (AknLayoutUtils::PenEnabled() )
       
  9691         {
       
  9692            iPeninputServer.UpdateAppInfo( KNullDesC, EAppIndicatorMsg );    
       
  9693         }
       
  9694     }
       
  9695 #else
       
  9696 // ---------------------------------------------------------
       
  9697 // CUniEditorAppUi::OnPeninputUiActivated
       
  9698 // ---------------------------------------------------------
       
  9699 //
       
  9700 void CUniEditorAppUi::OnPeninputUiActivated()
       
  9701     {
       
  9702     }
       
  9703 
       
  9704 // ---------------------------------------------------------
       
  9705 // CUniEditorAppUi::OnPeninputUiDeactivated
       
  9706 // ---------------------------------------------------------
       
  9707 //
       
  9708 void CUniEditorAppUi::OnPeninputUiDeactivated()
       
  9709     {
       
  9710     }
       
  9711 #endif    
       
  9712 
       
  9713 // ---------------------------------------------------------
       
  9714 // CUniEditorAppUi::SmsMsgLenToPenInputL
       
  9715 // ---------------------------------------------------------
       
  9716 //
       
  9717 void CUniEditorAppUi::SmsMsgLenToPenInputL()
       
  9718     {
       
  9719     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  9720     CUniEditorDocument* doc = Document();
       
  9721            
       
  9722     if ( doc->UniState() == EUniSms && ctrl && iMsgLenToVKB)
       
  9723         {
       
  9724         if ( UpdateMsgLenToPenInput() )                      
       
  9725             {
       
  9726             MsgLengthToNavipaneL( ETrue );
       
  9727             }        
       
  9728         }
       
  9729     else
       
  9730         { 
       
  9731         if (AknLayoutUtils::PenEnabled() )
       
  9732             {
       
  9733             iPeninputServer.UpdateAppInfo( KNullDesC, EAppIndicatorMsg );    
       
  9734             }     
       
  9735         }        
       
  9736     }
       
  9737 TBool CUniEditorAppUi::UpdateMsgLenToPenInput()
       
  9738     {
       
  9739     CMsgBaseControl* ctrl = iView->FocusedControl();
       
  9740     if ( ctrl->ControlId() == EMsgComponentIdBody || 
       
  9741        ( ctrl->ControlId() == EMsgComponentIdSubject && iEditorFlags & ESubjectOkInSms ) )                      
       
  9742        {
       
  9743        return ETrue;
       
  9744        }
       
  9745     else
       
  9746        {
       
  9747        return EFalse;           
       
  9748        }
       
  9749         
       
  9750     }
       
  9751 
       
  9752 // ---------------------------------------------------------
       
  9753 // CUniEditorAppUi::ExitWithoutSave
       
  9754 //	Exits from the Unified Editor whne there is not sufficient memory to continue
       
  9755 // ---------------------------------------------------------
       
  9756 //
       
  9757 void CUniEditorAppUi::ExitWithoutSave()
       
  9758     {
       
  9759      DeactivateInputBlocker();
       
  9760      EndActiveWait();
       
  9761      RemoveWaitNote();
       
  9762      TRAP_IGNORE(ShowConfirmableInfoL( R_UNIEDITOR_NOT_ENOUGH_MEMORY));     
       
  9763      Exit( EAknSoftkeyClose );
       
  9764     }
       
  9765 // End of file
       
  9766