[Gtk-sharp-list] Problems with DiaCanvas# new items

Mario Fuentes mario@gnome.cl
Tue, 03 Aug 2004 14:17:42 -0400


Hello, i'm working on diacanvas# support for create new items based on
Dia.CanvasItem.  I'm implemented four virtual methods, "update",
"get_shape_iter", "shape_next" and "shape_value".  the three first
methods are ok, but "shape_value" have a problem.
I implemented "shape_value" like this:

<libglue>
DiaShape *
diasharp_canvas_item_base_shape_value (DiaCanvasItem *item,
DiaCanvasIter *iter){
   DiaCanvasItemClass *parent = g_type_class_peek_parent
(G_OBJECT_GET_CLASS (item));

   if (parent->shape_value)
      return ((*parent->shape_value) (item, iter));

   return NULL;
}

void
diasharp_canvas_item_override_shape_value (GType gtype, gpointer
callback)
{
   DiaCanvasItemClass *klass;

   klass = g_type_class_peek (gtype);

   if (!klass)
      klass = g_type_class_ref (gtype);

   ((DiaCanvasItemClass *) klass)->shape_value = callback;
}
</libglue>

<CanvasItem>
delegate Shape ShapeValueDelegate (IntPtr item, ref CanvasIter iter);

static ShapeValueDelegate ShapeValueCallback;

static Shape ShapeValue_Callback (IntPtr item, ref CanvasIter iter)
{
	CanvasItem obj = GLib.Object.GetObject (item, false) as CanvasItem;

	return obj.ShapeValueFunc (ref iter);
}

[DllImport("diacanvassharpglue")]
static extern void diasharp_canvas_item_override_shape_value (GLib.GType
gtype, ShapeValueDelegate callback);

static void OverrideShapeValue (GLib.GType gtype)
{
	if (ShapeValueCallback == null)
		ShapeValueCallback += new ShapeValueDelegate (ShapeValue_Callback);

	diasharp_canvas_item_override_shape_value (gtype, ShapeValueCallback);
}

[DllImport("diacanvassharpglue")]
static extern IntPtr dia_canvas_item_base_shape_value (IntPtr raw, ref
Dia.CanvasIter iter);

[GLib.DefaultSignalHandler (Type=typeof(Dia.CanvasItem),
ConnectionMethod="OverrideShapeValue")]
protected virtual Shape ShapeValueFunc (ref CanvasIter iter)
{
	Console.WriteLine ("protected virtual Shape ShapeValueFunc (ref
CanvasIter iter)");
	IntPtr raw_ret = dia_canvas_item_base_shape_value (Handle, ref iter);
	Shape ret;
	
	if (raw_ret == IntPtr.Zero)
		ret = null;
	else
		ret = new Dia.Shape(raw_ret);

	return ret;
}
</CanvasItem>

<TestCode>
public class MyItem : CanvasElement {
	[...]
	protected override Shape ShapeValueFunc (ref CanvasIter iter)
	{
		Console.WriteLine ("ShapeValue");

		if (iter.Data[0] == IntPtr.Zero)
			return null;
		return new Shape (iter.Data[0]);
	}
}
</TestCode>

When override "ShapeValueFunc" method, sample crash with this message:

** ERROR **: file marshal.c: line 2580
(mono_marshal_get_managed_wrapper): assertion failed: ((klass->flags &
TYPE_ATTRIBUTE_LAYOUT_MASK) != TYPE_ATTRIBUTE_AUTO_LAYOUT)
aborting...

All code is in the CVS version of diacanvas# (diacavas-sharp module in
mono anoncvs)

Any idea is welcome, we need diacanvas# for MonoUML project.

Bye.
-- 
Mario Fuentes
http://primate.gnome.cl/~mario
mailto:mario@gnome.cl
<<Se omitio la tildacion, para evitar perdida de informacion>>