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