locationsystemui/locationsysui/locutils/src/locphonenumberformat.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     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: 
       
    15 *     Default implementation for number formatting.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <AknUtils.h>
       
    22 #include <AknLayoutDef.h>
       
    23 #include <AknLayout.lag>
       
    24 #include <eikfrlbd.h>
       
    25 #include <AknPhoneNumberGrouping.h>
       
    26 #include "locphonenumberformat.h"
       
    27 
       
    28 // CONSTANT DEFINITIONS
       
    29 
       
    30 // maximum phone number length
       
    31 const TInt KLocPhoneNumberMaxLen = 48;
       
    32 
       
    33 // ============= CLOCPHONENUMBERFORMAT MEMBER FUNCTIONS ===================
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CLocPhoneNumberFormat::NewL
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C CLocPhoneNumberFormat* CLocPhoneNumberFormat::NewL()
       
    40 	{
       
    41 	CLocPhoneNumberFormat *self = new ( ELeave ) CLocPhoneNumberFormat;
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CLocPhoneNumberFormat::ConstructL
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CLocPhoneNumberFormat::ConstructL()
       
    53 	{
       
    54 	iPNGEngine = CAknPhoneNumberGrouping::NewL(KLocPhoneNumberMaxLen);
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CLocPhoneNumberFormat::CLocPhoneNumberFormat
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CLocPhoneNumberFormat::CLocPhoneNumberFormat()
       
    62 	{
       
    63     // Intentionally empty
       
    64 	}
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CLocPhoneNumberFormat::~CLocPhoneNumberFormat
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CLocPhoneNumberFormat::~CLocPhoneNumberFormat()
       
    71 	{
       
    72 	delete iPNGEngine;
       
    73 	}
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CLocPhoneNumberFormat::PhoneNumberFormatL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 TFormatResult CLocPhoneNumberFormat::PhoneNumberFormatL(
       
    80     const TDesC& aNumberToFormat,
       
    81     TDes& aFormattedString )
       
    82 	{
       
    83 	TFormatResult rc( EResultOK );
       
    84 	if ( iPNGEngine->Set(aNumberToFormat) != KErrNone )
       
    85 		{
       
    86 		// If we cannot group the number then just return 
       
    87 		// the ungrouped number
       
    88 		return rc;
       
    89 		}
       
    90 
       
    91 	HBufC* groupedPhoneNumber = 
       
    92 		HBufC::NewL(iPNGEngine->FormattedNumber().Length());
       
    93 	// CAknPhoneNumberGrouping takes care of grouping based on the 
       
    94 	// current settings. If the __SERIES60_PHONE_NUMBER_GROUPING 
       
    95 	// feature flag is disabled then grouping is not done.
       
    96 	
       
    97 	TPtr grpPhoneNumberDesc = groupedPhoneNumber->Des();
       
    98 	iPNGEngine->CopyFormattedNumber(grpPhoneNumberDesc);
       
    99 	if (aFormattedString.MaxLength() < groupedPhoneNumber->Length())
       
   100 		{
       
   101 		// Store only as much as can be fitted into the resultant 
       
   102 		// Descriptor
       
   103 		rc = EResultTruncated;
       
   104 		aFormattedString = 
       
   105 			groupedPhoneNumber->Right( groupedPhoneNumber->Length() -
       
   106 										(groupedPhoneNumber->Length() - 
       
   107 										aFormattedString.MaxLength()) );
       
   108 		}
       
   109 	else
       
   110 		{
       
   111 		aFormattedString.Copy(*groupedPhoneNumber);
       
   112 		}
       
   113 
       
   114 	delete groupedPhoneNumber;
       
   115 	return rc;
       
   116 	}
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CLocPhoneNumberFormat::PhoneNumberGroupL
       
   120 // ---------------------------------------------------------------------------
       
   121 //	
       
   122 EXPORT_C HBufC* CLocPhoneNumberFormat::PhoneNumberGroupL( const TDesC& aNumberToGroup )
       
   123     {
       
   124 	if ( iPNGEngine->Set(aNumberToGroup) != KErrNone )
       
   125 		{
       
   126 		// If we cannot group the number then just return NULL
       
   127 		return NULL;
       
   128 		}
       
   129 
       
   130 	HBufC* groupedPhoneNumber = HBufC::NewL(iPNGEngine->FormattedNumber().Length());
       
   131 		
       
   132 	// CAknPhoneNumberGrouping takes care of grouping based on the 
       
   133 	// current settings. If the __SERIES60_PHONE_NUMBER_GROUPING 
       
   134 	// feature flag is disabled then grouping is not done.
       
   135 	
       
   136 	TPtr grpPhoneNumberDesc = groupedPhoneNumber->Des();
       
   137 	iPNGEngine->CopyFormattedNumber( grpPhoneNumberDesc );
       
   138 	
       
   139 	return groupedPhoneNumber;	
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CLocPhoneNumberFormat::PhoneNumberFormatL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C TFormatResult CLocPhoneNumberFormat::PhoneNumberFormatL(
       
   147     const TDesC& aNumberToFormat,
       
   148     TDes& aFormattedString,
       
   149     AknTextUtils::TClipDirection aClipDirection,
       
   150     CEikFormattedCellListBox *aListBox,
       
   151     TInt aItemIndex,
       
   152     TInt aSubCellNumber,
       
   153     TInt aIcons )
       
   154 	{
       
   155 	TFormatResult rc = PhoneNumberFormatL( aNumberToFormat, aFormattedString );
       
   156     if (aIcons == 0)
       
   157     	{
       
   158   		// There is no Icon so just use the AknTextUtils API
       
   159    		if( AknTextUtils::ClipToFit( aFormattedString, aClipDirection, 
       
   160    										aListBox, aItemIndex,
       
   161    										aSubCellNumber ))
       
   162    			{
       
   163    			rc = EResultClipped;
       
   164    			}
       
   165     	}
       
   166 	else
       
   167 		{
       
   168 		// Adjust for the Icon Space.
       
   169 	    CFormattedCellListBoxData *data = 
       
   170 	        aListBox->ItemDrawer()->FormattedCellData();
       
   171 	    const CFont *font = data->Font( aListBox->ItemDrawer()->Properties( 
       
   172 	                                            aItemIndex ), aSubCellNumber );
       
   173 		
       
   174 		//Obtain the layout parameters for this element from the Avkon Layout
       
   175 
       
   176 	    TAknLayoutText textLayout;
       
   177 	    textLayout.LayoutText(aListBox->Rect() , 
       
   178 			AKN_LAYOUT_TEXT_List_pane_texts__menu_single__Line_1(aIcons));
       
   179 	     
       
   180 		TRect rect = textLayout.TextRect();
       
   181 	    TInt width = rect.Width();
       
   182 
       
   183 		TInt clipgap = data->SubCellTextClipGap( aSubCellNumber );
       
   184 
       
   185 		if ( AknTextUtils::ClipToFit( aFormattedString, *font, width,
       
   186 	                                  aClipDirection, width + clipgap ) )
       
   187 			{
       
   188 			rc = EResultClipped;
       
   189 			}
       
   190 		}
       
   191     return rc;
       
   192     }
       
   193 
       
   194 //  End of File