emailuis/uicomponents/src/fstextviewermarkfacility.cpp
changeset 0 8466d47a6819
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:  Responsible for marking capabilities
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail> removed __FS_ALFRED_SUPPORT flag
       
    20 //#include <fsconfig.h>
       
    21 //</cmail> removed __FS_ALFRED_SUPPORT flag
       
    22 // <cmail> SF
       
    23 #include "emailtrace.h"
       
    24 #include <alf/alfanchorlayout.h>
       
    25 #include <alf/alfcontrol.h>
       
    26 #include <alf/alftextvisual.h>
       
    27 #include <alf/alfimagevisual.h>
       
    28 #include <alf/alfborderbrush.h>
       
    29 #include <alf/alfbrusharray.h>
       
    30 // </cmail>
       
    31 
       
    32 #include "fstextviewermarkfacility.h"
       
    33 #include "fstextviewerskindata.h"
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // NewL
       
    38 // ---------------------------------------------------------------------------
       
    39 CFsTextViewerMarkFacility* CFsTextViewerMarkFacility::NewL( 
       
    40         CAlfLayout* aLayout, 
       
    41         CAlfControl* aControl, 
       
    42         CFsTextViewerVisualizerData* aNavigator,
       
    43         CFsTextViewerSkinData* aSkinData )
       
    44     {
       
    45     FUNC_LOG;
       
    46     CFsTextViewerMarkFacility* self = new (ELeave) CFsTextViewerMarkFacility( 
       
    47             aLayout, 
       
    48             aControl, 
       
    49             aNavigator, 
       
    50             aSkinData );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // ~CFsTextViewerMarkFacility
       
    59 // ---------------------------------------------------------------------------
       
    60 CFsTextViewerMarkFacility::~CFsTextViewerMarkFacility()
       
    61     {
       
    62     FUNC_LOG;
       
    63     if ( iLayout )
       
    64         {
       
    65         iLayout->RemoveAndDestroyAllD();
       
    66         }
       
    67 
       
    68     if ( iBorder )
       
    69         {
       
    70         delete iBorder;
       
    71         }
       
    72     
       
    73     iVisuals.Close();
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // SetHeadOffset
       
    78 // ---------------------------------------------------------------------------
       
    79 void CFsTextViewerMarkFacility::SetHeadOffsetL( TInt aHead )
       
    80     {
       
    81     FUNC_LOG;
       
    82     iHead = aHead;
       
    83     TInt visualIndex = iNavigator->Find( iHead );
       
    84     
       
    85     TInt begin = iNavigator->GetVisStartOffset( visualIndex );
       
    86     TInt end = iNavigator->GetVisEndOffset( visualIndex );
       
    87 
       
    88     CAlfVisual* visual = CreateMarkVisualL( 
       
    89             iNavigator->GetVisual( visualIndex ), 
       
    90             begin,
       
    91             end );
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // SetTailOffset
       
    96 // ---------------------------------------------------------------------------
       
    97 void CFsTextViewerMarkFacility::SetTailOffsetL( TInt /* aTail */ )
       
    98     {
       
    99     FUNC_LOG;
       
   100 
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // FollowCursor
       
   105 // ---------------------------------------------------------------------------
       
   106 void CFsTextViewerMarkFacility::FollowCursorL()
       
   107     {
       
   108     FUNC_LOG;
       
   109     if ( iHead < iNavigator->GetCursorCharOffset() )
       
   110         {
       
   111         iTail = iNavigator->FindPrevChar();
       
   112         }
       
   113     else if ( iHead > iNavigator->GetCursorCharOffset() )
       
   114         {
       
   115         iTail = iNavigator->GetCursorCharOffset();
       
   116         }
       
   117     else
       
   118         {
       
   119         iTail = iHead;
       
   120         }
       
   121 
       
   122     TInt visualIndex = iNavigator->Find( iTail );
       
   123     
       
   124     TInt begin = iNavigator->GetVisStartOffset( visualIndex );
       
   125     TInt end = iNavigator->GetVisEndOffset( visualIndex );
       
   126     CAlfVisual* visual = NULL;
       
   127     
       
   128     visual = Find( iTail );
       
   129 
       
   130     if ( !visual )
       
   131         {
       
   132         visual = CreateMarkVisualL( 
       
   133             iNavigator->GetVisual( visualIndex ), 
       
   134             begin,
       
   135             end );
       
   136         }
       
   137 
       
   138     CAlfImageVisual* imageVisual( dynamic_cast<CAlfImageVisual*>( visual ) );
       
   139     CAlfTextVisual* textVisual( dynamic_cast<CAlfTextVisual*>( visual ) );
       
   140     if ( imageVisual )
       
   141         {
       
   142         UpdateImageVisualL( visual, iNavigator->GetVisual( visualIndex ) );
       
   143         }
       
   144     else if ( textVisual )
       
   145         {
       
   146         if ( iHead == iNavigator->GetCursorCharOffset() )
       
   147             {
       
   148             begin = LocalVisOffset( iHead );
       
   149             end = LocalVisOffset( iHead );
       
   150             }
       
   151         else if ( iTail >= iHead )
       
   152             {
       
   153             begin = IsHeadVisual( iTail ) ? LocalVisOffset( iHead ) : 0;
       
   154             end = LocalVisOffset( iTail ) + 1;
       
   155             }
       
   156         else if ( iTail < iHead )
       
   157             {
       
   158             begin = LocalVisOffset( iTail );
       
   159             end = IsHeadVisual( iTail ) 
       
   160                 ? LocalVisOffset( iHead ) 
       
   161                 : VisualLength( visual );
       
   162             }
       
   163 
       
   164         UpdateTextVisualL( 
       
   165                 visual, 
       
   166                 iNavigator->GetVisual( visualIndex ), 
       
   167                 begin, 
       
   168                 end );
       
   169         }
       
   170 
       
   171     DeleteUnused();
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // SetLayout
       
   176 // ---------------------------------------------------------------------------
       
   177 void CFsTextViewerMarkFacility::SetLayout( CAlfLayout* aLayout )
       
   178     {
       
   179     FUNC_LOG;
       
   180     iLayout = aLayout;
       
   181     iVisuals.Reset();
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // GetRange
       
   186 // ---------------------------------------------------------------------------
       
   187 void CFsTextViewerMarkFacility::GetRange( TInt& aBegin, TInt& aEnd ) const
       
   188     {
       
   189     FUNC_LOG;
       
   190     aBegin = iHead;
       
   191     aEnd = iTail;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CreateMarkVisualL
       
   196 // ---------------------------------------------------------------------------
       
   197 CAlfVisual* CFsTextViewerMarkFacility::CreateMarkVisualL( 
       
   198         CAlfVisual* aVisual, 
       
   199         TInt aBegin, 
       
   200         TInt aEnd )
       
   201     {
       
   202     FUNC_LOG;
       
   203     CAlfImageVisual* imageVisual( dynamic_cast<CAlfImageVisual*>( aVisual ) );
       
   204     CAlfTextVisual* textVisual( dynamic_cast<CAlfTextVisual*>( aVisual ) );
       
   205     TFsRangedVisual visual;
       
   206 
       
   207     visual.iStart = aBegin;
       
   208     visual.iEnd = aEnd;
       
   209 
       
   210     if ( imageVisual )
       
   211         {
       
   212         visual.iVisual = CAlfImageVisual::AddNewL( *iControl, iLayout );
       
   213         }
       
   214     else if ( textVisual )
       
   215         {
       
   216         visual.iVisual = CAlfTextVisual::AddNewL( *iControl, iLayout );
       
   217         static_cast<CAlfTextVisual*>(visual.iVisual)->SetStyle( 
       
   218                 EAlfTextStyleNormal, 
       
   219                 EAlfBackgroundTypeLight );
       
   220         static_cast<CAlfTextVisual*>(visual.iVisual)->EnableShadow( EFalse );
       
   221         static_cast<CAlfTextVisual*>(visual.iVisual)->SetAlign( 
       
   222                 EAlfAlignHLeft, 
       
   223                 EAlfAlignVBottom );
       
   224         static_cast<CAlfTextVisual*>(visual.iVisual)->SetColor( 
       
   225                 iSkinData->iMarkedTextColor );
       
   226         static_cast<CAlfTextVisual*>(visual.iVisual)->SetTextStyle(
       
   227                 static_cast<CAlfTextVisual*>(aVisual)->Style() );
       
   228         visual.iVisual->SetClipping();
       
   229         }
       
   230 
       
   231     visual.iVisual->EnableBrushesL();
       
   232     visual.iVisual->Brushes()->AppendL( iBorder, EAlfDoesNotHaveOwnership );
       
   233     
       
   234     iVisuals.AppendL( visual );
       
   235 
       
   236     return visual.iVisual;
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // UpdateImageVisualL
       
   241 // ---------------------------------------------------------------------------
       
   242 void CFsTextViewerMarkFacility::UpdateImageVisualL( 
       
   243         CAlfVisual* aVisual, 
       
   244         CAlfVisual* aBaseVisual )
       
   245     {
       
   246     FUNC_LOG;
       
   247     TRect markRect = aBaseVisual->DisplayRectTarget();
       
   248     aVisual->SetRect( markRect );
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // UpdateTextVisualL
       
   253 // ---------------------------------------------------------------------------
       
   254 void CFsTextViewerMarkFacility::UpdateTextVisualL( CAlfVisual* aVisual, 
       
   255                                     CAlfVisual* aBaseVisual, 
       
   256                                     TInt aBegin, TInt aEnd )
       
   257     {
       
   258     FUNC_LOG;
       
   259     CAlfTextVisual* visual = static_cast<CAlfTextVisual*>(aBaseVisual);
       
   260     CAlfTextVisual* targetVisual = static_cast<CAlfTextVisual*>(aVisual);
       
   261     TRect markRect = visual->SubstringExtents( aBegin, aEnd );
       
   262     markRect.Move( visual->DisplayRectTarget().iTl );
       
   263     
       
   264     HBufC* text = visual->Text().AllocL();
       
   265     targetVisual->SetTextL( text->Mid( aBegin, aEnd - aBegin ) );
       
   266     targetVisual->SetRect( markRect );
       
   267     delete text;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // ConstructL
       
   272 // ---------------------------------------------------------------------------
       
   273 void CFsTextViewerMarkFacility::ConstructL()
       
   274     {
       
   275     FUNC_LOG;
       
   276     iBorder = CAlfBorderBrush::NewL( iControl->Env(), 1, 1, 0, 0  );
       
   277     iBorder->SetColor( KRgbBlack );
       
   278     iBorder->SetOpacity( .55f );
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CFsTextViewerMarkFacility
       
   283 // ---------------------------------------------------------------------------
       
   284 CFsTextViewerMarkFacility::CFsTextViewerMarkFacility( 
       
   285         CAlfLayout* aLayout, 
       
   286         CAlfControl* aControl,
       
   287         CFsTextViewerVisualizerData* aNavigator,
       
   288         CFsTextViewerSkinData* aSkinData )
       
   289     {
       
   290     FUNC_LOG;
       
   291     iLayout = aLayout;
       
   292     iControl = aControl;
       
   293     iNavigator = aNavigator;
       
   294     iSkinData = aSkinData;
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // VisualLength
       
   299 // ---------------------------------------------------------------------------
       
   300 TInt CFsTextViewerMarkFacility::VisualLength( CAlfVisual* aVisual )
       
   301     {
       
   302     FUNC_LOG;
       
   303     TInt retVal = KErrNone;
       
   304     for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
   305         {
       
   306         if ( iVisuals[i].iVisual == aVisual )
       
   307             {
       
   308             retVal = iVisuals[i].iEnd - iVisuals[i].iStart + 1;
       
   309             }
       
   310         }
       
   311     return retVal;
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // Find
       
   316 // ---------------------------------------------------------------------------
       
   317 TInt CFsTextViewerMarkFacility::Find( CAlfVisual* aVisual )
       
   318     {
       
   319     FUNC_LOG;
       
   320     TInt retVal = KErrNone;
       
   321     for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
   322         {
       
   323         if ( iVisuals[i].iVisual == aVisual )
       
   324             {
       
   325             retVal = i;
       
   326             }
       
   327         }
       
   328     return retVal;
       
   329     }
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // Find
       
   333 // ---------------------------------------------------------------------------
       
   334 CAlfVisual* CFsTextViewerMarkFacility::Find( TInt aOffset )
       
   335     {
       
   336     FUNC_LOG;
       
   337     CAlfVisual* retVal = NULL;
       
   338 
       
   339     for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
   340         {
       
   341         if ( aOffset >= iVisuals[i].iStart && aOffset <= iVisuals[i].iEnd )
       
   342             {
       
   343             retVal = iVisuals[i].iVisual;
       
   344             }
       
   345         }
       
   346 
       
   347     return retVal;
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // Find
       
   352 // ---------------------------------------------------------------------------
       
   353 TInt CFsTextViewerMarkFacility::FindIndex( TInt aOffset )
       
   354     {
       
   355     FUNC_LOG;
       
   356     TInt retVal = -1;
       
   357 
       
   358     for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
   359         {
       
   360         if ( aOffset >= iVisuals[i].iStart && aOffset <= iVisuals[i].iEnd )
       
   361             {
       
   362             retVal = i;
       
   363             }
       
   364         }
       
   365 
       
   366     return retVal;
       
   367     }
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // LocalVisOffset
       
   371 // ---------------------------------------------------------------------------
       
   372 TInt CFsTextViewerMarkFacility::LocalVisOffset( TInt aGlobalOffset )
       
   373     {
       
   374     FUNC_LOG;
       
   375     TInt retVal = -1;
       
   376     TInt start = 
       
   377         iNavigator->GetVisStartOffset( iNavigator->Find( aGlobalOffset ) );
       
   378     retVal = aGlobalOffset - start;
       
   379 
       
   380     return retVal;
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // DeleteUnused
       
   385 // ---------------------------------------------------------------------------
       
   386 void CFsTextViewerMarkFacility::DeleteUnused()
       
   387     {
       
   388     FUNC_LOG;
       
   389     TInt begin = Min( iHead, iTail );
       
   390     TInt end = Max( iHead, iTail );
       
   391     for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
   392         {
       
   393         if ( ( iVisuals[i].iStart >= begin 
       
   394                    && iVisuals[i].iStart <= end ) 
       
   395              || ( iVisuals[i].iEnd >= begin 
       
   396                    && iVisuals[i].iEnd <= end ) 
       
   397              || ( iVisuals[i].iStart <= begin 
       
   398                    && iVisuals[i].iEnd >= begin ) )
       
   399             {
       
   400             
       
   401             }
       
   402         else
       
   403             {
       
   404             iVisuals[i].iVisual->RemoveAndDestroyAllD();
       
   405                 iVisuals.Remove( i );
       
   406             }
       
   407         }
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // IsHeadVisual
       
   412 // ---------------------------------------------------------------------------
       
   413 TBool CFsTextViewerMarkFacility::IsHeadVisual( TInt aGlobalOffset )
       
   414     {
       
   415     FUNC_LOG;
       
   416     TBool retVal = EFalse;
       
   417 
       
   418     TInt headIndex = FindIndex( iHead );
       
   419     
       
   420     if ( headIndex >= 0 
       
   421             && headIndex < iVisuals.Count()
       
   422             && aGlobalOffset <= iVisuals[headIndex].iEnd 
       
   423             && aGlobalOffset >= iVisuals[headIndex].iStart )
       
   424         {
       
   425         retVal = ETrue;
       
   426         }
       
   427 
       
   428     return retVal;
       
   429     }
       
   430