Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_label.c ewl_label.h ewl_widget.c ewl_widget.h 


Log Message:
Support setting the text on arbitrary edje parts.
Use the theme to determine default text part.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_label.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- ewl_label.c 12 Oct 2005 03:53:24 -0000      1.11
+++ ewl_label.c 17 Oct 2005 15:29:35 -0000      1.12
@@ -49,7 +49,6 @@
        ewl_widget_inherit(w, "label");
        ewl_object_fill_policy_set(EWL_OBJECT(la), EWL_FLAG_FILL_FILL);
 
-       ewl_callback_append(w, EWL_CALLBACK_REALIZE, ewl_label_realize_cb, 
NULL);
        ewl_callback_append(w, EWL_CALLBACK_DESTROY, ewl_label_destroy_cb, 
NULL);
 
        DRETURN_INT(TRUE, DLEVEL_STABLE);
@@ -119,17 +118,8 @@
 ewl_label_apply(Ewl_Label *la)
 {
        Ewl_Widget *w;
-       Evas_Coord nw, nh;
 
        w = EWL_WIDGET(la);
-       if (!w->theme_object) return;
 
-       /* Should htis check be in here? 
-       if (!edje_object_part_exists(w->theme_object, "text"))
-       printf(" NO PART\n");
-       */
-       edje_object_part_text_set(w->theme_object, "text", la->text);
-       edje_object_size_min_calc(w->theme_object, &nw, &nh);
-
-       ewl_object_preferred_inner_size_set(EWL_OBJECT(la), (int)nw, (int)nh);
+       ewl_widget_appearance_text_set(w, la->text);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_label.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- ewl_label.h 12 Oct 2005 03:53:24 -0000      1.5
+++ ewl_label.h 17 Oct 2005 15:29:35 -0000      1.6
@@ -31,7 +31,7 @@
        char * text;            /**< The text set into the widget */
 };
 
-Ewl_Widget *ewl_label_new();
+Ewl_Widget *ewl_label_new(void);
 int         ewl_label_init(Ewl_Label *la);
 
 void        ewl_label_text_set(Ewl_Label *la, const char *text);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_widget.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- ewl_widget.c        16 Oct 2005 19:47:01 -0000      1.25
+++ ewl_widget.c        17 Oct 2005 15:29:35 -0000      1.26
@@ -9,6 +9,8 @@
                                         int *t, int *b);
 static void ewl_widget_theme_insets_get(Ewl_Widget *w, int *l, int *r,
                                        int *t, int *b);
+static void ewl_widget_appearance_part_text_apply(Ewl_Widget * w, char *part,
+                                                 char *text);
 
 /**
  * @brief Allocate a new widget.
@@ -660,6 +662,111 @@
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
+/**     
+ * @param w: the widget whose text to change
+ * @param part: the theme part name whose text to change
+ * @param text: the new text to change to
+ * @return Returns no value.
+ * @brief Change the text of the given theme part of a widget
+ *
+ * Changes the text of a given Edje-define TEXT part.
+ */
+static void ewl_widget_appearance_part_text_apply(Ewl_Widget * w, char *part, 
char *text)
+{
+        Evas_Coord nw, nh;
+
+        DENTER_FUNCTION(DLEVEL_STABLE);
+        DCHECK_PARAM_PTR("w", w);
+        DCHECK_PARAM_PTR("part", part);
+        DCHECK_PARAM_PTR("text", text);
+
+        if (!w->theme_object)
+                DLEAVE_FUNCTION(DLEVEL_STABLE);
+
+        edje_object_part_text_set(w->theme_object, part, text);
+        edje_object_size_min_calc(w->theme_object, &nw, &nh);
+
+        ewl_object_preferred_inner_size_set(EWL_OBJECT(w), (int)nw, (int)nh);
+
+        DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param w: the widget whose text to change
+ * @param part: the theme part name whose text to change
+ * @param text: the new text to change to
+ * @return Returns no value.
+ * @brief Change the text of the given theme part of a widget
+ *
+ * Changes the text of a given Edje-define TEXT part.  This is for
+ * widgets whose Edje appearance defines TEXT parts, and enables
+ * each of those text parts to be changed independently.
+ * The text value is recorded in a hash and reapplied if the theme
+ * is reloaded for this widget.
+ */
+void ewl_widget_appearance_part_text_set(Ewl_Widget * w, char *part, char 
*text)
+{
+       char *key, *value, *old_value;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("w", w);
+       DCHECK_PARAM_PTR("part", part);
+
+       if (!(w->theme_text)) {
+               w->theme_text = ecore_hash_new(ecore_str_hash, 
ecore_str_compare);
+               ecore_hash_set_free_key(w->theme_text, free);
+               ecore_hash_set_free_value(w->theme_text, free);
+       }
+
+       old_value = ecore_hash_get(w->theme_text, part);
+
+       if (old_value && text && !strcmp(old_value, text))
+               DLEAVE_FUNCTION(DLEVEL_STABLE);
+
+       /*
+        * What should be the default if you enter NULL? A blank string?
+        * Revert to the text specified in the Edje? Use blank for now.
+        */
+       value = strdup( text ? text : "" );
+
+       if (old_value) key = part;
+       else key = strdup(part);
+
+       ecore_hash_set(w->theme_text, key, value);
+
+       ewl_widget_appearance_part_text_apply(w, key, value);
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param w: the widget whose text to change
+ * @param part: the theme part name whose text to change
+ * @param text: the new text to change to
+ * @return Returns no value.
+ * @brief Change the text of the given theme part of a widget
+ *
+ * Changes the text of an Edje-define TEXT part.  This is for
+ * widgets whose Edje appearance defines a TEXT part, and identifies
+ * it with with a data item called "/WIDGET/textpart".
+ * The text value is recorded in a hash and reapplied if the theme
+ * is reloaded for this widget.
+ */
+void ewl_widget_appearance_text_set(Ewl_Widget * w, char *text)
+{
+       char *part;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("w", w);
+
+       part = ewl_theme_data_str_get(w, "textpart");
+       if (part) {
+               ewl_widget_appearance_part_text_set(w, part, text);
+               FREE(part);
+       }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
 /**
  * @param w: the widget to re-enable
  * @return Returns no value.
@@ -1451,6 +1558,25 @@
                                && i_t >= EWL_OBJECT_MIN_SIZE
                                && i_t < EWL_OBJECT_MAX_SIZE)
                        ewl_object_maximum_h_set(EWL_OBJECT(w), i_t);
+
+               /*
+                * Apply any text overrides
+                * FIXME: These should probably be ported to an array rather
+                * than a full hash.
+                */
+               if (w->theme_text) {
+                       char *key;
+                       Ecore_List *keys = ecore_hash_keys(w->theme_text);
+
+                       ecore_list_goto_first(keys);
+                       while ((key = (char *)ecore_list_next(keys))) {
+                               char *value = ecore_hash_get(w->theme_text, 
key);
+                               ewl_widget_appearance_part_text_apply(w, key,
+                                                                     value);
+                       }
+                       ecore_list_destroy(keys);
+               }
+
        }
 
        ewl_object_visible_add(EWL_OBJECT(w), EWL_FLAG_VISIBLE_REALIZED);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_widget.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- ewl_widget.h        14 Oct 2005 03:18:19 -0000      1.16
+++ ewl_widget.h        17 Oct 2005 15:29:35 -0000      1.17
@@ -75,6 +75,7 @@
        int              layer; /**< Current layer of widget on canvas */
 
        Ecore_Hash       *theme; /**< Overriding theme settings of this widget 
*/
+       Ecore_Hash       *theme_text; /**< Overriding text in widgets theme */
        Ecore_Hash       *data; /**< Arbitrary data attached to this widget */
 };
 
@@ -184,6 +185,17 @@
 char          *ewl_widget_appearance_path_get(Ewl_Widget * w);
 
 /*
+ * Change the text of the given theme part of a widget.
+ */
+void           ewl_widget_appearance_part_text_set(Ewl_Widget * w, char *part,
+                                                  char *text);     
+
+/*
+ * Change the text of the theme-defined theme part of a widget.
+ */
+void           ewl_widget_appearance_text_set(Ewl_Widget * w, char *text);
+
+/*
  * Append to the inherited string 
  */
 void            ewl_widget_inherit(Ewl_Widget *widget, char *type);




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to