📄 unitconvertor.c
字号:
g_uconv_cntx->CurrHiliteUnitType = UCONV_WEIGHT;
SetLeftSoftkeyFunction(UConvGoToComputeScreen, KEY_EVENT_UP);
SetKeyHandler(UConvGoToComputeScreen, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
}
/*****************************************************************************
* FUNCTION
* UConvFillInlineStruct
* DESCRIPTION
* Fill inline structure of inline items in Length convertor
* PARAMETERS
* void
* UnitType(?) [IN] Type of unit 0 == length, 1 == weight
* RETURNS
* void
*****************************************************************************/
void UConvFillInlineStruct(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
UI_character_type *Caption1, *Caption2;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
DisableInlineInputMethodHints();
if (g_uconv_cntx->CurrHiliteUnitType == UCONV_LENGTH) /* length */
{
g_uconv_cntx->UnitList[0] = GetString(STR_UNITCONVERTOR_KMMILE);
g_uconv_cntx->UnitList[1] = GetString(STR_UNITCONVERTOR_MYARD);
g_uconv_cntx->UnitList[2] = GetString(STR_UNITCONVERTOR_MFOOT);
g_uconv_cntx->UnitList[3] = GetString(STR_UNITCONVERTOR_CMINCH);
/* caption strings */
Caption2 =
(UI_character_type*) (GetString((U16) (STR_UNITCONVERTOR_MILE + g_uconv_cntx->CurrInlineSelectUnit)));
switch (g_uconv_cntx->CurrInlineSelectUnit)
{
case 0:
Caption1 = (UI_character_type*) (GetString(STR_UNITCONVERTOR_KM));
break;
case 3:
Caption1 = (UI_character_type*) (GetString(STR_UNITCONVERTOR_CM));
break;
default:
Caption1 = (UI_character_type*) (GetString(STR_UNITCONVERTOR_METER));
break;
}
/* units */
SetInlineItemSelect(
&wgui_inline_items[UCONV_UNIT],
4,
(U8 **) g_uconv_cntx->UnitList,
&g_uconv_cntx->CurrInlineSelectUnit);
RegisterInlineSelectHighlightHandler(&wgui_inline_items[UCONV_UNIT], HighlightUConvInlineLenghSelect);
}
else /* weight */
{
g_uconv_cntx->UnitList[0] = GetString(STR_UNITCONVERTOR_KGPOUND);
Caption1 = (UI_character_type*) (GetString(STR_UNITCONVERTOR_KG));
g_uconv_cntx->UnitList[1] = GetString(STR_UCONV_KGOUNCE);
if (g_uconv_cntx->CurrInlineSelectUnit == 0) /* kg <-> pound */
{
Caption2 = (UI_character_type*) (GetString(STR_UNITCONVERTOR_POUND));
}
else /* Kg <-> Ounce */
{
Caption2 = (UI_character_type*) (GetString(STR_UCONV_OUNCE));
}
/* unit */
SetInlineItemSelect(
&wgui_inline_items[UCONV_UNIT],
2,
(U8 **) g_uconv_cntx->UnitList,
&g_uconv_cntx->CurrInlineSelectUnit);
RegisterInlineSelectHighlightHandler(&wgui_inline_items[UCONV_UNIT], HighlightUConvInlineWeightSelect);
}
SetInlineItemActivation(&wgui_inline_items[UCONV_UNIT], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
/* metric caption */
SetInlineItemActivation(&wgui_inline_items[UCONV_METRIC_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
SetInlineItemCaption(&wgui_inline_items[UCONV_METRIC_CAP], (U8*) Caption1);
/* metric unit */
SetInlineItemActivation(&wgui_inline_items[UCONV_METIRC], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
SetInlineItemTextEdit(
&wgui_inline_items[UCONV_METIRC],
(U8*) g_uconv_cntx->MetricBuf,
(UCONV_MAX_INPUT + 1),
INPUT_TYPE_DECIMAL_NUMERIC);
EnableInlineItemBoundary(&wgui_inline_items[UCONV_METIRC]);
RightJustifyInlineItem(&wgui_inline_items[UCONV_METIRC]);
SetInlineTextEditCustomFunction(&wgui_inline_items[UCONV_METIRC], UConvCustomInlineFunction);
/* English caption */
SetInlineItemActivation(&wgui_inline_items[UCONV_ENG_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
SetInlineItemCaption(&wgui_inline_items[UCONV_ENG_CAP], (U8*) Caption2);
/* English unit */
SetInlineItemActivation(&wgui_inline_items[UCONV_ENG], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
SetInlineItemTextEdit(
&wgui_inline_items[UCONV_ENG],
(U8*) g_uconv_cntx->EngBuf,
(UCONV_MAX_INPUT + 1),
INPUT_TYPE_DECIMAL_NUMERIC);
EnableInlineItemBoundary(&wgui_inline_items[UCONV_ENG]);
RightJustifyInlineItem(&wgui_inline_items[UCONV_ENG]);
SetInlineTextEditCustomFunction(&wgui_inline_items[UCONV_ENG], UConvCustomInlineFunction);
}
/*****************************************************************************
* FUNCTION
* ComputeLengthResult
* DESCRIPTION
* To calculate the result of length conversion
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void ComputeLengthResult(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
DOUBLE conversion_factor;
S32 precision = 0; /* ,temp_int = 0; */
DOUBLE result;
UI_character_type *ResultBuf = NULL, *SourceBuf = NULL;
S32 len;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
CloseCategory57Screen();
/* conversion rate */
switch (g_uconv_cntx->CurrInlineSelectUnit)
{
case 0:
conversion_factor = KM2MILE; /* 0.62137 */
break;
case 1:
conversion_factor = M2YARD; /* 1.09361 */
break;
case 2:
conversion_factor = M2FOOT; /* 3.28084 */
break;
default: /* case 3: */
conversion_factor = CM2INCH; /* 0.3937 */
break;
}
if (g_uconv_cntx->CurrSelectedItem == UCONV_METIRC)
{
SourceBuf = g_uconv_cntx->MetricBuf;
ResultBuf = g_uconv_cntx->EngBuf;
}
else
{
SourceBuf = g_uconv_cntx->EngBuf;
ResultBuf = g_uconv_cntx->MetricBuf;
conversion_factor = 1 / conversion_factor;
}
len = gui_strlen((UI_string_type) SourceBuf);
if ((len == 0) || ((len == 1) && (SourceBuf[0] == 46)))
{
DisplayPopup(
(U8*) GetString(UC_ERROR_EMPTY_STRING),
IMG_GLOBAL_WARNING,
0,
UI_POPUP_NOTIFYDURATION_TIME,
WARNING_TONE);
return;
}
g_uconv_cntx->ClearResultFlag = TRUE;
result = (DOUBLE) (conversion_factor * gui_atof(SourceBuf));
precision = CalcComputePrecision(result, (S16) UCONV_MAX_RESULT);
gui_float_string(result, precision, (S8*) ResultBuf);
UConvRedrawResult();
SetLeftSoftkeyFunction(ComputeLengthResult, KEY_EVENT_UP);
}
/*****************************************************************************
* FUNCTION
* ComputeWeightResult
* DESCRIPTION
* To calculate the result of weight conversion
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void ComputeWeightResult(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
DOUBLE result = 0;
S32 prec_val = 0;
DOUBLE conversion_factor = 0;
UI_character_type *ResultBuf = NULL, *SourceBuf = NULL;
S32 len;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
CloseCategory57Screen();
/* determine rate */
if (g_uconv_cntx->CurrInlineSelectUnit == 0) /* Kg to Pound */
{
conversion_factor = KG2POUND;
}
else
{
conversion_factor = KG2OUNCE;
}
/* determine conversion direction */
if (g_uconv_cntx->CurrSelectedItem == UCONV_METIRC)
{
SourceBuf = g_uconv_cntx->MetricBuf;
ResultBuf = g_uconv_cntx->EngBuf;
}
else /* UCONV_ENGLISH */
{
SourceBuf = g_uconv_cntx->EngBuf;
ResultBuf = g_uconv_cntx->MetricBuf;
conversion_factor = 1 / conversion_factor;
}
len = gui_strlen((UI_string_type) SourceBuf);
if ((len == 0) || ((len == 1) && (ResultBuf[0] == 46)))
{
DisplayPopup(
(U8*) GetString(UC_ERROR_EMPTY_STRING),
IMG_GLOBAL_WARNING,
0,
UI_POPUP_NOTIFYDURATION_TIME,
WARNING_TONE);
return;
}
g_uconv_cntx->ClearResultFlag = TRUE;
result = (DOUBLE) (conversion_factor * gui_atof(SourceBuf));
prec_val = CalcComputePrecision(result, UCONV_MAX_RESULT);
gui_float_string(result, prec_val, (S8*) ResultBuf);
UConvRedrawResult();
SetLeftSoftkeyFunction(ComputeWeightResult, KEY_EVENT_UP);
}
/*****************************************************************************
* FUNCTION
* UConvGoToComputeScreen
* DESCRIPTION
* Intialize state variables and enter weight convertor
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void UConvGoToComputeScreen(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
g_uconv_cntx->CurrInlineSelectUnit = 0;
g_uconv_cntx->CurrSelectedItem = 0;
memset(g_uconv_cntx->EngBuf, 0, 2);
memset(g_uconv_cntx->MetricBuf, 0, 2);
EntryUConvCompute();
}
/*****************************************************************************
* FUNCTION
* ExitUConvCompute
* DESCRIPTION
* Exit function of conterting screen
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void ExitUConvCompute(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
history HistoryUCWeight;
U16 inputBufferSize; /* added for inline edit history */
S16 nHistory = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
set_leading_zero(TRUE);
if (g_uconv_cntx)
{
CloseCategory57Screen();
HistoryUCWeight.scrnID = SCR_ID_UCONV_WEIGHT + g_uconv_cntx->CurrHiliteUnitType;
}
HistoryUCWeight.entryFuncPtr = EntryUConvCompute;
GetCategory57History(HistoryUCWeight.guiBuffer);
UCS2Strcpy((S8*) HistoryUCWeight.inputBuffer, (S8*) & nHistory);
inputBufferSize = (U16) GetCategory57DataSize(); /* added for inline edit history */
GetCategory57Data((U8*) HistoryUCWeight.inputBuffer); /* added for inline edit history */
AddNHistory(HistoryUCWeight, inputBufferSize); /* added for inline edit history */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -