uifw/AvKon/inc/AknPhedView.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef AKNPHEDVIEW_H
       
    19 #define AKNPHEDVIEW_H
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "AknPhedModel.h"
       
    24 #include <gdi.h>
       
    25 #include <w32std.h>
       
    26 #include "AknUtils.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 
       
    30 class CAknPhoneNumberEditor;
       
    31 class MAknsSkinInstance;
       
    32 class MAknsControlContext;
       
    33 
       
    34 //
       
    35 // TAknPhedViewLine
       
    36 //
       
    37 // Encapsulates the concept of a display line which exists as one of a set of lines.
       
    38 // Handles text, cursor and truncation positioning and drawing.
       
    39 // Note: position indexing is from RHS, since this class shows right justified text.
       
    40 //
       
    41 class TAknPhedViewLine
       
    42     {
       
    43     public:
       
    44         TAknPhedViewLine();
       
    45         
       
    46         // structural manipulation
       
    47         inline void SetModel( CAknPhedModel* aData );
       
    48         inline void SetLeftLine( TAknPhedViewLine* iLeft );
       
    49         inline void SetRightLine( TAknPhedViewLine* iRight );
       
    50         void SetFormat( const CFont* aFont, const TRect& aRect, TInt aBaseline );
       
    51         
       
    52         // Line limits manipulation
       
    53         inline TInt LeftPos() const;
       
    54         inline TInt RightPos() const;
       
    55         inline TBool LineContains( TInt aPos ) const;
       
    56         inline TInt LineWidth() const;
       
    57         void SetLeftPos( TInt aPos );
       
    58         void SetRightPos( TInt aPos );
       
    59         
       
    60         // Event handlers
       
    61         TBool HandleTextChange( TInt aStart, TInt aEnd );
       
    62         TBool HandleCursorChange( TInt aCursor );
       
    63         void HandleSelectionChange( TInt aLeft, TInt aRight );
       
    64         
       
    65         // Utility functions
       
    66         inline TBool InRange( TInt aPos, TInt aLeft, TInt aRight ) const;
       
    67         TInt CountChars( const TDesC& aDes, TBool aStartTruncated, 
       
    68             TBool aAllowEndTruncation, TInt aCharsToEnd ) const;
       
    69         
       
    70         // Truncation functions
       
    71         void SetTruncation( const TDesC& aTruncation );
       
    72         inline TInt TruncationWidth() const;
       
    73         inline TBool IsTruncated() const;
       
    74         inline TBool IsTruncatedLeft() const;
       
    75         inline TBool IsTruncatedRight() const;
       
    76         
       
    77         // Selection functions
       
    78         TBool HasSelection() const;
       
    79         TInt SelectionStart() const;
       
    80         TInt SelectionEnd() const;
       
    81         
       
    82         // Position translation functions
       
    83         TInt CursorPosToXPos( TInt aCursorPos ) const;
       
    84         TInt XPosToCursorPos( TInt aXPos ) const;
       
    85         
       
    86         // Positioning functions
       
    87         inline TInt Baseline() const;
       
    88         TPoint CursorPosition() const;
       
    89         
       
    90         // Text access functions
       
    91         TPtrC Text() const;
       
    92         TPtrC ReverseText() const;
       
    93         TPtrC MaxText() const;
       
    94         TPtrC MaxReverseText() const;
       
    95         
       
    96         // Drawing
       
    97         inline void SetRedrawRequired();
       
    98         inline TBool IsRedrawRequired() const;
       
    99         void Draw( CWindowGc& aGc, MAknsSkinInstance* aSkin, 
       
   100             MAknsControlContext* aContext, const CCoeControl* aControl ) const;
       
   101         void DrawText( CGraphicsContext& aGc, const TDesC& aText, TInt aBaseline,
       
   102             TRect& aRect ) const;
       
   103         
       
   104         TRect Rect() const;
       
   105         
       
   106     private:
       
   107         //
       
   108         // Measuring and drawing routines capable of implementing character translation. 
       
   109         //(for ArabicIndic number support)
       
   110         //
       
   111         
       
   112         /**
       
   113         * This routine is used to Draw text with settings-dependent numerals.
       
   114         * It is used as a replacement for CGraphicsContext::DrawText( const TDesC& aText,
       
   115         * TInt aBaseline, TRect& aRect, CGraphicsContext:TAlign aAlignment);
       
   116         * except that numeric digits will be replaced with the correct digits according 
       
   117         * to device settings.
       
   118         * 
       
   119         * The buffer passed to this routine must be <= length than the buffers
       
   120         * present in CAknPhedModel.
       
   121         */
       
   122         void DrawTextWithTranslation( CGraphicsContext& aGc, const TDesC& aText, 
       
   123             TInt aBaseline, TRect& aRect ) const;
       
   124         
       
   125         /**
       
   126         * This routine is used to count the numbers of unicode characters that fit in the given width
       
   127         * It is used as a replacement for CFont::TextCount( const TDesC& aText, TInt aWidth );
       
   128         * except that numeric digits will be replaced before measurement with 
       
   129         * the correct digits according to device settings.
       
   130         * 
       
   131         * The buffer passed to this routine must be <= length than the 
       
   132         * buffers present in CAknPhedModel.
       
   133         */
       
   134         TInt TextCountWithTranslation( const TDesC& aText, TInt aWidth ) const;
       
   135         
       
   136         /**
       
   137         * This routine is used to measure the width of the text when rendered.
       
   138         * It is used as a replacement for CFont::TextWidthInPixels( const TDesC& aText );
       
   139         * except that numeric digits will be replaced before measurement with 
       
   140         * the correct digits according to device settings.
       
   141         * 
       
   142         * The buffer passed to this routine must be <= length than the buffers 
       
   143         * present in CAknPhedModel.
       
   144         */
       
   145         TInt TextWidthInPixelsWithTranslation( const TDesC& aText ) const;
       
   146         
       
   147         void DrawHighlightText( CGraphicsContext& aGc, TBool aUseSkin ) const;
       
   148         TPtr TranslatedText( const TDesC& aText ) const;
       
   149         
       
   150     private:
       
   151         // None of these pointer data members own the objects pointed to.
       
   152         CAknPhedModel* iModel;
       
   153         TAknPhedDataMirror iMirror;
       
   154         const CFont* iFont;
       
   155         TRect iRect;
       
   156         TInt iBaseline;
       
   157         TPtrC iTruncation;
       
   158         TInt iTruncationWidth;
       
   159         
       
   160         TAknPhedViewLine* iLeftLine;
       
   161         TAknPhedViewLine* iRightLine;
       
   162         
       
   163         TInt iCursor;
       
   164         TInt iLeftPos;
       
   165         TInt iRightPos;
       
   166         
       
   167         mutable TBool iRedraw;
       
   168         
       
   169     private: // for testing
       
   170         friend class CTestPhedView;
       
   171     };
       
   172     
       
   173 typedef CArrayFixFlat<TAknPhedViewLine> CAknPhedViewLineArray;
       
   174     
       
   175     
       
   176     
       
   177     //
       
   178     // CAknPhedView
       
   179     //
       
   180     // Encapsulates the logical and positional relationships between display lines.
       
   181     // Handles "vertical" operations and logic.
       
   182     // Note: position indexing is from bottom-RHS, since this class 
       
   183     // shows bottom-right justified text.
       
   184     //
       
   185 NONSHARABLE_CLASS( CAknPhedView ) : public CBase, public MPhedDataObserver
       
   186     {
       
   187 public:
       
   188     enum
       
   189         {
       
   190         KNoPos = -1
       
   191         };
       
   192     
       
   193 public:
       
   194     CAknPhedView( CAknPhedModel* aModel );
       
   195     ~CAknPhedView();
       
   196     void ConstructL( TInt aMaxLines, const TDesC& aTruncation );
       
   197     void SetWindows( RWindowGroup* aWg, RWindowBase* aWindow );
       
   198     void SetChangeReceiver( CAknPhoneNumberEditor* aChangeReceiver );
       
   199     
       
   200     // Format manipulation functions
       
   201     TBool IsTruncated() const;
       
   202     void SetFormat( TInt aLines, const CFont* aFont, const TRect& aRect, 
       
   203         TInt aBottomBaselineOffset, TInt aBaselineSeparation );
       
   204     TRect Rect() const;
       
   205     
       
   206     // Drawing and cursor graphics
       
   207     void EnableCursor();
       
   208     void DisableCursor();
       
   209     void Draw( CWindowGc& aGc, TBool aRedrawAll, const CCoeControl* aControl ) const;
       
   210     
       
   211     // vertical navigation functions
       
   212     TBool CursorUp( TInt aTargetCursorPos );
       
   213     TBool CursorDown( TInt aTargetCursorPos );
       
   214     TBool SelectUp( TInt aTargetCursorPos );
       
   215     TBool SelectDown( TInt aTargetCursorPos );
       
   216     TPoint CursorPosition() const;
       
   217     TInt CursorLine() const;
       
   218     inline const CAknPhedViewLineArray* LineArray();
       
   219     
       
   220     /**
       
   221     * Calculate cursor position by pointer position.
       
   222     * 
       
   223     * @param aPt, the pointer position.     
       
   224     * @return cursor position for CAknPhedModel.
       
   225     */
       
   226     TInt GetCursorPosByPoint( const TPoint& aPt );
       
   227     
       
   228 private:
       
   229     // Event handling and reformatting
       
   230     void HandlePhedDataEvent( const TAknPhedDataEvent& aEvent, 
       
   231         CAknPhedModel* aPhedData );
       
   232     void FullFormat();
       
   233     void TextChangeFormat( TInt aStart, TInt aEnd );
       
   234     void CursorChangeFormat( TInt aCursor );
       
   235     void SelectionChangeFormat( TInt aLeft, TInt aRight );
       
   236     void SetLeftPos( TInt aPos );
       
   237     
       
   238     // cursor positioning and drawing
       
   239     void MoveCursorToLine( TInt aLineNo, TInt aTargetCursorPos );
       
   240     void UpdateCursor();
       
   241     void SetCursorFormat( const CFont* aFont );
       
   242     
       
   243     // Setting up the logical relationship between lines
       
   244     void SetConnectingLines( TAknPhedViewLine& aLine, TInt aLineNum );
       
   245     
       
   246 private:
       
   247     // owned pointer member
       
   248     CAknPhedViewLineArray* iLines;
       
   249     HBufC* iTruncation;
       
   250     
       
   251     // non-owned pointer members
       
   252     CAknPhedModel* iModel;
       
   253     TAknPhedDataMirror iMirror;
       
   254     
       
   255     TInt iNumLines;
       
   256     TInt iCursorLine;
       
   257     const CFont* iFont;
       
   258     TRect iRect;
       
   259     
       
   260     TTextCursor iCursor;
       
   261     TBool iCursorEnabled;
       
   262     RWindowGroup* iWg;
       
   263     RWindowBase* iWindow;
       
   264     
       
   265     CAknPhoneNumberEditor* iChangeReceiver;
       
   266     
       
   267 private: // for testing
       
   268     friend class CTestPhedView;
       
   269     };
       
   270 
       
   271 
       
   272 inline void TAknPhedViewLine::SetModel( CAknPhedModel* aModel )
       
   273     { iModel = aModel; iMirror.SetPhedModel( iModel ); }
       
   274 
       
   275 inline void TAknPhedViewLine::SetLeftLine( TAknPhedViewLine* iLeft )
       
   276     { iLeftLine = iLeft; }
       
   277 
       
   278 inline void TAknPhedViewLine::SetRightLine( TAknPhedViewLine* iRight )
       
   279     { iRightLine = iRight; }
       
   280 
       
   281 inline TInt TAknPhedViewLine::LeftPos() const
       
   282     { return iLeftPos; }
       
   283 
       
   284 inline TInt TAknPhedViewLine::RightPos() const
       
   285     { return iRightPos; }
       
   286 
       
   287 inline TBool TAknPhedViewLine::LineContains( TInt aPos ) const
       
   288     { return InRange(aPos, iLeftPos, iRightPos); }
       
   289 
       
   290 inline TBool TAknPhedViewLine::InRange( TInt aPos, TInt aLeft, TInt aRight ) const
       
   291     { return aLeft >= aPos && aPos >= aRight; }
       
   292 
       
   293 inline TInt TAknPhedViewLine::TruncationWidth() const
       
   294     { return iTruncationWidth; }
       
   295 
       
   296 inline TBool TAknPhedViewLine::IsTruncated() const
       
   297     { return IsTruncatedLeft() || IsTruncatedRight(); }
       
   298 
       
   299 inline TBool TAknPhedViewLine::IsTruncatedLeft() const
       
   300     { return !iLeftLine && iLeftPos < iModel->Length(); }
       
   301 
       
   302 inline TBool TAknPhedViewLine::IsTruncatedRight() const
       
   303     { return !iRightLine && iRightPos > 0; }
       
   304 
       
   305 inline TInt TAknPhedViewLine::LineWidth() const
       
   306     { return iLeftPos - iRightPos; }
       
   307 
       
   308 inline void TAknPhedViewLine::SetRedrawRequired()
       
   309     { iRedraw = ETrue; }
       
   310 
       
   311 inline TBool TAknPhedViewLine::IsRedrawRequired() const
       
   312     { return iRedraw; }
       
   313 
       
   314 inline TInt TAknPhedViewLine::Baseline() const
       
   315     { return iBaseline; }
       
   316 
       
   317 inline TPtrC TAknPhedViewLine::MaxText() const
       
   318     { return iModel->Text(iMirror.Mirror(iLeftPos), iModel->Length() - 1); }
       
   319 
       
   320 inline TPtrC TAknPhedViewLine::MaxReverseText() const
       
   321     { return iModel->ReverseText(iRightPos, iModel->Length() - 1); }
       
   322 
       
   323 inline TPtrC TAknPhedViewLine::Text() const
       
   324     { return MaxText().Left(LineWidth()); }
       
   325 
       
   326 inline TPtrC TAknPhedViewLine::ReverseText() const
       
   327     { return MaxReverseText().Left(LineWidth()); }
       
   328 
       
   329 inline const CAknPhedViewLineArray* CAknPhedView::LineArray()
       
   330     {
       
   331     return iLines;
       
   332     }
       
   333 
       
   334 #endif