A composite view is really a view containing widgets.
We have to communicate with the container to say how many widgets we contain. So consider the simpler case of a single widget, we have to define CountComponentControl as follows:
TInt CDemoContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
So we know how many widget we have, but we have also the need to get each widget in turn. This is done by ComponentControl(TInt aIndex) that will return in turn each widget access by an index. Here is the code for the simplest case:
CCoeControl* CDemoContainer::ComponentControl(TInt aIndex) const {
switch ( aIndex ) {
case 0: return iLabel;
default: return NULL;
}
}
You can easily imagine what will happen: for each index the method will be called to obtain the corresponding widget. The sizes (the really missing piece) are in the widget itself.
You assign the sizes at the construction time or (better) in the SizeChanged method, as follows:
void CDemoContainer::SizeChanged()
{
iLabel->SetRect(Rect());
}
Note that this method will be called at least once, so there is always the opportunity to set the size of the widgets. Each widget must know where it is going to be drawn.


Recent Comments