diff options
Diffstat (limited to 'lib/details/ct-input-change-name.c')
-rwxr-xr-x | lib/details/ct-input-change-name.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/lib/details/ct-input-change-name.c b/lib/details/ct-input-change-name.c new file mode 100755 index 0000000..8bd67ac --- /dev/null +++ b/lib/details/ct-input-change-name.c @@ -0,0 +1,167 @@ +/*
+* Copyright 2012 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#include "phone.h"
+#include "ct-input-change-name.h"
+
+typedef struct {
+ Evas_Object *navi;
+ Elm_Object_Item *name_item;
+ Elm_Object_Item *navi_it;
+ ct_change_name_cb change_name_cb;
+ void *cb_data;
+} ct_input_change_name_data;
+
+static void input_change_name_cancel_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ ct_input_change_name_data *changename_d = data;
+ elm_naviframe_item_pop(changename_d->navi);
+}
+
+static void input_change_name_save_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ char *name = NULL;
+ ct_input_change_name_data *changename_d = data;
+ Evas_Object *editfield = NULL;
+ Evas_Object *entry = NULL;
+
+ p_retm_if(NULL == changename_d, "parameter(changename_d) is NULL");
+
+ if (changename_d->change_name_cb) {
+ editfield = elm_object_item_part_content_get(changename_d->name_item, "elm.icon");
+ p_retm_if(NULL == changename_d, "elm_object_part_content_get() return NULL");
+ entry = elm_object_part_content_get(editfield, "elm.swallow.content");
+ p_retm_if(NULL == changename_d, "elm_object_part_content_get() return NULL");
+
+ name = ctui_entry_markup_to_utf8(elm_entry_entry_get(entry));
+ changename_d->change_name_cb(changename_d->cb_data, name);
+ free(name);
+ }
+ elm_naviframe_item_pop(changename_d->navi);
+}
+
+static void input_change_name_entry_changed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ char *text;
+ ct_input_change_name_data *changename_d = data;
+
+ text = ctui_entry_markup_to_utf8(elm_entry_entry_get(obj));
+ p_retm_if(NULL == text, "ctui_entry_markup_to_utf8() return NULL");
+
+ if (*text)
+ ctui_navi_left_btn_disabled_set(changename_d->navi_it, EINA_FALSE);
+ else
+ ctui_navi_left_btn_disabled_set(changename_d->navi_it, EINA_TRUE);
+ free(text);
+}
+
+static Evas_Object* input_change_name_gl_content_get(void *data, Evas_Object *obj, const char *part)
+{
+ static Elm_Entry_Filter_Limit_Size limit_filter_data;
+ Evas_Object *edit_field = NULL;
+ Evas_Object *entry = NULL;
+ ct_input_change_name_data *changename_d = data;
+
+ edit_field = ctui_create_editfield(obj, NULL, NULL, false);
+
+ entry = elm_object_part_content_get(edit_field, "elm.swallow.content");
+ elm_object_signal_emit(edit_field, "elm,state,guidetext,hide", "elm");
+
+ limit_filter_data.max_char_count = CT_EDITFIELD_MAX_CHAR;
+ elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
+ evas_object_smart_callback_add(entry, "changed", input_change_name_entry_changed_cb, changename_d);
+ evas_object_smart_callback_add(entry, "preedit,changed", input_change_name_entry_changed_cb, changename_d);
+
+ evas_object_show(entry);
+ elm_object_focus_set(entry, EINA_TRUE);
+ elm_entry_cursor_end_set(entry);
+
+ return edit_field;
+}
+
+static void __input_change_name_item_gl_sel(void *data, Evas_Object *obj, void *event_info)
+{
+ Elm_Object_Item *item = event_info;
+ p_retm_if(NULL == item, "parameter(item) is NULL");
+ elm_genlist_item_selected_set(item, EINA_FALSE);
+}
+
+static Elm_Genlist_Item_Class itc_change_name = { .item_style="dialogue/1icon", .func.content_get=input_change_name_gl_content_get };
+
+static Evas_Object* input_change_name_create_view(ct_input_change_name_data *changename_d)
+{
+ Evas_Object *base, *bg;
+ Evas_Object *genlist;
+
+ base = phone_create_base_layout(changename_d->navi, false);
+ bg = phone_create_bg(base);
+ if (NULL == bg) {
+ ERR("phone_create_bg() return NULL");
+ evas_object_del(base);
+ return NULL;
+ }
+ elm_object_style_set(bg, "group_list");
+
+ genlist = elm_genlist_add(base);
+ changename_d->name_item = elm_genlist_item_append(genlist, &itc_change_name, changename_d, NULL, ELM_GENLIST_ITEM_NONE, __input_change_name_item_gl_sel, NULL);
+ elm_genlist_item_select_mode_set(changename_d->name_item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
+
+ elm_object_part_content_set(base, "elm.swallow.content", genlist);
+
+ return base;
+}
+
+static void input_change_name_del(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ ct_input_change_name_data *changename_d = data;
+ free(changename_d);
+}
+
+void ct_input_change_name_view(Evas_Object *navi, ct_change_name_cb cb, void *cb_data)
+{
+ Evas_Object *layout;
+ Evas_Object *l_btn;
+ Evas_Object *r_btn;
+ ct_input_change_name_data *changename_d;
+
+ changename_d = calloc(1, sizeof(ct_input_change_name_data));
+ p_retm_if(NULL == changename_d, "calloc() return NULL");
+ changename_d->navi = navi;
+ changename_d->change_name_cb = cb;
+ changename_d->cb_data = cb_data;
+
+ layout = input_change_name_create_view(changename_d);
+ if (NULL == layout) {
+ ERR("input_change_name_create_view() return NULL");
+ free(changename_d);
+ return;
+ }
+ evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, input_change_name_del, changename_d);
+
+ changename_d->navi_it = elm_naviframe_item_push(navi, T_(CT_GET_TEXT_BASIC, CTTEXT_CUSTOM), NULL, NULL, layout, NULL);
+
+ l_btn = phone_create_navi_btn(navi, "plus");
+ evas_object_smart_callback_add(l_btn, "clicked", input_change_name_save_cb, changename_d);
+ elm_object_item_part_content_set(changename_d->navi_it, "title_left_btn", l_btn);
+ ctui_navi_left_btn_disabled_set(changename_d->navi_it, EINA_TRUE);
+
+ r_btn = phone_create_navi_btn(navi, "naviframe/prev_btn/default");
+ evas_object_smart_callback_add(r_btn, "clicked", input_change_name_cancel_cb, changename_d);
+ elm_object_item_part_content_set(changename_d->navi_it, "title_right_btn", r_btn);
+
+}
+
|