📄 personinfocontainer.cpp
字号:
/*
* ============================================================================
* Name : CPersonInfoContainer from CCoeControl, MCoeControlObserver
* Part of : PersonInfo
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <eiklabel.h> // for example label control
#include <barsread.h> // for resource reader
#include <eikedwin.h> // for CEikEdwin
#include <eikgted.h> // for CEikGlobalTextEditor
#include <FrMes.rsg>
#include "FrMes.hrh"
#include "PersonInfoContainer.h"
#include "FrMesAppUi.h"
#include "FrMesDB.h"
#include <aknquerydialog.h>
#include <aknlists.h>
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CPersonInfoContainer::CPersonInfoContainer()
{
m_pListBox = NULL;
m_pListBoxArray = NULL;
}
// EPOC default constructor can leave.
void CPersonInfoContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//listbox
m_pListBox = new( ELeave ) CAknDoubleNumberStyleListBox();
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);
//Add Item List
m_pListBoxArray = new (ELeave) CDesCArrayFlat(3);
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
CPersonInfoContainer::~CPersonInfoContainer()
{
if(m_pListBox)
{
delete m_pListBox;
m_pListBox = NULL;
}
if(m_pListBoxArray)
{
delete m_pListBoxArray;
m_pListBoxArray = NULL;
}
}
// ---------------------------------------------------------
// CPersonInfoContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPersonInfoContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CPersonInfoContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPersonInfoContainer::SizeChanged()
{
if (m_pListBox)
{
m_pListBox->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CPersonInfoContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CPersonInfoContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CPersonInfoContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CPersonInfoContainer::ComponentControl(TInt aIndex) const
{
switch(aIndex)
{
case 0:
return m_pListBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CPersonInfoContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPersonInfoContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbCyan);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CPersonInfoContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
TKeyResponse CPersonInfoContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (m_pListBox)
return m_pListBox->OfferKeyEventL (aKeyEvent, aType);
else
return EKeyWasNotConsumed;
}
// ---------------------------------------------------------
// CPersonInfoContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPersonInfoContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
void CPersonInfoContainer::AddInfoToList(TInt aIndex, const TDesC& aText, const TDesC& sText)
{
TBuf<64> sBuf;
sBuf.AppendNum(aIndex);
sBuf.Append(_L("\t"));
sBuf.Append(aText);
sBuf.Append(_L("\t"));
sBuf.Append(sText);
m_pListBoxArray->AppendL(sBuf);
m_pListBox->HandleItemAdditionL();
}
void CPersonInfoContainer::DisplayList()
{
CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();
TInt aCount = pApp->m_pDB->iArray->Count();
m_pListBoxArray->Reset();
if(aCount>0)
{
for(int i=0;i<aCount;i++)
{
TBuf<16> aName;
TBuf<16> aCode;
pApp->m_pDB->GetItem(i,aName,aCode);
TBuf<32> aText;
TBuf<32> sText;
CEikonEnv::Static()->ReadResource(aText, R_QTN_FRMES_LISTBOX_NAME);
CEikonEnv::Static()->ReadResource(sText, R_QTN_FRMES_LISTBOX_TEL);
aText.Append(aName);
sText.Append(aCode);
AddInfoToList(i+1, aText, sText);
}
m_pListBox->SetCurrentItemIndex(0);
}
}
void CPersonInfoContainer::DeleteInfo()
{
CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();
TInt aCount = pApp->m_pDB->iArray->Count();
if(aCount == 0)
return;
CAknQueryDialog* pdialog = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
TBool aResult=pdialog->ExecuteLD( R_QTN_FRMES_DIALOG );
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
CFrMesAppUi* pApp = (CFrMesAppUi*)CEikonEnv::Static()->AppUi();
pApp->m_pDB->DelInfo(currentIndex);
}
}
}
TInt CPersonInfoContainer::GetCurrentItemIndex()
{
return m_pListBox->CurrentItemIndex();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -