📄 singlelistcontainer.cpp
字号:
/*
* ============================================================================
* Name : CSingleListContainer from CCoeControl, MCoeControlObserver
* Part of : Hello
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <aknlists.h>
#include <Helloldci.rsg>
#include "Helloldci.hrh"
#include "SingleListContainer.h"
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CSingleListContainer::CSingleListContainer()
{
m_pSingleList = NULL;
m_pListArray = NULL;
}
// EPOC default constructor can leave.
void CSingleListContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
m_pSingleList = new(ELeave) CAknSingleNumberStyleListBox;
m_pSingleList->SetContainerWindowL(*this);
m_pSingleList->ConstructL(this,EAknListBoxSelectionList);
//启动滚动条
m_pSingleList->CreateScrollBarFrameL(ETrue);
m_pSingleList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
//创建列表项数组
m_pListArray = new(ELeave) CDesCArrayFlat(10);
CTextListBoxModel* model = m_pSingleList->Model();
model->SetItemTextArray(m_pListArray);
//设置模型是否拥有数据,如果为ELbmDoesNotOwnItemArray,需要我们手动删除
//如果设置为ELbmOwnItemArray,则不需要我们做处理
model->SetOwnershipType(ELbmDoesNotOwnItemArray);//ELbmOwnItemArray
//添加数据
AddInfoToList(0,_L("hello!"));
AddInfoToList(1,_L("hello!"));
m_pSingleList->SetCurrentItemIndex(1);
SetRect(aRect);
ActivateL();
}
// Destructor
CSingleListContainer::~CSingleListContainer()
{
if(m_pSingleList)
{
delete m_pSingleList;
m_pSingleList = NULL;
}
if (m_pListArray)
{
m_pListArray->Reset();
delete m_pListArray;
m_pListArray = NULL;
}
}
// ---------------------------------------------------------
// CSingleListContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CSingleListContainer::SizeChanged()
{
if (m_pSingleList)
{
m_pSingleList->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CSingleListContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CSingleListContainer::CountComponentControls() const
{
//return 0; // return nbr of controls inside this container
return 1;
}
// ---------------------------------------------------------
// CSingleListContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CSingleListContainer::ComponentControl(TInt aIndex) const
{
return m_pSingleList;
}
// ---------------------------------------------------------
// CSingleListContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CSingleListContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CSingleListContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CSingleListContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
if(m_pSingleList)
{
return m_pSingleList->OfferKeyEventL(aKeyEvent,aType);
}
return EKeyWasNotConsumed;
}
void CSingleListContainer::AddInfoToList(TInt aNumber,const TDesC& aContent)
{
TBuf<32> sBuf;
sBuf.AppendNum(aNumber);
sBuf.Append(_L("\t"));
sBuf.Append(aContent);
m_pListArray->AppendL(sBuf);
//listbox添加数据
m_pSingleList->HandleItemAdditionL();
}
void CSingleListContainer::DelInfoFromList()
{
TInt currentIndex = m_pSingleList->CurrentItemIndex();
if (currentIndex == -1) return;
m_pListArray->Delete(currentIndex);
//删除最后一项有问题
// m_pSingleList->HandleItemRemovalL();
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(m_pSingleList,currentIndex,ETrue);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -