Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 10
Текст из файла (страница 10)
To build the example, just enter the listings that applyto your chosen target platform, as well as the common code listings.It is instructive, however, to compare the platform-specific portions ofthe code, to get an idea of variations between platforms, and buildingthe example for both would be ideal. Furthermore, note that it wouldbe simpler to generate this application for both platforms using theCarbide.c++ project wizards, and again I think it is instructive to enterthe code manually, as discussed, for a better learning experience.SIMPLE EXAMPLE APPLICATION39This chapter will not examine the code in a lot of detail – that willbe done in later chapters. Some description is provided; however, don’tworry if you do not understand it all. It will be explained in due course.For now, the main goal is to get a feel for developing a basic applicationby actually building and running one on the emulator and a phone.2.3.1Application ComponentsHere are the minimum classes required for a Symbian application.
Youwill be creating them for your example application:•Application View. The root GUI control, this class implements themain window and acts as a container for the other application controls.•Application UI. This class instantiates the application view and handles the commands sent from the application’s GUI controls.•Application document. This class handles the non-GUI data aspectsof the application – the application data. It also instantiates the application’s UI class.•Application. The main application class starts the application byinstantiating and starting the document class. It also sets the application’s UID (a unique identifier that is required for each application – for more information, see Chapter 4).2.3.2 Overview of SimpleExThis section presents an example GUI application called SimpleEx.When launched, the example displays the text ‘Simple Example’ in thecenter of the window. It also has a menu item labeled ‘Start’ that displaysan alert dialog when selected (which displays ‘Start selected!’).The example for both platforms contains the following files organizedin the directories as shown:\includeSimpleEx.hSimpleEx.hrhSimpleExUid.h\srcSimpleEx.cppSimpleEx_app.cppSimpleEx_doc.cppSimpleEx_ui.cppSimpleEx_view.cpp\groupbld.infSimpleEx.rssSimpleEx_reg.rssSimpleEx.mmpSimpleEx.pkg40SYMBIAN OS QUICK STARTTo create the example you will perform the following steps:1.Create the application header files.2.Create the resource (RSS) and resource command header (HRH) files.3.Create the registration resource file.4.Create the source code for the application classes.5.Create the project definition file (SimpleEx.mmp) and build file(bld.inf).6.Build and run the example on the PC-based emulator.7.Create the target package definition (PKG) file.8.Generate the installation package (SIS file) and install it on a smartphone.9.Execute the SimpleEx application on the smartphone.2.3.3 Header FilesThis section describes the main header file for our example (SimpleEx.h), defined for S60 and UIQ platforms and the header file itincludes (SimpleExUid.h).
Put the header file for your particular platform in a file named SimpleEx.h and place it in the include directory(e.g., \SimpleEx\S60\include for the S60 headers).The following is this header for S60 3rd Edition:#ifndef __SIMP_H#define __SIMP_H/*==========================================S60 SimpleEx Header File==========================================*/#include <eikenv.h>#include <eikon.hrh>#include "SimpleEx.hrh"#include <akndoc.h>#include <aknapp.h>#include <aknappui.h>#include "SimpleExUid.h"const TUid KUidSimpleExApp = {SIMPLEEXUID};// The Application Classclass CSimpleExApplication : public CAknApplication{private:CApaDocument* CreateDocumentL();TUid AppDllUid() const;};// The Application View Classclass CSimpleExAppView : public CCoeControlSIMPLE EXAMPLE APPLICATION41{public:static CSimpleExAppView* NewL(const TRect& aRect);static CSimpleExAppView* CSimpleExAppView::NewLC(const TRect& aRect);void ConstructL(const TRect& aRect);private:void Draw(const TRect&) const;};// The UI Classclass CSimpleExAppUi : public CAknAppUi{public:void ConstructL();~CSimpleExAppUi();private:void HandleCommandL(TInt aCommand);CSimpleExAppView* iAppView;};// The Application Document Classclass CSimpleExDocument : public CAknDocument{public:CSimpleExDocument(CEikApplication& aApp): CAknDocument (aApp) { }private:CEikAppUi* CreateAppUiL();};#endifHere is the same version of the code for SimpleEx.h for UIQ 3:/*==========================================UIQ SimpleEx Header File==========================================*/#ifndef __SIMP_H#define __SIMP_H#include <eikenv.h>#include <eikon.hrh>#include "SimpleEx.hrh"#include <qikdocument.h>#include <qikapplication.h>#include <qikappui.h>#include <QikViewBase.h>#include "SimpleExUid.h"const TUid KUidSimpleExApp = {SIMPLEEXUID};/**Identifies the hello world application’s view.Each view need an unique UID in the application.*/const TUid KUidSimpleExView = {0x00000001};/*------------------------------------------The Application Class--------------------------------------------*/class CSimpleExApplication : public CQikApplication{private:42SYMBIAN OS QUICK STARTCApaDocument* CreateDocumentL();TUid AppDllUid() const;};/*-------------------------------------------The Application View Class---------------------------------------------*/class CSimpleExAppView : public CQikViewBase{public:static CSimpleExAppView* NewL(CQikAppUi& aAppUi);static CSimpleExAppView* CSimpleExAppView::NewLC(CQikAppUi& aAppUi);void ConstructL();// from CQikViewBaseTVwsViewId ViewId()const;void ViewConstructL();void HandleCommandL(CQikCommand& aCommand);private:void Draw(const TRect&) const;CSimpleExAppView(CQikAppUi& aAppUi);};/*----------------------------------------------The UI Class-----------------------------------------------*/class CSimpleExAppUi : public CQikAppUi{public:void ConstructL();private:CSimpleExAppView* iAppView;};/*---------------------------------------------The Application Document Class----------------------------------------------*/class CSimpleExDocument : public CQikDocument{public:CSimpleExDocument(CEikApplication& aApp) : CQikDocument(aApp) { };private:CEikAppUi* CreateAppUiL();};#endifNotice from the header files that the application, document, and UIclasses are derived from different base classes for each of the platforms(the differences are shown in bold text).
For example, the application UIclass is derived from CAknAppUI for S60, and CQikAppUI for UIQ.Figures 2.8 and 2.9 show the class hierarchy for SimpleEx, for S60and UIQ, respectively.Notice that the platform classes for S60 and UIQ derive from the samecore Symbian OS base application classes. Fortunately, the applicationplatform classes for the different platforms are similar from a developmentperspective due to their abstracted interface. Note also that while in UIQI inherit the view class from the UIQ view class CQikViewBase sinceall applications in UIQ should do that, I inherit the S60 application classSIMPLE EXAMPLE APPLICATION43Symbian OS base application classesCEikApplicationCEikAppUiCEikDocumentCCoeControlS60 platform layerCAknApplicationCAknAppUiCAknDocumentCSimpleExApplicationCSimpleExAppUiCSimpleExDocumentCSimpleExAppViewS60 SimpleExFigure 2.8 SimpleEx Class Hierarchy for S60Symbian OS base application classesCEikApplicationCEikAppUiCEikDocumentCCoeControlUIQ platform layerCQikApplicationCQikAppUiCSimpleExApplicationCSimpleExAppUiCQikDocumentCQikViewBaseCSimpleExDocumentCSimpleExAppViewUIQ SimpleExFigure 2.9SimpleEx Class Hierarchy for UIQ44SYMBIAN OS QUICK STARTdirectly from CCoeControl, which is fine for applications with a singleview such as this one.Although, for this example, I have put all the classes in one header file,it is common to separate each class into its own header file.Note also that SimpleEx.h includes SimpleExUid.h.