📄 hellocontainer.cpp
字号:
#include <gulicon.h>
#include <aknutils.h>
#include <avkon.hrh>
#include <eiklabel.h>
#include <aknlists.h>
#include "HelloContainer.h"
#define MEM_FREE(a) if(a) {delete a; a=NULL;}
CHelloContainer::CHelloContainer()
{
//指针初始化
iHelpLabel = NULL;
iSingleList = NULL;
iListBoxItem = NULL;
}
// EPOC default constructor can leave.
void CHelloContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect( aRect );
// //创建Label对象
// iHelpLabel = new(ELeave) CEikLabel;
// //设置container指针
// iHelpLabel->SetContainerWindowL(*this);
// //设置显示的信息
// iHelpLabel->SetTextL(_L("Good Soft!"));
// //设置显示的位置
// iHelpLabel->SetExtent(TPoint(0,0), aRect.Size());
//
//动态创建listbox
iSingleList = new( ELeave ) CAknSingleNumberStyleListBox;
iSingleList->SetContainerWindowL( *this );
iSingleList->ConstructL( this, EAknListBoxSelectionList);
//设置滚动条
iSingleList ->CreateScrollBarFrameL(ETrue);
iSingleList ->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
//创建列表项数组
iListBoxItem = new (ELeave) CDesCArrayFlat(10);
CTextListBoxModel* model1 = iSingleList ->Model();
model1->SetItemTextArray(iListBoxItem);
model1->SetOwnershipType(ELbmOwnsItemArray);
//设置Listbox显示位置和焦点
iSingleList->SetExtent(TPoint(0, 0), aRect.Size());
//设置Listbox焦点
iSingleList->SetFocus(ETrue);
ActivateL();
}
// destructor
CHelloContainer::~CHelloContainer()
{
//析构Label指针
MEM_FREE(iHelpLabel);
MEM_FREE(iSingleList);
//MEM_FREE(iListBoxItem);
}
void CHelloContainer::SizeChanged()
{
if(iSingleList)
{
iSingleList->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CHelloContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CHelloContainer::CountComponentControls() const
{
// return number of controls inside this container
return 1;
}
// ---------------------------------------------------------
// CHelloContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CHelloContainer::ComponentControl( TInt /*aIndex*/ ) const
{
return iSingleList;
}
// ---------------------------------------------------------
// CHelloContainer::Draw(const TRect& aRect) const
// handle the message when client region must be redrawn.
// ---------------------------------------------------------
//
void CHelloContainer::Draw( const TRect& /*aRect*/ ) const
{
CWindowGc& gc = SystemGc();
// gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
// gc.SetBrushColor(KRgbRed);
// gc.DrawRect(Rect());
}
// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
// const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CHelloContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
if(iSingleList)
{//设置按键
return iSingleList->OfferKeyEventL(aKeyEvent, aType);
}
return EKeyWasNotConsumed;
}
void CHelloContainer::SetTextToListL(TInt aNum, const TDesC& aBuf)
{
TBuf<64> sBuf;
sBuf.AppendNum(aNum);
sBuf.Append(_L("\t"));
sBuf.Append(aBuf);
iListBoxItem->AppendL(sBuf);
//通知Listbox添加内容
iSingleList->HandleItemAdditionL();
}
TInt CHelloContainer::GetIndexFromList()
{
if(!iSingleList)
return -1;
return iSingleList->CurrentItemIndex();
}
void CHelloContainer::DeleteTextFromList(TInt& aCurr)
{
iListBoxItem->Delete(aCurr);
//通知Listbox删除内容
iSingleList->HandleItemRemovalL();
}
void CHelloContainer::DeleteTextFromList()
{
iListBoxItem->Delete(0, iListBoxItem->Count());
//通知Listbox删除内容
iSingleList->HandleItemRemovalL();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -