emailuis/uicomponents/src/fstextviewervisualizerdata.cpp
changeset 0 8466d47a6819
child 11 0396474f30f5
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  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 
       
   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     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1023         {
       
  1024         if ( iVisArray[i]->iRect.iTl.iY >= iScreenOffset )
       
  1025             {
       
  1026             if ( iVisArray[i]->iRect.iTl.iY < retVal->iRect.iTl.iY )
       
  1027                 {
       
  1028                 retVal = iVisArray[i];
       
  1029                 }
       
  1030             else if ( iVisArray[i]->iRect.iTl.iY 
       
  1031                     == retVal->iRect.iTl.iY )
       
  1032                 {
       
  1033                 if ( iVisArray[i]->iRect.iTl.iX < retVal->iRect.iTl.iX )
       
  1034                     {
       
  1035                     retVal = iVisArray[i];
       
  1036                     }
       
  1037                 }
       
  1038             else if ( retVal->iRect.iTl.iY < iScreenOffset )
       
  1039                 {
       
  1040                 retVal = iVisArray[i];
       
  1041                 }
       
  1042             }
       
  1043         }
       
  1044     
       
  1045     return retVal;
       
  1046     }
       
  1047 
       
  1048 // ---------------------------------------------------------------------------
       
  1049 // GetLastVisible
       
  1050 // ---------------------------------------------------------------------------
       
  1051 TFsRangedVisual* CFsTextViewerVisualizerData::GetLastVisible()
       
  1052     {
       
  1053     FUNC_LOG;
       
  1054     TFsRangedVisual* retVal = NULL;
       
  1055 
       
  1056     if ( iVisArray.Count() > 0 )
       
  1057         {
       
  1058         retVal = iVisArray[0];
       
  1059         }
       
  1060 
       
  1061     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1062         {
       
  1063         if ( iVisArray[i]->iRect.iBr.iY <= iScreenOffset + iScreenHeight )
       
  1064             {
       
  1065             if ( iVisArray[i]->iRect.iBr.iY > retVal->iRect.iBr.iY )
       
  1066                 {
       
  1067                 retVal = iVisArray[i];
       
  1068                 }
       
  1069             else if ( iVisArray[i]->iRect.iBr.iY 
       
  1070                     == retVal->iRect.iBr.iY )
       
  1071                 {
       
  1072                 if ( iVisArray[i]->iRect.iBr.iX > retVal->iRect.iBr.iX )
       
  1073                     {
       
  1074                     retVal = iVisArray[i];
       
  1075                     }
       
  1076                 }
       
  1077             else 
       
  1078                 {
       
  1079                 }
       
  1080             }
       
  1081         }
       
  1082 
       
  1083     return retVal;
       
  1084     }
       
  1085 
       
  1086 // ---------------------------------------------------------------------------
       
  1087 // GetRangedVisual
       
  1088 // ---------------------------------------------------------------------------
       
  1089 TFsRangedVisual* CFsTextViewerVisualizerData::GetRangedVisual( 
       
  1090         CAlfVisual* aVisual )
       
  1091     {
       
  1092     FUNC_LOG;
       
  1093     TFsRangedVisual* retVal = NULL;
       
  1094     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1095         {
       
  1096         if ( iVisArray[i]->iVisual == aVisual )
       
  1097             {
       
  1098             retVal = iVisArray[i];
       
  1099             }
       
  1100         }
       
  1101 
       
  1102     return retVal;
       
  1103     }
       
  1104 
       
  1105 // ---------------------------------------------------------------------------
       
  1106 // UpdateLinesNumbers
       
  1107 // ---------------------------------------------------------------------------
       
  1108 void CFsTextViewerVisualizerData::UpdateLinesNumbers()
       
  1109     {
       
  1110     FUNC_LOG;
       
  1111     TInt lastLine = 1;
       
  1112     TInt i = 0;
       
  1113     if ( iVisArray.Count() <= 0 )
       
  1114         {
       
  1115         return;
       
  1116         }
       
  1117     do 
       
  1118         {
       
  1119         if ( iVisArray[i]->iIsActive )
       
  1120             {
       
  1121             lastLine = iVisArray[i]->iLineNumber;
       
  1122             }
       
  1123         ++i;
       
  1124         } while (
       
  1125                 i < iVisArray.Count()
       
  1126                 && ( iVisArray[i]->iLineNumber == lastLine
       
  1127                     || iVisArray[i]->iLineNumber == lastLine + 1 )
       
  1128                 );
       
  1129 
       
  1130     TInt lineNumber = lastLine;
       
  1131     for ( ; i < iVisArray.Count(); ++i )
       
  1132         {
       
  1133         if ( iVisArray[i]->iIsActive )
       
  1134             {
       
  1135             if ( iVisArray[i]->iLineNumber != lastLine )
       
  1136                 {
       
  1137                 ++lineNumber;
       
  1138                 }
       
  1139             lastLine = iVisArray[i]->iLineNumber;
       
  1140             iVisArray[i]->iLineNumber = lineNumber;
       
  1141             }
       
  1142         }
       
  1143     }
       
  1144 
       
  1145 // ---------------------------------------------------------------------------
       
  1146 // GetTotalLines
       
  1147 // ---------------------------------------------------------------------------
       
  1148 TInt CFsTextViewerVisualizerData::GetTotalLines()
       
  1149     {
       
  1150     FUNC_LOG;
       
  1151     TInt retVal = 0;
       
  1152     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1153         {
       
  1154         if ( iVisArray[i]->iIsActive 
       
  1155                 && iVisArray[i]->iLineNumber > retVal )
       
  1156             {
       
  1157             retVal = iVisArray[i]->iLineNumber;
       
  1158             }
       
  1159         }
       
  1160     return retVal;
       
  1161     }
       
  1162 
       
  1163 // ---------------------------------------------------------------------------
       
  1164 // RemoveFromLine
       
  1165 // ---------------------------------------------------------------------------
       
  1166 TInt CFsTextViewerVisualizerData::RemoveFromLineL( 
       
  1167         TInt aLineNumber, 
       
  1168         CFsTextViewerCoordinator* aHelper )
       
  1169     {
       
  1170     FUNC_LOG;
       
  1171     TInt retVal = GetFirstCharInLine( aLineNumber );
       
  1172     if ( GetCursorCharOffset() >= retVal )
       
  1173         {
       
  1174         while ( GetCursorCharOffset() >= retVal || GetCursorCharOffset() == 0 )
       
  1175             {
       
  1176             MoveToPrevCharL();
       
  1177             }
       
  1178         SetCursorCharOffset( retVal - 1 );
       
  1179         }
       
  1180     
       
  1181     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1182         {
       
  1183         if ( iVisArray[i]->iLineNumber >= aLineNumber )
       
  1184             {
       
  1185             if ( iVisArray[i]->iVisual )
       
  1186                 {
       
  1187                 iSelector->RemoveVisual( iVisArray[i] );
       
  1188                 iVisArray[i]->iVisual->RemoveAndDestroyAllD();
       
  1189                 iVisArray[i]->iVisual = NULL;
       
  1190                 }
       
  1191             aHelper->RemoveRect( iVisArray[i]->iRect );
       
  1192             delete iVisArray[i];
       
  1193             iVisArray.Remove(i);
       
  1194             --i;
       
  1195             }
       
  1196         }
       
  1197 
       
  1198     return retVal;
       
  1199     }
       
  1200 
       
  1201 // ---------------------------------------------------------------------------
       
  1202 // GetFirstCharInLine - gets the first character in line position
       
  1203 // ---------------------------------------------------------------------------
       
  1204 TInt CFsTextViewerVisualizerData::GetFirstCharInLine( TInt aLineNumber )
       
  1205     {
       
  1206     FUNC_LOG;
       
  1207     TInt retVal = iLength;
       
  1208     for ( TInt i = 0; i < iVisArray.Count(); ++i ) 
       
  1209         {
       
  1210         if ( iVisArray[i]->iLineNumber == aLineNumber  
       
  1211                 && iVisArray[i]->iStart < retVal )
       
  1212             {
       
  1213             retVal = iVisArray[i]->iStart;
       
  1214             }
       
  1215         }
       
  1216     return retVal;
       
  1217     }
       
  1218 
       
  1219 // <cmail>
       
  1220 // ---------------------------------------------------------------------------
       
  1221 // GetCharLineNumber - returns line number for character position (offset)
       
  1222 // ---------------------------------------------------------------------------
       
  1223 TInt CFsTextViewerVisualizerData::GetCharLineNumber( TInt aCharNumber )
       
  1224     {
       
  1225     FUNC_LOG;
       
  1226     TInt retVal = -1;
       
  1227     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1228         {
       
  1229         if ( iVisArray[i]->iStart <= aCharNumber  && aCharNumber <= iVisArray[i]->iEnd )
       
  1230             {
       
  1231             retVal = iVisArray[i]->iLineNumber;
       
  1232             i = iVisArray.Count();
       
  1233             }
       
  1234         }
       
  1235     return retVal;
       
  1236     }
       
  1237 // </cmail>
       
  1238 // ---------------------------------------------------------------------------
       
  1239 // SetParser
       
  1240 // ---------------------------------------------------------------------------
       
  1241 void CFsTextViewerVisualizerData::SetParser( CFsTextParser* aParser )
       
  1242     {
       
  1243     FUNC_LOG;
       
  1244     iParser = aParser;
       
  1245     }
       
  1246 
       
  1247 // ---------------------------------------------------------------------------
       
  1248 // FindAndHighlightHotspotL
       
  1249 // ---------------------------------------------------------------------------
       
  1250 void CFsTextViewerVisualizerData::FindAndHighlightHotspotL( TInt aLine )
       
  1251     {
       
  1252     FUNC_LOG;
       
  1253     TFsRangedVisual* visualFound = NULL;
       
  1254     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1255         {
       
  1256         if ( iVisArray[i]->iLineNumber == aLine )
       
  1257             {
       
  1258             if ( ( !visualFound 
       
  1259                         || visualFound->iStart > iVisArray[i]->iStart ) 
       
  1260                     && ( iVisArray[i]->iHotspot 
       
  1261                         ||  iVisArray[i]->iEmbed ) )
       
  1262                 {
       
  1263                 visualFound = iVisArray[i];
       
  1264                 }
       
  1265             }
       
  1266         }
       
  1267     
       
  1268     if ( visualFound )
       
  1269         {
       
  1270         iSelector->SelectL( visualFound->iId );
       
  1271         }
       
  1272     }
       
  1273 
       
  1274 // ---------------------------------------------------------------------------
       
  1275 // GetCursorLine
       
  1276 // ---------------------------------------------------------------------------
       
  1277 TInt CFsTextViewerVisualizerData::GetCursorLine()
       
  1278     {
       
  1279     FUNC_LOG;
       
  1280     TInt retVal = -1;
       
  1281     if ( iPosition.iVisual >= 0 && iPosition.iVisual < iVisArray.Count() )
       
  1282         {
       
  1283         retVal = iVisArray[iPosition.iVisual]->iLineNumber;
       
  1284         }
       
  1285     return retVal;
       
  1286     }
       
  1287 
       
  1288 // ---------------------------------------------------------------------------
       
  1289 // ReloadPicturesL
       
  1290 // ---------------------------------------------------------------------------
       
  1291 void CFsTextViewerVisualizerData::ReloadPicturesL( TInt aLine )
       
  1292     {
       
  1293     FUNC_LOG;
       
  1294     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1295         {
       
  1296         if ( ( iVisArray[i]->iVisual 
       
  1297                     && !iVisArray[i]->iIsText ) 
       
  1298                 && ( aLine == -1 
       
  1299                     || iVisArray[i]->iLineNumber == aLine ) )
       
  1300             {
       
  1301             iVisArray[i]->iVisual->RemoveAndDestroyAllD();
       
  1302             iVisArray[i]->iVisual = NULL;
       
  1303             RestoreL( iVisArray[i] );
       
  1304             }
       
  1305         }
       
  1306     }
       
  1307 
       
  1308 // ---------------------------------------------------------------------------
       
  1309 // GetTotalHeight
       
  1310 // ---------------------------------------------------------------------------
       
  1311 TInt CFsTextViewerVisualizerData::GetTotalHeight()
       
  1312     {
       
  1313     FUNC_LOG;
       
  1314     TInt retVal = 0;
       
  1315     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1316         {
       
  1317         if ( iVisArray[i]->iRect.iBr.iY > retVal )
       
  1318             {
       
  1319             retVal = iVisArray[i]->iRect.iBr.iY; 
       
  1320             }
       
  1321         }
       
  1322 
       
  1323     retVal += iStatusLineLayout->Size().ValueNow().iY;
       
  1324 
       
  1325     return retVal;
       
  1326     }
       
  1327 
       
  1328 // ---------------------------------------------------------------------------
       
  1329 // HideActionButtonFromCurrentHighlightedHotspot
       
  1330 // ---------------------------------------------------------------------------
       
  1331 void CFsTextViewerVisualizerData
       
  1332 ::HideActionButtonFromCurrentHighlightedHotspot()
       
  1333     {
       
  1334     if(iSelector && iSelector->IsHotspotHighlighted())
       
  1335         {
       
  1336         iSelector->HideActionButtonFromCurrentHighlightedHotspot();
       
  1337         }
       
  1338     }
       
  1339 
       
  1340 // ---------------------------------------------------------------------------
       
  1341 // ShowActionButtonForCurrentHighlightedHotspotL
       
  1342 // ---------------------------------------------------------------------------
       
  1343 void CFsTextViewerVisualizerData
       
  1344 ::ShowActionButtonForCurrentHighlightedHotspotL()
       
  1345     {
       
  1346     if(iSelector && iSelector->IsHotspotHighlighted())
       
  1347         {
       
  1348         iSelector->ShowActionButtonForCurrentHighlightedHotspotL();
       
  1349         }
       
  1350     }
       
  1351 
       
  1352 // ---------------------------------------------------------------------------
       
  1353 // HideAll
       
  1354 // ---------------------------------------------------------------------------
       
  1355 void CFsTextViewerVisualizerData::HideAll()
       
  1356     {
       
  1357     FUNC_LOG;
       
  1358     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1359         {
       
  1360         if ( iVisArray[i]->iVisual )
       
  1361             {
       
  1362             iVisArray[i]->iVisual->RemoveAndDestroyAllD();
       
  1363             iVisArray[i]->iVisual = NULL;
       
  1364             --iVisualAmount;
       
  1365             }
       
  1366         }
       
  1367     }
       
  1368 
       
  1369 // ---------------------------------------------------------------------------
       
  1370 // RestoreVisibleL
       
  1371 // ---------------------------------------------------------------------------
       
  1372 void CFsTextViewerVisualizerData::RestoreVisibleL()
       
  1373     {
       
  1374     FUNC_LOG;
       
  1375     TRect visibleArea = TRect( 0, 0, 500, iScreenHeight );
       
  1376     visibleArea.Move( 0, iScreenOffset );
       
  1377     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1378         {
       
  1379         if ( visibleArea.Intersects( iVisArray[i]->iRect ) )
       
  1380             {
       
  1381             RestoreL( iVisArray[i] );
       
  1382             }
       
  1383         }
       
  1384     }
       
  1385 
       
  1386 // ---------------------------------------------------------------------------
       
  1387 // RegisterHotspotsL
       
  1388 // ---------------------------------------------------------------------------
       
  1389 void CFsTextViewerVisualizerData::RegisterHotspotsL()
       
  1390     {
       
  1391     FUNC_LOG;
       
  1392     for ( TInt i = 0; i < iVisArray.Count(); ++i )
       
  1393         {
       
  1394         if ( iVisArray[i]->iEmbed )
       
  1395             {
       
  1396             iSelector->AppendSelectVisL( 
       
  1397                     iVisArray[i],
       
  1398                     iVisArray[i]->iId,
       
  1399                      CFsTextViewerSelect::EFsEmbedType );
       
  1400             }
       
  1401         else if ( iVisArray[i]->iHotspot )
       
  1402             {
       
  1403             if ( 0 == iVisArray[i]->iHotspotType )
       
  1404                 {
       
  1405                 iSelector->AppendSelectVisL(
       
  1406                         iVisArray[i],
       
  1407                         iVisArray[i]->iId,
       
  1408                          CFsTextViewerSelect::EFsHotspotType );
       
  1409                 }
       
  1410             else 
       
  1411                 {
       
  1412                 iSelector->AppendSelectVisL( 
       
  1413                         iVisArray[i], 
       
  1414                         iVisArray[i]->iId,
       
  1415                          CFsTextViewerSelect::EFsLineType );
       
  1416                 }
       
  1417             }
       
  1418         }
       
  1419     }
       
  1420 
       
  1421 // ---------------------------------------------------------------------------
       
  1422 // SetStatusLineLayout
       
  1423 // ---------------------------------------------------------------------------
       
  1424 void CFsTextViewerVisualizerData::SetStatusLineLayout( CAlfAnchorLayout* aLayout )
       
  1425     {
       
  1426     FUNC_LOG;
       
  1427     iStatusLineLayout = aLayout;
       
  1428     }
       
  1429 
       
  1430 // ---------------------------------------------------------------------------
       
  1431 // GetLineOffset
       
  1432 // ---------------------------------------------------------------------------
       
  1433 TInt CFsTextViewerVisualizerData::GetLineOffset( TInt aLine )
       
  1434 	{
       
  1435 	TInt retVal = -1;
       
  1436 	
       
  1437 	TInt i = 0;
       
  1438 	TInt lowestLine = 0;
       
  1439 	TInt highestLine = GetTotalLines();
       
  1440 	TInt positionInArrayOfLowest = 0;
       
  1441 	TInt positionInArrayOfHighest = 0;
       
  1442 	TBool exactMatch = EFalse;
       
  1443 	
       
  1444 	for ( i = 0; i < iVisArray.Count(); ++i )
       
  1445 		{
       
  1446 		if ( iVisArray[i]->iLineNumber == aLine )
       
  1447 			{
       
  1448 			retVal = iVisArray[i]->iRect.iTl.iY;
       
  1449 			exactMatch = ETrue;
       
  1450 			i = iVisArray.Count();
       
  1451 			}
       
  1452 		else if ( iVisArray[i]->iLineNumber < aLine && lowestLine < aLine )
       
  1453 			{
       
  1454 			lowestLine = iVisArray[i]->iLineNumber;
       
  1455 			positionInArrayOfLowest = i;
       
  1456 			}
       
  1457 		else if ( iVisArray[i]->iLineNumber > aLine && highestLine - aLine > iVisArray[i]->iLineNumber - aLine )
       
  1458 			{
       
  1459 			highestLine = iVisArray[i]->iLineNumber;
       
  1460 			positionInArrayOfHighest = i;
       
  1461 			}
       
  1462 		}
       
  1463 	
       
  1464 	if ( !exactMatch )
       
  1465 		{
       
  1466 		retVal = ( iVisArray[positionInArrayOfLowest]->iRect.iTl.iY + iVisArray[positionInArrayOfHighest]->iRect.iTl.iY ) / 2; 
       
  1467 		}
       
  1468 	
       
  1469 	return retVal;
       
  1470 	}
       
  1471 
       
  1472 // ---------------------------------------------------------------------------
       
  1473 // ConstructL
       
  1474 // ---------------------------------------------------------------------------
       
  1475 void CFsTextViewerVisualizerData::ConstructL()
       
  1476     {
       
  1477     }
       
  1478 
       
  1479 // ---------------------------------------------------------------------------
       
  1480 // CFsTextViewerVisualizerData
       
  1481 // ---------------------------------------------------------------------------
       
  1482 CFsTextViewerVisualizerData::CFsTextViewerVisualizerData(
       
  1483         CAlfControl* aControl,
       
  1484         CFsTextParser* aParser,
       
  1485         CFsTextViewerSelectsManager* aSelector )
       
  1486     : iControl( aControl ), iParser( aParser ), iSelector( aSelector )
       
  1487     {
       
  1488     FUNC_LOG;
       
  1489     }
       
  1490