wvuing/wvuiave/AppSrc/CCASmileyUtil.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2006 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 for selecting smile icon and converting
       
    15 *                between smile id and smile string.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include 	"CCASmileyUtil.h"
       
    22 #include 	"CCAPicture.h"
       
    23 #include    "ChatDefinitions.h"
       
    24 #include	"ChatDebugPrint.h"
       
    25 #include    "IMUtils.h"
       
    26 #include    "ccasmileyinformation.h"
       
    27 
       
    28 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    29 // so the enums for keys and central repository header is added here
       
    30 #include 	"VariantKeys.h"
       
    31 #include	<PUAcodes.hrh>
       
    32 
       
    33 #include	<gulicon.h>
       
    34 #include 	<txtrich.h>
       
    35 #include 	<gdi.h>
       
    36 #include    <eikrted.h>
       
    37 #include	<frmtlay.h>
       
    38 // ================= MEMBER FUNCTIONS =======================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CCASmileyUtil::NewL
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CCASmileyUtil* CCASmileyUtil::NewL(  MCASkinVariant& aSkinVariant,
       
    46                                      MCAAppUi& aAppUi, TMessageExtensionTypes aType )
       
    47     {
       
    48     CCASmileyUtil* self = new ( ELeave ) CCASmileyUtil( aType );
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL( aSkinVariant, aAppUi );
       
    51     CleanupStack::Pop();
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCASmileyUtil::~CCASmileyUtil
       
    57 // Destructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CCASmileyUtil::~CCASmileyUtil()
       
    61     {
       
    62     iConvertArray.ResetAndDestroy();
       
    63     delete iSmileUtil;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CCASmileyUtil::CCASmileyUtil
       
    68 // C++ constructor can NOT contain any code, that
       
    69 // might leave.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CCASmileyUtil::CCASmileyUtil( TMessageExtensionTypes aType )
       
    73         : MCAMessageExtension( aType )
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CCASmileyUtil::ConstructL
       
    79 // ConstructL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CCASmileyUtil::ConstructL( MCASkinVariant& aSkinVariant,
       
    83                                 MCAAppUi& aAppUi )
       
    84     {
       
    85     iSmileUtil = CCASmileIconUtility::NewL( aSkinVariant, aAppUi );
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CCASmileyUtil::InsertExtensionL
       
    90 // (other items were commented in a header).
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 void CCASmileyUtil::InsertExtensionL( CEikRichTextEditor& aEditor,
       
    94                                       TBool& aCancelled )
       
    95     {
       
    96     TPictureHeader picHeader;
       
    97     TInt bitmapId( KErrNone );
       
    98     TInt retVal = iSmileUtil->LaunchSmileIconDialogL( bitmapId );
       
    99     if ( retVal )
       
   100         {
       
   101         // check if there is room for icon, if not return
       
   102         if ( ( aEditor.MaxLength() - aEditor.TextLength() ) < KChatSmileyLength )
       
   103             {
       
   104             return;
       
   105             }
       
   106 
       
   107         //we don't own this
       
   108         CGulIcon* icon = const_cast<CGulIcon*>(
       
   109                              iSmileUtil->GetSmileIcon( bitmapId ) );
       
   110 
       
   111         //create CCAPicture from selected icon
       
   112         CCAPicture* smileIcon = new ( ELeave ) CCAPicture(
       
   113             *CCoeEnv::Static()->SystemGc().Device(),
       
   114             icon,
       
   115             bitmapId );
       
   116 
       
   117         picHeader.iPicture = TSwizzle<CPicture>( smileIcon );
       
   118         TInt cursorPos = aEditor.CursorPos();
       
   119 
       
   120         // insert smiley to editor
       
   121         aEditor.RichText()->InsertL( cursorPos, picHeader );
       
   122 
       
   123         // icon is inserted, and it should be converted to text
       
   124         // before sending, so it needs extra chars according to smiley string length
       
   125         TInt textLimit = aEditor.MaxLength() -
       
   126                          iSmileUtil->GetSmileString( bitmapId ).Length() + 1; // 1 to take icon
       
   127         // length into count
       
   128         aEditor.SetTextLimit( textLimit );
       
   129 
       
   130         // apply formatting
       
   131         TCharFormat charFormat;
       
   132         TCharFormatMask charFormatMask;
       
   133         charFormat.iFontPresentation.iPictureAlignment =
       
   134             TFontPresentation::EAlignCentered;
       
   135         charFormatMask.SetAttrib( EAttFontPictureAlignment );
       
   136         aEditor.RichText()->ApplyCharFormatL( charFormat, charFormatMask, 0,
       
   137                                               aEditor.TextLength() );
       
   138 
       
   139         if ( &aEditor != iEditor )
       
   140             {
       
   141             iEditor = &aEditor;
       
   142             iCurrentCount = 1;
       
   143             }
       
   144         else
       
   145             {
       
   146             ++iCurrentCount;
       
   147             }
       
   148 
       
   149         aCancelled = EFalse;
       
   150         }
       
   151     else
       
   152         {
       
   153         aCancelled = ETrue;
       
   154         }
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------
       
   158 // CCASmileyUtil::ExtensionToStringL
       
   159 // (other items were commented in a header).
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 void CCASmileyUtil::ExtensionToStringL( CEikRichTextEditor& anEditor, TDes& aDes )
       
   163     {
       
   164     RArray<TInt> iconIndArray;
       
   165     CleanupClosePushL( iconIndArray );
       
   166 
       
   167     CPicture* editorPic;
       
   168     TInt i;
       
   169     TInt limit( 0 );
       
   170 
       
   171     // for loop gets icon positions to array
       
   172     TInt length = aDes.Length();
       
   173     for ( i = 0; i < length; ++i )
       
   174         {
       
   175         if ( aDes[ i ] ==  CEditableText::EPictureCharacter )
       
   176             {
       
   177             User::LeaveIfError( iconIndArray.Append( i ) );
       
   178             }
       
   179         }
       
   180 
       
   181     // real count of pictures
       
   182     TInt count = anEditor.RichText()->PictureCount();
       
   183     TInt indCount = iconIndArray.Count();
       
   184 
       
   185     if ( &anEditor != iEditor )
       
   186         {
       
   187         Reset();
       
   188         }
       
   189 
       
   190     // whisper message
       
   191     if ( indCount > iCurrentCount )
       
   192         {
       
   193         limit = indCount - iCurrentCount;
       
   194         }
       
   195 
       
   196     if ( indCount > 0 )
       
   197         {
       
   198         for ( i = count; i > limit; --i )
       
   199             {
       
   200             editorPic = anEditor.RichText()->PictureHandleL(
       
   201                             iconIndArray[ i - 1 ], MLayDoc::EForceLoadTrue );
       
   202             if ( !editorPic )
       
   203                 {
       
   204                 User::Leave( KErrBadHandle );
       
   205                 }
       
   206 
       
   207             CCAPicture* icon = static_cast<CCAPicture*> ( editorPic );
       
   208 
       
   209             TInt oldLen = aDes.Length();
       
   210 
       
   211             TInt iconIndex = icon->Index();
       
   212 
       
   213             if ( iconIndex >= 0 && iconIndex < iSmileUtil->SmileIconCount() )
       
   214                 {
       
   215                 //delete padding char
       
   216                 aDes.Delete( iconIndArray[ i - 1 ], 1 ); // 1 = one char
       
   217                 //insert string smiley
       
   218                 aDes.Insert( iconIndArray[ i - 1 ],
       
   219                              iSmileUtil->GetSmileString( icon->Index() ) );
       
   220                 }
       
   221 
       
   222             }
       
   223         }
       
   224     CleanupStack::PopAndDestroy(); // iconIndArray.Close()
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CCASmileyUtil::ConvertSelectionToExtensionL
       
   229 // Convert selection smileys to icons.
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CCASmileyUtil::ConvertSelectionToExtensionL( CEikRichTextEditor& aEditor )
       
   233     {
       
   234     TInt selectAdd( 0 );
       
   235 
       
   236     // for loop gets icon positions to array
       
   237     TInt start = aEditor.Selection().LowerPos();
       
   238     TInt end = aEditor.Selection().HigherPos();
       
   239 
       
   240     // Clear convert array, it has something, but its not correct
       
   241     iConvertArray.ResetAndDestroy();
       
   242 
       
   243     HBufC* des = HBufC::NewLC( IMUtils::MaxMsgLength() );
       
   244     TPtr desText( des->Des() );
       
   245 
       
   246     aEditor.GetText( desText );
       
   247     TInt txtLen = desText.Length();
       
   248     if ( txtLen < end )
       
   249         {
       
   250         end = txtLen;
       
   251         }
       
   252     desText.Delete( end, txtLen - end );
       
   253     desText.Delete( 0, start );
       
   254 
       
   255     iSmileUtil->SearchSmilesL( desText, iConvertArray, NULL, start );
       
   256 
       
   257 #ifdef _DEBUG
       
   258     TPtrC myDebug( aEditor.Text()->Read( 0 ) );
       
   259     CHAT_DP( D_CHAT_LIT( "CCASmileyUtil::ConvertSelectionToExtensionL 3- %S" ), &myDebug );
       
   260 #endif
       
   261 
       
   262     for ( TInt a( iConvertArray.Count() - 1 ); a >= 0; --a )
       
   263         {
       
   264         if ( iConvertArray[ a ]->Position() >= start && iConvertArray[ a ]->Position() < end ) // do we convert or not
       
   265             {
       
   266             TPictureHeader picHeader;
       
   267             // Insert icon in place
       
   268 
       
   269             //we don't own this
       
   270             CGulIcon* icon = const_cast<CGulIcon*>(
       
   271                                  iSmileUtil->GetSmileIcon( iConvertArray[ a ]->Index() ) );
       
   272 
       
   273             //create CCAPicture from selected icon
       
   274             CCAPicture* smileIcon = new ( ELeave ) CCAPicture(
       
   275                 *CCoeEnv::Static()->SystemGc().Device(),
       
   276                 icon,
       
   277                 iConvertArray[ a ]->Index() );
       
   278 
       
   279             picHeader.iPicture = TSwizzle<CPicture>( smileIcon );
       
   280             aEditor.Text()->DeleteL( iConvertArray[ a ]->Position(), iConvertArray[ a ]->SmileyString().Length() );
       
   281 
       
   282 #ifdef _DEBUG
       
   283             myDebug.Set( aEditor.Text()->Read( 0 ) );
       
   284             CHAT_DP( D_CHAT_LIT( "CCASmileyUtil::ConvertSelectionToExtensionL 3b %S %d" )
       
   285                      , &myDebug, iConvertArray[ a ]->Position() );
       
   286 #endif
       
   287 
       
   288             aEditor.RichText()->InsertL( iConvertArray[ a ]->Position(), picHeader );
       
   289 
       
   290 #ifdef _DEBUG
       
   291             myDebug.Set( aEditor.Text()->Read( 0 ) );
       
   292             CHAT_DP( D_CHAT_LIT( "CCASmileyUtil::ConvertSelectionToExtensionL 3c %S" ), &myDebug );
       
   293 #endif
       
   294 
       
   295             selectAdd -= iConvertArray[ a ]->SmileyString().Length() - 1;
       
   296 
       
   297             // icon is inserted, and it should be converted to text
       
   298             // before sending, so it needs extra chars according to smiley string length
       
   299             TInt textLimit =
       
   300                 aEditor.MaxLength() - iConvertArray[ a ]->SmileyString().Length();
       
   301             TInt currentlength = aEditor.Text()->DocumentLength();
       
   302             aEditor.SetTextLimit( Max( textLimit, currentlength ) );
       
   303 
       
   304             if ( &aEditor != iEditor )
       
   305                 {
       
   306                 iEditor = &aEditor;
       
   307                 iCurrentCount = 1;
       
   308                 }
       
   309             else
       
   310                 {
       
   311                 ++iCurrentCount;
       
   312                 }
       
   313             }
       
   314         }
       
   315 
       
   316     // Apply formatting
       
   317     TInt selectionLen = end + selectAdd - start;
       
   318     TCharFormat charFormat;
       
   319     TCharFormatMask charFormatMask;
       
   320     charFormat.iFontPresentation.iPictureAlignment =
       
   321         TFontPresentation::EAlignCentered;
       
   322     charFormatMask.SetAttrib( EAttFontPictureAlignment );
       
   323     aEditor.RichText()->ApplyCharFormatL( charFormat, charFormatMask,
       
   324                                           start, selectionLen );
       
   325 
       
   326     // Handle changes in editor
       
   327     aEditor.TextView()->HandleGlobalChangeL();
       
   328 
       
   329     // Set selection to correct after adding images
       
   330     aEditor.SetSelectionL( start, end + selectAdd );
       
   331 
       
   332     // Clear convert array
       
   333     iConvertArray.ResetAndDestroy();
       
   334 
       
   335     CleanupStack::PopAndDestroy( des );
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CCASmileyUtil::ConvertSelectionToExtensionL
       
   340 // Convert selection smileys to icons.
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CCASmileyUtil::ConvertSelectionToExtensionL( CRichText& aRichText, TCursorSelection& aSelection )
       
   344     {
       
   345     TInt start( aSelection.LowerPos() );
       
   346     TInt length( aSelection.Length() );
       
   347 
       
   348     // Clear convert array and fetch the text
       
   349     iConvertArray.ResetAndDestroy();
       
   350     HBufC* text = HBufC::NewMaxLC( aRichText.DocumentLength() );
       
   351     TPtr desText( text->Des() );
       
   352     aRichText.Extract( desText, start, length );
       
   353 
       
   354     iSmileUtil->SearchSmilesL( desText, iConvertArray );
       
   355 
       
   356     for ( TInt a( iConvertArray.Count() - 1 ); a >= 0; --a )
       
   357         {
       
   358         TPictureHeader picHeader;
       
   359         // Insert icon in place
       
   360         //we don't own this
       
   361         CGulIcon* icon = const_cast<CGulIcon*>(
       
   362                              iSmileUtil->GetSmileIcon( iConvertArray[ a ]->Index() ) );
       
   363 
       
   364         //create CCAPicture from selected icon
       
   365         CCAPicture* smileIcon = new ( ELeave ) CCAPicture(
       
   366             *CCoeEnv::Static()->SystemGc().Device(),
       
   367             icon,
       
   368             iConvertArray[ a ]->Index() );
       
   369 
       
   370         picHeader.iPicture = TSwizzle<CPicture>( smileIcon );
       
   371         aRichText.DeleteL( iConvertArray[ a ]->Position() + start,
       
   372                            iConvertArray[ a ]->SmileyString().Length() );
       
   373 
       
   374         aRichText.InsertL( iConvertArray[ a ]->Position() + start, picHeader );
       
   375         }
       
   376 
       
   377     // clean up
       
   378     iConvertArray.ResetAndDestroy();
       
   379     CleanupStack::PopAndDestroy( text );
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CCASmileyUtil::ConvertSelectionToStringL
       
   384 // Convert selection smileys to strings
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CCASmileyUtil::ConvertSelectionToStringL( CEikRichTextEditor& aEditor, TBool aPreserve )
       
   388     {
       
   389     // Clear convert array
       
   390     iConvertArray.ResetAndDestroy();
       
   391 
       
   392     HBufC* text = HBufC::NewMaxLC( IMUtils::MaxMsgLength() );
       
   393     TPtr textCopy( text->Des() );
       
   394     aEditor.GetText( textCopy );
       
   395 
       
   396     // for loop gets icon positions to array
       
   397     TInt start = aEditor.Selection().LowerPos();
       
   398     TInt end = aEditor.Selection().HigherPos();
       
   399 
       
   400     TInt i;
       
   401     for ( i = start; i < end; ++i )
       
   402         {
       
   403         if ( textCopy[ i ] ==  CEditableText::EPictureCharacter )
       
   404             {
       
   405             CCASmileyInformation* smileInfo = CCASmileyInformation::NewL();
       
   406             CleanupStack::PushL( smileInfo );
       
   407             smileInfo->SetPosition( i );
       
   408             smileInfo->SetIcon( ETrue );
       
   409             User::LeaveIfError( iConvertArray.Append( smileInfo ) );
       
   410             CleanupStack::Pop( smileInfo );
       
   411             }
       
   412         }
       
   413 
       
   414     TInt count = iConvertArray.Count();
       
   415     for ( i = count - 1; i >= 0; --i )
       
   416         {
       
   417         CPicture* editorPic = aEditor.RichText()->PictureHandleL(
       
   418                                   iConvertArray[ i ]->Position(), MLayDoc::EForceLoadTrue );
       
   419 
       
   420         if ( !editorPic )
       
   421             {
       
   422             User::Leave( KErrBadHandle );
       
   423             }
       
   424 
       
   425         CCAPicture* icon = static_cast<CCAPicture*> ( editorPic );
       
   426 
       
   427         const TDesC& iconString = iSmileUtil->GetSmileString( icon->Index() );
       
   428         iConvertArray[ i ]->SetSmileyStringL( iconString );
       
   429         iConvertArray[ i ]->SetIndex( icon->Index() );
       
   430         }
       
   431 
       
   432     textCopy.Delete( end, textCopy.Length() - end );
       
   433     textCopy.Delete( 0, start );
       
   434     iSmileUtil->SearchSmilesL( textCopy, iConvertArray, NULL, start );
       
   435 
       
   436     // Change icons to strings
       
   437     TPtrC myDebug( aEditor.Text()->Read( 0 ) );
       
   438     CHAT_DP( D_CHAT_LIT( "CCASmileyUtil::ConvertSelectionToStringL %S" ), &myDebug );
       
   439     TInt selectAdd( 0 );
       
   440     count = iConvertArray.Count();
       
   441     for ( i = count - 1; i >= 0; --i )
       
   442         {
       
   443         if ( iConvertArray[ i ]->IsIcon() ) // Icon
       
   444             {
       
   445             TCursorSelection deleteSel( iConvertArray[ i ]->Position(),
       
   446                                         iConvertArray[ i ]->Position() + 1 );
       
   447 
       
   448             aEditor.InsertDeleteCharsL( iConvertArray[ i ]->Position(),
       
   449                                         iConvertArray[ i ]->SmileyString(),
       
   450                                         deleteSel );
       
   451             selectAdd += iConvertArray[ i ]->SmileyString().Length() - 1;
       
   452             aEditor.SetMaxLength( aEditor.MaxLength() + selectAdd );
       
   453             }
       
   454         }
       
   455     myDebug.Set( aEditor.Text()->Read( 0 ) );
       
   456     CHAT_DP( D_CHAT_LIT( "CCASmileyUtil::ConvertSelectionToStringL %S" ), &myDebug );
       
   457 
       
   458     aEditor.SetSelectionL( start, end + selectAdd );
       
   459     aEditor.TextView()->HandleGlobalChangeL();
       
   460 
       
   461     if ( !aPreserve )
       
   462         {
       
   463         iConvertArray.ResetAndDestroy();
       
   464         }
       
   465 
       
   466     CleanupStack::PopAndDestroy( text );
       
   467     }
       
   468 
       
   469 // ---------------------------------------------------------
       
   470 // CCASmileyUtil::DeleteExtensionL
       
   471 // (other items were commented in a header).
       
   472 // ---------------------------------------------------------
       
   473 //
       
   474 void CCASmileyUtil::DeleteExtensionL( CEikRichTextEditor& aEditor, TInt aPos )
       
   475     {
       
   476     // Set cursor position before deletion.
       
   477     // Deletion may cause editor size to change and if
       
   478     // cursor pos is not updated before that ETEXT 12 panic
       
   479     // is raised.
       
   480     aEditor.SetCursorPosL( aPos, EFalse );
       
   481     aEditor.RichText()->DeleteL( aPos, 1 );
       
   482     aEditor.HandleTextChangedL();
       
   483     // Needed to keep alignment of
       
   484     // cursor correct.
       
   485     aEditor.SetCursorPosL( aPos, EFalse );
       
   486 
       
   487     // update editors length, it grows by 2 when icon is deleted
       
   488     TInt textLimit = aEditor.MaxLength() + 2;
       
   489     aEditor.SetTextLimit( textLimit );
       
   490 
       
   491     --iCurrentCount;
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CCASmileyUtil::Reset
       
   496 // Reset extension
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 void CCASmileyUtil::Reset()
       
   500     {
       
   501     iCurrentCount = 0;
       
   502     }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CCASmileyUtil::SizeChanged
       
   506 // Reset extension
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 void CCASmileyUtil::SizeChanged( TSize& aSize )
       
   510     {
       
   511     iSmileUtil->ResizeIcons( aSize );
       
   512     }
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CCASmileyUtil::ConvertSelectionToStringL
       
   516 // Convert selection smileys to strings
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 void CCASmileyUtil::ConvertSelectionToStringL(
       
   520     CEikRichTextEditor& aEditor,
       
   521     TDes& aResultString,
       
   522     TCursorSelection& aSelectionAfterConversion,
       
   523     TBool aPreserve )
       
   524     {
       
   525     // Clear convert array
       
   526     iConvertArray.ResetAndDestroy();
       
   527 
       
   528     // Get text from editor
       
   529     HBufC* text = HBufC::NewMaxLC( IMUtils::MaxMsgLength() );
       
   530     TPtr textCopy( text->Des() );
       
   531     aEditor.GetText( textCopy );
       
   532 
       
   533     // For loop gets icon positions to array
       
   534     TInt start = aEditor.Selection().LowerPos();
       
   535     TInt end = aEditor.Selection().HigherPos();
       
   536 
       
   537     // Copy text to result string
       
   538     aResultString.Append( textCopy );
       
   539 
       
   540     TInt i = 0;
       
   541     for ( i = start; i < end; ++i )
       
   542         {
       
   543         if ( textCopy[i] ==  CEditableText::EPictureCharacter )
       
   544             {
       
   545             CCASmileyInformation* smileInfo = CCASmileyInformation::NewL();
       
   546             CleanupStack::PushL( smileInfo );
       
   547             smileInfo->SetPosition( i );
       
   548             smileInfo->SetIcon( ETrue );
       
   549             User::LeaveIfError( iConvertArray.Append( smileInfo ) );
       
   550             CleanupStack::Pop( smileInfo );
       
   551             }
       
   552         }
       
   553 
       
   554     TInt count = iConvertArray.Count();
       
   555     for ( i = count - 1; i >= 0; --i )
       
   556         {
       
   557         CPicture* editorPic = NULL;
       
   558 
       
   559         editorPic = aEditor.RichText()->PictureHandleL(
       
   560                         iConvertArray[i]->Position(), MLayDoc::EForceLoadTrue );
       
   561 
       
   562         if ( !editorPic )
       
   563             {
       
   564             User::Leave( KErrBadHandle );
       
   565             }
       
   566 
       
   567         CCAPicture* icon = static_cast<CCAPicture*> ( editorPic );
       
   568 
       
   569         const TDesC& iconString = iSmileUtil->GetSmileString( icon->Index() );
       
   570         iConvertArray[i]->SetSmileyStringL( iconString );
       
   571         iConvertArray[i]->SetIndex( icon->Index() );
       
   572         }
       
   573 
       
   574     textCopy.Delete( end, textCopy.Length() - end );
       
   575     textCopy.Delete( 0, start );
       
   576     iSmileUtil->SearchSmilesL( textCopy, iConvertArray, NULL, start );
       
   577 
       
   578     // Change icons to strings
       
   579     TInt selectAdd = 0;
       
   580     count = iConvertArray.Count();
       
   581     for ( i = count - 1; i >= 0; --i )
       
   582         {
       
   583         if ( iConvertArray[ i ]->IsIcon() ) // Icon
       
   584             {
       
   585             // Append smiley string to result
       
   586             aResultString.Delete( iConvertArray[i]->Position(), 1 );
       
   587             aResultString.Insert( iConvertArray[i]->Position(), iConvertArray[i]->SmileyString() );
       
   588             selectAdd += iConvertArray[ i ]->SmileyString().Length() - 1;
       
   589             }
       
   590         }
       
   591 
       
   592     if ( !aPreserve )
       
   593         {
       
   594         iConvertArray.ResetAndDestroy();
       
   595         }
       
   596 
       
   597     // Set correct selection
       
   598     aSelectionAfterConversion.SetSelection( end + selectAdd, start );
       
   599 
       
   600     CleanupStack::PopAndDestroy( text );
       
   601     }
       
   602 // End of File