[Gtk-sharp-list] Tree/List/GValue improvements
19 May 2003 21:26:04 -0500
So I recently committed some improvements which make it easier to use
* It is now possible to store managed objects in GValue. This means you
can store your actual data objects inside your Tree Model, rather than
copying their fields to the model manually.
* I added a number of overloads to the TreeStore and ListStore classes
so that you don't have to exlicitly use GLib.Value.
* I added a few convenience methods which make it easier to add columns
* TreeStore and ListStore constructors now accept System.Type in
addition to TypeFundamentals.
How to use the new convenience functions
I have updated TreeViewDemo.cs in the sample dir to show this.
To add an entire row, call store.AppendValues.
For a list it is:
iter =3D store.AppendValues (value1, value2, value3, ..);
For a tree it is:
iter =3D store.AppendValues (parent_iter, value1, value2, value3, ..);
To add a column to a view:
col =3D view.AppendColumn (title, cell_renderer, attr1_name,
col =3D view.AppendColumn (title, cell_renderer, cell_data_func);
The first form is if you want to pass a mapping of cell renderer
attributes to tree model columns. It is modelled after the varargs
convention used by Gtk+ proper.
The second form specifies instead a callback delegate which will be
called whenever the view needs redrawing. In this callback you can set
properties on the cell renderer in the normal .NET fashion. This is
mostly only of use if you are storing managed values in your tree model.
How to use managed value tree models
This is demonstrated in ManagedTreeViewDemo.cs. The key guidelines are:
* Just as you would normally pass in a type of int, string, etc to your
model constructor, pass in the type of the object you are storing.
* You can store your object in the model like any other value. The model
will hold a reference to your object so that you do not have to worry
about it getting GCed while the model/view are still using it.
* You can retrieve your object by calling store,GetValue (iter,
* You can copy the object fields to other tree model columns if you
want, but a more convenient way is to use the cell data callback
mechanism. This allows you to set up a virtual column mapping where
multiple view columns all refer back to a single tree model column.
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
-----END PGP SIGNATURE-----