[prev in list] [next in list] [prev in thread] [next in thread]
List: gtk-app-devel
Subject: Re: Arguments in GObject-based object constructor
From: Roger Leigh <rleigh () whinlatter ! ukfsn ! org>
Date: 2005-05-30 22:18:32
Message-ID: 87wtpguzlz.fsf () hardknott ! home ! whinlatter ! ukfsn ! org
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jacob Kroon <jacob.kroon@gmail.com> writes:
> Lets say I've written an abstract class Foo (a class that is not
> supposed to be instantiated), and a class that inherits from Foo
> called Bar, which is instantiable. Foo takes 2 constructor
> arguments/properties "x" and "y". Bar:s constructor takes the samt
> arguments. In order to initialize some of Bar:s attributes, it needs
> to know both "x" and "y". In the bar_init() function I can't get the
> "x" and "y" properties, because they arent set yet, so where do I
> initialize the attributes?
Object properties are set after construction has finished. That is,
after the contructors and init functions have been called. You need
to override the get_property and set_property vfuncs of GObjectClass,
and install properties of type G_PARAM_CONSTRUCT.
As an example, have a look at
http://arch.debian.org/cgi-bin/archzoom.cgi/rleigh@debian.org--2005-uterm/uterm--mainline--0.1--patch-41/cse/cse-selection.h?template=plain
http://arch.debian.org/cgi-bin/archzoom.cgi/rleigh@debian.org--2005-uterm/uterm--mainline--0.1--patch-41/cse/cse-selection.c?template=plain
This is a type derived from GObject. Here's an example for a type
derived from GtkWidget (hrm, just spotted a bug!):
http://arch.debian.org/cgi-bin/archzoom.cgi/rleigh@debian.org--2005-uterm/uterm--mainline--0.1--patch-41/cse/cse-canvas.h?template=plain
http://arch.debian.org/cgi-bin/archzoom.cgi/rleigh@debian.org--2005-uterm/uterm--mainline--0.1--patch-41/cse/cse-canvas.c?template=plain
> Should I hook into the get/set property of both "x" and "y", and
> once both are set (check with some boolean variables), I can
> initialize them in bar_set_property() ? That way sounds a little
> too complicated so I think I'm missing something.
If "x" and "y" are properties of the parent Bar class, simply call
g_object_new() with the properties to set. You don't need to do
anything more, since it will handle setting the properties for you.
Regards,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQFCm5EwVcFcaSW/uEgRArahAKCl+DyuixROOQQJmae/5mP5Wc8fzwCbBYm5
Ow8w5Mjsn8qcsHqnp6MZWWw=
=jCfR
-----END PGP SIGNATURE-----
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic