emailuis/emailui/src/ncsutility.cpp
changeset 0 8466d47a6819
child 2 5253a20d2a1e
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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: utility class definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "emailtrace.h"
       
    22 #include <StringLoader.h>
       
    23 #include <AknUtils.h>
       
    24 //<cmail>
       
    25 #include <AknsUtils.h>
       
    26 #include <AknsSkinInstance.h>
       
    27 #include <aknbutton.h>
       
    28 #include <eikedwin.h>
       
    29 //</cmail>
       
    30 #include <FreestyleEmailUi.rsg>
       
    31 #include <RPbkViewResourceFile.h>
       
    32 #include <CPbkContactEngine.h>
       
    33 #include <CPbkMultipleEntryFetchDlg.h>
       
    34 #include <CPbkContactItem.h>
       
    35 #include <AknIconUtils.h>
       
    36 #include <eikimage.h>
       
    37 #include <fbs.h>
       
    38 #include <flogger.h>
       
    39 #include <aknenv.h>	// CAknEnv
       
    40 //<cmail>
       
    41 #include "CFSMailBox.h"
       
    42 #include "CFSMailClient.h"
       
    43 #include "CFSMailAddress.h"
       
    44 //</cmail>
       
    45 
       
    46 //<cmail> Platform layout changes
       
    47 #include <aknlayoutscalable_apps.cdl.h>
       
    48 #include <layoutmetadata.cdl.h>
       
    49 #include <AknLayoutFont.h>
       
    50 //</cmail> Platform layout changes
       
    51 
       
    52 #include "ncsutility.h"
       
    53 #include "ncsemailaddressobject.h"
       
    54 #include "ncsconstants.h"
       
    55 #include "FSDelayedLoader.h"
       
    56 #include "FreestyleEmailUiUtilities.h"
       
    57 #include "FreestyleEmailUiLayoutData.h"
       
    58 
       
    59 //<cmail>
       
    60 // CONSTANTS
       
    61 const TInt KFSUtilityMinColorValue = 0;
       
    62 const TInt KFSUtilityMaxColorValue = 255;
       
    63 const TInt KFSUtilityThresholdColorValue = 200;
       
    64 const TInt KFSUtilityThresholdColorMiddleValue = 127;
       
    65 //</cmail>
       
    66 
       
    67 // ========================= MEMBER FUNCTIONS ==================================
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // NcsUtility::CompleteRelativePathL()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void NcsUtility::CompleteRelativePathL( const TDesC& aRelativePath, TPtr& aAbsolutePath )
       
    75 	{
       
    76     FUNC_LOG;
       
    77 
       
    78 	// + 2 is for drive letter and ":"
       
    79 	if( aAbsolutePath.MaxLength() < aRelativePath.Length() + 2 )
       
    80 		{
       
    81 		User::Leave( KErrArgument );
       
    82 		}
       
    83 
       
    84 	TFileName path;
       
    85   	path.Copy( aRelativePath );
       
    86 	TInt err = CompleteWithAppPath( path );
       
    87 	User::LeaveIfError( err );
       
    88 
       
    89 	aAbsolutePath.Copy( path );
       
    90 
       
    91 	}
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // NcsUtility::GenerateFromLineToMessageBodyL()
       
    95 //
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 HBufC* NcsUtility::GenerateFromLineToMessageBodyL( const RPointerArray<CNcsEmailAddressObject>& aFromArray )
       
    99 	{
       
   100     FUNC_LOG;
       
   101 
       
   102     HBufC* buf = DoGenerateAddressLineToMessageBodyL( R_NCS_ENGINE_EMAIL_FROM, aFromArray );
       
   103 
       
   104 	return buf;
       
   105 	}
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // NcsUtility::GenerateSentLineToMessageBodyL()
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 HBufC* NcsUtility::GenerateSentLineToMessageBodyL( CFSMailMessage& aMessage )
       
   113 	{
       
   114     FUNC_LOG;
       
   115 
       
   116 	HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &aMessage );
       
   117 	HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &aMessage );
       
   118 	HBufC* sent = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_SENT );
       
   119 
       
   120 	HBufC* buf = HBufC::NewL( sent->Length() +
       
   121                               KSpace().Length() +
       
   122 	                          dateText->Length() +
       
   123 	                          KSentLineDateAndTimeSeparatorText().Length() +
       
   124 	                          timeText->Length() );
       
   125 	TPtr ptr = buf->Des();
       
   126 	ptr.Append( *sent );
       
   127 	ptr.Append( KSpace );
       
   128 	ptr.Append( *dateText );
       
   129 	ptr.Append( KSentLineDateAndTimeSeparatorText );
       
   130 	ptr.Append( *timeText );
       
   131 
       
   132 	CleanupStack::PopAndDestroy( sent );
       
   133 	CleanupStack::PopAndDestroy( timeText );
       
   134 	CleanupStack::PopAndDestroy( dateText );
       
   135 
       
   136 	return buf;
       
   137 	}
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // NcsUtility::GenerateAddressLineToMessageBodyL()
       
   141 //
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 HBufC* NcsUtility::GenerateAddressLineToMessageBodyL(
       
   145 	RPointerArray<CNcsEmailAddressObject>& aToArray, TRecipientType aType )
       
   146 	{
       
   147     FUNC_LOG;
       
   148 
       
   149 	// figure out the recipient type dependent text
       
   150     TInt labelResource = R_NCS_ENGINE_EMAIL_TO;
       
   151     if ( aType == ERecipientTypeCc )
       
   152         {
       
   153         labelResource = R_NCS_ENGINE_EMAIL_CC;
       
   154         }
       
   155 
       
   156     HBufC* buf = DoGenerateAddressLineToMessageBodyL( labelResource, aToArray );
       
   157 
       
   158     return buf;
       
   159 	}
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // NcsUtility::DoGenerateAddressLineToMessageBodyL()
       
   163 //
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 HBufC* NcsUtility::DoGenerateAddressLineToMessageBodyL( TInt aLabelResourceId,
       
   167         const RPointerArray<CNcsEmailAddressObject>& aAddressArray )
       
   168     {
       
   169     FUNC_LOG;
       
   170 
       
   171     // load label string (e.g. "From:", "To:", "Cc:")
       
   172     HBufC* label = StringLoader::LoadLC( aLabelResourceId );
       
   173 
       
   174     // calculate how large buffer do we need for the whole line
       
   175     TInt bufLength = label->Length();
       
   176     TInt count = aAddressArray.Count();
       
   177     for ( TInt i = 0; i < count; i++ )
       
   178         {
       
   179         CNcsEmailAddressObject* obj = aAddressArray[i];
       
   180         const TDesC& dispName = obj->DisplayName();
       
   181         // use display name if it is available, otherwise email address
       
   182         if ( dispName.Length() > 0 )
       
   183             {
       
   184             bufLength += dispName.Length();
       
   185             }
       
   186         else
       
   187             {
       
   188             bufLength += obj->EmailAddress().Length();
       
   189             }
       
   190         if ( i < ( count - 1 ) )
       
   191             {
       
   192             bufLength += KEmailAddressSeparator().Length();
       
   193             bufLength += KSpace().Length();
       
   194             }
       
   195         }
       
   196 
       
   197     // allocate buffer to contain the whole text
       
   198     HBufC* buf = HBufC::NewL( bufLength );
       
   199     TPtr ptr = buf->Des();
       
   200 
       
   201     // add label
       
   202     ptr.Append( *label );
       
   203     CleanupStack::PopAndDestroy( label );
       
   204 
       
   205     // append each address into our text buffer
       
   206     for ( TInt i = 0; i < count; i++ )
       
   207         {
       
   208         CNcsEmailAddressObject* obj = aAddressArray[i];
       
   209         const TDesC& dispName = obj->DisplayName();
       
   210         // use display name if it is available, otherwise email address
       
   211         if ( dispName.Length() > 0 )
       
   212             {
       
   213             ptr.Append( dispName );
       
   214             }
       
   215         else
       
   216             {
       
   217             ptr.Append( obj->EmailAddress() );
       
   218             }
       
   219         if ( i < ( count - 1 ) )
       
   220             {
       
   221             ptr.Append( KEmailAddressSeparator );
       
   222             ptr.Append( KSpace );
       
   223             }
       
   224         }
       
   225 
       
   226     return buf;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // NcsUtility::GenerateSubjectLineToMessageBodyL()
       
   231 //
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 HBufC* NcsUtility::GenerateSubjectLineToMessageBodyL( const TDesC& aSubject )
       
   235 	{
       
   236     FUNC_LOG;
       
   237 
       
   238 	// load "Subject:" string
       
   239 	HBufC* subjectLabel = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_SUBJECT );
       
   240 
       
   241 	// allocate buffer for the text
       
   242 	HBufC* buf = HBufC::NewL( subjectLabel->Length() + aSubject.Length() );
       
   243     TPtr ptr = buf->Des();
       
   244     ptr.Append( *subjectLabel );
       
   245     ptr.Append( aSubject );
       
   246 
       
   247     CleanupStack::PopAndDestroy( subjectLabel );
       
   248 
       
   249 	return buf;
       
   250 	}
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // NcsUtility::CreateNcsAddressL()
       
   254 //
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 CNcsEmailAddressObject* NcsUtility::CreateNcsAddressL( const CFSMailAddress& aFsAddress )
       
   258 	{
       
   259     FUNC_LOG;
       
   260 
       
   261 	CNcsEmailAddressObject* address = CNcsEmailAddressObject::NewL( ETrue );
       
   262 	CleanupStack::PushL( address );
       
   263 	// temporary ugly code because email API can return references to null
       
   264 	TDesC& a = aFsAddress.GetEmailAddress();
       
   265 	if ( &a )
       
   266 		{
       
   267 		address->SetEmailAddressL( a );
       
   268 		}
       
   269 	TDesC& name = aFsAddress.GetDisplayName();
       
   270 	if ( &name )
       
   271 		{
       
   272 		address->SetDisplayNameL( name );
       
   273 		}
       
   274 
       
   275 	CleanupStack::Pop( address );
       
   276 
       
   277 	return address;
       
   278 	}
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // NcsUtility::CreateFsAddressL()
       
   282 // Caller takes the ownership of the returned address object
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 CFSMailAddress* NcsUtility::CreateFsAddressL( const CNcsEmailAddressObject& aNcsAddress )
       
   286 	{
       
   287     FUNC_LOG;
       
   288 
       
   289 	CFSMailAddress* address = CFSMailAddress::NewL();
       
   290 	address->SetEmailAddress( aNcsAddress.EmailAddress() );
       
   291 	address->SetDisplayName( aNcsAddress.DisplayName() );
       
   292 
       
   293 	return address;
       
   294 	}
       
   295 
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // NcsUtility::FormatSubjectLineL()
       
   299 //
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 HBufC* NcsUtility::FormatSubjectLineL( const TDesC& aNewSubjectLine, const TDesC& aPrefix )
       
   303 	{
       
   304     FUNC_LOG;
       
   305 
       
   306 	HBufC* formattedSubjectLine = aNewSubjectLine.AllocLC();
       
   307 	HBufC* prefix = aPrefix.AllocLC();
       
   308 
       
   309 	TPtr formattedSubjectLinePtr = formattedSubjectLine->Des();
       
   310 	TPtr prefixPtr = prefix->Des();
       
   311 	prefixPtr.Trim();
       
   312 
       
   313 	TInt subjectLineLength = formattedSubjectLinePtr.Length();
       
   314 	TInt index = 0;
       
   315 	TInt length = subjectLineLength;
       
   316 	TInt prefixLength = prefixPtr.Length();
       
   317 
       
   318 	do
       
   319 		{
       
   320 		formattedSubjectLinePtr = formattedSubjectLinePtr.RightTPtr( length );
       
   321 		index = formattedSubjectLinePtr.FindC( prefixPtr );
       
   322 		length = formattedSubjectLinePtr.Length() - index - prefixLength;
       
   323 		}
       
   324 	while( index != KErrNotFound );
       
   325 
       
   326 	formattedSubjectLinePtr.Trim();
       
   327 
       
   328 	HBufC* finalSubject = HBufC::NewL( formattedSubjectLinePtr.Length() + prefixPtr.Length() + KSpace().Length() );
       
   329 	TPtr ptr = finalSubject->Des();
       
   330 	if ( AknLayoutUtils::LayoutMirrored() )
       
   331 		{
       
   332 		ptr.Append( formattedSubjectLinePtr );
       
   333 		ptr.Append( KSpace );
       
   334 		ptr.Append( prefixPtr );		
       
   335 		}
       
   336 	else
       
   337 		{
       
   338 		ptr.Append( prefixPtr );
       
   339 		ptr.Append( KSpace );
       
   340 		ptr.Append( formattedSubjectLinePtr );
       
   341 		}
       
   342 
       
   343 	CleanupStack::PopAndDestroy( prefix );
       
   344 	CleanupStack::PopAndDestroy( formattedSubjectLine );
       
   345 
       
   346 	return finalSubject;
       
   347 	}
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // NcsUtility::ConvertAddressArrayL()
       
   351 //
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 void NcsUtility::ConvertAddressArrayL( const RPointerArray<CFSMailAddress>& aSrc, RPointerArray<CNcsEmailAddressObject>& aDst )
       
   355 	{
       
   356     FUNC_LOG;
       
   357 
       
   358  	for ( TInt i=0; i<aSrc.Count(); i++ )
       
   359  		{
       
   360 		CNcsEmailAddressObject* ncsRecipient = NcsUtility::CreateNcsAddressL( *aSrc[i] );
       
   361 		CleanupStack::PushL( ncsRecipient );
       
   362 		aDst.AppendL( ncsRecipient );
       
   363 		CleanupStack::Pop( ncsRecipient );
       
   364  		}
       
   365 
       
   366 	}
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // NcsUtility::ConvertAddressArrayL()
       
   370 // Caller takes the ownership of address objects pointoed in the array aDst.
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void NcsUtility::ConvertAddressArrayL( const RPointerArray<CNcsEmailAddressObject>& aSrc, RPointerArray<CFSMailAddress>& aDst )
       
   374 	{
       
   375     FUNC_LOG;
       
   376 
       
   377  	for ( TInt i=0; i<aSrc.Count(); i++ )
       
   378  		{
       
   379 		CFSMailAddress* fsRecipient = NcsUtility::CreateFsAddressL( *aSrc[i] );
       
   380 		CleanupStack::PushL( fsRecipient );
       
   381 		aDst.AppendL( fsRecipient );
       
   382 		CleanupStack::Pop( fsRecipient );
       
   383  		}
       
   384 
       
   385 	}
       
   386 
       
   387 
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // NcsUtility::LoadScalableIconL()
       
   391 //
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void NcsUtility::LoadScalableIconL( const TDesC& aMifRelativeFileName, TInt aImgId, TInt aMaskId, CEikImage*& aIcon, CFbsBitmap*& aImage, CFbsBitmap*& aMask )
       
   395     {
       
   396     FUNC_LOG;
       
   397 
       
   398 	HBufC* buf = HBufC::NewLC( KMaxFileName );
       
   399 	TPtr ptr = buf->Des();
       
   400 	NcsUtility::CompleteRelativePathL( aMifRelativeFileName, ptr );
       
   401 
       
   402     AknIconUtils::CreateIconL( aImage,
       
   403                                aMask,
       
   404                                ptr,
       
   405 	                           aImgId,
       
   406 	                           aMaskId );
       
   407 
       
   408     TSize size;
       
   409     AknIconUtils::GetContentDimensions( aImage, size );
       
   410     AknIconUtils::SetSize( aImage, size );
       
   411 
       
   412     aIcon = new ( ELeave ) CEikImage;
       
   413     aIcon->SetNewBitmaps( aImage, aMask );
       
   414     aIcon->SetPictureOwnedExternally( ETrue );
       
   415 
       
   416 	CleanupStack::PopAndDestroy( buf );
       
   417 
       
   418     }
       
   419 
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // NcsUtility::DebugLog
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 void NcsUtility::DebugLog( TRefByValue<const TDesC> aFmt, ... )
       
   426     {
       
   427     FUNC_LOG;
       
   428     _LIT( KDebugDir, "FreestyleEmailUi" );
       
   429     _LIT( KDebugLog, "log.txt" );
       
   430 
       
   431     VA_LIST args;
       
   432     VA_START( args, aFmt );
       
   433     RFileLogger::WriteFormat( KDebugDir,
       
   434                               KDebugLog,
       
   435                               EFileLoggingModeAppend,
       
   436                               aFmt,
       
   437                               args );
       
   438     VA_END( args );
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // NcsUtility::IsEqualAddressArray
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 TBool NcsUtility::IsEqualAddressArray( const RPointerArray<CFSMailAddress>& aAddresses1,
       
   446                                         const RPointerArray<CFSMailAddress>& aAddresses2 )
       
   447 	{
       
   448     FUNC_LOG;
       
   449 
       
   450 	if ( aAddresses1.Count() != aAddresses2.Count() )
       
   451 		{
       
   452 		return EFalse;
       
   453 		}
       
   454     for ( TInt i=0; i<aAddresses1.Count(); i++ )
       
   455     	{
       
   456     	if ( aAddresses1[i]->GetEmailAddress().Compare( aAddresses2[i]->GetEmailAddress() ) != 0 )
       
   457     		{
       
   458     		return EFalse;
       
   459     		}
       
   460     	if ( aAddresses1[i]->GetDisplayName().Compare( aAddresses2[i]->GetDisplayName() ) != 0 )
       
   461     		{
       
   462     		return EFalse;
       
   463     		}
       
   464     	}
       
   465 
       
   466     return ETrue;
       
   467 	}
       
   468 
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // NcsUtility::Measures
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 TNcsMeasures NcsUtility::Measures()
       
   475 	{
       
   476     FUNC_LOG;
       
   477 
       
   478 	TNcsMeasures ms;
       
   479 
       
   480 	TAknUiZoom zoomLevel = EAknUiZoomNormal;
       
   481 	CAknEnv::Static()->GetCurrentGlobalUiZoom( zoomLevel );
       
   482 	switch ( zoomLevel )
       
   483 		{
       
   484 		case EAknUiZoomNormal: case EAknUiZoomAutomatic:
       
   485 			{
       
   486 			ms.iAifHeight = KAifHeight;
       
   487 			ms.iAifLabelMarginVertical = KAifLabelMarginVertical;
       
   488 			ms.iAifEditorMarginVertical = KAifEditorMarginVertical;
       
   489 			ms.iAifEditorHeight = KAifEditorHeight;
       
   490 			ms.iSubjectExtraHeightBottom = KSubjectExtraHeightBottom;
       
   491 			ms.iAttachmentExtraHeightBottom = KAttachmentExtraHeightBottom;
       
   492 			ms.iIconMarginPriorityVertical = KIconMarginPriorityVertical;
       
   493 			ms.iIconMarginFollowUpVertical = KIconMarginFollowUpVertical;
       
   494             ms.iIconMarginAttachmentVertical = KIconMarginAttachmentVertical;
       
   495 			ms.iLabelFontHeightPx = KLabelFontHeightPx;
       
   496 			ms.iEditorFontHeightPx = KEditorFontHeightPx;
       
   497 			}
       
   498             break;
       
   499 		case EAknUiZoomSmall: case EAknUiZoomVerySmall:
       
   500 			{
       
   501 			ms.iAifHeight = KAifHeightSmall;
       
   502 			ms.iAifLabelMarginVertical = KAifLabelMarginVerticalSmall;
       
   503 			ms.iAifEditorMarginVertical = KAifEditorMarginVerticalSmall;
       
   504 			ms.iAifEditorHeight = KAifEditorHeightSmall;
       
   505 			ms.iSubjectExtraHeightBottom = KSubjectExtraHeightBottomSmall;
       
   506 			ms.iAttachmentExtraHeightBottom = KAttachmentExtraHeightBottomSmall;
       
   507 			ms.iIconMarginPriorityVertical = KIconMarginPriorityVerticalSmall;
       
   508 			ms.iIconMarginFollowUpVertical = KIconMarginFollowUpVerticalSmall;
       
   509             ms.iIconMarginAttachmentVertical = KIconMarginAttachmentVerticalSmall;
       
   510 			ms.iLabelFontHeightPx = KLabelFontHeightPxSmall;
       
   511 			ms.iEditorFontHeightPx = KEditorFontHeightPxSmall;
       
   512 			}
       
   513             break;
       
   514 		case EAknUiZoomLarge: case EAknUiZoomVeryLarge:
       
   515 			{
       
   516 			ms.iAifHeight = KAifHeightLarge;
       
   517 			ms.iAifLabelMarginVertical = KAifLabelMarginVerticalLarge;
       
   518 			ms.iAifEditorMarginVertical = KAifEditorMarginVerticalLarge;
       
   519 			ms.iAifEditorHeight = KAifEditorHeightLarge;
       
   520 			ms.iSubjectExtraHeightBottom = KSubjectExtraHeightBottomLarge;
       
   521 			ms.iAttachmentExtraHeightBottom = KAttachmentExtraHeightBottomLarge;
       
   522 			ms.iIconMarginPriorityVertical = KIconMarginPriorityVerticalLarge;
       
   523 			ms.iIconMarginFollowUpVertical = KIconMarginFollowUpVerticalLarge;
       
   524             ms.iIconMarginAttachmentVertical = KIconMarginAttachmentVerticalLarge;
       
   525 			ms.iLabelFontHeightPx = KLabelFontHeightPxLarge;
       
   526 			ms.iEditorFontHeightPx = KEditorFontHeightPxLarge;
       
   527 			}
       
   528             break;
       
   529 		}
       
   530 
       
   531 	return ms;
       
   532 	}
       
   533 
       
   534 // -----------------------------------------------------------------------------
       
   535 // NcsUtility::GetNearestFontL
       
   536 // -----------------------------------------------------------------------------
       
   537 //
       
   538 CFont* NcsUtility::GetNearestFontL( TInt aLogicalFontId, TInt aHeightPixels )
       
   539 	{
       
   540     FUNC_LOG;
       
   541 
       
   542 	// Base the font on logical font passed to us
       
   543 	const CFont* logicalFont = AknLayoutUtils::FontFromId( aLogicalFontId );
       
   544 	// Note: This font is owned by the application's system font array (where it
       
   545 	// is likely already to have been created) and does not need to be
       
   546 	// released. It can just go out of scope.
       
   547 
       
   548 	// Extract font information
       
   549 	TFontSpec fontSpec = logicalFont->FontSpecInTwips();
       
   550 
       
   551 	// Desired height, weight, and posture
       
   552 	CWsScreenDevice& screenDev = *( CEikonEnv::Static()->ScreenDevice() );
       
   553 	fontSpec.iHeight = screenDev.VerticalPixelsToTwips( aHeightPixels );
       
   554 	fontSpec.iFontStyle.SetStrokeWeight( EStrokeWeightNormal );
       
   555 	fontSpec.iFontStyle.SetPosture( EPostureUpright );
       
   556 
       
   557 	// Obtain new font
       
   558 	CFont* font;
       
   559 
       
   560 	TInt err = screenDev.GetNearestFontInTwips( font, fontSpec );
       
   561 	User::LeaveIfError( err );
       
   562 
       
   563 	return font;
       
   564 	// Font is now usable. Must be released before application
       
   565 	// exit using CWsScreenDevice::ReleaseFont()
       
   566 	}
       
   567 
       
   568 // <cmail> Platform layout change
       
   569 // -----------------------------------------------------------------------------
       
   570 // NcsUtility::GetLayoutFont
       
   571 // -----------------------------------------------------------------------------
       
   572 //
       
   573 const CFont* NcsUtility::GetLayoutFont(const TRect& aParent, TNcsLayoutFont aUsage )
       
   574     {
       
   575     FUNC_LOG;
       
   576     TAknLayoutText layoutText;
       
   577     switch (aUsage)
       
   578         {
       
   579         case ENcsHeaderCaptionFont:
       
   580             {
       
   581             layoutText.LayoutText(aParent, AknLayoutScalable_Apps::list_single_cmail_header_caption_pane_t1());
       
   582             break;
       
   583             }
       
   584         case ENcsHeaderDetailFont:
       
   585             {
       
   586             layoutText.LayoutText(aParent, AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t1(0));
       
   587             break;
       
   588             }
       
   589         case ENcsBodytextFont:
       
   590             {
       
   591             layoutText.LayoutText(aParent, AknLayoutScalable_Apps::list_cmail_body_pane_t1());
       
   592             break;
       
   593             }
       
   594         }
       
   595     return layoutText.Font();
       
   596     }
       
   597 // </cmail>
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // NcsUtility::IsEditReplyForwardQuoteSupported
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 TBool NcsUtility::IsReplyForwardQuoteReadOnly( const CFSMailBox& aMailBox )
       
   604     {
       
   605     FUNC_LOG;
       
   606     TBool r = aMailBox.HasCapability( EFSMBoxCapaReadOnlySmartQuote );
       
   607     return r;
       
   608     }
       
   609 
       
   610 // -----------------------------------------------------------------------------
       
   611 // NcsUtility::FindFirstPrintableCharIndex
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 TInt NcsUtility::FindFirstPrintableCharIndex( const TDesC& aText )
       
   615     {
       
   616     FUNC_LOG;
       
   617     for ( TInt i=0; i<aText.Length(); i++ )
       
   618         {
       
   619         TChar c = aText[i];
       
   620         if ( c.IsGraph() )
       
   621             {
       
   622             return i;
       
   623             }
       
   624         else
       
   625             {
       
   626             continue;
       
   627             }
       
   628         }
       
   629     return KErrNotFound;
       
   630     }
       
   631 
       
   632 // -----------------------------------------------------------------------------
       
   633 // NcsUtility::ConvertCharacters
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 void NcsUtility::ConvertCharacters( TDes& aBuffer, TUint16 aFrom, TUint16 aTo )
       
   637     {
       
   638     FUNC_LOG;
       
   639     for ( TInt i=0; i<aBuffer.Length(); i++ )
       
   640         {
       
   641         if ( aBuffer[i] == aFrom )
       
   642             {
       
   643             aBuffer[i] = aTo;
       
   644             }
       
   645         }
       
   646     }
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // NcsUtility::ConvertLineEndingsL
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 void NcsUtility::ConvertLineEndingsL( HBufC*& aBuffer )
       
   653     {
       
   654     FUNC_LOG;
       
   655     // find line ending positions
       
   656     RArray<TInt> positions;
       
   657     CleanupClosePushL( positions );
       
   658     for ( TInt i=0; i<aBuffer->Length(); i++ )
       
   659         {
       
   660         if ( (*aBuffer)[i] == (TInt32)CEditableText::EParagraphDelimiter )
       
   661             {
       
   662             positions.Append( i );
       
   663             }
       
   664         }
       
   665 
       
   666     // case when there are no line endings can be early exited
       
   667     if ( positions.Count() <= 0 )
       
   668         {
       
   669         CleanupStack::PopAndDestroy( &positions );
       
   670         return;
       
   671         }
       
   672 
       
   673     // we need to do the conversion
       
   674     // initialize
       
   675     const TChar KCR = 0x0D;
       
   676     const TChar KLF = 0x0A;
       
   677     TInt startPos = 0;
       
   678     TInt length = 0;
       
   679 
       
   680     // create destination buffer
       
   681     HBufC* newBuffer = HBufC::NewL( aBuffer->Length() + positions.Count() * 2 );
       
   682     TPtr dstPtr = newBuffer->Des();
       
   683 
       
   684     // do the conversion
       
   685     for ( TInt i=0; i<positions.Count(); i++ )
       
   686         {
       
   687         // copy text, no line ending
       
   688         length = positions[i] - startPos;
       
   689         TPtrC16 srcPtr = aBuffer->Mid( startPos, length );
       
   690         dstPtr.Append( srcPtr );
       
   691         startPos = positions[i] + 1;
       
   692         // append line ending
       
   693         dstPtr.Append( KCR );
       
   694         dstPtr.Append( KLF );
       
   695         }
       
   696     // handle the text piece after last line ending if there is such
       
   697     const TInt lastPos = positions[ positions.Count() - 1 ];
       
   698     const TInt high = aBuffer->Length() - 1;
       
   699     if ( lastPos < high )
       
   700         {
       
   701         const TInt start = lastPos + 1;
       
   702         TPtrC16 srcPtr = aBuffer->Mid( start, aBuffer->Length() - start );
       
   703         dstPtr.Append( srcPtr );
       
   704         }
       
   705     // delete old buffer and give pointer to new one
       
   706     delete aBuffer;
       
   707     aBuffer = newBuffer;
       
   708     CleanupStack::PopAndDestroy( &positions );
       
   709     }
       
   710 
       
   711  // -----------------------------------------------------------------------------
       
   712 // NcsUtility::DeleteMessage
       
   713 // -----------------------------------------------------------------------------
       
   714 //
       
   715 TInt NcsUtility::DeleteMessage( CFSMailClient& aMailClient,
       
   716 		const TFSMailMsgId& aMailBoxId,
       
   717 		const TFSMailMsgId& aFolderId,
       
   718 		const TFSMailMsgId& aMsgId )
       
   719     {
       
   720     FUNC_LOG;
       
   721     RArray<TFSMailMsgId> msgIds;
       
   722     TInt error = msgIds.Append( aMsgId );
       
   723     if ( error == KErrNone )
       
   724         {
       
   725         TRAP( error, aMailClient.DeleteMessagesByUidL( aMailBoxId, aFolderId,
       
   726             msgIds ) );
       
   727         }
       
   728     msgIds.Close();
       
   729     return error;
       
   730     }
       
   731 
       
   732 // <cmail> Platform layout changes
       
   733 // -----------------------------------------------------------------------------
       
   734 // NcsUtility::HeaderCaptionPaneRect
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 TRect NcsUtility::HeaderCaptionPaneRect( const TRect& aParent )
       
   738     {
       
   739 	FUNC_LOG;
       
   740     TAknLayoutRect headerCaptionPaneRect;
       
   741     headerCaptionPaneRect.LayoutRect( aParent, AknLayoutScalable_Apps::list_single_cmail_header_caption_pane() );
       
   742     return headerCaptionPaneRect.Rect();
       
   743     }
       
   744 
       
   745 // -----------------------------------------------------------------------------
       
   746 // NcsUtility::HeaderDetailPaneRect
       
   747 // -----------------------------------------------------------------------------
       
   748 //
       
   749 TRect NcsUtility::HeaderDetailPaneRect( const TRect& aParent, const TInt aRows, TBool aSameRow )
       
   750     {
       
   751     FUNC_LOG;
       
   752     const TInt variety( aRows == 1 ? 0 : 1 );
       
   753     TAknLayoutRect headerDetailPaneRect;
       
   754     headerDetailPaneRect.LayoutRect( aParent, AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( variety ) );
       
   755     TRect result( headerDetailPaneRect.Rect() );
       
   756     if (!aSameRow)
       
   757         {
       
   758         result.Move( 0, HeaderCaptionPaneRect( aParent ).Height() );
       
   759         }
       
   760     return result;
       
   761     }
       
   762 
       
   763 // -----------------------------------------------------------------------------
       
   764 // NcsUtility::HeaderDetailIconRect
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 TRect NcsUtility::HeaderDetailIconRect( const TRect& aParent, const TInt aRows, const THeaderDetailIcon aIcon )
       
   768     {
       
   769     FUNC_LOG;
       
   770     const TInt variety( aRows == 1 ? 0 : 1 );
       
   771     TAknLayoutRect headerIconRect;
       
   772     headerIconRect.LayoutRect( aParent,
       
   773             aIcon == EIconFront ?
       
   774                 AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_g1( variety ) :
       
   775                 AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_g2( variety ) );
       
   776     // Offset detail rect by header caption pane height
       
   777     TRect result( headerIconRect.Rect() );
       
   778     //result.Move( 0, HeaderCaptionPaneRect( aParent ).Height() );
       
   779     return result;
       
   780     }
       
   781 
       
   782 // -----------------------------------------------------------------------------
       
   783 // NcsUtility::ListscrollPaneRect
       
   784 // -----------------------------------------------------------------------------
       
   785 TRect NcsUtility::ListscrollPaneRect()
       
   786     {
       
   787     FUNC_LOG;
       
   788     TRect mainPaneRect;
       
   789     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   790     TAknLayoutRect listRect;
       
   791     listRect.LayoutRect( mainPaneRect, AknLayoutScalable_Apps::main_sp_fs_listscroll_pane_te() );
       
   792     return listRect.Rect();
       
   793     }
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // NcsUtility::ListCmailPaneRect
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 TRect NcsUtility::ListCmailPaneRect( const TRect& aParent )
       
   800     {
       
   801     FUNC_LOG;
       
   802     TAknLayoutRect listCmailPaneRect;
       
   803     listCmailPaneRect.LayoutRect( aParent, AknLayoutScalable_Apps::list_cmail_pane() );
       
   804     return listCmailPaneRect.Rect();
       
   805     }
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // NcsUtility::ListCmailScrollbarRect
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 TRect NcsUtility::ListCmailScrollbarRect( const TRect& aParent )
       
   812     {
       
   813     FUNC_LOG;
       
   814     TAknLayoutRect listCmailPaneRect;
       
   815     listCmailPaneRect.LayoutRect( aParent, AknLayoutScalable_Apps::sp_fs_scroll_pane_cp03() );
       
   816     return listCmailPaneRect.Rect();
       
   817     }
       
   818 
       
   819 //<cmail>
       
   820 // -----------------------------------------------------------------------------
       
   821 // NcsUtility::SeparatorSizeInThisResolution
       
   822 //
       
   823 // Returns size of empty space between header and message body
       
   824 // -----------------------------------------------------------------------------
       
   825 //
       
   826 TSize NcsUtility::SeparatorSizeInThisResolution()
       
   827     {
       
   828     FUNC_LOG;
       
   829 
       
   830     TRect mainPaneRect;
       
   831     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   832 
       
   833     TAknLayoutRect listRect;
       
   834     listRect.LayoutRect(mainPaneRect, AknLayoutScalable_Apps::list_cmail_pane());
       
   835 
       
   836     TAknLayoutRect bodyRect;
       
   837     bodyRect.LayoutRect(listRect.Rect(), AknLayoutScalable_Apps::list_cmail_body_pane());
       
   838 
       
   839     TRect rect( bodyRect.Rect() );
       
   840     rect.Shrink( 0, bodyRect.Rect().Height() / 4 );
       
   841     return rect.Size();
       
   842     }
       
   843 
       
   844 
       
   845 
       
   846 // -----------------------------------------------------------------------------
       
   847 // NcsUtility::SeparatorLineColor
       
   848 // -----------------------------------------------------------------------------
       
   849 //
       
   850 TRgb NcsUtility::SeparatorLineColor()
       
   851     {
       
   852     FUNC_LOG;
       
   853     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   854     TRgb rgb;
       
   855     if (AknsUtils::GetCachedColor( skin, rgb,
       
   856             KAknsIIDQsnLineColors, EAknsCIQsnLineColorsCG6) != KErrNone )
       
   857         {
       
   858         rgb = KRgbBlack;
       
   859         }
       
   860 
       
   861     return rgb;
       
   862     }
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // NcsUtility::ComposerLeftMarginInPixels
       
   866 //
       
   867 // Left margin value for additional graphics in composer view
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 TInt NcsUtility::ComposerLeftMarginInPixels( const TRect& aParent )
       
   871     {
       
   872     FUNC_LOG;
       
   873     const TRect cmailPaneRect( ListCmailPaneRect( aParent ) );
       
   874     TAknLayoutRect layoutRect;
       
   875     layoutRect.LayoutRect( cmailPaneRect, AknLayoutScalable_Apps::list_single_cmail_header_caption_pane() );
       
   876     TAknLayoutText captionTextRect;
       
   877     captionTextRect.LayoutText( layoutRect.Rect(), AknLayoutScalable_Apps::list_single_cmail_header_caption_pane_t1() );
       
   878     return Abs( cmailPaneRect.iTl.iX - captionTextRect.TextRect().iTl.iX );
       
   879     }
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 // NcsUtility::ComposerRightMarginInPixels
       
   883 //
       
   884 // Right margin value for additional graphics in composer view
       
   885 // -----------------------------------------------------------------------------
       
   886 //
       
   887 TInt NcsUtility::ComposerRightMarginInPixels( const TRect& aParent )
       
   888     {
       
   889     FUNC_LOG;
       
   890     const TRect cmailPaneRect( ListCmailPaneRect( aParent ) );
       
   891     TAknLayoutRect layoutRect;
       
   892     layoutRect.LayoutRect( cmailPaneRect, AknLayoutScalable_Apps::list_single_cmail_header_caption_pane() );
       
   893     TAknLayoutText captionTextRect;
       
   894     captionTextRect.LayoutText( layoutRect.Rect(), AknLayoutScalable_Apps::list_single_cmail_header_caption_pane_t1() );
       
   895     return Abs( cmailPaneRect.iBr.iX - captionTextRect.TextRect().iBr.iX );
       
   896     }
       
   897 //</cmail>
       
   898 
       
   899 // -----------------------------------------------------------------------------
       
   900 // NcsUtility::ListCmailBodyPaneRect
       
   901 // -----------------------------------------------------------------------------
       
   902 //
       
   903 TRect NcsUtility::ListCmailBodyPaneRect( const TRect& aParent )
       
   904     {
       
   905     FUNC_LOG;
       
   906     TAknLayoutRect listCmailBodyRect;
       
   907     listCmailBodyRect.LayoutRect( aParent, AknLayoutScalable_Apps::list_cmail_body_pane() );
       
   908     return listCmailBodyRect.Rect();
       
   909     }
       
   910 
       
   911 // -----------------------------------------------------------------------------
       
   912 // NcsUtility::LayoutCaptionLabel
       
   913 // -----------------------------------------------------------------------------
       
   914 //
       
   915 void NcsUtility::LayoutCaptionLabel( CEikLabel* aLabel, const TRect& aParentRect )
       
   916     {
       
   917     FUNC_LOG;
       
   918     AknLayoutUtils::LayoutLabel( aLabel, NcsUtility::HeaderCaptionPaneRect( aParentRect ), AknLayoutScalable_Apps::list_single_cmail_header_caption_pane_t1().LayoutLine() );
       
   919     }
       
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // NcsUtility::LayoutCaptionLabel
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 void NcsUtility::LayoutCaptionButton( CAknButton* aButton, const TRect& aParentRect)
       
   926     {
       
   927     FUNC_LOG;
       
   928     TAknLayoutText layoutText;
       
   929     
       
   930     const TInt labelVariety = 2;
       
   931     TAknTextComponentLayout textComponentLayout;
       
   932     TAknLayoutRect layoutRect;
       
   933     TRect rect;
       
   934     
       
   935     TInt fontId;
       
   936     TInt topMargin;
       
   937     TInt bottomMargin;
       
   938     
       
   939     // Getting editor's top and bottom margin from its layout
       
   940     textComponentLayout = AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t1(
       
   941             KHeaderDetailTextPaneVariety );
       
   942     fontId = textComponentLayout.LayoutLine().FontId();
       
   943     
       
   944     TAknTextDecorationMetrics metrics( fontId );
       
   945     metrics.GetTopAndBottomMargins( topMargin, bottomMargin );
       
   946     
       
   947     layoutRect.LayoutRect(
       
   948         HeaderDetailPaneRect( aParentRect, 1, ETrue ),
       
   949         AknLayoutScalable_Apps::bg_button_pane_cp12() );
       
   950     
       
   951     textComponentLayout = AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t2( labelVariety );
       
   952     layoutText.LayoutText(
       
   953         HeaderDetailPaneRect( aParentRect, 1, ETrue ),
       
   954         textComponentLayout.LayoutLine() );
       
   955     
       
   956     rect = layoutRect.Rect();
       
   957     rect.iTl.iY -= topMargin + bottomMargin;
       
   958     
       
   959     aButton->SetRect( rect );
       
   960     aButton->SetTextFont( layoutText.Font() );
       
   961     aButton->SetTextHorizontalAlignment( layoutText.Align() );
       
   962     TMargins8 margs( 0, 0, 5, 0 );
       
   963     aButton->SetMargins( margs );
       
   964     }
       
   965 
       
   966 // -----------------------------------------------------------------------------
       
   967 // NcsUtility::LayoutDetailLabel
       
   968 // -----------------------------------------------------------------------------
       
   969 //
       
   970 void NcsUtility::LayoutDetailLabel( CEikLabel* aLabel, const TRect& aParentRect )
       
   971     {
       
   972     FUNC_LOG;
       
   973     AknLayoutUtils::LayoutLabel( aLabel, NcsUtility::HeaderDetailPaneRect( aParentRect, 1, ETrue ), AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t1( 0 ).LayoutLine() );
       
   974     }
       
   975 
       
   976 // -----------------------------------------------------------------------------
       
   977 // NcsUtility::LayoutDetailEdwin
       
   978 // -----------------------------------------------------------------------------
       
   979 //
       
   980 void NcsUtility::LayoutDetailEdwin( CEikEdwin* aEdwin, const TRect& aParentRect, const TInt aLineCount, const TBool aBackIcon  )
       
   981     {
       
   982     FUNC_LOG;
       
   983     TAknMultiLineTextLayout edwinLayout;
       
   984     const TInt textPaneVariety( aBackIcon ? 1 : 3 );
       
   985     TAknTextComponentLayout textLayout( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t1( textPaneVariety ) );
       
   986     RArray< TAknTextComponentLayout > edwinLayoutLines;
       
   987     TAknTextComponentLayout textRowLayout;
       
   988     TAknWindowComponentLayout headerDetailPane( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0, 0, 0 ) );
       
   989     for ( TInt line = 0; line < aLineCount; line++ )
       
   990         {
       
   991         textRowLayout = TAknWindowComponentLayout::ComposeText( TAknWindowComponentLayout::MultiLineY( headerDetailPane, line, 0 ), textLayout );
       
   992         edwinLayoutLines.Append( textRowLayout );
       
   993         }
       
   994     AknLayoutUtils::LayoutEdwin( aEdwin, NcsUtility::HeaderDetailPaneRect( aParentRect, aLineCount ), TAknTextComponentLayout::Multiline( edwinLayoutLines ) );
       
   995     edwinLayoutLines.Reset();
       
   996     }
       
   997 
       
   998 // -----------------------------------------------------------------------------
       
   999 // NcsUtility::LayoutDetailEdwin
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 void NcsUtility::LayoutDetailEdwinTouch( CEikEdwin* aEdwin, const TRect& aParentRect,
       
  1003                                          const TInt aLineCount, const TBool /*aBackIcon*/  )
       
  1004     {
       
  1005     FUNC_LOG;
       
  1006     TAknMultiLineTextLayout edwinLayout;
       
  1007     TAknTextComponentLayout textLayout( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane_t1( KHeaderDetailTextPaneVariety ) );
       
  1008     RArray< TAknTextComponentLayout > edwinLayoutLines;
       
  1009     TAknTextComponentLayout textRowLayout;
       
  1010     TAknWindowComponentLayout headerDetailPane( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0, 0, 0 ) );
       
  1011     for ( TInt line = 0; line < aLineCount; line++ )
       
  1012         {
       
  1013         textRowLayout = TAknWindowComponentLayout::ComposeText( TAknWindowComponentLayout::MultiLineY( headerDetailPane, line, 0 ), textLayout );
       
  1014         edwinLayoutLines.Append( textRowLayout );
       
  1015         }
       
  1016     AknLayoutUtils::LayoutEdwin( aEdwin, NcsUtility::HeaderDetailPaneRect( aParentRect, aLineCount, ETrue ), TAknTextComponentLayout::Multiline( edwinLayoutLines ) );
       
  1017     edwinLayoutLines.Reset();
       
  1018     }
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // NcsUtility::HeaderControlPosition
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 TPoint NcsUtility::HeaderControlPosition( const TRect& aParentRect, const TInt aCurrentLine )
       
  1025     {
       
  1026     FUNC_LOG;
       
  1027     TAknLayoutRect detailPane;
       
  1028     TAknWindowComponentLayout headerDetailPane( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0, 0, 0 ) );
       
  1029     detailPane.LayoutRect( aParentRect, TAknWindowComponentLayout::MultiLineY( headerDetailPane, aCurrentLine, 0 ) );
       
  1030     return detailPane.Rect().iTl;
       
  1031     }
       
  1032 
       
  1033 // -----------------------------------------------------------------------------
       
  1034 // NcsUtility::LayoutHeaderControl
       
  1035 // -----------------------------------------------------------------------------
       
  1036 //
       
  1037 void NcsUtility::LayoutHeaderControl( CCoeControl* aControl, const TRect& aParentRect, const TInt aCurrentLine, const TInt aNumberOfLines )
       
  1038     {
       
  1039     FUNC_LOG;
       
  1040     TAknLayoutRect detailPane;
       
  1041     TAknWindowComponentLayout headerDetailPane( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0, 0, 0 ) );
       
  1042     detailPane.LayoutRect( aParentRect, TAknWindowComponentLayout::MultiLineY( headerDetailPane, aCurrentLine, 0 ) );
       
  1043     TRect rect( detailPane.Rect() );
       
  1044     rect.SetHeight( rect.Height() * aNumberOfLines );
       
  1045     aControl->SetRect( rect );
       
  1046     }
       
  1047 
       
  1048 // -----------------------------------------------------------------------------
       
  1049 // NcsUtility::LayoutBodyEdwin
       
  1050 // -----------------------------------------------------------------------------
       
  1051 //
       
  1052 //<cmail>
       
  1053 void NcsUtility::LayoutBodyEdwin( CEikEdwin* aEdwin, const TRect& aParentRect, const TInt aCurrentLine, const TInt aNumberOfLines,
       
  1054         TInt& aSeparatorYPosition )
       
  1055 //</cmail>
       
  1056     {
       
  1057     FUNC_LOG;
       
  1058     TAknMultiLineTextLayout edwinLayout;
       
  1059     TAknTextComponentLayout textLayout( AknLayoutScalable_Apps::list_cmail_body_pane_t1() );
       
  1060     RArray< TAknTextComponentLayout > edwinLayoutLines;
       
  1061     TAknTextComponentLayout textRowLayout;
       
  1062     TAknWindowComponentLayout headerCaptionPane( AknLayoutScalable_Apps::list_single_cmail_header_caption_pane( 0, 0, 0 ) );
       
  1063     TInt lines = Max( aNumberOfLines, 2 );
       
  1064     for ( TInt line = 0; line < lines; line++ )
       
  1065         {
       
  1066         textRowLayout = TAknWindowComponentLayout::ComposeText( TAknWindowComponentLayout::MultiLineY( headerCaptionPane, line, 0 ), textLayout );
       
  1067         edwinLayoutLines.Append( textRowLayout );
       
  1068         }
       
  1069     TAknLayoutRect bodyPane;
       
  1070     bodyPane.LayoutRect( aParentRect, AknLayoutScalable_Apps::list_cmail_body_pane() );
       
  1071     TRect bodyRect( bodyPane.Rect() );
       
  1072     TAknLayoutRect detailPane;
       
  1073     TAknWindowComponentLayout headerDetailPane( AknLayoutScalable_Apps::list_single_cmail_header_detail_pane( 0, 0, 0 ) );
       
  1074     detailPane.LayoutRect( aParentRect, TAknWindowComponentLayout::MultiLineY( headerDetailPane, aCurrentLine, 0 ) );
       
  1075     bodyRect = TRect( detailPane.Rect().iTl, bodyRect.Size() );
       
  1076     //<cmail>
       
  1077     aSeparatorYPosition = bodyRect.iTl.iY;
       
  1078     // Since layout doesn't specify enough space between separator line
       
  1079     // and editor, we add some space manually
       
  1080     TInt deltaMove = NcsUtility::SeparatorSizeInThisResolution().iHeight;
       
  1081     bodyRect.Move( 0, deltaMove );
       
  1082     //</cmail>
       
  1083     AknLayoutUtils::LayoutEdwin( aEdwin, bodyRect, TAknTextComponentLayout::Multiline( edwinLayoutLines ), EAknsCIQsnTextColorsCG6 );
       
  1084     edwinLayoutLines.Reset();
       
  1085     }
       
  1086 
       
  1087 //<cmail>
       
  1088 // -----------------------------------------------------------------------------
       
  1089 // NcsUtility::CalculateSeparatorLineSecondaryColor
       
  1090 //
       
  1091 // Calculates secondary color value based on the start value. Useful for
       
  1092 // gradient drawing.
       
  1093 // @param aDegree = color change coefficient
       
  1094 // -----------------------------------------------------------------------------
       
  1095 //
       
  1096 TRgb NcsUtility::CalculateSeparatorLineSecondaryColor( TInt aDegree,
       
  1097                                                        TRgb /*aStartColor*/ )
       
  1098     {
       
  1099     TRgb secondaryColor;
       
  1100     TInt redValue;
       
  1101     TInt greenValue;
       
  1102     TInt blueValue;
       
  1103     TRgb startColor = SeparatorLineColor();
       
  1104     if( startColor.Red() > KFSUtilityThresholdColorValue &&
       
  1105             startColor.Green() > KFSUtilityThresholdColorValue &&
       
  1106             startColor.Blue() > KFSUtilityThresholdColorValue )
       
  1107         {
       
  1108         //Original color is bright, so let's make secondary color darker
       
  1109         redValue = startColor.Red() - ( startColor.Red() / aDegree );
       
  1110         greenValue = startColor.Green() - ( startColor.Green() / aDegree );
       
  1111         blueValue = startColor.Blue() - ( startColor.Blue() / aDegree );
       
  1112         }
       
  1113     else
       
  1114         {
       
  1115         //Original color is dark, so let's make secondary color brighter
       
  1116         //Checking how bright original color is
       
  1117         if( startColor.Red() < KFSUtilityThresholdColorMiddleValue &&
       
  1118                 startColor.Green() < KFSUtilityThresholdColorMiddleValue &&
       
  1119                 startColor.Blue() < KFSUtilityThresholdColorMiddleValue )
       
  1120             {
       
  1121             // Calculating new values from the unoccupied color space
       
  1122             redValue = startColor.Red() + ( (
       
  1123                     KFSUtilityMaxColorValue - startColor.Red() ) / aDegree );
       
  1124             greenValue = startColor.Green() + ( (
       
  1125                     KFSUtilityMaxColorValue - startColor.Green() ) / aDegree );
       
  1126             blueValue = startColor.Blue() + ( (
       
  1127                     KFSUtilityMaxColorValue - startColor.Blue() ) / aDegree );
       
  1128             }
       
  1129         else
       
  1130             {
       
  1131             // Calculating new values from the occupied color space
       
  1132             redValue = startColor.Red() + ( startColor.Red() / aDegree );
       
  1133             greenValue = startColor.Green() + ( startColor.Green() / aDegree );
       
  1134             blueValue = startColor.Blue() + ( startColor.Blue() / aDegree );
       
  1135             }
       
  1136         }
       
  1137 
       
  1138     if ( redValue > KFSUtilityMaxColorValue )
       
  1139         {
       
  1140         redValue = KFSUtilityMaxColorValue;
       
  1141         }
       
  1142     if ( greenValue > KFSUtilityMaxColorValue )
       
  1143         {
       
  1144         greenValue = KFSUtilityMaxColorValue;
       
  1145         }
       
  1146     if ( blueValue > KFSUtilityMaxColorValue )
       
  1147         {
       
  1148         blueValue = KFSUtilityMaxColorValue;
       
  1149         }
       
  1150     return TRgb( redValue , greenValue, blueValue );
       
  1151     }
       
  1152 
       
  1153 // </cmail> Platform layout changes
       
  1154 // -----------------------------------------------------------------------------
       
  1155 // NcsUtility::CalculateMsgBodyLineColor
       
  1156 //
       
  1157 // Calculates line color to be used in message body. Calculated color is darker than
       
  1158 // given base color.
       
  1159 // @param aDegree = color darkening coefficient
       
  1160 // @param aBaseColor = base color to be used in calculation
       
  1161 // -----------------------------------------------------------------------------
       
  1162 //
       
  1163 TRgb NcsUtility::CalculateMsgBodyLineColor( TInt aDegree,
       
  1164                                             TRgb aBaseColor )
       
  1165     {
       
  1166     TInt redValue = aBaseColor.Red() - ( aBaseColor.Red() / aDegree );
       
  1167     TInt greenValue = aBaseColor.Green() - ( aBaseColor.Green() / aDegree );
       
  1168     TInt blueValue = aBaseColor.Blue() - ( aBaseColor.Blue() / aDegree );
       
  1169 
       
  1170     if ( redValue < KFSUtilityMinColorValue )
       
  1171         {
       
  1172         redValue = KFSUtilityMinColorValue;
       
  1173         }
       
  1174     if ( greenValue < KFSUtilityMinColorValue )
       
  1175         {
       
  1176         greenValue = KFSUtilityMinColorValue;
       
  1177         }
       
  1178     if ( blueValue < KFSUtilityMinColorValue )
       
  1179         {
       
  1180         blueValue = KFSUtilityMinColorValue;
       
  1181         }
       
  1182 
       
  1183     return TRgb( redValue , greenValue, blueValue );
       
  1184     }
       
  1185 
       
  1186 //End of file
       
  1187