Simon Poole wrote:
Attached is a patch against this morning's CVS to implement the ewl_widget_part_text_set stuff.

Eek! posted the wrong patch!  Here's the one *without* the bugs...

--
Simon Poole
www.appliancestudio.com
--- ewl-20050616.orig/src/lib/ewl_label.c       2005-06-16 03:10:56.000000000 
+0100
+++ ewl-20050616.new/src/lib/ewl_label.c        2005-06-16 11:10:54.000000000 
+0100
@@ -83,19 +83,10 @@
 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_part_text_set(w, "text", la->text);
 }
 
 
--- ewl-20050616.orig/src/lib/ewl_widget.c      2005-05-20 06:02:59.000000000 
+0100
+++ ewl-20050616.new/src/lib/ewl_widget.c       2005-06-16 11:53:51.000000000 
+0100
@@ -538,6 +538,114 @@
 }
 
 /**
+ * @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);
+
+       /* 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, 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(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 update the appearance
  * @param state: the new state of the widget
  * @return Returns no value.
@@ -1171,6 +1279,19 @@
         * Set up the theme object on the widgets evas
         */
        if (w->theme_object) {
+               /*
+                * Apply any text overrides
+                */
+               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))) {
+                               ewl_widget_appearance_part_text_apply(w, key, 
ecore_hash_get(w->theme_text, key));
+                       }
+               }
+                       
                if (w->bit_state)
                        edje_object_signal_emit(w->theme_object, w->bit_state, 
"EWL");
 
--- ewl-20050616.orig/src/lib/ewl_widget.h      2005-05-13 04:26:13.000000000 
+0100
+++ ewl-20050616.new/src/lib/ewl_widget.h       2005-06-16 11:51:26.000000000 
+0100
@@ -59,6 +59,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 this widget's 
theme */
        Ecore_Hash       *data; /**< Arbitrary data attached to this widget */
 };
 
@@ -158,6 +159,16 @@
 char           *ewl_widget_appearance_single_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);

Reply via email to