Wiley.Symbian.OS.C.plus.plus.for.Mobile.Phones.Aug.2007 (779890), страница 4
Текст из файла (страница 4)
In the process we introduce you to the emulator and to thetools for building C++ programs, so that by the end of the chapter youwill know how to build and run a Symbian OS application. We don’t gettoo involved in describing Symbian OS programming conventions, APIfunctions, and so forth; instead, we concentrate on the tools you needand how to use them, leaving the details until later chapters.First we briefly describe the emulator. Most Symbian OS software isdeveloped first on the emulator and only then on real target hardware.The emulator also includes a number of Symbian OS applications, and somimics a real Symbian OS phone very closely. You will need to becomefamiliar with the emulator and in the process we can take a look at thevarious graphical user interfaces (GUIs) used by Symbian OS.Then we create a program.
The easiest things to build are textmode console programs, so that’s the form of the classic ‘Hello World’application that we use. We demonstrate how to compile it for theemulator, and how to launch it using the Carbide.c++ IDE.1.1 Using the EmulatorThe emulator is a fundamental tool for all the Symbian OS SDKs, so it’svital that you get to know how to use it.If you are a newcomer to Symbian OS, the emulator offers an opportunity to get to know some Symbian OS basics from a user’s perspective,so we look at these straight away.
Later, you’ll want to learn to make2GETTING STARTEDeffective use of it as a developer, so we cover the details of its operationin Chapter 10.If you have some experience of Symbian OS, you may want to skipstraight to Section 1.2 and start building an application.Launching the EmulatorThe first piece of software you need is a software development kit (SDK).There are a couple of Symbian OS v9 SDKs available, depending onthe phone(s) you want to target. If you’re unsure which SDK to select,we recommend starting with both a S60 v3 and a UIQ 3rd Edition SDK.You can obtain these via the links on the Symbian developer website(developer.symbian.com).
Once you’ve installed your SDK, you canlaunch the emulator in any of the following ways:• launch the executable epoc.exe, which you’ll find in the directory \epoc32\release\winscw\udeb underneath the directory inwhich the SDK is installed• from the Start menu, select either Programs, UIQ SDK or Programs,S60 Developer Tools, 3rd Edition SDK and select Emulator from theappropriate submenu.However you choose to start it, and whichever emulator you’re using(either for S60 or UIQ), the first thing you’ll see in the emulator is theapplication launcher. As its name indicates, the application launcherenables you to launch applications.
Its menus allow you to view orchange system settings and it also has a control panel. It’s very easy forend users to get to know the application launcher; you don’t really needa manual. Just click with the mouse here and there and you’ll soon findout what it has to offer.GUI StyleIf you’ve started up the UIQ emulator (shown in Figure 1.1a with theP990 extensions), as you browse around the application launcher you’llbegin to see how UIQ is optimized for the pen-based mobile phoneform factor. UIQ is designed as a ‘read mostly’ user interface, to be usedmainly for browsing and for making a selection from a range of optionswith a single tap of a pen. Other GUIs – such as the S60 interface shownin Figure 1.1b and used, for example, on the Nokia Nseries phones – areoptimized for the different hardware resources of the devices on whichthey are intended to run.Although the various GUIs may have a superficially different appearance, they all rely on a common set of underlying features, some of whichare briefly described in the next section.USING THE EMULATOR(a)3(b)Figure 1.1 UIQ (with P990 extensions) and S60 emulatorsScreen layoutThe UIQ screen layout, illustrated in the following diagram, includes thefollowing areas (from top to bottom of the screen):The title bar displays the name and icon of the current application.
Italso contains a View context area. Selecting the label opens the menuin Pen style. The width of the menu is adjusted to fit the longest label.The View context area can contain controls, for example icons, textlabels and tabs. If there is enough space to the right of the tabs, otherapplication-specific data or controls can be added.The menu bar contains one or more menus, whose names and contentschange from application to application, and also as you change viewwithin a particular application. In UIQ, the menu bar usually containstwo menus on the left and may optionally have a folder menu on the right.The application space is the central area of the screen, where anapplication’s view is displayed. Applications use this area in whateverway is appropriate to the information that they display.Optionally, an application displays a button bar at the bottom of theapplication space.
The most common use is to provide buttons to move4GETTING STARTEDTitle bar with viewcontext areaApplication spaceButton barStatus barFigure 1.2 UIQ screen layoutbetween the application’s various views. In UIQ, a detail view, such asthe one in Figure 1.2 that shows the detail of a single Contact entry,usually has a special button in the lower right corner to return you to themain view.The status bar displays information such as battery charge, time ofday, signal strength and notification of incoming messages. The P990i’sstatus bar includes a keyboard icon in the lower right corner, which isused to display a virtual keyboard for text input if you do not wish to usehandwriting recognition.Status pane - with signal pane, context pane,title pane, navi pane and battery paneMain paneControl paneFigure 1.3S60 screen layoutUSING THE EMULATOR5Also displayed in some views is the application picker, containingicons that allow you to switch applications.
Selecting an icon brings theapplication it represents to the foreground. The application launcher iconbrings the application launcher to the foreground, allowing you to launchapplications that are not displayed on the application picker. If you wish,you can customize the application picker to launch your own preferredset of applications.Most of these screen layout elements can be recognized in other GUIsused with Symbian OS, such as in Figure 1.3, though they may differsignificantly in appearance or be located in different areas of the screen.MenusFigure 1.4 illustrates a set of menus in the Calendar application.
The menubar is different (but not very different) from menu bars in desktop GUIs.Cascaded menu items can be used both to hide less common optionsand to reduce the vertical space required by menu panes. This feature isused sparingly in UIQ applications, where menu content changes withcontext and each menu is designed to contain as small and as simple aset of menu commands as possible. Cascaded menu items are used morefrequently in the S60 interface, where they appear as in Figure 1.5.In the UIQ emulator, use the menu with the pen (i.e. your PC’s mouse)and you’ll see some interesting visual cues to confirm the option youFigure 1.4Menu structure in the Calendar application6GETTING STARTEDFigure 1.5 S60 cascaded menu itemsselected: the option will flash very briefly before the menu disappears.
Ittook a long time to get that effect just right!As with all other elements of a Symbian OS GUI and applications,where a keyboard is available (including the keyboard of a PC runningthe emulator), you can drive the menus with the keyboard as well as withthe pen. You can use the arrow keys and Enter to select items. You canalso use cursor keys and the Confirm button on real target hardware andon emulators that support such features.When writing an application you also have the option to assign ashortcut key to any menu item, which allows you to invoke the relevantfunction directly from a keyboard without going through the menus at all.Although they can be defined in any Symbian OS application, shortcutkeys are clearly not usable on mobile phones without keyboards (exceptwhen the application is running on the emulator) so neither the UIQ northe S60 user interfaces display shortcut key information in their menus.1.2 Hello World – Text VersionNow that you’ve started to get to grips with the emulator, it’s time to getyour first Symbian OS C++ program running.
Even though Symbian OSis primarily a system for developing GUI applications, the simplest kindof program uses a text interface, so for our first task we’ll build a programHELLO WORLD – TEXT VERSION7that writes ‘Hello world!’ to a text console. That will introduce you to thetools required for building applications for both the emulator and a realdevice, so that later on you’ll be ready for a program with a GUI.If you want to follow this chapter through at your desktop with theSDK, make sure that you’ve installed all the tools you need.