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;
15 Evas_Object *btn, *icon;
19 static void _del_hook(Evas_Object *obj);
20 static void _theme_hook(Evas_Object *obj);
21 static void _disable_hook(Evas_Object *obj);
22 static void _sizing_eval(Evas_Object *obj);
23 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
24 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
25 static void _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
28 _del_hook(Evas_Object *obj)
30 Widget_Data *wd = elm_widget_data_get(obj);
32 if (wd->label) eina_stringshare_del(wd->label);
37 _theme_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
41 _elm_theme_set(wd->btn, "button", "base", elm_widget_style_get(obj));
43 edje_object_part_swallow(wd->btn, "elm.swallow.content", wd->icon);
45 edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
47 edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
49 edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm");
51 edje_object_signal_emit(wd->btn, "elm,state,icon,hidden", "elm");
52 edje_object_part_text_set(wd->btn, "elm.text", wd->label);
53 edje_object_message_signal_process(wd->btn);
54 edje_object_scale_set(wd->btn, elm_widget_scale_get(obj) * _elm_config->scale);
59 _disable_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
62 if (elm_widget_disabled_get(obj))
63 edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
65 edje_object_signal_emit(wd->btn, "elm,state,enabled", "elm");
69 _sizing_eval(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
72 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
75 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
76 edje_object_size_min_restricted_calc(wd->btn, &minw, &minh, minw, minh);
77 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
78 evas_object_size_hint_min_set(obj, minw, minh);
79 evas_object_size_hint_max_set(obj, maxw, maxh);
83 _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
85 Widget_Data *wd = elm_widget_data_get(data);
87 if (obj != wd->icon) return;
92 _sub_del(void *data, Evas_Object *obj, void *event_info)
94 Widget_Data *wd = elm_widget_data_get(obj);
95 Evas_Object *sub = event_info;
99 edje_object_signal_emit(wd->btn, "elm,state,icon,hidden", "elm");
100 evas_object_event_callback_del(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
101 _changed_size_hints);
103 edje_object_message_signal_process(wd->btn);
109 _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
111 Widget_Data *wd = elm_widget_data_get(data);
113 evas_object_smart_callback_call(data, "clicked", NULL);
117 * Add a new button to the parent
118 * @param parent The parent object
119 * @return The new object or NULL if it cannot be created
124 elm_button_add(Evas_Object *parent)
130 wd = ELM_NEW(Widget_Data);
131 e = evas_object_evas_get(parent);
132 obj = elm_widget_add(e);
133 elm_widget_type_set(obj, "button");
134 elm_widget_sub_object_add(parent, obj);
135 elm_widget_data_set(obj, wd);
136 elm_widget_del_hook_set(obj, _del_hook);
137 elm_widget_theme_hook_set(obj, _theme_hook);
138 elm_widget_disable_hook_set(obj, _disable_hook);
140 wd->btn = edje_object_add(e);
141 _elm_theme_set(wd->btn, "button", "base", "default");
142 edje_object_signal_callback_add(wd->btn, "elm,action,click", "",
143 _signal_clicked, obj);
144 elm_widget_resize_object_set(obj, wd->btn);
146 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
153 * Set the label used in the button
155 * @param obj The button object
156 * @param label The text will be written on the button
161 elm_button_label_set(Evas_Object *obj, const char *label)
163 Widget_Data *wd = elm_widget_data_get(obj);
167 if (wd->label) eina_stringshare_del(wd->label);
170 wd->label = eina_stringshare_add(label);
171 edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
176 edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
178 edje_object_message_signal_process(wd->btn);
179 edje_object_part_text_set(wd->btn, "elm.text", label);
184 elm_button_label_get(Evas_Object *obj)
186 Widget_Data *wd = elm_widget_data_get(obj);
187 if (!wd) return NULL;
192 * Set the icon used for the button
194 * @param obj The button object
195 * @param icon The image for the button
200 elm_button_icon_set(Evas_Object *obj, Evas_Object *icon)
202 Widget_Data *wd = elm_widget_data_get(obj);
204 if ((wd->icon != icon) && (wd->icon))
205 elm_widget_sub_object_del(obj, wd->icon);
206 if ((icon) && (wd->icon != icon))
209 elm_widget_sub_object_add(obj, icon);
210 edje_object_part_swallow(wd->btn, "elm.swallow.content", icon);
211 edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm");
212 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
213 _changed_size_hints, obj);
214 edje_object_message_signal_process(wd->btn);
222 elm_button_icon_get(Evas_Object *obj)
224 Widget_Data *wd = elm_widget_data_get(obj);
225 if (!wd) return NULL;
230 * Set the button style
232 * @param obj The button object
233 * @param style The style for the button
235 * DEPRECATED. use elm_object_style_set() instead
240 elm_button_style_set(Evas_Object *obj, const char *style)
242 elm_widget_style_set(obj, style);