[gtkada] Canvas signal "item_select" - can't complile
Stephen Leake
stephen_leake at acm.org
Wed Oct 23 13:58:19 CEST 2002
Enno Bartels <enno.bartels at m.eads.net> writes:
> Here is my code:
>
> ----------------------------------------------------------------
> -- Redefine our own item type, since we want to provide our own
> -- graphics.
> ----------------------------------------------------------------
> type Display_Item_Record is new Canvas_Item_Record with record
> Color : Gdk.Color.Gdk_Color;
> W, H : Gint;
> Num : Positive;
> X, Y : Gint;
> Mode : Integer;
> end record;
> type Display_Item is access all Display_Item_Record'Class;
>
> ...................
>
> package Canvas_Cb is new Gtk.Handlers.Callback (Interactive_Canvas_Record);
Hmm. You declare "Display_Item_Record" above, but you are using
"Interactive_Canvas_Record" here. So I'm confused.
> ----------------------------------------------------------------------------
> -- procedure "Item_Select"
> ----------------------------------------------------------------------------
> procedure Item_Select
> (Canvas : access Interactive_Canvas_Record'Class;
> Item : Canvas_Item)
> is
> It : Display_Item := Display_Item (Item);
> begin
> Text_Io.Put_Line ("item selected " & It.Num'Img);
> end Item_Select;
>
> ......................
>
> Canvas : Interactive_Canvas;
> ...
> Canvas_Cb.Object_Connect (Canvas, "item_selected",
> Canvas_Cb.To_Marshaller(Item_Select'Access), Canvas);
There is no version of "To_Marshaller" in Canvas_Cb that can take a
handler procedure with a Canvas_Item parameter; only the general
parameter types gint, guint, event are declared for you (see
gtk-handlers.ads). So you need to instantiate your own. Something
like:
package Canvas_Item_Marshaller is new Marshallers.Generic_Marshaller
(Canvas_Item, To_Canvas_Item);
You have to write "To_Canvas_Item" as well; see gtk-arguments.ads, .adb.
Then you can do:
Canvas_Cb.Object_Connect
(Canvas,
"item_selected",
Canvas_Item_Marshaller.To_Marshaller (Item_Select'Access),
Canvas);
Yes, this is confusing!
--
-- Stephe
More information about the gtkada
mailing list