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

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_virtual_keyboard.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   Virtual keyboard - 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.  *------------------------------------------------------------------------------
  97.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  98.  *============================================================================
  99.  ****************************************************************************/
  100. #include "MMI_features.h"
  101. #include "gui_virtual_keyboard.h"
  102. #include "wgui_virtual_keyboard.h"
  103. #include "gui_themes.h"
  104. #include "wgui.h"
  105. #include "wgui_categories_defs.h"
  106. #include "wgui_categories_util.h"       /* get_image() */
  107. #include "DebugInitDef.h"
  108. /*
  109.  * FIXME.
  110.  *
  111.  * 1. Currently we only support one matrix layout per keyboard.
  112.  * 2. Use static memory to avoid out-of-memory in control buffer
  113.  *
  114.  */
  115. extern BOOL r2lMMIFlag;
  116. /***************************************************************************** 
  117. * Define
  118. *****************************************************************************/
  119. #define VKBD_DIFF_HALF(a, b)  ((a) >= (b) ? (((a)-(b))>>1) : 0)
  120. /***************************************************************************** 
  121. * Typedef 
  122. *****************************************************************************/
  123. /***************************************************************************** 
  124. * Local Variable
  125. *****************************************************************************/
  126. /***************************************************************************** 
  127. * Local Function
  128. *****************************************************************************/
  129. /*****************************************************************************
  130.  * FUNCTION
  131.  *  gui_virtual_keyboard_clear_selected_key
  132.  * DESCRIPTION
  133.  *  
  134.  * PARAMETERS
  135.  *  s       [OUT]     
  136.  * RETURNS
  137.  *  void
  138.  *****************************************************************************/
  139. static void gui_virtual_keyboard_clear_selected_key(virtual_keyboard_selection_struct *s)
  140. {
  141.     /*----------------------------------------------------------------*/
  142.     /* Local Variables                                                */
  143.     /*----------------------------------------------------------------*/
  144.     /*----------------------------------------------------------------*/
  145.     /* Code Body                                                      */
  146.     /*----------------------------------------------------------------*/
  147.     s->matrix_index = -1;
  148.     s->matrix_column = -1;
  149.     s->matrix_row = -1;
  150.     s->custom_key_index = -1;
  151.     s->key_width = 0;
  152.     s->key_height = 0;
  153.     s->key_x = 0;
  154.     s->key_y = 0;
  155. }
  156. /*****************************************************************************
  157.  * FUNCTION
  158.  *  gui_virtual_keyboard_check_dead_key
  159.  * DESCRIPTION
  160.  *  
  161.  * PARAMETERS
  162.  *  ch      [IN]        
  163.  * RETURNS
  164.  *  
  165.  *****************************************************************************/
  166. static BOOL gui_virtual_keyboard_check_dead_key(UI_character_type ch)
  167. {
  168.     /*----------------------------------------------------------------*/
  169.     /* Local Variables                                                */
  170.     /*----------------------------------------------------------------*/
  171.     /*----------------------------------------------------------------*/
  172.     /* Code Body                                                      */
  173.     /*----------------------------------------------------------------*/
  174.     switch (ch)
  175.     {
  176.         case 0x60:  /* ` */
  177.         case 0xB4:
  178.         case 0x5E:  /* ^ */
  179.         case 0xA8:
  180.         case 0x7E:  /* ~ */
  181.             return MMI_TRUE;
  182.         default:
  183.             return MMI_FALSE;
  184.     }
  185. }
  186. /*****************************************************************************
  187.  * FUNCTION
  188.  *  gui_virtual_keyboard_show_char_center_align
  189.  * DESCRIPTION
  190.  *  
  191.  * PARAMETERS
  192.  *  ch                  [IN]        
  193.  *  key_x               [IN]        
  194.  *  key_y               [IN]        
  195.  *  key_width           [IN]        
  196.  *  key_height          [IN]        
  197.  *  glyph_width         [OUT]         
  198.  *  glyph_height        [OUT]         
  199.  * RETURNS
  200.  *  void
  201.  *****************************************************************************/
  202. static void gui_virtual_keyboard_show_char_center_align(
  203.                 UI_character_type ch,
  204.                 S32 key_x,
  205.                 S32 key_y,
  206.                 S32 key_width,
  207.                 S32 key_height,
  208.                 S32 *glyph_width,
  209.                 S32 *glyph_height)
  210. {
  211.     /*----------------------------------------------------------------*/
  212.     /* Local Variables                                                */
  213.     /*----------------------------------------------------------------*/
  214.     S32 bbox_x, bbox_y, bbox_width, bbox_height;
  215.     S32 char_x, char_y;
  216.     /*----------------------------------------------------------------*/
  217.     /* Code Body                                                      */
  218.     /*----------------------------------------------------------------*/
  219.     if (ch == (UI_character_type) '_')  /* '_' is special because it will get confused with '-' */
  220.     {
  221.         gui_measure_character(ch, glyph_width, glyph_height);
  222.         char_x = key_x + VKBD_DIFF_HALF(key_width, *glyph_width);
  223.         char_y = key_y + VKBD_DIFF_HALF(key_width, *glyph_height);
  224.     }
  225.     else
  226.     {
  227.         Get_CharBoundingBox(ch, glyph_width, glyph_height, &bbox_x, &bbox_y, &bbox_width, &bbox_height);
  228.         char_x = key_x + VKBD_DIFF_HALF(key_width, bbox_width) - bbox_x;
  229.         char_y = key_y + VKBD_DIFF_HALF(key_height, bbox_height) - bbox_y;
  230.         /* HACK. the number of remaing pixels is odd. */
  231.         /* It is not always correct depending on the baseline of the font database */
  232.         /* The magic number bbox_y + "1" can be modified */
  233.         if (((key_height - bbox_height) & 1) && (bbox_y + 1 > *glyph_height - bbox_height - bbox_y))
  234.         {
  235.             char_y++;
  236.         }
  237.         if (r2lMMIFlag)
  238.         {
  239.             char_x += *glyph_width;
  240.         }
  241.     }
  242.     gui_move_text_cursor(char_x, char_y);
  243.     gui_print_character(ch);
  244. }
  245. /*****************************************************************************
  246.  * FUNCTION
  247.  *  gui_virtual_keyboard_convert_custom_img
  248.  * DESCRIPTION
  249.  *  Convert some image ID of custom key because some images are displayed 
  250.  *  differently in multi-block handwriting
  251.  * PARAMETERS 
  252.  *  v           [IN/OUT]         
  253.  *  id          [IN]        image ID of custom key
  254.  * RETURNS
  255.  *  Converted image id
  256.  *****************************************************************************/
  257. static MMI_ID_TYPE gui_virtual_keyboard_convert_custom_img(virtual_keyboard *v, MMI_ID_TYPE id)
  258. {
  259.     /*----------------------------------------------------------------*/
  260.     /* Local Variables                                                */
  261.     /*----------------------------------------------------------------*/
  262.     /*----------------------------------------------------------------*/
  263.     /* Code Body                                                      */
  264.     /*----------------------------------------------------------------*/
  265.     /* Phone number keyboard layout coexist with multi-block but it has IMG_VKBD_CUSTOM_HIDE key */
  266.     if (!(v->flags & GUI_VKBD_FLAG_MULTI_BLOCK_MODE) ||
  267.         v->lang_type == GUI_VIRTUAL_KEYBOARD_PHONE_NUMBER)
  268.     {
  269.         return id;
  270.     }
  271.     else if (id == IMG_VKBD_CUSTOM_HIDE)
  272.     {
  273.         return IMG_VKBD_CUSTOM_SWITCH_HANDWRITING;
  274.     }
  275.     else if (id == IMG_VKBD_CUSTOM_SHOW)
  276.     {
  277.         return IMG_VKBD_CUSTOM_SWITCH_KEYBOARD;
  278.     }
  279.     else
  280.     {
  281.         return id;
  282.     }
  283. }
  284. /*****************************************************************************
  285.  * FUNCTION
  286.  *  gui_virtual_keyboard_is_key_disabled
  287.  * DESCRIPTION
  288.  *  
  289.  * PARAMETERS
  290.  *  v           [IN/OUT]         
  291.  *  event       [IN]        
  292.  *  ch          [IN]        
  293.  * RETURNS
  294.  *  
  295.  *****************************************************************************/
  296. static MMI_BOOL gui_virtual_keyboard_is_key_disabled(
  297.                     virtual_keyboard *v,
  298.                     gui_virtual_keyboard_pen_enum event,
  299.                     UI_character_type ch)
  300. {
  301.     /*----------------------------------------------------------------*/
  302.     /* Local Variables                                                */
  303.     /*----------------------------------------------------------------*/
  304.     /*----------------------------------------------------------------*/
  305.     /* Code Body                                                      */
  306.     /*----------------------------------------------------------------*/
  307.     if (v->allowed_characters)
  308.     {
  309.         MMI_BOOL disabled = MMI_TRUE;
  310.         /* gui_set_virtual_keyboard_allowed_characters() and 
  311.            gui_set_virtual_board_disable_list() are mutually-exclusive */
  312.         MMI_DBG_ASSERT(v->disabled_chars[0] == 0 && v->disabled_symbols[0] == GUI_VKBD_PEN_NONE);
  313.         switch (event)
  314.         {
  315.                 // TODO: GUI_VKBD_PEN_EUROSYMB is not supported
  316.             case GUI_VKBD_PEN_HIDE:
  317.             case GUI_VKBD_PEN_SHOW:
  318.             case GUI_VKBD_PEN_CAPSLOCK:
  319.             case GUI_VKBD_PEN_BAKSPACE:
  320.             case GUI_VKBD_PEN_DISPLAY_AREA:
  321.                 /* GUI_VKBD_PEN_DISPLAY_AREA is always enabled because it's display only */
  322.                 disabled = MMI_FALSE;
  323.                 break;
  324.             case GUI_VKBD_PEN_NEWLINE:
  325.                 ch = (UI_character_type) 'n';
  326.                 event = GUI_VKBD_PEN_CHAR_I;
  327.                 break;
  328.             case GUI_VKBD_PEN_SPACE:
  329.                 ch = (UI_character_type) ' ';
  330.                 event = GUI_VKBD_PEN_CHAR_I;
  331.                 break;
  332.             case GUI_VKBD_PEN_SYMBPICKER:
  333.             {
  334.                 /* Check existence of non-alphanumeric character */
  335.                 const UI_character_type *pch = v->allowed_characters;
  336.                 UI_character_type tmp;
  337.                 while ((tmp = *pch++) != 0)
  338.                 {
  339.                     if (tmp == (UI_character_type) '\' ||  /* Assume the next character to be punctuation */
  340.                         !(tmp == (UI_character_type) '-' ||
  341.                           (tmp >= (UI_character_type) 'a' && tmp <= (UI_character_type) 'z') ||
  342.                           (tmp >= (UI_character_type) 'A' && tmp <= (UI_character_type) 'Z') ||
  343.                           (tmp >= (UI_character_type) '0' && tmp <= (UI_character_type) '9')))
  344.                     {
  345.                         disabled = MMI_FALSE;
  346.                         break;
  347.                     }
  348.                 }
  349.                 break;
  350.             }
  351.         }
  352.         if (event == GUI_VKBD_PEN_CHAR_I)
  353.         {
  354.             const UI_character_type *pch = v->allowed_characters;
  355.             S32 idx;
  356.             for (idx = 0; pch[idx]; idx++)
  357.             {
  358.                 UI_character_type tmp = pch[idx];
  359.                 if (tmp == (UI_character_type) '-' && idx > 0 && pch[idx + 1])
  360.                 {
  361.                     if (ch >= pch[idx - 1] && ch <= pch[idx + 1])
  362.                     {
  363.                         disabled = MMI_FALSE;
  364.                         break;
  365.                     }
  366.                     idx++;
  367.                 }
  368.                 else
  369.                 {
  370.                     if (tmp == (UI_character_type) '\' && pch[idx + 1])
  371.                     {
  372.                         tmp = pch[++idx];
  373.                     }
  374.                     if (tmp == ch)
  375.                     {
  376.                         disabled = MMI_FALSE;
  377.                         break;
  378.                     }
  379.                 }
  380.             }
  381.         }
  382.         return disabled;
  383.     }
  384.     else
  385.     {
  386.         if (event == GUI_VKBD_PEN_CHAR_I)
  387.         {
  388.             UI_character_type *ptr = v->disabled_chars, tmp;
  389.             if (ch == 0)
  390.             {
  391.                 return MMI_TRUE;
  392.             }
  393.             while ((tmp = *ptr++) != 0)
  394.             {
  395.                 if (tmp == ch)
  396.                 {
  397.                     return MMI_TRUE;
  398.                 }
  399.             }
  400.             return MMI_FALSE;
  401.         }
  402.         else if (event == GUI_VKBD_PEN_NONE)
  403.         {
  404.             return MMI_TRUE;
  405.         }
  406.         else
  407.         {
  408.             gui_virtual_keyboard_pen_enum *ptr = v->disabled_symbols, tmp;
  409.             while ((tmp = *ptr++) != GUI_VKBD_PEN_NONE)
  410.             {
  411.                 if (tmp == event)
  412.                 {
  413.                     return MMI_TRUE;
  414.                 }
  415.             }
  416.             return MMI_FALSE;
  417.         }
  418.     }
  419. }
  420. #ifdef __MMI_TOUCH_SCREEN__
  421. /* Return > 0 if dead key sequence is completed */
  422. /*****************************************************************************
  423.  * FUNCTION
  424.  *  gui_get_dead_key_symbol
  425.  * DESCRIPTION
  426.  *  
  427.  * PARAMETERS
  428.  *  lang_type           [IN]        
  429.  *  input_string        [IN]         
  430.  *  input_len           [IN]        
  431.  * RETURNS
  432.  *  
  433.  *****************************************************************************/
  434. UI_character_type gui_get_dead_key_symbol(
  435.                     gui_virtual_keyboard_language_enum lang_type,
  436.                     U16 *input_string,
  437.                     S32 input_len)
  438. {
  439.     /*----------------------------------------------------------------*/
  440.     /* Local Variables                                                */
  441.     /*----------------------------------------------------------------*/
  442.     S32 i;
  443.     S32 n_entry;
  444.     const gui_keyboard_language_struct *lang;
  445.     const gui_dead_key_map_struct *t;
  446.     const gui_dead_key_symbol_struct *d;
  447.     /*----------------------------------------------------------------*/
  448.     /* Code Body                                                      */
  449.     /*----------------------------------------------------------------*/
  450.     lang = MMI_virtual_keyboard_language_map[lang_type].virtual_keyboard_language;
  451.     if (!lang->enable_dead_key)
  452.     {
  453.         return 0;
  454.     }
  455.     t = &gui_dead_key_symbol_table[lang_type];
  456.     n_entry = t->nentry;
  457.     d = &t->dead_key_symbol[0];
  458.     for (i = 0; i < n_entry; i++)
  459.     {
  460.         if (input_len != d->nInputLen)
  461.         {
  462.             continue;
  463.         }
  464.         if (memcmp(d->input_char, input_string, d->nInputLen * 2) == 0)
  465.         {
  466.             return d->output_char;
  467.         }
  468.         d++;
  469.     }
  470.     return 0;
  471. }
  472. /*****************************************************************************
  473.  * FUNCTION
  474.  *  gui_virtual_keyboard_get_selected_key
  475.  * DESCRIPTION
  476.  *  
  477.  * PARAMETERS
  478.  *  v       [IN/OUT]     
  479.  *  ch      [OUT]     
  480.  *  evt     [OUT]     
  481.  * RETURNS
  482.  *  
  483.  *****************************************************************************/
  484. static BOOL gui_virtual_keyboard_get_selected_key(
  485.                 virtual_keyboard *v,
  486.                 UI_character_type *ch,
  487.                 gui_virtual_keyboard_pen_enum *evt)
  488. {
  489.     /*----------------------------------------------------------------*/
  490.     /* Local Variables                                                */
  491.     /*----------------------------------------------------------------*/
  492.     const gui_keyboard_language_struct *lang;
  493.     virtual_keyboard_selection_struct *s = &v->selected_key;
  494.     /*----------------------------------------------------------------*/
  495.     /* Code Body                                                      */
  496.     /*----------------------------------------------------------------*/
  497.     *ch = 0;
  498.     *evt = GUI_VKBD_PEN_NONE;
  499.     lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
  500.     if (s->matrix_index < 0 && s->custom_key_index < 0)
  501.     {
  502.         return MMI_FALSE;
  503.     }
  504.     if (s->matrix_index >= 0)
  505.     {
  506.         MMI_DBG_ASSERT(s->matrix_column >= 0 && s->matrix_row >= 0);
  507.         *evt = GUI_VKBD_PEN_CHAR_I;
  508.         *ch = lang->matrix_string[s->matrix_row][s->matrix_column];
  509.     }
  510.     else
  511.     {
  512.         *evt = lang->custom_key_type[s->custom_key_index];
  513.         *ch = lang->custom_string[s->custom_key_index];
  514.     }
  515.     MMI_DBG_ASSERT(!*ch || *evt == GUI_VKBD_PEN_CHAR_I);
  516.     return MMI_TRUE;
  517. }
  518. /*****************************************************************************
  519.  * FUNCTION
  520.  *  gui_virtual_keyboard_translate_dead_key
  521.  * DESCRIPTION
  522.  *  
  523.  * PARAMETERS
  524.  *  v       [IN/OUT]     
  525.  *  ch      [IN/OUT]     
  526.  *  evt     [IN/OUT]     
  527.  * RETURNS
  528.  *  void
  529.  *****************************************************************************/
  530. static void gui_virtual_keyboard_translate_dead_key(
  531.                 virtual_keyboard *v,
  532.                 UI_character_type *ch,
  533.                 gui_virtual_keyboard_pen_enum *evt)
  534. {
  535.     /*----------------------------------------------------------------*/
  536.     /* Local Variables                                                */
  537.     /*----------------------------------------------------------------*/
  538.     const gui_keyboard_language_struct *lang;
  539.     /*----------------------------------------------------------------*/
  540.     /* Code Body                                                      */
  541.     /*----------------------------------------------------------------*/
  542.     lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
  543.     if (lang->enable_dead_key)
  544.     {
  545.         if (*evt == GUI_VKBD_PEN_CHAR_I)
  546.         {
  547.             if (gui_virtual_keyboard_check_dead_key(*ch))
  548.             {
  549.                 v->dead_key_input[0] = *ch;
  550.                 *ch = 0;
  551.                 *evt = GUI_VKBD_PEN_DEAD_KEY;
  552.             }
  553.             else if (v->dead_key_input[0])
  554.             {
  555.                 /* Only two key combination is currently supported */
  556.                 UI_character_type ret;
  557.                 v->dead_key_input[1] = *ch;
  558.                 if ((ret = gui_get_dead_key_symbol(v->lang_type, v->dead_key_input, 2)) != 0)
  559.                 {
  560.                     *ch = ret;
  561.                 }
  562.                 /* Otherwise, use the original key */
  563.                 v->dead_key_input[0] = 0;
  564.             }
  565.         }
  566.         else
  567.         {
  568.             v->dead_key_input[0] = 0;
  569.         }
  570.     }
  571. }
  572. /*****************************************************************************
  573.  * FUNCTION
  574.  *  gui_virtual_keyboard_clear_dead_key
  575.  * DESCRIPTION
  576.  *  
  577.  * PARAMETERS
  578.  *  v       [IN/OUT]     
  579.  * RETURNS
  580.  *  void
  581.  *****************************************************************************/
  582. static void gui_virtual_keyboard_clear_dead_key(virtual_keyboard *v)
  583. {
  584.     /*----------------------------------------------------------------*/
  585.     /* Local Variables                                                */
  586.     /*----------------------------------------------------------------*/
  587.     /*----------------------------------------------------------------*/
  588.     /* Code Body                                                      */
  589.     /*----------------------------------------------------------------*/
  590.     v->dead_key_input[0] = 0;
  591. }
  592. /*****************************************************************************
  593.  * FUNCTION
  594.  *  gui_virtual_keyboard_cache_and_show_selected_key
  595.  * DESCRIPTION
  596.  *  
  597.  * PARAMETERS
  598.  *  v       [IN/OUT]     
  599.  * RETURNS
  600.  *  void
  601.  *****************************************************************************/
  602. static void gui_virtual_keyboard_cache_and_show_selected_key(virtual_keyboard *v)
  603. {
  604.     /*----------------------------------------------------------------*/
  605.     /* Local Variables                                                */
  606.     /*----------------------------------------------------------------*/
  607.     S32 x1, x2, y1, y2;
  608.     S32 glyph_width, glyph_height;
  609.     virtual_keyboard_selection_struct *s;
  610.     const gui_keyboard_language_struct *lang;
  611.     UI_character_type ch = 0;
  612.     PU8 img = NULL;
  613.     /*----------------------------------------------------------------*/
  614.     /* Code Body                                                      */
  615.     /*----------------------------------------------------------------*/
  616.     lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
  617.     s = &v->selected_key;
  618.     MMI_DBG_ASSERT(s->custom_key_index >= 0 || s->matrix_index >= 0);
  619.     if (s->custom_key_index >= 0 && lang->custom_key_type[s->custom_key_index] == GUI_VKBD_PEN_DISPLAY_AREA)
  620.     {
  621.         /* We do not select Display Area. Furthermore, it costs too much memory to cache the area */
  622.         return;
  623.     }
  624.     x1 = s->key_x;
  625.     y1 = s->key_y;
  626.     x2 = x1 + s->key_width - 1;
  627.     y2 = y1 + s->key_height - 1;
  628.     /* Use a fixed size to avoid running out of certain control buffer bucket size */
  629.     MMI_DBG_ASSERT((((S32) s->key_width * s->key_height * gdi_layer_get_bit_per_pixel() + 7) >> 3) <=
  630.                    MMI_virtual_keyboard_bitmap_cache_size);
  631.     v->selected_key_cached = 1;
  632. #if 1
  633.     {
  634.         /* Workaround. We might not be able allocate large control buffer */
  635.     #if defined(__MMI_MAIN_BASE_LAYER_FORMAT__) && (__MMI_MAIN_BASE_LAYER_FORMAT__ == GDI_COLOR_FORMAT_32)
  636.         static char bitmap_buffer[5000];    
  637.     #else
  638.         static char bitmap_buffer[2500];
  639.     #endif
  640.         MMI_ASSERT(MMI_virtual_keyboard_bitmap_cache_size < sizeof(bitmap_buffer));
  641.         v->selected_key_bitmap.buf_ptr = (U8*) bitmap_buffer;
  642.     }
  643. #else /* 1 */ 
  644. /* under construction !*/
  645. #endif /* 1 */ 
  646.     gui_lock_double_buffer();
  647.     gdi_layer_push_clip();
  648.     gdi_layer_set_clip(x1, y1, x2, y2);
  649.     gdi_image_cache_bmp_get(x1, y1, x2, y2, &v->selected_key_bitmap);
  650.     gui_draw_filled_area(x1 + 1, y1 + 1, x2 - 1, y2 - 1, v->keyboard_theme->key_down_filler);
  651.     if (s->matrix_index >= 0)
  652.     {
  653.         ch = lang->matrix_string[s->matrix_row][s->matrix_column];
  654.     }
  655.     else if (s->custom_key_index >= 0 && lang->custom_string[s->custom_key_index])
  656.     {
  657.         ch = lang->custom_string[s->custom_key_index];
  658.     }
  659.     else
  660.     {
  661.         img = get_image(gui_virtual_keyboard_convert_custom_img(v, lang->custom_key_image[s->custom_key_index]));
  662.     }
  663.     if (ch)
  664.     {
  665.         gui_set_font(v->keyboard_theme->text_font);
  666.         gui_set_text_color(v->keyboard_theme->key_down_text_color);
  667.         gui_virtual_keyboard_show_char_center_align(
  668.             ch,
  669.             s->key_x,
  670.             s->key_y,
  671.             s->key_width,
  672.             s->key_height,
  673.             &glyph_width,
  674.             &glyph_height);
  675.     }
  676.     if (img)
  677.     {
  678.         gui_measure_image(img, &glyph_width, &glyph_height);
  679.         gui_show_image(
  680.             s->key_x + VKBD_DIFF_HALF(s->key_width, glyph_width),
  681.             s->key_y + VKBD_DIFF_HALF(s->key_height, glyph_height),
  682.             img);
  683.     }
  684.     gdi_layer_pop_clip();
  685.     gui_unlock_double_buffer();
  686.     gui_BLT_double_buffer(x1, y1, x2, y2);
  687. }
  688. /*****************************************************************************
  689.  * FUNCTION
  690.  *  gui_virtual_keyboard_show_unselect_key_from_cache
  691.  * DESCRIPTION
  692.  *  
  693.  * PARAMETERS
  694.  *  v       [IN/OUT]     
  695.  * RETURNS
  696.  *  void
  697.  *****************************************************************************/
  698. static void gui_virtual_keyboard_show_unselect_key_from_cache(virtual_keyboard *v)
  699. {
  700.     /*----------------------------------------------------------------*/
  701.     /* Local Variables                                                */
  702.     /*----------------------------------------------------------------*/
  703.     S16 x1, x2, y1, y2;
  704.     /*----------------------------------------------------------------*/
  705.     /* Code Body                                                      */
  706.     /*----------------------------------------------------------------*/
  707.     if (!v->selected_key_cached)
  708.     {
  709.         return;
  710.     }
  711.     x1 = v->selected_key.key_x;
  712.     y1 = v->selected_key.key_y;
  713.     x2 = x1 + v->selected_key.key_width - 1;
  714.     y2 = y1 + v->selected_key.key_height - 1;
  715.     gui_lock_double_buffer();
  716.     gdi_layer_push_clip();
  717.     gdi_layer_set_clip(x1, y1, x2, y2);
  718.     gdi_image_cache_bmp_draw(x1, y1, &v->selected_key_bitmap);
  719.     gdi_layer_pop_clip();
  720.     gui_unlock_double_buffer();
  721.     gui_BLT_double_buffer(x1, y1, x2, y2);
  722.     /* gui_free(v->selected_key_bitmap.buf_ptr); */
  723.     v->selected_key_bitmap.buf_ptr = NULL;
  724.     v->selected_key_cached = 0;
  725. }
  726. /*****************************************************************************
  727.  * FUNCTION
  728.  *  gui_virtual_keyboard_translate_pen_position
  729.  * DESCRIPTION
  730.  *  
  731.  * PARAMETERS
  732.  *  v       [IN/OUT]         
  733.  *  x       [IN]        
  734.  *  y       [IN]        
  735.  *  s       [OUT]         
  736.  * RETURNS
  737.  *  
  738.  *****************************************************************************/
  739. static BOOL gui_virtual_keyboard_translate_pen_position(
  740.                 virtual_keyboard *v,
  741.                 S16 x,
  742.                 S16 y,
  743.                 virtual_keyboard_selection_struct *s)
  744. {
  745.     /*----------------------------------------------------------------*/
  746.     /* Local Variables                                                */
  747.     /*----------------------------------------------------------------*/
  748.     const gui_keyboard_layout_struct *layout;
  749.     S32 i;
  750.     /*----------------------------------------------------------------*/
  751.     /* Code Body                                                      */
  752.     /*----------------------------------------------------------------*/
  753.     layout = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_layout;
  754.     gui_virtual_keyboard_clear_selected_key(s);
  755.     for (i = 0; i < layout->n_matrix_key_layout; i++)
  756.     {
  757.         const gui_matrix_key_layout_struct *matrix;
  758.         S32 matrix_x, matrix_y;
  759.         matrix = &layout->matrix_layout[i];
  760.         matrix_x = v->x + matrix->x;
  761.         matrix_y = v->y + matrix->y;
  762.         if (PEN_CHECK_BOUND(x, y, matrix_x, matrix_y, matrix->width, matrix->height))
  763.         {
  764.             s->matrix_index = i;
  765.             s->matrix_column = (x - matrix_x) / (matrix->key_width + matrix->horizontal_key_gap);
  766.             if (s->matrix_column >= matrix->n_columns)
  767.             {
  768.                 s->matrix_column = matrix->n_columns - 1;
  769.             }
  770.             s->matrix_row = (y - matrix_y) / (matrix->key_height + matrix->vertical_key_gap);
  771.             if (s->matrix_row >= matrix->n_rows)
  772.             {
  773.                 s->matrix_row = matrix->n_rows - 1;
  774.             }
  775.             s->key_width = matrix->key_width;
  776.             s->key_height = matrix->key_height;
  777.             s->key_x = matrix_x + s->matrix_column * (matrix->key_width + matrix->horizontal_key_gap);
  778.             s->key_y = matrix_y + s->matrix_row * (matrix->key_height + matrix->vertical_key_gap);
  779.             return MMI_TRUE;
  780.         }
  781.     }
  782.     for (i = 0; i < layout->n_custom_keys; i++)
  783.     {
  784.         const gui_custom_key_layout_struct *custom_key;
  785.         S32 custom_key_x, custom_key_y;
  786.         custom_key = &layout->custom_keys[i];
  787.         custom_key_x = v->x + custom_key->x;
  788.         custom_key_y = v->y + custom_key->y;
  789.         if (PEN_CHECK_BOUND(x, y, custom_key_x, custom_key_y, custom_key->key_width, custom_key->key_height))
  790.         {
  791.             s->custom_key_index = i;
  792.             s->key_width = custom_key->key_width;
  793.             s->key_height = custom_key->key_height;
  794.             s->key_x = custom_key_x;
  795.             s->key_y = custom_key_y;
  796.             return MMI_TRUE;
  797.         }
  798.     }
  799.     return MMI_FALSE;
  800. }
  801. #endif /* __MMI_TOUCH_SCREEN__ */ 
  802. /***************************************************************************** 
  803. * Global Variable
  804. *****************************************************************************/
  805. UI_virtual_keyboard_theme *current_virtual_keyboard_theme = NULL;
  806. /***************************************************************************** 
  807. * Global Function
  808. *****************************************************************************/
  809. /*****************************************************************************
  810.  * FUNCTION
  811.  *  gui_set_virtual_keyboard_current_theme
  812.  * DESCRIPTION
  813.  *  Applies the current theme for virtual keyboard.
  814.  * PARAMETERS
  815.  *  v       [IN/OUT]        Is the virtual keyboard pointer
  816.  * RETURNS
  817.  *  void
  818.  *****************************************************************************/
  819. void gui_set_virtual_keyboard_current_theme(virtual_keyboard *v)
  820. {
  821.     /*----------------------------------------------------------------*/
  822.     /* Local Variables                                                */
  823.     /*----------------------------------------------------------------*/
  824.     /*----------------------------------------------------------------*/
  825.     /* Code Body                                                      */
  826.     /*----------------------------------------------------------------*/
  827.     MMI_DBG_ASSERT(current_virtual_keyboard_theme);
  828.     v->keyboard_theme = current_virtual_keyboard_theme;
  829.     v->keyboard_theme->flags |= current_virtual_keyboard_theme->flags;
  830. }
  831. /*****************************************************************************
  832.  * FUNCTION
  833.  *  gui_set_virtual_keyboard_theme
  834.  * DESCRIPTION
  835.  *  Applies the current theme for virtual keyboard.
  836.  * PARAMETERS
  837.  *  v       [IN/OUT]        Is the virtual keyboard pointer
  838.  *  t       [IN]         
  839.  * RETURNS
  840.  *  void
  841.  *****************************************************************************/
  842. void gui_set_virtual_keyboard_theme(virtual_keyboard *v, UI_virtual_keyboard_theme *t)
  843. {
  844.     /*----------------------------------------------------------------*/
  845.     /* Local Variables                                                */
  846.     /*----------------------------------------------------------------*/
  847.     /*----------------------------------------------------------------*/
  848.     /* Code Body                                                      */
  849.     /*----------------------------------------------------------------*/
  850.     MMI_DBG_ASSERT(t);
  851.     v->keyboard_theme = t;
  852.     v->keyboard_theme->flags |= t->flags;
  853. }
  854. /*****************************************************************************
  855.  * FUNCTION
  856.  *  gui_create_virtual_keyboard
  857.  * DESCRIPTION
  858.  *  Create virtual keyboard object
  859.  * PARAMETERS
  860.  *  v               [IN/OUT]    Is the virtual keyboard object
  861.  *  x               [IN]        Is the left-top cornerd
  862.  *  y               [IN]        Is the left-top cornerd
  863.  *  lang_type       [IN]        Is language type to be used for the keyboard
  864.  * RETURNS
  865.  *  void
  866.  *****************************************************************************/
  867. void gui_create_virtual_keyboard(virtual_keyboard *v, S16 x, S16 y, gui_virtual_keyboard_language_enum lang_type)
  868. {
  869.     /*----------------------------------------------------------------*/
  870.     /* Local Variables                                                */
  871.     /*----------------------------------------------------------------*/
  872.     /*----------------------------------------------------------------*/
  873.     /* Code Body                                                      */
  874.     /*----------------------------------------------------------------*/
  875.     v->x = x;
  876.     v->y = y;
  877.     v->width = MMI_virtual_keyboard_language_map[lang_type].virtual_keyboard_layout->width;
  878.     v->height = MMI_virtual_keyboard_language_map[lang_type].virtual_keyboard_layout->height;
  879.     v->lang_type = lang_type;
  880.     v->flags = 0;
  881.     v->allowed_characters = NULL;
  882.     v->disp_area_text[0] = (UI_character_type) '';
  883.     v->disabled_chars[0] = (UI_character_type) '';
  884.     v->disabled_symbols[0] = GUI_VKBD_PEN_NONE;
  885.     gui_set_virtual_keyboard_current_theme(v);
  886.     memset(v->dead_key_input, 0, sizeof(v->dead_key_input));
  887.     gui_virtual_keyboard_clear_selected_key(&v->selected_key);
  888.     v->selected_key_bitmap.buf_ptr = NULL;
  889.     v->selected_key_cached = 0;
  890. }
  891. /*****************************************************************************
  892.  * FUNCTION
  893.  *  gui_move_virtual_keyboard
  894.  * DESCRIPTION
  895.  *  Move the virtual keyboard
  896.  * PARAMETERS
  897.  *  v       [IN/OUT]    Is the virtual keyboard object
  898.  *  x       [IN]        Is the left-top cornerd
  899.  *  y       [IN]        Is the left-top cornerd
  900.  * RETURNS
  901.  *  void
  902.  *****************************************************************************/
  903. void gui_move_virtual_keyboard(virtual_keyboard *v, S16 x, S16 y)
  904. {
  905.     /*----------------------------------------------------------------*/
  906.     /* Local Variables                                                */
  907.     /*----------------------------------------------------------------*/
  908.     /*----------------------------------------------------------------*/
  909.     /* Code Body                                                      */
  910.     /*----------------------------------------------------------------*/
  911.     v->x = x;
  912.     v->y = y;
  913. }
  914. /*****************************************************************************
  915.  * FUNCTION
  916.  *  gui_show_virtual_keyboard
  917.  * DESCRIPTION
  918.  *  Show the virtual keyboard
  919.  * PARAMETERS
  920.  *  v       [IN/OUT]        Is the virtual keyboard object
  921.  * RETURNS
  922.  *  void
  923.  *****************************************************************************/
  924. void gui_show_virtual_keyboard(virtual_keyboard *v)
  925. {
  926.     /*----------------------------------------------------------------*/
  927.     /* Local Variables                                                */
  928.     /*----------------------------------------------------------------*/
  929.     S16 x1, y1, x2, y2;
  930.     S32 glyph_width, glyph_height;
  931.     UI_character_type key_char;
  932.     S16 key_width, key_height;
  933.     S16 key_x, key_y;
  934.     const gui_keyboard_layout_struct *layout;
  935.     const gui_keyboard_language_struct *lang;
  936.     S16 i, j, k;
  937.     BOOL enable_dead_key;
  938.     /*----------------------------------------------------------------*/
  939.     /* Code Body                                                      */
  940.     /*----------------------------------------------------------------*/
  941.     x1 = v->x;
  942.     y1 = v->y;
  943.     x2 = v->x + v->width - 1;
  944.     y2 = v->y + v->height - 1;
  945.     layout = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_layout;
  946.     lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
  947.     enable_dead_key = lang->enable_dead_key;
  948.     gui_push_clip();
  949.     gui_push_text_clip();
  950.     gui_set_clip(x1, y1, x2, y2);
  951.     gui_set_text_clip(x1, y1, x2, y2);
  952.     gui_show_image(x1, y1, (PU8) get_image(layout->ImageId));
  953.     for (k = 0; k < layout->n_matrix_key_layout; k++)
  954.     {
  955.         S16 horizontal_text_gap, vertical_text_gap;
  956.         S16 n_matrix_column, n_matrix_row;
  957.         const gui_matrix_key_layout_struct *matrix;
  958.         const UI_character_type *matrix_string;
  959.         matrix = &layout->matrix_layout[k];
  960.         horizontal_text_gap = matrix->horizontal_key_gap;
  961.         vertical_text_gap = matrix->vertical_key_gap;
  962.         n_matrix_column = matrix->n_columns;
  963.         n_matrix_row = matrix->n_rows;
  964.         key_x = v->x + matrix->x;
  965.         key_y = v->y + matrix->y;
  966.         key_width = matrix->key_width;
  967.         key_height = matrix->key_height;
  968.         gui_set_font(v->keyboard_theme->text_font);
  969.         gui_set_text_color(v->keyboard_theme->key_up_text_color);
  970.         for (i = 0; i < n_matrix_row; i++)
  971.         {
  972.             matrix_string = lang->matrix_string[i];
  973.             for (j = 0; j < n_matrix_column; j++)
  974.             {
  975.                 BOOL restore_text_color = MMI_FALSE;
  976.                 key_char = matrix_string[j];
  977.                 if (enable_dead_key && gui_virtual_keyboard_check_dead_key(key_char))
  978.                 {
  979.                     gui_set_text_color(v->keyboard_theme->dead_key_up_text_color);
  980.                     restore_text_color = MMI_TRUE;
  981.                 }
  982.                 gui_virtual_keyboard_show_char_center_align(
  983.                     key_char,
  984.                     key_x,
  985.                     key_y,
  986.                     key_width,
  987.                     key_height,
  988.                     &glyph_width,
  989.                     &glyph_height);
  990.                 if (restore_text_color)
  991.                 {
  992.                     gui_set_text_color(v->keyboard_theme->key_up_text_color);
  993.                 }
  994.                 if (gui_virtual_keyboard_is_key_disabled(v, GUI_VKBD_PEN_CHAR_I, key_char))
  995.                 {
  996.                     gui_greyscale_rectangle(
  997.                         key_x,
  998.                         key_y,
  999.                         key_x + key_width - 1,
  1000.                         key_y + key_height - 1,
  1001.                         MMI_VKBD_GRAYSCALE_VALUE,
  1002.                         MMI_BG_GREYSCALE_BLACK_VALUE);
  1003.                 }
  1004.                 key_x += horizontal_text_gap + key_width;
  1005.             }
  1006.             key_x = v->x + matrix->x;
  1007.             key_y += vertical_text_gap + key_height;
  1008.         }
  1009.     }
  1010.     for (i = 0; i < layout->n_custom_keys; i++)
  1011.     {
  1012.         PU8 custom_image;
  1013.         key_x = v->x + layout->custom_keys[i].x;
  1014.         key_y = v->y + layout->custom_keys[i].y;
  1015.         key_width = layout->custom_keys[i].key_width;
  1016.         key_height = layout->custom_keys[i].key_height;
  1017.         key_char = lang->custom_string[i];
  1018.         if (lang->custom_key_type[i] == GUI_VKBD_PEN_DISPLAY_AREA)
  1019.         {
  1020.             gui_set_text_color(v->keyboard_theme->disp_area_text_color);
  1021.             gui_measure_string((UI_string_type) v->disp_area_text, &glyph_width, &glyph_height);
  1022.             gui_move_text_cursor(
  1023.                 key_x + VKBD_DIFF_HALF(key_width, glyph_width),
  1024.                 key_y + VKBD_DIFF_HALF(key_height, glyph_height));
  1025.             gui_print_text((UI_string_type) v->disp_area_text);
  1026.             /* Restore text color */
  1027.             gui_set_text_color(v->keyboard_theme->key_up_text_color);
  1028.         }
  1029.         else if (!key_char)
  1030.         {
  1031.             custom_image = get_image(gui_virtual_keyboard_convert_custom_img(v, lang->custom_key_image[i]));
  1032.             gui_measure_image(custom_image, &glyph_width, &glyph_height);
  1033.             gui_show_image(
  1034.                 key_x + VKBD_DIFF_HALF(key_width, glyph_width),
  1035.                 key_y + VKBD_DIFF_HALF(key_height, glyph_height),
  1036.                 custom_image);
  1037.         }
  1038.         else
  1039.         {
  1040.             BOOL restore_text_color = MMI_FALSE;
  1041.             if (enable_dead_key && gui_virtual_keyboard_check_dead_key(key_char))
  1042.             {
  1043.                 gui_set_text_color(v->keyboard_theme->dead_key_up_text_color);
  1044.                 restore_text_color = MMI_TRUE;
  1045.             }
  1046.             gui_virtual_keyboard_show_char_center_align(
  1047.                 key_char,
  1048.                 key_x,
  1049.                 key_y,
  1050.                 key_width,
  1051.                 key_height,
  1052.                 &glyph_width,
  1053.                 &glyph_height);
  1054.             if (restore_text_color)
  1055.             {
  1056.                 gui_set_text_color(v->keyboard_theme->key_up_text_color);
  1057.             }
  1058.         }
  1059.         if (gui_virtual_keyboard_is_key_disabled(v, lang->custom_key_type[i], key_char))
  1060.         {
  1061.             gui_greyscale_rectangle(
  1062.                 key_x,
  1063.                 key_y,
  1064.                 key_x + key_width - 1,
  1065.                 key_y + key_height - 1,
  1066.                 MMI_VKBD_GRAYSCALE_VALUE,
  1067.                 MMI_BG_GREYSCALE_BLACK_VALUE);
  1068.         }
  1069.     }
  1070.     gui_pop_clip();
  1071.     gui_pop_text_clip();
  1072. }
  1073. /*****************************************************************************
  1074.  * FUNCTION
  1075.  *  gui_set_virtual_keyboard_display_area
  1076.  * DESCRIPTION
  1077.  *  Update text displayed on display area
  1078.  * PARAMETERS
  1079.  *  v           [IN/OUT]        
  1080.  *  string      [IN]        String to be displayed in display area
  1081.  *  redraw      [IN]        Whether to redraw the keyboard
  1082.  * RETURNS
  1083.  *  void
  1084.  *****************************************************************************/
  1085. void gui_set_virtual_keyboard_display_area(virtual_keyboard *v, const U8 *string, BOOL redraw)
  1086. {
  1087.     /*----------------------------------------------------------------*/
  1088.     /* Local Variables                                                */
  1089.     /*----------------------------------------------------------------*/
  1090.     const gui_keyboard_layout_struct *layout;
  1091.     const gui_keyboard_language_struct *lang;
  1092.     S32 x1, y1, x2, y2, glyph_width, glyph_height;
  1093.     S32 i;
  1094.     /*----------------------------------------------------------------*/
  1095.     /* Code Body                                                      */
  1096.     /*----------------------------------------------------------------*/
  1097.     UCS2Strncpy((S8*) v->disp_area_text, (const S8*)string, MMI_VKBD_MAX_DISPLAY_AREA_TEXT_LEN);
  1098.     /* redraw the area only */
  1099.     if (redraw)
  1100.     {
  1101.         layout = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_layout;
  1102.         lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
  1103.         gui_set_font(v->keyboard_theme->text_font);
  1104.         for (i = 0; i < layout->n_custom_keys; i++)
  1105.         {
  1106.             if (lang->custom_key_type[i] == GUI_VKBD_PEN_DISPLAY_AREA)
  1107.             {
  1108.                 const gui_custom_key_layout_struct *custom_key = &layout->custom_keys[i];
  1109.                 x1 = v->x + custom_key->x;
  1110.                 y1 = v->y + custom_key->y;
  1111.                 x2 = x1 + custom_key->key_width - 1;
  1112.                 y2 = y1 + custom_key->key_height - 1;
  1113.                 gui_lock_double_buffer();
  1114.                 gui_push_clip();
  1115.                 gui_push_text_clip();
  1116.                 gui_set_clip(x1, y1, x2, y2);
  1117.                 gui_set_text_clip(x1, y1, x2, y2);
  1118.                 gui_show_image(x1, y1, get_image(gui_virtual_keyboard_convert_custom_img(v, lang->custom_key_image[i])));
  1119.                 gui_set_text_color(v->keyboard_theme->disp_area_text_color);
  1120.                 gui_measure_string((UI_string_type) v->disp_area_text, &glyph_width, &glyph_height);
  1121.                 gui_move_text_cursor(
  1122.                     x1 + VKBD_DIFF_HALF(custom_key->key_width, glyph_width),
  1123.                     y1 + VKBD_DIFF_HALF(custom_key->key_height, glyph_height));
  1124.                 gui_print_text((UI_string_type) v->disp_area_text);
  1125.                 gui_pop_clip();
  1126.                 gui_pop_text_clip();
  1127.                 gui_unlock_double_buffer();
  1128.                 gui_BLT_double_buffer(x1, y1, x2, y2);
  1129.                 break;
  1130.             }
  1131.         }
  1132.     }
  1133. }
  1134. /*****************************************************************************
  1135.  * FUNCTION
  1136.  *  gui_set_virtual_keyboard_multi_block_mode
  1137.  * DESCRIPTION
  1138.  *  Enter or leave multi-block handwriting mode. 
  1139.  *
  1140.  *  In multi-block handwriting mode, some keyboard icons are displayed differently.
  1141.  * PARAMETERS
  1142.  *  v           [IN/OUT]        
  1143.  *  enabled     [IN]            
  1144.  * RETURNS
  1145.  *  void
  1146.  *****************************************************************************/
  1147. void gui_set_virtual_keyboard_multi_block_mode(virtual_keyboard *v, MMI_BOOL enabled)
  1148. {
  1149.     /*----------------------------------------------------------------*/
  1150.     /* Local Variables                                                */
  1151.     /*----------------------------------------------------------------*/
  1152.     /*----------------------------------------------------------------*/
  1153.     /* Code Body                                                      */
  1154.     /*----------------------------------------------------------------*/
  1155.     if (enabled)
  1156.     {
  1157.         v->flags |= GUI_VKBD_FLAG_MULTI_BLOCK_MODE;
  1158.     }
  1159.     else
  1160.     {
  1161.         v->flags &= ~GUI_VKBD_FLAG_MULTI_BLOCK_MODE;
  1162.     }
  1163. }
  1164. /*****************************************************************************
  1165.  * FUNCTION
  1166.  *  gui_set_virtual_keyboard_allowed_characters
  1167.  * DESCRIPTION
  1168.  *  Only the allowd characters can be input on keyboard.
  1169.  *  This function and gui_set_virtual_board_disable_list() are mutually-exclusive.
  1170.  *  
  1171.  *  Control keys such as GUI_VKBD_PEN_HIDE, GUI_VKBD_PEN_SHOW... are enabled because
  1172.  *  they are not related to character insertion.
  1173.  *  
  1174.  *  `allowed_characters' may contain '-' for consecutive characters
  1175.  *  (Ex. 'a-z' for characters from a to z.)
  1176.  *  If we want to accept "-", please write it as '-'.
  1177.  *  For example, '-0-9.' represents "-0123456789."
  1178.  *  
  1179.  *  Example of valid characters in email addresss:
  1180.  *  wgui_set_virtual_keyboard_allowed_characters((const UI_character_type *) L"+_\-.@A-Za-z0-9");
  1181.  *  (it is not a complete list of all characters allowed in RFC, but it satisfies almost all cases)
  1182.  * PARAMETERS
  1183.  *  v                   [IN/OUT]    Virtual keyboard
  1184.  *  allowed_chars       [IN]        Allowed characters
  1185.  * RETURNS
  1186.  *  void
  1187.  *****************************************************************************/
  1188. void gui_set_virtual_keyboard_allowed_characters(virtual_keyboard *v, const UI_character_type *allowed_chars)
  1189. {
  1190.     /*----------------------------------------------------------------*/
  1191.     /* Local Variables                                                */
  1192.     /*----------------------------------------------------------------*/
  1193.     /*----------------------------------------------------------------*/
  1194.     /* Code Body                                                      */
  1195.     /*----------------------------------------------------------------*/
  1196.     v->allowed_characters = allowed_chars;
  1197. }
  1198. /*****************************************************************************
  1199.  * FUNCTION
  1200.  *  gui_set_virtual_board_disable_list
  1201.  * DESCRIPTION
  1202.  *  Disable some keys on keyboard.
  1203.  *  This function and gui_set_virtual_keyboard_allowed_characters() are mutually-exclusive.
  1204.  * PARAMETERS
  1205.  *  v                       [IN/OUT]    Virtual keyboard
  1206.  *  disabled_chars          [IN]        Null-terminated array of disabled unicode characters
  1207.  *  disabled_symbols        [IN]        Ended by GUI_VKBD_PEN_NONE
  1208.  * RETURNS
  1209.  *  void
  1210.  *****************************************************************************/
  1211. void gui_set_virtual_board_disable_list(
  1212.         virtual_keyboard *v,
  1213.         const UI_character_type *disabled_chars,
  1214.         const gui_virtual_keyboard_pen_enum *disabled_symbols)
  1215. {
  1216.     /*----------------------------------------------------------------*/
  1217.     /* Local Variables                                                */
  1218.     /*----------------------------------------------------------------*/
  1219.     S32 i;
  1220.     /*----------------------------------------------------------------*/
  1221.     /* Code Body                                                      */
  1222.     /*----------------------------------------------------------------*/
  1223.     /* Setup v->disabled_chars[] */
  1224.     for (i = 0; i < MMI_VKBD_MAX_DISABLED_KEYS; i++)
  1225.     {
  1226.         if (!disabled_chars[i])
  1227.         {
  1228.             break;
  1229.         }
  1230.         v->disabled_chars[i] = disabled_chars[i];
  1231.     }
  1232.     MMI_DBG_ASSERT(i < MMI_VKBD_MAX_DISABLED_KEYS || !disabled_chars[i]);
  1233.     v->disabled_chars[i] = 0;
  1234.     /* Setup v->disabled_symbols[] */
  1235.     for (i = 0; i < MMI_VKBD_MAX_DISABLED_KEYS; i++)
  1236.     {
  1237.         if (disabled_symbols[i] == GUI_VKBD_PEN_NONE)
  1238.         {
  1239.             break;
  1240.         }
  1241.         v->disabled_symbols[i] = disabled_symbols[i];
  1242.     }
  1243.     MMI_DBG_ASSERT(i < MMI_VKBD_MAX_DISABLED_KEYS || (disabled_symbols[i] == GUI_VKBD_PEN_NONE));
  1244.     v->disabled_symbols[i] = GUI_VKBD_PEN_NONE;
  1245. }
  1246. #ifdef __MMI_TOUCH_SCREEN__
  1247. /*****************************************************************************
  1248.  * FUNCTION
  1249.  *  gui_virtual_keyboard_translate_pen_event
  1250.  * DESCRIPTION
  1251.  *  
  1252.  * PARAMETERS
  1253.  *  v               [IN/OUT]         
  1254.  *  x               [IN]        
  1255.  *  y               [IN]        
  1256.  *  pen_event       [IN]        
  1257.  *  vkbd_event      [OUT]         
  1258.  *  vkbd_param      [OUT]         
  1259.  * RETURNS
  1260.  *  
  1261.  *****************************************************************************/
  1262. BOOL gui_virtual_keyboard_translate_pen_event(
  1263.         virtual_keyboard *v,
  1264.         S16 x,
  1265.         S16 y,
  1266.         mmi_pen_event_type_enum pen_event,
  1267.         gui_virtual_keyboard_pen_enum *vkbd_event,
  1268.         gui_pen_event_param_struct *vkbd_param)
  1269. {
  1270.     /*----------------------------------------------------------------*/
  1271.     /* Local Variables                                                */
  1272.     /*----------------------------------------------------------------*/
  1273.     BOOL ret = MMI_TRUE;
  1274.     const gui_keyboard_language_struct *lang;
  1275.     UI_character_type ch;
  1276.     gui_virtual_keyboard_pen_enum evt;
  1277.     /*----------------------------------------------------------------*/
  1278.     /* Code Body                                                      */
  1279.     /*----------------------------------------------------------------*/
  1280.     *vkbd_event = GUI_VKBD_PEN_NONE;
  1281.     GUI_PEN_EVENT_PARAM_SET_VOID(vkbd_param);
  1282.     lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
  1283.     switch (pen_event)
  1284.     {
  1285.         case MMI_PEN_EVENT_DOWN:
  1286.             v->key_down_accepted = MMI_FALSE;
  1287.             if (PEN_CHECK_BOUND(x, y, v->x, v->y, v->width, v->height))
  1288.             {
  1289.                 if (gui_virtual_keyboard_translate_pen_position(v, x, y, &v->selected_key))
  1290.                 {
  1291.                     gui_virtual_keyboard_get_selected_key(v, &ch, &evt);
  1292.                     if ((evt == GUI_VKBD_PEN_NONE) || gui_virtual_keyboard_is_key_disabled(v, evt, ch))
  1293.                     {
  1294.                         /* Do nothing */
  1295.                     }
  1296.                     else
  1297.                     {
  1298.                         v->key_down_accepted = MMI_TRUE;
  1299.                         gui_virtual_keyboard_cache_and_show_selected_key(v);
  1300.                         /* 
  1301.                          * If Pen Down and Pen Up comes together, we should temporarily suspend MMI task. 
  1302.                          * Otherwise, user can not see pen down due to delayed LCM update.
  1303.                          */
  1304.                     #ifdef MMI_ON_HARDWARE_P
  1305.                         kal_sleep_task(kal_milli_secs_to_ticks(30));
  1306.                     #endif 
  1307.                     }
  1308.                 }
  1309.             }
  1310.             else
  1311.             {
  1312.                 return MMI_FALSE;
  1313.             }
  1314.             break;
  1315.         case MMI_PEN_EVENT_MOVE:
  1316.             if (v->key_down_accepted)
  1317.             {
  1318.                 virtual_keyboard_selection_struct s;
  1319.                 if (PEN_CHECK_BOUND(x, y, v->x, v->y, v->width, v->height) &&
  1320.                     gui_virtual_keyboard_translate_pen_position(v, x, y, &s))
  1321.                 {
  1322.                     if (memcmp(&v->selected_key, &s, sizeof(s)))
  1323.                     {
  1324.                         gui_virtual_keyboard_show_unselect_key_from_cache(v);
  1325.                         memcpy(&v->selected_key, &s, sizeof(s));
  1326.                         gui_virtual_keyboard_get_selected_key(v, &ch, &evt);
  1327.                         if (!((evt == GUI_VKBD_PEN_NONE) || gui_virtual_keyboard_is_key_disabled(v, evt, ch)))
  1328.                         {
  1329.                             gui_virtual_keyboard_cache_and_show_selected_key(v);
  1330.                         }
  1331.                     }
  1332.                 }
  1333.                 else
  1334.                 {
  1335.                     gui_virtual_keyboard_show_unselect_key_from_cache(v);
  1336.                     gui_virtual_keyboard_clear_selected_key(&v->selected_key);
  1337.                 }
  1338.             }
  1339.             break;
  1340.         case MMI_PEN_EVENT_UP:
  1341.             if (v->key_down_accepted)
  1342.             {
  1343.                 gui_virtual_keyboard_show_unselect_key_from_cache(v);
  1344.                 if (gui_virtual_keyboard_get_selected_key(v, &ch, &evt))
  1345.                 {
  1346.                     gui_virtual_keyboard_translate_dead_key(v, &ch, &evt);
  1347.                     if (evt == GUI_VKBD_PEN_SPACE)
  1348.                     {
  1349.                         evt = GUI_VKBD_PEN_CHAR_I;
  1350.                         ch = (UI_character_type) ' ';
  1351.                     }
  1352.                     else if (evt == GUI_VKBD_PEN_DEAD_KEY)
  1353.                     {
  1354.                         evt = GUI_VKBD_PEN_NONE;
  1355.                     }
  1356.                     *vkbd_event = evt;
  1357.                     if (evt == GUI_VKBD_PEN_CHAR_I)
  1358.                     {
  1359.                         GUI_PEN_EVENT_PARAM_SET_INTEGER(vkbd_param, (int)ch);
  1360.                     }
  1361.                 }
  1362.             }
  1363.             break;
  1364.         case MMI_PEN_EVENT_ABORT:
  1365.             gui_virtual_keyboard_show_unselect_key_from_cache(v);
  1366.             gui_virtual_keyboard_clear_dead_key(v);
  1367.             break;
  1368.         case MMI_PEN_EVENT_LONG_TAP:
  1369.             /* FALLTHROUGH no break */
  1370.         case MMI_PEN_EVENT_REPEAT:
  1371.             /* Do nothing */
  1372.             break;
  1373.     }
  1374.     return ret;
  1375. }
  1376. #endif /* __MMI_TOUCH_SCREEN__ */