gtk_rc_style_get_by_paths()



[ http://bugzilla.gnome.org/show_bug?id=52027 ]

To resolve the problem with people wanting to set styles
on subparts of widgets, I want to add something like 
the following to gtkrc.c

====
/**
 * gtk_rc_get_style_by_paths:
 * @settings: a #GtkSettings object
 * @widget_path: the widget path to use when looking up the style, or %NULL
 * @class_path: the class path to use when looking up the style, or %NULL
 * @type: a type that will be used along with parent types of this type
 *        when matching against class styles, or G_TYPE_NONE
 * 
 * Creates up a #GtkStyle from styles defined in a RC file by providing
 * the raw components used in matching. This function may be useful
 * when creating pseudo-widgets that should be themed like widgets but
 * don't actually have corresponding GTK+ widgets. An example of this
 * would be items inside a GNOME canvas widget.
 *
 * The action of gtk_rc_get_style() is similar to:
 *
 *  gtk_widget_path (widget, NULL, &path, NULL);
 *  gtk_widget_class_path (widget, NULL, &class_path, NULL);
 *  gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), path, class_path,
 *                             G_OBJECT_TYPE (widget));
 * 
 * Return value: A style created by matching with the supplied paths,
 *   or %NULL if nothign matching was specified and the  default style should
 *   be used. The returned value is owned by GTK+ as part of an internal cache,
 *   so you must call g_object_ref() on the returned value if you want to
 *   keep a reference to it.
 **/
GtkStyle *
gtk_rc_get_style_by_paths (GtkSettings *settings,
			   const char  *widget_path,
			   const char  *class_path,
			   GType        type)
===

The canonical usage would look something like:

===
 char *widget_path, *class_path, *subwidget_path, *subclass_path;

 gtk_widget_get_path (about_widget, NULL, &widget_path, NULL);
 subwidget_path = g_strconcat (widget_path, ".GnomeAboutName, NULL);

 gtk_widget_get_class_path (about_widget, NULL, &widget_path, NULL);
 subclass_path = g_strconcat (class_path, ".GnomeAboutName, NULL);

 style = gtk_rc_style_by_paths (gtk_widget_get_settings (about_widget);
                                subwidget_path, subclass_path, G_TYPE_NONE);
 if (!style)
   style = widget->style;

 
 g_free (widget_path);
 g_free (class_path);
 g_free (subwidget_path);
 g_free (wubclass_path);
===

I don't think its actually all that useful in the general case,
but its in the spirit of "make hard things possible"

Possible questions include:

 - Should there be a convience function that does something
   like the above example, which isn't exactly convenient?

 - Should the function have an extra GtkRcStyle in it 
   to correspond to the style set by gtk_widget_modify_style()?
   [ the pseudo-code in the docs ignores this style ]

Regards,
                                        Owen




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]