emailuis/uicomponents/src/fstextviewercoordinator.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:  Implementation of class CFsTextViewerCoordinator
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "fstextviewercoordinator.h"
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // NewL
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 CFsTextViewerCoordinator* CFsTextViewerCoordinator::NewL()
       
    27     {
       
    28     FUNC_LOG;
       
    29     CFsTextViewerCoordinator* self = 
       
    30         new ( ELeave ) CFsTextViewerCoordinator();
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // ~CFsTextViewerCoordinator
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CFsTextViewerCoordinator::~CFsTextViewerCoordinator()
       
    42     {
       
    43     FUNC_LOG;
       
    44     if ( iObstacles )
       
    45         {
       
    46         iObstacles->ResetAndDestroy();
       
    47         delete iObstacles;
       
    48         iObstacles = NULL;
       
    49         }
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // RegisterObstacle
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CFsTextViewerCoordinator::RegisterObstacleL( const TRect& aRect )
       
    57     {
       
    58     FUNC_LOG;
       
    59     TRect* append = new (ELeave) TRect();
       
    60     append->iTl = aRect.iTl;
       
    61     append->iBr = aRect.iBr;
       
    62     iObstacles->AppendL( append );
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Contains
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TBool CFsTextViewerCoordinator::Contains( const TRect aRect ) 
       
    70     {
       
    71     FUNC_LOG;
       
    72     TBool retVal = EFalse;
       
    73 
       
    74     if ( aRect.iBr.iX > iSize.iWidth + iLeftMargin )
       
    75         {
       
    76         retVal = ETrue;
       
    77         iLastObstacle = -1;
       
    78         }
       
    79     else 
       
    80         {
       
    81         for ( TInt i = 0; i < iObstacles->Count(); ++i )
       
    82             {
       
    83             if ( iObstacles->At(i)->Intersects( aRect ) )
       
    84                 {
       
    85                 iLastObstacle = i;
       
    86                 retVal = ETrue;
       
    87                 }
       
    88             }
       
    89         }
       
    90 
       
    91     return retVal;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // SetSize
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CFsTextViewerCoordinator::SetSize( const TSize& aSize )
       
    99     {
       
   100     FUNC_LOG;
       
   101     iSize = aSize;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // NextFreeCol
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 TInt CFsTextViewerCoordinator::NextFreeCol() const
       
   109     {
       
   110     FUNC_LOG;
       
   111     TInt retVal = 0;
       
   112     if ( iLastObstacle >=0 && iLastObstacle < iObstacles->Count() )
       
   113         {
       
   114         retVal = iLastObstacle == -1 ? 0 : iObstacles->At(iLastObstacle)->iBr.iX;
       
   115         }
       
   116     return retVal;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // NextFreeCol
       
   121 // ---------------------------------------------------------------------------
       
   122 TBool CFsTextViewerCoordinator::NextFreeCol( TRect& aRect, TBidiText::TDirectionality aDirection ) const
       
   123     {
       
   124     FUNC_LOG;
       
   125     TRect target = aRect;
       
   126     TBool retVal = EFalse;
       
   127     TInt dX;
       
   128     
       
   129     for ( TInt i = 0; i < iObstacles->Count(); ++i )
       
   130         {
       
   131         if ( target.Intersects( *iObstacles->At(i) ) )
       
   132             {
       
   133             if ( aDirection == TBidiText::ELeftToRight )
       
   134                 {
       
   135                 dX = iObstacles->At(i)->iBr.iX - target.iTl.iX;
       
   136                 target.iTl.iX += dX;
       
   137                 target.iBr.iX += dX;
       
   138                 }
       
   139             else
       
   140                 {
       
   141                 dX = target.iBr.iX - iObstacles->At(i)->iTl.iX;
       
   142                 target.iTl.iX -= dX;
       
   143                 target.iBr.iX -= dX;
       
   144                 }
       
   145             }
       
   146         }
       
   147     
       
   148     if ( target.iBr.iX > iSize.iWidth - iRightMargin || target.iTl.iX < iLeftMargin )
       
   149             {
       
   150             if ( aDirection == TBidiText::ELeftToRight )
       
   151                 {
       
   152                 dX = target.iTl.iX - iLeftMargin ;
       
   153                 target.iTl.iX -= dX;
       
   154                 target.iBr.iX -= dX;
       
   155                 target.iTl.iY += target.Height();
       
   156                 target.iBr.iY += target.Height();
       
   157                 retVal = ETrue;
       
   158                 }
       
   159             else 
       
   160                 {
       
   161                 dX = iSize.iWidth - iRightMargin - target.iBr.iX;
       
   162                 target.iTl.iX += dX;
       
   163                 target.iBr.iX += dX;
       
   164                 target.iTl.iY += target.Height();
       
   165                 target.iBr.iY += target.Height();
       
   166                 retVal = ETrue;
       
   167                 }
       
   168             }
       
   169     
       
   170     aRect = target;
       
   171     return retVal;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // IsNewLine
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 TBool CFsTextViewerCoordinator::IsNewLine() const
       
   179     {
       
   180     FUNC_LOG;
       
   181     TBool retVal;
       
   182     retVal = iLastObstacle == -1 ? ETrue : EFalse;
       
   183     return retVal;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // SetNewLine
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CFsTextViewerCoordinator::SetNewLine()
       
   191     {
       
   192     FUNC_LOG;
       
   193     iLastObstacle = -1;
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // RemoveRect
       
   198 // ---------------------------------------------------------------------------
       
   199 void CFsTextViewerCoordinator::RemoveRect( TRect aRect )
       
   200     {
       
   201     FUNC_LOG;
       
   202     for ( TInt i = 0; i < iObstacles->Count(); ++i )
       
   203         {
       
   204         if ( iObstacles->At(i)->iTl.iX ==  aRect.iTl.iX && iObstacles->At(i)->iTl.iY ==  aRect.iTl.iY )
       
   205             {
       
   206             delete iObstacles->At(i);
       
   207             iObstacles->At(i) = NULL;
       
   208             iObstacles->Delete(i);
       
   209             }
       
   210         }
       
   211 
       
   212     iLastObstacle = -1;
       
   213 
       
   214     if ( iLastObstacle >= iObstacles->Count() )
       
   215         {
       
   216         iLastObstacle = iObstacles->Count() - 1;
       
   217         }
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // RemoveFromOffset
       
   222 // ---------------------------------------------------------------------------
       
   223 void CFsTextViewerCoordinator::RemoveFromOffset( TInt aOffset )
       
   224     {
       
   225     FUNC_LOG;
       
   226     for ( TInt i = aOffset; i < iObstacles->Count(); ++i )
       
   227         {
       
   228         delete iObstacles->At(i);
       
   229         iObstacles->At(i) = NULL;
       
   230         iObstacles->Delete(i);
       
   231         }
       
   232     iLastObstacle = iObstacles->Count() - 1;
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // Reset
       
   237 // ---------------------------------------------------------------------------
       
   238 void CFsTextViewerCoordinator::Reset()
       
   239     {
       
   240     FUNC_LOG;
       
   241     iObstacles->ResetAndDestroy();
       
   242     iLastObstacle = -1;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // SetLeftMargin
       
   247 // ---------------------------------------------------------------------------
       
   248 void CFsTextViewerCoordinator::SetLeftMargin( TInt aMargin )
       
   249     {
       
   250     FUNC_LOG;
       
   251     iLeftMargin = aMargin;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // SetRightMargin
       
   256 // ---------------------------------------------------------------------------
       
   257 void CFsTextViewerCoordinator::SetRightMargin( TInt aMargin )
       
   258 	{
       
   259 	iRightMargin = aMargin;
       
   260 	}
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CFsTextViewerCoordinator
       
   264 // ---------------------------------------------------------------------------
       
   265 CFsTextViewerCoordinator::CFsTextViewerCoordinator()
       
   266     {
       
   267     FUNC_LOG;
       
   268     iLastObstacle = -1;
       
   269     iLeftMargin = 0;
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // ConstructL
       
   274 // ---------------------------------------------------------------------------
       
   275 void CFsTextViewerCoordinator::ConstructL()
       
   276     {
       
   277     FUNC_LOG;
       
   278     iObstacles = new (ELeave) CArrayPtrSeg<TRect>(10);
       
   279     }
       
   280