1 typedef struct
2 {
3 U32 key;
4 U32 data;
5 }mmi_frm_pair_data_struct;
6
7 typedef struct
8 {
9 U32 menu_id;
10 FuncPtr hilite_hdlr;
11 }mmi_frm_hilite_hdlr_struct;
12
13
14 static mmi_frm_hilite_hdlr_struct mmi_frm_int_hilite_hdlr_table[MMI_FRM_MAX_HILITE_HDLR];
15 /*****************************************************************************
16 * FUNCTION
17 * SetHiliteHandler
18 * DESCRIPTION
19 * This function is used for dynamcally register the handler for the menu item. If the
20 * menu items are pre-definable, the applications use this function to dynamcally set
21 * the highlight handlers.
22 *
23 * Note: (1) Please distinguish the function from RegisterHighlightHandler()
24 * which is provided by UI layer. SetHiliteHandler() is for single
25 * menu item; RegisterHighlightHandler() is global for all menu items.
26 * (2) When the screen switchs, the registred handler will invalid.
27 * PARAMETERS
28 * itemid [IN] ID of the item for which highlight handler needs
29 * to be set.
30 * hiliteFuncPtr [IN] Function to be executed whenever item with above
31 * ID is highlighted.
32 * RETURNS
33 * void
34 *****************************************************************************/
35 void SetHiliteHandler(U16 itemid, FuncPtr hiliteFuncPtr)
36 {
37 /*----------------------------------------------------------------*/
38 /* Local Variables */
39 /*----------------------------------------------------------------*/
40 U32 index;
41 MMI_BOOL result;
42
43 /*----------------------------------------------------------------*/
44 /* Code Body */
45 /*----------------------------------------------------------------*/
46 MMI_TRACE(MMI_FW_TRC_G1_FRM, TRC_MMI_FRM_EVENT_SETCURHILIHTE_HDLR, itemid, hiliteFuncPtr);
47
48 MMI_ASSERT(mmi_frm_int_hilite_hdlr_count < MMI_FRM_MAX_HILITE_HDLR);
49
50 result = mmi_frm_binary_search((U32)itemid, (mmi_frm_pair_data_struct*)mmi_frm_int_hilite_hdlr_table,
51 (U32)mmi_frm_int_hilite_hdlr_count, &index);
52
53 if (result == MMI_FALSE)
54 {
55 if (mmi_frm_int_hilite_hdlr_count != 0)
56 {
57 memmove(&mmi_frm_int_hilite_hdlr_table[index+1], &mmi_frm_int_hilite_hdlr_table[index],
58 (mmi_frm_int_hilite_hdlr_count - index)*sizeof(mmi_frm_hilite_hdlr_struct));
59 }
60 mmi_frm_int_hilite_hdlr_count++;
61 }
62
63 mmi_frm_int_hilite_hdlr_table[index].menu_id = itemid;
64 mmi_frm_int_hilite_hdlr_table[index].hilite_hdlr = hiliteFuncPtr;
65 }
66
67
68
69 /*****************************************************************************
70 * FUNCTION
71 * mmi_frm_binary_search
72 * DESCRIPTION
73 * Performs a binary search of a sorted array.
74 * PARAMETERS
75 * key [IN] Object to search for.
76 * search_table [IN] Pointer to base of search data.
77 * num [IN] Number of elements.
78 * index [OUT] index to an occurrence of key in the search_table
79 * array.
80 * RETURNS
81 * If key is found, the function returns MMI_TRUE, else returns MMI_FALSE.
82 *****************************************************************************/
83 MMI_BOOL mmi_frm_binary_search(U32 key, mmi_frm_pair_data_struct* search_table, U32 num, U32* index)
84 {
85 /*----------------------------------------------------------------*/
86 /* Local Variables */
87 /*----------------------------------------------------------------*/
88 S32 m =0, low = 0, high = num -1;
89
90 /*----------------------------------------------------------------*/
91 /* Code Body */
92 /*----------------------------------------------------------------*/
93 while(low <= high)
94 {
95 m = (low + high)/2;
96
97 if (key == search_table[m].key)
98 {
99 *index = m;
100 return MMI_TRUE;
101 }
102 else if (key > search_table[m].key)
103 {
104 low = m + 1;
105 }
106 else
107 {
108 high = m - 1;
109 }
110 }
111
112 *index = low;
113 return MMI_FALSE;
114 }
115