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

MTK

开发平台:

C/C++

  1.     ResetTextFormat(&wgui_EMS_text_format);
  2. }
  3. #if(EMS_USE_CRLF_COMBINATION || EMS_USE_ESC_COMBINATION)
  4. /*****************************************************************************
  5.  * FUNCTION
  6.  *  gui_EMS_input_box_delete
  7.  * DESCRIPTION
  8.  *  
  9.  * PARAMETERS
  10.  *  b       [?]     
  11.  * RETURNS
  12.  *  void
  13.  *****************************************************************************/
  14. void gui_EMS_input_box_delete(UI_EMS_input_box *b)
  15. {
  16.     /*----------------------------------------------------------------*/
  17.     /* Local Variables                                                */
  18.     /*----------------------------------------------------------------*/
  19.     /*----------------------------------------------------------------*/
  20.     /* Code Body                                                      */
  21.     /*----------------------------------------------------------------*/
  22. #ifdef __MMI_MESSAGES_EMS__
  23.     EMS_cancel_object_focus();
  24. #endif 
  25.     if (UI_TEST_CR_CHARACTER(b->data->textBuffer[b->data->CurrentPosition.OffsetToText]))
  26.     {
  27.         if (ForwardCurrentPosition(b->data, 1) == 1)
  28.         {
  29.             if (!UI_TEST_LF_CHARACTER(b->data->textBuffer[b->data->CurrentPosition.OffsetToText]))
  30.             {
  31.                 BackwardCurrentPosition(b->data, 1);
  32.             }
  33.         }
  34.     }
  35.     if (gui_EMS_input_box_forward_cursor(b) == 1)
  36.     {
  37.         gui_EMS_cancel_current_position(b);
  38.         gui_EMS_input_box_set_text_format_cursor_position(b);
  39.         gui_EMS_input_box_locate_cursor(b);
  40.     }
  41.     else
  42.     {
  43.         UI_editor_play_tone_cannot_change();
  44.     }
  45.     b->saved_cursor_ax = -1;
  46. }
  47. /*****************************************************************************
  48.  * FUNCTION
  49.  *  gui_EMS_input_box_previous
  50.  * DESCRIPTION
  51.  *  
  52.  * PARAMETERS
  53.  *  b       [?]     
  54.  * RETURNS
  55.  *  void
  56.  *****************************************************************************/
  57. void gui_EMS_input_box_previous(UI_EMS_input_box *b)
  58. {
  59. #if defined(__MMI_LANG_VIETNAMESE__)
  60.     /*----------------------------------------------------------------*/
  61.     /* Local Variables                                                */
  62.     /*----------------------------------------------------------------*/
  63.     EMSPosition mapped_cursor_position;
  64.     UI_character_type current_character, dummy_c = 0;
  65.     EMSData *data = b->data;
  66.     EMSObject *current_object;
  67.     U8 object_type;
  68.     viet_tone_mark tone_mark = VIET_TONE_NONE;
  69.     viet_vowel_letter viet_vowel = VIET_VOWEL_NONE;
  70. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  71.     /* MTK Add Steven 20050505  */
  72. #if defined(__MMI_LANG_THAI__)
  73.     EMSPosition mapped_cursor_position_thai;
  74.     UI_character_type current_character_thai, dummy_c_thai = 0;
  75.     EMSData *data_thai = b->data;
  76.     EMSObject *current_object_thai;
  77.     U8 object_type_thai;
  78.     UI_character_type pre_one_char = 0;
  79.     UI_character_type pre_two_char = 0;
  80.     UI_character_type pre_three_char = 0;
  81. #endif /* defined(__MMI_LANG_THAI__) */ 
  82.     /* MTK End */
  83. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  84.     EMSPosition mapped_cursor_position_arabic;
  85.     UI_character_type current_character_arabic, dummy_c_arabic = 0;
  86.     EMSData *data_arabic = b->data;
  87.     EMSObject *current_object_arabic;
  88.     U8 object_type_arabic;
  89.     S32 saved_text_len = 0;
  90. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  91.     /*----------------------------------------------------------------*/
  92.     /* Code Body                                                      */
  93.     /*----------------------------------------------------------------*/
  94.     /* MTK End */
  95. #ifdef __MMI_MESSAGES_EMS__
  96.     EMS_cancel_object_focus();
  97. #endif 
  98. #if defined(__MMI_LANG_VIETNAMESE__)
  99.     EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  100.     object_type = gui_EMS_input_box_get_previous_object(data, &mapped_cursor_position, &current_character, &current_object);
  101.     if (1 == object_type)
  102.     {
  103.         if ((current_character >= 0x0300) && (current_character <= 0x0323))
  104.         {
  105.             object_type = gui_EMS_input_box_get_previous_object(data, &mapped_cursor_position, &dummy_c, &current_object);      /* get next character */
  106.             if (1 == object_type)
  107.             {
  108.                 viet_vowel = mmi_viet_vowel_letter(dummy_c);
  109.                 if (VIET_VOWEL_NONE != viet_vowel)
  110.                 {
  111.                     tone_mark = mmi_viet_tone_mark(current_character);
  112.                     if (VIET_TONE_NONE != tone_mark)
  113.                     {
  114.                         current_character = mmi_viet_combine_vowel_tone(viet_vowel, tone_mark);
  115.                         BackwardCurrentPositionSkipCR(b->data);
  116.                     }
  117.                     else
  118.                     {
  119.                         object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  120.                     }
  121.                 }
  122.                 else
  123.                 {
  124.                     object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  125.                 }
  126.             }
  127.             else if (0 != object_type)
  128.             {
  129.                 object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  130.             }
  131.         }
  132.     }
  133. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  134.     /* MTK Steven 20050505 */
  135. #if defined(__MMI_LANG_THAI__)
  136.     EMS_map_position(data_thai, &data_thai->CurrentPosition, &mapped_cursor_position_thai);
  137.     object_type_thai = gui_EMS_input_box_get_previous_object(
  138.                         data_thai,
  139.                         &mapped_cursor_position_thai,
  140.                         &current_character_thai,
  141.                         &current_object_thai);
  142.     if (object_type_thai == 1 && isThaiChar(current_character_thai))    /* object type == 1 --> character */
  143.     {
  144.         object_type_thai = gui_EMS_input_box_get_previous_object(
  145.                             data_thai,
  146.                             &mapped_cursor_position_thai,
  147.                             &pre_one_char,
  148.                             &current_object_thai);
  149.         if (object_type_thai == 1 && isThaiChar(pre_one_char))
  150.         {
  151.             if (!RequireToMoveCursor(pre_one_char, current_character_thai))
  152.             {
  153.                 BackwardCurrentPositionSkipCR(b->data);
  154.                 object_type_thai = gui_EMS_input_box_get_previous_object(
  155.                                     data_thai,
  156.                                     &mapped_cursor_position_thai,
  157.                                     &pre_two_char,
  158.                                     &current_object_thai);
  159.                 if (object_type_thai == 1 && isThaiChar(pre_two_char))
  160.                 {
  161.                     if (!RequireToMoveCursor(pre_two_char, pre_one_char))
  162.                     {
  163.                         BackwardCurrentPositionSkipCR(b->data);
  164.                         object_type_thai = gui_EMS_input_box_get_previous_object(
  165.                                             data_thai,
  166.                                             &mapped_cursor_position_thai,
  167.                                             &pre_three_char,
  168.                                             &current_object_thai);
  169.                         if (object_type_thai == 1 && isThaiChar(pre_three_char))
  170.                         {
  171.                             if (!RequireToMoveCursor(pre_three_char, pre_two_char))
  172.                             {
  173.                                 BackwardCurrentPositionSkipCR(b->data);
  174.                             }
  175.                             else
  176.                             {
  177.                                 object_type_thai = gui_EMS_input_box_get_next_object(
  178.                                                     data_thai,
  179.                                                     &mapped_cursor_position_thai,
  180.                                                     &dummy_c_thai,
  181.                                                     &current_object_thai);
  182.                             }
  183.                         }
  184.                         else
  185.                         {
  186.                             object_type_thai = gui_EMS_input_box_get_next_object(
  187.                                                 data_thai,
  188.                                                 &mapped_cursor_position_thai,
  189.                                                 &dummy_c_thai,
  190.                                                 &current_object_thai);
  191.                         }
  192.                     }
  193.                     else
  194.                     {
  195.                         object_type_thai = gui_EMS_input_box_get_next_object(
  196.                                             data_thai,
  197.                                             &mapped_cursor_position_thai,
  198.                                             &dummy_c_thai,
  199.                                             &current_object_thai);
  200.                     }
  201.                 }
  202.                 else
  203.                 {
  204.                     object_type_thai = gui_EMS_input_box_get_next_object(
  205.                                         data_thai,
  206.                                         &mapped_cursor_position_thai,
  207.                                         &dummy_c_thai,
  208.                                         &current_object_thai);
  209.                 }
  210.             }
  211.             else
  212.             {
  213.                 object_type_thai = gui_EMS_input_box_get_next_object(
  214.                                     data_thai,
  215.                                     &mapped_cursor_position_thai,
  216.                                     &dummy_c_thai,
  217.                                     &current_object_thai);
  218.             }
  219.         }
  220.         else
  221.         {
  222.             object_type_thai = gui_EMS_input_box_get_next_object(
  223.                                 data_thai,
  224.                                 &mapped_cursor_position_thai,
  225.                                 &dummy_c_thai,
  226.                                 &current_object_thai);
  227.         }
  228.     }
  229. #endif /* defined(__MMI_LANG_THAI__) */ 
  230.     /* MTK End */
  231. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  232.     mapped_cursor_position_arabic.OffsetToText = data_arabic->CurrentPosition.OffsetToText;
  233.     mapped_cursor_position_arabic.Object = data_arabic->CurrentPosition.Object;
  234.     object_type_arabic = gui_EMS_input_box_get_previous_object(
  235.                             data_arabic,
  236.                             &mapped_cursor_position_arabic,
  237.                             &current_character_arabic,
  238.                             &current_object_arabic);
  239.     if (1 == object_type_arabic)
  240.     {
  241.         if (IS_ARABIC_CHARACTER(current_character_arabic))
  242.         {
  243.             U16 idx;
  244.             idx = gui_get_ems_text_actual_idx(b, data_arabic->CurrentPosition.OffsetToText) / 2 - 1;
  245.             while (idx > 0)
  246.             {
  247.                 if (OrgToSha[idx] == OrgToSha[idx - 1])
  248.                 {
  249.                     BackwardCurrentPositionSkipCR(b->data);
  250.                 }
  251.                 else
  252.                 {
  253.                     break;
  254.                 }
  255.                 idx--;
  256.             }
  257.         }
  258.     }
  259. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  260.     if (BackwardCurrentPositionSkipCR(b->data) != 1)
  261.     {
  262.         UI_editor_play_tone_cannot_navigate();
  263.     }
  264.     else
  265.     {
  266.         gui_EMS_input_box_set_text_format_cursor_position(b);
  267.         gui_EMS_input_box_locate_cursor(b);
  268.         b->saved_cursor_ax = -1;
  269.     }
  270. }
  271. /*****************************************************************************
  272.  * FUNCTION
  273.  *  gui_EMS_input_box_forward_cursor
  274.  * DESCRIPTION
  275.  *  
  276.  * PARAMETERS
  277.  *  b       [?]     
  278.  * RETURNS
  279.  *  
  280.  *****************************************************************************/
  281. U8 gui_EMS_input_box_forward_cursor(UI_EMS_input_box *b)
  282. {
  283.     /*----------------------------------------------------------------*/
  284.     /* Local Variables                                                */
  285.     /*----------------------------------------------------------------*/
  286.     /*----------------------------------------------------------------*/
  287.     /* Code Body                                                      */
  288.     /*----------------------------------------------------------------*/
  289.     if (b->data->CurrentPosition.OffsetToText <= (b->data->textLength))
  290.     {   /* START TARUN 20041212 */
  291.         if (ForwardCurrentPositionSkipCR(b->data) == 1)
  292.             //if(ForwardCurrentPositionSkipCR(b->data)>=1)
  293.             //END TARUN 20041212
  294.         {
  295.             return (1);
  296.         }
  297.     }
  298.     return (0);
  299. }
  300. /*****************************************************************************
  301.  * FUNCTION
  302.  *  gui_EMS_input_box_next
  303.  * DESCRIPTION
  304.  *  
  305.  * PARAMETERS
  306.  *  b       [?]     
  307.  * RETURNS
  308.  *  void
  309.  *****************************************************************************/
  310. void gui_EMS_input_box_next(UI_EMS_input_box *b)
  311. {
  312. #if defined(__MMI_LANG_VIETNAMESE__)
  313.     /*----------------------------------------------------------------*/
  314.     /* Local Variables                                                */
  315.     /*----------------------------------------------------------------*/
  316.     EMSPosition mapped_cursor_position;
  317.     UI_character_type current_character, dummy_c = 0;
  318.     EMSData *data = b->data;
  319.     EMSObject *current_object;
  320.     U8 object_type;
  321.     viet_tone_mark tone_mark = VIET_TONE_NONE;
  322.     viet_vowel_letter viet_vowel = VIET_VOWEL_NONE;
  323. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  324.     /* MTK Add Steven 20050505  */
  325. #if defined(__MMI_LANG_THAI__)
  326.     EMSPosition mapped_cursor_position_thai;
  327.     UI_character_type current_character_thai, dummy_c_thai = 0;
  328.     EMSData *data_thai = b->data;
  329.     EMSObject *current_object_thai;
  330.     U8 object_type_thai;
  331.     UI_character_type next_one_char = 0;
  332.     UI_character_type next_two_char = 0;
  333.     UI_character_type next_three_char = 0;
  334. #endif /* defined(__MMI_LANG_THAI__) */ 
  335.     /* MTK End */
  336. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  337.     EMSPosition mapped_cursor_position_arabic;
  338.     UI_character_type current_character_arabic, dummy_c_arabic = 0;
  339.     EMSData *data_arabic = b->data;
  340.     EMSObject *current_object_arabic;
  341.     U8 object_type_arabic;
  342.     S32 saved_text_len = 0;
  343. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  344.     /*----------------------------------------------------------------*/
  345.     /* Code Body                                                      */
  346.     /*----------------------------------------------------------------*/
  347.     /* MTK End */
  348. #ifdef __MMI_MESSAGES_EMS__
  349.     EMS_cancel_object_focus();
  350. #endif 
  351. #if defined(__MMI_LANG_VIETNAMESE__)
  352.     EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  353.     object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &current_character, &current_object);
  354.     if (1 == object_type)
  355.     {
  356.         if ((current_character > 0x0040) && (current_character < 0x01B1))
  357.         {
  358.             object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);  /* get next character */
  359.             if (1 == object_type)
  360.             {
  361.                 tone_mark = mmi_viet_tone_mark(dummy_c);
  362.                 if (VIET_TONE_NONE != tone_mark)
  363.                 {
  364.                     viet_vowel = mmi_viet_vowel_letter(current_character);
  365.                     if (VIET_VOWEL_NONE != viet_vowel)
  366.                     {
  367.                         current_character = mmi_viet_combine_vowel_tone(viet_vowel, tone_mark);
  368.                         gui_EMS_input_box_forward_cursor(b);
  369.                     }
  370.                     else
  371.                     {
  372.                         object_type = gui_EMS_input_box_get_previous_object(
  373.                                         data,
  374.                                         &mapped_cursor_position,
  375.                                         &dummy_c,
  376.                                         &current_object);
  377.                     }
  378.                 }
  379.                 else
  380.                 {
  381.                     object_type = gui_EMS_input_box_get_previous_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  382.                 }
  383.             }
  384.             else if (0 != object_type)
  385.             {
  386.                 object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  387.             }
  388.         }
  389.     }
  390. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  391.     /* MTK Steven 20050505 */
  392. #if defined(__MMI_LANG_THAI__)
  393.     EMS_map_position(data_thai, &data_thai->CurrentPosition, &mapped_cursor_position_thai);
  394.     object_type_thai = gui_EMS_input_box_get_next_object(
  395.                         data_thai,
  396.                         &mapped_cursor_position_thai,
  397.                         &current_character_thai,
  398.                         &current_object_thai);
  399.     if (object_type_thai == 1 && isThaiChar(current_character_thai))    /* object type == 1 --> character */
  400.     {
  401.         object_type_thai = gui_EMS_input_box_get_next_object(
  402.                             data_thai,
  403.                             &mapped_cursor_position_thai,
  404.                             &next_one_char,
  405.                             &current_object_thai);
  406.         if (object_type_thai == 1 && isThaiChar(next_one_char))
  407.         {
  408.             if (!RequireToMoveCursor(current_character_thai, next_one_char))
  409.             {
  410.                 gui_EMS_input_box_forward_cursor(b);
  411.                 object_type_thai = gui_EMS_input_box_get_next_object(
  412.                                     data_thai,
  413.                                     &mapped_cursor_position_thai,
  414.                                     &next_two_char,
  415.                                     &current_object_thai);
  416.                 if (object_type_thai == 1 && isThaiChar(next_two_char))
  417.                 {
  418.                     if (!RequireToMoveCursor(next_one_char, next_two_char))
  419.                     {
  420.                         gui_EMS_input_box_forward_cursor(b);
  421.                         object_type_thai = gui_EMS_input_box_get_next_object(
  422.                                             data_thai,
  423.                                             &mapped_cursor_position_thai,
  424.                                             &next_three_char,
  425.                                             &current_object_thai);
  426.                         if (object_type_thai == 1 && isThaiChar(next_three_char))
  427.                         {
  428.                             if (!RequireToMoveCursor(next_two_char, next_three_char))
  429.                             {
  430.                                 gui_EMS_input_box_forward_cursor(b);
  431.                             }
  432.                             else
  433.                             {
  434.                                 object_type_thai = gui_EMS_input_box_get_previous_object(
  435.                                                     data_thai,
  436.                                                     &mapped_cursor_position_thai,
  437.                                                     &dummy_c_thai,
  438.                                                     &current_object_thai);
  439.                             }
  440.                         }
  441.                         else
  442.                         {
  443.                             object_type_thai = gui_EMS_input_box_get_previous_object(
  444.                                                 data_thai,
  445.                                                 &mapped_cursor_position_thai,
  446.                                                 &dummy_c_thai,
  447.                                                 &current_object_thai);
  448.                         }
  449.                     }
  450.                     else
  451.                     {
  452.                         object_type_thai = gui_EMS_input_box_get_previous_object(
  453.                                             data_thai,
  454.                                             &mapped_cursor_position_thai,
  455.                                             &dummy_c_thai,
  456.                                             &current_object_thai);
  457.                     }
  458.                 }
  459.                 else
  460.                 {
  461.                     object_type_thai = gui_EMS_input_box_get_previous_object(
  462.                                         data_thai,
  463.                                         &mapped_cursor_position_thai,
  464.                                         &dummy_c_thai,
  465.                                         &current_object_thai);
  466.                 }
  467.             }
  468.             else
  469.             {
  470.                 object_type_thai = gui_EMS_input_box_get_previous_object(
  471.                                     data_thai,
  472.                                     &mapped_cursor_position_thai,
  473.                                     &dummy_c_thai,
  474.                                     &current_object_thai);
  475.             }
  476.         }
  477.         else
  478.         {
  479.             object_type_thai = gui_EMS_input_box_get_previous_object(
  480.                                 data_thai,
  481.                                 &mapped_cursor_position_thai,
  482.                                 &dummy_c_thai,
  483.                                 &current_object_thai);
  484.         }
  485.     }
  486. #endif /* defined(__MMI_LANG_THAI__) */ 
  487.     /* MTK End */
  488. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  489.     mapped_cursor_position_arabic.OffsetToText = data_arabic->CurrentPosition.OffsetToText;
  490.     mapped_cursor_position_arabic.Object = data_arabic->CurrentPosition.Object;
  491.     object_type_arabic = gui_EMS_input_box_get_next_object(
  492.                             data_arabic,
  493.                             &mapped_cursor_position_arabic,
  494.                             &current_character_arabic,
  495.                             &current_object_arabic);
  496.     if (1 == object_type_arabic)
  497.     {
  498.         if (IS_ARABIC_CHARACTER(current_character_arabic))
  499.         {
  500.             U16 idx;
  501.             U16 offset = 0;
  502.             if (mapped_cursor_position_arabic.Object != NULL)
  503.             {
  504.                 offset += 2;
  505.             }
  506.             idx = gui_get_ems_text_actual_idx(b, data_arabic->CurrentPosition.OffsetToText + offset);
  507.             if (idx != 0)
  508.             {
  509.                 idx = idx / 2 - 1;
  510.             }
  511.             while (idx < unshaped_text_len)
  512.             {
  513.                 if (OrgToSha[idx] == OrgToSha[idx + 1])
  514.                 {
  515.                     gui_EMS_input_box_forward_cursor(b);
  516.                 }
  517.                 else
  518.                 {
  519.                     break;
  520.                 }
  521.                 idx++;
  522.             }
  523.         }
  524.     }
  525. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  526.     if (gui_EMS_input_box_forward_cursor(b) != 1)
  527.     {
  528.         UI_editor_play_tone_cannot_navigate();
  529.     }
  530.     else
  531.     {
  532.         gui_EMS_input_box_set_text_format_cursor_position(b);
  533.         gui_EMS_input_box_locate_cursor(b);
  534.         b->saved_cursor_ax = -1;
  535.     }
  536. }
  537. #else /* (EMS_USE_CRLF_COMBINATION || EMS_USE_ESC_COMBINATION) */ 
  538. /*****************************************************************************
  539.  * FUNCTION
  540.  *  gui_EMS_input_box_delete
  541.  * DESCRIPTION
  542.  *  
  543.  * PARAMETERS
  544.  *  b       [?]     
  545.  * RETURNS
  546.  *  void
  547.  *****************************************************************************/
  548. void gui_EMS_input_box_delete(UI_EMS_input_box *b)
  549. {
  550.     /*----------------------------------------------------------------*/
  551.     /* Local Variables                                                */
  552.     /*----------------------------------------------------------------*/
  553.     /*----------------------------------------------------------------*/
  554.     /* Code Body                                                      */
  555.     /*----------------------------------------------------------------*/
  556. #ifdef __MMI_MESSAGES_EMS__
  557.     EMS_cancel_object_focus();
  558. #endif 
  559.     if (gui_EMS_input_box_forward_cursor(b) == 1)
  560.     {
  561.         gui_EMS_cancel_current_position(b);
  562.         gui_EMS_input_box_set_text_format_cursor_position(b);
  563.         gui_EMS_input_box_locate_cursor(b);
  564.     }
  565.     else
  566.     {
  567.         UI_editor_play_tone_cannot_change();
  568.     }
  569.     b->saved_cursor_ax = -1;
  570. }
  571. /*****************************************************************************
  572.  * FUNCTION
  573.  *  gui_EMS_input_box_previous
  574.  * DESCRIPTION
  575.  *  
  576.  * PARAMETERS
  577.  *  b       [?]     
  578.  * RETURNS
  579.  *  void
  580.  *****************************************************************************/
  581. void gui_EMS_input_box_previous(UI_EMS_input_box *b)
  582. {
  583. #if defined(__MMI_LANG_VIETNAMESE__)
  584.     /*----------------------------------------------------------------*/
  585.     /* Local Variables                                                */
  586.     /*----------------------------------------------------------------*/
  587.     EMSPosition mapped_cursor_position;
  588.     UI_character_type current_character, dummy_c = 0;
  589.     EMSData *data = b->data;
  590.     EMSObject *current_object;
  591.     U8 object_type;
  592.     viet_tone_mark tone_mark = VIET_TONE_NONE;
  593.     viet_vowel_letter viet_vowel = VIET_VOWEL_NONE;
  594. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  595. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  596.     EMSPosition mapped_cursor_position_arabic;
  597.     UI_character_type current_character_arabic, dummy_c_arabic = 0;
  598.     EMSData *data_arabic = b->data;
  599.     EMSObject *current_object_arabic;
  600.     U8 object_type_arabic;
  601.     S32 saved_text_len = 0;
  602. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  603.     /*----------------------------------------------------------------*/
  604.     /* Code Body                                                      */
  605.     /*----------------------------------------------------------------*/
  606. #ifdef __MMI_MESSAGES_EMS__
  607.     EMS_cancel_object_focus();
  608. #endif 
  609. #if defined(__MMI_LANG_VIETNAMESE__)
  610.     EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  611.     object_type = gui_EMS_input_box_get_previous_object(data, &mapped_cursor_position, &current_character, &current_object);
  612.     if (1 == object_type)
  613.     {
  614.         if ((current_character >= 0x0300) && (current_character <= 0x0323))
  615.         {
  616.             object_type = gui_EMS_input_box_get_previous_object(data, &mapped_cursor_position, &dummy_c, &current_object);      /* get next character */
  617.             if (1 == object_type)
  618.             {
  619.                 viet_vowel = mmi_viet_vowel_letter(dummy_c);
  620.                 if (VIET_VOWEL_NONE != viet_vowel)
  621.                 {
  622.                     tone_mark = mmi_viet_tone_mark(current_character);
  623.                     if (VIET_TONE_NONE != tone_mark)
  624.                     {
  625.                         current_character = mmi_viet_combine_vowel_tone(viet_vowel, tone_mark);
  626.                         BackwardCurrentPosition(b->data, 1);
  627.                     }
  628.                     else
  629.                     {
  630.                         object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  631.                     }
  632.                 }
  633.                 else
  634.                 {
  635.                     object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  636.                 }
  637.             }
  638.             else if (0 != object_type)
  639.             {
  640.                 object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  641.             }
  642.         }
  643.     }
  644. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  645. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  646.     mapped_cursor_position_arabic.OffsetToText = data_arabic->CurrentPosition.OffsetToText;
  647.     mapped_cursor_position_arabic.Object = data_arabic->CurrentPosition.Object;
  648.     object_type_arabic = gui_EMS_input_box_get_previous_object(
  649.                             data_arabic,
  650.                             &mapped_cursor_position_arabic,
  651.                             &current_character_arabic,
  652.                             &current_object_arabic);
  653.     if (1 == object_type_arabic)
  654.     {
  655.         if (IS_ARABIC_CHARACTER(current_character_arabic))
  656.         {
  657.             U16 idx;
  658.             idx = gui_get_ems_text_actual_idx(b, data_arabic->CurrentPosition.OffsetToText) / 2 - 1;
  659.             while (idx > 0)
  660.             {
  661.                 if (OrgToSha[idx] == OrgToSha[idx - 1])
  662.                 {
  663.                     BackwardCurrentPositionSkipCR(b->data);
  664.                 }
  665.                 else
  666.                 {
  667.                     break;
  668.                 }
  669.                 idx--;
  670.             }
  671.         }
  672.     }
  673. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  674.     if (BackwardCurrentPosition(b->data, 1) != 1)
  675.     {
  676.         UI_editor_play_tone_cannot_navigate();
  677.     }
  678.     gui_EMS_input_box_set_text_format_cursor_position(b);
  679.     gui_EMS_input_box_locate_cursor(b);
  680.     b->saved_cursor_ax = -1;
  681. }
  682. /*****************************************************************************
  683.  * FUNCTION
  684.  *  gui_EMS_input_box_forward_cursor
  685.  * DESCRIPTION
  686.  *  
  687.  * PARAMETERS
  688.  *  b       [?]     
  689.  * RETURNS
  690.  *  
  691.  *****************************************************************************/
  692. U8 gui_EMS_input_box_forward_cursor(UI_EMS_input_box *b)
  693. {
  694.     /*----------------------------------------------------------------*/
  695.     /* Local Variables                                                */
  696.     /*----------------------------------------------------------------*/
  697.     /*----------------------------------------------------------------*/
  698.     /* Code Body                                                      */
  699.     /*----------------------------------------------------------------*/
  700.     if (b->data->CurrentPosition.OffsetToText <= (b->data->textLength))
  701.     {
  702.         if (ForwardCurrentPosition(b->data, 1) == 1)
  703.         {
  704.             return (1);
  705.         }
  706.     }
  707.     return (0);
  708. }
  709. /*****************************************************************************
  710.  * FUNCTION
  711.  *  gui_EMS_input_box_next
  712.  * DESCRIPTION
  713.  *  
  714.  * PARAMETERS
  715.  *  b       [?]     
  716.  * RETURNS
  717.  *  void
  718.  *****************************************************************************/
  719. void gui_EMS_input_box_next(UI_EMS_input_box *b)
  720. {
  721. #if defined(__MMI_LANG_VIETNAMESE__)
  722.     /*----------------------------------------------------------------*/
  723.     /* Local Variables                                                */
  724.     /*----------------------------------------------------------------*/
  725.     EMSPosition mapped_cursor_position;
  726.     UI_character_type current_character, dummy_c = 0;
  727.     EMSData *data = b->data;
  728.     EMSObject *current_object;
  729.     U8 object_type;
  730.     viet_tone_mark tone_mark = VIET_TONE_NONE;
  731.     viet_vowel_letter viet_vowel = VIET_VOWEL_NONE;
  732. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  733. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  734.     EMSPosition mapped_cursor_position_arabic;
  735.     UI_character_type current_character_arabic, dummy_c_arabic = 0;
  736.     EMSData *data_arabic = b->data;
  737.     EMSObject *current_object_arabic;
  738.     U8 object_type_arabic;
  739.     S32 saved_text_len = 0;
  740. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  741.     /*----------------------------------------------------------------*/
  742.     /* Code Body                                                      */
  743.     /*----------------------------------------------------------------*/
  744. #ifdef __MMI_MESSAGES_EMS__
  745.     EMS_cancel_object_focus();
  746. #endif 
  747. #if defined(__MMI_LANG_VIETNAMESE__)
  748.     EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  749.     object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &current_character, &current_object);
  750.     if (1 == object_type)
  751.     {
  752.         if ((current_character > 0x0040) && (current_character < 0x01B1))
  753.         {
  754.             object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);  /* get next character */
  755.             if (1 == object_type)
  756.             {
  757.                 tone_mark = mmi_viet_tone_mark(dummy_c);
  758.                 if (VIET_TONE_NONE != tone_mark)
  759.                 {
  760.                     viet_vowel = mmi_viet_vowel_letter(current_character);
  761.                     if (VIET_VOWEL_NONE != viet_vowel)
  762.                     {
  763.                         current_character = mmi_viet_combine_vowel_tone(viet_vowel, tone_mark);
  764.                         gui_EMS_input_box_forward_cursor(b);
  765.                     }
  766.                     else
  767.                     {
  768.                         object_type = gui_EMS_input_box_get_previous_object(
  769.                                         data,
  770.                                         &mapped_cursor_position,
  771.                                         &dummy_c,
  772.                                         &current_object);
  773.                     }
  774.                 }
  775.                 else
  776.                 {
  777.                     object_type = gui_EMS_input_box_get_previous_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  778.                 }
  779.             }
  780.             else if (0 != object_type)
  781.             {
  782.                 object_type = gui_EMS_input_box_get_next_object(data, &mapped_cursor_position, &dummy_c, &current_object);
  783.             }
  784.         }
  785.     }
  786. #endif /* defined(__MMI_LANG_VIETNAMESE__) */ 
  787. #if defined(__MMI_LANG_ARABIC__) defined(__MMI_LANG_PERSIAN__)
  788.     mapped_cursor_position_arabic.OffsetToText = data_arabic->CurrentPosition.OffsetToText;
  789.     mapped_cursor_position_arabic.Object = data_arabic->CurrentPosition.Object;
  790.     object_type_arabic = gui_EMS_input_box_get_next_object(
  791.                             data_arabic,
  792.                             &mapped_cursor_position_arabic,
  793.                             &current_character_arabic,
  794.                             &current_object_arabic);
  795.     if (1 == object_type_arabic)
  796.     {
  797.         if (IS_ARABIC_CHARACTER(current_character_arabic))
  798.         {
  799.             U16 idx;
  800.             U16 offset = 0;
  801.             if (mapped_cursor_position_arabic.Object != NULL)
  802.             {
  803.                 offset += 2;
  804.             }
  805.             idx = gui_get_ems_text_actual_idx(b, data_arabic->CurrentPosition.OffsetToText + offset);
  806.             if (idx != 0)
  807.             {
  808.                 idx = idx / 2 - 1;
  809.             }
  810.             while (idx < unshaped_text_len)
  811.             {
  812.                 if (OrgToSha[idx] == OrgToSha[idx + 1])
  813.                 {
  814.                     gui_EMS_input_box_forward_cursor(b);
  815.                 }
  816.                 else
  817.                 {
  818.                     break;
  819.                 }
  820.                 idx++;
  821.             }
  822.         }
  823.     }
  824. #endif /* defined(__MMI_LANG_ARABIC__) defined(__MMI_LANG_PERSIAN__) */ /* defined(__MMI_LANG_ARABIC__) */
  825.     if (gui_EMS_input_box_forward_cursor(b) != 1)
  826.     {
  827.         UI_editor_play_tone_cannot_navigate();
  828.     }
  829.     gui_EMS_input_box_set_text_format_cursor_position(b);
  830.     gui_EMS_input_box_locate_cursor(b);
  831.     b->saved_cursor_ax = -1;
  832. }
  833. #endif /* (EMS_USE_CRLF_COMBINATION || EMS_USE_ESC_COMBINATION) */ 
  834. /*****************************************************************************
  835.  * FUNCTION
  836.  *  gui_move_EMS_input_box
  837.  * DESCRIPTION
  838.  *  
  839.  * PARAMETERS
  840.  *  b       [?]         
  841.  *  x       [IN]        
  842.  *  y       [IN]        
  843.  * RETURNS
  844.  *  void
  845.  *****************************************************************************/
  846. void gui_move_EMS_input_box(UI_EMS_input_box *b, S32 x, S32 y)
  847. {
  848.     /*----------------------------------------------------------------*/
  849.     /* Local Variables                                                */
  850.     /*----------------------------------------------------------------*/
  851.     /*----------------------------------------------------------------*/
  852.     /* Code Body                                                      */
  853.     /*----------------------------------------------------------------*/
  854.     b->x = x;
  855.     b->y = y;
  856.     gui_move_vertical_scrollbar(&b->vbar, b->x + b->width - b->vbar.width - 1, b->y + 1);
  857. }
  858. /*****************************************************************************
  859.  * FUNCTION
  860.  *  gui_resize_EMS_input_box
  861.  * DESCRIPTION
  862.  *  
  863.  * PARAMETERS
  864.  *  b           [?]         
  865.  *  width       [IN]        
  866.  *  height      [IN]        
  867.  * RETURNS
  868.  *  void
  869.  *****************************************************************************/
  870. void gui_resize_EMS_input_box(UI_EMS_input_box *b, S32 width, S32 height)
  871. {
  872.     /*----------------------------------------------------------------*/
  873.     /* Local Variables                                                */
  874.     /*----------------------------------------------------------------*/
  875.     /*----------------------------------------------------------------*/
  876.     /* Code Body                                                      */
  877.     /*----------------------------------------------------------------*/
  878.     b->width = width;
  879.     b->height = height;
  880.     gui_move_vertical_scrollbar(&b->vbar, b->x + b->width - b->vbar.width - 1, b->y + 1);
  881.     gui_resize_vertical_scrollbar(&b->vbar, b->vbar.width, b->height - 2);
  882.     gui_EMS_input_box_locate_cursor(b);
  883.     b->saved_cursor_ax = -1;
  884. }
  885. /* Returns 0: none, 1: character, 2:object   */
  886. /*****************************************************************************
  887.  * FUNCTION
  888.  *  gui_EMS_input_box_get_next_object
  889.  * DESCRIPTION
  890.  *  
  891.  * PARAMETERS
  892.  *  data                    [?]         
  893.  *  current_position        [?]         
  894.  *  c                       [?]         
  895.  *  o                       [IN]        
  896.  * RETURNS
  897.  *  
  898.  *****************************************************************************/
  899. U8 gui_EMS_input_box_get_next_object(
  900.     EMSData *data,
  901.     EMSPosition *current_position,
  902.     UI_character_type *c,
  903.     EMSObject **o)
  904. {
  905. #if(0)  /* Error in code: Do not enable this block   */
  906.     /*----------------------------------------------------------------*/
  907.     /* Local Variables                                                */
  908.     /*----------------------------------------------------------------*/
  909. byte return_type=0;
  910. if((current_position->Object!=NULL) && (current_position->Object->OffsetToText==current_position->OffsetToText))
  911. {
  912. if((current_position->Object->next!=NULL) && (current_position->Object->OffsetToText==current_position->Object->next->OffsetToText))
  913. {
  914. return_type=2;
  915. *o=current_position->Object;
  916. current_position->Object=current_position->Object->next;
  917. }
  918. else if(current_position->OffsetToText<=EMS_DATA_END_OFFSET(data->textLength))
  919. {
  920. return_type=2;
  921. *o=current_position->Object;
  922. current_position->Object=current_position->Object->next;
  923. }
  924. }
  925. else if(current_position->OffsetToText<EMS_DATA_END_OFFSET(data->textLength))
  926. {
  927. return_type=1;
  928. #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  929. *c=(data->textBuffer[current_position->OffsetToText+1]|(data->textBuffer[current_position->OffsetToText]<<8));
  930. #else
  931. *c=(data->textBuffer[current_position->OffsetToText]|(data->textBuffer[current_position->OffsetToText+1]<<8));
  932. #endif
  933. current_position->OffsetToText+=2;
  934. }
  935. return(return_type);
  936. #else /* (0) */ 
  937.     /*----------------------------------------------------------------*/
  938.     /* Code Body                                                      */
  939.     /*----------------------------------------------------------------*/
  940.     return (EMSGetNextObject(data, current_position, c, o));
  941. #endif /* (0) */ 
  942. }
  943. /* MTK Add By Elvis for Input method */
  944. /* Returns 0: none, 1: character, 2:object   */
  945. /*****************************************************************************
  946.  * FUNCTION
  947.  *  gui_EMS_input_box_get_next_object_for_input_method
  948.  * DESCRIPTION
  949.  *  
  950.  * PARAMETERS
  951.  *  data                    [?]         
  952.  *  current_position        [?]         
  953.  *  c                       [?]         
  954.  *  o                       [IN]        
  955.  * RETURNS
  956.  *  
  957.  *****************************************************************************/
  958. U8 gui_EMS_input_box_get_next_object_for_input_method(
  959.     EMSData *data,
  960.     EMSPosition *current_position,
  961.     UI_character_type *c,
  962.     EMSObject **o)
  963. {
  964.     /*----------------------------------------------------------------*/
  965.     /* Local Variables                                                */
  966.     /*----------------------------------------------------------------*/
  967.     U8 return_type = 0;
  968.     /*----------------------------------------------------------------*/
  969.     /* Code Body                                                      */
  970.     /*----------------------------------------------------------------*/
  971.     if (current_position->Object != NULL)
  972.     {
  973.         if (current_position->Object->next != NULL &&
  974.             current_position->Object->next->OffsetToText == current_position->OffsetToText)
  975.         {
  976.             return_type = 2;
  977.             *o = current_position->Object->next;
  978.             current_position->Object = current_position->Object->next;
  979.         }
  980.         else if (current_position->OffsetToText < EMS_DATA_END_OFFSET(data->textLength))
  981.         {
  982.             return_type = 1;
  983.         #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  984.             *c = (data->
  985.                   textBuffer[current_position->OffsetToText +
  986.                              1] | (data->textBuffer[current_position->OffsetToText] << 8));
  987.         #else /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  988.             *c = (data->
  989.                   textBuffer[current_position->OffsetToText] | (data->
  990.                                                                 textBuffer[current_position->OffsetToText + 1] << 8));
  991.         #endif /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  992.             current_position->OffsetToText += 2;
  993.         }
  994.     }
  995.     else if (data->listHead != NULL)
  996.     {
  997.         if (data->listHead->OffsetToText == current_position->OffsetToText)
  998.         {
  999.             return_type = 2;
  1000.             *o = data->listHead;
  1001.             current_position->Object = data->listHead;
  1002.         }
  1003.         else if (current_position->OffsetToText < EMS_DATA_END_OFFSET(data->textLength))
  1004.         {
  1005.             return_type = 1;
  1006.         #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1007.             *c = (data->
  1008.                   textBuffer[current_position->OffsetToText +
  1009.                              1] | (data->textBuffer[current_position->OffsetToText] << 8));
  1010.         #else /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  1011.             *c = (data->
  1012.                   textBuffer[current_position->OffsetToText] | (data->
  1013.                                                                 textBuffer[current_position->OffsetToText + 1] << 8));
  1014.         #endif /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  1015.             current_position->OffsetToText += 2;
  1016.         }
  1017.     }
  1018.     else if (current_position->OffsetToText < EMS_DATA_END_OFFSET(data->textLength))
  1019.     {
  1020.         return_type = 1;
  1021.     #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1022.         *c = (data->
  1023.               textBuffer[current_position->OffsetToText + 1] | (data->textBuffer[current_position->OffsetToText] << 8));
  1024.     #else /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  1025.         *c = (data->
  1026.               textBuffer[current_position->OffsetToText] | (data->textBuffer[current_position->OffsetToText + 1] << 8));
  1027.     #endif /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  1028.         current_position->OffsetToText += 2;
  1029.     }
  1030.     return (return_type);
  1031. }
  1032. /* MTK end */
  1033. /* Returns 0: none, 1: character, 2:object   */
  1034. /*****************************************************************************
  1035.  * FUNCTION
  1036.  *  gui_EMS_input_box_get_previous_object
  1037.  * DESCRIPTION
  1038.  *  
  1039.  * PARAMETERS
  1040.  *  data                    [?]         
  1041.  *  current_position        [?]         
  1042.  *  c                       [?]         
  1043.  *  o                       [IN]        
  1044.  * RETURNS
  1045.  *  
  1046.  *****************************************************************************/
  1047. U8 gui_EMS_input_box_get_previous_object(
  1048.     EMSData *data,
  1049.     EMSPosition *current_position,
  1050.     UI_character_type *c,
  1051.     EMSObject **o)
  1052. {
  1053. #if(0)
  1054.     /*----------------------------------------------------------------*/
  1055.     /* Local Variables                                                */
  1056.     /*----------------------------------------------------------------*/
  1057. byte return_type=0;
  1058.     //MTK Elvis
  1059. if((current_position->Object!=NULL) && (current_position->Object->OffsetToText==current_position->OffsetToText))
  1060. {
  1061. if((current_position->Object->prev!=NULL) && (current_position->Object->OffsetToText==current_position->Object->prev->OffsetToText))
  1062. {
  1063. return_type=2;
  1064. *o=current_position->Object;
  1065. current_position->Object=current_position->Object->prev;
  1066. }
  1067. else if(current_position->OffsetToText>=0)
  1068. {
  1069. return_type=2;
  1070. *o=current_position->Object;
  1071. current_position->Object=current_position->Object->prev;
  1072. }
  1073. }
  1074.     else if(current_position->OffsetToText <= EMS_DATA_END_OFFSET(data->textLength) && current_position->OffsetToText >= 2)
  1075. {
  1076. return_type=1;
  1077. #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1078.         *c=(data->textBuffer[current_position->OffsetToText-1]|(data->textBuffer[current_position->OffsetToText-2]<<8));
  1079. #else
  1080.         *c=(data->textBuffer[current_position->OffsetToText-2]|(data->textBuffer[current_position->OffsetToText-1]<<8));
  1081. #endif
  1082. current_position->OffsetToText-=2;
  1083. }
  1084.     //MTK end
  1085. return(return_type);
  1086. #else /* (0) */ 
  1087.     /*----------------------------------------------------------------*/
  1088.     /* Code Body                                                      */
  1089.     /*----------------------------------------------------------------*/
  1090.     return (EMSGetPreviousObject(data, current_position, c, o));
  1091. #endif /* (0) */ 
  1092. }
  1093. /* MTK Elvis 20031225 to avoid the cursor display out of editing window */
  1094. #if 0
  1095. /* under construction !*/
  1096. /* under construction !*/
  1097. /* under construction !*/
  1098. /* under construction !*/
  1099. #if(UI_BLINKING_CURSOR_SUPPORT)
  1100. /* under construction !*/
  1101. #else
  1102. /* under construction !*/
  1103. #endif
  1104. /* under construction !*/
  1105. /* under construction !*/
  1106. /* under construction !*/
  1107. #if(UI_BLINKING_CURSOR_SUPPORT)
  1108. /* under construction !*/
  1109. #else
  1110. /* under construction !*/
  1111. /* under construction !*/
  1112. #endif
  1113. /* under construction !*/
  1114. /* under construction !*/
  1115. /* under construction !*/
  1116. #if(UI_BLINKING_CURSOR_SUPPORT)
  1117. /* under construction !*/
  1118. /* under construction !*/
  1119. /* under construction !*/
  1120. /* under construction !*/
  1121. /* under construction !*/
  1122. #endif
  1123. /* under construction !*/
  1124. /* under construction !*/
  1125. /* under construction !*/
  1126. #endif /* 0 */ 
  1127. /*****************************************************************************
  1128.  * FUNCTION
  1129.  *  gui_show_EMS_input_box_cursor
  1130.  * DESCRIPTION
  1131.  *  
  1132.  * PARAMETERS
  1133.  *  b           [?]         
  1134.  *  x           [IN]        
  1135.  *  y           [IN]        
  1136.  *  width       [IN]        
  1137.  *  height      [IN]        
  1138.  *  flags       [IN]        
  1139.  * RETURNS
  1140.  *  void
  1141.  *****************************************************************************/
  1142. void gui_show_EMS_input_box_cursor(UI_EMS_input_box *b, S32 x, S32 y, S32 width, S32 height, U32 flags)
  1143. {
  1144.     /*----------------------------------------------------------------*/
  1145.     /* Local Variables                                                */
  1146.     /*----------------------------------------------------------------*/
  1147.     U8 cursor_type = (U8) (flags & 0x0f);
  1148.     S32 x1, y1, x2, y2;
  1149.     /*----------------------------------------------------------------*/
  1150.     /* Code Body                                                      */
  1151.     /*----------------------------------------------------------------*/
  1152.     if (cursor_type == 1)
  1153.     {
  1154.         x1 = x - 1;
  1155.         y1 = y;
  1156.         x2 = x;
  1157.         y2 = y + height - 1;
  1158.         if (x1 < (b->x + 1))
  1159.         {
  1160.             x1 = b->x + 1;
  1161.         }
  1162.         if (y1 < (b->y + 1))
  1163.         {
  1164.             y1 = b->y + 1;
  1165.         }
  1166.         if (x2 > (b->x + b->width - 2))
  1167.         {
  1168.             x2 = b->x + b->width - 2;
  1169.         }
  1170.         if (y2 > (b->y + b->height - 2))
  1171.         {
  1172.             y2 = b->y + b->height - 2;
  1173.         }
  1174.     #if(UI_BLINKING_CURSOR_SUPPORT)
  1175.         UI_inputbox_show_cursor(x1, y1, x2, y2, b->cursor_color);
  1176.     #else 
  1177.         gui_fill_rectangle(x1, y1, x2, y2, b->cursor_color);
  1178.     #endif 
  1179.     }
  1180.     else if (cursor_type == 2)
  1181.     {
  1182.         x1 = x - 2;
  1183.         y1 = y;
  1184.         x2 = x - 1;
  1185.         y2 = y + height - 1;
  1186.         if (x1 < (b->x + 1))
  1187.         {
  1188.             x1 = b->x + 1;
  1189.         }
  1190.         if (y1 < (b->y + 1))
  1191.         {
  1192.             y1 = b->y + 1;
  1193.         }
  1194.         if (x2 > (b->x + b->width - 2))
  1195.         {
  1196.             x2 = b->x + b->width - 2;
  1197.         }
  1198.         if (y2 > (b->y + b->height - 2))
  1199.         {
  1200.             y2 = b->y + b->height - 2;
  1201.         }
  1202.     #if(UI_BLINKING_CURSOR_SUPPORT)
  1203.         UI_inputbox_show_cursor(x1, y1, x2, y2, b->cursor_color);
  1204.     #else /* (UI_BLINKING_CURSOR_SUPPORT) */ 
  1205.         /* gui_draw_rectangle(x1,y1,x2,y2,b->cursor_color); */
  1206.         gui_fill_rectangle(x1, y1, x2, y2, b->cursor_color);
  1207.     #endif /* (UI_BLINKING_CURSOR_SUPPORT) */ 
  1208.     }
  1209.     else if (cursor_type == 3)
  1210.     {
  1211.         x1 = x - 1;
  1212.         y1 = y - 1;
  1213.         x2 = x + width - 1;
  1214.         y2 = y + height - 1;
  1215.         if (x1 < (b->x + 1))
  1216.         {
  1217.             x1 = b->x + 1;
  1218.         }
  1219.         if (y1 < (b->y + 1))
  1220.         {
  1221.             y1 = b->y + 1;
  1222.         }
  1223.         if (x2 > (b->x + b->width - 2))
  1224.         {
  1225.             x2 = b->x + b->width - 2;
  1226.         }
  1227.         if (y2 > (b->y + b->height - 2))
  1228.         {
  1229.             y2 = b->y + b->height - 2;
  1230.         }
  1231.     #if(UI_BLINKING_CURSOR_SUPPORT)
  1232.         //gui_cancel_timer(UI_inputbox_blink_cursor);
  1233.         //MTK Elvis
  1234.         StopMyTimer(BLINKING_CURSOR);
  1235.         /* MTK end */
  1236.     #endif /* (UI_BLINKING_CURSOR_SUPPORT) */ 
  1237.         gui_draw_rectangle(x1, y1, x2, y2, b->cursor_color);
  1238.     }
  1239. }
  1240. /* MTK end */
  1241. /* CRLF/Esc sequence handling functions:              */
  1242. /* These must be made available in the EMS library       */
  1243. /* Navigates CRLF/Esc sequence as a single object        */
  1244. /* Currently assumes Little endian byte ordering only    */
  1245. /* Supports only steps=1                           */
  1246. /*****************************************************************************
  1247.  * FUNCTION
  1248.  *  BackwardCurrentPositionSkipCR
  1249.  * DESCRIPTION
  1250.  *  
  1251.  * PARAMETERS
  1252.  *  data        [?]     
  1253.  * RETURNS
  1254.  *  
  1255.  *****************************************************************************/
  1256. kal_uint16 BackwardCurrentPositionSkipCR(EMSData *data)
  1257. {
  1258. #ifdef __MMI_HINDI_ALG__
  1259.     /*----------------------------------------------------------------*/
  1260.     /* Local Variables                                                */
  1261.     /*----------------------------------------------------------------*/
  1262.     UI_character_type current_character = 0;
  1263.     U8 object_type_check;
  1264.     EMSObject *o;
  1265.     EMSPosition p = data->CurrentPosition;
  1266.     EMSData *data_chk_type = data;
  1267.     UI_character_type dummy_c = 0;
  1268.     S32 prev_ems_moves = 0;
  1269.     UI_buffer_type check_ems_hindi_p;
  1270.     PU8 src_p;
  1271.     PU8 dest_p;
  1272.     /*----------------------------------------------------------------*/
  1273.     /* Code Body                                                      */
  1274.     /*----------------------------------------------------------------*/
  1275.     check_ems_hindi_p = src_p = (data->textBuffer + data->CurrentPosition.OffsetToText);
  1276.     UI_STRING_GET_PREVIOUS_CHARACTER(check_ems_hindi_p, dummy_c);       /* get previous character */
  1277.     if (UI_HINDI_CHARACTER_UCS2_RANGE(dummy_c))
  1278.     {
  1279.         /* Move by a syllable rather than by a character as in English */
  1280.         dest_p = hf_get_prev_cluster_p(data->textBuffer, src_p);
  1281.         prev_ems_moves = src_p - dest_p;
  1282.         prev_ems_moves = prev_ems_moves >> 1;
  1283.         object_type_check = gui_EMS_input_box_get_previous_object(data_chk_type, &p, &current_character, &o);
  1284.         if (object_type_check == 2)
  1285.         {
  1286.             prev_ems_moves = 1;
  1287.         }
  1288.     }
  1289.     else
  1290.     {
  1291.         prev_ems_moves = 1;
  1292.     }
  1293.     /* To be checked why its returning 0 for prev_ems_moves>1 */
  1294.     PRINT_INFORMATION_2((MMI_TRACE_INFO, "BackwardCurrentPositionSkipCR[prev_ems_moves]:%d  ", prev_ems_moves));
  1295.     MMI_ASSERT(!(prev_ems_moves < 0));
  1296.     if (BackwardCurrentPosition(data, prev_ems_moves) >= 1)
  1297. #else /* __MMI_HINDI_ALG__ */ 
  1298.     if (BackwardCurrentPosition(data, 1) == 1)
  1299. #endif /* __MMI_HINDI_ALG__ */ 
  1300.     {
  1301.         if (data->textBuffer == NULL)
  1302.         {
  1303.             return (1);
  1304.         }
  1305.     #if(EMS_USE_CRLF_COMBINATION)
  1306.         if (UI_TEST_LF_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText]))
  1307.         {
  1308.             if (BackwardCurrentPosition(data, 1) == 1)
  1309.             {
  1310.                 if (!UI_TEST_CR_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText]))
  1311.                 {
  1312.                     ForwardCurrentPosition(data, 1);
  1313.                 }
  1314.             }
  1315.         }
  1316.     #endif /* (EMS_USE_CRLF_COMBINATION) */ 
  1317.     #if(EMS_USE_ESC_COMBINATION)
  1318.         if (BackwardCurrentPosition(data, 1) == 1)
  1319.         {
  1320.             if (!UI_TEST_ESC_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText]))
  1321.             {
  1322.                 ForwardCurrentPosition(data, 1);
  1323.             }
  1324.         #ifdef __MMI_HINDI_ALG__
  1325.             else if ((UI_TEST_ESC_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText])) &&
  1326.                      (data->textBuffer[data->CurrentPosition.OffsetToText + 1 == 0x09]))
  1327.             {
  1328.                 ForwardCurrentPosition(data, 1);
  1329.             }
  1330.         #endif /* __MMI_HINDI_ALG__ */ 
  1331.         }
  1332.     #endif /* (EMS_USE_ESC_COMBINATION) */ 
  1333.         return (1);
  1334.     }
  1335.     return (0);
  1336. }
  1337. /* Navigates CRLF/Esc sequence as a single object        */
  1338. /* Currently assumes Little endian byte ordering only    */
  1339. /* Supports only steps=1                           */
  1340. /*****************************************************************************
  1341.  * FUNCTION
  1342.  *  ForwardCurrentPositionSkipCR
  1343.  * DESCRIPTION
  1344.  *  
  1345.  * PARAMETERS
  1346.  *  data        [?]     
  1347.  * RETURNS
  1348.  *  
  1349.  *****************************************************************************/
  1350. kal_uint16 ForwardCurrentPositionSkipCR(EMSData *data)
  1351. {
  1352.     /*----------------------------------------------------------------*/
  1353.     /* Local Variables                                                */
  1354.     /*----------------------------------------------------------------*/
  1355.     kal_uint16 count = 0;
  1356. #ifdef __MMI_HINDI_ALG__
  1357.     UI_character_type current_character = 0;
  1358.     U8 object_type_check;
  1359.     EMSObject *o;
  1360.     EMSPosition p = data->CurrentPosition;
  1361.     EMSData *data_chk_type = data;
  1362.     UI_character_type dummy_c = 0;
  1363.     S32 next_ems_moves = 0;
  1364.     UI_buffer_type check_ems_hindi_p;
  1365.     PU8 src_p;
  1366.     PU8 dest_p;
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Code Body                                                      */
  1369.     /*----------------------------------------------------------------*/
  1370.     check_ems_hindi_p = src_p = (data->textBuffer + data->CurrentPosition.OffsetToText);
  1371.     UI_STRING_GET_NEXT_CHARACTER(check_ems_hindi_p, dummy_c);   /* get previous character */
  1372.     if (UI_HINDI_CHARACTER_UCS2_RANGE(dummy_c))
  1373.     {
  1374.         /* Move by a syllable rather than by a character as in English */
  1375.         /* dest_p = hf_get_next_cluster_p(data->textBuffer,src_p); */
  1376.         dest_p = hf_get_next_cluster_p(src_p, src_p);
  1377.         next_ems_moves = dest_p - src_p;
  1378.         next_ems_moves = next_ems_moves >> 1;
  1379.         object_type_check = gui_EMS_input_box_get_next_object(data_chk_type, &p, &current_character, &o);
  1380.         /* PMT START FIX HINDI ISSUES 20060604 */
  1381.         if (object_type_check == 2 && (next_ems_moves >= 2) && p.Object->Type == EMS_TYPE_TEXT_FORMAT)
  1382.         {
  1383.             /* Do nothing */
  1384.         }
  1385.         else if (object_type_check == 2)
  1386.         {
  1387.             next_ems_moves = 1;
  1388.         }
  1389.         /* PMT END FIX HINDI ISSUES 20060604 */
  1390.     }
  1391.     else
  1392.     {
  1393.         next_ems_moves = 1;
  1394.     }
  1395. #endif /* __MMI_HINDI_ALG__ */ 
  1396.     if (data->textBuffer == NULL)
  1397.     {
  1398.         count = ForwardCurrentPosition(data, 1);
  1399.         return (count);
  1400.     }
  1401. #if(EMS_USE_ESC_COMBINATION)
  1402.     if ((data->dcs == SMSAL_DEFAULT_DCS) &&
  1403.         (UI_TEST_ESC_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText])))
  1404.     {
  1405.         count = ForwardCurrentPosition(data, 1);
  1406.         if (count == 1)
  1407.         {
  1408.             ForwardCurrentPosition(data, 1);
  1409.         }
  1410.     }
  1411.     else
  1412. #endif /* (EMS_USE_ESC_COMBINATION) */ 
  1413. #if(EMS_USE_CRLF_COMBINATION)
  1414.     if (UI_TEST_CR_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText]))
  1415.     {
  1416.         count = ForwardCurrentPosition(data, 1);
  1417.         if (UI_TEST_LF_CHARACTER(data->textBuffer[data->CurrentPosition.OffsetToText]))
  1418.         {
  1419.             ForwardCurrentPosition(data, 1);
  1420.         }
  1421.     }
  1422.     else
  1423. #endif /* (EMS_USE_CRLF_COMBINATION) */ 
  1424.     {
  1425.     #ifdef __MMI_HINDI_ALG__
  1426.         PRINT_INFORMATION_2((MMI_TRACE_INFO, "ForwardCurrentPositionSkipCR[next_ems_moves]:%d  ", next_ems_moves));
  1427.         MMI_ASSERT(!(next_ems_moves < 0));
  1428.         count = ForwardCurrentPosition(data, next_ems_moves);
  1429.         /* PMT MISSED START 20060711 */
  1430.         if (count >= 1)
  1431.         {
  1432.             count = 1;
  1433.         }
  1434.         /* PMT MISSED END 20060711 */
  1435.     #else /* __MMI_HINDI_ALG__ */ 
  1436.         count = ForwardCurrentPosition(data, 1);
  1437.     #endif /* __MMI_HINDI_ALG__ */ 
  1438.     }
  1439.     return (count);
  1440. }
  1441. /* Moves the cursor forwards by the number of steps specified.
  1442.    Cursor starts at start position. (If data->CursorPosition is not at
  1443.    the given start position, then the cursor will be moved to start position first)
  1444.    The cursor will not move beyond one step before the given end position  */
  1445. /*****************************************************************************
  1446.  * FUNCTION
  1447.  *  MoveCurrentPosition
  1448.  * DESCRIPTION
  1449.  *  
  1450.  * PARAMETERS
  1451.  *  data        [?]         
  1452.  *  start       [?]         
  1453.  *  end         [?]         
  1454.  *  steps       [IN]        
  1455.  * RETURNS
  1456.  *  void
  1457.  *****************************************************************************/
  1458. void MoveCurrentPosition(EMSData *data, EMSPosition *start, EMSPosition *end, kal_uint16 steps)
  1459. {
  1460.     /*----------------------------------------------------------------*/
  1461.     /* Local Variables                                                */
  1462.     /*----------------------------------------------------------------*/
  1463.     S32 diff;
  1464.     U8 object_flag;
  1465.     U8 done_flag = 0;
  1466.     S32 count = 0;
  1467.     U8 back_flag = 0;
  1468.     /*----------------------------------------------------------------*/
  1469.     /* Code Body                                                      */
  1470.     /*----------------------------------------------------------------*/
  1471.     object_flag = 0;
  1472.     diff = data->CurrentPosition.OffsetToText - start->OffsetToText;
  1473.     if ((start->Object != NULL) && (start->Object->OffsetToText == start->OffsetToText))
  1474.     {
  1475.         object_flag = 1;
  1476.     }
  1477.     if (diff < 0)
  1478.     {
  1479.         while (!done_flag)
  1480.         {
  1481.             if (data->CurrentPosition.OffsetToText == start->OffsetToText)
  1482.             {
  1483.                 if (object_flag)
  1484.                 {
  1485.                     if ((data->CurrentPosition.Object == start->Object) &&
  1486.                         (data->CurrentPosition.Object->OffsetToText == start->OffsetToText))
  1487.                     {
  1488.                         BackwardCurrentPosition(data, 1);
  1489.                         break;
  1490.                     }
  1491.                 }
  1492.                 else
  1493.                 {
  1494.                     break;
  1495.                 }
  1496.             }
  1497.             if (ForwardCurrentPosition(data, 1) != 1)
  1498.             {
  1499.                 break;
  1500.             }
  1501.         }
  1502.     }
  1503.     else if (diff > 0)
  1504.     {
  1505.         while (!done_flag)
  1506.         {
  1507.             if (data->CurrentPosition.OffsetToText == start->OffsetToText)
  1508.             {
  1509.                 if (object_flag)
  1510.                 {
  1511.                     if ((data->CurrentPosition.Object == start->Object) &&
  1512.                         (data->CurrentPosition.Object->OffsetToText == start->OffsetToText))
  1513.                     {
  1514.                         BackwardCurrentPosition(data, 1);
  1515.                         break;
  1516.                     }
  1517.                 }
  1518.                 else
  1519.                 {
  1520.                     break;
  1521.                 }
  1522.             }
  1523.             if (BackwardCurrentPosition(data, 1) != 1)
  1524.             {
  1525.                 break;
  1526.             }
  1527.         }
  1528.     }
  1529.     else
  1530.     {
  1531.         S32 old_OffsetToText = data->CurrentPosition.OffsetToText;
  1532.         while (data->CurrentPosition.OffsetToText == old_OffsetToText)
  1533.         {
  1534.             if (BackwardCurrentPosition(data, 1) != 1)
  1535.             {
  1536.                 break;
  1537.             }
  1538.         }
  1539.         while (!done_flag)
  1540.         {
  1541.             if (data->CurrentPosition.OffsetToText == start->OffsetToText)
  1542.             {
  1543.                 if (object_flag)
  1544.                 {
  1545.                     if ((data->CurrentPosition.Object == start->Object) &&
  1546.                         (data->CurrentPosition.Object->OffsetToText == start->OffsetToText))
  1547.                     {
  1548.                         BackwardCurrentPosition(data, 1);
  1549.                         break;
  1550.                     }
  1551.                 }
  1552.                 else
  1553.                 {
  1554.                     break;
  1555.                 }
  1556.             }
  1557.             if (ForwardCurrentPosition(data, 1) != 1)
  1558.             {
  1559.                 break;
  1560.             }
  1561.         }
  1562.     }
  1563.     if (steps == 0)
  1564.     {
  1565.         return;
  1566.     }
  1567.     object_flag = 0;
  1568.     if ((end->Object != NULL) && (end->Object->OffsetToText == end->OffsetToText))
  1569.     {
  1570.         object_flag = 1;
  1571.     }
  1572.     if (data->CurrentPosition.OffsetToText == end->OffsetToText)
  1573.     {
  1574.         S32 old_OffsetToText = data->CurrentPosition.OffsetToText;
  1575.         while (data->CurrentPosition.OffsetToText == old_OffsetToText)
  1576.         {
  1577.             if (BackwardCurrentPosition(data, 1) != 1)
  1578.             {
  1579.                 break;
  1580.             }
  1581.             count--;
  1582.         }
  1583.         while (!done_flag)
  1584.         {
  1585.             if (count >= steps)
  1586.             {
  1587.                 break;
  1588.             }
  1589.             count++;
  1590.             if (data->CurrentPosition.OffsetToText == end->OffsetToText)
  1591.             {
  1592.                 if (object_flag)
  1593.                 {
  1594.                     if ((data->CurrentPosition.Object == end->Object) &&
  1595.                         (data->CurrentPosition.Object->OffsetToText == end->OffsetToText))
  1596.                     {
  1597.                         back_flag = 1;
  1598.                         break;
  1599.                     }
  1600.                 }
  1601.                 else
  1602.                 {
  1603.                     back_flag = 1;
  1604.                     break;
  1605.                 }
  1606.             }
  1607.             if (ForwardCurrentPosition(data, 1) != 1)
  1608.             {
  1609.                 break;
  1610.             }
  1611.         }
  1612.         if (back_flag)
  1613.         {
  1614.             BackwardCurrentPosition(data, 1);
  1615.         }
  1616.         if (data->CurrentPosition.OffsetToText > end->OffsetToText)
  1617.         {
  1618.             BackwardCurrentPosition(data, 1);
  1619.         }
  1620.     }
  1621.     else
  1622.     {
  1623.         while (!done_flag)
  1624.         {
  1625.             if (count >= steps)
  1626.             {
  1627.                 break;
  1628.             }
  1629.             count++;
  1630.             if (data->CurrentPosition.OffsetToText == end->OffsetToText)
  1631.             {
  1632.                 if (object_flag)
  1633.                 {
  1634.                     if ((data->CurrentPosition.Object == end->Object) &&
  1635.                         (data->CurrentPosition.Object->OffsetToText == end->OffsetToText))
  1636.                     {
  1637.                         back_flag = 1;
  1638.                         break;
  1639.                     }
  1640.                 }
  1641.                 else
  1642.                 {
  1643.                     back_flag = 1;
  1644.                     break;
  1645.                 }
  1646.             }
  1647.             if (ForwardCurrentPosition(data, 1) != 1)
  1648.             {
  1649.                 break;
  1650.             }
  1651.         }
  1652.         if (back_flag)
  1653.         {
  1654.             BackwardCurrentPosition(data, 1);
  1655.         }
  1656.         if (data->CurrentPosition.OffsetToText >= end->OffsetToText)
  1657.         {
  1658.             if ((end->OffsetToText != data->textLength) && !((end->Object != NULL) && (end->Object != data->listHead)))
  1659.             {
  1660.                 BackwardCurrentPosition(data, 1);
  1661.             }
  1662.             if ((data->CurrentPosition.Object != NULL) && (end->Object != NULL))
  1663.             {
  1664.                 while (data->CurrentPosition.Object->OffsetToText > end->Object->OffsetToText)
  1665.                 {
  1666.                     if (BackwardCurrentPosition(data, 1) != 1)
  1667.                     {
  1668.                         break;
  1669.                     }
  1670.                 }
  1671.             }
  1672.         }
  1673.     }
  1674. }
  1675. /* Moves the cursor to a given position   */
  1676. /*****************************************************************************
  1677.  * FUNCTION
  1678.  *  MoveCursorToPosition
  1679.  * DESCRIPTION
  1680.  *  
  1681.  * PARAMETERS
  1682.  *  data        [?]     
  1683.  *  dst         [?]     
  1684.  * RETURNS
  1685.  *  void
  1686.  *****************************************************************************/
  1687. void MoveCursorToPosition(EMSData *data, EMSPosition *dst)
  1688. {
  1689.     /*----------------------------------------------------------------*/
  1690.     /* Local Variables                                                */
  1691.     /*----------------------------------------------------------------*/
  1692.     S32 diff;
  1693.     U8 done_flag = 0;
  1694.     EMSPosition dst_copy = *dst;
  1695.     EMSPosition mapped_cursor_position;
  1696.     /*----------------------------------------------------------------*/
  1697.     /* Code Body                                                      */
  1698.     /*----------------------------------------------------------------*/
  1699.     EMS_map_position(data, &dst_copy, dst);
  1700.     EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1701.     diff = data->CurrentPosition.OffsetToText - dst->OffsetToText;
  1702.     if (diff < 0)
  1703.     {
  1704.         while (!done_flag)
  1705.         {
  1706.             EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1707.             if ((mapped_cursor_position.OffsetToText == dst->OffsetToText) &&
  1708.                 (mapped_cursor_position.Object == dst->Object))
  1709.             {
  1710.                 break;
  1711.             }
  1712.             if (ForwardCurrentPosition(data, 1) != 1)
  1713.             {
  1714.                 break;
  1715.             }
  1716.         }
  1717.     }
  1718.     else if (diff > 0)
  1719.     {
  1720.         while (!done_flag)
  1721.         {
  1722.             EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1723.             if ((mapped_cursor_position.OffsetToText == dst->OffsetToText) &&
  1724.                 (mapped_cursor_position.Object == dst->Object))
  1725.             {
  1726.                 break;
  1727.             }
  1728.             if (BackwardCurrentPosition(data, 1) != 1)
  1729.             {
  1730.                 break;
  1731.             }
  1732.         }
  1733.     }
  1734.     else
  1735.     {
  1736.         S32 old_OffsetToText = data->CurrentPosition.OffsetToText;
  1737.         while (data->CurrentPosition.OffsetToText == old_OffsetToText)
  1738.         {
  1739.             if (BackwardCurrentPosition(data, 1) != 1)
  1740.             {
  1741.                 break;
  1742.             }
  1743.         }
  1744.         if (data->CurrentPosition.OffsetToText < old_OffsetToText)
  1745.         {
  1746.             ForwardCurrentPosition(data, 1);
  1747.         }
  1748.         while (!done_flag)
  1749.         {
  1750.             EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1751.             if (mapped_cursor_position.Object == dst->Object)
  1752.             {
  1753.                 break;
  1754.             }
  1755.             if (ForwardCurrentPosition(data, 1) != 1)
  1756.             {
  1757.                 break;
  1758.             }
  1759.         }
  1760.     }
  1761. }
  1762. /* Moves the cursor backwards to the given position. If an object is encountered, it breaks  */
  1763. /* Returns 1 if dst is reached, otherwise, returns 0                                */
  1764. /*****************************************************************************
  1765.  * FUNCTION
  1766.  *  BackwardCurrentPositionObject
  1767.  * DESCRIPTION
  1768.  *  
  1769.  * PARAMETERS
  1770.  *  data        [?]     
  1771.  *  dst         [?]     
  1772.  * RETURNS
  1773.  *  
  1774.  *****************************************************************************/
  1775. U8 BackwardCurrentPositionObject(EMSData *data, EMSPosition *dst)
  1776. {
  1777.     /*----------------------------------------------------------------*/
  1778.     /* Local Variables                                                */
  1779.     /*----------------------------------------------------------------*/
  1780.     EMSPosition mapped_cursor_position;
  1781.     U8 done = 0;
  1782.     /*----------------------------------------------------------------*/
  1783.     /* Code Body                                                      */
  1784.     /*----------------------------------------------------------------*/
  1785.     if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1786.     {
  1787.         return (1);
  1788.     }
  1789.     while (!done)
  1790.     {
  1791.         if (BackwardCurrentPosition(data, 1) != 1)
  1792.         {
  1793.             done = 1;
  1794.             break;
  1795.         }
  1796.         EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1797.         if ((mapped_cursor_position.Object != NULL) && (mapped_cursor_position.Object->Type != EMS_TYPE_TEXT_FORMAT))
  1798.         {
  1799.             break;
  1800.         }
  1801.         if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1802.         {
  1803.             done = 1;
  1804.             break;
  1805.         }
  1806.     }
  1807.     return (done);
  1808. }
  1809. /*****************************************************************************
  1810.  * FUNCTION
  1811.  *  ForwardCurrentPositionObject
  1812.  * DESCRIPTION
  1813.  *  
  1814.  * PARAMETERS
  1815.  *  data        [?]     
  1816.  *  dst         [?]     
  1817.  * RETURNS
  1818.  *  
  1819.  *****************************************************************************/
  1820. U8 ForwardCurrentPositionObject(EMSData *data, EMSPosition *dst)
  1821. {
  1822.     /*----------------------------------------------------------------*/
  1823.     /* Local Variables                                                */
  1824.     /*----------------------------------------------------------------*/
  1825.     EMSPosition mapped_cursor_position;
  1826.     U8 done = 0;
  1827.     /*----------------------------------------------------------------*/
  1828.     /* Code Body                                                      */
  1829.     /*----------------------------------------------------------------*/
  1830.     if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1831.     {
  1832.         return (1);
  1833.     }
  1834.     while (!done)
  1835.     {
  1836.         if (ForwardCurrentPosition(data, 1) != 1)
  1837.         {
  1838.             done = 1;
  1839.             break;
  1840.         }
  1841.         EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1842.         if ((mapped_cursor_position.Object != NULL) && (mapped_cursor_position.Object->Type != EMS_TYPE_TEXT_FORMAT))
  1843.         {
  1844.             break;
  1845.         }
  1846.         if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1847.         {
  1848.             done = 1;
  1849.             break;
  1850.         }
  1851.     }
  1852.     return (done);
  1853. }
  1854. /* Moves the cursor backwards to the given position. If an object is encountered, it breaks  */
  1855. /* Returns 1 if dst is reached, otherwise, returns 0                                */
  1856. /*****************************************************************************
  1857.  * FUNCTION
  1858.  *  BackwardCurrentPositionSeekObject
  1859.  * DESCRIPTION
  1860.  *  
  1861.  * PARAMETERS
  1862.  *  data        [?]     
  1863.  *  dst         [?]     
  1864.  * RETURNS
  1865.  *  
  1866.  *****************************************************************************/
  1867. U8 BackwardCurrentPositionSeekObject(EMSData *data, EMSPosition *dst)
  1868. {
  1869.     /*----------------------------------------------------------------*/
  1870.     /* Local Variables                                                */
  1871.     /*----------------------------------------------------------------*/
  1872.     EMSPosition mapped_cursor_position;
  1873.     U8 done = 0;
  1874.     U8 object_flag = 0;
  1875.     EMSPosition last_object_position = data->CurrentPosition;
  1876.     S32 count = 0;
  1877.     /*----------------------------------------------------------------*/
  1878.     /* Code Body                                                      */
  1879.     /*----------------------------------------------------------------*/
  1880.     if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1881.     {
  1882.         return (1);
  1883.     }
  1884.     while (!done)
  1885.     {
  1886.         EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1887.         if ((mapped_cursor_position.Object != NULL) && (mapped_cursor_position.Object->Type != EMS_TYPE_TEXT_FORMAT))
  1888.         {
  1889.             last_object_position = data->CurrentPosition;
  1890.             object_flag = 1;
  1891.             if (count > 0)
  1892.             {
  1893.                 break;
  1894.             }
  1895.         }
  1896.         if (BackwardCurrentPosition(data, 1) != 1)
  1897.         {
  1898.             done = 1;
  1899.             break;
  1900.         }
  1901.         if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1902.         {
  1903.             done = 1;
  1904.             break;
  1905.         }
  1906.         count++;
  1907.     }
  1908.     EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1909.     if (object_flag && (count > 0) &&
  1910.         ((data->CurrentPosition.OffsetToText != dst->OffsetToText) || (data->CurrentPosition.Object != dst->Object)))
  1911.     {
  1912.         MoveCursorToPosition(data, &last_object_position);
  1913.     }
  1914.     else if (mapped_cursor_position.Object == NULL)
  1915.     {
  1916.         MoveCursorToPosition(data, &last_object_position);
  1917.     }
  1918.     return (done);
  1919. }
  1920. /*****************************************************************************
  1921.  * FUNCTION
  1922.  *  ForwardCurrentPositionSeekObject
  1923.  * DESCRIPTION
  1924.  *  
  1925.  * PARAMETERS
  1926.  *  data        [?]     
  1927.  *  dst         [?]     
  1928.  * RETURNS
  1929.  *  
  1930.  *****************************************************************************/
  1931. U8 ForwardCurrentPositionSeekObject(EMSData *data, EMSPosition *dst)
  1932. {
  1933.     /*----------------------------------------------------------------*/
  1934.     /* Local Variables                                                */
  1935.     /*----------------------------------------------------------------*/
  1936.     EMSPosition mapped_cursor_position;
  1937.     U8 done = 0;
  1938.     EMSPosition last_object_position = data->CurrentPosition;
  1939.     S32 count = 0;
  1940.     /*----------------------------------------------------------------*/
  1941.     /* Code Body                                                      */
  1942.     /*----------------------------------------------------------------*/
  1943.     if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1944.     {
  1945.         return (1);
  1946.     }
  1947.     while (!done)
  1948.     {
  1949.         EMS_map_position(data, &data->CurrentPosition, &mapped_cursor_position);
  1950.         if ((mapped_cursor_position.Object != NULL) && (mapped_cursor_position.Object->Type != EMS_TYPE_TEXT_FORMAT))
  1951.         {
  1952.             last_object_position = data->CurrentPosition;
  1953.             if (count > 0)
  1954.             {
  1955.                 break;
  1956.             }
  1957.         }
  1958.         if (ForwardCurrentPosition(data, 1) != 1)
  1959.         {
  1960.             done = 1;
  1961.             break;
  1962.         }
  1963.         if ((data->CurrentPosition.OffsetToText == dst->OffsetToText) && (data->CurrentPosition.Object == dst->Object))
  1964.         {
  1965.             done = 1;
  1966.             break;
  1967.         }
  1968.         count++;
  1969.     }
  1970.     MoveCursorToPosition(data, &last_object_position);
  1971.     return (done);
  1972. }
  1973. /* Returns true if the given position is the last position  */
  1974. /* p=un-mapped EMS position                        */
  1975. /*****************************************************************************
  1976.  * FUNCTION
  1977.  *  TestLastPosition
  1978.  * DESCRIPTION
  1979.  *  
  1980.  * PARAMETERS
  1981.  *  data        [?]     
  1982.  *  p           [?]     
  1983.  * RETURNS
  1984.  *  
  1985.  *****************************************************************************/
  1986. U8 TestLastPosition(EMSData *data, EMSPosition *p)
  1987. {
  1988.     /*----------------------------------------------------------------*/
  1989.     /* Local Variables                                                */
  1990.     /*----------------------------------------------------------------*/
  1991.     EMSPosition dst;
  1992.     /*----------------------------------------------------------------*/
  1993.     /* Code Body                                                      */
  1994.     /*----------------------------------------------------------------*/
  1995.     EMS_map_position(data, p, &dst);
  1996.     if ((dst.OffsetToText >= data->textLength) && (dst.Object == NULL))
  1997.     {
  1998.         return (1);
  1999.     }
  2000.     else
  2001.     {
  2002.         return (0);
  2003.     }
  2004. }
  2005. /* Returns true if the given position is the first position */
  2006. /* p=un-mapped EMS position                        */
  2007. /*****************************************************************************
  2008.  * FUNCTION
  2009.  *  TestFirstPosition
  2010.  * DESCRIPTION
  2011.  *  
  2012.  * PARAMETERS
  2013.  *  data        [?]     
  2014.  *  p           [?]     
  2015.  * RETURNS
  2016.  *  
  2017.  *****************************************************************************/
  2018. U8 TestFirstPosition(EMSData *data, EMSPosition *p)
  2019. {
  2020.     /*----------------------------------------------------------------*/
  2021.     /* Local Variables                                                */
  2022.     /*----------------------------------------------------------------*/
  2023.     /*----------------------------------------------------------------*/
  2024.     /* Code Body                                                      */
  2025.     /*----------------------------------------------------------------*/
  2026.     if ((p->OffsetToText == 0) && (p->Object == NULL))
  2027.     {
  2028.         return (1);
  2029.     }
  2030.     else
  2031.     {
  2032.         return (0);
  2033.     }
  2034. }
  2035. /*****************************************************************************
  2036.  * FUNCTION
  2037.  *  EMS_map_position
  2038.  * DESCRIPTION
  2039.  *  
  2040.  * PARAMETERS
  2041.  *  data        [?]     
  2042.  *  src         [?]     
  2043.  *  dst         [?]     
  2044.  * RETURNS
  2045.  *  void
  2046.  *****************************************************************************/
  2047. void EMS_map_position(EMSData *data, EMSPosition *src, EMSPosition *dst)
  2048. {
  2049.     /*----------------------------------------------------------------*/
  2050.     /* Local Variables                                                */
  2051.     /*----------------------------------------------------------------*/
  2052.     /*----------------------------------------------------------------*/
  2053.     /* Code Body                                                      */
  2054.     /*----------------------------------------------------------------*/
  2055.     if (data->listHead == NULL)
  2056.     {
  2057.         *dst = *src;
  2058.     }
  2059.     else
  2060.     {
  2061.         EMSObject *object;
  2062.         if (src->Object == NULL)
  2063.         {
  2064.             object = data->listHead;
  2065.             if (object->OffsetToText == src->OffsetToText)
  2066.             {
  2067.             #if(EMS_ENABLE_TESTFIX_OBJECT_ORDERING)
  2068.                 /* Nov-21-2003: TESTFIX: text format object followed by EMS object fix                 */
  2069.                 /* Object ordering must be as text format object followed by other objects to use this fix   */
  2070.                 if (object != NULL)
  2071.                 {
  2072.                     if (object->Type == EMS_TYPE_TEXT_FORMAT)
  2073.                     {
  2074.                         if (object->next != NULL)
  2075.                         {
  2076.                             if (object->next->OffsetToText == object->OffsetToText)
  2077.                             {
  2078.                                 dst->OffsetToText = src->OffsetToText;
  2079.                                 dst->Object = object->next;
  2080.                             }
  2081.                             else
  2082.                             {
  2083.                                 dst->OffsetToText = src->OffsetToText;
  2084.                                 dst->Object = object;
  2085.                             }
  2086.                         }
  2087.                         else
  2088.                         {
  2089.                             dst->OffsetToText = src->OffsetToText;
  2090.                             dst->Object = object;
  2091.                         }
  2092.                     }
  2093.                     else
  2094.                     {
  2095.                         dst->OffsetToText = src->OffsetToText;
  2096.                         dst->Object = object;
  2097.                     }
  2098.                 }
  2099.                 else
  2100.                 {
  2101.                     /* Nov-21-2003: TESTFIX: ends */
  2102.             #endif /* (EMS_ENABLE_TESTFIX_OBJECT_ORDERING) */ 
  2103.                     dst->OffsetToText = src->OffsetToText;
  2104.                     dst->Object = object;
  2105.                 #if(EMS_ENABLE_TESTFIX_OBJECT_ORDERING)
  2106.                     /* Nov-21-2003: TESTFIX    */
  2107.                 }
  2108.                 /* Nov-21-2003: TESTFIX: ends */
  2109.                 #endif /* (EMS_ENABLE_TESTFIX_OBJECT_ORDERING) */ 
  2110.             }
  2111.             else
  2112.             {
  2113.                 dst->OffsetToText = src->OffsetToText;
  2114.                 dst->Object = NULL;
  2115.             }
  2116.         }
  2117.         else
  2118.         {
  2119.             object = src->Object->next;
  2120.             if ((object != NULL) && (object->OffsetToText == src->OffsetToText))
  2121.             {
  2122.             #if(EMS_ENABLE_TESTFIX_OBJECT_ORDERING)
  2123.                 /* Nov-21-2003: TESTFIX: text format object followed by EMS object fix                 */
  2124.                 /* Object ordering must be as text format object followed by other objects to use this fix   */
  2125.                 if (object->Type == EMS_TYPE_TEXT_FORMAT)
  2126.                 {
  2127.                     if (object->next != NULL)
  2128.                     {
  2129.                         if (object->next->OffsetToText == object->OffsetToText)
  2130.                         {
  2131.                             dst->OffsetToText = src->OffsetToText;
  2132.                             dst->Object = object->next;
  2133.                         }
  2134.                         else
  2135.                         {
  2136.                             dst->OffsetToText = src->OffsetToText;
  2137.                             dst->Object = NULL;
  2138.                         }
  2139.                     }
  2140.                     else
  2141.                     {
  2142.                         dst->OffsetToText = src->OffsetToText;
  2143.                         dst->Object = NULL;
  2144.                     }
  2145.                 }
  2146.                 else
  2147.                 {
  2148.                     /* Nov-21-2003: TESTFIX: ends */
  2149.             #endif /* (EMS_ENABLE_TESTFIX_OBJECT_ORDERING) */ 
  2150.                     dst->OffsetToText = src->OffsetToText;
  2151.                     dst->Object = object;
  2152.                 #if(EMS_ENABLE_TESTFIX_OBJECT_ORDERING)
  2153.                     /* Nov-21-2003: TESTFIX    */
  2154.                 }
  2155.                 /* Nov-21-2003: TESTFIX: ends */
  2156.                 #endif /* (EMS_ENABLE_TESTFIX_OBJECT_ORDERING) */ 
  2157.             }
  2158.             else
  2159.             {
  2160.                 dst->OffsetToText = src->OffsetToText;
  2161.                 dst->Object = NULL;
  2162.             }
  2163.         }
  2164.     }
  2165. }
  2166. U8 EMS_view_mode = 0;
  2167. #ifdef __MMI_MESSAGES_EMS__
  2168. #define EMS_ANIMATION_TIME    500
  2169. S32 EMS_current_predefined_sound_ID = -1;
  2170. U8 EMS_object_pre_defined_sound_flag = 0;
  2171. U8 EMS_object_user_defined_melody_flag = 0;
  2172. PU8 EMS_editor_sound_icon = NULL;
  2173. PU8 EMS_editor_melody_icon = NULL;
  2174. S32 EMS_object_x = 0;
  2175. S32 EMS_object_y = 0;
  2176. S32 EMS_object_width = 0;
  2177. S32 EMS_object_height = 0;
  2178. S32 EMS_object_frame_counter = 0;
  2179. S32 EMS_object_n_frames = 0;
  2180. S32 EMS_object_current_frame_size = 0;
  2181. S32 EMS_object_repeat_counter = 0;
  2182. U8 EMS_object_animation_timer_flag = 0;
  2183. U8 EMS_object_predefined_animation_timer_flag = 0;
  2184. EMSObject *EMS_current_object = NULL;
  2185. PU8 EMS_current_predefined_image;
  2186. extern PU8 get_image(U16 i);
  2187. extern void AudioPlayIMelodyString(U8 *string, U16 len, U8 style);
  2188. extern U16 EMS_predefined_sounds[];
  2189. #ifdef __MMI_AUDIO_PLAYER__
  2190. extern BOOL mmi_audply_is_play_activated(void);
  2191. #endif 
  2192. /*****************************************************************************
  2193.  * FUNCTION
  2194.  *  EMS_normal_play_pre_defined_sound
  2195.  * DESCRIPTION
  2196.  *  
  2197.  * PARAMETERS
  2198.  *  ID      [IN]        
  2199.  * RETURNS
  2200.  *  void
  2201.  *****************************************************************************/
  2202. void EMS_normal_play_pre_defined_sound(S32 ID)
  2203. {
  2204.     /*----------------------------------------------------------------*/
  2205.     /* Local Variables                                                */
  2206.     /*----------------------------------------------------------------*/
  2207.     /*----------------------------------------------------------------*/
  2208.     /* Code Body                                                      */
  2209.     /*----------------------------------------------------------------*/
  2210.     if (ID < 0)
  2211.     {
  2212.         ID = 0;
  2213.     }
  2214.     if (ID > 9)
  2215.     {
  2216.         ID = 9;
  2217.     }
  2218.     EMS_current_predefined_sound_ID = EMS_predefined_sounds[ID];
  2219.     StopCurrentKeyPadTone();
  2220.     AudioPlayReq((U8) EMS_current_predefined_sound_ID, DEVICE_AUDIO_PLAY_ONCE);
  2221. }
  2222. /*****************************************************************************
  2223.  * FUNCTION
  2224.  *  EMS_normal_stop_pre_defined_sound
  2225.  * DESCRIPTION
  2226.  *  
  2227.  * PARAMETERS
  2228.  *  void
  2229.  * RETURNS
  2230.  *  void
  2231.  *****************************************************************************/
  2232. void EMS_normal_stop_pre_defined_sound(void)
  2233. {
  2234.     /*----------------------------------------------------------------*/
  2235.     /* Local Variables                                                */
  2236.     /*----------------------------------------------------------------*/
  2237.     /*----------------------------------------------------------------*/
  2238.     /* Code Body                                                      */
  2239.     /*----------------------------------------------------------------*/
  2240.     AudioStopReq((U8) EMS_current_predefined_sound_ID);
  2241. }
  2242. #include "Mdi_datatype.h"
  2243. #include "Mdi_audio.h"
  2244. /*****************************************************************************
  2245.  * FUNCTION
  2246.  *  EMS_normal_play_user_defined_melody
  2247.  * DESCRIPTION
  2248.  *  
  2249.  * PARAMETERS
  2250.  *  data        [?]         
  2251.  *  length      [IN]        
  2252.  * RETURNS
  2253.  *  void
  2254.  *****************************************************************************/
  2255. void EMS_normal_play_user_defined_melody(U8 *data, S32 length)
  2256. {
  2257.     /*----------------------------------------------------------------*/
  2258.     /* Local Variables                                                */
  2259.     /*----------------------------------------------------------------*/
  2260.     /*----------------------------------------------------------------*/
  2261.     /* Code Body                                                      */
  2262.     /*----------------------------------------------------------------*/
  2263.     mdi_audio_play_string(data, (U16) length, MDI_FORMAT_IMELODY, DEVICE_AUDIO_PLAY_ONCE, NULL, NULL);
  2264. }
  2265. /*****************************************************************************
  2266.  * FUNCTION
  2267.  *  EMS_normal_stop_user_defined_melody
  2268.  * DESCRIPTION
  2269.  *  
  2270.  * PARAMETERS
  2271.  *  void
  2272.  * RETURNS
  2273.  *  void
  2274.  *****************************************************************************/
  2275. void EMS_normal_stop_user_defined_melody(void)
  2276. {
  2277.     /*----------------------------------------------------------------*/
  2278.     /* Local Variables                                                */
  2279.     /*----------------------------------------------------------------*/
  2280.     /*----------------------------------------------------------------*/
  2281.     /* Code Body                                                      */
  2282.     /*----------------------------------------------------------------*/
  2283.     mdi_audio_stop_string();
  2284. }
  2285. /*****************************************************************************
  2286.  * FUNCTION
  2287.  *  EMS_silent_play_pre_defined_sound
  2288.  * DESCRIPTION
  2289.  *  
  2290.  * PARAMETERS
  2291.  *  ID      [IN]        
  2292.  * RETURNS
  2293.  *  void
  2294.  *****************************************************************************/
  2295. void EMS_silent_play_pre_defined_sound(S32 ID)
  2296. {
  2297.     /*----------------------------------------------------------------*/
  2298.     /* Local Variables                                                */
  2299.     /*----------------------------------------------------------------*/
  2300.     /*----------------------------------------------------------------*/
  2301.     /* Code Body                                                      */
  2302.     /*----------------------------------------------------------------*/
  2303.     UI_UNUSED_PARAMETER(ID);
  2304. }
  2305. /*****************************************************************************
  2306.  * FUNCTION
  2307.  *  EMS_silent_stop_pre_defined_sound
  2308.  * DESCRIPTION
  2309.  *  
  2310.  * PARAMETERS
  2311.  *  void
  2312.  * RETURNS
  2313.  *  void
  2314.  *****************************************************************************/
  2315. void EMS_silent_stop_pre_defined_sound(void)
  2316. {
  2317.     /*----------------------------------------------------------------*/
  2318.     /* Local Variables                                                */
  2319.     /*----------------------------------------------------------------*/
  2320.     /*----------------------------------------------------------------*/
  2321.     /* Code Body                                                      */
  2322.     /*----------------------------------------------------------------*/
  2323. }
  2324. /*****************************************************************************
  2325.  * FUNCTION
  2326.  *  EMS_silent_play_user_defined_melody
  2327.  * DESCRIPTION
  2328.  *  
  2329.  * PARAMETERS
  2330.  *  data        [?]         
  2331.  *  length      [IN]        
  2332.  * RETURNS
  2333.  *  void
  2334.  *****************************************************************************/
  2335. void EMS_silent_play_user_defined_melody(U8 *data, S32 length)
  2336. {
  2337.     /*----------------------------------------------------------------*/
  2338.     /* Local Variables                                                */
  2339.     /*----------------------------------------------------------------*/
  2340.     /*----------------------------------------------------------------*/
  2341.     /* Code Body                                                      */
  2342.     /*----------------------------------------------------------------*/
  2343.     UI_UNUSED_PARAMETER(data);
  2344.     UI_UNUSED_PARAMETER(length);
  2345. }
  2346. /*****************************************************************************
  2347.  * FUNCTION
  2348.  *  EMS_silent_stop_user_defined_melody
  2349.  * DESCRIPTION
  2350.  *  
  2351.  * PARAMETERS
  2352.  *  void
  2353.  * RETURNS
  2354.  *  void
  2355.  *****************************************************************************/
  2356. void EMS_silent_stop_user_defined_melody(void)
  2357. {
  2358.     /*----------------------------------------------------------------*/
  2359.     /* Local Variables                                                */
  2360.     /*----------------------------------------------------------------*/
  2361.     /*----------------------------------------------------------------*/
  2362.     /* Code Body                                                      */
  2363.     /*----------------------------------------------------------------*/
  2364. }
  2365. void (*EMS_play_pre_defined_sound) (S32 ID) = EMS_normal_play_pre_defined_sound;
  2366. void (*EMS_stop_pre_defined_sound) (void) = EMS_normal_stop_pre_defined_sound;
  2367. void (*EMS_play_user_defined_melody) (U8 *data, S32 length) = EMS_normal_play_user_defined_melody;
  2368. void (*EMS_stop_user_defined_melody) (void) = EMS_normal_stop_user_defined_melody;
  2369. /*****************************************************************************
  2370.  * FUNCTION
  2371.  *  EMS_enable_audio_playback
  2372.  * DESCRIPTION
  2373.  *  
  2374.  * PARAMETERS
  2375.  *  void
  2376.  * RETURNS
  2377.  *  void
  2378.  *****************************************************************************/
  2379. void EMS_enable_audio_playback(void)
  2380. {
  2381.     /*----------------------------------------------------------------*/
  2382.     /* Local Variables                                                */
  2383.     /*----------------------------------------------------------------*/
  2384.     /*----------------------------------------------------------------*/
  2385.     /* Code Body                                                      */
  2386.     /*----------------------------------------------------------------*/
  2387.     EMS_play_pre_defined_sound = EMS_normal_play_pre_defined_sound;
  2388.     EMS_stop_pre_defined_sound = EMS_normal_stop_pre_defined_sound;
  2389.     EMS_play_user_defined_melody = EMS_normal_play_user_defined_melody;
  2390.     EMS_stop_user_defined_melody = EMS_normal_stop_user_defined_melody;
  2391. }
  2392. /*****************************************************************************
  2393.  * FUNCTION
  2394.  *  EMS_disable_audio_playback
  2395.  * DESCRIPTION
  2396.  *  
  2397.  * PARAMETERS
  2398.  *  void
  2399.  * RETURNS
  2400.  *  void
  2401.  *****************************************************************************/
  2402. void EMS_disable_audio_playback(void)
  2403. {
  2404.     /*----------------------------------------------------------------*/
  2405.     /* Local Variables                                                */
  2406.     /*----------------------------------------------------------------*/
  2407.     /*----------------------------------------------------------------*/
  2408.     /* Code Body                                                      */
  2409.     /*----------------------------------------------------------------*/
  2410.     EMS_play_pre_defined_sound = EMS_silent_play_pre_defined_sound;
  2411.     EMS_stop_pre_defined_sound = EMS_silent_stop_pre_defined_sound;
  2412.     EMS_play_user_defined_melody = EMS_silent_play_user_defined_melody;
  2413.     EMS_stop_user_defined_melody = EMS_silent_stop_user_defined_melody;
  2414. }
  2415. /*****************************************************************************
  2416.  * FUNCTION
  2417.  *  gui_EMS_input_box_measure_object
  2418.  * DESCRIPTION
  2419.  *  
  2420.  * PARAMETERS
  2421.  *  o           [?]     
  2422.  *  width       [?]     
  2423.  *  height      [?]     
  2424.  * RETURNS
  2425.  *  void
  2426.  *****************************************************************************/
  2427. void gui_EMS_input_box_measure_object(EMSObject *o, S32 *width, S32 *height)
  2428. {
  2429.     /*----------------------------------------------------------------*/
  2430.     /* Local Variables                                                */
  2431.     /*----------------------------------------------------------------*/
  2432.     /*----------------------------------------------------------------*/
  2433.     /* Code Body                                                      */
  2434.     /*----------------------------------------------------------------*/
  2435.     *width = 0;
  2436.     *height = 0;
  2437.     switch (o->Type)
  2438.     {
  2439.         case EMS_TYPE_PIC:
  2440.         {
  2441.             *width = o->data->picture.hDim;
  2442.             *height = o->data->picture.vDim;
  2443.         }
  2444.             break;
  2445.         case EMS_TYPE_USERDEF_ANM:
  2446.         {
  2447.             *width = o->data->animation.hDim;
  2448.             *height = o->data->animation.vDim;
  2449.         }
  2450.             break;
  2451.         case EMS_TYPE_PREDEF_ANM:
  2452.         {
  2453.             PU8 image = get_image(EMS_predefined_animations[o->PredefNo]);
  2454.             gui_measure_image(image, width, height);
  2455.         }
  2456.             break;
  2457.         case EMS_TYPE_PREDEF_SND:
  2458.         {
  2459.             gui_measure_image(EMS_editor_sound_icon, width, height);
  2460.         }
  2461.             break;
  2462.         case EMS_TYPE_USERDEF_SND:
  2463.         {
  2464.             gui_measure_image(EMS_editor_melody_icon, width, height);
  2465.         }
  2466.             break;
  2467.     }
  2468. }
  2469. void gui_EMS_input_box_display_object_pic(S32 x,S32 y,U8* src,S32 src_size,S32 w,S32 h,S32 bits_per_pixel)
  2470. {
  2471.     gdi_color palette[64]; // maximum is 64 colors
  2472.     switch(bits_per_pixel)
  2473.     {
  2474.     case 1:
  2475.         {
  2476.             palette[0] = gdi_act_color_from_rgb(255,255,255,255); // white
  2477.             palette[1] = gdi_act_color_from_rgb(255,0,0,0); // black
  2478.         }
  2479.         break;
  2480.     case 2:
  2481.         {
  2482.             palette[0] = gdi_act_color_from_rgb(255,0,0,0); // black
  2483.             palette[1] = gdi_act_color_from_rgb(255,85,85,85); // dark grey
  2484.             palette[2] = gdi_act_color_from_rgb(255,170,170,170); // light grey
  2485.             palette[3] = gdi_act_color_from_rgb(255,255,255,255); // white
  2486.         }
  2487.         break;
  2488.     case 6:
  2489.         {
  2490.             S32 R,G,B,index;
  2491.             const static S32 value[]={0,85,170,255};
  2492.             index = 0;
  2493.             for(R=0;R<4;R++)
  2494.                 for(G=0;G<4;G++)
  2495.                     for(B=0;B<4;B++,index++)
  2496.                         palette[index] = gdi_act_color_from_rgb(255,value[R],value[G],value[B]);
  2497.         }
  2498.         break;
  2499.     default:
  2500.         MMI_ASSERT(0); // strange bits_per_pixel
  2501.         break;
  2502.     }
  2503.     gdi_bits_draw(
  2504.         x,y,
  2505.         src,
  2506.         src_size,
  2507.         w,h,
  2508.         bits_per_pixel,
  2509.         palette);
  2510. }
  2511. /*****************************************************************************
  2512.  * FUNCTION
  2513.  *  EMS_input_box_show_animation_frame
  2514.  * DESCRIPTION
  2515.  *  
  2516.  * PARAMETERS
  2517.  *  void
  2518.  * RETURNS
  2519.  *  void
  2520.  *****************************************************************************/
  2521. void EMS_input_box_show_animation_frame(void)
  2522. {
  2523.     S32 width,height;
  2524.     EMS_object_frame_counter++;
  2525.     if (EMS_object_frame_counter >= EMS_current_object->data->animation.cFrame)
  2526.         EMS_object_frame_counter = 0;
  2527.     width = EMS_current_object->data->animation.hDim;
  2528.     height = EMS_current_object->data->animation.vDim;
  2529.     
  2530.     gui_EMS_input_box_display_object_pic(
  2531.                         EMS_object_x,EMS_object_y,
  2532.                         (U8*) (EMS_current_object->data->animation.pdu 
  2533.                              + EMS_object_frame_counter * EMS_object_current_frame_size),
  2534.                         EMS_object_current_frame_size,
  2535.                         width,
  2536.                         height,
  2537.                         EMS_current_object->data->animation.bitsPerPixel);
  2538.     gui_BLT_double_buffer(EMS_object_x, EMS_object_y, EMS_object_x + width - 1, EMS_object_y + height - 1);
  2539.     if (EMS_current_object->data->animation.cFrame != 0)
  2540.     {
  2541.         if (EMS_object_frame_counter % EMS_current_object->data->animation.cFrame == 0)
  2542.             EMS_object_repeat_counter++;
  2543.     }
  2544.     if (EMS_current_object->data->animation.cRepeat != 0 
  2545.     && EMS_object_repeat_counter >= EMS_current_object->data->animation.cRepeat)
  2546.     {
  2547.         gui_cancel_timer(NULL);
  2548.     }
  2549.     else
  2550.     {
  2551.         gui_start_timer((EMS_current_object->data->animation.Duration + 1) * 100, EMS_input_box_show_animation_frame);
  2552.     }
  2553. }
  2554. /*****************************************************************************
  2555.  * FUNCTION
  2556.  *  EMS_input_box_show_predefined_animation_frame
  2557.  * DESCRIPTION
  2558.  *  
  2559.  * PARAMETERS
  2560.  *  void
  2561.  * RETURNS
  2562.  *  void
  2563.  *****************************************************************************/
  2564. void EMS_input_box_show_predefined_animation_frame(void)
  2565. {
  2566.     /*----------------------------------------------------------------*/
  2567.     /* Local Variables                                                */
  2568.     /*----------------------------------------------------------------*/
  2569.     /*----------------------------------------------------------------*/
  2570.     /* Code Body                                                      */
  2571.     /*----------------------------------------------------------------*/
  2572.     EMS_object_frame_counter++;
  2573.     if (EMS_object_frame_counter >= EMS_object_n_frames)
  2574.     {
  2575.         EMS_object_frame_counter = 0;
  2576.     }
  2577.     gui_push_clip();
  2578.     gui_set_clip(0, MMI_title_y + MMI_title_height, UI_device_width - 1, UI_device_height - MMI_button_bar_height - 2);
  2579.     gui_show_animated_image_frame(
  2580.         EMS_object_x,
  2581.         EMS_object_y,
  2582.         EMS_current_predefined_image,
  2583.         (S16) EMS_object_frame_counter);
  2584.     gui_pop_clip();
  2585. #if(UI_DOUBLE_BUFFER_SUPPORT)
  2586.     gui_BLT_double_buffer(
  2587.         EMS_object_x,
  2588.         EMS_object_y,
  2589.         EMS_object_x + EMS_object_width - 1,
  2590.         EMS_object_y + EMS_object_height - 1);
  2591. #endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
  2592.     gui_start_timer(EMS_ANIMATION_TIME, EMS_input_box_show_predefined_animation_frame);
  2593. }
  2594. /*****************************************************************************
  2595.  * FUNCTION
  2596.  *  gui_EMS_input_box_display_object
  2597.  * DESCRIPTION
  2598.  *  
  2599.  * PARAMETERS
  2600.  *  x                   [IN]        
  2601.  *  y                   [IN]        
  2602.  *  o                   [?]         
  2603.  *  display_cursor      [IN]        
  2604.  * RETURNS
  2605.  *  void
  2606.  *****************************************************************************/
  2607. void gui_EMS_input_box_display_object(S32 x, S32 y, EMSObject *o, U8 display_cursor)
  2608. {
  2609. #if(EMS_ENABLE_EDITOR_OBJECT_PLAYBACK)
  2610.     U8 playback_flag = 1;
  2611. #else
  2612.     U8 playback_flag = 0;
  2613.     if (EMS_view_mode)
  2614.         playback_flag = 1;
  2615. #endif
  2616.     switch (o->Type)
  2617.     {