Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/helloworldbasic_2doc_2index_8html_source.html
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 13 Aug 2010 16:47:46 +0100
changeset 14 578be2adaf3e
parent 6 43e37759235e
permissions -rw-r--r--
Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TB9.2 Example Applications: examples/S60CppExamples/helloworldbasic/doc/index.html Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.2 -->
<h1>examples/S60CppExamples/helloworldbasic/doc/index.html</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;!DOCTYPE HTML PUBLIC <span class="stringliteral">&quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;</span>&gt;
<a name="l00002"></a>00002 &lt;html&gt;
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 &lt;head&gt;
<a name="l00005"></a>00005 &lt;meta http-equiv=<span class="stringliteral">&quot;Content-Type&quot;</span> content=<span class="stringliteral">&quot;text/html;charset=iso-8859-1&quot;</span>&gt;
<a name="l00006"></a>00006 &lt;title&gt;Hello World Basic Example&lt;/title&gt;
<a name="l00007"></a>00007 &lt;link href=<span class="stringliteral">&quot;style.css&quot;</span> rel=<span class="stringliteral">&quot;stylesheet&quot;</span> type=<span class="stringliteral">&quot;text/css&quot;</span>&gt;
<a name="l00008"></a>00008 &lt;/head&gt;
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 &lt;table border=<span class="stringliteral">&quot;0&quot;</span> width=<span class="stringliteral">&quot;100%&quot;</span> height=<span class="stringliteral">&quot;8&quot;</span> bgcolor=<span class="stringliteral">&quot;#eeeeee&quot;</span>&gt;
<a name="l00011"></a>00011 &lt;tr&gt; &lt;td width=<span class="stringliteral">&quot;100%&quot;</span> height=<span class="stringliteral">&quot;1&quot;</span>&gt;&lt;b&gt;&lt;font size=<span class="stringliteral">&quot;2&quot;</span> color=<span class="stringliteral">&quot;#000000&quot;</span> face=<span class="stringliteral">&quot;Arial, Helvetica, sans-serif&quot;</span>&gt;&lt;strong&gt;&lt;a name=Top&gt;&lt;/a&gt;
<a name="l00012"></a>00012 S60 5th Edition SDK &lt;/strong&gt;&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;i&gt;Example Applications Guide&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;
<a name="l00013"></a>00013 &lt;!-- Generated by Doxygen 1.4.5 --&gt;
<a name="l00014"></a>00014 &lt;div <span class="keyword">class</span>=<span class="stringliteral">&quot;tabs&quot;</span>&gt;
<a name="l00015"></a>00015   &lt;ul&gt;
<a name="l00016"></a>00016     &lt;li <span class="keywordtype">id</span>=<span class="stringliteral">&quot;current&quot;</span>&gt;&lt;a href=<span class="stringliteral">&quot;index.html&quot;</span>&gt;&lt;span&gt;Main&amp;nbsp;Page&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<a name="l00017"></a>00017     &lt;li&gt;&lt;a href=<span class="stringliteral">&quot;annotated.html&quot;</span>&gt;&lt;span&gt;Classes&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<a name="l00018"></a>00018     &lt;li&gt;&lt;a href=<span class="stringliteral">&quot;files.html&quot;</span>&gt;&lt;span&gt;Files&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
<a name="l00019"></a>00019   &lt;/ul&gt;&lt;/div&gt;
<a name="l00020"></a>00020 &lt;h1&gt;Hello World Basic Example&lt;/h1&gt;
<a name="l00021"></a>00021 &lt;p&gt;
<a name="l00022"></a>00022 &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;index.html#Intro_sec&quot;</span>&gt;1. About <span class="keyword">this</span> Example&lt;/a&gt; &lt;br&gt;
<a name="l00023"></a>00023 &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;index.html#Arch_sec&quot;</span>&gt;2. Architecture&lt;/a&gt; &lt;br&gt;
<a name="l00024"></a>00024 &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;index.html#Design_sec&quot;</span>&gt;3. Design and Implementation&lt;/a&gt;&lt;p&gt;
<a name="l00025"></a>00025 &lt;hr&gt;
<a name="l00026"></a>00026 &lt;h2&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Intro_sec&quot;</span>&gt;
<a name="l00027"></a>00027 1. About <span class="keyword">this</span> Example&lt;/a&gt;&lt;/h2&gt;
<a name="l00028"></a>00028 The Hello World Basic example demonstrates how to create a simple interactive application on Symbian OS. Although the program described here basically only displays a simple string, it can be easily adapted to make much larger applications.&lt;p&gt;
<a name="l00029"></a>00029 Hello World Basic application - in addition to its evident purpose to print <span class="stringliteral">&quot;Hello World!&quot;</span> to the screen - also demonstrates displaying text with Information Note and on to the background, loading strings with the help of StringLoader, writing to and reading from a file and use of dialog to inquire user input.&lt;p&gt;
<a name="l00030"></a>00030 Furthermore, Hello World Basic application is also localized to a few different languages.&lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub11&quot;</span>&gt;
<a name="l00031"></a>00031 1.1. APIs demonstrated&lt;/a&gt;&lt;/h3&gt;
<a name="l00032"></a>00032 &lt;ul&gt;
<a name="l00033"></a>00033 &lt;li&gt;StringLoader&lt;/li&gt;&lt;li&gt;RFs, RFile, RFileWriteStream and RFileReadStream&lt;/li&gt;&lt;li&gt;CAknInformationNote&lt;/li&gt;&lt;li&gt;CAknTextQueryDialog&lt;/li&gt;&lt;/ul&gt;
<a name="l00034"></a>00034 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub12&quot;</span>&gt;
<a name="l00035"></a>00035 1.2. Prerequisites&lt;/a&gt;&lt;/h3&gt;
<a name="l00036"></a>00036 None.&lt;p&gt;
<a name="l00037"></a>00037 &lt;hr&gt;
<a name="l00038"></a>00038 &lt;h2&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Arch_sec&quot;</span>&gt;
<a name="l00039"></a>00039 2. Architecture&lt;/a&gt;&lt;/h2&gt;
<a name="l00040"></a>00040 HelloWorld follows traditional Symbian OS Control-based architecture.&lt;p&gt;
<a name="l00041"></a>00041 &lt;hr&gt;
<a name="l00042"></a>00042 &lt;h2&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Design_sec&quot;</span>&gt;
<a name="l00043"></a>00043 3. Design and Implementation&lt;/a&gt;&lt;/h2&gt;
<a name="l00044"></a>00044 &lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub31&quot;</span>&gt;
<a name="l00045"></a>00045 3.1 Capabilities&lt;/a&gt;&lt;/h3&gt;
<a name="l00046"></a>00046 Hello World application does not require any capabilities. The program capabilities are defined in &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;helloworldbasic_8mmp-source.html&quot;</span>&gt;helloworldbasic.mmp&lt;/a&gt; file: CAPABILITY NONE.&lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub32&quot;</span>&gt;
<a name="l00047"></a>00047 3.2 ScalableUI&lt;/a&gt;&lt;/h3&gt;
<a name="l00048"></a>00048 The program takes screen parameters in the start of the application and works with all screen modes. The program supports changing the screen layout <span class="keywordflow">while</span> the program is running. Note that <span class="keyword">this</span> support must be coded in the application and <span class="keyword">this</span> code resides in the &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_app_view.html#9f9bb5a2110532e2f2909eaefb44d36a&quot;</span>&gt;<a class="code" href="class_c_hello_world_basic_app_view.html#aca7c3b8a59edd4f59b8923e2a89a7fc3">CHelloWorldBasicAppView::SizeChanged</a>()&lt;/a&gt; method.&lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub33&quot;</span>&gt;
<a name="l00049"></a>00049 3.3 Static structure&lt;/a&gt;&lt;/h3&gt;
<a name="l00050"></a>00050 All the classes are derived from CBase. CBase has a number of useful features: it initialises all member data to zero, it has a <span class="keyword">virtual</span> destructor, and it implements support <span class="keywordflow">for</span> the Symbian OS cleanup stack.&lt;h3&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub34&quot;</span>&gt;
<a name="l00051"></a>00051 3.4 Launch sequence and command handling&lt;/a&gt;&lt;/h3&gt;
<a name="l00052"></a>00052 This section explains the sequence of interactions that occur on the objects described in the last section when the application is run and the user selects the Hello menu option. The following sections describe the steps in more detail.&lt;p&gt;
<a name="l00053"></a>00053 &lt;ol type=1&gt;
<a name="l00054"></a>00054 &lt;li&gt;The application is launched, the framework loads the application EXE and the E32Main() method implemented in &lt;a class=&quot;el&quot; href=&quot;helloworldbasic_8cpp-source.html&quot;&gt;helloworldbasic.cpp&lt;/a&gt; is called. Read more from &lt;a class=&quot;el&quot; href=&quot;index.html<span class="preprocessor">#Sub341&quot;&gt;3.4.1 Creating the Application object&lt;/a&gt;. &lt;br&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span>&lt;br&gt;
<a name="l00056"></a>00056 &lt;/li&gt;&lt;li&gt;E32Main() method calls the function NewApplication(). This creates an instance of the HelloWorldApplication class, and returns a pointer to it. The framework subsequently uses this pointer to complete construction of the application. &lt;br&gt;
<a name="l00057"></a>00057 &lt;br&gt;
<a name="l00058"></a>00058 &lt;/li&gt;&lt;li&gt;The framework calls virtual function AppDllUid() (implementation &lt;a class=&quot;el&quot; href=&quot;class_c_hello_world_basic_application.html<span class="preprocessor">#266a6db7f5728454ee8b7a9c5f517dca&quot;&gt;CHelloWorldBasicApplication::AppDllUid&lt;/a&gt;) to get the UID of this particular application. The UID is used to, for example, check if an instance of the application is already running, so than the existing instance can be switched to, rather than a new instance created. Read more from &lt;a class=&quot;el&quot; href=&quot;index.html#Sub342&quot;&gt;3.4.2 Getting the application&#39;s UID&lt;/a&gt;. &lt;br&gt;</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span>&lt;br&gt;
<a name="l00060"></a>00060 &lt;/li&gt;&lt;li&gt;The framework calls <span class="keyword">virtual</span> function CreateDocumentL on the CHelloWorldApplication <span class="keywordtype">object</span>: &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_application.html#0a048c97a8c1868d0e1e5daf2838bcab&quot;</span>&gt;<a class="code" href="class_c_hello_world_basic_application.html#aaa57f357e3ce5464fd4f6785864eadfe">CHelloWorldBasicApplication::CreateDocumentL</a>&lt;/a&gt;. This creates an instance of the application Document and returns a pointer to it. This allows the framework to call certain Document methods directly. The Document <span class="keywordtype">object</span> is constructed <span class="keyword">using</span> the Symbian OS construction sequence, <span class="keyword">using</span> the Document <span class="keywordtype">object</span><span class="stringliteral">&#39;s static method NewL. Read more from &lt;a class=&quot;el&quot; href=&quot;index.html#Sub343&quot;&gt;3.4.3 Creating the Document object&lt;/a&gt;. &lt;br&gt;</span>
<a name="l00061"></a>00061 <span class="stringliteral">&lt;br&gt;</span>
<a name="l00062"></a>00062 <span class="stringliteral">&lt;/li&gt;&lt;li&gt;The framework calls AppDllUid again, to see if it is necessary to load a file from the filing system. The HelloWorld example does not need to persist any information, and so does not have a file associated with it. &lt;br&gt;</span>
<a name="l00063"></a>00063 <span class="stringliteral">&lt;br&gt;</span>
<a name="l00064"></a>00064 <span class="stringliteral">&lt;/li&gt;&lt;li&gt;The framework calls the Document object&#39;</span>s CreateAppUiL method: &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_document.html#0eb34f98d849338274127e28e8c78b4e&quot;</span>&gt;<a class="code" href="class_c_hello_world_basic_document.html#ac2579614da65e8b1ba74cc5cb525f19d">CHelloWorldBasicDocument::CreateAppUiL</a>&lt;/a&gt;. This creates the AppUI <span class="keywordtype">object</span> and returns a pointer to it. &lt;br&gt;
<a name="l00065"></a>00065 &lt;br&gt;
<a name="l00066"></a>00066 &lt;/li&gt;&lt;li&gt;The framework completes the construction of the AppUI <span class="keywordtype">object</span> by calling its ConstructL method (&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_app_ui.html#9ce34ba0b947863222da3c63d0481044&quot;</span>&gt;CHelloWorldBasicAppUi::ConstructL&lt;/a&gt;). The fact the framework calls the AppUi <span class="keywordtype">object</span><span class="stringliteral">&#39;s constructor and ConstructL separately allows the framework to complete any necessary initialisation before construction of the AppUI object is completed. Read more from &lt;a class=&quot;el&quot; href=&quot;index.html#Sub344&quot;&gt;3.4.4 Creating the AppUI and View objects&lt;/a&gt;. &lt;br&gt;</span>
<a name="l00067"></a>00067 <span class="stringliteral">&lt;br&gt;</span>
<a name="l00068"></a>00068 <span class="stringliteral">&lt;/li&gt;&lt;li&gt;The &lt;a class=&quot;el&quot; href=&quot;class_c_hello_world_basic_app_ui.html#9ce34ba0b947863222da3c63d0481044&quot;&gt;CHelloWorldBasicAppUi::ConstructL&lt;/a&gt; method first calls the base class&#39;</span>s BaseConstructL. This performs such tasks as reading the resource file associated with an application. &lt;br&gt;
<a name="l00069"></a>00069 &lt;br&gt;
<a name="l00070"></a>00070 &lt;/li&gt;&lt;li&gt;The AppUi calls &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_app_view.html#5891ab00f23b517058efe213c1febfd2&quot;</span>&gt;<a class="code" href="class_c_hello_world_basic_app_view.html#af938676f7eee65925c90b654b5a5034f">CHelloWorldBasicAppView::NewL</a>&lt;/a&gt; to create the AppView object, <span class="keyword">using</span> Symbian two phase construction. &lt;br&gt;
<a name="l00071"></a>00071 &lt;br&gt;
<a name="l00072"></a>00072 &lt;/li&gt;&lt;li&gt;The framework calls the Draw (&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_app_view.html#67f946ca7848ec78de4961c5bcefdb72&quot;</span>&gt;CHelloWorldBasicAppView::Draw&lt;/a&gt;) method to draw the view. In this case it will cause a blank screen to be displayed. Read more from &lt;a class=&quot;el&quot; href=&quot;index.html<span class="preprocessor">#Sub345&quot;&gt;3.4.5 Redrawing the screen&lt;/a&gt;. &lt;div align=&quot;center&quot;&gt;</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span>&lt;img src=<span class="stringliteral">&quot;application_started.png&quot;</span> alt=<span class="stringliteral">&quot;application_started.png&quot;</span>&gt;
<a name="l00074"></a>00074 &lt;/div&gt;
<a name="l00075"></a>00075 &lt;/li&gt;&lt;li&gt;Whenever the user selects a menu option, &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;class_c_hello_world_basic_app_ui.html#a682d228622cea7790645ce10f591242&quot;</span>&gt;CHelloWorldBasicAppUi::HandleCommandL&lt;/a&gt; is called by the framework and is passed an argument, aCommand, that indicates the command the user selected. The AppUI can then perform whatever actions are required <span class="keywordflow">for</span> that particular menu option: &lt;div align=<span class="stringliteral">&quot;center&quot;</span>&gt;
<a name="l00076"></a>00076 &lt;img src=<span class="stringliteral">&quot;application_menu.png&quot;</span> alt=<span class="stringliteral">&quot;application_menu.png&quot;</span>&gt;
<a name="l00077"></a>00077 &lt;/div&gt;
<a name="l00078"></a>00078 &lt;ol type=a&gt;
<a name="l00079"></a>00079 &lt;li&gt;In <span class="keywordflow">case</span> of <span class="stringliteral">&quot;Hello&quot;</span>, it creates an Information note with the text specified in resource file in it, and displays it.&lt;/li&gt;&lt;li&gt;In <span class="keywordflow">case</span> of <span class="stringliteral">&quot;Hello from file&quot;</span>, it reads text from Hello.txt -file and displays it in Information note.&lt;/li&gt;&lt;li&gt;In <span class="keywordflow">case</span> of <span class="stringliteral">&quot;Hello from edit&quot;</span>, it asks text from the user with a dialog and displays it on the screen.&lt;/li&gt;&lt;/ol&gt;
<a name="l00080"></a>00080 &lt;/li&gt;&lt;/ol&gt;
<a name="l00081"></a>00081 &lt;h4&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub341&quot;</span>&gt;
<a name="l00082"></a>00082 3.4.1 Creating the Application <span class="keywordtype">object</span>&lt;/a&gt;&lt;/h4&gt;
<a name="l00083"></a>00083 It is important to note that the NewApplication method is exported by the EXE. This is achieved by adding the EXPORT_C directive before <span class="keyword">this</span> function in the &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;helloworldbasic_8cpp-source.html&quot;</span>&gt;helloworldbasic.cpp&lt;/a&gt; file. If the EXPORT_C directive is missing, the code will fail to link.&lt;p&gt;
<a name="l00084"></a>00084 The framework calls the function that is exported by the application at ordinal 1 in the DLL. This means that the first function defined in the DEF-file <span class="keywordflow">for</span> an application must be the NewApplication method. By <span class="keywordflow">default</span>, the tool chain automatically ensures that <span class="keyword">this</span> is the <span class="keywordflow">case</span> <span class="keywordflow">for</span> a Symbian OS application.&lt;p&gt;
<a name="l00085"></a>00085 Note that <span class="keyword">this</span> construction does not use the usual Symbian OS <span class="keyword">new</span> (ELeave) method, but the C++ style <span class="keyword">new</span> method. This is because a TRAP harness has not been created <span class="keywordflow">for</span> the application at <span class="keyword">this</span> point. If the system is unable to allocate memory <span class="keywordflow">for</span> a <span class="keyword">new</span> instance of the application, the returned instance pointer will be NULL. The framework checks <span class="keywordflow">for</span>, and copes with, <span class="keyword">this</span> possibility.&lt;h4&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub342&quot;</span>&gt;
<a name="l00086"></a>00086 3.4.2 Getting the application<span class="stringliteral">&#39;s UID&lt;/a&gt;&lt;/h4&gt;</span>
<a name="l00087"></a>00087 <span class="stringliteral">AppDllUid which gets the application&#39;</span>s UID must be present, or the application will fail to link.&lt;h4&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub343&quot;</span>&gt;
<a name="l00088"></a>00088 3.4.3 Creating the Document object&lt;/a&gt;&lt;/h4&gt;
<a name="l00089"></a>00089 The Application <span class="keywordtype">object</span> is responsible <span class="keywordflow">for</span> creating an instance of the Document <span class="keywordtype">object</span>. However, it is not required to destroy it. Destruction of the Document <span class="keywordtype">object</span> is performed by the framework.&lt;h4&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub344&quot;</span>&gt;
<a name="l00090"></a>00090 3.4.4 Creating the AppUI and View objects&lt;/a&gt;&lt;/h4&gt;
<a name="l00091"></a>00091 Note that creation of the AppUi <span class="keywordtype">object</span> does not use the Symbian OS two phase construction sequence. Instead the C++ constructor is called, and a pointer to the created instance is returned to the framework. The framework completes construction by calling ConstructL later. Ownership of the AppUI is passed to the framework, and so the Document <span class="keywordtype">object</span> is not responsible <span class="keywordflow">for</span> destroying it.&lt;h4&gt;&lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;anchor&quot;</span> name=<span class="stringliteral">&quot;Sub345&quot;</span>&gt;
<a name="l00092"></a>00092 3.4.5 Redrawing the screen&lt;/a&gt;&lt;/h4&gt;
<a name="l00093"></a>00093 The Draw method is called by the framework when the view needs to be redrawn, and contains all the code necessary to draw the view <span class="keywordflow">for</span> <span class="keyword">this</span> application. Note that the framework only calls the Draw method in response to general system events. So, <span class="keywordflow">for</span> example, the framework automatically calls Draw when the application is launched, when the Options menu disappears, and <span class="keywordflow">if</span> the application regains focus.&lt;p&gt;
<a name="l00094"></a>00094 The programmer cannot call the Draw method directly, as it requires the system<span class="stringliteral">&#39;s graphics context to be activated before it is called. Instead, if the programmer wishes to have the screen redrawn, they should call the DrawNow method.&lt;p&gt;</span>
<a name="l00095"></a>00095 <span class="stringliteral">Note that the Draw function cannot leave. This is because the function may be called directly by the framework, and the framework would not know how to handle any errors that might occur. Instead the Draw function must TRAP and handle any errors that might occur.&lt;h4&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub346&quot;&gt;</span>
<a name="l00096"></a>00096 <span class="stringliteral">3.4.6 Handling commands&lt;/a&gt;&lt;/h4&gt;</span>
<a name="l00097"></a>00097 <span class="stringliteral">&lt;a class=&quot;el&quot; href=&quot;class_c_hello_world_basic_app_ui.html#a682d228622cea7790645ce10f591242&quot;&gt;HandleCommandL &lt;/a&gt; is called on the AppUi object whenever the user selects a menu option. The argument aCommand indicates the command the user selected. HandleCommandL typically takes the form of a switch statement which invokes different actions according to the value of aCommand.&lt;p&gt;</span>
<a name="l00098"></a>00098 <span class="stringliteral">&lt;b&gt;Handling command &quot;Hello&quot;&lt;/b&gt;&lt;p&gt;</span>
<a name="l00099"></a>00099 <span class="stringliteral">&lt;ul&gt;</span>
<a name="l00100"></a>00100 <span class="stringliteral">&lt;li&gt;string is loaded from the resource file with StringLoader&lt;/li&gt;&lt;li&gt;Information note is shown from the descriptor&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00101"></a>00101 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00102"></a>00102 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00103"></a>00103 <span class="stringliteral">&lt;img src=&quot;information_note.png&quot; alt=&quot;information_note.png&quot;&gt;</span>
<a name="l00104"></a>00104 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00105"></a>00105 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00106"></a>00106 <span class="stringliteral">&lt;b&gt;Handling command &quot;Hello from file&quot;&lt;/b&gt;&lt;p&gt;</span>
<a name="l00107"></a>00107 <span class="stringliteral">&lt;ul&gt;</span>
<a name="l00108"></a>00108 <span class="stringliteral">&lt;li&gt;connection to the file server is opened with RFs&lt;/li&gt;&lt;li&gt;RFile is used to open &quot;Hello.txt&quot;-file for reading&lt;/li&gt;&lt;li&gt;A RFileStream object is created from the file&lt;/li&gt;&lt;li&gt;An HBufC descriptor is created from the RFileReadStream object&lt;/li&gt;&lt;li&gt;The descriptor reads from the stream both the length of the data followed by the data. After this descriptor has been read the stream will be positioned at the beginning of the data.&lt;/li&gt;&lt;li&gt;Information note is shown from the descriptor&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00109"></a>00109 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00110"></a>00110 <span class="stringliteral">&lt;dl compact&gt;&lt;dt&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;&quot;Hello.txt&quot;-file, which is read during the execution of this command, is actually created by the application itself during the execution of &lt;a class=&quot;el&quot; href=&quot;class_c_hello_world_basic_app_ui.html#9ce34ba0b947863222da3c63d0481044&quot;&gt;CHelloWorldBasicAppUi::ConstructL&lt;/a&gt;. In other words, it is not an exported ready-made file. The reason for this is that HelloWorld is localized to different languages; and thus during start-up the file is created and the text is written into it with the current language.&lt;/dd&gt;&lt;/dl&gt;</span>
<a name="l00111"></a>00111 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00112"></a>00112 <span class="stringliteral">&lt;img src=&quot;japanese_hello.png&quot; alt=&quot;japanese_hello.png&quot;&gt;</span>
<a name="l00113"></a>00113 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00114"></a>00114 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00115"></a>00115 <span class="stringliteral">&lt;b&gt;Handling command &quot;Hello from edit&quot;&lt;/b&gt;&lt;p&gt;</span>
<a name="l00116"></a>00116 <span class="stringliteral">&lt;ul&gt;</span>
<a name="l00117"></a>00117 <span class="stringliteral">&lt;li&gt;a string is loaded from the resource file with StringLoader&lt;/li&gt;&lt;li&gt;&lt;a class=&quot;el&quot; href=&quot;class_c_hello_world_query_dialog.html&quot;&gt;CHelloWorldQueryDialog&lt;/a&gt; is created and the loaded string is passed to it to be used as default value for input and also a descriptor is passed to store the input given by the user&lt;/li&gt;&lt;li&gt;no other actions are made, but the text will be displayed in the screen, when the framework calls &lt;a class=&quot;el&quot; href=&quot;class_c_hello_world_basic_app_view.html#67f946ca7848ec78de4961c5bcefdb72&quot;&gt;Draw &lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00118"></a>00118 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00119"></a>00119 <span class="stringliteral">&lt;div align=&quot;center&quot;&gt;</span>
<a name="l00120"></a>00120 <span class="stringliteral">&lt;img src=&quot;dialog.png&quot; alt=&quot;dialog.png&quot;&gt;</span>
<a name="l00121"></a>00121 <span class="stringliteral">&lt;/div&gt;</span>
<a name="l00122"></a>00122 <span class="stringliteral">&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub35&quot;&gt;</span>
<a name="l00123"></a>00123 <span class="stringliteral">3.5 Handling key events&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00124"></a>00124 <span class="stringliteral">If the application is required to respond to user keypresses, the AddToStackL method must be called by the AppUi object&#39;</span>s ConstructL method, with the AppView <span class="keywordtype">object</span> as an argument. This adds the AppView <span class="keywordtype">object</span> to the control stack.&lt;p&gt;
<a name="l00125"></a>00125 If the view is on the control stack, then whenever the user presses a key the OfferKeyEventL method is called. This has arguments that indicate the type of key event (key down, key press or key up) as well as the code of the key pressed.&lt;p&gt;
<a name="l00126"></a>00126 When the AppUi <span class="keywordtype">object</span> is destroyed, the AppView must be removed from the stack. This is done by calling RemoveFromStack in the AppUi <span class="keywordtype">object</span><span class="stringliteral">&#39;s destructor.&lt;h3&gt;&lt;a class=&quot;anchor&quot; name=&quot;Sub36&quot;&gt;</span>
<a name="l00127"></a>00127 <span class="stringliteral">3.6 Localization&lt;/a&gt;&lt;/h3&gt;</span>
<a name="l00128"></a>00128 <span class="stringliteral">HelloWorld application is localized for English, Finnish, Chinese and Japanese. The &quot;main&quot; rls-file HelloWorldBasic.rls includes language specific rls-files, which all each define the same resource strings in specific language. The localized rls-files contain language id in their name (enum TLanguage in e32const.h specifies language identification values), for example: HelloWorldBasic_32.rls.&lt;p&gt;</span>
<a name="l00129"></a>00129 <span class="stringliteral">When localizing to languages, which do not use Western alphabets, such as Chinese or Japanese, a couple of additional steps needs to be taken. As the language cannot be written in ASCII, the language-specific rls-file has to&lt;ul&gt;</span>
<a name="l00130"></a>00130 <span class="stringliteral">&lt;li&gt;be written in UTF-8 format, and&lt;/li&gt;&lt;li&gt;contain a line CHARACTER_SET UTF8.&lt;/li&gt;&lt;/ul&gt;</span>
<a name="l00131"></a>00131 <span class="stringliteral">&lt;p&gt;</span>
<a name="l00132"></a>00132 <span class="stringliteral">&lt;dl compact&gt;&lt;dt&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;/dt&gt;&lt;dd&gt;Certain editors add some &quot;meta-bytes&quot; into the beginning of file stored in UTF-format. Unfortunately Symbian&#39;</span>s resource compiler RCOMP cannot deal with those additional bytes and resource file compilation will fail. It you encounter <span class="keyword">this</span>, you have to <span class="keyword">remove</span> those additional bytes with some other editor.&lt;/dd&gt;&lt;/dl&gt;
<a name="l00133"></a>00133 Furthermore, localization affects mmp- and pkg-files also:&lt;ul&gt;
<a name="l00134"></a>00134 &lt;li&gt;languages need to be defined in mmp-file. See LANG in &lt;a <span class="keyword">class</span>=<span class="stringliteral">&quot;el&quot;</span> href=<span class="stringliteral">&quot;helloworldbasic_8mmp-source.html&quot;</span>&gt;HelloWorldBasic.mmp&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;languages need to be defined in pkg-files and language dependent resource files have to be listed. In addition, most of the strings (e.g. component name) are required to be localized <span class="keywordflow">for each</span> defined language. See S60 SDK Help <span class="stringliteral">&quot;Package file format&quot;</span> <span class="keywordflow">for</span> more detailed information.&lt;/li&gt;&lt;/ul&gt;
<a name="l00135"></a>00135 &lt;p&gt;
<a name="l00136"></a>00136 Additionally, HelloWorld application<span class="stringliteral">&#39;s pkg-files demonstrate two ways to install localized application:&lt;ul&gt;</span>
<a name="l00137"></a>00137 <span class="stringliteral">&lt;li&gt;the language is determined during installation - and only the determined language is installed (the application&#39;</span>s language does not change, even <span class="keywordflow">if</span> the language in the phone is changed). &lt;br&gt;
<a name="l00138"></a>00138  HelloWorldBasic_gcce.pkg is made in <span class="keyword">this</span> fashion.&lt;/li&gt;&lt;li&gt;the language is determined during installation, but all the supported languages are installed. If the language in the phone changes, the language of the HelloWorld-application changes also, <span class="keywordflow">if</span> it supports the <span class="keyword">new</span> language (English otherwise). &lt;br&gt;
<a name="l00139"></a>00139  HelloWorldBasic_armv5.pkg is made in <span class="keyword">this</span> fashion. &lt;/li&gt;&lt;/ul&gt;
<a name="l00140"></a>00140 &lt;hr&gt;
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 &lt;table x-use-null-cells
<a name="l00143"></a>00143                 style=<span class="stringliteral">&quot;x-cell-content-align: top;</span>
<a name="l00144"></a>00144 <span class="stringliteral">                                width: 100%;</span>
<a name="l00145"></a>00145 <span class="stringliteral">                                border-spacing: 0px;</span>
<a name="l00146"></a>00146 <span class="stringliteral">                                border-spacing: 0px;&quot;</span>
<a name="l00147"></a>00147                 cellspacing=0
<a name="l00148"></a>00148                 width=100%&gt;
<a name="l00149"></a>00149   &lt;col style=<span class="stringliteral">&quot;width: 50%;&quot;</span>&gt;
<a name="l00150"></a>00150   &lt;col style=<span class="stringliteral">&quot;width: 50%;&quot;</span>&gt;
<a name="l00151"></a>00151 
<a name="l00152"></a>00152   &lt;tr style=<span class="stringliteral">&quot;x-cell-content-align: top;&quot;</span>
<a name="l00153"></a>00153         valign=top&gt;
<a name="l00154"></a>00154   &lt;td style=<span class="stringliteral">&quot;width: 50%;</span>
<a name="l00155"></a>00155 <span class="stringliteral">                        padding-right: 10px;</span>
<a name="l00156"></a>00156 <span class="stringliteral">                        padding-left: 10px;</span>
<a name="l00157"></a>00157 <span class="stringliteral">                        border-right-style: None;</span>
<a name="l00158"></a>00158 <span class="stringliteral">                        border-left-style: None;</span>
<a name="l00159"></a>00159 <span class="stringliteral">                        border-top-style: None;</span>
<a name="l00160"></a>00160 <span class="stringliteral">                        border-bottom-style: None;&quot;</span>
<a name="l00161"></a>00161         width=50%&gt;
<a name="l00162"></a>00162   &lt;p style=<span class="stringliteral">&quot;font-family: Arial;&quot;</span>&gt;&lt;small style=<span class="stringliteral">&quot;font-size: smaller;&quot;</span>&gt;© Nokia 2009&lt;/small&gt;&lt;/td&gt;
<a name="l00163"></a>00163   &lt;td style=<span class="stringliteral">&quot;width: 50%;</span>
<a name="l00164"></a>00164 <span class="stringliteral">                        padding-right: 10px;</span>
<a name="l00165"></a>00165 <span class="stringliteral">                        padding-left: 10px;</span>
<a name="l00166"></a>00166 <span class="stringliteral">                        border-top-style: None;</span>
<a name="l00167"></a>00167 <span class="stringliteral">                        border-bottom-style: None;</span>
<a name="l00168"></a>00168 <span class="stringliteral">                        border-right-style: None;&quot;</span>
<a name="l00169"></a>00169         width=50%&gt;
<a name="l00170"></a>00170   &lt;p style=<span class="stringliteral">&quot;text-align: right; margin-right: -4px;&quot;</span>
<a name="l00171"></a>00171         align=right&gt;&lt;span style=<span class="stringliteral">&quot;font-weight: bold;&quot;</span>&gt;&lt;a href=<span class="stringliteral">&quot;#Top&quot;</span>
<a name="l00172"></a>00172                                                                                                         title=<span class="stringliteral">&quot;Back to top&quot;</span>&gt;&lt;img
<a name="l00173"></a>00173  src=<span class="stringliteral">&quot;top.gif&quot;</span>
<a name="l00174"></a>00174         x-maintain-ratio=TRUE
<a name="l00175"></a>00175         alt=<span class="stringliteral">&quot;Back to top&quot;</span>
<a name="l00176"></a>00176         style=<span class="stringliteral">&quot;border: none;</span>
<a name="l00177"></a>00177 <span class="stringliteral">                        width: 18px;</span>
<a name="l00178"></a>00178 <span class="stringliteral">                        height: 15px;</span>
<a name="l00179"></a>00179 <span class="stringliteral">                        float: none;</span>
<a name="l00180"></a>00180 <span class="stringliteral">                        border-style: none;</span>
<a name="l00181"></a>00181 <span class="stringliteral">                        border-style: none;&quot;</span>
<a name="l00182"></a>00182         width=18
<a name="l00183"></a>00183         height=15
<a name="l00184"></a>00184         border=0&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
<a name="l00185"></a>00185  &lt;/table&gt;
<a name="l00186"></a>00186 &lt;/body&gt;
<a name="l00187"></a>00187 &lt;/html&gt;
<a name="l00188"></a>00188 
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>