lafagnosticuifoundation/bmpanimation/tef/Tanctl.cpp
changeset 0 2f259fa3e83a
child 18 0aa5fbdfbc30
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include <barsread.h>
       
    23 #include <eikenv.h>
       
    24 #include <eikappui.h>
       
    25 #include <eikapp.h>
       
    26 #include <fbs.h>
       
    27 #include <bmpancli.h>
       
    28 #include "Tanctl.h"
       
    29 
       
    30 
       
    31 void CAnimateFramesCtl::Panic(TEikAnimationPanic aPanic)
       
    32 	{
       
    33 	_LIT(KPanicCat,"TBMPANIM-Animation");
       
    34 	User::Panic(KPanicCat, aPanic);
       
    35 	}
       
    36 
       
    37 CAnimateFramesCtl* CAnimateFramesCtl::NewL()
       
    38 	{ // static
       
    39 	CAnimateFramesCtl* self=new(ELeave) CAnimateFramesCtl();
       
    40 	CleanupStack::PushL(self);
       
    41 	self->BaseConstructL();
       
    42 	CleanupStack::Pop();
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 CAnimateFramesCtl::CAnimateFramesCtl() :
       
    47 	iAnimDll(iEikonEnv->WsSession()),
       
    48 	iFlags(EWaitForRedrawing)
       
    49 	{
       
    50 	}
       
    51 
       
    52 CAnimateFramesCtl::~CAnimateFramesCtl()
       
    53 	{
       
    54 	delete iAnimation;
       
    55 	delete iBitmapAnimData;
       
    56 	delete iStartAnimationIdler;
       
    57 	iAnimDll.Close();
       
    58 	}
       
    59 
       
    60 //
       
    61 //
       
    62 void CAnimateFramesCtl::BaseConstructL()
       
    63 	{
       
    64 	iBitmapAnimData = CBitmapAnimClientData::NewL();
       
    65 	iAnimation = new (ELeave) RBitmapAnim(iAnimDll);
       
    66 	_LIT(DllName, "BMPANSRV.DLL");
       
    67 	User::LeaveIfError(iAnimDll.Load(DllName));
       
    68 	}
       
    69 
       
    70 // Creates a resource reader from the animation aResourceId
       
    71 void CAnimateFramesCtl::StaticConstructL(TInt aResourceId)
       
    72     {
       
    73     TResourceReader reader;
       
    74     iCoeEnv->CreateResourceReaderLC(reader,aResourceId);
       
    75     ConstructFromResourceL(reader);
       
    76 	CleanupStack::PopAndDestroy();
       
    77     }
       
    78 
       
    79 //
       
    80 // 
       
    81 void CAnimateFramesCtl::ConstructFromResourceL(TResourceReader& aReader)
       
    82 	{
       
    83 	iBitmapAnimData->SetFrameInterval(aReader.ReadInt16());
       
    84 	iBitmapAnimData->SetPlayMode((CBitmapAnimClientData::TPlayMode)aReader.ReadInt16());
       
    85 	iBitmapAnimData->SetFlash(aReader.ReadInt8());
       
    86 	TFileName ptr(aReader.ReadTPtrC());	// filename
       
    87     if (!ptr.Length())
       
    88 		ptr = KTBmpAnimMBMFilePath;//vm iEikonEnv->EikAppUi()->Application()->BitmapStoreName();
       
    89 // Start reading the data frames
       
    90     TInt listFrameLink=aReader.ReadInt32();
       
    91 	if (listFrameLink)
       
    92 		{
       
    93 		TResourceReader framesReader;
       
    94 		iCoeEnv->CreateResourceReaderLC(framesReader, listFrameLink);
       
    95 		const TInt count=framesReader.ReadInt16();
       
    96 		CBitmapFrameData* frameData = NULL;
       
    97 		for (TInt ii=0;ii<count;++ii)
       
    98 			{
       
    99 			//read the frame data from resource	
       
   100 			frameData = ReadFrameDataFromResourceL(framesReader, ptr);
       
   101 			CleanupStack::PushL(frameData);
       
   102 			iBitmapAnimData->AppendFrameL(frameData);
       
   103 			CleanupStack::Pop(); // frameData
       
   104 			}
       
   105 		CleanupStack::PopAndDestroy();
       
   106 		}
       
   107     TInt backgroundLink=aReader.ReadInt32();
       
   108 	if (backgroundLink > 0)
       
   109 		{
       
   110 		TResourceReader backgroundReader;
       
   111 		iCoeEnv->CreateResourceReaderLC(backgroundReader, backgroundLink);
       
   112 		//read the frame data from resource
       
   113 		CBitmapFrameData* backgroundData = ReadFrameDataFromResourceL(backgroundReader, ptr);
       
   114 		CleanupStack::PushL(backgroundData);
       
   115 		iBitmapAnimData->SetBackgroundFrame(backgroundData);
       
   116 		CleanupStack::Pop(); // backgroundData
       
   117 		CleanupStack::PopAndDestroy(); // backgroundReader
       
   118 		}
       
   119 	}
       
   120 
       
   121 
       
   122 //
       
   123 //
       
   124 CBitmapFrameData* CAnimateFramesCtl::ReadFrameDataFromResourceL(TResourceReader& aFramesReader, const TDesC& aFileName)
       
   125 	{
       
   126 	CBitmapFrameData* frameData = CBitmapFrameData::NewL();
       
   127 	CleanupStack::PushL(frameData);
       
   128 	frameData->SetInterval(aFramesReader.ReadInt16());
       
   129 	TPoint position;
       
   130 	position.iX = aFramesReader.ReadInt16();
       
   131 	position.iY = aFramesReader.ReadInt16();
       
   132 	frameData->SetPosition(position);
       
   133 	const TInt bmpId = aFramesReader.ReadInt16();
       
   134 	const TInt maskId = aFramesReader.ReadInt16();
       
   135 	if (bmpId >= 0)
       
   136 		{
       
   137 		CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(aFileName, bmpId);
       
   138 		frameData->SetBitmap(bitmap);
       
   139 		if (maskId >= 0)
       
   140 			{
       
   141 			CFbsBitmap* mask = iEikonEnv->CreateBitmapL(aFileName, maskId);
       
   142 			frameData->SetMask(mask);
       
   143 			}
       
   144 		}
       
   145 	CleanupStack::Pop();
       
   146 	return frameData;
       
   147 	}
       
   148 
       
   149 //
       
   150 //
       
   151 void CAnimateFramesCtl::CancelAnimationL()
       
   152 	{
       
   153 	__ASSERT_ALWAYS(iAnimation, Panic(EEikPanicAnimationNoRAnimation));
       
   154 	if (IsInitialisationComnpleted())
       
   155 		iAnimation->StopL();
       
   156 	}
       
   157 
       
   158 //
       
   159 //
       
   160 void CAnimateFramesCtl::CompleteAnimationInitialisationL()
       
   161 	{
       
   162 	__ASSERT_ALWAYS(iAnimation, Panic(EEikPanicAnimationNoRAnimation));
       
   163 	__ASSERT_ALWAYS(SetAnimationWindowL(), Panic(EEikPanicAnimationNoWindow));
       
   164 	iAnimation->SetBitmapAnimDataL(*iBitmapAnimData);
       
   165 	iAnimation->SetPositionL(iPosition);
       
   166 	iFlags |= EInitialisationCompleted;
       
   167 	}
       
   168 
       
   169 //
       
   170 //
       
   171 TSize CAnimateFramesCtl::MinimumSize()
       
   172 	{
       
   173 	return iBitmapAnimData->Size();
       
   174 	}
       
   175 
       
   176 //
       
   177 //
       
   178 void CAnimateFramesCtl::PositionChanged()
       
   179 	{
       
   180 	if ( (iAnimation) && IsInitialisationComnpleted() )
       
   181 		iAnimation->SetPositionL(iPosition);
       
   182 	}
       
   183 
       
   184 //
       
   185 //
       
   186 TBool CAnimateFramesCtl::SetAnimationWindowL()
       
   187 	{
       
   188 	RWindow* window = &Window();
       
   189 	if (window)
       
   190 		{	
       
   191 		iAnimation->ConstructL(*window);
       
   192 		return ETrue;
       
   193 		}
       
   194 	return EFalse;
       
   195 	}
       
   196 
       
   197 void CAnimateFramesCtl::SetAnimationCtlWindowL(CCoeControl* aParent)
       
   198 	{
       
   199 	if (aParent)
       
   200 		SetContainerWindowL(*aParent);
       
   201 	else
       
   202 		CreateWindowL();
       
   203 	}
       
   204 
       
   205 //
       
   206 void CAnimateFramesCtl::SetFrameIndexL(TInt aIndex)
       
   207 	{
       
   208 	if (IsInitialisationComnpleted())
       
   209 		iAnimation->DisplayFrameL(aIndex);
       
   210 	}
       
   211 
       
   212 //
       
   213 void CAnimateFramesCtl::SetFrameIntervalL(TInt aInterval)
       
   214 	{
       
   215 	if (IsInitialisationComnpleted())
       
   216 		iAnimation->SetFrameIntervalL(aInterval);
       
   217 	}
       
   218 //
       
   219 //
       
   220 void CAnimateFramesCtl::SizeChanged()
       
   221 	{
       
   222 	if ( (iAnimation) && IsInitialisationComnpleted() )
       
   223 		iAnimation->SetPositionL(iPosition);
       
   224 	}
       
   225 
       
   226 //
       
   227 //
       
   228 void CAnimateFramesCtl::StartAnimationL()
       
   229 	{
       
   230 	if (iFlags&EWaitForRedrawing)
       
   231 		{
       
   232 		CreateAndStartIdlerL();
       
   233 		iFlags &= ~EWaitForRedrawing;
       
   234 		}
       
   235 	else
       
   236 		{
       
   237 		if (!IsInitialisationComnpleted())
       
   238 			CompleteAnimationInitialisationL();
       
   239 		iAnimation->StartL();
       
   240 		}
       
   241 	}
       
   242 
       
   243 void CAnimateFramesCtl::SetBitmapAnimationDataL()
       
   244 	{
       
   245 	}
       
   246 
       
   247 void CAnimateFramesCtl::CreateAndStartIdlerL()
       
   248 	{
       
   249 	if (!iStartAnimationIdler)
       
   250 		iStartAnimationIdler = CBitmapAnimIdler::NewL();
       
   251 	iStartAnimationIdler->Cancel();
       
   252 	iStartAnimationIdler->Start(TCallBack(StartAnimationCallBackL,this));
       
   253 	}
       
   254 
       
   255 TInt CAnimateFramesCtl::StartAnimationCallBackL(TAny* aThis)
       
   256 	{ // static
       
   257 	CAnimateFramesCtl* self=(CAnimateFramesCtl*)aThis;
       
   258 	self->StartAnimationL();
       
   259 	return(EFalse); // single shot callback
       
   260 	}
       
   261 
       
   262 
       
   263 // Idle class
       
   264 
       
   265 CBitmapAnimIdler* CBitmapAnimIdler::NewL()
       
   266 	{
       
   267 	CBitmapAnimIdler* self=new(ELeave) CBitmapAnimIdler;
       
   268 	CActiveScheduler::Add(self);
       
   269 	return(self);
       
   270 	}
       
   271 
       
   272