Symbian学习笔记(10):使用ListBox
2008-04-06 20:52
519 查看
symbian中的ListBox比较复杂也是比较常用的,我只能先从最简单的CAknSingleStyleListBox入手来尝试看看。太复杂的东西不是我这样的新手要立刻去明白的。
先声明一个列表组件:CAknSingleStyleListBox* iListBox;
然后在Container的ConstructL中去创建它:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
void CUniNewsAppContainer::ConstructL(const TRect& aRect) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreateWindowL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//add your code here ...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//construct a listbox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox = new(ELeave) CAknSingleStyleListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetContainerWindowL( *this);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetListBoxObserver(this);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ConstructL(this,EAknListBoxSelectionList|EAknListBoxLoopScrolling);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->CreateScrollBarFrameL(ETrue);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,CEikScrollBarFrame::EOn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetRect(aRect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SetRect(aRect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ActivateL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
这里有几句话,一是SetScrollBarVisibilityL设置使用滚动条,二是ItemDrawer()->ColumData()->EnableMarqueeL()让选中的文本超长后可以左右滚动。
有一点比较奇怪,我得先设置ListBox的Rect才能设置整个Container的Rect?否则ListBox会不占整个主面板的位置。
接着在合适的地方需要去给ListBox增加内容:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CUniNewsAppContainer::InitListBox(TInt tabId)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(iListBox==NULL) return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TBuf<256> str;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list->Reset();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CUniNewsAppView * appView = STATIC_CAST(CUniNewsAppUi*,iCoeEnv->AppUi())->iAppView;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RArray<TNewsContent>* rc = appView->iChannelHandler->GetContents();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(TInt i=0;i<rc->Count();i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if( (*rc)[i].pid==tabId)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
str.FillZ(str.MaxLength());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
str.Format(KITEMFORMAT,(*rc)[i].title);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list->AppendL(str);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->HandleItemAdditionL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetFocus( ETrue );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetCurrentItemIndexAndDraw(appView->iListIndex);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ActivateL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->DrawNow();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
这里的HandleItemAdditionL()通知一下ListBox模型作了增加操作,同样还有一个HandleItemRemovalL()则是通知ListBox作了一个删除操作。
这里的KITEMFORMAT定义是"/t%S"。这里的格式似乎挺重要的,一般是:图标ID/t题头字串/t主要字串/t图标ID/t图标ID。
我这里因为没有用到图标所以是一个/t%S,这个/t不可省略。如果用图标,则变成%d/t%S了,同时还要增加iconArray在创建iListBox的时候。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CAknIconArray* icons =new(ELeave) CAknIconArray(2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CleanupStack::PushL(icons);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
icons->ConstructFromResourceL(R_ICON_LISTICONS);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CleanupStack::Pop();
在ListBox中有一个叫Model()的还有一个叫View()的,从名字上就可以看出它们的含义了。前面我们从Model中操作列表内容,而我们可以从View中获取ItemDrawer去操作列表显示
的一些参数,但是我觉得有一点不爽的是,缺省生成的列表框字体比较大,不是太喜欢,在网上搜了一下,似乎那个设置字体的方法对我的机器不管用?
iListBox->ItemDrawer()->SetFont(ApacPlain12());
不过有一种方法是可行的,只是比较麻烦,那就是自己去实现ListBox,以及它的ItemDrawer。在网上看到的代码我试了一下,还行。方法如下。
第一步作一个自己的ItemDrawer:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class CCustomListItemDrawer: public CListItemDrawer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CCustomListItemDrawer(const CEikTextListBox& aListBox);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~CCustomListItemDrawer();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual void DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool aViewIsDimmed,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TBool aItemIsSelected) const;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void SetIconArray(CArrayPtr<CGulIcon>* aIconArray);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TSize MaxIconSize() const;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void DeleteIconArray();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void CalculateMaxIconSize();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const CEikTextListBox& iListBox;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CArrayPtr<CGulIcon>* iIconArray;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TSize iMaxIconSize;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
实现的代码中最重要的就是那个DrawActualItem方法负责具体的绘制工作,从它的参数表中足够得到绘制所需的信息,剩下的事情就是用SystemGc去绘制。
第二步是作一个自己的ListBox控件:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class CCustomListBox: public CEikTextListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public: // constructors
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CCustomListBox();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ConstructL(const CCoeControl* aParent, TInt aFlags = 0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public: // from CEikTextListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TEventCode aType);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private: // from CEikTextListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual void CreateItemDrawerL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
在它的CreateItemDrawerL()中创建成员iItemDrawer = new (ELeave) CCustomListItemDrawer(*this)。而OfferKeyEvent主要的作用是处理上下方向键。
关于ListBox的使用,可以参考这个地址:http://pagesperso-orange.fr/klisa/3650/ListBox/page01.html
先声明一个列表组件:CAknSingleStyleListBox* iListBox;
然后在Container的ConstructL中去创建它:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
void CUniNewsAppContainer::ConstructL(const TRect& aRect) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CreateWindowL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//add your code here ...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//construct a listbox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox = new(ELeave) CAknSingleStyleListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetContainerWindowL( *this);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetListBoxObserver(this);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ConstructL(this,EAknListBoxSelectionList|EAknListBoxLoopScrolling);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->CreateScrollBarFrameL(ETrue);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,CEikScrollBarFrame::EOn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetRect(aRect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SetRect(aRect);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ActivateL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
这里有几句话,一是SetScrollBarVisibilityL设置使用滚动条,二是ItemDrawer()->ColumData()->EnableMarqueeL()让选中的文本超长后可以左右滚动。
有一点比较奇怪,我得先设置ListBox的Rect才能设置整个Container的Rect?否则ListBox会不占整个主面板的位置。
接着在合适的地方需要去给ListBox增加内容:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void CUniNewsAppContainer::InitListBox(TInt tabId)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(iListBox==NULL) return;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CDesCArray* list = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TBuf<256> str;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list->Reset();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CUniNewsAppView * appView = STATIC_CAST(CUniNewsAppUi*,iCoeEnv->AppUi())->iAppView;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
RArray<TNewsContent>* rc = appView->iChannelHandler->GetContents();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(TInt i=0;i<rc->Count();i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if( (*rc)[i].pid==tabId)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
str.FillZ(str.MaxLength());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
str.Format(KITEMFORMAT,(*rc)[i].title);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
list->AppendL(str);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->HandleItemAdditionL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetFocus( ETrue );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->SetCurrentItemIndexAndDraw(appView->iListIndex);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->ActivateL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
iListBox->DrawNow();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
这里的HandleItemAdditionL()通知一下ListBox模型作了增加操作,同样还有一个HandleItemRemovalL()则是通知ListBox作了一个删除操作。
这里的KITEMFORMAT定义是"/t%S"。这里的格式似乎挺重要的,一般是:图标ID/t题头字串/t主要字串/t图标ID/t图标ID。
我这里因为没有用到图标所以是一个/t%S,这个/t不可省略。如果用图标,则变成%d/t%S了,同时还要增加iconArray在创建iListBox的时候。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CAknIconArray* icons =new(ELeave) CAknIconArray(2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CleanupStack::PushL(icons);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
icons->ConstructFromResourceL(R_ICON_LISTICONS);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CleanupStack::Pop();
在ListBox中有一个叫Model()的还有一个叫View()的,从名字上就可以看出它们的含义了。前面我们从Model中操作列表内容,而我们可以从View中获取ItemDrawer去操作列表显示
的一些参数,但是我觉得有一点不爽的是,缺省生成的列表框字体比较大,不是太喜欢,在网上搜了一下,似乎那个设置字体的方法对我的机器不管用?
iListBox->ItemDrawer()->SetFont(ApacPlain12());
不过有一种方法是可行的,只是比较麻烦,那就是自己去实现ListBox,以及它的ItemDrawer。在网上看到的代码我试了一下,还行。方法如下。
第一步作一个自己的ItemDrawer:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class CCustomListItemDrawer: public CListItemDrawer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CCustomListItemDrawer(const CEikTextListBox& aListBox);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
~CCustomListItemDrawer();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual void DrawActualItem(TInt aItemIndex, const TRect& aActualItemRect,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TBool aItemIsCurrent, TBool aViewIsEmphasized, TBool aViewIsDimmed,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TBool aItemIsSelected) const;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void SetIconArray(CArrayPtr<CGulIcon>* aIconArray);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TSize MaxIconSize() const;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void DeleteIconArray();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void CalculateMaxIconSize();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
const CEikTextListBox& iListBox;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CArrayPtr<CGulIcon>* iIconArray;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TSize iMaxIconSize;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
实现的代码中最重要的就是那个DrawActualItem方法负责具体的绘制工作,从它的参数表中足够得到绘制所需的信息,剩下的事情就是用SystemGc去绘制。
第二步是作一个自己的ListBox控件:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class CCustomListBox: public CEikTextListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public: // constructors
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CCustomListBox();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
void ConstructL(const CCoeControl* aParent, TInt aFlags = 0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public: // from CEikTextListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TEventCode aType);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private: // from CEikTextListBox
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
virtual void CreateItemDrawerL();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
在它的CreateItemDrawerL()中创建成员iItemDrawer = new (ELeave) CCustomListItemDrawer(*this)。而OfferKeyEvent主要的作用是处理上下方向键。
关于ListBox的使用,可以参考这个地址:http://pagesperso-orange.fr/klisa/3650/ListBox/page01.html
相关文章推荐
- (17)Java学习笔记——面向对象10——包 / 权限修饰符的的使用
- Symbian学习笔记(4):在GUI应用中使用图像
- opencv学习笔记10 使用OpenCV对两幅图像求和(求混合(blending))¶
- 【python学习笔记】10:Beautiful Soup模块的使用
- AndEngine学习笔记10-Physics(andengine中使用Box2D的PhysicsWorld介绍)
- 使用 u-boot 烧写内核——韦东山嵌入式Linux学习笔记10
- Symbian学习笔记(4)——在GUI应用中使用图像
- SilverLight商业应用程序开发---学习笔记(10)使用数据源窗口创建DataGrid
- Symbian学习笔记(4):在GUI应用中使用图像
- Cocos2d-X 学习笔记 10 解决汉字乱码,win32工程中使用iconv配置方法
- 【Android】学习笔记(10)——adb使用方法
- Symbian学习笔记(18) - 初探Web Services API 的使用(中)
- iOS学习笔记(10)上 CABasicAnimation类使用
- Python下字符串的创建和转义字符的使用 - 千月的python linux 系统管理指南学习笔记(10)
- 深度学习Caffe实战笔记(10)Windows Caffe使用MATLAB接口提取和可视化特征
- 韩顺平_PHP程序员玩转算法公开课(第一季)10_使用栈完成高级计算器(2)_学习笔记_源代码图解_PPT文档整理
- Jquery学习笔记(10)--ajax删除用户,使用了js原生ajax
- Android:日常学习笔记(10)———使用LitePal操作数据库
- python学习笔记10(函数一): 函数使用、调用、返回值
- Symbian学习笔记(4):在GUI应用中使用图像