[elm] Grid now inheritable.
authorGustavo Lima Chaves <glima@profusion.mobi>
Tue, 31 Jul 2012 22:05:06 +0000 (22:05 +0000)
committerGustavo Lima Chaves <glima@profusion.mobi>
Tue, 31 Jul 2012 22:05:06 +0000 (22:05 +0000)
SVN revision: 74671

src/lib/elm_grid.c
src/lib/elm_widget_grid.h [new file with mode: 0644]

index 2d2d38f..659e54b 100644 (file)
@@ -1,37 +1,11 @@
 #include <Elementary.h>
 #include "elm_priv.h"
+#include "elm_widget_grid.h"
 
-static const char GRID_SMART_NAME[] = "elm_grid";
-
-typedef struct _Elm_Grid_Smart_Data Elm_Grid_Smart_Data;
-
-#define ELM_GRID_DATA_GET(o, sd) \
-  Elm_Widget_Smart_Data * sd = evas_object_smart_data_get(o)
-
-#define ELM_GRID_DATA_GET_OR_RETURN(o, ptr)          \
-  ELM_GRID_DATA_GET(o, ptr);                         \
-  if (!ptr)                                          \
-    {                                                \
-       CRITICAL("No widget data for object %p (%s)", \
-                o, evas_object_type_get(o));         \
-       return;                                       \
-    }
-
-#define ELM_GRID_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
-  ELM_GRID_DATA_GET(o, ptr);                         \
-  if (!ptr)                                          \
-    {                                                \
-       CRITICAL("No widget data for object %p (%s)", \
-                o, evas_object_type_get(o));         \
-       return val;                                   \
-    }
-
-#define ELM_GRID_CHECK(obj)                                             \
-  if (!obj || !elm_widget_type_check((obj), GRID_SMART_NAME, __func__)) \
-    return
+EAPI const char ELM_GRID_SMART_NAME[] = "elm_grid";
 
 EVAS_SMART_SUBCLASS_NEW
-  (GRID_SMART_NAME, _elm_grid, Elm_Widget_Smart_Class,
+  (ELM_GRID_SMART_NAME, _elm_grid, Elm_Grid_Smart_Class,
   Elm_Widget_Smart_Class, elm_widget_smart_class_get, NULL);
 
 static Eina_Bool
@@ -55,7 +29,7 @@ _elm_grid_smart_focus_next(const Evas_Object *obj,
      }
    else
      {
-        items = evas_object_grid_children_get(sd->resize_obj);
+        items = evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
         list_data_get = eina_list_data_get;
         list_free = eina_list_free;
 
@@ -92,7 +66,7 @@ _elm_grid_smart_focus_direction(const Evas_Object *obj,
      }
    else
      {
-        items = evas_object_grid_children_get(sd->resize_obj);
+        items = evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
         list_data_get = eina_list_data_get;
         list_free = eina_list_free;
 
@@ -112,7 +86,7 @@ _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
 {
    ELM_GRID_DATA_GET(obj, sd);
 
-   evas_object_grid_mirrored_set(sd->resize_obj, rtl);
+   evas_object_grid_mirrored_set(ELM_WIDGET_DATA(sd)->resize_obj, rtl);
 }
 
 static Eina_Bool
@@ -128,10 +102,11 @@ _elm_grid_smart_theme(Evas_Object *obj)
 static void
 _elm_grid_smart_add(Evas_Object *obj)
 {
-   EVAS_SMART_DATA_ALLOC(obj, Elm_Widget_Smart_Data);
+   EVAS_SMART_DATA_ALLOC(obj, Elm_Grid_Smart_Data);
 
-   priv->resize_obj = evas_object_grid_add(evas_object_evas_get(obj));
-   evas_object_grid_size_set(priv->resize_obj, 100, 100);
+   ELM_WIDGET_DATA(priv)->resize_obj =
+     evas_object_grid_add(evas_object_evas_get(obj));
+   evas_object_grid_size_set(ELM_WIDGET_DATA(priv)->resize_obj, 100, 100);
 
    _elm_grid_parent_sc->base.add(obj);
 
@@ -150,11 +125,12 @@ _elm_grid_smart_del(Evas_Object *obj)
 
    /* let's make our grid object the *last* to be processed, since it
     * may (smart) parent other sub objects here */
-   EINA_LIST_FOREACH (sd->subobjs, l, child)
+   EINA_LIST_FOREACH (ELM_WIDGET_DATA(sd)->subobjs, l, child)
      {
-        if (child == sd->resize_obj)
+        if (child == ELM_WIDGET_DATA(sd)->resize_obj)
           {
-             sd->subobjs = eina_list_demote_list(sd->subobjs, l);
+             ELM_WIDGET_DATA(sd)->subobjs =
+               eina_list_demote_list(ELM_WIDGET_DATA(sd)->subobjs, l);
              break;
           }
      }
@@ -163,14 +139,29 @@ _elm_grid_smart_del(Evas_Object *obj)
 }
 
 static void
-_elm_grid_smart_set_user(Elm_Widget_Smart_Class *sc)
+_elm_grid_smart_set_user(Elm_Grid_Smart_Class *sc)
 {
-   sc->base.add = _elm_grid_smart_add;
-   sc->base.del = _elm_grid_smart_del;
+   ELM_WIDGET_CLASS(sc)->base.add = _elm_grid_smart_add;
+   ELM_WIDGET_CLASS(sc)->base.del = _elm_grid_smart_del;
+
+   ELM_WIDGET_CLASS(sc)->theme = _elm_grid_smart_theme;
+   ELM_WIDGET_CLASS(sc)->focus_next = _elm_grid_smart_focus_next;
+   ELM_WIDGET_CLASS(sc)->focus_direction = _elm_grid_smart_focus_direction;
+}
+
+EAPI const Elm_Grid_Smart_Class *
+elm_grid_smart_class_get(void)
+{
+   static Elm_Grid_Smart_Class _sc =
+     ELM_GRID_SMART_CLASS_INIT_NAME_VERSION(ELM_GRID_SMART_NAME);
+   static const Elm_Grid_Smart_Class *class = NULL;
+
+   if (class) return class;
+
+   _elm_grid_smart_set(&_sc);
+   class = &_sc;
 
-   sc->theme = _elm_grid_smart_theme;
-   sc->focus_next = _elm_grid_smart_focus_next;
-   sc->focus_direction = _elm_grid_smart_focus_direction;
+   return class;
 }
 
 EAPI Evas_Object *
@@ -197,7 +188,7 @@ elm_grid_size_set(Evas_Object *obj,
    ELM_GRID_CHECK(obj);
    ELM_GRID_DATA_GET(obj, sd);
 
-   evas_object_grid_size_set(sd->resize_obj, w, h);
+   evas_object_grid_size_set(ELM_WIDGET_DATA(sd)->resize_obj, w, h);
 }
 
 EAPI void
@@ -208,7 +199,7 @@ elm_grid_size_get(const Evas_Object *obj,
    ELM_GRID_CHECK(obj);
    ELM_GRID_DATA_GET(obj, sd);
 
-   evas_object_grid_size_get(sd->resize_obj, w, h);
+   evas_object_grid_size_get(ELM_WIDGET_DATA(sd)->resize_obj, w, h);
 }
 
 EAPI void
@@ -223,7 +214,7 @@ elm_grid_pack(Evas_Object *obj,
    ELM_GRID_DATA_GET(obj, sd);
 
    elm_widget_sub_object_add(obj, subobj);
-   evas_object_grid_pack(sd->resize_obj, subobj, x, y, w, h);
+   evas_object_grid_pack(ELM_WIDGET_DATA(sd)->resize_obj, subobj, x, y, w, h);
 }
 
 EAPI void
@@ -234,7 +225,7 @@ elm_grid_unpack(Evas_Object *obj,
    ELM_GRID_DATA_GET(obj, sd);
 
    elm_widget_sub_object_del(obj, subobj);
-   evas_object_grid_unpack(sd->resize_obj, subobj);
+   evas_object_grid_unpack(ELM_WIDGET_DATA(sd)->resize_obj, subobj);
 }
 
 EAPI void
@@ -249,12 +240,12 @@ elm_grid_clear(Evas_Object *obj,
 
    if (!clear)
      {
-        chld = evas_object_grid_children_get(sd->resize_obj);
+        chld = evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
         EINA_LIST_FREE (chld, o)
           elm_widget_sub_object_del(obj, o);
      }
 
-   evas_object_grid_clear(sd->resize_obj, clear);
+   evas_object_grid_clear(ELM_WIDGET_DATA(sd)->resize_obj, clear);
 }
 
 EAPI void
@@ -269,7 +260,7 @@ elm_grid_pack_set(Evas_Object *subobj,
    ELM_GRID_CHECK(obj);
    ELM_GRID_DATA_GET(obj, sd);
 
-   evas_object_grid_pack(sd->resize_obj, subobj, x, y, w, h);
+   evas_object_grid_pack(ELM_WIDGET_DATA(sd)->resize_obj, subobj, x, y, w, h);
 }
 
 EAPI void
@@ -284,7 +275,8 @@ elm_grid_pack_get(Evas_Object *subobj,
    ELM_GRID_CHECK(obj);
    ELM_GRID_DATA_GET(obj, sd);
 
-   evas_object_grid_pack_get(sd->resize_obj, subobj, x, y, w, h);
+   evas_object_grid_pack_get
+     (ELM_WIDGET_DATA(sd)->resize_obj, subobj, x, y, w, h);
 }
 
 EAPI Eina_List *
@@ -293,5 +285,5 @@ elm_grid_children_get(const Evas_Object *obj)
    ELM_GRID_CHECK(obj) NULL;
    ELM_GRID_DATA_GET(obj, sd);
 
-   return evas_object_grid_children_get(sd->resize_obj);
+   return evas_object_grid_children_get(ELM_WIDGET_DATA(sd)->resize_obj);
 }
diff --git a/src/lib/elm_widget_grid.h b/src/lib/elm_widget_grid.h
new file mode 100644 (file)
index 0000000..f557038
--- /dev/null
@@ -0,0 +1,158 @@
+#ifndef ELM_WIDGET_GRID_H
+#define ELM_WIDGET_GRID_H
+
+/**
+ * @addtogroup Widget
+ * @{
+ *
+ * @section elm-grid-class The Elementary Grid Class
+ *
+ * Elementary, besides having the @ref Grid widget, exposes its
+ * foundation -- the Elementary Grid Class -- in order to create other
+ * widgets which are a grid with some more logic on top.
+ */
+
+/**
+ * @def ELM_GRID_CLASS
+ *
+ * Use this macro to cast whichever subclass of
+ * #Elm_Grid_Smart_Class into it, so to access its fields.
+ *
+ * @ingroup Widget
+ */
+#define ELM_GRID_CLASS(x) ((Elm_Grid_Smart_Class *)x)
+
+/**
+ * @def ELM_GRID_DATA
+ *
+ * Use this macro to cast whichever subdata of
+ * #Elm_Grid_Smart_Data into it, so to access its fields.
+ *
+ * @ingroup Widget
+ */
+#define ELM_GRID_DATA(x)  ((Elm_Grid_Smart_Data *)x)
+
+/**
+ * @def ELM_GRID_SMART_CLASS_VERSION
+ *
+ * Current version for Elementary grid @b base smart class, a value
+ * which goes to _Elm_Grid_Smart_Class::version.
+ *
+ * @ingroup Widget
+ */
+#define ELM_GRID_SMART_CLASS_VERSION 1
+
+/**
+ * @def ELM_GRID_SMART_CLASS_INIT
+ *
+ * Initializer for a whole #Elm_Grid_Smart_Class structure, with
+ * @c NULL values on its specific fields.
+ *
+ * @param smart_class_init initializer to use for the "base" field
+ * (#Evas_Smart_Class).
+ *
+ * @see EVAS_SMART_CLASS_INIT_NULL
+ * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
+ * @see ELM_GRID_SMART_CLASS_INIT_NULL
+ * @see ELM_GRID_SMART_CLASS_INIT_NAME_VERSION
+ *
+ * @ingroup Widget
+ */
+#define ELM_GRID_SMART_CLASS_INIT(smart_class_init) \
+  {smart_class_init, ELM_GRID_SMART_CLASS_VERSION}
+
+/**
+ * @def ELM_GRID_SMART_CLASS_INIT_NULL
+ *
+ * Initializer to zero out a whole #Elm_Grid_Smart_Class structure.
+ *
+ * @see ELM_GRID_SMART_CLASS_INIT_NAME_VERSION
+ * @see ELM_GRID_SMART_CLASS_INIT
+ *
+ * @ingroup Widget
+ */
+#define ELM_GRID_SMART_CLASS_INIT_NULL \
+  ELM_GRID_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
+
+/**
+ * @def ELM_GRID_SMART_CLASS_INIT_NAME_VERSION
+ *
+ * Initializer to zero out a whole #Elm_Grid_Smart_Class structure and
+ * set its name and version.
+ *
+ * This is similar to #ELM_GRID_SMART_CLASS_INIT_NULL, but it will
+ * also set the version field of #Elm_Grid_Smart_Class (base field)
+ * to the latest #ELM_GRID_SMART_CLASS_VERSION and name it to the
+ * specific value.
+ *
+ * It will keep a reference to the name field as a <c>"const char *"</c>,
+ * i.e., the name must be available while the structure is
+ * used (hint: static or global variable!) and must not be modified.
+ *
+ * @see ELM_GRID_SMART_CLASS_INIT_NULL
+ * @see ELM_GRID_SMART_CLASS_INIT
+ *
+ * @ingroup Widget
+ */
+#define ELM_GRID_SMART_CLASS_INIT_NAME_VERSION(name) \
+  ELM_GRID_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
+
+/**
+ * Elementary grid base smart class. This inherits directly from
+ * #Elm_Widget_Smart_Class and is meant to build widgets extending the
+ * behavior of a grid.
+ *
+ * All of the functions listed on @ref Grid namespace will work for
+ * objects deriving from #Elm_Grid_Smart_Class.
+ */
+typedef struct _Elm_Grid_Smart_Class
+{
+   Elm_Widget_Smart_Class base;
+
+   int                    version; /**< Version of this smart class definition */
+} Elm_Grid_Smart_Class;
+
+/**
+ * Base widget smart data extended with grid instance data.
+ */
+typedef struct _Elm_Grid_Smart_Data Elm_Grid_Smart_Data;
+struct _Elm_Grid_Smart_Data
+{
+   Elm_Widget_Smart_Data    base; /* base widget smart data as
+                                   * first member obligatory, as
+                                   * we're inheriting from it */
+};
+/**
+ * @}
+ */
+
+EAPI extern const char ELM_GRID_SMART_NAME[];
+EAPI const Elm_Grid_Smart_Class
+*elm_grid_smart_class_get(void);
+
+#define ELM_GRID_DATA_GET(o, sd) \
+  Elm_Grid_Smart_Data * sd = evas_object_smart_data_get(o)
+
+#define ELM_GRID_DATA_GET_OR_RETURN(o, ptr)          \
+  ELM_GRID_DATA_GET(o, ptr);                         \
+  if (!ptr)                                          \
+    {                                                \
+       CRITICAL("No widget data for object %p (%s)", \
+                o, evas_object_type_get(o));         \
+       return;                                       \
+    }
+
+#define ELM_GRID_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
+  ELM_GRID_DATA_GET(o, ptr);                         \
+  if (!ptr)                                          \
+    {                                                \
+       CRITICAL("No widget data for object %p (%s)", \
+                o, evas_object_type_get(o));         \
+       return val;                                   \
+    }
+
+#define ELM_GRID_CHECK(obj)                                                 \
+  if (!obj || !elm_widget_type_check((obj), ELM_GRID_SMART_NAME, __func__)) \
+    return
+
+#endif