1. Wrapping GTK+

Anyone have any clue how to go about wrapping the GTK+ library? I have a
number of questions:

[1. Is there a DLL for GTK+? ]

I know that Euphoria/Linux _can_ link to dynamic libraries - Graph and XLib,
for example. But is there a DLL for GTK+? If so, where is it, and how did
you figure it out?

In XLIB.H, the routines were declared as 'extern'; I don't see any such
animal in the GTK+ include files. How does the DLL know what routines are to
be exported?


[2. Prototype Syntax ]

 I've found the include files in /usr/include/gtk and /usr/include/gdk.
There are all sorts of declarations, such as:

    void gtk_list_undo_selection (GtkList *list);

I assume that these would have to be turned into something like:

    global constant
        gtk_list_undo_selection =
           define_c_proc(GTK,"gtk_list_undo_selection",{C_PTR})

Right? Wrong? I'm pretty sure I'm right, it's just that missing 'extern' has
me spooked.


[ 3. Enum ]

What value does 'enum' start numbering with? For example:

    /* cell types */
    typedef enum
    {
      GTK_CELL_EMPTY,
      GTK_CELL_TEXT,
      GTK_CELL_PIXMAP,
      GTK_CELL_PIXTEXT,
      GTK_CELL_WIDGET
    } GtkCellType;

Would the equivalent value of GTK_CELL_EMPTY be 0 or 1?


[ 4. Type declarations ]

In C, a typical declaration and assignment would be:

   GtkWidget *button;
   button = gtk_button_new_with_label ("I'm A Button!");

I assume that the equivalent in Euphoria would be something like this, with
no type casting needed:


   -- function prototype, for example's completeness
   constant gtk_list_undo_selection =
      define_c_func(GTK,"gtk_list_undo_selection",{C_PTR},C_PTR)

    -- no typecasting; they're just pointers
   atom szText, button

   -- convert to c string
   szText = allot_string("I'm A Button!")

   -- finally, the function call!
   button = c_func( gtk_button_new_with_label, {szText} )

   -- clean up local storage
   free( szText )

This looks good to me, but what do I know?

Thanks!

-- David Cuny

new topic     » topic index » view message » categorize

2. Re: Wrapping GTK+

[1. Is there a DLL for GTK+? ]

libgtk.so

[2. Prototype Syntax ]

The "extern" keyword is purely for the benefit of the programmer.  The
keyword is completely ignored by the C compiler and treats what follows it
like any other function prototype.

[ 3. Enum ]

Enumerations usually start with 0.

[ 4. Type declarations ]

Casting GtkWidget *'s as C_PTR should be fine.

Glad to hear you're making progress with xlib too.
 _______  ______  _______  ______
[    _  \[    _ ][ _   _ ][    _ ]
[/| [_] |[/| [_\][/ | | \][/| [_\]
  |  ___/  |  _]    | |     |  _]
[\| [/]  [\| [_/] [\| |/] [\| [_/]
[_____]  [______] [_____] [______]
xseal at harborside.com  ICQ:13466657
http://www.harborside.com/home/x/xseal/euphoria/

new topic     » goto parent     » topic index » view message » categorize

3. Re: Wrapping GTK+

Pete replied to my question:


>>[1. Is there a DLL for GTK+? ]
>
>libgtk.so


Here's the bit of code I'm currently struggling with. The value displayed
for gtk is 0, so it doesn't seem to be connecting. As a result, the code
fails at the first c_proc.

I've tried alternate values, such as:

   "/usr/lib/libgtk.so"

and paths to all the other GTK libraries I could find. "/usr/lib/libgtk.so"
is (as you know) actually a link to the library. I've got permissions to the
link, but I didn't bother checking if I had permissions to the library.
I've coded a number of small GTK programs in C under the same user login, so
I imagine that it's not a permissions problem.

Thanks!

-- David Cuny


-- gtktest.exu

include dll.e

-- try to link to a dll
atom gtk
gtk = open_dll("libgtk.so")

-- check value - this always returns 0  sad
? gtk

-- declare functions
constant
gtk_init = define_c_proc( gtk, "gtk_init", {C_POINTER, C_POINTER} ),
gtk_window_new = define_c_func( gtk, "gtk_window_new", {C_POINTER,
C_POINTER}, C_POINTER ),
gtk_window_set_title = define_c_func( gtk, "gtk_window_set_title",
{C_POINTER}, C_POINTER ),
gtk_container_border_width = define_c_func( gtk,
"gtk_container_border_width", {C_POINTER,C_LONG}, C_POINTER ),
gtk_button_new_with_label = define_c_func( gtk, "gtk_button_new_with_label",
{C_POINTER}, C_POINTER ),
gtk_widget_show = define_c_proc( gtk, "gtk_widget_show", {C_POINTER} ),
gtk_container_add = define_c_proc( gtk, "gtk_container_add", {C_POINTER,
C_POINTER} ),
gtk_main = define_c_proc( gtk, "gtk_main", {} )

constant
GTK_WINDOW_TOPLEVEL = 1 -- this might be 2

atom window, button

-- initialization
c_proc( gtk_init, { 0, 0 } )

-- create the toplevel window
window = c_func( gtk_window_new, {GTK_WINDOW_TOPLEVEL} )

-- title
c_proc( gtk_window_set_title, {window, allocate_string("Push Button") )

-- border
-- perhaps the prototype's #2 arg uses C_INT; I didn't really check
c_proc( gtk_container_border_width, {window, 50} )

-- create a button
button = c_func( gtk_button_new_with_label, {allocate_string("Button")} )

-- show the button (but not visible yet)
c_proc( gtk_widget_show, {button} )

-- add the button to the window
c_proc( gtk_container_add, {window, button} )

-- add button to window
c_proc( gtk_widget_show, {window} )

-- main loop
c_proc( gtk_main, {} )

-- return code of zero
abort(0)

new topic     » goto parent     » topic index » view message » categorize

4. Re: Wrapping GTK+

On Sat, 14 Aug 1999, you wrote:
> Pete replied to my question:
>
> Here's the bit of code I'm currently struggling with. The value displayed
> for gtk is 0, so it doesn't seem to be connecting. As a result, the code
> fails at the first c_proc.

I have the same results, likewise when I try to access libvga.so.
This always returns 0 (should be a very large number), even when
I make a copy of the library, and put it into the current directory, the
euphoria/bin directory, the euphoria/include directory, or wherever.
Doesn't matter whether I am running as root or as a user.
ld.so.conf shows the proper directories for the library.
Re-installing a new version doesn't help. Changing owner and
permissions doesn't help.

> I've tried alternate values, such as:
>
>    "/usr/lib/libgtk.so"

To access the libgraphapp.so file, I have to write this as:
"./libgraphapp.so"    (dot, slash) because the library file is
in the current working directory. Same technique won't work
with libvga.so or libgtk.so, however.

Irv

> Thanks!
>
> -- David Cuny
>
>
> -- gtktest.exu
>
> include dll.e
>
> -- try to link to a dll
> atom gtk
> gtk = open_dll("libgtk.so")
>
> -- check value - this always returns 0  sad
> ? gtk
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: Wrapping GTK+

Pete Eberlein wrote:

>I narrowed it down to:
>
>? open_dll("libgtkxmhtml.so")
>? open_dll("libgtk.so")

Thanks Pete (and Greg). I fixed some obvious errors (routine names, arg
counts, etc.) and it runs! The code is included.

I would never have figured this thing out myself. If there was a dependancy,
I would have bet on GDK or GLIB. Perhaps I can narrow it down a bit,
although at this point it's not really an issue.

Now I need to figure out how the callbacks work. If I'm lucky, it'll be as
trivial as it looks - simply registering the callback with
gtk_signal_connect. I'll try to give Irv and GraphApp a run for their money.
Hopefully there are no horrible licensing restrictions associated with GTK.

[ Llama ]

In case people are wondering what the status of Llama is, I've got it up and
running under Win32 again after some fairly serious modifications to the
classes. But I'm having some doubts about the wisdom of the underlying
messaging system. I think that I can accomplish a similar effect using
inheritance by simpler (and faster) means.

The end result should still accomplish all the original goals - portable
code, extensible classes and emulated controls.

And, of course, I'll be paying close attention to see if I can wrap GTK with
Llama. At this point, it looks very good.

-- David Cuny

-- gtktest.exu

include dll.e
include machine.e

-- link dlls
atom gtkhtml, gtk
gtkhtml = open_dll("libgtkxmhtml.so")
gtk = open_dll("libgtk.so")

-- declare functions
constant
gtk_init = define_c_proc( gtk, "gtk_init", {C_POINTER, C_POINTER} ),
gtk_window_new = define_c_func( gtk, "gtk_window_new", {C_POINTER},
C_POINTER ),
gtk_window_set_title = define_c_proc( gtk, "gtk_window_set_title",
{C_POINTER, C_POINTER} ),
gtk_container_set_border_width = define_c_proc( gtk,
"gtk_container_set_border_width", {C_POINTER, C_LONG} ),
gtk_button_new_with_label = define_c_func( gtk, "gtk_button_new_with_label",
{C_POINTER}, C_POINTER ),
gtk_widget_show = define_c_proc( gtk, "gtk_widget_show", {C_POINTER} ),
gtk_container_add = define_c_proc( gtk, "gtk_container_add", {C_POINTER,
C_POINTER} ),
gtk_main = define_c_proc( gtk, "gtk_main", {} )
constant

GTK_WINDOW_TOPLEVEL = 1

-- main loop
atom window, button

-- initialization
c_proc( gtk_init, { 0, 0 } )

-- create the toplevel window
window = c_func( gtk_window_new, {GTK_WINDOW_TOPLEVEL} )

-- title
c_proc( gtk_window_set_title, {window, allocate_string("Push Button")})

-- border
c_proc( gtk_container_set_border_width, {window, 50} )

-- create a button
button = c_func( gtk_button_new_with_label, {allocate_string("Button")} )

-- show the button (but not visible yet)
c_proc( gtk_widget_show, {button} )

-- add the button to the window
c_proc( gtk_container_add, {window, button} )

-- add button to window
c_proc( gtk_widget_show, {window} )

-- main loop
c_proc( gtk_main, {} )
abort(0)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu