03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Instead of calling CreateWindowL() to create a window of the right size, I call<br />

SetContainerWindowL() to register myself as a lodger of a control on an existing<br />

window.<br />

11.5.3 Compound Controls<br />

There needs to be some structure in laying out lodger controls such as those in the<br />

Battleships Start first game dialog, or indeed in the Battleships app view. That discipline is<br />

obtained by using compound controls: a control is compound if it has one or more<br />

component controls in addition to itself.<br />

� A component control is contained entirely within the area of its owning control.<br />

� All components of a control must have nonoverlapping rectangles.<br />

� A component control does not have to be a lodger, it can also be window-owning. In<br />

the majority of cases, however, a component control is a lodger.<br />

To indicate ownership of component controls to CONE's framework, a compound control<br />

must implement two virtual functions from CCoeControl:<br />

� CountComponentControls() indicates how many components a control has – by<br />

default, it has zero, but you can override this.<br />

� ComponentControl() returns the nth component, with n from zero to the count of<br />

components minus one. By default, this function panics (because it should never get<br />

called at all if there are zero components). If you override<br />

CountComponentControls(), you should also override this function to return a<br />

component for each possible value of n.<br />

Here is a generic example implementation of these functions. Most Symbian OS applications<br />

use enums for their controls like:<br />

enum<br />

{<br />

EMyFirstControl,<br />

EMySecondControl,<br />

EAmountOfControls<br />

}<br />

This enables you to simply return EAmountOfControls in the<br />

CountComponentControls. This ensures that you do not forget to change your return<br />

value when you add or remove controls over time:<br />

TInt anyExampleAppView::CountComponentControls() const<br />

{<br />

return EAmountOfControls;<br />

}<br />

CCoeControl* anyExampleAppView::ComponentControl(TInt aIndex) const<br />

{<br />

switch (aIndex)<br />

{<br />

case 0: return EMyFirstControl;<br />

case 1: return EMySecondControl;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!