symbian4container2.cpp

来自「S60 3版 音乐播放器及进度条实现 功能:前后倒放歌曲及暂停等功能」· C++ 代码 · 共 200 行

CPP
200
字号
/*
============================================================================
Name        : CSymbian4Container2 from Symbian3Container2.cpp
Author      : 
Version     :
Copyright   : Your copyright notice
Description : Container control implementation
============================================================================
*/

// INCLUDE FILES
#include  "Symbian4Container2.h"
#include <aknviewappui.h>
#include <eiklabel.h>  // for example label control
#include <eikedwin.h>
#include "Symbian4Appui.h"
#include <aknlists.h>
#include "eikenv.h"
#include <eikbtgpc.h>
#include <eikclbd.h>
#include <eiktxlbm.h> 


// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CSymbian4Container2::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
CSymbian4Container2::CSymbian4Container2(TBool ibool)
{
	abool=ibool;
}

void CSymbian4Container2::ConstructL(const TRect& aRect)
{
	CreateWindowL();


	m_pSingleListBox = new( ELeave ) CAknSingleNumberStyleListBox();
	CleanupStack::PushL(m_pSingleListBox);
	m_pSingleListBox->ConstructL(this, EAknListBoxMarkableList | EAknListBoxMultiselectionList);	
	m_pSingleListBox->SetContainerWindowL(*this);
	m_pSingleListBox->SetRect(aRect);
	//添加滚动条
	m_pSingleListBox->CreateScrollBarFrameL( ETrue );
	m_pSingleListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

	if(abool)
	{
	CSymbian4AppUi* pApp = (CSymbian4AppUi*)CEikonEnv::Static()->AppUi();
	m_pListBoxArray = pApp->GetPlayListPoint();

	CTextListBoxModel* model = m_pSingleListBox->Model();
	// set items and ownership
	model->SetItemTextArray( m_pListBoxArray );
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
    }
	m_pSingleListBox->HandleItemAdditionL();
	
	CleanupStack::Pop(1);	// !!! (2);

	m_pSingleListBox->ActivateL();
	m_pSingleListBox->SetFocus( ETrue );


	m_pSingleListBox->ItemDrawer()->ColumnData()->SetMarqueeParams (5, 50, 1000000, 200000);
	m_pSingleListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
	SetRect(aRect);
	ActivateL();

}

// Destructor
CSymbian4Container2::~CSymbian4Container2()
{
	
	delete m_pSingleListBox;
	m_pSingleListBox=NULL;
}

// ---------------------------------------------------------
// CSymbian4Container2::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//

void CSymbian4Container2::SizeChanged()
{
	CCoeControl::SizeChanged();
	if (m_pSingleListBox)
		m_pSingleListBox->SetRect(Rect());
	// TODO: Add here control resize code etc.
	//	iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
	//	iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}

// ---------------------------------------------------------
// CSymbian4Container2::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSymbian4Container2::CountComponentControls() const
{
	return 1; // return nbr of controls inside this container
}

// ---------------------------------------------------------
// CSymbian4Container2::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSymbian4Container2::ComponentControl(TInt aIndex) const
{
	switch ( aIndex )
	{
	case 0:
		return m_pSingleListBox;

	default:
		return NULL;
	}
}

// ---------------------------------------------------------
// CSymbian4Container2::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSymbian4Container2::Draw(const TRect& aRect) const
{
	CWindowGc& gc = SystemGc();
	// TODO: Add your drawing code here
	// example code...
	gc.SetPenStyle( CGraphicsContext::ENullPen );
	gc.SetBrushColor( KRgbGray );
	gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
	gc.DrawRect( aRect );
}

// ---------------------------------------------------------
// CSymbian4Container2::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSymbian4Container2::HandleControlEventL(
	CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
	// TODO: Add your control event handler code here

}

void CSymbian4Container2::AddInfoToList(TInt aIndex, const TDesC& aText)
{
	TBuf<64> sBuf;
	sBuf.AppendNum(aIndex); 
	sBuf.Append(_L("\t"));
	sBuf.Append(aText);

	m_pListBoxArray->AppendL(sBuf);

	// update listbox
	m_pSingleListBox->HandleItemAdditionL();
}


TInt CSymbian4Container2::GetSelectedItem() const
{
	return iIndex;
}
TKeyResponse CSymbian4Container2::OfferKeyEventL( 
	const TKeyEvent& aKeyEvent, 
	TEventCode aType )
{
	if (!abool)
	{
		return;
	}
	if(NULL != m_pSingleListBox)
	{
		if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
		{   
			if(iIndex<m_pListBoxArray->Count()) 
				iIndex++;
			if(iIndex==m_pListBoxArray->Count())
				iIndex=0;
			return m_pSingleListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
		{
			if(iIndex!=0)
				iIndex--;
			if(iIndex==0)
				iIndex=m_pListBoxArray->Count();
			return m_pSingleListBox->OfferKeyEventL(aKeyEvent, aType);
		}
		return EKeyWasConsumed;
	}
	return EKeyWasNotConsumed;

}

⌨️ 快捷键说明

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