[gtkada] Help -- interfacing to new widgets
Emmanuel Briot
briot at gnat.com
Thu Dec 21 14:50:48 CET 2000
Srinivasan, Rajagopalan (IndSys, SalemVA) writes:
> I am trying to build Ada Interfaces to several Gtk widgets that i
> downloaded. GtkExText is an example though I am shooting for the html
> renderer from mozilla. I got the "C" code, got it compiled etc. Now I am
> trying to hand translate the ".h" file into an Ada Spec etc using Gtk.Text
> as an example.
> - There is an Object Hierarchy as implemented in the GtkAda. It is not
> clear how this maps to the "struct" defined for each widget. Does it have to
> at all?
This tagged type hierarchy must reflect the one present implicitly in gtk+ or
the library you are trying to interface, so that primitive operations are
correctly inherited, and that the full power of tagged types can be used.
The name of the Ada type is pretty much up to you, although it would be nice
to keep a coherent interface with the rest of gtk+ and GtkAda. For instance,
you should use Gtk_Ex_Text as the name of the type.
> - Looking at gtk.ads -- it appears that the user_data field in the "C" world
> is used to store some sort of pointer to the Ada record. Is this true.
Yes. Basically, an Ada widget is simply a pointer to the underlying C struct,
so it is easy to convert from Ada to C.
On the other hand, we need to convert from C to Ada (for instance when a
function returns a C widget), which is why we store a "user_data" field with
the C widget. This field points to the Ada widget.
As a side effect, this also allows us to free the memory allocated in Ada
every time a C widget is destroyed.
> - Is it true that the handle returned eg Gtk_Text (access all
> Gtk_Text_Record'Class) is really a pointer to the "C" structure?
No. It is a pointer to an Ada record that happens to contain a pointer to the
C structure. But like all tagged types, it also contain a tag, or even some
other data for widgets created directly in Ada.
We will improve the documentation of GtkAda to reflect how new bindings can be
implemented. We also had at some point a Perl script that was taking care of
most of the work, although it was expecting some special format for the C
files (gtk+ style). We will revive that script if possible.
There was an article at Ada-Europe'2000 that explained a number of tricks we
used to make the binding, and that you might find useful. I don't know if we
are allowed to publish it or not, I will check that.
Emmanuel
GtkAda team
More information about the gtkada
mailing list