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

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * Calculator.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements Calculator application.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  *
  108.  * removed!
  109.  * removed!
  110.  * removed!
  111.  *
  112.  * removed!
  113.  * removed!
  114.  * removed!
  115.  *
  116.  * removed!
  117.  * removed!
  118.  * removed!
  119.  *
  120.  * removed!
  121.  * removed!
  122.  * removed!
  123.  *
  124.  * removed!
  125.  * removed!
  126.  * removed!
  127.  *
  128.  * removed!
  129.  * removed!
  130.  * removed!
  131.  *
  132.  * removed!
  133.  * removed!
  134.  * removed!
  135.  *
  136.  * removed!
  137.  * removed!
  138.  * removed!
  139.  *
  140.  * removed!
  141.  * removed!
  142.  * removed!
  143.  *
  144.  * removed!
  145.  * removed!
  146.  * removed!
  147.  *
  148.  * removed!
  149.  * removed!
  150.  * removed!
  151.  *
  152.  * removed!
  153.  * removed!
  154.  * removed!
  155.  *
  156.  * removed!
  157.  * removed!
  158.  * removed!
  159.  *
  160.  * removed!
  161.  * removed!
  162.  * removed!
  163.  *
  164.  * removed!
  165.  * removed!
  166.  * removed!
  167.  *
  168.  * removed!
  169.  * removed!
  170.  * removed!
  171.  *
  172.  * removed!
  173.  * removed!
  174.  * removed!
  175.  *
  176.  * removed!
  177.  * removed!
  178.  * removed!
  179.  *
  180.  * removed!
  181.  * removed!
  182.  * removed!
  183.  *
  184.  * removed!
  185.  * removed!
  186.  * removed!
  187.  *
  188.  * removed!
  189.  * removed!
  190.  * removed!
  191.  *
  192.  * removed!
  193.  * removed!
  194.  * removed!
  195.  *
  196.  * removed!
  197.  * removed!
  198.  * removed!
  199.  *
  200.   * Dec 11 2005 mtk01215
  201.  * removed!
  202.  * removed!
  203.  *
  204.  * removed!
  205.  * removed!
  206.  * removed!
  207.  *
  208.  * removed!
  209.  * removed!
  210.  * removed!
  211.  * removed!
  212.  *
  213.  * removed!
  214.  * removed!
  215.  * removed!
  216.  *
  217.  * removed!
  218.  * removed!
  219.  * removed!
  220.  *
  221.  * removed!
  222.  * removed!
  223.  * removed!
  224.  *
  225.  * removed!
  226.  * removed!
  227.  * removed!
  228.  *
  229.  * removed!
  230.  * removed!
  231.  * removed!
  232.  *
  233.  * removed!
  234.  * removed!
  235.  * removed!
  236.  *
  237.  * removed!
  238.  * removed!
  239.  * removed!
  240.  *
  241.  *------------------------------------------------------------------------------
  242.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  243.  *============================================================================
  244.  ****************************************************************************/
  245.  /**
  246.  * Copyright Notice
  247.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  248.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  249.  *  (It is illegal to remove this copyright notice from this software or any
  250.  *  portion of it)
  251.  */
  252. /**********************************************************************************
  253.    Filename:      Calculator.c
  254.    Author:        manju
  255.    Date Created:  June-21-2003
  256.    Contains:      Calculator
  257. **********************************************************************************/
  258. #ifndef _MMI_CALCULATOR_C
  259. #define _MMI_CALCULATOR_C
  260. #include "MMI_features.h"
  261. #include "PixtelDataTypes.h"
  262. #include "Unicodexdcl.h"
  263. #ifdef __MMI_TOUCH_CALCULATOR__
  264. /* start vijay 20050301 foe calculator */
  265. #include "gdi_include.h"
  266. #include "wgui.h"
  267. /* end vijay */
  268. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  269. #include "gui.h"
  270. #include "Calculator.h"
  271. #include "SettingProfile.h"
  272. #include "ProfileGprots.h"
  273. #ifdef __MMI_CALCULATOR__
  274. #include "Globaldefs.h"
  275. #include "CustDataRes.h"
  276. #include "gui_themes.h"
  277. #include "wgui_categories.h"
  278. #include "wgui_softkeys.h"
  279. #include "HistoryGprot.h"
  280. #include "OrganizerDef.h"
  281. #endif /* __MMI_CALCULATOR__ */ 
  282. /* MTK Elvis for R2L characters */
  283. extern BOOL r2lMMIFlag;
  284. /* MTK end */
  285. /* 
  286.  * Define
  287.  */
  288. /* Images for the calculator: Currently hardcoded */
  289. #define CALC_MAX_DIGITS          12
  290. #define CALC_MAX_BUFF_LEN        30
  291. #ifdef __MMI_CALCULATOR__
  292. #define CALC_NUM_BUTTONS         9
  293. #define CALC_SCR_X               0
  294. #define CALC_SCR_WIDTH           UI_device_width
  295. #define CALC_SCR_HEIGHT          (CALC_NUM_HEIGHT * 3 + 1)
  296. #if defined (__MMI_MAINLCD_128X128__) || defined (__MMI_MAINLCD_128X160__)
  297. #if defined (__MMI_MAINLCD_128X128__)
  298. #define CALC_NUM_HEIGHT 13
  299. #define CALC_KEYPAD_Y (CALC_NUM_HEIGHT * 3 + 2)
  300. #else
  301. #define CALC_NUM_HEIGHT 15
  302. #define CALC_KEYPAD_Y (CALC_NUM_HEIGHT * 3 + 15)
  303. #endif
  304. #ifdef __MMI_SLIM_CALCULATOR__
  305. #define CALC_KEYPAD_X            19
  306. #else 
  307. #define CALC_KEYPAD_X            21
  308. #endif 
  309. #define CALC_SCR_Y               0
  310. #else /* defined (__MMI_MAINLCD_128X128__) || defined (__MMI_MAINLCD_128X160__) */ 
  311. #if defined (__MMI_MAINLCD_176X220__)
  312. #define CALC_NUM_HEIGHT 15
  313. #define MAP_IMG_WIDTH 176
  314. #else /* defined (__MMI_MAINLCD_176X220__) */ 
  315. #define MAP_IMG_WIDTH   240
  316. #define CALC_NUM_HEIGHT 22
  317. #endif /* defined (__MMI_MAINLCD_176X220__) */ 
  318. #define CALC_KEYPAD_Y            (CALC_SCR_Y + CALC_NUM_HEIGHT * 3 + 15)
  319. #define CALC_KEYPAD_X            ((CALC_SCR_WIDTH - MAP_IMG_WIDTH)/2)   /* 0 */
  320. #define CALC_SCR_Y               0 + MMI_status_bar_height + MMI_TITLE_HEIGHT
  321. #endif /* defined (__MMI_MAINLCD_128X128__) || defined (__MMI_MAINLCD_128X160__) */ 
  322. #define CALC_OPERAND1_Y          (CALC_SCR_Y + CALC_NUM_HEIGHT)
  323. #define CALC_OPERAND2_Y          (CALC_SCR_Y + CALC_NUM_HEIGHT * 2)
  324. #define CALC_KEYPAD_WIDTH        86
  325. #define CALC_KEYPAD_HEIGHT       63
  326. #define CALC_OPERATOR_X          5
  327. #define CALC_OPERATOR_Y          CALC_OPERAND2_Y
  328. #define CALC_MEM_X1              2
  329. #define CALC_MEM_Y1              CALC_SCR_Y+1
  330. #define CALC_MEM_X2              CALC_SCR_WIDTH - 2
  331. #define CALC_MEM_Y2              CALC_OPERAND1_Y - 1
  332. #define RESULT_NOT_EXCEED        0
  333. #define RESULT_EXCEED            1
  334. #define CALC_RSK_BACK            0
  335. #define CALC_RSK_CLEAR           1
  336. #define CALC_ZEOR_LEN            1
  337. #define CALC_ZEOR_DOT_LEN           3
  338. #define CALC_SYM_ERROR     (UI_character_type)'E'
  339. #define CALC_SYM_EQUAL     (UI_character_type)'='
  340. #define CALC_SYM_PLUS      (UI_character_type)'+'
  341. #define CALC_SYM_MINUS     (UI_character_type)'-'
  342. #define CALC_SYM_MUL    (UI_character_type)'x'
  343. #define CALC_SYM_DIV    (UI_character_type)'/'
  344. #define CALC_SYM_DOT    (UI_character_type)'.'
  345. #define CALC_SYM_ZERO      (UI_character_type)'0'
  346. #define CALC_SYM_NULL      (UI_character_type)''
  347. #define CALC_RESERVED_SPACE_FOR_OPERATOR     20
  348. /* 
  349.  * Typedef 
  350.  */
  351. typedef struct
  352. {
  353.     S32 x;
  354.     S32 y;
  355.     PU8 image;
  356. } calc_img_struct;
  357. typedef struct
  358. {
  359.     DOUBLE Operand1;
  360.     DOUBLE Operand2;
  361. #ifndef __MMI_SLIM_CALCULATOR__
  362.     DOUBLE MemValue;
  363. #endif 
  364.     calc_img_struct OperatorImg[CALC_NUM_BUTTONS];
  365.     UI_character_type Operand1Buf[CALC_MAX_DIGITS + 2];
  366.     UI_character_type Operand2Buf[CALC_MAX_DIGITS + 2];
  367.     U8 Operand1Len;
  368.     U8 Operand2Len;
  369.     U8 Operator;
  370.     U8 CurrHilite;
  371.     U8 ResultState;
  372.     U8 RSKState;
  373.     U8 ExecFlag;    /* if just after execution */
  374.     U8 OpToExecute; /* operator to execute */
  375.     U8 IsRSKPress;
  376.     U8 ComputeType;
  377. } calc_context_struct;
  378. typedef enum
  379. {
  380.     CALC_OP_PLUS = 0,
  381.     CALC_OP_MINUS,
  382.     CALC_OP_MULT,
  383.     CALC_OP_DIV,
  384.     CALC_OP_EQUAL,
  385. #ifndef __MMI_SLIM_CALCULATOR__
  386.     CALC_OP_MP,
  387.     CALC_OP_MM,
  388.     CALC_OP_MC,
  389.     CALC_OP_MR,
  390. #endif /* __MMI_SLIM_CALCULATOR__ */ 
  391.     CALC_OP_NONE
  392. } CALC_OPER_ENUM;
  393. #ifdef __MMI_TOUCH_CALCULATOR__
  394. typedef enum
  395. {
  396.     TOUCH_CALC_KEY0 = 0,
  397.     TOUCH_CALC_KEY1,
  398.     TOUCH_CALC_KEY2,
  399.     TOUCH_CALC_KEY3,
  400.     TOUCH_CALC_KEY4,
  401.     TOUCH_CALC_KEY5,
  402.     TOUCH_CALC_KEY6,
  403.     TOUCH_CALC_KEY7,
  404.     TOUCH_CALC_KEY8,
  405.     TOUCH_CALC_KEY9,
  406.     TOUCH_CALC_KEY_DOT = 20 /* pound key or hash key */
  407. } TOUCH_CALC_NUM_KEY_ENUM;
  408. typedef enum
  409. {
  410.     TOUCH_CALC_OP_PLUS = CALC_OP_PLUS,
  411.     TOUCH_CALC_OP_MINUS = CALC_OP_MINUS,
  412.     TOUCH_CALC_OP_MULT = CALC_OP_MULT,
  413.     TOUCH_CALC_OP_DIV = CALC_OP_DIV,
  414.     TOUCH_CALC_OP_MP = CALC_OP_MP,
  415.     TOUCH_CALC_OP_MM = CALC_OP_MM,
  416.     TOUCH_CALC_OP_MC = CALC_OP_MC,
  417.     TOUCH_CALC_OP_MR = CALC_OP_MR,
  418.     TOUCH_CALC_OP_EQUAL = CALC_OP_EQUAL
  419. } TOUCH_CALC_SYM_KEY_ENUM;
  420. typedef enum
  421. {
  422.     TOUCH_CALC_PEN_NONE,
  423.     TOUCH_CALC_PEN_LSK,
  424.     TOUCH_CALC_PEN_RSK,
  425.     TOUCH_CALC_PEN_NUM_KEY
  426. } touch_calc_pen_state_enum;
  427. const S32 TouchCalcKeys[CALC_TOUCH_NROWS][CALC_TOUCH_NCOLUMNS] = 
  428. {
  429.     {TOUCH_CALC_OP_MP, TOUCH_CALC_OP_MM, TOUCH_CALC_OP_MR, TOUCH_CALC_OP_MC},
  430.     {TOUCH_CALC_KEY7, TOUCH_CALC_KEY8, TOUCH_CALC_KEY9, TOUCH_CALC_OP_DIV},
  431.     {TOUCH_CALC_KEY4, TOUCH_CALC_KEY5, TOUCH_CALC_KEY6, TOUCH_CALC_OP_MULT},
  432.     {TOUCH_CALC_KEY1, TOUCH_CALC_KEY2, TOUCH_CALC_KEY3, TOUCH_CALC_OP_MINUS},
  433.     {TOUCH_CALC_KEY0, TOUCH_CALC_KEY_DOT, TOUCH_CALC_OP_EQUAL, TOUCH_CALC_OP_PLUS}
  434. };
  435. const MMI_ID_TYPE calculator_key_image[] = 
  436. {
  437.     IMG_ID_TOUCH_CALC_MP,
  438.     IMG_ID_TOUCH_CALC_MM,
  439.     IMG_ID_TOUCH_CALC_MR,
  440.     IMG_ID_TOUCH_CALC_MC,
  441.     IMG_ID_TOUCH_CALC_KEY7,
  442.     IMG_ID_TOUCH_CALC_KEY8,
  443.     IMG_ID_TOUCH_CALC_KEY9,
  444.     IMG_ID_TOUCH_CALC_DIVIDE,
  445.     IMG_ID_TOUCH_CALC_KEY4,
  446.     IMG_ID_TOUCH_CALC_KEY5,
  447.     IMG_ID_TOUCH_CALC_KEY6,
  448.     IMG_ID_TOUCH_CALC_MULTIPLY,
  449.     IMG_ID_TOUCH_CALC_KEY1,
  450.     IMG_ID_TOUCH_CALC_KEY2,
  451.     IMG_ID_TOUCH_CALC_KEY3,
  452.     IMG_ID_TOUCH_CALC_MINUS,
  453.     IMG_ID_TOUCH_CALC_KEY0,
  454.     IMG_ID_TOUCH_CALC_KEY_DOT,
  455.     IMG_ID_TOUCH_CALC_KEY_EQUAL,
  456.     IMG_ID_TOUCH_CALC_PLUS
  457. };
  458. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  459. /* 
  460.  * Local Variable
  461.  */
  462. const color gCalcResultScrColor = {255, 234, 182, 100};
  463. const color gCalcResultBorderColor = {255, 186, 64, 100};
  464. const color gCalcTextColor = {0, 0, 0, 100};
  465. #ifdef __MMI_TOUCH_CALCULATOR__
  466. /* start vijay 20050305 */
  467. const color gTouchCalcResultScrColor = {209, 232, 254, 100};
  468. /* end vijay */
  469. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  470. extern const U8 gCalcImgCoor[][2];
  471. extern U8 matrix_main_menu_highlight_bitmap_data[]; /* 041205 Calvin added image cache buffer for calculator */
  472. /* 
  473.  * Local Function
  474.  */
  475. #ifdef __MMI_TOUCH_CALCULATOR__
  476. void mmi_touchcalc_pen_down_hdlr(mmi_pen_point_struct point);
  477. void mmi_touchcalc_pen_up_hdlr(mmi_pen_point_struct point);
  478. void mmi_touchcalc_pen_move_hdlr(mmi_pen_point_struct point);
  479. void mmi_touchcalc_pen_repeat_hdlr(mmi_pen_point_struct point);
  480. void mmi_touchcalc_pen_long_tap_hdlr(mmi_pen_point_struct point);
  481. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  482. U8 mmi_calc_del_scr_callback(void *p);
  483. /* 
  484.  * Global Variable
  485.  */
  486. calc_context_struct *g_calc_cntx = NULL;
  487. #ifdef __MMI_TOUCH_CALCULATOR__
  488. calculator_keypad_struct calculator_keypad;
  489. touch_calc_pen_state_enum calc_pen_on_object = TOUCH_CALC_PEN_NONE;
  490. #define CALC_PEN_DOWN_ON_KEYPAD     0x0001
  491. BOOL TOUCH_CALC_SELECT_KEY = TRUE;
  492. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  493. /* 
  494.  * Global Function
  495.  */
  496. /* Button co-ordinates for the on screen calculator keypad */
  497. #endif /* __MMI_CALCULATOR__ */ 
  498. #define CALC_UTILITY
  499. /*****************************************************************************
  500.  * FUNCTION
  501.  *  CalcDouble2String
  502.  * DESCRIPTION
  503.  *  
  504.  * PARAMETERS
  505.  *  num         [IN]        
  506.  *  result      [?]         
  507.  *  digits      [IN]        
  508.  * RETURNS
  509.  *  void
  510.  *****************************************************************************/
  511. void CalcDouble2String(DOUBLE num, S8 *result, U8 digits)
  512. {
  513.     /*----------------------------------------------------------------*/
  514.     /* Local Variables                                                */
  515.     /*----------------------------------------------------------------*/
  516.     S32 precision;
  517.     /*----------------------------------------------------------------*/
  518.     /* Code Body                                                      */
  519.     /*----------------------------------------------------------------*/
  520.     precision = CalcComputePrecision(num, digits);
  521.     gui_float_string(num, precision, result);
  522. }
  523. /*****************************************************************************
  524.  * FUNCTION
  525.  *  gui_atof
  526.  * DESCRIPTION
  527.  *  Convert string to float
  528.  * PARAMETERS
  529.  *  s       [IN]        String to be converted
  530.  * RETURNS
  531.  *  float value of the string
  532.  *****************************************************************************/
  533. DOUBLE gui_atof(UI_string_type s)
  534. {
  535.     /*----------------------------------------------------------------*/
  536.     /* Local Variables                                                */
  537.     /*----------------------------------------------------------------*/
  538.     S8 ansii_str[CALC_MAX_BUFF_LEN];
  539.     /*----------------------------------------------------------------*/
  540.     /* Code Body                                                      */
  541.     /*----------------------------------------------------------------*/
  542.     UnicodeToAnsii((S8*) ansii_str, (S8*) s);
  543.     return atof(ansii_str);
  544. }
  545. /*****************************************************************************
  546.  * FUNCTION
  547.  *  gui_float_string
  548.  * DESCRIPTION
  549.  *  Convert float to string
  550.  * PARAMETERS
  551.  *  dob_val         [IN]            Value to be converted.
  552.  *  prec_val        [IN]            Number of precision.
  553.  *  out_buffer      [IN/OUT]        Pointer to the result string
  554.  * RETURNS
  555.  *  void
  556.  *****************************************************************************/
  557. void gui_float_string(DOUBLE dob_val, S32 prec_val, S8 *out_buffer)
  558. {
  559.     /*----------------------------------------------------------------*/
  560.     /* Local Variables                                                */
  561.     /*----------------------------------------------------------------*/
  562.     S8 ansii_str[CALC_MAX_BUFF_LEN];
  563.     S8 fmt[8];
  564.     U8 i;
  565.     /*----------------------------------------------------------------*/
  566.     /* Code Body                                                      */
  567.     /*----------------------------------------------------------------*/
  568.     memset(ansii_str, 0, CALC_MAX_BUFF_LEN);
  569.     memset(fmt, 0, 8);
  570.     sprintf(fmt, "%%.%df", prec_val);
  571.     sprintf(ansii_str, fmt, dob_val);
  572.     /* to prevent 123.250000 */
  573.     if (prec_val > 0)
  574.     {
  575.         for (i = CALC_MAX_BUFF_LEN - 1; i != 0; i--)
  576.         {
  577.             if (ansii_str[i] == 0)
  578.             {
  579.                 continue;
  580.             }
  581.             else if (ansii_str[i] == '0')
  582.             {
  583.                 ansii_str[i] = 0;
  584.             }
  585.             else
  586.             {
  587.                 break;
  588.             }
  589.         }
  590.     }
  591.     /* to prevent -0 */
  592.     if (strlen(ansii_str) == 2 && ansii_str[0] == '-' && ansii_str[1] == '0')
  593.     {
  594.         ansii_str[0] = '0';
  595.         ansii_str[1] = 0;
  596.     }
  597.     AnsiiToUnicodeString(out_buffer, ansii_str);
  598. }
  599. /*****************************************************************************
  600.  * FUNCTION
  601.  *  CalcComputePrecision
  602.  * DESCRIPTION
  603.  *  To retrive the length of precision part of a given number.
  604.  * PARAMETERS
  605.  *  result          [IN]        The number to be computed.
  606.  *  max_digits      [IN]        Maximum digits of the number
  607.  * RETURNS
  608.  *  void
  609.  *****************************************************************************/
  610. S32 CalcComputePrecision(DOUBLE result, S16 max_digits)
  611. {
  612.     /*----------------------------------------------------------------*/
  613.     /* Local Variables                                                */
  614.     /*----------------------------------------------------------------*/
  615.     S32 prec_val = 0;
  616.     U8 str[CALC_MAX_BUFF_LEN];
  617.     S8 fmt[8];
  618.     S8 decimal_length = 0;
  619.     /*----------------------------------------------------------------*/
  620.     /* Code Body                                                      */
  621.     /*----------------------------------------------------------------*/
  622.     if (result < 0)
  623.     {
  624.         result = -(result);
  625.     }
  626.     /*
  627.      * str[]        = x.xxxxxxxxxxxe+/-xxx
  628.      * ex: 0.0000000001 = 1.00000000000e-010
  629.      * 646464646464 = 6.46464646464e+011
  630.      */
  631.     memset(fmt, 0, 8);
  632.     sprintf(fmt, "%%%d.%de", max_digits, (max_digits - 2));
  633.     memset(str, '', CALC_MAX_BUFF_LEN);
  634.     sprintf((S8*) str, fmt, result);
  635.     if (str[max_digits] == 'e')
  636.     {
  637.         S32 j;
  638.         memset(fmt, 0, 8);
  639.         memcpy(fmt, str + (max_digits + 2), 3);
  640.         prec_val = atoi(fmt);
  641.         /* Out of boundary */
  642.         if (prec_val >= max_digits - 1)
  643.         {
  644.             return 0;
  645.         }
  646.         if (str[max_digits + 1] == '-')
  647.         {
  648.             j = (max_digits - 1) - prec_val;
  649.         }
  650.         else
  651.         {
  652.             j = max_digits - 1;
  653.         }
  654.         for (; j > 1; j--)
  655.         {
  656.             if (str[j] != '0')
  657.             {
  658.                 decimal_length = (j - 1);
  659.                 break;
  660.             }
  661.         }
  662.         /* |result| < 1 */
  663.         if (str[max_digits + 1] == '-')
  664.         {
  665.             prec_val += decimal_length;
  666.         }
  667.         /* |result| >= 1 */
  668.         else if (str[max_digits + 1] == '+')
  669.         {
  670.             if (decimal_length > prec_val)
  671.             {
  672.                 prec_val = decimal_length - prec_val;
  673.             }
  674.             else
  675.             {
  676.                 prec_val = 0;
  677.             }
  678.         }
  679.     }
  680.     return prec_val;
  681. }
  682. #ifdef __MMI_CALCULATOR__
  683. #define CALC_INITIALIZE
  684. /*****************************************************************************
  685.  * FUNCTION
  686.  *  HighlightCalcMenu
  687.  * DESCRIPTION
  688.  *  Highlight handler of Calculator menu item.
  689.  *  Register key handlers.
  690.  * PARAMETERS
  691.  *  void
  692.  * RETURNS
  693.  *  void
  694.  *****************************************************************************/
  695. void HighlightCalcMenu(void)
  696. {
  697.     /*----------------------------------------------------------------*/
  698.     /* Local Variables                                                */
  699.     /*----------------------------------------------------------------*/
  700.     /*----------------------------------------------------------------*/
  701.     /* Code Body                                                      */
  702.     /*----------------------------------------------------------------*/
  703.     SetLeftSoftkeyFunction(CalcPreEntryApp, KEY_EVENT_UP);
  704.     SetKeyHandler(CalcPreEntryApp, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  705.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  706.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  707. }
  708. /*****************************************************************************
  709.  * FUNCTION
  710.  *  CalcInit
  711.  * DESCRIPTION
  712.  *  Initialize highlight handler and global vairables.
  713.  * PARAMETERS
  714.  *  void
  715.  * RETURNS
  716.  *  void
  717.  *****************************************************************************/
  718. void CalcInit(void)
  719. {
  720.     /*----------------------------------------------------------------*/
  721.     /* Local Variables                                                */
  722.     /*----------------------------------------------------------------*/
  723.     /*----------------------------------------------------------------*/
  724.     /* Code Body                                                      */
  725.     /*----------------------------------------------------------------*/
  726.     SetHiliteHandler(EXTRA_CALCULATOR_MENU, HighlightCalcMenu);
  727. }
  728. /*****************************************************************************
  729.  * FUNCTION
  730.  *  CalcDeInit
  731.  * DESCRIPTION
  732.  *  Free dynamic memory.
  733.  * PARAMETERS
  734.  *  void
  735.  * RETURNS
  736.  *  void
  737.  *****************************************************************************/
  738. void CalcDeInit(void)
  739. {
  740.     /*----------------------------------------------------------------*/
  741.     /* Local Variables                                                */
  742.     /*----------------------------------------------------------------*/
  743.     /*----------------------------------------------------------------*/
  744.     /* Code Body                                                      */
  745.     /*----------------------------------------------------------------*/
  746.     if (g_calc_cntx)
  747.     {
  748.         OslMfree(g_calc_cntx);
  749.         g_calc_cntx = NULL;
  750.     }
  751. }
  752. /*****************************************************************************
  753.  * FUNCTION
  754.  *  mmi_calc_del_scr_callback
  755.  * DESCRIPTION
  756.  *  Callback function of delete calculator screen
  757.  * PARAMETERS
  758.  *  p       [?]     
  759.  * RETURNS
  760.  *  void
  761.  *****************************************************************************/
  762. U8 mmi_calc_del_scr_callback(void *p)
  763. {
  764.     /*----------------------------------------------------------------*/
  765.     /* Local Variables                                                */
  766.     /*----------------------------------------------------------------*/
  767.     /*----------------------------------------------------------------*/
  768.     /* Code Body                                                      */
  769.     /*----------------------------------------------------------------*/
  770.     CalcDeInit();
  771.     return MMI_FALSE;
  772. }
  773. /*****************************************************************************
  774.  * FUNCTION
  775.  *  CalcFreeMemAndBack
  776.  * DESCRIPTION
  777.  *  Free memory and exit calculator application.
  778.  * PARAMETERS
  779.  *  void
  780.  * RETURNS
  781.  *  void
  782.  *****************************************************************************/
  783. void CalcFreeMemAndBack(void)
  784. {
  785.     /*----------------------------------------------------------------*/
  786.     /* Local Variables                                                */
  787.     /*----------------------------------------------------------------*/
  788.     /*----------------------------------------------------------------*/
  789.     /* Code Body                                                      */
  790.     /*----------------------------------------------------------------*/
  791.     if (g_calc_cntx->IsRSKPress)
  792.     {
  793.         g_calc_cntx->IsRSKPress = FALSE;
  794.         SetRightSoftkeyFunction(NULL, KEY_EVENT_LONG_PRESS);
  795.     }
  796.     else
  797.     {
  798.         /* CalcDeInit(); */
  799.         GoBackHistory();
  800.     }
  801. }
  802. /*****************************************************************************
  803.  * FUNCTION
  804.  *  CalcSetRSKClear
  805.  * DESCRIPTION
  806.  *  Change RSK to "Clear"
  807.  * PARAMETERS
  808.  *  void
  809.  * RETURNS
  810.  *  void
  811.  *****************************************************************************/
  812. void CalcSetRSKClear(void)
  813. {
  814.     /*----------------------------------------------------------------*/
  815.     /* Local Variables                                                */
  816.     /*----------------------------------------------------------------*/
  817.     /*----------------------------------------------------------------*/
  818.     /* Code Body                                                      */
  819.     /*----------------------------------------------------------------*/
  820.     ChangeRightSoftkey(STR_GLOBAL_CLEAR, IMG_GLOBAL_CLEAR);
  821.     SetRightSoftkeyFunction(CalcHandleRSKLongPress, KEY_LONG_PRESS);
  822.     SetRightSoftkeyFunction(CalcHandleClearKey, KEY_EVENT_UP);
  823. }
  824. /*****************************************************************************
  825.  * FUNCTION
  826.  *  CalcSetRSKBack
  827.  * DESCRIPTION
  828.  *  Change RSK to "Back"
  829.  * PARAMETERS
  830.  *  void
  831.  * RETURNS
  832.  *  void
  833.  *****************************************************************************/
  834. void CalcSetRSKBack(void)
  835. {
  836.     /*----------------------------------------------------------------*/
  837.     /* Local Variables                                                */
  838.     /*----------------------------------------------------------------*/
  839.     /*----------------------------------------------------------------*/
  840.     /* Code Body                                                      */
  841.     /*----------------------------------------------------------------*/
  842.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_OK);
  843.     SetRightSoftkeyFunction(CalcFreeMemAndBack, KEY_EVENT_UP);
  844. }
  845. /*****************************************************************************
  846.  * FUNCTION
  847.  *  CalcResetResultValue
  848.  * DESCRIPTION
  849.  *  Reset memory related variables
  850.  * PARAMETERS
  851.  *  void
  852.  * RETURNS
  853.  *  void
  854.  *****************************************************************************/
  855. void CalcResetResultValue(void)
  856. {
  857.     /*----------------------------------------------------------------*/
  858.     /* Local Variables                                                */
  859.     /*----------------------------------------------------------------*/
  860.     /*----------------------------------------------------------------*/
  861.     /* Code Body                                                      */
  862.     /*----------------------------------------------------------------*/
  863.     g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  864.     g_calc_cntx->Operator = CALC_OP_NONE;
  865.     g_calc_cntx->Operand1 = 0;
  866.     g_calc_cntx->Operand2Buf[0] = CALC_SYM_NULL;
  867.     g_calc_cntx->Operand1Buf[0] = CALC_SYM_NULL;
  868.     memset(g_calc_cntx->Operand2Buf, 0, sizeof(g_calc_cntx->Operand2Buf));
  869.     memset(g_calc_cntx->Operand1Buf, 0, sizeof(g_calc_cntx->Operand1Buf));
  870.     g_calc_cntx->Operand2Len = 1;
  871.     g_calc_cntx->Operand1Len = 1;
  872.     g_calc_cntx->OpToExecute = CALC_OP_NONE;
  873.     g_calc_cntx->RSKState = CALC_RSK_BACK;
  874.     g_calc_cntx->ExecFlag = FALSE;
  875.     g_calc_cntx->ResultState = RESULT_NOT_EXCEED;
  876. }
  877. /*****************************************************************************
  878.  * FUNCTION
  879.  *  CalcResetMemValue
  880.  * DESCRIPTION
  881.  *  Reset memory related variables
  882.  * PARAMETERS
  883.  *  void
  884.  * RETURNS
  885.  *  void
  886.  *****************************************************************************/
  887. #ifndef __MMI_SLIM_CALCULATOR__
  888. void CalcResetMemValue(void)
  889. {
  890.     /*----------------------------------------------------------------*/
  891.     /* Local Variables                                                */
  892.     /*----------------------------------------------------------------*/
  893.     /*----------------------------------------------------------------*/
  894.     /* Code Body                                                      */
  895.     /*----------------------------------------------------------------*/
  896.     g_calc_cntx->ResultState = RESULT_NOT_EXCEED;
  897.     g_calc_cntx->MemValue = 0;
  898. }
  899. #endif /* __MMI_SLIM_CALCULATOR__ */ 
  900. /*****************************************************************************
  901.  * FUNCTION
  902.  *  CalcResetContext
  903.  * DESCRIPTION
  904.  *  Reset all values to default.
  905.  * PARAMETERS
  906.  *  void
  907.  * RETURNS
  908.  *  void
  909.  *****************************************************************************/
  910. void CalcResetContext()
  911. {
  912.     /*----------------------------------------------------------------*/
  913.     /* Local Variables                                                */
  914.     /*----------------------------------------------------------------*/
  915.     /*----------------------------------------------------------------*/
  916.     /* Code Body                                                      */
  917.     /*----------------------------------------------------------------*/
  918.     CalcResetResultValue();
  919. #ifndef __MMI_SLIM_CALCULATOR__
  920.     CalcResetMemValue();
  921. #endif 
  922. }
  923. #define CALC_DRAW_FUNC
  924. /*****************************************************************************
  925.  * FUNCTION
  926.  *  CalcShowKeypad
  927.  * DESCRIPTION
  928.  *  Draw keypad of calculator.
  929.  * PARAMETERS
  930.  *  void
  931.  * RETURNS
  932.  *  void
  933.  *****************************************************************************/
  934. void CalcShowKeypad(void)
  935. {
  936.     /*----------------------------------------------------------------*/
  937.     /* Local Variables                                                */
  938.     /*----------------------------------------------------------------*/
  939.     /*----------------------------------------------------------------*/
  940.     /* Code Body                                                      */
  941.     /*----------------------------------------------------------------*/
  942.     gui_reset_clip();
  943.     gui_show_image(CALC_KEYPAD_X, CALC_KEYPAD_Y, (PU8) GetImage(IMG_ID_CALC_MAIN));
  944.     gui_show_transparent_image(
  945.         CALC_KEYPAD_X + g_calc_cntx->OperatorImg[g_calc_cntx->CurrHilite].x,
  946.         CALC_KEYPAD_Y + g_calc_cntx->OperatorImg[g_calc_cntx->CurrHilite].y,
  947.         (PU8) g_calc_cntx->OperatorImg[g_calc_cntx->CurrHilite].image,
  948.         0);
  949. #if(UI_DOUBLE_BUFFER_SUPPORT)
  950.     gui_BLT_double_buffer(CALC_KEYPAD_X, CALC_KEYPAD_Y, UI_device_width - 1, UI_device_height - 1);
  951. #endif 
  952. }
  953. /*****************************************************************************
  954.  * FUNCTION
  955.  *  CalcShowResultScreen
  956.  * DESCRIPTION
  957.  *  Draw result screen area.
  958.  * PARAMETERS
  959.  *  void
  960.  * RETURNS
  961.  *  void
  962.  *****************************************************************************/
  963. void CalcShowResultScreen()
  964. {
  965.     /*----------------------------------------------------------------*/
  966.     /* Local Variables                                                */
  967.     /*----------------------------------------------------------------*/
  968.     UI_character_type op = CALC_SYM_ERROR;
  969.     S32 w;
  970.     S8 uni_s[64];
  971.     S32 temp_int;
  972.     DOUBLE temp_res = 0;
  973.     S8 ansii_str[CALC_MAX_BUFF_LEN];
  974. #ifndef __MMI_SLIM_CALCULATOR__
  975.     S8 uni_memory[64];
  976. #endif 
  977.     /*----------------------------------------------------------------*/
  978.     /* Code Body                                                      */
  979.     /*----------------------------------------------------------------*/
  980. #if(UI_DOUBLE_BUFFER_SUPPORT)
  981.     gui_lock_double_buffer();
  982. #endif 
  983. #if defined(__MMI_TOUCH_CALCULATOR__)
  984.     gui_set_font(&MMI_large_font);
  985.     gui_set_text_color(gCalcTextColor);
  986.     gui_reset_clip();
  987.     gui_reset_text_clip();
  988.     gui_fill_rectangle(
  989.         calculator_keypad.result_area_x,
  990.         calculator_keypad.result_area_y,
  991.         calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - 1,
  992.         calculator_keypad.result_area_y + CALC_TOUCH_RESULT_AREA_HEIGHT - 1,
  993.         gTouchCalcResultScrColor);
  994. #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  995.     gui_set_font(&MMI_medium_font);
  996.     gui_set_text_color(gCalcTextColor);
  997.     /* screen background */
  998.     gui_reset_clip();
  999.     gui_reset_text_clip();
  1000.     gui_fill_rectangle(
  1001.         CALC_SCR_X,
  1002.         CALC_SCR_Y,
  1003.         CALC_SCR_X + CALC_SCR_WIDTH - 1,
  1004.         CALC_SCR_Y + CALC_SCR_HEIGHT - 1,
  1005.         gCalcResultScrColor);
  1006.     gui_draw_rectangle(
  1007.         CALC_SCR_X,
  1008.         CALC_SCR_Y,
  1009.         CALC_SCR_X + CALC_SCR_WIDTH - 1,
  1010.         CALC_SCR_Y + CALC_SCR_HEIGHT - 1,
  1011.         gCalcResultBorderColor);
  1012.     gui_draw_rectangle(
  1013.         CALC_SCR_X + 1,
  1014.         CALC_SCR_Y + 1,
  1015.         CALC_SCR_X + CALC_SCR_WIDTH - 2,
  1016.         CALC_SCR_Y + CALC_SCR_HEIGHT - 2,
  1017.         gCalcResultBorderColor);
  1018. #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ /* end of __MMI_TOUCH_CALCULATOR__ */
  1019. #if !defined(__MMI_TOUCH_CALCULATOR__) && !defined(__MMI_SLIM_CALCULATOR__)     /* 050905 Sophie modified */
  1020.     /* memory filed */
  1021.     if (r2lMMIFlag)
  1022.     {
  1023.         w = gui_get_character_width((UI_character_type) '[');
  1024.         gui_move_text_cursor(CALC_MEM_X1 + w, CALC_MEM_Y1);
  1025.     }
  1026.     else
  1027.     {
  1028.         gui_move_text_cursor(CALC_MEM_X1, CALC_MEM_Y1);
  1029.     }
  1030.     gui_print_character((UI_character_type) '[');
  1031.     if (r2lMMIFlag)
  1032.     {
  1033.         w = gui_get_character_width((UI_character_type) ']');
  1034.         gui_move_text_cursor(CALC_MEM_X2 - 6 + w, CALC_MEM_Y1);
  1035.     }
  1036.     else
  1037.     {
  1038.         gui_move_text_cursor(CALC_MEM_X2 - 6, CALC_MEM_Y1);
  1039.     }
  1040.     gui_print_character((UI_character_type) ']');
  1041. #endif /* !defined(__MMI_TOUCH_CALCULATOR__) && !defined(__MMI_SLIM_CALCULATOR__) */ 
  1042.     if (g_calc_cntx->ResultState == RESULT_EXCEED)
  1043.     {
  1044.         op = CALC_SYM_ERROR;
  1045.         w = gui_get_character_width(CALC_SYM_ZERO);
  1046.         if (r2lMMIFlag)
  1047.         {
  1048.             gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR, CALC_OPERAND2_Y);
  1049.         }
  1050.     #if defined(__MMI_TOUCH_CALCULATOR__)
  1051.         else
  1052.         {
  1053.             gui_move_text_cursor(
  1054.                 calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1055.                 calculator_keypad.operand2_y);
  1056.         }
  1057.     #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1058.         else
  1059.         {
  1060.             gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1061.         }
  1062.     #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1063.         gui_print_character(CALC_SYM_ZERO);
  1064.     }
  1065.     else
  1066.     {
  1067.         if (g_calc_cntx->Operator == CALC_OP_EQUAL)
  1068.         {
  1069.             op = CALC_SYM_EQUAL;
  1070.             temp_int = (S32) g_calc_cntx->Operand1;
  1071.             if (temp_int == g_calc_cntx->Operand1)
  1072.             {
  1073.                 sprintf(ansii_str, "%d", temp_int);
  1074.                 AnsiiToUnicodeString((S8*) uni_s, (S8*) ansii_str);
  1075.             }
  1076.             else
  1077.             {
  1078.                 CalcDouble2String(g_calc_cntx->Operand1, uni_s, CALC_MAX_DIGITS);
  1079.                 g_calc_cntx->Operand1 = gui_atof((UI_string_type) uni_s);
  1080.             }
  1081.             w = gui_get_string_width((UI_string_type) uni_s);
  1082.             if (r2lMMIFlag)
  1083.             {
  1084.                 gui_move_text_cursor(
  1085.                     CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1086.                     CALC_OPERAND2_Y);
  1087.             }
  1088.         #if defined(__MMI_TOUCH_CALCULATOR__)
  1089.             else
  1090.             {
  1091.                 gui_move_text_cursor(
  1092.                     calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1093.                     calculator_keypad.operand2_y);
  1094.             }
  1095.         #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1096.             else
  1097.             {
  1098.                 gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1099.             }
  1100.         #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1101.             gui_print_text((UI_string_type) uni_s);
  1102.         }
  1103.         else if (g_calc_cntx->Operator == CALC_OP_NONE)
  1104.         {
  1105.             if (g_calc_cntx->CurrHilite < CALC_OP_EQUAL)    /* +,-,*,/ */
  1106.             {
  1107.                 switch (g_calc_cntx->CurrHilite)
  1108.                 {
  1109.                     case CALC_OP_PLUS:
  1110.                         op = CALC_SYM_PLUS;
  1111.                         break;
  1112.                     case CALC_OP_MINUS:
  1113.                         op = CALC_SYM_MINUS;
  1114.                         break;
  1115.                     case CALC_OP_MULT:
  1116.                         op = CALC_SYM_MUL;
  1117.                         break;
  1118.                     case CALC_OP_DIV:
  1119.                         op = CALC_SYM_DIV;
  1120.                         break;
  1121.                     default:
  1122.                         break;
  1123.                 }
  1124.                 temp_res = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
  1125.                 CalcDouble2String(temp_res, uni_s, CALC_MAX_DIGITS);
  1126.                 w = gui_get_string_width((UI_string_type) uni_s);
  1127.                 if (r2lMMIFlag)
  1128.                 {
  1129.                     gui_move_text_cursor(
  1130.                         CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1131.                         CALC_OPERAND1_Y);
  1132.                 }
  1133.             #if defined(__MMI_TOUCH_CALCULATOR__)
  1134.                 else
  1135.                 {
  1136.                     gui_move_text_cursor(
  1137.                         calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1138.                         calculator_keypad.operand2_y);
  1139.                 }
  1140.             #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1141.                 else
  1142.                 {
  1143.                     gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND1_Y);
  1144.                 }
  1145.             #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1146.                 gui_print_text((UI_string_type) uni_s);
  1147.                 w = gui_get_character_width(CALC_SYM_ZERO);
  1148.                 if (r2lMMIFlag)
  1149.                 {
  1150.                     gui_move_text_cursor(
  1151.                         CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1152.                         CALC_OPERAND2_Y);
  1153.                 }
  1154.             #if defined(__MMI_TOUCH_CALCULATOR__)
  1155.                 else
  1156.                 {
  1157.                     gui_move_text_cursor(
  1158.                         calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1159.                         calculator_keypad.operand2_y);
  1160.                 }
  1161.             #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1162.                 else
  1163.                 {
  1164.                     gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1165.                 }
  1166.             #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1167.                 gui_print_character(CALC_SYM_ZERO);
  1168.             }
  1169.             else
  1170.             {
  1171.                 op = CALC_SYM_NULL;
  1172.                 if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_NULL)
  1173.                 {
  1174.                     w = gui_get_character_width(CALC_SYM_ZERO);
  1175.                     if (r2lMMIFlag)
  1176.                     {
  1177.                         gui_move_text_cursor(
  1178.                             CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1179.                             CALC_OPERAND2_Y);
  1180.                     }
  1181.                 #if defined(__MMI_TOUCH_CALCULATOR__)
  1182.                     else
  1183.                     {
  1184.                         gui_move_text_cursor(
  1185.                             calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1186.                             calculator_keypad.operand2_y);
  1187.                     }
  1188.                 #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1189.                     else
  1190.                     {
  1191.                         gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1192.                     }
  1193.                 #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1194.                     gui_print_character(CALC_SYM_ZERO);
  1195.                 }
  1196.                 else
  1197.                 {
  1198.                     w = gui_get_string_width(g_calc_cntx->Operand2Buf);
  1199.                     if (r2lMMIFlag)
  1200.                     {
  1201.                         gui_move_text_cursor(
  1202.                             CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1203.                             CALC_OPERAND2_Y);
  1204.                     }
  1205.                 #if defined(__MMI_TOUCH_CALCULATOR__)
  1206.                     else
  1207.                     {
  1208.                         gui_move_text_cursor(
  1209.                             calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1210.                             calculator_keypad.operand2_y);
  1211.                     }
  1212.                 #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1213.                     else
  1214.                     {
  1215.                         gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1216.                     }
  1217.                 #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1218.                     gui_print_text(g_calc_cntx->Operand2Buf);
  1219.                 }
  1220.             }
  1221.         }
  1222.         else
  1223.         {
  1224.             switch (g_calc_cntx->Operator)
  1225.             {
  1226.                 case CALC_OP_PLUS:
  1227.                     op = CALC_SYM_PLUS;
  1228.                     break;
  1229.                 case CALC_OP_MINUS:
  1230.                     op = CALC_SYM_MINUS;
  1231.                     break;
  1232.                 case CALC_OP_MULT:
  1233.                     op = CALC_SYM_MUL;
  1234.                     break;
  1235.                 case CALC_OP_DIV:
  1236.                     op = CALC_SYM_DIV;
  1237.                     break;
  1238.                 default:
  1239.                     break;
  1240.             }
  1241.             CalcDouble2String(g_calc_cntx->Operand1, uni_s, CALC_MAX_DIGITS);
  1242.             g_calc_cntx->Operand1 = gui_atof((UI_string_type) uni_s);
  1243.             w = gui_get_string_width((UI_string_type) uni_s);
  1244.             if (r2lMMIFlag)
  1245.             {
  1246.                 gui_move_text_cursor(
  1247.                     CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1248.                     CALC_OPERAND1_Y);
  1249.             }
  1250.         #if defined(__MMI_TOUCH_CALCULATOR__)
  1251.             else
  1252.             {
  1253.                 gui_move_text_cursor(
  1254.                     calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1255.                     calculator_keypad.operand1_y);
  1256.             }
  1257.         #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1258.             else
  1259.             {
  1260.                 gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND1_Y);
  1261.             }
  1262.         #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1263.             gui_print_text((UI_string_type) uni_s);
  1264.             w = gui_get_string_width(g_calc_cntx->Operand2Buf);
  1265.             if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_NULL)
  1266.             {
  1267.                 w = gui_get_character_width(CALC_SYM_ZERO);
  1268.                 if (r2lMMIFlag)
  1269.                 {
  1270.                     gui_move_text_cursor(
  1271.                         CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1272.                         CALC_OPERAND2_Y);
  1273.                 }
  1274.             #if defined(__MMI_TOUCH_CALCULATOR__)
  1275.                 else
  1276.                 {
  1277.                     gui_move_text_cursor(
  1278.                         calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1279.                         calculator_keypad.operand2_y);
  1280.                 }
  1281.             #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1282.                 else
  1283.                 {
  1284.                     gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1285.                 }
  1286.             #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1287.                 gui_print_character(CALC_SYM_ZERO);
  1288.             }
  1289.             else
  1290.             {
  1291.                 if (r2lMMIFlag)
  1292.                 {
  1293.                     gui_move_text_cursor(
  1294.                         CALC_SCR_X + CALC_SCR_WIDTH - 4 - CALC_RESERVED_SPACE_FOR_OPERATOR,
  1295.                         CALC_OPERAND2_Y);
  1296.                 }
  1297.             #if defined(__MMI_TOUCH_CALCULATOR__)
  1298.                 else
  1299.                 {
  1300.                     gui_move_text_cursor(
  1301.                         calculator_keypad.result_area_x + CALC_TOUCH_RESULT_AREA_WIDTH - w - 4,
  1302.                         calculator_keypad.operand2_y);
  1303.                 }
  1304.             #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1305.                 else
  1306.                 {
  1307.                     gui_move_text_cursor(CALC_SCR_X + CALC_SCR_WIDTH - w - 4, CALC_OPERAND2_Y);
  1308.                 }
  1309.             #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1310.                 gui_print_text(g_calc_cntx->Operand2Buf);
  1311.             }
  1312.         }
  1313.     #ifndef __MMI_SLIM_CALCULATOR__
  1314.         /* memory field */
  1315.         CalcDouble2String(g_calc_cntx->MemValue, uni_memory, CALC_MAX_DIGITS);
  1316.         g_calc_cntx->MemValue = gui_atof((UI_string_type) uni_memory);
  1317.         pfnUnicodeStrcat((S8*) uni_memory, (S8*) (L" "));
  1318.         w = gui_get_string_width((UI_string_type) uni_memory);
  1319.         if (r2lMMIFlag)
  1320.         {
  1321.             gui_move_text_cursor(CALC_SCR_X + CALC_MEM_X2 - 4, CALC_MEM_Y1);
  1322.         }
  1323.     #if defined(__MMI_TOUCH_CALCULATOR__)
  1324.         else
  1325.         {
  1326.             gui_move_text_cursor(
  1327.                 calculator_keypad.result_area_x + calculator_keypad.mem_x1 - w - 4,
  1328.                 calculator_keypad.mem_y1);
  1329.         }
  1330.     #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1331.         else
  1332.         {
  1333.             gui_move_text_cursor(CALC_SCR_X + CALC_MEM_X2 - w - 4, CALC_MEM_Y1);
  1334.         }
  1335.     #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1336.         gui_print_text((UI_string_type) uni_memory);
  1337.     #endif /* __MMI_SLIM_CALCULATOR__ */ 
  1338.     }   /* if(g_calc_cntx->ResultState == RESULT_EXCEED) */
  1339.     /* operator */
  1340.     if (r2lMMIFlag)
  1341.     {
  1342.         gui_move_text_cursor(CALC_SCR_WIDTH - 4, CALC_OPERATOR_Y);
  1343.     }
  1344. #if defined(__MMI_TOUCH_CALCULATOR__)
  1345.     else
  1346.     {
  1347.         gui_move_text_cursor(calculator_keypad.operator_x, calculator_keypad.operator_y);
  1348.     }
  1349. #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1350.     else
  1351.     {
  1352.         gui_move_text_cursor(CALC_OPERATOR_X, CALC_OPERATOR_Y);
  1353.     }
  1354. #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1355.     gui_print_character((UI_character_type) op);
  1356.     if (g_calc_cntx->RSKState == CALC_RSK_CLEAR)
  1357.     {
  1358.         CalcSetRSKClear();
  1359.     }
  1360.     else
  1361.     {
  1362.         CalcSetRSKBack();
  1363.     }
  1364.     show_softkey_background();
  1365.     show_left_softkey();
  1366.     show_right_softkey();
  1367.     gui_unlock_double_buffer();
  1368. #if defined(__MMI_TOUCH_CALCULATOR__)
  1369.     gui_BLT_double_buffer(
  1370.         TOUCH_CALC_SCREEN_X,
  1371.         TOUCH_CALC_SCREEN_Y,
  1372.         TOUCH_CALC_SCREEN_X + TOUCH_CALC_SCREEN_WIDTH - 1,
  1373.         TOUCH_CALC_SCREEN_Y + TOUCH_CALC_SCREEN_HEIGHT - 1);
  1374. #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1375.     gui_BLT_double_buffer(CALC_SCR_X, CALC_SCR_Y, CALC_SCR_X + CALC_SCR_WIDTH - 1, CALC_SCR_Y + CALC_SCR_HEIGHT - 1);
  1376. #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1377. }
  1378. /* 041205 Calvin added */
  1379. #if defined(__MMI_TOUCH_CALCULATOR__) /* && defined(__MMI_MAINLCD_240X320__) */ /* 060105 Calvin modified */
  1380. extern MMI_ID_TYPE idle_screen_wallpaper_ID;
  1381. extern gdi_handle wgui_base_layer;
  1382. extern gdi_handle wgui_layer_1;
  1383. #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1384. /* Calvin end */
  1385. /*****************************************************************************
  1386.  * FUNCTION
  1387.  *  CalcRedraw
  1388.  * DESCRIPTION
  1389.  *  Redraw calculator screen
  1390.  * PARAMETERS
  1391.  *  void
  1392.  * RETURNS
  1393.  *  void
  1394.  *****************************************************************************/
  1395. void CalcRedraw(void)
  1396. {
  1397.     /*----------------------------------------------------------------*/
  1398.     /* Local Variables                                                */
  1399.     /*----------------------------------------------------------------*/
  1400.     /*----------------------------------------------------------------*/
  1401.     /* Code Body                                                      */
  1402.     /*----------------------------------------------------------------*/
  1403.     gui_lock_double_buffer();
  1404.     gui_reset_clip();
  1405.     clear_screen();
  1406.     clear_category_screen_key_handlers();
  1407.     clear_left_softkey();
  1408.     clear_right_softkey();
  1409.     /* start vijay 20050302 */
  1410. #if defined(__MMI_TOUCH_CALCULATOR__)
  1411.     /* 052405 Calvin added */
  1412.     /* if ( gui_is_entry_new_screen()==MMI_TRUE ) */
  1413.     if (gui_is_entry_new_screen() == MMI_TRUE && wgui_is_wallpaper_on_bottom() == MMI_TRUE)
  1414.     {
  1415.         gui_set_entry_new_screen(MMI_FALSE);
  1416.         gdi_layer_multi_layer_enable();
  1417.         gdi_layer_get_base_handle(&wgui_base_layer);
  1418.         gui_layer_transparent(
  1419.             wgui_base_layer,
  1420.             UI_SUBMENU_OPACITY_BASED_LAYER,
  1421.             0,
  1422.             0,
  1423.             UI_DEVICE_WIDTH - 1,
  1424.             UI_DEVICE_HEIGHT - 1);
  1425.         if (wgui_layer_1 == GDI_LAYER_EMPTY_HANDLE)
  1426.         {
  1427.             gdi_layer_create(0, 0, UI_DEVICE_WIDTH, UI_DEVICE_HEIGHT, &wgui_layer_1);
  1428.         }
  1429.         gdi_layer_set_active(wgui_layer_1);
  1430.         gdi_layer_lock_frame_buffer();
  1431.         gdi_layer_push_clip();
  1432.         gdi_layer_reset_clip();
  1433.         gdi_layer_set_source_key(TRUE, GDI_COLOR_TRANSPARENT);
  1434.         gdi_layer_set_opacity(TRUE, 200);
  1435.         gdi_image_draw(0, 0, get_image(idle_screen_wallpaper_ID));
  1436.         gdi_layer_pop_clip();
  1437.         gdi_layer_unlock_frame_buffer();
  1438.         gdi_layer_restore_base_active();
  1439.         gdi_layer_set_blt_layer(wgui_layer_1, wgui_base_layer, 0, 0);
  1440.         gdi_layer_blt_previous(0, 0, UI_DEVICE_WIDTH - 1, UI_DEVICE_HEIGHT - 1);
  1441.         gdi_layer_set_active(wgui_base_layer);
  1442.         gdi_draw_solid_rect(0, 0, UI_DEVICE_WIDTH - 1, UI_DEVICE_HEIGHT - 1, GDI_COLOR_TRANSPARENT);
  1443.     }
  1444.     else
  1445.     {
  1446.         //Leo removed
  1447.         //              gdi_layer_get_base_handle(&wgui_base_layer);
  1448.         //              gui_layer_transparent(wgui_base_layer, UI_SUBMENU_OPACITY_BASED_LAYER, 0, 0, UI_DEVICE_WIDTH-1, UI_DEVICE_HEIGHT-1);
  1449.         //              gdi_layer_set_active(wgui_base_layer);
  1450.         //              gdi_draw_solid_rect(0, 0, UI_DEVICE_WIDTH-1, UI_DEVICE_HEIGHT-1,GDI_COLOR_TRANSPARENT);
  1451.     }
  1452.     /* Calvin end */
  1453.     setup_calculator_keypad(&calculator_keypad, TOUCH_CALC_SCREEN_X, TOUCH_CALC_SCREEN_Y);
  1454.     MMI_menu_shortcut_number = -1;
  1455.     /* 053005 Calvin modified */
  1456.     /* Leo 20050705 start */
  1457.     show_title_status_icon();
  1458.     //show_status_icons();
  1459.     //Leo 20050705 end
  1460.     /* Calvin end */
  1461.     ChangeTitleString((U8*) get_string(STR_ID_CALC_MENU));
  1462.     draw_title();
  1463.     show_touch_calculator_screen(
  1464.         TOUCH_CALC_SCREEN_X,
  1465.         TOUCH_CALC_SCREEN_Y,
  1466.         TOUCH_CALC_SCREEN_WIDTH,
  1467.         TOUCH_CALC_SCREEN_HEIGHT);
  1468.     CalcShowResultScreen();
  1469. #else /* defined(__MMI_TOUCH_CALCULATOR__) */ 
  1470. #if defined (__MMI_MAINLCD_176X220__) || defined (__MMI_MAINLCD_240X320__)
  1471.     MMI_disable_title_shortcut_display = 1;
  1472.     show_title_status_icon();
  1473.     ChangeTitleString((U8*) get_string(STR_ID_CALC_MENU));
  1474.     ChangeTitleIcon(GetRootTitleIcon(EXTRA_CALCULATOR_MENU));
  1475.     draw_title();
  1476. #endif /* defined (__MMI_MAINLCD_176X220__) || defined (__MMI_MAINLCD_240X320__) */ 
  1477.     CalcShowKeypad();
  1478.     CalcShowResultScreen();
  1479. #endif /* defined(__MMI_TOUCH_CALCULATOR__) */ /* end __MMI_TOUCH_CALCULATOR__ */
  1480.     /* end vijay */
  1481.     show_softkey_background();
  1482.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  1483.     show_left_softkey();
  1484.     show_right_softkey();
  1485.     gui_unlock_double_buffer();
  1486.     gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
  1487. }
  1488. /*****************************************************************************
  1489.  * FUNCTION
  1490.  *  CalcSearchDecimal
  1491.  * DESCRIPTION
  1492.  *  To search if there is a decimal point in current operand.
  1493.  * PARAMETERS
  1494.  *  void
  1495.  * RETURNS
  1496.  *  TRUE if decimal exists; otherwise, FALSE.
  1497.  *****************************************************************************/
  1498. U8 CalcSearchDecimal(void)
  1499. {
  1500.     /*----------------------------------------------------------------*/
  1501.     /* Local Variables                                                */
  1502.     /*----------------------------------------------------------------*/
  1503.     U8 index;
  1504.     /*----------------------------------------------------------------*/
  1505.     /* Code Body                                                      */
  1506.     /*----------------------------------------------------------------*/
  1507.     if (g_calc_cntx->Operand2Len > 1)
  1508.     {
  1509.         for (index = 0; index < g_calc_cntx->Operand2Len; index++)
  1510.         {
  1511.             if (g_calc_cntx->Operand2Buf[index] == CALC_SYM_DOT)
  1512.             {
  1513.                 return TRUE;
  1514.             }
  1515.         }
  1516.     }
  1517.     return FALSE;
  1518. }
  1519. /*****************************************************************************
  1520.  * FUNCTION
  1521.  *  CalcInsertChar
  1522.  * DESCRIPTION
  1523.  *  Insert a character to result screen.
  1524.  * PARAMETERS
  1525.  *  c       [IN]        
  1526.  * RETURNS
  1527.  *  void
  1528.  *****************************************************************************/
  1529. void CalcInsertChar(UI_character_type c)
  1530. {
  1531.     /*----------------------------------------------------------------*/
  1532.     /* Local Variables                                                */
  1533.     /*----------------------------------------------------------------*/
  1534.     /*----------------------------------------------------------------*/
  1535.     /* Code Body                                                      */
  1536.     /*----------------------------------------------------------------*/
  1537.     g_calc_cntx->ComputeType = CALC_OP_NONE;
  1538.     /* if operand2 = -(12 digit) || (12 digit) */
  1539.     if ((g_calc_cntx->Operand2Buf[0] == CALC_SYM_MINUS && g_calc_cntx->Operand2Len >= (CALC_MAX_DIGITS + 2)) ||
  1540.         (g_calc_cntx->Operand2Buf[0] != CALC_SYM_MINUS && g_calc_cntx->Operand2Len >= (CALC_MAX_DIGITS + 1)))
  1541.     {
  1542.         playRequestedTone(ERROR_TONE);
  1543.         return;
  1544.     }
  1545.     if (g_calc_cntx->Operand2Len == CALC_ZEOR_LEN && c == CALC_SYM_ZERO)
  1546.     {
  1547.         CalcShowResultScreen();
  1548.         return;
  1549.     }
  1550.     if (g_calc_cntx->Operator == CALC_OP_EQUAL)
  1551.     {
  1552.         g_calc_cntx->Operator = CALC_OP_NONE;
  1553.         g_calc_cntx->Operand1 = 0;
  1554.         g_calc_cntx->Operand2 = 0;
  1555.         g_calc_cntx->Operand2Len = 1;
  1556.         g_calc_cntx->Operand2Buf[0] = CALC_SYM_NULL;
  1557.         g_calc_cntx->OpToExecute = CALC_OP_NONE;
  1558.     }
  1559.     if (c == CALC_SYM_DOT && g_calc_cntx->Operand2Len == CALC_ZEOR_LEN) /* insert "." after zero */
  1560.     {
  1561.         g_calc_cntx->Operand2Buf[0] = CALC_SYM_ZERO;
  1562.         g_calc_cntx->Operand2Len++;
  1563.     }
  1564.     g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len - 1] = (UI_character_type) c;
  1565.     g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len] = CALC_SYM_NULL;
  1566.     g_calc_cntx->Operand2Len++;
  1567.     g_calc_cntx->RSKState = CALC_RSK_CLEAR;
  1568.     CalcShowResultScreen();
  1569. }
  1570. /*****************************************************************************
  1571.  * FUNCTION
  1572.  *  CalcExecMR
  1573.  * DESCRIPTION
  1574.  *  Execute MR operator.
  1575.  * PARAMETERS
  1576.  *  void
  1577.  * RETURNS
  1578.  *  void
  1579.  *****************************************************************************/
  1580. #ifndef __MMI_SLIM_CALCULATOR__
  1581. void CalcExecMR(void)
  1582. {
  1583.     /*----------------------------------------------------------------*/
  1584.     /* Local Variables                                                */
  1585.     /*----------------------------------------------------------------*/
  1586.     /*----------------------------------------------------------------*/
  1587.     /* Code Body                                                      */
  1588.     /*----------------------------------------------------------------*/
  1589.     CalcResetResultValue();
  1590.     CalcDouble2String(g_calc_cntx->MemValue, (S8*) g_calc_cntx->Operand2Buf, CALC_MAX_DIGITS);
  1591.     g_calc_cntx->Operand2Len = pfnUnicodeStrlen((S8*) g_calc_cntx->Operand2Buf) + 1;
  1592.     /* start vijay 20050616...no need to change the RSK on pressing MR button for touch panel */
  1593. #ifndef __MMI_TOUCH_CALCULATOR__
  1594.     if (g_calc_cntx->Operand2Len > 1)
  1595.     {
  1596.         g_calc_cntx->RSKState = CALC_RSK_CLEAR;
  1597.     }
  1598.     else
  1599.     {
  1600.         g_calc_cntx->RSKState = CALC_RSK_BACK;
  1601.     }
  1602. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  1603.     /* end vijay */
  1604. }
  1605. /*****************************************************************************
  1606.  * FUNCTION
  1607.  *  CalcExecMP
  1608.  * DESCRIPTION
  1609.  *  Execute M+ operator.
  1610.  * PARAMETERS
  1611.  *  void
  1612.  * RETURNS
  1613.  *  void
  1614.  *****************************************************************************/
  1615. void CalcExecMP(void)
  1616. {
  1617.     /*----------------------------------------------------------------*/
  1618.     /* Local Variables                                                */
  1619.     /*----------------------------------------------------------------*/
  1620.     DOUBLE temp_res;
  1621.     /*----------------------------------------------------------------*/
  1622.     /* Code Body                                                      */
  1623.     /*----------------------------------------------------------------*/
  1624.     if (g_calc_cntx->Operand2Buf[0] != CALC_SYM_NULL)
  1625.     {
  1626.         temp_res = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
  1627.         g_calc_cntx->MemValue += temp_res;
  1628.         if (!mmi_calc_check_boundary(g_calc_cntx->MemValue))
  1629.         {
  1630.             g_calc_cntx->ResultState = RESULT_EXCEED;
  1631.             playRequestedTone(ERROR_TONE);
  1632.             g_calc_cntx->MemValue = 0;
  1633.         }
  1634.     }
  1635. }
  1636. /*****************************************************************************
  1637.  * FUNCTION
  1638.  *  CalcExecMM
  1639.  * DESCRIPTION
  1640.  *  Execute M- operator.
  1641.  * PARAMETERS
  1642.  *  void
  1643.  * RETURNS
  1644.  *  void
  1645.  *****************************************************************************/
  1646. void CalcExecMM(void)
  1647. {
  1648.     /*----------------------------------------------------------------*/
  1649.     /* Local Variables                                                */
  1650.     /*----------------------------------------------------------------*/
  1651.     DOUBLE temp_res;
  1652.     /*----------------------------------------------------------------*/
  1653.     /* Code Body                                                      */
  1654.     /*----------------------------------------------------------------*/
  1655.     if (g_calc_cntx->Operand2Buf[0] != CALC_SYM_NULL)
  1656.     {
  1657.         temp_res = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
  1658.         g_calc_cntx->MemValue -= temp_res;
  1659.         if (!mmi_calc_check_boundary(g_calc_cntx->MemValue))
  1660.         {
  1661.             g_calc_cntx->ResultState = RESULT_EXCEED;
  1662.             playRequestedTone(ERROR_TONE);
  1663.             g_calc_cntx->MemValue = 0;
  1664.         }
  1665.     }
  1666. }
  1667. #endif /* __MMI_SLIM_CALCULATOR__ */ 
  1668. /*****************************************************************************
  1669.  * FUNCTION
  1670.  *  CalcGetCurrOperand
  1671.  * DESCRIPTION
  1672.  *  Convert the string of operand 1 to number
  1673.  * PARAMETERS
  1674.  *  void
  1675.  * RETURNS
  1676.  *  void
  1677.  *****************************************************************************/
  1678. void CalcGetCurrOperand(void)
  1679. {
  1680.     /*----------------------------------------------------------------*/
  1681.     /* Local Variables                                                */
  1682.     /*----------------------------------------------------------------*/
  1683.     /*----------------------------------------------------------------*/
  1684.     /* Code Body                                                      */
  1685.     /*----------------------------------------------------------------*/
  1686.     if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_NULL)
  1687.     {
  1688.         g_calc_cntx->Operand1 = 0;
  1689.     }
  1690.     else
  1691.     {
  1692.         g_calc_cntx->Operand1 = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
  1693.         /* 06/01/11, for bug of displaying "-0" */
  1694.         if (g_calc_cntx->Operand1 == -0)
  1695.         {
  1696.             g_calc_cntx->Operand1 = 0;
  1697.         }
  1698.     }
  1699. }
  1700. /*****************************************************************************
  1701.  * FUNCTION
  1702.  *  CalcGetPreOperand
  1703.  * DESCRIPTION
  1704.  *  Convert the string of operand 2 to number
  1705.  * PARAMETERS
  1706.  *  void
  1707.  * RETURNS
  1708.  *  void
  1709.  *****************************************************************************/
  1710. void CalcGetPreOperand(void)
  1711. {
  1712.     /*----------------------------------------------------------------*/
  1713.     /* Local Variables                                                */
  1714.     /*----------------------------------------------------------------*/
  1715.     /*----------------------------------------------------------------*/
  1716.     /* Code Body                                                      */
  1717.     /*----------------------------------------------------------------*/
  1718.     if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_NULL)
  1719.     {
  1720.         g_calc_cntx->Operand2 = 0;
  1721.     }
  1722.     else
  1723.     {
  1724.         g_calc_cntx->Operand2 = gui_atof((UI_string_type) g_calc_cntx->Operand2Buf);
  1725.     }
  1726. }
  1727. /*****************************************************************************
  1728.  * FUNCTION
  1729.  *  mmi_calc_check_boundary
  1730.  * DESCRIPTION
  1731.  *  Check the boundary of the calculated result.
  1732.  * PARAMETERS
  1733.  *  value       [IN]        Value to be checked
  1734.  * RETURNS
  1735.  *  0  out of the boundary
  1736.  *  1  within the boundary
  1737.  *****************************************************************************/
  1738. U8 mmi_calc_check_boundary(DOUBLE value)
  1739. {
  1740.     /*----------------------------------------------------------------*/
  1741.     /* Local Variables                                                */
  1742.     /*----------------------------------------------------------------*/
  1743.     S8 uni_s[64];
  1744.     S8 ansii_str[CALC_MAX_BUFF_LEN];
  1745.     /*----------------------------------------------------------------*/
  1746.     /* Code Body                                                      */
  1747.     /*----------------------------------------------------------------*/
  1748.     memset(uni_s, 0, sizeof(uni_s));
  1749.     memset(ansii_str, 0, CALC_MAX_BUFF_LEN);
  1750.     if (value < 0)
  1751.     {
  1752.         value = -(value);
  1753.     }
  1754.     CalcDouble2String(value, uni_s, CALC_MAX_DIGITS);
  1755.     UnicodeToAnsii((S8*) ansii_str, (S8*) uni_s);
  1756.     if (strlen(ansii_str) > CALC_MAX_DIGITS)
  1757.     {
  1758.         return RESULT_NOT_EXCEED;
  1759.     }
  1760.     else
  1761.     {
  1762.         return RESULT_EXCEED;
  1763.     }
  1764. }
  1765. /*****************************************************************************
  1766.  * FUNCTION
  1767.  *  CalcExecOperator
  1768.  * DESCRIPTION
  1769.  *  Execute current computation operation.
  1770.  * PARAMETERS
  1771.  *  op1     [IN]        
  1772.  *  op2     [IN]        
  1773.  * RETURNS
  1774.  *  void
  1775.  *****************************************************************************/
  1776. DOUBLE CalcExecOperator(DOUBLE op1, DOUBLE op2)
  1777. {
  1778.     /*----------------------------------------------------------------*/
  1779.     /* Local Variables                                                */
  1780.     /*----------------------------------------------------------------*/
  1781.     DOUBLE result = 0;
  1782.     /*----------------------------------------------------------------*/
  1783.     /* Code Body                                                      */
  1784.     /*----------------------------------------------------------------*/
  1785.     CalcSetRSKClear();
  1786.     switch (g_calc_cntx->OpToExecute)
  1787.     {
  1788.         case CALC_OP_PLUS:
  1789.             result = op1 + op2;
  1790.             break;
  1791.         case CALC_OP_MINUS:
  1792.             result = op1 - op2;
  1793.             break;
  1794.         case CALC_OP_MULT:
  1795.             result = op1 * op2;
  1796.             break;
  1797.         case CALC_OP_DIV:
  1798.             if (op2 > 0)
  1799.             {
  1800.                 result = (DOUBLE) op1 / op2;
  1801.             }
  1802.             break;
  1803.         default:
  1804.             return 0;
  1805.     }
  1806.     if (!mmi_calc_check_boundary(result))
  1807.     {
  1808.         g_calc_cntx->ResultState = RESULT_EXCEED;
  1809.         playRequestedTone(ERROR_TONE);
  1810.         return 0;
  1811.     }
  1812.     return (result);
  1813. }
  1814. /*****************************************************************************
  1815.  * FUNCTION
  1816.  *  CalcComputeResult
  1817.  * DESCRIPTION
  1818.  *  
  1819.  * PARAMETERS
  1820.  *  void
  1821.  * RETURNS
  1822.  *  void
  1823.  *****************************************************************************/
  1824. void CalcComputeResult(void)
  1825. {
  1826.     /*----------------------------------------------------------------*/
  1827.     /* Local Variables                                                */
  1828.     /*----------------------------------------------------------------*/
  1829.     /*----------------------------------------------------------------*/
  1830.     /* Code Body                                                      */
  1831.     /*----------------------------------------------------------------*/
  1832.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  1833.     {
  1834.         switch (g_calc_cntx->CurrHilite)
  1835.         {
  1836.         #ifndef __MMI_SLIM_CALCULATOR__
  1837.             case CALC_OP_MR:
  1838.             {
  1839.                 CalcExecMR();
  1840.                 g_calc_cntx->Operator = CALC_OP_NONE;
  1841.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  1842.                 g_calc_cntx->ComputeType = CALC_OP_MR;
  1843.                 break;
  1844.             }
  1845.             case CALC_OP_MC:
  1846.             {
  1847.                 CalcResetMemValue();
  1848.                 g_calc_cntx->Operator = CALC_OP_NONE;
  1849.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  1850.                 g_calc_cntx->ComputeType = CALC_OP_MC;
  1851.                 break;
  1852.             }
  1853.             case CALC_OP_MP:
  1854.             {
  1855.                 CalcExecMP();
  1856.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  1857.                 g_calc_cntx->Operator = CALC_OP_NONE;
  1858.                 g_calc_cntx->ComputeType = CALC_OP_MP;
  1859.                 break;
  1860.             }
  1861.             case CALC_OP_MM:
  1862.             {
  1863.                 CalcExecMM();
  1864.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  1865.                 g_calc_cntx->Operator = CALC_OP_NONE;
  1866.                 g_calc_cntx->ComputeType = CALC_OP_MM;
  1867.                 break;
  1868.             }
  1869.         #endif /* __MMI_SLIM_CALCULATOR__ */ 
  1870.             default:
  1871.             {
  1872.                 if (g_calc_cntx->Operator != CALC_OP_NONE)
  1873.                 {
  1874.                     g_calc_cntx->ComputeType = g_calc_cntx->Operator;
  1875.                     g_calc_cntx->Operator = CALC_OP_EQUAL;
  1876.                     CalcGetPreOperand();
  1877.                     if ((g_calc_cntx->Operand2 == 0) && (g_calc_cntx->OpToExecute == CALC_OP_DIV))
  1878.                     {
  1879.                         g_calc_cntx->ResultState = RESULT_EXCEED;
  1880.                         CalcSetRSKClear();
  1881.                         g_calc_cntx->Operator = CALC_OP_NONE;
  1882.                         playRequestedTone(ERROR_TONE);
  1883.                     }
  1884.                     else
  1885.                     {
  1886.                         if (g_calc_cntx->OpToExecute != CALC_OP_NONE)
  1887.                         {
  1888.                             g_calc_cntx->Operand1 = CalcExecOperator(g_calc_cntx->Operand1, g_calc_cntx->Operand2);
  1889.                             g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  1890.                             g_calc_cntx->OpToExecute = CALC_OP_NONE;
  1891.                         }
  1892.                     }
  1893.                 }
  1894.                 else
  1895.                 {
  1896.                     g_calc_cntx->ComputeType = CALC_OP_EQUAL;
  1897.                     g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  1898.                 }
  1899.                 break;
  1900.             }
  1901.         }
  1902.         g_calc_cntx->ExecFlag = TRUE;
  1903.     }
  1904.     else
  1905.     {
  1906.         playRequestedTone(ERROR_TONE);
  1907.     }
  1908. #if !defined(__MMI_TOUCH_CALCULATOR__)
  1909.     CalcShowKeypad();
  1910. #endif 
  1911.     CalcShowResultScreen();
  1912. }
  1913. #define CALC_KEY_HILITE_HANDLER
  1914. /*****************************************************************************
  1915.  * FUNCTION
  1916.  *  CalcHandleHiliteMemoryButton
  1917.  * DESCRIPTION
  1918.  *  Highlight handler of memory button.
  1919.  *  Move operand to result filed and clear all others.
  1920.  * PARAMETERS
  1921.  *  void
  1922.  * RETURNS
  1923.  *  void
  1924.  *****************************************************************************/
  1925. void CalcHandleHiliteMemoryButton(void)
  1926. {
  1927.     /*----------------------------------------------------------------*/
  1928.     /* Local Variables                                                */
  1929.     /*----------------------------------------------------------------*/
  1930.     /*----------------------------------------------------------------*/
  1931.     /* Code Body                                                      */
  1932.     /*----------------------------------------------------------------*/
  1933.     CalcDouble2String(g_calc_cntx->Operand1, (S8*) g_calc_cntx->Operand2Buf, CALC_MAX_DIGITS);
  1934.     g_calc_cntx->Operator = CALC_OP_NONE;
  1935.     if (g_calc_cntx->Operand1 != 0)
  1936.     {
  1937.         g_calc_cntx->Operand2Len = pfnUnicodeStrlen((S8*) g_calc_cntx->Operand2Buf) + 1;
  1938.     }
  1939.     else
  1940.     {
  1941.         g_calc_cntx->Operand2Len = CALC_ZEOR_LEN;
  1942.     }
  1943. }
  1944. /*****************************************************************************
  1945.  * FUNCTION
  1946.  *  CalcHandleHiliteOperator
  1947.  * DESCRIPTION
  1948.  *  Execute correspoding operation when highlighting on opeartor.
  1949.  *  Dislpay operator, calculator reslut, and add new operand.
  1950.  * PARAMETERS
  1951.  *  void
  1952.  * RETURNS
  1953.  *  void
  1954.  *****************************************************************************/
  1955. void CalcHandleHiliteOperator(void)
  1956. {
  1957.     /*----------------------------------------------------------------*/
  1958.     /* Local Variables                                                */
  1959.     /*----------------------------------------------------------------*/
  1960.     U8 PreOperator = g_calc_cntx->Operator;
  1961.     /*----------------------------------------------------------------*/
  1962.     /* Code Body                                                      */
  1963.     /*----------------------------------------------------------------*/
  1964.     g_calc_cntx->ExecFlag = FALSE;
  1965.     g_calc_cntx->Operator = g_calc_cntx->CurrHilite;
  1966.     /* start vijay 20050616.......RSK should not be changed to CLEAR key when pressed these buttons */
  1967. #ifdef __MMI_TOUCH_CALCULATOR__
  1968.     if (!(g_calc_cntx->Operator == CALC_OP_MP || g_calc_cntx->Operator == CALC_OP_MM ||
  1969.           g_calc_cntx->Operator == CALC_OP_MR || g_calc_cntx->Operator == CALC_OP_MC))
  1970.     {
  1971.         g_calc_cntx->RSKState = CALC_RSK_CLEAR;
  1972.     }
  1973. #else /* __MMI_TOUCH_CALCULATOR__ */ 
  1974.     g_calc_cntx->RSKState = CALC_RSK_CLEAR;
  1975. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  1976.     /* end vijay */
  1977.     switch (PreOperator)
  1978.     {
  1979.         case CALC_OP_PLUS:
  1980.         case CALC_OP_MINUS:
  1981.         case CALC_OP_MULT:
  1982.         case CALC_OP_DIV:
  1983.             if (g_calc_cntx->Operand2Buf[0] != CALC_SYM_NULL)
  1984.             {
  1985.                 g_calc_cntx->OpToExecute = PreOperator;
  1986.                 CalcGetPreOperand();
  1987.                 g_calc_cntx->Operand1 = CalcExecOperator(g_calc_cntx->Operand1, g_calc_cntx->Operand2);
  1988.                 /* g_calc_cntx->OpToExecute = g_calc_cntx->Operator; */
  1989.                 break;
  1990.             }
  1991.             else
  1992.             {
  1993.                 g_calc_cntx->OpToExecute = g_calc_cntx->Operator;
  1994.                 return;
  1995.             }
  1996.         #ifndef __MMI_SLIM_CALCULATOR__
  1997.         case CALC_OP_MP:
  1998.         case CALC_OP_MM:
  1999.         case CALC_OP_MR:
  2000.         case CALC_OP_MC:
  2001.         #endif /* __MMI_SLIM_CALCULATOR__ */ 
  2002.         case CALC_OP_NONE:
  2003.             CalcGetCurrOperand();
  2004.         default:
  2005.             break;
  2006.     }
  2007.     g_calc_cntx->OpToExecute = g_calc_cntx->Operator;
  2008.     memcpy(g_calc_cntx->Operand1Buf, g_calc_cntx->Operand2Buf, sizeof(g_calc_cntx->Operand1Buf));
  2009.     g_calc_cntx->Operand1Len = g_calc_cntx->Operand2Len;
  2010.     g_calc_cntx->Operand2 = 0;
  2011.     g_calc_cntx->Operand2Len = CALC_ZEOR_LEN;
  2012.     g_calc_cntx->Operand2Buf[0] = CALC_SYM_NULL;
  2013. }
  2014. /*****************************************************************************
  2015.  * FUNCTION
  2016.  *  CalcHandleLeftKey
  2017.  * DESCRIPTION
  2018.  *  Left arrow key handler.
  2019.  * PARAMETERS
  2020.  *  void
  2021.  * RETURNS
  2022.  *  void
  2023.  *****************************************************************************/
  2024. void CalcHandleLeftKey(void)
  2025. {
  2026.     /*----------------------------------------------------------------*/
  2027.     /* Local Variables                                                */
  2028.     /*----------------------------------------------------------------*/
  2029.     /*----------------------------------------------------------------*/
  2030.     /* Code Body                                                      */
  2031.     /*----------------------------------------------------------------*/
  2032.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  2033.     {
  2034.         switch (g_calc_cntx->CurrHilite)
  2035.         {
  2036.                 /* start Sophie 050904 */
  2037.         #ifdef __MMI_SLIM_CALCULATOR__
  2038.             case CALC_OP_MULT:
  2039.                 return;
  2040.         #else /* __MMI_SLIM_CALCULATOR__ */ 
  2041.             case CALC_OP_MC:
  2042.                 return;
  2043.             case CALC_OP_MR:
  2044.             {
  2045.                 g_calc_cntx->CurrHilite = CALC_OP_DIV;
  2046.                 CalcHandleHiliteOperator();
  2047.                 break;
  2048.             }
  2049.             case CALC_OP_MULT:
  2050.             {
  2051.                 g_calc_cntx->CurrHilite = CALC_OP_MC;
  2052.                 CalcHandleHiliteMemoryButton();
  2053.                 break;
  2054.             }
  2055.             case CALC_OP_MP:
  2056.             case CALC_OP_MM:
  2057.         #endif /* __MMI_SLIM_CALCULATOR__ */ /* end of ifdef __MMI_SLIM_CALCULATOR__ */
  2058.                 /* end Sophie */
  2059.             case CALC_OP_PLUS:
  2060.             case CALC_OP_MINUS:
  2061.             case CALC_OP_EQUAL:
  2062.             case CALC_OP_DIV:
  2063.             {
  2064.                 g_calc_cntx->CurrHilite = CALC_OP_MULT;
  2065.                 CalcHandleHiliteOperator();
  2066.                 break;
  2067.             }
  2068.             default:
  2069.             {
  2070.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  2071.                 break;
  2072.             }
  2073.         }
  2074.     }
  2075.     else
  2076.     {
  2077.         playRequestedTone(ERROR_TONE);
  2078.     }
  2079.     CalcShowKeypad();
  2080.     CalcShowResultScreen();
  2081. }
  2082. /*****************************************************************************
  2083.  * FUNCTION
  2084.  *  CalcHandleRightKey
  2085.  * DESCRIPTION
  2086.  *  Right arrow key handler.
  2087.  * PARAMETERS
  2088.  *  void
  2089.  * RETURNS
  2090.  *  void
  2091.  *****************************************************************************/
  2092. void CalcHandleRightKey(void)
  2093. {
  2094.     /*----------------------------------------------------------------*/
  2095.     /* Local Variables                                                */
  2096.     /*----------------------------------------------------------------*/
  2097.     /*----------------------------------------------------------------*/
  2098.     /* Code Body                                                      */
  2099.     /*----------------------------------------------------------------*/
  2100.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  2101.     {
  2102.         switch (g_calc_cntx->CurrHilite)
  2103.         {
  2104.                 /* start Sophie 050904 */
  2105.         #ifdef __MMI_SLIM_CALCULATOR__
  2106.             case CALC_OP_DIV:
  2107.                 return;
  2108.         #else /* __MMI_SLIM_CALCULATOR__ */ 
  2109.             case CALC_OP_MR:
  2110.                 return;
  2111.             case CALC_OP_MC:
  2112.             {
  2113.                 g_calc_cntx->CurrHilite = CALC_OP_MULT;
  2114.                 CalcHandleHiliteOperator();
  2115.                 break;
  2116.             }
  2117.             case CALC_OP_DIV:
  2118.             {
  2119.                 g_calc_cntx->CurrHilite = CALC_OP_MR;
  2120.                 CalcHandleHiliteMemoryButton();
  2121.                 break;
  2122.             }
  2123.             case CALC_OP_MP:
  2124.             case CALC_OP_MM:
  2125.         #endif /* __MMI_SLIM_CALCULATOR__ */ /* end of ifdef __MMI_SLIM_CALCULATOR__ */
  2126.                 /* end Sophie */
  2127.             case CALC_OP_PLUS:
  2128.             case CALC_OP_MINUS:
  2129.             case CALC_OP_MULT:
  2130.             case CALC_OP_EQUAL:
  2131.             {
  2132.                 g_calc_cntx->CurrHilite = CALC_OP_DIV;
  2133.                 CalcHandleHiliteOperator();
  2134.                 break;
  2135.             }
  2136.             default:
  2137.             {
  2138.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  2139.                 break;
  2140.             }
  2141.         }
  2142.     }
  2143.     else
  2144.     {
  2145.         playRequestedTone(ERROR_TONE);
  2146.     }
  2147.     CalcShowKeypad();
  2148.     CalcShowResultScreen();
  2149. }
  2150. /*****************************************************************************
  2151.  * FUNCTION
  2152.  *  CalcHandleUpKey
  2153.  * DESCRIPTION
  2154.  *  Up arrow key handler.
  2155.  * PARAMETERS
  2156.  *  void
  2157.  * RETURNS
  2158.  *  void
  2159.  *****************************************************************************/
  2160. void CalcHandleUpKey(void)
  2161. {
  2162.     /*----------------------------------------------------------------*/
  2163.     /* Local Variables                                                */
  2164.     /*----------------------------------------------------------------*/
  2165.     /*----------------------------------------------------------------*/
  2166.     /* Code Body                                                      */
  2167.     /*----------------------------------------------------------------*/
  2168.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  2169.     {
  2170.         switch (g_calc_cntx->CurrHilite)
  2171.         {
  2172.                 /* start Sophie 050904 */
  2173.         #ifdef __MMI_SLIM_CALCULATOR__
  2174.             case CALC_OP_PLUS:
  2175.                 return;
  2176.         #else /* __MMI_SLIM_CALCULATOR__ */ 
  2177.             case CALC_OP_MP:
  2178.                 return;
  2179.             case CALC_OP_MM:
  2180.             {
  2181.                 g_calc_cntx->CurrHilite = CALC_OP_MINUS;
  2182.                 CalcHandleHiliteOperator();
  2183.                 break;
  2184.             }
  2185.             case CALC_OP_PLUS:
  2186.             {
  2187.                 g_calc_cntx->CurrHilite = CALC_OP_MP;
  2188.                 CalcHandleHiliteMemoryButton();
  2189.                 break;
  2190.             }
  2191.             case CALC_OP_MR:
  2192.             case CALC_OP_MC:
  2193.         #endif /* __MMI_SLIM_CALCULATOR__ */ /* end of ifdef __MMI_SLIM_CALCULATOR__ */
  2194.                 /* end Sophie */
  2195.             case CALC_OP_DIV:
  2196.             case CALC_OP_MULT:
  2197.             case CALC_OP_EQUAL:
  2198.             case CALC_OP_MINUS:
  2199.             {
  2200.                 g_calc_cntx->CurrHilite = CALC_OP_PLUS;
  2201.                 CalcHandleHiliteOperator();
  2202.                 break;
  2203.             }
  2204.             default:
  2205.             {
  2206.                 g_calc_cntx->CurrHilite = CALC_OP_PLUS;
  2207.                 break;
  2208.             }
  2209.         }
  2210.     }
  2211.     else
  2212.     {
  2213.         playRequestedTone(ERROR_TONE);
  2214.     }
  2215.     CalcShowKeypad();
  2216.     CalcShowResultScreen();
  2217. }
  2218. /*****************************************************************************
  2219.  * FUNCTION
  2220.  *  CalcHandleDownKey
  2221.  * DESCRIPTION
  2222.  *  Down arrow key handler.
  2223.  * PARAMETERS
  2224.  *  void
  2225.  * RETURNS
  2226.  *  void
  2227.  *****************************************************************************/
  2228. void CalcHandleDownKey(void)
  2229. {
  2230.     /*----------------------------------------------------------------*/
  2231.     /* Local Variables                                                */
  2232.     /*----------------------------------------------------------------*/
  2233.     /*----------------------------------------------------------------*/
  2234.     /* Code Body                                                      */
  2235.     /*----------------------------------------------------------------*/
  2236.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  2237.     {
  2238.         switch (g_calc_cntx->CurrHilite)
  2239.         {
  2240.                 /* start Sophie 050904 */
  2241.         #ifdef __MMI_SLIM_CALCULATOR__
  2242.             case CALC_OP_MINUS:
  2243.                 return;
  2244.         #else /* __MMI_SLIM_CALCULATOR__ */ 
  2245.             case CALC_OP_MM:
  2246.                 return;
  2247.             case CALC_OP_MP:
  2248.             {
  2249.                 g_calc_cntx->CurrHilite = CALC_OP_PLUS;
  2250.                 CalcHandleHiliteOperator();
  2251.                 break;
  2252.             }
  2253.             case CALC_OP_MINUS:
  2254.             {
  2255.                 g_calc_cntx->CurrHilite = CALC_OP_MM;
  2256.                 CalcHandleHiliteMemoryButton();
  2257.                 break;
  2258.             }
  2259.             case CALC_OP_MR:
  2260.             case CALC_OP_MC:
  2261.         #endif /* __MMI_SLIM_CALCULATOR__ */ 
  2262.                 /* end Sophie */
  2263.             case CALC_OP_DIV:
  2264.             case CALC_OP_MULT:
  2265.             case CALC_OP_EQUAL:
  2266.             case CALC_OP_PLUS:
  2267.             {
  2268.                 g_calc_cntx->CurrHilite = CALC_OP_MINUS;
  2269.                 CalcHandleHiliteOperator();
  2270.                 break;
  2271.             }
  2272.             default:
  2273.             {
  2274.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  2275.                 break;
  2276.             }
  2277.         }
  2278.     }
  2279.     else
  2280.     {
  2281.         playRequestedTone(ERROR_TONE);
  2282.     }
  2283.     CalcShowKeypad();
  2284.     CalcShowResultScreen();
  2285. }
  2286. /*****************************************************************************
  2287.  * FUNCTION
  2288.  *  CalcHandleNumKey
  2289.  * DESCRIPTION
  2290.  *  Handle number key input
  2291.  * PARAMETERS
  2292.  *  key_code        [IN]        
  2293.  * RETURNS
  2294.  *  void
  2295.  *****************************************************************************/
  2296. void CalcHandleNumKey(S32 key_code)
  2297. {
  2298.     /*----------------------------------------------------------------*/
  2299.     /* Local Variables                                                */
  2300.     /*----------------------------------------------------------------*/
  2301.     /*----------------------------------------------------------------*/
  2302.     /* Code Body                                                      */
  2303.     /*----------------------------------------------------------------*/
  2304.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  2305.     {
  2306.         if (g_calc_cntx->ExecFlag)
  2307.         {
  2308.             CalcResetResultValue();
  2309.         }
  2310.         if (g_calc_cntx->CurrHilite <= CALC_OP_EQUAL)   /* operators */
  2311.         {
  2312.             g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  2313.         #if !defined(__MMI_TOUCH_CALCULATOR__)
  2314.             CalcShowKeypad();
  2315.         #endif 
  2316.         }
  2317.         CalcInsertChar((UI_character_type) ('0' + key_code));
  2318.     }
  2319.     else
  2320.     {
  2321.         playRequestedTone(ERROR_TONE);
  2322.     }
  2323. }
  2324. /*****************************************************************************
  2325.  * FUNCTION
  2326.  *  CalcHandlePoundKey
  2327.  * DESCRIPTION
  2328.  *  Pound key handler.
  2329.  * PARAMETERS
  2330.  *  void
  2331.  * RETURNS
  2332.  *  void
  2333.  *****************************************************************************/
  2334. void CalcHandlePoundKey(void)
  2335. {
  2336.     /*----------------------------------------------------------------*/
  2337.     /* Local Variables                                                */
  2338.     /*----------------------------------------------------------------*/
  2339.     /*----------------------------------------------------------------*/
  2340.     /* Code Body                                                      */
  2341.     /*----------------------------------------------------------------*/
  2342.     if (g_calc_cntx->ResultState == RESULT_NOT_EXCEED)
  2343.     {
  2344.         if (g_calc_cntx->ExecFlag)
  2345.         {
  2346.             CalcResetResultValue();
  2347.         }
  2348.         if (g_calc_cntx->Operand2Len == 1)
  2349.         {
  2350.             CalcInsertChar(CALC_SYM_DOT);
  2351.         }
  2352.         else if (!CalcSearchDecimal())
  2353.         {
  2354.             CalcInsertChar(CALC_SYM_DOT);
  2355.         }
  2356.     }
  2357.     else
  2358.     {
  2359.         playRequestedTone(ERROR_TONE);
  2360.     }
  2361. }
  2362. /*****************************************************************************
  2363.  * FUNCTION
  2364.  *  CalcHandleEndKey
  2365.  * DESCRIPTION
  2366.  *  End key handler of calculator
  2367.  * PARAMETERS
  2368.  *  void
  2369.  * RETURNS
  2370.  *  void
  2371.  *****************************************************************************/
  2372. void CalcHandleEndKey(void)
  2373. {
  2374.     /*----------------------------------------------------------------*/
  2375.     /* Local Variables                                                */
  2376.     /*----------------------------------------------------------------*/
  2377.     /*----------------------------------------------------------------*/
  2378.     /* Code Body                                                      */
  2379.     /*----------------------------------------------------------------*/
  2380.     /* CalcDeInit(); */
  2381.     DisplayIdleScreen();
  2382. }
  2383. /*****************************************************************************
  2384.  * FUNCTION
  2385.  *  CalcHandleClearKey
  2386.  * DESCRIPTION
  2387.  *  Clear key handler of calculator
  2388.  * PARAMETERS
  2389.  *  void
  2390.  * RETURNS
  2391.  *  void
  2392.  *****************************************************************************/
  2393. void CalcHandleClearKey(void)
  2394. {
  2395.     /*----------------------------------------------------------------*/
  2396.     /* Local Variables                                                */
  2397.     /*----------------------------------------------------------------*/
  2398.     /*----------------------------------------------------------------*/
  2399.     /* Code Body                                                      */
  2400.     /*----------------------------------------------------------------*/
  2401.     if (g_calc_cntx->ResultState == RESULT_EXCEED)
  2402.     {
  2403.         CalcResetContext();
  2404.     }
  2405.     else if (g_calc_cntx->Operator != CALC_OP_NONE)
  2406.     {
  2407.         if (g_calc_cntx->Operator != CALC_OP_EQUAL)
  2408.         {
  2409.             if (g_calc_cntx->Operand2Len > CALC_ZEOR_LEN)
  2410.             {
  2411.                 g_calc_cntx->Operand2Len--;
  2412.                 /* '0.x' || '-x' */
  2413.                 if ((g_calc_cntx->Operand2Len == CALC_ZEOR_DOT_LEN &&
  2414.                      (g_calc_cntx->Operand2Buf[1] == CALC_SYM_DOT && g_calc_cntx->Operand2Buf[0] == CALC_SYM_ZERO)) ||
  2415.                     (g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len - 2] == CALC_SYM_MINUS))
  2416.                 {
  2417.                     g_calc_cntx->Operand2Len = CALC_ZEOR_LEN;
  2418.                 }
  2419.                 g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len - 1] = '';
  2420.             }
  2421.             else
  2422.             {
  2423.                 g_calc_cntx->Operator = CALC_OP_NONE;
  2424.                 g_calc_cntx->CurrHilite = CALC_OP_EQUAL;
  2425.                 if (g_calc_cntx->Operand1 == 0)
  2426.                 {
  2427.                     CalcResetResultValue();
  2428.                 }
  2429.                 else
  2430.                 {
  2431.                     CalcDouble2String(g_calc_cntx->Operand1, (S8*) g_calc_cntx->Operand2Buf, CALC_MAX_DIGITS);
  2432.                     g_calc_cntx->Operand2Len = pfnUnicodeStrlen((S8*) g_calc_cntx->Operand2Buf) + 1;
  2433.                 }
  2434.             }
  2435.         }
  2436.         else    /* display result after calculator, operator == equal */
  2437.         {
  2438.             CalcResetResultValue();
  2439.         }
  2440.     }
  2441.     else
  2442.     {
  2443.         if (g_calc_cntx->ComputeType >= CALC_OP_EQUAL && g_calc_cntx->ComputeType < CALC_OP_NONE)       /* Move to Mx and press LSK */
  2444.         {
  2445.             CalcResetResultValue();
  2446.         }
  2447.         else    /* Move to Mx */
  2448.         {
  2449.             g_calc_cntx->Operand2Len--;
  2450.             /* current operand == "0.x" || "-x" */
  2451.             if ((g_calc_cntx->Operand2Len == CALC_ZEOR_DOT_LEN) &&
  2452.                 ((g_calc_cntx->Operand2Buf[1] == CALC_SYM_DOT) && (g_calc_cntx->Operand2Buf[0] == CALC_SYM_ZERO))
  2453.                 || (g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len - 2] == CALC_SYM_MINUS))
  2454.             {
  2455.                 g_calc_cntx->Operand2Len = CALC_ZEOR_LEN;
  2456.             }
  2457.             else
  2458.             {
  2459.                 g_calc_cntx->Operand2Buf[g_calc_cntx->Operand2Len - 1] = '';
  2460.             }
  2461.             if (g_calc_cntx->Operand2Len <= 1)
  2462.             {
  2463.                 CalcResetResultValue();
  2464.             }
  2465.         }
  2466.     }
  2467.     if (g_calc_cntx->Operand2Buf[0] == CALC_SYM_ZERO && g_calc_cntx->Operand2Buf[1] == CALC_SYM_NULL)
  2468.     {
  2469.         g_calc_cntx->Operand2Len = CALC_ZEOR_LEN;
  2470.     }
  2471.     /* start vijay 20050307 */
  2472. #if !defined(__MMI_TOUCH_CALCULATOR__)
  2473.     CalcShowKeypad();
  2474. #endif 
  2475.     /* end vijay */
  2476.     CalcShowResultScreen();
  2477. }
  2478. /*****************************************************************************
  2479.  * FUNCTION
  2480.  *  CalcHandleRSKLongPress
  2481.  * DESCRIPTION
  2482.  *  Reset calculator to defualt state
  2483.  * PARAMETERS
  2484.  *  void
  2485.  * RETURNS
  2486.  *  void
  2487.  *****************************************************************************/
  2488. void CalcHandleRSKLongPress(void)
  2489. {
  2490.     /*----------------------------------------------------------------*/
  2491.     /* Local Variables                                                */
  2492.     /*----------------------------------------------------------------*/
  2493.     /*----------------------------------------------------------------*/
  2494.     /* Code Body                                                      */
  2495.     /*----------------------------------------------------------------*/
  2496.     g_calc_cntx->IsRSKPress = TRUE;
  2497.     CalcResetResultValue();
  2498. #ifndef __MMI_TOUCH_CALCULATOR__
  2499.     CalcShowKeypad();
  2500. #endif 
  2501.     CalcShowResultScreen();
  2502. }
  2503. #ifndef __MTK_TARGET__
  2504. /*****************************************************************************
  2505.  * FUNCTION
  2506.  *  CalWin32NumKeyHandler
  2507.  * DESCRIPTION
  2508.  *  Key handler on Win 32
  2509.  * PARAMETERS
  2510.  *  keyc        [IN]        
  2511.  * RETURNS
  2512.  *  void
  2513.  *****************************************************************************/
  2514. void CalWin32NumKeyHandler(S32 keyc)
  2515. {
  2516.     /*----------------------------------------------------------------*/
  2517.     /* Local Variables                                                */
  2518.     /*----------------------------------------------------------------*/
  2519.     /*----------------------------------------------------------------*/
  2520.     /* Code Body                                                      */
  2521.     /*----------------------------------------------------------------*/
  2522.     if (keyc >= '0' && keyc <= '9')
  2523.     {
  2524.         CalcInsertChar((UI_character_type) keyc);
  2525.     }
  2526.     else if (keyc == 0x08)
  2527.     {
  2528.         CalcHandleClearKey();
  2529.     }
  2530.     else if (keyc == 0x1b); /* Esc   */
  2531.     else if (keyc == 0x0d); /* Tab   */
  2532. }
  2533. /*****************************************************************************
  2534.  * FUNCTION
  2535.  *  CalWin32ArrowKeyHandler
  2536.  * DESCRIPTION
  2537.  *  Key handler on Win 32
  2538.  * PARAMETERS
  2539.  *  vkey_code       [IN]        
  2540.  *  key_state       [IN]        
  2541.  * RETURNS
  2542.  *  void
  2543.  *****************************************************************************/
  2544. void CalWin32ArrowKeyHandler(S32 vkey_code, S32 key_state)
  2545. {
  2546. #if(MMI_BUILD_TYPE == BUILD_TYPE_X86WIN32)
  2547.     /*----------------------------------------------------------------*/
  2548.     /* Local Variables                                                */
  2549.     /*----------------------------------------------------------------*/
  2550.     /*----------------------------------------------------------------*/
  2551.     /* Code Body                                                      */
  2552.     /*----------------------------------------------------------------*/
  2553.     if (key_state)
  2554.     {
  2555.         switch (vkey_code)
  2556.         {
  2557.             case 37:
  2558.                 CalcHandleLeftKey();
  2559.                 break;
  2560.             case 39:
  2561.                 CalcHandleRightKey();
  2562.                 break;
  2563.             case 38:
  2564.                 CalcHandleUpKey();
  2565.                 break;
  2566.             case 40:
  2567.                 CalcHandleDownKey();
  2568.                 break;
  2569.         }
  2570.     }
  2571. #else /* (MMI_BUILD_TYPE == BUILD_TYPE_X86WIN32) */ 
  2572.     UI_UNUSED_PARAMETER(vkey_code);
  2573.     UI_UNUSED_PARAMETER(key_state);
  2574. #endif /* (MMI_BUILD_TYPE == BUILD_TYPE_X86WIN32) */ 
  2575. }
  2576. #endif /* __MTK_TARGET__ */ 
  2577. /*****************************************************************************
  2578.  * FUNCTION
  2579.  *  CalcRegisterKeyHandler
  2580.  * DESCRIPTION
  2581.  *  Register key handler of calculator
  2582.  * PARAMETERS
  2583.  *  void
  2584.  * RETURNS
  2585.  *  void
  2586.  *****************************************************************************/
  2587. void CalcRegisterKeyHandler(void)
  2588. {
  2589.     /*----------------------------------------------------------------*/
  2590.     /* Local Variables                                                */
  2591.     /*----------------------------------------------------------------*/
  2592.     /*----------------------------------------------------------------*/
  2593.     /* Code Body                                                      */
  2594.     /*----------------------------------------------------------------*/
  2595. #ifndef __MMI_TOUCH_CALCULATOR__
  2596.     SetKeyHandler(CalcHandleLeftKey, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  2597.     SetKeyHandler(CalcHandleRightKey, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  2598.     SetKeyHandler(CalcHandleUpKey, KEY_UP_ARROW, KEY_EVENT_DOWN);
  2599.     SetKeyHandler(CalcHandleDownKey, KEY_DOWN_ARROW, KEY_EVENT_DOWN);
  2600.     SetLeftSoftkeyFunction(CalcComputeResult, KEY_EVENT_UP);
  2601.     SetKeyHandler(CalcHandleEndKey, KEY_END, KEY_EVENT_DOWN);
  2602. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  2603.     SetKeyHandler(CalcHandlePoundKey, KEY_POUND, KEY_EVENT_UP);
  2604.     /* start vijay 20050603...moved outside the ifdefs for soft key's implementation */
  2605.     SetLeftSoftkeyFunction(CalcComputeResult, KEY_EVENT_UP);
  2606.     /* end vijay */
  2607.     if (g_calc_cntx->RSKState == CALC_RSK_BACK)
  2608.     {
  2609.         CalcSetRSKBack();
  2610.     }
  2611.     else
  2612.     {
  2613.         CalcSetRSKClear();
  2614.     }
  2615. #ifndef __MTK_TARGET__
  2616.     register_keyboard_key_handler(CalWin32ArrowKeyHandler);
  2617.     register_keyboard_input_handler(CalWin32NumKeyHandler);
  2618. #endif /* __MTK_TARGET__ */ 
  2619.     register_MMI_key_input_handler();
  2620.     register_key_down_handler(CalcHandleNumKey);
  2621. }
  2622. /*****************************************************************************
  2623.  * FUNCTION
  2624.  *  ExitCalcApp
  2625.  * DESCRIPTION
  2626.  *  Exit function of calculator application
  2627.  * PARAMETERS
  2628.  *  void
  2629.  * RETURNS
  2630.  *  void
  2631.  *****************************************************************************/
  2632. void ExitCalcApp(void)
  2633. {
  2634.     /*----------------------------------------------------------------*/
  2635.     /* Local Variables                                                */
  2636.     /*----------------------------------------------------------------*/
  2637.     /*----------------------------------------------------------------*/
  2638.     /* Code Body                                                      */
  2639.     /*----------------------------------------------------------------*/
  2640.     MMI_disable_title_shortcut_display = 0;
  2641. }
  2642. /*****************************************************************************
  2643.  * FUNCTION
  2644.  *  EntryCalcApp
  2645.  * DESCRIPTION
  2646.  *  Entry function of calculator application
  2647.  * PARAMETERS
  2648.  *  void
  2649.  * RETURNS
  2650.  *  void
  2651.  *****************************************************************************/
  2652. void EntryCalcApp(void)
  2653. {
  2654.     /*----------------------------------------------------------------*/
  2655.     /* Local Variables                                                */
  2656.     /*----------------------------------------------------------------*/
  2657.     /*----------------------------------------------------------------*/
  2658.     /* Code Body                                                      */
  2659.     /*----------------------------------------------------------------*/
  2660.     EntryNewScreen(SCR_ID_CALC_APP, ExitCalcApp, EntryCalcApp, NULL);
  2661.     SetDelScrnIDCallbackHandler(SCR_ID_CALC_APP, (HistoryDelCBPtr) mmi_calc_del_scr_callback);
  2662. #ifndef __MMI_TOUCH_CALCULATOR__
  2663. #if !defined (__MMI_MAINLCD_176X220__) && !defined (__MMI_MAINLCD_240X320__)
  2664.     entry_full_screen();
  2665. #endif 
  2666. #else /* __MMI_TOUCH_CALCULATOR__ */ 
  2667. #if defined(__MMI_MAINLCD_240X320__)
  2668. #ifdef __MMI_WALLPAPER_ON_BOTTOM__
  2669.     wgui_set_wallpaper_on_bottom(MMI_TRUE);
  2670.     dm_set_scr_bg_redraw(MMI_TRUE);
  2671. #endif /* __MMI_WALLPAPER_ON_BOTTOM__ */ 
  2672. #endif /* defined(__MMI_MAINLCD_240X320__) */ 
  2673. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  2674.     CalcRedraw();
  2675.     CalcRegisterKeyHandler();
  2676.     register_left_softkey_handler();
  2677.     register_right_softkey_handler();
  2678.     register_default_hide_softkeys();
  2679. #ifdef __MMI_TOUCH_CALCULATOR__
  2680.     mmi_pen_register_down_handler(mmi_touchcalc_pen_down_hdlr);
  2681.     mmi_pen_register_up_handler(mmi_touchcalc_pen_up_hdlr);
  2682.     mmi_pen_register_move_handler(mmi_touchcalc_pen_move_hdlr);
  2683.     mmi_pen_register_repeat_handler(mmi_touchcalc_pen_repeat_hdlr);
  2684.     mmi_pen_register_long_tap_handler(mmi_touchcalc_pen_long_tap_hdlr);
  2685. #endif /* __MMI_TOUCH_CALCULATOR__ */ 
  2686. #if defined(__MMI_WITH_C_KEY__)
  2687.     SetKeyHandler(CalcHandleClearKey, KEY_CLEAR, KEY_EVENT_DOWN);
  2688.     SetKeyHandler(CalcHandleRSKLongPress, KEY_CLEAR, KEY_EVENT_LONG_PRESS);
  2689. #endif /* defined(__MMI_WITH_C_KEY__) */ 
  2690.     RedrawCategoryFunction = CalcRedraw;
  2691. }
  2692. /*****************************************************************************
  2693.  * FUNCTION
  2694.  *  CalcPreEntryApp
  2695.  * DESCRIPTION
  2696.  *  Initialize data before entry calculator.
  2697.  * PARAMETERS
  2698.  *  void
  2699.  * RETURNS
  2700.  *  void
  2701.  *****************************************************************************/
  2702. void CalcPreEntryApp(void)
  2703. {
  2704.     /*----------------------------------------------------------------*/
  2705.     /* Local Variables                                                */
  2706.     /*----------------------------------------------------------------*/
  2707.     S32 i;
  2708.     /*----------------------------------------------------------------*/
  2709.     /* Code Body                                                      */
  2710.     /*----------------------------------------------------------------*/
  2711.     if (g_calc_cntx == NULL)
  2712.     {
  2713.         g_calc_cntx = OslMalloc(sizeof(calc_context_struct));
  2714.     }
  2715.     memset(g_calc_cntx, 0, sizeof(calc_context_struct));
  2716.     /* initialize image */
  2717.     /* 050905 Sophie modified start */
  2718. #ifdef __MMI_SLIM_CALCULATOR__
  2719.     for (i = CALC_OP_PLUS; i <= CALC_OP_EQUAL; i++)
  2720. #else 
  2721.     for (i = CALC_OP_PLUS; i < CALC_OP_NONE; i++)
  2722. #endif 
  2723.         /* 050905 Sophie modified end  */
  2724.     {
  2725.         g_calc_cntx->OperatorImg[i].x = gCalcImgCoor[i][0];
  2726.         g_calc_cntx->OperatorImg[i].y = gCalcImgCoor[i][1];
  2727.         g_calc_cntx->OperatorImg[i].image = (PU8) GetImage((U16) (IMG_ID_CALC_PLUS + i));
  2728.     }
  2729.     /* initialize keys */
  2730.     CalcResetContext();
  2731.     EntryCalcApp();
  2732. }
  2733. #ifdef __MMI_TOUCH_CALCULATOR__
  2734. /*****************************************************************************
  2735.  * FUNCTION
  2736.  *  mmi_touchcalc_pen_down_hdlr
  2737.  * DESCRIPTION
  2738.  *  
  2739.  * PARAMETERS
  2740.  *  point       [IN]        
  2741.  * RETURNS
  2742.  *  void
  2743.  *****************************************************************************/
  2744. void mmi_touchcalc_pen_down_hdlr(mmi_pen_point_struct point)
  2745. {
  2746.     /*----------------------------------------------------------------*/
  2747.     /* Local Variables                                                */
  2748.     /*----------------------------------------------------------------*/
  2749.     MMI_BOOL ret = MMI_FALSE;
  2750.     gui_calc_pen_enum calc_menu_event;
  2751.     gui_button_pen_enum button_event;
  2752.     /*----------------------------------------------------------------*/
  2753.     /* Code Body                                                      */
  2754.     /*----------------------------------------------------------------*/
  2755.     ret = translate_softkey_pen_event(MMI_LEFT_SOFTKEY, MMI_PEN_EVENT_DOWN, point.x, point.y, &button_event);
  2756.     if (ret)
  2757.     {
  2758.         calc_pen_on_object = TOUCH_CALC_PEN_LSK;
  2759.         if (button_event == GUI_BUTTON_PEN_DOWN)
  2760.         {
  2761.             execute_softkey_function(KEY_EVENT_DOWN, MMI_LEFT_SOFTKEY);
  2762.         }
  2763.     }
  2764.     ret = translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_DOWN, point.x, point.y, &button_event);
  2765.     if (ret)
  2766.     {
  2767.         calc_pen_on_object = TOUCH_CALC_PEN_RSK;
  2768.         if (button_event == GUI_BUTTON_PEN_DOWN)
  2769.         {
  2770.             execute_softkey_function(KEY_EVENT_DOWN, MMI_RIGHT_SOFTKEY);
  2771.         }
  2772.     }
  2773.     ret = gui_calculator_translate_pen_event(&calculator_keypad, point.x, point.y, &calc_menu_event, MMI_PEN_EVENT_DOWN);
  2774.     if (ret)
  2775.     {
  2776.         calc_pen_on_object = TOUCH_CALC_PEN_NUM_KEY;
  2777.         if (calc_menu_event == GUI_CALC_PEN_HIGHLIGHT_CHANGED)
  2778.         {
  2779.             gui_BLT_double_buffer(
  2780.                 TOUCH_CALC_SCREEN_X,
  2781.                 TOUCH_CALC_SCREEN_Y,
  2782.                 UI_device_width - 1,
  2783.                 TOUCH_CALC_SCREEN_Y + TOUCH_CALC_SCREEN_HEIGHT - 1);
  2784.         }
  2785.     }
  2786. }
  2787. /*****************************************************************************
  2788.  * FUNCTION
  2789.  *  mmi_touchcalc_pen_up_hdlr
  2790.  * DESCRIPTION
  2791.  *  
  2792.  * PARAMETERS
  2793.  *  point       [IN]        
  2794.  * RETURNS
  2795.  *  void
  2796.  *****************************************************************************/
  2797. void mmi_touchcalc_pen_up_hdlr(mmi_pen_point_struct point)
  2798. {
  2799.     /*----------------------------------------------------------------*/
  2800.     /* Local Variables                                                */
  2801.     /*----------------------------------------------------------------*/
  2802.     gui_button_pen_enum button_event;
  2803.     gui_calc_pen_enum calc_menu_event;
  2804.     /*----------------------------------------------------------------*/
  2805.     /* Code Body                                                      */
  2806.     /*----------------------------------------------------------------*/
  2807.     switch (calc_pen_on_object)
  2808.     {
  2809.         case TOUCH_CALC_PEN_NUM_KEY:
  2810.             gui_calculator_translate_pen_event(
  2811.                 &calculator_keypad,
  2812.                 point.x,
  2813.                 point.y,
  2814.                 &calc_menu_event,
  2815.                 MMI_PEN_EVENT_UP);
  2816.             if (calc_menu_event == GUI_CALC_PEN_HIGHLIGHT_CHANGED)
  2817.             {
  2818.                 gui_BLT_double_buffer(
  2819.                     TOUCH_CALC_SCREEN_X,
  2820.                     TOUCH_CALC_SCREEN_Y,
  2821.                     UI_device_width - 1,
  2822.                     TOUCH_CALC_SCREEN_Y + TOUCH_CALC_SCREEN_HEIGHT - 1);
  2823.             }
  2824.             break;
  2825.         case TOUCH_CALC_PEN_LSK:
  2826.             translate_softkey_pen_event(MMI_LEFT_SOFTKEY, MMI_PEN_EVENT_UP, point.x, point.y, &button_event);
  2827.             if (button_event == GUI_BUTTON_PEN_UP_INSIDE)
  2828.             {
  2829.                 execute_softkey_function(KEY_EVENT_UP, MMI_LEFT_SOFTKEY);
  2830.             }
  2831.             break;
  2832.         case TOUCH_CALC_PEN_RSK:
  2833.             translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_UP, point.x, point.y, &button_event);
  2834.             if (button_event == GUI_BUTTON_PEN_UP_INSIDE)
  2835.             {
  2836.                 execute_softkey_function(KEY_EVENT_UP, MMI_RIGHT_SOFTKEY);
  2837.             }
  2838.             break;
  2839.     }
  2840.     calc_pen_on_object = TOUCH_CALC_PEN_NONE;
  2841. }
  2842. /*****************************************************************************
  2843.  * FUNCTION
  2844.  *  mmi_touchcalc_pen_move_hdlr
  2845.  * DESCRIPTION
  2846.  *  
  2847.  * PARAMETERS
  2848.  *  point       [IN]        
  2849.  * RETURNS
  2850.  *  void
  2851.  *****************************************************************************/
  2852. void mmi_touchcalc_pen_move_hdlr(mmi_pen_point_struct point)
  2853. {
  2854.     /*----------------------------------------------------------------*/
  2855.     /* Local Variables                                                */
  2856.     /*----------------------------------------------------------------*/
  2857.     S16 x1, x2, y1, y2;
  2858.     gui_calc_pen_enum calc_menu_event;
  2859.     gui_button_pen_enum button_event;
  2860.     /*----------------------------------------------------------------*/
  2861.     /* Code Body                                                      */
  2862.     /*----------------------------------------------------------------*/
  2863.     switch (calc_pen_on_object)
  2864.     {
  2865.         case TOUCH_CALC_PEN_NUM_KEY:
  2866.             gui_calculator_translate_pen_event(
  2867.                 &calculator_keypad,
  2868.                 point.x,
  2869.                 point.y,
  2870.                 &calc_menu_event,
  2871.                 MMI_PEN_EVENT_MOVE);
  2872.             if (calc_menu_event == GUI_CALC_PEN_HIGHLIGHT_CHANGED)
  2873.             {
  2874.                 TOUCH_CALC_SELECT_KEY = FALSE;
  2875.                 x1 = calculator_keypad.selected_key_x;
  2876.                 y1 = calculator_keypad.selected_key_y;
  2877.                 x2 = x1 + calculator_keypad.key_width;
  2878.                 y2 = y1 + calculator_keypad.key_height;
  2879.                 gdi_layer_push_clip();
  2880.                 gdi_layer_set_clip(x1, y1, x2, y2);
  2881.                 gdi_image_cache_bmp_draw(x1, y1, &calculator_keypad.selected_key_bitmap);
  2882.                 gdi_layer_pop_clip();
  2883.                 gui_BLT_double_buffer(
  2884.                     TOUCH_CALC_SCREEN_X,
  2885.                     TOUCH_CALC_SCREEN_Y,
  2886.                     UI_device_width - 1,
  2887.                     TOUCH_CALC_SCREEN_Y + TOUCH_CALC_SCREEN_HEIGHT - 1);
  2888.             }
  2889.             gui_BLT_double_buffer(
  2890.                 TOUCH_CALC_SCREEN_X,
  2891.                 TOUCH_CALC_SCREEN_Y,
  2892.                 UI_device_width - 1,
  2893.                 TOUCH_CALC_SCREEN_Y + TOUCH_CALC_SCREEN_HEIGHT - 1);
  2894.             break;
  2895.         case TOUCH_CALC_PEN_LSK:
  2896.             translate_softkey_pen_event(MMI_LEFT_SOFTKEY, MMI_PEN_EVENT_MOVE, point.x, point.y, &button_event);
  2897.             break;
  2898.         case TOUCH_CALC_PEN_RSK:
  2899.             translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_MOVE, point.x, point.y, &button_event);
  2900.             break;
  2901.     }
  2902. }
  2903. /*****************************************************************************
  2904.  * FUNCTION
  2905.  *  mmi_touchcalc_pen_repeat_hdlr
  2906.  * DESCRIPTION
  2907.  *  
  2908.  * PARAMETERS
  2909.  *  point       [IN]        
  2910.  * RETURNS
  2911.  *  void
  2912.  *****************************************************************************/
  2913. void mmi_touchcalc_pen_repeat_hdlr(mmi_pen_point_struct point)
  2914. {
  2915.     /*----------------------------------------------------------------*/
  2916.     /* Local Variables                                                */
  2917.     /*----------------------------------------------------------------*/
  2918.     gui_calc_pen_enum calc_menu_event;
  2919.     /*----------------------------------------------------------------*/
  2920.     /* Code Body                                                      */
  2921.     /*----------------------------------------------------------------*/
  2922.     if (calculator_keypad.flag == CALC_PEN_DOWN_ON_KEYPAD)
  2923.     {
  2924.         gui_calculator_translate_pen_event(
  2925.             &calculator_keypad,
  2926.             point.x,
  2927.             point.y,
  2928.             &calc_menu_event,
  2929.             MMI_PEN_EVENT_REPEAT);
  2930.         if (calc_menu_event == GUI_CALC_PEN_HIGHLIGHT_CHANGED)
  2931.         {
  2932.             gui_BLT_double_buffer(
  2933.                 TOUCH_CALC_SCREEN_X,
  2934.                 TOUCH_CALC_SCREEN_Y,
  2935.                 UI_device_width - 1,
  2936.                 TOUCH_CALC_SCREEN_Y + TOUCH_CALC_SCREEN_HEIGHT - 1);
  2937.         }
  2938.     }
  2939. }
  2940. /*****************************************************************************
  2941.  * FUNCTION
  2942.  *  mmi_touchcalc_pen_long_tap_hdlr
  2943.  * DESCRIPTION
  2944.  *  
  2945.  * PARAMETERS
  2946.  *  point       [IN]        
  2947.  * RETURNS
  2948.  *  void
  2949.  *****************************************************************************/
  2950. void mmi_touchcalc_pen_long_tap_hdlr(mmi_pen_point_struct point)
  2951. {
  2952.     /*----------------------------------------------------------------*/
  2953.     /* Local Variables                                                */
  2954.     /*----------------------------------------------------------------*/
  2955.     gui_button_pen_enum button_event;
  2956.     /*----------------------------------------------------------------*/
  2957.     /* Code Body                                                      */
  2958.     /*----------------------------------------------------------------*/
  2959.     if (calc_pen_on_object == TOUCH_CALC_PEN_RSK)
  2960.     {
  2961.         translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_LONG_TAP, point.x, point.y, &button_event);
  2962.         if (button_event == GUI_BUTTON_PEN_LONGTAP)
  2963.         {
  2964.             execute_softkey_function(KEY_LONG_PRESS, MMI_RIGHT_SOFTKEY);
  2965.         }
  2966.     }
  2967. }
  2968. /*****************************************************************************
  2969.  * FUNCTION
  2970.  *  setup_calculator_keypad
  2971.  * DESCRIPTION
  2972.  *  
  2973.  * PARAMETERS
  2974.  *  calculator_keypad       [?]         
  2975.  *  x                       [IN]        
  2976.  *  y                       [IN]        
  2977.  * RETURNS
  2978.  *  void
  2979.  *****************************************************************************/
  2980. void setup_calculator_keypad(calculator_keypad_struct *calculator_keypad, S16 x, S16 y)
  2981. {
  2982.     /*----------------------------------------------------------------*/
  2983.     /* Local Variables                                                */
  2984.     /*----------------------------------------------------------------*/
  2985.     /*----------------------------------------------------------------*/
  2986.     /* Code Body                                                      */
  2987.     /*----------------------------------------------------------------*/
  2988.     calculator_keypad->result_area_x = x + CALC_TOUCH_RESULT_AREA_X;
  2989.     calculator_keypad->result_area_y = y + CALC_TOUCH_RESULT_AREA_Y;
  2990.     calculator_keypad->keypad_x = calculator_keypad->result_area_x;
  2991.     calculator_keypad->keypad_y = calculator_keypad->result_area_y + CALC_TOUCH_RESULT_AREA_HEIGHT + CALC_TOUCH_RESULT_KEYPAD_GAP;      /* 041205 Calvin modified */
  2992.     calculator_keypad->keypad_width = CALC_TOUCH_KEYPAD_WIDTH;
  2993.     calculator_keypad->keypad_height = CALC_TOUCH_KEYPAD_HEIGHT;
  2994.     calculator_keypad->key_width = CALC_TOUCH_KEY_WIDTH;
  2995.     calculator_keypad->key_height = CALC_TOUCH_KEY_HEIGHT;
  2996.     calculator_keypad->key_type = MMI_CALC_KEY_NONE;
  2997.     calculator_keypad->horizontal_gap = CALC_TOUCH_HORIZONTAL_GAP;
  2998.     calculator_keypad->vertical_gap = CALC_TOUCH_VERTICAL_GAP;
  2999.     calculator_keypad->n_column = CALC_TOUCH_NCOLUMNS;
  3000.     calculator_keypad->n_rows = CALC_TOUCH_NROWS;
  3001.     calculator_keypad->operand1_y = calculator_keypad->result_area_y + CALC_TOUCH_OPERAND1_Y;
  3002.     calculator_keypad->operand2_y = calculator_keypad->result_area_y + CALC_TOUCH_OPERAND2_Y;
  3003.     calculator_keypad->operator_x = calculator_keypad->result_area_x + CALC_TOUCH_OPERATOR_X;
  3004.     calculator_keypad->operator_y = calculator_keypad->operand2_y;
  3005.     calculator_keypad->mem_x1 = calculator_keypad->result_area_x + TOUCH_CALC_MEM_X1;
  3006.     calculator_keypad->mem_y1 = calculator_keypad->result_area_y + TOUCH_CALC_MEM_Y1;
  3007.     calculator_keypad->flag = 0;
  3008. }
  3009. /*****************************************************************************
  3010.  * FUNCTION
  3011.  *  show_touch_calculator_screen
  3012.  * DESCRIPTION
  3013.  *  
  3014.  * PARAMETERS
  3015.  *  x1          [IN]        
  3016.  *  y1          [IN]        
  3017.  *  width       [IN]        
  3018.  *  height      [IN]        
  3019.  * RETURNS
  3020.  *  void
  3021.  *****************************************************************************/
  3022. void show_touch_calculator_screen(S32 x1, S32 y1, S32 width, S32 height)
  3023. {
  3024.     /*----------------------------------------------------------------*/
  3025.     /* Local Variables                                                */
  3026.     /*----------------------------------------------------------------*/
  3027.     S32 x2, y2;
  3028.     /*----------------------------------------------------------------*/
  3029.     /* Code Body                                                      */
  3030.     /*----------------------------------------------------------------*/
  3031.     x2 = x1 + width - 1;
  3032.     y2 = y1 + height - 1;
  3033.     gdi_layer_push_clip();
  3034.     gdi_layer_set_clip(x1, y1, x2, y2);
  3035.     gui_show_image(x1, y1, (PU8) GetImage(IMG_ID_TOUCH_CALC_MAIN));
  3036.     gdi_layer_pop_clip();
  3037.     gui_BLT_double_buffer(x1, y1, x2, y2);
  3038. }
  3039. /*****************************************************************************
  3040.  * FUNCTION
  3041.  *  gui_calculator_translate_pen_position
  3042.  * DESCRIPTION
  3043.  *  
  3044.  * PARAMETERS
  3045.  *  calculator_keypad       [?]         
  3046.  *  x                       [IN]        
  3047.  *  y                       [IN]        
  3048.  *  item_index              [?]         
  3049.  *  key_variable            [?]         
  3050.  * RETURNS
  3051.  *  void
  3052.  *****************************************************************************/
  3053. void gui_calculator_translate_pen_position(
  3054.         calculator_keypad_struct *calculator_keypad,
  3055.         S32 x,
  3056.         S32 y,
  3057.         S32 *item_index,
  3058.         S32 *key_variable)
  3059. {
  3060.     /*----------------------------------------------------------------*/
  3061.     /* Local Variables                                                */
  3062.     /*----------------------------------------------------------------*/
  3063.     S32 total_height = 0, total_width = 0;
  3064.     S32 i, j;
  3065.     /*----------------------------------------------------------------*/
  3066.     /* Code Body                                                      */
  3067.     /*----------------------------------------------------------------*/
  3068.     total_height = 0;
  3069.     total_width = 0;
  3070.     x = x - calculator_keypad->keypad_x + 1;
  3071.     y = y - calculator_keypad->keypad_y + 1;
  3072.     for (i = 0; i < calculator_keypad->n_rows; i++)
  3073.     {
  3074.         total_height += calculator_keypad->key_height;
  3075.         if (total_height >= y)
  3076.         {
  3077.             for (j = 0; j < calculator_keypad->n_column; j++)
  3078.             {
  3079.                 total_width += calculator_keypad->key_width;
  3080.                 if (total_width >= x)
  3081.                 {
  3082.                     *item_index = i * calculator_keypad->n_column + j + 1;
  3083.                     *key_variable = TouchCalcKeys[i][j];
  3084.                     calculator_keypad->selected_key_x =
  3085.                         calculator_keypad->keypad_x + (calculator_keypad->key_width) * j +
  3086.                         (calculator_keypad->horizontal_gap) * j;
  3087.                     calculator_keypad->selected_key_y =
  3088.                         calculator_keypad->keypad_y + (calculator_keypad->key_height) * i +
  3089.                         (calculator_keypad->vertical_gap) * i;
  3090.                     if (i == 0 || j == (calculator_keypad->n_column - 1) ||
  3091.                         (*key_variable == TOUCH_CALC_OP_EQUAL && i == calculator_keypad->n_rows - 1))
  3092.                     {
  3093.                         calculator_keypad->key_type = MMI_CALC_SYM_KEY;
  3094.                     }
  3095.                     else
  3096.                     {
  3097.                         calculator_keypad->key_type = MMI_CALC_NUM_KEY;
  3098.                     }
  3099.                     break;
  3100.                 }
  3101.                 else
  3102.                 {
  3103.                     total_width += calculator_keypad->horizontal_gap;
  3104.                     if (total_width >= x)
  3105.                     {
  3106.                         *item_index = -1;
  3107.                         return;
  3108.                     }
  3109.                 }
  3110.             }
  3111.             break;
  3112.         }
  3113.         else
  3114.         {
  3115.             total_height += calculator_keypad->vertical_gap;
  3116.             if (total_height >= y)
  3117.             {
  3118.                 *item_index = -1;
  3119.                 return;
  3120.             }
  3121.         }
  3122.     }
  3123. }
  3124. /*****************************************************************************
  3125.  * FUNCTION
  3126.  *  gui_calculator_key_select
  3127.  * DESCRIPTION
  3128.  *  
  3129.  * PARAMETERS
  3130.  *  calculator_keypad       [?]         
  3131.  *  item_index              [IN]        
  3132.  * RETURNS
  3133.  *  void
  3134.  *****************************************************************************/
  3135. void gui_calculator_key_select(calculator_keypad_struct *calculator_keypad, S32 item_index)
  3136. {
  3137.     /*----------------------------------------------------------------*/
  3138.     /* Local Variables                                                */
  3139.     /*----------------------------------------------------------------*/
  3140.     S32 x1, y1, x2, y2;
  3141.     S32 width, height;
  3142.     MMI_ID_TYPE image_id;
  3143.     /*----------------------------------------------------------------*/
  3144.     /* Code Body                                                      */
  3145.     /*----------------------------------------------------------------*/
  3146.     x1 = calculator_keypad->selected_key_x;
  3147.     y1 = calculator_keypad->selected_key_y;
  3148.     x2 = x1 + calculator_keypad->key_width - 1;
  3149.     y2 = y1 + calculator_keypad->key_height - 1;
  3150.     calculator_keypad->selected_key_bitmap.buf_ptr = (U8*) matrix_main_menu_highlight_bitmap_data;
  3151.     memset(
  3152.         calculator_keypad->selected_key_bitmap.buf_ptr,
  3153.         0,
  3154.         (calculator_keypad->key_width) * (calculator_keypad->key_height) * 2);
  3155.     gdi_layer_push_clip();
  3156.     gdi_layer_set_clip(x1, y1, x2, y2);
  3157.     gdi_image_cache_bmp_get(x1, y1, x2, y2, &calculator_keypad->selected_key_bitmap);
  3158.     gdi_layer_pop_clip();
  3159.     gdi_layer_push_clip();
  3160.     gdi_layer_set_clip(x1, y1, x2, y2);
  3161.     image_id = calculator_key_image[item_index - 1];
  3162.     gui_measure_image(get_image(image_id), &width, &height);
  3163.     x1 = x1 + ((calculator_keypad->key_width >> 1) - (width >> 1));
  3164.     y1 = y1 + ((calculator_keypad->key_height >> 1) - (height >> 1));
  3165.     gui_show_image(x1, y1, get_image(image_id));
  3166.     gdi_layer_pop_clip();
  3167. }
  3168. /*****************************************************************************
  3169.  * FUNCTION
  3170.  *  gui_calculator_key_unselect
  3171.  * DESCRIPTION
  3172.  *  
  3173.  * PARAMETERS
  3174.  *  calculator_keypad       [?]     
  3175.  * RETURNS
  3176.  *  void
  3177.  *****************************************************************************/
  3178. void gui_calculator_key_unselect(calculator_keypad_struct *calculator_keypad)
  3179. {
  3180.     /*----------------------------------------------------------------*/
  3181.     /* Local Variables                                                */
  3182.     /*----------------------------------------------------------------*/
  3183.     S16 x1, x2, y1, y2;
  3184.     /*----------------------------------------------------------------*/
  3185.     /* Code Body                                                      */
  3186.     /*----------------------------------------------------------------*/
  3187.     x1 = calculator_keypad->selected_key_x;
  3188.     y1 = calculator_keypad->selected_key_y;
  3189.     x2 = x1 + calculator_keypad->key_width - 1;
  3190.     y2 = y1 + calculator_keypad->key_height - 1;
  3191.     gdi_layer_push_clip();
  3192.     gdi_layer_set_clip(x1, y1, x2, y2);
  3193.     gdi_image_cache_bmp_draw(x1, y1, &calculator_keypad->selected_key_bitmap);
  3194.     calculator_keypad->selected_key_x = 0;
  3195.     calculator_keypad->selected_key_y = 0;
  3196.     gdi_layer_pop_clip();
  3197. }
  3198. /*****************************************************************************
  3199.  * FUNCTION
  3200.  *  gui_calculator_translate_pen_event
  3201.  * DESCRIPTION
  3202.  *  
  3203.  * PARAMETERS
  3204.  *  calculator_keypad       [?]         
  3205.  *  x                       [IN]        
  3206.  *  y                       [IN]        
  3207.  *  menu_event              [?]         
  3208.  *  pen_event               [IN]        
  3209.  * RETURNS
  3210.  *  
  3211.  *****************************************************************************/
  3212. BOOL gui_calculator_translate_pen_event(
  3213.         calculator_keypad_struct *calculator_keypad,
  3214.         S32 x,
  3215.         S32 y,
  3216.         gui_calc_pen_enum *menu_event,
  3217.         mmi_pen_event_type_enum pen_event)
  3218. {
  3219.     /*----------------------------------------------------------------*/
  3220.     /* Local Variables                                                */
  3221.     /*----------------------------------------------------------------*/
  3222.     S32 x1, y1;
  3223.     BOOL ret;
  3224.     S32 item_index, key_variable;
  3225.     /*----------------------------------------------------------------*/
  3226.     /* Code Body                                                      */
  3227.     /*----------------------------------------------------------------*/
  3228.     x1 = calculator_keypad->keypad_x;
  3229.     y1 = calculator_keypad->keypad_y;
  3230.     ret = TRUE;
  3231.     *menu_event = GUI_CALC_PEN_NONE;
  3232.     switch (pen_event)
  3233.     {
  3234.         case MMI_PEN_EVENT_DOWN:
  3235.             if (PEN_CHECK_BOUND(x, y, x1, y1, calculator_keypad->keypad_width, calculator_keypad->keypad_height))
  3236.             {
  3237.                 gui_calculator_translate_pen_position(calculator_keypad, x, y, &item_index, &key_variable);
  3238.                 if (item_index > MMI_CALC_KEY_START && item_index <= MMI_CALC_KEY_END)
  3239.                 {
  3240.                     calculator_keypad->flag |= CALC_PEN_DOWN_ON_KEYPAD;
  3241.                     gui_calculator_key_select(calculator_keypad, item_index);
  3242.                     if (calculator_keypad->key_type == MMI_CALC_NUM_KEY)
  3243.                     {
  3244.                         *menu_event = GUI_CALC_PEN_HIGHLIGHT_CHANGED;
  3245.                         if (key_variable == TOUCH_CALC_KEY_DOT && g_calc_cntx->ResultState == RESULT_NOT_EXCEED)        /* should not be called if result is exceded..no change on pressing Dot */
  3246.                         {
  3247.                             CalcHandlePoundKey();
  3248.                         }
  3249.                         else
  3250.                         {
  3251.                             CalcHandleNumKey(key_variable);
  3252.                         }
  3253.                     }
  3254.                     else if (calculator_keypad->key_type == MMI_CALC_SYM_KEY)
  3255.                     {
  3256.                         *menu_event = GUI_CALC_PEN_HIGHLIGHT_CHANGED;
  3257.                         g_calc_cntx->CurrHilite = key_variable;
  3258.                         if (key_variable == TOUCH_CALC_OP_EQUAL)
  3259.                         {
  3260.                             CalcComputeResult();
  3261.                         }
  3262.                         else if (key_variable >= TOUCH_CALC_OP_MP && key_variable <= TOUCH_CALC_OP_MR && g_calc_cntx->ResultState == RESULT_NOT_EXCEED) /* should not be called if result is exceded..no change on pressing these buttons */
  3263.                         {
  3264.                             if (g_calc_cntx->OpToExecute < CALC_OP_EQUAL)
  3265.                             {
  3266.                                 CalcGetPreOperand();
  3267.                                 if ((g_calc_cntx->Operand2 == 0) && (g_calc_cntx->OpToExecute == CALC_OP_DIV))
  3268.                                 {
  3269.                                     g_calc_cntx->ResultState = RESULT_EXCEED;
  3270.                                     CalcSetRSKClear();
  3271.                                     g_calc_cntx->Operator = CALC_OP_NONE;
  3272.                                     playRequestedTone(ERROR_TONE);
  3273.                                 }
  3274.                                 else
  3275.                                 {
  3276.                                     g_calc_cntx->Operand1 = CalcExecOperator(g_calc_cntx->Operand1, g_calc_cntx->Operand2);
  3277.                                     g_calc_cntx->OpToExecute = CALC_OP_NONE;
  3278.                                 }
  3279.                             }
  3280.                             else
  3281.                             {
  3282.                                 CalcHandleHiliteOperator();
  3283.                             }
  3284.                             CalcHandleHiliteMemoryButton();
  3285.                             if (g_calc_cntx->ResultState == RESULT_EXCEED)
  3286.                             {
  3287.                                 playRequestedTone(ERROR_TONE);
  3288.                             }
  3289.                             CalcComputeResult();
  3290.                         }
  3291.                         else
  3292.                         {
  3293.                             CalcHandleHiliteOperator();
  3294.                             if (g_calc_cntx->ResultState == RESULT_EXCEED)
  3295.                             {
  3296.                                 playRequestedTone(ERROR_TONE);
  3297.                             }
  3298.                             CalcShowResultScreen();
  3299.                         }
  3300.                     }
  3301.                 }
  3302.                 else
  3303.                 {
  3304.                     ret = FALSE;
  3305.                 }
  3306.             }
  3307.             else
  3308.             {
  3309.                 ret = FALSE;
  3310.             }
  3311.             break;
  3312.         case MMI_PEN_EVENT_UP:
  3313.             calculator_keypad->flag &= ~CALC_PEN_DOWN_ON_KEYPAD;
  3314.             TOUCH_CALC_SELECT_KEY = TRUE;
  3315.             if (PEN_CHECK_BOUND
  3316.                 (x, y, calculator_keypad->selected_key_x, calculator_keypad->selected_key_y,
  3317.                  calculator_keypad->key_width, calculator_keypad->key_height))
  3318.             {
  3319.                 *menu_event = GUI_CALC_PEN_HIGHLIGHT_CHANGED;
  3320.                 gui_calculator_key_unselect(calculator_keypad);
  3321.             }
  3322.             else if (TOUCH_CALC_SELECT_KEY)
  3323.             {
  3324.                 gui_calculator_key_unselect(calculator_keypad);
  3325.             }
  3326.             break;
  3327.         case MMI_PEN_EVENT_MOVE:
  3328.             if ((!PEN_CHECK_BOUND
  3329.                  (x, y, calculator_keypad->selected_key_x, calculator_keypad->selected_key_y,
  3330.                   calculator_keypad->key_width, calculator_keypad->key_height)))
  3331.             {
  3332.                 *menu_event = GUI_CALC_PEN_HIGHLIGHT_CHANGED;
  3333.                 TOUCH_CALC_SELECT_KEY = FALSE;
  3334.             }
  3335.             else if (PEN_CHECK_BOUND
  3336.                      (x, y, calculator_keypad->selected_key_x, calculator_keypad->selected_key_y,
  3337.                       calculator_keypad->key_width, calculator_keypad->key_height))
  3338.             {
  3339.                 gui_calculator_translate_pen_position(calculator_keypad, x, y, &item_index, &key_variable);
  3340.                 if (!TOUCH_CALC_SELECT_KEY)
  3341.                 {
  3342.                     gui_calculator_key_select(calculator_keypad, item_index);
  3343.                 }
  3344.                 TOUCH_CALC_SELECT_KEY = TRUE;
  3345.             }
  3346.             break;
  3347.         case MMI_PEN_EVENT_LONG_TAP:
  3348.             break;
  3349.         case MMI_PEN_EVENT_REPEAT:
  3350.             if (PEN_CHECK_BOUND
  3351.                 (x, y, calculator_keypad->selected_key_x, calculator_keypad->selected_key_y,
  3352.                  calculator_keypad->key_width, calculator_keypad->key_height))
  3353.             {
  3354.                 gui_calculator_translate_pen_position(calculator_keypad, x, y, &item_index, &key_variable);
  3355.                 if (calculator_keypad->key_type == MMI_CALC_NUM_KEY)
  3356.                 {
  3357.                     *menu_event = GUI_CALC_PEN_HIGHLIGHT_CHANGED;
  3358.                     if (key_variable == TOUCH_CALC_KEY_DOT)
  3359.                     {
  3360.                         CalcHandlePoundKey();
  3361.                     }
  3362.                     else
  3363.                     {
  3364.                         CalcHandleNumKey(key_variable);
  3365.                     }
  3366.                 }
  3367.             }
  3368.             break;
  3369.     }
  3370.     return ret;
  3371. }
  3372. #endif /* __MMI_TOUCH_CALCULATOR__ */ /* __MMI_TOUCH_SCREEN */
  3373. #endif /* __MMI_CALCULATOR__ */ 
  3374. #endif /* _MMI_CALCULATOR_C */ // #ifndef _MMI_CALCULATOR_C