graphicsapitest/graphicssvs/gdi/src/T_DataPalette.cpp
changeset 111 29ddb8a72f0e
parent 110 7f25ef56562d
child 113 f3c3c510a760
child 152 9f1c3fea0f87
equal deleted inserted replaced
110:7f25ef56562d 111:29ddb8a72f0e
     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 "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:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_DataPalette
       
    23 */
       
    24 
       
    25 #include "T_DataPalette.h"
       
    26 #include "T_GraphicsUtil.h"
       
    27 
       
    28 
       
    29 /*@{*/
       
    30 ///	Parameters
       
    31 _LIT(KNumberOfColors,						"number_of_colors");
       
    32 _LIT(KDisplayMode,							"displaymode");
       
    33 
       
    34 ///	Commands
       
    35 _LIT(KCmdNewL,								"NewL");
       
    36 _LIT(KCmdNewDefaultL,						"NewDefaultL");
       
    37 _LIT(KCleanup,								"~");
       
    38 /*@}*/
       
    39 
       
    40 
       
    41 /**
       
    42 * Two phase constructor
       
    43 */
       
    44 CT_DataPalette* CT_DataPalette::NewL()
       
    45 	{
       
    46 	CT_DataPalette* ret = new (ELeave) CT_DataPalette();
       
    47 	CleanupStack::PushL(ret);
       
    48 	ret->ConstructL();
       
    49 	CleanupStack::Pop(ret);
       
    50 	return ret;
       
    51 	}
       
    52 
       
    53 
       
    54 /**
       
    55 * Protected constructor. First phase construction
       
    56 */
       
    57 CT_DataPalette::CT_DataPalette()
       
    58 :	CDataWrapperBase()
       
    59 ,	iPalette(NULL)
       
    60 	{
       
    61 	}
       
    62 
       
    63 
       
    64 /**
       
    65 * Protected second phase construction
       
    66 */
       
    67 void CT_DataPalette::ConstructL()
       
    68 	{
       
    69 	}
       
    70 
       
    71 
       
    72 /**
       
    73 * Destructor.
       
    74 */
       
    75 CT_DataPalette::~CT_DataPalette()
       
    76 	{
       
    77 	DestroyData();
       
    78 	}
       
    79 
       
    80 
       
    81 /**
       
    82 * cleanup implementation.
       
    83 */
       
    84 void CT_DataPalette::DestroyData()
       
    85 	{
       
    86 	delete iPalette;
       
    87 	iPalette = NULL;
       
    88 	}
       
    89 
       
    90 
       
    91 /**
       
    92 * Return a pointer to the object that the data wraps
       
    93 *
       
    94 * @return pointer to the object that the data wraps
       
    95 */
       
    96 TAny* CT_DataPalette::GetObject()
       
    97 	{
       
    98 	return iPalette;
       
    99 	}
       
   100 
       
   101 
       
   102 /**
       
   103 * Process a command read from the ini file
       
   104 *
       
   105 * @param aDataWrapper	test step requiring command to be processed
       
   106 * @param aCommand	the command to process
       
   107 * @param aSection		the entry in the ini file requiring the command to be processed
       
   108 *
       
   109 * @return ETrue if the command is processed
       
   110 */
       
   111 TBool CT_DataPalette::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   112 	{
       
   113 	TBool retVal = ETrue;
       
   114 
       
   115 	if (aCommand == KCmdNewL)
       
   116 		{
       
   117 		DoCmdNew(aSection);
       
   118 		}
       
   119 	else if (aCommand == KCmdNewDefaultL)
       
   120 		{
       
   121 		DoCmdNewDefault(aSection);
       
   122 		}
       
   123 	else if (aCommand == KCleanup)
       
   124 		{
       
   125 		DestroyData();
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		retVal=EFalse;
       
   130 		}
       
   131 
       
   132 	return retVal;
       
   133 	}
       
   134 
       
   135 
       
   136 ////////////////// COMMANDS IMPLEMENTATION  ////////////////////////
       
   137 
       
   138 /** Creates a default palette for the display mode specified */
       
   139 void CT_DataPalette::DoCmdNew(const TDesC& aSection)
       
   140 	{
       
   141 	INFO_PRINTF1(_L("Calls CPalette::NewL() creates a new palette with a given number of colors"));
       
   142 	// cleanup if any
       
   143 	delete iPalette;
       
   144 	iPalette = NULL;
       
   145 
       
   146 	// get number of colors from parameters
       
   147 	TInt	numberOfColors;
       
   148 	if(!GetIntFromConfig(aSection, KNumberOfColors(), numberOfColors))
       
   149 		{
       
   150 		ERR_PRINTF2(_L("No %S"), &KNumberOfColors());
       
   151 		SetBlockResult(EFail);
       
   152 		}
       
   153 	else
       
   154 		{
       
   155 		// create new palette
       
   156 		TRAPD(err, iPalette = CPalette::NewL(numberOfColors));
       
   157 
       
   158 		// check error code
       
   159 		if (err != KErrNone)
       
   160 			{
       
   161 			ERR_PRINTF2(_L("CPalette::NewL error: %d"), err);
       
   162 			SetBlockResult(EFail);
       
   163 			}
       
   164 		}
       
   165 	}
       
   166 
       
   167 
       
   168 /** Creates a default palette for the display mode specified */
       
   169 void CT_DataPalette::DoCmdNewDefault(const TDesC& aSection)
       
   170 	{
       
   171 	INFO_PRINTF1(_L("Calls CPalette::NewDefaultL() creating a default palette for the display mode specified"));
       
   172 
       
   173 	// cleanup if any
       
   174 	delete iPalette;
       
   175 	iPalette = NULL;
       
   176 
       
   177 	// get display mode from parameters
       
   178 	TDisplayMode	displayMode;
       
   179 	if ( !CT_GraphicsUtil::ReadDisplayMode(*this, aSection, KDisplayMode(), displayMode) )
       
   180 		{
       
   181 		ERR_PRINTF1(_L("No display mode"));
       
   182 		SetBlockResult(EFail);
       
   183 		}
       
   184 	else
       
   185 		{
       
   186 		// create new palette
       
   187 		TRAPD(err, iPalette = CPalette::NewDefaultL(displayMode));
       
   188 
       
   189 		// check error code
       
   190 		if (err != KErrNone)
       
   191 			{
       
   192 			ERR_PRINTF2(_L("CPalette::NewDefaultL error: %d"), err);
       
   193 			SetBlockResult(EFail);
       
   194 			}
       
   195 		}
       
   196 	}