graphics/wserv/src/T_DataWindowGc.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_DataWindowGc.h"
       
    19 #include "T_GraphicsUtil.h"
       
    20 
       
    21 /*@{*/
       
    22 _LIT(KDataClassname,	"CWindowGc");
       
    23 
       
    24 //Commands
       
    25 _LIT(KCmdnew,						"new");
       
    26 _LIT(KCmdDestructor,				"~CWindowGc");
       
    27 _LIT(KCmdDestructorGeneral,			"~");
       
    28 _LIT(KCmdConstruct,					"Construct");
       
    29 _LIT(KCmdActivate,					"Activate");
       
    30 _LIT(KCmdDeactivate,				"Deactivate");
       
    31 _LIT(KCmdBitBlt,					"BitBlt");
       
    32 _LIT(KCmdBitBltMasked,				"BitBltMasked");
       
    33 _LIT(KCmdSetDitherOrigin,			"SetDitherOrigin");
       
    34 _LIT(KCmdSetOpaque,					"SetOpaque");
       
    35 _LIT(KCmdDrawWsGraphic,				"DrawWsGraphic");
       
    36 
       
    37 // Fields
       
    38 _LIT(KFldData,						"data");
       
    39 _LIT(KFldWsga,						"wsga");
       
    40 _LIT(KFldDestRect,					"destrect");
       
    41 _LIT(KFldDestination,				"destination");
       
    42 _LIT(KFldDevice,					"device");
       
    43 _LIT(KFldId,						"id");
       
    44 _LIT(KFldInvertMask,				"invertmask");
       
    45 _LIT(KFldMaskBitmap,				"maskbitmap");
       
    46 _LIT(KFldPoint,						"point");
       
    47 _LIT(KFldSource,					"source");
       
    48 _LIT(KFldSourceRect,				"sourcerect");
       
    49 _LIT(KFldWsBitmap,					"wsbitmap");
       
    50 _LIT(KFldDrawOpaque,				"drawOpaque");
       
    51 
       
    52 ///	Logging
       
    53 _LIT(KLogError,						"Error=%d");
       
    54 _LIT(KLogMissingParameter,			"Missing parameter '%S'");
       
    55 /*@}*/
       
    56 
       
    57 //////////////////////////////////////////////////////////////////////
       
    58 // Construction/Destruction
       
    59 //////////////////////////////////////////////////////////////////////
       
    60 
       
    61 CT_DataWindowGc* CT_DataWindowGc::NewL()
       
    62 	{
       
    63 	CT_DataWindowGc*	ret=new (ELeave) CT_DataWindowGc();
       
    64 	CleanupStack::PushL(ret);
       
    65 	ret->ConstructL();
       
    66 	CleanupStack::Pop(ret);
       
    67 	return ret;
       
    68 	}
       
    69 
       
    70 CT_DataWindowGc::CT_DataWindowGc()
       
    71 :	CT_DataBitmapContext()
       
    72 ,	iWindowGc(NULL)
       
    73 	{
       
    74 	}
       
    75 
       
    76 void CT_DataWindowGc::ConstructL()
       
    77 	{
       
    78 	}
       
    79 
       
    80 CT_DataWindowGc::~CT_DataWindowGc()
       
    81 	{
       
    82 	DestroyData();
       
    83 	}
       
    84 
       
    85 void CT_DataWindowGc::SetObjectL(TAny* aAny)
       
    86 	{
       
    87 	DestroyData();
       
    88 	iWindowGc = static_cast<CWindowGc*> (aAny);
       
    89 	}
       
    90 
       
    91 void CT_DataWindowGc::DisownObjectL()
       
    92 	{
       
    93 	iWindowGc = NULL;
       
    94 	}
       
    95 
       
    96 void CT_DataWindowGc::DestroyData()
       
    97 	{
       
    98 	delete iWindowGc;
       
    99 	iWindowGc=NULL;
       
   100 	}
       
   101 
       
   102 MWsClientClass* CT_DataWindowGc::GetClientClass() const
       
   103 	{
       
   104 	return iWindowGc;
       
   105 	}
       
   106 
       
   107 CBitmapContext* CT_DataWindowGc::GetBitmapContext() const
       
   108 	{
       
   109 	return iWindowGc;
       
   110 	}
       
   111 
       
   112 CGraphicsContext* CT_DataWindowGc::GetGraphicsContext() const
       
   113 	{
       
   114 	return iWindowGc;
       
   115 	}
       
   116 
       
   117 
       
   118 
       
   119 /**
       
   120 * Process a command read from the ini file
       
   121 *
       
   122 * @param aCommand			the command to process
       
   123 * @param aSection			the entry in the ini file requiring the command to be processed
       
   124 * @param aAsyncErrorIndex	index of command. used for async calls
       
   125 *
       
   126 * @return ETrue if the command is processed
       
   127 */
       
   128 TBool CT_DataWindowGc::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   129 	{
       
   130 	TBool	ret = ETrue;
       
   131 
       
   132 	if ( aCommand==KCmdDestructor || aCommand==KCmdDestructorGeneral )
       
   133 		{
       
   134 		DoCmdDestructor();
       
   135 		}
       
   136 	else if ( aCommand==KCmdnew || aCommand==KDataClassname )
       
   137 		{
       
   138 		DoCmdnewL(aSection);
       
   139 		}
       
   140 	else if ( aCommand==KCmdConstruct )
       
   141 		{
       
   142 		DoCmdConstruct();
       
   143 		}
       
   144 	else if ( aCommand==KCmdActivate )
       
   145 		{
       
   146 		DoCmdActivateL(aSection);
       
   147 		}
       
   148 	else if ( aCommand==KCmdDeactivate )
       
   149 		{
       
   150 		DoCmdDeactivate();
       
   151 		}
       
   152 	else if ( aCommand==KCmdBitBlt )
       
   153 		{
       
   154 		DoCmdBitBltL(aCommand, aSection, aAsyncErrorIndex);
       
   155 		}
       
   156 	else if ( aCommand==KCmdBitBltMasked )
       
   157 		{
       
   158 		DoCmdBitBltMaskedL(aCommand, aSection, aAsyncErrorIndex);
       
   159 		}
       
   160 	else if ( aCommand==KCmdSetDitherOrigin )
       
   161 		{
       
   162 		DoCmdSetDitherOrigin(aSection);
       
   163 		}
       
   164 	else if ( aCommand==KCmdSetOpaque )
       
   165 		{
       
   166 		DoCmdSetOpaque(aSection);
       
   167 		}
       
   168 	else if ( aCommand==KCmdDrawWsGraphic )
       
   169 		{
       
   170 		DoCmdDrawWsGraphicL(aSection);
       
   171 		}
       
   172 	else if ( CT_DataBitmapContext::DoCommandL(aCommand, aSection, aAsyncErrorIndex) )
       
   173 		{
       
   174 		}
       
   175 	else
       
   176 		{
       
   177 		ret=CT_DataWsClientClass::DoCommandL(*this, aCommand, aSection, aAsyncErrorIndex);
       
   178 		}
       
   179 
       
   180 	return ret;
       
   181 	}
       
   182 
       
   183 
       
   184 void CT_DataWindowGc::DoCmdnewL(const TDesC& aSection)
       
   185 	{
       
   186 	DestroyData();
       
   187 
       
   188 	// Get test data for command input parameter(s)
       
   189 	CWsScreenDevice*	device = NULL;
       
   190 	if ( !CT_GraphicsUtil::GetWsScreenDeviceL(*this, aSection, KFldDevice, device) )
       
   191 		{
       
   192 		ERR_PRINTF2(KLogMissingParameter, &KFldDevice);
       
   193 		SetBlockResult(EFail);
       
   194 		}
       
   195 	else
       
   196 		{
       
   197 		INFO_PRINTF1(_L("execute new CWindowGc(CWsScreenDevice)"));
       
   198 		TRAPD( err, iWindowGc = new (ELeave) CWindowGc(device) );
       
   199 		if ( err != KErrNone )
       
   200 			{
       
   201 			ERR_PRINTF2(KLogError, err);
       
   202 			SetError(err);
       
   203 			}
       
   204 		}
       
   205 	}
       
   206 
       
   207 void CT_DataWindowGc::DoCmdDestructor()
       
   208 	{
       
   209 	// Execute command and log parameters
       
   210 	INFO_PRINTF1(_L("execute ~CWindowGc()"));
       
   211 	delete iWindowGc;
       
   212 	iWindowGc=NULL;
       
   213 	}
       
   214 
       
   215 
       
   216 void CT_DataWindowGc::DoCmdConstruct()
       
   217 	{
       
   218 	// Execute command and log parameters
       
   219 	INFO_PRINTF1(_L("execute Construct()"));
       
   220 	TInt	returnCode = iWindowGc->Construct();
       
   221 
       
   222 	// Check the command return code, if !=KErrNone then stop this command
       
   223 	if ( returnCode!=KErrNone )
       
   224 		{
       
   225 		ERR_PRINTF2(KLogError, returnCode);
       
   226 		SetError(returnCode);
       
   227 		}
       
   228 	}
       
   229 
       
   230 
       
   231 void CT_DataWindowGc::DoCmdActivateL(const TDesC& aSection)
       
   232 	{
       
   233 	// Get test data for command input parameter(s)
       
   234 	RDrawableWindow	*device = NULL;
       
   235 
       
   236 	if ( !CT_GraphicsUtil::GetDrawableWindowL(*this, aSection, KFldDevice, device) )
       
   237 		{
       
   238 		ERR_PRINTF2(KLogMissingParameter, &KFldDevice);
       
   239 		SetBlockResult(EFail);
       
   240 		}
       
   241 	else
       
   242 		{
       
   243 		// Execute command and log parameters
       
   244 		INFO_PRINTF1(_L("execute Activate(RDrawableWindow)"));
       
   245 		iWindowGc->Activate(*device);
       
   246 
       
   247 		// No command return value and output parameter to display and check
       
   248 		}
       
   249 	}
       
   250 
       
   251 
       
   252 void CT_DataWindowGc::DoCmdDeactivate()
       
   253 	{
       
   254 	// No command input parameter to process
       
   255 
       
   256 	// Execute command and log parameters
       
   257 	INFO_PRINTF1(_L("execute Deactivate()"));
       
   258 	iWindowGc->Deactivate();
       
   259 
       
   260 	// No command return value and output parameter to display and check
       
   261 	}
       
   262 
       
   263 void CT_DataWindowGc::DoCmdBitBltL(const TDesC& aCommand, const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   264 	{
       
   265 	TBool	dataOk=ETrue;
       
   266 
       
   267 	CWsBitmap*	wsBitmap=NULL;
       
   268 	if ( !CT_GraphicsUtil::GetWsBitmapL(*this, aSection, KFldWsBitmap, wsBitmap) )
       
   269 		{
       
   270 		CT_DataBitmapContext::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   271 		}
       
   272 	else
       
   273 		{
       
   274 		TPoint		point;
       
   275 		if ( GetPointFromConfig(aSection, KFldPoint, point) )
       
   276 			{
       
   277 			if ( dataOk )
       
   278 				{
       
   279 				// Execute command and log parameters
       
   280 				INFO_PRINTF1(_L("execute BitBlt(TPoint, CWsBitmap*)"));
       
   281 				iWindowGc->BitBlt(point, wsBitmap);
       
   282 				}
       
   283 			}
       
   284 		else
       
   285 			{
       
   286 			TPoint	destination;
       
   287 			if ( !GetPointFromConfig(aSection, KFldDestination, destination) )
       
   288 				{
       
   289 				dataOk=EFalse;
       
   290 				ERR_PRINTF2(KLogMissingParameter, &KFldDestination());
       
   291 				SetBlockResult(EFail);
       
   292 				}
       
   293     	
       
   294 			TRect	source;
       
   295 			if ( !GetRectFromConfig(aSection, KFldSource, source) )
       
   296 				{
       
   297 				dataOk=EFalse;
       
   298 				ERR_PRINTF2(KLogMissingParameter, &KFldSource());
       
   299 				SetBlockResult(EFail);
       
   300 				}
       
   301     	
       
   302 			if ( dataOk )
       
   303 				{
       
   304 				// Execute command and log parameters
       
   305 				INFO_PRINTF1(_L("execute BitBlt(TRect, CWsBitmap*, TRect)"));
       
   306 				iWindowGc->BitBlt(destination, wsBitmap, source);
       
   307 				}
       
   308 			}
       
   309 		}
       
   310 	}
       
   311 
       
   312 
       
   313 void CT_DataWindowGc::DoCmdBitBltMaskedL(const TDesC& aCommand, const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   314 	{
       
   315 	TBool	dataOk=ETrue;
       
   316 
       
   317 	CWsBitmap*	wsBitmap=NULL;
       
   318 	if ( !CT_GraphicsUtil::GetWsBitmapL(*this, aSection, KFldWsBitmap, wsBitmap) )
       
   319 		{
       
   320 		CT_DataBitmapContext::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   321 		}
       
   322 	else
       
   323 		{
       
   324 		// Get test data for command input parameter(s)
       
   325 		TPoint	point;
       
   326 		if ( !GetPointFromConfig(aSection, KFldPoint, point) )
       
   327 			{
       
   328 			dataOk=EFalse;
       
   329 			ERR_PRINTF2(KLogMissingParameter, &KFldPoint());
       
   330 			SetBlockResult(EFail);
       
   331 			}
       
   332     	
       
   333 		TRect	sourceRect;
       
   334 		if ( !GetRectFromConfig(aSection, KFldSourceRect, sourceRect) )
       
   335 			{
       
   336 			dataOk=EFalse;
       
   337 			ERR_PRINTF2(KLogMissingParameter, &KFldSourceRect());
       
   338 			SetBlockResult(EFail);
       
   339 			}
       
   340     	
       
   341 		TBool	invertMask;
       
   342 		if ( !GetBoolFromConfig(aSection, KFldInvertMask, invertMask) )
       
   343 			{
       
   344 			dataOk=EFalse;
       
   345 			ERR_PRINTF2(KLogMissingParameter, &KFldInvertMask());
       
   346 			SetBlockResult(EFail);
       
   347 			}
       
   348     	
       
   349 		if ( dataOk )
       
   350 			{
       
   351 			CWsBitmap*	maskBitmap=NULL;
       
   352 			CT_GraphicsUtil::GetWsBitmapL(*this, aSection, KFldMaskBitmap, maskBitmap);
       
   353     	
       
   354 			// Execute command and log parameters
       
   355 			INFO_PRINTF1(_L("execute BitBltMasked(TPoint, CWsBitmap*, TRect, CWsBitmap*, TBool)"));
       
   356 			iWindowGc->BitBltMasked(point, wsBitmap, sourceRect, maskBitmap, invertMask);
       
   357 			}
       
   358 		}
       
   359 	}
       
   360 
       
   361 void CT_DataWindowGc::DoCmdSetDitherOrigin(const TDesC& aSection)
       
   362 	{
       
   363 	TPoint	point;
       
   364 	if ( GetPointFromConfig(aSection, KFldPoint, point) )
       
   365 		{
       
   366 		INFO_PRINTF1(_L("CWindowGc::SetDitherOrigin"));
       
   367 		iWindowGc->SetDitherOrigin(point);
       
   368 		}
       
   369 	else
       
   370 		{
       
   371 		ERR_PRINTF2(_L("Missing parameter %S"), &KFldPoint());
       
   372 		SetBlockResult(EFail);
       
   373 		}
       
   374 	}
       
   375 
       
   376 void CT_DataWindowGc::DoCmdSetOpaque(const TDesC& aSection)
       
   377 	{
       
   378 	TBool	drawOpaque=ETrue;
       
   379 	if(	GetBoolFromConfig(aSection, KFldDrawOpaque(), drawOpaque))
       
   380 		{
       
   381 		INFO_PRINTF1(_L("CWindowGc::SetOpaque"));
       
   382 		iWindowGc->SetOpaque(drawOpaque);
       
   383 		}
       
   384 	else
       
   385 		{
       
   386 		ERR_PRINTF2(_L("Missing parameter %S"), &KFldDrawOpaque());
       
   387 		SetBlockResult(EFail);
       
   388 		}
       
   389 	}
       
   390 
       
   391 void CT_DataWindowGc::DoCmdDrawWsGraphicL(const TDesC& aSection)
       
   392 	{
       
   393 	TBool	dataOk=ETrue;
       
   394 
       
   395 	// Get test data for command input parameter(s)
       
   396 	TWsGraphicId	datId(0);
       
   397 	if ( !GetWsGraphicIdFromConfigL(aSection, KFldId, datId) )
       
   398 		{
       
   399 		dataOk=EFalse;
       
   400 		ERR_PRINTF2(KLogMissingParameter, &KFldId);
       
   401 		SetBlockResult(EFail);
       
   402 		}
       
   403 
       
   404 	TRect	datDestRect;
       
   405 	if ( !GetRectFromConfig(aSection, KFldDestRect, datDestRect) )
       
   406 		{
       
   407 		dataOk=EFalse;
       
   408 		ERR_PRINTF2(KLogMissingParameter, &KFldDestRect);
       
   409 		SetBlockResult(EFail);
       
   410 		}
       
   411 
       
   412 	if ( dataOk )
       
   413 		{
       
   414 		RWsGraphicMsgBuf*	pData = NULL;
       
   415 		TWsGraphicAnimation* pWsga = NULL;
       
   416 		if ( CT_GraphicsUtil::GetWsGraphicMsgBufL(*this, aSection, KFldData, pData) )
       
   417 			{
       
   418 			// Execute command and log parameters
       
   419 			INFO_PRINTF1(_L("execute DrawWsGraphic(TWsGraphicId, TRect, TDesC8)"));
       
   420 			iWindowGc->DrawWsGraphic(datId, datDestRect, pData->Pckg());
       
   421 			}
       
   422 		else if( CT_GraphicsUtil::GetWsGraphicAnimationL(*this, aSection, KFldWsga, pWsga) )
       
   423 			{
       
   424 			INFO_PRINTF1(_L("execute DrawWsGraphic(TWsGraphicId, TRect, TDesC8)"));
       
   425 			iWindowGc->DrawWsGraphic(datId, datDestRect, pWsga->Pckg());
       
   426 			}
       
   427 		else
       
   428 			{
       
   429 			// Execute command and log parameters
       
   430 			INFO_PRINTF1(_L("execute DrawWsGraphic(TWsGraphicId, TRect)"));
       
   431 			iWindowGc->DrawWsGraphic(datId, datDestRect);
       
   432 			}
       
   433 		// No command return value and output parameter to display and check
       
   434 		}
       
   435 	}
       
   436 
       
   437