commonuisupport/grid/tef/TESTIMG.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2005-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 // Implements the CTestLableImg class which is used as a Grid Label
       
    15 // for Grid0Step. Provides handlers to draw labels.\n
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <coedef.h>
       
    25 #include "TESTIMG.H"
       
    26 
       
    27 
       
    28 #define KRgbGridLabels	KRgbDitheredLightGray
       
    29 /**
       
    30   Two argument Constructor with font specification and an Interface class for mapping between twips 
       
    31   and device-specific units (pixels) as arguments.\n 
       
    32 */
       
    33 CTestLabelImg::CTestLabelImg(const TFontSpec& aFontSpec,MGraphicsDeviceMap* aGraphicsDeviceMap)
       
    34 	: CGridLabelImg(aFontSpec,aGraphicsDeviceMap)
       
    35 	{
       
    36 	}
       
    37 /**
       
    38   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
    39   Function which draws the  Label for each row of the grid table.\n
       
    40 */	
       
    41 void CTestLabelImg::DrawRowLabelL(CGraphicsContext *aGc,TInt aRow,const TRect &aRect) const
       
    42 	{
       
    43 	TRect rect=aRect;
       
    44 	aGc->SetPenColor(iGridColors.iLines);
       
    45 	--rect.iBr.iY;
       
    46 	aGc->DrawLine(TPoint(rect.iTl.iX,rect.iBr.iY),rect.iBr);
       
    47 	rect.iBr.iX-=ERowCursorDiameterInPixels;
       
    48 	TInt offset = rect.Height()-iFont->DescentInPixels();
       
    49 	TBuf<32> buf;
       
    50 	buf.Num(aRow+1);
       
    51 	aGc->UseFont(iFont);
       
    52 	aGc->SetPenColor(iGridColors.iForeground);
       
    53 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    54 	aGc->SetBrushColor(iGridColors.iBackground);
       
    55 	aGc->DrawText(buf,rect,offset,CGraphicsContext::ECenter);
       
    56 	rect.iTl.iX=rect.iBr.iX;
       
    57 	rect.iBr.iX+=ERowCursorDiameterInPixels;
       
    58 	TGridUtils::FillRect(aGc, iGridColors.iBackground, rect);
       
    59 	}
       
    60 /**
       
    61   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
    62   Function which draws the  Label for each column of the grid table.\n
       
    63 */	
       
    64 void CTestLabelImg::DrawColLabelL(CGraphicsContext *aGc,TInt aCol,const TRect &aRect) const
       
    65 	{
       
    66 	TRect rect=aRect;
       
    67 	aGc->SetPenColor(KRgbDarkGray);
       
    68 	--rect.iBr.iY;
       
    69 	TPoint point(rect.iTl.iX,rect.iBr.iY);
       
    70 	aGc->DrawLine(point,rect.iBr);
       
    71 	--rect.iBr.iY;
       
    72 	--point.iY;
       
    73 	aGc->DrawLine(point,rect.iBr);
       
    74 	TBuf<32> buf;
       
    75 	if (aCol>25)
       
    76 		buf.Append(aCol/26+'A'-1);
       
    77 	buf.Append(aCol%26+'A');
       
    78 	aGc->UseFont(iFont);
       
    79 	aGc->SetPenColor(iGridColors.iForeground);
       
    80 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    81 	aGc->SetBrushColor(iGridColors.iBackground);
       
    82 	aGc->DrawText(buf,rect,rect.Height()-iFont->DescentInPixels(),CGraphicsContext::ELeft);
       
    83 	aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
    84 	}
       
    85 /**
       
    86   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
    87   Gets the width of the side label.\n
       
    88   @return  The width of the side label in pixels.\n
       
    89   
       
    90 */
       
    91 TInt CTestLabelImg::SideLabelWidthInPixels(TInt aStartRow,TInt aEndRow) const
       
    92 	{
       
    93 	TInt maxLen=Max(Abs(aStartRow),Abs(aEndRow));
       
    94 	if (maxLen<9)
       
    95 		maxLen=9;	//Single digit labels must be same width as double digit labels
       
    96 	TBuf<32> buf;
       
    97 	buf.Num(maxLen+1);
       
    98 	return (iFont->TextWidthInPixels(buf) + ERowCursorDiameterInPixels
       
    99 		+ iGraphicsDeviceMap->HorizontalTwipsToPixels(ESideLabelMarginWidthInTwips));
       
   100 	}
       
   101 /**
       
   102   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   103   Draw function for the row cursor of the gridcell.\n
       
   104 */
       
   105 void CTestLabelImg::DrawRowCursorL(CGraphicsContext* aGc,const TRect& aRect) const
       
   106 	{
       
   107 	TRect rect=aRect;
       
   108 	rect.iTl.iX=rect.iBr.iX-ERowCursorDiameterInPixels-1;
       
   109 	TInt midY=rect.iTl.iY+rect.Height()/2;
       
   110 	rect.iTl.iY=midY-ERowCursorDiameterInPixels/2;
       
   111 	rect.iBr.iY=midY+ERowCursorDiameterInPixels/2;
       
   112 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   113 	aGc->SetBrushColor(iGridColors.iForeground);
       
   114 	aGc->DrawEllipse(rect);
       
   115 	aGc->SetBrushStyle(CGraphicsContext::ENullBrush);
       
   116 	aGc->SetBrushColor(iGridColors.iBackground);
       
   117 	}
       
   118 /**
       
   119   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   120   Function that draws the top left label of the grid table.\n
       
   121 */
       
   122 void CTestLabelImg::DrawTopLeftLabelL(CGraphicsContext* aGc,const TRect& aRect) const
       
   123 	{
       
   124 	TRect rect=aRect;
       
   125 	aGc->SetPenColor(KRgbDarkGray);
       
   126 	--rect.iBr.iY;
       
   127 	TPoint point(rect.iTl.iX,rect.iBr.iY);
       
   128 	aGc->DrawLine(point,rect.iBr);
       
   129 	--rect.iBr.iY;
       
   130 	--point.iY;
       
   131 	aGc->DrawLine(point,rect.iBr);
       
   132 	TGridUtils::FillRect(aGc,iGridColors.iBackground,rect);
       
   133 	}
       
   134 
       
   135 
       
   136 /**
       
   137   Constructor for the grid cell.\n
       
   138   Initializes the font for a grid cell.\n
       
   139   Initializes the iData array with some test data.\n
       
   140   The data will be returned by invoking GetL function.
       
   141   The GetL function is used to get the data in a grid cell.\n
       
   142 */
       
   143 CTestCellImg::CTestCellImg(const CFont *aFont)
       
   144 	: iFont(aFont)
       
   145 	{
       
   146 	iData[0].iPos=TCellRef(2,2);
       
   147 	iData[0].iBuf=_L("Some");
       
   148 	iData[1].iPos=TCellRef(2,4);
       
   149 	iData[1].iBuf=_L("Hard");
       
   150 	iData[2].iPos=TCellRef(3,3);
       
   151 	iData[2].iBuf=_L("Coded");
       
   152 	iData[3].iPos=TCellRef(4,2);
       
   153 	iData[3].iBuf=_L("Test");
       
   154 	iData[4].iPos=TCellRef(4,4);
       
   155 	iData[4].iBuf=_L("Data");
       
   156 	}
       
   157 /**
       
   158   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   159   Draw function for the grid cell and the data contained in the cell.\n
       
   160   Calculates the effective rectange and sets the brush style and colour.\n
       
   161   Redraws the text in the grid cell .\n
       
   162 */
       
   163 void CTestCellImg::DrawL(CGraphicsContext* aGc,const TCellRef& aCell,const TRect& aRect,const TRect& aClipRect) const
       
   164 	{
       
   165 	TInt offset = aRect.Height()-iFont->DescentInPixels();
       
   166 	TRect effectiveRect=aRect;
       
   167 	effectiveRect.iTl.iX-=BurstLeft();
       
   168 	effectiveRect.iBr.iX+=BurstRight();
       
   169 	aGc->UseFont(iFont);
       
   170 	aGc->SetPenColor(iGridColors.iForeground);
       
   171 	TRect realClipRect=aRect;
       
   172 	realClipRect.Grow(1,1);
       
   173 	realClipRect.Intersection(effectiveRect);
       
   174 	realClipRect.Intersection(aClipRect);
       
   175 	aGc->SetClippingRect(realClipRect);
       
   176 	aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   177 	aGc->SetBrushColor(iGridColors.iBackground);
       
   178 	const TDesC* des=GetL(aCell.iRow,aCell.iCol-BurstColOffset());
       
   179 	if (des)
       
   180 		aGc->DrawText(*des,effectiveRect,offset,CGraphicsContext::ELeft);
       
   181 	else
       
   182 		{
       
   183 		aGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   184 		aGc->DrawRect(effectiveRect);
       
   185 		}
       
   186 	aGc->CancelClippingRect();
       
   187 	aGc->Reset();
       
   188 	}
       
   189 /**
       
   190   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   191   @return Width of the text in pixels contained in the grid cell.\n
       
   192 */
       
   193 TInt CTestCellImg::DataWidthInPixelsL(const TCellRef& aCell) const
       
   194 	{
       
   195 	const TDesC* des=GetL(aCell.iRow,aCell.iCol);
       
   196 	if (des!=NULL)
       
   197 		return iFont->TextWidthInPixels(*des);
       
   198 	return 0;
       
   199 	}
       
   200 /**
       
   201   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   202   @return Boolean,True if the grid cell contains data else False.\n
       
   203 
       
   204 */
       
   205 TBool CTestCellImg::DoesCellContainDataL(const TCellRef& aCell) const
       
   206 	{
       
   207 	const TDesC* des=GetL(aCell.iRow,aCell.iCol);
       
   208 	return des!=NULL;
       
   209 	}
       
   210 /**
       
   211   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   212   @return Returns the data contained in the grid cell identified by the row and column arguments.\n
       
   213 */
       
   214 const TDesC* CTestCellImg::GetL(TInt aRow,TInt aCol) const
       
   215 //
       
   216 // Horrible array access function but OK for low ENumberOfItems
       
   217 	{
       
   218 	for (TInt ii=0;ii<ENumberOfItems;ii++)
       
   219 		{
       
   220 		if (iData[ii].iPos.iRow==aRow && iData[ii].iPos.iCol==aCol)
       
   221 			return &iData[ii].iBuf;
       
   222 		}
       
   223 	return NULL;
       
   224 	}
       
   225 
       
   226 
       
   227 /**
       
   228   Constructor for a Test Grid Table.\n
       
   229   Initializes the member variable indicating zero rows as False.\n
       
   230 */
       
   231 CTestGridTable::CTestGridTable()
       
   232 	: iZeroRows(EFalse)
       
   233 	{
       
   234 	}
       
   235 /**
       
   236   Auxiliary Function for T-CoGridStep-RunTestStepL.\n
       
   237   @return Boolean,True if rows are non Zero.\n
       
   238 */
       
   239 
       
   240 TBool CTestGridTable::RequestRow(TInt aRow,TInt& aReturnRow) const
       
   241 // Test function for grids with indefinite row boundaries
       
   242 	{
       
   243 	if (aRow>49)
       
   244 		aReturnRow=49;
       
   245 	else if (aRow<-21)
       
   246 		aReturnRow=-21;
       
   247 	else
       
   248 		aReturnRow=aRow;
       
   249 	return !iZeroRows;
       
   250 	}