javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtlabel.cpp
branchRCL_3
changeset 26 2455ef1f5bbc
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #include <AknsDrawUtils.h>
       
    14 #include <AknUtils.h>
       
    15 #include <eiklbi.h>
       
    16 #include <eikenv.h>
       
    17 #include <AknsUtils.h>
       
    18 #include <aknconsts.h>
       
    19 #include <AknLayoutFont.h>
       
    20 #include <AknBidiTextUtils.h>
       
    21 #include <swtlaffacade.h>
       
    22 #include <avkon.mbg>
       
    23 #include "swtlabel.h"
       
    24 #include "swtcontrolbase.h"
       
    25 #include "swtfont.h"
       
    26 
       
    27 
       
    28 const TInt KBorderMargin = 1;
       
    29 
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CSwtLabel::CSwtLabel
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CSwtLabel::CSwtLabel(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    39                      MSwtComposite& aParent, TInt aStyle)
       
    40         : ASwtControlBase(aDisplay, aPeer, &aParent, aStyle)
       
    41         , iOriginalText(NULL)
       
    42 {
       
    43     SetFocusing(EFalse);
       
    44 }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CSwtLabel::~CSwtLabel
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CSwtLabel::~CSwtLabel()
       
    51 {
       
    52     delete iEikLabel;
       
    53     delete iSeparatorHead;
       
    54     delete iSeparatorHeadMask;
       
    55     delete iSeparatorCenter;
       
    56     delete iSeparatorCenterMask;
       
    57     delete iSeparatorTail;
       
    58     delete iSeparatorTailMask;
       
    59     delete iOriginalText;
       
    60 
       
    61     if (iDefaultFont)
       
    62     {
       
    63         iDefaultFont->RemoveRef();
       
    64     }
       
    65 
       
    66     if (iImage != NULL)
       
    67         iImage->RemoveRef();
       
    68 
       
    69 #ifdef _lint
       
    70     iDefaultFont = NULL;
       
    71     iImage       = NULL;
       
    72     iForegroundColor = NULL;
       
    73 #endif
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CSwtLabel::ConstructL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CSwtLabel::ConstructL()
       
    81 {
       
    82     CCoeControl& coeParent = iParent->Control()->CoeControl();
       
    83 
       
    84     SetContainerWindowL(coeParent);
       
    85 
       
    86     CAknControl::MakeVisible(coeParent.IsVisible());
       
    87     CAknControl::SetDimmed(coeParent.IsDimmed());
       
    88 
       
    89     if (iStyle & KSwtStyleSeparator)
       
    90     {
       
    91         CreateSeparatorL();
       
    92     }
       
    93     else
       
    94     {
       
    95         CreateTextL();
       
    96     }
       
    97 
       
    98     SetBackground(this);   // Back will be drawn by ASwtControlBase::Draw
       
    99     ActivateL();
       
   100 }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CSwtLabel::CreateTextL
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CSwtLabel::CreateTextL()
       
   107 {
       
   108     ASSERT(!(iStyle & KSwtStyleSeparator));
       
   109     ASSERT(!iEikLabel);
       
   110 
       
   111     iEikLabel = new(ELeave) CEikLabel();
       
   112     iEikLabel->SetFocusing(EFalse);
       
   113     iEikLabel->SetContainerWindowL(*this);
       
   114     iEikLabel->MakeVisible(EFalse);
       
   115     iEikLabel->SetDimmed(IsDimmed());
       
   116     iEikLabel->SetTextL(KNullDesC);
       
   117     SetAlignment(iStyle & KSwtAlignmentMask);
       
   118     RetrieveDefaultFontL();
       
   119     DoSetFontL(&iDefaultFont->Font());
       
   120     UpdateTextColor();
       
   121 
       
   122     // Correct position of CEikLabel will be set in PositionChanged()
       
   123 }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CSwtLabel::CreateSeparatorL
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CSwtLabel::CreateSeparatorL()
       
   130 {
       
   131     ASSERT(!iEikLabel);
       
   132     ASSERT(!iImage);
       
   133 
       
   134     delete iSeparatorHead;
       
   135     iSeparatorHead = NULL;
       
   136     delete iSeparatorHeadMask;
       
   137     iSeparatorHeadMask = NULL;
       
   138     delete iSeparatorCenter;
       
   139     iSeparatorCenter = NULL;
       
   140     delete iSeparatorCenterMask;
       
   141     iSeparatorCenterMask = NULL;
       
   142     delete iSeparatorTail;
       
   143     iSeparatorTail = NULL;
       
   144     delete iSeparatorTailMask;
       
   145     iSeparatorTailMask = NULL;
       
   146 
       
   147     // Get skin and bitmap ids
       
   148     TAknsItemID separatorHeadSkinId;
       
   149     TAknsItemID separatorCenterSkinId;
       
   150     TAknsItemID separatorTailSkinId;
       
   151 
       
   152     TInt separatorCenterId;
       
   153     TInt separatorCenterMaskId;
       
   154 
       
   155     if (iStyle & KSwtStyleVertical)
       
   156     {
       
   157 
       
   158         if (iStyle & KSwtStyleShadowIn)
       
   159         {
       
   160             separatorHeadSkinId.Set(KAknsIIDQsnFrSeparatorVTShdwin);
       
   161             separatorCenterSkinId.Set(KAknsIIDQsnFrSeparatorVMShdwin);
       
   162             separatorTailSkinId.Set(KAknsIIDQsnFrSeparatorVBShdwin);
       
   163         }
       
   164         else if (iStyle & KSwtStyleShadowOut)
       
   165         {
       
   166             separatorHeadSkinId.Set(KAknsIIDQsnFrSeparatorVTShdwout);
       
   167             separatorCenterSkinId.Set(KAknsIIDQsnFrSeparatorVMShdwout);
       
   168             separatorTailSkinId.Set(KAknsIIDQsnFrSeparatorVBShdwout);
       
   169         }
       
   170         else
       
   171         {
       
   172             separatorHeadSkinId.Set(KAknsIIDQsnFrSeparatorVTShdwnone);
       
   173             separatorCenterSkinId.Set(KAknsIIDQsnFrSeparatorVMShdwnone);
       
   174             separatorTailSkinId.Set(KAknsIIDQsnFrSeparatorVBShdwnone);
       
   175         }
       
   176     }
       
   177     else
       
   178     {
       
   179 
       
   180         if (iStyle & KSwtStyleShadowIn)
       
   181         {
       
   182             separatorHeadSkinId.Set(KAknsIIDQsnFrSeparatorHLShdwin);
       
   183             separatorCenterSkinId.Set(KAknsIIDQsnFrSeparatorHMShdwin);
       
   184             separatorTailSkinId.Set(KAknsIIDQsnFrSeparatorHRShdwin);
       
   185         }
       
   186         else if (iStyle & KSwtStyleShadowOut)
       
   187         {
       
   188             separatorHeadSkinId.Set(KAknsIIDQsnFrSeparatorHLShdwout);
       
   189             separatorCenterSkinId.Set(KAknsIIDQsnFrSeparatorHMShdwout);
       
   190             separatorTailSkinId.Set(KAknsIIDQsnFrSeparatorHRShdwout);
       
   191         }
       
   192         else
       
   193         {
       
   194             separatorHeadSkinId.Set(KAknsIIDQsnFrSeparatorHLShdwnone);
       
   195             separatorCenterSkinId.Set(KAknsIIDQsnFrSeparatorHMShdwnone);
       
   196             separatorTailSkinId.Set(KAknsIIDQsnFrSeparatorHRShdwnone);
       
   197         }
       
   198     }
       
   199 
       
   200 
       
   201     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   202 
       
   203 
       
   204     // first, try to get separator specific images from skin
       
   205     _LIT(KNoneFile," ");
       
   206     TInt err(KErrNone);
       
   207 
       
   208     TRAP(err, AknsUtils::CreateIconL(
       
   209              skin,
       
   210              separatorHeadSkinId,
       
   211              iSeparatorHead,
       
   212              iSeparatorHeadMask,
       
   213              KNoneFile,
       
   214              0,
       
   215              0));
       
   216 
       
   217 
       
   218     if (err == KErrNone)
       
   219     {
       
   220 
       
   221         TRAP(err, AknsUtils::CreateIconL(
       
   222                  skin,
       
   223                  separatorCenterSkinId,
       
   224                  iSeparatorCenter,
       
   225                  iSeparatorCenterMask,
       
   226                  KNoneFile,
       
   227                  0,
       
   228                  0));
       
   229     }
       
   230 
       
   231     if (err == KErrNone)
       
   232     {
       
   233 
       
   234         TRAP(err, AknsUtils::CreateIconL(
       
   235                  skin,
       
   236                  separatorTailSkinId,
       
   237                  iSeparatorTail,
       
   238                  iSeparatorTailMask,
       
   239                  KNoneFile,
       
   240                  0,
       
   241                  0));
       
   242     }
       
   243 
       
   244     if (err != KErrNone)
       
   245         // if separator specific images are not available from skin
       
   246         // try to use dashed line image from skin, or from image file
       
   247     {
       
   248 
       
   249         if (iStyle & KSwtStyleVertical)
       
   250         {
       
   251             separatorCenterSkinId = KAknsIIDQgnGrafLinePrimaryVerticalDashed;
       
   252             separatorCenterId = EMbmAvkonQgn_graf_line_primary_vertical_dashed;
       
   253             separatorCenterMaskId = EMbmAvkonQgn_graf_line_primary_vertical_dashed_mask;
       
   254 
       
   255         }
       
   256         else
       
   257         {
       
   258             separatorCenterSkinId = KAknsIIDQgnGrafLinePrimaryHorizontalDashed;
       
   259             separatorCenterId = EMbmAvkonQgn_graf_line_primary_horizontal_dashed;
       
   260             separatorCenterMaskId = EMbmAvkonQgn_graf_line_primary_horizontal_dashed_mask;
       
   261         }
       
   262 
       
   263         AknsUtils::CreateIconL(
       
   264             skin,
       
   265             separatorCenterSkinId,
       
   266             iSeparatorCenter,
       
   267             iSeparatorCenterMask,
       
   268             KAvkonBitmapFile,
       
   269             separatorCenterId,
       
   270             separatorCenterMaskId);
       
   271 
       
   272         delete iSeparatorHead;
       
   273         iSeparatorHead = NULL;
       
   274         delete iSeparatorHeadMask;
       
   275         iSeparatorHeadMask =NULL;
       
   276         delete iSeparatorTail;
       
   277         iSeparatorTail = NULL;
       
   278         delete iSeparatorTailMask;
       
   279         iSeparatorTailMask = NULL;
       
   280         iDashedLineSeparatorInUse =  ETrue;
       
   281     }
       
   282 
       
   283 
       
   284     // Get separator thickness
       
   285     TAknLayoutRect layoutRect;
       
   286     const TInt KBigEnough(50);
       
   287     if (iStyle & KSwtStyleVertical)
       
   288     {
       
   289         layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorVerticalPane,
       
   290                      TRect(0, 0, KBigEnough, KBigEnough), 0);
       
   291         iSeparatorThickness = layoutRect.Rect().Size().iWidth;
       
   292     }
       
   293     else
       
   294     {
       
   295         layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorHorizontalPane,
       
   296                      TRect(0, 0, KBigEnough, KBigEnough), 0);
       
   297         iSeparatorThickness = layoutRect.Rect().Size().iHeight;
       
   298     }
       
   299 
       
   300     if (iDashedLineSeparatorInUse)
       
   301     {
       
   302         iSeparatorThickness = 1;
       
   303     }
       
   304 
       
   305     ResizeSeparatorImages();
       
   306 
       
   307 }
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // CSwtLabel::NewL
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 CSwtLabel* CSwtLabel::NewL(MSwtDisplay& aDisplay,
       
   314                            TSwtPeer aPeer, MSwtComposite& aParent, TInt aStyle)
       
   315 {
       
   316     CSwtLabel* self = new(ELeave) CSwtLabel(aDisplay, aPeer, aParent, aStyle);
       
   317     CleanupStack::PushL(self);
       
   318     self->ConstructL();
       
   319     self->InitControlBaseL();
       
   320     CleanupStack::Pop(self);
       
   321     return self;
       
   322 }
       
   323 
       
   324 // ---------------------------------------------------------------------------
       
   325 // CSwtLabel::ClipTextL
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void  CSwtLabel::ClipTextL(TInt aWHint)
       
   329 {
       
   330     if (iOriginalText == NULL || aWHint <= 0 || !iEikLabel)
       
   331     {
       
   332         return;
       
   333     }
       
   334 
       
   335     RBuf textToClip;
       
   336     textToClip.Create(*iOriginalText);
       
   337     textToClip.CleanupClosePushL();
       
   338 
       
   339     const CFont* font = iEikLabel->Font();
       
   340     if (iOriginalTextLineCount == 1)
       
   341     {
       
   342         if (aWHint > font->CharWidthInPixels(CEditableText::EEllipsis))
       
   343         {
       
   344             AknTextUtils::ClipToFit(textToClip, *font, aWHint);
       
   345         }
       
   346     }
       
   347     iEikLabel->SetTextL(textToClip);
       
   348 
       
   349     CleanupStack::PopAndDestroy(); // textToClip
       
   350 }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // CSwtLabel::ComputeTextSizeL
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 TSize CSwtLabel::ComputeTextSizeL(TInt aWHint, TInt aHHint)
       
   357 {
       
   358     // Return non default hints
       
   359     if (aWHint != KSwtDefault && aHHint != KSwtDefault)
       
   360     {
       
   361         return TSize(aWHint, aHHint);
       
   362     }
       
   363 
       
   364     // Compute size
       
   365     TSize prefSize(0, 0);
       
   366     if ((iStyle & KSwtStyleWrap) && !(aWHint == KSwtDefault && aHHint == KSwtDefault))
       
   367     {
       
   368         // Wrap text with a default hint
       
   369         if (aWHint != KSwtDefault)
       
   370         {
       
   371             prefSize.iWidth = aWHint;
       
   372             prefSize.iHeight = CalcWrappedTextHeightL(aWHint);
       
   373         }
       
   374         else
       
   375         {
       
   376             prefSize.iHeight = aHHint;
       
   377             prefSize.iWidth = CalcWrappedTextWidth(aHHint);
       
   378         }
       
   379     }
       
   380     else
       
   381     {
       
   382         // This will return the width of the longer line and height that fits all lines
       
   383         prefSize = MinimumSize();
       
   384     }
       
   385 
       
   386     // Avoid text touching the border
       
   387     prefSize += TPoint(2 * KBorderMargin, 2 * KBorderMargin);
       
   388 
       
   389     if (aHHint != KSwtDefault)
       
   390     {
       
   391         prefSize.iHeight = aHHint;
       
   392     }
       
   393 
       
   394     if (aWHint != KSwtDefault)
       
   395     {
       
   396         prefSize.iWidth = aWHint;
       
   397     }
       
   398 
       
   399     return prefSize;
       
   400 }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CSwtLabel::CalcWrappedTextHeightL
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 TInt CSwtLabel::CalcWrappedTextHeightL(TInt aWidth)
       
   407 {
       
   408     if (iOriginalText == NULL || aWidth <= 0 || !iEikLabel)
       
   409     {
       
   410         return 0;
       
   411     }
       
   412 
       
   413     // Calculate the number of lines when wrapping text to the given rectangle
       
   414     const TInt ARRAY_GRANULARITY = 4;
       
   415     CArrayFixFlat<TPtrC>* wrappedArray = new(ELeave) CArrayFixFlat<TPtrC>(ARRAY_GRANULARITY);
       
   416     CleanupStack::PushL(wrappedArray);
       
   417     const CFont* font(iEikLabel->Font());
       
   418 
       
   419     // NOTE!!! AknTextUtils::WrapToArrayL behaves strange for strings that
       
   420     // contain '-' (dash) char. Sometimes return one lesser line if several
       
   421     // dashes are encountered.
       
   422 
       
   423     AknTextUtils::WrapToArrayL(*iOriginalText, aWidth, *font, *wrappedArray);
       
   424     TInt nbStrings = wrappedArray->Count();
       
   425     if (nbStrings < 1)
       
   426     {
       
   427         // It happens when aWidth < Char's width
       
   428         // here just set nBStrings to 1
       
   429         // so something can be visible.
       
   430         nbStrings = 1;
       
   431     }
       
   432 
       
   433     // Calculate text height
       
   434     const TInt result(MinimumHeight(nbStrings));
       
   435 
       
   436     wrappedArray->Reset();
       
   437     CleanupStack::PopAndDestroy(wrappedArray);
       
   438 
       
   439     return result;
       
   440 }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // CSwtLabel::CalcWrappedTextWidth
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 TInt CSwtLabel::CalcWrappedTextWidth(TInt aHeight)
       
   447 {
       
   448     if (iOriginalText == NULL || aHeight <= 0)
       
   449     {
       
   450         return 0;
       
   451     }
       
   452     // This will return the width of the longer line and height that fits all lines
       
   453     return MinimumWidth();
       
   454 }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // CSwtLabel::WrapTextL
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 void CSwtLabel::WrapTextL(TSize aSize)
       
   461 {
       
   462     WrapTextL(aSize.iWidth, aSize.iHeight);
       
   463 }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CSwtLabel::WrapTextL
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CSwtLabel::WrapTextL(TInt aWHint, TInt aHHint)
       
   470 {
       
   471     if (iOriginalText == NULL || aWHint <= 0 || aHHint <= 0 || !iEikLabel)
       
   472     {
       
   473         return;
       
   474     }
       
   475 
       
   476     const CFont* font = iEikLabel->Font();
       
   477 
       
   478     // Estimate how many text rows within given rectangle
       
   479     TInt textPaneHeight = GetFontHeight(font);
       
   480     const TInt gap = iEikLabel->PixelGapBetweenLines();
       
   481 
       
   482     // The last row in label does not add a gap after it. So...
       
   483     // aHHint = rows * textPaneHeight + (rows - 1) * gap; and therefore...
       
   484     TInt rows = (aHHint + gap) / (textPaneHeight + gap);
       
   485     if (rows < 1)
       
   486     {
       
   487         // It happens when hint height < Char's height
       
   488         // here just set nBStrings to 1
       
   489         // so something can be visible.
       
   490         rows = 1;
       
   491     }
       
   492 
       
   493     // Setup width arrray
       
   494     CArrayFixFlat< TInt >* widthsArray = new(ELeave) CArrayFixFlat< TInt >(rows);
       
   495     CleanupStack::PushL(widthsArray);
       
   496     widthsArray->SetReserveL(rows);
       
   497     TInt i;
       
   498     for (i = 0; i < rows; ++i)
       
   499     {
       
   500         widthsArray->AppendL(aWHint);
       
   501     }
       
   502 
       
   503     // Convert text into wrapped text with AKnTextUtils
       
   504     RBuf wrappedBuffer;
       
   505     const TInt KDouble(2);
       
   506     wrappedBuffer.CreateL(KDouble *(iOriginalText->Length()));
       
   507     wrappedBuffer.CleanupClosePushL();
       
   508     AknTextUtils::WrapToStringAndClipL(*iOriginalText, *widthsArray, *font, wrappedBuffer);
       
   509 
       
   510     // Set wrapped text
       
   511     iEikLabel->SetTextL(wrappedBuffer);
       
   512 
       
   513     CleanupStack::PopAndDestroy(); // wrappedBuffer
       
   514     CleanupStack::PopAndDestroy(widthsArray);
       
   515 }
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // CSwtLabel::RetrieveDefaultFontL
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 void CSwtLabel::RetrieveDefaultFontL()
       
   522 {
       
   523     ASSERT(iEikLabel);
       
   524     if (iDefaultFont)
       
   525     {
       
   526         iDefaultFont->RemoveRef();
       
   527         iDefaultFont = NULL;
       
   528     }
       
   529     // Same as Button's
       
   530     iDefaultFont = CSwtFont::NewL(iDisplay.Device(), iDisplay.Device().GetSystemFont()->Font());
       
   531 }
       
   532 
       
   533 // ---------------------------------------------------------------------------
       
   534 // CSwtLabel::MinimumSize
       
   535 // Replaces CEikLabel's MinimumSize to fix some texts getting ellipsed and clipped
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 TSize CSwtLabel::MinimumSize() const
       
   539 {
       
   540     const TInt height = MinimumHeight();
       
   541     const TInt width = MinimumWidth();
       
   542     return TSize(width, height);
       
   543 }
       
   544 
       
   545 // ---------------------------------------------------------------------------
       
   546 // CSwtLabel::MinimumWidth
       
   547 // Replaces CEikLabel's MinimumWidth to fix some texts getting ellipsed.
       
   548 // ---------------------------------------------------------------------------
       
   549 //
       
   550 TInt CSwtLabel::MinimumWidth() const
       
   551 {
       
   552     if (!iEikLabel || !iOriginalText)
       
   553     {
       
   554         return 0;
       
   555     }
       
   556 
       
   557     TInt result = 0;
       
   558     TPtrC ptr(iOriginalText->Des());
       
   559     const CFont* font = iEikLabel->Font();
       
   560     CFont::TMeasureTextInput::TFlags order = CFont::TMeasureTextInput::EFVisualOrder;
       
   561     if (AknLayoutUtils::LayoutMirrored())
       
   562     {
       
   563         order = CFont::TMeasureTextInput::EFVisualOrderRightToLeft;
       
   564     }
       
   565 
       
   566     FOREVER
       
   567     {
       
   568         const TInt pos = ptr.Locate('\n');
       
   569         TPtrC left = ptr;
       
   570         if (pos >= 0)
       
   571         {
       
   572             left.Set(ptr.Left(pos));
       
   573         }
       
   574         TInt lineW = AknBidiTextUtils::MeasureTextBoundsWidth(*font, left, order);
       
   575         if (lineW > result)
       
   576         {
       
   577             result = lineW;
       
   578         }
       
   579         if (pos < 0 || pos == ptr.Length() - 1)
       
   580         {
       
   581             break;
       
   582         }
       
   583         ptr.Set(ptr.Mid(pos + 1));
       
   584     }
       
   585 
       
   586     return result;
       
   587 }
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // CSwtLabel::MinimumHeight
       
   591 // Replaces CEikLabel's MinimumHeight to fix some texts getting clipped
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 TInt CSwtLabel::MinimumHeight() const
       
   595 {
       
   596     return(MinimumHeight(iOriginalTextLineCount));
       
   597 }
       
   598 
       
   599 // ---------------------------------------------------------------------------
       
   600 // CSwtLabel::MinimumHeight
       
   601 // Replaces CEikLabel's MinimumHeight to fix some texts getting clipped
       
   602 // ---------------------------------------------------------------------------
       
   603 //
       
   604 TInt CSwtLabel::MinimumHeight(TInt aLineCount) const
       
   605 {
       
   606     if (!iEikLabel)
       
   607     {
       
   608         return 0;
       
   609     }
       
   610 
       
   611     // Compared to CEikLabel's MinimumHeight() we add one more gap.
       
   612     // This is to fix some fonts getting clipped from above.
       
   613     // Do not change this ever, as wrapping will surely brake.
       
   614     return aLineCount * iEikLabel->PixelGapBetweenLines()
       
   615            + aLineCount * GetFontHeight(iEikLabel->Font());
       
   616 }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // CSwtLabel::DoSetFontL
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 void CSwtLabel::DoSetFontL(const CFont* aFont)
       
   623 {
       
   624     if (!iEikLabel)
       
   625     {
       
   626         return;
       
   627     }
       
   628     iEikLabel->SetFont(aFont);
       
   629     if (aFont)
       
   630     {
       
   631         // The gap must be set exaclty in the same way as in AknLayoutUtils::LayoutLabel().
       
   632         // So, do not modify this unless CEikLabel does too!
       
   633         iEikLabel->SetPixelGapBetweenLines(
       
   634             Max(aFont->FontLineGap() - aFont->HeightInPixels(), KSwtMinLinePadding));
       
   635 
       
   636         // This is to fix some fonts getting to much space after last line.
       
   637         iEikLabel->iMargin.iTop = aFont->FontMaxDescent();
       
   638 
       
   639         TRAP_IGNORE(ClipTextL(iEikLabel->Size().iWidth));
       
   640     }
       
   641 }
       
   642 
       
   643 // ---------------------------------------------------------------------------
       
   644 // CSwtLabel::GetFontHeight
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 TInt CSwtLabel::GetFontHeight(const CFont* aFont) const
       
   648 {
       
   649     if (!aFont)
       
   650     {
       
   651         return 0;
       
   652     }
       
   653 
       
   654 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   655     return aFont->FontMaxHeight();
       
   656 #else
       
   657     return aFont->HeightInPixels();
       
   658 #endif
       
   659 }
       
   660 
       
   661 // ---------------------------------------------------------------------------
       
   662 // CSwtLabel::Draw
       
   663 // From CCoeControl
       
   664 // ---------------------------------------------------------------------------
       
   665 //
       
   666 void CSwtLabel::Draw(const TRect& aRect) const
       
   667 {
       
   668     ASSERT(!(iCtrlFlags & EFlagDoNotDraw));
       
   669 
       
   670     const TRect clientRect(BorderInnerRect());
       
   671     TRect dirtyClientRect(clientRect);
       
   672     dirtyClientRect.Intersection(aRect);
       
   673 
       
   674     CWindowGc& gc = SystemGc();
       
   675 
       
   676     // Draw the image if we have one
       
   677     if (iImage != NULL && !iEikLabel->IsVisible())   //lint !e613 iEikLabel cannot be NULL if iImage is not
       
   678     {
       
   679         const TSize imgSize(iImage->GetBounds().Size());
       
   680         TPoint imgPos(TPoint::EUninitialized);
       
   681 
       
   682 
       
   683         const TBool leftToRight((iStyle & KSwtStyleRightToLeft)
       
   684                                 || AknLayoutUtils::LayoutMirrored());
       
   685         if (iStyle & KSwtStyleCenter)
       
   686         {
       
   687             imgPos.iX = clientRect.iTl.iX + (clientRect.Width() - imgSize.iWidth) / 2;
       
   688         }
       
   689         else if (((iStyle & KSwtStyleTrail) && (!leftToRight))
       
   690                  || ((iStyle &  KSwtStyleLead) && leftToRight))
       
   691         {
       
   692             imgPos.iX = clientRect.iBr.iX - imgSize.iWidth;
       
   693         }
       
   694         else
       
   695         {
       
   696             imgPos.iX = clientRect.iTl.iX;
       
   697         }
       
   698 
       
   699         // Vertical alignment ( always centered )
       
   700         imgPos.iY = clientRect.iTl.iY + (clientRect.Height() - imgSize.iHeight) / 2;
       
   701 
       
   702         TRect drawRect(imgPos, imgSize);
       
   703         drawRect.Intersection(dirtyClientRect);
       
   704 
       
   705         if (!drawRect.IsEmpty())
       
   706         {
       
   707             TRect imgRect(drawRect);
       
   708             imgRect.Move(-imgPos);
       
   709 
       
   710             const CFbsBitmap& bitmap = iImage->Bitmap();
       
   711             const CFbsBitmap* mask   = iImage->MaskBitmap();
       
   712             if (mask == NULL)
       
   713                 gc.BitBlt(drawRect.iTl, &bitmap, imgRect);
       
   714             else
       
   715                 gc.BitBltMasked(drawRect.iTl, &bitmap, imgRect, mask, EFalse);
       
   716         }
       
   717     }
       
   718     else if (iSeparatorCenter)
       
   719     {
       
   720         DrawSeparator(gc);
       
   721     }
       
   722 }
       
   723 
       
   724 // ---------------------------------------------------------------------------
       
   725 // CSwtLabel::FocusChanged
       
   726 // From CCoeControl
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 void CSwtLabel::FocusChanged(TDrawNow aDrawNow)
       
   730 {
       
   731     // Labels are not supposed to gain focus on their own, but they may still
       
   732     // get it through ForceFocus().
       
   733     TBool focused = IsFocused();
       
   734     if (iEikLabel)
       
   735     {
       
   736         iEikLabel->SetFocus(focused);
       
   737     }
       
   738 
       
   739     HandleFocusChanged(aDrawNow);
       
   740 }
       
   741 
       
   742 // ---------------------------------------------------------------------------
       
   743 // CSwtLabel::SetDimmed
       
   744 // From CCoeControl
       
   745 // ---------------------------------------------------------------------------
       
   746 //
       
   747 void CSwtLabel::SetDimmed(TBool aDimmed)
       
   748 {
       
   749     CAknControl::SetDimmed(aDimmed);
       
   750     if (iEikLabel)
       
   751     {
       
   752         iEikLabel->SetDimmed(aDimmed);
       
   753     }
       
   754 }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // CSwtLabel::ComponentControl
       
   758 // From CCoeControl
       
   759 // ---------------------------------------------------------------------------
       
   760 //
       
   761 CCoeControl* CSwtLabel::ComponentControl(TInt /*aIndex*/) const
       
   762 {
       
   763     if (iEikLabel)
       
   764     {
       
   765         return static_cast< CCoeControl* >(iEikLabel);
       
   766     }
       
   767     else
       
   768     {
       
   769         return NULL;
       
   770     }
       
   771 } //lint !e1763
       
   772 
       
   773 // ---------------------------------------------------------------------------
       
   774 // CSwtLabel::CountComponentControls
       
   775 // From CCoeControl
       
   776 // ---------------------------------------------------------------------------
       
   777 //
       
   778 TInt CSwtLabel::CountComponentControls() const
       
   779 {
       
   780     if (iEikLabel)
       
   781     {
       
   782         return 1;
       
   783     }
       
   784     else
       
   785     {
       
   786         return 0;
       
   787     }
       
   788 }
       
   789 
       
   790 // ---------------------------------------------------------------------------
       
   791 // CSwtLabel::OfferKeyEventL
       
   792 // From CCoeControl
       
   793 // ---------------------------------------------------------------------------
       
   794 //
       
   795 TKeyResponse CSwtLabel::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   796 {
       
   797     return HandleKeyL(aKeyEvent, aType, ETrue);
       
   798 }
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // CSwtLabel::HandleResourceChange
       
   802 // From CCoeControl
       
   803 // ---------------------------------------------------------------------------
       
   804 //
       
   805 void CSwtLabel::HandleResourceChange(TInt aType)
       
   806 {
       
   807     TRAP_IGNORE(SwtHandleResourceChangeL(aType));
       
   808 }
       
   809 
       
   810 // ---------------------------------------------------------------------------
       
   811 // CSwtLabel::SwtHandleResourceChangeL
       
   812 // ---------------------------------------------------------------------------
       
   813 //
       
   814 void CSwtLabel::SwtHandleResourceChangeL(TInt aType)
       
   815 {
       
   816     CAknControl::HandleResourceChange(aType);
       
   817     if (aType == KAknsMessageSkinChange || aType == KEikDynamicLayoutVariantSwitch)
       
   818     {
       
   819         if (iEikLabel)
       
   820         {
       
   821             RetrieveDefaultFontL();
       
   822             if (!iFont)
       
   823             {
       
   824                 iEikLabel->SetFont(&iDefaultFont->Font());
       
   825             }
       
   826         }
       
   827         else if (iStyle & KSwtStyleSeparator)
       
   828         {
       
   829             CreateSeparatorL();
       
   830         }
       
   831 
       
   832         if (aType == KAknsMessageSkinChange)
       
   833         {
       
   834             UpdateTextColor();
       
   835         }
       
   836     }
       
   837     else if (aType == KEikDynamicLayoutVariantSwitch)
       
   838     {
       
   839         SetAlignment(iStyle & KSwtAlignmentMask);
       
   840     }
       
   841 }
       
   842 
       
   843 // ---------------------------------------------------------------------------
       
   844 // CSwtLabel::PositionChanged
       
   845 // From CCoeControl
       
   846 // ---------------------------------------------------------------------------
       
   847 //
       
   848 void CSwtLabel::PositionChanged()
       
   849 {
       
   850     if (iEikLabel)
       
   851     {
       
   852         TRect clientRect(BorderInnerRect());
       
   853         if (HasBorderStyle())
       
   854         {
       
   855             // The text should not touch the border
       
   856             iEikLabel->SetPosition(clientRect.iTl + TPoint(KBorderMargin, KBorderMargin));
       
   857         }
       
   858         else
       
   859         {
       
   860             iEikLabel->SetPosition(clientRect.iTl);
       
   861         }
       
   862     }
       
   863     else if (iSeparatorCenter)
       
   864     {
       
   865         ResizeSeparatorImages();
       
   866     }
       
   867 
       
   868     HandlePositionChanged();
       
   869 }
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // CSwtLabel::SizeChanged
       
   873 // From CCoeControl
       
   874 // ---------------------------------------------------------------------------
       
   875 //
       
   876 void CSwtLabel::SizeChanged()
       
   877 {
       
   878     if (iEikLabel)
       
   879     {
       
   880         const TRect clientRect(BorderInnerRect());
       
   881         if (HasBorderStyle())
       
   882         {
       
   883             // The text should not touch the border
       
   884             iEikLabel->SetSize(clientRect.Size() - TPoint(2 * KBorderMargin, 2 * KBorderMargin));
       
   885         }
       
   886         else
       
   887         {
       
   888             iEikLabel->SetSize(clientRect.Size());
       
   889         }
       
   890 
       
   891         if (iStyle & KSwtStyleWrap)
       
   892         {
       
   893             TRAP_IGNORE(WrapTextL(iEikLabel->Size()));
       
   894         }
       
   895         else
       
   896         {
       
   897             TRAP_IGNORE(ClipTextL(iEikLabel->Size().iWidth));
       
   898         }
       
   899     }
       
   900     else if (iSeparatorCenter)
       
   901     {
       
   902         ResizeSeparatorImages();
       
   903     }
       
   904 
       
   905     HandleSizeChanged();
       
   906 }
       
   907 
       
   908 // ---------------------------------------------------------------------------
       
   909 // CSwtLabel::MopSupplyObject
       
   910 // From CCoeControl
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 TTypeUid::Ptr CSwtLabel::MopSupplyObject(TTypeUid aId)
       
   914 {
       
   915     TTypeUid::Ptr id = ASwtControlBase::SwtMopSupplyObject(aId);
       
   916 
       
   917     if (id.Pointer() == NULL)
       
   918     {
       
   919         return CAknControl::MopSupplyObject(aId);
       
   920     }
       
   921     else
       
   922     {
       
   923         return id;
       
   924     }
       
   925 }
       
   926 
       
   927 // ---------------------------------------------------------------------------
       
   928 // CSwtLabel::CoeControl
       
   929 // From MSwtControl
       
   930 // ---------------------------------------------------------------------------
       
   931 //
       
   932 CCoeControl& CSwtLabel::CoeControl()
       
   933 {
       
   934     return *this;
       
   935 }
       
   936 
       
   937 // ---------------------------------------------------------------------------
       
   938 // CSwtLabel::CoeControl
       
   939 // From MSwtControl
       
   940 // ---------------------------------------------------------------------------
       
   941 //
       
   942 const CCoeControl& CSwtLabel::CoeControl() const
       
   943 {
       
   944     return *this;
       
   945 }
       
   946 
       
   947 // ---------------------------------------------------------------------------
       
   948 // CSwtLabel::IsFocusable
       
   949 // From MSwtControl
       
   950 // ---------------------------------------------------------------------------
       
   951 //
       
   952 TBool CSwtLabel::IsFocusable(TInt aReason /*=KSwtFocusByApi*/) const
       
   953 {
       
   954     const CCoeControl& coeCtrl = CoeControl();
       
   955 
       
   956     // Invisible or disabled controls can never get the focus ( not even forced )
       
   957     if (!coeCtrl.IsVisible() || coeCtrl.IsDimmed())
       
   958         return EFalse;
       
   959     else
       
   960         return aReason == KSwtFocusByForce;
       
   961 }
       
   962 
       
   963 // ---------------------------------------------------------------------------
       
   964 // CSwtLabel::ProcessKeyEventL
       
   965 // From MSwtControl
       
   966 // ---------------------------------------------------------------------------
       
   967 //
       
   968 void CSwtLabel::ProcessKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
       
   969 {
       
   970     // Do nothing
       
   971 }
       
   972 
       
   973 // ---------------------------------------------------------------------------
       
   974 // CSwtLabel::ComputeSizeL
       
   975 // From MSwtControl
       
   976 // ---------------------------------------------------------------------------
       
   977 //
       
   978 TSize CSwtLabel::ComputeSizeL(TInt aWHint, TInt aHHint)
       
   979 {
       
   980     if (aWHint != KSwtDefault && aHHint != KSwtDefault)
       
   981     {
       
   982         return TSize(aWHint, aHHint);
       
   983     }
       
   984 
       
   985     TSize prefSize(0, 0);
       
   986     if (iSeparatorCenter)
       
   987     {
       
   988         if (aHHint != KSwtDefault)
       
   989         {
       
   990             prefSize.iHeight = aHHint;
       
   991         }
       
   992         else if (!(iStyle & KSwtStyleVertical))
       
   993         {
       
   994             prefSize.iHeight = Min(iSeparatorThickness, prefSize.iHeight);
       
   995         }
       
   996 
       
   997         if (aWHint != KSwtDefault)
       
   998         {
       
   999             prefSize.iWidth = aWHint;
       
  1000         }
       
  1001         else if (iStyle & KSwtStyleVertical)
       
  1002         {
       
  1003             prefSize.iWidth = Min(iSeparatorThickness, prefSize.iWidth);
       
  1004         }
       
  1005     }
       
  1006 
       
  1007     if (iImage)
       
  1008     {
       
  1009         prefSize = iImage->GetBounds().Size();
       
  1010     }
       
  1011     else
       
  1012     {
       
  1013         prefSize = ComputeTextSizeL(aWHint, aHHint);
       
  1014     }
       
  1015 
       
  1016     if (!iSeparatorCenter)
       
  1017     {
       
  1018         prefSize += BorderSizeDelta();
       
  1019     }
       
  1020 
       
  1021     if (aWHint != KSwtDefault)
       
  1022     {
       
  1023         prefSize.iWidth = aWHint;
       
  1024     }
       
  1025     if (aHHint != KSwtDefault)
       
  1026     {
       
  1027         prefSize.iHeight = aHHint;
       
  1028     }
       
  1029 
       
  1030     return prefSize;
       
  1031 }
       
  1032 
       
  1033 // ---------------------------------------------------------------------------
       
  1034 // CSwtLabel::DrawSeparator
       
  1035 // ---------------------------------------------------------------------------
       
  1036 //
       
  1037 void CSwtLabel::DrawSeparator(CWindowGc& aGc) const
       
  1038 {
       
  1039     aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
  1040 
       
  1041     if (iSeparatorHead && iSeparatorHeadMask)
       
  1042     {
       
  1043         aGc.BitBltMasked(iSeparatorHeadRect.iTl, iSeparatorHead,
       
  1044                          iSeparatorHeadRect.Size(), iSeparatorHeadMask, ETrue);
       
  1045     }
       
  1046     else if (iSeparatorHead)
       
  1047     {
       
  1048         aGc.BitBlt(iSeparatorHeadRect.iTl, iSeparatorHead, iSeparatorHeadRect.Size());
       
  1049     }
       
  1050 
       
  1051     if (iSeparatorCenter && iSeparatorCenterMask)
       
  1052     {
       
  1053         aGc.BitBltMasked(iSeparatorCenterRect.iTl, iSeparatorCenter,
       
  1054                          iSeparatorCenterRect.Size(), iSeparatorCenterMask, ETrue);
       
  1055     }
       
  1056     else if (iSeparatorCenter)
       
  1057     {
       
  1058         aGc.BitBlt(iSeparatorCenterRect.iTl, iSeparatorCenter, iSeparatorCenterRect.Size());
       
  1059     }
       
  1060 
       
  1061     if (iSeparatorTail && iSeparatorTailMask)
       
  1062     {
       
  1063         aGc.BitBltMasked(iSeparatorTailRect.iTl, iSeparatorTail,
       
  1064                          iSeparatorTailRect.Size(), iSeparatorTailMask, ETrue);
       
  1065     }
       
  1066     else if (iSeparatorTail)
       
  1067     {
       
  1068         aGc.BitBlt(iSeparatorTailRect.iTl, iSeparatorTail, iSeparatorTailRect.Size());
       
  1069     }
       
  1070 }
       
  1071 
       
  1072 // ---------------------------------------------------------------------------
       
  1073 // CSwtLabel::CalcAndUpdateSeparatorRect
       
  1074 // ---------------------------------------------------------------------------
       
  1075 //
       
  1076 TRect CSwtLabel::CalcAndUpdateSeparatorRect()
       
  1077 {
       
  1078     TRect rect(Rect());
       
  1079 
       
  1080     TRect separatorRect;
       
  1081     TAknLayoutRect layoutRect;
       
  1082     if (iStyle & KSwtStyleVertical)
       
  1083     {
       
  1084         layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorVerticalPane, rect, 0);
       
  1085         separatorRect =  layoutRect.Rect();
       
  1086         if (iDashedLineSeparatorInUse)
       
  1087         {
       
  1088             separatorRect.SetWidth(iSeparatorThickness);
       
  1089         }
       
  1090         // adjust seperator's width according to the width of the parent
       
  1091         if (separatorRect.Width() > rect.Width())
       
  1092         {
       
  1093             separatorRect.iTl.iX = rect.iTl.iX;
       
  1094             separatorRect.iBr.iX = rect.iBr.iX;
       
  1095         }
       
  1096 
       
  1097         // move to center
       
  1098         TInt xPos = rect.iTl.iX + Max(0, (rect.Width() - separatorRect.Width()) / 2);
       
  1099         separatorRect.SetRect(TPoint(xPos, separatorRect.iTl.iY), separatorRect.Size());
       
  1100 
       
  1101         if (iDashedLineSeparatorInUse)
       
  1102         {
       
  1103             iSeparatorCenterRect = separatorRect;
       
  1104         }
       
  1105         else
       
  1106         {
       
  1107             layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorVerticalPaneG1, separatorRect, 0);
       
  1108             iSeparatorHeadRect = layoutRect.Rect();
       
  1109             layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorVerticalPaneG2, separatorRect, 0);
       
  1110             iSeparatorCenterRect = layoutRect.Rect();
       
  1111             layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorVerticalPaneG3, separatorRect, 0);
       
  1112             iSeparatorTailRect = layoutRect.Rect();
       
  1113 
       
  1114             // adjust seperator's height according to the height of the parent
       
  1115             if ((iSeparatorHeadRect.Height()
       
  1116                     + iSeparatorTailRect.Height()) > separatorRect.Height())
       
  1117             {
       
  1118                 iSeparatorHeadRect = separatorRect;
       
  1119                 iSeparatorHeadRect.iBr.iY  = separatorRect.Center().iY;
       
  1120                 iSeparatorTailRect = separatorRect;
       
  1121                 iSeparatorTailRect.iTl.iY  = iSeparatorHeadRect.iBr.iY;
       
  1122             }
       
  1123         }
       
  1124 
       
  1125     }
       
  1126     else
       
  1127     {
       
  1128         layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorHorizontalPane, rect, 0);
       
  1129         separatorRect =  layoutRect.Rect();
       
  1130         if (iDashedLineSeparatorInUse)
       
  1131         {
       
  1132             separatorRect.SetHeight(iSeparatorThickness);
       
  1133         }
       
  1134         // adjust seperator's height according to height of the parent
       
  1135         if (separatorRect.Height() > rect.Height())
       
  1136         {
       
  1137             separatorRect.iTl.iY = rect.iTl.iY;
       
  1138             separatorRect.iBr.iY = rect.iBr.iY;
       
  1139         }
       
  1140 
       
  1141         // move to center
       
  1142         TInt yPos = rect.iTl.iY + Max(0,
       
  1143                                       (rect.Height() - separatorRect.Height()) / 2);
       
  1144         separatorRect.SetRect(TPoint(separatorRect.iTl.iX, yPos), separatorRect.Size());
       
  1145 
       
  1146         if (iDashedLineSeparatorInUse)
       
  1147         {
       
  1148             iSeparatorCenterRect = separatorRect;
       
  1149         }
       
  1150         else
       
  1151         {
       
  1152             layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorHorizontalPaneG1, separatorRect, 0);
       
  1153             iSeparatorHeadRect = layoutRect.Rect();
       
  1154             layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorHorizontalPaneG2, separatorRect, 0);
       
  1155             iSeparatorCenterRect = layoutRect.Rect();
       
  1156             layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::ESeparatorHorizontalPaneG3, separatorRect, 0);
       
  1157             iSeparatorTailRect = layoutRect.Rect();
       
  1158 
       
  1159             // adjust seperator's width according to the width of the parent
       
  1160             if ((iSeparatorHeadRect.Width()
       
  1161                     + iSeparatorTailRect.Width()) > separatorRect.Width())
       
  1162             {
       
  1163                 iSeparatorHeadRect = separatorRect;
       
  1164                 iSeparatorHeadRect.iBr.iX  = separatorRect.Center().iX;
       
  1165                 iSeparatorTailRect = separatorRect;
       
  1166                 iSeparatorTailRect.iTl.iX  = iSeparatorHeadRect.iBr.iX;
       
  1167             }
       
  1168         }
       
  1169 
       
  1170     }
       
  1171 
       
  1172     return separatorRect;
       
  1173 }
       
  1174 
       
  1175 // ---------------------------------------------------------------------------
       
  1176 // CSwtLabel::ResizeSeparatorImages
       
  1177 // ---------------------------------------------------------------------------
       
  1178 //
       
  1179 void  CSwtLabel::ResizeSeparatorImages()
       
  1180 {
       
  1181     CalcAndUpdateSeparatorRect();
       
  1182     AknIconUtils::SetSize(iSeparatorHead,
       
  1183                           iSeparatorHeadRect.Size(), EAspectRatioNotPreserved);
       
  1184     AknIconUtils::SetSize(iSeparatorHeadMask,
       
  1185                           iSeparatorHeadRect.Size(), EAspectRatioNotPreserved);
       
  1186     AknIconUtils::SetSize(iSeparatorCenter,
       
  1187                           iSeparatorCenterRect.Size(), EAspectRatioNotPreserved);
       
  1188     AknIconUtils::SetSize(iSeparatorCenterMask,
       
  1189                           iSeparatorCenterRect.Size(), EAspectRatioNotPreserved);
       
  1190     AknIconUtils::SetSize(iSeparatorTail,
       
  1191                           iSeparatorTailRect.Size(), EAspectRatioNotPreserved);
       
  1192     AknIconUtils::SetSize(iSeparatorTailMask,
       
  1193                           iSeparatorTailRect.Size(), EAspectRatioNotPreserved);
       
  1194 }
       
  1195 
       
  1196 // ---------------------------------------------------------------------------
       
  1197 // CSwtLabel::DefaultFont
       
  1198 // From MSwtControl
       
  1199 // ---------------------------------------------------------------------------
       
  1200 //
       
  1201 void CSwtLabel::SetFontL(const MSwtFont* aFont)
       
  1202 {
       
  1203     ASwtControlBase::DoSetFontL(aFont);
       
  1204 
       
  1205     if (iEikLabel)
       
  1206     {
       
  1207         const MSwtFont* swtFont = GetFont();
       
  1208         ASSERT(swtFont != NULL);
       
  1209         const CFont& font = (swtFont->Font());
       
  1210         DoSetFontL(&font);
       
  1211     }
       
  1212 
       
  1213     Redraw();
       
  1214 }
       
  1215 
       
  1216 // ---------------------------------------------------------------------------
       
  1217 // CSwtLabel::UpdateTextColor
       
  1218 // ---------------------------------------------------------------------------
       
  1219 //
       
  1220 void CSwtLabel::UpdateTextColor()
       
  1221 {
       
  1222     // This method is used only when label has parent, that has gained focus
       
  1223     // highlight. In such case label gets focus highlight and text color
       
  1224     // has to be updated
       
  1225     if (iEikLabel)
       
  1226     {
       
  1227         TRgb color(0);
       
  1228         TInt err(KErrNone);
       
  1229 
       
  1230         if (HasHighlight())
       
  1231         {
       
  1232             // Highlighted foreground color, overrides all others.
       
  1233             err = AknsUtils::GetCachedColor(AknsUtils::SkinInstance()
       
  1234                                             , color
       
  1235                                             , KAknsIIDQsnTextColors
       
  1236                                             , KHighlightedTextColor);
       
  1237         }
       
  1238         else if (iCustomFg)
       
  1239         {
       
  1240             // Custom foreground color, overrides the default.
       
  1241             color = iCustomFg->RgbValue();
       
  1242         }
       
  1243         else
       
  1244         {
       
  1245             // Default foreground color.
       
  1246             err = AknsUtils::GetCachedColor(AknsUtils::SkinInstance()
       
  1247                                             , color
       
  1248                                             , KAknsIIDQsnTextColors
       
  1249                                             , KNonHighlightedTextColor);
       
  1250         }
       
  1251 
       
  1252         if (err == KErrNone)
       
  1253         {
       
  1254             TRAP_IGNORE(iEikLabel->OverrideColorL(EColorLabelText, color));
       
  1255         }
       
  1256     }
       
  1257 }
       
  1258 
       
  1259 // ---------------------------------------------------------------------------
       
  1260 // CSwtLabel::HandleHighlightChange
       
  1261 // From MSwtControl
       
  1262 // ---------------------------------------------------------------------------
       
  1263 //
       
  1264 void CSwtLabel::HandleHighlightChange()
       
  1265 {
       
  1266     UpdateTextColor();
       
  1267 }
       
  1268 
       
  1269 // ---------------------------------------------------------------------------
       
  1270 // CSwtLabel::SetForegroundL
       
  1271 // From MSwtControl
       
  1272 // ---------------------------------------------------------------------------
       
  1273 //
       
  1274 void CSwtLabel::SetForegroundL(const MSwtColor* aColor)
       
  1275 {
       
  1276     ASwtControlBase::DoSetForegroundL(aColor);
       
  1277     SetColorL(EColorLabelText, aColor);
       
  1278     iCustomFg = aColor;
       
  1279     UpdateTextColor();
       
  1280     Redraw();
       
  1281 }
       
  1282 
       
  1283 // ---------------------------------------------------------------------------
       
  1284 // CSwtLabel::DefaultFont
       
  1285 // From ASwtControlBase
       
  1286 // ---------------------------------------------------------------------------
       
  1287 //
       
  1288 const MSwtFont& CSwtLabel::DefaultFont() const
       
  1289 {
       
  1290     if (iDefaultFont != NULL)   // Implies iEikLabel != NULL
       
  1291         return *iDefaultFont;
       
  1292 
       
  1293     return *iDisplay.Device().GetSystemFont();
       
  1294 }
       
  1295 
       
  1296 // ---------------------------------------------------------------------------
       
  1297 // CSwtLabel::Control
       
  1298 // From MSwtLabel
       
  1299 // ---------------------------------------------------------------------------
       
  1300 //
       
  1301 MSwtControl* CSwtLabel::Control()
       
  1302 {
       
  1303     return this;
       
  1304 }
       
  1305 
       
  1306 // ---------------------------------------------------------------------------
       
  1307 // CSwtLabel::GetAlignment
       
  1308 // From MSwtLabel
       
  1309 // ---------------------------------------------------------------------------
       
  1310 //
       
  1311 TInt CSwtLabel::GetAlignment() const
       
  1312 {
       
  1313     return iStyle & KSwtAlignmentMask;
       
  1314 }
       
  1315 
       
  1316 // ---------------------------------------------------------------------------
       
  1317 // CSwtLabel::SetAlignment
       
  1318 // From MSwtLabel
       
  1319 // ---------------------------------------------------------------------------
       
  1320 //
       
  1321 void CSwtLabel::SetAlignment(TInt aAlignment)
       
  1322 {
       
  1323     ASSERT(!(iStyle & KSwtStyleSeparator));
       
  1324 
       
  1325     TGulAlignment alignmentValueOS;
       
  1326     if (aAlignment == KSwtStyleCenter)         // Center
       
  1327     {
       
  1328         alignmentValueOS = EHCenterVCenter;
       
  1329     }
       
  1330     else if (aAlignment == KSwtStyleTrail)     // Trail
       
  1331     {
       
  1332         if ((iStyle & KSwtStyleRightToLeft)
       
  1333                 || AknLayoutUtils::LayoutMirrored())
       
  1334             alignmentValueOS = EHLeftVCenter;
       
  1335         else
       
  1336             alignmentValueOS = EHRightVCenter;
       
  1337     }
       
  1338     else                                    // Lead ( default )
       
  1339     {
       
  1340         ASSERT(aAlignment==KSwtStyleLead);
       
  1341         if (iStyle & KSwtStyleRightToLeft
       
  1342                 || AknLayoutUtils::LayoutMirrored())
       
  1343             alignmentValueOS = EHRightVCenter;
       
  1344         else
       
  1345             alignmentValueOS = EHLeftVCenter;
       
  1346     }
       
  1347 
       
  1348     iStyle &= ~KSwtAlignmentMask;
       
  1349     iStyle |= aAlignment;
       
  1350 
       
  1351     if (iEikLabel != NULL)
       
  1352     {
       
  1353         iEikLabel->SetAlignment(alignmentValueOS);
       
  1354     }
       
  1355 
       
  1356     Redraw();
       
  1357 }
       
  1358 
       
  1359 // ---------------------------------------------------------------------------
       
  1360 // CSwtLabel::SetImageL
       
  1361 // From MSwtLabel
       
  1362 // ---------------------------------------------------------------------------
       
  1363 //
       
  1364 void CSwtLabel::SetImageL(const MSwtImage* aImage)
       
  1365 {
       
  1366     ASSERT(!(iStyle & KSwtStyleSeparator));
       
  1367     ASSERT(!iSeparatorCenter);
       
  1368 
       
  1369     if (iImage != NULL)
       
  1370         iImage->RemoveRef();
       
  1371 
       
  1372     iImage = aImage;
       
  1373 
       
  1374     TBool showText;
       
  1375     if (iImage != NULL)
       
  1376     {
       
  1377         iImage->AddRef();
       
  1378         showText = EFalse;
       
  1379     }
       
  1380     else
       
  1381     {
       
  1382         showText = ETrue;
       
  1383     }
       
  1384 
       
  1385     iEikLabel->MakeVisible(showText);   //lint !e613
       
  1386 
       
  1387     Redraw();
       
  1388 }
       
  1389 
       
  1390 // ---------------------------------------------------------------------------
       
  1391 // CSwtLabel::SetTextL
       
  1392 // From MSwtLabel
       
  1393 // NOTE! The text was already set on the Java side and that Label.getText() returns.
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 void CSwtLabel::SetTextL(const TDesC& aText)
       
  1397 {
       
  1398     ASSERT(!(iStyle & KSwtStyleSeparator));
       
  1399 
       
  1400     // Replace local copy of the text
       
  1401     delete iOriginalText;
       
  1402     iOriginalText = NULL;
       
  1403     iOriginalText = aText.AllocL();
       
  1404     iEikLabel->MakeVisible(ETrue);
       
  1405 
       
  1406     // Count lines and cache result
       
  1407     TInt numberOfLines = 1;
       
  1408     TPtrC ptr = aText;
       
  1409     FOREVER
       
  1410     {
       
  1411         const TInt offset = ptr.Locate('\n');
       
  1412         if (offset < 0 || offset == ptr.Length() - 1)
       
  1413         {
       
  1414             break;
       
  1415         }
       
  1416         numberOfLines++;
       
  1417         ptr.Set(ptr.Mid(offset + 1));
       
  1418     }
       
  1419     iOriginalTextLineCount = numberOfLines;
       
  1420 
       
  1421     // Wrap or clip text and set the result to CEikLabel
       
  1422     if (iStyle & KSwtStyleWrap)
       
  1423     {
       
  1424         WrapTextL(iEikLabel->Size());
       
  1425     }
       
  1426     else
       
  1427     {
       
  1428         ClipTextL(iEikLabel->Size().iWidth);
       
  1429     }
       
  1430 
       
  1431     Redraw();
       
  1432 }