Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_e_com_calculator_appui_8cpp_source.html
Initial contribution of the Adaptation Documentation.
<!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/ForumNokia/EComCalculator/client/src/EComCalculatorAppui.cpp 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/ForumNokia/EComCalculator/client/src/EComCalculatorAppui.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * ============================================================================</span>
<a name="l00003"></a>00003 <span class="comment"> * Name : CEComCalculatorAppUi from CEComCalculatorAppui.cpp</span>
<a name="l00004"></a>00004 <span class="comment"> * Part of : EComCalculator</span>
<a name="l00005"></a>00005 <span class="comment"> * Created : 29/05/2006 by Forum Nokia</span>
<a name="l00006"></a>00006 <span class="comment"> * Version : 2.0</span>
<a name="l00007"></a>00007 <span class="comment"> * Copyright: Nokia Corporation</span>
<a name="l00008"></a>00008 <span class="comment"> * ============================================================================</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010
<a name="l00011"></a>00011 <span class="preprocessor">#include <avkon.hrh></span>
<a name="l00012"></a>00012 <span class="preprocessor">#include <aknnotewrappers.h></span> <span class="comment">// CAknInformationNote</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include "EComCalculatorAppUi.h"</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include "EComCalculatorAppView.h"</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include "EComCalculator.hrh"</span> <span class="comment">// menu commands</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include "EComInterfaceDefinition.h"</span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018
<a name="l00019"></a>00019 <span class="comment">// Names of plugin operations. Valid values are defined in plugin's</span>
<a name="l00020"></a>00020 <span class="comment">// resource file. See</span>
<a name="l00021"></a>00021 <span class="comment">// ..\..\plugin\101F5465.RSS</span>
<a name="l00022"></a>00022 <span class="comment">// Typically plugin provider gives these in the plugin documentation.</span>
<a name="l00023"></a>00023 _LIT8(KSumOperationName,<span class="stringliteral">"sum"</span>);
<a name="l00024"></a>00024 _LIT8(KMultiplyOperationName,<span class="stringliteral">"multiply"</span>);
<a name="l00025"></a>00025 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KImplNotFound,<span class="stringliteral">"Implementation not found: "</span>);
<a name="l00026"></a>00026 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KEComErr,<span class="stringliteral">"ECOM error: "</span>);
<a name="l00027"></a>00027 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KEComErrCont,<span class="stringliteral">". Is the Calculation plugin installed?"</span>);
<a name="l00028"></a>00028
<a name="l00029"></a>00029 <span class="keyword">const</span> TInt KOpNameLength=32;
<a name="l00030"></a>00030 <span class="keyword">const</span> TInt KOpLength = 64;
<a name="l00031"></a>00031 <span class="keyword">const</span> TInt KErrMsgLength = 128;
<a name="l00032"></a>00032
<a name="l00033"></a>00033
<a name="l00034"></a>00034 <span class="comment">// Perform the second phase construction. This is allowed to leave.</span>
<a name="l00035"></a><a class="code" href="class_c_e_com_calculator_app_ui.html#a895c22e48cfabbb49e2ee7b52c2f25d6">00035</a> <span class="keywordtype">void</span> <a class="code" href="class_c_e_com_calculator_app_ui.html#a895c22e48cfabbb49e2ee7b52c2f25d6">CEComCalculatorAppUi::ConstructL</a>()
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037 BaseConstructL(EAknEnableSkin);
<a name="l00038"></a>00038
<a name="l00039"></a>00039 <span class="comment">// Create the view. Note that the view in this example is not CAknView,</span>
<a name="l00040"></a>00040 <span class="comment">// but a simple Avkon UI compound control.</span>
<a name="l00041"></a>00041 iAppView = <a class="code" href="class_c_e_com_calculator_app_view.html#a684da4b24db80dcf7dc41768e59d1435">CEComCalculatorAppView::NewL</a>(ClientRect());
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="comment">// Add the view to control stack so that it is able to receive key events.</span>
<a name="l00044"></a>00044 <span class="comment">// The CEComCalculatorAppView handles them in the OfferKeyEventL method.</span>
<a name="l00045"></a>00045 AddToStackL(iAppView);
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047
<a name="l00048"></a>00048 <span class="comment">// Construct the AppUi. This may not leave.</span>
<a name="l00049"></a><a class="code" href="class_c_e_com_calculator_app_ui.html#a1184b0545d8fd1610a1fb7afd6300f04">00049</a> <a class="code" href="class_c_e_com_calculator_app_ui.html#a1184b0545d8fd1610a1fb7afd6300f04">CEComCalculatorAppUi::CEComCalculatorAppUi</a>()
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051 <span class="comment">// No implementation required</span>
<a name="l00052"></a>00052 }
<a name="l00053"></a>00053
<a name="l00054"></a>00054 <span class="comment">// Destructor. Release reserved resources.</span>
<a name="l00055"></a><a class="code" href="class_c_e_com_calculator_app_ui.html#a69fa3e3f4e5835e6bc9caacdf2f72878">00055</a> <a class="code" href="class_c_e_com_calculator_app_ui.html#a69fa3e3f4e5835e6bc9caacdf2f72878">CEComCalculatorAppUi::~CEComCalculatorAppUi</a>()
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057 <span class="keywordflow">if</span> (iAppView)
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059 <span class="comment">// Remember to remove the view from control stack.</span>
<a name="l00060"></a>00060 iEikonEnv->RemoveFromStack(iAppView);
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062
<a name="l00063"></a>00063 <span class="keyword">delete</span> iAppView;
<a name="l00064"></a>00064 iAppView = NULL;
<a name="l00065"></a>00065
<a name="l00066"></a>00066 <span class="preprocessor">#ifdef __SERIES60_3X__</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span> REComSession::FinalClose();
<a name="l00068"></a>00068 <span class="preprocessor">#endif</span>
<a name="l00069"></a>00069 <span class="preprocessor"></span> }
<a name="l00070"></a>00070
<a name="l00071"></a>00071 <span class="comment">// Handle menu commands. The commands are defined in EComCalculator.hrh</span>
<a name="l00072"></a><a class="code" href="class_c_e_com_calculator_app_ui.html#ad563dcdda58399fcf1516e026dd371e7">00072</a> <span class="keywordtype">void</span> <a class="code" href="class_c_e_com_calculator_app_ui.html#ad563dcdda58399fcf1516e026dd371e7">CEComCalculatorAppUi::HandleCommandL</a>(TInt aCommand)
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074 <span class="keywordflow">switch</span>(aCommand)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076 <span class="keywordflow">case</span> ECalculateSumCmd:
<a name="l00077"></a>00077 <span class="keywordflow">case</span> ECalculateMultiplyCmd:
<a name="l00078"></a>00078 CalculateL(aCommand);
<a name="l00079"></a>00079 <span class="keywordflow">break</span>;
<a name="l00080"></a>00080
<a name="l00081"></a>00081 <span class="keywordflow">case</span> EAknSoftkeyExit:
<a name="l00082"></a>00082 <span class="keywordflow">case</span> EEikCmdExit:
<a name="l00083"></a>00083 Exit();
<a name="l00084"></a>00084 <span class="keywordflow">break</span>;
<a name="l00085"></a>00085
<a name="l00086"></a>00086 <span class="keywordflow">default</span>:
<a name="l00087"></a>00087 <span class="keywordflow">break</span>;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090
<a name="l00091"></a>00091 <span class="comment">// Perform calculation and tell the view to show the result.</span>
<a name="l00092"></a>00092 <span class="keywordtype">void</span> CEComCalculatorAppUi::CalculateL(TInt aCommand)
<a name="l00093"></a>00093 {
<a name="l00094"></a>00094 TBuf8<KOpNameLength> operationName; <span class="comment">// Data used in ECOM resolution.</span>
<a name="l00095"></a>00095 <span class="comment">// Either "sum" or "multiply"</span>
<a name="l00096"></a>00096 TReal A, B, calcResult;
<a name="l00097"></a>00097 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFailedA,<span class="stringliteral">"Failed. A is not a valid number."</span>);
<a name="l00098"></a>00098 <a class="code" href="secureclientandserver_8h.html#a5eadd4429627d82193b37536d4faa03a">_LIT</a>(KFailedB,<span class="stringliteral">"Failed. B is not a valid number."</span>);
<a name="l00099"></a>00099
<a name="l00100"></a>00100 <span class="comment">// Gather required info to perform ECOM interface call.</span>
<a name="l00101"></a>00101 <span class="keywordflow">if</span>( iAppView-><a class="code" href="class_c_e_com_calculator_app_view.html#a26b6acd4cea10ef2c8bd4724f284c6f9">GetA</a>(A) != KErrNone )
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103 ShowNoteL(KFailedA);
<a name="l00104"></a>00104 <span class="keywordflow">return</span>;
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 <span class="keywordflow">if</span>( iAppView-><a class="code" href="class_c_e_com_calculator_app_view.html#a8ade2ea0aa3f0ca7f99086ab3fc86433">GetB</a>(B) != KErrNone )
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108 ShowNoteL(KFailedB);
<a name="l00109"></a>00109 <span class="keywordflow">return</span>;
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111
<a name="l00112"></a>00112 <span class="keywordflow">if</span>(aCommand == ECalculateSumCmd)
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114 operationName.Append(KSumOperationName); <span class="comment">// "sum"</span>
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116 <span class="keywordflow">else</span>
<a name="l00117"></a>00117 {
<a name="l00118"></a>00118 operationName.Append(KMultiplyOperationName); <span class="comment">// "multiply"</span>
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120
<a name="l00121"></a>00121 <span class="keywordflow">if</span>(DoEComCalculationL(operationName, A, B, calcResult) == KErrNone)
<a name="l00122"></a>00122 iAppView-><a class="code" href="class_c_e_com_calculator_app_view.html#ab71438832dbc68110ebaefd1c42c5c19">ShowResultL</a>(operationName, calcResult);
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124
<a name="l00125"></a>00125 <span class="comment">// Let the ECOM plugin do the calculation.</span>
<a name="l00126"></a>00126 TInt CEComCalculatorAppUi::DoEComCalculationL(<span class="keyword">const</span> TDesC8& aOperationName,
<a name="l00127"></a>00127 TReal aA, TReal aB, TReal& aResult)
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129 <span class="comment">// Create instance of our own ECOM interface definition. The NewL</span>
<a name="l00130"></a>00130 <span class="comment">// method will ask ECOM framework to find appropriate implementation</span>
<a name="l00131"></a>00131 <span class="comment">// for the interface. The file</span>
<a name="l00132"></a>00132 <span class="comment">// ..\..\interface\EComInterfaceDefinition.inl</span>
<a name="l00133"></a>00133 <span class="comment">// defines, how the framework will search. It uses default resolver.</span>
<a name="l00134"></a>00134 <span class="comment">//</span>
<a name="l00135"></a>00135 <span class="comment">// The NewL fails, if there is no plugin installed in the system,</span>
<a name="l00136"></a>00136 <span class="comment">// or if an implementation for aOperationName cannot be found</span>
<a name="l00137"></a>00137 <span class="comment">// (resolved).</span>
<a name="l00138"></a>00138 <span class="comment">//</span>
<a name="l00139"></a>00139 <span class="comment">// - aOperationName must match one of the names of plugin</span>
<a name="l00140"></a>00140 <span class="comment">// implementations. The valid names are defined in plugin</span>
<a name="l00141"></a>00141 <span class="comment">// implementation resource file, see</span>
<a name="l00142"></a>00142 <span class="comment">// ..\..\plugin\101F5465.RSS</span>
<a name="l00143"></a>00143 <span class="comment">// The field "default_data" specifies name for a implementation.</span>
<a name="l00144"></a>00144 <span class="comment">// (In more detail, it is the identification data used by resolver.</span>
<a name="l00145"></a>00145 <span class="comment">// Default resolver used in this example just checks the matching</span>
<a name="l00146"></a>00146 <span class="comment">// string.)</span>
<a name="l00147"></a>00147 <span class="comment">//</span>
<a name="l00148"></a>00148 <span class="comment">// - In emulator, the plugin implementation project must be built.</span>
<a name="l00149"></a>00149 <span class="comment">// In device, the plugin dll providing implementations must be</span>
<a name="l00150"></a>00150 <span class="comment">// installed. See</span>
<a name="l00151"></a>00151 <span class="comment">// ..\..\plugin.</span>
<a name="l00152"></a>00152 <span class="comment">// If there is no plugin available, the ECOM framework causes leave.</span>
<a name="l00153"></a>00153 <span class="comment">//</span>
<a name="l00154"></a>00154 <a class="code" href="class_c_calculation_interface_definition.html">CCalculationInterfaceDefinition</a>* calculateInterface = NULL;
<a name="l00155"></a>00155 TRAPD(error,
<a name="l00156"></a>00156 calculateInterface =
<a name="l00157"></a>00157 <a class="code" href="class_c_calculation_interface_definition.html#a0c188739edb316bd3a93843f6d997593">CCalculationInterfaceDefinition::NewL</a>(aOperationName);
<a name="l00158"></a>00158 )
<a name="l00159"></a>00159 <span class="keywordflow">if</span>( error )
<a name="l00160"></a>00160 {
<a name="l00161"></a>00161 HandleEComInitializationErrorL(error, aOperationName);
<a name="l00162"></a>00162 <span class="keywordflow">return</span> error;
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 CleanupStack::PushL(calculateInterface);
<a name="l00165"></a>00165
<a name="l00166"></a>00166 <span class="comment">// Use given interface implementation to perform calculation.</span>
<a name="l00167"></a>00167 aResult = calculateInterface-><a class="code" href="class_c_calculation_interface_definition.html#aa0f96f52f4d5b6c55d7aa6b0aea0c3b7">Calculate</a>(aA, aB);
<a name="l00168"></a>00168
<a name="l00169"></a>00169 CleanupStack::PopAndDestroy(calculateInterface);
<a name="l00170"></a>00170 <span class="keywordflow">return</span> KErrNone;
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172
<a name="l00173"></a>00173 <span class="comment">// Show error note for ECOM errors</span>
<a name="l00174"></a>00174 <span class="keywordtype">void</span> CEComCalculatorAppUi::HandleEComInitializationErrorL(TInt aError,
<a name="l00175"></a>00175 <span class="keyword">const</span> TDesC8& aOperationName)<span class="keyword"> const</span>
<a name="l00176"></a>00176 <span class="keyword"> </span>{
<a name="l00177"></a>00177
<a name="l00178"></a>00178 TBuf<KOpLength> operationName16bit;
<a name="l00179"></a>00179 TBuf<KErrMsgLength> errorMsg;
<a name="l00180"></a>00180 operationName16bit.Copy(aOperationName);
<a name="l00181"></a>00181
<a name="l00182"></a>00182 <span class="keywordflow">if</span>(aError == KErrNotFound) <span class="comment">// Plugin implementation not found (no match)</span>
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184 errorMsg.Append(KImplNotFound);
<a name="l00185"></a>00185 errorMsg.Append(operationName16bit);
<a name="l00186"></a>00186 ShowNoteL(errorMsg);
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(aError != KErrNone) <span class="comment">// Some other ECOM error. See in SDK help</span>
<a name="l00189"></a>00189 {
<a name="l00190"></a>00190 errorMsg.Append(KEComErr);
<a name="l00191"></a>00191 errorMsg.AppendNum(aError);
<a name="l00192"></a>00192 errorMsg.Append(KEComErrCont);
<a name="l00193"></a>00193 ShowNoteL(errorMsg);
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196
<a name="l00197"></a>00197 <span class="comment">// Show a note. Note that successive frequent calls to this method results in</span>
<a name="l00198"></a>00198 <span class="comment">// showing the latest message only.</span>
<a name="l00199"></a>00199 <span class="keywordtype">void</span> CEComCalculatorAppUi::ShowNoteL(<span class="keyword">const</span> TDesC& aMessage)<span class="keyword"> const</span>
<a name="l00200"></a>00200 <span class="keyword"> </span>{
<a name="l00201"></a>00201
<a name="l00202"></a>00202 CAknInformationNote* note = <span class="keyword">new</span>(ELeave)CAknInformationNote;
<a name="l00203"></a>00203 note->ExecuteLD(aMessage); <span class="comment">// Deletes itself, when returns</span>
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205
<a name="l00206"></a><a class="code" href="class_c_e_com_calculator_app_ui.html#a65f8e6daaf8c5545eb64784b4d59495c">00206</a> <span class="keywordtype">void</span> <a class="code" href="class_c_e_com_calculator_app_ui.html#a65f8e6daaf8c5545eb64784b4d59495c">CEComCalculatorAppUi::HandleResourceChangeL</a>(TInt aType)
<a name="l00207"></a>00207 {
<a name="l00208"></a>00208 <a class="code" href="class_c_e_com_calculator_app_ui.html#a65f8e6daaf8c5545eb64784b4d59495c">CAknAppUi::HandleResourceChangeL</a>(aType); <span class="comment">//call to upper class</span>
<a name="l00209"></a>00209
<a name="l00210"></a>00210 <span class="comment">// ADDED FOR SCALABLE UI SUPPORT</span>
<a name="l00211"></a>00211 <span class="comment">// *****************************</span>
<a name="l00212"></a>00212 <span class="keywordflow">if</span> ( aType == KEikDynamicLayoutVariantSwitch )
<a name="l00213"></a>00213 {
<a name="l00214"></a>00214 iAppView->SetRect( ClientRect() );
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216 }
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2 </small></address>
</body>
</html>