os/kernelhwsrv/kerneltest/f32test/bench/t_select.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/bench/t_select.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,296 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\bench\t_select.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32test.h>
    1.23 +#include "t_select.h"
    1.24 +//
    1.25 +LOCAL_D const TInt KArrayGranularity=16;
    1.26 +LOCAL_D const TInt KDriveSelector=0;
    1.27 +
    1.28 +CSelectionBox* CSelectionBox::NewL(CConsoleBase* aConsole)
    1.29 +//
    1.30 +// Create a CSelection box
    1.31 +//
    1.32 +	{
    1.33 +
    1.34 +	CSelectionBox* selBox=new(ELeave) CSelectionBox;
    1.35 +	CleanupStack::PushL(selBox);
    1.36 +	selBox->iText=new(ELeave) CArrayFixFlat<TSelBoxEntry>(KArrayGranularity);
    1.37 +	TSelBoxEntry firstEntry;
    1.38 +	firstEntry.iText=_L("Exit").AllocL();
    1.39 +	CleanupStack::PushL(firstEntry.iText);
    1.40 +	selBox->iText->InsertL(0,firstEntry);
    1.41 +	CleanupStack::Pop(2);
    1.42 +	selBox->iConsole=aConsole;
    1.43 +	return(selBox);
    1.44 +	}
    1.45 +
    1.46 +CSelectionBox::~CSelectionBox()
    1.47 +//
    1.48 +// Destructor
    1.49 +//
    1.50 +	{
    1.51 +
    1.52 +	if (iText==NULL)
    1.53 +		return;
    1.54 +	TInt count=iText->Count();
    1.55 +	while (count--)
    1.56 +		User::Free((*iText)[count].iText);
    1.57 +	delete iText;
    1.58 +	}
    1.59 +
    1.60 +void CSelectionBox::AddLineL(const TDesC& aText,const TCallBack& aCallBack)
    1.61 +//
    1.62 +// Add a line to be displayed
    1.63 +//
    1.64 +	{
    1.65 +	
    1.66 +	TSelBoxEntry entry;
    1.67 +	entry.iText=aText.AllocL();
    1.68 +	CleanupStack::PushL(entry.iText);
    1.69 +	entry.iCallBack=aCallBack;
    1.70 +	iText->InsertL(iText->Count()-1,entry);
    1.71 +	CleanupStack::Pop();
    1.72 +	}
    1.73 +
    1.74 +void CSelectionBox::ReplaceTextL(TInt aLine,const TDesC& aText)
    1.75 +//
    1.76 +// Replace text at aLine
    1.77 +//
    1.78 +	{
    1.79 +
    1.80 +	TSelBoxEntry& entry=(*iText)[aLine];
    1.81 +	User::Free(entry.iText);
    1.82 +	entry.iText=aText.AllocL();
    1.83 +	}
    1.84 +
    1.85 +void CSelectionBox::Display()
    1.86 +//
    1.87 +// Display the box
    1.88 +//
    1.89 +	{
    1.90 +	iConsole->ClearScreen();
    1.91 +
    1.92 +	TSize size=iConsole->ScreenSize();
    1.93 +	TInt widestLine=0;
    1.94 +	TInt items=iText->Count();
    1.95 +
    1.96 +	TInt count=items;
    1.97 +	while (count--)
    1.98 +		widestLine=Max(widestLine,(*iText)[count].iText->Length());
    1.99 +
   1.100 +	iTopLeft=TPoint((size.iWidth-widestLine)/2,(size.iHeight-items)/2-2);
   1.101 +	TInt downOffset=iTopLeft.iY;
   1.102 +
   1.103 +	for (count=0;count<items;count++)
   1.104 +		{
   1.105 +		if (count==iHighLight)
   1.106 +			DisplayHighLight(ETrue);
   1.107 +		iConsole->SetCursorPosAbs(TPoint(iTopLeft.iX,downOffset));
   1.108 +		iConsole->Printf(_L("%S"),(*iText)[count].iText);
   1.109 +		downOffset++;
   1.110 +		}
   1.111 +
   1.112 +	iConsole->SetCursorPosAbs(TPoint(iTopLeft.iX-1,iTopLeft.iY+iHighLight));
   1.113 +	}
   1.114 +
   1.115 +void CSelectionBox::DisplayHighLight(TBool aOn)
   1.116 +//
   1.117 +// Draw aHighLight to the left of aLine
   1.118 +//
   1.119 +	{
   1.120 +
   1.121 +	TBuf<1> cursor(1);
   1.122 +	cursor[0]=(TUint8)((aOn) ? 16 : 32);
   1.123 +	iConsole->SetCursorPosAbs(TPoint(iTopLeft.iX-2,iTopLeft.iY+iHighLight));
   1.124 +	iConsole->Printf(_L("%S"),&cursor);
   1.125 +	}
   1.126 +
   1.127 +TChar CSelectionBox::CurrentKeyPress()
   1.128 +	{return(iChar);}
   1.129 +
   1.130 +TInt CSelectionBox::CurrentDrive()
   1.131 +	{return(iCurrentDrive);}
   1.132 +
   1.133 +TBool CSelectionBox::MediaPresent(TInt aDrive)
   1.134 +//
   1.135 +// Return ETrue if a media is present in aDrive
   1.136 +//
   1.137 +	{
   1.138 +
   1.139 +	TDriveInfo driveInfo;
   1.140 +	iFs.Drive(driveInfo,aDrive);
   1.141 +	if (driveInfo.iType!=EMediaNotPresent)
   1.142 +		return(ETrue);
   1.143 +	return(EFalse);
   1.144 +	}
   1.145 +
   1.146 +TInt CSelectionBox::NextDrive(TInt aDrive)
   1.147 +//
   1.148 +// Find the next drive in the driveList
   1.149 +//
   1.150 +	{
   1.151 +
   1.152 +	for(TInt i=aDrive+1;i<=EDriveZ;i++)
   1.153 +		{
   1.154 +		if (iDriveList[i]!=0 && MediaPresent(i))
   1.155 +			return(i);
   1.156 +		}
   1.157 +	return(aDrive);
   1.158 +	}
   1.159 +		
   1.160 +TInt CSelectionBox::PreviousDrive(TInt aDrive)
   1.161 +//
   1.162 +// Find the next drive in the driveList
   1.163 +//
   1.164 +	{
   1.165 +
   1.166 +	for (TInt i=aDrive-1;i>=0;i--)
   1.167 +		{
   1.168 +		if (iDriveList[i]!=0 && MediaPresent(i))
   1.169 +			return(i);
   1.170 +		}
   1.171 +	return(aDrive);
   1.172 +	}
   1.173 +
   1.174 +void CSelectionBox::SetDriveName()
   1.175 +//
   1.176 +// Set the drive name
   1.177 +//
   1.178 +	{
   1.179 +
   1.180 +	TBuf<16> driveName;
   1.181 +	if (PreviousDrive(iCurrentDrive)!=iCurrentDrive)
   1.182 +		driveName+=_L("<-");
   1.183 +	driveName+=_L("Drive ");
   1.184 +	driveName.Append('A'+iCurrentDrive);
   1.185 +	driveName.Append(':');
   1.186 +	if (NextDrive(iCurrentDrive)!=iCurrentDrive)
   1.187 +		driveName+=_L("->");
   1.188 +	while (driveName.Length()<12)
   1.189 +		driveName+=_L(" ");
   1.190 +	(*iText)[0].iText->Des()=driveName;
   1.191 +	}
   1.192 +
   1.193 +void CSelectionBox::DisplayDrive()
   1.194 +//
   1.195 +// Display the drive
   1.196 +//
   1.197 +	{
   1.198 +
   1.199 +	iConsole->SetCursorPosAbs(iTopLeft);
   1.200 +	iConsole->Printf(_L("%S"),(*iText)[0].iText);
   1.201 +	iConsole->SetCursorPosAbs(TPoint(iTopLeft.iX-1,iTopLeft.iY));
   1.202 +	}
   1.203 +
   1.204 +GLDEF_C TInt ChangeDrives(TAny* aSelector)
   1.205 +//
   1.206 +// Move to next drive if it is mounted
   1.207 +//
   1.208 +	{
   1.209 +	CSelectionBox& selBox=*(CSelectionBox*)aSelector;
   1.210 +	TChar key=selBox.CurrentKeyPress();
   1.211 +	TInt drive=selBox.iCurrentDrive;
   1.212 +	if (key==EKeyLeftArrow)
   1.213 +		drive=selBox.PreviousDrive(selBox.iCurrentDrive);
   1.214 +	else if (key==EKeyRightArrow)
   1.215 +		drive=selBox.NextDrive(selBox.iCurrentDrive);
   1.216 +	selBox.iCurrentDrive=drive;
   1.217 +	selBox.SetDriveName();
   1.218 +	selBox.DisplayDrive();
   1.219 +	return(KErrNone);
   1.220 +	}
   1.221 +
   1.222 +void CSelectionBox::AddDriveSelectorL(RFs aFs)
   1.223 +//
   1.224 +// Add a drive selector to the list
   1.225 +//
   1.226 +	{
   1.227 +
   1.228 +	if (iDriveSelectorPresent)
   1.229 +		return;
   1.230 +	iDriveSelectorPresent=ETrue;
   1.231 +	iFs=aFs;
   1.232 +	iFs.DriveList(iDriveList);
   1.233 +	iCurrentDrive=EDriveC;
   1.234 +	TSelBoxEntry entry;
   1.235 +	entry.iText=_L("<-Drive X:->").AllocL();
   1.236 +	CleanupStack::PushL(entry.iText);
   1.237 +	entry.iCallBack=TCallBack(ChangeDrives,this);
   1.238 +	iText->InsertL(0,entry);
   1.239 +	CleanupStack::Pop();
   1.240 +	SetDriveName();
   1.241 +	}
   1.242 +
   1.243 +void CSelectionBox::Run()
   1.244 +//
   1.245 +// Display the box and handle keypresses
   1.246 +//
   1.247 +	{
   1.248 +	
   1.249 +	Display();
   1.250 +
   1.251 +	FOREVER
   1.252 +		{
   1.253 +		iChar=iConsole->Getch();
   1.254 +		switch (iChar)
   1.255 +	    	{
   1.256 +		case EKeyEscape:
   1.257 +			return;
   1.258 +		case EKeyHome:
   1.259 +			DisplayHighLight(EFalse);
   1.260 +			iHighLight=KDriveSelector;
   1.261 +			DisplayHighLight(ETrue);
   1.262 +			break;
   1.263 +		case EKeyLeftArrow:
   1.264 +			(*iText)[iHighLight].iCallBack.CallBack();
   1.265 +			break;
   1.266 +		case EKeyRightArrow:
   1.267 +			(*iText)[iHighLight].iCallBack.CallBack();
   1.268 +			break;
   1.269 +		case EKeyUpArrow:
   1.270 +			if (iHighLight)
   1.271 +				{
   1.272 +				DisplayHighLight(EFalse);
   1.273 +				iHighLight--;
   1.274 +				DisplayHighLight(ETrue);
   1.275 +				}
   1.276 +			break;
   1.277 +		case EKeyDownArrow:
   1.278 +			if (iHighLight+1<iText->Count())
   1.279 +				{
   1.280 +				DisplayHighLight(EFalse);
   1.281 +				iHighLight++;
   1.282 +				DisplayHighLight(ETrue);
   1.283 +				}
   1.284 +			break;
   1.285 +		case EKeyEnter:
   1.286 +			if (iHighLight+1==iText->Count())
   1.287 +				return;
   1.288 +			if (iHighLight==KDriveSelector && iDriveSelectorPresent)
   1.289 +				break;
   1.290 +			iConsole->ClearScreen();
   1.291 +			(*iText)[iHighLight].iCallBack.CallBack();
   1.292 +			Display();
   1.293 +			break;
   1.294 +		default:
   1.295 +			break;
   1.296 +			}
   1.297 +		}
   1.298 +	}
   1.299 +