Remove global variables
[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
86 #define EMOTICON_WIDTH_PORT (EMOTICON_ICON_WIDTH_PORT + EMOTICON_ICON_GAP_WIDTH_PORT)
87 #define EMOTICON_HEIGHT_PORT (EMOTICON_ICON_HEIGHT_PORT + EMOTICON_ICON_GAP_HEIGHT_PORT)
88
89 #define EMOTICON_ICON_WIDTH_LAND 27
90 #define EMOTICON_ICON_HEIGHT_LAND 27
91
92 #ifdef _COMMON
93 #define EMOTICON_ICON_GAP_WIDTH_LAND 16
94 #define EMOTICON_ICON_GAP_HEIGHT_LAND 16
95 #else
96 #define EMOTICON_ICON_GAP_WIDTH_LAND 4
97 #define EMOTICON_ICON_GAP_HEIGHT_LAND 0
98 #endif
99
100 #define EMOTICON_LAYOUT_LEFT_MARGIN 88
101
102 #define EMOTICON_WIDTH_LAND (EMOTICON_ICON_WIDTH_LAND + EMOTICON_ICON_GAP_WIDTH_LAND)
103 #define EMOTICON_HEIGHT_LAND (EMOTICON_ICON_HEIGHT_LAND + EMOTICON_ICON_GAP_HEIGHT_LAND)
104
105 #define MIN_RECENT_EMOTICON_NEEDED_IN_PORT 22        // (7*3 + 1)
106 #define MIN_RECENT_EMOTICON_NEEDED_IN_LAND 27        // (13*2 + 1)
107
108 #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))
109 #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))
110
111 static bool is_emoticon_mode = false;
112 emoticon_group_t current_emoticon_group = EMOTICON_GROUP_RECENTLY_USED;
113 std::vector <int> emoticon_list_recent;
114
115 extern int * emoticon_list[];
116
117 #ifdef _WEARABLE
118 static unsigned short int emoticon_group_items[MAX_EMOTICON_GROUP] =
119 {
120     EMOTICON_GROUP_RECENTLY_USED_NUM,
121     EMOTICON_GROUP_1_NUM,
122     EMOTICON_GROUP_2_NUM,
123     EMOTICON_GROUP_3_NUM
124 };
125 #else
126 static unsigned short int emoticon_group_items[MAX_EMOTICON_GROUP] =
127 {
128     EMOTICON_GROUP_RECENTLY_USED_NUM,
129     EMOTICON_GROUP_1_NUM,
130     EMOTICON_GROUP_2_NUM,
131     EMOTICON_GROUP_3_NUM,
132     EMOTICON_GROUP_4_NUM,
133     EMOTICON_GROUP_5_NUM
134 };
135
136 const char *emoticon_group_icons_press[MAX_EMOTICON_GROUP] =
137 {
138     "emotion/icon_recent_press.png",
139     "emotion/icon_emotion_press.png",
140     "emotion/icon_crown_press.png",
141     "emotion/icon_dog_press.png",
142     "emotion/icon_house_press.png",
143     "emotion/icon_star_press.png"
144 };
145 #endif
146
147 struct emoticon_item_t
148 {
149     Elm_Object_Item *item;
150     int code;
151     std::string path;
152     Eina_Unicode keyevent;
153 };
154
155 static emoticon_item_t emoticon_items[MAX_SIZE_AMONG_EMOTICON_GROUPS] = {{0, }, };
156
157 // Static variable declarations
158 static Evas_Object *layout = NULL;
159 static Evas_Object *gengrid = NULL;
160 static Elm_Theme *theme = NULL;
161 static Elm_Gengrid_Item_Class *gic = NULL;
162
163 // Static Function declarations
164 static void __ise_emoticon_create_gengrid(unsigned short int screen_degree);
165 static void __ise_emoticon_append_items_to_gengrid(emoticon_group_t emoticon_group);
166 static void __ise_emoticon_create_item_class(unsigned short int screen_degree);
167 #if SUPPORTS_EMOTICONS_BY_IMAGE
168 static Evas_Object * grid_content_get(void *data, Evas_Object *obj, const char *part);
169 static void grid_content_del(void *data, Evas_Object *obj);
170 #else
171 static char * grid_text_get(void *data, Evas_Object *obj, const char *part);
172 #endif
173 static void _item_selected(void *data, Evas_Object *obj, void *event_info);
174 static Eina_Bool _focus_done(void *data);
175 static void _multi_down(void *data, Evas *e, Evas_Object *o, void *event_info);
176 static void _multi_up(void *data, Evas *e, Evas_Object *o, void *event_info);
177
178 static bool get_landscape_device(int degree)
179 {
180     sclint width = 0;
181     sclint height = 0;
182     bool landscape_device = false;
183
184     CSCLUI *ui = get_ui();
185     if (!ui) return false;
186
187     ui->get_screen_resolution(&width, &height);
188
189     if (degree == 0 || degree == 180) {
190         if (width > height)
191             landscape_device = true;
192     }
193     else {
194         if (width < height)
195             landscape_device = true;
196     }
197
198     return landscape_device;
199 }
200
201 void ise_read_recent_emoticon_list_from_scim(void)
202 {
203     LOGD("Enter\n");
204     std::string string_value;
205     read_ise_config_string(ISE_CONFIG_RECENT_EMOTICONS_LIST, string_value);
206
207     if (string_value.length() > 0) {
208         LOGD("read recent emoticon:%s\n", string_value.c_str());
209         std::stringstream ss(string_value);
210         std::istream_iterator<std::string> begin(ss);
211         std::istream_iterator<std::string> end;
212         std::vector<std::string> vstrings(begin, end);
213
214         emoticon_list_recent.clear();
215         std::vector<std::string>::iterator it;
216         for (it = vstrings.begin(); it != vstrings.end(); it++) {
217             emoticon_list_recent.push_back(atoi((*it).c_str()));
218         }
219     }
220 }
221
222 void ise_write_recent_emoticon_list_to_scim(void)
223 {
224     std::string string_value;
225     for (std::vector<int>::iterator it = emoticon_list_recent.begin();
226         it != emoticon_list_recent.end(); std::advance(it, 1)) {
227             char buf[10]= {0};
228             snprintf (buf, sizeof(buf), "%d", *it);
229             string_value += std::string(buf);
230             string_value += " ";
231     }
232     if (string_value.length() > 0) {
233         preference_set_string(ISE_CONFIG_RECENT_EMOTICONS_LIST, string_value.c_str());
234         LOGD("write recent emoticon:%s\n", string_value.c_str());
235     }
236 }
237
238 void ise_show_emoticon_layout(emoticon_group_t emoticon_group, const int screen_degree, const bool is_candidate_on, void *main_window)
239 {
240     CSCLUI *ui = get_ui();
241     if (!ui) return;
242
243     CONFIG_VALUES *config_values = get_config_values();
244     if (!config_values) return;
245 #ifdef _TV
246     return;
247 #endif
248     //xt9_send_flush(0);
249     ise_init_emoticon_list();
250     ise_set_private_key_for_emoticon_mode(emoticon_group);
251
252     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
253         //ise_read_recent_emoticon_list_from_scim();
254         if (emoticon_list_recent.size() == 0) {
255             //PRINTFUNC(DLOG_ERROR,"Cannot display recently used emoticons group. No recently used emoticons available");
256             return;
257         }
258     }
259
260     ise_destroy_emoticon_layout();
261
262     layout = elm_layout_add((Evas_Object *)main_window);
263     evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
264     evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
265
266     int y = 0;
267     Candidate *candidate = get_candidate();
268     if (candidate && candidate->get_visible())
269         y = candidate->get_height();
270
271     read_ise_config_values();
272     if (config_values->floating_mode)
273         evas_object_move(layout, 0, y + FLOATING_TITLE_BAR_HEIGHT);
274     else
275         evas_object_move(layout, 0, y);
276
277     bool landscape_device = get_landscape_device(screen_degree);
278
279     if (is_candidate_on) {
280         if (screen_degree == 0 || screen_degree == 180) {
281             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH,
282                                 landscape_device ?
283                                 EMOTICON_EDJ_GROUP_LAND_CANDIDATE_ON :
284                                 EMOTICON_EDJ_GROUP_PORT_CANDIDATE_ON);
285         }
286         else {
287             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH,
288                                 landscape_device ?
289                                 EMOTICON_EDJ_GROUP_PORT_CANDIDATE_ON :
290                                 EMOTICON_EDJ_GROUP_LAND_CANDIDATE_ON);
291         }
292     } else {
293         sclint width = 0;
294         sclint height = 0;
295         ui->get_screen_resolution(&width, &height);
296         LOGD("screen width:%d, height:%d\n", width, height);
297         if (screen_degree == 0 || screen_degree == 180) {
298             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH,
299                                 landscape_device ?
300                                 EMOTICON_EDJ_GROUP_LAND_CANDIDATE_OFF :
301                                 EMOTICON_EDJ_GROUP_PORT_CANDIDATE_OFF);
302
303             if (config_values->floating_mode)
304                 evas_object_resize(layout, width * FLOATING_SCALE_RATE, ui->get_scaled_y(ISE_HEIGHT_PORT) - ELM_SCALE_SIZE(EMOTICON_HEIGHT_PORT));
305             else
306                 evas_object_resize(layout, width, ui->get_scaled_y(landscape_device ? ISE_HEIGHT_LAND : ISE_HEIGHT_PORT));
307         } else {
308             elm_layout_file_set(layout, EMOTICON_EDJ_FILE_PATH,
309                                 landscape_device ?
310                                 EMOTICON_EDJ_GROUP_PORT_CANDIDATE_OFF :
311                                 EMOTICON_EDJ_GROUP_LAND_CANDIDATE_OFF);
312
313             if (config_values->floating_mode)
314                 evas_object_resize(layout, width * FLOATING_SCALE_RATE, ui->get_scaled_y(ISE_HEIGHT_LAND) * FLOATING_SCALE_RATE);
315             else {
316                 evas_object_resize(layout, width, ui->get_scaled_y(landscape_device ? ISE_HEIGHT_PORT : ISE_HEIGHT_LAND));
317             }
318         }
319 #ifdef _WEARABLE
320         if (config_values->floating_mode) {
321             evas_object_resize(layout, 260 * FLOATING_SCALE_RATE, 240 * FLOATING_SCALE_RATE);
322             evas_object_move(layout, 10, y + FLOATING_TITLE_BAR_HEIGHT);
323         } else {
324             evas_object_resize(layout, 260, 240);
325             evas_object_move(layout, 10, y);
326         }
327 #else
328         if (screen_degree == 0 || screen_degree == 180) {
329             if (landscape_device) {
330                 evas_object_resize(layout, width - ui->get_scaled_y(EMOTICON_LAYOUT_LEFT_MARGIN*2), ui->get_scaled_y(ISE_HEIGHT_LAND));
331                 evas_object_move(layout, ui->get_scaled_y(EMOTICON_LAYOUT_LEFT_MARGIN), y);
332             }
333         } else {
334             if (config_values->floating_mode) {
335                 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);
336                 evas_object_move(layout, ui->get_scaled_y(EMOTICON_LAYOUT_LEFT_MARGIN), y + FLOATING_TITLE_BAR_HEIGHT);
337             } else {
338                 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));
339                 evas_object_move(layout, ui->get_scaled_y(EMOTICON_LAYOUT_LEFT_MARGIN), y);
340             }
341         }
342 #endif
343     }
344
345     theme = elm_theme_new();
346     elm_theme_ref_set(theme, NULL); // refer to default theme
347     elm_theme_extension_add(theme, CUSTOM_GENGRID_EDJ_FILE_PATH);
348
349     __ise_emoticon_create_gengrid((unsigned short)screen_degree);
350     __ise_emoticon_create_item_class((unsigned short)screen_degree);
351     __ise_emoticon_append_items_to_gengrid(emoticon_group);
352
353     elm_object_part_content_set(layout, "emoticon.swallow.gengrid", gengrid);
354     //elm_win_resize_object_add(main_window, layout);
355
356     evas_object_show(gengrid);
357     evas_object_layer_set(layout, EVAS_CANDIDATE_LAYER-1);
358     evas_object_show(layout);
359
360     is_emoticon_mode = true;
361     current_emoticon_group = emoticon_group;
362 }
363
364 void ise_destroy_emoticon_layout(void)
365 {
366     /* According to UI FW team, when the a parent is deleted, all its child content will
367      * also be deleted. So no need to delete gengrid explicitly. Just setting the gendrid
368      * pointer to NULL should suffice here.
369      * OR
370      * We can first delete all the child elements and then we delete the parent.
371      * This approach is currently used below
372      */
373
374     if (gengrid) {
375         elm_gengrid_clear(gengrid);
376         evas_object_del(gengrid);
377         gengrid = NULL;
378     }
379
380     if (layout) {
381         evas_object_del(layout);
382         layout = NULL;
383     }
384
385     if (theme) {
386         elm_theme_free(theme);
387         theme = NULL;
388     }
389 }
390
391 void ise_change_emoticon_mode(emoticon_group_t emoticon_group)
392 {
393     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
394         //ise_read_recent_emoticon_list_from_scim();
395         if (emoticon_list_recent.size() == 0) {
396             //PRINTFUNC(DLOG_ERROR,"Cannot display recently used emoticons group. No recently used emoticons available");
397             return;
398         }
399     }
400
401     if (gengrid) {
402         elm_gengrid_clear(gengrid);
403     }
404
405     __ise_emoticon_append_items_to_gengrid(emoticon_group);
406     current_emoticon_group = emoticon_group;
407 }
408
409 static Eina_Bool _focus_done(void *data)
410 {
411     Elm_Object_Item *item = (Elm_Object_Item *)data;
412
413     elm_object_item_signal_emit(item, "mouse,up,1", "reorder_bg");
414
415     return ECORE_CALLBACK_CANCEL;
416 }
417
418 static void _multi_down(void *data, Evas *e, Evas_Object *o, void *event_info)
419 {
420     Evas_Event_Multi_Down *ev = (Evas_Event_Multi_Down*)event_info;
421
422 //  PRINTFUNC(DLOG_DEBUG,"MULTI: down @ %4i %4i | dev: %i\n", ev->canvas.x, ev->canvas.y, ev->device);
423     if (ev->device >= IND_NUM)
424         return;
425
426     Elm_Object_Item *item;
427     item = elm_gengrid_at_xy_item_get(o, ev->canvas.x, ev->canvas.y, NULL, NULL);
428
429     elm_object_item_signal_emit(item, "mouse,down,1", "reorder_bg");
430
431     ecore_timer_add(0.5, _focus_done, item);
432 }
433
434 static void _multi_up(void *data, Evas *e, Evas_Object *o, void *event_info)
435 {
436     Evas_Event_Multi_Up *ev = (Evas_Event_Multi_Up*)event_info;
437 //  PRINTFUNC(DLOG_DEBUG,"MULTI: up    @ %4i %4i | dev: %i\n", ev->canvas.x, ev->canvas.y, ev->device);
438     if (ev->device >= IND_NUM)
439         return;
440
441     Elm_Object_Item *item = NULL;
442     item = elm_gengrid_at_xy_item_get(o, ev->canvas.x, ev->canvas.y, NULL, NULL);
443
444     elm_object_item_signal_emit(item, "mouse,up,1", "reorder_bg");
445
446     elm_gengrid_item_selected_set(item, EINA_TRUE);
447 }
448
449 #ifndef _WEARABLE
450 static const char *get_item_style_for_degree(int screen_degree)
451 {
452     bool landscape_device = get_landscape_device(screen_degree);
453
454     if (screen_degree == 0 || screen_degree == 180) {
455         if (landscape_device)
456             return EMOTICON_GENGRID_ITEM_STYLE_LAND2;
457         else
458             return EMOTICON_GENGRID_ITEM_STYLE_PORT2;
459     }
460     else {
461         if (landscape_device)
462             return EMOTICON_GENGRID_ITEM_STYLE_PORT2;
463         else
464             return EMOTICON_GENGRID_ITEM_STYLE_LAND2;
465     }
466 }
467 #endif
468
469 static void __ise_emoticon_create_gengrid(unsigned short int screen_degree)
470 {
471     gengrid = elm_gengrid_add(layout);
472     elm_object_theme_set(gengrid, theme);
473     //elm_object_style_set(gengrid,"no_effect");
474     elm_gengrid_align_set(gengrid, 0.5, 0);
475
476     evas_object_size_hint_weight_set(gengrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
477     evas_object_size_hint_align_set(gengrid, EVAS_HINT_FILL, EVAS_HINT_FILL);
478
479     bool landscape_device = get_landscape_device(screen_degree);
480
481     if (screen_degree == 0 || screen_degree == 180) {
482         elm_gengrid_item_size_set(gengrid,
483                                   ELM_SCALE_SIZE(landscape_device ? EMOTICON_WIDTH_LAND : EMOTICON_WIDTH_PORT),
484                                   ELM_SCALE_SIZE(landscape_device ? EMOTICON_HEIGHT_LAND : EMOTICON_HEIGHT_PORT));
485     }
486     else {
487         elm_gengrid_item_size_set(gengrid,
488                                   ELM_SCALE_SIZE(landscape_device ? EMOTICON_WIDTH_PORT : EMOTICON_WIDTH_LAND),
489                                   ELM_SCALE_SIZE(landscape_device ? EMOTICON_HEIGHT_PORT: EMOTICON_HEIGHT_LAND));
490     }
491
492     elm_gengrid_highlight_mode_set(gengrid, EINA_TRUE);
493     elm_gengrid_select_mode_set(gengrid, ELM_OBJECT_SELECT_MODE_ALWAYS);
494 //  elm_gengrid_cache_mode_set(gengrid, EINA_TRUE);
495     elm_gengrid_multi_select_set(gengrid, EINA_TRUE);
496
497     evas_object_event_callback_add(gengrid, EVAS_CALLBACK_MULTI_DOWN, _multi_down, NULL);
498     evas_object_event_callback_add(gengrid, EVAS_CALLBACK_MULTI_UP, _multi_up, NULL);
499 }
500
501 #if SUPPORTS_EMOTICONS_BY_IMAGE
502 static void __ise_emoticon_append_items_to_gengrid(emoticon_group_t emoticon_group)
503 {
504     char img_name[10];
505     short int items = 0;
506     std::string file_path = "";
507
508     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
509         items = emoticon_list_recent.size();
510
511         for (int i = 0; i < items; i++) {
512             snprintf(img_name, 10, "%x", emoticon_list_recent[i]);
513             emoticon_items[i].code = emoticon_list_recent[i];
514             emoticon_items[i].keyevent = emoticon_list_recent[i];
515             emoticon_items[i].path = (std::string)EMOTICON_DIR + (std::string)"u" + (std::string)img_name + (std::string)".png";
516             emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
517         }
518     } else {
519         if (emoticon_group != EMOTICON_GROUP_DESTROY) {
520             items = emoticon_group_items[emoticon_group];
521         }
522         for (int i = 0; i < items; i++) {
523             snprintf(img_name, 10, "%x", emoticon_list[emoticon_group-1][i]);
524             file_path = (std::string)EMOTICON_DIR + (std::string)"u" + (std::string)img_name + (std::string)".png";
525             if (ise_util_does_file_exists(file_path)) {
526                 emoticon_items[i].code = emoticon_list[emoticon_group-1][i];
527                 emoticon_items[i].keyevent = emoticon_list[emoticon_group-1][i];
528                 emoticon_items[i].path = file_path;
529                 emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
530 //              PRINTFUNC(SECURE_DEBUG,"file_path = %s\n",file_path.c_str());
531             }
532         }
533     }
534     Elm_Object_Item * it = elm_gengrid_first_item_get(gengrid);
535     elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_NONE);
536 }
537
538 static void __ise_emoticon_create_item_class(unsigned short int screen_degree)
539 {
540     if (!gic)
541         gic = elm_gengrid_item_class_new();
542
543     gic->item_style = get_item_style_for_degree(screen_degree);
544
545     gic->func.text_get = NULL;
546     gic->func.content_get = grid_content_get;
547     gic->func.state_get = NULL;
548     gic->func.del = grid_content_del;
549 }
550
551 static Evas_Object * grid_content_get(void *data, Evas_Object *obj, const char *part)
552 {
553     emoticon_item_t *ti = (emoticon_item_t *)data;
554     if (ti == NULL)
555         return NULL;
556
557     if (!strcmp(part, "elm.swallow.icon")) {
558         if (ti->path.c_str()) {
559             Eina_Bool is_image_file_set = false;
560             Evas_Object *icon = elm_image_add(obj);
561             is_image_file_set = elm_image_file_set(icon, ti->path.c_str(), NULL);
562             if (!is_image_file_set) {
563                 //PRINTFUNC(SECURE_ERROR,"image \"%s\" not set",ti->path.c_str());
564             } else {
565                 elm_image_aspect_fixed_set(icon, EINA_FALSE);
566                 elm_image_preload_disabled_set(icon, EINA_FALSE);
567                 evas_object_show(icon);
568             }
569             evas_object_data_set(icon, "code", (void *)ti->code);
570             return icon;
571         }
572     }
573
574     return NULL;
575 }
576
577 static void grid_content_del(void *data, Evas_Object *obj)
578 {
579     emoticon_item_t *ti = (emoticon_item_t *)data;
580     if (!ti)
581         return;
582
583     Evas_Object *icon = elm_object_item_part_content_get(ti->item, "elm.swallow.icon");
584     if (icon) {
585         evas_object_data_del(icon, "code");
586     }
587     return;
588 }
589 #else //SUPPORTS_EMOTICONS_BY_IMAGE
590 static void __ise_emoticon_append_items_to_gengrid(emoticon_group_t emoticon_group)
591 {
592     char img_name[10];
593     short int items = 0;
594     std::string file_path = "";
595
596     if (emoticon_group == EMOTICON_GROUP_RECENTLY_USED) {
597         items = emoticon_list_recent.size();
598
599         for (int i = 0; i < items; i++) {
600             snprintf(img_name, 10, "%x", emoticon_list_recent[i]);
601             emoticon_items[i].keyevent = emoticon_list_recent[i];
602             emoticon_items[i].path = (std::string)img_name;
603             emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
604         }
605     } else {
606         if (emoticon_group != EMOTICON_GROUP_DESTROY) {
607             items = emoticon_group_items[emoticon_group];
608         }
609         for (int i = 0; i < items; i++) {
610             snprintf(img_name, 10, "%x", emoticon_list[emoticon_group-1][i]);
611             file_path = (std::string)img_name;
612             emoticon_items[i].keyevent = emoticon_list[emoticon_group-1][i];
613             emoticon_items[i].path = file_path;
614             emoticon_items[i].item = elm_gengrid_item_append(gengrid, gic, &(emoticon_items[i]), _item_selected, &(emoticon_items[i]));
615         }
616     }
617     Elm_Object_Item * it = elm_gengrid_first_item_get(gengrid);
618     elm_gengrid_item_show(it, ELM_GENGRID_ITEM_SCROLLTO_NONE);
619 }
620
621 static void __ise_emoticon_create_item_class(unsigned short int screen_degree)
622 {
623     if (!gic)
624         gic = elm_gengrid_item_class_new();
625
626     if (gic) {
627 #ifdef _WEARABLE
628         gic->item_style = EMOTICON_GENGRID_ITEM_STYLE_WEARABLE;
629 #else
630         gic->item_style = get_item_style_for_degree(screen_degree);
631 #endif
632         gic->func.text_get = grid_text_get;
633         gic->func.content_get = NULL;
634         gic->func.state_get = NULL;
635         gic->func.del = NULL;
636     }
637 }
638
639 static char * grid_text_get(void *data, Evas_Object *obj, const char *part)
640 {
641     emoticon_item_t *ti = (emoticon_item_t *)data;
642
643     char *utf_8 = NULL;
644     int length = 0;
645
646     if (!strcmp(part, "elm.text")) {
647         if (ti && !(ti->path.empty())) {
648             const Eina_Unicode unicode_event[2] = {ti->keyevent, 0};
649             utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
650             return (utf_8);
651         }
652     }
653
654     return NULL;
655 }
656 #endif //SUPPORTS_EMOTICONS_BY_IMAGE
657
658 static void _item_selected(void *data, Evas_Object *obj, void *event_info)
659 {
660     emoticon_item_t *ti = (emoticon_item_t *)data;
661     char *utf_8 = NULL;
662     int length = 0;
663
664     std::vector<int>::iterator it;
665
666     CONFIG_VALUES *config_values = get_config_values();
667     static CSCLUtils *utils = CSCLUtils::get_instance();
668     if (utils && config_values) {
669         if (config_values->sound_on)
670             utils->play_sound(DEFAULT_SOUND_STYLE);
671         if (config_values->vibration_on)
672             utils->play_vibration(DEFAULT_VIBRATION_STYLE, DEFAULT_VIBRATION_DURATION);
673     }
674
675     if (event_info) {
676         elm_gengrid_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
677         if (ti && ti->keyevent) {
678             const Eina_Unicode unicode_event[2] = {ti->keyevent, 0};
679 //          PRINTFUNC(DLOG_DEBUG,"unicode_event is %x",unicode_event);
680             utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
681
682             if (utf_8) {
683                 ise_send_string((sclchar *)utf_8);
684                 free(utf_8);
685             }
686
687             if (current_emoticon_group != EMOTICON_GROUP_RECENTLY_USED) {
688                 if (emoticon_list_recent.size() < EMOTICON_GROUP_RECENTLY_USED_NUM) {
689                     it = find(emoticon_list_recent.begin(), emoticon_list_recent.end(), ti->keyevent);
690                     if (it == emoticon_list_recent.end()) {    // Item not found
691                         emoticon_list_recent.insert(emoticon_list_recent.begin(), ti->keyevent);
692                     } else {
693                         emoticon_list_recent.erase(it);
694                         emoticon_list_recent.insert(emoticon_list_recent.begin(), ti->keyevent);
695                     }
696                 } else {
697                     it = find(emoticon_list_recent.begin(), emoticon_list_recent.end(), ti->keyevent);
698                     if (it != emoticon_list_recent.end())
699                         emoticon_list_recent.erase(it);
700                     else
701                         emoticon_list_recent.erase(emoticon_list_recent.end() - 1);
702
703                     emoticon_list_recent.insert(emoticon_list_recent.begin(), ti->keyevent);
704                 }
705                 ise_write_recent_emoticon_list_to_scim();
706                 /*
707                 if (is_recently_used_emoticon_mode_disabled)
708                     ise_disable_recently_used_emoticon_key(false);
709                 */
710             }
711         }
712     }
713     //PRINTFUNC(DLOG_DEBUG,"_item_selected() ends");
714 }
715
716 bool is_emoticon_show(void)
717 {
718     return is_emoticon_mode;
719 }
720
721 void ise_set_private_key_for_emoticon_mode(const emoticon_group_t emoticon_group)
722 {
723     CSCLUI *ui = get_ui();
724     if (ui) {
725         const char *group_name = NULL;
726         for (int id = EMOTICON_GROUP_RECENTLY_USED; id < MAX_EMOTICON_GROUP; id++) {
727             group_name = ise_get_emoticon_group_name(id);
728             if (group_name)
729                 ui->unset_private_key(group_name);
730         }
731
732         group_name = ise_get_emoticon_group_name(emoticon_group);
733         if (group_name) {
734 #ifndef _WEARABLE
735             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
736                const_cast<sclchar*>(emoticon_group_icons_press[emoticon_group]), const_cast<sclchar*>(""), const_cast<sclchar*>("")};
737
738             ui->set_private_key(group_name, const_cast<sclchar*>(""), imagelabel, NULL, 0, const_cast<sclchar*>(group_name), TRUE);
739 #endif
740         }
741     }
742 }
743 #endif