dependencies/AknMarqueeControl.h
branchv5backport
changeset 21 11157e26c4a7
equal deleted inserted replaced
20:d2ab7c3d0c48 21:11157e26c4a7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Text scrolling functionality.
       
    15 *  
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef AKNMARQUEECONTROL_H
       
    22 #define AKNMARQUEECONTROL_H
       
    23 
       
    24 #include <coecntrl.h>
       
    25 #include <coemain.h>
       
    26 #include <babitflags.h>
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class TAknTextComponentLayout;
       
    30 
       
    31 /**
       
    32 * Marquee control for AVKON
       
    33 *
       
    34 */
       
    35 NONSHARABLE_CLASS(CAknMarqueeControl) : public CCoeControl, MCoeForegroundObserver
       
    36     {
       
    37     public:
       
    38 	
       
    39         /**
       
    40         * Two-phased constructor.
       
    41         * @param aLoops Max number of loops to be executed
       
    42         * @param aScrollAmount The amount of pixels scrolled per iteration
       
    43         * @param aScrollDelay The interval between iterations
       
    44         */
       
    45         IMPORT_C static CAknMarqueeControl* NewL(const TInt aLoops = 1, 
       
    46                         const TInt aScrollAmount = 6, const TInt aScrollDelay = 1000000);
       
    47 
       
    48         /**
       
    49         * Two-phased constructor.
       
    50         * @param aLoops Max number of loops to be executed
       
    51         * @param aScrollAmount The amount of pixels scrolled per iteration
       
    52         * @param aScrollDelay The interval between iterations
       
    53         */
       
    54         IMPORT_C static CAknMarqueeControl* NewLC(const TInt aLoops = 1, 
       
    55                         const TInt aScrollAmount = 6, const TInt aScrollDelay = 1000000);
       
    56         
       
    57         /** 
       
    58         * set redraw event callback
       
    59         *
       
    60         */
       
    61         IMPORT_C void SetRedrawCallBack( TCallBack& aRedrawEventCallback );
       
    62 
       
    63         /** 
       
    64         * Draws text in the current position. 
       
    65         * After the marquee object is created calling this should be enough.
       
    66         * @return ETrue = All the loops have been executed, EFalse = There are loops to be executed.
       
    67         */
       
    68         IMPORT_C TBool DrawText( CWindowGc& aGc,
       
    69                                  const TRect& aTextRect,
       
    70                                  const TDesC& aText,
       
    71                                  const TInt aBaselineOffset,
       
    72                                  const CGraphicsContext::TTextAlign aAlign,
       
    73                                  const CFont& aFont );
       
    74 
       
    75         /** 
       
    76         * Draws text in the current position. 
       
    77         * After the marquee object is created calling this should be enough.
       
    78         * @since S60 3.1
       
    79         * @deprecated, use version taking color as last parameter instead
       
    80         * @param aGc Graphics context.
       
    81         * @param aRect Parent rectangle for the text layout.
       
    82         * @param aTextLayout Text layout that is used to draw the text.
       
    83         * @param aText Text to marquee.
       
    84         * @param aFont Font used in drawing. If this is NULL then the font is
       
    85         * taken from the aTextLayout.
       
    86         * @return ETrue = All the loops have been executed, EFalse = There are loops to be executed.
       
    87         */
       
    88         IMPORT_C TBool DrawText( CWindowGc& aGc,
       
    89                                  const TRect& aRect,
       
    90                                  const TAknTextComponentLayout& aTextLayout,
       
    91                                  const TDesC& aText,
       
    92                                  const CFont* aFont );
       
    93 
       
    94         /** 
       
    95         * Draws text in the current position. 
       
    96         * After the marquee object is created calling this should be enough.
       
    97         * @since S60 3.1
       
    98         * @param aGc Graphics context.
       
    99         * @param aRect Parent rectangle for the text layout.
       
   100         * @param aTextLayout Text layout that is used to draw the text.
       
   101         * @param aText Text to marquee.
       
   102         * @param aFont Font used in drawing. If this is NULL then the font is
       
   103         * taken from the aTextLayout.
       
   104         * @param aColor Color of the text        
       
   105         * @return ETrue = All the loops have been executed, EFalse = There are loops to be executed.
       
   106         */
       
   107         IMPORT_C TBool DrawText( CWindowGc& aGc,
       
   108                                  const TRect& aRect,
       
   109                                  const TAknTextComponentLayout& aTextLayout,
       
   110                                  const TDesC& aText,
       
   111                                  const CFont* aFont,
       
   112                                  TRgb  aColor );
       
   113 
       
   114     	/**
       
   115     	* Enable or disable logical to visual reordering in text drawing.
       
   116         * By default, it is enabled. This has any effect only when bidirectional text
       
   117         * is rendered.
       
   118         *
       
   119         * If the text is converted to visual order prior to passing it to DrawText methods
       
   120         * of this class, then the conversion should be disabled by calling this method.
       
   121         *
       
   122     	* @since 3.1
       
   123     	* @param aUseConversion Enable or disable conversion.
       
   124     	*/
       
   125 	    IMPORT_C void UseLogicalToVisualConversion( TBool aUseConversion );
       
   126        
       
   127         /** 
       
   128         * Starts scrolling the text.
       
   129         *
       
   130         */
       
   131         IMPORT_C void Start();
       
   132 
       
   133         /** 
       
   134         * Stops scrolling the text.
       
   135         *
       
   136         */
       
   137         IMPORT_C void Stop();
       
   138 
       
   139         /** 
       
   140         * Resets the animation data.
       
   141         * 
       
   142         */
       
   143         IMPORT_C void Reset();
       
   144 	
       
   145 	    /** 
       
   146         * Is marquee on?
       
   147         *
       
   148         */
       
   149     #ifdef __WINS__
       
   150         IMPORT_C const TBool IsMarqueeOn();
       
   151     #else
       
   152     	IMPORT_C TBool IsMarqueeOn();
       
   153     #endif // __WINS__
       
   154         
       
   155         /** 
       
   156         * Sets the amount of pixels the text moves per animation loop
       
   157         *
       
   158         */
       
   159 	    IMPORT_C void SetSpeedInPixels(TInt aSpeed);
       
   160 	    
       
   161         /** 
       
   162         * Sets the delay between loops.
       
   163         *
       
   164         */
       
   165         IMPORT_C void SetDelay(TInt aDelay); 
       
   166         
       
   167         /** 
       
   168         * Sets the animation interval (=frames/second)
       
   169         *
       
   170         */
       
   171 	    IMPORT_C void SetInterval(TInt aInterval);
       
   172         
       
   173         /** 
       
   174         * Sets the maximum number of loops to be executed.
       
   175         *
       
   176         */
       
   177         IMPORT_C void SetLoops(TInt aLoops);    
       
   178         
       
   179         /** 
       
   180         * Enables / disables marquee feature but does NOT start it yet.
       
   181         * 
       
   182         */
       
   183         IMPORT_C void EnableMarquee(TBool aEnable); // ETrue = ON, EFalse = OFF
       
   184 
       
   185         /** 
       
   186         * Destructor
       
   187         *
       
   188         */
       
   189         virtual ~CAknMarqueeControl();
       
   190 
       
   191         // from CCoeControl
       
   192 
       
   193         /**
       
   194          * From @c CCoeControl
       
   195          *
       
   196          * Handles fade and unfade message for stops and starts scrolling the text.
       
   197          *
       
   198          * @param aType Type of resource change.
       
   199          */        
       
   200         void HandleResourceChange( TInt aType );
       
   201         
       
   202     protected:
       
   203 
       
   204     private:
       
   205     
       
   206     enum TMarqueeFlags
       
   207         {
       
   208         // Is marquee enabled or not
       
   209         EFlagIsOn,
       
   210         // RTL when the first directional character is LTR character
       
   211         EFlagIsWestern,
       
   212         // If true, there needs to be a delay before the scrolling starts
       
   213         EFlagIsBeginningOfLoop,
       
   214         // Is conversion needed
       
   215         EFlagUseVisualToLogicalConversion,
       
   216         // In case of two-lined lists etc, this flag is turned on
       
   217         // when the text has been scrolled all the way to the left/right.
       
   218         EFlagIsWaitingForCallBack
       
   219         };
       
   220         
       
   221         /** 
       
   222         * Default constructor
       
   223         *
       
   224         */
       
   225         CAknMarqueeControl(const TInt aLoops, const TInt aScrollAmount, const TInt aScrollDelay);
       
   226 
       
   227         /**
       
   228         * By default Symbian 2nd phase constructor is private.
       
   229         */
       
   230         void ConstructL();
       
   231 
       
   232 	    /**
       
   233         * advance text and issue a callback to parent
       
   234         */
       
   235         void DoScroll();
       
   236 
       
   237 	    /**
       
   238         * static callback for periodic timer
       
   239         */
       
   240         static TInt ScrollEvent(TAny * aPtr);
       
   241 
       
   242         /**
       
   243         * From CCoeControl
       
   244         */
       
   245         void Draw(const TRect& aRect) const;
       
   246 
       
   247     private: // Functions from MCoeForegroundObserver
       
   248 
       
   249 	    /**
       
   250 	    * Handles the application coming to the foreground.
       
   251 	    */
       
   252 	    void HandleGainingForeground();
       
   253 
       
   254 	    /**
       
   255 	    * Handles the application going into the background.
       
   256 	    */
       
   257 	    void HandleLosingForeground();
       
   258 	
       
   259     private:    // Data
       
   260     
       
   261 	    CPeriodic* iPeriodicTimer;        // creates scrolling events
       
   262 	    TInt       iDelta;                // The difference between the old and new position in pixels
       
   263 	    TInt       iDelay;                // Delay between loops in microseconds
       
   264 	    TInt       iSpeed;                // Amount of pixels the text moves in a frame
       
   265 	    TInt       iInterval;             // The interval between frame updates (= "frames/second")
       
   266         TCallBack  iCallBack;             // Callback to parent
       
   267         TInt       iLoops;                // Amount of loops executed
       
   268         TInt       iMaxLoops;             // Amount of loops *to be executed*
       
   269         TBitFlags  iFlags;
       
   270         TBool      iLastCharacter;        // It is ETrue if last character has appeared, otherwise.
       
   271     };
       
   272 
       
   273 #endif // AKNMARQUEECONTROL_H