summaryrefslogtreecommitdiff
path: root/lib/details/ct-input-change-name.c
blob: 020907987c299d19f2684f19cec16657b22e17ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright 2012 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (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);

}