Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 73
Текст из файла (страница 73)
menubarpoints to the MENU BAR resource that contains the menu pane with thestart items on it. This menu will be presented to the user when the userpresses the options softkey.384GUI APPLICATION PROGRAMMING12.4.3 Application Registration Resource FileGUI applications are EXE files in the sys\bin directory (in Symbian OSv9) and in order for the device to recognize an executable as a GUIapplication, and to display them on the desktop for user selection, theapplication must be registered via a special resource file known as aregistration resource file.
The compiled registration resources are placedin the \private\10003a3f\import\apps\ directory on the device.The source file names are typically <application name> reg.rss.The user will not be able to run an application on the device without aregistration resource specified for that application.Here is the registration file for SimpleEx, which is generic and canbe used for UIQ and S60 applications:#include <AppInfo.rh>#include "SimpleExUid.h" // defines the application UIDUID2 KUidAppRegistrationResourceFileUID3 SIMPLEEXUID// application UIDRESOURCE APP_REGISTRATION_INFO{app_file = "SimpleEx";}As you can see, there is not much to this. Besides including theUID2 KUidAppRegistrationResourceFile, which is standard, youspecify your application’s UID (via the UID3 line) and the name ofyour EXE file (minus the .exe suffix) in the app file attribute of theAPP REGISTRATION INFO resource.
This information is sufficient forthe device to register your application to the device and have it appearon the desktop.Although not used in the SimpleEx registration resource, APPREGISTRATION INFO also has a localizable resource fileattribute. This attribute is optional and points to what is known as alocalizable application information file that specifies the application’scaption (in multiple languages if desired) as well as defines the application icons.
If you have a localizable application information file, thefile name must be set to the localizable resource file attributeof APP REGISTRATION INFO in order for it to be used. Localizableapplication information files will be discussed more in section 12.8.To compile the registration file, you need to have the following inyour MMP file, substituting SimpleEx reg.rss with your applicationregistration resource file name:START RESOURCETARGETPATHENDSimpleEx_reg.rss\private\10003a3f\appsRESOURCE FILES385Note that 10003a3f is the SID of the application architecture component, and the directory in TARGETPATH is its private directory.12.4.4 Supporting Multiple LanguagesWhile you can put text strings directly within the resource file as Ihave done in the examples, this is not recommended if you need yourapplication to support different languages.
Symbian recommends that youput all your strings into a RLS file, and then include this string file using#include in your RSS file. There should be a separate RLS file for eachlanguage you support.Each string in the RLS file is defined using the rls string keyword.For example:rls_string STRING_r_example_start "Start"Then in your RSS file, you supply the keyword STRING r examplestart selected, instead of putting in the string directly.
For example:RESOURCE MENU_PANE r_SimpleEx_menu{items ={MENU_ITEM{command = ESimpleExCommand;txt = STRING_r_example_start_selected;}};}At the top of the RSS file you need to include the proper language RLSfile, and this is normally done by using #ifdef’s. Below is an exampleof including RLS files in your resource file for a program that supportsEnglish, French, and German:#ifdef LANGUAGE_EN#include "strings_en.rls"#elif defined LANGUAGE_FR#include "strings_fr.rls"#elif defined LANGUAGE_DE#include "strings_de.rls"#endifHow are the language definitions set? Symbian OS provides supportfor this in the project MMP file by means of the LANG keyword.
Here arethe example lines in the MMP:LANGRESOURCEEN FR DEMyApp.rss386GUI APPLICATION PROGRAMMINGThe build script will compile the resource file, defined on the RESOURCEline, once for every language specified in the LANG line. Duringeach resource compilation, LANGUAGE <language> is defined, where<language> is the current item on the LANG line. So it will compileSimpleEx.rss once with LANGUAGE EN defined (with the output goingto SimpleEx.ren), then with LANGUAGE FR defined (with the outputgoing to SimpleEx.rfr), and, finally, with LANGUAGE DE defined(with the output going to SimpleEx.rde).
During each compilation,the correct language RLS file is included in the resource as defined in the#ifdef structure.There are no rules for the format of the language identifiers on theLANG line, each compilation stage simply #define’s a variable with thespecified name, prefixed with LANGUAGE . You can use letter codes as Idid, or numeric codes (e.g., 01, 02) to represent different languages.You typically have all the supported languages of an applicationcontained in a single SIS file. The user can then select the language theyneed when they install that file to their phone (sometimes the system willinstall the language that matches the one defined in the phone).Here are the PKG files needed to support having these languages in asingle SIS:&EN,FR,GE...{" c:\Symbian\UIQ3SDK\epoc32\data\z\resource\apps\simpleEx\SimpleEx.ren"" c:\Symbian\UIQ3SDK\epoc32\data\z\resource\apps\simpleEx\SimpleEx.rfr"" c:\Symbian\UIQ3SDK\epoc32\data\z\resource\apps\simpleEx\SimpleEx.rde"}-" !:\resource\apps\SimpleEx.rsc "The & line contains a list of language codes that determine whichlanguage options are offered to the user during installation.
Unlike theLANG statement in the MMP file, you must use predefined two-letterlanguage codes that correspond to the languages you are supporting(these are listed in section 5.9.4).The package line in the above example will cause the correct resourcefile to be installed on the phone (as \resource\apps\SimpleEx.rsc)based on the language that the user selected. It is important that the filesto be installed should be listed in the same order as the list of specifiedlanguages in the & line.12.4.5 Reading Resource Strings From CodeYou should try to avoid using displayable strings directly in the code,since this makes localizing your applications very difficult. For example,I hardcoded a string in the SimpleEx example in the following lines:_LIT(KMessage,"Start Selected!");iEikonEnv->AlertWin(KMessage);DIALOGS387The recommended way of doing this is to define a TBUF resource.
Youcould define it as follows:RESOURCE TBUF r_start_selected {buf="Start Selected!";}But a better way is to define an rls string in your RLS file (one foreach supported language):rls_string STRING_start_selected "Start Selected!"and use that in your RSS file:RESOURCE TBUF r_start_selected { STRING_start_selected;}Then in the code, you could read the resource string in the following way:TBuf<256> message;iCoeEnv->ReadResource(message, R_START_SELECTED);This will read the string defined in the TBUF resource whose resourceidentifier is R START SELECTED into the descriptor message.Note that it is not good to declare large TBuf (or any large stackallocating declaration) as an automatic variable. The TBuf could beallocated as a member variable to a heap allocated class.
Or you canuse an RBuf or HBuf heap descriptor to store the string. For HBuf, thereis a function called CCoeEnv::AllocReadResourceAsDes16L() toread a resource string to an HBuf. For example:HBufC* message = iCoeEnv->AllocReadResourceAsDes16L(R_START_SELECTED);Don’t forget to delete the HBufC when you are finished.12.5 DialogsMuch of your GUI application programming will be concerned withcreating and managing dialogs. This section discusses the basics ofcreating a dialog and presents a simple dialog you can add to SimpleExto illustrate how to create and manage a dialog box and its associatedcontrols.Dialogs exist on all Symbian OS platforms, although some of the detailsof their usage vary from platform to platform or even with modes withinthe same platform (as with UIQ).388GUI APPLICATION PROGRAMMINGA dialog is a window that has a title, one or more buttons to dismiss the dialog, and one or more lines containing controls that displayinformation and allow the user to set application-specific parameters.Dialogs are almost always modal, meaning that the user can interact onlywith the dialog, and not the rest of the application, until the dialog isdismissed.Creating a dialog typically consists of the following steps:1.Create a dialog resource in your resource file to define the dialog’stitle and set of dialog lines, where each line contains a control and atext prompt.
For S60, this resource is called DIALOG. For UIQ, it iscalled QIK DIALOG.2.Create a dialog class that, at a minimum, initializes the controls whenthe dialog is started up and processes/saves the control values whenthe dialog is dismissed.3.Implement code to launch the dialog by calling the dialog’s ExecuteLD() specifying the resource identifier of your DIALOG orQIK DIALOG resource.To best explain the process, let’s look at an example of a dialog box forboth UIQ and S60.
This dialogue is added to SimpleEx, and allows youto set the text that is displayed in the middle of the screen, as well as thecolour of the text.12.5.1Creating a Basic UIQ DialogFigure 12.9 shows the UIQ version of the SimpleEx dialog describedin the last section. The first line of the dialog has a text edit control tospecify the display text, and the second line is a choice list control, whereyou select the color of the text to be one of black, red, green, or blue.When the user selects OK, the text in the center of the screen is changedto reflect the string and color that was specified in the dialog.Before describing the UIQ dialog code, let me emphasize that thisbook covers UIQ version 3. If you have experience already on UIQversions before that, you will note that UIQ 3 is very different fromprevious versions, including how dialogs are implemented. S60 3rdEdition GUI programming, on the other hand, is very similar to previousS60 versions.First, let’s look at the resources needed to create this UIQ dialog, whichI added to the SimpleEx resource file.