📄 calculator.c
字号:
* Redraw calculator screen
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void CalcRedraw(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
gui_lock_double_buffer();
gui_reset_clip();
clear_screen();
clear_category_screen_key_handlers();
clear_left_softkey();
clear_right_softkey();
/* start vijay 20050302 */
#if defined(__MMI_TOUCH_CALCULATOR__)
/* 052405 Calvin added */
/* if ( gui_is_entry_new_screen()==MMI_TRUE ) */
if (gui_is_entry_new_screen() == MMI_TRUE && wgui_is_wallpaper_on_bottom() == MMI_TRUE)
{
gui_set_entry_new_screen(MMI_FALSE);
gdi_layer_multi_layer_enable();
gdi_layer_get_base_handle(&wgui_base_layer);
gui_layer_transparent(
wgui_base_layer,
UI_SUBMENU_OPACITY_BASED_LAYER,
0,
0,
UI_DEVICE_WIDTH - 1,
UI_DEVICE_HEIGHT - 1);
if (wgui_layer_1 == GDI_LAYER_EMPTY_HANDLE)
{
gdi_layer_create(0, 0, UI_DEVICE_WIDTH, UI_DEVICE_HEIGHT, &wgui_layer_1);
}
// TODO: should use draw manager DM_SCR_BG mechanism
gdi_image_abm_set_source_layer(wgui_layer_1);
gdi_layer_set_active(wgui_layer_1);
gdi_layer_lock_frame_buffer();
gdi_layer_push_clip();
gdi_layer_reset_clip();
gdi_layer_set_source_key(TRUE, GDI_COLOR_TRANSPARENT);
gdi_layer_set_opacity(TRUE, 200);
gdi_image_draw(0, 0, get_image(idle_screen_wallpaper_ID));
gdi_layer_pop_clip();
gdi_layer_unlock_frame_buffer();
gdi_layer_restore_base_active();
gdi_layer_set_blt_layer(wgui_layer_1, wgui_base_layer, 0, 0);
gdi_layer_blt_previous(0, 0, UI_DEVICE_WIDTH - 1, UI_DEVICE_HEIGHT - 1);
gdi_layer_set_active(wgui_base_layer);
gdi_draw_solid_rect(0, 0, UI_DEVICE_WIDTH - 1, UI_DEVICE_HEIGHT - 1, GDI_COLOR_TRANSPARENT);
}
else
{
//Leo removed
// gdi_layer_get_base_handle(&wgui_base_layer);
// gui_layer_transparent(wgui_base_layer, UI_SUBMENU_OPACITY_BASED_LAYER, 0, 0, UI_DEVICE_WIDTH-1, UI_DEVICE_HEIGHT-1);
// gdi_layer_set_active(wgui_base_layer);
// gdi_draw_solid_rect(0, 0, UI_DEVICE_WIDTH-1, UI_DEVICE_HEIGHT-1,GDI_COLOR_TRANSPARENT);
}
/* Calvin end */
setup_calculator_keypad(&calculator_keypad, TOUCH_CALC_SCREEN_X, TOUCH_CALC_SCREEN_Y);
MMI_menu_shortcut_number = -1;
/* 053005 Calvin modified */
/* Leo 20050705 start */
show_title_status_icon();
//show_status_icons();
//Leo 20050705 end
/* Calvin end */
ChangeTitleString((U8*) get_string(STR_ID_CALC_MENU));
draw_title();
show_touch_calculator_screen(
TOUCH_CALC_SCREEN_X,
TOUCH_CALC_SCREEN_Y,
TOUCH_CALC_SCREEN_WIDTH,
TOUCH_CALC_SCREEN_HEIGHT);
CalcShowResultScreen();
#else /* defined(__MMI_TOUCH_CALCULATOR__) */
#if defined (__MMI_MAINLCD_176X220__) || defined (__MMI_MAINLCD_240X320__)
MMI_disable_title_shortcut_display = 1;
#ifndef GUI_COMMON_SHOW_STATUS_ICON
move_title(0,0);
#else
show_title_status_icon();
#endif
#ifdef GUI_COMMON_USE_THICK_TITLE
wgui_title_set_thick(MMI_TRUE);
#else
wgui_title_set_thick(MMI_FALSE);
#endif
ChangeTitleString((U8*) get_string(STR_ID_CALC_MENU));
ChangeTitleIcon(GetRootTitleIcon(EXTRA_CALCULATOR_MENU));
draw_title();
#endif /* defined (__MMI_MAINLCD_176X220__) || defined (__MMI_MAINLCD_240X320__) */
CalcShowKeypad();
CalcShowResultScreen();
#endif /* defined(__MMI_TOUCH_CALCULATOR__) */ /* end __MMI_TOUCH_CALCULATOR__ */
/* end vijay */
show_softkey_background();
ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
show_left_softkey();
show_right_softkey();
gui_unlock_double_buffer();
gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
}
/*****************************************************************************
* FUNCTION
* CalcSearchDecimal
* DESCRIPTION
* To search if there is a decimal point in current operand.
* PARAMETERS
* void
* RETURNS
* TRUE if decimal exists; otherwise, FALSE.
*****************************************************************************/
U8 CalcSearchDecimal(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
U8 index;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_calc_cntx->Operand2Len > 1)
{
for (index = 0; index < g_calc_cntx->Operand2Len; index++)
{
if (g_calc_cntx->Operand2Buf[index] == CALC_SYM_DOT)
{
return TRUE;
}
}
}
return FALSE;
}
/*****************************************************************************
* FUNCTION
* CalcInsertChar
* DESCRIPTION
* Insert a character to result screen.
* PARAMETERS
* c [IN]
* RETURNS
* void
*****************************************************************************/
void CalcInsertChar(UI_character_type c)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
g_calc_cntx->ComputeType = CALC_OP_NONE;
/* if operand2 = -(12 digit) || (12 digit) */
if ((g_calc_cntx->Operand2Buf[0] == CALC_SYM_MINUS && g_calc_cntx->Operand2Len >= (CALC_MAX_DIGITS + 2)) ||
(g_calc_cntx->Operand2Buf[0] != CALC_SYM_MINUS && g_calc_cntx->Operand2Len >= (CALC_MAX_DIGITS + 1)))
{
playRequestedTone(ERROR_TONE);
return;
}
if (g_calc_cntx->Operand2Len == CALC_ZEOR_LEN && c == CALC_SYM_ZERO)
{
CalcShowResultScreen();
return;
}
if (g_calc_cntx->Operator == CALC_OP_EQUAL)
{
g_calc_cntx->Operator = CALC_OP_NONE;
g_calc_cntx->Operand1 = 0;
g_calc_cntx->Operand2 = 0;
g_calc_cntx->Operand2Len = 1;
g_calc_cntx->Operand2Buf[0] = CALC_SYM_NULL;
g_calc_cntx->OpToExecute = CALC_OP_NONE;
}
if (c == CALC_SYM_DOT && g_calc_cntx->Operand2Len == CALC_ZEOR_LEN) /* insert "." after zero */
{
g_calc_cntx->Operand2Buf[0] = CALC_SYM_ZERO;
g_calc_cntx->Operand2Len++;
}
g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len - 1] = (UI_character_type) c;
g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len] = CALC_SYM_NULL;
g_calc_cntx->Operand2Len++;
g_calc_cntx->RSKState = CALC_RSK_CLEAR;
CalcShowResultScreen();
}
/*****************************************************************************
* FUNCTION
* CalcExecMR
* DESCRIPTION
* Execute MR operator.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
#ifndef __MMI_SLIM_CALCULATOR__
void CalcExecMR(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
CalcResetResultValue();
CalcDouble2String(g_calc_cntx->MemValue, (S8*) g_calc_cntx->Operand2Buf, CALC_MAX_DIGITS);
g_calc_cntx->Operand2Len = UCS2Strlen((S8*) g_calc_cntx->Operand2Buf) + 1;
/* start vijay 20050616...no need to change the RSK on pressing MR button for touch panel */
#ifndef __MMI_TOUCH_CALCULATOR__
if (g_calc_cntx->Operand2Len > 1)
{
g_calc_cntx->RSKState = CALC_RSK_CLEAR;
}
else
{
g_calc_cntx->RSKState = CALC_RSK_BACK;
}
#endif /* __MMI_TOUCH_CALCULATOR__ */
/* end vijay */
}
/*****************************************************************************
* FUNCTION
* CalcExecMP
* DESCRIPTION
* Execute M+ operator.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void CalcExecMP(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
DOUBLE temp_res;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_calc_cntx->Operand2Buf[0] != CALC_SYM_NULL)
{
temp_res = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
g_calc_cntx->MemValue += temp_res;
if (!mmi_calc_check_boundary(g_calc_cntx->MemValue))
{
g_calc_cntx->ResultState = RESULT_EXCEED;
playRequestedTone(ERROR_TONE);
g_calc_cntx->MemValue = 0;
}
}
}
/*****************************************************************************
* FUNCTION
* CalcExecMM
* DESCRIPTION
* Execute M- operator.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void CalcExecMM(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
DOUBLE temp_res;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_calc_cntx->Operand2Buf[0] != CALC_SYM_NULL)
{
temp_res = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
g_calc_cntx->MemValue -= temp_res;
if (!mmi_calc_check_boundary(g_calc_cntx->MemValue))
{
g_calc_cntx->ResultState = RESULT_EXCEED;
playRequestedTone(ERROR_TONE);
g_calc_cntx->MemValue = 0;
}
}
}
#endif /* __MMI_SLIM_CALCULATOR__ */
/*****************************************************************************
* FUNCTION
* CalcGetCurrOperand
* DESCRIPTION
* Convert the string of operand 1 to number
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void CalcGetCurrOperand(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_NULL)
{
g_calc_cntx->Operand1 = 0;
}
else
{
g_calc_cntx->Operand1 = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
/* 06/01/11, for bug of displaying "-0" */
if (g_calc_cntx->Operand1 == -0)
{
g_calc_cntx->Operand1 = 0;
}
}
}
/*****************************************************************************
* FUNCTION
* CalcGetPreOperand
* DESCRIPTION
* Convert the string of operand 2 to number
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void CalcGetPreOperand(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_NULL)
{
g_calc_cntx->Operand2 = 0;
}
else
{
g_calc_cntx->Operand2 = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
}
}
/*****************************************************************************
* FUNCTION
* mmi_calc_check_boundary
* DESCRIPTION
* Check the boundary of the calculated result.
* PARAMETERS
* value [IN] Value to be checked
* RETURNS
* 0 out of the boundary
* 1 within the boundary
*****************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -