⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 currencyconvertor.c

📁 mtk工具箱,计算器的详细设计,可以由此入手了解mtk的
💻 C
📖 第 1 页 / 共 3 页
字号:
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void CconvPreEntryApp(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_cconv_cntx)
    {
        OslMfree(g_cconv_cntx);
    }

    g_cconv_cntx = OslMalloc(sizeof(cconv_context_struct));
    memset(g_cconv_cntx, 0, sizeof(cconv_context_struct));

    EntryCconvApp();
}


/*****************************************************************************
 * FUNCTION
 *  HighlightCConvMenu
 * DESCRIPTION
 *  Highlight handler of Currency Converter menu item.
 *  Register key handlers.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void HighlightCConvMenu(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
    SetLeftSoftkeyFunction(CconvPreEntryApp, KEY_EVENT_UP);
    SetKeyHandler(CconvPreEntryApp, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
}


/*****************************************************************************
 * FUNCTION
 *  HighlightCconvRateItem
 * DESCRIPTION
 *  Highlight handler of rate input inline item.
 * PARAMETERS
 *  index       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void HighlightCconvRateItem(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    SetLeftSoftkeyFunction(CconvPreEntryExchange, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  EntryCconvApp
 * DESCRIPTION
 *  Display rate input screen of currency convertor application
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryCconvApp()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 precision;
    U8 *guiBuffer;
    U8 *inputBuffer;
    U16 inputBufferSize;
    S16 error;
    U16 RskImg = STR_GLOBAL_BACK;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    EntryNewScreen(SCR_ID_CCONV_RATE_INPUT, ExitCConvApp, NULL, NULL);

    guiBuffer = GetCurrGuiBuffer(SCR_ID_CCONV_RATE_INPUT);

    SetDelScrnIDCallbackHandler(SCR_ID_CCONV_RATE_INPUT, (HistoryDelCBPtr) mmi_cconv_del_scr_callback);

    InitializeCategory57Screen();

    if (guiBuffer)
    {
        memset((void*)guiBuffer, 0, 2);
    }

    inputBuffer = GetCurrNInputBuffer(SCR_ID_CCONV_COMPUTE, &inputBufferSize);  /* added for inline edit history */

    if (inputBuffer)    /* added for inline edit history */
    {
        SetCategory57Data(wgui_inline_items, 2, inputBuffer);   /* sets the data */
    }

    if (g_cconv_cntx->IsFromHistory)
    {
        g_cconv_cntx->Rate = gui_atof((U16*) g_cconv_cntx->RateBuff);
        if (UCS2Strlen(g_cconv_cntx->RateBuff))
        {
            RskImg = STR_GLOBAL_CLEAR;
        }
        else
        {
            RskImg = STR_GLOBAL_BACK;
        }
    }
    else
    {
        ReadValue(CURRENCY_CONVERTOR_EXCHANGE_RATE, &g_cconv_cntx->Rate, DS_DOUBLE, &error);
        g_cconv_cntx->IsFromHistory = TRUE;
    }

    if (g_cconv_cntx->Rate <= 999999 && g_cconv_cntx->Rate > 0) /* o data has been written set the text to blank */
    {
        precision = CalcComputePrecision(g_cconv_cntx->Rate, CCONV_MAX_RATE);
        gui_float_string(g_cconv_cntx->Rate, precision, (S8*) g_cconv_cntx->RateBuff);
    }

    SetInlineItemCaption(&wgui_inline_items[0], (U8*) get_string(STR_CURRENCYCONVERTOR_RATE));

    SetInlineItemActivation(&wgui_inline_items[1], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemTextEdit(
        &wgui_inline_items[1],
        (U8*) g_cconv_cntx->RateBuff,
        (CCONV_MAX_RATE + 1),
        INPUT_TYPE_DECIMAL_NUMERIC);
    EnableInlineItemBoundary(&wgui_inline_items[1]);
    RightJustifyInlineItem(&wgui_inline_items[1]);

    set_leading_zero(FALSE);
    RegisterHighlightHandler(HighlightCconvRateItem);

    ShowCategory257Screen(
        STR_CURRENCYCONVERTOR_RATEINPUT,
        GetRootTitleIcon(EXTRA_CURRENCYCONVERTOR_MENU),
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        RskImg,
        IMG_GLOBAL_BACK,
        CURRENCY_CONVERTOR_IMAGE,
        2,
        NULL,
        wgui_inline_items,
        1,
        guiBuffer);

    SetCategory57RightSoftkeyFunctions(CconvPreEntryExchange, GoBackHistory);
    SetLeftSoftkeyFunction(CconvPreEntryExchange, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  ExitCConvApp
 * DESCRIPTION
 *  Display rate input screen of currency convertor application
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void ExitCConvApp(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 inputBufferSize;    /* added for inline edit history */
    history HistoryCCComputeCurrency;
    S16 nHistory = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    set_leading_zero(TRUE);
    if (g_cconv_cntx)
    {
        CloseCategory57Screen();
    }
    HistoryCCComputeCurrency.scrnID = SCR_ID_CCONV_RATE_INPUT;
    HistoryCCComputeCurrency.entryFuncPtr = EntryCconvApp;
    GetCategory57History(HistoryCCComputeCurrency.guiBuffer);
    UCS2Strcpy((S8*) HistoryCCComputeCurrency.inputBuffer, (S8*) & nHistory);
    inputBufferSize = (U16) GetCategory57DataSize();        /* added for inline edit history */
    GetCategory57Data((U8*) HistoryCCComputeCurrency.inputBuffer);     /* added for inline edit history */
    AddNHistory(HistoryCCComputeCurrency, inputBufferSize); /* added for inline edit history */
}

#define UCONV_CONVERTING


/*****************************************************************************
 * FUNCTION
 *  CconvComputeResult
 * DESCRIPTION
 *  Convert the result and display.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void CconvComputeResult(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 precision;
    DOUBLE result, conversion_factor;

#if 0
/* under construction !*/
#endif /* 0 */ 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CloseCategory57Screen();

    if ((gui_strlen((UI_string_type) g_cconv_cntx->LocalBuff) < 1))
    {
        memset(g_cconv_cntx->ForeBuff, 0, 15);
        DisplayPopup(
            (U8*) GetString(ERROR_CURRENCYCONVERTOR_RATE1),
            IMG_GLOBAL_WARNING,
            0,
            UI_POPUP_NOTIFYDURATION_TIME,
            WARNING_TONE);
        return;
    }

    /* calculate result */
    if (g_cconv_cntx->CurrSelRate)  /* 1:R */
    {
        conversion_factor = g_cconv_cntx->Rate;
    }
    else
    {
        conversion_factor = (1 / g_cconv_cntx->Rate);
    }

    result = (DOUBLE) (conversion_factor * gui_atof((UI_string_type) g_cconv_cntx->LocalBuff));

    precision = CalcComputePrecision(result, CCONV_MAX_RESULT);

    gui_float_string(result, precision, (S8*) g_cconv_cntx->ForeBuff);

    g_cconv_cntx->ClearResultFlag = 1;

#ifdef __MMI_CONVERTER_KEEP_INLINE_FOCUS__
    RedrawCategoryFunction();
#if 0
/* under construction !*/
	#if(UI_DOUBLE_BUFFER_SUPPORT)
/* under construction !*/
	#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
	#if defined(UI_DOUBLE_BUFFER_SUPPORT)
/* under construction !*/
/* under construction !*/
	#endif
#endif /* 0 */ 
#else /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 

    SetHighlightedItem(0);
#endif /* __MMI_CONVERTER_KEEP_INLINE_FOCUS__ */ 

    SetLeftSoftkeyFunction(CconvComputeResult, KEY_EVENT_UP);

}


/*****************************************************************************
 * FUNCTION
 *  CconvPreEntryExchange
 * DESCRIPTION
 *  Pre-entry function for exchange screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void CconvPreEntryExchange(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CloseCategory57Screen();

    g_cconv_cntx->Rate = gui_atof((U16*) g_cconv_cntx->RateBuff /* Currency_Convertor_rate.text */ );

	/* If the rate is ".xxx", it will be treated as wrong input. */
    if (gui_strlen((UI_string_type) g_cconv_cntx->RateBuff) < 1 || g_cconv_cntx->Rate == 0 || g_cconv_cntx->RateBuff[0] == '.')
    {
        DisplayPopup(
            (U8*) GetString(ERROR_CURRENCYCONVERTOR_RATE1),
            IMG_GLOBAL_WARNING,
            0,
            UI_POPUP_NOTIFYDURATION_TIME,
            WARNING_TONE);
        return;
    }
    else
    {
        g_cconv_cntx->CurrSelRate = 0;
        g_cconv_cntx->CurrHiliteItem = 0;

        memset(g_cconv_cntx->LocalBuff, 0, ENCODING_LENGTH);
        memset(g_cconv_cntx->ForeBuff, 0, ENCODING_LENGTH);

        WriteValue(CURRENCY_CONVERTOR_EXCHANGE_RATE, &g_cconv_cntx->Rate, DS_DOUBLE, &error);
        g_cconv_cntx->IsFromHistory = FALSE;
        EntryCConvExchange();
    }
}


/*****************************************************************************
 * FUNCTION
 *  CConvFillInlineStruct
 * DESCRIPTION
 *  Fill inline structure of converting screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void CConvFillInlineStruct(void)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -