[elm] Rework focus_region and on_focus_region
authorGustavo Lima Chaves <glima@profusion.mobi>
Thu, 30 Aug 2012 16:47:16 +0000 (16:47 +0000)
committerGustavo Lima Chaves <glima@profusion.mobi>
Thu, 30 Aug 2012 16:47:16 +0000 (16:47 +0000)
 hooks.

The former is now issued for all scrollables, with the behavior it had
before, and the latter is a new virtual base function, with a default
implementation leading to values matching the old case where one
didn't implement the hook.

Please help me test if everything is OK -- it seems so, here.

SVN revision: 75904

src/lib/elm_entry.c
src/lib/elm_scroller.c
src/lib/elm_widget.c
src/lib/elm_widget.h

index d08c548..177079e 100644 (file)
@@ -866,11 +866,11 @@ _elm_entry_smart_translate(Evas_Object *obj)
 }
 
 static void
-_on_focus_region_hook(const Evas_Object *obj,
-                      Evas_Coord *x,
-                      Evas_Coord *y,
-                      Evas_Coord *w,
-                      Evas_Coord *h)
+_elm_entry_smart_on_focus_region(const Evas_Object *obj,
+                                 Evas_Coord *x,
+                                 Evas_Coord *y,
+                                 Evas_Coord *w,
+                                 Evas_Coord *h)
 {
    ELM_ENTRY_DATA_GET(obj, sd);
 
@@ -879,19 +879,6 @@ _on_focus_region_hook(const Evas_Object *obj,
 }
 
 static void
-_focus_region_hook(Evas_Object *obj,
-                   Evas_Coord x,
-                   Evas_Coord y,
-                   Evas_Coord w,
-                   Evas_Coord h)
-{
-   ELM_ENTRY_DATA_GET(obj, sd);
-
-   if (sd->scroll)
-     sd->s_iface->content_region_show(obj, x, y, w, h);
-}
-
-static void
 _show_region_hook(void *data,
                   Evas_Object *obj)
 {
@@ -2887,8 +2874,6 @@ _elm_entry_smart_add(Evas_Object *obj)
 
    elm_layout_text_set(obj, "elm.text", "");
 
-   elm_widget_focus_region_hook_set(obj, _focus_region_hook);
-   elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
    elm_object_sub_cursor_set
      (ELM_WIDGET_DATA(priv)->resize_obj, obj, ELM_CURSOR_XTERM);
    elm_widget_can_focus_set(obj, EINA_TRUE);
@@ -3065,6 +3050,7 @@ _elm_entry_smart_set_user(Elm_Entry_Smart_Class *sc)
    ELM_WIDGET_CLASS(sc)->base.resize = _elm_entry_smart_resize;
    ELM_WIDGET_CLASS(sc)->base.member_add = _elm_entry_smart_member_add;
 
+   ELM_WIDGET_CLASS(sc)->on_focus_region = _elm_entry_smart_on_focus_region;
    ELM_WIDGET_CLASS(sc)->sub_object_del = _elm_entry_smart_sub_object_del;
    ELM_WIDGET_CLASS(sc)->on_focus = _elm_entry_smart_on_focus;
    ELM_WIDGET_CLASS(sc)->theme = _elm_entry_smart_theme;
index 593253d..c1e5ba6 100644 (file)
@@ -354,18 +354,6 @@ _show_region_hook(void *data,
 }
 
 static void
-_focus_region_hook(Evas_Object *obj,
-                   Evas_Coord x,
-                   Evas_Coord y,
-                   Evas_Coord w,
-                   Evas_Coord h)
-{
-   ELM_SCROLLER_DATA_GET(obj, sd);
-
-   sd->s_iface->content_region_show(obj, x, y, w, h);
-}
-
-static void
 _changed_size_hints_cb(void *data,
                        Evas *e __UNUSED__,
                        Evas_Object *obj __UNUSED__,
@@ -563,9 +551,6 @@ _elm_scroller_smart_add(Evas_Object *obj)
    evas_object_show(priv->hit_rect);
    evas_object_repeat_events_set(priv->hit_rect, EINA_TRUE);
 
-   /* FIXME: rework it */
-   elm_widget_focus_region_hook_set(obj, _focus_region_hook);
-
    priv->s_iface = evas_object_smart_interface_get
        (obj, ELM_SCROLLABLE_IFACE_NAME);
 
index df01e72..3dd8de4 100644 (file)
@@ -96,6 +96,18 @@ _elm_widget_theme_func(Evas_Object *obj)
    return EINA_TRUE;
 }
 
+static void
+_elm_widget_on_focus_region_func(const Evas_Object *obj,
+                                 Evas_Coord *x,
+                                 Evas_Coord *y,
+                                 Evas_Coord *w,
+                                 Evas_Coord *h)
+{
+   evas_object_geometry_get(obj, NULL, NULL, w, h);
+   if (x) *x = 0;
+   if (y) *y = 0;
+}
+
 static Eina_Bool
 _elm_widget_on_focus_func_unimplemented(Evas_Object *obj)
 {
@@ -706,7 +718,8 @@ _elm_widget_smart_set(Elm_Widget_Smart_Class *api)
    API_DEFAULT_SET_UNIMPLEMENTED(on_focus);
    API_DEFAULT_SET_UNIMPLEMENTED(disable);
 
-   api->theme = _elm_widget_theme_func;
+   API_DEFAULT_SET(theme);
+   API_DEFAULT_SET(on_focus_region);
 
    API_DEFAULT_SET_UNIMPLEMENTED(translate);
    API_DEFAULT_SET_UNIMPLEMENTED(event);
@@ -873,7 +886,6 @@ static void
 _elm_widget_focus_region_show(const Evas_Object *obj)
 {
    Evas_Coord x, y, w, h, ox, oy;
-   Elm_Widget_Smart_Data *sd2;
    Evas_Object *o;
 
    API_ENTRY return;
@@ -883,13 +895,17 @@ _elm_widget_focus_region_show(const Evas_Object *obj)
 
    elm_widget_focus_region_get(obj, &x, &y, &w, &h);
    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
+
    while (o)
      {
         Evas_Coord px, py;
-        sd2 = evas_object_smart_data_get(o);
-        if (sd2->focus_region)
+
+        if (_elm_scrollable_is(o))
           {
-             sd2->focus_region(o, x, y, w, h);
+             ELM_SCROLLABLE_IFACE_GET(o, s_iface);
+
+             s_iface->content_region_show(o, x, y, w, h);
+
              elm_widget_focus_region_get(o, &x, &y, &w, &h);
           }
         else
@@ -1175,62 +1191,6 @@ elm_widget_on_show_region_hook_set(Evas_Object *obj,
    sd->on_show_region_data = data;
 }
 
-/**
- * @internal
- *
- * Set the hook to use to show the focused region.
- *
- * Whenever a new widget gets focused or it's needed to show the focused
- * area of the current one, this hook will be called on objects that may
- * want to move their children into their visible area.
- * The area given in the hook function is relative to the @p obj widget.
- *
- * @param obj The widget object
- * @param func The function to call to show the specified area.
- *
- * @ingroup Widget
- */
-EAPI void
-elm_widget_focus_region_hook_set(Evas_Object *obj,
-                                 void (*func)(Evas_Object *obj,
-                                              Evas_Coord x,
-                                              Evas_Coord y,
-                                              Evas_Coord w,
-                                              Evas_Coord h))
-{
-   API_ENTRY return;
-
-   sd->focus_region = func;
-}
-
-/**
- * @internal
- *
- * Set the hook to retrieve the focused region of a widget.
- *
- * This hook will be called by elm_widget_focus_region_get() whenever
- * it's needed to get the focused area of a widget. The area must be relative
- * to the widget itself and if no hook is set, it will default to the entire
- * object.
- *
- * @param obj The widget object
- * @param func The function used to retrieve the focus region.
- *
- * @ingroup Widget
- */
-EAPI void
-elm_widget_on_focus_region_hook_set(Evas_Object *obj,
-                                    void (*func)(const Evas_Object *obj,
-                                                 Evas_Coord *x,
-                                                 Evas_Coord *y,
-                                                 Evas_Coord *w,
-                                                 Evas_Coord *h))
-{
-   API_ENTRY return;
-
-   sd->on_focus_region = func;
-}
-
 EAPI Eina_Bool
 elm_widget_sub_object_add(Evas_Object *obj,
                           Evas_Object *sobj)
@@ -2834,19 +2794,17 @@ elm_widget_focus_region_get(const Evas_Object *obj,
                             Evas_Coord *w,
                             Evas_Coord *h)
 {
-   Elm_Widget_Smart_Data *sd;
-
-   if (!obj) return;
-
-   sd = evas_object_smart_data_get(obj);
-   if (!sd || !_elm_widget_is(obj) || !sd->on_focus_region)
+   if (!_elm_widget_is(obj))
      {
         evas_object_geometry_get(obj, NULL, NULL, w, h);
         if (x) *x = 0;
         if (y) *y = 0;
         return;
      }
-   sd->on_focus_region(obj, x, y, w, h);
+
+   ELM_WIDGET_DATA_GET(obj, sd);
+
+   sd->api->on_focus_region(obj, x, y, w, h);
 }
 
 EAPI Eina_List *
index 8a43638..0a90cd4 100644 (file)
  */
 #define ELM_WIDGET_SMART_CLASS_INIT(smart_class_init)                        \
   {smart_class_init, ELM_WIDGET_SMART_CLASS_VERSION, NULL, NULL, NULL, NULL, \
-   NULL, NULL, NULL, NULL, NULL, NULL, NULL}
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
 
 /**
  * @def ELM_WIDGET_SMART_CLASS_INIT_NULL
@@ -437,6 +437,11 @@ typedef struct _Elm_Widget_Smart_Class
                              Evas_Object *source,
                              Evas_Callback_Type type,
                              void *event_info); /**< 'Virtual' function handling input events on the widget */
+   void             (*on_focus_region)(const Evas_Object *obj,
+                                       Evas_Coord *x,
+                                       Evas_Coord *y,
+                                       Evas_Coord *w,
+                                       Evas_Coord *h); /**< 'Virtual' function returning an inner area of a widget that should be brought into the visible are of a broader viewport, may this context arise. On the base Elementary widget class, it defaults to the object's total area, so only override it if you have to. */
    Eina_Bool        (*focus_next)(const Evas_Object *obj,
                                   Elm_Focus_Direction dir,
                                   Evas_Object **next); /**< 'Virtual' function handling passing focus to sub-objects */
@@ -497,16 +502,6 @@ typedef struct _Elm_Widget_Smart_Data
    void                         *on_show_region_data;
    void                        (*on_show_region)(void *data,
                                                  Evas_Object *obj);
-   void                        (*focus_region)(Evas_Object *obj,
-                                               Evas_Coord x,
-                                               Evas_Coord y,
-                                               Evas_Coord w,
-                                               Evas_Coord h);
-   void                        (*on_focus_region)(const Evas_Object *obj,
-                                                  Evas_Coord *x,
-                                                  Evas_Coord *y,
-                                                  Evas_Coord *w,
-                                                  Evas_Coord *h);
 
    int                           frozen;
 
@@ -657,8 +652,6 @@ EAPI Eina_Bool        elm_widget_theme(Evas_Object *obj);
 EAPI void             elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force);
 EAPI void             elm_widget_translate(Evas_Object *obj);
 EAPI void             elm_widget_on_show_region_hook_set(Evas_Object *obj, void (*func)(void *data, Evas_Object *obj), void *data);
-EAPI void             elm_widget_focus_region_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h));
-EAPI void             elm_widget_on_focus_region_hook_set(Evas_Object *obj, void (*func)(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h));
 EAPI Eina_Bool        elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj);
 EAPI Eina_Bool        elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj);
 EAPI void             elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj);