uifw/EikStd/coctlsrc/smileybmpobserver.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 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:  smiely engine class
       
    15 *
       
    16 */
       
    17 
       
    18 #include <fbs.h>
       
    19 #include <AknIconUtils.h>
       
    20 #include <coeutils.h>
       
    21 #include <eikedwin.h>
       
    22 #include "smileybmpobserver.h"
       
    23 #include "smileydrawer.h"
       
    24 #include "smileyimagedata.h"
       
    25 #include "smileyiconrecord.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 // ---------------------------------------------------------------------------
       
    29 // CSmileyImageData::CSmileyImageData
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CSmileyBmpObserver::CSmileyBmpObserver( CSmileyAsyncDraw& aAsyncDraw ) : 
       
    33     iAsyncDraw( aAsyncDraw )
       
    34     {
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CSmileyBmpObserver::~CSmileyBmpObserver
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CSmileyBmpObserver::~CSmileyBmpObserver()
       
    42     {
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CSmileyBmpObserver::SetImageData
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CSmileyBmpObserver::SetImageData( CSmileyImageData* aImage )
       
    50     {
       
    51     iImage = aImage;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CSmileyBmpObserver::BitmapChanged
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 void CSmileyBmpObserver::BitmapChanged( CFbsBitmap* /*aBitmap*/ )
       
    59     {
       
    60     if ( iImage )
       
    61         {
       
    62         if ( !iIsRegisted )
       
    63             {
       
    64             iAsyncDraw.SmileyDrawer().RegisterAnimChecker( this );
       
    65             iIsRegisted = EFalse;
       
    66             }
       
    67         iIsAnimProgress = ETrue;
       
    68         iAsyncDraw.RequestAsyncDraw();
       
    69         }
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CSmileyBmpObserver::ReplayAnimationL
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CSmileyBmpObserver::ReplayAnimationL()
       
    77     { 
       
    78     if ( iImage )
       
    79         {
       
    80         iAsyncDraw.SmileyDrawer().CreateImageL( iImage );
       
    81         }
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CSmileyBmpObserver::StopAnimation
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CSmileyBmpObserver::StopAnimation()
       
    89     {
       
    90     if ( iImage )
       
    91         {
       
    92         iImage->DeleteImage();
       
    93         iAsyncDraw.SmileyDrawer().RemoveAnimChecker( this );
       
    94         }
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CSmileyBmpObserver::IsOnProgress
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TBool CSmileyBmpObserver::IsOnProgress() const
       
   102     {
       
   103     return iIsAnimProgress;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CSmileyBmpObserver::IsOnProgress
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CSmileyBmpObserver::ResetStatus()
       
   111     {
       
   112     iIsAnimProgress = EFalse;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CSmileyBmpObserver::IsOnProgress
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CSmileyBmpObserver::DoOnAnimStoppedL()
       
   120     {
       
   121     TBool replay( EFalse );   
       
   122     for ( TInt i( 0 ); i < iImage->RefArrayCount(); i++ )
       
   123         {
       
   124         CSmileyIcon* icon( iImage->RefIcon( i ) ); 
       
   125         icon->IncreasePlayCount();
       
   126         replay = ( replay || !icon->IsPlayFinished() );
       
   127         }
       
   128     if ( replay )
       
   129         {
       
   130         iAsyncDraw.AddReplayImage( iImage );
       
   131         }
       
   132     else
       
   133         {
       
   134         StopAnimation();
       
   135         }
       
   136     iAsyncDraw.RequestAsyncDraw( ETrue );
       
   137     }
       
   138 
       
   139 // ======== MEMBER FUNCTIONS ========
       
   140 // ---------------------------------------------------------------------------
       
   141 // CSmileyAsyncDraw::CSmileyAsyncDraw
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 CSmileyAsyncDraw::CSmileyAsyncDraw( CSmileyDrawer& aDrawer ) : 
       
   145     CActive( EPriorityStandard ), iDrawer( aDrawer )
       
   146     {
       
   147     CActiveScheduler::Add( this );
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CSmileyAsyncDraw::~CSmileyAsyncDraw
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 CSmileyAsyncDraw::~CSmileyAsyncDraw()
       
   155     {
       
   156     Cancel();
       
   157     iReplayImageArray.Reset();
       
   158     iReplayImageArray.Close();
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CSmileyAsyncDraw::StartActive
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CSmileyAsyncDraw::RequestAsyncDraw( TBool aForce )
       
   166     {
       
   167     if ( !IsActive() && ( IsRequestIntervalBigEnough() || aForce ) )
       
   168         {
       
   169         iEverActivated = ETrue;
       
   170         iLastRequestTime.HomeTime();
       
   171         iStatus = KRequestPending;
       
   172         TRequestStatus* status = &iStatus;
       
   173         User::RequestComplete( status, KErrNone );
       
   174         SetActive();        
       
   175         }
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CSmileyAsyncDraw::DoCancel
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CSmileyAsyncDraw::DoCancel()
       
   183     {
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CSmileyAsyncDraw::RunL
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CSmileyAsyncDraw::RunL()
       
   191     {
       
   192     CreateReplayImageL();
       
   193     iDrawer.DrawTextView();
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CSmileyAsyncDraw::AddReplayImage
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CSmileyAsyncDraw::AddReplayImage( CSmileyImageData* aImage )
       
   201     {
       
   202     if ( aImage )
       
   203         {
       
   204         TBool found( EFalse );
       
   205         for ( TInt i( 0 ); i < iReplayImageArray.Count(); i++ )
       
   206             {
       
   207             if ( iReplayImageArray[i] == aImage )
       
   208                 {
       
   209                 found = ETrue;
       
   210                 break;
       
   211                 }
       
   212             }
       
   213         if ( !found )
       
   214             {
       
   215             aImage->DeleteImage();
       
   216             iReplayImageArray.Append( aImage );
       
   217             }
       
   218         }
       
   219     RequestAsyncDraw( ETrue );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CSmileyAsyncDraw::CreateReplayImageL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CSmileyAsyncDraw::CreateReplayImageL()
       
   227     {
       
   228     for ( TInt i( 0 ); i < iReplayImageArray.Count(); i++ )
       
   229         {
       
   230         iDrawer.CreateImageL( iReplayImageArray[i] );
       
   231         }
       
   232     iReplayImageArray.Reset();
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CSmileyAsyncDraw::IsRequestIntervalBigEnough
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 TBool CSmileyAsyncDraw::IsRequestIntervalBigEnough() const
       
   240     {
       
   241     if ( !iEverActivated )
       
   242         {
       
   243         return ETrue;
       
   244         }
       
   245     TTime current;
       
   246     current.HomeTime();
       
   247     return ( current.MicroSecondsFrom( iLastRequestTime ) >= KDrawIntervalMicroSec );
       
   248     }