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

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   gui_ems.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   EMS editor - UI component
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  * -------
  53.  *
  54.  *============================================================================
  55.  *             HISTORY
  56.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  57.  *------------------------------------------------------------------------------
  58.  * removed!
  59.  *
  60.  * removed!
  61.  * removed!
  62.  * removed!
  63.  *
  64.  * removed!
  65.  * removed!
  66.  * removed!
  67.  *
  68.  * removed!
  69.  * removed!
  70.  * removed!
  71.  *
  72.  * removed!
  73.  * removed!
  74.  * removed!
  75.  *
  76.  * removed!
  77.  * removed!
  78.  * removed!
  79.  *
  80.  * removed!
  81.  * removed!
  82.  * removed!
  83.  *
  84.  * removed!
  85.  * removed!
  86.  * removed!
  87.  *
  88.  * removed!
  89.  * removed!
  90.  * removed!
  91.  *
  92.  * removed!
  93.  * removed!
  94.  * removed!
  95.  *
  96.  * removed!
  97.  * removed!
  98.  * removed!
  99.  *
  100.  * removed!
  101.  * removed!
  102.  * removed!
  103.  *
  104.  * removed!
  105.  * removed!
  106.  * removed!
  107.  *
  108.  * removed!
  109.  * removed!
  110.  * removed!
  111.  *
  112.  * removed!
  113.  * removed!
  114.  * removed!
  115.  *
  116.  * removed!
  117.  * removed!
  118.  * removed!
  119.  *
  120.  * removed!
  121.  * removed!
  122.  * removed!
  123.  *
  124.  * removed!
  125.  * removed!
  126.  * removed!
  127.  *
  128.  * removed!
  129.  * removed!
  130.  * removed!
  131.  *
  132.  * removed!
  133.  * removed!
  134.  * removed!
  135.  *
  136.  * removed!
  137.  * removed!
  138.  * removed!
  139.  *
  140.  * removed!
  141.  * removed!
  142.  * removed!
  143.  *
  144.  * removed!
  145.  * removed!
  146.  * removed!
  147.  *
  148.  * removed!
  149.  * removed!
  150.  * removed!
  151.  *
  152.  * removed!
  153.  * removed!
  154.  * removed!
  155.  *
  156.  * removed!
  157.  * removed!
  158.  * removed!
  159.  *
  160.  * removed!
  161.  * removed!
  162.  * removed!
  163.  *
  164.  * removed!
  165.  * removed!
  166.  * removed!
  167.  *
  168.  * removed!
  169.  * removed!
  170.  * removed!
  171.  *
  172.  * removed!
  173.  * removed!
  174.  * removed!
  175.  *
  176.  * removed!
  177.  * removed!
  178.  * removed!
  179.  *
  180.  * removed!
  181.  * removed!
  182.  * removed!
  183.  *
  184.  * removed!
  185.  * removed!
  186.  * removed!
  187.  *
  188.  * removed!
  189.  * removed!
  190.  * removed!
  191.  *
  192.  * removed!
  193.  * removed!
  194.  * removed!
  195.  *
  196.  * removed!
  197.  * removed!
  198.  * removed!
  199.  *
  200.  * removed!
  201.  * removed!
  202.  * removed!
  203.  *
  204.  * removed!
  205.  * removed!
  206.  * removed!
  207.  *
  208.  * removed!
  209.  * removed!
  210.  * removed!
  211.  *
  212.  * removed!
  213.  * removed!
  214.  * removed!
  215.  *
  216.  * removed!
  217.  * removed!
  218.  * removed!
  219.  *
  220.  * removed!
  221.  * removed!
  222.  * removed!
  223.  *
  224.  * removed!
  225.  * removed!
  226.  * removed!
  227.  *
  228.  * removed!
  229.  * removed!
  230.  * removed!
  231.  *
  232.  * removed!
  233.  * removed!
  234.  * removed!
  235.  *
  236.  * removed!
  237.  * removed!
  238.  * removed!
  239.  *
  240.  * removed!
  241.  * removed!
  242.  * removed!
  243.  *
  244.  * removed!
  245.  * removed!
  246.  * removed!
  247.  *
  248.  * removed!
  249.  * removed!
  250.  * removed!
  251.  *
  252.  * removed!
  253.  * removed!
  254.  * removed!
  255.  *
  256.  * removed!
  257.  * removed!
  258.  * removed!
  259.  *
  260.  * removed!
  261.  * removed!
  262.  * removed!
  263.  *
  264.  * removed!
  265.  * removed!
  266.  * removed!
  267.  *
  268.  * removed!
  269.  * removed!
  270.  * removed!
  271.  *
  272.  * removed!
  273.  * removed!
  274.  * removed!
  275.  *
  276.  * removed!
  277.  * removed!
  278.  * removed!
  279.  *
  280.  * removed!
  281.  * removed!
  282.  * removed!
  283.  *
  284.  * removed!
  285.  * removed!
  286.  * removed!
  287.  *
  288.  * removed!
  289.  * removed!
  290.  * removed!
  291.  *
  292.  * removed!
  293.  * removed!
  294.  * removed!
  295.  *
  296.  * removed!
  297.  * removed!
  298.  * removed!
  299.  *
  300.  * removed!
  301.  * removed!
  302.  * removed!
  303.  *
  304.  * removed!
  305.  * removed!
  306.  * removed!
  307.  *
  308.  * removed!
  309.  * removed!
  310.  * removed!
  311.  *
  312.  * removed!
  313.  * removed!
  314.  * removed!
  315.  *
  316.  * removed!
  317.  * removed!
  318.  * removed!
  319.  *
  320.  * removed!
  321.  * removed!
  322.  * removed!
  323.  *
  324.  * removed!
  325.  * removed!
  326.  * removed!
  327.  *
  328.  * removed!
  329.  * removed!
  330.  * removed!
  331.  *
  332.  * removed!
  333.  * removed!
  334.  * removed!
  335.  *
  336.  * removed!
  337.  * removed!
  338.  * removed!
  339.  *
  340.  * removed!
  341.  * removed!
  342.  * removed!
  343.  *
  344.  * removed!
  345.  * removed!
  346.  * removed!
  347.  *
  348.  * removed!
  349.  * removed!
  350.  * removed!
  351.  *
  352.  * removed!
  353.  * removed!
  354.  * removed!
  355.  *
  356.  * removed!
  357.  * removed!
  358.  * removed!
  359.  *
  360.  * removed!
  361.  * removed!
  362.  * removed!
  363.  *
  364.  * removed!
  365.  * removed!
  366.  * removed!
  367.  *
  368.  * removed!
  369.  * removed!
  370.  * removed!
  371.  *
  372.  * removed!
  373.  * removed!
  374.  * removed!
  375.  *
  376.  * removed!
  377.  * removed!
  378.  * removed!
  379.  *
  380.  * removed!
  381.  * removed!
  382.  * removed!
  383.  *
  384.  * removed!
  385.  * removed!
  386.  * removed!
  387.  *
  388.  * removed!
  389.  * removed!
  390.  * removed!
  391.  *
  392.  * removed!
  393.  * removed!
  394.  * removed!
  395.  *
  396.  *------------------------------------------------------------------------------
  397.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  398.  *============================================================================
  399.  ****************************************************************************/
  400. /**********************************************************************************
  401.    Filename:      gui_ems.c
  402.    Author:        manju
  403.    Date Created:  March-25-2003
  404.    Contains:      EMS input box
  405. **********************************************************************************/
  406. #include "SettingProfile.h"
  407. #include "KeyBrd.h"
  408. #include "gui_ems.h"
  409. #include "gui_inputs.h"
  410. #include "wgui_categories_defs.h"
  411. #include "DebugInitDef.h"
  412. #include "wgui_categories_inputs.h"
  413. #ifdef __MMI_HINDI_ALG__
  414. #include  "hf_rules.h"
  415. #include  "gui.h"
  416. #endif /* __MMI_HINDI_ALG__ */ 
  417. #include "MMI_features.h"
  418. #include "TimerEvents.h"
  419. #ifdef __MMI_LANG_VIETNAMESE__
  420. #include "gui_lang_viet.h"
  421. #endif 
  422. #ifdef __MMI_ZI_V7__
  423. #include "ezicmn.h"
  424. #endif 
  425. #if defined(__MMI_ZI_ARABIC__) || defined(__MMI_ZI_PERSIAN__)
  426. #include "zi8ARshape.h"
  427. #endif /* defined(__MMI_ZI_ARABIC__) || defined(__MMI_ZI_PERSIAN__) */ 
  428. /* for R2L characters */
  429. #include "BIDIDEF.h"
  430. #include "BIDIProt.h"
  431. /* for R2L characters */
  432. extern BOOL r2lMMIFlag;
  433. #ifdef __MMI_BIDI_ALG__
  434. extern U8 visual_str[];
  435. extern U8 MMI_bidi_input_type;
  436. #endif /* __MMI_BIDI_ALG__ */ 
  437. /* MTK Steven 20050505 */
  438. #ifdef __MMI_LANG_THAI__
  439. #define isThaiChar(ch)  (((ch >= 0x0E01) && (ch <= 0x0E7F))? (1):(0))
  440. #endif 
  441. /* MTK End */
  442. extern U16 StopMyTimer(U16 nTimerId);
  443. extern U16 StartMyTimerInt(U16 nTimerId, U32 nTimeDuration, oslTimerFuncPtr TimerExpiry, U8 alignment);
  444. extern U8 mmi_msg_get_seg_num(void);
  445. extern void UI_set_current_text_color(color c);
  446. extern S32 UI_cursor_x1;    /* cursor x1 postioon */
  447. extern S32 UI_cursor_y1;    /* cursor y1 position */
  448. extern void UI_draw_horizontal_line(S32 x1, S32 x2, S32 y, color c);
  449. #if defined(__MMI_T9__)
  450. extern void T9SynT9WithInputBoxForEMSInputBox(void);
  451. #endif 
  452. #ifdef __MMI_ARSHAPING_ENGINE__
  453. extern void ArabicShapeEngine2(PU16 , PU16 , PU16 , PU16 );
  454. #endif 
  455. #if defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__)
  456. extern U16 shaping_str[];
  457. extern S32 unshaped_text_len;
  458. extern U16 gui_get_ems_text_actual_idx(UI_EMS_input_box *b, U16 OffsetToText);
  459. extern U16 OrgToSha[];
  460. #endif /* defined(__MMI_LANG_ARABIC__) || defined(__MMI_LANG_PERSIAN__) */ 
  461. /* PMT END LANGUAGE 20060104 */
  462. #if(0)
  463. #include "DebugInitDef.h"
  464. #endif /* (0) */ 
  465. #ifdef __MMI_HINDI_ALG__
  466. #define UI_CHK_CONSONANT(ch)  (( (ch >= 0x15 && ch <= 0x39) || (ch >= 0x58 && ch <= 0x5f) || ch==0x50 )? (1):(0))
  467. #endif 
  468. #define EMS_SHOW_HORIZONTAL_RULE_FOR_NEWLINE       0
  469. /* START PMT NEERAJ 20050916 */
  470. #define EMS_SHOW_HORIZONTAL_RULE_FOR_ALL_LINES        1
  471. /* END PMT NEERAJ 20050916 */
  472. #define EMS_ENABLE_EDITOR_OBJECT_PLAYBACK          0
  473. #define EMS_PREVENT_CRLF_DISPLAY                1
  474. #define EMS_USE_CRLF_COMBINATION                1
  475. #define EMS_USE_ESC_COMBINATION                    1
  476. #define EMS_USE_GSM_EXTENDED                    0
  477. #define EMS_DISPLAY_SPECIAL_CHARACTERS             0
  478. #define EMS_ENABLE_GRAPHICAL_CURSOR_MOVEMENT       1
  479. #define EMS_INPUTBOX_PARAGRAPH_BREAK_CHARACTER        0x0A
  480. #define EMS_ENABLE_SPECIAL_FONT_DISPLAY               1
  481. #define EMS_HEADER_SCROLL_SIZE                     20
  482. #define EMS_ENABLE_TESTFIX_OBJECT_ORDERING            1
  483. #define EMS_DEFAULT_DCS_ALLOCATED_LENGTH           mmi_msg_get_seg_num() * 153
  484. #define EMS_UCS2_DCS_ALLOCATED_LENGTH              mmi_msg_get_seg_num() * 67
  485. #if defined(__MMI_MESSAGES_CONCAT_SMS__)
  486. #define EMS_DEFAULT_DCS_AVAILABLE_LENGTH           mmi_msg_get_seg_num() * 153
  487. #define EMS_UCS2_DCS_AVAILABLE_LENGTH              mmi_msg_get_seg_num() * 67
  488. #else /* defined(__MMI_MESSAGES_CONCAT_SMS__) */ 
  489. #define EMS_DEFAULT_DCS_AVAILABLE_LENGTH           160
  490. #define EMS_UCS2_DCS_AVAILABLE_LENGTH              70
  491. #endif /* defined(__MMI_MESSAGES_CONCAT_SMS__) */ 
  492. UI_EMS_input_box_theme *current_EMS_input_box_theme = NULL;
  493. stFontAttribute UI_EMS_inputbox_small_font = {0, 0, 0, SMALL_FONT, 0, 0};
  494. stFontAttribute UI_EMS_inputbox_medium_font = {0, 0, 0, MEDIUM_FONT, 0, 0};
  495. #ifdef __MMI_DIALLING_FONT__
  496. stFontAttribute UI_EMS_inputbox_large_font = {0, 0, 0, MEDIUM_FONT, 0, 0};
  497. #else 
  498. stFontAttribute UI_EMS_inputbox_large_font = {0, 0, 0, LARGE_FONT, 0, 0};
  499. #endif 
  500. /* PMT VIKAS GUPTA START 20051129 */
  501. U8 check_for_halant = 0;
  502. /* PMT VIKAS GUPTA END 20051129 */
  503. stFontAttribute UI_EMS_inputbox_current_font = {0, 0, 0, MEDIUM_FONT, 0, 0};
  504. color UI_EMS_inputbox_text_color = {0, 0, 0, 100};
  505. #if(EMS_DISPLAY_SPECIAL_CHARACTERS)
  506. /* Temporary data for debugging  */
  507. const U8 EMS_CR_display_character[] = 
  508. {
  509.     0x04, 0x00, 0xAF, 0x00, 0x00, 0x00,
  510.     0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0C, 0x12, 0x00, 0x00, 0x00,
  511.     0x34, 0x12, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20,
  512.     0x34, 0x12, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20,
  513.     0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  514.     0xFF, 0xFF, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0x20,
  515.     0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0xFF, 0xFF, 0xFF, 0xFF,
  516.     0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0xFF, 0xFF,
  517.     0xFF, 0xFF, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20,
  518.     0x04, 0x20, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20,
  519.     0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20,
  520.     0x34, 0x12, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20,
  521.     0x34, 0x12,
  522. };
  523. const U8 EMS_LF_display_character[] = 
  524. {
  525.     0x04, 0x00, 0xAF, 0x00, 0x00, 0x00,
  526.     0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0C, 0x12, 0x00, 0x00, 0x00,
  527.     0x34, 0x12, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00,
  528.     0x34, 0x12, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00,
  529.     0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0xC0, 0x00,
  530.     0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00,
  531.     0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  532.     0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xFF, 0xFF,
  533.     0xFF, 0xFF, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00,
  534.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00,
  535.     0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00,
  536.     0x34, 0x12, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00,
  537.     0x34, 0x12,
  538. };
  539. const U8 EMS_ESC_display_character[] = 
  540. {
  541.     0x04, 0x00, 0xAF, 0x00, 0x00, 0x00,
  542.     0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0C, 0x12, 0x00, 0x00, 0x00,
  543.     0x34, 0x12, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F,
  544.     0x34, 0x12, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F,
  545.     0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  546.     0xFF, 0xFF, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0xFF, 0xFF, 0x42, 0x1F, 0x42, 0x1F,
  547.     0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF,
  548.     0xFF, 0xFF, 0xFF, 0xFF, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0xFF, 0xFF,
  549.     0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F,
  550.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F,
  551.     0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F,
  552.     0x34, 0x12, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F, 0x42, 0x1F,
  553.     0x34, 0x12,
  554. };
  555. #endif /* (EMS_DISPLAY_SPECIAL_CHARACTERS) */ 
  556. #if(!UI_DISABLE_EMS_INPUT_BOX)
  557. EMSObjData UI_EMS_normal_text_format_object_data;
  558. EMSObject UI_EMS_normal_text_format_object;
  559. #ifdef __MMI_MESSAGES_EMS__
  560. extern void EMS_cancel_object_focus(void);
  561. extern U16 EMS_predefined_animations[];
  562. #endif /* __MMI_MESSAGES_EMS__ */ 
  563. #define EMS_DATA_END_OFFSET(x)   ((x))
  564. /* Basic Latin,Latin 1,Latin Extended A, Latin Extended B */
  565. /* Cyrillic */
  566. /* Latin Extended Additional  */
  567. /* Combining Marks  */
  568. /* Basic Arabic  */
  569. /* Arabic Presentation Forms-A */
  570. /* Arabic Presentation Forms-B */
  571. #define UI_MULTI_LINE_INPUT_BOX_ALPHABETIC_CHARACTER(c)                                                              
  572.    ((((UI_character_type)(c)<=(UI_character_type)0x0240) ||                                                          
  573.    ( ((UI_character_type)(c)>=(UI_character_type)0x0400) && ((UI_character_type)(c)<=(UI_character_type)0x04FF) ) || 
  574.    ( ((UI_character_type)(c)>=(UI_character_type)0x1E00) && ((UI_character_type)(c)<=(UI_character_type)0x1EFF) ) || 
  575.    ( ((UI_character_type)(c)>=(UI_character_type)0x0300) && ((UI_character_type)(c)<=(UI_character_type)0x036F) ) || 
  576.    ( ((UI_character_type)(c)>=(UI_character_type)0x0621) && ((UI_character_type)(c)<=(UI_character_type)0x0653) ) || 
  577.    ( ((UI_character_type)(c)>=(UI_character_type)0xFB50) && ((UI_character_type)(c)<=(UI_character_type)0xFDFF) ) || 
  578.    ( ((UI_character_type)(c)>=(UI_character_type)0xFE70) && ((UI_character_type)(c)<=(UI_character_type)0xFEFF) ) )?(1):(0))
  579. kal_uint16 BackwardCurrentPositionSkipCR(EMSData *data);
  580. kal_uint16 ForwardCurrentPositionSkipCR(EMSData *data);
  581. void MoveCurrentPosition(EMSData *data, EMSPosition *start, EMSPosition *end, kal_uint16 steps);
  582. void EMS_map_position(EMSData *data, EMSPosition *src, EMSPosition *dst);
  583. void MoveCursorToPosition(EMSData *data, EMSPosition *dst);
  584. U8 TestLastPosition(EMSData *data, EMSPosition *p);
  585. U8 TestFirstPosition(EMSData *data, EMSPosition *p);
  586. U8 BackwardCurrentPositionObject(EMSData *data, EMSPosition *dst);
  587. U8 ForwardCurrentPositionObject(EMSData *data, EMSPosition *dst);
  588. void EMS_move_graphical_cursor(EMSData *data, S32 start_x, S32 cursor_x, S32 max_count);
  589. /*****************************************************************************
  590.  * FUNCTION
  591.  *  gui_intialize_EMS
  592.  * DESCRIPTION
  593.  *  
  594.  * PARAMETERS
  595.  *  void
  596.  * RETURNS
  597.  *  void
  598.  *****************************************************************************/
  599. void gui_intialize_EMS(void)
  600. {
  601.     /*----------------------------------------------------------------*/
  602.     /* Local Variables                                                */
  603.     /*----------------------------------------------------------------*/
  604.     /*----------------------------------------------------------------*/
  605.     /* Code Body                                                      */
  606.     /*----------------------------------------------------------------*/
  607.     UI_EMS_normal_text_format_object.Type = EMS_TYPE_TEXT_FORMAT;
  608.     UI_EMS_normal_text_format_object.next = NULL;
  609.     UI_EMS_normal_text_format_object.prev = NULL;
  610.     UI_EMS_normal_text_format_object.OffsetToText = 0;
  611.     UI_EMS_normal_text_format_object.data = &UI_EMS_normal_text_format_object_data;
  612.     ResetTextFormat(&UI_EMS_normal_text_format_object.data->text_format);
  613. #ifdef __MMI_MESSAGES_TEXT_FORMAT_ALIGN_LEFT__
  614.     UI_EMS_normal_text_format_object.data->text_format.Alignment = EMS_ALIGN_LEFT;
  615. #else 
  616.     UI_EMS_normal_text_format_object.data->text_format.Alignment = EMS_ALIGN_LANG_DEP;
  617. #endif 
  618. }
  619. /*****************************************************************************
  620.  * FUNCTION
  621.  *  gui_set_EMS_input_box_theme
  622.  * DESCRIPTION
  623.  *  
  624.  * PARAMETERS
  625.  *  b       [?]     
  626.  *  t       [?]     
  627.  * RETURNS
  628.  *  void
  629.  *****************************************************************************/
  630. void gui_set_EMS_input_box_theme(UI_EMS_input_box *b, UI_EMS_input_box_theme *t)
  631. {
  632.     /*----------------------------------------------------------------*/
  633.     /* Local Variables                                                */
  634.     /*----------------------------------------------------------------*/
  635.     /*----------------------------------------------------------------*/
  636.     /* Code Body                                                      */
  637.     /*----------------------------------------------------------------*/
  638.     b->normal_filler = t->normal_filler;
  639.     b->disabled_filler = t->disabled_filler;
  640.     b->selected_filler = t->selected_filler;
  641.     b->normal_text_color = t->normal_text_color;
  642.     b->selected_text_color = t->selected_text_color;
  643.     b->selection_color = t->selection_color;
  644.     b->cursor_color = t->cursor_color;
  645.     b->boundary_color = t->boundary_color;  /* Pixtel - Gurinder - 3/14/2004 - Editor With BG Image */
  646.     b->flags |= t->flags;
  647. }
  648. /*****************************************************************************
  649.  * FUNCTION
  650.  *  gui_set_EMS_input_box_current_theme
  651.  * DESCRIPTION
  652.  *  
  653.  * PARAMETERS
  654.  *  b       [?]     
  655.  * RETURNS
  656.  *  void
  657.  *****************************************************************************/
  658. void gui_set_EMS_input_box_current_theme(UI_EMS_input_box *b)
  659. {
  660.     /*----------------------------------------------------------------*/
  661.     /* Local Variables                                                */
  662.     /*----------------------------------------------------------------*/
  663.     /*----------------------------------------------------------------*/
  664.     /* Code Body                                                      */
  665.     /*----------------------------------------------------------------*/
  666.     b->normal_filler = current_EMS_input_box_theme->normal_filler;
  667.     b->disabled_filler = current_EMS_input_box_theme->disabled_filler;
  668.     b->selected_filler = current_EMS_input_box_theme->selected_filler;
  669.     b->normal_text_color = current_EMS_input_box_theme->normal_text_color;
  670.     b->selected_text_color = current_EMS_input_box_theme->selected_text_color;
  671.     b->selection_color = current_EMS_input_box_theme->selection_color;
  672.     b->cursor_color = current_EMS_input_box_theme->cursor_color;
  673.     b->boundary_color = current_EMS_input_box_theme->boundary_color;    /* Pixtel - Gurinder - 3/14/2004 - Editor With BG Image */
  674.     b->flags |= current_EMS_input_box_theme->flags;
  675. }
  676. extern S16 MMI_current_input_ext_type;
  677. /*****************************************************************************
  678.  * FUNCTION
  679.  *  gui_create_EMS_input_box
  680.  * DESCRIPTION
  681.  *  
  682.  * PARAMETERS
  683.  *  b           [?]         
  684.  *  x           [IN]        
  685.  *  y           [IN]        
  686.  *  width       [IN]        
  687.  *  height      [IN]        
  688.  * RETURNS
  689.  *  void
  690.  *****************************************************************************/
  691. void gui_create_EMS_input_box(UI_EMS_input_box *b, S32 x, S32 y, S32 width, S32 height)
  692. {
  693.     /*----------------------------------------------------------------*/
  694.     /* Local Variables                                                */
  695.     /*----------------------------------------------------------------*/
  696.     /*----------------------------------------------------------------*/
  697.     /* Code Body                                                      */
  698.     /*----------------------------------------------------------------*/
  699.     b->x = x;
  700.     b->y = y;
  701.     b->width = width;
  702.     b->height = height;
  703.     b->flags = 0;
  704.     MMI_current_input_ext_type = 0;
  705.     gui_set_EMS_input_box_current_theme(b);
  706.     b->overflow_callback = UI_dummy_function;
  707.     b->change_callback = UI_dummy_function;
  708.     gui_create_vertical_scrollbar(
  709.         &b->vbar,
  710.         b->x + b->width - current_EMS_input_box_theme->vbar_width - 1,
  711.         b->y + 1,
  712.         current_EMS_input_box_theme->vbar_width,
  713.         b->height - 2);
  714.     b->data = NULL;
  715.     b->start_position.Object = NULL;
  716.     b->start_position.OffsetToText = 0;
  717.     b->end_position.Object = NULL;
  718.     b->end_position.OffsetToText = 0;
  719.     b->display_y = 0;
  720.     ResetTextFormat(&b->text_format);
  721. #if defined(__MMI_HINDI_ALG__)
  722.     reset_use_multitap();
  723. #endif 
  724.     b->text_format.Alignment = UI_EMS_normal_text_format_object.data->text_format.Alignment;
  725.     b->saved_cursor_ax = -1;
  726.     b->underline_color = gui_color(0, 0, 128);
  727.     b->strikethrough_color = gui_color(192, 0, 0);
  728.     b->paragraph_color = gui_color(0, 128, 0);
  729.     
  730.     b->locate_cursor_flag = 1;
  731.     
  732. }
  733. #if(EMS_USE_DCS)
  734. /*****************************************************************************
  735.  * FUNCTION
  736.  *  gui_EMS_change_DCS
  737.  * DESCRIPTION
  738.  *  
  739.  * PARAMETERS
  740.  *  b       [?]     
  741.  * RETURNS
  742.  *  void
  743.  *****************************************************************************/
  744. void gui_EMS_change_DCS(UI_EMS_input_box *b)
  745. {
  746.     /*----------------------------------------------------------------*/
  747.     /* Local Variables                                                */
  748.     /*----------------------------------------------------------------*/
  749.     /*----------------------------------------------------------------*/
  750.     /* Code Body                                                      */
  751.     /*----------------------------------------------------------------*/
  752.     if (b->UCS2_count > 0)
  753.     {
  754.         EMSSetDCS(b->data, SMSAL_UCS2_DCS);
  755.     #if defined(__MMI_MESSAGES_CONCAT_SMS__)
  756.         b->available_length = b->data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num() >> 1;
  757.     #else 
  758.         b->available_length = EMS_UCS2_DCS_AVAILABLE_LENGTH;
  759.     #endif 
  760.     }
  761.     else
  762.     {
  763.         EMSSetDCS(b->data, SMSAL_DEFAULT_DCS);
  764.     #if defined(__MMI_MESSAGES_CONCAT_SMS__)
  765.         b->available_length = b->data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num();
  766.     #else 
  767.         b->available_length = EMS_DEFAULT_DCS_AVAILABLE_LENGTH;
  768.     #endif 
  769.     }
  770. }
  771. #endif /* (EMS_USE_DCS) */ 
  772. /*****************************************************************************
  773.  * FUNCTION
  774.  *  gui_set_EMS_input_box_data
  775.  * DESCRIPTION
  776.  *  
  777.  * PARAMETERS
  778.  *  b       [?]     
  779.  *  d       [?]     
  780.  * RETURNS
  781.  *  void
  782.  *****************************************************************************/
  783. void gui_set_EMS_input_box_data(UI_EMS_input_box *b, EMSData *d)
  784. {
  785.     /*----------------------------------------------------------------*/
  786.     /* Local Variables                                                */
  787.     /*----------------------------------------------------------------*/
  788.     EMSObject *text_format_object;
  789.     U8 done = 0;
  790.     EMSPosition current_position;
  791.     /*----------------------------------------------------------------*/
  792.     /* Code Body                                                      */
  793.     /*----------------------------------------------------------------*/
  794.     b->data = d;
  795.     if (d == NULL)
  796.     {
  797.         return;
  798.     }
  799.     /* ResetCurrentPosition(b->data); */
  800.     b->UCS2_count = 0;
  801.     b->object_count = 0;
  802.     b->GSM_ext_count = 0;
  803. #if(EMS_USE_DCS)
  804.     if ((b->data->textLength > 0) || (b->data->listHead != NULL))
  805.     {
  806.         U8 r;
  807.         EMSPosition p = b->data->CurrentPosition;
  808.         EMSObject *current_object;
  809.         UI_character_type c;
  810.         p.OffsetToText = 0;
  811.         p.Object = b->data->listHead;
  812.         while (!done)
  813.         {
  814.             r = gui_EMS_input_box_get_next_object(d, &p, &c, &current_object);
  815.             switch (r)
  816.             {
  817.                 case 0:
  818.                     done = 1;
  819.                     break;
  820.                 case 1:
  821.                     if (UI_TEST_UCS2_CHARACTER(c))
  822.                     {
  823.                         b->UCS2_count++;
  824.                     }
  825.                     if (UI_TEST_GSM_EXTENDED(c))
  826.                     {
  827.                         b->GSM_ext_count++;
  828.                     }
  829.                     break;
  830.                 case 2:
  831.                     b->object_count++;
  832.                     break;
  833.             }
  834.         }
  835.     }
  836.     gui_EMS_change_DCS(b);
  837. #endif /* (EMS_USE_DCS) */ 
  838.     current_position.OffsetToText = 0;
  839.     current_position.Object = NULL;
  840.     text_format_object = GetTextFormatObjectAtPosition(b->data, &current_position);
  841.     if (text_format_object != NULL)
  842.     {
  843.         b->text_format = text_format_object->data->text_format;
  844.     }
  845.     b->saved_cursor_ax = -1;
  846. }
  847. /*****************************************************************************
  848.  * FUNCTION
  849.  *  EMS_get_remaining_length
  850.  * DESCRIPTION
  851.  *  
  852.  * PARAMETERS
  853.  *  data        [?]     
  854.  * RETURNS
  855.  *  
  856.  *****************************************************************************/
  857. S32 EMS_get_remaining_length(EMSData *data)
  858. {
  859.     /*----------------------------------------------------------------*/
  860.     /* Local Variables                                                */
  861.     /*----------------------------------------------------------------*/
  862.     /*----------------------------------------------------------------*/
  863.     /* Code Body                                                      */
  864.     /*----------------------------------------------------------------*/
  865.     if (data->dcs == SMSAL_DEFAULT_DCS)
  866. #if defined(__MMI_MESSAGES_CONCAT_SMS__)
  867.         return (data->Reminder.totalRemainingOctet -
  868.                 (data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num() -
  869.                  data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num()));
  870. #else /* defined(__MMI_MESSAGES_CONCAT_SMS__) */ 
  871.         return (data->Reminder.totalRemainingOctet -
  872.                 (EMS_DEFAULT_DCS_ALLOCATED_LENGTH - EMS_DEFAULT_DCS_AVAILABLE_LENGTH));
  873. #endif /* defined(__MMI_MESSAGES_CONCAT_SMS__) */ 
  874.     else
  875. #if defined(__MMI_MESSAGES_CONCAT_SMS__)
  876.         return (data->Reminder.totalRemainingOctet -
  877.                 (data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num() -
  878.                  data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num()));
  879. #else /* defined(__MMI_MESSAGES_CONCAT_SMS__) */ 
  880.         return (data->Reminder.totalRemainingOctet -
  881.                 ((EMS_UCS2_DCS_ALLOCATED_LENGTH << 1) - (EMS_UCS2_DCS_AVAILABLE_LENGTH << 1)));
  882. #endif /* defined(__MMI_MESSAGES_CONCAT_SMS__) */ 
  883. }
  884. #ifdef __MMI_MESSAGES_EMS__
  885. /*****************************************************************************
  886.  * FUNCTION
  887.  *  gui_EMS_input_box_set_text_format_object
  888.  * DESCRIPTION
  889.  *  
  890.  * PARAMETERS
  891.  *  b       [?]     
  892.  *  f       [?]     
  893.  * RETURNS
  894.  *  void
  895.  *****************************************************************************/
  896. void gui_EMS_input_box_set_text_format_object(UI_EMS_input_box *b, EMSTextFormat *f)
  897. {
  898.     /*----------------------------------------------------------------*/
  899.     /* Local Variables                                                */
  900.     /*----------------------------------------------------------------*/
  901.     /*----------------------------------------------------------------*/
  902.     /* Code Body                                                      */
  903.     /*----------------------------------------------------------------*/
  904.     if (f != NULL)
  905.     {
  906.         b->text_format = *f;
  907.     }
  908. }
  909. #endif /* __MMI_MESSAGES_EMS__ */ 
  910. /*****************************************************************************
  911.  * FUNCTION
  912.  *  gui_EMS_input_box_locate_cursor
  913.  * DESCRIPTION
  914.  *  
  915.  * PARAMETERS
  916.  *  b       [?]     
  917.  * RETURNS
  918.  *  void
  919.  *****************************************************************************/
  920. void gui_EMS_input_box_locate_cursor(UI_EMS_input_box *b)
  921. {
  922.     /*----------------------------------------------------------------*/
  923.     /* Local Variables                                                */
  924.     /*----------------------------------------------------------------*/
  925.     S32 box_height = b->height - 4;
  926. S32 cursory;
  927. S32 content_h;
  928.     /*----------------------------------------------------------------*/
  929.     /* Code Body                                                      */
  930.     /*----------------------------------------------------------------*/
  931.     b->flags |= UI_EMS_INPUT_BOX_DISABLE_DRAW;
  932.     gui_show_EMS_input_box(b);
  933.     b->flags &= ~UI_EMS_INPUT_BOX_DISABLE_DRAW;
  934.     if (b->flags & UI_EMS_INPUT_BOX_DISPLAY_HEADER)
  935.     {
  936. cursory = b->cursor_ay + b->header_height;
  937. content_h = b->display_height + b->header_height;
  938. }
  939. else
  940. {
  941. cursory = b->cursor_ay;
  942. content_h = b->display_height;
  943. }
  944. /*    if (b->flags & UI_EMS_INPUT_BOX_DISPLAY_HEADER)
  945.     {
  946.         if ((b->cursor_ay + b->header_height) < (-b->display_y))
  947.         {
  948.             b->display_y = -b->cursor_ay - b->header_height;
  949.         }
  950.         else if ((b->cursor_ay + b->header_height + b->cursor_line_height) > ((-b->display_y) + (box_height)))
  951.         {
  952.             b->display_y -=
  953.                 (b->cursor_ay + b->cursor_line_height) - ((-b->display_y) + (box_height - b->header_height));
  954.         }
  955.         if (b->display_y > 0)
  956.         {
  957.             b->display_y = 0;
  958.         }
  959.     }
  960.     else*/
  961.     {
  962.         if (cursory < (-b->display_y))
  963.         {
  964.             b->display_y = -cursory;
  965.         }
  966.         else if ((cursory + b->cursor_line_height) > ((-b->display_y) + box_height))
  967.         {
  968.             b->display_y -= (cursory + b->cursor_line_height) - ((-b->display_y) + box_height);
  969.         }
  970.         if ((b->display_y + content_h) < box_height)
  971.         {
  972.             b->display_y = (box_height) - content_h;
  973.         }
  974.         if (b->display_y > 0)
  975.         {
  976.             b->display_y = 0;
  977.         }
  978.     }
  979. }
  980. /*****************************************************************************
  981.  * FUNCTION
  982.  *  gui_EMS_input_box_reset_cursor_position
  983.  * DESCRIPTION
  984.  *  
  985.  * PARAMETERS
  986.  *  b       [?]     
  987.  * RETURNS
  988.  *  void
  989.  *****************************************************************************/
  990. void gui_EMS_input_box_reset_cursor_position(UI_EMS_input_box *b)
  991. {
  992.     /*----------------------------------------------------------------*/
  993.     /* Local Variables                                                */
  994.     /*----------------------------------------------------------------*/
  995.     /*----------------------------------------------------------------*/
  996.     /* Code Body                                                      */
  997.     /*----------------------------------------------------------------*/
  998.     if (b->data != NULL)
  999.     {
  1000.         ResetCurrentPosition(b->data);
  1001.         gui_EMS_input_box_locate_cursor(b);
  1002.     }
  1003. }
  1004. /*****************************************************************************
  1005.  * FUNCTION
  1006.  *  gui_EMS_input_box_get_previous_text_alignment
  1007.  * DESCRIPTION
  1008.  *  
  1009.  * PARAMETERS
  1010.  *  b       [?]     
  1011.  *  p       [?]     
  1012.  * RETURNS
  1013.  *  
  1014.  *****************************************************************************/
  1015. U8 gui_EMS_input_box_get_previous_text_alignment(UI_EMS_input_box *b, EMSPosition *p)
  1016. {
  1017.     /*----------------------------------------------------------------*/
  1018.     /* Local Variables                                                */
  1019.     /*----------------------------------------------------------------*/
  1020.     U8 done = 0;
  1021.     UI_character_type c;
  1022.     EMSObject *o;
  1023.     U8 r;
  1024.     EMSPosition current_position = *p;
  1025.     U8 alignment = UI_EMS_normal_text_format_object.data->text_format.Alignment;
  1026.     /*----------------------------------------------------------------*/
  1027.     /* Code Body                                                      */
  1028.     /*----------------------------------------------------------------*/
  1029.     while (!done)
  1030.     {
  1031.         r = gui_EMS_input_box_get_previous_object(b->data, &current_position, &c, &o);
  1032.         switch (r)
  1033.         {
  1034.             case 0:
  1035.                 done = 1;
  1036.                 break;
  1037.             case 1:
  1038.                 if (c == EMS_INPUTBOX_PARAGRAPH_BREAK_CHARACTER)
  1039.                 {
  1040.                     done = 1;
  1041.                 }
  1042.                 break;
  1043.             case 2:
  1044.                 if (o->Type == EMS_TYPE_TEXT_FORMAT)
  1045.                 {
  1046.                     alignment = o->data->text_format.Alignment;
  1047.                 }
  1048.                 break;
  1049.         }
  1050.     }
  1051.     return (alignment);
  1052. }
  1053. /* Sets the alignment of the whole paragraph to the value specified.
  1054.    Starts from the given cursor position.
  1055.    The cursor position given must be at the first position on the paragraph   */
  1056. /*****************************************************************************
  1057.  * FUNCTION
  1058.  *  gui_EMS_input_box_set_paragraph_text_alignment
  1059.  * DESCRIPTION
  1060.  *  
  1061.  * PARAMETERS
  1062.  *  b               [?]         
  1063.  *  p               [?]         
  1064.  *  alignment       [IN]        
  1065.  * RETURNS
  1066.  *  void
  1067.  *****************************************************************************/
  1068. void gui_EMS_input_box_set_paragraph_text_alignment(UI_EMS_input_box *b, EMSPosition *p, U8 alignment)
  1069. {
  1070.     /*----------------------------------------------------------------*/
  1071.     /* Local Variables                                                */
  1072.     /*----------------------------------------------------------------*/
  1073.     U8 done = 0;
  1074.     UI_character_type c;
  1075.     EMSObject *o;
  1076.     U8 r;
  1077.     EMSPosition current_position = *p;
  1078.     /*----------------------------------------------------------------*/
  1079.     /* Code Body                                                      */
  1080.     /*----------------------------------------------------------------*/
  1081.     while (!done)
  1082.     {
  1083.         r = gui_EMS_input_box_get_next_object(b->data, &current_position, &c, &o);
  1084.         switch (r)
  1085.         {
  1086.             case 0:
  1087.                 done = 1;
  1088.                 break;
  1089.             case 1:
  1090.                 if (c == EMS_INPUTBOX_PARAGRAPH_BREAK_CHARACTER)
  1091.                 {
  1092.                     done = 1;
  1093.                 }
  1094.                 break;
  1095.             case 2:
  1096.                 if (o->Type == EMS_TYPE_TEXT_FORMAT)
  1097.                 {
  1098.                     o->data->text_format.Alignment = (EMSALIGNMENT) alignment;
  1099.                 }
  1100.                 break;
  1101.         }
  1102.     }
  1103. }
  1104. /* Checks if the cursor is at the beginning of a paragraph  */
  1105. /*****************************************************************************
  1106.  * FUNCTION
  1107.  *  gui_EMS_input_box_test_paragraph_start
  1108.  * DESCRIPTION
  1109.  *  
  1110.  * PARAMETERS
  1111.  *  b       [?]     
  1112.  *  p       [?]     
  1113.  * RETURNS
  1114.  *  
  1115.  *****************************************************************************/
  1116. U8 gui_EMS_input_box_test_paragraph_start(UI_EMS_input_box *b, EMSPosition *p)
  1117. {
  1118.     /*----------------------------------------------------------------*/
  1119.     /* Local Variables                                                */
  1120.     /*----------------------------------------------------------------*/
  1121.     U8 paragraph_flag = 0;
  1122.     UI_character_type c;
  1123.     EMSObject *o;
  1124.     U8 r;
  1125.     EMSPosition current_position = *p;
  1126.     /*----------------------------------------------------------------*/
  1127.     /* Code Body                                                      */
  1128.     /*----------------------------------------------------------------*/
  1129.     if (TestFirstPosition(b->data, &current_position))
  1130.     {
  1131.         paragraph_flag = 1;
  1132.     }
  1133.     else
  1134.     {
  1135.         if (BackwardCurrentPosition(b->data, 1) == 1)
  1136.         {
  1137.             current_position = b->data->CurrentPosition;
  1138.             r = gui_EMS_input_box_get_next_object(b->data, &current_position, &c, &o);
  1139.             ForwardCurrentPosition(b->data, 1);
  1140.             if ((r == 1) && (c == EMS_INPUTBOX_PARAGRAPH_BREAK_CHARACTER))
  1141.             {
  1142.                 paragraph_flag = 1;
  1143.             }
  1144.         }
  1145.     }
  1146.     return (paragraph_flag);
  1147. }
  1148. /*****************************************************************************
  1149.  * FUNCTION
  1150.  *  gui_EMS_input_box_set_text_format_cursor_position
  1151.  * DESCRIPTION
  1152.  *  
  1153.  * PARAMETERS
  1154.  *  b       [?]     
  1155.  * RETURNS
  1156.  *  void
  1157.  *****************************************************************************/
  1158. void gui_EMS_input_box_set_text_format_cursor_position(UI_EMS_input_box *b)
  1159. {
  1160.     /*----------------------------------------------------------------*/
  1161.     /* Local Variables                                                */
  1162.     /*----------------------------------------------------------------*/
  1163.     U8 done = 0;
  1164.     EMSPosition current_position;
  1165.     EMSObject *current_text_format_object;
  1166.     UI_character_type c;
  1167.     EMSObject *o;
  1168.     U8 r;
  1169.     /*----------------------------------------------------------------*/
  1170.     /* Code Body                                                      */
  1171.     /*----------------------------------------------------------------*/
  1172.     b->text_format = UI_EMS_normal_text_format_object.data->text_format;
  1173.     if (b->data == NULL)
  1174.     {
  1175.         return;
  1176.     }
  1177.     current_position = b->data->CurrentPosition;
  1178.     current_text_format_object = b->data->CurrentTextFormatObj;
  1179.     if ((current_text_format_object != NULL)
  1180.         && (current_position.OffsetToText >= current_text_format_object->OffsetToText)
  1181.         && (current_position.OffsetToText <=
  1182.             (current_text_format_object->OffsetToText + current_text_format_object->data->text_format.textLength)))
  1183.     {
  1184.         b->text_format = current_text_format_object->data->text_format;
  1185.     }
  1186.     /* At the beginning of a paragraph ? Then locate the text alignment to be used   */
  1187.     if (gui_EMS_input_box_test_paragraph_start(b, &current_position))
  1188.     {
  1189.         while (!done)
  1190.         {
  1191.             r = gui_EMS_input_box_get_next_object(b->data, &current_position, &c, &o);
  1192.             switch (r)
  1193.             {
  1194.                 case 0:
  1195.                     b->text_format.Alignment = UI_EMS_normal_text_format_object.data->text_format.Alignment;
  1196.                     done = 1;
  1197.                     break;
  1198.                 case 1:
  1199.                     if (c == EMS_INPUTBOX_PARAGRAPH_BREAK_CHARACTER)
  1200.                     {
  1201.                         done = 1;
  1202.                     }
  1203.                     break;
  1204.                 case 2:
  1205.                     if (o->Type == EMS_TYPE_TEXT_FORMAT)
  1206.                     {
  1207.                         b->text_format.Alignment = o->data->text_format.Alignment;
  1208.                         done = 1;
  1209.                     }
  1210.                     break;
  1211.             }
  1212.         }
  1213.     }
  1214.     else
  1215.     {
  1216.         while (!done)
  1217.         {
  1218.             r = gui_EMS_input_box_get_previous_object(b->data, &current_position, &c, &o);
  1219.             switch (r)
  1220.             {
  1221.                 case 0:
  1222.                     done = 1;
  1223.                     break;
  1224.                 case 1:
  1225.                     if (c == EMS_INPUTBOX_PARAGRAPH_BREAK_CHARACTER)
  1226.                     {
  1227.                         done = 1;
  1228.                     }
  1229.                     break;
  1230.                 case 2:
  1231.                     if (o->Type == EMS_TYPE_TEXT_FORMAT)
  1232.                     {
  1233.                         b->text_format.Alignment = o->data->text_format.Alignment;
  1234.                         done = 1;
  1235.                     }
  1236.                     break;
  1237.             }
  1238.         }
  1239.     }
  1240. }
  1241. /*****************************************************************************
  1242.  * FUNCTION
  1243.  *  gui_EMS_input_box_set_cursor_position
  1244.  * DESCRIPTION
  1245.  *  
  1246.  * PARAMETERS
  1247.  *  b       [?]     
  1248.  *  p       [?]     
  1249.  * RETURNS
  1250.  *  void
  1251.  *****************************************************************************/
  1252. void gui_EMS_input_box_set_cursor_position(UI_EMS_input_box *b, EMSPosition *p)
  1253. {
  1254.     /*----------------------------------------------------------------*/
  1255.     /* Local Variables                                                */
  1256.     /*----------------------------------------------------------------*/
  1257.     /*----------------------------------------------------------------*/
  1258.     /* Code Body                                                      */
  1259.     /*----------------------------------------------------------------*/
  1260.     if (b->data != NULL)
  1261.     {
  1262.         ResetCurrentPosition(b->data);
  1263.         while (!
  1264.                ((b->data->CurrentPosition.OffsetToText == p->OffsetToText) &&
  1265.                 (b->data->CurrentPosition.Object == p->Object)))
  1266.         {
  1267.             if (ForwardCurrentPosition(b->data, 1) != 1)
  1268.             {
  1269.                 break;
  1270.             }
  1271.         }
  1272.         gui_EMS_input_box_locate_cursor(b);
  1273.     }
  1274. }
  1275. /* Macros for graphics functions */
  1276. extern stFontAttribute *UI_font;
  1277. extern U8 SetFont(stFontAttribute Font, U8 arrCount);
  1278. extern S32 UI_clip_x1, UI_clip_x2, UI_clip_y1, UI_clip_y2;
  1279. extern S32 UI_text_x, UI_text_y;
  1280. extern color UI_text_color;
  1281. #define EMS_SET_FONT(f)             
  1282.       {  UI_font=(f);               
  1283.          SetFont(*(f),0);           
  1284.       }
  1285. #define EMS_MOVE_TEXT_CURSOR(x,y)      
  1286.       {  UI_text_x=x;                  
  1287.          UI_text_y=y;                  
  1288.       }
  1289. #define EMS_SET_TEXT_COLOR(c)                     
  1290.       {  UI_text_color=c;                         
  1291.          UI_set_current_text_color(UI_text_color);
  1292.       }
  1293. /*****************************************************************************
  1294.  * FUNCTION
  1295.  *  gui_EMS_input_box_equal_text_format
  1296.  * DESCRIPTION
  1297.  *  
  1298.  * PARAMETERS
  1299.  *  t1      [?]     
  1300.  *  t2      [?]     
  1301.  * RETURNS
  1302.  *  
  1303.  *****************************************************************************/
  1304. U8 gui_EMS_input_box_equal_text_format(EMSTextFormat *t1, EMSTextFormat *t2)
  1305. {
  1306.     /*----------------------------------------------------------------*/
  1307.     /* Local Variables                                                */
  1308.     /*----------------------------------------------------------------*/
  1309.     /*----------------------------------------------------------------*/
  1310.     /* Code Body                                                      */
  1311.     /*----------------------------------------------------------------*/
  1312.     if (t1->Alignment != t2->Alignment)
  1313.     {
  1314.         return (0);
  1315.     }
  1316.     if (t1->bgColor != t2->bgColor)
  1317.     {
  1318.         return (0);
  1319.     }
  1320.     if (t1->fgColor != t2->fgColor)
  1321.     {
  1322.         return (0);
  1323.     }
  1324.     if (t1->FontSize != t2->FontSize)
  1325.     {
  1326.         return (0);
  1327.     }
  1328.     if (t1->isBold != t2->isBold)
  1329.     {
  1330.         return (0);
  1331.     }
  1332.     if (t1->isItalic != t2->isItalic)
  1333.     {
  1334.         return (0);
  1335.     }
  1336.     if (t1->isStrikethrough != t2->isStrikethrough)
  1337.     {
  1338.         return (0);
  1339.     }
  1340.     if (t1->isUnderline != t2->isUnderline)
  1341.     {
  1342.         return (0);
  1343.     }
  1344.     if (t1->textLength != t2->textLength)
  1345.     {
  1346.         return (0);
  1347.     }
  1348.     return (1);
  1349. }
  1350. #define EMS_EQUAL_TEXT_FORMAT(t1,t2) (~(memcmp((t1),(t2),sizeof(EMSTextFormat)))
  1351. #define EMS_ESCAPE_CHARACTER  (27)
  1352. /*****************************************************************************
  1353.  * FUNCTION
  1354.  *  gui_EMS_input_box_remove_extension_character
  1355.  * DESCRIPTION
  1356.  *  
  1357.  * PARAMETERS
  1358.  *  data        [?]     
  1359.  * RETURNS
  1360.  *  void
  1361.  *****************************************************************************/
  1362. void gui_EMS_input_box_remove_extension_character(EMSData *data)
  1363. {
  1364.     /*----------------------------------------------------------------*/
  1365.     /* Local Variables                                                */
  1366.     /*----------------------------------------------------------------*/
  1367.     U16 c, OffsetToText;
  1368.     U8 *textBuffer = data->textBuffer;
  1369.     U16 textBufferLength = data->textLength;
  1370.     EMSPosition currposition = data->CurrentPosition;
  1371. #if defined(__MMI_T9__)
  1372.     /* PMT VIKAS GUPTA START 20051129 */
  1373.     EMSPosition backupcurrposition = data->CurrentPosition;
  1374.     /* PMT VIKAS GUPTA END 20051129 */
  1375. #endif /* defined(__MMI_T9__) */ 
  1376.     kal_uint16 ret_char;
  1377.     EMSPosition dummyposition;
  1378.     EMSObject *ret_object;
  1379.     /*----------------------------------------------------------------*/
  1380.     /* Code Body                                                      */
  1381.     /*----------------------------------------------------------------*/
  1382.     if (textBuffer == NULL)
  1383.     {
  1384.         return;
  1385.     }
  1386.     ResetCurrentPosition(data);
  1387.     if (data->dcs == SMSAL_DEFAULT_DCS)
  1388.     {
  1389.         while ((OffsetToText = data->CurrentPosition.OffsetToText) < textBufferLength)
  1390.         {
  1391.         #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1392.             c = (U16) (textBuffer[OffsetToText + 1] | (textBuffer[OffsetToText] << 8));
  1393.         #else 
  1394.             c = (U16) (textBuffer[OffsetToText] | (textBuffer[OffsetToText + 1] << 8));
  1395.         #endif 
  1396.             if (c == EMS_ESCAPE_CHARACTER)
  1397.             {
  1398.                 dummyposition = data->CurrentPosition;
  1399.                 while (EMSGetNextObject(data, &dummyposition, &ret_char, &ret_object) == 2)
  1400.                 {
  1401.                     ForwardCurrentPosition(data, 1);
  1402.                     dummyposition = data->CurrentPosition;
  1403.                     if (ret_object->Type == EMS_TYPE_TEXT_FORMAT)
  1404.                     {
  1405.                         if (EMSGetPreviousObject(data, &dummyposition, &ret_char, &ret_object) == 1)
  1406.                         {
  1407.                             BackwardCurrentPosition(data, 1);
  1408.                             break;
  1409.                         }
  1410.                         dummyposition = data->CurrentPosition;
  1411.                     }
  1412.                 }
  1413.             #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1414.                 if (ForwardCurrentPosition(data, 1) != 1)
  1415.                 {
  1416.                     break;
  1417.                 }
  1418.                 CancelCurrentPosition(data, 1);
  1419.                 if (OffsetToText <= currposition.OffsetToText)
  1420.                 {
  1421.                     currposition.OffsetToText--;
  1422.                 }
  1423.                 OffsetToText = data->CurrentPosition.OffsetToText;
  1424.                 textBufferLength -= ENCODING_LENGTH;
  1425.             #else /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  1426.                 if (ForwardCurrentPosition(data, 1) != 1)
  1427.                 {
  1428.                     break;
  1429.                 }
  1430.                 CancelCurrentPosition(data, 1);
  1431.                 if (OffsetToText <= currposition.OffsetToText)
  1432.                 {
  1433.                     currposition.OffsetToText -= ENCODING_LENGTH;
  1434.                 }
  1435.                 OffsetToText = data->CurrentPosition.OffsetToText;
  1436.                 textBufferLength -= ENCODING_LENGTH;
  1437.             #endif /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  1438.             }
  1439.             if (ForwardCurrentPosition(data, 1) != 1)
  1440.             {
  1441.                 break;
  1442.             }
  1443.         }
  1444.     }
  1445.     MoveCursorToPosition(data, &currposition);
  1446. #if defined(__MMI_T9__)
  1447.     /* PMT VIKAS GUPTA START 20051129 */
  1448.     if (memcmp((const void*)&backupcurrposition, (const void*)&currposition, sizeof(EMSPosition)) == 0)
  1449.     {
  1450.         return;
  1451.     }
  1452.     /* PMT VIKAS GUPTA END 20051129 */
  1453.     T9SynT9WithInputBoxForEMSInputBox();
  1454. #endif /* defined(__MMI_T9__) */ 
  1455. }
  1456. /* Call before EMSPack  */
  1457. /*****************************************************************************
  1458.  * FUNCTION
  1459.  *  gui_EMS_input_box_insert_extension_character
  1460.  * DESCRIPTION
  1461.  *  
  1462.  * PARAMETERS
  1463.  *  data        [?]     
  1464.  * RETURNS
  1465.  *  void
  1466.  *****************************************************************************/
  1467. void gui_EMS_input_box_insert_extension_character(EMSData *data)
  1468. {
  1469.     /*----------------------------------------------------------------*/
  1470.     /* Local Variables                                                */
  1471.     /*----------------------------------------------------------------*/
  1472.     U16 c, OffsetToText;
  1473.     U8 *textBuffer = data->textBuffer;
  1474.     U16 textBufferLength = data->textLength;
  1475.     EMSPosition currposition = data->CurrentPosition;
  1476. #if defined(__MMI_T9__)
  1477.     /* PMT VIKAS GUPTA START 20051129 */
  1478.     EMSPosition backupcurrposition = data->CurrentPosition;
  1479.     /* PMT VIKAS GUPTA END 20051129 */
  1480. #endif /* defined(__MMI_T9__) */ 
  1481. #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1482.     U8 ESC_string[] = {0x00, 0x1B};
  1483. #else 
  1484.     U8 ESC_string[] = {0x1B, 0x00};
  1485. #endif 
  1486.     /*----------------------------------------------------------------*/
  1487.     /* Code Body                                                      */
  1488.     /*----------------------------------------------------------------*/
  1489.     if (textBuffer == NULL)
  1490.     {
  1491.         return;
  1492.     }
  1493.     ResetCurrentPosition(data);
  1494.     if (data->dcs == SMSAL_DEFAULT_DCS)
  1495.     {
  1496.         while ((OffsetToText = data->CurrentPosition.OffsetToText) < textBufferLength)
  1497.         {
  1498.         #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1499.             c = (U16) (textBuffer[OffsetToText + 1] | (textBuffer[OffsetToText] << 8));
  1500.         #else 
  1501.             c = (U16) (textBuffer[OffsetToText] | (textBuffer[OffsetToText + 1] << 8));
  1502.         #endif 
  1503.             if (UI_TEST_GSM_EXTENDED(c))
  1504.             {
  1505.                 AddString(data, ESC_string, 1, NULL);
  1506.                 if (OffsetToText <= currposition.OffsetToText)
  1507.                 {
  1508.                     currposition.OffsetToText += ENCODING_LENGTH;
  1509.                 }
  1510.                 OffsetToText = data->CurrentPosition.OffsetToText;
  1511.                 /* MTK Elvis 20031126 */
  1512.                 textBufferLength += ENCODING_LENGTH;
  1513.                 /* MTK end */
  1514.             }
  1515.             if (ForwardCurrentPosition(data, 1) != 1)
  1516.             {
  1517.                 break;
  1518.             }
  1519.         }
  1520.     }
  1521.     MoveCursorToPosition(data, &currposition);
  1522. #if defined(__MMI_T9__)
  1523.     /* PMT VIKAS GUPTA START 20051129 */
  1524.     if (memcmp((const void*)&backupcurrposition, (const void*)&currposition, sizeof(EMSPosition)) == 0)
  1525.     {
  1526.         return;
  1527.     }
  1528.     /* PMT VIKAS GUPTA END 20051129 */
  1529.     T9SynT9WithInputBoxForEMSInputBox();
  1530. #endif /* defined(__MMI_T9__) */ 
  1531. }
  1532. #if(EMS_USE_DCS)
  1533. #if(EMS_USE_CRLF_COMBINATION || EMS_USE_ESC_COMBINATION)
  1534. /* Deletes one object/character before cursor position and updates UCS2 and Object counters  */
  1535. /* Also handles CRLF combination                                              */
  1536. /*****************************************************************************
  1537.  * FUNCTION
  1538.  *  gui_EMS_cancel_current_position
  1539.  * DESCRIPTION
  1540.  *  
  1541.  * PARAMETERS
  1542.  *  b       [?]     
  1543.  * RETURNS
  1544.  *  
  1545.  *****************************************************************************/
  1546. U8 gui_EMS_cancel_current_position(UI_EMS_input_box *b)
  1547. {
  1548. #ifdef __MMI_HINDI_ALG__
  1549.     /*----------------------------------------------------------------*/
  1550.     /* Local Variables                                                */
  1551.     /*----------------------------------------------------------------*/
  1552.     S32 lst_pos = 0;
  1553.     S32 cancel_two_pos = 0;
  1554.     UI_character_type current_character1 = 0;
  1555.     U8 object_type_check1 = 0;
  1556.     EMSObject *o1;
  1557.     EMSPosition p1 = b->data->CurrentPosition;
  1558.     EMSData *data_chk_type1 = b->data;
  1559.     /*----------------------------------------------------------------*/
  1560.     /* Code Body                                                      */
  1561.     /*----------------------------------------------------------------*/
  1562.     if (TestLastPosition(b->data, &(b->data->CurrentPosition)))
  1563.     {
  1564.         lst_pos = 1;
  1565.     }
  1566. #endif /* __MMI_HINDI_ALG__ */ 
  1567.     if (BackwardCurrentPosition(b->data, 1) == 1)
  1568.     {
  1569.         EMSPosition p = b->data->CurrentPosition;
  1570.         EMSObject *current_object;
  1571.         UI_character_type c;
  1572.         U8 r;
  1573.         S32 count;
  1574.         U8 dcs_change = 0;
  1575.         r = gui_EMS_input_box_get_next_object(b->data, &p, &c, &current_object);
  1576.     #ifdef __MMI_HINDI_ALG__
  1577.         if (lst_pos)
  1578.         {
  1579.             if (b->data->CurrentPosition.OffsetToText >= 4 &&
  1580.                 UI_TEST_LF_CHARACTER(b->data->textBuffer[b->data->CurrentPosition.OffsetToText]) &&
  1581.                 UI_TEST_CR_CHARACTER(b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 2]))
  1582.             {
  1583.                 b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 2] = 0;
  1584.                 b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 1] = 0;
  1585.                 cancel_two_pos = 1;
  1586.             }
  1587.             b->data->textBuffer[b->data->CurrentPosition.OffsetToText] = 0;
  1588.             b->data->textBuffer[b->data->CurrentPosition.OffsetToText + 1] = 0;
  1589.         }
  1590.     #endif /* __MMI_HINDI_ALG__ */ 
  1591.         ForwardCurrentPosition(b->data, 1);
  1592.         switch (r)
  1593.         {
  1594.             case 0:
  1595.                 break;
  1596.             case 1:
  1597.         #if(EMS_USE_CRLF_COMBINATION)
  1598.                 if (UI_TEST_LF_CHARACTER(c))
  1599.                 {
  1600.                     count = BackwardCurrentPosition(b->data, 2);
  1601.                     if (count == 2)
  1602.                     {
  1603.                         p = b->data->CurrentPosition;
  1604.                         r = gui_EMS_input_box_get_next_object(b->data, &p, &c, &current_object);
  1605.                         if ((r == 1) && UI_TEST_CR_CHARACTER(c))
  1606.                         {
  1607.                             ForwardCurrentPosition(b->data, 2);
  1608.                             CancelCurrentPosition(b->data, 1);
  1609.                             count = 0;
  1610.                         }
  1611.                     }
  1612.                     ForwardCurrentPosition(b->data, (U16) count);
  1613.                 }
  1614.                 else
  1615.         #endif /* (EMS_USE_CRLF_COMBINATION) */ 
  1616.                 if (UI_TEST_UCS2_CHARACTER(c))
  1617.                 {
  1618.                     if (b->UCS2_count > 0)
  1619.                     {
  1620.                         b->UCS2_count--;
  1621.                         if (b->UCS2_count == 0)
  1622.                         {
  1623.                             dcs_change = 1;
  1624.                             gui_EMS_change_DCS(b);
  1625.                         }
  1626.                     }
  1627.                 }
  1628.                 else if (UI_TEST_GSM_EXTENDED(c))
  1629.                 {
  1630.                     if (b->GSM_ext_count > 0)
  1631.                     {
  1632.                         b->GSM_ext_count--;
  1633.                     }
  1634.                 }
  1635.                 break;
  1636.             case 2:
  1637.                 /* MTK Joy added for text format case, get the character and set the parameters accordingly, 1230 */
  1638.                 if (current_object->Type == 0)
  1639.                 {
  1640.                     r = gui_EMS_input_box_get_next_object(b->data, &p, &c, &current_object);
  1641.                     if ((r == 1) && UI_TEST_UCS2_CHARACTER(c))
  1642.                     {
  1643.                         if (b->UCS2_count > 0)
  1644.                         {
  1645.                             b->UCS2_count--;
  1646.                             if (b->UCS2_count == 0)
  1647.                             {
  1648.                                 dcs_change = 1;
  1649.                                 gui_EMS_change_DCS(b);
  1650.                             }
  1651.                         }
  1652.                     }
  1653.                     else if (UI_TEST_GSM_EXTENDED(c))
  1654.                     {
  1655.                         if (b->GSM_ext_count > 0)
  1656.                         {
  1657.                             b->GSM_ext_count--;
  1658.                         }
  1659.                     }
  1660.                     break;
  1661.                 }
  1662.                 /* MTK end */
  1663.                 if (b->object_count > 0)
  1664.                 {
  1665.                     b->object_count--;
  1666.                     if (b->object_count == 0)
  1667.                     {
  1668.                         gui_EMS_change_DCS(b);
  1669.                     }
  1670.                 }
  1671.                 break;
  1672.         }
  1673.         CancelCurrentPosition(b->data, 1);
  1674.     #ifdef __MMI_HINDI_ALG__
  1675.         b->data->textBuffer[b->data->textLength] = 0;
  1676.         b->data->textBuffer[b->data->textLength + 1] = 0;
  1677.         if (cancel_two_pos)
  1678.         {
  1679.             CancelCurrentPosition(b->data, 1);
  1680.         }
  1681.         if (b->data->CurrentPosition.OffsetToText >= 4)
  1682.         {
  1683.             if ((UI_CHK_CONSONANT(b->data->textBuffer[b->data->CurrentPosition.OffsetToText]))
  1684.                 && (UI_CHK_CONSONANT(b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 4]))
  1685.                 && (b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 2] == 0x4d)
  1686.                 && ((b->data->textBuffer[b->data->CurrentPosition.OffsetToText + 1]) == 0x09)
  1687.                 && ((b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 3]) == 0x09))
  1688.             {
  1689.                 EMSObject *bb;
  1690.                 U8 fwd_positions = 0;
  1691.                 U8 saved_fwd_positions = 0;
  1692.                 PU8 dest_pos;
  1693.                 PU8 src_pos = &b->data->textBuffer[b->data->CurrentPosition.OffsetToText];
  1694.                 p1 = b->data->CurrentPosition;
  1695.                 object_type_check1 = gui_EMS_input_box_get_next_object(data_chk_type1, &p1, &current_character1, &o1);
  1696.                 /* dest_pos = hf_get_next_cluster_p(b->data->textBuffer,src_pos); */
  1697.                 dest_pos = hf_get_next_cluster_p(src_pos, src_pos);
  1698.                 fwd_positions = dest_pos - src_pos; /* Number of moves */
  1699.                 fwd_positions = fwd_positions >> 1;
  1700.                 saved_fwd_positions = fwd_positions;
  1701.                 PRINT_INFORMATION_2((MMI_TRACE_INFO, "pixtel_UI_EMS_cancel_current_position[fwd_positions]:%d  ",
  1702.                                      fwd_positions));
  1703.                 while (fwd_positions--)
  1704.                 {
  1705.                     ForwardCurrentPosition(b->data, 1);
  1706.                 }
  1707.                 if (object_type_check1 == 2)
  1708.                 {
  1709.                     if (saved_fwd_positions == 1)
  1710.                     {
  1711.                         /* To shift the images on cluster completion */
  1712.                         bb = b->data->listTail;
  1713.                         do
  1714.                         {
  1715.                             if (bb->OffsetToText == b->data->CurrentPosition.Object->OffsetToText)
  1716.                             {
  1717.                                 bb->OffsetToText += (saved_fwd_positions) * 2;
  1718.                             }
  1719.                             bb = bb->prev;
  1720.                         } while (bb != NULL);
  1721.                         ForwardCurrentPosition(b->data, saved_fwd_positions);
  1722.                         BackwardCurrentPositionSkipCR(b->data);
  1723.                     }
  1724.                     else if (saved_fwd_positions > 1)
  1725.                     {
  1726.                         /* To shift the images on cluster completion */
  1727.                         bb = b->data->listHead;
  1728.                         do
  1729.                         {
  1730.                             if (bb->OffsetToText == b->data->CurrentPosition.Object->OffsetToText)
  1731.                             {
  1732.                                 bb->OffsetToText += (saved_fwd_positions) * 2;
  1733.                             }
  1734.                             bb = bb->next;
  1735.                         } while (bb != NULL);
  1736.                         ForwardCurrentPosition(b->data, saved_fwd_positions);
  1737.                         if (b->data->listHead == b->data->listTail)
  1738.                         {
  1739.                             BackwardCurrentPositionSkipCR(b->data);
  1740.                         }
  1741.                         else
  1742.                         {
  1743.                             BackwardCurrentPositionSkipCR(b->data);
  1744.                             BackwardCurrentPositionSkipCR(b->data);
  1745.                         }
  1746.                     }
  1747.                 }
  1748.             }
  1749.         }
  1750.     #endif /* __MMI_HINDI_ALG__ */ 
  1751.         if (dcs_change)
  1752.         {
  1753.             gui_EMS_input_box_insert_extension_character(b->data);
  1754.         }
  1755.     #if(EMS_USE_ESC_COMBINATION)
  1756.         if (b->UCS2_count == 0)
  1757.         {
  1758.             p = b->data->CurrentPosition;
  1759.             r = gui_EMS_input_box_get_previous_object(b->data, &p, &c, &current_object);
  1760.             if ((r == 1) && UI_TEST_ESC_CHARACTER(c))
  1761.             {
  1762.                 CancelCurrentPosition(b->data, 1);
  1763.             }
  1764.         }
  1765.     #endif /* (EMS_USE_ESC_COMBINATION) */ 
  1766.         return (1);
  1767.     }
  1768.     return (0);
  1769. }
  1770. #else /* (EMS_USE_CRLF_COMBINATION || EMS_USE_ESC_COMBINATION) */ 
  1771. /* Deletes one object/character before cursor position and updates UCS2 and Object counters  */
  1772. /*****************************************************************************
  1773.  * FUNCTION
  1774.  *  gui_EMS_cancel_current_position
  1775.  * DESCRIPTION
  1776.  *  
  1777.  * PARAMETERS
  1778.  *  b       [?]     
  1779.  * RETURNS
  1780.  *  
  1781.  *****************************************************************************/
  1782. U8 gui_EMS_cancel_current_position(UI_EMS_input_box *b)
  1783. {
  1784.     /*----------------------------------------------------------------*/
  1785.     /* Local Variables                                                */
  1786.     /*----------------------------------------------------------------*/
  1787.     /*----------------------------------------------------------------*/
  1788.     /* Code Body                                                      */
  1789.     /*----------------------------------------------------------------*/
  1790.     if (BackwardCurrentPosition(b->data, 1) == 1)
  1791.     {
  1792.         EMSPosition p = b->data->CurrentPosition;
  1793.         EMSObject *current_object;
  1794.         UI_character_type c;
  1795.         U8 r;
  1796.         r = gui_EMS_input_box_get_next_object(b->data, &p, &c, &current_object);
  1797.         ForwardCurrentPosition(b->data, 1);
  1798.         switch (r)
  1799.         {
  1800.             case 0:
  1801.                 break;
  1802.             case 1:
  1803.                 if (UI_TEST_UCS2_CHARACTER(c))
  1804.                 {
  1805.                     if (b->UCS2_count > 0)
  1806.                     {
  1807.                         b->UCS2_count--;
  1808.                         if (b->UCS2_count == 0)
  1809.                         {
  1810.                             gui_EMS_change_DCS(b);
  1811.                         }
  1812.                     }
  1813.                 }
  1814.                 break;
  1815.             case 2:
  1816.                 if (b->object_count > 0)
  1817.                 {
  1818.                     b->object_count--;
  1819.                     if (b->object_count == 0)
  1820.                     {
  1821.                         gui_EMS_change_DCS(b);
  1822.                     }
  1823.                 }
  1824.                 break;
  1825.         }
  1826.         CancelCurrentPosition(b->data, 1);
  1827.         return (1);
  1828.     }
  1829.     return (0);
  1830. }
  1831. #endif /* (EMS_USE_CRLF_COMBINATION || EMS_USE_ESC_COMBINATION) */ 
  1832. #define  EMSSWAP(t,a,b) 
  1833. {  t temp=a;            
  1834.    a=b;                 
  1835.    b=temp;              
  1836. }
  1837. /* Temporary function: Will be removed later                            */
  1838. /* For testing purpose only: Using this will cause an assertion in the EMS library  */
  1839. /*****************************************************************************
  1840.  * FUNCTION
  1841.  *  ArrangeEMSObjects
  1842.  * DESCRIPTION
  1843.  *  
  1844.  * PARAMETERS
  1845.  *  data        [?]     
  1846.  * RETURNS
  1847.  *  void
  1848.  *****************************************************************************/
  1849. void ArrangeEMSObjects(EMSData *data)
  1850. {
  1851.     /*----------------------------------------------------------------*/
  1852.     /* Local Variables                                                */
  1853.     /*----------------------------------------------------------------*/
  1854.     EMSObject *current = data->listHead;
  1855.     EMSObject *start;
  1856.     U8 done;
  1857.     /*----------------------------------------------------------------*/
  1858.     /* Code Body                                                      */
  1859.     /*----------------------------------------------------------------*/
  1860.     while (current != NULL)
  1861.     {
  1862.         done = 0;
  1863.         start = current;
  1864.         while (!done)
  1865.         {
  1866.             current = current->next;
  1867.             if (current == NULL)
  1868.             {
  1869.                 done = 1;
  1870.                 break;
  1871.             }
  1872.             if (current->OffsetToText != start->OffsetToText)
  1873.             {
  1874.                 done = 1;
  1875.                 break;
  1876.             }
  1877.             if (current->Type == EMS_TYPE_TEXT_FORMAT)
  1878.             {
  1879.                 EMSSWAP(EMSObject, *current, *start);
  1880.                 EMSSWAP(kal_uint16, current->OffsetToText, start->OffsetToText);
  1881.                 EMSSWAP(struct _EMSObject *, current->prev, start->prev);
  1882.                 EMSSWAP(struct _EMSObject *, current->next, start->next);
  1883.                 break;
  1884.             }
  1885.         }
  1886.     }
  1887. }
  1888. /*****************************************************************************
  1889.  * FUNCTION
  1890.  *  gui_EMS_input_box_add_string
  1891.  * DESCRIPTION
  1892.  *  
  1893.  * PARAMETERS
  1894.  *  b               [?]     
  1895.  *  s               [?]     
  1896.  *  text_format     [?]     
  1897.  * RETURNS
  1898.  *  
  1899.  *****************************************************************************/
  1900. EMSTATUS gui_EMS_input_box_add_string(UI_EMS_input_box *b, U8 *s, EMSTextFormat *text_format)
  1901. {
  1902.     /*----------------------------------------------------------------*/
  1903.     /* Local Variables                                                */
  1904.     /*----------------------------------------------------------------*/
  1905.     U16 num_char = 1;
  1906. #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  1907.     UI_character_type c = ((UI_character_type) s[1]) | (((UI_character_type) s[0]) << 8);
  1908. #else 
  1909.     UI_character_type c = ((UI_character_type) s[0]) | (((UI_character_type) s[1]) << 8);
  1910. #endif 
  1911.     EMSTATUS r;
  1912.     /*----------------------------------------------------------------*/
  1913.     /* Code Body                                                      */
  1914.     /*----------------------------------------------------------------*/
  1915.     if (text_format == NULL)
  1916.     {
  1917.         r = AddString(b->data, s, num_char, NULL);
  1918.     }
  1919.     else if (b->data->CurrentTextFormatObj == NULL)
  1920.     {
  1921.         if (gui_EMS_input_box_equal_text_format(&b->text_format, &UI_EMS_normal_text_format_object.data->text_format))
  1922.         {
  1923.             r = AddString(b->data, s, num_char, NULL);
  1924.         }
  1925.         else
  1926.         {
  1927.             r = AddString(b->data, s, num_char, text_format);
  1928.         }
  1929.     }
  1930.     else
  1931.     {
  1932.         r = AddString(b->data, s, num_char, text_format);
  1933.     }
  1934.     if (r == EMS_OK)
  1935.     {
  1936.         if (UI_TEST_UCS2_CHARACTER(c))
  1937.         {
  1938.             if (b->UCS2_count == 0)
  1939.             {
  1940.                 b->UCS2_count++;
  1941.                 gui_EMS_change_DCS(b);
  1942.             }
  1943.             else
  1944.             {
  1945.                 b->UCS2_count++;
  1946.             }
  1947.         }
  1948.         else if (UI_TEST_GSM_EXTENDED(c))
  1949.         {
  1950.             b->GSM_ext_count++;
  1951.         }
  1952.         if (b->UCS2_count > 0)
  1953.         {
  1954.             S32 remaining_length = (EMS_get_remaining_length(b->data) >> 1);
  1955.             if (remaining_length < 0)
  1956.             {
  1957.                 gui_EMS_cancel_current_position(b);
  1958.                 r = EMS_NO_SPACE;
  1959.             }
  1960.         }
  1961.     #if(EMS_USE_GSM_EXTENDED)
  1962.         else if (b->GSM_ext_count > 0)
  1963.         {
  1964.             S32 remaining_length = EMS_get_remaining_length(b->data);
  1965.             /* S32 available_length=b->available_length; */
  1966.             if (remaining_length < 0)
  1967.             {
  1968.                 gui_EMS_cancel_current_position(b);
  1969.                 r = EMS_NO_SPACE;
  1970.             }
  1971.         }
  1972.     #endif /* (EMS_USE_GSM_EXTENDED) */ 
  1973.     }
  1974.     else
  1975.     {
  1976.         /* MTK Terry for EMS_NO_MEMORY or other error cause */
  1977.         gui_EMS_change_DCS(b);
  1978.     }
  1979.     /* Temporary   */
  1980.     /* ArrangeEMSObjects(b->data); */
  1981.     return (r);
  1982. }
  1983. #else /* (EMS_USE_DCS) */ 
  1984. /*****************************************************************************
  1985.  * FUNCTION
  1986.  *  gui_EMS_input_box_add_string
  1987.  * DESCRIPTION
  1988.  *  
  1989.  * PARAMETERS
  1990.  *  b               [?]     
  1991.  *  s               [?]     
  1992.  *  text_format     [?]     
  1993.  * RETURNS
  1994.  *  
  1995.  *****************************************************************************/
  1996. EMSTATUS gui_EMS_input_box_add_string(UI_EMS_input_box *b, U8 *s, EMSTextFormat *text_format)
  1997. {
  1998.     /*----------------------------------------------------------------*/
  1999.     /* Local Variables                                                */
  2000.     /*----------------------------------------------------------------*/
  2001.     U16 num_char = 1;
  2002.     /*----------------------------------------------------------------*/
  2003.     /* Code Body                                                      */
  2004.     /*----------------------------------------------------------------*/
  2005.     if (text_format == NULL)
  2006.     {
  2007.         return (AddString(b->data, s, num_char, NULL));
  2008.     }
  2009.     else if (b->data->CurrentTextFormatObj == NULL)
  2010.     {
  2011.         if (gui_EMS_input_box_equal_text_format(&b->text_format, &UI_EMS_normal_text_format_object.data.text_format))
  2012.         {
  2013.             return (AddString(b->data, s, num_char, NULL));
  2014.         }
  2015.         else
  2016.         {
  2017.             return (AddString(b->data, s, num_char, text_format));
  2018.         }
  2019.     }
  2020.     else
  2021.     {
  2022.         return (AddString(b->data, s, num_char, text_format));
  2023.     }
  2024. }
  2025. #endif /* (EMS_USE_DCS) */ 
  2026. /*****************************************************************************
  2027.  * FUNCTION
  2028.  *  gui_EMS_inputbox_add_object
  2029.  * DESCRIPTION
  2030.  *  
  2031.  * PARAMETERS
  2032.  *  b                               [?]         
  2033.  *  type                            [IN]        
  2034.  *  objData                         [?]         
  2035.  *  predefined_object_number        [IN]        
  2036.  * RETURNS
  2037.  *  
  2038.  *****************************************************************************/
  2039. EMSTATUS gui_EMS_inputbox_add_object(UI_EMS_input_box *b, U8 type, EMSObjData *objData, U8 predefined_object_number)
  2040. {
  2041.     /*----------------------------------------------------------------*/
  2042.     /* Local Variables                                                */
  2043.     /*----------------------------------------------------------------*/
  2044.     EMSTATUS r;
  2045.     /*----------------------------------------------------------------*/
  2046.     /* Code Body                                                      */
  2047.     /*----------------------------------------------------------------*/
  2048.     r = AddObject(b->data, type, objData, (U8) predefined_object_number);
  2049. #ifdef __MMI_HINDI_ALG__
  2050.     //START TARUN 20050103
  2051.     //if ((b->data->CurrentPosition.OffsetToText >= 4)  && (b->data->textBuffer[b->data->CurrentPosition.OffsetToText-1] == 0x09)
  2052.     //   && (b->data->textBuffer[b->data->CurrentPosition.OffsetToText-2] == 0x4d))
  2053.     //{
  2054.     //   b->data->textBuffer[b->data->CurrentPosition.OffsetToText]=0x20;
  2055.     //   b->data->textBuffer[b->data->CurrentPosition.OffsetToText+1]=0x00;
  2056.     //   ForwardCurrentPosition(b->data,1);
  2057.     //   b->data->listTail->OffsetToText += 2;
  2058.     //}
  2059. #endif /* __MMI_HINDI_ALG__ */ // #ifdef __MMI_HINDI_ALG__
  2060. #if(EMS_USE_DCS)
  2061.     if (r == EMS_OK)
  2062.     {
  2063.         S32 remaining_length;
  2064.         if (b->object_count == 0)
  2065.         {
  2066.             b->object_count++;
  2067.             gui_EMS_change_DCS(b);
  2068.         }
  2069.         else
  2070.         {
  2071.             b->object_count++;
  2072.         }
  2073.         if (b->UCS2_count > 0)
  2074.         {
  2075.             remaining_length = (EMS_get_remaining_length(b->data) >> 1);
  2076.         }
  2077.         else
  2078.         {
  2079.             remaining_length = EMS_get_remaining_length(b->data);
  2080.         }
  2081.         if (remaining_length < 0)
  2082.         {
  2083.             CancelCurrentPosition(b->data, 1);
  2084.             b->object_count--;
  2085.             if (b->object_count == 0)
  2086.             {
  2087.                 gui_EMS_change_DCS(b);
  2088.             }
  2089.             UI_editor_play_tone_cannot_insert();
  2090.             return (EMS_NO_SPACE);
  2091.         }
  2092.     }
  2093. #endif /* (EMS_USE_DCS) */ 
  2094.     b->saved_cursor_ax = -1;
  2095.     return (r);
  2096. }
  2097. /*****************************************************************************
  2098.  * FUNCTION
  2099.  *  gui_EMS_input_box_insert_character
  2100.  * DESCRIPTION
  2101.  *  
  2102.  * PARAMETERS
  2103.  *  b       [?]         
  2104.  *  c       [IN]        
  2105.  * RETURNS
  2106.  *  
  2107.  *****************************************************************************/
  2108. U8 gui_EMS_input_box_insert_character(UI_EMS_input_box *b, UI_character_type c)
  2109. {
  2110.     /*----------------------------------------------------------------*/
  2111.     /* Local Variables                                                */
  2112.     /*----------------------------------------------------------------*/
  2113.     //W06.03 EMS_get_remaining_length > 0 does not make sure that we could insert one more character
  2114.     //Return EMS_OK if we insert the character successfully
  2115.     U16 ch = (U16) c;
  2116.     U8 s[2] = {0, 0};
  2117.     S32 remaining_length;
  2118.     U8 ret = EMS_OK;
  2119.     /*----------------------------------------------------------------*/
  2120.     /* Code Body                                                      */
  2121.     /*----------------------------------------------------------------*/
  2122. #ifdef __MMI_MESSAGES_EMS__
  2123.     EMS_cancel_object_focus();
  2124. #endif 
  2125.     if (b->UCS2_count > 0)
  2126.     {
  2127.         remaining_length = (EMS_get_remaining_length(b->data) >> 1);
  2128.     }
  2129.     else
  2130.     {
  2131.         remaining_length = EMS_get_remaining_length(b->data);
  2132.     }
  2133.     if (remaining_length <= 0)
  2134.     {
  2135.         UI_editor_play_tone_cannot_insert();
  2136.         return EMS_NO_SPACE;
  2137.     }
  2138.     /* MTK Elvis */
  2139.     /* if((b->UCS2_count==0) && UI_TEST_UCS2_CHARACTER(c) && remaining_length<=344))
  2140.        {  UI_editor_play_tone_cannot_insert();
  2141.        return;
  2142.        } */
  2143.     if (b->UCS2_count == 0)
  2144.     {
  2145.         if (UI_TEST_UCS2_CHARACTER(c))
  2146.         {
  2147.             gui_EMS_input_box_remove_extension_character(b->data);
  2148.             if (EMSSetDCS(b->data, SMSAL_UCS2_DCS) != EMS_OK)
  2149.             {
  2150.                 EMSSetDCS(b->data, SMSAL_DEFAULT_DCS);
  2151.                 gui_EMS_input_box_insert_extension_character(b->data);
  2152.                 UI_editor_play_tone_cannot_insert();
  2153.                 return EMS_NO_SPACE;
  2154.             }
  2155.             else
  2156.             {
  2157.                 if (EMS_get_remaining_length(b->data) < 2)
  2158.                 {
  2159.                     EMSSetDCS(b->data, SMSAL_DEFAULT_DCS);
  2160.                     gui_EMS_input_box_insert_extension_character(b->data);
  2161.                     UI_editor_play_tone_cannot_insert();
  2162.                     return EMS_NO_SPACE;
  2163.                 }
  2164.             }
  2165.         }
  2166.         else if (UI_TEST_GSM_EXTENDED(c))
  2167.         {
  2168.             if (EMS_get_remaining_length(b->data) < 2)
  2169.             {
  2170.                 UI_editor_play_tone_cannot_insert();
  2171.                 return EMS_NO_SPACE;
  2172.             }
  2173.         }
  2174.     }
  2175.     /* MTK end */
  2176.     /* If in Overwrite mode, delete the current character/object and insert the new one */
  2177.     if (b->flags & UI_EMS_INPUT_BOX_OVERWRITE_MODE)
  2178.     {
  2179.         if (gui_EMS_input_box_forward_cursor(b) == 1)
  2180.         {
  2181.             gui_EMS_cancel_current_position(b);
  2182.         }
  2183.     }
  2184. #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  2185.     s[0] = (ch & 0xff00) >> 8;
  2186.     s[1] = (ch & 0x00ff);
  2187. #else /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  2188.     s[1] = (U8) (ch >> 8);
  2189.     s[0] = (U8) ch;
  2190. #endif /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  2191.     if (gui_EMS_input_box_add_string(b, s, &b->text_format) == EMS_NO_SPACE)
  2192.     {
  2193.         UI_editor_play_tone_cannot_insert();
  2194.         b->overflow_callback();
  2195.         ret = EMS_NO_SPACE;
  2196.     }
  2197.     else
  2198.     {
  2199.         b->change_callback();
  2200.     }
  2201.     
  2202.     if (b->locate_cursor_flag)
  2203.     {
  2204.         gui_EMS_input_box_locate_cursor(b);
  2205.     }
  2206.     
  2207.     b->saved_cursor_ax = -1;
  2208.     return ret;
  2209. }
  2210. #ifdef __MMI_HINDI_ALG__
  2211. U8 saved_last_skip_pos = 0;
  2212. #endif 
  2213. //END TARUN PMT 20050128
  2214. //START PMTFARHAD 20050224
  2215. #if defined __MMI_LANG_HINDI__ && (defined __MMI_LANG_ARABIC__ || defined __MMI_LANG_PERSIAN__)
  2216. S32 HINDI_PRESENT = 0;
  2217. S32 ARABIC_PRESENT = 0;
  2218. #endif /* defined __MMI_LANG_HINDI__ && defined __MMI_LANG_ARABIC__ */
  2219. /* END PMTFARHAD  20050224 */
  2220. /*****************************************************************************
  2221.  * FUNCTION
  2222.  *  gui_EMS_input_box_insert_multitap_character
  2223.  * DESCRIPTION
  2224.  *  
  2225.  * PARAMETERS
  2226.  *  b       [?]         
  2227.  *  c       [IN]        
  2228.  * RETURNS
  2229.  *  void
  2230.  *****************************************************************************/
  2231. void gui_EMS_input_box_insert_multitap_character(UI_EMS_input_box *b, UI_character_type c)
  2232. {
  2233.     /*----------------------------------------------------------------*/
  2234.     /* Local Variables                                                */
  2235.     /*----------------------------------------------------------------*/
  2236.     U16 ch = (U16) c;
  2237.     U8 s[2] = {0, 0};
  2238.     EMSTextFormat text_format;
  2239.     S32 remaining_length;
  2240. #ifdef __MMI_HINDI_ALG__
  2241.     EMSObject *bb;
  2242.     UI_character_type current_character1 = 0;
  2243.     U8 object_type_check1 = 0;
  2244.     EMSObject *o1;
  2245.     EMSPosition p1 = b->data->CurrentPosition;
  2246.     EMSData *data_chk_type1 = b->data;
  2247.     UI_character_type current_character2 = 0;
  2248.     U8 object_type_check2 = 0;
  2249.     /* PMT VIKAS GUPTA START 20051129 */
  2250.     U8 halant_after_object = 0;
  2251.     /* PMT VIKAS GUPTA END 20051129 */
  2252.     EMSObject *o2;
  2253.     EMSPosition p2 = b->data->CurrentPosition;
  2254.     EMSData *data_chk_type2 = b->data;
  2255.     /* PMT VIKAS GUPTA START 20051129 */
  2256.     UI_buffer_type middle_ems_position, first_cons_ems_position, second_cons_ems_position, halant_check_position;
  2257.     /* PMT VIKAS GUPTA END 20051129 */
  2258.     static U8 ems_cursor_pos_flag = 0;
  2259.     /* PMT VIKAS GUPTA START 20051129 */
  2260.     U8 total_no_of_objects = 0;
  2261.     /* PMT VIKAS GUPTA END 20051129 */
  2262. #endif /* __MMI_HINDI_ALG__ */ 
  2263.     /*----------------------------------------------------------------*/
  2264.     /* Code Body                                                      */
  2265.     /*----------------------------------------------------------------*/
  2266. #ifdef __MMI_MESSAGES_EMS__
  2267.     EMS_cancel_object_focus();
  2268. #endif 
  2269.     if (b->UCS2_count > 0)
  2270.     {
  2271.         remaining_length = (EMS_get_remaining_length(b->data) >> 1);
  2272.     }
  2273.     else
  2274.     {
  2275.         remaining_length = EMS_get_remaining_length(b->data);
  2276.     }
  2277.     if ((remaining_length <= 0) && !(b->flags & UI_EMS_INPUT_BOX_STATE_MULTITAP) &&
  2278.         !(b->flags & UI_EMS_INPUT_BOX_OVERWRITE_MODE))
  2279.     {
  2280.         UI_editor_play_tone_cannot_insert();
  2281.         return;
  2282.     }
  2283. #if(0)
  2284. if((b->UCS2_count==0) && UI_TEST_UCS2_CHARACTER(c) && (remaining_length<=344))
  2285. { UI_editor_play_tone_cannot_insert();
  2286. return;
  2287. }
  2288. #endif /* (0) */ 
  2289.     if (b->UCS2_count == 0)
  2290.     {
  2291.         if (UI_TEST_UCS2_CHARACTER(c))
  2292.         {
  2293.             if (EMSSetDCS(b->data, SMSAL_UCS2_DCS) != EMS_OK)
  2294.             {
  2295.                 EMSSetDCS(b->data, SMSAL_DEFAULT_DCS);
  2296.                 UI_editor_play_tone_cannot_insert();
  2297.                 return;
  2298.             }
  2299.             else
  2300.             {
  2301.                 if (EMS_get_remaining_length(b->data) < 2)
  2302.                 {
  2303.                     EMSSetDCS(b->data, SMSAL_DEFAULT_DCS);
  2304.                     UI_editor_play_tone_cannot_insert();
  2305.                     return;
  2306.                 }
  2307.             }
  2308.         }
  2309.         else if (UI_TEST_GSM_EXTENDED(c))
  2310.         {
  2311.             if (EMS_get_remaining_length(b->data) < 2)
  2312.             {
  2313.                 UI_editor_play_tone_cannot_insert();
  2314.                 return;
  2315.             }
  2316.         }
  2317.     }
  2318. #if(EMS_BYTE_ORDER_BIG_ENDIAN)
  2319.     s[0] = (ch & 0xff00) >> 8;
  2320.     s[1] = (ch & 0x00ff);
  2321. #else /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  2322.     s[1] = (U8) (ch >> 8);
  2323.     s[0] = (U8) ch;
  2324. #endif /* (EMS_BYTE_ORDER_BIG_ENDIAN) */ 
  2325.     if (b->flags & UI_EMS_INPUT_BOX_STATE_MULTITAP)
  2326.     {
  2327.     #ifdef __MMI_HINDI_ALG__
  2328.         second_cons_ems_position = &(b->data->textBuffer[b->data->CurrentPosition.OffsetToText]);
  2329.         /* PMT VIKAS GUPTA START 20051129 */
  2330.         halant_check_position = &(b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 4]);
  2331.         /* PMT VIKAS GUPTA END 20051129 */
  2332.         if ((ems_cursor_pos_flag) && ((c == 49) || (c == 0x901) || (c == 0x902)))       /* Only when multitap input is 1 */
  2333.         {
  2334.             BackwardCurrentPosition(b->data, saved_last_skip_pos);
  2335.             ems_cursor_pos_flag = 0;
  2336.             saved_last_skip_pos = 0;
  2337.         }
  2338.         /* PMT VIKAS GUPTA START 20051129 */
  2339.         {
  2340.             EMSObject *object_and_halant_check;
  2341.             EMSPosition p = b->data->CurrentPosition;
  2342.             UI_character_type c;
  2343.             EMSObject *current_object;
  2344.             U8 r;
  2345.             object_and_halant_check = b->data->listHead;
  2346.             /* r=gui_EMS_input_box_get_previous_object(b->data,&p,&c,&current_object); */
  2347.             halant_after_object = gui_EMS_input_box_get_previous_object(b->data, &p, &c, &current_object);
  2348.             while (object_and_halant_check != NULL && halant_after_object == 2)
  2349.             {
  2350.                 total_no_of_objects++;
  2351.                 object_and_halant_check = object_and_halant_check->next;
  2352.             }
  2353.         }
  2354.         if (*halant_check_position == 0x4D && halant_after_object == 2)
  2355.         {
  2356.             check_for_halant = 1;
  2357.         }
  2358.         /* PMT VIKAS GUPTA END 20051129 */
  2359.     #endif /* __MMI_HINDI_ALG__ */ 
  2360.         /* PMT VIKAS GUPTA START 20051129 */
  2361.     #ifdef __MMI_HINDI_ALG__
  2362.         if (check_for_halant)
  2363.         {
  2364.             BackwardCurrentPosition(b->data, total_no_of_objects);
  2365.             gui_EMS_cancel_current_position(b);
  2366.         }
  2367.         else
  2368.     #endif /* __MMI_HINDI_ALG__ */ 
  2369.             /* PMT VIKAS GUPTA END 20051129 */
  2370.             gui_EMS_cancel_current_position(b);
  2371.     #ifdef __MMI_HINDI_ALG__
  2372.         ems_cursor_pos_flag = 0;
  2373.         saved_last_skip_pos = 0;
  2374.         middle_ems_position = &(b->data->textBuffer[b->data->CurrentPosition.OffsetToText]);
  2375.         first_cons_ems_position = &(b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 2]);
  2376.     #endif /* __MMI_HINDI_ALG__ */ 
  2377.         text_format = b->text_format;
  2378.         /* MTK Terry for EMS_NO_MEMORY or other error cause */
  2379.         if (gui_EMS_input_box_add_string(b, s, &text_format) != EMS_OK /*==EMS_NO_SPACE */ )
  2380.         {
  2381.             UI_editor_play_tone_cannot_insert();
  2382.             b->overflow_callback();
  2383.         }
  2384.         else
  2385.         {
  2386.         #ifdef __MMI_HINDI_ALG__
  2387.             if (!TestLastPosition(b->data, &(b->data->CurrentPosition)))
  2388.             {
  2389.                 object_type_check1 = gui_EMS_input_box_get_next_object(data_chk_type1, &p1, &current_character1, &o1);
  2390.             }
  2391.             if ((UI_CHK_CONSONANT(*first_cons_ems_position)) && (UI_CHK_CONSONANT(*second_cons_ems_position))
  2392.                 && (*middle_ems_position == 0x4d)
  2393.                 && (*(first_cons_ems_position + 1) == 0x09) && (*(second_cons_ems_position + 1) == 0x09))
  2394.             {
  2395.                 U8 skip_positions = 0;
  2396.                 PU8 src_ems_pos = second_cons_ems_position;
  2397.                 PU8 dest_ems_pos;
  2398.                 /* dest_ems_pos = hf_get_next_cluster_p(b->data->textBuffer,src_ems_pos); */
  2399.                 dest_ems_pos = hf_get_next_cluster_p(src_ems_pos, src_ems_pos);
  2400.                 skip_positions = dest_ems_pos - src_ems_pos;    /* Number of moves */
  2401.                 skip_positions = skip_positions >> 1;
  2402.                 saved_last_skip_pos = skip_positions;
  2403.                 PRINT_INFORMATION_2((MMI_TRACE_INFO,
  2404.                                      "pixtel_UI_EMS_input_box_insert_multitap_character[skip_positions]:%d  ",
  2405.                                      skip_positions));
  2406.                 while (skip_positions--)
  2407.                 {
  2408.                     ForwardCurrentPosition(b->data, 1);
  2409.                 }
  2410.                 ems_cursor_pos_flag = 1;
  2411.                 if (object_type_check1 == 2)
  2412.                 {
  2413.                     /* START TARUN 20050106 : */
  2414.                     if (saved_last_skip_pos == 1)
  2415.                     {
  2416.                         /* To shift the images on cluster completion */
  2417.                         bb = b->data->listTail;
  2418.                         do
  2419.                         {
  2420.                             if (bb->OffsetToText == b->data->CurrentPosition.Object->OffsetToText)
  2421.                             {
  2422.                                 bb->OffsetToText += (saved_last_skip_pos) * 2;
  2423.                             }
  2424.                             bb = bb->prev;
  2425.                         } while (bb != NULL);
  2426.                         ForwardCurrentPosition(b->data, saved_last_skip_pos);
  2427.                         BackwardCurrentPositionSkipCR(b->data);
  2428.                     }
  2429.                     else if (saved_last_skip_pos > 1)
  2430.                     {
  2431.                         bb = b->data->listHead;
  2432.                         do
  2433.                         {
  2434.                             if (bb->OffsetToText == b->data->CurrentPosition.Object->OffsetToText)
  2435.                             {
  2436.                                 bb->OffsetToText += (saved_last_skip_pos) * 2;
  2437.                             }
  2438.                             bb = bb->next;
  2439.                         } while (bb != NULL);
  2440.                         ForwardCurrentPosition(b->data, saved_last_skip_pos);
  2441.                         if (b->data->listHead == b->data->listTail)
  2442.                         {
  2443.                             BackwardCurrentPositionSkipCR(b->data);
  2444.                         }
  2445.                         else
  2446.                         {
  2447.                             BackwardCurrentPositionSkipCR(b->data);
  2448.                             BackwardCurrentPositionSkipCR(b->data);
  2449.                         }
  2450.                     }
  2451.                 }
  2452.             }
  2453.             /* PMT VIKAS GUPTA START 20051129 */
  2454.             if (check_for_halant)
  2455.             {
  2456.                 ForwardCurrentPosition(b->data, total_no_of_objects);
  2457.                 check_for_halant = 0;
  2458.             }
  2459.             /* PMT VIKAS GUPTA END 20051129 */
  2460.         #endif /* __MMI_HINDI_ALG__ */ 
  2461.             b->change_callback();
  2462.         }
  2463.     }
  2464.     else
  2465.     {
  2466.     #ifdef __MMI_HINDI_ALG__
  2467.         ems_cursor_pos_flag = 0;
  2468.         saved_last_skip_pos = 0;
  2469.         second_cons_ems_position = &(b->data->textBuffer[b->data->CurrentPosition.OffsetToText - 2]);
  2470.         object_type_check2 = gui_EMS_input_box_get_previous_object(data_chk_type2, &p2, &current_character2, &o2);
  2471.         /* PMT VIKAS GUPTA START 20051129 */
  2472.         if ((*second_cons_ems_position == 0x4d) && (object_type_check2 == 2))
  2473.         {
  2474.             check_for_halant = 1;
  2475.         }
  2476.         //PMT VIKAS GUPTA END 20051129
  2477.         //START TARUN PMT 20050128
  2478.         if ((object_type_check2 == 2) && (*second_cons_ems_position == 0x4d) && UI_CHK_CONSONANT(s[0]) && s[1] == 0x09)
  2479.             /* END TARUN PMT 20050128 */
  2480.         {
  2481.             {
  2482.                 U8 skip_positions = 0;
  2483.                 PU8 src_ems_pos = second_cons_ems_position;
  2484.                 PU8 dest_ems_pos;
  2485.                 dest_ems_pos = hf_get_next_cluster_p(src_ems_pos, src_ems_pos);
  2486.                 skip_positions = dest_ems_pos - src_ems_pos;
  2487.                 skip_positions = skip_positions >> 1;
  2488.                 /* To shift the images on cluster completion */
  2489.                 bb = b->data->listHead;
  2490.                 do
  2491.                 {
  2492.                     if (bb->OffsetToText == b->data->CurrentPosition.Object->OffsetToText)
  2493.                     {
  2494.                         bb->OffsetToText += (skip_positions) * 2;
  2495.                     }
  2496.                     bb = bb->next;
  2497.                 } while (bb != NULL);
  2498.                 //START TARUN PMT 20050128
  2499.                 //ForwardCurrentPosition(b->data,1);
  2500.                 //END TARUN PMT 20050128
  2501.             }
  2502.         }
  2503.     #endif /* __MMI_HINDI_ALG__ */ 
  2504.         if (b->flags & UI_EMS_INPUT_BOX_OVERWRITE_MODE)
  2505.         {
  2506.             if (gui_EMS_input_box_forward_cursor(b) == 1)
  2507.             {
  2508.                 gui_EMS_cancel_current_position(b);
  2509.                 text_format = b->text_format;
  2510.                 /* MTK Terry for EMS_NO_MEMORY or other error cause */
  2511.                 if (gui_EMS_input_box_add_string(b, s, &text_format) != EMS_OK /*==EMS_NO_SPACE */ )
  2512.                 {
  2513.                     UI_editor_play_tone_cannot_insert();
  2514.                     b->overflow_callback();
  2515.                 }
  2516.                 else
  2517.                 {
  2518.                     b->change_callback();
  2519.                 }
  2520.             }
  2521.             /* to prevent to enable the multitap flag while reaching the max length(cannot add any char) */
  2522.             b->flags |= UI_EMS_INPUT_BOX_STATE_MULTITAP;
  2523.         }
  2524.         else
  2525.         {
  2526.             /* MTK Terry for EMS_NO_MEMORY or other error cause */
  2527.             if (gui_EMS_input_box_add_string(b, s, &b->text_format) != EMS_OK /*==EMS_NO_SPACE */ )
  2528.             {
  2529.                 UI_editor_play_tone_cannot_insert();
  2530.                 b->overflow_callback();
  2531.             }
  2532.             else
  2533.             {
  2534.                 b->change_callback();
  2535.                 /* MTK Elvis */
  2536.                 b->flags |= UI_EMS_INPUT_BOX_STATE_MULTITAP;
  2537.                 /* MTK end */
  2538.             }
  2539.         }
  2540.         //MTK Elvis
  2541.         //b->flags|=UI_EMS_INPUT_BOX_STATE_MULTITAP;
  2542.         //MTK end
  2543.     }
  2544. #ifdef __MMI_HINDI_ALG__
  2545.     if (TestLastPosition(b->data, &(b->data->CurrentPosition)))
  2546.     {
  2547.         b->data->textBuffer[b->data->CurrentPosition.OffsetToText] = 0;
  2548.         b->data->textBuffer[b->data->CurrentPosition.OffsetToText + 1] = 0;
  2549.     }
  2550. #endif /* __MMI_HINDI_ALG__ */ 
  2551.     gui_EMS_input_box_locate_cursor(b);
  2552.     b->saved_cursor_ax = -1;
  2553. }
  2554. /*****************************************************************************
  2555.  * FUNCTION
  2556.  *  gui_EMS_input_box_confirm_multitap_character
  2557.  * DESCRIPTION
  2558.  *  
  2559.  * PARAMETERS
  2560.  *  b       [?]     
  2561.  * RETURNS
  2562.  *  void
  2563.  *****************************************************************************/
  2564. void gui_EMS_input_box_confirm_multitap_character(UI_EMS_input_box *b)
  2565. {
  2566.     /*----------------------------------------------------------------*/
  2567.     /* Local Variables                                                */
  2568.     /*----------------------------------------------------------------*/
  2569.     /*----------------------------------------------------------------*/
  2570.     /* Code Body                                                      */
  2571.     /*----------------------------------------------------------------*/
  2572.     b->flags &= ~UI_EMS_INPUT_BOX_STATE_MULTITAP;
  2573. }
  2574. extern EMSTextFormat wgui_EMS_text_format;
  2575. /*****************************************************************************
  2576.  * FUNCTION
  2577.  *  gui_EMS_input_box_delete_all
  2578.  * DESCRIPTION
  2579.  *  
  2580.  * PARAMETERS
  2581.  *  b       [?]     
  2582.  * RETURNS
  2583.  *  void
  2584.  *****************************************************************************/
  2585. void gui_EMS_input_box_delete_all(UI_EMS_input_box *b)
  2586. {
  2587.     /*----------------------------------------------------------------*/
  2588.     /* Local Variables                                                */
  2589.     /*----------------------------------------------------------------*/
  2590.     /*----------------------------------------------------------------*/
  2591.     /* Code Body                                                      */
  2592.     /*----------------------------------------------------------------*/
  2593. #ifdef __MMI_MESSAGES_EMS__
  2594.     EMS_cancel_object_focus();
  2595. #endif 
  2596.     ResetCurrentPosition(b->data);
  2597.     /* MTK Elvis 20040611 donot plan tone while the EMS data is empty. */
  2598. #if 0
  2599. /* under construction !*/
  2600. #endif /* 0 */ 
  2601.     /* MTK end */
  2602.     /* Probably a better way of doing this is to have a EMS library API  */
  2603.     GoToEndPosition(b->data);
  2604.     /* START TARUN 20041230 */
  2605.     memset(b->data->textBuffer, 0, b->data->CurrentPosition.OffsetToText);
  2606.     /* END TARUN 20041230 */
  2607. #if defined(__MMI_MESSAGES_CONCAT_SMS__)
  2608.     CancelCurrentPosition(b->data, (U16) (b->data->Reminder.maxUsableLenPerSeg * mmi_msg_get_seg_num()));
  2609. #else 
  2610.     CancelCurrentPosition(b->data, (U16) (EMS_DEFAULT_DCS_ALLOCATED_LENGTH));
  2611. #endif 
  2612.     gui_EMS_input_box_set_text_format_cursor_position(b);
  2613.     gui_EMS_input_box_locate_cursor(b);
  2614.     b->UCS2_count = 0;
  2615.     b->object_count = 0;
  2616.     /* MTK Joy added for clear all, 1228 */
  2617.     b->GSM_ext_count = 0;
  2618.     /* MTK end */
  2619.     gui_EMS_change_DCS(b);
  2620.     b->saved_cursor_ax = -1;