messagingappbase/msgeditor/mediacontrolinc/MsgImageControl.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005-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 *       MsgEditor Image media control - a Message Editor Base control
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef MSGIMAGECONTROL_H
       
    22 #define MSGIMAGECONTROL_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <msgmediacontrol.h>
       
    26 #include <MIHLViewerObserver.h>
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // MACROS
       
    31 
       
    32 // DATA TYPES
       
    33 
       
    34 // FUNCTION PROTOTYPES
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 class CMsgEditorView;
       
    38 class MIHLFileImage;
       
    39 class MIHLBitmap;
       
    40 class MIHLImageViewer;
       
    41 class TAknsItemID;
       
    42 class CMsgBitmapControl;
       
    43 
       
    44 // CLASS DECLARATION
       
    45 
       
    46 // ==========================================================
       
    47 
       
    48 /**
       
    49 * Message Editor Base control for handling images
       
    50 */
       
    51 class CMsgImageControl : public CMsgMediaControl,
       
    52                          public MIHLViewerObserver,
       
    53                          public MCoeControlHitTest
       
    54     {
       
    55 
       
    56     public:  // Constructor and destructor
       
    57 
       
    58         /**
       
    59         * Two-phased constructor.
       
    60         * @param aObserver Control state observer.
       
    61         * @param aParent   Parent control.
       
    62         *
       
    63         * @return new object
       
    64         */
       
    65         IMPORT_C static CMsgImageControl* NewL( CMsgEditorView& aParent, 
       
    66                                                 MMsgAsyncControlObserver* aObserver );
       
    67 
       
    68         /**
       
    69         * Destructor.
       
    70         */
       
    71         virtual ~CMsgImageControl();
       
    72 
       
    73     public:
       
    74         
       
    75         /**
       
    76         * From MMsgAsyncControl
       
    77         *
       
    78         * Load media to from given file handle to media control.
       
    79         */
       
    80         void LoadL( RFile& aFileHandle );
       
    81         
       
    82         /**
       
    83         * From MMsgAsyncControl
       
    84         *
       
    85         * Cancels the asyncronous operation if it is pending.
       
    86         */         
       
    87         void Cancel();
       
    88         
       
    89         /**
       
    90         * From MMsgAsyncControl
       
    91         *
       
    92         * Closes control. Closing means freeing file
       
    93         * specific resources that other application can use the file.
       
    94         */         
       
    95         void Close();
       
    96         
       
    97         /**
       
    98         * From CMsgMediaControl    
       
    99         *
       
   100         * Shows the image in the viewer
       
   101         */
       
   102         void PlayL();
       
   103         
       
   104         /**
       
   105         * From CMsgMediaControl    
       
   106         *
       
   107         * Pauses playing media including animations. 
       
   108         */         
       
   109         void PauseL();
       
   110         
       
   111         /**
       
   112         * From CMsgMediaControl    
       
   113         *
       
   114         * Stops playing media including animations. 
       
   115         */         
       
   116         void Stop();
       
   117         
       
   118         /**
       
   119         * Return ETrue if loaded image is animation.
       
   120         */
       
   121         IMPORT_C TBool IsAnimation() const;
       
   122         
       
   123         /**
       
   124         * Sets how many time animation should loop.
       
   125         * 
       
   126         * @param aCount Animation loop count (-1 == indefinite).
       
   127         */
       
   128         IMPORT_C void SetAnimationLoopCount( TInt aCount );
       
   129         
       
   130         /**
       
   131         *
       
   132         */
       
   133         IMPORT_C void SetImageFileClosed( );
       
   134         
       
   135         /**
       
   136         * Loads the image into display.
       
   137         * @param aImageFile image file name - expected to be valid image
       
   138         * @param aMaxHeight maximum height of the displayed image - default is
       
   139         *                   0 = {max display size or max thumbnail size}.
       
   140         */
       
   141         inline void SetMaxHeight( TInt aMaxHeight );
       
   142 
       
   143         /**
       
   144         * Loads the image into display.
       
   145         * @param aImageFile image file name - expected to be valid image
       
   146         * @param aMaxSize maximum height and width of the displayed image
       
   147         */
       
   148         inline void SetMaxSize( TSize aMaxSize );
       
   149         
       
   150         /**
       
   151         * returns the framesize
       
   152         */
       
   153         IMPORT_C TSize FrameSize();
       
   154         
       
   155     public: // from CMsgBaseControl
       
   156 
       
   157         /**
       
   158         * Calculates and sets the size of the control and returns new size as
       
   159         * reference aSize.
       
   160         * From CMsgBaseControl
       
   161         */
       
   162         void SetAndGetSizeL( TSize& aSize );
       
   163 
       
   164         /**
       
   165         * Resets (= clears) contents of the control.
       
   166         * From CMsgBaseControl
       
   167         */
       
   168         void Reset();
       
   169         
       
   170         /**
       
   171         * Handles control events from view.
       
   172         *
       
   173         * @param aEvent     IN      Event type
       
   174         * @param aParam     IN      Event related parameters.
       
   175         */
       
   176         void NotifyViewEvent( TMsgViewEvent aEvent, TInt aParam );
       
   177     
       
   178     public: // from CCoeControl
       
   179         
       
   180         /**
       
   181         * This is called when the focus of the control is changed.
       
   182         * @param aDrawNow
       
   183         */
       
   184         void FocusChanged( TDrawNow aDrawNow );
       
   185         
       
   186         /**
       
   187         * Called when size is changed.
       
   188         * From CCoeControl
       
   189         */
       
   190         void SizeChanged();
       
   191         
       
   192         /**
       
   193         * From CCoeControl,Draw.
       
   194         * @param aRect draw rect
       
   195         */
       
   196         void Draw(const TRect& aRect) const;
       
   197         
       
   198         /**
       
   199         * From CCoeControl. MakeVisible
       
   200         * @param aVisible
       
   201         */
       
   202         void MakeVisible( TBool aVisible );
       
   203         
       
   204         /**
       
   205         * From CCoeControl. PositionChanged
       
   206         * @param aVisible
       
   207         */
       
   208         void PositionChanged();
       
   209         
       
   210         /**
       
   211         * From CCoeControl. Handles resource change events.
       
   212         * @param aType
       
   213         */
       
   214         void HandleResourceChange( TInt aType );
       
   215         
       
   216     public: // From MIHLViewerObserver
       
   217         
       
   218 		/**
       
   219         * From MIHLViewerObserver Notifies client when viewer bitmap content is changed.
       
   220 		* Leave situation is handled in ViewerError() callback.
       
   221 		*
       
   222 		* @since 3.0
       
   223 		*
       
   224         * @return void
       
   225 		*/
       
   226 		void ViewerBitmapChangedL();
       
   227 
       
   228         /**
       
   229         * From MIHLViewerObserver Notifies client if error occurs in viewer.
       
   230         * 
       
   231         * @since 3.0
       
   232         *
       
   233         * @param aError     IN  System wide error code.
       
   234         *
       
   235         * @return void
       
   236 		*/
       
   237 		void ViewerError( TInt aError );
       
   238     
       
   239     public: // from MCoeControlHitTest
       
   240     
       
   241         /**
       
   242         * Evaluates whether control is "hit" by touch event.
       
   243         */
       
   244         TBool HitRegionContains( const TPoint& aPoint, const CCoeControl& aControl ) const;
       
   245         
       
   246     protected: // from CCoeControl
       
   247         
       
   248         /**
       
   249         * Return count of controls be included in this component
       
   250         * From CCoeControl
       
   251         */
       
   252         TInt CountComponentControls() const;
       
   253 
       
   254         /**
       
   255         * Return pointer to component in question.
       
   256         * From CCoeControl
       
   257         */
       
   258         CCoeControl* ComponentControl( TInt aIndex ) const;
       
   259         
       
   260     private:
       
   261         
       
   262         /**
       
   263         * Calculates correct centered image position.
       
   264         */
       
   265         TPoint CalculateImagePosition() const;
       
   266         
       
   267         /**
       
   268         * Calculates the size for the image control.
       
   269         * @param aProposedSize size given by the framework. Our size is either this or smaller.
       
   270         * @return new size for the control
       
   271         */
       
   272         TSize CalculateControlSize( const TSize& aProposedSize ) const;
       
   273         
       
   274         /**
       
   275         * Returns ETrue if control is off screen.
       
   276         */
       
   277         TBool IsOffScreen() const;
       
   278 
       
   279         /**
       
   280         * Original size of image/icon bitmap
       
   281         */
       
   282         TSize BitmapSize() const;
       
   283         
       
   284         /**
       
   285         * Performs icon loading steps.
       
   286         */
       
   287         void DoIconLoadingL( const TAknsItemID& aId,
       
   288                              const TDesC& aFileName,
       
   289                              const TInt aFileBitmapId,
       
   290                              const TInt aFileMaskId );
       
   291 
       
   292     private: // Constructors
       
   293 
       
   294         /**
       
   295         * C++ default constructor.
       
   296         */
       
   297         CMsgImageControl();
       
   298                           
       
   299         /**
       
   300         * constructor
       
   301         * @param aFlags - CMsgImageControl::TFlags
       
   302         * @param aBaseControlObserver - observer to notify about changes.
       
   303         */
       
   304         CMsgImageControl( MMsgBaseControlObserver& aBaseControlObserver );
       
   305                           
       
   306         /**
       
   307         * By default Symbian constructor is private.
       
   308         * @param aParent - parent control.
       
   309         */
       
   310         void ConstructL( CMsgEditorView& aParent,
       
   311                          MMsgAsyncControlObserver* aObserver );
       
   312 
       
   313         /**
       
   314         * Reopens every media. Restarts possible animation.
       
   315         * @param aMainContent is ignored 
       
   316         */
       
   317         void DoReloadL( TBool aMainContent = ETrue );
       
   318         
       
   319         /**
       
   320         * Performs play functionality.
       
   321         */
       
   322         void DoPlay( TInt aAnimationStartDelay ); 
       
   323         
       
   324         /**
       
   325         * Performs pause functionality.
       
   326         */
       
   327         void DoPause();
       
   328         
       
   329         /**
       
   330         * Calculates maximum size for image control.
       
   331         */
       
   332         void CalculateMaxSize(); 
       
   333         
       
   334         /**
       
   335         * Starts animation playback.
       
   336         */
       
   337         void StartAnimation( TInt aAnimationStartDelay );
       
   338         
       
   339         /**
       
   340         * Stops animation playback.
       
   341         */
       
   342         void StopAnimation();
       
   343         
       
   344         /**
       
   345         * Pauses animation playback.
       
   346         */
       
   347         void PauseAnimation();
       
   348         
       
   349         /**
       
   350         * Callback function to start animation loop
       
   351         */
       
   352         static TInt DoStartLoop( TAny* aObject );
       
   353         
       
   354         /**
       
   355         * Starts new animation loop
       
   356         */
       
   357         void StartLoop();
       
   358         
       
   359     private: //Data
       
   360 
       
   361         enum TAnimationState
       
   362             {
       
   363             EAnimationNotReady,
       
   364             EAnimationStopped,
       
   365             EAnimationPlaying,
       
   366             EAnimationPaused
       
   367             };
       
   368         
       
   369         // Source image
       
   370         MIHLFileImage*      iSourceImage;
       
   371         
       
   372         // Destination bitmap
       
   373         MIHLBitmap*         iDestinationBitmap;
       
   374 
       
   375         // Image viewer used as engine
       
   376         MIHLImageViewer*    iEngine;
       
   377                 
       
   378         // Maximum control size.
       
   379         TSize               iMaxSize;
       
   380 
       
   381         // Internal animation state.
       
   382         TAnimationState     iAnimationState;
       
   383         
       
   384         // Maximum loop count for animations.
       
   385         TInt                iLoopCount;
       
   386         
       
   387         // Current loop number.
       
   388         TInt                iCurrentLoop;
       
   389 
       
   390         // Control that contains the image bitmap.
       
   391         CMsgBitmapControl*  iBitmapControl;
       
   392         
       
   393         // Loop delay timer.
       
   394         CPeriodic*          iLoopTimer;
       
   395     };
       
   396     
       
   397 #include <msgimagecontrol.inl>
       
   398 
       
   399 #endif // MSGIMAGECONTROL_H