容器控制必须能够提供其包含控制的数量以及这些控制是什么的信息。框架利用这些信息去绘制容器。容器通过实现两种方法提供这些信息: 一个方法是
CountComponentControls(),该方法返回组件控制的数目; 另一个方法是ComponentControl(TInt aIndex),该方法通过索引返回控制。
例如, 在下面简单的列表框中:
和
两种方法相互配合工作。框架可以查询控制来获得它具有组件的数量信息, 并要求提供一个指向每个组件控制的指针。在运行时,可利用这两种方法来添加或移去控制。
CountComponentControls(),该方法返回组件控制的数目; 另一个方法是ComponentControl(TInt aIndex),该方法通过索引返回控制。
例如, 在下面简单的列表框中:
TInt CContainerContainer::CountComponentControls() const
{
return 1; // return number of controls inside this container
// (i.e. the list)
}
{
return 1; // return number of controls inside this container
// (i.e. the list)
}
和
CCoeControl* CContainerContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListBox; // return a pointer to the listbox
default:
return NULL;
}
}
{
switch ( aIndex )
{
case 0:
return iListBox; // return a pointer to the listbox
default:
return NULL;
}
}
两种方法相互配合工作。框架可以查询控制来获得它具有组件的数量信息, 并要求提供一个指向每个组件控制的指针。在运行时,可利用这两种方法来添加或移去控制。