2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include <Elementary.h>
8 * @defgroup Searchbar Searchbar
12 * It can contain a simple entry and button object.
15 typedef struct _Widget_Data Widget_Data;
19 Evas_Object *base, *eb, *cancel_btn;
20 Eina_Bool cancel_btn_ani_flag;
21 Eina_Bool cancel_btn_show_mode;
22 Eina_Bool boundary_mode;
25 static void _del_hook(Evas_Object *obj);
26 static void _theme_hook(Evas_Object *obj);
27 static void _on_focus_hook(void *data, Evas_Object *obj);
28 static void _sizing_eval(Evas_Object *obj);
29 static void _clicked(void *data, Evas_Object *obj, void *event_info);
30 static void _changed(void *data, Evas_Object *obj, void *event_info);
31 static void _cancel_clicked(void *data, Evas_Object *obj, void *event_info);
33 static void _del_hook(Evas_Object *obj)
35 Widget_Data *wd = elm_widget_data_get(obj);
42 static void _theme_hook(Evas_Object *obj)
44 Widget_Data *wd = elm_widget_data_get(obj);
47 _elm_theme_object_set(obj, wd->base, "searchbar", "base", elm_widget_style_get(obj));
50 edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
52 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
54 edje_object_scale_set(wd->cancel_btn, elm_widget_scale_get(obj) * _elm_config->scale);
59 _on_focus_hook(void *data, Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
64 if (elm_widget_focus_get(obj))
66 if (wd->cancel_btn_show_mode)
68 if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
69 else edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
74 static void _sizing_eval(Evas_Object *obj)
76 Widget_Data *wd = elm_widget_data_get(obj);
77 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
80 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
81 edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
82 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
83 evas_object_size_hint_min_set(obj, minw, minh);
84 evas_object_size_hint_max_set(obj, maxw, maxh);
87 static void _clicked(void *data, Evas_Object *obj, void *event_info)
89 Widget_Data *wd = elm_widget_data_get(data);
92 if (wd->cancel_btn_show_mode)
94 if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
95 else edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
98 evas_object_smart_callback_call(data, "clicked", NULL);
101 static void _changed(void *data, Evas_Object *obj, void *event_info)
103 Widget_Data *wd = elm_widget_data_get(data);
107 // TODO : inform to use entry changed callback
108 // evas_object_smart_callback_call(data, "changed", NULL);
111 static void _cancel_clicked(void *data, Evas_Object *obj, void *event_info)
113 Widget_Data *wd = elm_widget_data_get(data);
116 if (wd->cancel_btn_show_mode)
118 if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
119 else edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
123 text = elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
124 if (text != NULL && strlen(text) > 0) elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
126 evas_object_smart_callback_call(data, "cancel,clicked", NULL);
130 _searchicon_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
132 Widget_Data *wd = elm_widget_data_get(data);
135 if (!strcmp(source, "search_icon"))
136 evas_object_smart_callback_call(data, "searchsymbol,clicked", NULL);
137 else if (!strcmp(source, "base_bg"))
138 _clicked(data, obj, NULL); //emission, source);
142 * Add a new searchbar to the parent
143 * @param parent The parent object
144 * @return The new object or NULL if it cannot be created
148 EAPI Evas_Object *elm_searchbar_add(Evas_Object *parent)
154 wd = ELM_NEW(Widget_Data);
155 e = evas_object_evas_get(parent);
156 if (e == NULL) return NULL;
157 obj = elm_widget_add(e);
158 if (obj == NULL) return NULL;
159 elm_widget_type_set(obj, "searchbar");
160 elm_widget_sub_object_add(parent, obj);
161 elm_widget_data_set(obj, wd);
162 elm_widget_del_hook_set(obj, _del_hook);
163 elm_widget_theme_hook_set(obj, _theme_hook);
164 elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
165 elm_widget_can_focus_set(obj, 1 );
167 wd->base = edje_object_add(e);
168 if (wd->base == NULL) return NULL;
170 _elm_theme_object_set(obj, wd->base, "searchbar", "base", "default");
172 // evas_object_size_hint_weight_set(wd->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
173 // evas_object_size_hint_align_set(wd->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
176 wd->eb = elm_editfield_add(parent);
177 elm_object_style_set(wd->eb, "searchbar");
178 edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
179 // elm_editfield_guide_text_set(wd->eb, "Search");
180 elm_editfield_entry_single_line_set(wd->eb, EINA_TRUE);
181 elm_editfield_eraser_set(wd->eb, EINA_TRUE);
182 evas_object_smart_callback_add(wd->eb, "clicked", _clicked, obj);
183 evas_object_smart_callback_add(elm_editfield_entry_get(wd->eb), "changed", _changed, obj);
184 edje_object_signal_callback_add(wd->base, "mouse,up,1", "*", _searchicon_clicked, obj);
186 elm_widget_sub_object_add(obj, wd->eb);
189 wd->cancel_btn = elm_button_add(parent);
190 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
191 elm_object_style_set(wd->cancel_btn, "custom/darkblue");
192 elm_button_label_set(wd->cancel_btn, "Cancel");
193 evas_object_smart_callback_add(wd->cancel_btn, "clicked", _cancel_clicked, obj);
194 elm_widget_sub_object_add(obj, wd->cancel_btn);
196 wd->cancel_btn_ani_flag = EINA_FALSE;
197 wd->cancel_btn_show_mode = EINA_TRUE;
198 wd->boundary_mode = EINA_TRUE;
200 elm_widget_resize_object_set(obj, wd->base);
208 * set the text of entry
210 * @param obj The searchbar object
215 EAPI void elm_searchbar_text_set(Evas_Object *obj, const char *entry)
217 Widget_Data *wd = elm_widget_data_get(obj);
220 elm_entry_entry_set(elm_editfield_entry_get(wd->eb), entry);
224 * get the text of entry
226 * @param obj The searchbar object
227 * @return string pointer of entry
231 EAPI const char* elm_searchbar_text_get(Evas_Object *obj)
233 Widget_Data *wd = elm_widget_data_get(obj);
234 if (!wd) return NULL;
236 return elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
240 * get the pointer of entry
242 * @param obj The searchbar object
243 * @return the entry object
247 EAPI Evas_Object *elm_searchbar_entry_get(Evas_Object *obj)
249 Widget_Data *wd = elm_widget_data_get(obj);
250 if (!wd) return NULL;
252 return elm_editfield_entry_get(wd->eb);
256 * set the cancel button animation flag
258 * @param obj The searchbar object
259 * @param cancel_btn_ani_flag The flag of animating cancen button or not
264 EAPI void elm_searchbar_cancel_button_animation_set(Evas_Object *obj, Eina_Bool cancel_btn_ani_flag)
266 Widget_Data *wd = elm_widget_data_get(obj);
269 if (wd->cancel_btn_ani_flag == cancel_btn_ani_flag) return;
270 else wd->cancel_btn_ani_flag = cancel_btn_ani_flag;
274 * set the cancel button show mode
276 * @param obj The searchbar object
277 * @param visible The flag of cancen button show or not
282 EAPI void elm_searchbar_cancel_button_set(Evas_Object *obj, Eina_Bool visible)
284 Widget_Data *wd = elm_widget_data_get(obj);
287 if (wd->cancel_btn_show_mode == visible) return;
288 else wd->cancel_btn_show_mode = visible;
292 if (wd->cancel_btn_ani_flag)
293 edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
295 edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
301 * clear searchbar status
303 * @param obj The searchbar object
308 EAPI void elm_searchbar_clear(Evas_Object *obj)
310 Widget_Data *wd = elm_widget_data_get(obj);
313 if (wd->cancel_btn_show_mode)
315 if (wd->cancel_btn_ani_flag)
316 edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
318 edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
320 // elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
324 * set the searchbar boundary rect mode(with bg rect) set
326 * @param obj The searchbar object
327 * @param boundary The present flag of boundary rect or not
332 EAPI void elm_searchbar_boundary_rect_set(Evas_Object *obj, Eina_Bool boundary)
334 Widget_Data *wd = elm_widget_data_get(obj);
337 if (wd->boundary_mode == boundary) return;
338 else wd->boundary_mode = boundary;
340 if (wd->boundary_mode)
342 edje_object_signal_emit(wd->base, "BDSHOW", "PROG");
346 edje_object_signal_emit(wd->base, "BDHIDE", "PROG");