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);
77 _elm_button_smart_activate(Evas_Object *obj)
79 evas_object_smart_callback_call(obj, SIG_CLICKED, NULL);
80 elm_layout_signal_emit(obj, "elm,anim,activate", "elm");
83 /* FIXME: replicated from elm_layout just because button's icon spot
84 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
85 * can changed the theme API */
87 _icon_signal_emit(Evas_Object *obj)
91 snprintf(buf, sizeof(buf), "elm,state,icon,%s",
92 elm_layout_content_get(obj, "icon") ? "visible" : "hidden");
94 elm_layout_signal_emit(obj, buf, "elm");
95 edje_object_message_signal_process(elm_layout_edje_get(obj));
96 _elm_button_smart_sizing_eval(obj);
99 /* FIXME: replicated from elm_layout just because button's icon spot
100 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
101 * can changed the theme API */
103 _elm_button_smart_theme(Evas_Object *obj)
105 if (!ELM_WIDGET_CLASS(_elm_button_parent_sc)->theme(obj)) return EINA_FALSE;
107 _icon_signal_emit(obj);
112 /* FIXME: replicated from elm_layout just because button's icon spot
113 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
114 * can changed the theme API */
116 _elm_button_smart_sub_object_del(Evas_Object *obj,
119 if (!ELM_WIDGET_CLASS(_elm_button_parent_sc)->sub_object_del(obj, sobj))
122 _icon_signal_emit(obj);
127 /* FIXME: replicated from elm_layout just because button's icon spot
128 * is elm.swallow.content, not elm.swallow.icon. Fix that whenever we
129 * can changed the theme API */
131 _elm_button_smart_content_set(Evas_Object *obj,
133 Evas_Object *content)
135 if (!ELM_CONTAINER_CLASS(_elm_button_parent_sc)->content_set
136 (obj, part, content))
139 _icon_signal_emit(obj);
145 _elm_button_smart_event(Evas_Object *obj,
146 Evas_Object *src __UNUSED__,
147 Evas_Callback_Type type,
150 Evas_Event_Key_Down *ev = event_info;
152 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
154 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
155 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
157 if ((strcmp(ev->keyname, "Return")) &&
158 (strcmp(ev->keyname, "KP_Enter")) &&
159 (strcmp(ev->keyname, "space")))
163 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
164 elm_layout_signal_emit(obj, "elm,anim,activate", "elm");
170 _on_clicked_signal(void *data,
171 Evas_Object *obj __UNUSED__,
172 const char *emission __UNUSED__,
173 const char *source __UNUSED__)
179 _autorepeat_send(void *data)
181 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(data, sd, ECORE_CALLBACK_CANCEL);
183 evas_object_smart_callback_call(data, SIG_REPEATED, NULL);
187 return ECORE_CALLBACK_CANCEL;
190 return ECORE_CALLBACK_RENEW;
194 _autorepeat_initial_send(void *data)
196 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(data, sd, ECORE_CALLBACK_CANCEL);
198 if (sd->timer) ecore_timer_del(sd->timer);
199 sd->repeating = EINA_TRUE;
200 _autorepeat_send(data);
201 sd->timer = ecore_timer_add(sd->ar_interval, _autorepeat_send, data);
203 return ECORE_CALLBACK_CANCEL;
207 _on_pressed_signal(void *data,
208 Evas_Object *obj __UNUSED__,
209 const char *emission __UNUSED__,
210 const char *source __UNUSED__)
212 ELM_BUTTON_DATA_GET_OR_RETURN(data, sd);
214 if ((sd->autorepeat) && (!sd->repeating))
216 if (sd->ar_threshold <= 0.0)
217 _autorepeat_initial_send(data); /* call immediately */
219 sd->timer = ecore_timer_add
220 (sd->ar_threshold, _autorepeat_initial_send, data);
223 evas_object_smart_callback_call(data, SIG_PRESSED, NULL);
227 _on_unpressed_signal(void *data,
228 Evas_Object *obj __UNUSED__,
229 const char *emission __UNUSED__,
230 const char *source __UNUSED__)
232 ELM_BUTTON_DATA_GET_OR_RETURN(data, sd);
236 ecore_timer_del(sd->timer);
239 sd->repeating = EINA_FALSE;
240 evas_object_smart_callback_call(data, SIG_UNPRESSED, NULL);
244 _access_info_cb(void *data __UNUSED__,
246 Elm_Widget_Item *item __UNUSED__)
248 const char *txt = elm_widget_access_info_get(obj);
250 if (!txt) txt = elm_layout_text_get(obj, NULL);
251 if (txt) return strdup(txt);
257 _access_state_cb(void *data __UNUSED__,
259 Elm_Widget_Item *item __UNUSED__)
261 if (elm_widget_disabled_get(obj))
262 return strdup(E_("State: Disabled"));
268 _elm_button_smart_add(Evas_Object *obj)
270 EVAS_SMART_DATA_ALLOC(obj, Elm_Button_Smart_Data);
272 ELM_WIDGET_CLASS(_elm_button_parent_sc)->base.add(obj);
274 edje_object_signal_callback_add
275 (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,click", "",
276 _on_clicked_signal, obj);
277 edje_object_signal_callback_add
278 (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,press", "",
279 _on_pressed_signal, obj);
280 edje_object_signal_callback_add
281 (ELM_WIDGET_DATA(priv)->resize_obj, "elm,action,unpress", "",
282 _on_unpressed_signal, obj);
284 _elm_access_object_register(obj, ELM_WIDGET_DATA(priv)->resize_obj);
286 (_elm_access_object_get(obj), ELM_ACCESS_TYPE, E_("Button"));
287 _elm_access_callback_set
288 (_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
289 _elm_access_callback_set
290 (_elm_access_object_get(obj), ELM_ACCESS_STATE, _access_state_cb, priv);
292 elm_widget_can_focus_set(obj, EINA_TRUE);
294 elm_layout_theme_set(obj, "button", "base", elm_widget_style_get(obj));
298 _elm_button_smart_set_user(Elm_Button_Smart_Class *sc)
300 ELM_WIDGET_CLASS(sc)->base.add = _elm_button_smart_add;
302 ELM_WIDGET_CLASS(sc)->event = _elm_button_smart_event;
303 ELM_WIDGET_CLASS(sc)->theme = _elm_button_smart_theme;
304 ELM_WIDGET_CLASS(sc)->sub_object_del = _elm_button_smart_sub_object_del;
306 /* not a 'focus chain manager' */
307 ELM_WIDGET_CLASS(sc)->focus_next = NULL;
308 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
310 ELM_CONTAINER_CLASS(sc)->content_set = _elm_button_smart_content_set;
312 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_button_smart_sizing_eval;
313 ELM_WIDGET_CLASS(sc)->activate = _elm_button_smart_activate;
315 ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
316 ELM_LAYOUT_CLASS(sc)->text_aliases = _text_aliases;
318 sc->admits_autorepeat = EINA_TRUE;
321 EAPI const Elm_Button_Smart_Class *
322 elm_button_smart_class_get(void)
324 static Elm_Button_Smart_Class _sc =
325 ELM_BUTTON_SMART_CLASS_INIT_NAME_VERSION(ELM_BUTTON_SMART_NAME);
326 static const Elm_Button_Smart_Class *class = NULL;
327 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
329 if (class) return class;
331 _elm_button_smart_set(&_sc);
332 esc->callbacks = _smart_callbacks;
339 elm_button_add(Evas_Object *parent)
343 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
345 obj = elm_widget_add(_elm_button_smart_class_new(), parent);
346 if (!obj) return NULL;
348 if (!elm_widget_sub_object_add(parent, obj))
349 ERR("could not add %p as sub object of %p", obj, parent);
355 elm_button_autorepeat_set(Evas_Object *obj,
358 ELM_BUTTON_CHECK(obj);
359 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
363 ecore_timer_del(sd->timer);
367 sd->repeating = EINA_FALSE;
370 #define _AR_CAPABLE(_sd) \
371 (ELM_BUTTON_CLASS(ELM_WIDGET_DATA(_sd)->api)->admits_autorepeat)
374 elm_button_autorepeat_get(const Evas_Object *obj)
376 ELM_BUTTON_CHECK(obj) EINA_FALSE;
377 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
379 return _AR_CAPABLE(sd) & sd->autorepeat;
383 elm_button_autorepeat_initial_timeout_set(Evas_Object *obj,
386 ELM_BUTTON_CHECK(obj);
387 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
389 if (!_AR_CAPABLE(sd))
391 ERR("this widget does not support auto repetition of clicks.");
395 if (sd->ar_threshold == t) return;
398 ecore_timer_del(sd->timer);
401 sd->ar_threshold = t;
405 elm_button_autorepeat_initial_timeout_get(const Evas_Object *obj)
407 ELM_BUTTON_CHECK(obj) 0.0;
408 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, 0.0);
410 if (!_AR_CAPABLE(sd)) return 0.0;
412 return sd->ar_threshold;
416 elm_button_autorepeat_gap_timeout_set(Evas_Object *obj,
419 ELM_BUTTON_CHECK(obj);
420 ELM_BUTTON_DATA_GET_OR_RETURN(obj, sd);
422 if (!_AR_CAPABLE(sd))
424 ERR("this widget does not support auto repetition of clicks.");
428 if (sd->ar_interval == t) return;
431 if ((sd->repeating) && (sd->timer)) ecore_timer_interval_set(sd->timer, t);
435 elm_button_autorepeat_gap_timeout_get(const Evas_Object *obj)
437 ELM_BUTTON_CHECK(obj) 0.0;
438 ELM_BUTTON_DATA_GET_OR_RETURN_VAL(obj, sd, 0.0);
440 return sd->ar_interval;