javauis/lcdui_akn/lcdui/inc/CMIDItemLabel.h
branchRCL_3
changeset 19 04becd199f91
child 60 6c158198356e
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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 #ifndef CMIDITEMLABEL_H
       
    21 #define CMIDITEMLABEL_H
       
    22 
       
    23 // needed for TRgb and TMargins classes
       
    24 #include <gdi.h>
       
    25 // CCoeControl inheritance in class declaration
       
    26 #include <coecntrl.h>
       
    27 // using CAknPictographInterface for iPictographInterface
       
    28 #include <AknPictographInterface.h>
       
    29 // MAknPictographAnimatorCallBack interface in class declaration
       
    30 #include <AknPictographDrawerInterface.h>
       
    31 
       
    32 // using CMIDFont::TDefaultId for iDefaultFontId
       
    33 #include "CMIDFont.h"
       
    34 
       
    35 class CEikLabel;
       
    36 
       
    37 /** This class implements the text in form item labels and the
       
    38     content in string items. Its name is therefore not the best one
       
    39     as it is more than a label in form items.
       
    40 
       
    41     It uses and array of CEikLabel to wrap the given text in more than
       
    42     one line. The text wrapping is performed via the AVKON Text utilities.
       
    43 */
       
    44 NONSHARABLE_CLASS(CMIDItemLabel) : public CCoeControl, public MAknPictographAnimatorCallBack
       
    45 {
       
    46 public:
       
    47 
       
    48     static CMIDItemLabel* NewL(TInt aMaxWidth, TBool aLabelBeforeContent,
       
    49     TInt aMaxNumberOfLines = -1,
       
    50     const CMIDFont::TDefaultId& aDefaultFontId = CMIDFont::EDefaultLabelId,
       
    51     TBool aIsContent = EFalse);
       
    52 
       
    53     ~CMIDItemLabel();
       
    54 
       
    55     //
       
    56     // From CCoeControl
       
    57     //
       
    58     TSize MinimumSize();
       
    59     TInt CountComponentControls() const;
       
    60     CCoeControl* ComponentControl(TInt aIndex) const;
       
    61 
       
    62     void SetTextL(const TDesC& aText);
       
    63     inline const TDesC* Text() const;
       
    64 
       
    65     TSize PreferredSize() const;
       
    66     TInt PreferredWidth() const;
       
    67     void SetWidthL(TInt aLineWidth);
       
    68 
       
    69     void SetVariableWidthL(TInt aFirstWidth, TInt aSecondWidth);
       
    70     TInt FirstWordWidth() const;
       
    71 
       
    72     void SetCentered(TBool aValue);
       
    73     void SetUnderlined(TBool aUnderlined);
       
    74     void SetColorL(TRgb aColor);
       
    75     void SetEmphasisL(TBool aEmphasis);
       
    76     TRgb GetDefaultColor();
       
    77     void SetFont(const MMIDFont* aFont);
       
    78     const CFont* Font() const;
       
    79     inline TInt NumLines();
       
    80     TInt LineHeight() const;
       
    81     CEikLabel* LabelAtIdx(TInt aIdx);
       
    82     void SetMaxWidth(TInt aMaxWidth);   // this just sets the new max width (usually form width), no reformatting is actually done
       
    83 
       
    84     inline TBool IsContent();
       
    85     // Pictograph
       
    86     void DrawPictographArea();
       
    87 
       
    88     inline void SetMaxNumLines(TInt aMaxNumLines);
       
    89     inline TInt MaxNumLines() const;
       
    90 
       
    91     void ResolutionChange();
       
    92     TInt ItemLabelMargin();
       
    93     void AdjustToSizeL(const TSize& aSize);
       
    94 
       
    95 private:
       
    96     CMIDItemLabel(TInt aMaxWidth, TBool aLabelBeforeContent, TInt aMaxNumberOfLines,
       
    97                   const CMIDFont::TDefaultId& aDefaultFontId, TBool aIsContent = EFalse);
       
    98 
       
    99     void UpdateMargins();
       
   100     void ConstructL();
       
   101 
       
   102 private:
       
   103     //
       
   104     // From CCoeControl
       
   105     //
       
   106     void SizeChanged();
       
   107 
       
   108 private:
       
   109     void WrapTextAndSetSizeL();
       
   110     void ResetLabelArray();
       
   111 
       
   112     TBool IsLineSeparator(const TText aChar) const;
       
   113     TInt LongestLineWidth() const;
       
   114     TSize PropperEikLabelMinumumSize(CEikLabel& aLabel) const;
       
   115 
       
   116     /** The font used by current layout*/
       
   117     void PrepareFont();
       
   118 private:
       
   119     TBool iCentered;
       
   120 
       
   121     HBufC* iText; /** The text given by the application */
       
   122     HBufC* iWrappedText; /** The text given plus newlines for wrapping and eventual ellipsis*/
       
   123 
       
   124     CArrayFixFlat<TPtrC>* iWrappedArray;
       
   125     CArrayFixFlat<CEikLabel*>* iLabelArray;
       
   126 
       
   127     /** A font assigned java side. If this is null we use the default font id */
       
   128     const MMIDFont* iFont;
       
   129 
       
   130     /** The default font id, to be used if no font has been given */
       
   131     CMIDFont::TDefaultId iDefaultFontId;
       
   132     TInt iFontSize;
       
   133 
       
   134     TRgb iColor;
       
   135     TRgb iDefaultColor;
       
   136     TBool iUnderlined;
       
   137     TInt iMaxWidth;
       
   138 
       
   139 
       
   140     //
       
   141     CAknPictographInterface* iPictographInterface;
       
   142 
       
   143     /** We can have at most this number of lines, -1 means unlimited */
       
   144     TInt iMaxNumberOfLines;
       
   145 
       
   146     /** The array containing the width of each line. If it contains less that
       
   147     iMaxNumberOfLines elements, then the last width is used for the remaining
       
   148     lines. So if this array has only one element, it means all lines have the
       
   149     same width. */
       
   150     CArrayFixFlat<TInt>* iLineWidthArray;
       
   151 
       
   152     TBool iLabelBeforeContent; // EFalse with ImageItem, otherwise ETrue
       
   153     TBool iIsContent;      // ETrue if this represents the StringItem content, EFalse otherwise
       
   154     TMargins iLabelMargins;
       
   155 
       
   156 };
       
   157 
       
   158 inline const TDesC* CMIDItemLabel::Text() const
       
   159 {
       
   160     return(iText);
       
   161 }
       
   162 
       
   163 inline TInt CMIDItemLabel::NumLines()
       
   164 {
       
   165     if (iLabelArray)
       
   166     {
       
   167         return iLabelArray->Count();
       
   168     }
       
   169     return 0;
       
   170 }
       
   171 
       
   172 inline void CMIDItemLabel::SetMaxNumLines(TInt aMaxNumLines)
       
   173 {
       
   174     iMaxNumberOfLines = aMaxNumLines;
       
   175 }
       
   176 
       
   177 inline TInt CMIDItemLabel::MaxNumLines() const
       
   178 {
       
   179     return iMaxNumberOfLines;
       
   180 }
       
   181 
       
   182 inline TBool CMIDItemLabel::IsContent()
       
   183 {
       
   184     return iIsContent;
       
   185 }
       
   186 #endif // CMIDITEMLABEL_H