Here is a patch which adds the ability for elm_widgets to have a color_class hook.

Some background:
This came about because of an app I am working on. In the app, I use custom-themed elm_buttons (w/ elm_object_style_set). These custom-themed buttons need the ability to change some colors such as background, etc, etc (when certain events occur), and the elm_button does not expose it's edje_object to allow edje_object_color_class_set calls.

So the attached patch adds the ability for an elm_widget to have a color_class hook. When someone calls elm_object_color_class_set, the hook will get fired and the widget can call edje_object_color_class_set in the hook on the appropriate edje objects.

The only widget I added this for currently is elm_button (cause that's what I needed.) If the patch goes in, feel free to add the hook for other widgets ;)

dh
Index: elm_button.c
===================================================================
--- elm_button.c	(revision 52765)
+++ elm_button.c	(working copy)
@@ -36,17 +36,28 @@
 static void _activate_hook(Evas_Object *obj);
 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
                              Evas_Callback_Type type, void *event_info);
+static void _color_class_hook(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3);
 
 static const char SIG_CLICKED[] = "clicked";
 static const char SIG_REPEATED[] = "repeated";
 static const char SIG_UNPRESSED[] = "unpressed";
-static const Evas_Smart_Cb_Description _signals[] = {
+static const Evas_Smart_Cb_Description _signals[] = 
+{
   {SIG_CLICKED, ""},
   {SIG_REPEATED, ""},
   {SIG_UNPRESSED, ""},
   {NULL, NULL}
 };
 
+static void 
+_color_class_hook(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   edje_object_color_class_set(wd->btn, color_class, 
+                               r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3);
+}
+
 static Eina_Bool
 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
 {
@@ -277,6 +288,7 @@
    elm_widget_can_focus_set(obj, 1);                 
    elm_widget_activate_hook_set(obj, _activate_hook);
    elm_widget_event_hook_set(obj, _event_hook);
+   elm_widget_color_class_hook_set(obj, _color_class_hook);
 
    wd->btn = edje_object_add(e);
    _elm_theme_object_set(obj, wd->btn, "button", "base", "default");
Index: elm_widget.c
===================================================================
--- elm_widget.c	(revision 52765)
+++ elm_widget.c	(working copy)
@@ -49,6 +49,8 @@
    void          *on_change_data;
    void         (*on_show_region_func) (void *data, Evas_Object *obj);
    void          *on_show_region_data;
+   void         (*color_class_func) (Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3);
+
    void          *data;
    Evas_Coord     rx, ry, rw, rh;
    int            scroll_hold;
@@ -1454,6 +1456,22 @@
    EINA_LIST_FREE(list, s) eina_stringshare_del(s);
 }
 
+EAPI void 
+elm_widget_color_class_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3)) 
+{
+   API_ENTRY return;
+   sd->color_class_func = func;
+}
+
+EAPI void 
+elm_widget_color_class_set(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3) 
+{
+   API_ENTRY return;
+   if (sd->color_class_func) 
+     sd->color_class_func(obj, color_class, 
+                          r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3);
+}
+
 /**
  * Allocate a new Elm_Widget_Item-derived structure.
  *
Index: elm_widget.h
===================================================================
--- elm_widget.h	(revision 52765)
+++ elm_widget.h	(working copy)
@@ -294,6 +294,9 @@
 EAPI Eina_List       *elm_widget_stringlist_get(const char *str);
 EAPI void             elm_widget_stringlist_free(Eina_List *list);
 
+EAPI void             elm_widget_color_class_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3));
+EAPI void             elm_widget_color_class_set(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3);
+
 EAPI Elm_Widget_Item *_elm_widget_item_new(Evas_Object *parent, size_t alloc_size);
 EAPI void             _elm_widget_item_del(Elm_Widget_Item *item);
 EAPI void             _elm_widget_item_pre_notify_del(Elm_Widget_Item *item);
Index: elm_main.c
===================================================================
--- elm_main.c	(revision 52765)
+++ elm_main.c	(working copy)
@@ -1013,7 +1013,7 @@
  * Get the style
  *
  * This gets the style being used for that widget. Note that the string
- * pointer is only valid as longas the object is valid and the style doesn't
+ * pointer is only valid as long as the object is valid and the style doesn't
  * change.
  *
  * @param obj The object
@@ -1057,6 +1057,33 @@
 }
 
 /**
+ * Set the color class
+ *
+ * This sets the color class of the object
+ * @param obj The object
+ * @param color_class The new color class to use
+ * @param r
+ * @param g
+ * @param b
+ * @param r2
+ * @param g2
+ * @param b2
+ * @param a2
+ * @param r3
+ * @param g3
+ * @param b3
+ * @param a3
+ * 
+ * @ingroup Styles
+ */
+EAPI void 
+elm_object_color_class_set(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3) 
+{
+   elm_widget_color_class_set(obj, color_class, 
+                              r, g, b, a, r2, g2, b2, a2, r3, g3, b3, a3);
+}
+
+/**
  * Get the global scaling factor
  *
  * This gets the globally configured scaling factor that is applied to all
Index: Elementary.h.in
===================================================================
--- Elementary.h.in	(revision 52765)
+++ Elementary.h.in	(working copy)
@@ -304,6 +304,8 @@
    EAPI Evas_Object *elm_object_top_widget_get(const Evas_Object *obj);
    EAPI const char  *elm_object_widget_type_get(const Evas_Object *obj);
 
+   EAPI void         elm_object_color_class_set(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3);
+
    EAPI double       elm_scale_get(void);
    EAPI void         elm_scale_set(double scale);
    EAPI void         elm_scale_all_set(double scale);
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to