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;
23 static void _del_hook(Evas_Object *obj);
24 static void _theme_hook(Evas_Object *obj);
25 static void _sizing_eval(Evas_Object *obj);
26 static void _clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
27 static void _changed(void *data, Evas_Object *obj, const char *emission, const char *source);
28 static void _cancel_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
29 static void _signal_reset_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
31 static void _del_hook(Evas_Object *obj)
33 Widget_Data *wd = elm_widget_data_get(obj);
40 static void _theme_hook(Evas_Object *obj)
42 Widget_Data *wd = elm_widget_data_get(obj);
45 _elm_theme_object_set(obj, wd->base, "searchbar", "base", elm_widget_style_get(obj));
48 edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
50 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
52 edje_object_signal_callback_add(wd->base, "elm,action,click", "", _signal_reset_clicked, obj);
54 edje_object_scale_set(wd->cancel_btn, elm_widget_scale_get(obj) * _elm_config->scale);
58 static void _sizing_eval(Evas_Object *obj)
60 Widget_Data *wd = elm_widget_data_get(obj);
61 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
64 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
65 edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
66 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
67 evas_object_size_hint_min_set(obj, minw, minh);
68 evas_object_size_hint_max_set(obj, maxw, maxh);
71 static void _clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
73 Widget_Data *wd = elm_widget_data_get(data);
76 elm_entry_cursor_end_set(elm_editfield_entry_get(wd->eb));
77 if (wd->cancel_btn_ani_flag == EINA_TRUE)
78 edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
80 edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
82 evas_object_smart_callback_call(data, "clicked", NULL);
85 static void _changed(void *data, Evas_Object *obj, const char *emission, const char *source)
87 Widget_Data *wd = elm_widget_data_get(data);
88 fprintf(stderr, "##changed\n");
93 const char* text = elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
101 edje_object_signal_emit(wd->base, "RESETHIDE", "PROG");
105 edje_object_signal_emit(wd->base, "RESETSHOW", "PROG");
110 edje_object_signal_emit(wd->base, "RESETHIDE", "PROG");
114 evas_object_smart_callback_call(data, "changed", NULL);
117 static void _cancel_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
119 Widget_Data *wd = elm_widget_data_get(data);
122 if (wd->cancel_btn_ani_flag == EINA_TRUE)
123 edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
125 edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
129 text = elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
130 if (text != NULL && strlen(text) > 0)
131 elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
133 evas_object_smart_callback_call(data, "cancel,clicked", NULL);
136 static void _signal_reset_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
138 Widget_Data *wd = elm_widget_data_get(data);
140 elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
144 * Add a new searchbar to the parent
145 * @param parent The parent object
146 * @return The new object or NULL if it cannot be created
150 EAPI Evas_Object *elm_searchbar_add(Evas_Object *parent)
156 wd = ELM_NEW(Widget_Data);
157 e = evas_object_evas_get(parent);
158 if (e == NULL) return NULL;
159 obj = elm_widget_add(e);
160 if (obj == NULL) return NULL;
161 elm_widget_type_set(obj, "searchbar");
162 elm_widget_sub_object_add(parent, obj);
163 elm_widget_data_set(obj, wd);
164 elm_widget_del_hook_set(obj, _del_hook);
165 elm_widget_theme_hook_set(obj, _theme_hook);
166 elm_widget_can_focus_set(obj, 1 );
168 wd->base = edje_object_add(e);
169 if (wd->base == NULL) return NULL;
171 _elm_theme_object_set(obj, wd->base, "searchbar", "base", "default");
173 // evas_object_size_hint_weight_set(wd->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174 // evas_object_size_hint_align_set(wd->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
177 wd->eb = elm_editfield_add(parent);
178 elm_object_style_set(wd->eb, "searchbar");
179 edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
180 // elm_editfield_guide_text_set(wd->eb, "Search");
181 elm_editfield_entry_single_line_set(wd->eb, EINA_TRUE);
182 elm_editfield_eraser_set(wd->eb, EINA_TRUE);
183 evas_object_smart_callback_add(wd->eb, "clicked", _clicked, obj);
184 evas_object_smart_callback_add(wd->eb, "changed", _changed, obj);
185 elm_widget_sub_object_add(obj, wd->eb);
188 wd->cancel_btn = elm_button_add(parent);
189 edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
190 elm_object_style_set(wd->cancel_btn, "custom/darkblue");
191 elm_button_label_set(wd->cancel_btn, "Cancel");
192 evas_object_smart_callback_add(wd->cancel_btn, "clicked", _cancel_clicked, obj);
193 elm_widget_sub_object_add(obj, wd->cancel_btn);
195 wd->cancel_btn_ani_flag = EINA_FALSE;
197 edje_object_signal_callback_add(wd->base, "elm,action,click", "", _signal_reset_clicked, obj);
199 elm_widget_resize_object_set(obj, wd->base);
207 * get the text of entry
209 * @param obj The entry object
210 * @return The title of entry
214 EAPI void elm_searchbar_text_set(Evas_Object *obj, const char *entry)
216 Widget_Data *wd = elm_widget_data_get(obj);
217 if (!wd) return NULL;
219 elm_entry_entry_set(elm_editfield_entry_get(wd->eb), entry);
223 * get the text of entry
225 * @param obj The entry object
226 * @return The title of entry
230 EAPI const char* elm_searchbar_text_get(Evas_Object *obj)
232 Widget_Data *wd = elm_widget_data_get(obj);
233 if (!wd) return NULL;
235 return elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
239 * get the pointer of entry
241 * @param obj The entry object
242 * @return The title of entry
246 EAPI Evas_Object *elm_searchbar_entry_get(Evas_Object *obj)
248 Widget_Data *wd = elm_widget_data_get(obj);
249 if (!wd) return NULL;
251 return elm_editfield_entry_get(wd->eb);
255 * get the pointer of entry
257 * @param obj The entry object
258 * @return The title of entry
262 EAPI void elm_searchbar_cancel_button_animation_set(Evas_Object *obj, Eina_Bool cancel_btn_ani_flag)
264 Widget_Data *wd = elm_widget_data_get(obj);
267 if (cancel_btn_ani_flag == EINA_TRUE)
268 wd->cancel_btn_ani_flag = EINA_TRUE;
270 wd->cancel_btn_ani_flag = EINA_FALSE;