8d97293ad94928c7c9299cabd429085ca53144f0
[platform/core/uifw/ise-default.git] / src / ise-emoticon-mode.cpp
1 /*
2  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #ifdef SUPPORTS_EMOTICONS
19
20 #include <string>
21 #include <vector>
22 #include <sstream>
23 #include <iterator>
24 #include <algorithm>
25 #include <Elementary.h>
26 #include <app_preference.h>
27 #include <sclutils.h>
28 #include <sclfeedback.h>
29
30 #include "ise-emoticon-mode.h"
31 #include "ise.h"
32 #include "config.h"
33 #include "candidate-factory.h"
34
35 #undef LOG_TAG
36 #define LOG_TAG "ISE_DEFAULT"
37 #include <dlog.h>
38
39 #define EVAS_CANDIDATE_LAYER    32000
40
41 #ifdef _TV
42 #define ISE_HEIGHT_PORT         398
43 #define ISE_HEIGHT_LAND         398
44 #elif _WEARABLE
45 #define ISE_HEIGHT_PORT         240
46 #define ISE_HEIGHT_LAND         240
47 #else
48 #define ISE_HEIGHT_PORT         442
49 #define ISE_HEIGHT_LAND         318
50 #endif
51
52 #define EMOTICON_DIR LAYOUTDIR"/emoticons/"
53 #define EMOTICON_EDJ_FILE_PATH RESDIR"/edje/layout_keypad.edj"
54 #define CUSTOM_GENGRID_EDJ_FILE_PATH RESDIR"/edje/customised_gengrid.edj"
55
56 #define EMOTICON_EDJ_GROUP_PORT_CANDIDATE_ON "emoticon.main.portrait.candidate.on"
57 #define EMOTICON_EDJ_GROUP_LAND_CANDIDATE_ON "emoticon.main.landscape.candidate.on"
58
59 #define EMOTICON_EDJ_GROUP_PORT_CANDIDATE_OFF "emoticon.main.portrait.candidate.off"
60 #define EMOTICON_EDJ_GROUP_LAND_CANDIDATE_OFF "emoticon.main.landscape.candidate.off"
61
62 #define EMOTICON_GENGRID_ITEM_STYLE_PORT "ise/customized_default_style_port"
63 #define EMOTICON_GENGRID_ITEM_STYLE_LAND "ise/customized_default_style_land"
64
65 #define EMOTICON_GENGRID_ITEM_STYLE_PORT2 "ise/customized_default_style_port2"
66 #define EMOTICON_GENGRID_ITEM_STYLE_LAND2 "ise/customized_default_style_land2"
67
68 #define EMOTICON_GENGRID_ITEM_STYLE_WEARABLE "ise/customized_default_style_wearable"
69
70 #define IND_NUM 20
71
72 #ifdef _WEARABLE
73 #define EMOTICON_ICON_WIDTH_PORT 40
74 #define EMOTICON_ICON_HEIGHT_PORT 40
75
76 #define EMOTICON_ICON_GAP_WIDTH_PORT 24
77 #define EMOTICON_ICON_GAP_HEIGHT_PORT 3
78 #else
79 #define EMOTICON_ICON_WIDTH_PORT 27
80 #define EMOTICON_ICON_HEIGHT_PORT 27
81
82 #define EMOTICON_ICON_GAP_WIDTH_PORT 10
83 #define EMOTICON_ICON_GAP_HEIGHT_PORT 2
84 #endif
85 #define EMOTICON_WIDTH_PORT (EMOTICON_ICON_WIDTH_PORT + EMOTICON_ICON_GAP_WIDTH_PORT)
86 #define EMOTICON_HEIGHT_PORT (EMOTICON_ICON_HEIGHT_PORT + EMOTICON_ICON_GAP_HEIGHT_PORT)
87
88 #define EMOTICON_ICON_WIDTH_LAND 27
89 #define EMOTICON_ICON_HEIGHT_LAND 27
90
91 #define EMOTICON_ICON_GAP_WIDTH_LAND 4
92 #define EMOTICON_ICON_GAP_HEIGHT_LAND 0
93
94 #define EMOTICON_WIDTH_LAND (EMOTICON_ICON_WIDTH_LAND + EMOTICON_ICON_GAP_WIDTH_LAND)
95 #define EMOTICON_HEIGHT_LAND (EMOTICON_ICON_HEIGHT_LAND + EMOTICON_ICON_GAP_HEIGHT_LAND)
96
97 #define MIN_RECENT_EMOTICON_NEEDED_IN_PORT 22        // (7*3 + 1)
98 #define MIN_RECENT_EMOTICON_NEEDED_IN_LAND 27        // (13*2 + 1)
99
100 #define MAX_SIZE_AMONG_FIRST_3_EMOTICON_GROUPS  (EMOTICON_GROUP_1_NUM > EMOTICON_GROUP_2_NUM ? (EMOTICON_GROUP_1_NUM > EMOTICON_GROUP_3_NUM ? EMOTICON_GROUP_1_NUM : EMOTICON_GROUP_3_NUM) : (EMOTICON_GROUP_2_NUM > EMOTICON_GROUP_3_NUM ? EMOTICON_GROUP_2_NUM : EMOTICON_GROUP_3_NUM))
101 #define MAX_SIZE_AMONG_EMOTICON_GROUPS (EMOTICON_GROUP_4_NUM > EMOTICON_GROUP_5_NUM ? (EMOTICON_GROUP_4_NUM > MAX_SIZE_AMONG_FIRST_3_EMOTICON_GROUPS ? EMOTICON_GROUP_4_NUM : MAX_SIZE_AMONG_FIRST_3_EMOTICON_GROUPS) : (EMOTICON_GROUP_5_NUM > MAX_SIZE_AMONG_FIRST_3_EMOTICON_GROUPS ? EMOTICON_GROUP_5_NUM : MAX_SIZE_AMONG_FIRST_3_EMOTICON_GROUPS))
102
103 bool is_emoticon_mode = false;
104 emoticon_group_t current_emoticon_group = EMOTICON_GROUP_RECENTLY_USED;
105 std::vector <int> emoticon_list_recent;
106 bool is_recently_used_emoticon_mode_disabled = true;
107
108 extern CSCLUI *g_ui;
109 extern int * emoticon_list[];
110 extern CONFIG_VALUES g_config_values;
111 extern Candidate    *g_candidate;
112
113 #ifdef _WEARABLE
114 unsigned short int emoticon_group_items[MAX_EMOTICON_GROUP] =
115 {
116     EMOTICON_GROUP_RECENTLY_USED_NUM,
117     EMOTICON_GROUP_1_NUM,
118     EMOTICON_GROUP_2_NUM,
119     EMOTICON_GROUP_3_NUM
120 };
121 #else
122 unsigned short int emoticon_group_items[MAX_EMOTICON_GROUP] =
123 {
124     EMOTICON_GROUP_RECENTLY_USED_NUM,
125     EMOTICON_GROUP_1_NUM,
126     EMOTICON_GROUP_2_NUM,
127     EMOTICON_GROUP_3_NUM,
128     EMOTICON_GROUP_4_NUM,
129     EMOTICON_GROUP_5_NUM
130 };
131
132 const char *emoticon_group_icons_press[MAX_EMOTICON_GROUP] =
133 {
134     "emotion/icon_recent_press.png",
135     "emotion/icon_emotion_press.png",
136     "emotion/icon_crown_press.png",
137     "emotion/icon_dog_press.png",
138     "emotion/icon_house_press.png",
139     "emotion/icon_star_press.png"
140 };
141 #endif
142
143 struct emoticon_item_t
144 {
145     Elm_Object_Item *item;
146     int code;
147     std::string path;
148     Eina_Unicode keyevent;
149 };
150
151 emoticon_item_t emoticon_items[MAX_SIZE_AMONG_EMOTICON_GROUPS] = {{0, }, };
152
153 // Static variable declarations
154 static Evas_Object *layout = NULL;
155 static Evas_Object *gengrid = NULL;
156 static Elm_Theme *theme = NULL;
157 static Elm_Gengrid_Item_Class *gic = NULL;
158
159 // Static Function declarations
160 static void __ise_emoticon_create_gengrid(unsigned short int screen_degree);
161 static void __ise_emoticon_append_items_to_gengrid(emoticon_group_t emoticon_group);
162 static void __ise_emoticon_create_item_class(unsigned short int screen_degree);
163 #if SUPPORTS_EMOTICONS_BY_IMAGE
164 static Evas_Object * grid_content_get(void *data, Evas_Object *obj, const char *part);
165 static void grid_content_del(void *data, Evas_Object *obj);
166 #else
167 static char * grid_text_get(void *data, Evas_Object *obj, const char *part);
168 #endif
169 static void _item_selected(void *data, Evas_Object *obj, void *event_info);
170 static Eina_Bool _focus_done(void *data);
171 static void _multi_down(void *data, Evas *e, Evas_Object *o, void *event_info);
172 static void _multi_up(void *data, Evas *e, Evas_Object *o, void *event_info);
173
174 void ise_read_recent_emoticon_list_from_scim(void)
175 {
176     LOGD("Enter\n");
177     std::string string_value;
178     read_ise_config_string(ISE_CONFIG_RECENT_EMOTICONS_LIST, string_value);
179
180     if (string_value.length() > 0) {
181         LOGD("read recent emoticon:%s\n", string_value.c_str());
182         std::stringstream ss(string_value);
183         std::istream_iterator<std::string> begin(ss);
184         std::istream_iterator<std::string> end;
185         std::vector<std::string> vstrings(begin, end);
186
187         emoticon_list_recent.clear();
188         std::vector<std::string>::iterator it;
189         for (it = vstrings.begin(); it != vstrings.end(); it++) {
190             emoticon_list_recent.push_back(atoi((*it).c_str()));
191         }
192     }
193 }
194
195 void ise_write_recent_emoticon_list_to_scim(void)
196 {
197     std::string string_value;
198     for (std::vector<int>::iterator it = emoticon_list_recent.begin();
199         it != emoticon_list_recent.end(); std::advance(it, 1)) {
200             char buf[10]= {0};
201             snprintf (buf, sizeof(buf), "%d", *it);
202             string_value += std::string(buf);
203             string_value += " ";
204     }
205     if (string_value.length() > 0) {
206         preference_set_string(ISE_CONFIG_RECENT_EMOTICONS_LIST, string_value.c_str());
207         LOGD("write recent emoticon:%s\n", string_value.c_str());
208     }
209 }
210
211 void ise_show_emoticon_layout(emoticon_group_t emoticon_group, const int screen_degree, const bool is_candidate_on, void *main_window)
212 {
213 #ifdef _TV
214     return;
215 #endif
216     //xt9_send_flush(0);
217     ise_init_emoticon_list();
218     ise_set_private_key_for_emoticon_mode(emoticon_group);
219
220     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
221         //ise_read_recent_emoticon_list_from_scim();
222         if (emoticon_list_recent.size() == 0) {
223             //PRINTFUNC(DLOG_ERROR,"Cannot display recently used emoticons group. No recently used emoticons available");
224             return;
225         }
226     }
227
228     ise_destroy_emoticon_layout();
229
230     layout = elm_layout_add((Evas_Object *)main_window);
231     evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
232     evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
233
234     int y = 0;
235     if (g_candidate && g_candidate->get_visible())
236         y = g_candidate->get_height();
237
238     read_ise_config_values();
239     if (g_config_values.floating_mode)
240         evas_object_move(layout, 0, y + FLOATING_TITLE_BAR_HEIGHT);
241     else
242         evas_object_move(layout, 0, y);
243
244     if (is_candidate_on) {
245         if (screen_degree == 0 || screen_degree == 180)
246             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH, EMOTICON_EDJ_GROUP_PORT_CANDIDATE_ON);
247         else
248             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH, EMOTICON_EDJ_GROUP_LAND_CANDIDATE_ON);
249     } else {
250         sclint width = 0;
251         sclint height = 0;
252         g_ui->get_screen_resolution(&width, &height);
253         LOGD("screen width:%d, height:%d\n", width, height);
254         if (screen_degree == 0 || screen_degree == 180) {
255             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH, EMOTICON_EDJ_GROUP_PORT_CANDIDATE_OFF);
256             if (g_config_values.floating_mode)
257                 evas_object_resize(layout, width * FLOATING_SCALE_RATE, g_ui->get_scaled_y(ISE_HEIGHT_PORT) - ELM_SCALE_SIZE(EMOTICON_HEIGHT_PORT));
258             else
259                 evas_object_resize(layout, width, g_ui->get_scaled_y(ISE_HEIGHT_PORT));
260         } else {
261             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH, EMOTICON_EDJ_GROUP_LAND_CANDIDATE_OFF);
262             if (g_config_values.floating_mode)
263                 evas_object_resize(layout, width * FLOATING_SCALE_RATE, g_ui->get_scaled_y(ISE_HEIGHT_LAND) * FLOATING_SCALE_RATE);
264             else
265                 evas_object_resize(layout, width, g_ui->get_scaled_y(ISE_HEIGHT_LAND));
266         }
267 #ifdef _WEARABLE
268         if (g_config_values.floating_mode) {
269             evas_object_resize(layout, 260 * FLOATING_SCALE_RATE, 240 * FLOATING_SCALE_RATE);
270             evas_object_move(layout, 10, y + FLOATING_TITLE_BAR_HEIGHT);
271         } else {
272             evas_object_resize(layout, 260, 240);
273             evas_object_move(layout, 10, y);
274         }
275 #else
276         if (screen_degree == 0 || screen_degree == 180) {
277             ;
278         } else {
279             if (g_config_values.floating_mode) {
280                 evas_object_resize(layout, (width - g_ui->get_scaled_y(88*2)) * FLOATING_SCALE_RATE, (g_ui->get_scaled_y(ISE_HEIGHT_LAND)) * FLOATING_SCALE_RATE);
281                 evas_object_move(layout, g_ui->get_scaled_y(88), y + FLOATING_TITLE_BAR_HEIGHT);
282             } else {
283                 evas_object_resize(layout, width - g_ui->get_scaled_y(88*2), g_ui->get_scaled_y(ISE_HEIGHT_LAND));
284                 evas_object_move(layout, g_ui->get_scaled_y(88), y);
285             }
286         }
287 #endif
288     }
289
290     theme = elm_theme_new();
291     elm_theme_ref_set(theme, NULL); // refer to default theme
292     elm_theme_extension_add(theme, CUSTOM_GENGRID_EDJ_FILE_PATH);
293
294     __ise_emoticon_create_gengrid((unsigned short)screen_degree);
295     __ise_emoticon_create_item_class((unsigned short)screen_degree);
296     __ise_emoticon_append_items_to_gengrid(emoticon_group);
297
298     elm_object_part_content_set(layout, "emoticon.swallow.gengrid", gengrid);
299     //elm_win_resize_object_add(main_window, layout);
300
301     evas_object_show(gengrid);
302     evas_object_layer_set(layout, EVAS_CANDIDATE_LAYER-1);
303     evas_object_show(layout);
304
305     is_emoticon_mode = true;
306     current_emoticon_group = emoticon_group;
307 }
308
309 void ise_destroy_emoticon_layout(void)
310 {
311     /* According to UI FW team, when the a parent is deleted, all its child content will
312      * also be deleted. So no need to delete gengrid explicitly. Just setting the gendrid
313      * pointer to NULL should suffice here.
314      * OR
315      * We can first delete all the child elements and then we delete the parent.
316      * This approach is currently used below
317      */
318
319     if (gengrid) {
320         elm_gengrid_clear(gengrid);
321         evas_object_del(gengrid);
322         gengrid = NULL;
323     }
324
325     if (layout) {
326         evas_object_del(layout);
327         layout = NULL;
328     }
329
330     if (theme) {
331         elm_theme_free(theme);
332         theme = NULL;
333     }
334 }
335
336 void ise_change_emoticon_mode(emoticon_group_t emoticon_group)
337 {
338     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
339         //ise_read_recent_emoticon_list_from_scim();
340         if (emoticon_list_recent.size() == 0) {
341             //PRINTFUNC(DLOG_ERROR,"Cannot display recently used emoticons group. No recently used emoticons available");
342             return;
343         }
344     }
345
346     if (gengrid) {
347         elm_gengrid_clear(gengrid);
348     }
349
350     __ise_emoticon_append_items_to_gengrid(emoticon_group);
351     current_emoticon_group = emoticon_group;
352 }
353
354 static Eina_Bool _focus_done(void *data)
355 {
356     Elm_Object_Item *item = (Elm_Object_Item *)data;
357
358     elm_object_item_signal_emit(item, "mouse,up,1", "reorder_bg");
359
360     return ECORE_CALLBACK_CANCEL;
361 }
362
363 static void _multi_down(void *data, Evas *e, Evas_Object *o, void *event_info)
364 {
365     Evas_Event_Multi_Down *ev = (Evas_Event_Multi_Down*)event_info;
366
367 //  PRINTFUNC(DLOG_DEBUG,"MULTI: down @ %4i %4i | dev: %i\n", ev->canvas.x, ev->canvas.y, ev->device);
368     if (ev->device >= IND_NUM)
369         return;
370
371     Elm_Object_Item *item;
372     item = elm_gengrid_at_xy_item_get(o, ev->canvas.x, ev->canvas.y, NULL, NULL);
373
374     elm_object_item_signal_emit(item, "mouse,down,1", "reorder_bg");
375
376     ecore_timer_add(0.5, _focus_done, item);
377 }
378
379 static void _multi_up(void *data, Evas *e, Evas_Object *o, void *event_info)
380 {
381     Evas_Event_Multi_Up *ev = (Evas_Event_Multi_Up*)event_info;
382 //  PRINTFUNC(DLOG_DEBUG,"MULTI: up    @ %4i %4i | dev: %i\n", ev->canvas.x, ev->canvas.y, ev->device);
383     if (ev->device >= IND_NUM)
384         return;
385
386     Elm_Object_Item *item = NULL;
387     item = elm_gengrid_at_xy_item_get(o, ev->canvas.x, ev->canvas.y, NULL, NULL);
388
389     elm_object_item_signal_emit(item, "mouse,up,1", "reorder_bg");
390
391     elm_gengrid_item_selected_set(item, EINA_TRUE);
392 }
393
394 static void __ise_emoticon_create_gengrid(unsigned short int screen_degree)
395 {
396     gengrid = elm_gengrid_add(layout);
397     elm_object_theme_set(gengrid, theme);
398     //elm_object_style_set(gengrid,"no_effect");
399     elm_gengrid_align_set(gengrid, 0.5, 0);
400
401     evas_object_size_hint_weight_set(gengrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
402     evas_object_size_hint_align_set(gengrid, EVAS_HINT_FILL, EVAS_HINT_FILL);
403
404     if (screen_degree == 0 || screen_degree == 180)
405         elm_gengrid_item_size_set(gengrid, ELM_SCALE_SIZE(EMOTICON_WIDTH_PORT), ELM_SCALE_SIZE(EMOTICON_HEIGHT_PORT));
406     else
407         elm_gengrid_item_size_set(gengrid, ELM_SCALE_SIZE(EMOTICON_WIDTH_LAND), ELM_SCALE_SIZE(EMOTICON_HEIGHT_LAND));
408
409     elm_gengrid_highlight_mode_set(gengrid, EINA_TRUE);
410     elm_gengrid_select_mode_set(gengrid, ELM_OBJECT_SELECT_MODE_ALWAYS);
411 //  elm_gengrid_cache_mode_set(gengrid, EINA_TRUE);
412     elm_gengrid_multi_select_set(gengrid, EINA_TRUE);
413
414     evas_object_event_callback_add(gengrid, EVAS_CALLBACK_MULTI_DOWN, _multi_down, NULL);
415     evas_object_event_callback_add(gengrid, EVAS_CALLBACK_MULTI_UP, _multi_up, NULL);
416 }
417
418 #if SUPPORTS_EMOTICONS_BY_IMAGE
419 static void __ise_emoticon_append_items_to_gengrid(emoticon_group_t emoticon_group)
420 {
421     char img_name[10];
422     short int items = 0;
423     std::string file_path = "";
424
425     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
426         items = emoticon_list_recent.size();
427
428         for (int i = 0; i < items; i++) {
429             snprintf(img_name, 10, "%x", emoticon_list_recent[i]);
430             emoticon_items[i].code = emoticon_list_recent[i];
431             emoticon_items[i].keyevent = emoticon_list_recent[i];
432             emoticon_items[i].path = (std::string)EMOTICON_DIR + (std::string)"u" + (std::string)img_name + (std::string)".png";
433             emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
434         }
435     } else {
436         if (emoticon_group != EMOTICON_GROUP_DESTROY) {
437             items = emoticon_group_items[emoticon_group];
438         }
439         for (int i = 0; i < items; i++) {
440             snprintf(img_name, 10, "%x", emoticon_list[emoticon_group-1][i]);
441             file_path = (std::string)EMOTICON_DIR + (std::string)"u" + (std::string)img_name + (std::string)".png";
442             if (ise_util_does_file_exists(file_path)) {
443                 emoticon_items[i].code = emoticon_list[emoticon_group-1][i];
444                 emoticon_items[i].keyevent = emoticon_list[emoticon_group-1][i];
445                 emoticon_items[i].path = file_path;
446                 emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
447 //              PRINTFUNC(SECURE_DEBUG,"file_path = %s\n",file_path.c_str());
448             }
449         }
450     }
451     Elm_Object_Item * it = elm_gengrid_first_item_get(gengrid);
452     elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_NONE);
453 }
454
455
456 static void __ise_emoticon_create_item_class(unsigned short int screen_degree)
457 {
458     if (!gic)
459         gic = elm_gengrid_item_class_new();
460
461     if (screen_degree == 0 || screen_degree == 180)
462         gic->item_style = EMOTICON_GENGRID_ITEM_STYLE_PORT2;
463     else
464         gic->item_style = EMOTICON_GENGRID_ITEM_STYLE_LAND2;
465
466     gic->func.text_get = NULL;
467     gic->func.content_get = grid_content_get;
468     gic->func.state_get = NULL;
469     gic->func.del = grid_content_del;
470 }
471
472 static Evas_Object * grid_content_get(void *data, Evas_Object *obj, const char *part)
473 {
474     emoticon_item_t *ti = (emoticon_item_t *)data;
475     if (ti == NULL)
476         return NULL;
477
478     if (!strcmp(part, "elm.swallow.icon")) {
479         if (ti->path.c_str()) {
480             Eina_Bool is_image_file_set = false;
481             Evas_Object *icon = elm_image_add(obj);
482             is_image_file_set = elm_image_file_set(icon, ti->path.c_str(), NULL);
483             if (!is_image_file_set) {
484                 //PRINTFUNC(SECURE_ERROR,"image \"%s\" not set",ti->path.c_str());
485             } else {
486                 elm_image_aspect_fixed_set(icon, EINA_FALSE);
487                 elm_image_preload_disabled_set(icon, EINA_FALSE);
488                 evas_object_show(icon);
489             }
490             evas_object_data_set(icon, "code", (void *)ti->code);
491             return icon;
492         }
493     }
494
495     return NULL;
496 }
497
498 static void grid_content_del(void *data, Evas_Object *obj)
499 {
500     emoticon_item_t *ti = (emoticon_item_t *)data;
501     if (!ti)
502         return;
503
504     Evas_Object *icon = elm_object_item_part_content_get(ti->item, "elm.swallow.icon");
505     if (icon) {
506         evas_object_data_del(icon, "code");
507     }
508     return;
509 }
510 #else //SUPPORTS_EMOTICONS_BY_IMAGE
511 static void __ise_emoticon_append_items_to_gengrid(emoticon_group_t emoticon_group)
512 {
513     char img_name[10];
514     short int items = 0;
515     std::string file_path = "";
516
517     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
518         items = emoticon_list_recent.size();
519
520         for (int i = 0; i < items; i++) {
521             snprintf(img_name, 10, "%x", emoticon_list_recent[i]);
522             emoticon_items[i].keyevent = emoticon_list_recent[i];
523             emoticon_items[i].path = (std::string)img_name;
524             emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
525         }
526     } else {
527         if (emoticon_group != EMOTICON_GROUP_DESTROY) {
528             items = emoticon_group_items[emoticon_group];
529         }
530         for (int i = 0; i < items; i++) {
531             snprintf(img_name, 10, "%x", emoticon_list[emoticon_group-1][i]);
532             file_path = (std::string)img_name;
533             emoticon_items[i].keyevent = emoticon_list[emoticon_group-1][i];
534             emoticon_items[i].path = file_path;
535             emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
536         }
537     }
538     Elm_Object_Item * it = elm_gengrid_first_item_get(gengrid);
539     elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_NONE);
540 }
541
542 static void __ise_emoticon_create_item_class(unsigned short int screen_degree)
543 {
544     if (!gic)
545         gic = elm_gengrid_item_class_new();
546
547     if (gic) {
548 #ifdef _WEARABLE
549         gic->item_style = EMOTICON_GENGRID_ITEM_STYLE_WEARABLE;
550 #else
551         if (screen_degree == 0 || screen_degree == 180)
552             gic->item_style = EMOTICON_GENGRID_ITEM_STYLE_PORT2;
553         else
554             gic->item_style = EMOTICON_GENGRID_ITEM_STYLE_LAND2;
555 #endif
556         gic->func.text_get = grid_text_get;
557         gic->func.content_get = NULL;
558         gic->func.state_get = NULL;
559         gic->func.del = NULL;
560     }
561 }
562
563 static char * grid_text_get(void *data, Evas_Object *obj, const char *part)
564 {
565     emoticon_item_t *ti = (emoticon_item_t *)data;
566
567     char *utf_8 = NULL;
568     int length = 0;
569
570     if (!strcmp(part, "elm.text")) {
571         if (ti && !(ti->path.empty())) {
572             const Eina_Unicode unicode_event[2] = {ti->keyevent, 0};
573             utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
574             return (utf_8);
575         }
576     }
577
578     return NULL;
579 }
580 #endif //SUPPORTS_EMOTICONS_BY_IMAGE
581
582 static void _item_selected(void *data, Evas_Object *obj, void *event_info)
583 {
584     emoticon_item_t *ti = (emoticon_item_t *)data;
585     char *utf_8 = NULL;
586     int length = 0;
587
588     std::vector<int>::iterator it;
589
590     static CSCLUtils *utils = CSCLUtils::get_instance();
591     if (utils) {
592         if (g_config_values.sound_on)
593             utils->play_sound(DEFAULT_SOUND_STYLE);
594         if (g_config_values.vibration_on)
595             utils->play_vibration(DEFAULT_VIBRATION_STYLE, DEFAULT_VIBRATION_DURATION);
596     }
597
598     if (event_info) {
599         elm_gengrid_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
600         if (ti && ti->keyevent) {
601             const Eina_Unicode unicode_event[2] = {ti->keyevent, 0};
602 //          PRINTFUNC(DLOG_DEBUG,"unicode_event is %x",unicode_event);
603             utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
604
605             if (utf_8) {
606                 ise_send_string((sclchar *)utf_8);
607                 free(utf_8);
608             }
609
610             if (current_emoticon_group != EMOTICON_GROUP_RECENTLY_USED) {
611                 if (emoticon_list_recent.size() < EMOTICON_GROUP_RECENTLY_USED_NUM) {
612                     it = find(emoticon_list_recent.begin(), emoticon_list_recent.end(), ti->keyevent);
613                     if (it == emoticon_list_recent.end()) {    // Item not found
614                         emoticon_list_recent.insert(emoticon_list_recent.begin(), ti->keyevent);
615                     } else {
616                         emoticon_list_recent.erase(it);
617                         emoticon_list_recent.insert(emoticon_list_recent.begin(), ti->keyevent);
618                     }
619                 } else {
620                     it = find(emoticon_list_recent.begin(), emoticon_list_recent.end(), ti->keyevent);
621                     if (it != emoticon_list_recent.end())
622                         emoticon_list_recent.erase(it);
623                     else
624                         emoticon_list_recent.erase(emoticon_list_recent.end() - 1);
625
626                     emoticon_list_recent.insert(emoticon_list_recent.begin(), ti->keyevent);
627                 }
628                 ise_write_recent_emoticon_list_to_scim();
629                 /*
630                 if (is_recently_used_emoticon_mode_disabled)
631                     ise_disable_recently_used_emoticon_key(false);
632                 */
633             }
634         }
635     }
636     //PRINTFUNC(DLOG_DEBUG,"_item_selected() ends");
637 }
638
639 bool is_emoticon_show(void)
640 {
641     return is_emoticon_mode;
642 }
643
644 void ise_set_private_key_for_emoticon_mode(const emoticon_group_t emoticon_group)
645 {
646     if (g_ui) {
647         const char *group_name = NULL;
648         for (int id = EMOTICON_GROUP_RECENTLY_USED; id < MAX_EMOTICON_GROUP; id++) {
649             group_name = ise_get_emoticon_group_name(id);
650             if (group_name)
651                 g_ui->unset_private_key(group_name);
652         }
653
654         group_name = ise_get_emoticon_group_name(emoticon_group);
655         if (group_name) {
656 #ifndef _WEARABLE
657             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
658                const_cast<sclchar*>(emoticon_group_icons_press[emoticon_group]), const_cast<sclchar*>(""), const_cast<sclchar*>("")};
659
660             g_ui->set_private_key(group_name, const_cast<sclchar*>(""), imagelabel, NULL, 0, const_cast<sclchar*>(group_name), TRUE);
661 #endif
662         }
663     }
664 }
665 #endif