emailuis/uicomponents/src/fsrichtext.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c)  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 CFsTextViewer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "fsrichtext.h"
       
    21 #include "fsrichtextfields.h"
       
    22 #include "fstexture.h"
       
    23 #include <eikenv.h>
       
    24 #include <fbs.h>
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CMyPicture
       
    28 // ---------------------------------------------------------------------------
       
    29 EXPORT_C CMyPicture::CMyPicture( TSize aSize, CFbsBitmap& aBitmap )
       
    30     : iSizeInTwips(aSize), iBitmap(&aBitmap), iBitmapMask(NULL)
       
    31     {
       
    32     FUNC_LOG;
       
    33     }
       
    34     
       
    35 // ---------------------------------------------------------------------------
       
    36 // CMyPicture
       
    37 // ---------------------------------------------------------------------------
       
    38 EXPORT_C CMyPicture::CMyPicture( 
       
    39                 TSize aSize, CFbsBitmap& aBitmap, CFbsBitmap& aBitmapMask )
       
    40     : iSizeInTwips(aSize), iBitmap(&aBitmap), iBitmapMask(&aBitmapMask)
       
    41     {
       
    42     FUNC_LOG;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // ~CMyPicture
       
    47 // ---------------------------------------------------------------------------
       
    48 EXPORT_C CMyPicture::~CMyPicture()
       
    49     {
       
    50     FUNC_LOG;
       
    51     delete iBitmap;  
       
    52     delete iBitmapMask;    
       
    53     }
       
    54 // ---------------------------------------------------------------------------
       
    55 // Draw
       
    56 // ---------------------------------------------------------------------------
       
    57 EXPORT_C void CMyPicture::Draw( CGraphicsContext& /*aGc*/,
       
    58                              const TPoint& /*aTopLeft*/,
       
    59                              const TRect& /*aClipRect*/,
       
    60                              MGraphicsDeviceMap* /*aMap*/ ) const
       
    61     {
       
    62     FUNC_LOG;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // ExternalizeL
       
    67 // ---------------------------------------------------------------------------
       
    68 EXPORT_C void CMyPicture::ExternalizeL( RWriteStream& /*aStream*/ ) const
       
    69     {
       
    70     FUNC_LOG;
       
    71     }
       
    72         
       
    73 // ---------------------------------------------------------------------------
       
    74 // SetOriginalSizeInTwips
       
    75 // ---------------------------------------------------------------------------
       
    76 EXPORT_C void CMyPicture::SetOriginalSizeInTwips( TSize aSize )
       
    77     {
       
    78     FUNC_LOG;
       
    79     iSizeInTwips = aSize;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // GetOriginalSizeInTwips
       
    84 // ---------------------------------------------------------------------------
       
    85 EXPORT_C void CMyPicture::GetOriginalSizeInTwips( TSize& aSize ) const
       
    86     {
       
    87     FUNC_LOG;
       
    88     aSize = iSizeInTwips;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // GetBitmap
       
    93 // ---------------------------------------------------------------------------
       
    94 EXPORT_C CFbsBitmap* CMyPicture::GetBitmap()
       
    95     {
       
    96     FUNC_LOG;
       
    97     return iBitmap;
       
    98     }
       
    99     
       
   100 // ---------------------------------------------------------------------------
       
   101 // GetBitmapMask
       
   102 // ---------------------------------------------------------------------------
       
   103 EXPORT_C CFbsBitmap* CMyPicture::GetBitmapMask()
       
   104     {
       
   105     FUNC_LOG;
       
   106     return iBitmapMask;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // NewL
       
   111 // ---------------------------------------------------------------------------
       
   112 EXPORT_C CFsRichText* CFsRichText::NewL(const CParaFormatLayer* aGlobalParaLayer,
       
   113                        const CCharFormatLayer* aGlobalCharLayer,
       
   114                        TDocumentStorage aStorage,
       
   115                        TInt aDefaultTextGranularity,
       
   116                        TParaType aParaType)
       
   117     {
       
   118     FUNC_LOG;
       
   119     CFsRichText* self = 
       
   120         new(ELeave) CFsRichText(aGlobalParaLayer, aGlobalCharLayer);
       
   121     CleanupStack::PushL(self);
       
   122     self->ConstructL(aStorage, aDefaultTextGranularity, aParaType);
       
   123     CleanupStack::Pop(self);
       
   124     return self;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // NewL
       
   129 // ---------------------------------------------------------------------------
       
   130 EXPORT_C CFsRichText* CFsRichText::NewL(const CParaFormatLayer* aGlobalParaLayer,
       
   131                        const CCharFormatLayer* aGlobalCharLayer,
       
   132                        const CStyleList& aStyleList,
       
   133                        TDocumentStorage aStorage,
       
   134                        TInt aDefaultTextGranularity,
       
   135                        TParaType aParaType)
       
   136     {
       
   137     FUNC_LOG;
       
   138     CFsRichText* self = new(ELeave) CFsRichText(
       
   139             aGlobalParaLayer, 
       
   140             aGlobalCharLayer, 
       
   141             CONST_CAST(CStyleList*, &aStyleList));
       
   142     CleanupStack::PushL(self);
       
   143     self->ConstructL(aStorage, aDefaultTextGranularity, aParaType);
       
   144     CleanupStack::Pop(self);
       
   145     return self;
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // NewL
       
   151 // ---------------------------------------------------------------------------
       
   152 EXPORT_C CFsRichText* CFsRichText::NewL(const CStreamStore& aStore,
       
   153                        TStreamId aStreamId,
       
   154                        const CParaFormatLayer* aGlobalParaLayer,
       
   155                        const CCharFormatLayer* aGlobalCharLayer,
       
   156                        MTextFieldFactory* aFieldFactory,
       
   157                        TDocumentStorage aStorage)
       
   158     {
       
   159     FUNC_LOG;
       
   160     CFsRichText* self = 
       
   161         new(ELeave) CFsRichText(aGlobalParaLayer, aGlobalCharLayer);
       
   162     CleanupStack::PushL(self);
       
   163     self->ConstructL(aStore, aStreamId, NULL, NULL, aFieldFactory, aStorage);
       
   164     CleanupStack::Pop(self);
       
   165     return self;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // NewL
       
   170 // ---------------------------------------------------------------------------
       
   171 EXPORT_C CFsRichText* CFsRichText::NewL(const CStreamStore& aStore, 
       
   172                        TStreamId aStreamId,
       
   173                        const CParaFormatLayer* aGlobalParaLayer, 
       
   174                        const CCharFormatLayer* aGlobalCharLayer,
       
   175                        MPictureFactory* aPictureFactory, 
       
   176                        MRichTextStoreResolver* aStoreResolver,
       
   177                        MTextFieldFactory* aFieldFactory,
       
   178                        TDocumentStorage aStorage)
       
   179 
       
   180     {
       
   181     FUNC_LOG;
       
   182     CFsRichText* self = 
       
   183         new(ELeave) CFsRichText(aGlobalParaLayer, aGlobalCharLayer);
       
   184     CleanupStack::PushL(self);
       
   185     self->ConstructL(
       
   186             aStore, 
       
   187             aStreamId, 
       
   188             aPictureFactory, 
       
   189             aStoreResolver, 
       
   190             aFieldFactory, 
       
   191             aStorage);
       
   192     CleanupStack::Pop(self);
       
   193     return self;
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // ~CFsRichText()
       
   198 // ---------------------------------------------------------------------------
       
   199 EXPORT_C CFsRichText::~CFsRichText()
       
   200     {
       
   201     FUNC_LOG;
       
   202     iExpandAreaArray.Close();
       
   203     iHotSpotAreaArray.Close();
       
   204     iPictureAreaArray.Close();
       
   205     }
       
   206     
       
   207 // ---------------------------------------------------------------------------
       
   208 // CFsRichText
       
   209 // ---------------------------------------------------------------------------
       
   210 CFsRichText::CFsRichText(const CParaFormatLayer* aGlobalParaLayer, 
       
   211                  const CCharFormatLayer* aGlobalCharLayer,
       
   212                  CStyleList* aStyleList)
       
   213             :CRichText(aGlobalParaLayer, aGlobalCharLayer, aStyleList)
       
   214     {
       
   215     FUNC_LOG;
       
   216     
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // SetPictureL
       
   221 // ---------------------------------------------------------------------------
       
   222 EXPORT_C TBool CFsRichText::SetPictureL(TFileName aFileName, TInt aIndex)
       
   223     {
       
   224     FUNC_LOG;
       
   225     TBool retVal = ETrue;    
       
   226     
       
   227     TRichTextPictureArea richTextPictureArea;
       
   228     
       
   229     richTextPictureArea.iFileName = aFileName;
       
   230     richTextPictureArea.iPictureIndex = aIndex;
       
   231     
       
   232     iPictureAreaArray.AppendL(richTextPictureArea);
       
   233     
       
   234     return retVal;
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // SetHotSpotL
       
   239 // ---------------------------------------------------------------------------
       
   240 EXPORT_C TBool CFsRichText::SetHotSpotL(TInt aStartIndex, TInt aLength, TInt aId)
       
   241     {
       
   242     FUNC_LOG;
       
   243     TBool retVal = ETrue;
       
   244     
       
   245     for(TInt i = 0 ; i < iHotSpotAreaArray.Count() ; ++i)
       
   246         {
       
   247         if((aStartIndex >= iHotSpotAreaArray[i].iStartIndex && 
       
   248             aStartIndex < iHotSpotAreaArray[i].iStartIndex + iHotSpotAreaArray[i].iLength) ||
       
   249             (aStartIndex + aLength >= iHotSpotAreaArray[i].iStartIndex && 
       
   250             aStartIndex + aLength < iHotSpotAreaArray[i].iStartIndex + iHotSpotAreaArray[i].iLength))
       
   251             {
       
   252             retVal = EFalse;
       
   253             }
       
   254         }
       
   255     
       
   256     if( retVal )
       
   257         { 
       
   258         TRichTextHotSpotArea richTextHotSpotArea;
       
   259         
       
   260         richTextHotSpotArea.iStartIndex = aStartIndex;
       
   261         richTextHotSpotArea.iOriginalStartIndex = aStartIndex;
       
   262         richTextHotSpotArea.iLength = aLength;
       
   263         richTextHotSpotArea.iOriginalLength = aLength;
       
   264         richTextHotSpotArea.iId = aId;
       
   265         
       
   266         iHotSpotAreaArray.AppendL(richTextHotSpotArea);
       
   267         }
       
   268     
       
   269     return retVal;
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // SetExpandL
       
   274 // ---------------------------------------------------------------------------
       
   275 EXPORT_C TBool CFsRichText::SetExpandL(TInt aStartIndex, TInt aLength, TInt aCaptionLength)
       
   276     {
       
   277     FUNC_LOG;
       
   278     TBool retVal = ETrue;
       
   279     
       
   280     for(TInt i = 0 ; i < iExpandAreaArray.Count() ; ++i)
       
   281         {
       
   282         if((aStartIndex >= iExpandAreaArray[i].iStartIndex && 
       
   283             aStartIndex < iExpandAreaArray[i].iStartIndex + iExpandAreaArray[i].iLength) ||
       
   284             (aStartIndex + aLength >= iExpandAreaArray[i].iStartIndex && 
       
   285             aStartIndex + aLength < iExpandAreaArray[i].iStartIndex + iExpandAreaArray[i].iLength))
       
   286             {
       
   287             retVal = EFalse;
       
   288             }
       
   289         }
       
   290     
       
   291     if(retVal)
       
   292         { 
       
   293         TRichTextExapandArea richTextExpandArea;
       
   294         
       
   295         richTextExpandArea.iStartIndex = aStartIndex;
       
   296         richTextExpandArea.iLength = aLength;
       
   297         richTextExpandArea.iCaptionLength = aCaptionLength;
       
   298         richTextExpandArea.iIsExpand = EFalse;
       
   299         
       
   300         iExpandAreaArray.AppendL(richTextExpandArea);
       
   301         }
       
   302     
       
   303     return retVal;
       
   304     }
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // GetNumberOfExpandAreas
       
   308 // ---------------------------------------------------------------------------
       
   309 EXPORT_C TInt CFsRichText::GetNumberOfExpandAreas()
       
   310     {
       
   311     FUNC_LOG;
       
   312     return iExpandAreaArray.Count();
       
   313     }
       
   314     
       
   315 // ---------------------------------------------------------------------------
       
   316 // GetNumberOfPicture
       
   317 // ---------------------------------------------------------------------------
       
   318 EXPORT_C TInt CFsRichText::GetNumberOfPicture()
       
   319     {
       
   320     FUNC_LOG;
       
   321     return iPictureAreaArray.Count();
       
   322     }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // GetNumberOfHotSpotAreas
       
   326 // ---------------------------------------------------------------------------
       
   327 EXPORT_C TInt CFsRichText::GetNumberOfHotSpotAreas()
       
   328     {
       
   329     FUNC_LOG;
       
   330     return iHotSpotAreaArray.Count();
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // GetExpandAreaL
       
   335 // ---------------------------------------------------------------------------
       
   336 EXPORT_C TRichTextExapandArea CFsRichText::GetExpandAreaL(TInt aIndex)
       
   337     {
       
   338     FUNC_LOG;
       
   339     if(aIndex > iExpandAreaArray.Count())
       
   340         {
       
   341         User::Leave(KErrArgument);
       
   342         }
       
   343         
       
   344     return iExpandAreaArray[aIndex];
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // GetHotSpotAreaL
       
   349 // ---------------------------------------------------------------------------
       
   350 EXPORT_C TRichTextHotSpotArea CFsRichText::GetHotSpotAreaL(TInt aIndex)
       
   351     {
       
   352     FUNC_LOG;
       
   353     if(aIndex > iHotSpotAreaArray.Count())
       
   354         {
       
   355         User::Leave(KErrArgument);
       
   356         }
       
   357         
       
   358     return iHotSpotAreaArray[aIndex];
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // GetPictureArea
       
   363 // ---------------------------------------------------------------------------
       
   364 // <cmail>
       
   365 EXPORT_C TRichTextPictureArea CFsRichText::GetPictureAreaL(TInt aIndex)
       
   366 // </cmail>
       
   367     {
       
   368     FUNC_LOG;
       
   369     if(aIndex > iPictureAreaArray.Count())
       
   370         {
       
   371         User::Leave(KErrArgument);
       
   372         }
       
   373         
       
   374     return iPictureAreaArray[aIndex];    
       
   375     }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // Reset
       
   379 // ---------------------------------------------------------------------------
       
   380 EXPORT_C void CFsRichText::Reset()
       
   381     {
       
   382     FUNC_LOG;
       
   383     CRichText::Reset();
       
   384     iExpandAreaArray.Reset();
       
   385     iHotSpotAreaArray.Reset();
       
   386     iPictureAreaArray.Reset();
       
   387     }
       
   388