cardclipcontainer.cpp

来自「symbian 3nd 实现短信息收发」· C++ 代码 · 共 215 行

CPP
215
字号
#include <FrMes.rsg>
#include "FrMes.hrh"
#include "CardClipContainer.h"


#include <aknlists.h> // for avrell style listbox
#include "FrMesAppUi.h"
#include "BookEngine.h"
#include <aknquerydialog.h>//CAknQueryDialog
// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CCardClipContainer::CCardClipContainer()
    {
	m_pListBox		=	NULL;
	m_pListBoxArray	=	NULL;
    }

// EPOC default constructor can leave.
void CCardClipContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

	//listbox
	m_pListBox = new( ELeave ) CAknSingleNumberStyleListBox();
	CleanupStack::PushL(m_pListBox);
	m_pListBox->ConstructL(this, EAknListBoxMarkableList | EAknListBoxMultiselectionList);	
	m_pListBox->SetContainerWindowL( *this );
	m_pListBox->SetRect(aRect);
    m_pListBox->CreateScrollBarFrameL( ETrue );
    m_pListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	//添加项目列表
	m_pListBoxArray = new (ELeave) CDesCArrayFlat(10);
	CleanupStack::PushL(m_pListBoxArray);
	CTextListBoxModel* model = m_pListBox->Model();
	model->SetItemTextArray( m_pListBoxArray );
	model->SetOwnershipType(ELbmDoesNotOwnItemArray);
	CleanupStack::Pop(2);

	m_pListBox->SetFocus( ETrue );

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CCardClipContainer::~CCardClipContainer()
    {
	if (m_pListBox) 
	{
		delete m_pListBox;
		m_pListBox	=	NULL;
	}
	if (m_pListBoxArray) 
	{
		delete	m_pListBoxArray;
		m_pListBoxArray	=	NULL;
	}
    }

// ---------------------------------------------------------
// CAknExEditorContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//

void CCardClipContainer::FocusTo(TInt aCommand)
    {
    }

// ---------------------------------------------------------
// CCardClipContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CCardClipContainer::SizeChanged()
    {
	if (m_pListBox) 
	{
		m_pListBox->SetRect(Rect());
	}
    }

// ---------------------------------------------------------
// CCardClipContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CCardClipContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CCardClipContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CCardClipContainer::ComponentControl(TInt aIndex) const
    {
    return m_pListBox;
    }

// ---------------------------------------------------------
// CCardClipContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CCardClipContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbBlue);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
    }

// ---------------------------------------------------------
// CCardClipContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CCardClipContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
    {
	if (m_pListBox) 
	{
		return m_pListBox->OfferKeyEventL(aKeyEvent,	aType);
	}
    return EKeyWasNotConsumed;
    }


// ---------------------------------------------------------
// CCardClipContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CCardClipContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    }

void CCardClipContainer::AddInfoToList(const TDesC& aText)
{
	TBuf<16>	sBuf;
	sBuf.Append(_L("\t"));
	sBuf.Append(aText);
	m_pListBoxArray->AppendL(sBuf);
	m_pListBox->HandleItemAdditionL();
}

void CCardClipContainer::DisplayList()
{
	CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();
	TInt aCount = pApp->iPhoneBookArray->Count();
	m_pListBoxArray->Reset();
	if(aCount>0)
	{
		for(int i=0;i<aCount;i++)
		{
			HBufC* aFamilyName = NULL;
			HBufC* aFirstName = NULL;
			HBufC* aTelephone = NULL;
 			aFamilyName = pApp->iPhoneBookArray->At(i)->GetLastName();
			aFirstName = pApp->iPhoneBookArray->At(i)->GetFirstName();
			aTelephone = pApp->iPhoneBookArray->At(i)->GetTelephone();
			TBuf<16> aText;
            aText.Append(*aFamilyName);
 			aText.Append(*aFirstName);
			AddInfoToList(aText);
		}
		m_pListBox->SetCurrentItemIndex(0);
	}	
}

void CCardClipContainer::DeleteInfo(TDes& sTemp)
{
	CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();	
	
	TInt aCount = pApp->iPhoneBookArray->Count();	
	if(aCount == 0)
		return;

	CAknQueryDialog* pdialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
	TBool aResult=pdialog->ExecuteLD( R_QTN_FRMES_DIALOG ,sTemp);

	if (aResult)
	{
 		CTextListBoxModel* model = m_pListBox->Model();	//Getting ListBox's Model

		if (model->NumberOfItems() >= 0)	//Judging ListBox items is or not null
		{
 			CDesCArray* itemArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
 			TInt currentIndex = GetCurrentItemIndex();	//Getting selected item
			pApp->iBookEngine->DeleteUserFromBook(pApp->iPhoneBookArray->At(currentIndex)->GetItemID());
			delete pApp->iPhoneBookArray->At(currentIndex);
			pApp->iPhoneBookArray->Delete(currentIndex);
		}
	}
}

TInt CCardClipContainer::GetCurrentItemIndex()
{
	return m_pListBox->CurrentItemIndex();
}

// End of File  

⌨️ 快捷键说明

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