#include <Elementary.h>
#include "elm_priv.h"
-/**
- * @defgroup Button Button
- *
- * This is a push-button. Press it and run some function. It can contain
- * a simple label and icon object.
- */
-
typedef struct _Widget_Data Widget_Data;
struct _Widget_Data
static const char SIG_CLICKED[] = "clicked";
static const char SIG_REPEATED[] = "repeated";
+static const char SIG_PRESSED[] = "pressed";
static const char SIG_UNPRESSED[] = "unpressed";
static const Evas_Smart_Cb_Description _signals[] = {
{SIG_CLICKED, ""},
{SIG_REPEATED, ""},
+ {SIG_PRESSED, ""},
{SIG_UNPRESSED, ""},
{NULL, NULL}
};
}
static void
-_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
+_signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
}
static void
-_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
+_signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
edje_object_signal_callback_del_full(wd->btn, emission, source, func_cb,
else
wd->timer = ecore_timer_add(wd->ar_threshold, _autorepeat_initial_send, data);
}
+
+ evas_object_smart_callback_call(data, SIG_PRESSED, NULL);
}
static void
evas_object_smart_callback_call(data, SIG_UNPRESSED, NULL);
}
-/**
- * Add a new button to the parent
- * @param parent The parent object
- * @return The new object or NULL if it cannot be created
- *
- * @ingroup Button
- */
+static void
+_elm_button_label_set(Evas_Object *obj, const char *item, const char *label)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (item && strcmp(item, "default")) return;
+ if (!wd) return;
+ eina_stringshare_replace(&wd->label, label);
+ if (label)
+ edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
+ else
+ edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
+ edje_object_message_signal_process(wd->btn);
+ edje_object_part_text_set(wd->btn, "elm.text", label);
+ _sizing_eval(obj);
+}
+
+static const char *
+_elm_button_label_get(const Evas_Object *obj, const char *item)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype) NULL;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (item && strcmp(item, "default")) return NULL;
+ if (!wd) return NULL;
+ return wd->label;
+}
+
+static char *
+_access_info_cb(const void *data, Evas_Object *obj, Elm_Widget_Item *item)
+{
+ const char *txt = _elm_button_label_get(obj, NULL);
+ if (txt) return strdup(txt);
+ return txt;
+}
+
EAPI Evas_Object *
elm_button_add(Evas_Object *parent)
{
Widget_Data *wd;
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
-
+
ELM_SET_WIDTYPE(widtype, "button");
elm_widget_type_set(obj, "button");
elm_widget_sub_object_add(parent, obj);
elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
+ elm_widget_text_set_hook_set(obj, _elm_button_label_set);
+ elm_widget_text_get_hook_set(obj, _elm_button_label_get);
wd->btn = edje_object_add(e);
_elm_theme_object_set(obj, wd->btn, "button", "base", "default");
// TODO: convert Elementary to subclassing of Evas_Smart_Class
// TODO: and save some bytes, making descriptions per-class and not instance!
evas_object_smart_callbacks_descriptions_set(obj, _signals);
+
+ _elm_access_object_register(obj, wd->btn);
+ _elm_access_text_set(_elm_access_object_get(obj),
+ ELM_ACCESS_TYPE, E_("Button"));
+ _elm_access_callback_set(_elm_access_object_get(obj),
+ ELM_ACCESS_INFO, _access_info_cb, obj);
return obj;
}
-/**
- * Set the label used in the button
- *
- * @param obj The button object
- * @param label The text will be written on the button
- *
- * @ingroup Button
- */
EAPI void
elm_button_label_set(Evas_Object *obj, const char *label)
{
- ELM_CHECK_WIDTYPE(obj, widtype);
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
- eina_stringshare_replace(&wd->label, label);
- if (label)
- edje_object_signal_emit(wd->btn, "elm,state,text,visible", "elm");
- else
- edje_object_signal_emit(wd->btn, "elm,state,text,hidden", "elm");
- edje_object_message_signal_process(wd->btn);
- edje_object_part_text_set(wd->btn, "elm.text", label);
- _sizing_eval(obj);
+ _elm_button_label_set(obj, NULL, label);
}
EAPI const char *
elm_button_label_get(const Evas_Object *obj)
{
- ELM_CHECK_WIDTYPE(obj, widtype) NULL;
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return NULL;
- return wd->label;
+ return _elm_button_label_get(obj, NULL);
}
-/**
- * Set the icon used for the button
- *
- * Once the icon object is set, a previously set one will be deleted
- * If you want to keep that old content object, use the
- * elm_button_icon_unset() function.
- *
- * @param obj The button object
- * @param icon The icon object for the button
- *
- * @ingroup Button
- */
EAPI void
elm_button_icon_set(Evas_Object *obj, Evas_Object *icon)
{
_sizing_eval(obj);
}
-/**
- * Get the icon used for the button
- *
- * Return the icon object which is set for this widget.
- *
- * @param obj The button object
- * @return The icon object that is being used
- *
- * @ingroup Button
- */
EAPI Evas_Object *
elm_button_icon_get(const Evas_Object *obj)
{
return wd->icon;
}
-/**
- * Unset the icon used for the button
- *
- * Unparent and return the icon object which was set for this widget.
- *
- * @param obj The button object
- * @return The icon object that was being used
- *
- * @ingroup Button
- */
EAPI Evas_Object *
elm_button_icon_unset(Evas_Object *obj)
{
return icon;
}
-/**
- * Turn on/off the autorepeat event generated when the user keeps pressing on the button
- *
- * @param obj The button object
- * @param on A bool to turn on/off the event
- *
- * @ingroup Button
- */
EAPI void
elm_button_autorepeat_set(Evas_Object *obj, Eina_Bool on)
{
wd->repeating = EINA_FALSE;
}
-/**
- * Get if autorepeat event is on
- *
- * @param obj The button object
- * @return If autorepeat is on
- *
- * @ingroup Button
- */
EAPI Eina_Bool
elm_button_autorepeat_get(const Evas_Object *obj)
{
return wd->autorepeat;
}
-/**
- * Set the initial timeout before the autorepeat event is generated
- *
- * @param obj The button object
- * @param t Timeout
- *
- * @ingroup Button
- */
EAPI void
elm_button_autorepeat_initial_timeout_set(Evas_Object *obj, double t)
{
wd->ar_threshold = t;
}
-/**
- * Get the initial timeout before the autorepeat event is generated
- *
- * @param obj The button object
- * @return Timeout
- *
- * @ingroup Button
- */
EAPI double
elm_button_autorepeat_initial_timeout_get(const Evas_Object *obj)
{
return wd->ar_threshold;
}
-/**
- * Set the interval between each generated autorepeat event
- *
- * @param obj The button object
- * @param t Interval
- *
- * @ingroup Button
- */
EAPI void
elm_button_autorepeat_gap_timeout_set(Evas_Object *obj, double t)
{
if ((wd->repeating) && (wd->timer)) ecore_timer_interval_set(wd->timer, t);
}
-/**
- * Get the interval between each generated autorepeat event
- *
- * @param obj The button object
- * @return Interval
- *
- * @ingroup Button
- */
EAPI double
elm_button_autorepeat_gap_timeout_get(const Evas_Object *obj)
{