d73b69289f9c90dc6cf22757f5d86eb07045ba8b
[platform/core/uifw/inputdelegator.git] / src / w-input-emoticon.cpp
1 /*
2  * Copyright (c) 2016 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 #include <app.h>
18 #include <Elementary.h>
19 #include <string>
20 #include <efl_assist.h>
21
22 #include "Debug.h"
23 #include "w-input-selector.h"
24
25 #define EMOTICON_CNT 27
26
27 using namespace std;
28
29 typedef struct {
30     int code;
31     const char* name;
32 }Emoticon;
33
34 Emoticon emoticon_info[EMOTICON_CNT] = {
35     {0x1f44c, "IDS_IME_BODY_OK_HAND_SIGN_M_EMOTICON_NAME_TTS"},
36     {0x1f44d, "IDS_IME_BODY_THUMBS_UP_SIGN_M_EMOTICON_NAME"},
37     {0x1f44e, "IDS_IME_BODY_THUMBS_DOWN_SIGN_M_EMOTICON_NAME"},
38     {0x1f604, "IDS_IME_BODY_SMILING_FACE_WITH_OPEN_MOUTH_AND_SMILING_EYES_M_EMOTICON_NAME"},
39     {0x1f606, "IDS_IME_BODY_SMILING_FACE_WITH_OPEN_MOUTH_AND_TIGHTLY_CLOSED_EYES_M_EMOTICON_NAME"},
40     {0x1f60a, "IDS_IME_BODY_SMILING_FACE_WITH_SMILING_EYES_M_EMOTICON_NAME"},
41     {0x1f60d, "IDS_IME_BODY_SMILING_FACE_WITH_HEART_SHAPED_EYES_M_EMOTICON_NAME"},
42     {0x1f61a, "IDS_IME_BODY_KISSING_FACE_WITH_CLOSED_EYES_M_EMOTICON_NAME"},
43     {0x1f61c, "IDS_IME_BODY_FACE_WITH_STUCK_OUT_TONGUE_AND_WINKING_EYE_M_EMOTICON_NAME"},
44     {0x1f620, "IDS_IME_BODY_ANGRY_FACE_M_EMOTICON_NAME"},
45     {0x1f621, "IDS_IME_BODY_POUTING_FACE_M_EMOTICON_NAME"},
46     {0x1f622, "IDS_IME_BODY_CRYING_FACE_M_EMOTICON_NAME"},
47     {0x1f624, "IDS_IME_BODY_FACE_WITH_LOOK_OF_TRIUMPH_M_EMOTICON_NAME"},
48     {0x1f625, "IDS_IME_BODY_DISAPPOINTED_BUT_RELIEVED_FACE_M_EMOTICON_NAME"},
49     {0x1f62a, "IDS_IME_BODY_SLEEPY_FACE_M_EMOTICON_NAME"},
50     {0x1f62b, "IDS_IME_BODY_TIRED_FACE_M_EMOTICON_NAME"},
51     {0x1f631, "IDS_IME_BODY_FACE_SCREAMING_IN_FEAR_M_EMOTICON_NAME"},
52     {0x1f632, "IDS_IME_BODY_ASTONISHED_FACE_M_EMOTICON_NAME"},
53     {0x1f637, "IDS_IME_BODY_FACE_WITH_MEDICAL_MASK_M_EMOTICON_NAME"},
54     {0x1f495, "IDS_IME_BODY_TWO_HEARTS_M_EMOTICON_NAME"},
55     {0x1f43d, "IDS_IME_BODY_PIG_NOSE_M_EMOTICON_NAME"},
56     {0x1f415, "IDS_IME_BODY_DOG_M_EMOTICON_NAME"},
57     {0x1f408, "IDS_IME_BODY_CAT_M_EMOTICON_NAME"},
58     {0x1f414, "IDS_IME_BODY_CHICKEN_M_EMOTICON_NAME"},
59     {0x1f433, "IDS_IME_BODY_SPOUTING_WHALE_M_EMOTICON_NAME"},
60     {0x1f43c, "IDS_IME_BODY_PANDA_FACE_M_EMOTICON_NAME"},
61     {0x1f42f, "IDS_IME_BODY_TIGER_FACE_M_EMOTICON_NAME"},
62 };
63
64 const char * get_emoticon_file_name(int index)
65 {
66     static string path = get_resource_path() + string("images/u00000.png");
67
68     int ipos = path.size()-9;
69     char str_emoticon_code[10] = {0};
70     snprintf(str_emoticon_code, sizeof(str_emoticon_code), "%x", emoticon_info[index].code);
71     path.erase(ipos, 5);
72     path.insert(ipos, str_emoticon_code);
73     return path.c_str();
74 }
75
76 static Eina_Bool _custom_back_cb(void *data, Elm_Object_Item *it)
77 {
78     _back_to_genlist_for_selector();
79     return EINA_TRUE;
80 }
81
82 static Eina_Bool
83 _rotary_selector_rotary_cb(void *data, Evas_Object *obj, Eext_Rotary_Event_Info *info)
84 {
85     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
86
87    if (info->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE){
88                 evas_object_smart_callback_call(obj, "item,selected", (void*)data);
89                 eext_rotary_object_event_callback_del(obj, _rotary_selector_rotary_cb);
90    }
91
92         return ECORE_CALLBACK_PASS_ON;
93 }
94
95 static void _rotary_selector_item_clicked(void *data, Evas_Object *obj, void *event_info)
96 {
97     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
98     App_Data* ad = (App_Data*) data;
99     if (!ad)
100         return;
101
102     Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
103     Eina_List *rotary_selector_list = (Eina_List *)eext_rotary_selector_items_get(obj);
104
105     int i = 0;
106     Eina_List *l = rotary_selector_list;
107     Eext_Object_Item *item = (Eext_Object_Item *)eina_list_data_get(l);
108
109     for (i = 0; l != NULL; i++) {
110         if (selected_item == item)
111             break;
112
113         l = eina_list_next(l);
114         item = (Eext_Object_Item *)eina_list_data_get(l);
115     }
116
117     int length;
118     const Eina_Unicode unicode_event[2] = { emoticon_info[i].code, 0 };
119     char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
120
121     reply_to_sender_by_callback((const char*)utf_8, "emoticon");
122
123     PRINTFUNC(SECURE_DEBUG, "[%d]%s", i, utf_8);
124     if (utf_8)
125         free(utf_8);
126
127         if(ad->reply_type == REPLY_APP_NORMAL)
128             elm_exit();
129 }
130
131 static void _rotary_selector_item_selected(void *data, Evas_Object *obj, void *event_info)
132 {
133     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
134 }
135
136 void ise_show_emoticon_popup_rotary(void *data)
137 {
138     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
139     App_Data* ad = (App_Data*) data;
140     if (!ad)
141         return;
142
143
144     Evas_Object *rotary_selector = eext_rotary_selector_add(ad->naviframe);
145 //    uxt_theme_object_replace_color(rotary_selector, "B01153", "AO0117");
146     PRINTFUNC(DLOG_DEBUG, "replace color");
147     for (int i = 0; i < EMOTICON_CNT; ++i)
148     {
149         Evas_Object *img = NULL;
150         Eext_Object_Item *item = eext_rotary_selector_item_append(rotary_selector);
151
152         img = elm_image_add(rotary_selector);
153         elm_image_file_set(img, get_emoticon_file_name(i), NULL);
154         eext_rotary_selector_item_part_content_set(item, "item,bg_image", EEXT_ROTARY_SELECTOR_ITEM_STATE_NORMAL, img);
155
156         img = elm_image_add(rotary_selector);
157         elm_image_file_set(img, get_emoticon_file_name(i), NULL);
158         eext_rotary_selector_item_part_content_set(item, "selector,icon", EEXT_ROTARY_SELECTOR_ITEM_STATE_NORMAL, img);
159     }
160
161     evas_object_smart_callback_add(rotary_selector, "item,selected", _rotary_selector_item_selected, rotary_selector);
162     evas_object_smart_callback_add(rotary_selector, "item,clicked", _rotary_selector_item_clicked, (void*)ad);
163
164     Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, rotary_selector, "empty");
165     elm_naviframe_item_pop_cb_set(nf_item, _custom_back_cb, NULL);
166     eext_rotary_object_event_activated_set(rotary_selector, EINA_TRUE);
167
168     PRINTFUNC(DLOG_DEBUG, "%s", __func__);
169 }