[accessability] Initial merge
[framework/uifw/elementary.git] / src / lib / elm_button.c
index 242568b..7f784ea 100644 (file)
@@ -1,10 +1,6 @@
 #include <Elementary.h>
 #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,6 +209,53 @@ _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);
@@ -379,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)
 {
@@ -405,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");
@@ -433,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;
 }
 
@@ -509,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