email/mail/EditorSrc/cmsgmailnavipaneutils.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Navi pane handling utilities
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Mail includes
       
    20 #include "cmsgmailnavipaneutils.h"
       
    21 #include <avkon.hrh>
       
    22 #include <aknenv.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <AknIndicatorContainer.h>
       
    25 #include <MsgAttachmentUtils.h>
       
    26 #include <AknIconUtils.h>
       
    27 #include <aknEditStateIndicator.h>
       
    28 #include <aknnavi.h>    // for CAknNavigationControlContainer
       
    29 #include <aknnavide.h>  // for CAknNavigationDecorator
       
    30 #include <avkon.mbg>
       
    31 
       
    32 // LOCAL CONSTANTS
       
    33 
       
    34 const TInt KMaxNaviMailSize(9999*1024); // largest size shown in navi pane
       
    35 const TInt KMaxNaviMailDigits(20); // some language variants require this
       
    36 								   // to be longer than 10, since they
       
    37 								   // write kB with more characters
       
    38 								   // this will cause overlapping in 
       
    39 								   // navi pane with priority 
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CMsgMailNaviPaneUtils::NewL()
       
    45 // Symbian two-phased constructor
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMsgMailNaviPaneUtils* CMsgMailNaviPaneUtils::NewL()
       
    49     {
       
    50     CMsgMailNaviPaneUtils* self = new( ELeave ) CMsgMailNaviPaneUtils();
       
    51     CleanupStack::PushL( self );
       
    52 	self->ConstructL();
       
    53 	CleanupStack::Pop(self); // self
       
    54     return self;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMsgMailNaviPaneUtils::CMsgMailNaviPaneUtils()
       
    59 // A default constructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMsgMailNaviPaneUtils::CMsgMailNaviPaneUtils()
       
    63     {
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CMsgMailNaviPaneUtils::ConstructL()
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CMsgMailNaviPaneUtils::ConstructL()
       
    71     {
       
    72     CEikStatusPane* statusPane =
       
    73         CEikonEnv::Static()->AppUiFactory()->StatusPane();					// CSI: 27 # Must be used because of iEikEnv 
       
    74 																			// is not accessible.
       
    75     ASSERT( statusPane );
       
    76     // We don't own iNaviPane. 
       
    77     iNaviPane = static_cast<CAknNavigationControlContainer*>(
       
    78         statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
    79     ASSERT( iNaviPane );
       
    80     // iNaviDecorator must be deleted in destructor. 
       
    81     iNaviDecorator = iNaviPane->CreateEditorIndicatorContainerL();
       
    82     ASSERT( iNaviDecorator );
       
    83     iNaviIndi = static_cast<CAknIndicatorContainer*>(
       
    84         iNaviDecorator->DecoratedControl() );
       
    85     ASSERT( iNaviIndi );
       
    86 
       
    87     // Address fields contain by default t9 and abc icons, and to avoid
       
    88     // other indicators changing position when our own navi pane is enabled or
       
    89     // disabled we will create invisible indicators.
       
    90     CreateInvisibleIndicatorL( EAknNaviPaneEditorIndicatorLowerCase );
       
    91     CreateInvisibleIndicatorL( EAknNaviPaneEditorIndicatorT9 );
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CMsgMailNaviPaneUtils::~CMsgMailNaviPaneUtils()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CMsgMailNaviPaneUtils::~CMsgMailNaviPaneUtils()
       
   100     {
       
   101     delete iNaviDecorator;    
       
   102     }
       
   103 
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CMsgMailNaviPaneUtils::SetPriorityIndicator()
       
   107 // if priority is EMsvMediumPriority then no indicator is shown
       
   108 // ----------------------------------------------------------------------------
       
   109 void CMsgMailNaviPaneUtils::SetPriorityIndicator( TMsvPriority aPriority )
       
   110 	{
       
   111     SetIndicatorState( EAknNaviPaneEditorIndicatorMcePriorityHigh,
       
   112         ( aPriority == EMsvHighPriority ) ? ETrue : EFalse );
       
   113 
       
   114     SetIndicatorState( EAknNaviPaneEditorIndicatorMcePriorityLow,
       
   115         ( aPriority == EMsvLowPriority ) ? ETrue : EFalse );
       
   116 	}
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // void CMsgMailNaviPaneUtils::SetMessageSizeIndicatorL()
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CMsgMailNaviPaneUtils::SetMessageSizeIndicatorL( TInt aSize )
       
   123     {
       
   124     TBuf<KMaxNaviMailDigits> sizeString;
       
   125     if ( aSize > KMaxNaviMailSize )
       
   126         {
       
   127         aSize = KMaxNaviMailSize;
       
   128         }
       
   129 
       
   130     MsgAttachmentUtils::FileSizeToStringL( sizeString, aSize, ETrue ); 
       
   131     
       
   132     SetIndicatorState( EAknNaviPaneEditorIndicatorMessageLength, ETrue );
       
   133     SetIndicatorValueL( EAknNaviPaneEditorIndicatorMessageLength, sizeString );
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // void CMsgMailNaviPaneUtils::SetAttachmentIndicator()
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CMsgMailNaviPaneUtils::SetAttachmentIndicator( TBool aHasAttachments )
       
   141     {
       
   142     SetIndicatorState( EAknNaviPaneEditorIndicatorAttachment, aHasAttachments );
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CMsgMailNaviPaneUtils::EnableOwnNaviPaneL
       
   147 // Enable or disable our own navi pane. 
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CMsgMailNaviPaneUtils::EnableOwnNaviPaneL( TBool aDoEnable )
       
   151     {
       
   152     if( aDoEnable )
       
   153         {
       
   154         // If iNaviDecorator already exists in window stack, 
       
   155         // it is put foremost. 
       
   156         iNaviPane->PushL( *iNaviDecorator );
       
   157         iNaviDecorator->MakeVisible( ETrue );
       
   158         }
       
   159     else
       
   160         {
       
   161         iNaviDecorator->MakeVisible( EFalse );
       
   162         }                
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CMsgMailNaviPaneUtils::SetIndicatorState
       
   167 // Sets indicator state on/off in both default and our own navi pane
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CMsgMailNaviPaneUtils::SetIndicatorState(
       
   171     TInt aIndicatorId,
       
   172     TBool aDoEnable )
       
   173     {    
       
   174     TInt state( aDoEnable ? EAknIndicatorStateOn : EAknIndicatorStateOff );
       
   175     TUid indicator( TUid::Uid( aIndicatorId ) );    
       
   176     
       
   177     // default navi pane
       
   178     MAknEditingStateIndicator* ind = AVKONENV->EditingStateIndicator();
       
   179     if ( ind )
       
   180         {        
       
   181         CAknIndicatorContainer* defaultNaviIndi = ind->IndicatorContainer();    
       
   182         ASSERT( defaultNaviIndi );
       
   183         defaultNaviIndi->SetIndicatorState( indicator, state );
       
   184         }
       
   185         
       
   186     // our own navi pane
       
   187     iNaviIndi->SetIndicatorState( indicator, state );    
       
   188     }
       
   189     
       
   190 // ---------------------------------------------------------------------------
       
   191 // CMsgMailNaviPaneUtils::SetIndicatorValueL
       
   192 // Sets indicator value in both default and our own navi pane
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CMsgMailNaviPaneUtils::SetIndicatorValueL(
       
   196     TInt aIndicatorId,
       
   197     const TDesC& aString )
       
   198     {    
       
   199     TUid indicator( TUid::Uid( aIndicatorId ) );
       
   200     
       
   201     // default navi pane
       
   202     MAknEditingStateIndicator* ind = AVKONENV->EditingStateIndicator();
       
   203     if ( ind )
       
   204         {        
       
   205         CAknIndicatorContainer* defaultNaviIndi = ind->IndicatorContainer();    
       
   206         ASSERT( defaultNaviIndi );
       
   207         defaultNaviIndi->SetIndicatorValueL( indicator, aString );
       
   208         }
       
   209         
       
   210     // our own navi pane
       
   211     iNaviIndi->SetIndicatorValueL( indicator, aString );
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // CMsgMailNaviPaneUtils::CreateInvisibleIndicatorL
       
   216 // We add invisible "abc" and t9 icons to our navi pane so that email priority
       
   217 // icon won't change it's place horizontally when focus is moved to/from 
       
   218 // attachment field. This is quite ugly, but avkon doesn't provide support for
       
   219 // keeping indicator in fixed location.
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CMsgMailNaviPaneUtils::CreateInvisibleIndicatorL( TInt aIndicatorId )
       
   223     {
       
   224     // 1. Turn indicator on   
       
   225     
       
   226     SetIndicatorState( aIndicatorId, ETrue );
       
   227     
       
   228     // 2. Make icon invisible
       
   229                     
       
   230     CFbsBitmap* bitmap( NULL );
       
   231     // Get bitmap for "abc" icon
       
   232     CreateIconLC( aIndicatorId, bitmap );
       
   233                
       
   234     // We cannot use CFbsBitmap::SizeInPixels() since it is zero due
       
   235     // to icon scalability. To get a size for our empty mask we query
       
   236     // content dimensions. All scaling and sizing of actual indicators
       
   237     // will be taken care by CAknIndicatorContainer
       
   238     TSize size;        
       
   239     User::LeaveIfError( AknIconUtils::GetContentDimensions( bitmap,
       
   240                                                             size ) );        
       
   241     CFbsBitmap* emptyMask = new (ELeave) CFbsBitmap();
       
   242     CleanupStack::PushL( emptyMask );
       
   243     User::LeaveIfError( emptyMask->Create( size, EGray2 ) );
       
   244 
       
   245     // Ownership of bitmap and newMask is transferred to iNaviIndi. 
       
   246     iNaviIndi->ReplaceIndicatorIconL( TUid::Uid( aIndicatorId ),
       
   247                                       EAknIndicatorStateOn, 
       
   248                                       CAknIndicatorContainer::ELayoutModeWide,
       
   249                                       bitmap,
       
   250                                       emptyMask );
       
   251     CleanupStack::Pop( 2, bitmap );						// CSI: 47,12 # emptyMask, bitmap
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CMsgMailNaviPaneUtils::CreateIconLC
       
   256 //
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CMsgMailNaviPaneUtils::CreateIconLC(
       
   260     TInt aIndicatorId,
       
   261     CFbsBitmap*& aBitmap ) const
       
   262     {
       
   263     TAknsItemID skinId;
       
   264     TInt bitmapId;
       
   265     TInt maskId; // dummy    
       
   266     GetIconIds( aIndicatorId, skinId, bitmapId, maskId );
       
   267     MAknsSkinInstance *skin = AknsUtils::SkinInstance();    
       
   268     AknsUtils::CreateIconLC( skin,
       
   269                              skinId,
       
   270                              aBitmap,
       
   271                              AknIconUtils::AvkonIconFileName(),
       
   272                              bitmapId );    
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CMsgMailNaviPaneUtils::GetIconIds
       
   277 //
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CMsgMailNaviPaneUtils::GetIconIds(
       
   281     TInt aIndicatorId,
       
   282     TAknsItemID& aSkinId,
       
   283     TInt& aFileBitmapId,
       
   284     TInt& aFileMaskId ) const
       
   285     {
       
   286     switch ( aIndicatorId )
       
   287         {
       
   288         case EAknNaviPaneEditorIndicatorLowerCase:
       
   289             {
       
   290             aSkinId = KAknsIIDQgnStatCaseSmall;
       
   291             aFileBitmapId = EMbmAvkonQgn_stat_case_small;
       
   292             aFileMaskId = EMbmAvkonQgn_stat_case_small_mask;
       
   293             break;
       
   294             }
       
   295         case EAknNaviPaneEditorIndicatorT9:
       
   296             {
       
   297             aSkinId = KAknsIIDQgnStatT9;
       
   298             aFileBitmapId = EMbmAvkonQgn_stat_t9;
       
   299             aFileMaskId = EMbmAvkonQgn_stat_t9_mask;
       
   300             break;
       
   301             }            
       
   302         default:
       
   303             {
       
   304             // do nothing
       
   305             }
       
   306         }
       
   307     }
       
   308 
       
   309 // End of File