Merge "elm_button - added a pressed signal"
[framework/uifw/elementary.git] / src / lib / elm_button.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Button Button
6  * @ingroup Elementary
7  *
8  * This is a push-button. Press it and run some function. It can contain
9  * a simple label and icon object.
10  *
11  * Signals that you can add callbacks for are:
12  *
13  * "clicked" - the user clicked the button
14  * "repeated" - the user pressed the button without releasing it
15  * "pressed" - when the button is pressed
16  * "unpressed" - when the button is unpressed (released)
17  */
18
19 typedef struct _Widget_Data Widget_Data;
20
21 enum
22 {
23    DEFAULT = 0,
24    HIGHLIGHTED,
25    FOCUSED,
26    DISABLED,
27 };
28
29 struct _Widget_Data
30 {
31    Evas_Object *btn, *icon;
32    const char *label;
33    Eina_Bool autorepeat;
34    Eina_Bool repeating;
35    double ar_threshold;
36    double ar_interval;
37    Ecore_Timer *timer;
38    const char *statelabel[4];
39    int statetype[4];
40 };
41
42 static const char *widtype = NULL;
43 static void _del_hook(Evas_Object *obj);
44 static void _theme_hook(Evas_Object *obj);
45 static void _disable_hook(Evas_Object *obj);
46 static void _sizing_eval(Evas_Object *obj);
47 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
48 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
49 static void _signal_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
50 static void _signal_pressed(void *data, Evas_Object *obj, const char *emission, const char *source);
51 static void _signal_unpressed(void *data, Evas_Object *obj, const char *emission, const char *source);
52 static void _on_focus_hook(void *data, Evas_Object *obj);
53 static void _activate(Evas_Object *obj);
54 static void _activate_hook(Evas_Object *obj);
55 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
56                              Evas_Callback_Type type, void *event_info);
57
58 static void _set_label(Evas_Object *obj, const char *label);
59 static void _signal_default_text_set(void *data, Evas_Object *obj, const char *emission, const char *source);
60
61 static const char SIG_CLICKED[] = "clicked";
62 static const char SIG_REPEATED[] = "repeated";
63 static const char SIG_PRESSED[] = "pressed";
64 static const char SIG_UNPRESSED[] = "unpressed";
65 static const Evas_Smart_Cb_Description _signals[] = {
66        {SIG_CLICKED, ""},
67        {SIG_REPEATED, ""},
68        {SIG_PRESSED, ""},
69        {SIG_UNPRESSED, ""},
70        {NULL, NULL}
71 };
72
73 static Eina_Bool
74 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
75 {
76    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
77    Evas_Event_Key_Down *ev = event_info;
78    Widget_Data *wd = elm_widget_data_get(obj);
79    if (!wd) return EINA_FALSE;
80    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
81    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
82    if ((strcmp(ev->keyname, "Return")) &&
83        (strcmp(ev->keyname, "KP_Enter")) &&
84        (strcmp(ev->keyname, "space")))
85      return EINA_FALSE;
86    _activate(obj);
87    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
88    edje_object_signal_emit(wd->btn, "elm,anim,activate", "elm");
89    return EINA_TRUE;
90 }
91
92 static void
93 _del_hook(Evas_Object *obj)
94 {
95    Widget_Data *wd = elm_widget_data_get(obj);
96    if (!wd) return;
97    if (wd->label) eina_stringshare_del(wd->label);
98    if (wd->statelabel[DEFAULT]) eina_stringshare_del(wd->statelabel[DEFAULT]);
99    if (wd->statelabel[HIGHLIGHTED]) eina_stringshare_del(wd->statelabel[HIGHLIGHTED]);
100    if (wd->statelabel[FOCUSED]) eina_stringshare_del(wd->statelabel[FOCUSED]);
101    if (wd->statelabel[DISABLED]) eina_stringshare_del(wd->statelabel[DISABLED]);
102    free(wd);
103 }
104
105 static void
106 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
107 {
108    Widget_Data *wd = elm_widget_data_get(obj);
109    if (!wd) return;
110    if (elm_widget_focus_get(obj))
111      {
112         if (wd->statelabel[FOCUSED])
113           {
114              _set_label(obj, wd->statelabel[FOCUSED]);
115           }
116         edje_object_signal_emit(wd->btn, "elm,action,focus", "elm");
117         evas_object_focus_set(wd->btn, EINA_TRUE);
118      }
119    else
120      {
121         if (wd->statelabel[DEFAULT])
122           _set_label(obj, wd->statelabel[DEFAULT]);
123         #if 0
124         else
125           _set_label(obj, wd->label);
126         #endif
127         edje_object_signal_emit(wd->btn, "elm,action,unfocus", "elm");
128         evas_object_focus_set(wd->btn, EINA_FALSE);
129      }
130 }
131
132 static void
133 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
134 {
135    Widget_Data *wd = elm_widget_data_get(obj);
136    if (!wd) return;
137    edje_object_mirrored_set(wd->btn, rtl);
138 }
139
140 static void
141 _theme_hook(Evas_Object *obj)
142 {
143    Widget_Data *wd = elm_widget_data_get(obj);
144    const char *str;
145    if (!wd) return;
146    _elm_widget_mirrored_reload(obj);
147    _mirrored_set(obj, elm_widget_mirrored_get(obj));
148    _elm_theme_object_set(obj, wd->btn, "button", "base", elm_widget_style_get(obj));
149    if (elm_object_disabled_get(obj))
150      edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
151    if (wd->icon)
152      edje_object_part_swallow(wd->btn, "elm.swallow.content", wd->icon);
153    if (wd->label)
154      edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
155    else
156      edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
157    if (wd->icon)
158      edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm");
159    else
160      edje_object_signal_emit(wd->btn, "elm,state,icon,hidden", "elm");
161    edje_object_part_text_set(wd->btn, "elm.text", wd->label);
162    edje_object_message_signal_process(wd->btn);
163    edje_object_scale_set(wd->btn, elm_widget_scale_get(obj) * _elm_config->scale);
164    str = edje_object_data_get(wd->btn, "focus_highlight");
165    if ((str) && (!strcmp(str, "on")))
166      elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
167    else
168      elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
169    _sizing_eval(obj);
170 }
171
172 static void
173 _disable_hook(Evas_Object *obj)
174 {
175    Widget_Data *wd = elm_widget_data_get(obj);
176    if (!wd) return;
177    if (elm_widget_disabled_get(obj))
178      {
179         if (wd->statelabel[DISABLED] )
180           {
181              _set_label(obj, wd->statelabel[DISABLED]);
182           }
183         edje_object_signal_emit(wd->btn, "elm,state,disabled", "elm");
184      }
185    else
186      {
187         if (wd->statelabel[DEFAULT])
188           _set_label(obj, wd->statelabel[DEFAULT]);
189         #if 0
190         else
191           _set_label(obj, wd->label);
192         #endif
193         edje_object_signal_emit(wd->btn, "elm,state,enabled", "elm");
194      }
195 }
196
197 static void
198 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
199 {
200    Widget_Data *wd = elm_widget_data_get(obj);
201    if (!wd) return;
202    edje_object_signal_emit(wd->btn, emission, source);
203 }
204
205 static void
206 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
207 {
208    Widget_Data *wd = elm_widget_data_get(obj);
209    if (!wd) return;
210    edje_object_signal_callback_add(wd->btn, emission, source, func_cb, data);
211 }
212
213 static void
214 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
215 {
216    Widget_Data *wd = elm_widget_data_get(obj);
217    edje_object_signal_callback_del_full(wd->btn, emission, source, func_cb,
218                                         data);
219 }
220
221 static void
222 _sizing_eval(Evas_Object *obj)
223 {
224    Widget_Data *wd = elm_widget_data_get(obj);
225    Evas_Coord minw = -1, minh = -1;
226    Evas_Coord w, h;
227
228    if (!wd) return;
229    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
230    edje_object_size_min_restricted_calc(wd->btn, &minw, &minh, minw, minh);
231    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
232    //Commenting to sync with open source and able to resize based on text change
233    evas_object_size_hint_min_get(obj, &w, &h);
234    //if (w > minw) minw = w;
235    if (h > minh) minh = h;
236
237    evas_object_size_hint_min_set(obj, minw, minh);
238 }
239
240 static void
241 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
242 {
243    Widget_Data *wd = elm_widget_data_get(data);
244    if (!wd) return;
245    if (obj != wd->icon) return;
246    _sizing_eval(data);
247 }
248
249 static void
250 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
251 {
252    Widget_Data *wd = elm_widget_data_get(obj);
253    Evas_Object *sub = event_info;
254    if (!wd) return;
255    if (sub == wd->icon)
256      {
257         edje_object_signal_emit(wd->btn, "elm,state,icon,hidden", "elm");
258         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
259                                             _changed_size_hints, obj);
260         wd->icon = NULL;
261         edje_object_message_signal_process(wd->btn);
262         _sizing_eval(obj);
263      }
264 }
265
266 static void
267 _activate(Evas_Object *obj)
268 {
269    Widget_Data *wd = elm_widget_data_get(obj);
270    if (!wd) return;
271    if (wd->timer)
272      {
273         ecore_timer_del(wd->timer);
274         wd->timer = NULL;
275      }
276    wd->repeating = EINA_FALSE;
277    evas_object_smart_callback_call(obj, SIG_CLICKED, NULL);
278 }
279
280 static void
281 _activate_hook(Evas_Object *obj)
282 {
283    _activate(obj);
284 }
285
286 static void
287 _signal_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
288 {
289    _activate(data);
290 }
291
292 static Eina_Bool
293 _autorepeat_send(void *data)
294 {
295    Widget_Data *wd = elm_widget_data_get(data);
296    if (!wd) return ECORE_CALLBACK_CANCEL;
297
298    evas_object_smart_callback_call(data, SIG_REPEATED, NULL);
299    if (!wd->repeating)
300      {
301         wd->timer = NULL;
302         return ECORE_CALLBACK_CANCEL;
303      }
304
305    return ECORE_CALLBACK_RENEW;
306 }
307
308 static Eina_Bool
309 _autorepeat_initial_send(void *data)
310 {
311    Widget_Data *wd = elm_widget_data_get(data);
312    if (!wd) return ECORE_CALLBACK_CANCEL;
313
314    if (wd->timer) ecore_timer_del(wd->timer);
315    wd->repeating = EINA_TRUE;
316    _autorepeat_send(data);
317    wd->timer = ecore_timer_add(wd->ar_interval, _autorepeat_send, data);
318
319    return ECORE_CALLBACK_CANCEL;
320 }
321
322 static void
323 _signal_pressed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
324 {
325    Widget_Data *wd = elm_widget_data_get(data);
326    if (!wd) return;
327
328    if (wd->statelabel[HIGHLIGHTED])
329      {
330         _set_label(data, wd->statelabel[HIGHLIGHTED]);
331      }
332    if ((wd->autorepeat) && (!wd->repeating))
333      {
334         if (wd->ar_threshold <= 0.0)
335           _autorepeat_initial_send(data); /* call immediately */
336         else
337           wd->timer = ecore_timer_add(wd->ar_threshold, _autorepeat_initial_send, data);
338      }
339
340    evas_object_smart_callback_call(data, SIG_PRESSED, NULL);
341 }
342
343 static void
344 _signal_unpressed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
345 {
346    Widget_Data *wd = elm_widget_data_get(data);
347    if (!wd) return;
348    if (wd->statelabel[DEFAULT])
349      _set_label(data, wd->statelabel[DEFAULT]);
350    #if 0
351    else
352      _set_label(data, wd->label);
353    #endif
354
355    if (wd->timer)
356      {
357         ecore_timer_del(wd->timer);
358         wd->timer = NULL;
359      }
360    wd->repeating = EINA_FALSE;
361    evas_object_smart_callback_call(data, SIG_UNPRESSED, NULL);
362 }
363
364 static void
365 _signal_default_text_set(void *data, Evas_Object *obj, const char *emission, const char *source)
366 {
367    Widget_Data *wd = elm_widget_data_get(data);
368    if (!wd) return;
369    if (wd->statelabel[DEFAULT])
370      _set_label(data, wd->statelabel[DEFAULT]);
371    #if 0
372    else
373      _set_label(data, wd->label);
374    #endif
375 }
376 /**
377  * Add a new button to the parent
378  * @param[in] parent The parent object
379  * @return The new object or NULL if it cannot be created
380  *
381  * @ingroup Button
382  */
383 EAPI Evas_Object *
384 elm_button_add(Evas_Object *parent)
385 {
386    Evas_Object *obj;
387    Evas *e;
388    Widget_Data *wd;
389
390    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
391
392    ELM_SET_WIDTYPE(widtype, "button");
393    elm_widget_type_set(obj, "button");
394    elm_widget_sub_object_add(parent, obj);
395    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
396    elm_widget_data_set(obj, wd);
397    elm_widget_del_hook_set(obj, _del_hook);
398    elm_widget_theme_hook_set(obj, _theme_hook);
399    elm_widget_disable_hook_set(obj, _disable_hook);
400    elm_widget_can_focus_set(obj, EINA_TRUE);
401    elm_widget_activate_hook_set(obj, _activate_hook);
402    elm_widget_event_hook_set(obj, _event_hook);
403    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
404    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
405    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
406
407    wd->btn = edje_object_add(e);
408    _elm_theme_object_set(obj, wd->btn, "button", "base", "default");
409    wd->statetype[DEFAULT] = 0;
410    wd->statetype[HIGHLIGHTED] = 0;
411    wd->statetype[FOCUSED] = 0;
412    wd->statetype[DISABLED] = 0;
413    wd->statelabel[DEFAULT] = 0;
414    wd->statelabel[HIGHLIGHTED] = 0;
415    wd->statelabel[FOCUSED] = 0;
416    wd->statelabel[DISABLED] = 0;
417    edje_object_signal_callback_add(wd->btn, "elm,action,click", "",
418                                    _signal_clicked, obj);
419    edje_object_signal_callback_add(wd->btn, "elm,action,press", "",
420                                    _signal_pressed, obj);
421    edje_object_signal_callback_add(wd->btn, "elm,action,unpress", "",
422                                    _signal_unpressed, obj);
423    edje_object_signal_callback_add(wd->btn, "elm,action,default,text,set", "",
424                                    _signal_default_text_set, obj);
425    elm_widget_resize_object_set(obj, wd->btn);
426
427    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
428
429    _theme_hook(obj);
430
431    // TODO: convert Elementary to subclassing of Evas_Smart_Class
432    // TODO: and save some bytes, making descriptions per-class and not instance!
433    evas_object_smart_callbacks_descriptions_set(obj, _signals);
434    return obj;
435 }
436
437 /**
438  * Set the label used in the button
439  *
440  * @param[in] obj The button object
441  * @param[in] label The text will be written on the button
442  *
443  * @ingroup Button
444  */
445 EAPI void
446 elm_button_label_set(Evas_Object *obj, const char *label)
447 {
448    ELM_CHECK_WIDTYPE(obj, widtype);
449    Widget_Data *wd = elm_widget_data_get(obj);
450    if (!wd) return;
451    eina_stringshare_replace(&wd->label, label);
452    if (label)
453      edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
454    else
455      edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
456    edje_object_message_signal_process(wd->btn);
457    edje_object_part_text_set(wd->btn, "elm.text", label);
458    _sizing_eval(obj);
459 }
460
461 static void
462 _set_label(Evas_Object *obj, const char *label)
463 {
464    Widget_Data *wd = elm_widget_data_get(obj);
465
466    edje_object_part_text_set(wd->btn, "elm.text", label);
467    _sizing_eval(obj);
468 }
469 /**
470  * Set the label for each state of button
471  *
472  * @param[in] obj The button object
473  * @param[in] label The text will be written on the button
474  * @param[in] state The state of button
475  *
476  * @ingroup Button
477  */
478 EAPI void
479 elm_button_label_set_for_state(Evas_Object *obj, const char *label, UIControlState state)
480 {
481    Widget_Data *wd = elm_widget_data_get(obj);
482
483    if (!wd) return;
484    if (label == NULL) return;
485
486    if (state == UIControlStateDefault)
487      {
488         wd->statetype[DEFAULT] = UIControlStateDefault;
489         eina_stringshare_replace(&wd->statelabel[DEFAULT], label);
490         return;
491      }
492    if (state == UIControlStateHighlighted)
493      {
494         wd->statetype[HIGHLIGHTED] = UIControlStateHighlighted;
495         eina_stringshare_replace(&wd->statelabel[HIGHLIGHTED], label);
496         return;
497      }
498    if (state == UIControlStateFocused)
499      {
500         wd->statetype[FOCUSED] = UIControlStateFocused;
501         eina_stringshare_replace(&wd->statelabel[FOCUSED], label);
502         return;
503      }
504    if (state == UIControlStateDisabled)
505      {
506         wd->statetype[DISABLED] = UIControlStateDisabled;
507         eina_stringshare_replace(&wd->statelabel[DISABLED], label);
508         return;
509      }
510 }
511
512 /**
513  * Get the label of button
514  *
515  * @param[in] obj The button object
516  * @return The title of button
517  *
518  * @ingroup Button
519  */
520 EAPI const char *
521 elm_button_label_get(const Evas_Object *obj)
522 {
523    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
524    Widget_Data *wd = elm_widget_data_get(obj);
525    if (!wd) return NULL;
526    return wd->label;
527 }
528 /**
529  * Get the label of button for each state
530  *
531  * @param[in] obj The button object
532  * @param[in] state The state of button
533  * @return The title of button for state
534  *
535  * @ingroup Button
536  */
537 EAPI const char*
538 elm_button_label_get_for_state(const Evas_Object *obj, UIControlState state)
539 {
540    Widget_Data *wd = elm_widget_data_get(obj);
541    if (!wd) return NULL;
542
543    if (state == UIControlStateDefault)
544      return wd->statelabel[DEFAULT];
545    else if (state == UIControlStateHighlighted)
546      return wd->statelabel[HIGHLIGHTED];
547    else if (state == UIControlStateFocused)
548      return wd->statelabel[FOCUSED];
549    else if (state == UIControlStateDisabled)
550      return wd->statelabel[DISABLED];
551    else
552      return NULL;
553 }
554
555 /**
556  * Set the icon used for the button
557  *
558  * Once the icon object is set, a previously set one will be deleted
559  * If you want to keep that old content object, use the
560  * elm_button_icon_unset() function.
561  *
562  * @param[in] obj The button object
563  * @param[in] icon The icon object for the button
564  *
565  * @ingroup Button
566  */
567 EAPI void
568 elm_button_icon_set(Evas_Object *obj, Evas_Object *icon)
569 {
570    ELM_CHECK_WIDTYPE(obj, widtype);
571    Widget_Data *wd = elm_widget_data_get(obj);
572    if (!wd) return;
573    if (wd->icon == icon) return;
574    if (wd->icon) evas_object_del(wd->icon);
575    wd->icon = icon;
576    if (icon)
577      {
578         elm_widget_sub_object_add(obj, icon);
579         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
580                                        _changed_size_hints, obj);
581         edje_object_part_swallow(wd->btn, "elm.swallow.content", icon);
582         edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm");
583         edje_object_message_signal_process(wd->btn);
584      }
585    _sizing_eval(obj);
586 }
587
588 /**
589  * Get the icon used for the button
590  *
591  * Return the icon object which is set for this widget.
592  *
593  * @param[in] obj The button object
594  * @return The icon object that is being used
595  *
596  * @ingroup Button
597  */
598 EAPI Evas_Object *
599 elm_button_icon_get(const Evas_Object *obj)
600 {
601    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
602    Widget_Data *wd = elm_widget_data_get(obj);
603    if (!wd) return NULL;
604    return wd->icon;
605 }
606
607 /**
608  * Unset the icon used for the button
609  *
610  * Unparent and return the icon object which was set for this widget.
611  *
612  * @param[in] obj The button object
613  * @return The icon object that was being used
614  *
615  * @ingroup Button
616  */
617 EAPI Evas_Object *
618 elm_button_icon_unset(Evas_Object *obj)
619 {
620    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
621    Widget_Data *wd = elm_widget_data_get(obj);
622    if (!wd) return NULL;
623    if (!wd->icon) return NULL;
624    Evas_Object *icon = wd->icon;
625    elm_widget_sub_object_del(obj, wd->icon);
626    edje_object_part_unswallow(wd->btn, wd->icon);
627    wd->icon = NULL;
628    return icon;
629 }
630
631 /**
632  * Turn on/off the autorepeat event generated when the user keeps pressing on the button
633  *
634  * @param[in] obj The button object
635  * @param[in] on  A bool to turn on/off the event
636  *
637  * @ingroup Button
638  */
639 EAPI void
640 elm_button_autorepeat_set(Evas_Object *obj, Eina_Bool on)
641 {
642    ELM_CHECK_WIDTYPE(obj, widtype);
643    Widget_Data *wd = elm_widget_data_get(obj);
644    if (!wd) return;
645    if (wd->timer)
646      {
647         ecore_timer_del(wd->timer);
648         wd->timer = NULL;
649      }
650    wd->autorepeat = on;
651    wd->repeating = EINA_FALSE;
652 }
653
654 /**
655  * Get if autorepeat event is on
656  *
657  * @param[in] obj The button object
658  * @return If autorepeat is on
659  *
660  * @ingroup Button
661  */
662 EAPI Eina_Bool
663 elm_button_autorepeat_get(const Evas_Object *obj)
664 {
665    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
666    Widget_Data *wd = elm_widget_data_get(obj);
667    if (!wd) return EINA_FALSE;
668    return wd->autorepeat;
669 }
670
671 /**
672  * Set the initial timeout before the autorepeat event is generated
673  *
674  * @param[in] obj The button object
675  * @param[in] t   Timeout
676  *
677  * @ingroup Button
678  */
679 EAPI void
680 elm_button_autorepeat_initial_timeout_set(Evas_Object *obj, double t)
681 {
682    ELM_CHECK_WIDTYPE(obj, widtype);
683    Widget_Data *wd = elm_widget_data_get(obj);
684    if (!wd) return;
685    if (wd->ar_threshold == t) return;
686    if (wd->timer)
687      {
688         ecore_timer_del(wd->timer);
689         wd->timer = NULL;
690      }
691    wd->ar_threshold = t;
692 }
693
694 /**
695  * Get the initial timeout before the autorepeat event is generated
696  *
697  * @param[in] obj The button object
698  * @return Timeout
699  *
700  * @ingroup Button
701  */
702 EAPI double
703 elm_button_autorepeat_initial_timeout_get(const Evas_Object *obj)
704 {
705    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
706    Widget_Data *wd = elm_widget_data_get(obj);
707    if (!wd) return 0.0;
708    return wd->ar_threshold;
709 }
710
711 /**
712  * Set the interval between each generated autorepeat event
713  *
714  * @param[in] obj The button object
715  * @param[in] t   Interval
716  *
717  * @ingroup Button
718  */
719 EAPI void
720 elm_button_autorepeat_gap_timeout_set(Evas_Object *obj, double t)
721 {
722    ELM_CHECK_WIDTYPE(obj, widtype);
723    Widget_Data *wd = elm_widget_data_get(obj);
724    if (!wd) return;
725    if (wd->ar_interval == t) return;
726
727    wd->ar_interval = t;
728    if ((wd->repeating) && (wd->timer)) ecore_timer_interval_set(wd->timer, t);
729 }
730
731 /**
732  * Get the interval between each generated autorepeat event
733  *
734  * @param[in] obj The button object
735  * @return Interval
736  *
737  * @ingroup Button
738  */
739 EAPI double
740 elm_button_autorepeat_gap_timeout_get(const Evas_Object *obj)
741 {
742    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
743    Widget_Data *wd = elm_widget_data_get(obj);
744    if (!wd) return 0.0;
745    return wd->ar_interval;
746 }