mobilemessaging/smilui/mediainc/SmilTextRenderer.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-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:  
       
    15 *       SMIL Player media renderer for displaying text files
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef SMILTEXTRENDERER_H
       
    22 #define SMILTEXTRENDERER_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include "SmilMediaRendererBase.h"
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <frmtlay.h>
       
    29 #include <AknPictographDrawerInterface.h>
       
    30 
       
    31 #include <eiksbfrm.h>
       
    32 
       
    33 #include <xhtmlparser.h> 
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class CRichText;
       
    37 class CSmilTransitionFilter;
       
    38 class CFbsBitmap;
       
    39 class CSmilTextRendererCustomDraw;
       
    40 class CAknPictographInterface;  //pictograph support
       
    41 class CGraphicsContext;
       
    42 
       
    43 // CLASS DECLARATION
       
    44 
       
    45 /**
       
    46 * SMIL Player media renderer for displaying text files
       
    47 *
       
    48 * @lib smilmediarenderer.lib
       
    49 * @since 2.0
       
    50 */
       
    51 NONSHARABLE_CLASS(CSmilTextRenderer) : public CSmilMediaRendererBase,
       
    52                                        public MEikScrollBarObserver,
       
    53                                        public MXhtmlParserObserver
       
    54     {
       
    55 
       
    56     public: // Constructors and destructor
       
    57         
       
    58         /**
       
    59         * Factory method that creates this object.
       
    60         *
       
    61         * @param    aFileHandle IN File handle to the media file
       
    62         * @param    aMedia      IN SMIL engine side object representing
       
    63         *                          this media file
       
    64         * @param    aDrmCommon  IN DRM Common
       
    65         * @param    aDrmHelper  IN DRM Helper
       
    66         * @param    aCharset    IN IANA character set MIB enumeration
       
    67         *                          of the media file
       
    68         * @param    aGc         IN graphics context
       
    69         *
       
    70         * @return   pointer to instance
       
    71         */
       
    72         static CSmilTextRenderer* NewL( RFile& aFileHandle,
       
    73                                         MSmilMedia* aMedia,
       
    74                                         DRMCommon& aDrmCommon,
       
    75                                         CDRMHelper& aDrmHelper,
       
    76                                         TUint aCharset,
       
    77                                         CGraphicsContext& aGc,
       
    78                                         TMsgMediaType aMediaType 
       
    79 										);
       
    80         /**
       
    81         * Destructor.
       
    82         */
       
    83         virtual ~CSmilTextRenderer();
       
    84 
       
    85     public: // Functions from base classes
       
    86     
       
    87         /**
       
    88         * From MSmilMediaRenderer Returns if renderer is visual 
       
    89         * (i.e. draws something to the screen).
       
    90         *
       
    91         * @since 2.0
       
    92         * 
       
    93         * @return Returns ETrue since the media type is visual.
       
    94         */
       
    95         TBool IsVisual() const;
       
    96         
       
    97         /**
       
    98         * From MSmilMediaRenderer Returns if renderer is scrollable.
       
    99         *
       
   100         * @since 2.0
       
   101         *
       
   102         * @return Returns ETrue if text is scrollable and EFalse if
       
   103         * it is not.
       
   104         */
       
   105         TBool IsScrollable() const;
       
   106 
       
   107         /**
       
   108         * From MSmilMediaRenderer Move scrollable media to given position.
       
   109         *
       
   110         * @since 2.0
       
   111         *
       
   112         * @param aDirX  IN  Amount of pixels to move on X direction.
       
   113         * @param aDirY  IN  Amount of pixels to move on Y direction.
       
   114         *
       
   115         * @return void
       
   116         */
       
   117         void Scroll( TInt aDirX, TInt aDirY );
       
   118         
       
   119         /**
       
   120         * From MSmilMediaRenderer Returns the unscalable size of the
       
   121         * visual media object.
       
   122         *
       
   123         * @since 2.0
       
   124         * 
       
   125         * @return Width in pixels.
       
   126         */
       
   127         TInt IntrinsicWidth() const;
       
   128 
       
   129         /**
       
   130         * From MSmilMediaRenderer Returns the unscalable size of the
       
   131         * visual media object.
       
   132         *
       
   133         * @since 2.0
       
   134         * 
       
   135         * @return Height in pixels.
       
   136         */
       
   137         TInt IntrinsicHeight() const;   
       
   138         
       
   139         /**
       
   140         * From MSmilMediaRenderer Called by the engine to seek the media
       
   141         * to given position in its local timeline.
       
   142         *
       
   143         * @since 2.0
       
   144         * 
       
   145         * @param aTime  IN  Seek position.
       
   146         *
       
   147         * @return void
       
   148         */
       
   149         void SeekMediaL( const TSmilTime& aTime );
       
   150         
       
   151         /**
       
   152         * From MSmilMediaRenderer Set volume of the audio media.
       
   153         *
       
   154         * @since 2.0
       
   155         *
       
   156         * @param aVolume    IN  A percentage value from maximum value that
       
   157         *                       the volume should be set.
       
   158         * @return void
       
   159         */
       
   160         
       
   161         /**
       
   162         * From MSmilMediaRenderer Called by the engine to signal that
       
   163         * the media is going to be played soon.
       
   164         *
       
   165         * @since 2.0
       
   166         *
       
   167         * @return void
       
   168         */
       
   169         void PrepareMediaL();       
       
   170         
       
   171         /**
       
   172         * From MSmilMediaRenderer Called by the engine to start media
       
   173         * playback and to make visual media visible.
       
   174         *
       
   175         * @since 2.0
       
   176         * 
       
   177         * @return void
       
   178         */
       
   179         void ShowMediaL();
       
   180         
       
   181         /**
       
   182         * From MSmilMediaRenderer Called by the engine to stop media
       
   183         * playback and remove visual media from the screen.
       
   184         *
       
   185         * @since 2.0
       
   186         *
       
   187         * @return void
       
   188         */
       
   189         void HideMedia();
       
   190         
       
   191         /**
       
   192         * From MSmilMediaRenderer Called by the engine to pause media playback.
       
   193         *
       
   194         * @since 2.0
       
   195         *
       
   196         * @return void
       
   197         */
       
   198         void FreezeMedia();
       
   199         
       
   200         /**
       
   201         * From MSmilMediaRenderer Called by the engine to continue paused
       
   202         * media playback.
       
   203         *
       
   204         * @since 2.0
       
   205         *
       
   206         * @return void
       
   207         */
       
   208         void ResumeMedia();
       
   209         
       
   210         /**
       
   211         * From MSmilMediaRenderer Called by the engine to make a media
       
   212         * renderer draw its content.
       
   213         *
       
   214         * @since 2.0
       
   215         *
       
   216         * @param aGc    IN      Graphical context performing the drawing.
       
   217         * @param aRect  IN      Target rectangle.
       
   218         * @param aTransitionFilter IN Transition effects if present.
       
   219         * @param aFocus IN      Focus indication if focussed.
       
   220         *
       
   221         * @return void
       
   222         */
       
   223         void Draw( CGraphicsContext& aGc,
       
   224                    const TRect& aRect,
       
   225                    CSmilTransitionFilter* aTransitionFilter,
       
   226                    const MSmilFocus* aFocus );
       
   227 
       
   228         /**
       
   229         * Return text of the renderer
       
   230         *
       
   231         * @since 2.0
       
   232         *
       
   233         * @return Pointer to plain text object
       
   234         */
       
   235         IMPORT_C CPlainText* GetText();
       
   236 
       
   237         /**
       
   238         * Redraw pictographarea in animation callback
       
   239         *
       
   240         * @since 2.0
       
   241         */
       
   242         void DrawPictoCallback() const;
       
   243         
       
   244         /**
       
   245         * from MEikScrollBarObserver
       
   246         *   Handles the scrollevents
       
   247         */
       
   248         void HandleScrollEventL( CEikScrollBar* aScrollBar, 
       
   249                         TEikScrollEvent aEventType );
       
   250                         
       
   251 
       
   252 
       
   253     private:
       
   254 
       
   255         /**
       
   256         * C++ default constructor.
       
   257         */
       
   258         CSmilTextRenderer();
       
   259         
       
   260         /**
       
   261         * Constructor.
       
   262         */
       
   263         CSmilTextRenderer( MSmilMedia* aMedia, 
       
   264                            DRMCommon& aDrmCommon,
       
   265                            CDRMHelper& aDrmHelper,
       
   266                            TUint aCharset,
       
   267                            TMsgMediaType aMediaType 
       
   268 						   );
       
   269         /**
       
   270         * 2nd phase constructor
       
   271         */
       
   272         void ConstructL( RFile& aFileHandle, CGraphicsContext& aGc ); 
       
   273 
       
   274         /**
       
   275         * Draws scroll bar
       
   276         */
       
   277         void DrawScrollBarL( CGraphicsContext& aGc,
       
   278                              const TRect& aRect ) ;
       
   279 
       
   280         /**
       
   281         * Draws transition
       
   282         */
       
   283         void DrawTransitionL( CGraphicsContext& aGc,
       
   284                               CSmilTransitionFilter* aTransitionFilter,
       
   285                               const TRect& aRect );
       
   286         
       
   287         /**
       
   288         * Creates text layout.
       
   289         */
       
   290         void CreateLayoutL();
       
   291 
       
   292         /**
       
   293         * Opens text file pointed by file handle.
       
   294         */
       
   295         void OpenTextL( RFile& aFileHandle );
       
   296 
       
   297         /**
       
   298         * Setup correct format for text
       
   299         */
       
   300         void FormatTextL( const CGraphicsContext& aGc );
       
   301 
       
   302         /**
       
   303         * Resolves text color.
       
   304         */
       
   305         TRgb ResolveTextColorL( TRgb aDefaultColor ) const;
       
   306         
       
   307         /**
       
   308         * Scrolls the text without changing manually the thumb
       
   309         *   position.
       
   310         */                        
       
   311         void ScrollWithOutThumbUpdate( TInt aDirY );
       
   312         
       
   313         /**
       
   314         * from MXhtmlParserObserver
       
   315         *   Handles the parse events
       
   316      	* Call back function used to inform a client of the Parser
       
   317 	    * when a parsing operation completes.
       
   318 	    *
       
   319 	    * @since S60 v3.2
       
   320 	    */
       
   321 		void ParseCompleteL();
       
   322 		
       
   323 		/**
       
   324         * from MXhtmlParserObserver
       
   325         *   Handles the parse events
       
   326      	* Call back function used to inform a client of the Parser
       
   327 	    * about error.
       
   328 	    *
       
   329 	    * @since S60 v3.2
       
   330 	    */
       
   331 		void ParseError( TInt aError );
       
   332     private: // data
       
   333         
       
   334         // Character set
       
   335         TUint iCharset;
       
   336 
       
   337         // Rich text object
       
   338         CRichText* iRichText;
       
   339         
       
   340         // Paragraph formatter
       
   341         CParaFormatLayer* iParaFormatLayer;
       
   342         
       
   343         // Character formatter
       
   344         CCharFormatLayer* iCharFormatLayer;
       
   345         
       
   346         // Text layout
       
   347         CTextLayout* iLayout;
       
   348         
       
   349         // Text draw context
       
   350         TDrawTextLayoutContext iDrawContext;
       
   351         
       
   352         // Specifies whether text renderer is visible
       
   353         TBool iShowing;
       
   354         
       
   355         // Specifies whether scroll bar is enabled
       
   356         TBool iScrollBar;
       
   357         
       
   358         // Text Y position
       
   359         TInt iYPos;
       
   360         
       
   361         // Custom text drawer
       
   362         CSmilTextRendererCustomDraw* iCustomDraw;
       
   363         
       
   364         // Buffer bitmap
       
   365         CFbsBitmap* iBufferBitmap;
       
   366         
       
   367         // Buffer bitmap device
       
   368         CFbsBitmapDevice* iBufferDevice;
       
   369         
       
   370         // Mask bitmap
       
   371         CFbsBitmap* iMaskBitmap;
       
   372         
       
   373         // Mask bitmap device
       
   374         CFbsBitmapDevice* iMaskDevice;
       
   375 
       
   376         // Line length
       
   377         TInt iLineHeight;
       
   378 
       
   379 #ifdef RD_MSG_XHTML_SUPPORT
       
   380 		// XHTML parser
       
   381 		CXhtmlParser* iXhtmlParser;
       
   382 #endif
       
   383 				
       
   384 		// Parser error
       
   385 		TInt iError;
       
   386 		        
       
   387 #ifdef RD_SCALABLE_UI_V2        
       
   388         // Scrollbar frame
       
   389         CEikScrollBarFrame* iSBFrame;
       
   390         
       
   391         //does the scrollbar need to be initialised and drawn
       
   392         TBool iNotYetDrawn;
       
   393         
       
   394         //save the thumb position if replay is needed
       
   395         TInt iThumbPos;
       
   396         
       
   397         //from scrollbar, member because maxvalue of scrollbar 
       
   398         // is uninitialised and anyhow this is more efficient
       
   399         TInt iScrollSpan;
       
   400 #endif // RD_SCALABLE_UI_V2       
       
   401         };
       
   402 
       
   403 /**
       
   404 *  Implementation of MFormCustomDraw
       
   405 *       Class is used to draw transparent background
       
   406 *       by empty implementation of DrawBackground(...)
       
   407 *       In addition class is used to get mask by using iWhite -member.
       
   408 *
       
   409 * @lib smilmediarenderer.lib
       
   410 * @since 2.0
       
   411 */
       
   412 NONSHARABLE_CLASS(CSmilTextRendererCustomDraw): public CBase,
       
   413                                     public MFormCustomDraw,
       
   414                                     public MAknPictographAnimatorCallBack
       
   415     {
       
   416 
       
   417     public:
       
   418 
       
   419         /**
       
   420         * Static constructor.
       
   421         *
       
   422         * @param    aParent IN Parent text renderer
       
   423         * @param    aGc     IN Graphic context.
       
   424         *
       
   425         * @return   pointer to instance
       
   426         */
       
   427         static CSmilTextRendererCustomDraw* NewL( const CSmilTextRenderer& aParent,
       
   428                                                   CGraphicsContext& aGc );
       
   429 
       
   430         /**
       
   431         * Destructor
       
   432         */
       
   433         ~CSmilTextRendererCustomDraw();
       
   434 
       
   435         /**
       
   436         * SetWhite
       
   437         *
       
   438         * @since 2.0
       
   439         * 
       
   440         * @param aWhite IN Specifies whether white is enabled.
       
   441         */
       
   442         void SetWhite( TBool aWhite );
       
   443 
       
   444     public: // Functions from base classes
       
   445         
       
   446         /**
       
   447         * From MFormCustomDraw
       
   448         * See frmtlay.h for more information.
       
   449         */
       
   450         void DrawBackground( const TParam& aParam,
       
   451                              const TRgb& aRgb,
       
   452                              TRect& aDrawn ) const;
       
   453 
       
   454         /**
       
   455         * From MFormCustomDraw
       
   456         * See frmtlay.h for more information.
       
   457         */
       
   458         void DrawText( const TParam& aParam,
       
   459                        const TLineInfo& aLineInfo,
       
   460                        const TCharFormat& aFormat,
       
   461                        const TDesC& aText,
       
   462                        const TPoint& aTextOrigin,
       
   463                        TInt aExtraPixels ) const;
       
   464 
       
   465         /**
       
   466         * From MAknPictographAnimatorCallBack
       
   467         * See AknPictographDrawerInterface.h for more information.
       
   468         */
       
   469         void DrawPictographArea();
       
   470 
       
   471     private:
       
   472 
       
   473         /**
       
   474         * C++ contructor
       
   475         */
       
   476         CSmilTextRendererCustomDraw( const CSmilTextRenderer& aParent,
       
   477                                      CGraphicsContext& aGc );
       
   478                                      
       
   479         /**
       
   480         * 2nd phase constructor
       
   481         */
       
   482         void ConstructL();
       
   483 
       
   484     private: // data
       
   485 
       
   486         TBool iWhite;
       
   487         const CSmilTextRenderer& iParent;
       
   488         CAknPictographInterface* iPictographDrawer;
       
   489         CGraphicsContext& iGc; 
       
   490 
       
   491         };
       
   492 
       
   493 #endif // SMILTEXTRENDERER_H