1 #include <Elementary.h>
3 #include "elm_widget_button.h"
5 EAPI const char ELM_BUTTON_SMART_NAME[] = "elm_button";
7 static const char SIG_CLICKED[] = "clicked";
8 static const char SIG_REPEATED[] = "repeated";
9 static const char SIG_PRESSED[] = "pressed";
10 static const char SIG_UNPRESSED[] = "unpressed";
12 static const Elm_Layout_Part_Alias_Description _content_aliases[] =
14 {"icon", "elm.swallow.content"},
18 static const Elm_Layout_Part_Alias_Description _text_aliases[] =
20 {"default", "elm.text"},
24 /* smart callbacks coming from elm button objects (besides the ones
25 * coming from elm layout): */
26 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
34 EVAS_SMART_SUBCLASS_NEW
35 (ELM_BUTTON_SMART_NAME, _elm_button, Elm_Button_Smart_Class,
36 Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks);
39 _activate(Evas_Object *obj)
41 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
45 ecore_timer_del(sd->timer);
49 sd->repeating = EINA_FALSE;
51 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
52 (_elm_access_2nd_click_timeout(obj)))
54 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
55 _elm_access_say(E_("Clicked"));
56 if (!elm_widget_disabled_get(obj) &&
57 !evas_object_freeze_events_get(obj))
58 evas_object_smart_callback_call(obj, SIG_CLICKED, NULL);
63 _elm_button_smart_sizing_eval(Evas_Object *obj)
65 Evas_Coord minw = -1, minh = -1;
67 ELM_BUTTON_DATA_GET(obj, sd);
69 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
70 edje_object_size_min_restricted_calc
71 (ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh, minw, minh);
72 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
73 evas_object_size_hint_min_set(obj, minw, minh);
76 /* FIXME: replicated from elm_layout just because button's icon spot
77 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
78 * can changed the theme API */
80 _icon_signal_emit(Evas_Object *obj)
84 snprintf(buf, sizeof(buf), "elm,state,icon,%s",
85 elm_layout_content_get(obj, "icon") ? "visible" : "hidden");
87 elm_layout_signal_emit(obj, buf, "elm");
88 edje_object_message_signal_process(elm_layout_edje_get(obj));
89 _elm_button_smart_sizing_eval(obj);
92 /* FIXME: replicated from elm_layout just because button's icon spot
93 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
94 * can changed the theme API */
96 _elm_button_smart_theme(Evas_Object *obj)
98 if (!ELM_WIDGET_CLASS(_elm_button_parent_sc)->theme(obj)) return EINA_FALSE;
100 _icon_signal_emit(obj);
105 /* FIXME: replicated from elm_layout just because button's icon spot
106 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
107 * can changed the theme API */
109 _elm_button_smart_sub_object_del(Evas_Object *obj,
112 if (!ELM_WIDGET_CLASS(_elm_button_parent_sc)->sub_object_del(obj, sobj))
115 _icon_signal_emit(obj);
120 /* FIXME: replicated from elm_layout just because button's icon spot
121 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
122 * can changed the theme API */
124 _elm_button_smart_content_set(Evas_Object *obj,
126 Evas_Object *content)
128 if (!ELM_CONTAINER_CLASS(_elm_button_parent_sc)->content_set
129 (obj, part, content))
132 _icon_signal_emit(obj);
138 _elm_button_smart_event(Evas_Object *obj,
139 Evas_Object *src __UNUSED__,
140 Evas_Callback_Type type,
143 Evas_Event_Key_Down *ev = event_info;
145 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
147 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
148 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
150 if ((strcmp(ev->keyname, "Return")) &&
151 (strcmp(ev->keyname, "KP_Enter")) &&
152 (strcmp(ev->keyname, "space")))
156 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
157 elm_layout_signal_emit(obj, "elm,anim,activate", "elm");
163 _on_clicked_signal(void *data,
164 Evas_Object *obj __UNUSED__,
165 const char *emission __UNUSED__,
166 const char *source __UNUSED__)
172 _autorepeat_send(void *data)
174 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(data, sd, ECORE_CALLBACK_CANCEL);
176 evas_object_smart_callback_call(data, SIG_REPEATED, NULL);
180 return ECORE_CALLBACK_CANCEL;
183 return ECORE_CALLBACK_RENEW;
187 _autorepeat_initial_send(void *data)
189 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(data, sd, ECORE_CALLBACK_CANCEL);
191 if (sd->timer) ecore_timer_del(sd->timer);
192 sd->repeating = EINA_TRUE;
193 _autorepeat_send(data);
194 sd->timer = ecore_timer_add(sd->ar_interval, _autorepeat_send, data);
196 return ECORE_CALLBACK_CANCEL;
200 _on_pressed_signal(void *data,
201 Evas_Object *obj __UNUSED__,
202 const char *emission __UNUSED__,
203 const char *source __UNUSED__)
205 ELM_BUTTON_DATA_GET_OR_RETURN(data, sd);
207 if ((sd->autorepeat) && (!sd->repeating))
209 if (sd->ar_threshold <= 0.0)
210 _autorepeat_initial_send(data); /* call immediately */
212 sd->timer = ecore_timer_add
213 (sd->ar_threshold, _autorepeat_initial_send, data);
216 evas_object_smart_callback_call(data, SIG_PRESSED, NULL);
220 _on_unpressed_signal(void *data,
221 Evas_Object *obj __UNUSED__,
222 const char *emission __UNUSED__,
223 const char *source __UNUSED__)
225 ELM_BUTTON_DATA_GET_OR_RETURN(data, sd);
229 ecore_timer_del(sd->timer);
232 sd->repeating = EINA_FALSE;
233 evas_object_smart_callback_call(data, SIG_UNPRESSED, NULL);
237 _access_info_cb(void *data __UNUSED__,
239 Elm_Widget_Item *item __UNUSED__)
241 const char *txt = elm_widget_access_info_get(obj);
243 if (!txt) txt = elm_layout_text_get(obj, NULL);
244 if (txt) return strdup(txt);
250 _access_state_cb(void *data __UNUSED__,
252 Elm_Widget_Item *item __UNUSED__)
254 if (elm_widget_disabled_get(obj))
255 return strdup(E_("State: Disabled"));
261 _elm_button_smart_add(Evas_Object *obj)
263 EVAS_SMART_DATA_ALLOC(obj, Elm_Button_Smart_Data);
265 ELM_WIDGET_CLASS(_elm_button_parent_sc)->base.add(obj);
267 edje_object_signal_callback_add
268 (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,click", "",
269 _on_clicked_signal, obj);
270 edje_object_signal_callback_add
271 (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,press", "",
272 _on_pressed_signal, obj);
273 edje_object_signal_callback_add
274 (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,unpress", "",
275 _on_unpressed_signal, obj);
277 _elm_access_object_register(obj, ELM_WIDGET_DATA(priv)->resize_obj);
279 (_elm_access_object_get(obj), ELM_ACCESS_TYPE, E_("Button"));
280 _elm_access_callback_set
281 (_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
282 _elm_access_callback_set
283 (_elm_access_object_get(obj), ELM_ACCESS_STATE, _access_state_cb, priv);
285 elm_widget_can_focus_set(obj, EINA_TRUE);
287 elm_layout_theme_set(obj, "button", "base", elm_widget_style_get(obj));
291 _elm_button_smart_set_user(Elm_Button_Smart_Class *sc)
293 ELM_WIDGET_CLASS(sc)->base.add = _elm_button_smart_add;
295 ELM_WIDGET_CLASS(sc)->event = _elm_button_smart_event;
296 ELM_WIDGET_CLASS(sc)->theme = _elm_button_smart_theme;
297 ELM_WIDGET_CLASS(sc)->sub_object_del = _elm_button_smart_sub_object_del;
299 /* not a 'focus chain manager' */
300 ELM_WIDGET_CLASS(sc)->focus_next = NULL;
301 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
303 ELM_CONTAINER_CLASS(sc)->content_set = _elm_button_smart_content_set;
305 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_button_smart_sizing_eval;
307 ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
308 ELM_LAYOUT_CLASS(sc)->text_aliases = _text_aliases;
310 sc->admits_autorepeat = EINA_TRUE;
313 EAPI const Elm_Button_Smart_Class *
314 elm_button_smart_class_get(void)
316 static Elm_Button_Smart_Class _sc =
317 ELM_BUTTON_SMART_CLASS_INIT_NAME_VERSION(ELM_BUTTON_SMART_NAME);
318 static const Elm_Button_Smart_Class *class = NULL;
319 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
321 if (class) return class;
323 _elm_button_smart_set(&_sc);
324 esc->callbacks = _smart_callbacks;
331 elm_button_add(Evas_Object *parent)
335 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
337 obj = elm_widget_add(_elm_button_smart_class_new(), parent);
338 if (!obj) return NULL;
340 if (!elm_widget_sub_object_add(parent, obj))
341 ERR("could not add %p as sub object of %p", obj, parent);
347 elm_button_autorepeat_set(Evas_Object *obj,
350 ELM_BUTTON_CHECK(obj);
351 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
355 ecore_timer_del(sd->timer);
359 sd->repeating = EINA_FALSE;
362 #define _AR_CAPABLE(_sd) \
363 (ELM_BUTTON_CLASS(ELM_WIDGET_DATA(_sd)->api)->admits_autorepeat)
366 elm_button_autorepeat_get(const Evas_Object *obj)
368 ELM_BUTTON_CHECK(obj) EINA_FALSE;
369 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
371 return _AR_CAPABLE(sd) & sd->autorepeat;
375 elm_button_autorepeat_initial_timeout_set(Evas_Object *obj,
378 ELM_BUTTON_CHECK(obj);
379 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
381 if (!_AR_CAPABLE(sd))
383 ERR("this widget does not support auto repetition of clicks.");
387 if (sd->ar_threshold == t) return;
390 ecore_timer_del(sd->timer);
393 sd->ar_threshold = t;
397 elm_button_autorepeat_initial_timeout_get(const Evas_Object *obj)
399 ELM_BUTTON_CHECK(obj) 0.0;
400 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, 0.0);
402 if (!_AR_CAPABLE(sd)) return 0.0;
404 return sd->ar_threshold;
408 elm_button_autorepeat_gap_timeout_set(Evas_Object *obj,
411 ELM_BUTTON_CHECK(obj);
412 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
414 if (!_AR_CAPABLE(sd))
416 ERR("this widget does not support auto repetition of clicks.");
420 if (sd->ar_interval == t) return;
423 if ((sd->repeating) && (sd->timer)) ecore_timer_interval_set(sd->timer, t);
427 elm_button_autorepeat_gap_timeout_get(const Evas_Object *obj)
429 ELM_BUTTON_CHECK(obj) 0.0;
430 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, 0.0);
432 return sd->ar_interval;