Fix memory leak
[platform/core/uifw/inputdelegator.git] / src / w-input-keyboard.cpp
index 7fe4860..5e9ae09 100755 (executable)
@@ -34,7 +34,9 @@ bool input_keyboard_init(app_control_h app_control)
        int ret = -1;
        char *default_text = NULL;
        char *guide_text = NULL;
-       char *return_key_type = NULL;
+       char *return_key_type = _("IDS_AMEMO_BUTTON_SEND");
+       char *max_text_length = NULL;
+       char *cursor_position_set = NULL;
 
        input_keyboard_deinit();
 
@@ -50,6 +52,16 @@ bool input_keyboard_init(app_control_h app_control)
        if (ret == APP_CONTROL_ERROR_NONE) {
                g_input_keyboard_data.return_key_type = return_key_type;
        }
+       ret = app_control_get_extra_data(app_control, "max_text_length", &max_text_length);
+       if (ret == APP_CONTROL_ERROR_NONE) {
+               g_input_keyboard_data.max_text_length = atoi(max_text_length);
+               free(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);
+               free(cursor_position_set);
+       }
 
        return true;
 }
@@ -67,7 +79,9 @@ void input_keyboard_deinit(void)
 
        g_input_keyboard_data.default_text = NULL;
        g_input_keyboard_data.guide_text = NULL;
-       g_input_keyboard_data.return_key_type = NULL;
+       g_input_keyboard_data.return_key_type = _("IDS_AMEMO_BUTTON_SEND");
+       g_input_keyboard_data.max_text_length = KEYBOARD_EDITOR_CHAR_COUNT_MAX;
+       g_input_keyboard_data.cursor_position_set = 0;
 
        return;
 }
@@ -82,7 +96,10 @@ void exit_keyboard()
        }
 
        const char *getText = elm_entry_entry_get(entry);
-       LOGD("button key clicked!! : getText = %s", getText);
+       SECURE_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);
@@ -91,9 +108,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)
@@ -110,6 +126,10 @@ static Eina_Bool custom_back_cb(void *data, Elm_Object_Item *it)
 static void maxlength_cb(void *data, Evas_Object *obj, void *event_info)
 {
        LOGD("maxlength_cb : size = %d", KEYBOARD_EDITOR_CHAR_COUNT_MAX);
+       char text[512];
+       const char *guide = _(MAX_TEXT_LENGTH_REACH);
+       snprintf(text, sizeof(text), guide, g_input_keyboard_data.max_text_length);
+       show_popup_toast((const char *)text, false);
 }
 
 static void enter_keydown_cb(void *data, Evas_Object *obj, void *event_info)
@@ -141,7 +161,7 @@ void create_fullscreen_editor(void *data)
        entry = elm_entry_add(box);
 
        static Elm_Entry_Filter_Limit_Size limit_filter_data;
-       limit_filter_data.max_char_count = KEYBOARD_EDITOR_CHAR_COUNT_MAX;
+       limit_filter_data.max_char_count = g_input_keyboard_data.max_text_length;
        elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
        evas_object_smart_callback_add(entry, "maxlength,reached", maxlength_cb, data);
 
@@ -157,11 +177,14 @@ 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);
 
        Evas_Object *btn = elm_button_add(box);
-       elm_object_text_set(btn, "SEND");
+       elm_object_text_set(btn, g_input_keyboard_data.return_key_type);
        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.5);
        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
        evas_object_smart_callback_add(btn, "clicked", btn_clicked_cb, NULL);
@@ -205,7 +228,7 @@ static Evas_Object *create_multiline_editfield_layout(Evas_Object *parent, void
 
        entry = elm_entry_add(editfield);
        static Elm_Entry_Filter_Limit_Size limit_filter_data;
-       limit_filter_data.max_char_count = KEYBOARD_EDITOR_CHAR_COUNT_MAX;
+       limit_filter_data.max_char_count = g_input_keyboard_data.max_text_length;
        elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
        evas_object_smart_callback_add(entry, "maxlength,reached", maxlength_cb, data);
 
@@ -220,6 +243,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);