[gtkada] Help! GtkAda-2.2.0 Callback with Arguments Confusion

Warren W. Gay VE3WWG ve3wwg at cogeco.ca
Wed Aug 25 04:23:33 CEST 2004


I am having a terrible time trying to sort out
callbacks with the combination of the GtkAda documentation
and the various layers of packages and generics involved.

I am trying to create a callback for the Gtk.Extra.Sheet
"traverse" event. The documentation sayz:

"traverse" function Handler (Sheet : access Gtk_Sheet_Record'Class;
    Row : Gint;
    Column : Gint;
    New_Row : Gint_Access;
    New_Column : Gint_Access)
return Boolean;


Now, I can get a simple callback to work if I ignore the need
for the arguments Row, Column, New_Row, and New_Column
such as in:

    package Sheet_Callback_Rtn is new
       Gtk.Handlers.Return_Callback(Gtk_Sheet_Record,Boolean);

    function Traverse_CB(
       M : access Gtk_Sheet_Record'Class
    ) return Boolean
    is
    begin
       Ada.Text_IO.Put_Line("Traverse..");
       return True;
    end Traverse_CB;

    ...
      -- set up callback
      Sheet_Callback_Rtn.Connect(M.Sheet,"traverse",
         Sheet_Callback_Rtn.To_Marshaller(Traverse_CB'Access),
         False
      );

But how in blazes do I get this to work using those
with those extra arguments? The impression I get is that
these To_Marshaller calls are supposed to make this easy
(I say humph!). I just get compile problems.

Based upon the documentation I am lead to believe that
I should be able to declare the callback as:

    function Traverse_CB(
       M :          access Gtk_Sheet_Record'Class;
       Row :        Gint;
       Column :     Gint;
       New_Row :    Gint_Access;
       New_Column : Gint_Access
    ) return Boolean
    is
    begin
       Ada.Text_IO.Put_Line("Traverse..");
       return True;
    end Traverse_CB;

but then I can never get the Connect call to compile (it
complains about the Memory_Travers_CB'Access). I
must be missing something that is assumed here.

I have the same problem for the documentation:

"changed" procedure Handler (Sheet : access Gtk_Sheet_Record'Class;
    Row : Gint;
    Column : Gint);

    Emitted when the content of the cell is modified (either the text itself, or its properties, alignment,...) A value of -1 for Row or 
Column means the row title, the column title, or their intersection.


Incidentally, the documentation for Package Gtk.Marshallers
says:
...
Note that most users don't need to understand or even look at this package,
... This package is rather complex (generic packages inside generic packages),
and thus you should understand correctly how Gtk.Handlers work before looking
at this one.


So fine, I go to the documentation "Package Gtkada.Handlers", which
says:

    This package provides the most commonly used instantiations of Gtk.Handlers

    Gate takes advantage of these pre-instantiated packages.

Hmmm.. this helped a lot. :P

I've also looked at the tutorial documentation, and none of the examples
listed seem complete enough to muddle this out, except for
simple cases where you are not using the extra arguments.

Is it just me?  Or have others had trouble with this? I didn't find
much on the web or the mailing list archives.

[NOTE: I can't use Glade-2 for this project, since it doesn't yet
support the Gtk.Extra.Sheet widget I need to use.]

Looking at the package specs, I don't see the obvious connection
between the callback with the different arguments, and the
To_Marshaller calls etc. I must be missing something.

Help!

Once I get that tackled, then I'll try User_Data parameters.

TIA, Warren.

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg



More information about the gtkada mailing list