After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 673317 - There's no way to install custom widget style properties
There's no way to install custom widget style properties
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2012-04-01 20:04 UTC by Mark Vender
Modified: 2014-11-13 14:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] Widget: Add install_style_property() (5.75 KB, patch)
2012-05-02 17:26 UTC, Mark Vender
none Details | Review
Shows how CustomStyleProperty could be implemented (9.10 KB, patch)
2012-05-02 17:29 UTC, Mark Vender
none Details | Review
patch: Add Gtk::StyleProperty (10.12 KB, patch)
2014-11-06 18:17 UTC, Kjell Ahlstedt
none Details | Review
Test case (3.49 KB, application/x-compressed-tar)
2014-11-06 18:18 UTC, Kjell Ahlstedt
  Details

Description Mark Vender 2012-04-01 20:04:34 UTC
Currently the gtk_widget_class_install_style_property() is not wrapped, thus there is no way to define custom style properties for custom widgets. Other bindings, such as pygtk or vala, provide this function, so we probably should wrap it too.

I could write a patch for this. I have thought of two ways the needed functionality could be implemented:

1) A Gtk::Widget::install_style_property() function template with an interface similar to Gtk::Widget::get_style_property().

2) Gtk::CustomStyleProperty or Gtk::StyleProperty class template with an interface similar to that of Glib::Property. Gtk::CustomStyleProperty should probably be chosen, because it avoids confusion with GtkStyleProperties).

In my opinion the second design is better, because style properties conceptually are very similar to the object properties. Moreover, this class could make the get_style_property() function obsolete, since the function would be only useful for style properties installed by base classes. I couldn't think of a use case where this information can be useful, though, if need arises, a CustomStylePropertyProxy similar to Glib::PropertyProxy could be implemented.

Any opinions?
Comment 1 Kjell Ahlstedt 2012-04-28 08:10:55 UTC
(In reply to comment #0)
> Moreover, this class could make the get_style_property() function obsolete,
> since the function would be only useful for style properties installed by
> base classes. I couldn't think of a use case where this information can be
> useful,

I made a quick and incomplete search in gtk+'s source code. GtkWidget installs
style properties that are used by some of its subclasses. Examples:

link-color is used by GtkAboutDialog, GtkLabel, GtkLinkButton.
separator-height is used by GtkMenuItem, GtkSeparator, GtkToolbar, GtkTreeView.

Don't you think someone who makes a custom widget might want to use some of the
style properties installed by the base class Gtk::Widget (GtkWidget)?


My only experience with style properties is that I made some changes for gtkmm3
to the custom widget example in the gtkmm tutorial. I can't really decide which
of your suggested implementations is better. I suppose the first alternative is
easier to implement. Probably very few gtkmm programmers will ever use style
properties. Therefore I would vote for the simpler alternative.
Comment 2 Mark Vender 2012-05-02 17:24:49 UTC
(In reply to comment #1)
> I made a quick and incomplete search in gtk+'s source code. GtkWidget installs
> style properties that are used by some of its subclasses. Examples:
> 
> link-color is used by GtkAboutDialog, GtkLabel, GtkLinkButton.
> separator-height is used by GtkMenuItem, GtkSeparator, GtkToolbar, GtkTreeView.
> 
> Don't you think someone who makes a custom widget might want to use some of the
> style properties installed by the base class Gtk::Widget (GtkWidget)?
> 
I supposed that if custom style properties are defined rarely, one would need style properties of base classes even in rarer cases. If we, however, do need access to the custom properties, then CustomStylePropertyProxy could be implemented and added to the existing classes in much the same way Glib::Property proxy is used to access the style properties defined in Gtk+.

Anyway, I've already implemented both solutions and will attach them below. I still think that the CustomStyleProperty/CustomStylePropertyProxy is a better way to handle things, just because of the similarity with Glib::Property and Glib::PropertyProxy. Using this would IMO result in a cleaner API. However, since only few will use that API, the argument of simplicity wins. Thus I think adding install_style_property() is a indeed better option for the moment.
Comment 3 Mark Vender 2012-05-02 17:26:02 UTC
Created attachment 213313 [details] [review]
[PATCH] Widget: Add install_style_property()

Patch to add install_style_property() wrapper.
Comment 4 Mark Vender 2012-05-02 17:29:30 UTC
Created attachment 213314 [details] [review]
Shows how CustomStyleProperty could be implemented

An example how CustomStyleProperty could be implemented.
Comment 5 Kjell Ahlstedt 2014-11-06 18:17:38 UTC
Created attachment 290117 [details] [review]
patch: Add Gtk::StyleProperty

Now when I return to this bug after more than two years, I have changed my
mind. GObject properties, GtkContainer child properties and GtkWidget style
properties should as far as possible and reasonable be handled similarly.
This requires
  // For wrapped glib/gtk+ properties
  class Glib::PropertyProxy_Base
  class Glib::PropertyProxy<T> : public Glib::PropertyProxy_Base
  class Glib::PropertyProxy_ReadOnly<T> : public Glib::PropertyProxy_Base
  class Glib::PropertyProxy_WriteOnly<T> : public Glib::PropertyProxy_Base
  // For custom properties
  class Glib::PropertyBase
  class Glib::Property<T> : public Glib::PropertyBase

  // For wrapped gtk+ child properties
  class Gtk::ChildPropertyProxy_Base
  class Gtk::ChildPropertyProxy<T> : public Gtk::ChildPropertyProxy_Base
  class Gtk::ChildPropertyProxy_ReadOnly<T> :
        public Gtk::ChildPropertyProxy_Base
  class Gtk::ChildPropertyProxy_WriteOnly<T> :
        public Gtk::ChildPropertyProxy_Base
  // For custom child properties (not implemented)
  class Gtk::ChildPropertyBase
  class Gtk::ChildProperty<T> : public Gtk::ChildPropertyBase

  // For wrapped gtk+ style properties (not implemented,
  // Gtk::Widget::get_style_property() is a substitute)
  class Gtk::StylePropertyProxy_Base
  class Gtk::StylePropertyProxy<T> : public Gtk::StylePropertyProxy_Base
  class Gtk::StylePropertyProxy_ReadOnly<T> :
        public Gtk::StylePropertyProxy_Base
  // No Gtk::StylePropertyProxy_WriteOnly. All style properties are readable.
  // For custom style properties
  class Gtk::StylePropertyBase
  class Gtk::StyleProperty<T> : public Glib::StylePropertyBase

I propose that we implement Gtk::StylePropertyBase and Gtk::StyleProperty<>.
I have made some small changes to Mark's patch in comment 4.
Comment 6 Kjell Ahlstedt 2014-11-06 18:18:31 UTC
Created attachment 290118 [details]
Test case

This test case is a modified version of
https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/custom/custom_widget
Comment 7 Kjell Ahlstedt 2014-11-13 14:39:03 UTC
I have pushed a patch very similar to the one in comment 5.
https://git.gnome.org/browse/gtkmm/commit/?id=20728720ea5930147c0b24b9b6fde87d526fa14e