javauis/lcdui_akn/lcdui/src/CMIDItemLabel.cpp
changeset 21 2a9601315dfc
child 34 71c436fe3ce0
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2003-2006 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:  Used to draw the item labels and some string items. Provides
       
    15 *                word wrapping and other functionality.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <coemain.h>
       
    21 // API for CEikLabel used in several places
       
    22 #include <eikcapc.h>
       
    23 // API for text wrapping
       
    24 #include <AknBidiTextUtils.h>
       
    25 // using CAknLayoutFont for retrieving height in pixels of each line
       
    26 #include <AknLayoutFont.h>
       
    27 // used in constructor for obtaining label color from skin
       
    28 #include <AknsDrawUtils.h>
       
    29 
       
    30 #include "CMIDControlItem.h"
       
    31 #include "CMIDGc.h"
       
    32 // using CMIDUtils::IsLineSeparator
       
    33 #include "CMIDUtils.h"
       
    34 #include "CMIDCommand.h"
       
    35 #include "CMIDForm.h"
       
    36 #include "CMIDCommandList.h"
       
    37 #include "CMIDItemLabel.h"
       
    38 #include "CMIDFont.h"
       
    39 
       
    40 // using TAknWindowLineLayout (in UpdateMargins function)
       
    41 #include <applayout.cdl.h>
       
    42 // LAF - AknLayoutScalable_Avkon::form2_midp_label_pane_cp (in UpdateMargins function)
       
    43 #include <aknlayoutscalable_avkon.cdl.h>
       
    44 
       
    45 
       
    46 CMIDItemLabel* CMIDItemLabel::NewL(TInt aMaxWidth, TBool aLabelBeforeContent,
       
    47                                    TInt aMaxNumberOfLines, const CMIDFont::TDefaultId& aDefaultFontId, TBool aIsContent)
       
    48 {
       
    49     CMIDItemLabel* self = new(ELeave) CMIDItemLabel(aMaxWidth,
       
    50             aLabelBeforeContent, aMaxNumberOfLines, aDefaultFontId, aIsContent);
       
    51 
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54 
       
    55     CleanupStack::Pop(self);
       
    56     return self;
       
    57 }
       
    58 
       
    59 CMIDItemLabel::~CMIDItemLabel()
       
    60 {
       
    61     delete iText;
       
    62     iText = NULL;
       
    63     delete iWrappedText;
       
    64     iWrappedText = NULL;
       
    65 
       
    66     delete iWrappedArray;
       
    67     iWrappedArray = NULL;
       
    68 
       
    69     delete iLineWidthArray;
       
    70     iLineWidthArray = NULL;
       
    71 
       
    72     ResetLabelArray();
       
    73     delete iLabelArray;
       
    74     iLabelArray = NULL;
       
    75 
       
    76     delete iPictographInterface;
       
    77     iPictographInterface = NULL;
       
    78 }
       
    79 
       
    80 /** Returns the width of the ellipsis truncation character
       
    81     and the average line height */
       
    82 TSize CMIDItemLabel::MinimumSize()
       
    83 {
       
    84     if (iLabelBeforeContent)
       
    85     {
       
    86         return TSize(Font()->CharWidthInPixels(KEllipsis) + iLabelMargins.iLeft
       
    87                      + iLabelMargins.iRight,
       
    88                      LineHeight() + iLabelMargins.iTop);
       
    89     }
       
    90     else
       
    91     {
       
    92         return TSize(Font()->CharWidthInPixels(KEllipsis) + iLabelMargins.iLeft
       
    93                      + iLabelMargins.iRight,
       
    94                      LineHeight() + iLabelMargins.iBottom);
       
    95     }
       
    96 
       
    97 }
       
    98 
       
    99 TInt CMIDItemLabel::CountComponentControls() const
       
   100 {
       
   101     return iLabelArray->Count();
       
   102 }
       
   103 
       
   104 CCoeControl* CMIDItemLabel::ComponentControl(TInt aIndex) const
       
   105 {
       
   106     return (*iLabelArray)[aIndex];
       
   107 }
       
   108 
       
   109 /**
       
   110 Returns the preferred size, this is not the one given by the
       
   111 application but the size that allows the text to be displayed
       
   112 without wrapping at word level but only wrapping at line level.
       
   113 */
       
   114 TSize CMIDItemLabel::PreferredSize() const
       
   115 {
       
   116     if (iLabelBeforeContent)
       
   117     {
       
   118         return TSize(PreferredWidth(), LineHeight() + iLabelMargins.iTop);
       
   119     }
       
   120     else
       
   121     {
       
   122         return TSize(PreferredWidth(), LineHeight() + iLabelMargins.iBottom);
       
   123     }
       
   124 }
       
   125 
       
   126 // it is up to the component changing the text to tell the form to update. This will lead to
       
   127 // the label being re-wrapped
       
   128 void CMIDItemLabel::SetTextL(const TDesC& aText)
       
   129 {
       
   130     delete iText;
       
   131     iText = NULL;
       
   132 
       
   133     iText = aText.AllocL();
       
   134 
       
   135     iWrappedArray->Reset();
       
   136     ResetLabelArray();
       
   137 
       
   138     delete iWrappedText;
       
   139     iWrappedText = NULL;
       
   140 
       
   141 }
       
   142 
       
   143 /**
       
   144     Return the width of the longest line amongst those
       
   145     allowed by iMaxNumberOfLines
       
   146 */
       
   147 TInt CMIDItemLabel::PreferredWidth() const
       
   148 {
       
   149     return Min((LongestLineWidth() + iLabelMargins.iLeft + iLabelMargins.iRight), iMaxWidth);
       
   150 }
       
   151 
       
   152 /** Return the width of the longest line as long as this line
       
   153     is not beyond iMaxNumberOfLines. If we haven't exausted
       
   154     all the text we add the width of the ellipses truncation indicator.
       
   155     */
       
   156 TInt CMIDItemLabel::LongestLineWidth() const
       
   157 {
       
   158     if (!iText)
       
   159     {
       
   160         return Font()->CharWidthInPixels(KEllipsis);
       
   161     }
       
   162 
       
   163     TInt length = iText->Length();
       
   164     TInt width = 0;
       
   165     TBool inLine = EFalse;
       
   166     TInt lineStartIdx = 0;
       
   167     TInt numLines = 0;
       
   168 
       
   169     for (TInt i=0; i < length; i++)
       
   170     {
       
   171         if (!IsLineSeparator((*iText)[i]) && !inLine)
       
   172         {
       
   173             inLine = ETrue;
       
   174             lineStartIdx = i;
       
   175         }
       
   176         else if (IsLineSeparator((*iText)[i]) && inLine)
       
   177         {
       
   178             inLine = EFalse;
       
   179             numLines++;
       
   180 
       
   181             TPtrC ptr = iText->Mid(lineStartIdx, i - lineStartIdx);
       
   182             TInt w = Font()->TextWidthInPixels(ptr);
       
   183             if (w > width)
       
   184             {
       
   185                 width = w;
       
   186             }
       
   187         }
       
   188         else if (inLine && (i == (length - 1)))
       
   189         {
       
   190             inLine = EFalse;
       
   191             TPtrC ptr = iText->Mid(lineStartIdx, (i - lineStartIdx) + 1);
       
   192             TInt w = Font()->TextWidthInPixels(ptr);
       
   193             if (w > width)
       
   194             {
       
   195                 width = w;
       
   196             }
       
   197         }
       
   198 
       
   199         if ((iMaxNumberOfLines > 0) && (numLines >= iMaxNumberOfLines))
       
   200         {
       
   201             if (i != (length - 1))
       
   202             {//if there is still text add space for ellipsis truncation
       
   203                 width += Font()->CharWidthInPixels(KEllipsis);
       
   204             }
       
   205             break;
       
   206         }
       
   207     }
       
   208 
       
   209     return width;
       
   210 }
       
   211 
       
   212 /**
       
   213  *  Returns the height in pixels of each line
       
   214  */
       
   215 TInt CMIDItemLabel::LineHeight() const
       
   216 {
       
   217     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull(Font());
       
   218 
       
   219     TInt height = 0;
       
   220     if (layoutFont)
       
   221     {
       
   222         // Calculate height of one line
       
   223         height += layoutFont->TextPaneHeight();
       
   224     }
       
   225     else
       
   226     {
       
   227         height += Font()->HeightInPixels();
       
   228     }
       
   229     return height;
       
   230 }
       
   231 
       
   232 /**
       
   233  * Prepare the line width array to the case of all lines having the same
       
   234  * width and then call WrapTextAndSetSizeL()
       
   235  *
       
   236  * @see WrapTextAndSetSizeL()
       
   237  */
       
   238 void CMIDItemLabel::SetWidthL(TInt aLineWidth)
       
   239 {
       
   240     iLineWidthArray->Reset();
       
   241     iLineWidthArray->AppendL(aLineWidth - iLabelMargins.iLeft - iLabelMargins.iRight);
       
   242 
       
   243     WrapTextAndSetSizeL();
       
   244 }
       
   245 
       
   246 /**
       
   247  *  Wrap the text and set the size of the control to the longest line width and to the
       
   248  *  sum of the height of the lines of text.
       
   249  */
       
   250 void CMIDItemLabel::WrapTextAndSetSizeL()
       
   251 {
       
   252 
       
   253     iWrappedArray->Reset();
       
   254     ResetLabelArray();
       
   255 
       
   256     delete iWrappedText;
       
   257     iWrappedText = NULL;
       
   258 
       
   259     if (iMaxNumberOfLines > 0)
       
   260     {
       
   261         iWrappedText = HBufC::NewL(iText->Length()
       
   262                                    + (iMaxNumberOfLines * KAknBidiExtraSpacePerLine));
       
   263 
       
   264         TPtr wrappedTextPtr = iWrappedText->Des();
       
   265         wrappedTextPtr.Append(*iText);
       
   266 
       
   267         CArrayFixFlat<TInt>* lineWidthArray = new(ELeave) CArrayFixFlat<TInt>(iMaxNumberOfLines);
       
   268         CleanupStack::PushL(lineWidthArray);
       
   269 
       
   270         TInt numWidthsAvailable = iLineWidthArray->Count();
       
   271         ASSERT(numWidthsAvailable > 0);
       
   272 
       
   273         for (TInt i = 0; i < iMaxNumberOfLines; i++)
       
   274         {
       
   275             TInt width = i < numWidthsAvailable ?
       
   276                          (*iLineWidthArray)[i] :
       
   277                          (*iLineWidthArray)[numWidthsAvailable - 1];
       
   278             lineWidthArray->AppendL(width);
       
   279         }
       
   280 
       
   281         AknBidiTextUtils::ConvertToVisualAndWrapToArrayL
       
   282         (wrappedTextPtr, *lineWidthArray, *Font(), *iWrappedArray, ETrue);
       
   283 
       
   284         CleanupStack::PopAndDestroy(lineWidthArray);
       
   285     }
       
   286     else if (iMaxNumberOfLines == -1)
       
   287     { //unlimited wrapping
       
   288         iWrappedText= AknBidiTextUtils::ConvertToVisualAndWrapToArrayWholeTextL
       
   289                       (*iText, *iLineWidthArray, *Font(), *iWrappedArray);
       
   290     }
       
   291 
       
   292     TInt width = 0;
       
   293     TInt numOfLabels = iWrappedArray->Count();
       
   294     for (TInt i=0; i < numOfLabels; i++)
       
   295     {
       
   296         CEikLabel* tmp = new(ELeave) CEikLabel();
       
   297         CleanupStack::PushL(tmp);
       
   298         tmp->UseLogicalToVisualConversion(EFalse);
       
   299         tmp->OverrideColorL(EColorLabelText, iColor);
       
   300         tmp->SetFont(Font());
       
   301         tmp->SetTextL((*iWrappedArray)[i]);
       
   302         tmp->SetSize(CMIDItemLabel::PropperEikLabelMinumumSize(*tmp));
       
   303         tmp->EnablePictographsL(*iPictographInterface);
       
   304         iLabelArray->AppendL(tmp);
       
   305         CleanupStack::Pop(tmp);
       
   306         TSize lineSize = tmp->Size();
       
   307         width = width < lineSize.iWidth ? lineSize.iWidth : width;
       
   308         tmp->ActivateL();
       
   309     }
       
   310 
       
   311     SetUnderlined(iUnderlined);
       
   312 
       
   313     // we rely on set extent being called at some later stage to trigger SizeChanged()
       
   314     // Label Top margin is added to label height
       
   315 
       
   316     width += iLabelMargins.iLeft + iLabelMargins.iRight;
       
   317     TInt height = LineHeight() * NumLines();
       
   318     if (iIsContent)
       
   319     {
       
   320         // adds margin to bottom of string item content
       
   321         height += iLabelMargins.iBottom;
       
   322     }
       
   323     if (iLabelBeforeContent)
       
   324     {
       
   325         iSize = TSize(width, height + iLabelMargins.iTop);
       
   326     }
       
   327     else
       
   328     {
       
   329         iSize = TSize(width, height + iLabelMargins.iBottom);
       
   330     }
       
   331 }
       
   332 
       
   333 /**
       
   334  *  Prepare the line width array for the case in which the first line has
       
   335  *  a different width or the remaining lines and then call WrapTextAndSetSizeL()
       
   336  *
       
   337  * @see WrapTextAndSetSizeL()
       
   338  */
       
   339 void CMIDItemLabel::SetVariableWidthL(TInt aFirstWidth, TInt aSecondWidth)
       
   340 {
       
   341     iLineWidthArray->Reset();
       
   342 
       
   343     iLineWidthArray->AppendL(aFirstWidth - iLabelMargins.iLeft - iLabelMargins.iRight);
       
   344     iLineWidthArray->AppendL(aSecondWidth - iLabelMargins.iLeft - iLabelMargins.iRight);
       
   345 
       
   346     WrapTextAndSetSizeL();
       
   347 }
       
   348 
       
   349 
       
   350 /** Returns the width in pixels of the first word */
       
   351 TInt CMIDItemLabel::FirstWordWidth() const
       
   352 {
       
   353     if (!iText)
       
   354     {
       
   355         return Font()->CharWidthInPixels(KEllipsis);
       
   356     }
       
   357 
       
   358     TInt pos = iText->Length();
       
   359     for (TInt i = 0; i < iText->Length(); i++)
       
   360     {
       
   361         if (TChar((*iText)[i]).IsSpace() || IsLineSeparator((*iText)[i]))
       
   362         {
       
   363             pos = i;
       
   364             break;
       
   365         }
       
   366     }
       
   367 
       
   368     return Font()->TextWidthInPixels(iText->Left(pos));
       
   369 }
       
   370 
       
   371 void CMIDItemLabel::SetCentered(TBool aValue)
       
   372 {
       
   373     if (aValue != iCentered)
       
   374     {
       
   375         iCentered = aValue;
       
   376 
       
   377         // re-layout the lables
       
   378         SizeChanged();
       
   379     }
       
   380 }
       
   381 
       
   382 void CMIDItemLabel::SetUnderlined(TBool aUnderlined)
       
   383 {
       
   384     iUnderlined = aUnderlined;
       
   385     TInt i;
       
   386     for (i=0; i < iLabelArray->Count(); i++)
       
   387     {
       
   388         CEikLabel* label = (CEikLabel*)((*iLabelArray)[i]);
       
   389         label->SetUnderlining(iUnderlined);
       
   390     }
       
   391 }
       
   392 
       
   393 void CMIDItemLabel::SetColorL(TRgb aColor)
       
   394 {
       
   395     iColor = aColor;
       
   396     AknLayoutUtils::OverrideControlColorL(*this, EColorLabelText, iColor);
       
   397     TInt i;
       
   398     for (i=0; i < iLabelArray->Count(); i++)
       
   399     {
       
   400         CEikLabel* label = (CEikLabel*)((*iLabelArray)[i]);
       
   401         label->OverrideColorL(EColorLabelText, iColor);
       
   402     }
       
   403 }
       
   404 
       
   405 void CMIDItemLabel::SetEmphasisL(TBool aEmphasis)
       
   406 {
       
   407     TInt i;
       
   408     CEikLabel::TTextEmphasis emphasis = aEmphasis ?
       
   409                                         CEikLabel::EPartialEmphasis :
       
   410                                         CEikLabel::ENoEmphasis;
       
   411 
       
   412     for (i=0; i < iLabelArray->Count(); i++)
       
   413     {
       
   414         CEikLabel* label = (CEikLabel*)((*iLabelArray)[i]);
       
   415         label->OverrideColorL(EColorLabelHighlightPartialEmphasis, TRgb(0x32, 0x99, 0xCC));
       
   416         label->SetEmphasis(emphasis);
       
   417     }
       
   418 }
       
   419 
       
   420 TRgb CMIDItemLabel::GetDefaultColor()
       
   421 {
       
   422     return iDefaultColor;
       
   423 }
       
   424 
       
   425 void CMIDItemLabel::SetFont(const MMIDFont* aFont)
       
   426 {
       
   427     iFont = aFont;
       
   428     PrepareFont();
       
   429 
       
   430     for (TInt i=0; i < iLabelArray->Count(); i++)
       
   431     {
       
   432         CEikLabel* label = (CEikLabel*)((*iLabelArray)[i]);
       
   433         label->SetFont(Font());
       
   434     }
       
   435 }
       
   436 
       
   437 const CFont* CMIDItemLabel::Font() const
       
   438 {
       
   439     return iFont ? const_cast<MMIDFont*>(iFont)->Font(ETrue) : CMIDFont::DefaultFont(iDefaultFontId);
       
   440 }
       
   441 
       
   442 CEikLabel* CMIDItemLabel::LabelAtIdx(TInt aIdx)
       
   443 {
       
   444     if (aIdx > -1 && aIdx < iLabelArray->Count())
       
   445     {
       
   446         return (*iLabelArray)[aIdx];
       
   447     }
       
   448     return NULL;
       
   449 }
       
   450 
       
   451 void CMIDItemLabel::SetMaxWidth(TInt aMaxWidth)
       
   452 {
       
   453     iMaxWidth = aMaxWidth;
       
   454 }
       
   455 
       
   456 CMIDItemLabel::CMIDItemLabel(TInt aMaxWidth, TBool aLabelBeforeContent, TInt aMaxNumberOfLines,
       
   457                              const CMIDFont::TDefaultId& aDefaultFontId, TBool aIsContent) :
       
   458         iDefaultFontId(aDefaultFontId), iMaxWidth(aMaxWidth),
       
   459         iMaxNumberOfLines(aMaxNumberOfLines), iLabelBeforeContent(aLabelBeforeContent), iIsContent(aIsContent)
       
   460 {
       
   461 }
       
   462 
       
   463 void CMIDItemLabel::ConstructL()
       
   464 {
       
   465     iWrappedArray = new(ELeave) CArrayFixFlat<TPtrC>(2);
       
   466     iLabelArray = new(ELeave) CArrayFixFlat<CEikLabel*>(2);
       
   467 
       
   468     iLineWidthArray = new(ELeave) CArrayFixFlat<TInt>(2);
       
   469 
       
   470     // Label should have proper color. This color is obtained from skin.
       
   471     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   472     if (skin)
       
   473     {
       
   474         AknsUtils::GetCachedColor(skin, iDefaultColor, KAknsIIDQsnTextColors,
       
   475                                   EAknsCIQsnTextColorsCG8);
       
   476         iColor = iDefaultColor;
       
   477     }
       
   478 
       
   479     iPictographInterface = CAknPictographInterface::NewL(*this, *this);
       
   480     UpdateMargins();
       
   481     PrepareFont();
       
   482 }
       
   483 
       
   484 void CMIDItemLabel::UpdateMargins()
       
   485 {
       
   486     TAknWindowLineLayout layout =
       
   487         AknLayoutScalable_Avkon::form2_midp_label_pane_cp(0).LayoutLine();
       
   488 
       
   489     iLabelMargins.iTop    = layout.it;
       
   490     iLabelMargins.iLeft   = layout.il;
       
   491     iLabelMargins.iRight  = layout.ir;
       
   492 
       
   493     // bottom margin is defined only for ImageItem, so it's read from imageitem's label pane
       
   494     layout = AknLayoutScalable_Avkon::form2_midp_label_pane_cp(2).LayoutLine();
       
   495 
       
   496     iLabelMargins.iBottom = layout.ib;
       
   497 
       
   498 }
       
   499 
       
   500 /**
       
   501 * Set font size for later using in labels layouting (@see SizeChanged())
       
   502 */
       
   503 void CMIDItemLabel::PrepareFont()
       
   504 {
       
   505     const TInt KJavaFontSmall  = 16; // Java-side small font
       
   506     const TInt KJavaFontMedium = 18; // Java-side medium font
       
   507 
       
   508     iFontSize = 1; //if ItemLabel is label part of StringItem (or some other item which has label)
       
   509     if (iIsContent)
       
   510     {
       
   511         //if ItemLabel is content part of StringItem font can have three different heights
       
   512         //according to java side font
       
   513         TInt fontHeight = Font()->HeightInPixels();
       
   514         if (fontHeight <= KJavaFontSmall)   // Java-side small font
       
   515         {
       
   516             iFontSize = 0;
       
   517         }
       
   518         else if (fontHeight <= KJavaFontMedium)   // Java-side medium font
       
   519         {
       
   520             iFontSize = 1;
       
   521         }
       
   522         else // Java-side large font
       
   523         {
       
   524             iFontSize = 2;
       
   525         }
       
   526     }
       
   527 }
       
   528 
       
   529 void CMIDItemLabel::SizeChanged()
       
   530 {
       
   531     TAknLayoutRect layoutRect;
       
   532     CEikLabel* label;
       
   533     const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull(Font());
       
   534 
       
   535     if (iIsContent)   // This is a StringItem content
       
   536     {
       
   537         // get label rect
       
   538         TRect rect = Rect();
       
   539 
       
   540         // layout rect
       
   541         layoutRect.LayoutRect(rect,
       
   542                               AknLayoutScalable_Avkon::form2_midp_string_pane(0).LayoutLine());
       
   543         rect = layoutRect.Rect();
       
   544 
       
   545         // determine maximum rows based on layout data available
       
   546         TAknLayoutScalableParameterLimits textLimits =
       
   547             AknLayoutScalable_Avkon::form2_mdip_string_pane_t1_ParamLimits(iFontSize);
       
   548 
       
   549         TInt maxRows = textLimits.LastRow();
       
   550 
       
   551         // layout the lines
       
   552         TInt numOfLabels = iLabelArray->Count();
       
   553         TAknTextLineLayout lineLayout;
       
   554 
       
   555         for (TInt i = 0; i < numOfLabels; i++)
       
   556         {
       
   557             label = (*iLabelArray)[i];
       
   558 
       
   559             if (i < maxRows)
       
   560             {
       
   561                 // get proper layout
       
   562                 lineLayout = AknLayoutScalable_Avkon::form2_mdip_string_pane_t1(
       
   563                                  iFontSize, i).LayoutLine();
       
   564             }
       
   565 
       
   566             // do the layouting of the label using the prepared layout
       
   567             AknLayoutUtils::LayoutLabel(label, rect, lineLayout);
       
   568 
       
   569             if (i > 0)
       
   570             { // because layout function adds small gap between lines, we must
       
   571                 // set proper position
       
   572                 label->SetPosition(TPoint(label->Position().iX ,
       
   573                                           (*iLabelArray)[i-1]->Position().iY + (*iLabelArray)[i-1]->Size().iHeight));
       
   574             }
       
   575 
       
   576             // while LayoutLabel doesn't produce the right color we have to
       
   577             // override it with correct value
       
   578             TRAP_IGNORE(label->OverrideColorL(EColorLabelText, iColor));
       
   579 
       
   580             // as font in layout data is not correct for non-default fonts
       
   581             // we need to change labels font directly
       
   582             label->SetFont(Font());
       
   583             //
       
   584             label->SetSize(TSize(label->Size().iWidth, LineHeight()));
       
   585 
       
   586             if (iCentered)
       
   587             {
       
   588                 label->SetLabelAlignment(ELayoutAlignCenter);
       
   589             }
       
   590 
       
   591         } //for
       
   592     }
       
   593     else // This is a label
       
   594     {
       
   595         // get label rect
       
   596         TRect rect = Rect();
       
   597 
       
   598         // layout rect
       
   599         layoutRect.LayoutRect(rect,
       
   600                               AknLayoutScalable_Avkon::form2_midp_label_pane(0).LayoutLine());
       
   601         rect = layoutRect.Rect();
       
   602 
       
   603         // determine maximum rows based on layout data available
       
   604         TAknLayoutScalableParameterLimits textLimits =
       
   605             AknLayoutScalable_Avkon::form2_midp_label_pane_t1_ParamLimits();
       
   606 
       
   607         TInt maxRows = textLimits.LastRow();
       
   608 
       
   609         // layout the lines
       
   610         TInt numOfLabels = iLabelArray->Count();
       
   611         TAknTextLineLayout lineLayout;
       
   612 
       
   613         for (TInt i = 0; i < numOfLabels; i++)
       
   614         {
       
   615             label = (*iLabelArray)[i];
       
   616 
       
   617             if (i < maxRows)
       
   618             {
       
   619                 // get proper layout
       
   620                 lineLayout = AknLayoutScalable_Avkon::form2_midp_label_pane_t1(i, 0).LayoutLine();
       
   621             }
       
   622 
       
   623             // do the layouting of the label using the prepared layout
       
   624             AknLayoutUtils::LayoutLabel(label, rect, lineLayout);
       
   625 
       
   626             if (i > 0)
       
   627             { // because layout function adds small gap between lines, we must
       
   628                 // set proper position
       
   629                 label->SetPosition(TPoint(label->Position().iX ,
       
   630                                           (*iLabelArray)[i-1]->Position().iY + (*iLabelArray)[i-1]->Size().iHeight));
       
   631             }
       
   632 
       
   633             // while LayoutLabel doesn't produce the right color we have to make workaround
       
   634             // to override it with correct value
       
   635             TRAP_IGNORE(label->OverrideColorL(EColorLabelText, iColor));
       
   636 
       
   637             if (iCentered)
       
   638             {
       
   639                 label->SetLabelAlignment(ELayoutAlignCenter);
       
   640             }
       
   641 
       
   642         } //for
       
   643     } //else
       
   644 }
       
   645 
       
   646 void CMIDItemLabel::ResetLabelArray()
       
   647 {
       
   648     for (TInt i=0; i < iLabelArray->Count(); i++)
       
   649     {
       
   650         delete(*iLabelArray)[i];
       
   651     }
       
   652     iLabelArray->Reset();
       
   653 }
       
   654 
       
   655 TBool CMIDItemLabel::IsLineSeparator(const TText aChar) const
       
   656 {
       
   657     return CMIDUtils::IsLineSeparator(aChar);
       
   658 }
       
   659 
       
   660 TSize CMIDItemLabel::PropperEikLabelMinumumSize(CEikLabel& aLabel) const
       
   661 {
       
   662     TSize size = aLabel.MinimumSize();
       
   663     size.iHeight = LineHeight();
       
   664 
       
   665     if (aLabel.LogicalToVisualConversionUsed())
       
   666     {
       
   667         return size;
       
   668     }
       
   669 
       
   670     const TDesC* text = aLabel.Text();
       
   671 
       
   672     TInt textLength = aLabel.Font()->TextWidthInPixels(*text);
       
   673 
       
   674     // Calculate correct width, because label calculates it wrong.
       
   675     size.iWidth = textLength + aLabel.iMargin.iLeft + aLabel.iMargin.iRight;
       
   676 
       
   677     return size;
       
   678 }
       
   679 
       
   680 void CMIDItemLabel::DrawPictographArea()
       
   681 {
       
   682     if (IsVisible())
       
   683     {
       
   684         RDrawableWindow* rDrawableWindow = DrawableWindow();
       
   685         if (rDrawableWindow)
       
   686         {
       
   687             DrawDeferred();
       
   688         }
       
   689     }
       
   690 }
       
   691 
       
   692 void CMIDItemLabel::ResolutionChange()
       
   693 {
       
   694     UpdateMargins();
       
   695 }
       
   696 
       
   697 TInt CMIDItemLabel::ItemLabelMargin()
       
   698 {
       
   699     return iLabelBeforeContent ? iLabelMargins.iTop : iLabelMargins.iBottom;
       
   700 }
       
   701 
       
   702 void CMIDItemLabel::AdjustToSizeL(const TSize& aSize)
       
   703 {
       
   704     if (iSize.iWidth != aSize.iWidth || iSize.iHeight != aSize.iHeight)
       
   705     {
       
   706         TInt oldNumLabelLines = iMaxNumberOfLines;
       
   707         iMaxNumberOfLines = Min(iMaxNumberOfLines,
       
   708                                 (aSize.iHeight - ItemLabelMargin()) / LineHeight());
       
   709 
       
   710         SetWidthL(aSize.iWidth);
       
   711         iMaxNumberOfLines = oldNumLabelLines;
       
   712     }
       
   713 }
       
   714 
       
   715 //end of File