⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 results_container.cpp

📁 一个关于s60第五版中的传感器的使用方法的例子
💻 CPP
字号:
#include <AknUtils.h>
#include <aknappui.h>
#include "Results_Container.h"

_LIT(KtxNoData				,"No Sensors");


/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
CResultsContainer* CResultsContainer::NewL(const TRect& aRect,RSensrvChannelInfoList& aChannelInfoList)
    {
    CResultsContainer* self = CResultsContainer::NewLC(aRect,aChannelInfoList);
    CleanupStack::Pop(self);
    return self;
    }
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
CResultsContainer* CResultsContainer::NewLC(const TRect& aRect,RSensrvChannelInfoList& aChannelInfoList)
    {
    CResultsContainer* self = new (ELeave) CResultsContainer(aChannelInfoList);
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
    }
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
CResultsContainer::CResultsContainer(RSensrvChannelInfoList& aChannelInfoList)
:iChannelInfoList(aChannelInfoList)
	{
	
    }
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
CResultsContainer::~CResultsContainer()
{	

}
	
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
void CResultsContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();    
    SetRect(aRect);
  	ActivateL();		
}

/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CResultsContainer::SizeChanged()
{	
	MakeListBoxL();	
}
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
TBool CResultsContainer::SelectSensorL(TInt& aIndex)
	{
	TBool ret(EFalse);
	
	if(iMyListBox)
		{
		aIndex = iMyListBox->CurrentItemIndex();
		ret = ETrue;
		}
	
	return ret;
	}
/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CResultsContainer::HandleResourceChange(TInt aType)
{
	TRect rect;
	TBool SetR(EFalse);
	
    if ( aType==KEikDynamicLayoutVariantSwitch )
    {  	
    	SetR = ETrue;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
    }
  
 
 	if(SetR)
 	{	    
	    SetRect(rect);
 	}
 	
	CCoeControl::HandleResourceChange(aType);
}
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
void CResultsContainer::MakeListBoxL()
{
	TInt MySetIndex(0);
	
	if(iMyListBox)
	{
		MySetIndex = iMyListBox->CurrentItemIndex();
	}
    
	delete iMyListBox;
	iMyListBox = NULL;

    iMyListBox   = new( ELeave ) CAknDoubleStyleListBox();
	iMyListBox->ConstructL(this,EAknListBoxSelectionList);

	iMyListBox->Model()->SetItemTextArray(GetArrayL());
   	iMyListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
	
	iMyListBox->CreateScrollBarFrameL( ETrue );
    iMyListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
	iMyListBox->SetRect(Rect());
	
	iMyListBox->View()->SetListEmptyTextL(KtxNoData);

	iMyListBox->ActivateL();

	TInt ItemsCount = iMyListBox->Model()->ItemTextArray()->MdcaCount();
	
	if(ItemsCount > MySetIndex && MySetIndex >= 0)
		iMyListBox->SetCurrentItemIndex(MySetIndex);
	else if(ItemsCount > 0)
		iMyListBox->SetCurrentItemIndex(0);
		
	UpdateScrollBar(iMyListBox);
	iMyListBox->DrawNow();
}
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
CDesCArray* CResultsContainer::GetArrayL(void)
{	
	CDesCArrayFlat* MyArray = new(ELeave)CDesCArrayFlat(1);
	CleanupStack::PushL(MyArray);
	
	TFileName hjelpper;
	
	for ( TInt i = 0; i < iChannelInfoList.Count() ; i++ )
	{
		hjelpper.Copy(_L("\t"));
		switch(iChannelInfoList[i].iQuantity)
		{
		case ESensrvQuantityNotUsed:
			hjelpper.Append(_L("NotUsed"));
			break;
		case ESensrvQuantityAcceleration:
			hjelpper.Append(_L("Acceleration"));
			break;
		case ESensrvQuantityTapping:
			hjelpper.Append(_L("Tapping"));
			break;
		case ESensrvQuantityOrientation:
			hjelpper.Append(_L("Orientation"));
			break;
		case ESensrvQuantityRotation:
			hjelpper.Append(_L("Rotation"));
			break;
		case ESensrvQuantityMagnetic:
			hjelpper.Append(_L("Magnetic"));
			break;
    	case ESensrvQuantityProximity:
    		hjelpper.Append(_L("Proximity"));
			break;
		case ESensrvQuantityNotdefined:
		default:
			hjelpper.Append(_L("Notdefined"));
			break;
		};
		hjelpper.Append(_L("\t"));
		
		switch(iChannelInfoList[i].iChannelType)
		{
		case KSensrvChannelTypeIdAccelerometerXYZAxisData:
			hjelpper.Append(_L("TypeIdAccelerometerXYZAxisData"));
			break;
		case KSensrvChannelTypeIdAccelerometerDoubleTappingData:
			hjelpper.Append(_L("TypeIdAccelerometerDoubleTappingData"));
			break;
		case KSensrvChannelTypeIdOrientationData:
			hjelpper.Append(_L("TypeIdOrientationData"));
			break;
		case KSensrvChannelTypeIdRotationData:
			hjelpper.Append(_L("TypeIdRotationData"));
			break;
		case KSensrvChannelTypeIdMagnetometerXYZAxisData:
			hjelpper.Append(_L("MagnetometerXYZAxisData"));
			break;
		default:
			hjelpper.Append(_L(",Unk: "));
			hjelpper.AppendNum(iChannelInfoList[i].iChannelType,EHex);
			break;
		};
		
		MyArray->AppendL(hjelpper);
	}

	CleanupStack::Pop(MyArray);
	return MyArray;
}
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
void CResultsContainer::UpdateScrollBar(CEikListBox* aListBox)
    {
    if (aListBox)
        {   
        TInt pos(aListBox->View()->CurrentItemIndex());
        if (aListBox->ScrollBarFrame())
            {
            aListBox->ScrollBarFrame()->MoveVertThumbTo(pos);
            }
        }
    }
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
TKeyResponse CResultsContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
	TKeyResponse Ret = EKeyWasNotConsumed;
	
	if(iMyListBox)
	{
		Ret = iMyListBox->OfferKeyEventL(aKeyEvent,aType);
	}
    
	return Ret;
}
  	
/*
-----------------------------------------------------------------------

-----------------------------------------------------------------------
*/
TInt CResultsContainer::CountComponentControls() const
{
	if(iMyListBox)
	{
		return 1;
	}
	else
		return 0;
}

/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
CCoeControl* CResultsContainer::ComponentControl(TInt /*aIndex*/) const
{	
	return iMyListBox;
}

/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
void CResultsContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -