1 #include <Elementary.h>
5 * @defgroup Searchbar Searchbar
9 * It can contain a simple entry and button object.
12 typedef struct _Widget_Data Widget_Data;
16 Evas_Object *base, *eb, *cancel_btn;
17 Eina_Bool cancel_btn_ani_flag;
20 static void _del_hook(Evas_Object *obj);
21 static void _theme_hook(Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23 static void _clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
24 static void _changed(void *data, Evas_Object *obj, const char *emission, const char *source);
25 static void _cancel_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
26 static void _signal_reset_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
28 static void _del_hook(Evas_Object *obj)
30 Widget_Data *wd = elm_widget_data_get(obj);
37 static void _theme_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
42 _elm_theme_object_set(obj, wd->base, "searchbar", "base", elm_widget_style_get(obj));
45 edje_object_part_swallow(wd->base, "btn_text", wd->eb);
47 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
49 edje_object_signal_callback_add(wd->base, "elm,action,click", "", _signal_reset_clicked, obj);
51 edje_object_scale_set(wd->cancel_btn, elm_widget_scale_get(obj) * _elm_config->scale);
55 static void _sizing_eval(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
58 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
61 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
62 edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
63 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
64 evas_object_size_hint_min_set(obj, minw, minh);
65 evas_object_size_hint_max_set(obj, maxw, maxh);
68 static void _clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
70 Widget_Data *wd = elm_widget_data_get(data);
73 elm_entry_cursor_end_set(wd->eb);
74 if (wd->cancel_btn_ani_flag == EINA_TRUE)
75 edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
77 edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
79 evas_object_smart_callback_call(data, "clicked", NULL);
82 static void _changed(void *data, Evas_Object *obj, const char *emission, const char *source)
84 Widget_Data *wd = elm_widget_data_get(data);
88 const char* text = elm_entry_entry_get(wd->eb);
94 edje_object_signal_emit(wd->base, "RESETHIDE", "PROG");
96 edje_object_signal_emit(wd->base, "RESETSHOW", "PROG");
101 edje_object_signal_emit(wd->base, "RESETHIDE", "PROG");
104 evas_object_smart_callback_call(data, "changed", NULL);
107 static void _cancel_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
109 Widget_Data *wd = elm_widget_data_get(data);
112 if (wd->cancel_btn_ani_flag == EINA_TRUE)
113 edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
115 edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
119 text = elm_entry_entry_get(wd->eb);
120 if (text != NULL && strlen(text) > 0)
121 elm_entry_entry_set(wd->eb, NULL);
123 evas_object_smart_callback_call(data, "cancel,clicked", NULL);
126 static void _signal_reset_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
128 Widget_Data *wd = elm_widget_data_get(data);
130 elm_entry_entry_set(wd->eb, NULL);
134 * Add a new searchbar to the parent
135 * @param parent The parent object
136 * @return The new object or NULL if it cannot be created
140 EAPI Evas_Object *elm_searchbar_add(Evas_Object *parent)
147 wd = ELM_NEW(Widget_Data);
148 e = evas_object_evas_get(parent);
149 if (e == NULL) return NULL;
150 obj = elm_widget_add(e);
151 if (obj == NULL) return NULL;
152 elm_widget_type_set(obj, "searchbar");
153 elm_widget_sub_object_add(parent, obj);
154 elm_widget_data_set(obj, wd);
155 elm_widget_del_hook_set(obj, _del_hook);
156 elm_widget_theme_hook_set(obj, _theme_hook);
157 elm_widget_can_focus_set(obj, 1 );
159 wd->base = edje_object_add(e);
160 if (wd->base == NULL) return NULL;
162 _elm_theme_object_set(obj, wd->base, "searchbar", "base", "default");
164 // evas_object_size_hint_weight_set(wd->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
165 // evas_object_size_hint_align_set(wd->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
168 wd->eb = elm_entry_add(parent);
169 edje_object_part_swallow(wd->base, "btn_text", wd->eb);
170 // elm_object_style_set(wd->eb, "search_input");
171 elm_entry_single_line_set(wd->eb, EINA_TRUE);
172 evas_object_smart_callback_add(wd->eb, "clicked", _clicked, obj);
173 evas_object_smart_callback_add(wd->eb, "changed", _changed, obj);
174 elm_widget_sub_object_add(obj, wd->eb);
177 wd->cancel_btn = elm_button_add(parent);
178 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
179 elm_object_style_set(wd->cancel_btn, "custom/darkblue");
180 elm_button_label_set(wd->cancel_btn, "Cancel");
181 evas_object_smart_callback_add(wd->cancel_btn, "clicked", _cancel_clicked, obj);
182 elm_widget_sub_object_add(obj, wd->cancel_btn);
184 wd->cancel_btn_ani_flag = EINA_FALSE;
186 edje_object_signal_callback_add(wd->base, "elm,action,click", "", _signal_reset_clicked, obj);
188 elm_widget_resize_object_set(obj, wd->base);
196 * get the text of entry
198 * @param obj The entry object
199 * @return The title of entry
203 EAPI void elm_searchbar_text_set(Evas_Object *obj, const char *entry)
205 Widget_Data *wd = elm_widget_data_get(obj);
206 if (!wd) return NULL;
208 elm_entry_entry_set(wd->eb, entry);
212 * get the text of entry
214 * @param obj The entry object
215 * @return The title of entry
219 EAPI const char* elm_searchbar_text_get(Evas_Object *obj)
221 Widget_Data *wd = elm_widget_data_get(obj);
222 if (!wd) return NULL;
224 return elm_entry_entry_get(wd->eb);
228 * get the pointer of entry
230 * @param obj The entry object
231 * @return The title of entry
235 EAPI Evas_Object *elm_searchbar_entry_get(Evas_Object *obj)
237 Widget_Data *wd = elm_widget_data_get(obj);
238 if (!wd) return NULL;
244 * get the pointer of entry
246 * @param obj The entry object
247 * @return The title of entry
251 EAPI void elm_searchbar_cancel_button_animation_set(Evas_Object *obj, Eina_Bool cancel_btn_ani_flag)
253 Widget_Data *wd = elm_widget_data_get(obj);
256 if (cancel_btn_ani_flag == EINA_TRUE)
257 wd->cancel_btn_ani_flag = EINA_TRUE;
259 wd->cancel_btn_ani_flag = EINA_FALSE;