Support API for set/get cursor position
[platform/core/uifw/inputdelegator.git] / src / w-input-emoticon.cpp
index 8ad6c45..d94c553 100755 (executable)
  * limitations under the License.
  */
 
+#include <app.h>
 #include <app_preference.h>
 #include <Elementary.h>
 #include <string>
 #include <vector>
+#include <stdint.h>
 
 #include <vconf.h>
 #include <vconf-keys.h>
@@ -47,6 +49,7 @@ typedef struct {
 static Elm_Object_Item *it_emoticon_empty = NULL;
 static Elm_Object_Item *it_emoticon_recent_group = NULL;
 static Elm_Object_Item *it_emoticon_emoji_group = NULL;
+static Elm_Object_Item* it_drawing = NULL;
 static Elm_Object_Item *it_last = NULL;
 
 static Elm_Genlist_Item_Class *itc_emoticon = NULL;
@@ -70,6 +73,7 @@ typedef struct emoticon_content
 } emoticon_content_s;
 
 static emoticon_content_s emoticon_contents_pool[EMOTICON_CNT] = { 0, };
+static emoticon_content_s emoticon_drawing_pool = { 0, };
 static emoticon_content_s emoticon_recents_pool[RECENT_CNT] = { 0, };
 
 
@@ -276,6 +280,11 @@ static Eina_Bool _custom_back_cb2(void *data, Elm_Object_Item *it)
             lazy_loading_timer_for_contents = NULL;
         }
 
+        if(emoticon_drawing_pool.used == 0){
+            evas_object_del(emoticon_drawing_pool.content);
+        }
+        emoticon_drawing_pool.content = NULL;
+
         //Recent EMOTICONS : the recent emoiton need to be updated whenever emoticon view is generated, so deleted here.
         for (i=0;i< RECENT_CNT;i++)
         {
@@ -359,11 +368,49 @@ void set_recent_emoticons(vector <int> &emoticon_list, int val)
     if (PREFERENCE_ERROR_NONE != ret) {
         PRINTFUNC(DLOG_ERROR, "preference_set_string error!(%d)", ret);
     }
+
+}
+
+static void _drawing_app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
+{
+    char* path = NULL;
+    app_control_get_extra_data(reply, APP_CONTROL_DATA_PATH, &path);
+
+    if(path){
+        PRINTFUNC(DLOG_DEBUG, "path=%s", path);
+        char *pathes[] = {path, };
+        reply_to_sender_by_callback(NULL, "image", (const char **)pathes, NULL);
+        free(path);
+    }
+    ui_app_exit();
+}
+
+static void _drawing_item_clicked_cb(void *data, Evas_Object * obj, void *event_info)
+{
+    PRINTFUNC(DLOG_DEBUG, "%s", __func__);
+    App_Data* ad = (App_Data*) data;
+    if (!ad)
+        return;
+
+    Elm_Object_Item *item = (Elm_Object_Item *) event_info;
+    if (item)
+        elm_genlist_item_selected_set(item, EINA_FALSE);
+
+    /* launch */
+    app_control_h request = NULL;
+    app_control_create(&request);
+    app_control_set_app_id(request, "org.tizen.sketch");
+
+    int ret = app_control_send_launch_request(request, _drawing_app_control_reply_cb, NULL);
+    if (ret != APP_CONTROL_ERROR_NONE) {
+        PRINTFUNC(DLOG_DEBUG, "error code = 0x%x", ret);
+    }
+    app_control_destroy(request);
 }
 
 static void _emoticon_item_clicked_cb(void *data, Evas_Object * obj, void *event_info)
 {
-    int index = (int)data;
+    int index = (uintptr_t)data;
 
     PRINTFUNC(DLOG_DEBUG, "index = %d", index);
 
@@ -371,16 +418,16 @@ static void _emoticon_item_clicked_cb(void *data, Evas_Object * obj, void *event
     set_recent_emoticons(recent_emoji_list, index);
 
     int length;
-    const Eina_Unicode unicode_event[2] = { (unsigned int)emoticon_info[index].code, 0 };
+    const Eina_Unicode unicode_event[2] = { (Eina_Unicode)emoticon_info[index].code, 0 };
     char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
 
-    reply_to_sender_by_callback((const char*)utf_8, "emoticon");
+    reply_to_sender_by_callback((const char*)utf_8, "emoticon", NULL, NULL);
 
     PRINTFUNC(SECURE_DEBUG, "[%d]%s", index, utf_8);
     if (utf_8)
         free(utf_8);
 
-    elm_exit();
+    ui_app_exit();
 }
 
 Evas_Object* get_emoticon_button(Evas_Object* parent, int index){
@@ -393,7 +440,7 @@ Evas_Object* get_emoticon_button(Evas_Object* parent, int index){
      evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
      int length;
-     const Eina_Unicode unicode_event[2] = { (unsigned int)emoticon_info[index].code, 0 };
+     const Eina_Unicode unicode_event[2] = { (Eina_Unicode)emoticon_info[index].code, 0 };
      char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
      elm_object_part_text_set(btn, "elm.text", utf_8);
 
@@ -402,7 +449,7 @@ Evas_Object* get_emoticon_button(Evas_Object* parent, int index){
 
      evas_object_layer_set(btn, 32000);
 
-     evas_object_smart_callback_add(btn, "clicked", _emoticon_item_clicked_cb, (void *)index);
+     evas_object_smart_callback_add(btn, "clicked", _emoticon_item_clicked_cb, (void *)(uintptr_t)index);
 
      return btn;
 }
@@ -417,17 +464,17 @@ Evas_Object* get_recent_emoticon_button(Evas_Object* parent, int index){
      evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
 
      int length;
-     const Eina_Unicode unicode_event[2] = { (unsigned int)emoticon_info[recent_emoji_list.at(index)].code, 0 };
+     const Eina_Unicode unicode_event[2] = { (Eina_Unicode)emoticon_info[recent_emoji_list.at(index)].code, 0 };
      char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
      elm_object_part_text_set(btn, "elm.text", utf_8);
 
-     evas_object_data_set(btn, "index", (void*) recent_emoji_list.at(index));
+     evas_object_data_set(btn, "index", (void*)(uintptr_t) recent_emoji_list.at(index));
 
      if (utf_8)
          free(utf_8);
 
      evas_object_layer_set(btn, 32000);
-     evas_object_smart_callback_add(btn, "clicked", _emoticon_item_clicked_cb, (void*) recent_emoji_list.at(index));
+     evas_object_smart_callback_add(btn, "clicked", _emoticon_item_clicked_cb, (void*)(uintptr_t) recent_emoji_list.at(index));
 
      return btn;
 }
@@ -440,7 +487,6 @@ static void _emoticon_gl_lang_changed(void *data, Evas_Object *obj, void *event_
 static char * __emoticon_gl_text_get(void *data, Evas_Object *obj, const char *part)
 {
     //PRINTFUNC(DLOG_DEBUG,"part = %s", part);
-
     const char* str = (const char*) data;
     if (!str)
         return NULL;
@@ -458,9 +504,9 @@ static void _emoticon_gl_content_unswallowed_cb(void *data, Evas_Object *obj, vo
 
     const Elm_Genlist_Item_Class *itc = elm_genlist_item_item_class_get(it);
 
-//      PRINTFUNC(DLOG_DEBUG,"%s - stype[%s]", __func__, itc->item_style);
+    //PRINTFUNC(DLOG_DEBUG,"%s - stype[%s]", __func__, itc->item_style);
     if (!strcmp(itc->item_style, "3button_flat")) {
-        int index = (int)elm_object_item_data_get(it);
+        int index = (uintptr_t)elm_object_item_data_get(it);
         //PRINTFUNC(DLOG_DEBUG,"it = %p", it);
         PRINTFUNC(DLOG_DEBUG, "index = %d %d %d", index, index+1, index+2);
 
@@ -474,7 +520,7 @@ static void _emoticon_gl_content_unswallowed_cb(void *data, Evas_Object *obj, vo
             emoticon_contents_pool[index+2].used = 0;
         }
     } else if (!strcmp(itc->item_style, "3button_flat_recent")) {
-        unsigned int index = (int)elm_object_item_data_get(it);
+        unsigned int index = (uintptr_t)elm_object_item_data_get(it);
         //PRINTFUNC(DLOG_DEBUG,"index = %d",index);
 
         if (index < recent_emoji_list.size()) {
@@ -486,16 +532,55 @@ static void _emoticon_gl_content_unswallowed_cb(void *data, Evas_Object *obj, vo
         if (index + 2 < recent_emoji_list.size()) {
             emoticon_recents_pool[index+2].used = 0;
         }
+    } else if (it_drawing == it) {
+        //PRINTFUNC(DLOG_DEBUG,"it_drawing = %p", it_drawing);
+        emoticon_drawing_pool.used = 0;
     }
 }
 
+static Evas_Object * __emoticon_gl_1_content_get(void *data, Evas_Object *obj, const char *part)
+{
+    if (!strcmp(part, "elm.icon")) {
+        Evas_Object* btn = elm_button_add(obj);
+        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
+        Evas_Object* ic = elm_image_add(btn);
+        elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
+
+        string path = get_resource_path();
+        if (_WEARABLE)
+            path = path + "wearable/";
+        else if (_TV)
+            path = path + "tv/";
+        else
+            path = path + "mobile/";
+
+        elm_object_style_set(btn, "ime_button_drawing");
+        string path_ic = path + "images/wi_drawing_icon.png";
+        PRINTFUNC(DLOG_DEBUG, "path_ic = %s", path_ic.c_str());
+        elm_image_file_set(ic, path_ic.c_str(), NULL);
+        elm_object_content_set(btn, ic);
+        evas_object_layer_set(btn, 32000);
+
+        emoticon_drawing_pool.index = 0;
+        emoticon_drawing_pool.content = btn;
+        emoticon_drawing_pool.used = 0;
+        return btn;
+    } else if(!strcmp(part, "base")){
+        Evas_Object* btn = elm_button_add(obj);
+        elm_object_style_set(btn, "ime/transparent");
+        return btn;
+    }
+    return NULL;
+}
+
 static Evas_Object * __emoticon_gl_recent_content_get(void *data, Evas_Object *obj, const char *part)
 {
     if (is_content_reuse_on) {
-        unsigned int index = (unsigned int)data;
+        unsigned int index = (uintptr_t)data;
         int new_index = 0;
 
-    //PRINTFUNC(DLOG_DEBUG,"%s %d", part, index);
+        //PRINTFUNC(DLOG_DEBUG,"%s %d", part, index);
         if (!strcmp(part, "elm.icon.1") || (!strcmp(part, "elm.icon.2")) || (!strcmp(part, "elm.icon.3"))) {
             if (!strcmp(part, "elm.icon.1")) {
                 if (index >= recent_emoji_list.size()) return NULL;
@@ -518,10 +603,10 @@ static Evas_Object * __emoticon_gl_recent_content_get(void *data, Evas_Object *o
             return btn;
         }
     } else {
-        unsigned int index = (unsigned int)data;
+        unsigned int index = (uintptr_t)data;
         int new_index = 0;
 
-    //    PRINTFUNC(DLOG_DEBUG,"%s %d", part, index);
+        //PRINTFUNC(DLOG_DEBUG,"%s %d", part, index);
         if (!strcmp(part, "elm.icon.1") || (!strcmp(part, "elm.icon.2")) || (!strcmp(part, "elm.icon.3"))) {
             if (!strcmp(part, "elm.icon.1")) {
                 if (index >= recent_emoji_list.size()) return NULL;
@@ -546,9 +631,8 @@ static Evas_Object * __emoticon_gl_recent_content_get(void *data, Evas_Object *o
 static Evas_Object * __emoticon_gl_emoticon_content_get(void *data, Evas_Object *obj, const char *part)
 {
     //PRINTFUNC(DLOG_DEBUG,"%s", __func__);
-
     if (is_content_reuse_on) {
-        int index = (int)data;
+        int index = (uintptr_t)data;
         int new_index = 0;
 
         if (!strcmp(part, "elm.icon.1") || (!strcmp(part, "elm.icon.2")) || (!strcmp(part, "elm.icon.3"))) {
@@ -572,10 +656,10 @@ static Evas_Object * __emoticon_gl_emoticon_content_get(void *data, Evas_Object
             elm_object_part_text_set(btn, "elm.text", strdup(utf_8));
 #else
             int length;
-            const Eina_Unicode unicode_event[2] = { (unsigned int)emoticon_info[new_index].code, 0 };
+            const Eina_Unicode unicode_event[2] = { (Eina_Unicode)emoticon_info[new_index].code, 0 };
             char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
             elm_object_part_text_set(btn, "elm.text", utf_8);
-            evas_object_data_set(btn, "index", (void*)new_index);
+            evas_object_data_set(btn, "index", (void*)(uintptr_t)new_index);
 
             if (utf_8)
                 free(utf_8);
@@ -588,7 +672,7 @@ static Evas_Object * __emoticon_gl_emoticon_content_get(void *data, Evas_Object
             return btn;
         }
     } else {
-        int index = (int)data;
+        int index = (uintptr_t)data;
         int new_index = 0;
 
         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2")) ||  (!strcmp(part, "elm.icon.3"))) {
@@ -612,7 +696,6 @@ static Evas_Object * __emoticon_gl_emoticon_content_get(void *data, Evas_Object
     return NULL;
 }
 
-
 void _create_reusable_recents(Evas_Object *parent)
 {
     if (!parent) {
@@ -722,7 +805,7 @@ static Eina_Bool _lazy_loader_cb_for_items(void *data)
     int i;
     for (i = loading_done_for_item; i < loading_top; i++ ) {
         if (i%3 == 0)
-            elm_genlist_item_append(gl, itc_emoticon, (void*)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)i);
+            elm_genlist_item_append(gl, itc_emoticon, (void*)(uintptr_t)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)(uintptr_t)i);
     }
 
     loading_done_for_item = loading_top;
@@ -739,7 +822,7 @@ void _create_reusable_contents(Evas_Object *gl){
 
     for (i = 0; i < INITAL_ITEM_UNIT; i++ ) {
         if (i%3 == 0)
-            elm_genlist_item_append(gl, itc_emoticon, (void*)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)i);
+            elm_genlist_item_append(gl, itc_emoticon, (void*)(uintptr_t)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)(uintptr_t)i);
     }
 
     lazy_loading_timer_for_items = ecore_timer_add(0.1, _lazy_loader_cb_for_items, (void *)gl);
@@ -756,16 +839,20 @@ Evas_Object* _create_emoticon_genlist(void* data)
     if (NULL == genlist)
         return NULL;
 
-    Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, ad->circle_surface);
-    eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
-    evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
-    eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
-
+    if (_WEARABLE) {
+        Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, ad->circle_surface);
+        eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+        evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
+        eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
+    }
     evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
     evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
     evas_object_show(genlist);
 
-    Elm_Object_Item *nf_emoticon_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, genlist, "empty");
+    const char *item_style = NULL;
+    if (_WEARABLE)
+        item_style = "empty";
+    Elm_Object_Item *nf_emoticon_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, genlist, item_style);
 
     elm_naviframe_item_pop_cb_set(nf_emoticon_item, _custom_back_cb2, ad);
 
@@ -796,8 +883,17 @@ void _update_emoticon_items(void *data)
     itc_dummy->func.state_get = NULL;
     itc_dummy->func.del = NULL;
 
-    Elm_Genlist_Item_Class *itc_group = elm_genlist_item_class_new();
+    Elm_Genlist_Item_Class *itc_1text_1icon = NULL;
+    if (app_data->mime_type == MIME_TYPE_ALL) {
+        itc_1text_1icon = elm_genlist_item_class_new();
+        itc_1text_1icon->item_style = "drawing";
+        itc_1text_1icon->func.text_get = __emoticon_gl_text_get;
+        itc_1text_1icon->func.content_get = __emoticon_gl_1_content_get;
+        itc_1text_1icon->func.state_get = NULL;
+        itc_1text_1icon->func.del = NULL;
+    }
 
+    Elm_Genlist_Item_Class *itc_group = elm_genlist_item_class_new();
     itc_group->item_style = "groupindex";
     itc_group->func.text_get = __emoticon_gl_text_get;
     itc_group->func.content_get = NULL;
@@ -805,9 +901,6 @@ void _update_emoticon_items(void *data)
     itc_group->func.del = NULL;
 
     Elm_Genlist_Item_Class *itc_recent = elm_genlist_item_class_new();
-    if (is_content_reuse_on) {
-//        itc_recent->content_reusable = EINA_TRUE;
-    }
     itc_recent->item_style = "3button_flat_recent";
     itc_recent->func.text_get = NULL;
     itc_recent->func.content_get = __emoticon_gl_recent_content_get;
@@ -815,9 +908,6 @@ void _update_emoticon_items(void *data)
     itc_recent->func.del = NULL;
 
     itc_emoticon = elm_genlist_item_class_new();
-    if (is_content_reuse_on) {
-//        itc_emoticon->content_reusable = EINA_TRUE;
-    }
     itc_emoticon->item_style = "3button_flat";
     itc_emoticon->func.text_get = NULL;
     itc_emoticon->func.content_get = __emoticon_gl_emoticon_content_get;
@@ -827,6 +917,12 @@ void _update_emoticon_items(void *data)
     // dummy title for empty space
     it_emoticon_empty = elm_genlist_item_append(gl, itc_dummy, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
 
+    // Drawing
+    if (app_data->mime_type == MIME_TYPE_ALL) {
+        it_drawing = elm_genlist_item_append(gl, itc_1text_1icon, "Doodle", NULL, ELM_GENLIST_ITEM_NONE, _drawing_item_clicked_cb, (void *)app_data);
+        first_it = it_drawing;
+    }
+
     if (recent_emoji_list.size() > 0) {
         if (is_content_reuse_on) {
             _create_reusable_recents(gl);
@@ -842,7 +938,7 @@ void _update_emoticon_items(void *data)
 
         for (i=0;i < recent_emoji_list.size();i=i+3)
         {
-            it = elm_genlist_item_append(gl, itc_recent, (void*)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)i);
+            it = elm_genlist_item_append(gl, itc_recent, (void*)(uintptr_t)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)(uintptr_t)i);
         }
     }
 
@@ -857,7 +953,7 @@ void _update_emoticon_items(void *data)
     } else {
         // Emoticons
         for (i=0;i< EMOTICON_CNT;i=i+3) {
-            it = elm_genlist_item_append(gl, itc_emoticon, (void*)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)i);
+            it = elm_genlist_item_append(gl, itc_emoticon, (void*)(uintptr_t)i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)(uintptr_t)i);
             it_last = it;
         }
         elm_genlist_item_class_free(itc_emoticon);
@@ -871,6 +967,7 @@ void _update_emoticon_items(void *data)
 
     elm_genlist_item_class_free(itc_recent);
     elm_genlist_item_class_free(itc_group);
+    elm_genlist_item_class_free(itc_1text_1icon);
     elm_genlist_item_class_free(itc_dummy);
 }
 
@@ -883,6 +980,7 @@ void ise_show_emoticon_list(void *data)
     it_emoticon_empty = NULL;
     it_emoticon_recent_group = NULL;
     it_emoticon_emoji_group = NULL;
+    it_drawing = NULL;
     it_last = NULL;
 
     get_recent_emoticons(recent_emoji_list);
@@ -896,3 +994,12 @@ void ise_show_emoticon_list(void *data)
     }
     _update_emoticon_items(emoticon_list);
 }
+
+void launch_drawing_app(void *data)
+{
+    App_Data* ad = (App_Data*) data;
+    if (!ad)
+        return;
+
+    _drawing_item_clicked_cb(ad, NULL, NULL);
+}