uifw/AvKon/inc/AknTitlePaneLabel.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Title pane's label.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_AKNTITLEPANELABEL_H
       
    20 #define C_AKNTITLEPANELABEL_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <eiklabel.h>
       
    24 #include <AknUtils.h>
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class TAknLayoutText;
       
    28 
       
    29 // CLASS DECLARATION
       
    30 
       
    31 /**
       
    32  * This class is the text label which is used in title pane to display
       
    33  * texts.
       
    34  *
       
    35  * @lib avkon.lib
       
    36  */
       
    37 NONSHARABLE_CLASS( CAknTitlePaneLabel ) : public CEikLabel,
       
    38                                           public MCoeForegroundObserver
       
    39     {
       
    40 public:
       
    41 
       
    42    /** 
       
    43     * Supported effects:
       
    44     *
       
    45     * EEffectNone: No effect is applied, drawing is done as in CEikLabel::Draw()
       
    46     *
       
    47     * EEffectFadeToLeft: Text is faded to left using alpha blending.
       
    48     *
       
    49     * EEffectFadeToRight: Text is faded to right using alpha blending.
       
    50     *
       
    51     * EEffectDefaultScroll: Default scrolling effect. Text is scrolled in the
       
    52     *                       text window and when end or beginning of the text
       
    53     *                       is visible the scrolling direction is reversed. 
       
    54     *
       
    55     * EEffectDefaultScrollWithFade: Same as EEffectDefaultScroll but text is
       
    56     *                               faded from the scrolling area start and end.
       
    57     *
       
    58     * EEffectLoopScroll: Loop scrolling effect. Text is scrolled in the
       
    59     *                    text window and when whole text has been scrolled
       
    60     *                    it starts again from the other side.
       
    61     *
       
    62     * EEffectLoopScrollWithFade: Same as EEffectLoopScroll but text is faded
       
    63     *                            from the scrolling area start and end.
       
    64     *
       
    65     * EEffectFadeOut: Text is transformed gradually from opaque to transparent.
       
    66     * 
       
    67     * EEffectFadeIn: Text is transformed gradually from transparent to opaque.
       
    68     *
       
    69     * EEffectScrollOnceWithFade: Text is scrolled once and during scrolling
       
    70     *                            text is faded a bit from both ends.
       
    71     *
       
    72     * EEffectPause: Does nothing but waits.
       
    73     *
       
    74     * EEffectToggleScrolledTextTruncation: Toggles wheter text is drawn
       
    75     *                                      as truncated or not.
       
    76     *
       
    77     */
       
    78     enum TAknTitlePaneLabelEffect
       
    79         {
       
    80         EEffectNone = 0,
       
    81         EEffectFadeToLeft,
       
    82         EEffectFadeToRight,
       
    83         EEffectDefaultScroll,
       
    84         EEffectDefaultScrollWithFade,        
       
    85         EEffectLoopScroll,
       
    86         EEffectLoopScrollWithFade,        
       
    87         EEffectFadeOut,
       
    88         EEffectFadeIn,
       
    89         EEffectScrollOnceWithFade,
       
    90         EEffectPause,
       
    91         EEffectToggleScrolledTextTruncation
       
    92         };
       
    93     
       
    94    /** 
       
    95     * Struct for holding effect related data.
       
    96     */
       
    97     struct SAknTitleLableEffect
       
    98         {
       
    99         SAknTitleLableEffect() : iEffect( 0 ),
       
   100                                  iEffectDuration( 0 ), 
       
   101                                  iEffectRect( 0, 0, 0, 0 ),
       
   102                                  iLabelRect( 0, 0, 0, 0 ),
       
   103                                  iTitleText( NULL ),
       
   104                                  iObserver( NULL )
       
   105                                  {};
       
   106                                  
       
   107         TInt                iEffect;
       
   108         TInt                iEffectDuration;   
       
   109         TRect               iEffectRect;
       
   110         TRect               iLabelRect;
       
   111         TAknLayoutText      iTextLayout;
       
   112         TAknTextLineLayout  iTextLayoutLine;
       
   113         HBufC*              iTitleText; // not owned
       
   114         CCoeControl*        iObserver;  // not owned
       
   115         };
       
   116     
       
   117     
       
   118     /** 
       
   119      * Constructor
       
   120      */
       
   121     CAknTitlePaneLabel();
       
   122 
       
   123     /** 
       
   124      * Destructor
       
   125      */
       
   126     ~CAknTitlePaneLabel();
       
   127 
       
   128     /** 
       
   129      * Sets given effect active.
       
   130      *
       
   131      * @param  aEffect          The effect to be activated
       
   132      *                          (@see TAknTitlePaneLabelEffect).
       
   133      * @param  aEffectRect      The rect where effect is to be activated.
       
   134      * @param  aEffectDuration  Duration of the effect.
       
   135      * @param  aTextLayout      TextLayout for title text.
       
   136      * @param  aTextLayoutLine  LayoutLine for title text.
       
   137      * @param  aTitleText       The text.
       
   138      */
       
   139     void SetTextEffect( TInt aEffect,
       
   140                         TRect aEffectRect,
       
   141                         TInt aEffectDuration,
       
   142                         TRect aLabelRect,
       
   143                         TAknLayoutText aTextLayout,
       
   144                         TAknTextLineLayout aTextLayoutLine,
       
   145                         HBufC* aTitleText,
       
   146                         CCoeControl* aObserver = NULL );
       
   147 
       
   148     /** 
       
   149      * Returns currently active text effect id.
       
   150      * @return Currently active text effect id.
       
   151      */
       
   152     TInt TextEffect();
       
   153 
       
   154     /** 
       
   155      * Returns title text as bitmap if available. Otherwise NULL.
       
   156      * @return  Title text drawn to a bitmap.
       
   157      *          Ownership of bitmap is not transferred.
       
   158      */
       
   159 	CFbsBitmap* TextAsBitmap();
       
   160 	
       
   161     /** 
       
   162      * Returns title text as mask bitmap if available. Otherwise NULL.
       
   163      * @return  Title text drawn to a bitmap.
       
   164      *          Ownership of bitmap is not transferred.
       
   165      */
       
   166 	CFbsBitmap* TextAsMask();
       
   167 
       
   168     /** 
       
   169      * Returns currently active text length in pixels.
       
   170      * @return Text lenght in pixels
       
   171      */
       
   172     TInt TextLength();
       
   173 	
       
   174     /** 
       
   175      * Initializes and clears effect queue.
       
   176      */
       
   177 	void InitEffectQueueL();
       
   178 
       
   179     /** 
       
   180      * Adds given effect to queue.
       
   181      *
       
   182      * @param  aEffect  The effect to be added.
       
   183      */
       
   184 	void AddToEffectQueueL( SAknTitleLableEffect aEffect );
       
   185 	
       
   186     /** 
       
   187      * Activates effect queue. All effects from queue are executed.
       
   188      */
       
   189 	void ActivateEffectQueue();
       
   190 
       
   191 protected: // from @c CEikLabel
       
   192 	
       
   193     /** 
       
   194      * Actually draws the text to screen.
       
   195      */
       
   196     void Draw( const TRect& aRect ) const;
       
   197     
       
   198     /**
       
   199 	 * Handles a change to the control's resources of type aType
       
   200 	 * which are shared across the environment, e.g. color scheme change.
       
   201 	 *
       
   202 	 * @param  aType  Event type.
       
   203 	 */
       
   204     void HandleResourceChange( TInt aType );
       
   205     
       
   206 public:
       
   207     
       
   208     /** 
       
   209      * Enables Japanese pictograph support.
       
   210      *
       
   211      * @param  aInterface  Interface to be used in drawing the pictographs,
       
   212      *                     ownership is not transferred.
       
   213      */
       
   214     void SetPictographInterface( CAknPictographInterface& aInterface );
       
   215 
       
   216     /** 
       
   217      * Marks given text as invalid. It is no more used for drawing text.
       
   218      */
       
   219     void InvalidateText();
       
   220 
       
   221     /** 
       
   222      * Tells whether effect queue is empty.
       
   223      *
       
   224      * @return  @c ETrue if queue is empty, @c EFalse otherwise.
       
   225      */
       
   226 	TBool EffectQueueIsEmpty();
       
   227 
       
   228     /** 
       
   229      * Replaces control characters in the title text 
       
   230      * with a space (0x20) character.
       
   231      *
       
   232      * @param[in,out] aText     Text which control characters are
       
   233      *                          to be replaced.
       
   234      *
       
   235      * @param aReplaceLinefeeds Determine if linefeeds (0x0A) and and paragraph
       
   236      *                          separatoirs (0x2029) are also converted just
       
   237      *                          like other control characters.
       
   238      *        
       
   239      */
       
   240 	void ReplaceControlCharacters( HBufC* aText, TBool aReplaceLinefeeds );
       
   241 
       
   242 private: // from @c MCoeForegroundObserver
       
   243 
       
   244     /** 
       
   245      * Activates timer if needed.
       
   246      */
       
   247     void HandleGainingForeground();
       
   248 
       
   249     /** 
       
   250      * Cancels timer if active.
       
   251      */
       
   252     void HandleLosingForeground();
       
   253 
       
   254 private:
       
   255 
       
   256     /** 
       
   257      * Initializes effect, creates needed bitmap contextes etc.
       
   258      */
       
   259     void InitEffectL();
       
   260 
       
   261     /** 
       
   262      * Initializes timer for e.g. scrolling effect
       
   263      *
       
   264      * @param  aDelay    Initial delay before the first timer event
       
   265      *                   in microseconds.
       
   266      * @param  aInterval Interval between the consequent events
       
   267      *                   in microseconds.
       
   268      */
       
   269     void InitTimerL( TInt aDelay, TInt aInterval );
       
   270 
       
   271     /** 
       
   272      * Cancels timer for e.g. scrolling effect
       
   273      */
       
   274     void CancelTimer();
       
   275 
       
   276     /** 
       
   277      * Clears and initalizes bitmaps that are used for drawing the text.
       
   278      */
       
   279     void InitBitmaps() const;
       
   280    
       
   281     /**
       
   282      * Draws the text without the truncation character (@c KEllipsis).
       
   283      * This is used with long texts that are scrolled, so that the
       
   284      * text is not truncated before the scrolling starts, but is
       
   285      * afterwards.
       
   286      * This function calls @c CEikLabel::Draw().
       
   287      *
       
   288      * @param  aRect  Passed to @c CEikLabel::Draw().
       
   289      */
       
   290     void DrawWithoutTruncationL( const TRect& aRect );
       
   291     
       
   292     /** 
       
   293      * Main function for drawing with effects. This method selects the proper
       
   294      * subroutine based on active effect. This function is intended to be used
       
   295      * instead of @c CEikLabel::Draw() functionality.
       
   296      *
       
   297      * If no effect is currently specified, this will call @c CEikLabel::Draw().
       
   298      *
       
   299      * @param  aRect  Passed to @c CEikLabel::Draw() if no effect is
       
   300      *                active.
       
   301      */
       
   302     void DrawWithEffect( const TRect& aRect ) const;	
       
   303 	
       
   304     /** 
       
   305      * Draws the text into bitmap context using selected effect.
       
   306      */
       
   307 	void DrawTextWithEffect() const;
       
   308 
       
   309     /** 
       
   310      * Draws the text into bitmap context using fade effect. Text is
       
   311      * faded by using alphablending.
       
   312      */
       
   313 	void DrawTextWithFadeEffect() const;
       
   314 
       
   315     /** 
       
   316      * Draws the text into bitmap context using scroll effect. Text is
       
   317      * scrolled one pixels every time timer expires.
       
   318      */
       
   319 	void DrawTextWithScrollEffect() const;
       
   320 
       
   321     /** 
       
   322      * Draws the text into bitmap context using scroll effect. Text is
       
   323      * scrolled one pixels every time timer expires. Additionally text is
       
   324      * faded from both sides to give scrolling a smoother look.
       
   325      */
       
   326 	void DrawTextWithScrollAndFadeEffect() const;
       
   327 
       
   328     /** 
       
   329      * Static funtion which is called when timer expires.
       
   330      */
       
   331     static TInt EffectEvent( TAny* aPtr );
       
   332 
       
   333     /** 
       
   334      * Funtion which is called when timer expires.
       
   335      */
       
   336     void DoEffectEvent();
       
   337 
       
   338     /** 
       
   339      * Funtions which manipulate text when timer event happens.
       
   340      */
       
   341     TBool DoDefaultScrollEffectEvent();
       
   342     TBool DoLoopScrollEffectEvent();
       
   343     TBool DoScrollOnceEffectEvent();
       
   344     TBool DoFadeInEffectEvent();
       
   345     TBool DoFadeOutEffectEvent();
       
   346     TBool DoPauseEffectEvent();
       
   347     TBool DoToggleScrolledTextTruncationEffectEvent();
       
   348     	
       
   349     /** 
       
   350      * Test wheter text fits to screen at once.
       
   351      *
       
   352      * @return  @c ETrue  if truncation is needed,
       
   353      *          @c EFalse otherwise.
       
   354      */
       
   355 	TBool TextNeedsTruncation() const;	    
       
   356 
       
   357     /** 
       
   358      * Test wheter selected effect requires timed events.
       
   359      *
       
   360      * @param  aEffect  Effect to be checked
       
   361      *                  (@see TAknTitlePaneLabelEffect).
       
   362      *
       
   363      * @return @c ETrue  if timed events are needed,
       
   364      *         @c EFalse otherwise.
       
   365      */
       
   366 	TBool EffectEventsNeeded( TInt aEffect ) const;	    
       
   367 
       
   368     /** 
       
   369      * Test wheter selected effect requires bitmap devices.
       
   370      *
       
   371      * @param  aEffect  Effect to be checked
       
   372      *                  (@see TAknTitlePaneLabelEffect).
       
   373      *
       
   374      * @return @c ETrue  if bitmap devices are needed,
       
   375      *         @c EFalse otherwise.
       
   376      */
       
   377 	TBool EffectBitmapsNeeded( TInt aEffect ) const;	    
       
   378 
       
   379     /** 
       
   380      * Calculates suitable step for scrolling text.
       
   381      *
       
   382      * @return  Step size in pixels
       
   383      */
       
   384     TInt ScrollStepInPixels() const;
       
   385     
       
   386     /** 
       
   387      * Sets next effect from queue active.
       
   388      */
       
   389     void NextEffect();
       
   390 
       
   391     /** 
       
   392      * Creates scrolling text from given text.
       
   393      *
       
   394      * @param[in] aOriginalText The text from which the scrolling text
       
   395      *                          will be created from
       
   396      */
       
   397     void CreateScrollingTextL( const HBufC* aOriginalText );
       
   398 
       
   399 
       
   400 private: // Member variables
       
   401     
       
   402     /** Currently active effect */
       
   403     TInt  iEffect;
       
   404     
       
   405     /** Previously active effect */
       
   406     TInt  iPreviousEffect;
       
   407     
       
   408     /** Area where currently active effect is applied */
       
   409     TRect iEffectRect;
       
   410     
       
   411     /** Area where scrolling is applied */
       
   412     TRect iScrollRect;
       
   413     
       
   414     /** Size of this control when effect was last time set active */
       
   415     TSize iEffectLabelSize;
       
   416     
       
   417     /** Timer for effects that require changes often (scroll) */
       
   418     CPeriodic* iEffectTimer;
       
   419     
       
   420     /** Duration of the effects */
       
   421     TInt  iEffectDuration;
       
   422 	
       
   423 	/** Current position of scrolling text */
       
   424 	TInt  iScrollPosition;
       
   425 	
       
   426 	/** Interval for scrolling text updates */
       
   427 	TInt  iScrollInterval;
       
   428 	
       
   429 	/** Amount of pixels scrolling text is shifed each time that timer expires */
       
   430 	TInt  iScrollStep;
       
   431 	
       
   432 	/** Determines the scrolling direction of the text */
       
   433 	TBool  iScrollDirectionBackwards;     
       
   434     
       
   435     /** Alpha value for fade out text */
       
   436     TInt  iFadeInOutValue;
       
   437     
       
   438     /** Alpha value for fade in text */
       
   439     TInt  iFadeInOutStep;
       
   440     
       
   441     /** Phase where operator name effect is at the moment */
       
   442     TInt  iOperatorNamePhase;
       
   443     
       
   444     /** Title text, not owned */
       
   445 	HBufC* iTitleText;
       
   446 	
       
   447 	/** Scrolled text without truncations but always in visual order, owned */
       
   448 	HBufC* iScrollingText;
       
   449     
       
   450     /** Title text layout */
       
   451     TAknLayoutText iTextLayout;
       
   452     
       
   453     /** Title text layoutline */
       
   454     TAknTextLineLayout iTextLayoutLine;
       
   455     
       
   456     /** Calculated length of the text in pixels */
       
   457 	TInt  iTextLength;
       
   458     
       
   459     /** Bitmap where text with effect is draw into */
       
   460     CFbsBitmap* iBitmap;
       
   461     
       
   462     /** Bitmap device where text with effect is draw into */
       
   463     CFbsBitmapDevice* iBitmapDevice;
       
   464     
       
   465     /** Bitmap context where text with effect is draw into */
       
   466     CFbsBitGc* iBitmapGc;
       
   467     
       
   468     /** Mask where texts mask with effect is draw into */
       
   469     CFbsBitmap* iMask;
       
   470     
       
   471     /** Mask device where texts mask with effect is draw into */
       
   472     CFbsBitmapDevice* iMaskDevice;
       
   473     
       
   474     /** Mask context where texts mask with effect is draw into */
       
   475     CFbsBitGc* iMaskGc;
       
   476     
       
   477     /**
       
   478      * Not owned. Observer, whose DrawNow() -method gets called if effect
       
   479      * has changed text outlook.
       
   480      */
       
   481     CCoeControl* iObserver;
       
   482 
       
   483     /** Queue which can store multiple effects. */
       
   484    	CArrayFixFlat<SAknTitleLableEffect>* iEffectQueue;
       
   485    	
       
   486    	/** Number of the next effect to be executed from effect queue */
       
   487    	TInt  iNextEffectInEffectQueue;
       
   488     
       
   489     /** The pictograph interface used to draw Japanese pictographs, not owned */
       
   490     CAknPictographInterface* iPictographInterface;
       
   491     
       
   492     /** Whether or not the current language is LTR (ETrue) or RTL (EFalse) */
       
   493     TBool  iWesternText;
       
   494     };
       
   495 
       
   496 #endif // C_AKNTITLEPANELABEL_H