and now do toolbar - showing how to add access stuff to items in a
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 24 Aug 2011 06:29:13 +0000 (06:29 +0000)
committerMike McCormack <mj.mccormack@samsung.com>
Mon, 14 Nov 2011 07:52:54 +0000 (16:52 +0900)
widget

git-svn-id: https://svn.enlightenment.org/svn/e/trunk/elementary@62733 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/elm_access.c
src/lib/elm_toolbar.c
src/lib/elm_widget.h

index 2e48d16..2964d97 100644 (file)
@@ -133,6 +133,31 @@ static void
 _access_read_done(void *data __UNUSED__)
 {
    printf("read done\n");
+   // FIXME: produce event here
+}
+
+static void
+_access_2nd_click_del_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+{
+   Ecore_Timer *t;
+
+   evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
+                                       _access_2nd_click_del_cb, NULL);
+   t = evas_object_data_get(obj, "_elm_2nd_timeout");
+   if (t)
+     {
+        ecore_timer_del(t);
+        evas_object_data_del(obj, "_elm_2nd_timeout");
+     }
+}
+
+static Eina_Bool
+_access_2nd_click_timeout_cb(void *data)
+{
+   evas_object_event_callback_del_full(data, EVAS_CALLBACK_DEL,
+                                       _access_2nd_click_del_cb, NULL);
+   evas_object_data_del(data, "_elm_2nd_timeout");
+   return EINA_FALSE;
 }
 
 static void
@@ -286,6 +311,12 @@ _elm_access_object_get(Evas_Object *obj)
    return evas_object_data_get(obj, "_elm_access");
 }
 
+EAPI Elm_Access_Info *
+_elm_access_item_get(Elm_Widget_Item *it)
+{
+   return it->access;
+}
+
 EAPI void
 _elm_access_object_hilight(Evas_Object *obj)
 {
@@ -391,28 +422,86 @@ _elm_access_object_register(Evas_Object *obj, Evas_Object *hoverobj)
    evas_object_data_set(obj, "_elm_access", ac);
 }
 
+static Eina_Bool
+_access_item_over_timeout_cb(void *data)
+{
+   Elm_Access_Info *ac = ((Elm_Widget_Item *)data)->access;
+   if (!ac) return EINA_FALSE;
+   if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
+     {
+        _elm_access_object_hilight(((Elm_Widget_Item *)data)->view);
+        _elm_access_read(ac, ELM_ACCESS_CANCEL, NULL, data);
+        _elm_access_read(ac, ELM_ACCESS_TYPE,   NULL, data);
+        _elm_access_read(ac, ELM_ACCESS_INFO,   NULL, data);
+        _elm_access_read(ac, ELM_ACCESS_STATE,  NULL, data);
+        _elm_access_read(ac, ELM_ACCESS_DONE,   NULL, data);
+     }
+   ac->delay_timer = NULL;
+   return EINA_FALSE;
+}
+
 static void
-_access_2nd_click_del_cb(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+_access_item_mouse_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info  __UNUSED__)
 {
-   Ecore_Timer *t;
+   Elm_Access_Info *ac = ((Elm_Widget_Item *)data)->access;
+   if (!ac) return;
+
+   if (ac->delay_timer)
+     {
+        ecore_timer_del(ac->delay_timer);
+        ac->delay_timer = NULL;
+     }
+   if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
+      ac->delay_timer = ecore_timer_add(0.2, _access_item_over_timeout_cb, data);
+}
+
+static void
+_access_item_mouse_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Elm_Access_Info *ac = ((Elm_Widget_Item *)data)->access;
+   if (!ac) return;
+   
+   _elm_access_object_unhilight(((Elm_Widget_Item *)data)->view);
+   if (ac->delay_timer)
+     {
+        ecore_timer_del(ac->delay_timer);
+        ac->delay_timer = NULL;
+     }
+}
 
+static void
+_access_item_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+{
+   Elm_Access_Info *ac;
+
+   evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOUSE_IN,
+                                       _access_item_mouse_in_cb, data);
+   evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOUSE_OUT,
+                                       _access_item_mouse_out_cb, data);
    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
-                                       _access_2nd_click_del_cb, NULL);
-   t = evas_object_data_get(obj, "_elm_2nd_timeout");
-   if (t)
+                                       _access_item_del_cb, data);
+   ac = ((Elm_Widget_Item *)data)->access;
+   ((Elm_Widget_Item *)data)->access = NULL;
+   if (ac)
      {
-        ecore_timer_del(t);
-        evas_object_data_del(obj, "_elm_2nd_timeout");
+        _elm_access_clear(ac);
+        free(ac);
      }
 }
 
-static Eina_Bool
-_access_2nd_click_timeout_cb(void *data)
+EAPI void
+_elm_access_item_register(Elm_Widget_Item *item, Evas_Object *hoverobj)
 {
-   evas_object_event_callback_del_full(data, EVAS_CALLBACK_DEL,
-                                       _access_2nd_click_del_cb, NULL);
-   evas_object_data_del(data, "_elm_2nd_timeout");
-   return EINA_FALSE;
+   Elm_Access_Info *ac;
+
+   evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_MOUSE_IN,
+                                  _access_item_mouse_in_cb, item);
+   evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_MOUSE_OUT,
+                                  _access_item_mouse_out_cb, item);
+   evas_object_event_callback_add(hoverobj, EVAS_CALLBACK_DEL,
+                                  _access_item_del_cb, item);
+   ac = calloc(1, sizeof(Elm_Access_Info));
+   item->access = ac;
 }
 
 EAPI Eina_Bool
@@ -435,9 +524,3 @@ _elm_access_2nd_click_timeout(Evas_Object *obj)
                                   _access_2nd_click_del_cb, NULL);
    return EINA_FALSE;
 }
-
-// XXX special version for items
-//EAPI void
-//_elm_access_item_hover_register(Elm_Widget_Item *item, Evas_Object *hoverobj)
-//{
-//}
index 525bc6b..c90974a 100644 (file)
@@ -639,7 +639,15 @@ _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *em
 static void
 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
 {
-   _item_select(data);
+   Elm_Toolbar_Item *it = data;
+   
+   if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
+       (_elm_access_2nd_click_timeout(it->base.view)))
+     {
+        if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
+           _elm_access_say(E_("Selected"));
+        _item_select(it);
+     }
 }
 
 static Eina_Bool
@@ -703,6 +711,31 @@ _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
    _els_box_layout(o, priv, 1, wd->homogeneous, elm_widget_mirrored_get(obj));
 }
 
+static char *
+_access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
+{
+   Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
+   char *txt = NULL; // FIXME set access info on items - prefer that
+   if (!txt) txt = (char *)it->label;
+   if (txt) return strdup(txt);
+   return txt;
+}
+
+static char *
+_access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
+{
+   Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
+   if (it->separator)
+      return strdup(E_("Separator"));
+   else if (it->disabled)
+      return strdup(E_("State: Disabled"));
+   else if (it->selected)
+      return strdup(E_("State: Selected"));
+   else if (it->menu)
+      return strdup(E_("Has menu"));
+   return NULL;
+}
+
 static Elm_Toolbar_Item *
 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
 {
@@ -727,6 +760,14 @@ _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb f
    it->separator = EINA_FALSE;
    it->base.data = data;
    VIEW(it) = edje_object_add(evas_object_evas_get(obj));
+   _elm_access_item_register((Elm_Widget_Item *)it, it->base.view);
+   _elm_access_text_set(_elm_access_item_get((Elm_Widget_Item *)it),
+                        ELM_ACCESS_TYPE, E_("Tool Item"));
+   _elm_access_callback_set(_elm_access_item_get((Elm_Widget_Item *)it),
+                            ELM_ACCESS_INFO, _access_info_cb, it);
+   _elm_access_callback_set(_elm_access_item_get((Elm_Widget_Item *)it),
+                            ELM_ACCESS_STATE, _access_state_cb, it);
+   
    if (_item_icon_set(icon_obj, "toolbar/", icon))
      {
         it->icon = icon_obj;
index 90f9d5a..b813135 100644 (file)
@@ -232,10 +232,12 @@ EAPI char            *_elm_access_text_get(Elm_Access_Info *ac, int type,  Evas_
 EAPI void             _elm_access_read(Elm_Access_Info *ac, int type, Evas_Object *obj, Elm_Widget_Item *item);
 EAPI void             _elm_access_say(const char *txt);
 EAPI Elm_Access_Info *_elm_access_object_get(Evas_Object *obj);
+EAPI Elm_Access_Info *_elm_access_item_get(Elm_Widget_Item *it);
 EAPI void             _elm_access_object_hilight(Evas_Object *obj);
 EAPI void             _elm_access_object_unhilight(Evas_Object *obj);
 EAPI void             _elm_access_object_hilight_disable(Evas *e);
 EAPI void             _elm_access_object_register(Evas_Object *obj, Evas_Object *hoverobj);
+EAPI void             _elm_access_item_register(Elm_Widget_Item *item, Evas_Object *hoverobj);
 EAPI Eina_Bool        _elm_access_2nd_click_timeout(Evas_Object *obj);
 
 #define ELM_WIDGET_ITEM Elm_Widget_Item base /**< put this as the first member in your widget item struct */
@@ -258,6 +260,7 @@ struct _Elm_Widget_Item
    Elm_Widget_On_Text_Set_Cb on_text_set_func;
    Elm_Widget_On_Text_Get_Cb on_text_get_func;
    Elm_Widget_On_Signal_Emit_Cb on_signal_emit_func;
+   Elm_Access_Info *access;
    /* widget variations should have data from here and on */
    /* @todo: TODO check if this is enough for 1.0 release, maybe add padding! */
 };