uifw/AvKon/inc/AknTextWrapper.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Avkon text wrapper implementation class
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef AKNTEXTWRAPPER_H
       
    22 #define AKNTEXTWRAPPER_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "AknLineBreaker.h"
       
    27 #include "AknBidiTextUtils.h"
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 
       
    31 class CFont;
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 struct TAknLocVariant
       
    36     {
       
    37     TInt iStart;
       
    38     TInt iEnd;
       
    39     };
       
    40 
       
    41 const TInt KAknMaxLocVariants = 5;
       
    42 
       
    43 // CLASS DECLARATION
       
    44 
       
    45 /**
       
    46 * Text wrapper implementation class
       
    47 *
       
    48 *  @lib avkon.dll
       
    49 *  @since 2.0
       
    50 *
       
    51 *  @internal
       
    52 */
       
    53 class TAknTextWrapper
       
    54     {
       
    55     public:
       
    56 
       
    57         enum // used with bit flags, values must be powers of two
       
    58             {
       
    59             EClip                   = 0x0001,
       
    60             EConvertToVisual        = 0x0002,
       
    61             EReserveVisualBuffer    = 0x0004,
       
    62             EWrapAllText            = 0x0008,
       
    63             // internal flags    
       
    64             EClipRequired           = 0x4000,
       
    65             EFits                   = 0x8000
       
    66             };
       
    67 
       
    68     public:  // Constructors and destructor
       
    69 
       
    70         /**
       
    71         * C++ default constructor.
       
    72         */
       
    73         TAknTextWrapper(
       
    74             TDes& aStringToWrap,
       
    75             const CArrayFix<TInt>* aLineWidthArray, 
       
    76             const CFont& aFont,
       
    77             CArrayFix<TPtrC>& aWrappedArray,
       
    78             TInt aLineWidth,
       
    79             TInt aFlags,
       
    80             AknBidiTextUtils::TParagraphDirectionality aDirectionality );
       
    81 
       
    82         /**
       
    83         * Destructor.
       
    84         */
       
    85         ~TAknTextWrapper();
       
    86 
       
    87     public: // New functions
       
    88 
       
    89         /**
       
    90         * Wrap implementation.
       
    91         *
       
    92         * @return If flag EReserveVisualBuffer was set, allocated visual buffer.
       
    93         *         Otherwise, NULL.
       
    94         */
       
    95         HBufC* WrapToArrayL();
       
    96 
       
    97         /**
       
    98         * Chop implementation.
       
    99         *
       
   100         * @return If flag EReserveVisualBuffer was set, allocated visual buffer.
       
   101         *         Otherwise, NULL.
       
   102         */
       
   103         HBufC* ChopToArrayAndClipL();
       
   104 
       
   105         /*
       
   106         * Separates localisation variants from the given text.
       
   107         * Those variants are separated with the character 0x0001.
       
   108         * They are sorted in descending order of character count
       
   109         * and returned in the array aVariants.
       
   110         *
       
   111         * @param aText
       
   112         * @param aVariants Pointer to an array containing room for at least
       
   113         * 'KAknMaxLocVariants' elements.
       
   114         *
       
   115         * @ret Number of the localisation variants returned in aVariants.
       
   116         * The minimum value is 1 and the maximum value is KAknMaxLocVariants.
       
   117         */
       
   118         static TInt GetLocVariants(
       
   119             const TDesC& aText, TAknLocVariant* aVariants );
       
   120 
       
   121     private: // New functions
       
   122 
       
   123         HBufC* DoOperationL( TInt aOp );
       
   124         HBufC* DoWrapToArrayL();
       
   125         HBufC* DoChopToArrayAndClipL();
       
   126 
       
   127         /*
       
   128         * Finds last legal position to break the line in given text,
       
   129         * according to the given line width.
       
   130         *
       
   131         * If a legal breaking position is found, iBreakPos is set to it.
       
   132         *
       
   133         * @param aText text
       
   134         * @param aFitsInLine max amount of characters fitting in line
       
   135         * @param aLineWidth line width in pixels
       
   136         * @param aReplaceSoftHyphen whether to replace soft hyphen with real hyphen or not,
       
   137         *        if the line is broken after a soft hyphen
       
   138         *
       
   139         * @return ETrue if a legal breaking position was found, EFalse otherwise.
       
   140         */
       
   141         TBool GetWrappingPosition( 
       
   142             const TDesC& aText,
       
   143             TInt aFitsInLine,
       
   144             TInt aLineWidth,
       
   145             TBool aReplaceSoftHyphen );
       
   146 
       
   147         /*
       
   148         * Appends the given line in the result array.
       
   149         *
       
   150         * @param aLine line to be appended
       
   151         */
       
   152         void AppendToArrayL( const TDesC& aLine );
       
   153 
       
   154         /*
       
   155         * Finds the first explicit line break character in given text.
       
   156         *
       
   157         * @param aText text
       
   158         *
       
   159         * @return offset of first explicit line break character or KErrNotFound
       
   160         */
       
   161         TInt FindLineBreak( const TDesC& aText );
       
   162 
       
   163         /*
       
   164         * Examines character at position iNextLineStart in descriptor iText
       
   165         * and if character is recognized as a separator, increases iNextLineStart
       
   166         * by 1. In case of combination CR+LF, iNextLineStart is increased by 2.
       
   167         */
       
   168         void PassLineBreak();
       
   169 
       
   170         /*
       
   171         * Inserts ellipsis in given text in the last possible position so that
       
   172         * the line fits in the given pixel width. If flag EConvertToVisual is set,
       
   173         * this method returns the position of where ellipsis would be added, but
       
   174         * does not actually add it. It will be added in logical to visual
       
   175         * conversion.
       
   176         *
       
   177         * @param aText text
       
   178         * @param aLineWidth line width in pixels
       
   179         *
       
   180         * @return If EConvertToVisual flag is set,
       
   181         *         position of where ellipsis should be inserted.
       
   182         *         otherwise, position after the inserted ellipsis.
       
   183         */
       
   184         TInt InsertEllipsis( const TDesC& aText, TInt aLineWidth );
       
   185 
       
   186         HBufC* ConvertToVisualIfRequiredL();
       
   187 
       
   188         TBool ResultFits();
       
   189 
       
   190     private: // Data
       
   191 
       
   192         TDes& iSourceString;
       
   193         const CArrayFix<TInt>* iLineWidthArray;
       
   194         const CFont& iFont;
       
   195         CArrayFix<TPtrC>& iResultArray;
       
   196         TInt iLineWidth;
       
   197         TInt iFlags;
       
   198         AknBidiTextUtils::TParagraphDirectionality iDirectionality;
       
   199 
       
   200         TAknLineBreaker iBreaker;
       
   201         const TDesC& iSeparators;
       
   202 
       
   203         TPtrC iText;
       
   204         TInt iBreakPos;
       
   205         TInt iNextLineStart;
       
   206     };
       
   207 
       
   208 #endif      // AKNTEXTWRAPPER_H
       
   209             
       
   210 // End of File