[Gtk-sharp-list] Custom cellrenderer

Rodolfo Campero rodolfocampero@hotmail.com
Sat, 17 Jul 2004 12:42:26 -0300


El s=E1b, 17-07-2004 a las 12:28, Adam Lofts escribi=F3:
> Hi,
>=20
> I am trying to implement a custom cellrenderer as follows:
>=20
> class MyClass {
>  ...
> }
>=20
> class MyCellRenderer {
> 	MyClass TheClass {
> 		set { ... }
> 	}
> }
>=20
> class MyWindow {
>=20
> MyWindow() {
> 	MyTreeView.AppendColumn(=20
> 			new TreeViewColumn("Channel",=20
> 				new MyCellRenderer,=20
> 				new TreeCellDataFunc (TreeChannelData))
> 				);
> 	}
>=20
> 	void TreeChannelData (TreeViewColumn tree_column, CellRenderer cell,
> TreeModel tree_model, TreeIter iter) {
> 		(cell as MyCellRenderer).TheClass =3D (tree_model.GetValue(iter, 1) as
> MyClass);
> 	}
> }
>=20
> And get the following error:
>=20
> Unhandled Exception: GLib.MissingIntPtrCtorException: GLib.Object
> subclass MyCellRenderer must provide a protected or public IntPtr ctor
> to support wrapping of native object handles.
> in <0x001e3> GLib.ObjectManager:CreateObject (intptr)
> in <0x000e3> GLib.Object:GetObject (intptr,bool)
> in <0x00036> Gtk.CellRenderer:GetSize_cb
> (intptr,intptr,intptr,intptr,intptr,intptr,intptr)
> in <0x000e8> (wrapper native-to-managed) Gtk.CellRenderer:GetSize_cb
> (intptr,intptr,intptr,intptr,intptr,intptr,intptr)
> in (unmanaged) (wrapper managed-to-native) Gtk.Application:gtk_main ()
> in <0x00004> (wrapper managed-to-native) Gtk.Application:gtk_main ()
> in <0x00007> Gtk.Application:Run ()
>=20
> Adding an empty constuctor avoids this error, eg.
>=20
> protected MyCellRenderer(IntPtr i) {
>=20
> }
>=20
I don't know much about gtk-sharp (nor gtk for that matter), but I think
your custom cell renderer should derive from another class, say
CellRenderer (you'll have to google because I don't know the actual
class).
Wrt your problem, passing the IntPtr param to the base class should
work:

protected MyCellRenderer(IntPtr i): base(i) { /* ... */ }

> but this seems to create a bug. Also, the sample custom cellrenderer
> does not need a IntPtr constructor.
>=20
> Any help appreciated,
>=20
> Adam
>=20
>=20
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
--=20
Rodolfo Campero
http://expertcoder.sourceforge.net/