graphics/bitgdi/src/T_DataFbsBitmapDevice.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 //
       
     2 // Copyright (c) 2005-2009 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 the License "Symbian Foundation License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 
       
    17 //	User includes
       
    18 #include "T_DataFbsBitmapDevice.h"
       
    19 #include "T_GraphicsUtil.h"
       
    20 
       
    21 /*@{*/
       
    22 ///	Commands
       
    23 _LIT(KCmdNewL,							"NewL");
       
    24 _LIT(KCmdDestructor,					"~");
       
    25 _LIT(KCmdDrawingBegin, 					"DrawingBegin");
       
    26 _LIT(KCmdDrawingEnd,					"DrawingEnd");
       
    27 _LIT(KCmdResize,						"Resize");
       
    28 _LIT(KCmdSwapWidthAndHeight,			"SwapWidthAndHeight");
       
    29 
       
    30 ///	Parameters
       
    31 _LIT(KFldBitmap,						"bitmap");
       
    32 _LIT(KFldLibName,						"libname");
       
    33 _LIT(KFldSize,							"size");
       
    34 _LIT(KFldResize,						"resize");
       
    35 _LIT(KFldAlways,						"Always");
       
    36 
       
    37 // Logs
       
    38 _LIT(KLogMissingParameter,				"Missing parameter '%S'");
       
    39 _LIT(KLogErrNum,						"Execute failed with error = %d!");	
       
    40 /*@}*/
       
    41 
       
    42 
       
    43 /**
       
    44 * Two phase constructor
       
    45 */
       
    46 CT_DataFbsBitmapDevice* CT_DataFbsBitmapDevice::NewL()
       
    47 	{
       
    48 	CT_DataFbsBitmapDevice*	ret = new (ELeave) CT_DataFbsBitmapDevice();
       
    49 	CleanupStack::PushL(ret);
       
    50 	ret->ConstructL();
       
    51 	CleanupStack::Pop(ret);
       
    52 	return ret;
       
    53 	}
       
    54 
       
    55 /**
       
    56 * Protected constructor. First phase construction
       
    57 */
       
    58 CT_DataFbsBitmapDevice::CT_DataFbsBitmapDevice()
       
    59 :	CT_DataFbsDevice()
       
    60 ,	iFbsBitmapDevice(NULL)
       
    61 	{
       
    62 	}
       
    63 
       
    64 /**
       
    65 * Protected second phase construction
       
    66 */
       
    67 void CT_DataFbsBitmapDevice::ConstructL()
       
    68 	{
       
    69 	}
       
    70 
       
    71 /**
       
    72 * Destructor.
       
    73 */
       
    74 CT_DataFbsBitmapDevice::~CT_DataFbsBitmapDevice()
       
    75 	{
       
    76 	DestroyData();
       
    77 	}
       
    78 
       
    79 void CT_DataFbsBitmapDevice::DestroyData()
       
    80 	{
       
    81 	delete iFbsBitmapDevice;
       
    82 	iFbsBitmapDevice=NULL;
       
    83 	}
       
    84 
       
    85 MGraphicsDeviceMap* CT_DataFbsBitmapDevice::GetGraphicsDeviceMap() const
       
    86 	{
       
    87 	return iFbsBitmapDevice;
       
    88 	}
       
    89 
       
    90 CGraphicsDevice* CT_DataFbsBitmapDevice::GetGraphicsDevice() const
       
    91 	{
       
    92 	return iFbsBitmapDevice;
       
    93 	}
       
    94 
       
    95 CBitmapDevice* CT_DataFbsBitmapDevice::GetBitmapDevice() const
       
    96 	{
       
    97 	return iFbsBitmapDevice;
       
    98 	}
       
    99 
       
   100 CFbsDevice* CT_DataFbsBitmapDevice::GetFbsDevice() const
       
   101 	{
       
   102 	return iFbsBitmapDevice;
       
   103 	}
       
   104 /**
       
   105 * Return a pointer to the object that the data wraps
       
   106 *
       
   107 * @return pointer to the object that the data wraps
       
   108 */
       
   109 TAny* CT_DataFbsBitmapDevice::GetObject()
       
   110 	{
       
   111 	return iFbsBitmapDevice;
       
   112 	}
       
   113 
       
   114 void CT_DataFbsBitmapDevice::SetObjectL(TAny* aObject)
       
   115 	{
       
   116 	DestroyData();
       
   117 	iFbsBitmapDevice = static_cast<CFbsBitmapDevice*> (aObject);
       
   118 	}
       
   119 
       
   120 void CT_DataFbsBitmapDevice::DisownObjectL() 
       
   121 	{
       
   122 	iFbsBitmapDevice = NULL;
       
   123 	}
       
   124 
       
   125 /**
       
   126 * Process a command read from the ini file
       
   127 *
       
   128 * @param aDataWrapper	test step requiring command to be processed
       
   129 * @param aCommand	the command to process
       
   130 * @param aSection		the entry in the ini file requiring the command to be processed
       
   131 *
       
   132 * @return ETrue if the command is processed
       
   133 */
       
   134 TBool CT_DataFbsBitmapDevice::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   135 	{
       
   136 	/* Another work package will complete the implement of this */
       
   137 	TBool	retVal = ETrue;
       
   138 
       
   139 	if ( aCommand == KCmdNewL )
       
   140 		{
       
   141 		DoCmdNewL(aSection);
       
   142 		}
       
   143 	else if (aCommand == KCmdDestructor)
       
   144 		{
       
   145 		DoCmdDestructor();
       
   146 		}
       
   147 	else if (aCommand == KCmdDrawingBegin)
       
   148 		{
       
   149 		DoCmdDrawingBegin(aSection);
       
   150 		}
       
   151 	else if (aCommand == KCmdDrawingEnd)
       
   152 		{
       
   153 		DoCmdDrawingEnd(aSection);
       
   154 		}
       
   155 	else if (aCommand == KCmdResize)
       
   156 		{
       
   157 		DoCmdResize(aSection);
       
   158 		}
       
   159 	else if (aCommand == KCmdSwapWidthAndHeight)
       
   160 		{
       
   161 		DoCmdSwapWidthAndHeight();
       
   162 		}
       
   163 	else
       
   164 		{
       
   165 		retVal=CT_DataFbsDevice::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   166 		}
       
   167 	return retVal;
       
   168 	}
       
   169 
       
   170 void CT_DataFbsBitmapDevice::DoCmdNewL(const TDesC& aSection)
       
   171 	{
       
   172 	DestroyData();
       
   173 	CFbsBitmap*	bitmap = NULL;
       
   174 	
       
   175 	if (!CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KFldBitmap, bitmap))
       
   176 		{
       
   177 		ERR_PRINTF2(KLogMissingParameter, &KFldBitmap);
       
   178 		SetBlockResult(EFail);
       
   179 		return;
       
   180 		}
       
   181 	TInt	err = KErrNone;
       
   182 	TPtrC	libName;
       
   183 	if ( GetStringFromConfig(aSection, KFldLibName(), libName) )
       
   184 		{
       
   185 		INFO_PRINTF1(_L("execute NewL(CFbsBitmap*, const TDesC&)."));
       
   186 		TRAP(err, iFbsBitmapDevice=CFbsBitmapDevice::NewL(bitmap, libName));
       
   187 		}
       
   188 	else
       
   189 		{
       
   190 		INFO_PRINTF1(_L("execute NewL(CFbsBitmap*)."));
       
   191 		TRAP(err, iFbsBitmapDevice=CFbsBitmapDevice::NewL(bitmap));
       
   192 		}
       
   193 	
       
   194 	if ( err != KErrNone )
       
   195 		{
       
   196 		ERR_PRINTF2(KLogErrNum, err);
       
   197 		SetError(err);
       
   198 		}
       
   199 	}
       
   200 
       
   201 void CT_DataFbsBitmapDevice::DoCmdDestructor()
       
   202 	{
       
   203 	DestroyData();
       
   204 	}
       
   205 
       
   206 void CT_DataFbsBitmapDevice::DoCmdDrawingBegin(const TDesC& aSection)
       
   207 	{
       
   208 	TBool Always = EFalse;
       
   209 	GetBoolFromConfig(aSection, KFldAlways, Always);
       
   210 	INFO_PRINTF2(_L("execute DrawingBegin function with the Always parameter=%d."), Always);
       
   211 	iFbsBitmapDevice->DrawingBegin(Always);
       
   212 	}
       
   213 
       
   214 void CT_DataFbsBitmapDevice::DoCmdDrawingEnd(const TDesC& aSection)
       
   215 	{
       
   216 	TBool Always = EFalse;
       
   217 	GetBoolFromConfig(aSection, KFldAlways, Always);
       
   218 	INFO_PRINTF2(_L("execute DrawingEnd function with the Always parameter=%d."), Always);
       
   219 	iFbsBitmapDevice->DrawingEnd(Always);
       
   220 	}
       
   221 
       
   222 void CT_DataFbsBitmapDevice::DoCmdResize(const TDesC& aSection)
       
   223 	{
       
   224 	TSize	datSize;
       
   225 	TInt 	err = KErrNone;
       
   226 	INFO_PRINTF1(_L("execute Resize(const TSize&)"));
       
   227 	if (!GetSizeFromConfig(aSection, KFldResize, datSize))
       
   228 		{
       
   229 		ERR_PRINTF2(KLogMissingParameter, &KFldResize);
       
   230 		SetBlockResult(EFail);
       
   231 		}
       
   232 	else
       
   233 		{
       
   234 		err = iFbsBitmapDevice->Resize(datSize);
       
   235 		if (KErrNone != err)
       
   236 			{
       
   237 			ERR_PRINTF2(KLogErrNum, err);
       
   238 			SetError(err);
       
   239 			}
       
   240 		}
       
   241 	}
       
   242 
       
   243 void CT_DataFbsBitmapDevice::DoCmdSwapWidthAndHeight()
       
   244 	{
       
   245 	INFO_PRINTF1(_L("execute SwapWidthAndHeight()"));
       
   246 	TInt err = iFbsBitmapDevice->SwapWidthAndHeight();
       
   247 	if (KErrNone != err)
       
   248 		{
       
   249 		ERR_PRINTF2(KLogErrNum, err);
       
   250 		SetError(err);
       
   251 		}
       
   252 	}
       
   253