1 #include <Elementary.h>
5 * @defgroup Button Button
7 * This is a push-button. Press it and run some function. It can contain
8 * a simple label and icon object.
11 typedef struct _Widget_Data Widget_Data;
20 static void _del_hook(Evas_Object *obj);
21 static void _theme_hook(Evas_Object *obj);
22 static void _disable_hook(Evas_Object *obj);
23 static void _sizing_eval(Evas_Object *obj);
24 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
25 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
26 static void _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
29 _del_hook(Evas_Object *obj)
31 Widget_Data *wd = elm_widget_data_get(obj);
33 if (wd->label) eina_stringshare_del(wd->label);
38 _theme_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
42 _elm_theme_set(wd->btn, "button", "base", elm_widget_style_get(obj));
44 edje_object_part_swallow(wd->btn, "elm.swallow.content", wd->icon);
46 edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
48 edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
50 edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm");
52 edje_object_signal_emit(wd->btn, "elm,state,icon,hidden", "elm");
53 edje_object_part_text_set(wd->btn, "elm.text", wd->label);
54 edje_object_message_signal_process(wd->btn);
55 edje_object_scale_set(wd->btn, elm_widget_scale_get(obj) * _elm_config->scale);
60 _disable_hook(Evas_Object *obj)
62 Widget_Data *wd = elm_widget_data_get(obj);
63 if (elm_widget_disabled_get(obj))
64 edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
66 edje_object_signal_emit(wd->btn, "elm,state,enabled", "elm");
70 _sizing_eval(Evas_Object *obj)
72 Widget_Data *wd = elm_widget_data_get(obj);
74 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
76 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
77 edje_object_size_min_restricted_calc(wd->btn, &minw, &minh, minw, minh);
78 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
79 evas_object_size_hint_min_set(obj, minw, minh);
80 evas_object_size_hint_max_set(obj, maxw, maxh);
84 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
86 Widget_Data *wd = elm_widget_data_get(data);
88 if (obj != wd->icon) return;
89 edje_object_part_swallow(wd->btn, "elm.swallow.content", obj);
94 _sub_del(void *data, Evas_Object *obj, void *event_info)
96 Widget_Data *wd = elm_widget_data_get(obj);
98 Evas_Object *sub = event_info;
101 edje_object_signal_emit(wd->btn, "elm,state,icon,hidden", "elm");
102 evas_object_event_callback_del
103 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints);
105 edje_object_message_signal_process(wd->btn);
111 _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
113 Widget_Data *wd = elm_widget_data_get(data);
115 evas_object_smart_callback_call(data, "clicked", NULL);
119 * Add a new button to the parent
120 * @param parent The parent object
121 * @return The new object or NULL if it cannot be created
126 elm_button_add(Evas_Object *parent)
132 wd = ELM_NEW(Widget_Data);
133 e = evas_object_evas_get(parent);
134 obj = elm_widget_add(e);
135 elm_widget_type_set(obj, "button");
136 elm_widget_sub_object_add(parent, obj);
137 elm_widget_data_set(obj, wd);
138 elm_widget_del_hook_set(obj, _del_hook);
139 elm_widget_theme_hook_set(obj, _theme_hook);
140 elm_widget_disable_hook_set(obj, _disable_hook);
142 wd->btn = edje_object_add(e);
143 _elm_theme_set(wd->btn, "button", "base", "default");
144 edje_object_signal_callback_add(wd->btn, "elm,action,click", "", _signal_clicked, obj);
145 elm_widget_resize_object_set(obj, wd->btn);
147 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
154 * Set the label used in the button
156 * @param obj The button object
157 * @param label The text will be written on the button
162 elm_button_label_set(Evas_Object *obj, const char *label)
164 Widget_Data *wd = elm_widget_data_get(obj);
168 if (wd->label) eina_stringshare_del(wd->label);
171 wd->label = eina_stringshare_add(label);
172 edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
173 edje_object_message_signal_process(wd->btn);
178 edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
179 edje_object_message_signal_process(wd->btn);
181 edje_object_part_text_set(wd->btn, "elm.text", label);
186 elm_button_label_get(Evas_Object *obj)
188 Widget_Data *wd = elm_widget_data_get(obj);
189 if (!wd) return NULL;
195 * Set the icon used for the button
197 * @param obj The button object
198 * @param icon The image for the button
203 elm_button_icon_set(Evas_Object *obj, Evas_Object *icon)
205 Widget_Data *wd = elm_widget_data_get(obj);
207 if ((wd->icon != icon) && (wd->icon))
208 elm_widget_sub_object_del(obj, wd->icon);
209 if ((icon) && (wd->icon != icon))
212 elm_widget_sub_object_add(obj, icon);
213 edje_object_part_swallow(wd->btn, "elm.swallow.content", icon);
214 edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm");
215 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
216 _changed_size_hints, obj);
217 edje_object_message_signal_process(wd->btn);
225 elm_button_icon_get(Evas_Object *obj)
227 Widget_Data *wd = elm_widget_data_get(obj);
228 if (!wd) return NULL;
233 * Set the button style
235 * @param obj The button object
236 * @param style The style for the button
241 elm_button_style_set(Evas_Object *obj, const char *style)
243 elm_widget_style_set(obj, style);