03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Words used in MVC<br />

I should finish this section with a word on nomenclature. A 'control' in Symbian OS is not<br />

usually a 'controller' in the MVC sense, which is precisely why the word 'controller' is not<br />

used. A Symbian OS control does, however, usually contain pure MVC view functionality: its<br />

Draw() function draws a model without changing it.<br />

In Symbian OS literature, the word 'view' is used for a control or some drawing/interaction<br />

code to highlight the fact that the 'view' is entirely separate from the 'model'. A good example<br />

is ETEXT and FORM, Symbian OS rich text components:<br />

� ETEXT is a model without views<br />

� FORM provides views but has no model.<br />

We use 'app view' in this sense, while the model is often contained in the document class. In<br />

Battleships, I use 'fleet view' and 'player status view' as the names of my controls, because<br />

the fleet and player status 'model' data is kept in separate classes.<br />

Often, in Symbian OS literature, the word 'model' is used for application data that can be<br />

saved to file.<br />

11.3.2 The Draw() Contract<br />

Symbian OS controls use the Draw() function to implement MVC view functionality.<br />

CCoeControl::Draw() is defined in coecntrl.h as<br />

IMPORT_C virtual void Draw(const TRect& aRect) const;<br />

A derived class will override this virtual function to draw – or redraw – its model. In the rare<br />

cases in which this function is not overridden, there's a default implementation that leaves<br />

the control blank.<br />

Important<br />

Because CCoeControl::Draw() is strictly an MVC view function, it<br />

should not update the model. It is therefore const, and nonleaving.<br />

Your Draw() implementation must not leave.<br />

This is another reason CGraphicsContext functions return void: if they could fail,<br />

Draw() could fail also.<br />

Redraw handling<br />

System-initiated redraw handling starts in the window server, which detects when you need<br />

to redraw part of a window. In fact, it maintains an invalid region on the window, and sends<br />

an event to the application that owns the window, asking it to redraw the invalid region.<br />

CONE works out the control that intersects the invalid region and converts the event into a<br />

call to Draw() for all affected controls. A system-initiated redraw must redraw the model<br />

exactly as the previous draw.<br />

Application-initiated redraw handling starts (by definition) in the application. If you update a<br />

model and need to redraw a control, you can simply call its DrawNow() function.<br />

DrawNow() is a nonvirtual function in CCoeControl that:<br />

� tells the window server that the control is about to start redrawing,<br />

� calls Draw(),<br />

� tells the window server that the control has finished redrawing.

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

Saved successfully!

Ooh no, something went wrong!