graphics/wserv/src/T_DataWsSprite.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 
       
    18 #include "T_GraphicsUtil.h"
       
    19 #include "T_DataWsSprite.h"
       
    20 
       
    21 /*@{*/
       
    22 //Commands
       
    23 _LIT(KCmdNew,							    "new");
       
    24 _LIT(KCmdConstruct,						    "Construct");
       
    25 _LIT(KCmdSetPosition,						"SetPosition");
       
    26 
       
    27 // Fields
       
    28 _LIT(KFldWs,							"ws");
       
    29 _LIT(KFldFlag,                          "flag");
       
    30 _LIT(KFldPoint,							"pos");
       
    31 _LIT(KFldWindow,                        "win");
       
    32 ///	Logging
       
    33 _LIT(KLogError,								"Error=%d");
       
    34 _LIT(KLogMissingParameter,					"Missing parameter '%S'");
       
    35 
       
    36 _LIT(KLogNew,                               "execute new RWsSprite()");
       
    37 _LIT(KLogNew2,                              "execute new RWsSprite(RWsSession)");
       
    38 _LIT(KLogConstruct,                         "execute Construct(RWindowTreeNode, const TPoint, TInt)");
       
    39 _LIT(KLogSetPosition,                       "execute SetPosition(TPoint)");
       
    40 /*@}*/
       
    41 
       
    42 //////////////////////////////////////////////////////////////////////
       
    43 // Construction/Destruction
       
    44 //////////////////////////////////////////////////////////////////////
       
    45 
       
    46 CT_DataWsSprite::CT_DataWsSprite()
       
    47 :	CT_DataWsSpriteBase(),iWsSprite(NULL)
       
    48 	{
       
    49 	}
       
    50 
       
    51 CT_DataWsSprite*	CT_DataWsSprite::NewL()
       
    52 	{
       
    53 	CT_DataWsSprite*    ret=new (ELeave) CT_DataWsSprite();
       
    54 	CleanupStack::PushL(ret);
       
    55 	ret->ConstructL();
       
    56 	CleanupStack::Pop(ret);
       
    57 	return ret;
       
    58 	}
       
    59 
       
    60 void CT_DataWsSprite::ConstructL()
       
    61 	{
       
    62 	}
       
    63 
       
    64 CT_DataWsSprite::~CT_DataWsSprite()
       
    65 	{
       
    66 	DestroyData();
       
    67 	}
       
    68 
       
    69 /**
       
    70  * Called by TEF framework to set object.
       
    71  *
       
    72  * @param: None
       
    73  *
       
    74  * @return: None
       
    75  */
       
    76 void CT_DataWsSprite::SetObjectL(TAny* aAny)
       
    77 	{
       
    78 	DestroyData();
       
    79 	iWsSprite = static_cast<RWsSprite*> (aAny);
       
    80 	}
       
    81 
       
    82 /**
       
    83  * Called by TEF framework to disown the object.
       
    84  *
       
    85  * @param: None
       
    86  *
       
    87  * @return: None
       
    88  */
       
    89 void CT_DataWsSprite::DisownObjectL()
       
    90 	{
       
    91 	iWsSprite = NULL;
       
    92 	}
       
    93 
       
    94 /**
       
    95  * Destroy the object which has been constructed.
       
    96  *
       
    97  * @param: None
       
    98  *
       
    99  * @return: None
       
   100  */
       
   101 void CT_DataWsSprite::DestroyData()
       
   102 	{
       
   103 	delete iWsSprite;
       
   104 	iWsSprite = NULL;
       
   105 	}
       
   106 	
       
   107 /**
       
   108 * Process a command read from the ini file
       
   109 *
       
   110 * @param aCommand			the command to process
       
   111 * @param aSection			the entry in the ini file requiring the command to be processed
       
   112 * @param aAsyncErrorIndex	index of command. used for async calls
       
   113 *
       
   114 * @return ETrue if the command is processed
       
   115 */
       
   116 TBool CT_DataWsSprite::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   117 	{
       
   118 	TBool	ret = ETrue;
       
   119 
       
   120 	if ( aCommand==KCmdNew )
       
   121 		{
       
   122 		DoCmdNewL(aSection);
       
   123 		}
       
   124 	else if ( aCommand==KCmdConstruct )
       
   125 		{
       
   126 		DoCmdConstructL(aSection);
       
   127 		}
       
   128 	else if ( aCommand==KCmdSetPosition )
       
   129 		{
       
   130 		DoCmdSetPosition(aSection);
       
   131 		}
       
   132 	else
       
   133 		{
       
   134 		ret=CT_DataWsSpriteBase::DoCommandL(aCommand,aSection,aAsyncErrorIndex);
       
   135 		}
       
   136 
       
   137 	return ret;
       
   138 	}
       
   139 
       
   140 /**
       
   141  * Process new command
       
   142  *
       
   143  * @param aSection			the entry in the ini file requiring the command to be processed
       
   144  *
       
   145  * @return: None
       
   146  */
       
   147 void CT_DataWsSprite::DoCmdNewL(const TDesC& aSection)
       
   148 	{
       
   149 	TPtrC	wsName;
       
   150 	RWsSession* ws=NULL;
       
   151 	
       
   152 	if ( GetStringFromConfig(aSection, KFldWs, wsName) )
       
   153 		{
       
   154 		ws = static_cast<RWsSession*>(GetDataObjectL(wsName));
       
   155 		}
       
   156 		
       
   157 	TInt err=KErrNone;
       
   158 	
       
   159 	if ( ws!=NULL )
       
   160 		{
       
   161 		// Execute command and log parameters
       
   162 		INFO_PRINTF1(KLogNew2);
       
   163 		TRAP( err, iWsSprite=new (ELeave) RWsSprite(*ws));
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		// Execute command and log parameters
       
   168 		INFO_PRINTF1(KLogNew);
       
   169 		TRAP( err, iWsSprite=new (ELeave) RWsSprite());
       
   170 		}
       
   171 
       
   172 	if ( err!=KErrNone )
       
   173 		{
       
   174 		ERR_PRINTF2(KLogError, err);
       
   175 		SetError(err);
       
   176 		}
       
   177 	// No command return value and output parameter to display and check
       
   178 	}
       
   179 
       
   180 /**
       
   181  * Process Construct command
       
   182  *
       
   183  * @param aSection			the entry in the ini file requiring the command to be processed
       
   184  *
       
   185  * @return: None
       
   186  */
       
   187 void CT_DataWsSprite::DoCmdConstructL(const TDesC& aSection)
       
   188 	{
       
   189 	TBool	dataOk=ETrue;
       
   190 
       
   191 	// Get test data for command input parameter(s)
       
   192 	TPtrC	winName;
       
   193 	RWindow* win=NULL;
       
   194 	
       
   195 	if ( GetStringFromConfig(aSection, KFldWindow, winName) )
       
   196 		{
       
   197 		win=static_cast<RWindow*>(GetDataObjectL(winName));
       
   198 		}
       
   199 	
       
   200 	if ( win==NULL )
       
   201 		{
       
   202 		dataOk=EFalse;
       
   203 		ERR_PRINTF2(KLogMissingParameter, &KFldWindow);
       
   204 		SetBlockResult(EFail);
       
   205 		}
       
   206 
       
   207 	TUint aSpriteFlags=0;
       
   208 	
       
   209 	if(!CT_GraphicsUtil::ReadSpriteFlags(*this,aSection,KFldFlag,aSpriteFlags))
       
   210 		{
       
   211 		dataOk=EFalse;
       
   212 		ERR_PRINTF2(KLogMissingParameter, &KFldFlag);
       
   213 		SetBlockResult(EFail);
       
   214 		}
       
   215 
       
   216 	TPoint	dataPoint;
       
   217 	
       
   218 	if ( !GetPointFromConfig(aSection, KFldPoint, dataPoint) )
       
   219 		{
       
   220 		dataPoint=TPoint(0,0);
       
   221 		}
       
   222 	
       
   223 	if ( dataOk )
       
   224 		{
       
   225 		// Execute command and log parameters
       
   226 		INFO_PRINTF1(KLogConstruct);
       
   227 		TInt returnCode=iWsSprite->Construct(*win, dataPoint,aSpriteFlags);
       
   228 
       
   229 		// Check the command return code, if !=KErrNone then stop this command
       
   230 		if ( returnCode!=KErrNone )
       
   231 			{
       
   232 			ERR_PRINTF2(KLogError, returnCode);
       
   233 			SetError(returnCode);
       
   234 			}
       
   235 		}
       
   236 	}
       
   237 
       
   238 /**
       
   239  * Process SetPosition command
       
   240  *
       
   241  * @param aSection			the entry in the ini file requiring the command to be processed
       
   242  *
       
   243  * @return: None
       
   244  */
       
   245 void CT_DataWsSprite::DoCmdSetPosition(const TDesC& aSection)
       
   246 	{
       
   247 	TBool	dataOk=ETrue;
       
   248 	TPoint	dataPoint;
       
   249 	
       
   250 	if ( !GetPointFromConfig(aSection, KFldPoint, dataPoint) )
       
   251 		{
       
   252 		dataOk=EFalse;
       
   253 		ERR_PRINTF2(KLogMissingParameter, &KFldPoint);
       
   254 		SetBlockResult(EFail);
       
   255 		}
       
   256 	
       
   257 	if ( dataOk )
       
   258 		{
       
   259 		// Execute command and log parameters
       
   260 		INFO_PRINTF1(KLogSetPosition);
       
   261 		iWsSprite->SetPosition(dataPoint);
       
   262 		// No command return value and output parameter to display and check
       
   263 		}
       
   264 	// No command return value and output parameter to display and check
       
   265 	}