Support API for set/get cursor position
[platform/core/uifw/inputdelegator.git] / src / w-input-keyboard.cpp
index cd6356f..ba9a217 100755 (executable)
@@ -36,6 +36,7 @@ bool input_keyboard_init(app_control_h app_control)
        char *guide_text = NULL;
        char *return_key_type = "SEND";
        char *max_text_length = NULL;
+       char *cursor_position_set = "0";
 
        input_keyboard_deinit();
 
@@ -55,6 +56,10 @@ bool input_keyboard_init(app_control_h app_control)
        if (ret == APP_CONTROL_ERROR_NONE) {
                g_input_keyboard_data.max_text_length = atoi(max_text_length);
        }
+       ret = app_control_get_extra_data(app_control, "cursor_position_set", &cursor_position_set);
+       if (ret == APP_CONTROL_ERROR_NONE) {
+               g_input_keyboard_data.cursor_position_set = atoi(cursor_position_set);
+       }
 
        return true;
 }
@@ -74,6 +79,7 @@ void input_keyboard_deinit(void)
        g_input_keyboard_data.guide_text = NULL;
        g_input_keyboard_data.return_key_type = "SEND";
        g_input_keyboard_data.max_text_length = KEYBOARD_EDITOR_CHAR_COUNT_MAX;
+       g_input_keyboard_data.cursor_position_set = 0;
 
        return;
 }
@@ -90,6 +96,9 @@ void exit_keyboard()
        const char *getText = elm_entry_entry_get(entry);
        LOGD("button key clicked!! : getText = %s", getText);
 
+       char cursorPosition[512];
+       snprintf(cursorPosition, sizeof(cursorPosition), "%d", elm_entry_cursor_pos_get(entry));
+
        char *app_id = NULL;
        app_control_get_caller(app_data->source_app_control, &app_id);
        if (app_id != NULL)
@@ -97,9 +106,8 @@ void exit_keyboard()
        app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
        set_source_caller_app_id(app_control);
        free(app_id);
-       reply_to_sender_by_callback(getText, "keyboard", NULL);
+       reply_to_sender_by_callback(getText, "keyboard", NULL, cursorPosition);
        ui_app_exit();
-
 }
 
 void btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
@@ -166,6 +174,9 @@ void create_fullscreen_editor(void *data)
                elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
                evas_object_smart_callback_add(entry, "activated", enter_keydown_cb, ad);
        }
+       if (g_input_keyboard_data.cursor_position_set != 0) {
+               elm_entry_cursor_pos_set(entry, g_input_keyboard_data.cursor_position_set);
+       }
        evas_object_show(entry);
        elm_box_pack_end(box, entry);
 
@@ -229,6 +240,9 @@ static Evas_Object *create_multiline_editfield_layout(Evas_Object *parent, void
                elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
                evas_object_smart_callback_add(entry, "activated", enter_keydown_cb, ad);
        }
+       if (g_input_keyboard_data.cursor_position_set != 0) {
+               elm_entry_cursor_pos_set(entry, g_input_keyboard_data.cursor_position_set);
+       }
 
        evas_object_show(entry);
        elm_object_part_content_set(editfield, "elm.swallow.content", entry);