emailuis/uicomponents/src/fstextviewerselectline.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:  Whole line highlight class
       
    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/alfimagevisual.h>
       
    25 #include <alf/alftextvisual.h>
       
    26 #include <alf/alfgradientbrush.h>
       
    27 #include <alf/alfimage.h>
       
    28 // </cmail>
       
    29 #include <aknnotewrappers.h>
       
    30 
       
    31 #include "fstextviewerselectline.h"
       
    32 #include "fstextviewervisualizer.h"
       
    33 #include "fstextviewervisualizerdata.h"
       
    34 #include "fstextviewerselectsmanager.h"
       
    35 #include "fstextviewervisualizersettings.h"
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // NewL
       
    39 // ---------------------------------------------------------------------------
       
    40 CFsTextViewerSelectLine* CFsTextViewerSelectLine::NewL( 
       
    41         CFsTextViewerSelectsManager* aManager )
       
    42      {
       
    43     FUNC_LOG;
       
    44      CFsTextViewerSelectLine* self = 
       
    45          new (ELeave) CFsTextViewerSelectLine( aManager );
       
    46      CleanupStack::PushL( self );
       
    47      self->ConstructL();
       
    48      CleanupStack::Pop( self );
       
    49      return self;
       
    50      }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // SelectL
       
    54 // ---------------------------------------------------------------------------
       
    55 void CFsTextViewerSelectLine::SelectL()
       
    56     {
       
    57     FUNC_LOG;
       
    58     for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
    59         {
       
    60         if ( !iVisuals[i]->iVisual )
       
    61             {
       
    62             return;
       
    63             }
       
    64         }
       
    65     
       
    66     if(!iIsShown)
       
    67         {
       
    68         iIsShown = ETrue;
       
    69         
       
    70         TRect target = TRect( 0, 0, 0, 0 );
       
    71         TInt targetLine = 0;
       
    72         if ( iVisuals.Count() > 0 )
       
    73             {
       
    74             if ( iVisuals[0]->iIsText )
       
    75                 {
       
    76 //                CAlfTextVisual* tmp = static_cast<CAlfTextVisual*>( iVisuals[0]->iVisual );
       
    77                 target = iVisuals[0]->iRect;
       
    78 //                target.SetSize( tmp->TextExtents() );
       
    79                 }
       
    80             else
       
    81                 {
       
    82                 target = iVisuals[0]->iRect;
       
    83                 }
       
    84             targetLine = 
       
    85                 iManager->Visualizer()->Navigator()
       
    86                 ->GetRangedVisual(iVisuals[0]->iVisual)->iLineNumber;
       
    87             }
       
    88         TRect visual;
       
    89         TInt visualLine;
       
    90         for ( TInt i = 0; i < iVisuals.Count(); ++i )
       
    91             {
       
    92             if ( iVisuals[i]->iIsText )
       
    93                 {
       
    94 //                CAlfTextVisual* tmp = static_cast<CAlfTextVisual*>( iVisuals[i]->iVisual );
       
    95                 visual = iVisuals[i]->iRect;
       
    96 //                visual.SetSize( tmp->TextExtents() );
       
    97                 }
       
    98             else
       
    99                 {
       
   100                 visual = iVisuals[i]->iRect;
       
   101                 }
       
   102             
       
   103             visualLine = iVisuals[i]->iLineNumber;
       
   104             
       
   105             if( targetLine != visualLine )
       
   106                 {
       
   107                 CAlfImageVisual* highlightLine;
       
   108                 highlightLine = CAlfImageVisual::AddNewL( 
       
   109                         *iManager->iControl, 
       
   110                         iManager->Visualizer()->BackgroundLayout() );
       
   111                 highlightLine->SetFlag( EAlfVisualFlagManualLayout );
       
   112                 highlightLine->SetScaleMode( CAlfImageVisual::EScaleFit );
       
   113                 highlightLine->SetImage( 
       
   114                         TAlfImage( *iManager->iHighlightLine ) );
       
   115                 highlightLine->SetRect( target );
       
   116                 highlightLine->SetOpacity( 
       
   117                         iManager->iHighlightLineOpacity );
       
   118                     
       
   119                 TFsPartBgVisual toAdd;
       
   120                 toAdd.iVisual = highlightLine;
       
   121                 toAdd.iRect = target;
       
   122                 iManager->Visualizer()->Navigator()->AppendBgL( toAdd );
       
   123                     
       
   124                 iHighlightLines.Append(highlightLine); 
       
   125                 
       
   126                 target = visual;
       
   127                 targetLine = visualLine; 
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 
       
   132                 if ( target.iTl.iX > visual.iTl.iX )
       
   133                     {
       
   134                     target.iTl.iX = visual.iTl.iX;
       
   135                     }
       
   136                 if ( target.iBr.iX < visual.iBr.iX )
       
   137                     {
       
   138                     target.iBr.iX = visual.iBr.iX;
       
   139                     }
       
   140                 if(target.iTl.iY > visual.iTl.iY)
       
   141                     {
       
   142                     target.iTl.iY = visual.iTl.iY;
       
   143                     }
       
   144                     
       
   145                 if(target.iBr.iY < visual.iBr.iY)
       
   146                     {
       
   147                     target.iBr.iY = visual.iBr.iY;
       
   148                     }
       
   149                 }
       
   150             
       
   151             if(i == (iVisuals.Count() - 1))
       
   152                 {
       
   153                 CAlfImageVisual* highlightLine;
       
   154                 highlightLine = CAlfImageVisual::AddNewL( 
       
   155                         *iManager->iControl, 
       
   156                         iManager->Visualizer()->BackgroundLayout() );
       
   157                 highlightLine->SetFlag( EAlfVisualFlagManualLayout );
       
   158                 highlightLine->SetScaleMode( CAlfImageVisual::EScaleFit );
       
   159                 highlightLine->SetImage( 
       
   160                         TAlfImage( *iManager->iHighlightLine ) );
       
   161                 highlightLine->SetRect( target );
       
   162                 highlightLine->SetOpacity( 
       
   163                         iManager->iHighlightLineOpacity );
       
   164                     
       
   165                 TFsPartBgVisual toAdd;
       
   166                 toAdd.iVisual = highlightLine;
       
   167                 toAdd.iRect = target;
       
   168                 iManager->Visualizer()->Navigator()->AppendBgL( toAdd );
       
   169                     
       
   170                 iHighlightLines.Append( highlightLine ); 
       
   171                 }
       
   172             }
       
   173             
       
   174         if( iIsActionButton && !iActionButton && iVisuals.Count() > 0)
       
   175             {     
       
   176             TAlfTimedPoint highlightedLineSize = iHighlightLines[0]->Size();
       
   177             TAlfTimedPoint highlightedLinePos = iHighlightLines[0]->Pos();
       
   178                     
       
   179             TInt actionButtonWidth = iManager->Visualizer()->iSettings->iActionButtonWidth;
       
   180             TInt actionButtonHeight = iManager->Visualizer()->iSettings->iActionButtonHeight;
       
   181             TInt actionButtonMargin = iManager->Visualizer()->iSettings->iActionButtonMargin;
       
   182 
       
   183             // Width of the actual text content area (without scroll bar)
       
   184             TInt contentWidth = iManager->Visualizer()->iContentSize.iWidth + 
       
   185                                 iManager->Visualizer()->iSettings->iLeftMargin + 
       
   186                                 iManager->Visualizer()->iSettings->iRightMargin;
       
   187 
       
   188             // If the width of the whole main pane is more than the width of
       
   189             // the actual content area, it means that scroll bar is visible.
       
   190             // In that case we don't need to leave any extra margin for the
       
   191             // action button, because the scroll bar has some margin already.
       
   192             // This way the button overlaps the text bit less in long lines.
       
   193             if( iManager->Visualizer()->iDisplaySize.iWidth > contentWidth )
       
   194                 {
       
   195                 actionButtonMargin = 0;
       
   196                 }
       
   197                    
       
   198             TInt yTranslate = (highlightedLineSize.Target().iY - actionButtonHeight) / 2;
       
   199                    
       
   200             if(iManager->Visualizer()->iSettings->iMirroring)
       
   201                 {   
       
   202                 target.iTl.iX = actionButtonMargin;                
       
   203                 target.iTl.iY = highlightedLinePos.Target().iY + yTranslate;
       
   204                 target.iBr.iX = target.iTl.iX + actionButtonWidth;
       
   205                 target.iBr.iY = target.iTl.iY + actionButtonHeight;
       
   206                 }
       
   207             else
       
   208                 {
       
   209                 target.iTl.iX = contentWidth - actionButtonMargin - actionButtonWidth;
       
   210                 target.iTl.iY = highlightedLinePos.Target().iY + yTranslate;
       
   211                 target.iBr.iX = target.iTl.iX + actionButtonWidth;
       
   212                 target.iBr.iY =target.iTl.iY + actionButtonHeight;
       
   213                 }
       
   214                 
       
   215             TFsPartBgVisual toAdd;
       
   216             iActionButton = CAlfImageVisual::AddNewL( 
       
   217                     *iManager->iControl, 
       
   218                     iManager->Visualizer()->BackgroundLayout() );
       
   219             iActionButton->SetScaleMode( CAlfImageVisual::EScaleFit );
       
   220             iActionButton->SetImage( TAlfImage( *iManager->iActionButton ) );
       
   221             iActionButton->SetRect( target );
       
   222             iActionButton->SetOpacity( iManager->iActionButtonOpacity );
       
   223 
       
   224 /*
       
   225             if(iManager->Visualizer()->iSettings->iMirroring)
       
   226                 {
       
   227                 iActionButton->SetTurnAngle(180);
       
   228                 }
       
   229 */
       
   230                 
       
   231             toAdd.iVisual = iActionButton;
       
   232             toAdd.iRect = target;
       
   233             iManager->Visualizer()->Navigator()->AppendBgL( toAdd );
       
   234             }
       
   235         }
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // Deselect
       
   240 // ---------------------------------------------------------------------------
       
   241 void CFsTextViewerSelectLine::DeselectL()
       
   242     {
       
   243     FUNC_LOG;
       
   244     TInt ala = iHighlightLines.Count();
       
   245     
       
   246     for( TInt i = iHighlightLines.Count() - 1 ; i >= 0 ; --i )
       
   247         {
       
   248         if ( iManager->Visualizer()->Navigator()
       
   249                 ->RemoveBg( iHighlightLines[i] ) )
       
   250             {
       
   251             iHighlightLines[i]->RemoveAndDestroyAllD();
       
   252             }
       
   253         
       
   254         iHighlightLines[i] = NULL;
       
   255         iHighlightLines.Remove(i);
       
   256         }
       
   257         
       
   258     iIsShown = EFalse;
       
   259 
       
   260     if ( iActionButton )
       
   261         {
       
   262         if(iManager->Visualizer()->Navigator()->RemoveBg( iActionButton ))
       
   263             {
       
   264             iActionButton->RemoveAndDestroyAllD();
       
   265             }
       
   266         
       
   267         iActionButton = NULL;
       
   268         }
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // SelectedL
       
   273 // ---------------------------------------------------------------------------
       
   274 void CFsTextViewerSelectLine::SelectedL()
       
   275     {
       
   276     FUNC_LOG;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // HideActionButton
       
   281 // ---------------------------------------------------------------------------
       
   282 void CFsTextViewerSelectLine::HideActionButton()
       
   283     {
       
   284     FUNC_LOG;
       
   285     if ( iActionButton )
       
   286         {
       
   287         if(iManager->Visualizer()->Navigator()->RemoveBg( iActionButton ))
       
   288             {
       
   289             iActionButton->RemoveAndDestroyAllD();
       
   290             }
       
   291         
       
   292         iActionButton = NULL;
       
   293         }
       
   294         
       
   295     iIsActionButton = EFalse;
       
   296     }
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // ShowActionButtonL
       
   300 // ---------------------------------------------------------------------------
       
   301 void CFsTextViewerSelectLine::ShowActionButtonL()
       
   302     {
       
   303     FUNC_LOG;
       
   304     if(!iIsActionButton && iVisuals.Count() > 0 && !iActionButton )
       
   305         {
       
   306         iIsActionButton = ETrue;
       
   307         
       
   308         TInt pxTranslation = 10;    
       
   309         TRect target = TRect( 0, 0, 0, 0 );
       
   310            
       
   311         if(iManager->Visualizer()->iSettings->iMirroring)
       
   312             {
       
   313             target = iVisuals[0]->iVisual->DisplayRectTarget();
       
   314                    
       
   315             target.iBr.iX = target.iTl.iX + pxTranslation;
       
   316             target.iTl.iX -= pxTranslation; 
       
   317             }
       
   318         else 
       
   319             {
       
   320             target = iVisuals[iVisuals.Count() - 1]->iVisual->DisplayRectTarget();
       
   321             
       
   322             target.iTl.iX = target.iBr.iX - pxTranslation;
       
   323             target.iBr.iX += pxTranslation;   
       
   324             }
       
   325                 
       
   326         TFsPartBgVisual toAdd;
       
   327         iActionButton = CAlfImageVisual::AddNewL( 
       
   328                     *iManager->iControl, 
       
   329                     iManager->Visualizer()->BackgroundLayout() );
       
   330         iActionButton->SetScaleMode( CAlfImageVisual::EScaleFit );
       
   331         iActionButton->SetImage( TAlfImage( *iManager->iActionButton ) );
       
   332         iActionButton->SetRect( target );
       
   333         iActionButton->SetOpacity( iManager->iActionButtonOpacity );
       
   334 
       
   335 /*
       
   336         if(iManager->Visualizer()->iSettings->iMirroring)
       
   337             {
       
   338             iActionButton->SetTurnAngle(180);
       
   339             }
       
   340 */
       
   341                
       
   342         toAdd.iVisual = iActionButton;
       
   343         toAdd.iRect = target;
       
   344         iManager->Visualizer()->Navigator()->AppendBgL( toAdd );
       
   345         }
       
   346     }
       
   347 // ---------------------------------------------------------------------------
       
   348 // ~CFsTextViewerSelectLine
       
   349 // ---------------------------------------------------------------------------
       
   350 CFsTextViewerSelectLine::~CFsTextViewerSelectLine()
       
   351     {
       
   352     FUNC_LOG;
       
   353     for(TInt i = iHighlightLines.Count() - 1 ; i >= 0 ; --i)
       
   354         {
       
   355         iHighlightLines[i]->RemoveAndDestroyAllD();
       
   356         iHighlightLines[i] = NULL;
       
   357         iHighlightLines.Remove(i);
       
   358         }
       
   359     
       
   360     iHighlightLines.Close();
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CFsTextViewerSelectLine
       
   365 // ---------------------------------------------------------------------------
       
   366 CFsTextViewerSelectLine::CFsTextViewerSelectLine( 
       
   367         CFsTextViewerSelectsManager* aManager ) 
       
   368     {
       
   369     FUNC_LOG;
       
   370     iManager = aManager;
       
   371     iType = EFsLineType;
       
   372     iActionButton = NULL;
       
   373     
       
   374     iIsShown = EFalse;
       
   375     iIsActionButton = ETrue;
       
   376     }
       
   377 
       
   378