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

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.  * PhoneBookSearch.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for sorting, search, quick search function in Phonebook application
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  *
  171.  * removed!
  172.  * removed!
  173.  * removed!
  174.  *
  175.  *------------------------------------------------------------------------------
  176.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  177.  *============================================================================
  178.  ****************************************************************************/
  179. #ifndef _PHONEBOOKSEARCH_C
  180. #define _PHONEBOOKSEARCH_C
  181. #include "MMI_features.h"
  182. #if defined(__MMI_T9__)
  183. #if defined(__MMI_T9_V7__)
  184. #include "t9ccapi.h"
  185. #include "T9Main.h"
  186. #else /* defined(__MMI_T9_V7__) */ 
  187. #include "T9api.h"
  188. #include "T9Main.h"
  189. #endif /* defined(__MMI_T9_V7__) */ 
  190. #endif /* defined(__MMI_T9__) */ 
  191. #if defined(__MMI_ZI__)
  192. #include "Zi8api.h"
  193. #ifndef ZI8_GETMODE_BOPOMOFO_NAME
  194. #define ZI8_GETMODE_BOPOMOFO_NAME ZI8_GETMODE_BOPOMOFO
  195. #endif 
  196. #ifndef ZI8_GETMODE_PINYIN_NAME
  197. #define ZI8_GETMODE_PINYIN_NAME ZI8_GETMODE_PINYIN
  198. #endif 
  199. #endif /* defined(__MMI_ZI__) */ 
  200. //KP Jerry add on 2007-3-8 start
  201. #if defined(__MMI_CSTAR__)
  202. #include "cstarime.h"
  203. #endif
  204. //KP Jerry add on 2007-3-8 end
  205. #if defined(__MMI_ITAP__)
  206. /* under construction !*/
  207. /* under construction !*/
  208. /* under construction !*/
  209. #endif /* defined(__MMI_ITAP__) */ 
  210. #include "stdC.h"
  211. #include "L4Dr1.h"
  212. #include "PixtelDataTypes.h"
  213. #include "GlobalConstants.h"
  214. #include "DebugInitDef.h"
  215. #include "ProtocolEvents.h"
  216. #include "wgui_categories.h"
  217. #include "wgui_categories_inputs.h"
  218. #include "wgui_status_icons.h"
  219. #include "PhonebookDef.h"
  220. #include "PhoneBookTypes.h"
  221. #include "PhonebookProt.h"
  222. #include "PhonebookGprot.h"
  223. #include "HistoryGprot.h"
  224. #include "QueueGProt.h"
  225. #include "mainmenudef.h"
  226. #include "Unicodexdcl.h"
  227. #include "GlobalDefs.h"
  228. #include "CommonScreens.h"
  229. #include "TimerEvents.h"
  230. #include "NVRAMProt.h"
  231. #include "NVRAMType.h"
  232. #include "NVRAMEnum.h"
  233. #if defined(__MMI_PHB_EMAIL_SORT__)
  234. #include "Nvram_user_defs.h"    /* For email sorting. Need Accessing NVRAM data */
  235. #include "NVRAMProt.h"
  236. #endif /* defined(__MMI_PHB_EMAIL_SORT__) */ 
  237. #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  238. #include "mdi_datatype.h"
  239. #include "mdi_audio.h"
  240. #endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 
  241. #ifdef __FLIGHT_MODE_SUPPORT__
  242. #include "SimDetectionGprot.h"
  243. #endif 
  244. #ifdef __SYNCML_SUPPORT__
  245. #include "SyncMLDef.h"
  246. #include "SyncMLGprot.h"
  247. #endif /* __SYNCML_SUPPORT__ */
  248. /*
  249.  * Typedef
  250.  */
  251. typedef void (*phb_comp_func) (U16 first, U16 second, U8 *same_count, S32 *distance);
  252. /*
  253.  * Define
  254.  */
  255. #define MMI_PHB_COMPARE_LENGTH 10       /* Compare 10 characters */
  256. #define MMI_PHB_CONVERT_BUFF_ZI 32      /* ZI convert function need 32 bytes for buffer. */
  257. #define MMI_PHB_QUICK_SEARCH_INPUT_LENGTH 6
  258. #define MMI_PHB_SORT_LENGTH 10  /* Compare 10 characters */
  259. #define MAX_PHB_NUMBER_COMP   20        /* Compare 20 entries for number filed */
  260. #define BYTE_SIZE                      8        /* for g_phb_qsearch_bitmask */
  261. #define BYTE_SIZE_SHIFT_ARITHMETIC     3
  262. /*
  263.  * Local Variable
  264.  */
  265. #if defined(__MMI_PHB_QUICK_SEARCH__)
  266. static U16 g_phb_qsearch_cache[MAX_PB_ENTRIES];
  267. /* static U8    g_phb_qsearch[MAX_PB_ENTRIES]; */
  268. static U8 g_phb_qsearch_bitmask[(MAX_PB_ENTRIES + 7) / 8];
  269. static U8 g_phb_qsearch_input[(MMI_PHB_QUICK_SEARCH_INPUT_LENGTH + 1) * ENCODING_LENGTH];
  270. static U8 g_phb_qsearch_is_cache = 0;   /* Check if cache already build */
  271. #endif /* defined(__MMI_PHB_QUICK_SEARCH__) */ 
  272. #if defined(__MMI_PHB_PINYIN_SORT__)
  273. static U8 g_phb_name_pinyin_index[MAX_PB_ENTRIES][(MMI_PHB_SORT_LENGTH + 1) * ENCODING_LENGTH];
  274. #endif 
  275. static U8 g_phb_compare_length = 0xff;  /* number compare length */
  276. /*
  277.  * Global Variable
  278.  */
  279. extern MMI_PHB_LIST_VIEW phbListView;
  280. extern S8 pbName[(MAX_PB_NAME_LENGTH + 1) * ENCODING_LENGTH];
  281. extern MMI_PHB_ENTRY_BCD_STRUCT PhoneBook[];
  282. extern U16 g_phb_name_index[];
  283. extern U16 PhoneBookEntryCount;
  284. #ifdef __MMI_PHB_USIM_FIELD__
  285. extern MMI_PHB_NUMBER_BCD_STRUCT phb_anr[MAX_PB_SIM_ENTRIES][3];
  286. #ifdef __MMI_PHB_EMAIL_SORT__
  287. extern MMI_PHB_EMAIL_STRUCT phb_email[MAX_PB_SIM_ENTRIES];
  288. #endif 
  289. #endif /* __MMI_PHB_USIM_FIELD__ */
  290. extern U8 MMI_current_input_mode;
  291. extern U8 gInsertSimAppFlag;
  292. extern MMI_PHB_LOOKUP_NODE_STRUCT LookUpTable[];
  293. #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  294. extern U8 g_phb_is_speaking_name;
  295. #endif 
  296. #if defined(__MMI_T9__)
  297. #if defined(__MMI_T9_V7__)
  298. extern T9CCAWFieldInfo FieldInfo;
  299. #else 
  300. extern T9FieldInfo FieldInfo;
  301. #endif 
  302. #endif /* defined(__MMI_T9__) */ 
  303. #if defined(__MMI_ITAP__)
  304. /* under construction !*/
  305. /* under construction !*/
  306. /* under construction !*/
  307. /* under construction !*/
  308. #endif /* defined(__MMI_ITAP__) */ 
  309. extern PHB_OPTIONAL_FIELDS_STRUCT PhoneBookOptionalFields;
  310. extern S8 pbEmailAddress[];
  311. /*
  312.  * Local Function
  313.  */
  314. static void mmi_phb_sort_name_fast_quicksort(U16 left, U16 right, phb_comp_func compare);
  315. static void mmi_phb_sort_name_quicksort(U16 left, U16 right, phb_comp_func compare);
  316. static void mmi_phb_sort_name_insertionsort(U16 low, U16 high, phb_comp_func compare);
  317. static void mmi_phb_sort_name_swap(U16 a, U16 b);
  318. /*
  319.  * Global Function
  320.  */
  321. #define MMI_PHB_SEARCH_INIT
  322. /*****************************************************************************
  323.  * FUNCTION
  324.  *  mmi_phb_search_init
  325.  * DESCRIPTION
  326.  *  Initial function for phonebook search and sort.
  327.  * PARAMETERS
  328.  *  void
  329.  * RETURNS
  330.  *  void
  331.  *****************************************************************************/
  332. void mmi_phb_search_init(void)
  333. {
  334.     /*----------------------------------------------------------------*/
  335.     /* Local Variables                                                */
  336.     /*----------------------------------------------------------------*/
  337.     /*----------------------------------------------------------------*/
  338.     /* Code Body                                                      */
  339.     /*----------------------------------------------------------------*/
  340.     SetHiliteHandler(MITEM101_PBOOK_SEARCH_ENTRY, mmi_phb_highlight_search_name);
  341.     SetHiliteHandler(MITEM1010_SEARCH, mmi_phb_highlight_search_name_option_search);
  342.     SetHiliteHandler(MITEM1011_INPUT_MEHTHOD, mmi_phb_highlight_search_name_option_input_method);
  343. #if defined(__MMI_PHB_QUICK_SEARCH__)
  344.     SetHiliteHandler(MENU_ID_PHB_QUICK_SEARCH, mmi_phb_highlight_quick_search_list);
  345. #if defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__)
  346.     SetHiliteHandler(MENU_ID_PHB_QUICK_SEARCH_INPUT_METHOD, mmi_phb_highlight_quick_search_input_method);
  347.     SetHiliteHandler(MENU_ID_PHB_QUICK_SEARCH_OP_OPTION, mmi_phb_highlight_quick_search_op_option);
  348. #endif /* defined(__MMI_MULTITAP_FOR_STAR_AND_POUND__) */ 
  349. #endif /* defined(__MMI_PHB_QUICK_SEARCH__) */ 
  350. }
  351. #define MMI_PHB_SORT
  352. /*****************************************************************************
  353.  * FUNCTION
  354.  *  mmi_phb_sort_build_name_index
  355.  * DESCRIPTION
  356.  *  This function is just for template.
  357.  * PARAMETERS
  358.  *  void
  359.  * RETURNS
  360.  *  void
  361.  *****************************************************************************/
  362. void mmi_phb_sort_build_name_index(void)
  363. {
  364.     /*----------------------------------------------------------------*/
  365.     /* Local Variables                                                */
  366.     /*----------------------------------------------------------------*/
  367.     /*----------------------------------------------------------------*/
  368.     /* Code Body                                                      */
  369.     /*----------------------------------------------------------------*/
  370.     if (PhoneBookEntryCount > 1)
  371.     {
  372.     #if defined(__MMI_PHB_PINYIN_SORT__)
  373.         if (g_phb_cntx.sort_type == MMI_PHB_SORT_PINYIN)
  374.         {
  375.             mmi_phb_sort_name_fast_quicksort(
  376.                 0,
  377.                 (U16) (PhoneBookEntryCount - 1),
  378.                 mmi_phb_sort_compare_name_index_by_pinyin_cache);
  379.         }
  380.         else
  381.     #endif /* defined(__MMI_PHB_PINYIN_SORT__) */ 
  382.             mmi_phb_sort_name_fast_quicksort(
  383.                 0,
  384.                 (U16) (PhoneBookEntryCount - 1),
  385.                 mmi_phb_sort_compare_name_index_by_encoding);
  386.     }
  387. }
  388. /*****************************************************************************
  389.  * FUNCTION
  390.  *  mmi_phb_sort_insert_name_index
  391.  * DESCRIPTION
  392.  *  This function is just for template.
  393.  * PARAMETERS
  394.  *  store_index     [IN]            
  395.  *  a(?)            [IN/OUT]        First variable, used as returns
  396.  *  b(?)            [IN]            Second variable
  397.  * RETURNS
  398.  *  the description of return value, if any.
  399.  *****************************************************************************/
  400. U16 mmi_phb_sort_insert_name_index(U16 store_index)
  401. {
  402.     /*----------------------------------------------------------------*/
  403.     /* Local Variables                                                */
  404.     /*----------------------------------------------------------------*/
  405.     U16 pos;
  406.     U16 i;
  407.     /*----------------------------------------------------------------*/
  408.     /* Code Body                                                      */
  409.     /*----------------------------------------------------------------*/
  410.     if (PhoneBookEntryCount == 0)
  411.     {
  412.         g_phb_name_index[PhoneBookEntryCount] = store_index;
  413.         PhoneBookEntryCount++;
  414.         return 0;
  415.     }
  416.     else
  417.     {
  418.         pos = mmi_phb_sort_insert_name_index_find_pos(0, (PhoneBookEntryCount - 1), store_index);
  419.         for (i = PhoneBookEntryCount; i > pos; i--)
  420.         {
  421.             g_phb_name_index[i] = g_phb_name_index[i - 1];
  422.         }
  423.         g_phb_name_index[pos] = store_index;
  424.         PhoneBookEntryCount++;
  425.         return pos;
  426.     }
  427. }
  428. /*****************************************************************************
  429.  * FUNCTION
  430.  *  mmi_phb_sort_insert_name_index_find_pos
  431.  * DESCRIPTION
  432.  *  This function is just for template.
  433.  * PARAMETERS
  434.  *  low             [IN]            
  435.  *  high            [IN]            
  436.  *  store_index     [IN]            
  437.  *  a(?)            [IN/OUT]        First variable, used as returns
  438.  *  b(?)            [IN]            Second variable
  439.  * RETURNS
  440.  *  the description of return value, if any.
  441.  *****************************************************************************/
  442. U16 mmi_phb_sort_insert_name_index_find_pos(S32 low, S32 high, U16 store_index)
  443. {
  444.     /*----------------------------------------------------------------*/
  445.     /* Local Variables                                                */
  446.     /*----------------------------------------------------------------*/
  447.     S32 mid = 0;
  448.     S16 flag = 0;
  449.     U8 same_count;
  450.     S32 distance;
  451.     /*----------------------------------------------------------------*/
  452.     /* Code Body                                                      */
  453.     /*----------------------------------------------------------------*/
  454.     while (low <= high)
  455.     {
  456.         mid = (low + high) / 2;
  457.     #if defined(__MMI_PHB_PINYIN_SORT__)
  458.         if (g_phb_cntx.sort_type == MMI_PHB_SORT_PINYIN)
  459.         {
  460.             mmi_phb_sort_compare_name_index_by_pinyin(store_index, g_phb_name_index[mid], &same_count, &distance);
  461.         }
  462.         else
  463.     #endif /* defined(__MMI_PHB_PINYIN_SORT__) */ 
  464.             mmi_phb_sort_compare_name_index_by_encoding(store_index, g_phb_name_index[mid], &same_count, &distance);
  465.         if (distance > 0)
  466.         {
  467.             low = mid + 1;
  468.             flag = -1;
  469.         }
  470.         else    /* Either > 0 or < 0, not possible ==0 */
  471.         {
  472.             high = mid - 1;
  473.             flag = 1;
  474.         }
  475.     }
  476.     if (flag == -1)
  477.     {
  478.         return (U16) (mid + 1);
  479.     }
  480.     else
  481.     {
  482.         return (U16) mid;
  483.     }
  484. }
  485. /*****************************************************************************
  486.  * FUNCTION
  487.  *  mmi_phb_sort_compare_name_index
  488.  * DESCRIPTION
  489.  *  Compare two phonebook by name string. If name is empty use number instead.
  490.  * PARAMETERS
  491.  *  first           [IN]            Store_index of first compare element
  492.  *  second          [IN]            Store_index of second compare element
  493.  *  string1         [IN]            First name string
  494.  *  string2         [IN]            Second name string
  495.  *  same_count      [IN/OUT]        Same count of two element
  496.  *  distance        [IN/OUT]        Difference of two element
  497.  * RETURNS
  498.  *  void
  499.  *****************************************************************************/
  500. void mmi_phb_sort_compare_name_index(U16 first, U16 second, S8 *string1, S8 *string2, U8 *same_count, S32 *distance)
  501. {
  502.     /*----------------------------------------------------------------*/
  503.     /* Local Variables                                                */
  504.     /*----------------------------------------------------------------*/
  505.     S8 number1[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  506.     S8 number2[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  507.     /*----------------------------------------------------------------*/
  508.     /* Code Body                                                      */
  509.     /*----------------------------------------------------------------*/
  510.     /* Use number to sort if name empty */
  511.     if (pfnUnicodeStrlen(string1) == 0)
  512.     {
  513.         mmi_phb_convert_get_ucs2_number(number1, first);
  514.         string1 = (S8*) number1;
  515.     }
  516.     /* Use number to sort if name empty */
  517.     if (pfnUnicodeStrlen(string2) == 0)
  518.     {
  519.         mmi_phb_convert_get_ucs2_number(number2, second);
  520.         string2 = (S8*) number2;
  521.     }
  522.     /* Compare two strings */
  523.     mmi_phb_compare_ucs2_strings(string1, string2, same_count, distance);
  524.     /* sort according storage location, let entry in NVRAM put before in SIM. (store_index can decide store location) */
  525.     if (*distance == 0)
  526.     {
  527.         if (first < second)
  528.         {
  529.             *distance = -1;
  530.         }
  531.         else if (first > second)
  532.         {
  533.             *distance = 1;
  534.         }
  535.     }
  536. }
  537. /*****************************************************************************
  538.  * FUNCTION
  539.  *  mmi_phb_sort_compare_name_index_by_encoding
  540.  * DESCRIPTION
  541.  *  Compare two phonebook entry element by encoding.
  542.  * PARAMETERS
  543.  *  first           [IN]            Store_index of first compare element
  544.  *  second          [IN]            Store_index of second compare element
  545.  *  same_count      [IN/OUT]        Same count of two element
  546.  *  distance        [IN/OUT]        Difference of two element
  547.  * RETURNS
  548.  *  void
  549.  *****************************************************************************/
  550. void mmi_phb_sort_compare_name_index_by_encoding(U16 first, U16 second, U8 *same_count, S32 *distance)
  551. {
  552.     /*----------------------------------------------------------------*/
  553.     /* Local Variables                                                */
  554.     /*----------------------------------------------------------------*/
  555.     S8 *string1, *string2;
  556.     /*----------------------------------------------------------------*/
  557.     /* Code Body                                                      */
  558.     /*----------------------------------------------------------------*/
  559.     string1 = (S8*) PhoneBook[first].alpha_id.name;
  560.     string2 = (S8*) PhoneBook[second].alpha_id.name;
  561.     mmi_phb_sort_compare_name_index(first, second, string1, string2, same_count, distance);
  562. }
  563. /*****************************************************************************
  564.  * FUNCTION
  565.  *  mmi_phb_sort_compare_name_index_by_pinyin_cache
  566.  * DESCRIPTION
  567.  *  Compare two phonebook entry element by pinyin by using prior convert result.
  568.  * PARAMETERS
  569.  *  first           [IN]            Store_index of first compare element
  570.  *  second          [IN]            Store_index of second compare element
  571.  *  same_count      [IN/OUT]        Same count of two element
  572.  *  distance        [IN/OUT]        Difference of two element
  573.  * RETURNS
  574.  *  void
  575.  *****************************************************************************/
  576. #if defined(__MMI_PHB_PINYIN_SORT__)
  577. void mmi_phb_sort_compare_name_index_by_pinyin_cache(U16 first, U16 second, U8 *same_count, S32 *distance)
  578. {
  579.     /*----------------------------------------------------------------*/
  580.     /* Local Variables                                                */
  581.     /*----------------------------------------------------------------*/
  582.     S8 *string1, *string2;
  583.     /*----------------------------------------------------------------*/
  584.     /* Code Body                                                      */
  585.     /*----------------------------------------------------------------*/
  586.     if (PhoneBook[first].alpha_id.name_dcs == MMI_PHB_ASCII)
  587.     {
  588.         string1 = (S8*) PhoneBook[first].alpha_id.name;
  589.     }
  590.     else
  591.     {
  592.         string1 = (S8*) g_phb_name_pinyin_index[first];
  593.     }
  594.     if (PhoneBook[second].alpha_id.name_dcs == MMI_PHB_ASCII)
  595.     {
  596.         string2 = (S8*) PhoneBook[second].alpha_id.name;
  597.     }
  598.     else
  599.     {
  600.         string2 = (S8*) g_phb_name_pinyin_index[second];
  601.     }
  602.     mmi_phb_sort_compare_name_index(first, second, string1, string2, same_count, distance);
  603. }
  604. /*****************************************************************************
  605.  * FUNCTION
  606.  *  mmi_phb_sort_compare_name_index_by_pinyin
  607.  * DESCRIPTION
  608.  *  Compare two phonebook entry element by pinyin.
  609.  * PARAMETERS
  610.  *  first           [IN]            Store_index of first compare element
  611.  *  second          [IN]            Store_index of second compare element
  612.  *  same_count      [IN/OUT]        Same count of two element
  613.  *  distance        [IN/OUT]        Difference of two element
  614.  * RETURNS
  615.  *  void
  616.  *****************************************************************************/
  617. void mmi_phb_sort_compare_name_index_by_pinyin(U16 first, U16 second, U8 *same_count, S32 *distance)
  618. {
  619.     /*----------------------------------------------------------------*/
  620.     /* Local Variables                                                */
  621.     /*----------------------------------------------------------------*/
  622.     S8 *string1, *string2;
  623.     S8 buffer1[(MMI_PHB_SORT_LENGTH + 1) * ENCODING_LENGTH];
  624.     S8 buffer2[(MMI_PHB_SORT_LENGTH + 1) * ENCODING_LENGTH];
  625.     U16 count;
  626.     /*----------------------------------------------------------------*/
  627.     /* Code Body                                                      */
  628.     /*----------------------------------------------------------------*/
  629.     if (PhoneBook[first].alpha_id.name_dcs == MMI_PHB_ASCII)
  630.     {
  631.         string1 = (S8*) PhoneBook[first].alpha_id.name;
  632.     }
  633.     else
  634.     {
  635.         count = mmi_phb_util_convert_to_pinyin(
  636.                     PhoneBook[first].alpha_id.name,
  637.                     (U8*) buffer1,
  638.                     (MMI_PHB_SORT_LENGTH * ENCODING_LENGTH));
  639.         buffer1[count++] = 0x00;
  640.         buffer1[count] = 0x00;
  641.         string1 = (S8*) buffer1;
  642.     }
  643.     if (PhoneBook[second].alpha_id.name_dcs == MMI_PHB_ASCII)
  644.     {
  645.         string2 = (S8*) PhoneBook[second].alpha_id.name;
  646.     }
  647.     else
  648.     {
  649.         count = mmi_phb_util_convert_to_pinyin(
  650.                     PhoneBook[second].alpha_id.name,
  651.                     (U8*) buffer2,
  652.                     (MMI_PHB_SORT_LENGTH * ENCODING_LENGTH));
  653.         buffer2[count++] = 0x00;
  654.         buffer2[count] = 0x00;
  655.         string2 = (S8*) buffer2;
  656.     }
  657.     mmi_phb_sort_compare_name_index(first, second, string1, string2, same_count, distance);
  658. }
  659. #endif /* defined(__MMI_PHB_PINYIN_SORT__) */ 
  660. /*****************************************************************************
  661.  * FUNCTION
  662.  *  mmi_phb_sort_name_fast_quicksort
  663.  * DESCRIPTION
  664.  *  This function is just for template.
  665.  * PARAMETERS
  666.  *  left        [IN]            
  667.  *  right       [IN]            
  668.  *  compare     [IN]            
  669.  *  a(?)        [IN/OUT]        First variable, used as returns
  670.  *  b(?)        [IN]            Second variable
  671.  * RETURNS
  672.  *  the description of return value, if any.(?)
  673.  *****************************************************************************/
  674. void mmi_phb_sort_name_fast_quicksort(U16 left, U16 right, phb_comp_func compare)
  675. {
  676.     /*----------------------------------------------------------------*/
  677.     /* Local Variables                                                */
  678.     /*----------------------------------------------------------------*/
  679.     /*----------------------------------------------------------------*/
  680.     /* Code Body                                                      */
  681.     /*----------------------------------------------------------------*/
  682.     mmi_phb_sort_name_quicksort(left, right, compare);
  683.     mmi_phb_sort_name_insertionsort(left, right, compare);
  684. }
  685. /*****************************************************************************
  686.  * FUNCTION
  687.  *  mmi_phb_sort_name_quicksort
  688.  * DESCRIPTION
  689.  *  This function is just for template.
  690.  * PARAMETERS
  691.  *  left        [IN]            
  692.  *  right       [IN]            
  693.  *  compare     [IN]            
  694.  *  a(?)        [IN/OUT]        First variable, used as returns
  695.  *  b(?)        [IN]            Second variable
  696.  * RETURNS
  697.  *  the description of return value, if any.(?)
  698.  *****************************************************************************/
  699. void mmi_phb_sort_name_quicksort(U16 left, U16 right, phb_comp_func compare)
  700. {
  701.     /*----------------------------------------------------------------*/
  702.     /* Local Variables                                                */
  703.     /*----------------------------------------------------------------*/
  704.     U16 const Min = 4;  /* Lower bound to sort */
  705.     U16 i;
  706.     U16 j;
  707.     U16 pivot;
  708.     S32 distance;
  709.     U8 same_count;
  710.     /*----------------------------------------------------------------*/
  711.     /* Code Body                                                      */
  712.     /*----------------------------------------------------------------*/
  713.     MMI_ASSERT(compare != NULL);
  714.     if ((right - left) > Min)
  715.     {
  716.         i = (right + left) / 2;
  717.         /* left > mid */
  718.         (*compare) (g_phb_name_index[left], g_phb_name_index[i], &same_count, &distance);
  719.         if (distance > 0)
  720.         {
  721.             mmi_phb_sort_name_swap(left, i);
  722.         }
  723.         /* left > right */
  724.         (*compare) (g_phb_name_index[left], g_phb_name_index[right], &same_count, &distance);
  725.         if (distance > 0)
  726.         {
  727.             mmi_phb_sort_name_swap(left, right);
  728.         }
  729.         /* mid > right */
  730.         (*compare) (g_phb_name_index[i], g_phb_name_index[right], &same_count, &distance);
  731.         if (distance > 0)
  732.         {
  733.             mmi_phb_sort_name_swap(i, right);
  734.         }
  735.         j = right - 1;
  736.         mmi_phb_sort_name_swap(i, j);
  737.         i = left;
  738.         pivot = g_phb_name_index[j];    /* kal_mem_cpy(&v, (void const*)&a[j], sizeof(pindex_struct)); */
  739.         for (;;)
  740.         {
  741.             do  /* ++i < pivot */
  742.             {
  743.                 (*compare) (g_phb_name_index[++i], pivot, &same_count, &distance);
  744.             }
  745.             while (distance < 0);
  746.             do  /* --j > pivot */
  747.             {
  748.                 (*compare) (g_phb_name_index[--j], pivot, &same_count, &distance);
  749.             }
  750.             while (distance > 0);
  751.             if (j < i)
  752.             {
  753.                 break;
  754.             }
  755.             mmi_phb_sort_name_swap(i, j);
  756.         }
  757.         mmi_phb_sort_name_swap(i, (U16) (right - 1));
  758.         mmi_phb_sort_name_quicksort(left, j, compare);
  759.         mmi_phb_sort_name_quicksort((U16) (i + 1), right, compare);
  760.     }
  761. }   /* end of phb_quicksort */
  762. /*****************************************************************************
  763.  * FUNCTION
  764.  *  mmi_phb_sort_name_insertionsort
  765.  * DESCRIPTION
  766.  *  This function is just for template.
  767.  * PARAMETERS
  768.  *  low         [IN]            
  769.  *  high        [IN]            
  770.  *  compare     [IN]            
  771.  *  a(?)        [IN/OUT]        First variable, used as returns
  772.  *  b(?)        [IN]            Second variable
  773.  * RETURNS
  774.  *  the description of return value, if any.(?)
  775.  *****************************************************************************/
  776. void mmi_phb_sort_name_insertionsort(U16 low, U16 high, phb_comp_func compare)
  777. {
  778.     /*----------------------------------------------------------------*/
  779.     /* Local Variables                                                */
  780.     /*----------------------------------------------------------------*/
  781.     U16 i;
  782.     U16 j;
  783.     U16 pivot;
  784.     S32 distance;
  785.     U8 same_count;
  786.     /*----------------------------------------------------------------*/
  787.     /* Code Body                                                      */
  788.     /*----------------------------------------------------------------*/
  789.     ASSERT(compare != NULL);
  790.     for (i = low + 1; i <= high; ++i)
  791.     {
  792.         pivot = g_phb_name_index[i];
  793.         j = i;
  794.         while (j > low)
  795.         {
  796.             (*compare) (g_phb_name_index[j - 1], pivot, &same_count, &distance);
  797.             if (distance <= 0)
  798.             {
  799.                 break;
  800.             }
  801.             g_phb_name_index[j] = g_phb_name_index[j - 1];
  802.             j--;
  803.         }
  804.         g_phb_name_index[j] = pivot;
  805.     }
  806. }   /* end of phb_insertion_sort */
  807. /*****************************************************************************
  808.  * FUNCTION
  809.  *  mmi_phb_sort_name_swap
  810.  * DESCRIPTION
  811.  *  This function is just for template.
  812.  * PARAMETERS
  813.  *  a       [IN/OUT]        First variable, used as returns
  814.  *  b       [IN]            Second variable
  815.  * RETURNS
  816.  *  the description of return value, if any.(?)
  817.  *****************************************************************************/
  818. void mmi_phb_sort_name_swap(U16 a, U16 b)
  819. {
  820.     /*----------------------------------------------------------------*/
  821.     /* Local Variables                                                */
  822.     /*----------------------------------------------------------------*/
  823.     U16 tmp;
  824.     /*----------------------------------------------------------------*/
  825.     /* Code Body                                                      */
  826.     /*----------------------------------------------------------------*/
  827.     tmp = g_phb_name_index[a];
  828.     g_phb_name_index[a] = g_phb_name_index[b];
  829.     g_phb_name_index[b] = tmp;
  830. }
  831. #define MMI_PHB_SEARCH_NAME
  832. /*****************************************************************************
  833.  * FUNCTION
  834.  *  mmi_phb_highlight_search_name
  835.  * DESCRIPTION
  836.  *  Highlight handler for "Search Entry" in PHB main menu
  837.  * PARAMETERS
  838.  *  void
  839.  * RETURNS
  840.  *  void
  841.  *****************************************************************************/
  842. void mmi_phb_highlight_search_name(void)
  843. {
  844.     /*----------------------------------------------------------------*/
  845.     /* Local Variables                                                */
  846.     /*----------------------------------------------------------------*/
  847.     /*----------------------------------------------------------------*/
  848.     /* Code Body                                                      */
  849.     /*----------------------------------------------------------------*/
  850.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_highlight_search_name.>n", __FILE__,
  851.                          __LINE__));
  852.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  853.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  854.     SetLeftSoftkeyFunction(mmi_phb_search_name_pre_entry, KEY_EVENT_UP);
  855.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  856.     SetKeyHandler(mmi_phb_search_name_pre_entry, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  857.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  858.     phbListView = MMI_PHB_LIST_FOR_PHB;
  859. }
  860. /*****************************************************************************
  861.  * FUNCTION
  862.  *  mmi_phb_highlight_search_name_option_search
  863.  * DESCRIPTION
  864.  *  Highlight handler for "Search" in Search Option menu
  865.  * PARAMETERS
  866.  *  void
  867.  * RETURNS
  868.  *  void
  869.  *****************************************************************************/
  870. void mmi_phb_highlight_search_name_option_search(void)
  871. {
  872.     /*----------------------------------------------------------------*/
  873.     /* Local Variables                                                */
  874.     /*----------------------------------------------------------------*/
  875.     /*----------------------------------------------------------------*/
  876.     /* Code Body                                                      */
  877.     /*----------------------------------------------------------------*/
  878.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_highlight_search_name_option_search.>n",
  879.                          __FILE__, __LINE__));
  880.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  881.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  882.     SetLeftSoftkeyFunction(mmi_phb_search_name, KEY_EVENT_UP);
  883.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  884.     SetKeyHandler(mmi_phb_search_name, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  885.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  886. }
  887. /*****************************************************************************
  888.  * FUNCTION
  889.  *  mmi_phb_highlight_search_name_option_input_method
  890.  * DESCRIPTION
  891.  *  Highlight handler for "Input Method" in Search Option menu
  892.  * PARAMETERS
  893.  *  void
  894.  * RETURNS
  895.  *  void
  896.  *****************************************************************************/
  897. void mmi_phb_highlight_search_name_option_input_method(void)
  898. {
  899.     /*----------------------------------------------------------------*/
  900.     /* Local Variables                                                */
  901.     /*----------------------------------------------------------------*/
  902.     /*----------------------------------------------------------------*/
  903.     /* Code Body                                                      */
  904.     /*----------------------------------------------------------------*/
  905.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB,
  906.                          "File: [%s]  Line: [%d] <<mmi_phb_highlight_search_name_option_input_method.>n", __FILE__,
  907.                          __LINE__));
  908.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  909.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  910.     SetInputMethodAndDoneCaptionIcon(IMG_SCR_PBOOK_CAPTION);
  911.     SetLeftSoftkeyFunction(EntryInputMethodScreen, KEY_EVENT_UP);
  912.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  913.     SetKeyHandler(EntryInputMethodScreen, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  914.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  915. }
  916. /*****************************************************************************
  917.  * FUNCTION
  918.  *  mmi_phb_search_name_pre_entry
  919.  * DESCRIPTION
  920.  *  Calls mmi_phb_entry_search_name() after few checks
  921.  * PARAMETERS
  922.  *  void
  923.  * RETURNS
  924.  *  void
  925.  *****************************************************************************/
  926. void mmi_phb_search_name_pre_entry(void)
  927. {
  928.     /*----------------------------------------------------------------*/
  929.     /* Local Variables                                                */
  930.     /*----------------------------------------------------------------*/
  931.     /*----------------------------------------------------------------*/
  932.     /* Code Body                                                      */
  933.     /*----------------------------------------------------------------*/
  934.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_search_name_pre_entry.>n", __FILE__,
  935.                          __LINE__));
  936. #ifdef __SYNCML_SUPPORT__
  937.     if (mmi_syncml_is_phb_sync_now())
  938.     {
  939.         mmi_phb_entry_not_ready(STR_ID_SYNC_PLEASE_WAIT);
  940.     }
  941.     else
  942. #endif /* __SYNCML_SUPPORT__ */
  943.     if (g_phb_cntx.phb_ready && !g_phb_cntx.processing)
  944.     {
  945.         memset(pbName, 0, ENCODING_LENGTH);
  946.         if (PhoneBookEntryCount)
  947.         {
  948.             mmi_phb_entry_search_name();
  949.         }
  950.         else
  951.         {
  952.             DisplayPopup(
  953.                 (PU8) GetString(STR_NO_ENTRIES_MESSAGE),
  954.                 IMG_GLOBAL_EMPTY,
  955.                 TRUE,
  956.                 PHB_NOTIFY_TIMEOUT,
  957.                 EMPTY_LIST_TONE);
  958.         }
  959.     }
  960.     else
  961.     {
  962.         mmi_phb_entry_not_ready(STR_PROCESSING_PHONEBOOK);
  963.     }
  964. }
  965. /*****************************************************************************
  966.  * FUNCTION
  967.  *  mmi_phb_entry_search_name
  968.  * DESCRIPTION
  969.  *  Gets name input from user
  970.  * PARAMETERS
  971.  *  void
  972.  * RETURNS
  973.  *  void
  974.  *****************************************************************************/
  975. void mmi_phb_entry_search_name(void)
  976. {
  977.     /*----------------------------------------------------------------*/
  978.     /* Local Variables                                                */
  979.     /*----------------------------------------------------------------*/
  980.     U8 *guiBuffer;
  981.     S8 state;
  982.     /*----------------------------------------------------------------*/
  983.     /* Code Body                                                      */
  984.     /*----------------------------------------------------------------*/
  985.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_entry_search_name.>n", __FILE__,
  986.                          __LINE__));
  987.     EntryNewScreen(SCR_SEARCH_NAME_ENTRY, mmi_phb_exit_search_name, NULL, NULL);
  988.     guiBuffer = GetCurrGuiBuffer(SCR_SEARCH_NAME_ENTRY);
  989.     if (guiBuffer != NULL)
  990.     {
  991.         state = get_multiline_inputbox_category_history_state(SCR_SEARCH_NAME_ENTRY, guiBuffer);
  992.         if (state != -1)
  993.         {
  994.             phbListView = (U8) state;
  995.         }
  996.     }
  997. #if defined UI_SMALL_CATEGORY_EDITOR
  998.     enable_resized_small_screen();
  999. #endif 
  1000.     ShowCategory5Screen_ext(
  1001.         STR_SCR_SEARCH_NAME_CAPTION,
  1002.         IMG_SCR_PBOOK_CAPTION,
  1003.         STR_GLOBAL_OPTIONS,
  1004.         IMG_GLOBAL_OPTIONS,
  1005.         STR_GLOBAL_BACK,
  1006.         IMG_GLOBAL_BACK,
  1007.         (INPUT_TYPE_ALPHANUMERIC_UPPERCASE | INPUT_TYPE_USE_ENCODING_BASED_LENGTH | INPUT_TYPE_ONE_LESS_CHARACTER),
  1008.         (PU8) pbName,
  1009.         MAX_SEARCH_NAME_LENGTH + 1,
  1010.         guiBuffer,
  1011.         INPUT_TYPE_EXT_NO_SHOW_NEW_LINE_SYMBOL,
  1012.         NULL,
  1013.         NULL);
  1014.     SetLeftSoftkeyFunction(mmi_phb_entry_search_name_option, KEY_EVENT_UP);
  1015.     SetCategory5RightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1016.     SetKeyHandler(mmi_phb_search_name, KEY_SEND, KEY_EVENT_UP);
  1017. }
  1018. /*****************************************************************************
  1019.  * FUNCTION
  1020.  *  mmi_phb_exit_search_name
  1021.  * DESCRIPTION
  1022.  *  Exit function for mmi_phb_entry_search_name()
  1023.  * PARAMETERS
  1024.  *  void
  1025.  * RETURNS
  1026.  *  void
  1027.  *****************************************************************************/
  1028. void mmi_phb_exit_search_name(void)
  1029. {
  1030.     /*----------------------------------------------------------------*/
  1031.     /* Local Variables                                                */
  1032.     /*----------------------------------------------------------------*/
  1033.     history h;
  1034.     S8 state = (S8) phbListView;
  1035.     /*----------------------------------------------------------------*/
  1036.     /* Code Body                                                      */
  1037.     /*----------------------------------------------------------------*/
  1038.     if (g_phb_cntx.start_scr_id == 0)   /* start from Shortcut */
  1039.     {
  1040.         g_phb_cntx.start_scr_id = GetCurrScrnId();
  1041.     }
  1042.     g_phb_cntx.end_scr_id = SCR_SEARCH_NAME_ENTRY;
  1043.     h.scrnID = SCR_SEARCH_NAME_ENTRY;
  1044.     h.entryFuncPtr = mmi_phb_entry_search_name;
  1045.     pfnUnicodeStrcpy((S8*) h.inputBuffer, (S8*) pbName);
  1046.     GetCategoryHistory(h.guiBuffer);
  1047.     set_multiline_inputbox_category_history_state(SCR_SEARCH_NAME_ENTRY, h.guiBuffer, state);
  1048.     AddHistory(h);
  1049. }
  1050. /*****************************************************************************
  1051.  * FUNCTION
  1052.  *  mmi_phb_entry_search_name_option
  1053.  * DESCRIPTION
  1054.  *  Draws the Search Options menu
  1055.  * PARAMETERS
  1056.  *  void
  1057.  * RETURNS
  1058.  *  void
  1059.  *****************************************************************************/
  1060. void mmi_phb_entry_search_name_option(void)
  1061. {
  1062.     /*----------------------------------------------------------------*/
  1063.     /* Local Variables                                                */
  1064.     /*----------------------------------------------------------------*/
  1065.     U8 *guiBuffer;
  1066.     U16 nStrItemList[2];
  1067.     U16 nNumofItem;
  1068.     S8 state;
  1069.     /*----------------------------------------------------------------*/
  1070.     /* Code Body                                                      */
  1071.     /*----------------------------------------------------------------*/
  1072.     PRINT_INFORMATION_2((MMI_TRACE_G4_PHB, "File: [%s]  Line: [%d] <<mmi_phb_entry_search_name_option.>n", __FILE__,
  1073.                          __LINE__));
  1074.     EntryNewScreen(SCR_SEARCH_OPTIONS, mmi_phb_exit_search_name_option, NULL, NULL);
  1075.     guiBuffer = GetCurrGuiBuffer(SCR_SEARCH_OPTIONS);
  1076.     if (guiBuffer != NULL)
  1077.     {
  1078.         state = get_list_menu_category_history_state(SCR_PBOOK_LIST, guiBuffer);
  1079.         if (state != -1)
  1080.         {
  1081.             phbListView = (U8) state;   /* Restore State in history. */
  1082.         }
  1083.     }
  1084.     nNumofItem = GetNumOfChild(MITEM101_SEARCH_OPTIONS);
  1085.     GetSequenceStringIds(MITEM101_SEARCH_OPTIONS, nStrItemList);
  1086.     SetParentHandler(MITEM101_SEARCH_OPTIONS);
  1087.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  1088.     ShowCategory15Screen(
  1089.         STR_GLOBAL_OPTIONS,
  1090.         IMG_SCR_PBOOK_CAPTION,
  1091.         STR_GLOBAL_OK,
  1092.         IMG_GLOBAL_OK,
  1093.         STR_GLOBAL_BACK,
  1094.         IMG_GLOBAL_BACK,
  1095.         nNumofItem,
  1096.         nStrItemList,
  1097.         (U16*) gIndexIconsImageList,
  1098.         LIST_MENU,
  1099.         0,
  1100.         guiBuffer);
  1101.     RegisterInputMethodScreenCloseFunction(mmi_phb_go_back_2_history);
  1102.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1103. }
  1104. /*****************************************************************************
  1105.  * FUNCTION
  1106.  *  mmi_phb_exit_search_name_option
  1107.  * DESCRIPTION
  1108.  *  Exit function for mmi_phb_entry_search_name_option()
  1109.  * PARAMETERS
  1110.  *  void
  1111.  * RETURNS
  1112.  *  void
  1113.  *****************************************************************************/
  1114. void mmi_phb_exit_search_name_option(void)
  1115. {
  1116.     /*----------------------------------------------------------------*/
  1117.     /* Local Variables                                                */
  1118.     /*----------------------------------------------------------------*/
  1119.     history h;
  1120.     S16 nHistory = 0;
  1121.     S8 state = (S8) phbListView;
  1122.     /*----------------------------------------------------------------*/
  1123.     /* Code Body                                                      */
  1124.     /*----------------------------------------------------------------*/
  1125.     g_phb_cntx.end_scr_id = SCR_SEARCH_OPTIONS;
  1126.     h.scrnID = SCR_SEARCH_OPTIONS;
  1127.     h.entryFuncPtr = mmi_phb_entry_search_name_option;
  1128.     pfnUnicodeStrcpy((S8*) h.inputBuffer, (S8*) & nHistory);
  1129.     GetCategoryHistory(h.guiBuffer);
  1130.     set_list_menu_category_history_state(SCR_PBOOK_LIST, h.guiBuffer, state);   /* Keep State in history. */
  1131.     AddHistory(h);
  1132. }
  1133. /*****************************************************************************
  1134.  * FUNCTION
  1135.  *  mmi_phb_search_name
  1136.  * DESCRIPTION
  1137.  *  This function is just for template.
  1138.  * PARAMETERS
  1139.  *  void
  1140.  *  a(?)        [IN/OUT]        First variable, used as returns
  1141.  *  b(?)        [IN]            Second variable
  1142.  * RETURNS
  1143.  *  the description of return value, if any.(?)
  1144.  *****************************************************************************/
  1145. void mmi_phb_search_name(void)
  1146. {
  1147.     /*----------------------------------------------------------------*/
  1148.     /* Local Variables                                                */
  1149.     /*----------------------------------------------------------------*/
  1150.     /*----------------------------------------------------------------*/
  1151.     /* Code Body                                                      */
  1152.     /*----------------------------------------------------------------*/
  1153.     g_phb_cntx.highlight_entry = mmi_phb_search_name_find_closet();
  1154.     if (phbListView == MMI_PHB_LIST_FOR_PHB)
  1155.     {
  1156.         mmi_phb_list_pre_entry();   /* Dynamic List */
  1157.     }
  1158.     else if ((phbListView == MMI_PHB_LIST_FOR_SMS) || (phbListView == MMI_PHB_LIST_FOR_SMS_SEARCH_NAME))
  1159.     {
  1160.         mmi_phb_list_pre_entry_second_level();
  1161.     }
  1162.     DeleteNScrId(SCR_SEARCH_NAME_ENTRY);
  1163.     /* Not Found, Not Possible, will return closet entry */
  1164.     //   DisplayPopup((PU8)GetString(STR_NOENTRY_FOUND_MSG), IMG_GLOBAL_WARNING, FALSE, PHB_NOTIFY_TIMEOUT, WARNING_TONE);
  1165.     //   DeleteNScrId(SCR_SEARCH_NAME_ENTRY);
  1166. }
  1167. /*****************************************************************************
  1168.  * FUNCTION
  1169.  *  mmi_phb_search_name_find_closet
  1170.  * DESCRIPTION
  1171.  *  This function is just for template.
  1172.  * PARAMETERS
  1173.  *  void
  1174.  *  a(?)        [IN/OUT]        First variable, used as returns
  1175.  *  b(?)        [IN]            Second variable
  1176.  * RETURNS
  1177.  *  the description of return value, if any.
  1178.  *****************************************************************************/
  1179. U16 mmi_phb_search_name_find_closet(void)
  1180. {
  1181.     /*----------------------------------------------------------------*/
  1182.     /* Local Variables                                                */
  1183.     /*----------------------------------------------------------------*/
  1184.     U16 result_index;
  1185.     /*----------------------------------------------------------------*/
  1186.     /* Code Body                                                      */
  1187.     /*----------------------------------------------------------------*/
  1188.     if (pfnUnicodeStrlen((S8*) pbName) == 0)
  1189.     {
  1190.         return 0;
  1191.     }
  1192.     result_index = mmi_phb_search_name_binary_search(0, (PhoneBookEntryCount - 1), (S8*) pbName);
  1193.     /* Check boundary */
  1194.     if (result_index >= PhoneBookEntryCount)
  1195.     {
  1196.         result_index = PhoneBookEntryCount - 1;
  1197.     }
  1198.     return result_index;
  1199. }
  1200. /*****************************************************************************
  1201.  * FUNCTION
  1202.  *  mmi_phb_search_name_binary_search
  1203.  * DESCRIPTION
  1204.  *  This function is just for template.
  1205.  * PARAMETERS
  1206.  *  low             [IN]            
  1207.  *  high            [IN]            
  1208.  *  ucs2_name       [?]             
  1209.  *  a(?)            [IN/OUT]        First variable, used as returns
  1210.  *  b(?)            [IN]            Second variable
  1211.  * RETURNS
  1212.  *  the description of return value, if any.
  1213.  *****************************************************************************/
  1214. U16 mmi_phb_search_name_binary_search(S32 low, S32 high, S8 *ucs2_name)
  1215. {
  1216.     /*----------------------------------------------------------------*/
  1217.     /* Local Variables                                                */
  1218.     /*----------------------------------------------------------------*/
  1219.     S32 mid = 0;
  1220.     S16 flag = 0;
  1221.     U8 same_count;
  1222.     S32 distance;
  1223.     U16 index;
  1224.     S8 *string;
  1225.     S8 number[(MAX_PB_NUMBER_LENGTH + 1 + 1) * ENCODING_LENGTH];
  1226. #if defined(__MMI_PHB_PINYIN_SORT__)
  1227.     S8 buffer1[(MMI_PHB_SORT_LENGTH + 1) * ENCODING_LENGTH];
  1228.     S8 buffer2[(MMI_PHB_SORT_LENGTH + 1) * ENCODING_LENGTH];
  1229.     U16 count;
  1230.     /*----------------------------------------------------------------*/
  1231.     /* Code Body                                                      */
  1232.     /*----------------------------------------------------------------*/
  1233.     if (GetUCS2Flag(ucs2_name))
  1234.     {
  1235.         count = mmi_phb_util_convert_to_pinyin((U8*) ucs2_name, (U8*) buffer1, (MMI_PHB_SORT_LENGTH * ENCODING_LENGTH));
  1236.         buffer1[count++] = 0x00;
  1237.         buffer1[count] = 0x00;
  1238.         ucs2_name = (S8*) buffer1;
  1239.     }
  1240. #endif /* defined(__MMI_PHB_PINYIN_SORT__) */ 
  1241.     /*
  1242.      * Use binary search to find nearest name.
  1243.      */
  1244.     while (low <= high)
  1245.     {
  1246.         mid = (low + high) / 2;
  1247.         /*
  1248.          * Prepare entry data to compare
  1249.          */
  1250.         index = g_phb_name_index[mid];
  1251.     #if defined(__MMI_PHB_PINYIN_SORT__)
  1252.         if (PhoneBook[index].alpha_id.name_dcs == MMI_PHB_ASCII)
  1253.         {
  1254.             string = (S8*) PhoneBook[index].alpha_id.name;
  1255.         }
  1256.         else
  1257.         {
  1258.             count = mmi_phb_util_convert_to_pinyin(
  1259.                         PhoneBook[index].alpha_id.name,
  1260.                         (U8*) buffer2,
  1261.                         (MMI_PHB_SORT_LENGTH * ENCODING_LENGTH));
  1262.             buffer2[count++] = 0x00;
  1263.             buffer2[count] = 0x00;
  1264.             string = (S8*) buffer2;
  1265.         }
  1266.     #else /* defined(__MMI_PHB_PINYIN_SORT__) */ 
  1267.         string = (S8*) PhoneBook[index].alpha_id.name;
  1268.     #endif /* defined(__MMI_PHB_PINYIN_SORT__) */ 
  1269.         /*
  1270.          * Use number to compare if name is empty
  1271.          */
  1272.         if (pfnUnicodeStrlen(string) == 0)
  1273.         {
  1274.             mmi_phb_convert_get_ucs2_number(number, index);
  1275.             string = (S8*) number;
  1276.         }
  1277.         /*
  1278.          * Compare search pattern with entry
  1279.          */
  1280.         mmi_phb_compare_ucs2_strings(ucs2_name, string, &same_count, &distance);
  1281.         if (distance > 0)
  1282.         {
  1283.             low = mid + 1;
  1284.             flag = -1;
  1285.         }
  1286.         /*
  1287.          * Distance == 0 or < 0 here
  1288.          * If there are duplicate entry, this will help to move up until first entry.
  1289.          */
  1290.         else
  1291.         {
  1292.             high = mid - 1;
  1293.             flag = 1;
  1294.         }
  1295.     }
  1296.     if (flag == -1)
  1297.     {
  1298.         return (U16) (mid + 1);
  1299.     }
  1300.     else
  1301.     {
  1302.         return (U16) mid;
  1303.     }
  1304. }
  1305. #define MMI_PHB_QUICKSEARCH
  1306. #if defined(__MMI_PHB_QUICK_SEARCH__) || defined(MMI_ON_WIN32)
  1307. /*****************************************************************************
  1308.  * FUNCTION
  1309.  *  mmi_phb_highlight_quick_search_list
  1310.  * DESCRIPTION
  1311.  *  
  1312.  * PARAMETERS
  1313.  *  void
  1314.  * RETURNS
  1315.  *  void
  1316.  *****************************************************************************/
  1317. void mmi_phb_highlight_quick_search_list(void)
  1318. {
  1319.     /*----------------------------------------------------------------*/
  1320.     /* Local Variables                                                */
  1321.     /*----------------------------------------------------------------*/
  1322.     /*----------------------------------------------------------------*/
  1323.     /* Code Body                                                      */
  1324.     /*----------------------------------------------------------------*/
  1325.     ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
  1326.     ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
  1327. #if defined(MMI_ON_WIN32)
  1328.     SetLeftSoftkeyFunction(PopupNoSupport, KEY_EVENT_UP);
  1329.     SetKeyHandler(PopupNoSupport, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1330. #else
  1331.     SetLeftSoftkeyFunction(mmi_phb_quick_search_list_pre_entry, KEY_EVENT_UP);
  1332.     SetKeyHandler(mmi_phb_quick_search_list_pre_entry, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  1333. #endif /* MMI_ON_WIN32 */
  1334.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1335.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1336. }
  1337. #endif /* defined(__MMI_PHB_QUICK_SEARCH__) || defined(MMI_ON_WIN32) */
  1338. #if defined(__MMI_PHB_QUICK_SEARCH__)
  1339. #if defined(__MMI_T9__) && (defined(__MMI_LANG_TR_CHINESE__) || defined(__MMI_LANG_SM_CHINESE__))
  1340. #if defined(__MMI_T9_V7__)
  1341. /*****************************************************************************
  1342.  * FUNCTION
  1343.  *  mmi_phb_quick_search_convert_to_spelling
  1344.  * DESCRIPTION
  1345.  *  This function is just for template.
  1346.  * PARAMETERS
  1347.  *  input_string        [?]             
  1348.  *  output_string       [?]             
  1349.  *  out_len             [?]             
  1350.  *  a(?)                [IN/OUT]        First variable, used as returns
  1351.  *  b(?)                [IN]            Second variable
  1352.  * RETURNS
  1353.  *  the description of return value, if any.
  1354.  *****************************************************************************/
  1355. BOOL mmi_phb_quick_search_convert_to_spelling(U8 *input_string, U8 *output_string, U8 *out_len)
  1356. {
  1357.     /*----------------------------------------------------------------*/
  1358.     /* Local Variables                                                */
  1359.     /*----------------------------------------------------------------*/
  1360.     S8 out = 0;
  1361.     U8 i = 0;
  1362.     T9STATUS t9ReturnCodes;
  1363.     /*----------------------------------------------------------------*/
  1364.     /* Code Body                                                      */
  1365.     /*----------------------------------------------------------------*/
  1366.     /* Should already switch to the proper input language in "mmi_phb_quick_search_convert_cache()". */
  1367.     if (input_string[0] != 0 || input_string[1] != 0)
  1368.     {
  1369.         if (MMI_current_input_mode == INPUT_MODE_MMI_SM_STROKE || MMI_current_input_mode == INPUT_MODE_MMI_TR_STROKE)
  1370.         {
  1371.             t9ReturnCodes = T9CCGetCharStrokes(&FieldInfo.CCFieldInfo, (U16*) input_string, 0);
  1372.         }
  1373.         else
  1374.         {
  1375.             t9ReturnCodes = T9CCGetCharSpell(&FieldInfo.CCFieldInfo, (U16*) input_string, 0);
  1376.         }
  1377.         if (t9ReturnCodes == 0)
  1378.         {
  1379.             switch (MMI_current_input_mode)
  1380.             {
  1381.                 case INPUT_MODE_MMI_MULTITAP_BPMF:
  1382.                     while ((FieldInfo.CCFieldInfo.pbSpellBuf[i] != 0x00) && (i <= 7))
  1383.                     {
  1384.                         *((U16*) (output_string + out)) = BPMFInternalToUnicode(FieldInfo.CCFieldInfo.pbSpellBuf[i]);
  1385.                         out = out + 2;
  1386.                         i = i + 1;
  1387.                     }
  1388.                     break;
  1389.                 case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1390.                     while ((FieldInfo.CCFieldInfo.pbSpellBuf[i] != 0x00) && (i <= 7))
  1391.                     {
  1392.                         output_string[out] = FieldInfo.CCFieldInfo.pbSpellBuf[i];
  1393.                         output_string[out + 1] = 0;
  1394.                         out = out + 2;
  1395.                         i = i + 1;
  1396.                     }
  1397.                     break;
  1398.                 case INPUT_MODE_MMI_SM_STROKE:
  1399.                 case INPUT_MODE_MMI_TR_STROKE:
  1400.                     while ((FieldInfo.CCFieldInfo.pbKeyBuf[i] != 0x00) &&
  1401.                            (i < FieldInfo.CCFieldInfo.nKeyBufLen) && (i <= 7))
  1402.                     {
  1403.                         *((U16*) (output_string + out)) = StrokeInternalToUnicode(FieldInfo.CCFieldInfo.pbKeyBuf[i]);
  1404.                         out = out + 2;
  1405.                         i = i + 1;
  1406.                     }
  1407.                     break;
  1408.                 default:
  1409.                     break;
  1410.             }
  1411.             *out_len = i;
  1412.             return TRUE;
  1413.         }
  1414.         /* Input String Does not Converted. */
  1415.         memcpy(output_string, input_string, 2);
  1416.         *out_len = 1;
  1417.         return TRUE;
  1418.     }
  1419.     *out_len = 0;
  1420.     return FALSE;
  1421. }
  1422. /*****************************************************************************
  1423.  * FUNCTION
  1424.  *  mmi_phb_quick_search_convert_cache
  1425.  * DESCRIPTION
  1426.  *  This function convert first character of name field into cache.
  1427.  * PARAMETERS
  1428.  *  index       [IN]        Phonebook entry index
  1429.  * RETURNS
  1430.  *  void
  1431.  *****************************************************************************/
  1432. void mmi_phb_quick_search_convert_cache(U16 index)
  1433. {
  1434.     /*----------------------------------------------------------------*/
  1435.     /* Local Variables                                                */
  1436.     /*----------------------------------------------------------------*/
  1437.     T9STATUS t9ReturnCodes;
  1438.     /*----------------------------------------------------------------*/
  1439.     /* Code Body                                                      */
  1440.     /*----------------------------------------------------------------*/
  1441.     /* move change language function out from loop to speed up */
  1442.     if (MMI_current_input_mode == INPUT_MODE_MMI_SM_STROKE || MMI_current_input_mode == INPUT_MODE_MMI_TR_STROKE)
  1443.     {
  1444.         t9ReturnCodes = T9CCGetCharStrokes(&FieldInfo.CCFieldInfo, (U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name, 0);
  1445.     }
  1446.     else
  1447.     {
  1448.         t9ReturnCodes = T9CCGetCharSpell(&FieldInfo.CCFieldInfo, (U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name, 0);
  1449.     }
  1450.     if (t9ReturnCodes == 0)
  1451.     {
  1452.         switch (MMI_current_input_mode)
  1453.         {
  1454.             case INPUT_MODE_MMI_MULTITAP_BPMF:
  1455.                 g_phb_qsearch_cache[index] = BPMFInternalToUnicode(FieldInfo.CCFieldInfo.pbSpellBuf[0]);
  1456.                 break;
  1457.             case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1458.                 g_phb_qsearch_cache[index] = FieldInfo.CCFieldInfo.pbSpellBuf[0];
  1459.                 break;
  1460.             case INPUT_MODE_MMI_SM_STROKE:
  1461.             case INPUT_MODE_MMI_TR_STROKE:
  1462.                 g_phb_qsearch_cache[index] = StrokeInternalToUnicode(FieldInfo.CCFieldInfo.pbKeyBuf[0]);
  1463.                 break;
  1464.             default:
  1465.                 g_phb_qsearch_cache[index] = *((U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name);
  1466.                 break;
  1467.         }
  1468.     }
  1469.     else
  1470.     {
  1471.         g_phb_qsearch_cache[index] = *((U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name);
  1472.     }
  1473. }
  1474. #else /* defined(__MMI_T9_V7__) */ 
  1475. /*****************************************************************************
  1476.  * FUNCTION
  1477.  *  mmi_phb_quick_search_convert_to_spelling
  1478.  * DESCRIPTION
  1479.  *  This function is just for template.
  1480.  * PARAMETERS
  1481.  *  input_string        [?]             
  1482.  *  output_string       [?]             
  1483.  *  out_len             [?]             
  1484.  *  a(?)                [IN/OUT]        First variable, used as returns
  1485.  *  b(?)                [IN]            Second variable
  1486.  * RETURNS
  1487.  *  the description of return value, if any.
  1488.  *****************************************************************************/
  1489. BOOL mmi_phb_quick_search_convert_to_spelling(U8 *input_string, U8 *output_string, U8 *out_len)
  1490. {
  1491.     /*----------------------------------------------------------------*/
  1492.     /* Local Variables                                                */
  1493.     /*----------------------------------------------------------------*/
  1494.     S8 out = 0;
  1495.     U8 i = 0;
  1496.     T9Event t9EventInput;
  1497.     T9STATUS t9ReturnCodes;
  1498.     /*----------------------------------------------------------------*/
  1499.     /* Code Body                                                      */
  1500.     /*----------------------------------------------------------------*/
  1501.     /* Should already switch to the proper input language in "mmi_phb_quick_search_convert_cache()". */
  1502.     if (input_string[0] != 0 || input_string[1] != 0)
  1503.     {
  1504.         if (MMI_current_input_mode == INPUT_MODE_MMI_SM_STROKE || MMI_current_input_mode == INPUT_MODE_MMI_TR_STROKE)
  1505.         {
  1506.             t9EventInput.mType = T9EVTSTROKES;
  1507.         }
  1508.         else
  1509.         {
  1510.             t9EventInput.mType = T9EVTSPELLING;
  1511.         }
  1512.         t9EventInput.data.sLDBData.psBuf = (U16*) input_string;
  1513.         t9EventInput.data.sLDBData.mCtrlID = 0;
  1514.         t9ReturnCodes = T9HandleEvent(&FieldInfo, &t9EventInput);
  1515.         if (t9ReturnCodes == 0)
  1516.         {
  1517.             switch (MMI_current_input_mode)
  1518.             {
  1519.                 case INPUT_MODE_MMI_MULTITAP_BPMF:
  1520.                     while ((FieldInfo.uLangData.pAuxChinese->pbSpellBuf[i] != 0x00) && (i <= 7))
  1521.                     {
  1522.                         *((U16*) (output_string + out)) = BPMFInternalToUnicode(FieldInfo.uLangData.pAuxChinese->pbSpellBuf[i]);
  1523.                         out = out + 2;
  1524.                         i = i + 1;
  1525.                     }
  1526.                     break;
  1527.                 case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1528.                     while ((FieldInfo.uLangData.pAuxChinese->pbSpellBuf[i] != 0x00) && (i <= 7))
  1529.                     {
  1530.                         output_string[out] = FieldInfo.uLangData.pAuxChinese->pbSpellBuf[i];
  1531.                         output_string[out + 1] = 0;
  1532.                         out = out + 2;
  1533.                         i = i + 1;
  1534.                     }
  1535.                     break;
  1536.                 case INPUT_MODE_MMI_SM_STROKE:
  1537.                 case INPUT_MODE_MMI_TR_STROKE:
  1538.                     while ((FieldInfo.uLangData.pAuxChinese->pbKeyBuf[i] != 0x00) &&
  1539.                            (i < FieldInfo.uLangData.pAuxChinese->nKeyBufLen) && (i <= 7))
  1540.                     {
  1541.                         *((U16*) (output_string + out)) = StrokeInternalToUnicode(FieldInfo.uLangData.pAuxChinese->pbKeyBuf[i]);
  1542.                         out = out + 2;
  1543.                         i = i + 1;
  1544.                     }
  1545.                     break;
  1546.                 default:
  1547.                     break;
  1548.             }
  1549.             *out_len = i;
  1550.             return TRUE;
  1551.         }
  1552.         /* Input String Does not Converted. */
  1553.         memcpy(output_string, input_string, 2);
  1554.         *out_len = 1;
  1555.         return TRUE;
  1556.     }
  1557.     *out_len = 0;
  1558.     return FALSE;
  1559. }
  1560. /*****************************************************************************
  1561.  * FUNCTION
  1562.  *  mmi_phb_quick_search_convert_cache
  1563.  * DESCRIPTION
  1564.  *  This function convert first character of name field into cache.
  1565.  * PARAMETERS
  1566.  *  index       [IN]        Phonebook entry index
  1567.  * RETURNS
  1568.  *  void
  1569.  *****************************************************************************/
  1570. void mmi_phb_quick_search_convert_cache(U16 index)
  1571. {
  1572.     /*----------------------------------------------------------------*/
  1573.     /* Local Variables                                                */
  1574.     /*----------------------------------------------------------------*/
  1575.     T9Event t9EventInput;
  1576.     T9STATUS t9ReturnCodes;
  1577.     /*----------------------------------------------------------------*/
  1578.     /* Code Body                                                      */
  1579.     /*----------------------------------------------------------------*/
  1580.     /* move change language function out from loop to speed up */
  1581.     if (MMI_current_input_mode == INPUT_MODE_MMI_SM_STROKE || MMI_current_input_mode == INPUT_MODE_MMI_TR_STROKE)
  1582.     {
  1583.         t9EventInput.mType = T9EVTSTROKES;
  1584.     }
  1585.     else
  1586.     {
  1587.         t9EventInput.mType = T9EVTSPELLING;
  1588.     }
  1589.     t9EventInput.data.sLDBData.psBuf = (U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name;
  1590.     t9EventInput.data.sLDBData.mCtrlID = 0;
  1591.     t9ReturnCodes = T9HandleEvent(&FieldInfo, &t9EventInput);
  1592.     if (t9ReturnCodes == 0)
  1593.     {
  1594.         switch (MMI_current_input_mode)
  1595.         {
  1596.             case INPUT_MODE_MMI_MULTITAP_BPMF:
  1597.                 g_phb_qsearch_cache[index] = BPMFInternalToUnicode(FieldInfo.uLangData.pAuxChinese->pbSpellBuf[0]);
  1598.                 break;
  1599.             case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1600.                 g_phb_qsearch_cache[index] = FieldInfo.uLangData.pAuxChinese->pbSpellBuf[0];
  1601.                 break;
  1602.             case INPUT_MODE_MMI_SM_STROKE:
  1603.             case INPUT_MODE_MMI_TR_STROKE:
  1604.                 g_phb_qsearch_cache[index] = StrokeInternalToUnicode(FieldInfo.uLangData.pAuxChinese->pbKeyBuf[0]);
  1605.                 break;
  1606.             default:
  1607.                 g_phb_qsearch_cache[index] = *((U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name);
  1608.                 break;
  1609.         }
  1610.     }
  1611.     else
  1612.     {
  1613.         g_phb_qsearch_cache[index] = *((U16*) PhoneBook[g_phb_name_index[index]].alpha_id.name);
  1614.     }
  1615. }
  1616. #endif /* defined(__MMI_T9_V7__) */ 
  1617. #elif defined(__MMI_ZI__)
  1618. /*****************************************************************************
  1619.  * FUNCTION
  1620.  *  mmi_phb_quick_search_convert_to_spelling
  1621.  * DESCRIPTION
  1622.  *  This function is just for template.
  1623.  * PARAMETERS
  1624.  *  input_string        [?]             
  1625.  *  output_string       [?]             
  1626.  *  out_len             [?]             
  1627.  *  a(?)                [IN/OUT]        First variable, used as returns
  1628.  *  b(?)                [IN]            Second variable
  1629.  * RETURNS
  1630.  *  the description of return value, if any.
  1631.  *****************************************************************************/
  1632. BOOL mmi_phb_quick_search_convert_to_spelling(U8 *input_string, U8 *output_string, U8 *out_len)
  1633. {
  1634.     /*----------------------------------------------------------------*/
  1635.     /* Local Variables                                                */
  1636.     /*----------------------------------------------------------------*/
  1637.     S8 out = 0;
  1638.     U8 i = 0;
  1639.     U16 code;
  1640.     U16 mode;
  1641.     U16 pCharInfoBuffer[MMI_PHB_CONVERT_BUFF_ZI];
  1642.     U16 CharInfo;
  1643.     /*----------------------------------------------------------------*/
  1644.     /* Code Body                                                      */
  1645.     /*----------------------------------------------------------------*/
  1646.     /* Change convert mode according to input method. */
  1647.     switch (MMI_current_input_mode)
  1648.     {
  1649.         case INPUT_MODE_MMI_MULTITAP_BPMF:
  1650.             /* mode = ZI8_GETMODE_BOPOMOFO; */
  1651.             mode = ZI8_GETMODE_BOPOMOFO_NAME;
  1652.             break;
  1653.         case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1654.             /* mode = ZI8_GETMODE_PINYIN; */
  1655.             mode = ZI8_GETMODE_PINYIN_NAME;
  1656.             break;
  1657.         case INPUT_MODE_MMI_SM_STROKE:
  1658.         case INPUT_MODE_MMI_TR_STROKE:
  1659.             mode = ZI8_GETMODE_STROKES;
  1660.             break;
  1661.         default:
  1662.             return FALSE;
  1663.             break;
  1664.     }
  1665.     if (input_string[0] != 0 || input_string[1] != 0)
  1666.     {
  1667.         memcpy(&code, input_string, 2);
  1668.         if ((code >= 0x4e00) && (code <= 0x9fa5) &&
  1669.             Zi8GetCharInfo(code, (U16*) pCharInfoBuffer, MMI_PHB_CONVERT_BUFF_ZI, mode))
  1670.         {
  1671.             switch (MMI_current_input_mode)
  1672.             {
  1673.                 case INPUT_MODE_MMI_MULTITAP_BPMF:
  1674.                     /* Do not convert tone */
  1675.                     while ((pCharInfoBuffer[i] != 0x0000) &&
  1676.                            ((pCharInfoBuffer[i] < 0xf431) || (pCharInfoBuffer[i] > 0xf435)))
  1677.                     {
  1678.                         CharInfo = pCharInfoBuffer[i] - ZI8_BASE_BPMF + 0x3105;
  1679.                         memcpy(output_string + out, &CharInfo, 2);
  1680.                         out = out + 2;
  1681.                         i = i + 1;
  1682.                     }
  1683.                     break;
  1684.                 case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1685.                     /* Do not convert tone */
  1686.                     while ((pCharInfoBuffer[i] != 0x0000) &&
  1687.                            ((pCharInfoBuffer[i] < 0xf431) || (pCharInfoBuffer[i] > 0xf435)))
  1688.                     {
  1689.                         CharInfo = pCharInfoBuffer[i] - ZI8_BASE_PINYIN + 0x0061;
  1690.                         memcpy(output_string + out, &CharInfo, 2);
  1691.                         out = out + 2;
  1692.                         i = i + 1;
  1693.                     }
  1694.                     break;
  1695.                 case INPUT_MODE_MMI_SM_STROKE:
  1696.                 case INPUT_MODE_MMI_TR_STROKE:
  1697.                     while ((pCharInfoBuffer[i] != 0x0000) && (i <= 7))
  1698.                     {
  1699.                         memcpy(output_string + out, &pCharInfoBuffer[i], 2);
  1700.                         out = out + 2;
  1701.                         i = i + 1;
  1702.                     }
  1703.                     break;
  1704.                 default:
  1705.                     break;
  1706.             }
  1707.             *out_len = i;
  1708.             return TRUE;
  1709.         }
  1710.         memcpy(output_string, input_string, 2);
  1711.         *out_len = 1;
  1712.         return TRUE;
  1713.     }
  1714.     *out_len = 0;
  1715.     return FALSE;
  1716. }
  1717. /*****************************************************************************
  1718.  * FUNCTION
  1719.  *  mmi_phb_quick_search_convert_cache
  1720.  * DESCRIPTION
  1721.  *  This function convert first character of name field into cache.
  1722.  * PARAMETERS
  1723.  *  index       [IN]        Phonebook entry index
  1724.  * RETURNS
  1725.  *  void
  1726.  *****************************************************************************/
  1727. void mmi_phb_quick_search_convert_cache(U16 index)
  1728. {
  1729.     /*----------------------------------------------------------------*/
  1730.     /* Local Variables                                                */
  1731.     /*----------------------------------------------------------------*/
  1732.     U16 code;
  1733.     U16 mode;
  1734.     U16 pCharInfoBuffer[MMI_PHB_CONVERT_BUFF_ZI];
  1735.     /*----------------------------------------------------------------*/
  1736.     /* Code Body                                                      */
  1737.     /*----------------------------------------------------------------*/
  1738.     memcpy(&code, PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1739.     /* Change to proper input method. */
  1740.     switch (MMI_current_input_mode)
  1741.     {
  1742.         case INPUT_MODE_MMI_MULTITAP_BPMF:
  1743.             mode = ZI8_GETMODE_BOPOMOFO;
  1744.             break;
  1745.         case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1746.             mode = ZI8_GETMODE_PINYIN;
  1747.             break;
  1748.         case INPUT_MODE_MMI_SM_STROKE:
  1749.         case INPUT_MODE_MMI_TR_STROKE:
  1750.             mode = ZI8_GETMODE_STROKES;
  1751.             break;
  1752.         default:
  1753.             memcpy(&g_phb_qsearch_cache[index], PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1754.             return;
  1755.     }
  1756.     /* Begin to convert and store the result according to the input method. */
  1757.     if ((code >= 0x4e00) && (code <= 0x9fa5) &&
  1758.         Zi8GetCharInfo(code, (U16*) pCharInfoBuffer, MMI_PHB_CONVERT_BUFF_ZI, mode))
  1759.     {
  1760.         switch (MMI_current_input_mode)
  1761.         {
  1762.             case INPUT_MODE_MMI_MULTITAP_BPMF:
  1763.                 g_phb_qsearch_cache[index] = pCharInfoBuffer[0] - ZI8_BASE_BPMF + 0x3105;
  1764.                 break;
  1765.             case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1766.                 g_phb_qsearch_cache[index] = pCharInfoBuffer[0] - ZI8_BASE_PINYIN + 0x0061;
  1767.                 break;
  1768.             case INPUT_MODE_MMI_SM_STROKE:
  1769.             case INPUT_MODE_MMI_TR_STROKE:
  1770.                 g_phb_qsearch_cache[index] = pCharInfoBuffer[0];
  1771.                 break;
  1772.             default:
  1773.                 memcpy(&g_phb_qsearch_cache[index], PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1774.                 break;
  1775.         }
  1776.     }
  1777.     else
  1778.     {
  1779.         memcpy(&g_phb_qsearch_cache[index], PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1780.     }
  1781. }
  1782. //KP Jerry add on 2007-3-8 start
  1783. #elif defined(__MMI_CSTAR__)
  1784. BOOL mmi_phb_quick_search_convert_to_spelling(U8* input_string, U8* output_string, U8* out_len) 
  1785. {
  1786.     int c;
  1787.     int mode;
  1788.     U16 code;
  1789.     U16 buf[16];
  1790.     mode = MMI_current_input_mode;
  1791. switch (mode)
  1792. {
  1793. case INPUT_MODE_MMI_MULTITAP_BPMF:
  1794. case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1795. case INPUT_MODE_MMI_SM_STROKE:
  1796. case INPUT_MODE_MMI_TR_STROKE:         
  1797.         break;
  1798. default:
  1799.             *out_len = 0;
  1800. return FALSE;
  1801. }
  1802.     if ( (input_string[0] == 0) && (input_string[1] == 0) )
  1803.     {
  1804.         *out_len = 0;
  1805. return FALSE;
  1806.     }
  1807.     memcpy(&code, input_string, 2);
  1808.     c = CstarQueryCharInfo(code, buf, 16, mode);
  1809.     if (c <= 0)
  1810.     {
  1811.         memcpy(output_string, input_string, 2);
  1812.         *out_len = 1;
  1813.         return TRUE;
  1814.     }
  1815.     if (c > 7)
  1816.         c = 7;
  1817.     memcpy(output_string, buf, sizeof(U16) * c);
  1818.     *out_len = (U8)c;
  1819.     return TRUE;
  1820. }
  1821. void mmi_phb_quick_search_convert_cache(U16 index)
  1822. {
  1823.     int c;
  1824.     int mode;
  1825.     U16 code;
  1826.     U16 buf[16];
  1827.     mode = MMI_current_input_mode;
  1828. switch (mode)
  1829.     {   
  1830.         case INPUT_MODE_MMI_MULTITAP_BPMF:
  1831.         case INPUT_MODE_MMI_MULTITAP_PINYIN:
  1832.         case INPUT_MODE_MMI_SM_STROKE:
  1833.         case INPUT_MODE_MMI_TR_STROKE:                              
  1834.             break;
  1835.         default:
  1836.             memcpy(&g_phb_qsearch_cache[index], PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1837.             return;
  1838.     }
  1839.     memcpy(&code, PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1840.     c = CstarQueryCharInfo(code, buf, 16, mode);
  1841.     if (c <= 0)
  1842.     {
  1843.         memcpy(&g_phb_qsearch_cache[index], PhoneBook[g_phb_name_index[index]].alpha_id.name, 2);
  1844.         return;
  1845.     }
  1846.     g_phb_qsearch_cache[index] = buf[0];
  1847. }
  1848. //KP Jerry add on 2007-3-8 end
  1849. #elif defined(__MMI_ITAP__)
  1850. /* under construction !*/
  1851. /* under construction !*/
  1852. /* under construction !*/
  1853. /* under construction !*/
  1854. /* under construction !*/
  1855. /* under construction !*/
  1856. /* under construction !*/
  1857. /* under construction !*/
  1858. /* under construction !*/
  1859. /* under construction !*/
  1860. /* under construction !*/
  1861. /* under construction !*/
  1862. /* under construction !*/
  1863. /* under construction !*/
  1864. /* under construction !*/
  1865. /* under construction !*/
  1866. /* under construction !*/
  1867. /* under construction !*/
  1868. /* under construction !*/
  1869. /* under construction !*/
  1870. /* under construction !*/
  1871. /* under construction !*/
  1872. /* under construction !*/
  1873. /* under construction !*/
  1874. /* under construction !*/
  1875. /* under construction !*/
  1876. /* under construction !*/
  1877. /* under construction !*/
  1878. /* under construction !*/
  1879. /* under construction !*/
  1880. /* under construction !*/
  1881. /* under construction !*/
  1882. /* under construction !*/
  1883. /* under construction !*/
  1884. /* under construction !*/
  1885. /* under construction !*/
  1886. /* under construction !*/
  1887. /* under construction !*/
  1888. /* under construction !*/
  1889. /* under construction !*/
  1890. /* under construction !*/
  1891. /* under construction !*/
  1892. /* under construction !*/
  1893. /* under construction !*/
  1894. /* under construction !*/
  1895. /* under construction !*/
  1896. /* under construction !*/
  1897. /* under construction !*/
  1898. /* under construction !*/
  1899. /* under construction !*/
  1900. /* under construction !*/
  1901. /* under construction !*/
  1902. /* under construction !*/
  1903. /* under construction !*/
  1904. /* under construction !*/
  1905. /* under construction !*/
  1906. /* under construction !*/
  1907. /* under construction !*/
  1908. /* under construction !*/
  1909. /* under construction !*/
  1910. /* under construction !*/
  1911. /* under construction !*/
  1912. /* under construction !*/
  1913. /* under construction !*/
  1914. /* under construction !*/
  1915. /* under construction !*/
  1916. /* under construction !*/
  1917. /* under construction !*/
  1918. /* under construction !*/
  1919. /* under construction !*/
  1920. /* under construction !*/
  1921. /* under construction !*/
  1922. /* under construction !*/
  1923. /* under construction !*/
  1924. /* under construction !*/
  1925. /* under construction !*/
  1926. /* under construction !*/
  1927. /* under construction !*/
  1928. /* under construction !*/
  1929. /* under construction !*/
  1930. /* under construction !*/
  1931. /* under construction !*/
  1932. /* under construction !*/
  1933. /* under construction !*/
  1934. /* under construction !*/
  1935. /* under construction !*/
  1936. /* under construction !*/
  1937. /* under construction !*/
  1938. /* under construction !*/
  1939. /* under construction !*/
  1940. /* under construction !*/
  1941. /* under construction !*/
  1942. /* under construction !*/
  1943. /* under construction !*/
  1944. /* under construction !*/
  1945. /* under construction !*/
  1946. /* under construction !*/
  1947. /* under construction !*/
  1948. /* under construction !*/
  1949. /* under construction !*/
  1950. /* under construction !*/
  1951. /* under construction !*/
  1952. /* under construction !*/
  1953. /* under construction !*/
  1954. /* under construction !*/
  1955. /* under construction !*/
  1956. /* under construction !*/
  1957. /* under construction !*/
  1958. /* under construction !*/
  1959. /* under construction !*/
  1960. /* under construction !*/
  1961. /* under construction !*/
  1962. /* under construction !*/
  1963. /* under construction !*/
  1964. /* under construction !*/
  1965. /* under construction !*/
  1966. /* under construction !*/
  1967. /* under construction !*/
  1968. /* under construction !*/
  1969. /* under construction !*/
  1970. /* under construction !*/
  1971. /* under construction !*/
  1972. /* under construction !*/
  1973. /* under construction !*/
  1974. /* under construction !*/
  1975. /* under construction !*/
  1976. /* under construction !*/
  1977. /* under construction !*/
  1978. /* under construction !*/
  1979. /* under construction !*/
  1980. /* under construction !*/
  1981. /* under construction !*/
  1982. /* under construction !*/
  1983. /* under construction !*/
  1984. /* under construction !*/
  1985. /* under construction !*/
  1986. /* under construction !*/
  1987. /* under construction !*/
  1988. /* under construction !*/
  1989. /* under construction !*/
  1990. /* under construction !*/
  1991. /* under construction !*/
  1992. /* under construction !*/
  1993. /* under construction !*/
  1994. /* under construction !*/
  1995. /* under construction !*/
  1996. /* under construction !*/
  1997. /* under construction !*/
  1998. /* under construction !*/
  1999. /* under construction !*/
  2000. /* under construction !*/
  2001. /* under construction !*/
  2002. /* under construction !*/
  2003. /* under construction !*/
  2004. /* under construction !*/
  2005. /* under construction !*/
  2006. /* under construction !*/
  2007. /* under construction !*/
  2008. /* under construction !*/
  2009. /* under construction !*/
  2010. /* under construction !*/
  2011. /* under construction !*/
  2012. /* under construction !*/
  2013. /* under construction !*/
  2014. /* under construction !*/
  2015. /* under construction !*/
  2016. /* under construction !*/
  2017. /* under construction !*/
  2018. /* under construction !*/
  2019. /* under construction !*/
  2020. /* under construction !*/
  2021. /* under construction !*/
  2022. /* under construction !*/
  2023. /* under construction !*/
  2024. /* under construction !*/
  2025. /* under construction !*/
  2026. /* under construction !*/
  2027. /* under construction !*/
  2028. /* under construction !*/
  2029. /* under construction !*/
  2030. /* under construction !*/
  2031. /* under construction !*/
  2032. /* under construction !*/
  2033. /* under construction !*/
  2034. /* under construction !*/
  2035. /* under construction !*/
  2036. /* under construction !*/
  2037. /* under construction !*/
  2038. /* under construction !*/
  2039. /* under construction !*/
  2040. /* under construction !*/
  2041. /* under construction !*/
  2042. /* under construction !*/
  2043. /* under construction !*/
  2044. /* under construction !*/
  2045. /* under construction !*/
  2046. /* under construction !*/
  2047. /* under construction !*/
  2048. /* under construction !*/
  2049. /* under construction !*/
  2050. /* under construction !*/
  2051. /* under construction !*/
  2052. /* under construction !*/
  2053. /* under construction !*/
  2054. /* under construction !*/
  2055. /* under construction !*/
  2056. /* under construction !*/
  2057. /* under construction !*/
  2058. /* under construction !*/
  2059. /* under construction !*/
  2060. /* under construction !*/
  2061. /* under construction !*/
  2062. /* under construction !*/
  2063. /* under construction !*/
  2064. /* under construction !*/
  2065. /* under construction !*/
  2066. /* under construction !*/
  2067. /* under construction !*/
  2068. /* under construction !*/
  2069. /* under construction !*/
  2070. #else /* No default input method library */
  2071. /*****************************************************************************
  2072.  * FUNCTION
  2073.  *  mmi_phb_quick_search_convert_to_spelling
  2074.  * DESCRIPTION
  2075.  *  This function is just for template.
  2076.  * PARAMETERS
  2077.  *  input_string        [?]             
  2078.  *  output_string       [?]             
  2079.  *  out_len             [?]             
  2080.  *  a(?)                [IN/OUT]        First variable, used as returns
  2081.  *  b(?)                [IN]            Second variable
  2082.  * RETURNS
  2083.  *  the description of return value, if any.
  2084.  *****************************************************************************/
  2085. BOOL mmi_phb_quick_search_convert_to_spelling(U8 *input_string, U8 *output_string, U8 *out_len)
  2086. {
  2087.     /*----------------------------------------------------------------*/
  2088.     /* Local Variables                                                */
  2089.     /*----------------------------------------------------------------*/
  2090.     /*----------------------------------------------------------------*/
  2091.     /* Code Body                                                      */
  2092.     /*----------------------------------------------------------------*/
  2093.     memcpy(output_string, input_string, 2);
  2094.     *out_len = 1;
  2095.     return TRUE;
  2096. }
  2097. /*****************************************************************************
  2098.  * FUNCTION
  2099.  *  mmi_phb_quick_search_convert_cache
  2100.  * DESCRIPTION
  2101.  *  This function convert first character of name field into cache.
  2102.  * PARAMETERS
  2103.  *  index       [IN]        Phonebook entry index
  2104.  * RETURNS
  2105.  *  void
  2106.  *****************************************************************************/
  2107. void mmi_phb_quick_search_convert_cache(U16 index)
  2108. {
  2109.     /*----------------------------------------------------------------*/
  2110.     /* Local Variables                                                */
  2111.     /*----------------------------------------------------------------*/
  2112.     /*----------------------------------------------------------------*/
  2113.     /* Code Body                                                      */
  2114.     /*----------------------------------------------------------------*/
  2115.     g_phb_qsearch_cache[index] = (U16) PhoneBook[g_phb_name_index[index]].alpha_id.name[0];
  2116. }
  2117. #endif 
  2118. /*****************************************************************************
  2119.  * FUNCTION
  2120.  *  mmi_phb_quick_search_make_cache
  2121.  * DESCRIPTION
  2122.  *  
  2123.  * PARAMETERS
  2124.  *  void
  2125.  * RETURNS
  2126.  *  void
  2127.  *****************************************************************************/
  2128. void mmi_phb_quick_search_make_cache(void)
  2129. {
  2130.     /*----------------------------------------------------------------*/
  2131.     /* Local Variables                                                */
  2132.     /*----------------------------------------------------------------*/
  2133.     U16 index;
  2134.     U16 pre_store_index;
  2135.     U16 store_index;
  2136.     /*----------------------------------------------------------------*/
  2137.     /* Code Body                                                      */
  2138.     /*----------------------------------------------------------------*/
  2139. #if defined(__MMI_T9__)
  2140.     /* Switch to the proper input language, only for T9 */
  2141.     switch (MMI_current_input_mode)
  2142.     {
  2143.     #if defined(__MMI_T9_TR_CHINESE__)
  2144.         case INPUT_MODE_MMI_MULTITAP_BPMF:
  2145.             T9ChangeLanguageToTRChineseBoPoMo();
  2146.             break;
  2147.         case INPUT_MODE_MMI_TR_STROKE:
  2148.             T9ChangeLanguageToTRChineseStroke();
  2149.             break;
  2150.     #endif /* defined(__MMI_T9_TR_CHINESE__) */ 
  2151.     #if defined(__MMI_T9_SM_CHINESE__)
  2152.         case INPUT_MODE_MMI_MULTITAP_PINYIN:
  2153.             T9ChangeLanguageToSMChinesePinYin();
  2154.             break;
  2155.         case INPUT_MODE_MMI_SM_STROKE:
  2156.             T9ChangeLanguageToSMChineseStroke();
  2157.             break;
  2158.     #endif /* defined(__MMI_T9_SM_CHINESE__) */ 
  2159.         default:
  2160.             break;
  2161.     }
  2162. #endif /* defined(__MMI_T9__) */ 
  2163.     /* Begin to convert first character of name field to associated input method string. */
  2164.     for (index = 0; index < PhoneBookEntryCount; index++)
  2165.     {
  2166.         store_index = g_phb_name_index[index];
  2167.         if (pfnUnicodeStrlen((S8*) PhoneBook[store_index].alpha_id.name) > 0)
  2168.         {
  2169.             /* The Entry Name is an UCS2 string */
  2170.             if (PhoneBook[store_index].alpha_id.name_dcs == PHB_UCS2)
  2171.             {
  2172.                 if (index != 0)
  2173.                 {
  2174.                     pre_store_index = g_phb_name_index[index - 1];
  2175.                     /* If character is the same, do not convert again. */
  2176.                     if ((PhoneBook[pre_store_index].alpha_id.name[0] == PhoneBook[store_index].alpha_id.name[0]) &&
  2177.                         (PhoneBook[pre_store_index].alpha_id.name[1] == PhoneBook[store_index].alpha_id.name[1]))
  2178.                     {
  2179.                         g_phb_qsearch_cache[index] = g_phb_qsearch_cache[index - 1];
  2180.                         continue;
  2181.                     }
  2182.                 }
  2183.                 mmi_phb_quick_search_convert_cache(index);
  2184.             }
  2185.             else
  2186.                 /* This is an ASCII string */
  2187.             {
  2188.                 g_phb_qsearch_cache[index] = (U16) PhoneBook[store_index].alpha_id.name[0];
  2189.             }
  2190.         }
  2191.         /* The name field is Empty */
  2192.         else
  2193.         {
  2194.             g_phb_qsearch_cache[index] = 0x0000;
  2195.         }
  2196.     }
  2197.     g_phb_qsearch_is_cache = 1; /* Convert cache done */
  2198. }
  2199. /*****************************************************************************
  2200.  * FUNCTION
  2201.  *  mmi_phb_quick_search_find_entry
  2202.  * DESCRIPTION
  2203.  *  
  2204.  * PARAMETERS
  2205.  *  keyword     [?]     
  2206.  * RETURNS
  2207.  *  
  2208.  *****************************************************************************/
  2209. S32 mmi_phb_quick_search_find_entry(U8 *keyword)
  2210. {
  2211.     /*----------------------------------------------------------------*/
  2212.     /* Local Variables                                                */
  2213.     /*----------------------------------------------------------------*/
  2214.     U8 key_length;
  2215.     U8 flag;
  2216.     U16 i;
  2217.     U16 code1, code2;
  2218.     U16 result_count;
  2219.     U8 same_count;
  2220.     U8 convert_result;
  2221.     S32 distance;
  2222.     S8 *string1, *string2 = NULL;
  2223.     S8 convert_string[22 * ENCODING_LENGTH];    /* 7*3 + 1 => (char1 + char2 + char3 + Null Terminator) */
  2224.     U8 char1[7 * ENCODING_LENGTH];              /* Cache 1st character convert result */
  2225.     U8 char2[7 * ENCODING_LENGTH];              /* Cache 2nd character convert result */
  2226.     U8 char3[7 * ENCODING_LENGTH];              /* Cache 3rd character convert result */
  2227.     U8 len1, len2, len3;
  2228.     U16 store_index;
  2229.     U8 prev_ucs2 = 0;                           /* Is previous record ucs2 encoding */
  2230.     /*----------------------------------------------------------------*/
  2231.     /* Code Body                                                      */
  2232.     /*----------------------------------------------------------------*/
  2233.     /* Check if cache already build up before using */
  2234.     if (!g_phb_qsearch_is_cache)
  2235.     {
  2236.         StopTimer(PHB_QUICK_SEARCH_TIMER);
  2237.         mmi_phb_quick_search_make_cache();
  2238.     }
  2239.     /* Count the input string length to decide behavior */
  2240.     key_length = (U8) pfnUnicodeStrlen((S8*) keyword);
  2241.     result_count = 0;
  2242.     /* For each entry, check if it is in the quick search sub-list */
  2243.     for (i = 0; i < PhoneBookEntryCount; i++)
  2244.     {
  2245.         flag = FALSE;
  2246.         /*
  2247.          * search length == 1, compare whole list with first character only.
  2248.          */
  2249.         if (key_length == 1)
  2250.         {
  2251.             code1 = (U16) g_phb_qsearch_cache[i];
  2252.             memcpy(&code2, keyword, 2);
  2253.             if (mmi_phb_compare_chars(code1, code2) == 0)
  2254.             {
  2255.                 flag = TRUE;
  2256.             }
  2257.         }
  2258.         /*
  2259.          * search length > 1, compare subset list with maximum search character.
  2260.          */
  2261.         else if (key_length > 1)
  2262.         {
  2263.             code1 = (U16) g_phb_qsearch_cache[i];
  2264.             memcpy(&code2, keyword, 2);
  2265.             /* Compare character in cache first. If match, compare the rest part. */
  2266.             if (mmi_phb_compare_chars(code1, code2) == 0)
  2267.             {
  2268.                 store_index = g_phb_name_index[i];
  2269.                 flag = FALSE;
  2270.                 if (PhoneBook[store_index].alpha_id.name_dcs == MMI_PHB_UCS2)
  2271.                 {
  2272.                     /* Use previous record convert result as cache */
  2273.                     if (i != 0)
  2274.                     {
  2275.                         string2 = (S8*) PhoneBook[g_phb_name_index[i - 1]].alpha_id.name;
  2276.                     }
  2277.                     /* Current record */
  2278.                     string1 = (S8*) PhoneBook[store_index].alpha_id.name;
  2279.                     /*
  2280.                      *  Convert 1st character
  2281.                      */
  2282.                     if ((i != 0) && (string2[0] == string1[0]) && (string2[1] == string1[1]) && prev_ucs2)
  2283.                     {
  2284.                         convert_result = 10;    /* Use 10 to represent that first character is the same as previous one */
  2285.                     }
  2286.                     else
  2287.                     {
  2288.                         U16 code;
  2289.                         memcpy(&code, &PhoneBook[store_index].alpha_id.name[0], 2);
  2290.                         if ((code >= 0x4e00) && (code <= 0x9fa5))
  2291.                         {
  2292.                             convert_result = mmi_phb_quick_search_convert_to_spelling(
  2293.                                                 &PhoneBook[store_index].alpha_id.name[0],
  2294.                                                 char1,
  2295.                                                 &len1);
  2296.                         }
  2297.                         else
  2298.                         {
  2299.                             convert_result = FALSE;
  2300.                         }
  2301.                     }
  2302.                     if (convert_result)
  2303.                     {
  2304.                         memset(convert_string, 0, 22 * ENCODING_LENGTH);        /* Clear String in advance, to make sure there will be terminator */
  2305.                         len1 = (len1 > 7) ? 7 : len1;
  2306.                         memcpy(convert_string, char1, (len1 * ENCODING_LENGTH));
  2307.                         /*
  2308.                          *  Convert 2nd Character
  2309.                          */
  2310.                         if (len1 < key_length)
  2311.                         {
  2312.                             if ((convert_result == 10) && (string2[2] == string1[2]) && (string2[3] == string1[3]) &&
  2313.                                 prev_ucs2)
  2314.                             {
  2315.                                 convert_result = 20;    /* Use 20 to represent that second character is the same as previous one */
  2316.                             }
  2317.                             else
  2318.                             {
  2319.                                 convert_result = mmi_phb_quick_search_convert_to_spelling(
  2320.                                                     &PhoneBook[store_index].alpha_id.name[2],
  2321.                                                     char2,
  2322.                                                     &len2);
  2323.                             }
  2324.                             if (convert_result)
  2325.                             {
  2326.                                 len2 = (len2 > 7) ? 7 : len2;
  2327.                                 memcpy((convert_string + len1 * ENCODING_LENGTH), char2, (len2 * ENCODING_LENGTH));
  2328.                                 /*
  2329.                                  *  Convert 3rd Character
  2330.                                  */
  2331.                                 if ((len1 + len2) < key_length)
  2332.                                 {
  2333.                                     if ((convert_result == 20) && (string2[4] == string1[4]) &&
  2334.                                         (string2[5] == string1[5]) && prev_ucs2)
  2335.                                     {
  2336.                                         convert_result = 30;    /* Use 30 to represent that third character is the same as previous one */
  2337.                                     }
  2338.                                     else
  2339.                                     {
  2340.                                         convert_result = mmi_phb_quick_search_convert_to_spelling(
  2341.                                                             &PhoneBook[store_index].alpha_id. name[4],
  2342.                                                             char3,
  2343.                                                             &len3);
  2344.                                     }
  2345.                                     if (convert_result)
  2346.                                     {
  2347.                                         len3 = (len3 > 7) ? 7 : len3;
  2348.                                         memcpy(
  2349.                                             (convert_string + (len1 + len2) * ENCODING_LENGTH),
  2350.                                             char3,
  2351.                                             (len3 * ENCODING_LENGTH));
  2352.                                     }
  2353.                                     else
  2354.                                     {
  2355.                                         memcpy(
  2356.                                             (convert_string + len1 * ENCODING_LENGTH),
  2357.                                             &PhoneBook[store_index].alpha_id.name[4],
  2358.                                             2);
  2359.                                     }
  2360.                                 }
  2361.                             }
  2362.                             else
  2363.                             {
  2364.                                 memcpy(
  2365.                                     (convert_string + len1 * ENCODING_LENGTH),
  2366.                                     &PhoneBook[store_index].alpha_id.name[2],
  2367.                                     2);
  2368.                             }
  2369.                         }
  2370.                         /* Chinese convert successfully, use convert result to compare */
  2371.                         string1 = convert_string;
  2372.                         prev_ucs2 = 1;
  2373.                     }
  2374.                     else    /* Not Chinese */
  2375.                     {
  2376.                         string1 = (S8*) PhoneBook[store_index].alpha_id.name;
  2377.                         prev_ucs2 = 0;
  2378.                     }
  2379.                 }
  2380.                 else    /* ASCII */
  2381.                 {
  2382.                     string1 = (S8*) PhoneBook[store_index].alpha_id.name;
  2383.                     prev_ucs2 = 0;
  2384.                 }
  2385.                 mmi_phb_compare_ucs2_strings((S8*) string1, (S8*) keyword, &same_count, &distance);
  2386.                 if (same_count == key_length)
  2387.                 {
  2388.                     flag = TRUE;
  2389.                 }
  2390.             }
  2391.         }
  2392.         /*
  2393.          *search length == 0, display whole list.
  2394.          */
  2395.         else
  2396.         {
  2397.             flag = TRUE;
  2398.         }
  2399.         /* Add to list if entry is a subset of a quick search result */
  2400.         if (flag)
  2401.         {
  2402.             /* g_phb_qsearch[i] = 1; */
  2403.             g_phb_qsearch_bitmask[i >> BYTE_SIZE_SHIFT_ARITHMETIC] |= 1 << (i % BYTE_SIZE);
  2404.             result_count++;
  2405.         }
  2406.         else
  2407.         {
  2408.             /* g_phb_qsearch[i] = 0; */
  2409.             g_phb_qsearch_bitmask[i >> BYTE_SIZE_SHIFT_ARITHMETIC] &= (kal_uint8) (~(1 << (i % BYTE_SIZE)));
  2410.         }
  2411.     }
  2412.     if (result_count == 0)  /* Clear send key when no entry found */
  2413.     {
  2414.         ClearKeyHandler(KEY_SEND, KEY_EVENT_UP);
  2415.     #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
  2416.         StopTimer(PHB_LIST_SPEAK_NAME_TIMER);
  2417.         if (g_phb_is_speaking_name)
  2418.         {