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.

stream.OpenLC(aStore,aStreamId);<br />

iEngine = new(ELeave) CGameEngine;<br />

iEngine->InternalizeL(stream);<br />

InternalizeL(stream);<br />

CleanupStack::PopAndDestroy(); // stream<br />

}<br />

The first task is to get a GUI environment pointer. That's needed by the controller, whether<br />

it's constructing from scratch or restoring from a document. Next, it creates a new engine<br />

object and requests it to initialize itself from the specified stream. As you would expect,<br />

InternalizeL()is the conventional name for functions that read data from a stream. The<br />

controller's and engine's InternalizeL() functions are pretty well the reverse of the<br />

ExternalizeL() functions already seen: they add little that's new, so I'll move quickly on.<br />

9.8.3 Creating a Default Document<br />

When the application is opened with a new file (which for UIQ is only when the application is<br />

started for the first time), it can't restore from anything, so instead it needs a new default<br />

document. The framework creates the actual new document file: the folder for this is devicespecific<br />

(in the standard UIQ emulator it's C:\Documents\), while the default<br />

document name is read from the first TBUF in the resource file ('Solo Ships' in this case).<br />

The application class has the responsibility of setting up the application appropriately for a<br />

default state:<br />

CApaDocument* CGameApplication::CreateDocumentL()<br />

{<br />

CGameDocument* doc = new(ELeave) CGameDocument(*this);<br />

CleanupStack::PushL(doc);<br />

doc->ConstructL();<br />

CleanupStack::Pop();<br />

return doc;<br />

}<br />

The document second-phase constructor creates a new controller:<br />

void CGameDocument::ConstructL()<br />

{<br />

iController = CGameController::NewL();<br />

}<br />

This uses the conventional NewL(), which constructs a default controller, rather than<br />

restoring one from file.<br />

9.8.4 App UI and the Document<br />

Finally, we need to link the app UI to the document. Most importantly, the command handler<br />

for EEikCmdExit which, in all our applications until now, has just been called Exit(), now<br />

includes SaveL():

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

Saved successfully!

Ooh no, something went wrong!