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

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) 2004
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11. *
  12. * Filename:
  13. * ---------
  14. *  CurrencyConvertorE.c
  15. *
  16. * Project:
  17. * --------
  18. *  MAUI
  19. *
  20. * Description:
  21. * ------------
  22. *  This file implements Cur Convertor application.
  23. *
  24. * Author:
  25. * -------
  26. *  Cecil Wei
  27. *
  28. *============================================================================
  29. *             HISTORY
  30. * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31. *------------------------------------------------------------------------------
  32. * $Log$
  33.  *
  34.  * removed!
  35.  * removed!
  36.  * 
  37.  *
  38.  * removed!
  39.  * removed!
  40.  * Update foreign rate immediately when local rate has been changed.
  41.  *
  42.  * removed!
  43.  * removed!
  44.  * Redraw the single text line after updating its position.
  45.  *
  46.  * removed!
  47.  * removed!
  48.  * 
  49.  *
  50.  * removed!
  51.  * removed!
  52.  * Add screen check when executing closecategory57.
  53.  *
  54.  * removed!
  55.  * removed!
  56.  * Execute closeCategory57 in delete callback function.
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * Move CconvClearResult out of __MMI_CURRENCY_CONVERTER__ and __MMI_EXTENDED_CURRENCY_CONVERTER__
  61.  * 
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * Skip CloseCategory57Screen() if global context has already been freed by delete callback function.
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * Save the gui buffer to history when exiting screen.
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * 
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * 
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * Remove CconvClearResult function
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * 
  86. *
  87. *------------------------------------------------------------------------------
  88. * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  89. *============================================================================*/
  90. #ifndef _MMI_CURRENCYCONVERTORE_C
  91. #define _MMI_CURRENCYCONVERTORE_C
  92. /*  Include: MMI header file */
  93. #include "MMI_features.h"
  94. #ifdef __MMI_EXTENDED_CURRENCY_CONVERTER__
  95. #include "PixtelDataTypes.h"
  96. #include "WrapperGprot.h"
  97. #include "currencyconvertorE.h"
  98. #include "CurrencyConvertor.h"
  99. #include "Unicodexdcl.h"
  100. #include "HistoryGprot.h"
  101. #include "GlobalDefs.h"
  102. #include "TimerEvents.h"
  103. #include "DebugInitDef.h"
  104. #include "EventsGprot.h"
  105. #include "SettingProfile.h"
  106. #include "wgui_inputs.h"
  107. #include "wgui_categories.h"
  108. #include "wgui_categories_inputs.h"
  109. #include "string.h"
  110. #include "NVRAMType.h"
  111. #include "NVRAMProt.h"
  112. #include "NVRAMEnum.h"
  113. #include "ExtraDef.h"
  114. #include "CustDataProts.h"
  115. #include "CommonScreens.h"
  116. /*  Include: PS header file */
  117. /* ... Add More PS header */
  118. /* 
  119.  * Define
  120.  */
  121. #define  CCONV_MAX_CURRENCY      9      /* total number of currencies */
  122. #define  CCONV_NAMED_CURRENCY    6      /* number of named currencies */
  123. #define  CCONV_MAX_RATE          10
  124. #define  CCONV_MAX_INPUT         8
  125. #define  CCONV_MAX_RESULT        12
  126. #define  CCONV_SEL_BUF_LEN       12*ENCODING_LENGTH     /* length of inline selection string */
  127. #define  CCONV_RESULT_BUF_LEN    (12+1)*ENCODING_LENGTH
  128. #define  CCONV_MAX_RATEENTRIES   5      /* number of exchange rate entries */
  129. #define  ITEM_BASE               CCONV_RATE_INLINE_FORE_SELECT1
  130. /* 
  131.  * Typedef 
  132.  */
  133. typedef struct
  134. {
  135.     DOUBLE selectedRate;    /* active exchange rate */
  136.     DOUBLE rate[CCONV_MAX_RATEENTRIES];
  137.     S32 localCurID;     /* selected local cur */
  138.     S32 foreignCurID;   /* selected foreign cur */
  139.     S32 localCurIndex;      /* selected local cur */
  140.     S32 foreignCurIndex;    /* selected foreign cur */
  141.     S32 curID[CCONV_MAX_RATEENTRIES];       /* Setting selected foreign cur */
  142.     S32 curIndex[CCONV_MAX_RATEENTRIES];    /* Setting selected foreign cur */
  143.     S32 selectedLocalCurID;                 /* selected local cur */
  144.     S32 prevSelectedLocalCurID;             /* previous selected local cur */
  145.     S8 LocalBuff[CCONV_RESULT_BUF_LEN];
  146.     S8 ForeBuff[CCONV_RESULT_BUF_LEN];
  147.     S8 strRate[CCONV_MAX_RATEENTRIES][CCONV_SEL_BUF_LEN];
  148.     S32 hiliteItemIndex;
  149.     /* U8   IsComputingResult; */
  150.     S8 *curList1[CCONV_MAX_CURRENCY];
  151.     S8 *curList2[CCONV_MAX_CURRENCY];
  152.     S8 *curList[CCONV_MAX_RATEENTRIES][CCONV_MAX_CURRENCY];
  153.     U8 reloadFromNVRAM;
  154.     U8 isRedrawScreen;
  155.     S8 bRateDefined;
  156. } cconv_context_struct;
  157. /* 
  158.  * Local Variable
  159.  */
  160. /* 
  161.  * Local Function
  162.  */
  163. /* Utility functions */
  164. S32 mmi_cconv_get_cur_id(S32 index, S8 **list);
  165. S32 mmi_cconv_get_cur_index(S32 id, S8 **list, S8 nItems);
  166. DOUBLE mmi_cconv_get_exchange_rate(S32 cur1Idx, S32 cur2Idx);
  167. void mmi_cconv_compute_result(U8 *buffer);
  168. void mmi_cconv_return_to_menu(void);
  169. void mmi_cconv_fill_inline(void);
  170. U8 mmi_cconv_del_scr_callback(void *p);
  171. S8 mmi_cconv_local_select_list();
  172. S8 mmi_cconv_fore_select_list();
  173. /* Highlight handlers */
  174. void mmi_cconv_compute_item_highlight_hdlr(S32 index);
  175. void mmi_cconv_compute_local_select_highlight_hdlr(S32 index);
  176. void mmi_cconv_compute_fore_select_highlight_hdlr(S32 index);
  177. void mmi_cconv_compute_inline_edit_highlight_hdlr(void);
  178. void mmi_cconv_rate_item_highlight_hdlr(S32 index);
  179. void mmi_cconv_rate_local_select_hdlr(S32 index);
  180. void mmi_cconv_rate_inline_select_highlight_hdlr(S32 index);
  181. void mmi_cconv_rate_inline_edit_highlight_hdlr(void);
  182. void mmi_cconv_rate_inline_edit_key_hdlr(void);
  183. /* Validation handler */
  184. void mmi_cconv_compute_inline_edit_validation_hdlr(U8 *buffer, U8 *cursor, S32 text_length);
  185. void mmi_cconv_rate_inline_edit_validation_hdlr(U8 *buffer, U8 *cursor, S32 text_length);
  186. /* Key Handlers */
  187. void mmi_cconv_rate_save_change(void);
  188. /* 
  189.  * Global Variable
  190.  */
  191. cconv_context_struct *g_cconv_ctx = NULL;
  192. extern wgui_inline_item wgui_inline_items[];
  193. extern single_line_input_box MMI_inline_singleline_inputbox;
  194. S8 *curShortName[CCONV_MAX_CURRENCY];
  195. S8 *curName[CCONV_MAX_CURRENCY];
  196. S8 *strEmpty = "";
  197. /* 
  198.  * Global Function
  199.  */
  200. extern void set_leading_zero(U8 u8type);
  201. extern DOUBLE gui_atof(UI_string_type s);
  202. extern void gui_float_string(DOUBLE dob_val, S32 prec_val, S8 *out_buffer);
  203. extern S32 CalcComputePrecision(DOUBLE result, S16 max_digits);
  204. extern void inline_edit_singleline_inputbox_next_character(void);
  205. /*****************************************************************************
  206.  * FUNCTION
  207.  *  mmi_cconv_init
  208.  * DESCRIPTION
  209.  *  Initialize cur converter application.
  210.  * PARAMETERS
  211.  *  void
  212.  * RETURNS
  213.  *  void
  214.  *****************************************************************************/
  215. void mmi_cconv_init(void)
  216. {
  217.     /*----------------------------------------------------------------*/
  218.     /* Local Variables                                                */
  219.     /*----------------------------------------------------------------*/
  220.     /*----------------------------------------------------------------*/
  221.     /* Code Body                                                      */
  222.     /*----------------------------------------------------------------*/
  223.     SetHiliteHandler(EXTRA_CURRENCYCONVERTOR_MENU, mmi_cconv_menu_highlight_hdlr);
  224. }
  225. /*****************************************************************************
  226.  * FUNCTION
  227.  *  mmi_cconv_deinit
  228.  * DESCRIPTION
  229.  *  Free allocated memory.
  230.  * PARAMETERS
  231.  *  void
  232.  * RETURNS
  233.  *  void
  234.  *****************************************************************************/
  235. void mmi_cconv_deinit(void)
  236. {
  237.     /*----------------------------------------------------------------*/
  238.     /* Local Variables                                                */
  239.     /*----------------------------------------------------------------*/
  240.     /*----------------------------------------------------------------*/
  241.     /* Code Body                                                      */
  242.     /*----------------------------------------------------------------*/
  243.     if (g_cconv_ctx)
  244.     {
  245.         OslMfree(g_cconv_ctx);
  246.         g_cconv_ctx = NULL;
  247.     }
  248. }
  249. /*****************************************************************************
  250.  * FUNCTION
  251.  *  mmi_cconv_del_scr_callback
  252.  * DESCRIPTION
  253.  *  Callback function of delete currencty converter screen
  254.  * PARAMETERS
  255.  *  p       [?]     
  256.  * RETURNS
  257.  *  void
  258.  *****************************************************************************/
  259. U8 mmi_cconv_del_scr_callback(void *p)
  260. {
  261.     /*----------------------------------------------------------------*/
  262.     /* Local Variables                                                */
  263.     /*----------------------------------------------------------------*/
  264.     /*----------------------------------------------------------------*/
  265.     /* Code Body                                                      */
  266.     /*----------------------------------------------------------------*/
  267.     if (GetActiveScreenId() == SCR_ID_CCONV_RATE_INPUT || GetActiveScreenId() == SCR_ID_CCONV_COMPUTE)
  268.     {
  269.         CloseCategory57Screen();
  270.     }
  271.     mmi_cconv_deinit();
  272.     return MMI_FALSE;
  273. }
  274. /*****************************************************************************
  275.  * FUNCTION
  276.  *  mmi_cconv_pre_entry_app
  277.  * DESCRIPTION
  278.  *  Init the Application memory and entry application.
  279.  * PARAMETERS
  280.  *  void
  281.  * RETURNS
  282.  *  void
  283.  *****************************************************************************/
  284. void mmi_cconv_pre_entry_app(void)
  285. {
  286.     /*----------------------------------------------------------------*/
  287.     /* Local Variables                                                */
  288.     /*----------------------------------------------------------------*/
  289.     U8 i;
  290.     S16 error;
  291.     /*----------------------------------------------------------------*/
  292.     /* Code Body                                                      */
  293.     /*----------------------------------------------------------------*/
  294.     if (g_cconv_ctx)
  295.     {
  296.         OslMfree(g_cconv_ctx);
  297.     }
  298.     g_cconv_ctx = OslMalloc(sizeof(cconv_context_struct));
  299.     memset(g_cconv_ctx, 0, sizeof(cconv_context_struct));
  300.     /* Preload currency name */
  301.     for (i = 0; i < CCONV_MAX_CURRENCY; i++)
  302.     {
  303.         curName[i] = GetString((U16) (STR_CURRENCYCONV_USD + i));
  304.         if (i < CCONV_NAMED_CURRENCY)
  305.         {
  306.             curShortName[i] = GetString((U16) (STR_CURRENCYCONV_USD_ABBR + i));
  307.         }
  308.         else
  309.         {
  310.             curShortName[i] = strEmpty;
  311.         }
  312.     }
  313.     g_cconv_ctx->reloadFromNVRAM = TRUE;
  314.     g_cconv_ctx->isRedrawScreen = FALSE;
  315.     if (g_cconv_ctx->reloadFromNVRAM)
  316.     {
  317.         ReadValue(NVRAM_CCONV_SELECTED_CURRENCY1, &g_cconv_ctx->localCurID, DS_BYTE, &error);
  318.         if (error == NVRAM_READ_FAIL)
  319.         {
  320.             g_cconv_ctx->localCurID = 0;
  321.         }
  322.         ReadValue(NVRAM_CCONV_SELECTED_CURRENCY2, &g_cconv_ctx->foreignCurID, DS_BYTE, &error);
  323.         if (error == NVRAM_READ_FAIL)
  324.         {
  325.             g_cconv_ctx->foreignCurID = 0;
  326.         }
  327.         for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  328.         {
  329.             ReadValue((U8) (NVRAM_CCONV_SETTING_CURRENCY1 + i), &g_cconv_ctx->curID[i], DS_BYTE, &error);
  330.             if (error == NVRAM_READ_FAIL)
  331.             {
  332.                 g_cconv_ctx->curID[i] = 0;
  333.             }
  334.             ReadValue((U8) (NVRAM_CCONV_EXCHANGE_RATE1 + i), &g_cconv_ctx->rate[i], DS_DOUBLE, &error);
  335.             if (error == NVRAM_READ_FAIL)
  336.             {
  337.                 g_cconv_ctx->rate[i] = -1;
  338.             }
  339.             if (!g_cconv_ctx->bRateDefined && g_cconv_ctx->rate[i] > 0)
  340.             {
  341.                 g_cconv_ctx->bRateDefined = TRUE;
  342.             }
  343.         }
  344.         ReadValue(NVRAM_CCONV_SETTING_LOCALCURRENCY, &g_cconv_ctx->selectedLocalCurID, DS_BYTE, &error);
  345.         if (error == NVRAM_READ_FAIL || g_cconv_ctx->selectedLocalCurID == 0xff)
  346.         {
  347.             g_cconv_ctx->selectedLocalCurID = 0;
  348.         }
  349.         g_cconv_ctx->prevSelectedLocalCurID = g_cconv_ctx->selectedLocalCurID;
  350.         memset(g_cconv_ctx->LocalBuff, 0, ENCODING_LENGTH);
  351.         memset(g_cconv_ctx->ForeBuff, 0, ENCODING_LENGTH);
  352.         g_cconv_ctx->hiliteItemIndex = 0;
  353.     }
  354.     mmi_cconv_entry_app();
  355. }
  356. /*****************************************************************************
  357.  * FUNCTION
  358.  *  mmi_cconv_menu_highlight_hdlr
  359.  * DESCRIPTION
  360.  *  Highlight handler of Cur Converter menu item.
  361.  *  Register key handlers.
  362.  * PARAMETERS
  363.  *  void
  364.  * RETURNS
  365.  *  void
  366.  *****************************************************************************/
  367. void mmi_cconv_menu_highlight_hdlr(void)
  368. {
  369.     /*----------------------------------------------------------------*/
  370.     /* Local Variables                                                */
  371.     /*----------------------------------------------------------------*/
  372.     /*----------------------------------------------------------------*/
  373.     /* Code Body                                                      */
  374.     /*----------------------------------------------------------------*/
  375.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  376.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  377.     SetLeftSoftkeyFunction(mmi_cconv_pre_entry_app, KEY_EVENT_UP);
  378.     SetKeyHandler(mmi_cconv_pre_entry_app, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  379. }
  380. /*****************************************************************************
  381.  * FUNCTION
  382.  *  mmi_cconv_entry_app
  383.  * DESCRIPTION
  384.  *  Display rate input screen of cur convertor application
  385.  * PARAMETERS
  386.  *  void
  387.  * RETURNS
  388.  *  void
  389.  *****************************************************************************/
  390. void mmi_cconv_entry_app(void)
  391. {
  392.     /*----------------------------------------------------------------*/
  393.     /* Local Variables                                                */
  394.     /*----------------------------------------------------------------*/
  395.     U8 *guiBuffer;
  396.     U8 *inputBuffer;
  397.     U16 inputBufferSize;
  398.     S8 i = 0;
  399.     /*----------------------------------------------------------------*/
  400.     /* Code Body                                                      */
  401.     /*----------------------------------------------------------------*/
  402.     if (!g_cconv_ctx->bRateDefined)
  403.     {
  404.         DisplayConfirm(
  405.             STR_GLOBAL_YES,
  406.             IMG_GLOBAL_YES,
  407.             STR_GLOBAL_NO,
  408.             IMG_GLOBAL_NO,
  409.             get_string(ERROR_CURRENCYCONV_RATE2),
  410.             IMG_GLOBAL_QUESTION,
  411.             WARNING_TONE);
  412.         if (IsScreenPresent(SCR_ID_CCONV_RATE_INPUT))
  413.         {
  414.             SetLeftSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  415.         }
  416.         else
  417.         {
  418.             SetLeftSoftkeyFunction(mmi_cconv_pre_entry_rate, KEY_EVENT_UP);
  419.         }
  420.         SetRightSoftkeyFunction(mmi_cconv_return_to_menu, KEY_EVENT_UP);
  421.         return;
  422.     }
  423.     else
  424.     {
  425.         g_cconv_ctx->selectedRate = mmi_cconv_get_exchange_rate(g_cconv_ctx->localCurID, g_cconv_ctx->foreignCurID);
  426.     }
  427.     EntryNewScreen(SCR_ID_CCONV_COMPUTE, mmi_cconv_exit_app, NULL, NULL);
  428.     RegisterHighlightHandler(mmi_cconv_compute_item_highlight_hdlr);
  429.     SetDelScrnIDCallbackHandler(SCR_ID_CCONV_COMPUTE, (HistoryDelCBPtr) mmi_cconv_del_scr_callback);
  430.     guiBuffer = GetCurrGuiBuffer(SCR_ID_CCONV_COMPUTE);
  431.     InitializeCategory57Screen();
  432.     inputBuffer = GetCurrNInputBuffer(SCR_ID_CCONV_COMPUTE, &inputBufferSize);  /* added for inline edit history */
  433.     if (inputBuffer && g_cconv_ctx->isRedrawScreen == FALSE)    /* added for inline edit history */
  434.     {
  435.         SetCategory57Data(wgui_inline_items, CCONV_CURRENCY_INLINE_TOTAL, inputBuffer); /* sets the data */
  436.     }
  437.     else
  438.     {
  439.         g_cconv_ctx->isRedrawScreen = FALSE;
  440.     }
  441.     set_leading_zero(FALSE);
  442.     DisableInlineInputMethodHints();
  443.     mmi_cconv_fill_inline();
  444.     ShowCategory57Screen(
  445.         STR_CURRENCYCONV_INPUT,
  446.         GetRootTitleIcon(EXTRA_CURRENCYCONVERTOR_MENU),
  447.         STR_CURRENCYCONV_RATE,
  448.         IMG_GLOBAL_OK,
  449.         STR_GLOBAL_BACK,
  450.         IMG_GLOBAL_BACK,
  451.         CCONV_CURRENCY_INLINE_TOTAL,
  452.         NULL,
  453.         wgui_inline_items,
  454.         g_cconv_ctx->hiliteItemIndex,
  455.         guiBuffer);
  456.     DisableCategory57ScreenDone();
  457.     SetCategory57RightSoftkeyFunctions(mmi_cconv_return_to_menu, mmi_cconv_return_to_menu);
  458.     SetLeftSoftkeyFunction(mmi_cconv_pre_entry_rate, KEY_EVENT_UP);
  459. }
  460. /*****************************************************************************
  461.  * FUNCTION
  462.  *  mmi_cconv_fill_inline
  463.  * DESCRIPTION
  464.  *  Fill inline editor structure
  465.  * PARAMETERS
  466.  *  void
  467.  * RETURNS
  468.  *  void
  469.  *****************************************************************************/
  470. void mmi_cconv_fill_inline(void)
  471. {
  472.     /*----------------------------------------------------------------*/
  473.     /* Local Variables                                                */
  474.     /*----------------------------------------------------------------*/
  475.     S8 nItems1 = 0, nItems2 = 0, i = 0;
  476.     /*----------------------------------------------------------------*/
  477.     /* Code Body                                                      */
  478.     /*----------------------------------------------------------------*/
  479.     nItems1 = mmi_cconv_local_select_list(&nItems1);
  480.     nItems2 = mmi_cconv_fore_select_list(&nItems2);
  481.     SetInlineItemActivation(
  482.         &wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL_SELECT],
  483.         INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT,
  484.         0);
  485.     SetInlineItemSelect(
  486.         &wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL_SELECT],
  487.         nItems1,
  488.         (U8 **) g_cconv_ctx->curList1,
  489.         &g_cconv_ctx->localCurIndex);
  490.     RegisterInlineSelectHighlightHandler(
  491.         &wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL_SELECT],
  492.         mmi_cconv_compute_local_select_highlight_hdlr);
  493.     if (nItems1 == 0)
  494.     {
  495.         DisableInlineItem(&wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL_SELECT], 0);
  496.     }
  497.     SetInlineItemActivation(&wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  498.     SetInlineItemTextEdit(
  499.         &wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL],
  500.         (U8*) g_cconv_ctx->LocalBuff,
  501.         (CCONV_MAX_INPUT + 1),
  502.         INPUT_TYPE_DECIMAL_NUMERIC);
  503.     SetInlineTextEditCustomFunction(
  504.         &wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL],
  505.         mmi_cconv_compute_inline_edit_highlight_hdlr);
  506.     RegisterInlineFullScreenEditValidationFunction(
  507.         &wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL],
  508.         mmi_cconv_compute_inline_edit_validation_hdlr);
  509.     EnableInlineItemBoundary(&wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL]);
  510.     RightJustifyInlineItem(&wgui_inline_items[CCONV_CURRENCY_INLINE_LOCAL]);
  511.     SetInlineItemActivation(
  512.         &wgui_inline_items[CCONV_CURRENCY_INLINE_FORE_SELECT],
  513.         INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT,
  514.         0);
  515.     SetInlineItemSelect(
  516.         &wgui_inline_items[CCONV_CURRENCY_INLINE_FORE_SELECT],
  517.         nItems2,
  518.         (U8 **) g_cconv_ctx->curList2,
  519.         &g_cconv_ctx->foreignCurIndex);
  520.     RegisterInlineSelectHighlightHandler(
  521.         &wgui_inline_items[CCONV_CURRENCY_INLINE_FORE_SELECT],
  522.         mmi_cconv_compute_fore_select_highlight_hdlr);
  523.     if (nItems2 == 0)
  524.     {
  525.         DisableInlineItem(&wgui_inline_items[CCONV_CURRENCY_INLINE_FORE_SELECT], 2);
  526.     }
  527.     SetInlineItemActivation(&wgui_inline_items[CCONV_CURRENCY_INLINE_FORE], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  528.     SetInlineItemTextEdit(
  529.         &wgui_inline_items[CCONV_CURRENCY_INLINE_FORE],
  530.         (U8*) g_cconv_ctx->ForeBuff,
  531.         (CCONV_MAX_INPUT + 1),
  532.         INPUT_TYPE_DECIMAL_NUMERIC);
  533.     EnableInlineItemBoundary(&wgui_inline_items[CCONV_CURRENCY_INLINE_FORE]);
  534.     RightJustifyInlineItem(&wgui_inline_items[CCONV_CURRENCY_INLINE_FORE]);
  535.     DisableInlineItem(&wgui_inline_items[CCONV_CURRENCY_INLINE_FORE], 3);
  536. }
  537. /*****************************************************************************
  538.  * FUNCTION
  539.  *  mmi_cconv_exit_app
  540.  * DESCRIPTION
  541.  *  Display rate input screen of cur convertor application
  542.  * PARAMETERS
  543.  *  void
  544.  * RETURNS
  545.  *  void
  546.  *****************************************************************************/
  547. void mmi_cconv_exit_app(void)
  548. {
  549.     /*----------------------------------------------------------------*/
  550.     /* Local Variables                                                */
  551.     /*----------------------------------------------------------------*/
  552.     U16 inputBufferSize;    /* added for inline edit history */
  553.     history HistoryCCComputeCurrency;
  554.     S16 nHistory = 0;
  555.     S16 error;
  556.     /*----------------------------------------------------------------*/
  557.     /* Code Body                                                      */
  558.     /*----------------------------------------------------------------*/
  559.     set_leading_zero(TRUE);
  560.     if (g_cconv_ctx)
  561.     {
  562.         g_cconv_ctx->localCurID = mmi_cconv_get_cur_id(g_cconv_ctx->localCurIndex, g_cconv_ctx->curList1);
  563.         g_cconv_ctx->foreignCurID = mmi_cconv_get_cur_id(g_cconv_ctx->foreignCurIndex, g_cconv_ctx->curList2);
  564.         WriteValue(NVRAM_CCONV_SELECTED_CURRENCY1, &g_cconv_ctx->localCurID, DS_BYTE, &error);
  565.         WriteValue(NVRAM_CCONV_SELECTED_CURRENCY2, &g_cconv_ctx->foreignCurID, DS_BYTE, &error);
  566.         CloseCategory57Screen();
  567.     }
  568.     HistoryCCComputeCurrency.scrnID = SCR_ID_CCONV_COMPUTE;
  569.     HistoryCCComputeCurrency.entryFuncPtr = mmi_cconv_entry_app;
  570.     GetCategory57History(HistoryCCComputeCurrency.guiBuffer);
  571.     pfnUnicodeStrcpy((S8*) HistoryCCComputeCurrency.inputBuffer, (S8*) & nHistory);
  572.     inputBufferSize = (U16) GetCategory57DataSize();        /* added for inline edit history */
  573.     GetCategory57Data((U8*) HistoryCCComputeCurrency.inputBuffer);     /* added for inline edit history */
  574.     AddNHistory(HistoryCCComputeCurrency, inputBufferSize); /* added for inline edit history */
  575. }
  576. /*****************************************************************************
  577.  * FUNCTION
  578.  *  mmi_cconv_pre_entry_rate
  579.  * DESCRIPTION
  580.  *  Pre-entry function for exchange screen.
  581.  * PARAMETERS
  582.  *  void
  583.  * RETURNS
  584.  *  void
  585.  *****************************************************************************/
  586. void mmi_cconv_pre_entry_rate(void)
  587. {
  588.     /*----------------------------------------------------------------*/
  589.     /* Local Variables                                                */
  590.     /*----------------------------------------------------------------*/
  591.     /*----------------------------------------------------------------*/
  592.     /* Code Body                                                      */
  593.     /*----------------------------------------------------------------*/
  594.     g_cconv_ctx->hiliteItemIndex = 0;
  595.     CloseCategory57Screen();
  596.     mmi_cconv_entry_rate();
  597. }
  598. /*****************************************************************************
  599.  * FUNCTION
  600.  *  mmi_cconv_rate_select_list
  601.  * DESCRIPTION
  602.  *  create rate selection list for rate setting
  603.  * PARAMETERS
  604.  *  void
  605.  * RETURNS
  606.  *  void
  607.  *****************************************************************************/
  608. void mmi_cconv_rate_select_list(void)
  609. {
  610.     /*----------------------------------------------------------------*/
  611.     /* Local Variables                                                */
  612.     /*----------------------------------------------------------------*/
  613.     S8 listCount[CCONV_MAX_RATEENTRIES];
  614.     S8 strTemp[] = { ' ', '', '', '' };
  615.     S32 precision;
  616.     S8 i, j;
  617.     /*----------------------------------------------------------------*/
  618.     /* Code Body                                                      */
  619.     /*----------------------------------------------------------------*/
  620.     /* Exchange rate Input Setting */
  621.     for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  622.     {
  623.         if (i == 0)
  624.         {
  625.             for (j = 0, listCount[i] = 0; j < CCONV_MAX_CURRENCY; j++)
  626.             {
  627.                 if (curName[j] == curName[g_cconv_ctx->selectedLocalCurID])
  628.                 {
  629.                     continue;
  630.                 }
  631.                 g_cconv_ctx->curList[0][listCount[0]++] = curName[j];
  632.             }
  633.         }
  634.         else
  635.         {
  636.             for (j = 0, listCount[i] = 0; j < listCount[i - 1]; j++)
  637.             {
  638.                 if (g_cconv_ctx->curList[i - 1][j] == curName[g_cconv_ctx->curID[i - 1]])
  639.                 {
  640.                     continue;
  641.                 }
  642.                 g_cconv_ctx->curList[i][listCount[i]++] = g_cconv_ctx->curList[i - 1][j];
  643.             }
  644.         }
  645.         g_cconv_ctx->curIndex[i] = mmi_cconv_get_cur_index(g_cconv_ctx->curID[i], g_cconv_ctx->curList[i], listCount[i]);
  646.         g_cconv_ctx->curID[i] = mmi_cconv_get_cur_id(g_cconv_ctx->curIndex[i], g_cconv_ctx->curList[i]);
  647.         SetInlineItemActivation(&wgui_inline_items[ITEM_BASE + i * 2], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  648.         SetInlineItemSelect(
  649.             &wgui_inline_items[ITEM_BASE + i * 2],
  650.             listCount[i],
  651.             (U8 **) g_cconv_ctx->curList[i],
  652.             &g_cconv_ctx->curIndex[i]);
  653.         RegisterInlineSelectHighlightHandler(
  654.             &wgui_inline_items[ITEM_BASE + i * 2],
  655.             mmi_cconv_rate_inline_select_highlight_hdlr);
  656.         memset(g_cconv_ctx->strRate[i], 0, CCONV_SEL_BUF_LEN);
  657.         if (g_cconv_ctx->rate[i] > 0)
  658.         {
  659.             precision = CalcComputePrecision(g_cconv_ctx->rate[i], CCONV_MAX_RESULT);
  660.             gui_float_string(g_cconv_ctx->rate[i], precision, (S8*) g_cconv_ctx->strRate[i]);
  661.         }
  662.         if (g_cconv_ctx->selectedLocalCurID < CCONV_NAMED_CURRENCY)
  663.         {
  664.             pfnUnicodeStrcat((S8*) g_cconv_ctx->strRate[i], (S8*) strTemp);   /* concatenate white space */
  665.             pfnUnicodeStrcat((S8*) g_cconv_ctx->strRate[i], (S8*) curShortName[g_cconv_ctx->selectedLocalCurID]);
  666.         }
  667.         SetInlineItemActivation(&wgui_inline_items[ITEM_BASE + i * 2 + 1], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  668.         SetInlineItemTextEdit(
  669.             &wgui_inline_items[ITEM_BASE + i * 2 + 1],
  670.             (U8*) g_cconv_ctx->strRate[i],
  671.             (CCONV_MAX_RATE + 1),
  672.             INPUT_TYPE_DECIMAL_NUMERIC);
  673.         SetInlineTextEditCustomFunction(
  674.             &wgui_inline_items[ITEM_BASE + i * 2 + 1],
  675.             mmi_cconv_rate_inline_edit_highlight_hdlr);
  676.         RegisterInlineFullScreenEditValidationFunction(
  677.             &wgui_inline_items[ITEM_BASE + i * 2 + 1],
  678.             mmi_cconv_rate_inline_edit_validation_hdlr);
  679.         EnableInlineItemBoundary(&wgui_inline_items[ITEM_BASE + i * 2 + 1]);
  680.         RightJustifyInlineItem(&wgui_inline_items[ITEM_BASE + i * 2 + 1]);
  681.     }
  682. }
  683. /*****************************************************************************
  684.  * FUNCTION
  685.  *  mmi_cconv_rate_layout_inline_items
  686.  * DESCRIPTION
  687.  *  Layout inline items in rate screen
  688.  * PARAMETERS
  689.  *  void
  690.  * RETURNS
  691.  *  void
  692.  *****************************************************************************/
  693. void mmi_cconv_rate_layout_inline_items(void)
  694. {
  695.     /*----------------------------------------------------------------*/
  696.     /* Local Variables                                                */
  697.     /*----------------------------------------------------------------*/
  698.     /*----------------------------------------------------------------*/
  699.     /* Code Body                                                      */
  700.     /*----------------------------------------------------------------*/
  701.     set_leading_zero(FALSE);
  702.     DisableInlineInputMethodHints();
  703.     /* Local Currency Selection */
  704.     SetInlineItemActivation(&wgui_inline_items[CCONV_RATE_INLINE_LOCAL_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  705.     SetInlineItemCaption(&wgui_inline_items[CCONV_RATE_INLINE_LOCAL_CAP], (U8*) GetString(STR_CURRENCYCONV_LOCAL));
  706.     SetInlineItemActivation(
  707.         &wgui_inline_items[CCONV_RATE_INLINE_LOCAL_SELECT],
  708.         INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT,
  709.         0);
  710.     SetInlineItemSelect(
  711.         &wgui_inline_items[CCONV_RATE_INLINE_LOCAL_SELECT],
  712.         CCONV_MAX_CURRENCY,
  713.         (U8 **) curName,
  714.         &g_cconv_ctx->selectedLocalCurID);
  715.     RegisterInlineSelectHighlightHandler(
  716.         &wgui_inline_items[CCONV_RATE_INLINE_LOCAL_SELECT],
  717.         mmi_cconv_rate_local_select_hdlr);
  718.     SetInlineItemActivation(&wgui_inline_items[CCONV_RATE_INLINE_FORE_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
  719.     SetInlineItemCaption(&wgui_inline_items[CCONV_RATE_INLINE_FORE_CAP], (U8*) GetString(STR_CURRENCYCONV_FOREIGN));
  720.     mmi_cconv_rate_select_list();
  721.     g_cconv_ctx->prevSelectedLocalCurID = g_cconv_ctx->selectedLocalCurID;
  722. }
  723. /*****************************************************************************
  724.  * FUNCTION
  725.  *  mmi_cconv_entry_rate
  726.  * DESCRIPTION
  727.  *  Entry Function of Compute cur exchange
  728.  * PARAMETERS
  729.  *  void
  730.  * RETURNS
  731.  *  void
  732.  *****************************************************************************/
  733. void mmi_cconv_entry_rate(void)
  734. {
  735.     /*----------------------------------------------------------------*/
  736.     /* Local Variables                                                */
  737.     /*----------------------------------------------------------------*/
  738.     U8 *guiBuffer;
  739.     U8 *inputBuffer;        /* added for inline edit history */
  740.     U16 inputBufferSize;    /* added for inline edit history */
  741.     /*----------------------------------------------------------------*/
  742.     /* Code Body                                                      */
  743.     /*----------------------------------------------------------------*/
  744.     EntryNewScreen(SCR_ID_CCONV_RATE_INPUT, mmi_cconv_exit_rate, NULL, NULL);
  745.     guiBuffer = GetCurrGuiBuffer(SCR_ID_CCONV_RATE_INPUT);
  746.     InitializeCategory57Screen();
  747.     inputBuffer = GetCurrNInputBuffer(SCR_ID_CCONV_RATE_INPUT, &inputBufferSize);       /* added for inline edit history */
  748.     if (inputBuffer && g_cconv_ctx->isRedrawScreen == FALSE)
  749.     {
  750.         SetCategory57Data(wgui_inline_items, CCONV_RATE_INLINE_TOTAL, inputBuffer);     /* sets the data */
  751.     }
  752.     else
  753.     {
  754.         g_cconv_ctx->isRedrawScreen = FALSE;
  755.     }
  756.     mmi_cconv_rate_layout_inline_items();
  757.     RegisterHighlightHandler(mmi_cconv_rate_item_highlight_hdlr);
  758.     ShowCategory57Screen(
  759.         STR_CURRENCYCONV_RATEINPUT,
  760.         GetRootTitleIcon(EXTRA_CURRENCYCONVERTOR_MENU),
  761.         STR_GLOBAL_OK,
  762.         IMG_GLOBAL_OK,
  763.         STR_GLOBAL_BACK,
  764.         IMG_GLOBAL_BACK,
  765.         CCONV_RATE_INLINE_TOTAL,
  766.         NULL,
  767.         wgui_inline_items,
  768.         g_cconv_ctx->hiliteItemIndex,
  769.         guiBuffer);
  770.     DisableCategory57ScreenDone();
  771.     SetLeftSoftkeyFunction(mmi_cconv_rate_save_change, KEY_EVENT_UP);
  772.     SetCategory57RightSoftkeyFunctions(mmi_cconv_rate_save_change, GoBackHistory);
  773.     SetHighlightedItem(g_cconv_ctx->hiliteItemIndex);
  774. }
  775. /*****************************************************************************
  776.  * FUNCTION
  777.  *  mmi_cconv_exit_rate
  778.  * DESCRIPTION
  779.  *  Entry Function of Compute cur exchange
  780.  * PARAMETERS
  781.  *  void
  782.  * RETURNS
  783.  *  void
  784.  *****************************************************************************/
  785. void mmi_cconv_exit_rate(void)
  786. {
  787.     /*----------------------------------------------------------------*/
  788.     /* Local Variables                                                */
  789.     /*----------------------------------------------------------------*/
  790.     U16 inputBufferSize;    /* added for inline edit history */
  791.     history HistoryCCComputeCurrency;
  792.     S16 nHistory = 0;
  793.     S8 i;
  794.     S8 strTemp[CCONV_SEL_BUF_LEN];
  795.     S8 length;
  796.     /*----------------------------------------------------------------*/
  797.     /* Code Body                                                      */
  798.     /*----------------------------------------------------------------*/
  799.     set_leading_zero(TRUE);
  800.     if (g_cconv_ctx)
  801.     {
  802.         CloseCategory57Screen();
  803.         if (!g_cconv_ctx->isRedrawScreen)
  804.         {
  805.             for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  806.             {
  807.                 /* Extract rate value from strings */
  808.                 if (g_cconv_ctx->selectedLocalCurID < CCONV_NAMED_CURRENCY)
  809.                 {
  810.                     length = gui_strlen((UI_string_type) g_cconv_ctx->strRate[i]) -
  811.                         gui_strlen((UI_string_type) curShortName[g_cconv_ctx->selectedLocalCurID]) - 1;
  812.                     if (length < 1)
  813.                     {
  814.                         g_cconv_ctx->rate[i] = -1;
  815.                     }
  816.                     else
  817.                     {
  818.                         pfnUnicodeStrncpy(strTemp, (S8*) g_cconv_ctx->strRate[i], length);
  819.                         g_cconv_ctx->rate[i] = gui_atof((U16*) strTemp);
  820.                     }
  821.                 }
  822.                 else
  823.                 {
  824.                     if (gui_strlen((UI_string_type) g_cconv_ctx->strRate[i]) < 1)
  825.                     {
  826.                         g_cconv_ctx->rate[i] = -1;
  827.                     }
  828.                     else
  829.                     {
  830.                         g_cconv_ctx->rate[i] = gui_atof((U16*) g_cconv_ctx->strRate[i]);
  831.                     }
  832.                 }
  833.                 // Remap currency selections into IDs.
  834.                 //g_cconv_ctx->curID[i] = mmi_cconv_get_cur_id(g_cconv_ctx->curIndex[i], g_cconv_ctx->curList[i]);
  835.             }
  836.         }
  837.         g_cconv_ctx->reloadFromNVRAM = TRUE;
  838.     }
  839.     HistoryCCComputeCurrency.scrnID = SCR_ID_CCONV_RATE_INPUT;
  840.     HistoryCCComputeCurrency.entryFuncPtr = mmi_cconv_entry_rate;
  841.     GetCategory57History(HistoryCCComputeCurrency.guiBuffer);
  842.     pfnUnicodeStrcpy((S8*) HistoryCCComputeCurrency.inputBuffer, (S8*) & nHistory);
  843.     inputBufferSize = (U16) GetCategory57DataSize();        /* added for inline edit history */
  844.     GetCategory57Data((U8*) HistoryCCComputeCurrency.inputBuffer);     /* added for inline edit history */
  845.     AddNHistory(HistoryCCComputeCurrency, inputBufferSize); /* added for inline edit history */
  846. }
  847. /*****************************************************************************
  848.  * FUNCTION
  849.  *  mmi_cconv_rate_save_change
  850.  * DESCRIPTION
  851.  *  Save rate setting changes into NVRAM.
  852.  * PARAMETERS
  853.  *  void
  854.  * RETURNS
  855.  *  void
  856.  *****************************************************************************/
  857. void mmi_cconv_rate_save_change(void)
  858. {
  859.     /*----------------------------------------------------------------*/
  860.     /* Local Variables                                                */
  861.     /*----------------------------------------------------------------*/
  862.     S8 strTemp[CCONV_SEL_BUF_LEN];
  863.     S8 length;
  864.     S16 error;
  865.     S8 i;
  866.     U8 rateflag = 0;
  867.     /*----------------------------------------------------------------*/
  868.     /* Code Body                                                      */
  869.     /*----------------------------------------------------------------*/
  870.     CloseCategory57Screen();
  871.     for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  872.     {
  873.         /* Extract rate value from strings */
  874.         if (g_cconv_ctx->selectedLocalCurID < CCONV_NAMED_CURRENCY)
  875.         {
  876.             length = gui_strlen((UI_string_type) g_cconv_ctx->strRate[i]) -
  877.                 gui_strlen((UI_string_type) curShortName[g_cconv_ctx->selectedLocalCurID]) - 1;
  878.             if (length < 1)
  879.             {
  880.                 g_cconv_ctx->rate[i] = -1;
  881.             }
  882.             else
  883.             {
  884.                 pfnUnicodeStrncpy(strTemp, (S8*) g_cconv_ctx->strRate[i], length);
  885.                 g_cconv_ctx->rate[i] = gui_atof((U16*) strTemp);
  886.                 rateflag = 1;
  887.             }
  888.         }
  889.         else
  890.         {
  891.             if (gui_strlen((UI_string_type) g_cconv_ctx->strRate[i]) < 1)
  892.             {
  893.                 g_cconv_ctx->rate[i] = -1;
  894.             }
  895.             else
  896.             {
  897.                 g_cconv_ctx->rate[i] = gui_atof((U16*) g_cconv_ctx->strRate[i]);
  898.                 rateflag = 1;
  899.             }
  900.         }
  901.         if (!g_cconv_ctx->bRateDefined && g_cconv_ctx->rate[i] > 0)
  902.         {
  903.             g_cconv_ctx->bRateDefined = TRUE;
  904.         }
  905.         WriteValue((U8) (NVRAM_CCONV_EXCHANGE_RATE1 + i), &g_cconv_ctx->rate[i], DS_DOUBLE, &error);
  906.         /* Remap currency selections into IDs. */
  907.         g_cconv_ctx->curID[i] = mmi_cconv_get_cur_id(g_cconv_ctx->curIndex[i], g_cconv_ctx->curList[i]);
  908.         WriteValue((U8) (NVRAM_CCONV_SETTING_CURRENCY1 + i), &g_cconv_ctx->curID[i], DS_BYTE, &error);
  909.     }
  910.     if (rateflag == 0)
  911.     {
  912.         g_cconv_ctx->bRateDefined = FALSE;
  913.     }
  914.     g_cconv_ctx->prevSelectedLocalCurID = g_cconv_ctx->selectedLocalCurID;
  915.     WriteValue(NVRAM_CCONV_SETTING_LOCALCURRENCY, &g_cconv_ctx->selectedLocalCurID, DS_BYTE, &error);
  916.     if (IsScreenPresent(SCR_ID_CCONV_COMPUTE))
  917.     {
  918.         GoBackHistory();
  919.     }
  920.     else
  921.     {
  922.         mmi_cconv_entry_app();
  923.     }
  924. }
  925. /*****************************************************************************
  926.  * FUNCTION
  927.  *  mmi_cconv_compute_item_highlight_hdlr
  928.  * DESCRIPTION
  929.  *  Highlight handler of inline items in compute screen.
  930.  * PARAMETERS
  931.  *  index       [IN]        Index of highlight item.
  932.  * RETURNS
  933.  *  void
  934.  *****************************************************************************/
  935. void mmi_cconv_compute_item_highlight_hdlr(S32 index)
  936. {
  937.     /*----------------------------------------------------------------*/
  938.     /* Local Variables                                                */
  939.     /*----------------------------------------------------------------*/
  940.     /*----------------------------------------------------------------*/
  941.     /* Code Body                                                      */
  942.     /*----------------------------------------------------------------*/
  943.     g_cconv_ctx->hiliteItemIndex = index;
  944.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  945.     SetRightSoftkeyFunction(mmi_cconv_return_to_menu, KEY_EVENT_UP);
  946.     ChangeLeftSoftkey(STR_CURRENCYCONV_RATE, IMG_GLOBAL_OK);
  947.     SetLeftSoftkeyFunction(mmi_cconv_pre_entry_rate, KEY_EVENT_UP);
  948. }
  949. /*****************************************************************************
  950.  * FUNCTION
  951.  *  mmi_cconv_fore_select_list
  952.  * DESCRIPTION
  953.  *  create selection list for foreign currency.
  954.  * PARAMETERS
  955.  *  void
  956.  *  index  index of selected item.(?)
  957.  * RETURNS
  958.  *  void
  959.  *****************************************************************************/
  960. S8 mmi_cconv_fore_select_list()
  961. {
  962.     /*----------------------------------------------------------------*/
  963.     /* Local Variables                                                */
  964.     /*----------------------------------------------------------------*/
  965.     S8 i, nItems2;
  966.     /*----------------------------------------------------------------*/
  967.     /* Code Body                                                      */
  968.     /*----------------------------------------------------------------*/
  969.     for (i = 0, nItems2 = 0; i < CCONV_MAX_RATEENTRIES; i++)
  970.     {
  971.         if (g_cconv_ctx->rate[i] > 0)
  972.         {   /* if the rate is defined, add the correspoding cur into curList */
  973.             if (g_cconv_ctx->curID[i] == g_cconv_ctx->localCurID)
  974.             {
  975.                 continue;   /* skip the one selected in list 1 */
  976.             }
  977.             g_cconv_ctx->curList2[nItems2++] = curName[g_cconv_ctx->curID[i]];
  978.         }
  979.     }
  980.     if (g_cconv_ctx->bRateDefined && g_cconv_ctx->selectedLocalCurID != g_cconv_ctx->localCurID)
  981.     {
  982.         g_cconv_ctx->curList2[nItems2++] = curName[g_cconv_ctx->selectedLocalCurID];
  983.     }
  984.     g_cconv_ctx->foreignCurIndex = mmi_cconv_get_cur_index(g_cconv_ctx->foreignCurID, g_cconv_ctx->curList2, nItems2);
  985.     g_cconv_ctx->foreignCurID = mmi_cconv_get_cur_id(g_cconv_ctx->foreignCurIndex, g_cconv_ctx->curList2);
  986.     return nItems2;
  987. }
  988. /*****************************************************************************
  989.  * FUNCTION
  990.  *  mmi_cconv_local_select_list
  991.  * DESCRIPTION
  992.  *  create selection list for local currency.
  993.  * PARAMETERS
  994.  *  void
  995.  *  index  index of selected item.(?)
  996.  * RETURNS
  997.  *  void
  998.  *****************************************************************************/
  999. S8 mmi_cconv_local_select_list()
  1000. {
  1001.     /*----------------------------------------------------------------*/
  1002.     /* Local Variables                                                */
  1003.     /*----------------------------------------------------------------*/
  1004.     S8 i, nItems1;
  1005.     /*----------------------------------------------------------------*/
  1006.     /* Code Body                                                      */
  1007.     /*----------------------------------------------------------------*/
  1008.     for (i = 0, nItems1 = 0; i < CCONV_MAX_RATEENTRIES; i++)
  1009.     {
  1010.         if (g_cconv_ctx->rate[i] > 0)
  1011.         {                                       /* if the rate is defined, add the correspoding cur into curList */
  1012.             g_cconv_ctx->curList1[nItems1++] = curName[g_cconv_ctx->curID[i]];
  1013.             g_cconv_ctx->bRateDefined = TRUE;   /* at least one exchange rate is defined for conversion. */
  1014.         }
  1015.     }
  1016.     /* add the local cur into list as well */
  1017.     if (g_cconv_ctx->bRateDefined)
  1018.     {
  1019.         g_cconv_ctx->curList1[nItems1++] = curName[g_cconv_ctx->selectedLocalCurID];
  1020.     }
  1021.     g_cconv_ctx->localCurIndex = mmi_cconv_get_cur_index(g_cconv_ctx->localCurID, g_cconv_ctx->curList1, nItems1);
  1022.     g_cconv_ctx->localCurID = mmi_cconv_get_cur_id(g_cconv_ctx->localCurIndex, g_cconv_ctx->curList1);
  1023.     return nItems1;
  1024. }
  1025. /*****************************************************************************
  1026.  * FUNCTION
  1027.  *  mmi_cconv_compute_local_select_highlight_hdlr
  1028.  * DESCRIPTION
  1029.  *  Highlight handler of local currency inline selection in compute screen.
  1030.  * PARAMETERS
  1031.  *  index       [IN]        Index of selected item.
  1032.  * RETURNS
  1033.  *  void
  1034.  *****************************************************************************/
  1035. void mmi_cconv_compute_local_select_highlight_hdlr(S32 index)
  1036. {
  1037.     /*----------------------------------------------------------------*/
  1038.     /* Local Variables                                                */
  1039.     /*----------------------------------------------------------------*/
  1040. S8 nItems2;
  1041.     /*----------------------------------------------------------------*/
  1042.     /* Code Body                                                      */
  1043.     /*----------------------------------------------------------------*/
  1044.     if (g_cconv_ctx->localCurID != mmi_cconv_get_cur_id(index, g_cconv_ctx->curList1))
  1045.     {
  1046.         g_cconv_ctx->localCurID = mmi_cconv_get_cur_id(index, g_cconv_ctx->curList1);
  1047.         memset(g_cconv_ctx->LocalBuff, 0, ENCODING_LENGTH);
  1048.         memset(g_cconv_ctx->ForeBuff, 0, ENCODING_LENGTH);
  1049. nItems2 = mmi_cconv_fore_select_list();
  1050. change_fixed_icontext_item(
  1051. CCONV_CURRENCY_INLINE_FORE_SELECT,
  1052. (UI_string_type) g_cconv_ctx->curList2[g_cconv_ctx->foreignCurIndex],
  1053. 0);
  1054. redraw_fixed_list();
  1055.     }
  1056.     g_cconv_ctx->selectedRate = mmi_cconv_get_exchange_rate(g_cconv_ctx->localCurID, g_cconv_ctx->foreignCurID);
  1057.     return;
  1058. }
  1059. /*****************************************************************************
  1060.  * FUNCTION
  1061.  *  mmi_cconv_compute_fore_select_highlight_hdlr
  1062.  * DESCRIPTION
  1063.  *  Highlight handler of foreign currency inline selection in compute screen.
  1064.  * PARAMETERS
  1065.  *  index       [IN]        Index of selected item.
  1066.  * RETURNS
  1067.  *  void
  1068.  *****************************************************************************/
  1069. void mmi_cconv_compute_fore_select_highlight_hdlr(S32 index)
  1070. {
  1071.     /*----------------------------------------------------------------*/
  1072.     /* Local Variables                                                */
  1073.     /*----------------------------------------------------------------*/
  1074.     /*----------------------------------------------------------------*/
  1075.     /* Code Body                                                      */
  1076.     /*----------------------------------------------------------------*/
  1077.     g_cconv_ctx->foreignCurID = mmi_cconv_get_cur_id(index, g_cconv_ctx->curList2);
  1078.     g_cconv_ctx->selectedRate = mmi_cconv_get_exchange_rate(g_cconv_ctx->localCurID, g_cconv_ctx->foreignCurID);
  1079.     mmi_cconv_compute_result((U8*) g_cconv_ctx->LocalBuff);
  1080.     return;
  1081. }
  1082. /*****************************************************************************
  1083.  * FUNCTION
  1084.  *  mmi_cconv_compute_inline_edit_highlight_hdlr
  1085.  * DESCRIPTION
  1086.  *  Highlight handler of inline edit in compute screen. (To correct LSK function)
  1087.  * PARAMETERS
  1088.  *  void
  1089.  * RETURNS
  1090.  *  void
  1091.  *****************************************************************************/
  1092. void mmi_cconv_compute_inline_edit_highlight_hdlr(void)
  1093. {
  1094.     /*----------------------------------------------------------------*/
  1095.     /* Local Variables                                                */
  1096.     /*----------------------------------------------------------------*/
  1097.     /*----------------------------------------------------------------*/
  1098.     /* Code Body                                                      */
  1099.     /*----------------------------------------------------------------*/
  1100.     DisableCategory57ScreenDone();
  1101.     SetCategory57RightSoftkeyFunctions(mmi_cconv_pre_entry_rate, mmi_cconv_return_to_menu);
  1102.     ChangeLeftSoftkey(STR_CURRENCYCONV_RATE, IMG_GLOBAL_OK);
  1103.     SetLeftSoftkeyFunction(mmi_cconv_pre_entry_rate, KEY_EVENT_UP);
  1104. }
  1105. /*****************************************************************************
  1106.  * FUNCTION
  1107.  *  mmi_cconv_compute_inline_edit_validation_hdlr
  1108.  * DESCRIPTION
  1109.  *  Perform currency conversion while user is typing.
  1110.  * PARAMETERS
  1111.  *  buffer          [?]         Content of inline edit.
  1112.  *  cursor          [?]         Content after the cursor position
  1113.  *  text_length     [IN]        Content length
  1114.  * RETURNS
  1115.  *  void
  1116.  *****************************************************************************/
  1117. void mmi_cconv_compute_inline_edit_validation_hdlr(U8 *buffer, U8 *cursor, S32 text_length)
  1118. {
  1119.     /*----------------------------------------------------------------*/
  1120.     /* Local Variables                                                */
  1121.     /*----------------------------------------------------------------*/
  1122.     /*----------------------------------------------------------------*/
  1123.     /* Code Body                                                      */
  1124.     /*----------------------------------------------------------------*/
  1125.     if (pfnUnicodeStrcmp((S8*) buffer, g_cconv_ctx->LocalBuff) == 0)
  1126.     {
  1127.         if (text_length == 0 && (gui_strlen((UI_string_type) g_cconv_ctx->ForeBuff) > 0))
  1128.         {
  1129.             memset(g_cconv_ctx->ForeBuff, 0, 15);
  1130.             RedrawCategoryFunction();
  1131.         }
  1132.         return;
  1133.     }
  1134.     mmi_cconv_compute_result(buffer);
  1135. }
  1136. /*****************************************************************************
  1137.  * FUNCTION
  1138.  *  mmi_cconv_rate_item_highlight_hdlr
  1139.  * DESCRIPTION
  1140.  *  Highlight handler of inline item in exchange screen.
  1141.  * PARAMETERS
  1142.  *  index       [IN]        Index of item.
  1143.  * RETURNS
  1144.  *  void
  1145.  *****************************************************************************/
  1146. void mmi_cconv_rate_item_highlight_hdlr(S32 index)
  1147. {
  1148.     /*----------------------------------------------------------------*/
  1149.     /* Local Variables                                                */
  1150.     /*----------------------------------------------------------------*/
  1151.     /*----------------------------------------------------------------*/
  1152.     /* Code Body                                                      */
  1153.     /*----------------------------------------------------------------*/
  1154.     g_cconv_ctx->hiliteItemIndex = index;
  1155.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  1156.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1157.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  1158.     SetLeftSoftkeyFunction(mmi_cconv_rate_save_change, KEY_EVENT_UP);
  1159. }
  1160. /*****************************************************************************
  1161.  * FUNCTION
  1162.  *  mmi_cconv_rate_local_select_hdlr
  1163.  * DESCRIPTION
  1164.  *  Highlight handler of local currency inline selection in rate screen.
  1165.  *  reset all rates and redraw the screen
  1166.  * PARAMETERS
  1167.  *  index       [IN]        Index of selected item.
  1168.  * RETURNS
  1169.  *  void
  1170.  *****************************************************************************/
  1171. void mmi_cconv_rate_local_select_hdlr(S32 index)
  1172. {
  1173.     /*----------------------------------------------------------------*/
  1174.     /* Local Variables                                                */
  1175.     /*----------------------------------------------------------------*/
  1176.     S8 i;
  1177.     /*----------------------------------------------------------------*/
  1178.     /* Code Body                                                      */
  1179.     /*----------------------------------------------------------------*/
  1180.     if (g_cconv_ctx->prevSelectedLocalCurID != index)
  1181.     {
  1182.         for (i = 0; i < CCONV_MAX_CURRENCY; i++)
  1183.         {
  1184.             g_cconv_ctx->rate[i] = -1;
  1185.         }
  1186.         RedrawCategoryFunction();
  1187.     }
  1188. }
  1189. /*****************************************************************************
  1190.  * FUNCTION
  1191.  *  mmi_cconv_rate_inline_select_highlight_hdlr
  1192.  * DESCRIPTION
  1193.  *  Highlight handler of foreign currency inline selection in rate screen.
  1194.  *  update the currency id and redraw the screen
  1195.  * PARAMETERS
  1196.  *  index       [IN]        Index of selected item.
  1197.  * RETURNS
  1198.  *  void
  1199.  *****************************************************************************/
  1200. void mmi_cconv_rate_inline_select_highlight_hdlr(S32 index)
  1201. {
  1202.     /*----------------------------------------------------------------*/
  1203.     /* Local Variables                                                */
  1204.     /*----------------------------------------------------------------*/
  1205.     S8 i;
  1206.     /*----------------------------------------------------------------*/
  1207.     /* Code Body                                                      */
  1208.     /*----------------------------------------------------------------*/
  1209.     for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  1210.     {
  1211.         if (g_cconv_ctx->curID[i] != mmi_cconv_get_cur_id(g_cconv_ctx->curIndex[i], g_cconv_ctx->curList[i]))
  1212.         {
  1213.             g_cconv_ctx->curID[i] = mmi_cconv_get_cur_id(g_cconv_ctx->curIndex[i], g_cconv_ctx->curList[i]);
  1214.             CloseCategory57Screen();
  1215.             /* mmi_cconv_rate_layout_inline_items(); */
  1216.             mmi_cconv_rate_select_list();
  1217.             RedrawCategoryFunction();
  1218.             return;
  1219.         }
  1220.     }
  1221. }
  1222. /*****************************************************************************
  1223.  * FUNCTION
  1224.  *  mmi_cconv_rate_inline_edit_highlight_hdlr
  1225.  * DESCRIPTION
  1226.  *  Set group key handlers of inline editor
  1227.  * PARAMETERS
  1228.  *  void
  1229.  * RETURNS
  1230.  *  void
  1231.  *****************************************************************************/
  1232. void mmi_cconv_rate_inline_edit_highlight_hdlr(void)
  1233. {
  1234.     /*----------------------------------------------------------------*/
  1235.     /* Local Variables                                                */
  1236.     /*----------------------------------------------------------------*/
  1237.     /*----------------------------------------------------------------*/
  1238.     /* Code Body                                                      */
  1239.     /*----------------------------------------------------------------*/
  1240.     SetKeyHandler(mmi_cconv_rate_inline_edit_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1241.     DisableCategory57ScreenDone();
  1242.     SetLeftSoftkeyFunction(mmi_cconv_rate_save_change, KEY_EVENT_UP);
  1243.     SetCategory57RightSoftkeyFunctions(mmi_cconv_rate_save_change, GoBackHistory);
  1244. }
  1245. /*****************************************************************************
  1246.  * FUNCTION
  1247.  *  mmi_cconv_rate_inline_edit_validation_hdlr
  1248.  * DESCRIPTION
  1249.  *  Correct the cursor posiition of inline edit
  1250.  * PARAMETERS
  1251.  *  buffer          [?]         Content of inline edit.
  1252.  *  cursor          [?]         Content after the cursor position
  1253.  *  text_length     [IN]        Content length
  1254.  * RETURNS
  1255.  *  void
  1256.  *****************************************************************************/
  1257. void mmi_cconv_rate_inline_edit_validation_hdlr(U8 *buffer, U8 *cursor, S32 text_length)
  1258. {
  1259.     /*----------------------------------------------------------------*/
  1260.     /* Local Variables                                                */
  1261.     /*----------------------------------------------------------------*/
  1262.     S32 diff;
  1263.     /*----------------------------------------------------------------*/
  1264.     /* Code Body                                                      */
  1265.     /*----------------------------------------------------------------*/
  1266.     if (!(g_cconv_ctx->selectedLocalCurID < CCONV_NAMED_CURRENCY))
  1267.     {
  1268.         return;
  1269.     }
  1270.     diff = gui_strlen((UI_string_type) curShortName[g_cconv_ctx->selectedLocalCurID]) -
  1271.         gui_strlen((UI_string_type) cursor) + 1;
  1272.     if (diff > 0)
  1273.     {
  1274.         gui_single_line_input_box_previous_steps(&MMI_inline_singleline_inputbox, diff);
  1275.     }
  1276.     else if (diff < 0)
  1277.     {
  1278.         gui_single_line_input_box_next_steps(&MMI_inline_singleline_inputbox, diff);
  1279.     }
  1280. redraw_inline_singleline_inputbox();
  1281. }
  1282. /*****************************************************************************
  1283.  * FUNCTION
  1284.  *  mmi_cconv_rate_inline_edit_key_hdlr
  1285.  * DESCRIPTION
  1286.  *  Correct the cursor posiition of inline edit
  1287.  * PARAMETERS
  1288.  *  void
  1289.  * RETURNS
  1290.  *  void
  1291.  *****************************************************************************/
  1292. void mmi_cconv_rate_inline_edit_key_hdlr(void)
  1293. {
  1294.     /*----------------------------------------------------------------*/
  1295.     /* Local Variables                                                */
  1296.     /*----------------------------------------------------------------*/
  1297.     S32 diff;
  1298.     /*----------------------------------------------------------------*/
  1299.     /* Code Body                                                      */
  1300.     /*----------------------------------------------------------------*/
  1301.     if (g_cconv_ctx->selectedLocalCurID < CCONV_NAMED_CURRENCY)
  1302.     {
  1303.         diff = gui_strlen((UI_string_type) curShortName[g_cconv_ctx->selectedLocalCurID]) -
  1304.             gui_strlen((UI_string_type) MMI_inline_singleline_inputbox.current_text_p) + 1;
  1305.         if (diff > 0)
  1306.         {
  1307.             gui_single_line_input_box_previous_steps(&MMI_inline_singleline_inputbox, diff);
  1308.         }
  1309.         else if (diff < 0)
  1310.         {
  1311.             inline_edit_singleline_inputbox_next_character();
  1312.             /* gui_single_line_input_box_next_steps(&MMI_inline_singleline_inputbox, diff); */
  1313.         }
  1314.     }
  1315.     else
  1316.     {
  1317.         inline_edit_singleline_inputbox_next_character();
  1318.     }
  1319. }
  1320. /*****************************************************************************
  1321.  * FUNCTION
  1322.  *  mmi_cconv_get_cur_id
  1323.  * DESCRIPTION
  1324.  *  Returns the id of a currency given the index in the list provided.
  1325.  * PARAMETERS
  1326.  *  index       [IN]        Index of the currency in the list.
  1327.  *  list        [IN]        A list that contains the currency.
  1328.  * RETURNS
  1329.  *  currency id.
  1330.  *****************************************************************************/
  1331. S32 mmi_cconv_get_cur_id(S32 index, S8 **list)
  1332. {
  1333.     /*----------------------------------------------------------------*/
  1334.     /* Local Variables                                                */
  1335.     /*----------------------------------------------------------------*/
  1336.     S8 i;
  1337.     /*----------------------------------------------------------------*/
  1338.     /* Code Body                                                      */
  1339.     /*----------------------------------------------------------------*/
  1340.     for (i = 0; i < CCONV_MAX_CURRENCY; i++)
  1341.     {
  1342.         if (list[index] == curName[i])
  1343.         {
  1344.             return i;
  1345.         }
  1346.     }
  1347.     return 0;
  1348. }
  1349. /*****************************************************************************
  1350.  * FUNCTION
  1351.  *  mmi_cconv_get_cur_index
  1352.  * DESCRIPTION
  1353.  *  Returns the index of a currency in the list provided.
  1354.  * PARAMETERS
  1355.  *  id          [IN]        Id of the currency.
  1356.  *  list        [IN]        A list that contains the currency.
  1357.  *  nItems      [IN]        Number of items in the list.
  1358.  * RETURNS
  1359.  *  currency index in the list.
  1360.  *****************************************************************************/
  1361. S32 mmi_cconv_get_cur_index(S32 id, S8 **list, S8 nItems)
  1362. {
  1363.     /*----------------------------------------------------------------*/
  1364.     /* Local Variables                                                */
  1365.     /*----------------------------------------------------------------*/
  1366.     S8 i;
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Code Body                                                      */
  1369.     /*----------------------------------------------------------------*/
  1370.     for (i = 0; i < nItems; i++)
  1371.     {
  1372.         if (list[i] == curName[id])
  1373.         {
  1374.             return i;
  1375.         }
  1376.     }
  1377.     return 0;
  1378. }
  1379. /*****************************************************************************
  1380.  * FUNCTION
  1381.  *  mmi_cconv_get_exchange_rate
  1382.  * DESCRIPTION
  1383.  *  Returns predefined exchange rate by given currency id.
  1384.  * PARAMETERS
  1385.  *  currencyID1     [IN]        Id of currency 1.
  1386.  *  currencyID2     [IN]        Id of currency 2.
  1387.  * RETURNS
  1388.  *  Predefined exchange rate.
  1389.  *****************************************************************************/
  1390. DOUBLE mmi_cconv_get_exchange_rate(S32 currencyID1, S32 currencyID2)
  1391. {
  1392.     /*----------------------------------------------------------------*/
  1393.     /* Local Variables                                                */
  1394.     /*----------------------------------------------------------------*/
  1395.     S8 i;
  1396.     DOUBLE rate1 = 0, rate2 = 0;
  1397.     /*----------------------------------------------------------------*/
  1398.     /* Code Body                                                      */
  1399.     /*----------------------------------------------------------------*/
  1400.     for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  1401.     {
  1402.         if (g_cconv_ctx->curID[i] == currencyID1)
  1403.         {
  1404.             rate1 = g_cconv_ctx->rate[i];
  1405.             break;
  1406.         }
  1407.     }
  1408.     for (i = 0; i < CCONV_MAX_RATEENTRIES; i++)
  1409.     {
  1410.         if (g_cconv_ctx->curID[i] == currencyID2)
  1411.         {
  1412.             rate2 = g_cconv_ctx->rate[i];
  1413.             break;
  1414.         }
  1415.     }
  1416.     if (rate2 == 0)
  1417.     {
  1418.         rate2 = 1;  /* get around with divide zero case. */
  1419.     }
  1420.     if (currencyID1 == g_cconv_ctx->selectedLocalCurID)
  1421.     {
  1422.         return 1 / rate2;
  1423.     }
  1424.     else if (currencyID2 == g_cconv_ctx->selectedLocalCurID)
  1425.     {
  1426.         return rate1;
  1427.     }
  1428.     else
  1429.     {
  1430.         return rate1 / rate2;
  1431.     }
  1432. }
  1433. /*****************************************************************************
  1434.  * FUNCTION
  1435.  *  mmi_cconv_compute_result
  1436.  * DESCRIPTION
  1437.  *  Convert the result and display.
  1438.  * PARAMETERS
  1439.  *  buffer      [?]     A string of number for conversion.
  1440.  * RETURNS
  1441.  *  void
  1442.  *****************************************************************************/
  1443. void mmi_cconv_compute_result(U8 *buffer)
  1444. {
  1445.     /*----------------------------------------------------------------*/
  1446.     /* Local Variables                                                */
  1447.     /*----------------------------------------------------------------*/
  1448.     S32 precision;
  1449.     DOUBLE result, conversion_factor;
  1450.     /*----------------------------------------------------------------*/
  1451.     /* Code Body                                                      */
  1452.     /*----------------------------------------------------------------*/
  1453.     /* CloseCategory57Screen(); */
  1454.     if ((gui_strlen((UI_string_type) buffer) < 1))
  1455.     {
  1456.         memset(g_cconv_ctx->ForeBuff, 0, 15);
  1457.     }
  1458.     else
  1459.     {
  1460.         /* calculate result */
  1461.         conversion_factor = g_cconv_ctx->selectedRate;
  1462.         result = (DOUBLE) (conversion_factor * gui_atof((UI_string_type) buffer));
  1463.         precision = CalcComputePrecision(result, CCONV_MAX_RESULT);
  1464.         gui_float_string(result, precision, (S8*) g_cconv_ctx->ForeBuff);
  1465.     }
  1466.     RedrawCategoryFunction();
  1467. }
  1468. /*****************************************************************************
  1469.  * FUNCTION
  1470.  *  mmi_cconv_return_to_menu
  1471.  * DESCRIPTION
  1472.  *  Exit application and return to menu.
  1473.  * PARAMETERS
  1474.  *  void
  1475.  * RETURNS
  1476.  *  void
  1477.  *****************************************************************************/
  1478. void mmi_cconv_return_to_menu(void)
  1479. {
  1480.     /*----------------------------------------------------------------*/
  1481.     /* Local Variables                                                */
  1482.     /*----------------------------------------------------------------*/
  1483.     /*----------------------------------------------------------------*/
  1484.     /* Code Body                                                      */
  1485.     /*----------------------------------------------------------------*/
  1486.     GoBackToHistory(SCR_EXTRA);
  1487.     /* GoBackHistory(); */
  1488. }
  1489. #endif /* __MMI_EXTENDED_CURRENCY_CONVERTER__ */ // #ifdef __MMI_EXTENDED_CURRENCY_CONVERTER__
  1490. #endif /* _MMI_CURRENCYCONVERTORE_C */ // #ifndef _MMI_CURRENCYCONVERTORE_C