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);
49 _elm_theme_object_set(obj, wd->base, "searchbar", "base", elm_widget_style_get(obj));
52 edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
54 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
56 snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
57 elm_object_style_set(wd->eb, buf);
59 snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
60 elm_object_style_set(wd->cancel_btn, buf);
62 edje_object_scale_set(wd->cancel_btn, elm_widget_scale_get(obj) * _elm_config->scale);
67 _on_focus_hook(void *data, Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
72 if (elm_widget_focus_get(obj))
74 if (wd->cancel_btn_show_mode)
76 if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
77 else edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
82 static void _sizing_eval(Evas_Object *obj)
84 Widget_Data *wd = elm_widget_data_get(obj);
85 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
88 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
89 edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
90 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
91 evas_object_size_hint_min_set(obj, minw, minh);
92 evas_object_size_hint_max_set(obj, maxw, maxh);
95 static void _clicked(void *data, Evas_Object *obj, void *event_info)
97 Widget_Data *wd = elm_widget_data_get(data);
100 if (wd->cancel_btn_show_mode)
102 if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
103 else edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
106 evas_object_smart_callback_call(data, "clicked", NULL);
109 static void _changed(void *data, Evas_Object *obj, void *event_info)
111 Widget_Data *wd = elm_widget_data_get(data);
115 // TODO : inform to use entry changed callback
116 // evas_object_smart_callback_call(data, "changed", NULL);
119 static void _cancel_clicked(void *data, Evas_Object *obj, void *event_info)
121 Widget_Data *wd = elm_widget_data_get(data);
124 if (wd->cancel_btn_show_mode)
126 if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
127 else edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
131 text = elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
132 if (text != NULL && strlen(text) > 0) elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
134 evas_object_smart_callback_call(data, "cancel,clicked", NULL);
135 elm_object_unfocus(data);
139 _basebg_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
141 Widget_Data *wd = elm_widget_data_get(data);
145 if (!strcmp(source, "base_bg"))
146 _clicked(data, obj, NULL);
150 _searchsymbol_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
152 Widget_Data *wd = elm_widget_data_get(data);
155 evas_object_smart_callback_call(data, "searchsymbol,clicked", NULL);
159 * Add a new searchbar to the parent
160 * @param parent The parent object
161 * @return The new object or NULL if it cannot be created
165 EAPI Evas_Object *elm_searchbar_add(Evas_Object *parent)
172 wd = ELM_NEW(Widget_Data);
173 e = evas_object_evas_get(parent);
174 if (e == NULL) return NULL;
175 obj = elm_widget_add(e);
176 if (obj == NULL) return NULL;
177 elm_widget_type_set(obj, "searchbar");
178 elm_widget_sub_object_add(parent, obj);
179 elm_widget_data_set(obj, wd);
180 elm_widget_del_hook_set(obj, _del_hook);
181 elm_widget_theme_hook_set(obj, _theme_hook);
182 elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
183 elm_widget_can_focus_set(obj, 1 );
185 wd->base = edje_object_add(e);
186 if (wd->base == NULL) return NULL;
188 _elm_theme_object_set(obj, wd->base, "searchbar", "base", "default");
190 // evas_object_size_hint_weight_set(wd->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
191 // evas_object_size_hint_align_set(wd->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
194 wd->eb = elm_editfield_add(parent);
195 snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
196 elm_object_style_set(wd->eb, buf);
198 edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
199 // elm_editfield_guide_text_set(wd->eb, "Search");
200 elm_editfield_entry_single_line_set(wd->eb, EINA_TRUE);
201 elm_editfield_eraser_set(wd->eb, EINA_TRUE);
202 evas_object_smart_callback_add(wd->eb, "clicked", _clicked, obj);
203 evas_object_smart_callback_add(elm_editfield_entry_get(wd->eb), "changed", _changed, obj);
204 edje_object_signal_callback_add(wd->base, "mouse,up,1", "*", _basebg_clicked, obj);
205 edje_object_signal_callback_add(wd->base, "elm,action,click", "", _searchsymbol_clicked, obj);
207 elm_widget_sub_object_add(obj, wd->eb);
210 wd->cancel_btn = elm_button_add(parent);
211 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
213 snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
214 elm_object_style_set(wd->cancel_btn, buf);
216 elm_button_label_set(wd->cancel_btn, "Cancel");
217 evas_object_smart_callback_add(wd->cancel_btn, "clicked", _cancel_clicked, obj);
218 elm_widget_sub_object_add(obj, wd->cancel_btn);
220 wd->cancel_btn_ani_flag = EINA_FALSE;
221 wd->cancel_btn_show_mode = EINA_TRUE;
222 wd->boundary_mode = EINA_TRUE;
224 elm_widget_resize_object_set(obj, wd->base);
232 * set the text of entry
234 * @param obj The searchbar object
239 EAPI void elm_searchbar_text_set(Evas_Object *obj, const char *entry)
241 Widget_Data *wd = elm_widget_data_get(obj);
244 elm_entry_entry_set(elm_editfield_entry_get(wd->eb), entry);
248 * get the text of entry
250 * @param obj The searchbar object
251 * @return string pointer of entry
255 EAPI const char* elm_searchbar_text_get(Evas_Object *obj)
257 Widget_Data *wd = elm_widget_data_get(obj);
258 if (!wd) return NULL;
260 return elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
264 * get the pointer of entry
266 * @param obj The searchbar object
267 * @return the entry object
271 EAPI Evas_Object *elm_searchbar_entry_get(Evas_Object *obj)
273 Widget_Data *wd = elm_widget_data_get(obj);
274 if (!wd) return NULL;
276 return elm_editfield_entry_get(wd->eb);
280 * set the cancel button animation flag
282 * @param obj The searchbar object
283 * @param cancel_btn_ani_flag The flag of animating cancen button or not
288 EAPI void elm_searchbar_cancel_button_animation_set(Evas_Object *obj, Eina_Bool cancel_btn_ani_flag)
290 Widget_Data *wd = elm_widget_data_get(obj);
293 if (wd->cancel_btn_ani_flag == cancel_btn_ani_flag) return;
294 else wd->cancel_btn_ani_flag = cancel_btn_ani_flag;
298 * set the cancel button show mode
300 * @param obj The searchbar object
301 * @param visible The flag of cancen button show or not
306 EAPI void elm_searchbar_cancel_button_set(Evas_Object *obj, Eina_Bool visible)
308 Widget_Data *wd = elm_widget_data_get(obj);
311 if (wd->cancel_btn_show_mode == visible) return;
312 else wd->cancel_btn_show_mode = visible;
316 if (wd->cancel_btn_ani_flag)
317 edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
319 edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
325 * clear searchbar status
327 * @param obj The searchbar object
332 EAPI void elm_searchbar_clear(Evas_Object *obj)
334 Widget_Data *wd = elm_widget_data_get(obj);
337 if (wd->cancel_btn_show_mode)
339 if (wd->cancel_btn_ani_flag)
340 edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
342 edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
344 // elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
348 * set the searchbar boundary rect mode(with bg rect) set
350 * @param obj The searchbar object
351 * @param boundary The present flag of boundary rect or not
356 EAPI void elm_searchbar_boundary_rect_set(Evas_Object *obj, Eina_Bool boundary)
358 Widget_Data *wd = elm_widget_data_get(obj);
361 if (wd->boundary_mode == boundary) return;
362 else wd->boundary_mode = boundary;
364 if (wd->boundary_mode)
366 edje_object_signal_emit(wd->base, "BDSHOW", "PROG");
370 edje_object_signal_emit(wd->base, "BDHIDE", "PROG");