uiacceltk/hitchcock/coretoolkit/src/HuiTextMesh.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-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 CHuiTextMesh. CHuiTextMesh stores a cached 
       
    15 *                version of a text string.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20  
       
    21 #include <AknUtils.h>
       
    22 #include "alf/alfconstants.h"
       
    23 
       
    24 #include "uiacceltk/HuiTextMesh.h"
       
    25 #include "uiacceltk/HuiStatic.h"
       
    26 #include "uiacceltk/HuiFont.h"
       
    27 #include "uiacceltk/HuiTexture.h"
       
    28 #include "uiacceltk/HuiGc.h"
       
    29 #include "uiacceltk/HuiUtil.h"
       
    30 #include "uiacceltk/HuiPanic.h"
       
    31 #include "uiacceltk/HuiEnv.h"
       
    32 #include "uiacceltk/huitextstylemanager.h"
       
    33 #include "uiacceltk/huitextstyle.h"
       
    34 #include "uiacceltk/HuiDisplay.h"
       
    35 #include "HuiRosterImpl.h"
       
    36 
       
    37   
       
    38 CHuiTextMesh::CHuiTextMesh()
       
    39         : iTextStyleId(0),
       
    40           iLineSpacing(0),        
       
    41           iTextMeshScale(1.0),        
       
    42           iLineMode(ELineModeTruncate),
       
    43           iMaxLineWidth(KMaxTInt),
       
    44           iScaledMaxLineWidth(KMaxTInt),
       
    45           iMaxLineCount(KMaxTInt),          
       
    46           iRasterizedShadow(EFalse)
       
    47     {
       
    48     }
       
    49 
       
    50     
       
    51 void CHuiTextMesh::ConstructL()
       
    52     {
       
    53     // Register as observer
       
    54     CHuiStatic::Env().iActionObservers.AppendL(*this);
       
    55     RPointerArray<CHuiDisplay> displays = CHuiStatic::Env().Displays();
       
    56     for(TInt i = 0; i<displays.Count(); i++)
       
    57         {
       
    58         displays[i]->iVisibleAreaObservers.AppendL(*this);
       
    59         
       
    60         if (displays[i]->IsDisplayTypeTvOut())
       
    61             {
       
    62             displays[i]->iDeletionObservers.AppendL(*this);
       
    63             }
       
    64         }
       
    65     ReleaseFont();
       
    66         
       
    67     CalculateTvOutScales();
       
    68     }
       
    69    
       
    70 
       
    71 CHuiTextMesh::~CHuiTextMesh()
       
    72     {
       
    73     // Remove observers
       
    74     CHuiStatic::Env().iActionObservers.RemoveIfFound(*this);
       
    75     RPointerArray<CHuiDisplay> displays = CHuiStatic::Env().Displays();
       
    76     for(TInt i = 0; i<displays.Count(); i++)
       
    77         {
       
    78         displays[i]->iVisibleAreaObservers.RemoveIfFound(*this);
       
    79         
       
    80         if (displays[i]->IsDisplayTypeTvOut())
       
    81             {
       
    82             displays[i]->iDeletionObservers.RemoveIfFound(*this);
       
    83             }
       
    84         }
       
    85         
       
    86     delete iString;
       
    87     iPictographInterface = NULL;
       
    88     }
       
    89     
       
    90     
       
    91 void CHuiTextMesh::Reset()
       
    92     {
       
    93     delete iString; 
       
    94     iString = 0;
       
    95     }
       
    96 
       
    97 
       
    98 void CHuiTextMesh::SetLineMode(TLineMode aLineMode)
       
    99     {
       
   100     iLineMode = aLineMode;
       
   101     }
       
   102     
       
   103 
       
   104 CHuiTextMesh::TLineMode CHuiTextMesh::LineMode() const
       
   105     {
       
   106     return iLineMode;
       
   107     }
       
   108 
       
   109 
       
   110 TBool CHuiTextMesh::SetMaxLineWidth(TInt aMaxLineWidth)
       
   111     {
       
   112     // Note: this do not tell if only scaling has been changed.
       
   113     TBool isDifferent = (iMaxLineWidth != aMaxLineWidth);
       
   114     iMaxLineWidth = aMaxLineWidth;
       
   115 
       
   116     // Max line width has to be scaled to get proper line wrapping
       
   117     if(iTextMeshScale != 1 && aMaxLineWidth != KMaxTInt)
       
   118         {
       
   119         // Scale width with Y-scale to retain correct font proportions
       
   120         iScaledMaxLineWidth = HUI_ROUND_FLOAT_TO_INT( aMaxLineWidth * iTextMeshScale );
       
   121         } 
       
   122 
       
   123     return isDifferent;
       
   124     }
       
   125 
       
   126 
       
   127 TInt CHuiTextMesh::MaxLineWidth() const
       
   128     {
       
   129     if(iTextMeshScale != 1)
       
   130         {
       
   131         return iScaledMaxLineWidth;
       
   132         } 
       
   133 
       
   134     return iMaxLineWidth;
       
   135     }
       
   136 
       
   137 
       
   138 TBool CHuiTextMesh::SetMaxLineCount(TInt aMaxLineCount)
       
   139     {
       
   140     TBool isDifferent = (iMaxLineCount != aMaxLineCount);
       
   141     iMaxLineCount = aMaxLineCount;
       
   142     return isDifferent;
       
   143     }
       
   144 
       
   145 
       
   146 TInt CHuiTextMesh::MaxLineCount() const
       
   147     {
       
   148     return iMaxLineCount;
       
   149     }
       
   150       
       
   151 
       
   152 void CHuiTextMesh::SetFontL(const THuiFont& aFont, TBool aRefreshTextures)
       
   153     {
       
   154     THuiTextStyle* textStyle = CHuiStatic::Env().TextStyleManager().TextStyle(iTextStyleId);
       
   155     textStyle->SetFont(aFont);
       
   156     
       
   157     if(iString && aRefreshTextures)
       
   158         {
       
   159         BuildL(ETrue);
       
   160         }
       
   161     }
       
   162 
       
   163 
       
   164 void CHuiTextMesh::SetTextL(const TDesC& aText, TBool aRasterize)
       
   165     {
       
   166     delete iString; iString = 0;
       
   167     iString = aText.AllocL();
       
   168 
       
   169     // Rasterize text into textures.
       
   170     BuildL(aRasterize);    
       
   171     }
       
   172 
       
   173     
       
   174 const TDesC* CHuiTextMesh::Text() const
       
   175     {
       
   176     return iString;
       
   177     }
       
   178     
       
   179     
       
   180 void CHuiTextMesh::EnableRasterizedShadow(const TBool aIsEnabled)
       
   181     {
       
   182     TBool isChanged = ETrue;
       
   183     if ( (iRasterizedShadow && aIsEnabled) || 
       
   184          ( !iRasterizedShadow && !aIsEnabled ) )
       
   185         {
       
   186         isChanged = EFalse;
       
   187         }
       
   188         
       
   189     iRasterizedShadow = aIsEnabled;
       
   190         
       
   191     if(isChanged && iString)
       
   192         {
       
   193         // Status of rasterized shadow has changed.
       
   194         // Assuming the sharp shadow is prerendered.
       
   195         TRAP_IGNORE(BuildL(ETrue))
       
   196         }
       
   197     }
       
   198    
       
   199    
       
   200 TBool CHuiTextMesh::RasterizedShadow() const
       
   201     {
       
   202     if ( iVisual )
       
   203         {
       
   204         return TBool(iVisual->DropShadowHandler());
       
   205         }
       
   206     return iRasterizedShadow;
       
   207     }
       
   208      
       
   209    
       
   210 TSize CHuiTextMesh::Extents() const
       
   211     {
       
   212     TSize extents = iExtents;
       
   213     
       
   214     if(iTextMeshScale != 1)
       
   215         {
       
   216         extents.iHeight = iScaledExtents.iHeight;
       
   217         extents.iWidth = iScaledExtents.iWidth;
       
   218         }
       
   219     
       
   220     return extents;
       
   221     }
       
   222     
       
   223 void CHuiTextMesh::ExpandRectWithShadow(TRect& /*aRect*/) const
       
   224     {
       
   225     }
       
   226 
       
   227 void CHuiTextMesh::SetExtents(const TSize& aExtents)
       
   228     {
       
   229     TBool isChanged = (iExtents != aExtents);
       
   230     
       
   231     iExtents = aExtents;
       
   232     
       
   233     if(iTextMeshScale != 1 && isChanged)
       
   234         {
       
   235         iScaledExtents.iHeight = HUI_ROUND_FLOAT_TO_INT( aExtents.iHeight/iTextMeshScale );
       
   236         iScaledExtents.iWidth = HUI_ROUND_FLOAT_TO_INT( aExtents.iWidth/iTextMeshScale );
       
   237         }
       
   238     }
       
   239 
       
   240 
       
   241 void CHuiTextMesh::InitPictographsL(CAknPictographInterface* aInterface)
       
   242     {
       
   243     iPictographInterface = aInterface;    
       
   244     }
       
   245 
       
   246 
       
   247 void CHuiTextMesh::SetTextStyle(TInt aTextStyleId)
       
   248     {
       
   249     iTextStyleId = aTextStyleId;
       
   250     ReleaseFont(); 
       
   251     }
       
   252 
       
   253 
       
   254 TInt CHuiTextMesh::TextStyle() const
       
   255 	{
       
   256 	return iTextStyleId;
       
   257 	}
       
   258 
       
   259 
       
   260 void CHuiTextMesh::BuildPictographsL()
       
   261     {        
       
   262     }
       
   263 
       
   264 
       
   265 void CHuiTextMesh::SetLineSpacing(TInt aLineSpacingInPixels)
       
   266     {
       
   267     iLineSpacing = aLineSpacingInPixels;
       
   268     }
       
   269     
       
   270     
       
   271 void CHuiTextMesh::ReleaseFont()
       
   272     {
       
   273     THuiTextStyle* textStyle = CHuiStatic::Env().TextStyleManager().TextStyle(iTextStyleId);
       
   274     textStyle->Font().ReleaseFont();
       
   275     }
       
   276     
       
   277 
       
   278 void CHuiTextMesh::CalculateTvOutScales()
       
   279     {
       
   280     // Calculate the TV Out scales
       
   281     RPointerArray<CHuiDisplay> displays = CHuiStatic::Env().Displays();
       
   282     for(TInt i = 0; i<CHuiStatic::Env().DisplayCount(); i++)
       
   283         {
       
   284         if (displays[i]->IsDisplayTypeTvOut())
       
   285             {
       
   286             // Scale with height to retain correct font proportions
       
   287             iTextMeshScale = (TReal32)displays[i]->Size().iHeight / (TReal32)displays[i]->RosterImpl().Rect().Height();
       
   288             }
       
   289         }
       
   290     }
       
   291     
       
   292     
       
   293 void CHuiTextMesh::NotifyDisplayVisibleAreaChanged(CHuiDisplay& aDisplay)
       
   294     {
       
   295     if (aDisplay.IsDisplayTypeTvOut())
       
   296         {
       
   297         iTextMeshScale = (TReal32)aDisplay.Size().iHeight / (TReal32)aDisplay.RosterImpl().Rect().Height();
       
   298         }
       
   299         
       
   300     ReleaseFont();
       
   301     }
       
   302 
       
   303 
       
   304 void CHuiTextMesh::NotifyDisplayDeletion(CHuiDisplay& aDisplay)
       
   305     {
       
   306     if (iString && aDisplay.IsDisplayTypeTvOut())
       
   307         {
       
   308         iTextMeshScale = 1.0;
       
   309         ReleaseFont();
       
   310         ResetLines();
       
   311         ResetPictographLines();
       
   312         // Updates the mesh and the extents
       
   313         TRAP_IGNORE(BuildL(ETrue));
       
   314         }
       
   315     }
       
   316 
       
   317 
       
   318 void CHuiTextMesh::HandleActionL(const THuiActionCommand& aActionCommand)
       
   319     {
       
   320     if(aActionCommand.Id() == KHuiActionNewTVOutDisplayUid.iUid)
       
   321         {
       
   322         // find the TvOut display
       
   323         RPointerArray<CHuiDisplay> displays = CHuiStatic::Env().Displays();
       
   324         for(TInt i = 0; i<displays.Count(); i++)
       
   325             {
       
   326             if (displays[i]->IsDisplayTypeTvOut())
       
   327                 {
       
   328                 // Register as observer
       
   329                 displays[i]->iVisibleAreaObservers.AppendIfNotFoundL(*this);
       
   330                 displays[i]->iDeletionObservers.AppendIfNotFoundL(*this);
       
   331                 
       
   332                 // calculate new scale factors
       
   333                 CalculateTvOutScales();
       
   334                 }
       
   335             }
       
   336             
       
   337         ReleaseFont();
       
   338         ResetLines();
       
   339         ResetPictographLines();
       
   340         // Updates the mesh and the extents
       
   341         if(Text() != NULL)
       
   342             {
       
   343             BuildL(ETrue);
       
   344             }
       
   345         }
       
   346             
       
   347     else if ( aActionCommand.Id() == KAknsMessageSkinChange )
       
   348         {
       
   349         // When the resolution/skin changes and this text visual is not in 
       
   350         // the roster, the change notification is not received through the normal
       
   351         // route aka CHuiVisual::NotifySkinChangedL() 
       
   352         //
       
   353         // Setting the iMaxLineWidth into -1 is a hack. It would be better to
       
   354         // set the iMeshUpdated into EFalse in the CHuiTextVisual, but this class
       
   355         // has no pointer to the owning text visual. The text visual calls the 
       
   356         // SetMaxLineWidth function before it draws this mesh so the "changed" 
       
   357         // notification is informed through that function call.
       
   358         iMaxLineWidth = -1;
       
   359         }
       
   360     else
       
   361         {
       
   362         // For PC lint
       
   363         }
       
   364     }
       
   365 
       
   366 void CHuiTextMesh::SetRelatedVisual(CHuiVisual* aVisual)
       
   367     {
       
   368     iVisual = aVisual;
       
   369     }
       
   370 
       
   371 void CHuiTextMesh::UpdateMeshL(const TDesC8& /*aBuffer*/)
       
   372     {
       
   373     }