currencyconvertor.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:36k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * Currencyconvertor.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements Currency Convertor application.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  *------------------------------------------------------------------------------
  140.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  141.  *============================================================================
  142.  ****************************************************************************/
  143.  /**
  144.  * Copyright Notice
  145.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  146.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  147.  *  (It is illegal to remove this copyright notice from this software or any
  148.  *  portion of it)
  149.  */
  150. /**********************************************************************************
  151.    Filename:      Currencyconvertor.c
  152.    Author:        Vandana M
  153.    Date Created:  June-29-2003
  154.    Contains:      Currency Convertor
  155. **********************************************************************************/
  156. #ifndef _MMI_CURRENCYCONVRETOR_C
  157. #define _MMI_CURRENCYCONVRETOR_C
  158. /*  Include: MMI header file */
  159. #include "MMI_features.h"
  160. #include "EventsGprot.h" 
  161. #include "wgui_inputs.h"
  162. #include "wgui_categories.h"
  163. #include "wgui_categories_inputs.h"
  164. #include "HistoryGprot.h"
  165. #if defined __MMI_CURRENCY_CONVERTER__
  166. #include "PixtelDataTypes.h"
  167. #include "WrapperGprot.h"
  168. #include "CurrencyConvertor.h"
  169. #include "UnitConvertor.h"
  170. #include "Unicodexdcl.h"
  171. #include "GlobalDefs.h"
  172. #include "TimerEvents.h"
  173. #include "DebugInitDef.h"
  174. #include "SettingProfile.h"
  175. #include "string.h"
  176. #include "NVRAMType.h"
  177. #include "NVRAMProt.h"
  178. #include "NVRAMEnum.h"
  179. #include "OrganizerDef.h"
  180. #include "CustDataProts.h"
  181. #include "CommonScreens.h"
  182. #if defined(__MMI_TOUCH_SCREEN__)
  183. #include "EditorPen.h"
  184. #endif 
  185. /*  Include: PS header file */
  186. /* ... Add More PS header */
  187. /* 
  188.  * Define
  189.  */
  190. #define  CCONV_MAX_RATE          6
  191. #define  CCONV_MAX_INPUT            8
  192. #define  CCONV_MAX_RESULT        14
  193. #define  CCONV_SEL_BUF_LEN       10*ENCODING_LENGTH     /* length of inline selection string */
  194. #define  CCONV_RESULT_BUF_LEN    (14+1)*ENCODING_LENGTH
  195. /* 
  196.  * Typedef 
  197.  */
  198. typedef struct
  199. {
  200.     DOUBLE Rate;
  201.     S32 CurrSelRate;    /* current selecting rate */
  202.     S8 *RateList[2];
  203.     S8 LocalBuff[CCONV_RESULT_BUF_LEN];
  204.     S8 ForeBuff[CCONV_RESULT_BUF_LEN];
  205.     S8 RateBuff[CCONV_RESULT_BUF_LEN];
  206.     S8 RateString[2][CCONV_SEL_BUF_LEN];
  207.     U8 CurrHiliteItem;
  208.     U8 ClearResultFlag;
  209.     U8 IsFromHistory;
  210.     /* U8   IsComputingResult; */
  211. } cconv_context_struct;
  212. /* 
  213.  * Local Variable
  214.  */
  215. /* 
  216.  * Local Function
  217.  */
  218. U8 mmi_cconv_del_scr_callback(void *p);
  219. /* 
  220.  * Global Variable
  221.  */
  222. cconv_context_struct *g_cconv_cntx = NULL;
  223. extern wgui_inline_item wgui_inline_items[];
  224. #if defined(__MMI_TOUCH_SCREEN__)
  225. extern void (*complete_inline_item_edit) (void);
  226. #endif 
  227. /* 
  228.  * Global Function
  229.  */
  230. extern void set_leading_zero(U8 u8type);
  231. extern DOUBLE gui_atof(UI_string_type s);
  232. extern void gui_float_string(DOUBLE dob_val, S32 prec_val, S8 *out_buffer);
  233. extern S32 CalcComputePrecision(DOUBLE result, S16 max_digits);
  234. extern void HighlightCConvMenu(void);
  235. extern void EntryCconvApp(void);
  236. extern void ExitCConvApp(void);
  237. extern void CconvPreEntryExchange(void);
  238. extern void EntryCConvExchange(void);
  239. extern void ExitCConvExchange(void);
  240. extern void HighlightCconvInlineItemHandler(S32 index);
  241. extern void HighlightCconvInlineSelHandler(S32 index);
  242. extern void CconvCustomInlineFunction(void);
  243. extern void CconvClearResult(void);
  244. #define UCONV_RATE_INPUT
  245. /*****************************************************************************
  246.  * FUNCTION
  247.  *  CconvInit
  248.  * DESCRIPTION
  249.  *  Initialize currency converter application.
  250.  * PARAMETERS
  251.  *  void
  252.  * RETURNS
  253.  *  void
  254.  *****************************************************************************/
  255. void CconvInit(void)
  256. {
  257.     /*----------------------------------------------------------------*/
  258.     /* Local Variables                                                */
  259.     /*----------------------------------------------------------------*/
  260.     /*----------------------------------------------------------------*/
  261.     /* Code Body                                                      */
  262.     /*----------------------------------------------------------------*/
  263.     SetHiliteHandler(EXTRA_CURRENCYCONVERTOR_MENU, HighlightCConvMenu);
  264. }
  265. /*****************************************************************************
  266.  * FUNCTION
  267.  *  CconvDeInit
  268.  * DESCRIPTION
  269.  *  Free allocated memory.
  270.  * PARAMETERS
  271.  *  void
  272.  * RETURNS
  273.  *  void
  274.  *****************************************************************************/
  275. void CconvDeInit(void)
  276. {
  277.     /*----------------------------------------------------------------*/
  278.     /* Local Variables                                                */
  279.     /*----------------------------------------------------------------*/
  280.     /*----------------------------------------------------------------*/
  281.     /* Code Body                                                      */
  282.     /*----------------------------------------------------------------*/
  283.     if (g_cconv_cntx)
  284.     {
  285.         OslMfree(g_cconv_cntx);
  286.         g_cconv_cntx = NULL;
  287.     }
  288. }
  289. /*****************************************************************************
  290.  * FUNCTION
  291.  *  mmi_cconv_del_scr_callback
  292.  * DESCRIPTION
  293.  *  Callback function of delete currencty converter screen
  294.  * PARAMETERS
  295.  *  p       [?]     
  296.  * RETURNS
  297.  *  void
  298.  *****************************************************************************/
  299. U8 mmi_cconv_del_scr_callback(void *p)
  300. {
  301.     /*----------------------------------------------------------------*/
  302.     /* Local Variables                                                */
  303.     /*----------------------------------------------------------------*/
  304.     /*----------------------------------------------------------------*/
  305.     /* Code Body                                                      */
  306.     /*----------------------------------------------------------------*/
  307.     if (GetActiveScreenId() == SCR_ID_CCONV_RATE_INPUT || GetActiveScreenId() == SCR_ID_CCONV_COMPUTE)
  308.     {
  309.         CloseCategory57Screen();
  310.     }
  311.     CconvDeInit();
  312.     return MMI_FALSE;
  313. }
  314. /*****************************************************************************
  315.  * FUNCTION
  316.  *  CconvPreEntryApp
  317.  * DESCRIPTION
  318.  *  Application memory and entry application.
  319.  * PARAMETERS
  320.  *  void
  321.  * RETURNS
  322.  *  void
  323.  *****************************************************************************/
  324. void CconvPreEntryApp(void)
  325. {
  326.     /*----------------------------------------------------------------*/
  327.     /* Local Variables                                                */
  328.     /*----------------------------------------------------------------*/
  329.     /*----------------------------------------------------------------*/
  330.     /* Code Body                                                      */
  331.     /*----------------------------------------------------------------*/
  332.     if (g_cconv_cntx)
  333.     {
  334.         OslMfree(g_cconv_cntx);
  335.     }
  336.     g_cconv_cntx = OslMalloc(sizeof(cconv_context_struct));
  337.     memset(g_cconv_cntx, 0, sizeof(cconv_context_struct));
  338.     EntryCconvApp();
  339. }
  340. /*****************************************************************************
  341.  * FUNCTION
  342.  *  HighlightCConvMenu
  343.  * DESCRIPTION
  344.  *  Highlight handler of Currency Converter menu item.
  345.  *  Register key handlers.
  346.  * PARAMETERS
  347.  *  void
  348.  * RETURNS
  349.  *  void
  350.  *****************************************************************************/
  351. void HighlightCConvMenu(void)
  352. {
  353.     /*----------------------------------------------------------------*/
  354.     /* Local Variables                                                */
  355.     /*----------------------------------------------------------------*/
  356.     /*----------------------------------------------------------------*/
  357.     /* Code Body                                                      */
  358.     /*----------------------------------------------------------------*/
  359.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  360.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  361.     SetLeftSoftkeyFunction(CconvPreEntryApp, KEY_EVENT_UP);
  362.     SetKeyHandler(CconvPreEntryApp, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  363. }
  364. /*****************************************************************************
  365.  * FUNCTION
  366.  *  HighlightCconvRateItem
  367.  * DESCRIPTION
  368.  *  Highlight handler of rate input inline item.
  369.  * PARAMETERS
  370.  *  index       [IN]        
  371.  * RETURNS
  372.  *  void
  373.  *****************************************************************************/
  374. void HighlightCconvRateItem(S32 index)
  375. {
  376.     /*----------------------------------------------------------------*/
  377.     /* Local Variables                                                */
  378.     /*----------------------------------------------------------------*/
  379.     /*----------------------------------------------------------------*/
  380.     /* Code Body                                                      */
  381.     /*----------------------------------------------------------------*/
  382.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  383.     SetLeftSoftkeyFunction(CconvPreEntryExchange, KEY_EVENT_UP);
  384. }
  385. /*****************************************************************************
  386.  * FUNCTION
  387.  *  EntryCconvApp
  388.  * DESCRIPTION
  389.  *  Display rate input screen of currency convertor application
  390.  * PARAMETERS
  391.  *  void
  392.  * RETURNS
  393.  *  void
  394.  *****************************************************************************/
  395. void EntryCconvApp()
  396. {
  397.     /*----------------------------------------------------------------*/
  398.     /* Local Variables                                                */
  399.     /*----------------------------------------------------------------*/
  400.     S32 precision;
  401.     U8 *guiBuffer;
  402.     U8 *inputBuffer;
  403.     U16 inputBufferSize;
  404.     S16 error;
  405.     U16 RskImg = STR_GLOBAL_BACK;
  406.     /*----------------------------------------------------------------*/
  407.     /* Code Body                                                      */
  408.     /*----------------------------------------------------------------*/
  409.     EntryNewScreen(SCR_ID_CCONV_RATE_INPUT, ExitCConvApp, NULL, NULL);
  410.     guiBuffer = GetCurrGuiBuffer(SCR_ID_CCONV_RATE_INPUT);
  411.     SetDelScrnIDCallbackHandler(SCR_ID_CCONV_RATE_INPUT, (HistoryDelCBPtr) mmi_cconv_del_scr_callback);
  412.     InitializeCategory57Screen();
  413.     if (guiBuffer)
  414.     {
  415.         memset((void*)guiBuffer, 0, 2);
  416.     }
  417.     inputBuffer = GetCurrNInputBuffer(SCR_ID_CCONV_COMPUTE, &inputBufferSize);  /* added for inline edit history */
  418.     if (inputBuffer)    /* added for inline edit history */
  419.     {
  420.         SetCategory57Data(wgui_inline_items, 2, inputBuffer);   /* sets the data */
  421.     }
  422.     if (g_cconv_cntx->IsFromHistory)
  423.     {
  424.         g_cconv_cntx->Rate = gui_atof((U16*) g_cconv_cntx->RateBuff);
  425.         if (pfnUnicodeStrlen(g_cconv_cntx->RateBuff))
  426.         {
  427.             RskImg = STR_GLOBAL_CLEAR;
  428.         }
  429.         else
  430.         {
  431.             RskImg = STR_GLOBAL_BACK;
  432.         }
  433.     }
  434.     else
  435.     {
  436.         ReadValue(CURRENCY_CONVERTOR_EXCHANGE_RATE, &g_cconv_cntx->Rate, DS_DOUBLE, &error);
  437.         g_cconv_cntx->IsFromHistory = TRUE;
  438.     }
  439.     if (g_cconv_cntx->Rate <= 999999 && g_cconv_cntx->Rate > 0) /* o data has been written set the text to blank */
  440.     {
  441.         precision = CalcComputePrecision(g_cconv_cntx->Rate, CCONV_MAX_RATE);
  442.         gui_float_string(g_cconv_cntx->Rate, precision, (S8*) g_cconv_cntx->RateBuff);
  443.     }
  444.     SetInlineItemCaption(&wgui_inline_items[0], (U8*) get_string(STR_CURRENCYCONVERTOR_RATE));
  445.     SetInlineItemActivation(&wgui_inline_items[1], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  446.     SetInlineItemTextEdit(
  447.         &wgui_inline_items[1],
  448.         (U8*) g_cconv_cntx->RateBuff,
  449.         (CCONV_MAX_RATE + 1),
  450.         INPUT_TYPE_DECIMAL_NUMERIC);
  451.     EnableInlineItemBoundary(&wgui_inline_items[1]);
  452.     RightJustifyInlineItem(&wgui_inline_items[1]);
  453.     set_leading_zero(FALSE);
  454.     RegisterHighlightHandler(HighlightCconvRateItem);
  455.     ShowCategory257Screen(
  456.         STR_CURRENCYCONVERTOR_INPUT,
  457.         GetRootTitleIcon(EXTRA_CURRENCYCONVERTOR_MENU),
  458.         STR_GLOBAL_OK,
  459.         IMG_GLOBAL_OK,
  460.         RskImg,
  461.         IMG_GLOBAL_BACK,
  462.         CURRENCY_CONVERTOR_IMAGE,
  463.         2,
  464.         NULL,
  465.         wgui_inline_items,
  466.         1,
  467.         guiBuffer);
  468.     SetCategory57RightSoftkeyFunctions(CconvPreEntryExchange, GoBackHistory);
  469.     SetLeftSoftkeyFunction(CconvPreEntryExchange, KEY_EVENT_UP);
  470. }
  471. /*****************************************************************************
  472.  * FUNCTION
  473.  *  ExitCConvApp
  474.  * DESCRIPTION
  475.  *  Display rate input screen of currency convertor application
  476.  * PARAMETERS
  477.  *  void
  478.  * RETURNS
  479.  *  void
  480.  *****************************************************************************/
  481. void ExitCConvApp(void)
  482. {
  483.     /*----------------------------------------------------------------*/
  484.     /* Local Variables                                                */
  485.     /*----------------------------------------------------------------*/
  486.     U16 inputBufferSize;    /* added for inline edit history */
  487.     history HistoryCCComputeCurrency;
  488.     S16 nHistory = 0;
  489.     /*----------------------------------------------------------------*/
  490.     /* Code Body                                                      */
  491.     /*----------------------------------------------------------------*/
  492.     set_leading_zero(TRUE);
  493.     if (g_cconv_cntx)
  494.     {
  495.         CloseCategory57Screen();
  496.     }
  497.     HistoryCCComputeCurrency.scrnID = SCR_ID_CCONV_RATE_INPUT;
  498.     HistoryCCComputeCurrency.entryFuncPtr = EntryCconvApp;
  499.     GetCategory57History(HistoryCCComputeCurrency.guiBuffer);
  500.     pfnUnicodeStrcpy((S8*) HistoryCCComputeCurrency.inputBuffer, (S8*) & nHistory);
  501.     inputBufferSize = (U16) GetCategory57DataSize();        /* added for inline edit history */
  502.     GetCategory57Data((U8*) HistoryCCComputeCurrency.inputBuffer);     /* added for inline edit history */
  503.     AddNHistory(HistoryCCComputeCurrency, inputBufferSize); /* added for inline edit history */
  504. }
  505. #define UCONV_CONVERTING
  506. /*****************************************************************************
  507.  * FUNCTION
  508.  *  CconvComputeResult
  509.  * DESCRIPTION
  510.  *  Convert the result and display.
  511.  * PARAMETERS
  512.  *  void
  513.  * RETURNS
  514.  *  void
  515.  *****************************************************************************/
  516. void CconvComputeResult(void)
  517. {
  518.     /*----------------------------------------------------------------*/
  519.     /* Local Variables                                                */
  520.     /*----------------------------------------------------------------*/
  521.     S32 precision;
  522.     DOUBLE result, conversion_factor;
  523. #if 0
  524. /* under construction !*/
  525. #endif /* 0 */ 
  526.     /*----------------------------------------------------------------*/
  527.     /* Code Body                                                      */
  528.     /*----------------------------------------------------------------*/
  529.     CloseCategory57Screen();
  530.     if ((gui_strlen((UI_string_type) g_cconv_cntx->LocalBuff) < 1))
  531.     {
  532.         memset(g_cconv_cntx->ForeBuff, 0, 15);
  533.         DisplayPopup(
  534.             (U8*) GetString(ERROR_CURRENCYCONVERTOR_RATE1),
  535.             IMG_GLOBAL_WARNING,
  536.             0,
  537.             UI_POPUP_NOTIFYDURATION_TIME,
  538.             WARNING_TONE);
  539.         return;
  540.     }
  541.     /* calculate result */
  542.     if (g_cconv_cntx->CurrSelRate)  /* 1:R */
  543.     {
  544.         conversion_factor = g_cconv_cntx->Rate;
  545.     }
  546.     else
  547.     {
  548.         conversion_factor = (1 / g_cconv_cntx->Rate);
  549.     }
  550.     result = (DOUBLE) (conversion_factor * gui_atof((UI_string_type) g_cconv_cntx->LocalBuff));
  551.     precision = CalcComputePrecision(result, CCONV_MAX_RESULT);
  552.     gui_float_string(result, precision, (S8*) g_cconv_cntx->ForeBuff);
  553.     g_cconv_cntx->ClearResultFlag = 1;
  554. #ifdef __MMI_CONVERTER_KEEP_INLINE_FOCUS__
  555.     RedrawCategoryFunction();
  556. #if 0
  557. /* under construction !*/
  558. #if(UI_DOUBLE_BUFFER_SUPPORT)
  559. /* under construction !*/
  560. #endif
  561. /* under construction !*/
  562. /* under construction !*/
  563. /* under construction !*/
  564. /* under construction !*/
  565. /* under construction !*/
  566. #if defined(UI_DOUBLE_BUFFER_SUPPORT)
  567. /* under construction !*/
  568. /* under construction !*/
  569. #endif
  570. #endif /* 0 */ 
  571. #else /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 
  572.     SetHighlightedItem(0);
  573. #endif /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 
  574.     SetLeftSoftkeyFunction(CconvComputeResult, KEY_EVENT_UP);
  575. }
  576. /*****************************************************************************
  577.  * FUNCTION
  578.  *  CconvPreEntryExchange
  579.  * DESCRIPTION
  580.  *  Pre-entry function for exchange screen.
  581.  * PARAMETERS
  582.  *  void
  583.  * RETURNS
  584.  *  void
  585.  *****************************************************************************/
  586. void CconvPreEntryExchange(void)
  587. {
  588.     /*----------------------------------------------------------------*/
  589.     /* Local Variables                                                */
  590.     /*----------------------------------------------------------------*/
  591.     S16 error;
  592.     /*----------------------------------------------------------------*/
  593.     /* Code Body                                                      */
  594.     /*----------------------------------------------------------------*/
  595.     CloseCategory57Screen();
  596.     g_cconv_cntx->Rate = gui_atof((U16*) g_cconv_cntx->RateBuff /* Currency_Convertor_rate.text */ );
  597.     if (gui_strlen((UI_string_type) g_cconv_cntx->RateBuff) < 1 || g_cconv_cntx->Rate == 0)
  598.     {
  599.         DisplayPopup(
  600.             (U8*) GetString(ERROR_CURRENCYCONVERTOR_RATE1),
  601.             IMG_GLOBAL_WARNING,
  602.             0,
  603.             UI_POPUP_NOTIFYDURATION_TIME,
  604.             WARNING_TONE);
  605.         return;
  606.     }
  607.     else
  608.     {
  609.         g_cconv_cntx->CurrSelRate = 0;
  610.         g_cconv_cntx->CurrHiliteItem = 0;
  611.         memset(g_cconv_cntx->LocalBuff, 0, ENCODING_LENGTH);
  612.         memset(g_cconv_cntx->ForeBuff, 0, ENCODING_LENGTH);
  613.         WriteValue(CURRENCY_CONVERTOR_EXCHANGE_RATE, &g_cconv_cntx->Rate, DS_DOUBLE, &error);
  614.         g_cconv_cntx->IsFromHistory = FALSE;
  615.         EntryCConvExchange();
  616.     }
  617. }
  618. /*****************************************************************************
  619.  * FUNCTION
  620.  *  CConvFillInlineStruct
  621.  * DESCRIPTION
  622.  *  Fill inline structure of converting screen.
  623.  * PARAMETERS
  624.  *  void
  625.  * RETURNS
  626.  *  void
  627.  *****************************************************************************/
  628. void CConvFillInlineStruct(void)
  629. {
  630.     /*----------------------------------------------------------------*/
  631.     /* Local Variables                                                */
  632.     /*----------------------------------------------------------------*/
  633.     S32 precision;
  634.     U8 strTemp[] = { ':', '', '1', '', '', '' };
  635.     U8 strTemp2[] = { '1', '', ':', '', '', '' };
  636.     /*----------------------------------------------------------------*/
  637.     /* Code Body                                                      */
  638.     /*----------------------------------------------------------------*/
  639.     precision = CalcComputePrecision(g_cconv_cntx->Rate, 6);
  640.     gui_float_string(g_cconv_cntx->Rate, precision, g_cconv_cntx->RateString[0]);
  641.     pfnUnicodeStrcpy((S8*) g_cconv_cntx->RateString[1], (S8*) strTemp2);      /* 1:R */
  642.     pfnUnicodeStrcat((S8*) g_cconv_cntx->RateString[1], (S8*) g_cconv_cntx->RateString[0]);   /* R:1 */
  643.     pfnUnicodeStrcat((S8*) g_cconv_cntx->RateString[0], (S8*) strTemp);
  644.     g_cconv_cntx->RateList[0] = g_cconv_cntx->RateString[0];
  645.     g_cconv_cntx->RateList[1] = g_cconv_cntx->RateString[1];
  646.     set_leading_zero(FALSE);
  647.     DisableInlineInputMethodHints();
  648.     SetInlineItemActivation(&wgui_inline_items[CCONV_INLINE_RATE], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  649.     SetInlineItemSelect(
  650.         &wgui_inline_items[CCONV_INLINE_RATE],
  651.         2,
  652.         (U8 **) g_cconv_cntx->RateList,
  653.         &g_cconv_cntx->CurrSelRate);
  654.     RegisterInlineSelectHighlightHandler(&wgui_inline_items[CCONV_INLINE_RATE], HighlightCconvInlineSelHandler);
  655.     SetInlineItemActivation(&wgui_inline_items[CCONV_INLINE_LOCAL_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  656.     SetInlineItemCaption(&wgui_inline_items[CCONV_INLINE_LOCAL_CAP], (U8*) GetString(STR_CURRENCYCONVERTOR_LOCAL));
  657.     SetInlineItemActivation(&wgui_inline_items[CCONV_INLINE_LOCAL], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  658.     SetInlineItemTextEdit(
  659.         &wgui_inline_items[CCONV_INLINE_LOCAL],
  660.         (U8*) g_cconv_cntx->LocalBuff,
  661.         (CCONV_MAX_INPUT + 1),
  662.         INPUT_TYPE_DECIMAL_NUMERIC);
  663.     SetInlineTextEditCustomFunction(&wgui_inline_items[CCONV_INLINE_LOCAL], CconvCustomInlineFunction);
  664.     EnableInlineItemBoundary(&wgui_inline_items[CCONV_INLINE_LOCAL]);
  665.     RightJustifyInlineItem(&wgui_inline_items[CCONV_INLINE_LOCAL]);
  666.     SetInlineItemActivation(&wgui_inline_items[CCONV_INLINE_FORE_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  667.     SetInlineItemCaption(
  668.         &wgui_inline_items[CCONV_INLINE_FORE_CAP],
  669.         (U8*) (U8*) GetString(STR_CURRENCYCONVERTOR_FOREIGN));
  670.     SetInlineItemActivation(&wgui_inline_items[CCONV_INLINE_FORE], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  671.     SetInlineItemTextEdit(
  672.         &wgui_inline_items[CCONV_INLINE_FORE],
  673.         (U8*) g_cconv_cntx->ForeBuff,
  674.         (CCONV_MAX_INPUT + 1),
  675.         INPUT_TYPE_DECIMAL_NUMERIC);
  676.     EnableInlineItemBoundary(&wgui_inline_items[CCONV_INLINE_FORE]);
  677.     RightJustifyInlineItem(&wgui_inline_items[CCONV_INLINE_FORE]);
  678.     DisableInlineItem(&wgui_inline_items[CCONV_INLINE_FORE], CCONV_INLINE_FORE);
  679. }
  680. /*****************************************************************************
  681.  * FUNCTION
  682.  *  EntryCConvExchange
  683.  * DESCRIPTION
  684.  *  Entry Function of Compute currency exchange
  685.  * PARAMETERS
  686.  *  void
  687.  * RETURNS
  688.  *  void
  689.  *****************************************************************************/
  690. void EntryCConvExchange(void)
  691. {
  692.     /*----------------------------------------------------------------*/
  693.     /* Local Variables                                                */
  694.     /*----------------------------------------------------------------*/
  695.     U8 *guiBuffer;
  696.     U8 *inputBuffer;        /* added for inline edit history */
  697.     U16 inputBufferSize;    /* added for inline edit history */
  698.     /*----------------------------------------------------------------*/
  699.     /* Code Body                                                      */
  700.     /*----------------------------------------------------------------*/
  701.     EntryNewScreen(SCR_ID_CCONV_COMPUTE, ExitCConvExchange, NULL, NULL);
  702.     guiBuffer = GetCurrGuiBuffer(SCR_ID_CCONV_COMPUTE);
  703.     InitializeCategory57Screen();
  704.     CConvFillInlineStruct();
  705.     RegisterHighlightHandler(HighlightCconvInlineItemHandler);
  706.     inputBuffer = GetCurrNInputBuffer(SCR_ID_CCONV_COMPUTE, &inputBufferSize);  /* added for inline edit history */
  707.     if (inputBuffer)    /* added for inline edit history */
  708.     {
  709.         SetCategory57Data(wgui_inline_items, CCONV_INLINE_TOTAL, inputBuffer);  /* sets the data */
  710.     }
  711. DisableCategory57ScreenDone();
  712.     ShowCategory57Screen(
  713.         STR_CURRENCYCONVERTOR_INPUT,
  714.         GetRootTitleIcon(EXTRA_CURRENCYCONVERTOR_MENU),
  715.         STR_GLOBAL_OK,
  716.         IMG_GLOBAL_OK,
  717.         STR_GLOBAL_BACK,
  718.         IMG_GLOBAL_BACK,
  719.         CCONV_INLINE_TOTAL,
  720.         NULL,
  721.         wgui_inline_items,
  722.         g_cconv_cntx->CurrHiliteItem,
  723.         guiBuffer);
  724.     SetLeftSoftkeyFunction(CconvComputeResult, KEY_EVENT_UP);
  725.     SetCategory57RightSoftkeyFunctions(CconvComputeResult, GoBackHistory);
  726. }
  727. /*****************************************************************************
  728.  * FUNCTION
  729.  *  ExitCConvExchange
  730.  * DESCRIPTION
  731.  *  Entry Function of Compute currency exchange
  732.  * PARAMETERS
  733.  *  void
  734.  * RETURNS
  735.  *  void
  736.  *****************************************************************************/
  737. void ExitCConvExchange(void)
  738. {
  739.     /*----------------------------------------------------------------*/
  740.     /* Local Variables                                                */
  741.     /*----------------------------------------------------------------*/
  742.     U16 inputBufferSize;    /* added for inline edit history */
  743.     history HistoryCCComputeCurrency;
  744.     S16 nHistory = 0;
  745.     /*----------------------------------------------------------------*/
  746.     /* Code Body                                                      */
  747.     /*----------------------------------------------------------------*/
  748.     set_leading_zero(TRUE);
  749.     if (g_cconv_cntx)
  750.     {
  751.         CloseCategory57Screen();
  752.     }
  753.     HistoryCCComputeCurrency.scrnID = SCR_ID_CCONV_COMPUTE;
  754.     HistoryCCComputeCurrency.entryFuncPtr = EntryCConvExchange;
  755.     GetCategory57History(HistoryCCComputeCurrency.guiBuffer);
  756.     pfnUnicodeStrcpy((S8*) HistoryCCComputeCurrency.inputBuffer, (S8*) & nHistory);
  757.     inputBufferSize = (U16) GetCategory57DataSize();        /* added for inline edit history */
  758.     GetCategory57Data((U8*) HistoryCCComputeCurrency.inputBuffer);     /* added for inline edit history */
  759.     AddNHistory(HistoryCCComputeCurrency, inputBufferSize); /* added for inline edit history */
  760. }
  761. /*****************************************************************************
  762.  * FUNCTION
  763.  *  HighlightCconvInlineSelHandler
  764.  * DESCRIPTION
  765.  *  Highlight handler of inline selection.
  766.  * PARAMETERS
  767.  *  index       [IN]        
  768.  * RETURNS
  769.  *  void
  770.  *****************************************************************************/
  771. void HighlightCconvInlineSelHandler(S32 index)
  772. {
  773.     /*----------------------------------------------------------------*/
  774.     /* Local Variables                                                */
  775.     /*----------------------------------------------------------------*/
  776.     /*----------------------------------------------------------------*/
  777.     /* Code Body                                                      */
  778.     /*----------------------------------------------------------------*/
  779.     memset(g_cconv_cntx->LocalBuff, 0, ENCODING_LENGTH);
  780.     memset(g_cconv_cntx->ForeBuff, 0, ENCODING_LENGTH);
  781.     RedrawCategoryFunction();
  782. }
  783. /*****************************************************************************
  784.  * FUNCTION
  785.  *  HighlightCconvInlineItemHandler
  786.  * DESCRIPTION
  787.  *  Highlight handler of inline item in exchange screen.
  788.  * PARAMETERS
  789.  *  index       [IN]        Index of item.
  790.  * RETURNS
  791.  *  void
  792.  *****************************************************************************/
  793. void HighlightCconvInlineItemHandler(S32 index)
  794. {
  795.     /*----------------------------------------------------------------*/
  796.     /* Local Variables                                                */
  797.     /*----------------------------------------------------------------*/
  798.     /*----------------------------------------------------------------*/
  799.     /* Code Body                                                      */
  800.     /*----------------------------------------------------------------*/
  801.     if (index == 0)
  802.     {
  803.         //              if(!g_cconv_cntx->IsComputingResult)
  804.         //              {
  805.         ClearKeyHandler(KEY_LSK, KEY_EVENT_UP);
  806.         ChangeLeftSoftkey(STRING_ID_NULL, IMAGE_ID_NULL);
  807.         ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  808.         SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  809.         /* } */
  810.     }
  811.     else    /* 2 */
  812.     {
  813.     #ifdef __MMI_CONVERTER_KEEP_INLINE_FOCUS__
  814.         if (g_cconv_cntx->CurrHiliteItem != index)
  815.         {
  816.             memset(g_cconv_cntx->LocalBuff, 0, 2);
  817.             memset(g_cconv_cntx->ForeBuff, 0, 2);
  818.         }
  819.         else if (!g_cconv_cntx->ClearResultFlag && *(g_cconv_cntx->ForeBuff) != 0)
  820.         {
  821.             g_cconv_cntx->ClearResultFlag = 1;
  822.         }
  823.     #if !defined(__MMI_WITH_C_KEY__)
  824.         SetCategory57ScreenRSKClear();  /* Max: set RSK to "Clear" */
  825.     #endif 
  826.         ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  827.         SetLeftSoftkeyFunction(CconvComputeResult, KEY_EVENT_UP);
  828.     #else /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 
  829.         if (g_cconv_cntx->CurrHiliteItem != index)
  830.         {
  831.             memset(g_cconv_cntx->LocalBuff, 0, 2);
  832.             memset(g_cconv_cntx->ForeBuff, 0, 2);
  833.         }
  834.         ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  835.         SetLeftSoftkeyFunction(CconvComputeResult, KEY_EVENT_UP);
  836.     #endif /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 
  837.     }
  838.     g_cconv_cntx->CurrHiliteItem = (U8) index;
  839. }
  840. /*****************************************************************************
  841.  * FUNCTION
  842.  *  CconvCustomInlineFunction
  843.  * DESCRIPTION
  844.  *  Set group key handlers of inline editor
  845.  * PARAMETERS
  846.  *  void
  847.  * RETURNS
  848.  *  void
  849.  *****************************************************************************/
  850. void CconvCustomInlineFunction(void)
  851. {
  852. #ifdef __MMI_CONVERTER_KEEP_INLINE_FOCUS__
  853.     /*----------------------------------------------------------------*/
  854.     /* Local Variables                                                */
  855.     /*----------------------------------------------------------------*/
  856.     U16 keyCodes[] = {KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_POUND};
  857.     U8 nKeyCodes = (U8) 11;
  858.     /*----------------------------------------------------------------*/
  859.     /* Code Body                                                      */
  860.     /*----------------------------------------------------------------*/
  861.     if (g_cconv_cntx->ClearResultFlag)
  862.     {
  863.         g_cconv_cntx->ClearResultFlag = 0;
  864.         SetGroupKeyHandler(CconvClearResult, keyCodes, nKeyCodes, KEY_EVENT_DOWN);
  865.     #if !defined(__MMI_WITH_C_KEY__)
  866.         SetRightSoftkeyFunction(CconvClearResult, KEY_EVENT_UP);
  867.         SetRightSoftkeyFunction(CconvClearResult, KEY_EVENT_LONG_PRESS);
  868.         SetRightSoftkeyFunction(NULL, KEY_EVENT_DOWN);
  869.     #else /* !defined(__MMI_WITH_C_KEY__) */ 
  870.         SetKeyHandler(CconvClearResult, KEY_CLEAR, KEY_EVENT_UP);
  871.         SetKeyHandler(CconvClearResult, KEY_CLEAR, KEY_EVENT_LONG_PRESS);
  872.         SetKeyHandler(NULL, KEY_CLEAR, KEY_EVENT_DOWN);
  873.     #endif /* !defined(__MMI_WITH_C_KEY__) */ 
  874.     #if defined(__MMI_TOUCH_SCREEN__)
  875.         mmi_pen_editor_disable_input(PEN_EDITOR_DISABLE_HANDWRITNG | PEN_EDITOR_DISABLE_VIRTUAL_KEYBOARD);
  876.         ChangeRightSoftkey(STR_ID_CURRENCYCONVERTOR_RESET, 0);
  877.     #endif /* defined(__MMI_TOUCH_SCREEN__) */ 
  878.     }
  879. #endif /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 
  880. }
  881. #endif /* defined __MMI_CURRENCY_CONVERTER__ */ 
  882. /*****************************************************************************
  883.  * FUNCTION
  884.  *  CconvClearResult
  885.  * DESCRIPTION
  886.  *  Clear buffer and input a character.
  887.  *  This function is used for new digits input after calculation.
  888.  * PARAMETERS
  889.  *  void
  890.  * RETURNS
  891.  *  void
  892.  *****************************************************************************/
  893. void CconvClearResult(void)
  894. {
  895. #ifdef __MMI_CONVERTER_KEEP_INLINE_FOCUS__
  896.     /*----------------------------------------------------------------*/
  897.     /* Local Variables                                                */
  898.     /*----------------------------------------------------------------*/
  899.     U16 keyCode, keyType;
  900.     S32 hItem = GetHighlightedItem();
  901.     /*----------------------------------------------------------------*/
  902.     /* Code Body                                                      */
  903.     /*----------------------------------------------------------------*/
  904.     GetkeyInfo((U16*) & keyCode, (U16*) & keyType);
  905. #if(UI_DOUBLE_BUFFER_SUPPORT)
  906.     gui_lock_double_buffer();
  907. #endif 
  908. #if defined(__MMI_TOUCH_SCREEN__)
  909.     complete_inline_item_edit();
  910. #endif 
  911.     gui_fixed_list_menu_goto_item(&MMI_fixed_list_menu, 0);
  912.     gui_fixed_list_menu_goto_item(&MMI_fixed_list_menu, hItem);
  913.     show_fixed_list();
  914.     if (keyType == KEY_EVENT_LONG_PRESS)
  915.     {
  916.         SetRightSoftkeyFunction(mmi_conv_reset_rsk, KEY_EVENT_UP);
  917.     }
  918.     if (keyCode != KEY_CLEAR)
  919.     {
  920.         ExecuteCurrKeyHandler(keyCode, keyType);
  921.     }
  922. #if(UI_DOUBLE_BUFFER_SUPPORT)
  923.     gui_unlock_double_buffer();
  924.     gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
  925. #endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
  926. #endif /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 
  927. }
  928. /*****************************************************************************
  929.  * FUNCTION
  930.  *  mmi_conv_reset_rsk
  931.  * DESCRIPTION
  932.  *  This function is used reset RSK.
  933.  * PARAMETERS
  934.  *  void
  935.  * RETURNS
  936.  *  void
  937.  *****************************************************************************/
  938. void mmi_conv_reset_rsk(void)
  939. {
  940.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  941. }
  942. #endif /* _MMI_CURRENCYCONVRETOR_C */ // #ifndef _MMI_CURRENCYCONVRETOR_C