emailuis/uicomponents/src/fstextviewervisualizerdata.cpp
branchRCL_3
changeset 64 3533d4323edc
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     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:  Storage class for visuals belonging to visualizer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail>
       
    20 //#include <fsconfig.h>
       
    21 #include "emailtrace.h"
       
    22 #include <alf/alfvisual.h>
       
    23 #include <alf/alftextvisual.h>
       
    24 #include <alf/alfimagevisual.h>
       
    25 #include <alf/alfanchorlayout.h>
       
    26 #include <alf/alfborderbrush.h>
       
    27 // </cmail>
       
    28 
       
    29 // <cmail>
       
    30 #include <alf/alfcontrol.h>
       
    31 #include <alf/alfbrusharray.h>
       
    32 // </cmail>
       
    33 #include "fstextviewervisualizerdata.h"
       
    34 #include "fstextparser.h"
       
    35 #include "fstexture.h"
       
    36 #include "fstextviewerselectsmanager.h"
       
    37 #include "fstextviewercoordinator.h"
       
    38 
       
    39 TAny* TKeyArrayPtr::At(TInt aIndex) const
       
    40     {
       
    41     FUNC_LOG;
       
    42     if (aIndex==KIndexPtr)
       
    43         {
       
    44         return *(TUint8**)iPtr+iKeyOffset;
       
    45         }
       
    46     return *(TUint8**)iBase->Ptr(aIndex*sizeof(TUint8**)).Ptr()+iKeyOffset;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // NewL
       
    51 // ---------------------------------------------------------------------------
       
    52 CFsTextViewerVisualizerData* CFsTextViewerVisualizerData::NewL( 
       
    53         CAlfControl* aControl, 
       
    54         CFsTextParser* aParser, 
       
    55         CFsTextViewerSelectsManager* aSelector )
       
    56     {
       
    57     FUNC_LOG;
       
    58     CFsTextViewerVisualizerData* self = 
       
    59         new (ELeave) CFsTextViewerVisualizerData( 
       
    60                 aControl, 
       
    61                 aParser, 
       
    62                 aSelector );
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // ~CFsTextViewerVisualizerData
       
    71 // ---------------------------------------------------------------------------
       
    72 CFsTextViewerVisualizerData::~CFsTextViewerVisualizerData()
       
    73     {
       
    74     FUNC_LOG;
       
    75     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
    76         {
       
    77         if ( iVisArray[i] && iVisArray[i]->iVisual && iSelector )
       
    78             {
       
    79             iSelector->RemoveVisual( iVisArray[i] );
       
    80             }
       
    81         }
       
    82     
       
    83     iVisArray.ResetAndDestroy();
       
    84 //    delete iDebugBrush;
       
    85     iVisArray.Close();
       
    86     iLayoutArray.Close();
       
    87     iBgArray.Close();
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // AppendVisualL
       
    92 // ---------------------------------------------------------------------------
       
    93 void CFsTextViewerVisualizerData::AppendVisualL( TFsRangedVisual aVisual )
       
    94     {
       
    95     FUNC_LOG;
       
    96     TFsRangedVisual* rVisual = new (ELeave) TFsRangedVisual();
       
    97     rVisual->iStart = aVisual.iStart;
       
    98     rVisual->iEnd = aVisual.iEnd;
       
    99     rVisual->iVisual = aVisual.iVisual;
       
   100     rVisual->iIsActive = aVisual.iIsActive;
       
   101     rVisual->iRect = aVisual.iRect;
       
   102     rVisual->iLayout = aVisual.iLayout;
       
   103     rVisual->iIsText = aVisual.iIsText;
       
   104     rVisual->iEmbed = aVisual.iEmbed;
       
   105     rVisual->iHotspot = aVisual.iHotspot;
       
   106     rVisual->iHotspotType = aVisual.iHotspotType;
       
   107     rVisual->iId = aVisual.iId;
       
   108     rVisual->iTextStyleId = aVisual.iTextStyleId;
       
   109     rVisual->iTextColor = aVisual.iTextColor;
       
   110     rVisual->iLineNumber = aVisual.iLineNumber;
       
   111 
       
   112     iVisArray.Append( rVisual );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // AppendVisualL
       
   117 // ---------------------------------------------------------------------------
       
   118 void CFsTextViewerVisualizerData::AppendVisualL( TFsRangedVisual* aVisual )
       
   119     {
       
   120     FUNC_LOG;
       
   121     iVisArray.Append( aVisual );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // AppendVisualL
       
   126 // ---------------------------------------------------------------------------
       
   127 void CFsTextViewerVisualizerData::AppendVisualL( 
       
   128         CAlfVisual* aVisual, 
       
   129         TFsVisRange aRange )
       
   130     {
       
   131     FUNC_LOG;
       
   132     TFsRangedVisual* visual = new (ELeave) TFsRangedVisual();
       
   133     visual->iVisual = aVisual;
       
   134     visual->iStart = aRange.iStart;
       
   135     visual->iEnd = aRange.iEnd;
       
   136     visual->iIsActive = ETrue;
       
   137 
       
   138     iVisArray.Append( visual );
       
   139     }
       
   140     
       
   141 // ---------------------------------------------------------------------------
       
   142 // AppendLayoutL
       
   143 // ---------------------------------------------------------------------------
       
   144 void CFsTextViewerVisualizerData::AppendLayoutL( 
       
   145         CAlfVisual* aVisual, 
       
   146         TFsVisRange aRange )
       
   147     {
       
   148     FUNC_LOG;
       
   149     TFsRangedVisual visual;
       
   150     visual.iVisual = aVisual;
       
   151     visual.iStart = aRange.iStart;
       
   152     visual.iEnd = aRange.iEnd;
       
   153     visual.iIsActive = ETrue;
       
   154 
       
   155     iLayoutArray.AppendL( visual );
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // AppendBgL
       
   160 // ---------------------------------------------------------------------------
       
   161 void CFsTextViewerVisualizerData::AppendBgL( TFsPartBgVisual aBg )
       
   162     {
       
   163     FUNC_LOG;
       
   164     iBgArray.AppendL( aBg );
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // RemoveBg
       
   169 // ---------------------------------------------------------------------------
       
   170 TBool CFsTextViewerVisualizerData::RemoveBg( CAlfVisual* aVisual )
       
   171     {
       
   172     FUNC_LOG;
       
   173     TBool retVal = EFalse;
       
   174     for ( TInt i = 0; i < iBgArray.Count(); ++i )
       
   175         {
       
   176         if ( iBgArray[i].iVisual == aVisual )
       
   177             {
       
   178             iBgArray.Remove( i );
       
   179             i = iBgArray.Count();
       
   180             retVal = ETrue;
       
   181             }
       
   182         }
       
   183     
       
   184     return retVal;
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // ResetBgArray
       
   189 // ---------------------------------------------------------------------------
       
   190 void CFsTextViewerVisualizerData::ResetBgArray()
       
   191     {
       
   192     FUNC_LOG;
       
   193     for ( TInt i =  0; i < iBgArray.Count(); ++i )
       
   194         {
       
   195         iBgArray[i].iVisual->RemoveAndDestroyAllD();
       
   196         }
       
   197     iBgArray.Reset();
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // InsertVisualL
       
   202 // ---------------------------------------------------------------------------
       
   203 void CFsTextViewerVisualizerData::InsertVisualL( TInt aIndex, 
       
   204                         CAlfVisual* aVisual, TFsVisRange aRange )
       
   205     {
       
   206     FUNC_LOG;
       
   207     TFsRangedVisual* visual = new (ELeave) TFsRangedVisual();
       
   208     visual->iVisual = aVisual;
       
   209     visual->iStart = aRange.iStart;
       
   210     visual->iEnd = aRange.iEnd;
       
   211     visual->iIsActive = ETrue;
       
   212 
       
   213     iVisArray.Insert( visual, aIndex );
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // PopVisual
       
   218 // ---------------------------------------------------------------------------
       
   219 void CFsTextViewerVisualizerData::PopVisual()
       
   220     {
       
   221     FUNC_LOG;
       
   222     iVisArray.Remove( iVisArray.Count() - 1 );
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // RemoveVisual
       
   227 // ---------------------------------------------------------------------------
       
   228 void CFsTextViewerVisualizerData::RemoveVisual( TInt aIndex )
       
   229     {
       
   230     FUNC_LOG;
       
   231     iVisArray.Remove( aIndex );
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // DisableVisual
       
   236 // ---------------------------------------------------------------------------
       
   237 void CFsTextViewerVisualizerData::DisableVisual( TInt aIndex, TBool aStatus )
       
   238     {
       
   239     FUNC_LOG;
       
   240     if ( aIndex >=0 && aIndex < iVisArray.Count() )
       
   241         {
       
   242         iVisArray[aIndex]->iIsActive = !aStatus;
       
   243         }
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // DisableVisual
       
   248 // ---------------------------------------------------------------------------
       
   249 void CFsTextViewerVisualizerData::DisableVisual( 
       
   250         CAlfVisual* aVisual, 
       
   251         TBool aStatus )
       
   252     {
       
   253     FUNC_LOG;
       
   254     TInt index = Find( aVisual );
       
   255     if ( index >= 0 && index < iVisArray.Count() )
       
   256         {
       
   257         iVisArray[index]->iIsActive = !aStatus;
       
   258         }
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // EnableVisual
       
   263 // ---------------------------------------------------------------------------
       
   264 void CFsTextViewerVisualizerData::EnableVisual( TInt aIndex, TBool aStatus )
       
   265     {
       
   266     FUNC_LOG;
       
   267     if ( aIndex >=0 && aIndex < iVisArray.Count() )
       
   268         {
       
   269         iVisArray[aIndex]->iIsActive = aStatus;
       
   270         }
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // EnableVisual
       
   275 // ---------------------------------------------------------------------------
       
   276 void CFsTextViewerVisualizerData::EnableVisual( 
       
   277         CAlfVisual* aVisual, 
       
   278         TBool aStatus )
       
   279     {
       
   280     FUNC_LOG;
       
   281     TInt index = Find( aVisual );
       
   282     if ( index >= 0 && index < iVisArray.Count() )
       
   283         {
       
   284         iVisArray[index]->iIsActive = aStatus;
       
   285         }
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // GetVisual
       
   290 // ---------------------------------------------------------------------------
       
   291 CAlfVisual* CFsTextViewerVisualizerData::GetVisual( TInt aIndex )
       
   292     {
       
   293     FUNC_LOG;
       
   294     CAlfVisual* retVal = NULL;
       
   295     if ( aIndex >= 0 && aIndex < iVisArray.Count() )
       
   296         {
       
   297         retVal = iVisArray[aIndex]->iVisual;
       
   298         }
       
   299 
       
   300     return retVal;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // GetVisLength
       
   305 // ---------------------------------------------------------------------------
       
   306 TInt CFsTextViewerVisualizerData::GetVisLength( TInt aIndex )
       
   307     {
       
   308     FUNC_LOG;
       
   309     TInt retVal = -1;
       
   310     
       
   311     if ( aIndex >= 0 && aIndex < iVisArray.Count() )
       
   312         {
       
   313         retVal = 
       
   314             iVisArray[aIndex]->iEnd - iVisArray[aIndex]->iStart + 1;
       
   315         }
       
   316     else
       
   317         {
       
   318         }
       
   319 
       
   320     return retVal;
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // GetVisStartOffset
       
   325 // ---------------------------------------------------------------------------
       
   326 TInt CFsTextViewerVisualizerData::GetVisStartOffset( TInt aIndex )
       
   327     {
       
   328     FUNC_LOG;
       
   329     TInt retVal = -1;
       
   330     if ( aIndex >= 0 && aIndex < iVisArray.Count() )
       
   331         {
       
   332         retVal = iVisArray[aIndex]->iStart;
       
   333         }
       
   334 
       
   335     return retVal;
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // GetVisEndOffset
       
   340 // ---------------------------------------------------------------------------
       
   341 TInt CFsTextViewerVisualizerData::GetVisEndOffset( TInt aIndex )
       
   342     {
       
   343     FUNC_LOG;
       
   344     TInt retVal = -1;
       
   345     if ( aIndex >= 0 && aIndex < iVisArray.Count() )
       
   346         {
       
   347         retVal = iVisArray[aIndex]->iEnd;
       
   348         }
       
   349         
       
   350     return retVal;
       
   351     }
       
   352     
       
   353 // ---------------------------------------------------------------------------
       
   354 // GetLayEndOffset
       
   355 // ---------------------------------------------------------------------------
       
   356 TInt CFsTextViewerVisualizerData::GetLayEndOffset( TInt aIndex )
       
   357     {
       
   358     FUNC_LOG;
       
   359     TInt retVal = -1;
       
   360     if ( aIndex >= 0 && aIndex < iLayoutArray.Count() )
       
   361         {
       
   362         retVal = iLayoutArray[aIndex].iEnd;
       
   363         }
       
   364         
       
   365     return retVal;
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------------------------
       
   369 // GetVisOffsets
       
   370 // ---------------------------------------------------------------------------
       
   371 TFsVisRange CFsTextViewerVisualizerData::GetVisOffsets( TInt aIndex )
       
   372     {
       
   373     FUNC_LOG;
       
   374     TFsVisRange retVal;
       
   375     retVal.iStart = 0;
       
   376     retVal.iEnd = 0;
       
   377     if ( aIndex >= 0 && aIndex < iVisArray.Count() )
       
   378         {
       
   379         retVal.iStart = iVisArray[aIndex]->iStart;
       
   380         retVal.iEnd = iVisArray[aIndex]->iEnd;
       
   381         }
       
   382 
       
   383     return retVal;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // Count
       
   388 // ---------------------------------------------------------------------------
       
   389 TInt CFsTextViewerVisualizerData::Count()
       
   390     {
       
   391     FUNC_LOG;
       
   392     return iVisArray.Count();
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // Find
       
   397 // ---------------------------------------------------------------------------
       
   398 TInt CFsTextViewerVisualizerData::Find( CAlfVisual* aVisual )
       
   399     {
       
   400     FUNC_LOG;
       
   401     TInt retVal = -1;
       
   402 
       
   403     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   404         {
       
   405         if ( iVisArray[i]->iVisual == aVisual )
       
   406             {
       
   407             retVal = i;
       
   408 //            i = iVisArray.Count();
       
   409             }
       
   410         }
       
   411 
       
   412     return retVal;
       
   413     }
       
   414     
       
   415 // ---------------------------------------------------------------------------
       
   416 // FindLayout
       
   417 // ---------------------------------------------------------------------------
       
   418 TInt CFsTextViewerVisualizerData::FindLayout( CAlfVisual* aVisual )
       
   419     {
       
   420     FUNC_LOG;
       
   421     TInt retVal = -1;
       
   422 
       
   423     for ( TInt i = 0; i < iLayoutArray.Count(); ++i )
       
   424         {
       
   425         if ( iLayoutArray[i].iVisual == aVisual )
       
   426             {
       
   427             retVal = i;
       
   428             i = iLayoutArray.Count();
       
   429             }
       
   430         }
       
   431 
       
   432     return retVal;
       
   433     }
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 // Find
       
   437 // ---------------------------------------------------------------------------
       
   438 TInt CFsTextViewerVisualizerData::Find( TInt aOffset )
       
   439     {
       
   440     FUNC_LOG;
       
   441     TInt retVal = -1;
       
   442     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   443         {
       
   444         if ( aOffset >= iVisArray[i]->iStart && aOffset <= 
       
   445                 iVisArray[i]->iEnd && iVisArray[i]->iIsActive )
       
   446             {
       
   447             retVal = i;
       
   448             }
       
   449         }
       
   450     return retVal;
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // MoveToNextCharL
       
   455 // ---------------------------------------------------------------------------
       
   456 TBool CFsTextViewerVisualizerData::MoveToNextCharL()
       
   457     {
       
   458     FUNC_LOG;
       
   459     TInt i;
       
   460     TInt maxChar = 0;
       
   461     for ( i = 0; i < iVisArray.Count(); ++i )
       
   462         {
       
   463         if ( iVisArray[i]->iIsActive 
       
   464                 && iVisArray[i]->iEnd > maxChar )
       
   465             {
       
   466             maxChar = iVisArray[i]->iEnd;
       
   467             }
       
   468         }
       
   469         
       
   470     if ( iCurrentChar >= maxChar - 1 )
       
   471         {
       
   472         return EFalse;
       
   473         }
       
   474         
       
   475     iPrevChar = iCurrentChar;
       
   476     TBool notFound = ETrue;
       
   477     ++iCurrentChar;
       
   478 
       
   479     if ( !iVisArray[iPosition.iVisual]->iVisual )
       
   480         {
       
   481         RestoreL( iVisArray[iPosition.iVisual] );
       
   482         }
       
   483 
       
   484     CAlfImageVisual* visual( dynamic_cast<CAlfImageVisual*>( iVisArray[iPosition.iVisual]->iVisual ) );
       
   485     if ( visual )
       
   486         {
       
   487         iCurrentChar = iVisArray[iPosition.iVisual]->iEnd + 1;
       
   488         }
       
   489     while ( notFound )
       
   490         {
       
   491         if ( iCurrentChar >= iLength )
       
   492             {
       
   493             notFound = EFalse;
       
   494             }
       
   495         for ( i = 0; i < iVisArray.Count(); ++i )
       
   496             {
       
   497             if ( iCurrentChar >= iVisArray[i]->iStart 
       
   498                     && iCurrentChar <= iVisArray[i]->iEnd )
       
   499                 {
       
   500                 if ( iVisArray[i]->iIsActive )
       
   501                     {
       
   502                     iPosition.iVisual = i;
       
   503                     iPosition.iOffset = 
       
   504                         iCurrentChar - iVisArray[i]->iStart;
       
   505                     notFound = EFalse;
       
   506                     }
       
   507                 else 
       
   508                     {
       
   509                     iCurrentChar = iVisArray[i]->iEnd + 1;
       
   510                     }
       
   511                 }
       
   512             }
       
   513         if ( notFound )
       
   514             {
       
   515             ++iCurrentChar;
       
   516             }
       
   517         }
       
   518     if ( iCurrentChar >= iLength )
       
   519             {
       
   520             iPosition.iVisual = iVisArray.Count() - 1;
       
   521             iPosition.iOffset = iVisArray[iVisArray.Count() - 1]->iEnd;
       
   522             }
       
   523 
       
   524     return ETrue;
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // MoveToPrevCharL
       
   529 // ---------------------------------------------------------------------------
       
   530 TBool CFsTextViewerVisualizerData::MoveToPrevCharL()
       
   531     {
       
   532     FUNC_LOG;
       
   533     if ( iCurrentChar == 0 )
       
   534         {
       
   535         return EFalse;
       
   536         }
       
   537     iPrevChar = iCurrentChar;
       
   538     TBool notFound = ETrue;
       
   539     TInt i;
       
   540     
       
   541     --iCurrentChar;
       
   542 
       
   543     if ( iPosition.iVisual >= 0 
       
   544             && iPosition.iVisual < iVisArray.Count() 
       
   545             && !iVisArray[iPosition.iVisual]->iVisual )
       
   546         {
       
   547         RestoreL( iVisArray[iPosition.iVisual] );
       
   548         }
       
   549 
       
   550     CAlfImageVisual* visual( NULL );
       
   551     if ( iPosition.iVisual >= 0 && iPosition.iVisual < iVisArray.Count() )
       
   552         {
       
   553         visual = dynamic_cast<CAlfImageVisual*>( iVisArray[iPosition.iVisual]->iVisual );
       
   554         }
       
   555     else
       
   556         {
       
   557         return EFalse;
       
   558         }
       
   559     if ( visual  )
       
   560         {
       
   561         iCurrentChar = iVisArray[iPosition.iVisual]->iStart - 1;
       
   562         }
       
   563     
       
   564     while ( notFound )
       
   565         {
       
   566         if ( iCurrentChar <= 0 )
       
   567             {
       
   568             notFound = EFalse;
       
   569             }
       
   570         for ( i = 0; i < iVisArray.Count(); ++i )
       
   571             {
       
   572             if ( iCurrentChar >= iVisArray[i]->iStart 
       
   573                     && iCurrentChar <= iVisArray[i]->iEnd )
       
   574                 {
       
   575                 if ( iVisArray[i]->iIsActive )
       
   576                     {
       
   577                     iPosition.iVisual = i;
       
   578                     iPosition.iOffset = 
       
   579                         iCurrentChar - iVisArray[i]->iStart;
       
   580                     notFound = EFalse;
       
   581                     }
       
   582                 else 
       
   583                     {
       
   584                     iCurrentChar = iVisArray[i]->iStart - 1;
       
   585                     }
       
   586                 }
       
   587             }
       
   588             if ( notFound )
       
   589                 {
       
   590                 --iCurrentChar;
       
   591                 }
       
   592         }
       
   593     if ( iCurrentChar <= 0 )
       
   594             {
       
   595             iPosition.iVisual = 0;
       
   596             iPosition.iOffset = 0;
       
   597             }
       
   598 
       
   599     return ETrue;
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // FindPrevChar
       
   604 // ---------------------------------------------------------------------------
       
   605 TInt CFsTextViewerVisualizerData::FindPrevChar()
       
   606     {
       
   607     FUNC_LOG;
       
   608     TInt retVal = -1;
       
   609 
       
   610     TInt current = iCurrentChar - 1;
       
   611     TBool notFound = ETrue;
       
   612 
       
   613     while ( notFound && current >= 0 )
       
   614         {
       
   615         if ( 0 > Find( current ) )
       
   616             {
       
   617             --current;
       
   618             }
       
   619         else
       
   620             {
       
   621             retVal = current;
       
   622             notFound = EFalse;
       
   623             }
       
   624         }
       
   625 
       
   626     return retVal;
       
   627     }
       
   628 
       
   629 // ---------------------------------------------------------------------------
       
   630 // GetCursorRectL
       
   631 // ---------------------------------------------------------------------------
       
   632 TRect CFsTextViewerVisualizerData::GetCursorRectL()
       
   633     {
       
   634     FUNC_LOG;
       
   635     TRect retVal;
       
   636     if ( iPosition.iVisual < 0 || iPosition.iVisual >= iVisArray.Count() )
       
   637         {
       
   638         return retVal;
       
   639         }
       
   640     if ( !iVisArray[iPosition.iVisual]->iVisual )
       
   641         {
       
   642         RestoreL( iVisArray[iPosition.iVisual] );
       
   643         }
       
   644 
       
   645     CAlfTextVisual* textVisual( dynamic_cast<CAlfTextVisual*>( iVisArray[iPosition.iVisual]->iVisual ) );
       
   646     if ( textVisual )
       
   647         {
       
   648         retVal = static_cast<CAlfTextVisual*>
       
   649             ( iVisArray[iPosition.iVisual]->iVisual )->
       
   650                 SubstringExtents( iPosition.iOffset, iPosition.iOffset + 1 );
       
   651         }
       
   652     else
       
   653         {
       
   654         retVal = TRect( 
       
   655             TPoint( 0, 0 ),
       
   656             iVisArray[iPosition.iVisual]->iVisual->Size().Target() );
       
   657         }
       
   658 
       
   659     TPoint translation; 
       
   660     translation = 
       
   661         iVisArray[iPosition.iVisual]->iVisual->DisplayRectTarget().iTl;
       
   662     retVal.Move( translation );
       
   663 
       
   664     return retVal;
       
   665     }
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // GetCursorCharOffset
       
   669 // ---------------------------------------------------------------------------
       
   670 TInt CFsTextViewerVisualizerData::GetCursorCharOffset()
       
   671     {
       
   672     FUNC_LOG;
       
   673     return iCurrentChar;
       
   674     }
       
   675 
       
   676 // ---------------------------------------------------------------------------
       
   677 // SetCursorCharOffset
       
   678 // ---------------------------------------------------------------------------
       
   679 void CFsTextViewerVisualizerData::SetCursorCharOffset( TInt aOffset )
       
   680     {
       
   681     FUNC_LOG;
       
   682     iCurrentChar = aOffset;
       
   683     }
       
   684 
       
   685 // ---------------------------------------------------------------------------
       
   686 // Sort
       
   687 // ---------------------------------------------------------------------------
       
   688 void CFsTextViewerVisualizerData::Sort()
       
   689     {
       
   690     FUNC_LOG;
       
   691     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   692         {
       
   693         if ( iVisArray[i]->iEnd > iLength )
       
   694             {
       
   695             iLength = iVisArray[i]->iEnd;
       
   696             }
       
   697         }   
       
   698     }
       
   699 
       
   700 // ---------------------------------------------------------------------------
       
   701 // RestoreL
       
   702 // ---------------------------------------------------------------------------
       
   703 TInt CFsTextViewerVisualizerData::RestoreL( TFsRangedVisual* aVisual )
       
   704     {
       
   705     FUNC_LOG;
       
   706     if ( !aVisual || aVisual->iVisual || iVisualAmount > 300 )
       
   707         {
       
   708         return KErrNone;
       
   709         }
       
   710 
       
   711     CAlfVisual* visual = NULL;
       
   712 //    CFsTexture *texture = NULL;
       
   713     if ( aVisual->iIsText )
       
   714         {
       
   715         visual = CAlfTextVisual::AddNewL( *iControl, aVisual->iLayout );
       
   716         HBufC* text;
       
   717         text = iParser->GetTextL( 
       
   718                 aVisual->iStart, 
       
   719                 aVisual->iEnd );
       
   720         
       
   721         static_cast<CAlfTextVisual*>(visual)->SetTextL( text->Des() );
       
   722         delete text;
       
   723 
       
   724         static_cast<CAlfTextVisual*>(visual)->SetTextStyle( aVisual->iTextStyleId );
       
   725         static_cast<CAlfTextVisual*>(visual)->EnableShadow( EFalse );
       
   726         static_cast<CAlfTextVisual*>(visual)->SetColor(
       
   727                 aVisual->iTextColor );
       
   728         if ( aVisual->iDirection == TBidiText::ELeftToRight )
       
   729             {
       
   730         static_cast<CAlfTextVisual*>(visual)->SetAlign( EAlfAlignHLeft, EAlfAlignVBottom );
       
   731             }
       
   732         else 
       
   733             {
       
   734             static_cast<CAlfTextVisual*>(visual)->SetAlign( EAlfAlignHRight, EAlfAlignVBottom );
       
   735             }
       
   736 //        visual->EnableBrushesL();
       
   737 //        visual->Brushes()->AppendL( iDebugBrush, EAlfDoesNotHaveOwnership );
       
   738         visual->SetRect( aVisual->iRect );
       
   739         aVisual->iVisual = visual;
       
   740         }
       
   741     else
       
   742         {
       
   743         visual = CAlfImageVisual::AddNewL( *iControl, aVisual->iLayout );
       
   744 
       
   745         static_cast<CAlfImageVisual*>(visual)->SetScaleMode( 
       
   746                 CAlfImageVisual::EScaleFit );
       
   747         static_cast<CAlfImageVisual*>(visual)->SetImage( TAlfImage( 
       
   748             ( ( iParser->GetTextureL( aVisual->iStart ) ).Texture() ) ) );
       
   749         visual->SetRect( aVisual->iRect );
       
   750         aVisual->iVisual = visual;
       
   751         }
       
   752 
       
   753     visual->SetFlag( EAlfVisualFlagManualLayout );
       
   754     ++iVisualAmount;
       
   755 
       
   756     if ( aVisual->iEmbed )
       
   757         {
       
   758         iSelector->AppendSelectVisL( 
       
   759                  aVisual,
       
   760                  aVisual->iId,
       
   761                  CFsTextViewerSelect::EFsEmbedType );
       
   762         }
       
   763     else if ( aVisual->iHotspot )
       
   764         {
       
   765         if ( 0 == aVisual->iHotspotType )
       
   766             {
       
   767             iSelector->AppendSelectVisL(
       
   768                      aVisual,
       
   769                      aVisual->iId,
       
   770                      CFsTextViewerSelect::EFsHotspotType );
       
   771             }
       
   772         else 
       
   773             {
       
   774             iSelector->AppendSelectVisL( 
       
   775                      aVisual, 
       
   776                      aVisual->iId,
       
   777                      CFsTextViewerSelect::EFsLineType );
       
   778             }
       
   779         }
       
   780         
       
   781     return KErrNone;
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------------------------
       
   785 // ScrollAllL
       
   786 // ---------------------------------------------------------------------------
       
   787 void CFsTextViewerVisualizerData::ScrollAllL( 
       
   788         TInt aTrans, 
       
   789         TInt aTime, 
       
   790         CAlfLayout* aRootLayout )
       
   791     {
       
   792     FUNC_LOG;
       
   793     aRootLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
   794     TRect visibleRect = TRect( 0, 0, 500, iScreenHeight );
       
   795     
       
   796     TInt heightBuffer = 0;
       
   797     if ( aTime != 0 )
       
   798         {
       
   799         visibleRect.iTl.iY -= Abs( aRootLayout->ScrollOffset().iY.ValueNow() - iScreenOffset );
       
   800         visibleRect.iBr.iY += Abs( aRootLayout->ScrollOffset().iY.ValueNow() - iScreenOffset );
       
   801         heightBuffer = Abs( aTrans );
       
   802         }
       
   803     else 
       
   804         {
       
   805         HideAll();
       
   806         visibleRect.Move( 0, -aTrans );
       
   807         }
       
   808     visibleRect.Move( 0, iScreenOffset );
       
   809     iScreenOffset -= aTrans;
       
   810     
       
   811     
       
   812     iScrollDirection = aTrans < 0 ? EFsScrollDown : EFsScrollUp;
       
   813     
       
   814     TFsRangedVisual* current = NULL;
       
   815     
       
   816     if ( iScrollDirection == EFsScrollDown )
       
   817         {
       
   818         visibleRect.iBr.iY += heightBuffer;
       
   819         for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   820             {
       
   821             current = iVisArray[i];
       
   822             if ( visibleRect.Intersects( current->iRect ) || current->iLayout != aRootLayout )
       
   823                 {
       
   824                 if ( !current->iVisual )
       
   825                     {
       
   826                     RestoreL( current );
       
   827                     }
       
   828                 }
       
   829             else
       
   830                 {
       
   831                 if ( current->iVisual )
       
   832                     {
       
   833                     current->iVisual->RemoveAndDestroyAllD();
       
   834                     current->iVisual = NULL;
       
   835                     --iVisualAmount;
       
   836                     }   
       
   837                 }
       
   838             }        
       
   839         }
       
   840     else
       
   841         {
       
   842         visibleRect.iTl.iY -= heightBuffer;
       
   843         for ( TInt i = iVisArray.Count() - 1; i >= 0; --i )
       
   844             {
       
   845             current = iVisArray[i];
       
   846             if ( visibleRect.Intersects( current->iRect ) || current->iLayout != aRootLayout )
       
   847                 {
       
   848                 if ( !current->iVisual )
       
   849                     {
       
   850                     RestoreL( current );
       
   851                     }
       
   852                 }
       
   853             else
       
   854                 {
       
   855                 if ( current->iVisual )
       
   856                     {
       
   857                     current->iVisual->RemoveAndDestroyAllD();
       
   858                     current->iVisual = NULL;
       
   859                     --iVisualAmount;
       
   860                     }                        
       
   861                 }
       
   862             }
       
   863         }
       
   864     TAlfTimedPoint offset;
       
   865     offset.iY.SetTarget( iScreenOffset, aTime );
       
   866     aRootLayout->SetScrollOffset( offset );
       
   867     aRootLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
   868     iStatusLineLayout->SetPos( TPoint( 0, GetTotalHeight() - iStatusLineLayout->Size().Target().iY ) );
       
   869     RefreshSelectsL();
       
   870     }
       
   871 
       
   872 // ---------------------------------------------------------------------------
       
   873 // GetTextStyle
       
   874 // ---------------------------------------------------------------------------
       
   875 TInt CFsTextViewerVisualizerData::GetTextStyle( CAlfTextVisual* aVisual )
       
   876     {
       
   877     FUNC_LOG;
       
   878     TInt retVal = 0;
       
   879     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   880         {
       
   881         if ( aVisual == iVisArray[i]->iVisual )
       
   882             {
       
   883             retVal = iVisArray[i]->iTextStyleId;
       
   884             i = iVisArray.Count();
       
   885             }
       
   886         }
       
   887     return retVal;
       
   888     }
       
   889 
       
   890 // ---------------------------------------------------------------------------
       
   891 // DimAllHotspots
       
   892 // ---------------------------------------------------------------------------
       
   893 void CFsTextViewerVisualizerData::DimAllHotspotsL()
       
   894     {
       
   895     FUNC_LOG;
       
   896     iSelector->DimAllL();
       
   897     }
       
   898 
       
   899 // ---------------------------------------------------------------------------
       
   900 // RefreshSelects
       
   901 // ---------------------------------------------------------------------------
       
   902 void CFsTextViewerVisualizerData::RefreshSelectsL()
       
   903     {
       
   904     FUNC_LOG;
       
   905     iSelector->RefreshSelectionL();
       
   906     }
       
   907 
       
   908 // ---------------------------------------------------------------------------
       
   909 // GetVisualPos
       
   910 // ---------------------------------------------------------------------------
       
   911 TRect CFsTextViewerVisualizerData::GetVisualPos( TInt aCharIndex )
       
   912     {
       
   913     FUNC_LOG;
       
   914     TRect retVal;
       
   915     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   916         {
       
   917         if ( aCharIndex >= iVisArray[i]->iStart 
       
   918                 && aCharIndex <= iVisArray[i]->iEnd )
       
   919             {
       
   920             retVal = iVisArray[i]->iRect;
       
   921             i = iVisArray.Count();
       
   922             }
       
   923         }
       
   924     return retVal;
       
   925     }
       
   926 
       
   927 // ---------------------------------------------------------------------------
       
   928 // GetVisualAtIndex
       
   929 // ---------------------------------------------------------------------------
       
   930 TFsRangedVisual* CFsTextViewerVisualizerData::GetVisualAtIndex( TInt aIndex )
       
   931     {
       
   932     FUNC_LOG;
       
   933     TFsRangedVisual* retVal = NULL;
       
   934     if ( aIndex >= 0 && aIndex < iVisArray.Count() )
       
   935         {
       
   936         retVal = iVisArray[aIndex];
       
   937         }
       
   938 
       
   939     return retVal;
       
   940     }
       
   941 
       
   942 // ---------------------------------------------------------------------------
       
   943 // ScrollFromCharL //<cmail> leaving
       
   944 // ---------------------------------------------------------------------------
       
   945 void CFsTextViewerVisualizerData::ScrollFromCharL( //<cmail> leaving
       
   946         TInt aCharIndex, 
       
   947         TInt aTrans, 
       
   948         TInt aTime,
       
   949         CAlfLayout* aRootLayout )
       
   950     {
       
   951     FUNC_LOG;
       
   952     aRootLayout->SetFlag( EAlfVisualFlagFreezeLayout );
       
   953     TRect visibleRect = TRect( 0, 0, 500, iScreenHeight + Abs( aTrans ) );
       
   954     visibleRect.iTl.iY -= Abs( aRootLayout->ScrollOffset().iY.ValueNow() );
       
   955     visibleRect.iBr.iY += Abs( aRootLayout->ScrollOffset().iY.ValueNow() );
       
   956     visibleRect.Move( 0, iScreenOffset );
       
   957     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   958         {
       
   959         if ( iVisArray[i]->iStart > aCharIndex )
       
   960             {
       
   961             if ( visibleRect.Intersects( iVisArray[i]->iRect ) )
       
   962                 {
       
   963                 RestoreL( iVisArray[i] );
       
   964                 }
       
   965             iVisArray[i]->iRect.iTl.iY += aTrans;
       
   966             iVisArray[i]->iRect.iBr.iY += aTrans;
       
   967             if ( iVisArray[i]->iVisual )
       
   968                 {
       
   969                 iVisArray[i]->iVisual->Move( TPoint( 0, aTrans ), aTime );
       
   970                 }
       
   971             }
       
   972         }
       
   973     aRootLayout->ClearFlag( EAlfVisualFlagFreezeLayout );
       
   974     }
       
   975 
       
   976 // ---------------------------------------------------------------------------
       
   977 // SetScreenHeight
       
   978 // ---------------------------------------------------------------------------
       
   979 void CFsTextViewerVisualizerData::SetScreenHeight( TInt aScreenHeight )
       
   980     {
       
   981     FUNC_LOG;
       
   982     iScreenHeight = aScreenHeight;
       
   983     iTopBorder = -1 * iScreenHeight;
       
   984     iBottomBorder = 2 * iScreenHeight;
       
   985     }
       
   986 
       
   987 // ---------------------------------------------------------------------------
       
   988 // GetVisualWithChar
       
   989 // ---------------------------------------------------------------------------
       
   990 TFsRangedVisual* CFsTextViewerVisualizerData::GetVisualWithChar( 
       
   991         TInt aCharIndex )
       
   992     {
       
   993     FUNC_LOG;
       
   994     TFsRangedVisual* retVal = NULL;
       
   995 
       
   996     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
   997         {
       
   998         if ( iVisArray[i]->iStart <= aCharIndex 
       
   999                 && iVisArray[i]->iEnd >= aCharIndex )
       
  1000             {
       
  1001             retVal = iVisArray[i];
       
  1002             i = iVisArray.Count();
       
  1003             }
       
  1004         }
       
  1005 
       
  1006     return retVal;
       
  1007     }
       
  1008 
       
  1009 // ---------------------------------------------------------------------------
       
  1010 // GetFirstVisible
       
  1011 // ---------------------------------------------------------------------------
       
  1012 TFsRangedVisual* CFsTextViewerVisualizerData::GetFirstVisible()
       
  1013     {
       
  1014     FUNC_LOG;
       
  1015     TFsRangedVisual* retVal = NULL;
       
  1016 
       
  1017     if ( iVisArray.Count() > 0 )
       
  1018         {
       
  1019         retVal = iVisArray[0];
       
  1020         }
       
  1021     
       
  1022     if(retVal) // Coverity error fix, retVal could be NULL and used
       
  1023         {
       
  1024         for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1025             {
       
  1026             if ( iVisArray[i]->iRect.iTl.iY >= iScreenOffset )
       
  1027                 {
       
  1028                 if ( iVisArray[i]->iRect.iTl.iY < retVal->iRect.iTl.iY )
       
  1029                     {
       
  1030                     retVal = iVisArray[i];
       
  1031                     }
       
  1032                 else if ( iVisArray[i]->iRect.iTl.iY 
       
  1033                         == retVal->iRect.iTl.iY )
       
  1034                     {
       
  1035                     if ( iVisArray[i]->iRect.iTl.iX < retVal->iRect.iTl.iX )
       
  1036                         {
       
  1037                         retVal = iVisArray[i];
       
  1038                         }
       
  1039                     }
       
  1040                 else if ( retVal->iRect.iTl.iY < iScreenOffset )
       
  1041                     {
       
  1042                     retVal = iVisArray[i];
       
  1043                     }
       
  1044                 }
       
  1045             }
       
  1046         }
       
  1047     return retVal;
       
  1048     }
       
  1049 
       
  1050 // ---------------------------------------------------------------------------
       
  1051 // GetLastVisible
       
  1052 // ---------------------------------------------------------------------------
       
  1053 TFsRangedVisual* CFsTextViewerVisualizerData::GetLastVisible()
       
  1054     {
       
  1055     FUNC_LOG;
       
  1056     TFsRangedVisual* retVal = NULL;
       
  1057 
       
  1058     if ( iVisArray.Count() > 0 )
       
  1059         {
       
  1060         retVal = iVisArray[0];
       
  1061         }
       
  1062     if(retVal) // Coverity error fix, retval could be null and used
       
  1063         {
       
  1064         for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1065             {
       
  1066             if ( iVisArray[i]->iRect.iBr.iY <= iScreenOffset + iScreenHeight )
       
  1067                 {
       
  1068                 if ( iVisArray[i]->iRect.iBr.iY > retVal->iRect.iBr.iY )
       
  1069                     {
       
  1070                     retVal = iVisArray[i];
       
  1071                     }
       
  1072                 else if ( iVisArray[i]->iRect.iBr.iY 
       
  1073                         == retVal->iRect.iBr.iY )
       
  1074                     {
       
  1075                     if ( iVisArray[i]->iRect.iBr.iX > retVal->iRect.iBr.iX )
       
  1076                         {
       
  1077                         retVal = iVisArray[i];
       
  1078                         }
       
  1079                     }
       
  1080                 else 
       
  1081                     {
       
  1082                     }
       
  1083                 }
       
  1084             }
       
  1085         }
       
  1086     return retVal;
       
  1087     }
       
  1088 
       
  1089 // ---------------------------------------------------------------------------
       
  1090 // GetRangedVisual
       
  1091 // ---------------------------------------------------------------------------
       
  1092 TFsRangedVisual* CFsTextViewerVisualizerData::GetRangedVisual( 
       
  1093         CAlfVisual* aVisual )
       
  1094     {
       
  1095     FUNC_LOG;
       
  1096     TFsRangedVisual* retVal = NULL;
       
  1097     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1098         {
       
  1099         if ( iVisArray[i]->iVisual == aVisual )
       
  1100             {
       
  1101             retVal = iVisArray[i];
       
  1102             }
       
  1103         }
       
  1104 
       
  1105     return retVal;
       
  1106     }
       
  1107 
       
  1108 // ---------------------------------------------------------------------------
       
  1109 // UpdateLinesNumbers
       
  1110 // ---------------------------------------------------------------------------
       
  1111 void CFsTextViewerVisualizerData::UpdateLinesNumbers()
       
  1112     {
       
  1113     FUNC_LOG;
       
  1114     TInt lastLine = 1;
       
  1115     TInt i = 0;
       
  1116     if ( iVisArray.Count() <= 0 )
       
  1117         {
       
  1118         return;
       
  1119         }
       
  1120     do 
       
  1121         {
       
  1122         if ( iVisArray[i]->iIsActive )
       
  1123             {
       
  1124             lastLine = iVisArray[i]->iLineNumber;
       
  1125             }
       
  1126         ++i;
       
  1127         } while (
       
  1128                 i < iVisArray.Count()
       
  1129                 && ( iVisArray[i]->iLineNumber == lastLine
       
  1130                     || iVisArray[i]->iLineNumber == lastLine + 1 )
       
  1131                 );
       
  1132 
       
  1133     TInt lineNumber = lastLine;
       
  1134     for ( ; i < iVisArray.Count(); ++i )
       
  1135         {
       
  1136         if ( iVisArray[i]->iIsActive )
       
  1137             {
       
  1138             if ( iVisArray[i]->iLineNumber != lastLine )
       
  1139                 {
       
  1140                 ++lineNumber;
       
  1141                 }
       
  1142             lastLine = iVisArray[i]->iLineNumber;
       
  1143             iVisArray[i]->iLineNumber = lineNumber;
       
  1144             }
       
  1145         }
       
  1146     }
       
  1147 
       
  1148 // ---------------------------------------------------------------------------
       
  1149 // GetTotalLines
       
  1150 // ---------------------------------------------------------------------------
       
  1151 TInt CFsTextViewerVisualizerData::GetTotalLines()
       
  1152     {
       
  1153     FUNC_LOG;
       
  1154     TInt retVal = 0;
       
  1155     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1156         {
       
  1157         if ( iVisArray[i]->iIsActive 
       
  1158                 && iVisArray[i]->iLineNumber > retVal )
       
  1159             {
       
  1160             retVal = iVisArray[i]->iLineNumber;
       
  1161             }
       
  1162         }
       
  1163     return retVal;
       
  1164     }
       
  1165 
       
  1166 // ---------------------------------------------------------------------------
       
  1167 // RemoveFromLine
       
  1168 // ---------------------------------------------------------------------------
       
  1169 TInt CFsTextViewerVisualizerData::RemoveFromLineL( 
       
  1170         TInt aLineNumber, 
       
  1171         CFsTextViewerCoordinator* aHelper )
       
  1172     {
       
  1173     FUNC_LOG;
       
  1174     TInt retVal = GetFirstCharInLine( aLineNumber );
       
  1175     if ( GetCursorCharOffset() >= retVal )
       
  1176         {
       
  1177         while ( GetCursorCharOffset() >= retVal || GetCursorCharOffset() == 0 )
       
  1178             {
       
  1179             MoveToPrevCharL();
       
  1180             }
       
  1181         SetCursorCharOffset( retVal - 1 );
       
  1182         }
       
  1183     
       
  1184     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1185         {
       
  1186         if ( iVisArray[i]->iLineNumber >= aLineNumber )
       
  1187             {
       
  1188             if ( iVisArray[i]->iVisual )
       
  1189                 {
       
  1190                 iSelector->RemoveVisual( iVisArray[i] );
       
  1191                 iVisArray[i]->iVisual->RemoveAndDestroyAllD();
       
  1192                 iVisArray[i]->iVisual = NULL;
       
  1193                 }
       
  1194             aHelper->RemoveRect( iVisArray[i]->iRect );
       
  1195             delete iVisArray[i];
       
  1196             iVisArray.Remove(i);
       
  1197             --i;
       
  1198             }
       
  1199         }
       
  1200 
       
  1201     return retVal;
       
  1202     }
       
  1203 
       
  1204 // ---------------------------------------------------------------------------
       
  1205 // GetFirstCharInLine - gets the first character in line position
       
  1206 // ---------------------------------------------------------------------------
       
  1207 TInt CFsTextViewerVisualizerData::GetFirstCharInLine( TInt aLineNumber )
       
  1208     {
       
  1209     FUNC_LOG;
       
  1210     TInt retVal = iLength;
       
  1211     for ( TInt i = 0; i < iVisArray.Count(); ++i ) 
       
  1212         {
       
  1213         if ( iVisArray[i]->iLineNumber == aLineNumber  
       
  1214                 && iVisArray[i]->iStart < retVal )
       
  1215             {
       
  1216             retVal = iVisArray[i]->iStart;
       
  1217             }
       
  1218         }
       
  1219     return retVal;
       
  1220     }
       
  1221 
       
  1222 // <cmail>
       
  1223 // ---------------------------------------------------------------------------
       
  1224 // GetCharLineNumber - returns line number for character position (offset)
       
  1225 // ---------------------------------------------------------------------------
       
  1226 TInt CFsTextViewerVisualizerData::GetCharLineNumber( TInt aCharNumber )
       
  1227     {
       
  1228     FUNC_LOG;
       
  1229     TInt retVal = -1;
       
  1230     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1231         {
       
  1232         if ( iVisArray[i]->iStart <= aCharNumber  && aCharNumber <= iVisArray[i]->iEnd )
       
  1233             {
       
  1234             retVal = iVisArray[i]->iLineNumber;
       
  1235             i = iVisArray.Count();
       
  1236             }
       
  1237         }
       
  1238     return retVal;
       
  1239     }
       
  1240 // </cmail>
       
  1241 // ---------------------------------------------------------------------------
       
  1242 // SetParser
       
  1243 // ---------------------------------------------------------------------------
       
  1244 void CFsTextViewerVisualizerData::SetParser( CFsTextParser* aParser )
       
  1245     {
       
  1246     FUNC_LOG;
       
  1247     iParser = aParser;
       
  1248     }
       
  1249 
       
  1250 // ---------------------------------------------------------------------------
       
  1251 // FindAndHighlightHotspotL
       
  1252 // ---------------------------------------------------------------------------
       
  1253 void CFsTextViewerVisualizerData::FindAndHighlightHotspotL( TInt aLine )
       
  1254     {
       
  1255     FUNC_LOG;
       
  1256     TFsRangedVisual* visualFound = NULL;
       
  1257     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1258         {
       
  1259         if ( iVisArray[i]->iLineNumber == aLine )
       
  1260             {
       
  1261             if ( ( !visualFound 
       
  1262                         || visualFound->iStart > iVisArray[i]->iStart ) 
       
  1263                     && ( iVisArray[i]->iHotspot 
       
  1264                         ||  iVisArray[i]->iEmbed ) )
       
  1265                 {
       
  1266                 visualFound = iVisArray[i];
       
  1267                 }
       
  1268             }
       
  1269         }
       
  1270     
       
  1271     if ( visualFound )
       
  1272         {
       
  1273         iSelector->SelectL( visualFound->iId );
       
  1274         }
       
  1275     }
       
  1276 
       
  1277 // ---------------------------------------------------------------------------
       
  1278 // GetCursorLine
       
  1279 // ---------------------------------------------------------------------------
       
  1280 TInt CFsTextViewerVisualizerData::GetCursorLine()
       
  1281     {
       
  1282     FUNC_LOG;
       
  1283     TInt retVal = -1;
       
  1284     if ( iPosition.iVisual >= 0 && iPosition.iVisual < iVisArray.Count() )
       
  1285         {
       
  1286         retVal = iVisArray[iPosition.iVisual]->iLineNumber;
       
  1287         }
       
  1288     return retVal;
       
  1289     }
       
  1290 
       
  1291 // ---------------------------------------------------------------------------
       
  1292 // ReloadPicturesL
       
  1293 // ---------------------------------------------------------------------------
       
  1294 void CFsTextViewerVisualizerData::ReloadPicturesL( TInt aLine )
       
  1295     {
       
  1296     FUNC_LOG;
       
  1297     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1298         {
       
  1299         if ( ( iVisArray[i]->iVisual 
       
  1300                     && !iVisArray[i]->iIsText ) 
       
  1301                 && ( aLine == -1 
       
  1302                     || iVisArray[i]->iLineNumber == aLine ) )
       
  1303             {
       
  1304             iVisArray[i]->iVisual->RemoveAndDestroyAllD();
       
  1305             iVisArray[i]->iVisual = NULL;
       
  1306             RestoreL( iVisArray[i] );
       
  1307             }
       
  1308         }
       
  1309     }
       
  1310 
       
  1311 // ---------------------------------------------------------------------------
       
  1312 // GetTotalHeight
       
  1313 // ---------------------------------------------------------------------------
       
  1314 TInt CFsTextViewerVisualizerData::GetTotalHeight()
       
  1315     {
       
  1316     FUNC_LOG;
       
  1317     TInt retVal = 0;
       
  1318     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1319         {
       
  1320         if ( iVisArray[i]->iRect.iBr.iY > retVal )
       
  1321             {
       
  1322             retVal = iVisArray[i]->iRect.iBr.iY; 
       
  1323             }
       
  1324         }
       
  1325 
       
  1326     retVal += iStatusLineLayout->Size().ValueNow().iY;
       
  1327 
       
  1328     return retVal;
       
  1329     }
       
  1330 
       
  1331 // ---------------------------------------------------------------------------
       
  1332 // HideActionButtonFromCurrentHighlightedHotspot
       
  1333 // ---------------------------------------------------------------------------
       
  1334 void CFsTextViewerVisualizerData
       
  1335 ::HideActionButtonFromCurrentHighlightedHotspot()
       
  1336     {
       
  1337     if(iSelector && iSelector->IsHotspotHighlighted())
       
  1338         {
       
  1339         iSelector->HideActionButtonFromCurrentHighlightedHotspot();
       
  1340         }
       
  1341     }
       
  1342 
       
  1343 // ---------------------------------------------------------------------------
       
  1344 // ShowActionButtonForCurrentHighlightedHotspotL
       
  1345 // ---------------------------------------------------------------------------
       
  1346 void CFsTextViewerVisualizerData
       
  1347 ::ShowActionButtonForCurrentHighlightedHotspotL()
       
  1348     {
       
  1349     if(iSelector && iSelector->IsHotspotHighlighted())
       
  1350         {
       
  1351         iSelector->ShowActionButtonForCurrentHighlightedHotspotL();
       
  1352         }
       
  1353     }
       
  1354 
       
  1355 // ---------------------------------------------------------------------------
       
  1356 // HideAll
       
  1357 // ---------------------------------------------------------------------------
       
  1358 void CFsTextViewerVisualizerData::HideAll()
       
  1359     {
       
  1360     FUNC_LOG;
       
  1361     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1362         {
       
  1363         if ( iVisArray[i]->iVisual )
       
  1364             {
       
  1365             iVisArray[i]->iVisual->RemoveAndDestroyAllD();
       
  1366             iVisArray[i]->iVisual = NULL;
       
  1367             --iVisualAmount;
       
  1368             }
       
  1369         }
       
  1370     }
       
  1371 
       
  1372 // ---------------------------------------------------------------------------
       
  1373 // RestoreVisibleL
       
  1374 // ---------------------------------------------------------------------------
       
  1375 void CFsTextViewerVisualizerData::RestoreVisibleL()
       
  1376     {
       
  1377     FUNC_LOG;
       
  1378     TRect visibleArea = TRect( 0, 0, 500, iScreenHeight );
       
  1379     visibleArea.Move( 0, iScreenOffset );
       
  1380     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1381         {
       
  1382         if ( visibleArea.Intersects( iVisArray[i]->iRect ) )
       
  1383             {
       
  1384             RestoreL( iVisArray[i] );
       
  1385             }
       
  1386         }
       
  1387     }
       
  1388 
       
  1389 // ---------------------------------------------------------------------------
       
  1390 // RegisterHotspotsL
       
  1391 // ---------------------------------------------------------------------------
       
  1392 void CFsTextViewerVisualizerData::RegisterHotspotsL()
       
  1393     {
       
  1394     FUNC_LOG;
       
  1395     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1396         {
       
  1397         if ( iVisArray[i]->iEmbed )
       
  1398             {
       
  1399             iSelector->AppendSelectVisL( 
       
  1400                     iVisArray[i],
       
  1401                     iVisArray[i]->iId,
       
  1402                      CFsTextViewerSelect::EFsEmbedType );
       
  1403             }
       
  1404         else if ( iVisArray[i]->iHotspot )
       
  1405             {
       
  1406             if ( 0 == iVisArray[i]->iHotspotType )
       
  1407                 {
       
  1408                 iSelector->AppendSelectVisL(
       
  1409                         iVisArray[i],
       
  1410                         iVisArray[i]->iId,
       
  1411                          CFsTextViewerSelect::EFsHotspotType );
       
  1412                 }
       
  1413             else 
       
  1414                 {
       
  1415                 iSelector->AppendSelectVisL( 
       
  1416                         iVisArray[i], 
       
  1417                         iVisArray[i]->iId,
       
  1418                          CFsTextViewerSelect::EFsLineType );
       
  1419                 }
       
  1420             }
       
  1421         }
       
  1422     }
       
  1423 
       
  1424 // ---------------------------------------------------------------------------
       
  1425 // SetStatusLineLayout
       
  1426 // ---------------------------------------------------------------------------
       
  1427 void CFsTextViewerVisualizerData::SetStatusLineLayout( CAlfAnchorLayout* aLayout )
       
  1428     {
       
  1429     FUNC_LOG;
       
  1430     iStatusLineLayout = aLayout;
       
  1431     }
       
  1432 
       
  1433 // ---------------------------------------------------------------------------
       
  1434 // GetLineOffset
       
  1435 // ---------------------------------------------------------------------------
       
  1436 TInt CFsTextViewerVisualizerData::GetLineOffset( TInt aLine )
       
  1437 	{
       
  1438 	TInt retVal = -1;
       
  1439 	
       
  1440 	TInt i = 0;
       
  1441 	TInt lowestLine = 0;
       
  1442 	TInt highestLine = GetTotalLines();
       
  1443 	TInt positionInArrayOfLowest = 0;
       
  1444 	TInt positionInArrayOfHighest = 0;
       
  1445 	TBool exactMatch = EFalse;
       
  1446 	
       
  1447 	for ( i = 0; i < iVisArray.Count(); ++i )
       
  1448 		{
       
  1449 		if ( iVisArray[i]->iLineNumber == aLine )
       
  1450 			{
       
  1451 			retVal = iVisArray[i]->iRect.iTl.iY;
       
  1452 			exactMatch = ETrue;
       
  1453 			i = iVisArray.Count();
       
  1454 			}
       
  1455 		else if ( iVisArray[i]->iLineNumber < aLine && lowestLine < aLine )
       
  1456 			{
       
  1457 			lowestLine = iVisArray[i]->iLineNumber;
       
  1458 			positionInArrayOfLowest = i;
       
  1459 			}
       
  1460 		else if ( iVisArray[i]->iLineNumber > aLine && highestLine - aLine > iVisArray[i]->iLineNumber - aLine )
       
  1461 			{
       
  1462 			highestLine = iVisArray[i]->iLineNumber;
       
  1463 			positionInArrayOfHighest = i;
       
  1464 			}
       
  1465 		}
       
  1466 	
       
  1467 	if ( !exactMatch )
       
  1468 		{
       
  1469 		retVal = ( iVisArray[positionInArrayOfLowest]->iRect.iTl.iY + iVisArray[positionInArrayOfHighest]->iRect.iTl.iY ) / 2; 
       
  1470 		}
       
  1471 	
       
  1472 	return retVal;
       
  1473 	}
       
  1474 
       
  1475 // ---------------------------------------------------------------------------
       
  1476 // ConstructL
       
  1477 // ---------------------------------------------------------------------------
       
  1478 void CFsTextViewerVisualizerData::ConstructL()
       
  1479     {
       
  1480     }
       
  1481 
       
  1482 // ---------------------------------------------------------------------------
       
  1483 // CFsTextViewerVisualizerData
       
  1484 // ---------------------------------------------------------------------------
       
  1485 CFsTextViewerVisualizerData::CFsTextViewerVisualizerData(
       
  1486         CAlfControl* aControl,
       
  1487         CFsTextParser* aParser,
       
  1488         CFsTextViewerSelectsManager* aSelector )
       
  1489     : iControl( aControl ), iParser( aParser ), iSelector( aSelector )
       
  1490     {
       
  1491     FUNC_LOG;
       
  1492     }
       
  1493