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 140515 - Container child properties not wrapped
Container child properties not wrapped
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.4
Other All
: Normal normal
: 3
Assigned To: gtkmm-forge
gtkmm-forge
: 333241 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-04-19 16:51 UTC by Murray Cumming
Modified: 2014-09-10 07:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add support for _WRAP_CHILD_PROPERTY in gmmproc. (9.65 KB, patch)
2014-05-15 08:22 UTC, Juan R. Garcia Blanco
none Details | Review
Add infrastructure to handle child properties. (14.81 KB, patch)
2014-05-15 10:18 UTC, Juan R. Garcia Blanco
none Details | Review
Child properties little demo. (14.37 KB, patch)
2014-05-15 10:19 UTC, Juan R. Garcia Blanco
none Details | Review
Add support for _WRAP_CHILD_PROPERTY and define-child-property in gmmproc. (16.98 KB, patch)
2014-06-15 18:43 UTC, Juan R. Garcia Blanco
none Details | Review
Add infrastructure to handle child properties. (14.80 KB, patch)
2014-06-15 18:43 UTC, Juan R. Garcia Blanco
none Details | Review
Child properties little demo. (12.55 KB, patch)
2014-06-15 18:44 UTC, Juan R. Garcia Blanco
none Details | Review
Add infrastructure to handle GtkContainer child properties. (19.59 KB, patch)
2014-06-19 21:29 UTC, Juan R. Garcia Blanco
none Details | Review
Add infrastructure to handle GtkContainer child properties. (18.98 KB, patch)
2014-06-28 11:55 UTC, Juan R. Garcia Blanco
none Details | Review
Add infrastructure to handle GtkContainer child properties. (19.67 KB, patch)
2014-06-30 20:15 UTC, Juan R. Garcia Blanco
none Details | Review
Add _WRAP_CHILD_PROPERTY to tutorial. (2.17 KB, patch)
2014-07-06 11:15 UTC, Juan R. Garcia Blanco
none Details | Review

Description Murray Cumming 2004-04-19 16:51:27 UTC
We don't wrap the various GtkContainer "child properties". Search for
gtk_container_class_install_child_property() in the GTK+ sources.

These can be set with gtk_container_child_set_property().
http://developer.gimp.org/api/2.0/gtk/GtkContainer.html#gtk-container-child-set-property

We should add a new type of PropertyProxy for these, but the set_value() method
should take an extra "child_widget" parameter. operator=() will not be possible
because it can not take 2 parameters. Or maybe the property_something() 
accessor could take the child_widget parameter.
Comment 1 Murray Cumming 2006-03-04 13:29:33 UTC
*** Bug 333241 has been marked as a duplicate of this bug. ***
Comment 2 Daniel Elstner 2009-06-12 16:59:23 UTC
Yes, I'd also vote for the property_something(child) solution.
Comment 3 Juan R. Garcia Blanco 2014-05-15 08:22:08 UTC
Created attachment 276580 [details] [review]
Add support for _WRAP_CHILD_PROPERTY in gmmproc.
Comment 4 Juan R. Garcia Blanco 2014-05-15 10:18:19 UTC
Created attachment 276589 [details] [review]
Add infrastructure to handle child properties.
Comment 5 Juan R. Garcia Blanco 2014-05-15 10:19:25 UTC
Created attachment 276590 [details] [review]
Child properties little demo.
Comment 6 Juan R. Garcia Blanco 2014-05-15 10:23:53 UTC
I've uploaded patches to get child properties working, at least for setting, getting and resetting them. I haven't added support for ::child-notify signals until we make sure that we really want child properties implemented in this way. 

Hope you find this implementation pleasant; however I presume it will require changes before being pushed. For example, I'm not sure if we want to add a new method in generate_defs_gtk.cc. All comments are of course welcome; I'll try to make required changes at your request.
Comment 7 Kjell Ahlstedt 2014-06-11 12:50:39 UTC
--- Add support for GtkContainer child properties (glibmm, gmmproc)
    Add support for _WRAP_CHILD_PROPERTY in gmmproc. (comment 3)

* tools/extra_defs_gen/generate_extra_defs.[h|cc]

  std::string get_property(GParamSpec* pParamSpec, std::string strObjectName)
I recommend
  std::string get_property(GParamSpec* pParamSpec, const std::string& strObjectName)


--- Add GtkContainer's child property handling (gtkmm)
    Add infrastructure to handle child properties. (comment 4)

* gtk/gtkmm/childpropertyproxy.[h|cc]

   // -*- c++ -*-
   /* $Id$ */
Probably a left-over from a previously used version handling program.
No reason to include it in new files.

* gtk/gtkmm/childpropertyproxy.h

The get_value() and set_value() methods should take [const] Gtk::Widget& child
instead of [const] Gtk::Widget* child.

* tools/extra_defs_gen/generate_defs_gtk.cc

   ppParamSpec = g_object_class_list_properties (pGClass, &iCount);
   ppParamSpec = gtk_container_class_list_child_properties (pGClass, &iCount);
Does the first of these two statements do anything useful here?

   strResult += ";; Warning: g_object_class_list_properties() ...
Should be ";; Warning: gtk_container_class_list_child_properties() ...

You might delete the deprecated GTK_TYPE_TABLE from the list of container
classes to get child properties from.

* tools/m4/child_property.m4

   dnl $Id$
I think this is a left-over from a version handling program that was used
before git. No reason to include it in a new file.

   ChildPropertyProxy$4< _QUOTE($3) >'dnl
should be
   Gtk::ChildPropertyProxy$4< _QUOTE($3) >'dnl
ChildPropertiesProxy can be useful in other packages than gtkmm, e.g.
class Canvas : public Gtk::Container
in goocanvasmm, where Canvas belongs to namespace Goocanvas.
(Goocanvas::Canvas does not have child properties, but there might be some
container widget in some package that does.)

GLIBMM_PROPERTIES_ENABLED is always defined nowadays. There's no need for
testing that.

   You rarely need to use properties because there are get_ and set_ methods
   for almost all of them.
Is that true of child properties? Don't you do this job because it's not true?


--- Example to demo child properties (gtkmm)
    Child properties little demo. (comment 5)

Ok


--- General comments

You assume that there can't be a child property with the same name as an
ordinary property. Are you sure of that? It looks like gtk+ keeps a separate
list of child properties, and uses a separate set of functions to handle
child properties.
I haven't found an example, but just imagine that a container class defines
a child property called "margin" while its base class GtkWidget has an
ordinary property also called "margin".

Instead of having a member
  Gtk::ChildPropertyProxy property_foo();
or
  Glib::PropertyProxy property_foo();
depending on which kind of property it is, wouldn't it be safer, and also
more informative for the users, to have
  Gtk::ChildPropertyProxy child_property_foo();
for a child property? And
  (define-child-property foo
in the .defs file?

Comment 0 and comment 2 discuss the alternative
  Gtk::ChildPropertyProxy property_foo(child);
(or perhaps also
  Gtk::ChildPropertyProxy child_property_foo(child);)
Would that be more difficult to implement?

Then you could write, in your demo example
  m_Notebook.child_property_tab_expand(m_TextWidget_Info) = true;
similar to what can be done with ordinary properties.
Comment 8 Juan R. Garcia Blanco 2014-06-14 14:23:46 UTC
I do not think implementing the alternative property_foo(child) would be more difficult. I see however something I do not know how to solve; ideas are welcome. For implementing this alternative, I would need to add a new constructor to ChildPropertyProxy that takes three arguments: container, child, and property name. However, argument child could be const and non-const, depending on the property being read only or not. E.g.:

Gtk::ChildPropertyProxy< bool > Notebook::child_property_tab_expand(Gtk::Widget& child)                                                                                                                            
{
  return Gtk::ChildPropertyProxy< bool >(this, child, "tab-expand");
}

Gtk::ChildPropertyProxy_ReadOnly< bool > Notebook::child_property_tab_expand(const Gtk::Widget& child) const
{
  return Gtk::ChildPropertyProxy_ReadOnly< bool >(this, child, "tab-expand");
}

ChildPropertyProxy would need to hold a reference to a Gtk::Widget; however, if I make this reference non-const, then I would need to do a const_cast in the constructor of ChildPropertyProxy_ReadOnly. I do not think this is acceptable. Maybe I can hold a pointer instead of a reference...
Comment 9 Juan R. Garcia Blanco 2014-06-14 14:26:10 UTC
Sorry, I just realized that there is a const_cast right in the constructor of PropertyProxy_ReadOnly. Then I would try to implement this using references, unless you state otherwise.
Comment 10 Juan R. Garcia Blanco 2014-06-15 18:43:11 UTC
Created attachment 278493 [details] [review]
Add support for _WRAP_CHILD_PROPERTY and define-child-property in gmmproc.
Comment 11 Juan R. Garcia Blanco 2014-06-15 18:43:51 UTC
Created attachment 278494 [details] [review]
Add infrastructure to handle child properties.
Comment 12 Juan R. Garcia Blanco 2014-06-15 18:44:25 UTC
Created attachment 278495 [details] [review]
Child properties little demo.
Comment 13 Juan R. Garcia Blanco 2014-06-15 18:47:43 UTC
Please disregard my two last comments. Please find the new proposed solution in the last patches. I have included the comments made on the first review. Please let me know of anything that needs improvements and of errors.
Comment 14 Kjell Ahlstedt 2014-06-18 17:02:32 UTC
Now that get_value() takes no parameter, and set_value() takes one parameter,
ChildPropertyProxy can be made even more similar to PropertyProxy.

ChildPropertyProxy and ChildPropertyProxy_ReadOnly can have
    operator PropertyType() const
    { return this->get_value(); }

The code snippet in the description of ChildPropertyProxy does not reflect
the changes in get_value() and set_value(). Compare the description of
PropertyProxy.

Except for this detail and the missing signal_changed(), which you're aware of,
it looks really fine.
Comment 15 Juan R. Garcia Blanco 2014-06-19 08:57:30 UTC
Thank you for the quick review.

I'll add operator().

Yes, the description now is erroneous. In fact, documentation of get/set_value() is also wrong. I'll fix that.

Now that I know this is the expected implementation, I will continue implementing (maybe no additional code is needed) and testing signal_changed().
Comment 16 Juan R. Garcia Blanco 2014-06-19 10:50:34 UTC
I see a problem in implementing signal_changed() the way ChildPropertyProxy is right now. As it inherits from PropertyProxy_Base, and that class has already a signal_changed() method that returns a SignalProxyProperty, we cannot overload it to return our own SignalProxyChildProperty. We need to overload it because SignalProxyProperty has hardcoded in it the "notify::" prefix, that becomes "child-notify::" with child properties.

I think it is reasonable to stop inheriting from PropertyProxy_Base and make ChildPropertyProxy a top class; I don't know exactly what we could potentially loose by doing this and what we will need to reimplement. Would it be reasonable to create a ChildPropertyProxy_Base?
Comment 17 Kjell Ahlstedt 2014-06-19 17:46:04 UTC
A non-template base class can be useful in some situations.
E.g. if you want to create a std::vector<Glib::PropertyProxy_Base*>, or in
this case perhaps a std::vector<Gtk::ChildPropertyProxy_Base*>.
I haven't found any std::vector<Glib::PropertyProxy_Base*> in glibmm or
gtkmm, but there are some methods that take a const Glib::PropertyProxy_Base&
parameter.

Conclusion: If you can't use Glib::PropertyProxy_Base as a base class, make
a Gtk::ChildPropertyProxy_Base.

It's a pity that you probably have to duplicate a lot of code just because of
a tiny difference in signal_changed().connect().
Comment 18 Juan R. Garcia Blanco 2014-06-19 19:43:49 UTC
I think I have not duplicated much code; it would be worse if I had to reimplement SignalProxyProperty, but for that case I simply subclassed SignalProxyProperty and overwrite the connect() method. I'll soon update some patches. I just started also an example in gtkmm-documentation.
Comment 19 Juan R. Garcia Blanco 2014-06-19 21:29:08 UTC
Created attachment 278803 [details] [review]
Add infrastructure to handle GtkContainer child properties.
Comment 20 Juan R. Garcia Blanco 2014-06-19 21:29:59 UTC
I'm not sure about the TODO part (if it is true what comes after that) in ChildPropeprtyProxy :S
Comment 21 Kjell Ahlstedt 2014-06-22 18:21:46 UTC
Only Gtk::Container and its subclasses can have child properties.
Why not change
  Glib::ObjectBase* obj_;
in ChildPropertyProxy_Base to
  Container* container_;
or to
  Container* parent_;
?
The calls to gtk_container_child_[set|get]_property() can be simplified.
Calling GTK_CONTAINER() becomes unnecessary.


I also find the text after TODO in childpropertyproxy.h (and the identical
text in propertyproxy.h) confusing. It was added to the description of
PropertyProxy as a result of bug 523043.
The text is misleading. PropertyProxy and ChildPropertyProxy don't register
properties. They give access to properties that have been registered by other
means. I wonder if the text was added to the wrong class. It seems more like
a description of Glib::Property.
Perhaps it refers to a special use of PropertyProxy, which is illustrated in
https://git.gnome.org/browse/gtkmm-documentation/tree/examples/others/cellrenderercustom/cellrenderertoggle.cc
where a Glib::PropertyProxy is a proxy for a Glib::Property.

Anyway, I recommend that you delete that text from the description of
Gtk::ChildPropertyProxy. As long as there is no Gtk::ChildProperty that can
register custom child properties, the text would be plain wrong in
ChildPropertyProxy. And the need for a ChildProperty class is probably very
low or non-existent. Don't waste time on it, unless someone asks for it.
Comment 22 Juan R. Garcia Blanco 2014-06-28 11:55:41 UTC
Created attachment 279472 [details] [review]
Add infrastructure to handle GtkContainer child properties.
Comment 23 Juan R. Garcia Blanco 2014-06-28 11:57:08 UTC
Now that ChildPropertyProxy_Base depends directly on Gtk::Container, in order to avoid a circular dependency, gtkmm/childpropertyproxy.h cannot be included in container.hg, and therefore it needs to be included in each .hg that wraps child properties.
Comment 24 Kjell Ahlstedt 2014-06-29 18:29:37 UTC
Since you don't include container.h in childpropertyproxy_base.h or in
childpropertyproxy.h, it's possible to include childpropertyproxy.h in
container.h. I can build gtkmm with your latest patch and
#include <gtkmm/childpropertyproxy.h> in container.hg. Can't you?

It's the same idea which is used for Glib::PropertyProxy:
Include propertyproxy.h in objectbase.h. Include glibmm/object.h only in
propertyproxy_base.cc. Add only an incomplete class ObjectBase declaration
in propertyproxy_base.h.

If you want to, you can also change the SignalProxyChildProperty constructor to 
  SignalProxyChildProperty(Widget* child, const char* property_name)
    : Glib::SignalProxyProperty(child, property_name) {}
Comment 25 Juan R. Garcia Blanco 2014-06-30 20:14:27 UTC
You are completely right. It didn't compile for some reason; maybe because I tested this on osx. On Fedora it compiles without any problem.
Comment 26 Juan R. Garcia Blanco 2014-06-30 20:15:10 UTC
Created attachment 279635 [details] [review]
Add infrastructure to handle GtkContainer child properties.
Comment 27 Kjell Ahlstedt 2014-07-01 08:15:01 UTC
The patches in comment 10 (glibmm) and comment 26 (gtkmm) look good.
I recommend that you push them.

Git does not accept the update of gtk_signals.defs in comment 12 after I
updated that file for the Gesture classes. But perhaps that patch is not meant
to be pushed?

Remaining work:
  Describe _WRAP_CHILD_PROPERTY in the gtkmm tutorial, appendix G.
  Add _WRAP_CHILD_PROPORTY in some .hg files.
Comment 28 Juan R. Garcia Blanco 2014-07-03 21:01:22 UTC
If I understood correctly, the recommendation is to push the aforementioned patches *before* completing the tasks under "Remaining work"; is this correct? Anyways the remaining work is, I presume, pretty straightforward, so it can be completed a short period of time.
Comment 29 Kjell Ahlstedt 2014-07-04 13:32:52 UTC
Do as you like. You can push what's ready now, and other patches later,
or wait and push all at the same time. I don't think it matters.

I expect that adding _WRAP_CHILD_PROPERTY to .hg files will be an ongoing
activity, just like we add some _WRAP_METHOD/SIGNAL/PROPERTY now and then.
Comment 30 Juan R. Garcia Blanco 2014-07-06 11:15:38 UTC
Created attachment 279982 [details] [review]
Add _WRAP_CHILD_PROPERTY to tutorial.
Comment 31 Juan R. Garcia Blanco 2014-07-06 11:18:45 UTC
In the description, mostly copied from _WRAP_PROPERTY, I wouldn't like to talk much about GtkContainer child properties, that's why a placed a link, but I don't know if that is allowed.

I could translate the new section to castilian spanish, and I tried to do that, but I wasn't able to find how to generate the .po file... sorry.

I don't plan to upload patches here for actually wrapping the child properties, as I think it is easy enough to commit directly.
Comment 32 Kjell Ahlstedt 2014-07-06 17:45:14 UTC
(In reply to comment #31)
> In the description, mostly copied from _WRAP_PROPERTY, I wouldn't like to talk
> much about GtkContainer child properties, that's why a placed a link, but I
> don't know if that is allowed.

There are lots of links in the gtkmm tutorial. I can't find any other link to
developer.gnome.org/gtk3, but there are links to developer.gnome.org/pango and
developer.gnome.org/jhbuild. So why not to gtk3?

Your patch is good.

> I could translate the new section to castilian spanish, and I tried to do that,
> but I wasn't able to find how to generate the .po file... sorry.

Don't know. If you don't get a useful reply here, perhaps you can e-mail
your question directly to someone who has updated a .po file in
gtkmm-documentation.

> I don't plan to upload patches here for actually wrapping the child properties,
> as I think it is easy enough to commit directly.

I agree.
Comment 33 Kjell Ahlstedt 2014-07-07 17:18:13 UTC
Juan, a note for patches that you push in the future:
If a patch is related to a bug report, include the bug number in the commit
message.

That's how I found bug 523043 that I mentioned in comment 21.
First use 'git blame' to see when the suspicious code or comment was committed.
Then find the bug number in the commit message.
Comment 34 Juan R. Garcia Blanco 2014-07-11 19:23:11 UTC
Sorry, I forgot. Thank you for reminding me. I'll link to this bug report when committing changes to wrap child properties in GtkContainer subclasses.
Comment 35 Juan R. Garcia Blanco 2014-07-13 11:04:05 UTC
I just pushed notebook.hg with child properties wrapped, and again forgot to mention the bug report :( I'm really sorry. I'll be more careful hereon.
Comment 36 Kjell Ahlstedt 2014-09-09 07:13:25 UTC
Isn't this bug fixed?
Comment 37 Juan R. Garcia Blanco 2014-09-09 20:13:38 UTC
I think all child properties are wrapped. So yes, I think this can be closed. Even if some child properties were not wrapped I think it is normal work.