Hey people,

I'm using elementary in a project and I need to send signals to widgets themes.
For example, I could decide that for a value on a spinner the text
should change color. Or that could even depends on other widgets
values combinations.

So, I've talked to Sacheil on #edevelop a bit and I've made a patch
with a possible solution.
We could have an elm_object_signal_emit, that could be used by any
widget, if it set a hook function.

I believe it's a better approach than exposing the edje obj as done by
elm_list_item_base_get.

The patch is attached. I would like to hear from you before committing
to svn / continue working on the other widgets.
I'm not very familiar with widgets code, I can be missing something.

Thanks in advance
Index: src/lib/elm_widget.c
===================================================================
--- src/lib/elm_widget.c	(revision 49676)
+++ src/lib/elm_widget.c	(working copy)
@@ -27,6 +27,8 @@
    void         (*activate_func) (Evas_Object *obj);
    void         (*disable_func) (Evas_Object *obj);
    void         (*theme_func) (Evas_Object *obj);
+   void         (*signal_func) (Evas_Object *obj, const char *emission,
+	                        const char *source);
    void         (*changed_func) (Evas_Object *obj);
    void         (*on_focus_func) (void *data, Evas_Object *obj);
    void          *on_focus_data;
@@ -157,6 +159,13 @@
 }
 
 EAPI void
+elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source))
+{
+   API_ENTRY return;
+   sd->signal_func = func;
+}
+
+EAPI void
 elm_widget_theme(Evas_Object *obj)
 {
    const Eina_List *l;
@@ -585,6 +594,14 @@
 }
 
 EAPI void
+elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source)
+{
+   API_ENTRY return;
+   if (!sd->signal_func) return;
+   sd->signal_func(obj, emission, source);
+}
+
+EAPI void
 elm_widget_focus_set(Evas_Object *obj, int first)
 {
    API_ENTRY return;
Index: src/lib/elm_main.c
===================================================================
--- src/lib/elm_main.c	(revision 49676)
+++ src/lib/elm_main.c	(working copy)
@@ -1379,3 +1379,20 @@
 {
    return elm_widget_type_get(obj);
 }
+
+/**
+ * Send a signal to the widget edje object.
+ *
+ * This function sends a signal to the edje object of the obj. An edje program
+ * can respond to a signal by specifying matching 'signal' and
+ * 'source' fields.
+ *
+ * @param obj The object
+ * @param emission The signal's name.
+ * @param source The signal's source.
+ * @ingroup General
+ */
+EAPI void elm_object_signal_emit(Evas_Object *obj, const char *emission, const char *source)
+{
+    elm_widget_signal_emit(obj, emission, source);
+}
Index: src/lib/elm_priv.h
===================================================================
--- src/lib/elm_priv.h	(revision 49676)
+++ src/lib/elm_priv.h	(working copy)
@@ -122,6 +122,7 @@
 EAPI void         elm_widget_disable_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj));
 EAPI void         elm_widget_theme_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj));
 EAPI void         elm_widget_changed_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj));
+EAPI void         elm_widget_signal_emit_hook_set(Evas_Object *obj, void (*func) (Evas_Object *obj, const char *emission, const char *source));
 EAPI void         elm_widget_theme(Evas_Object *obj);
 EAPI void         elm_widget_on_focus_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data);
 EAPI void         elm_widget_on_change_hook_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *obj), void *data);
@@ -132,6 +133,7 @@
 EAPI void         elm_widget_sub_object_del(Evas_Object *obj, Evas_Object *sobj);
 EAPI void         elm_widget_resize_object_set(Evas_Object *obj, Evas_Object *sobj);
 EAPI void         elm_widget_hover_object_set(Evas_Object *obj, Evas_Object *sobj);
+EAPI void         elm_widget_signal_emit(Evas_Object *obj, const char *emission, const char *source);
 EAPI void         elm_widget_can_focus_set(Evas_Object *obj, int can_focus);
 EAPI int          elm_widget_can_focus_get(const Evas_Object *obj);
 EAPI int          elm_widget_focus_get(const Evas_Object *obj);
Index: src/lib/elm_spinner.c
===================================================================
--- src/lib/elm_spinner.c	(revision 49676)
+++ src/lib/elm_spinner.c	(working copy)
@@ -82,6 +82,14 @@
 }
 
 static void
+_signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   edje_object_signal_emit(wd->spinner, emission, source);
+}
+
+static void
 _theme_hook(Evas_Object *obj)
 {
    Widget_Data *wd = elm_widget_data_get(obj);
@@ -508,6 +516,7 @@
    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
    elm_widget_theme_hook_set(obj, _theme_hook);
    elm_widget_disable_hook_set(obj, _disable_hook);
+   elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
 
    wd->val = 0.0;
    wd->val_min = 0.0;
Index: src/lib/Elementary.h.in
===================================================================
--- src/lib/Elementary.h.in	(revision 49676)
+++ src/lib/Elementary.h.in	(working copy)
@@ -285,6 +285,8 @@
    EAPI void         elm_object_scroll_freeze_push(Evas_Object *obj);
    EAPI void         elm_object_scroll_freeze_pop(Evas_Object *obj);
 
+   EAPI void         elm_object_signal_emit(Evas_Object *obj, const char *emission, const char *source);
+
    EAPI void         elm_coords_finger_size_adjust(int times_w, Evas_Coord *w, int times_h, Evas_Coord *h);
 
    EAPI Elm_Theme   *elm_theme_new(void);
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to