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

📄 maincontainer.cpp

📁 symbian和旗下的HTTPENGINE的相关代码
💻 CPP
字号:
#include <aknlists.h> //listbox
#include <gulicon.h>
#include <aknutils.h>
#include <avkon.hrh>
#include <akntitle.h>
#include <eiklabel.h>
#include <AknIconArray.h> 
#include <eikclbd.h> //CColumnListBoxData


#include "MainContainer.h"
#include "ASSISTANTAppUi.h"

const TInt KNumberOfIcons(2);

CMainContainer::CMainContainer()
{
	m_pListBoxArray=NULL;
}

// EPOC default constructor can leave.
void CMainContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
//create listbox
	m_pListBox = new( ELeave ) CAknSingleGraphicStyleListBox();
	CleanupStack::PushL(m_pListBox);
	m_pListBox->ConstructL(this, EAknListBoxMarkableList);	
	m_pListBox->SetContainerWindowL( *this );
	m_pListBox->SetRect(aRect);
    m_pListBox->CreateScrollBarFrameL( ETrue );
    m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );


//add icons
	CASSISTANTAppUi* pApp = (CASSISTANTAppUi*)CEikonEnv::Static()->AppUi();
	CArrayPtr<CGulIcon>* icons = new( ELeave ) CAknIconArray(KNumberOfIcons);
	CleanupStack::PushL( icons );
	icons->AppendL(pApp->LoadGraphicsL(0));
	icons->AppendL(pApp->LoadGraphicsL(1));
	icons->AppendL(pApp->LoadGraphicsL(2));
	m_pListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);


//add informations
	m_pListBoxArray = new (ELeave) CDesCArrayFlat(10);
	CleanupStack::PushL(m_pListBoxArray);
	CTextListBoxModel* model = m_pListBox->Model();	
	model->SetItemTextArray( m_pListBoxArray );
	model->SetOwnershipType(ELbmOwnsItemArray);	
//	addInfotolist(_L("1"),_L("mecimeci"));
	CleanupStack::Pop(3);
/*
	CTextListBoxModel* model = m_pListBox->Model();  // not taking ownership
	model->SetOwnershipType (ELbmOwnsItemArray);
	CDesCArray* savedGamesArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	LoadSavedGamesL(*savedGamesArray);
	CleanupStack::Pop(2);
*/
    SetRect( aRect );
    ActivateL();
}

// destructor
CMainContainer::~CMainContainer()
{
	MEMORY_FREE(m_pListBox);

	m_sIndicesArray.Close();
 //	IndicesArray.Reset();
}

void CMainContainer::SizeChanged()
{
	m_pListBox->SetRect(Rect());
}

// ---------------------------------------------------------
// CMainContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CMainContainer::CountComponentControls() const
{
	// return number of controls inside this container
	return 1; 
}

// ---------------------------------------------------------
// CMainContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CMainContainer::ComponentControl( TInt aIndex ) const
{
	switch (aIndex)
	{
		case 0:
			return m_pListBox;
		default:
			return NULL;
	}
}

// ---------------------------------------------------------
// CMainContainer::Draw(const TRect& aRect) const
// handle the message when client region must be redrawn.
// ---------------------------------------------------------
//
void CMainContainer::Draw( const TRect& /*aRect*/ ) const
{
	CWindowGc& gc = SystemGc();
	gc.Clear(Rect());

//	gc.DrawRect(TRect(TPoint(10, 10), TSize(20, 20)));
}

// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
//           const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CMainContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
	if (m_pListBox) 	
		return m_pListBox->OfferKeyEventL(aKeyEvent, aType );
	else
		return EKeyWasNotConsumed;
	
}
void CMainContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
{
	
	// if the Select Key has been pressed
	if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
		(aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
	{
			GetSelectedL();
	}
}
void CMainContainer::AddInfotolist(const TDesC& aIcon, const TDesC& aName)
{
	TBuf<64> sTmpBuf;
	sTmpBuf.Copy(aIcon);
	sTmpBuf.Append(_L("\t"));
	sTmpBuf.Append(aName);	
	m_pListBoxArray->AppendL(sTmpBuf);
	m_pListBox->HandleItemAdditionL();
}

void CMainContainer::HandleMarkCommandL(TInt aCommand)
{
	if (m_pListBox)
	{
		AknSelectionService::HandleMarkableListProcessCommandL(aCommand, m_pListBox);
	}
}

void CMainContainer::GetSelectedL()
{
	if (m_pListBox)
	{
		CTextListBoxModel* model = m_pListBox->Model();
		
		if (model->NumberOfItems() > 0)
		{			
			// Create a copy of the currently selected items (copyIndices) in numeric order
			const CListBoxView::CSelectionIndexArray* selectionIndices = m_pListBox->SelectionIndexes();			
			
			TInt numberSelectedContacts = selectionIndices->Count();
			for (TInt i=0; i< numberSelectedContacts; i++)
			{
				m_sIndicesArray.Append(selectionIndices->At(i));
			}
		}
	}
}



// End of File  

⌨️ 快捷键说明

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