X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flib%2Felm_button.c;h=7f784ea84cedfab3fe41cdd1c6130ad57c657f7f;hb=76315f85e6f98edbe7ffe8cc6f695308aff2f89c;hp=33ed125fa83abb3ee9a3bcc8dfba4c73fe25065e;hpb=0a19754cc8e7d6427648fb5b70569db0c41d230e;p=framework%2Fuifw%2Felementary.git diff --git a/src/lib/elm_button.c b/src/lib/elm_button.c index 33ed125..7f784ea 100644 --- a/src/lib/elm_button.c +++ b/src/lib/elm_button.c @@ -1,10 +1,6 @@ #include #include "elm_priv.h" -/** - * @ingroup Elementary - */ - typedef struct _Widget_Data Widget_Data; enum @@ -34,6 +30,9 @@ static void _del_hook(Evas_Object *obj); static void _del_pre_hook(Evas_Object *obj); static void _theme_hook(Evas_Object *obj); static void _disable_hook(Evas_Object *obj); +static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content); +static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part); +static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part); static void _sizing_eval(Evas_Object *obj); static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _sub_del(void *data, Evas_Object *obj, void *event_info); @@ -112,15 +111,15 @@ _on_focus_hook(void *data __UNUSED__, Evas_Object *obj) { _set_label(obj, wd->statelabel[FOCUSED]); } - edje_object_signal_emit(wd->btn, "elm,action,focus", "elm"); - evas_object_focus_set(wd->btn, EINA_TRUE); + edje_object_signal_emit(wd->btn, "elm,action,focus", "elm"); + evas_object_focus_set(wd->btn, EINA_TRUE); } else { if (wd->statelabel[DEFAULT]) _set_label(obj, wd->statelabel[DEFAULT]); - edje_object_signal_emit(wd->btn, "elm,action,unfocus", "elm"); - evas_object_focus_set(wd->btn, EINA_FALSE); + edje_object_signal_emit(wd->btn, "elm,action,unfocus", "elm"); + evas_object_focus_set(wd->btn, EINA_FALSE); } } @@ -210,20 +209,63 @@ _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *so } static void +_content_set_hook(Evas_Object *obj, const char *part __UNUSED__, Evas_Object *content) +{ + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + if (wd->icon == content) return; + if (wd->icon) evas_object_del(wd->icon); + wd->icon = content; + if (content) + { + elm_widget_sub_object_add(obj, content); + evas_object_event_callback_add(content, + EVAS_CALLBACK_CHANGED_SIZE_HINTS, + _changed_size_hints, obj); + edje_object_part_swallow(wd->btn, "elm.swallow.content", content); + edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm"); + edje_object_message_signal_process(wd->btn); + } + _sizing_eval(obj); +} + +static Evas_Object * +_content_get_hook(const Evas_Object *obj, const char *part __UNUSED__) +{ + ELM_CHECK_WIDTYPE(obj, widtype) NULL; + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return NULL; + return wd->icon; +} + +static Evas_Object * +_content_unset_hook(Evas_Object *obj, const char *part __UNUSED__) +{ + ELM_CHECK_WIDTYPE(obj, widtype) NULL; + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return NULL; + if (!wd->icon) return NULL; + Evas_Object *icon = wd->icon; + elm_widget_sub_object_del(obj, wd->icon); + evas_object_event_callback_del_full(wd->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS, + _changed_size_hints, obj); + edje_object_part_unswallow(wd->btn, wd->icon); + wd->icon = NULL; + return icon; +} + +static void _sizing_eval(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); Evas_Coord minw = -1, minh = -1; - Evas_Coord w, h; if (!wd) return; if (wd->delete_me) return; elm_coords_finger_size_adjust(1, &minw, 1, &minh); edje_object_size_min_restricted_calc(wd->btn, &minw, &minh, minw, minh); elm_coords_finger_size_adjust(1, &minw, 1, &minh); - evas_object_size_hint_min_get(obj, &w, &h); - if (h > minh) minh = h; - evas_object_size_hint_min_set(obj, minw, minh); } @@ -348,7 +390,7 @@ _signal_unpressed(void *data, Evas_Object *obj __UNUSED__, const char *emission } static void -_signal_default_text_set(void *data, Evas_Object *obj, const char *emission, const char *source) +_signal_default_text_set(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { Widget_Data *wd = elm_widget_data_get(data); if (!wd) return; @@ -356,6 +398,7 @@ _signal_default_text_set(void *data, Evas_Object *obj, const char *emission, con _set_label(data, wd->statelabel[DEFAULT]); } +static void _elm_button_label_set(Evas_Object *obj, const char *item, const char *label) { ELM_CHECK_WIDTYPE(obj, widtype); @@ -382,6 +425,14 @@ _elm_button_label_get(const Evas_Object *obj, const char *item) 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) { @@ -408,6 +459,9 @@ elm_button_add(Evas_Object *parent) 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); + elm_widget_content_set_hook_set(obj, _content_set_hook); + elm_widget_content_get_hook_set(obj, _content_get_hook); + elm_widget_content_unset_hook_set(obj, _content_unset_hook); wd->btn = edje_object_add(e); _elm_theme_object_set(obj, wd->btn, "button", "base", "default"); @@ -436,6 +490,12 @@ elm_button_add(Evas_Object *parent) // 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; } @@ -512,48 +572,23 @@ elm_button_label_get(const Evas_Object *obj) return _elm_button_label_get(obj, NULL); } + EAPI void elm_button_icon_set(Evas_Object *obj, Evas_Object *icon) { - ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; - if (wd->icon == icon) return; - if (wd->icon) evas_object_del(wd->icon); - wd->icon = icon; - if (icon) - { - elm_widget_sub_object_add(obj, icon); - evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS, - _changed_size_hints, obj); - edje_object_part_swallow(wd->btn, "elm.swallow.content", icon); - edje_object_signal_emit(wd->btn, "elm,state,icon,visible", "elm"); - edje_object_message_signal_process(wd->btn); - } - _sizing_eval(obj); + _content_set_hook(obj, NULL, icon); } EAPI Evas_Object * elm_button_icon_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->icon; + return _content_get_hook(obj, NULL); } EAPI Evas_Object * elm_button_icon_unset(Evas_Object *obj) { - ELM_CHECK_WIDTYPE(obj, widtype) NULL; - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return NULL; - if (!wd->icon) return NULL; - Evas_Object *icon = wd->icon; - elm_widget_sub_object_del(obj, wd->icon); - edje_object_part_unswallow(wd->btn, wd->icon); - wd->icon = NULL; - return icon; + return _content_unset_hook(obj, NULL); } EAPI void