1. Full GTK+ example

Hurrah! Callbacks in GTK turn out to be trivial, after all.

This example adds functionality to the button - pressing it closes the
window.

After this, I'll stop posting examples to the mailing list. I just thought
people might be interested in seeing what the code looks like.

My only complaint is my usual gripe about the scoping of routine_id.
Robert - *please* consider changing it.

-- David Cuny

-- gtktest.exu

-- without this, you get warnings before the window closes
without warning

-- reading dlls
include dll.e
include machine.e

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

-- declare gtk 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_quit = define_c_proc( gtk, "gtk_main_quit", {} ),
gtk_signal_connect = define_c_proc( gtk, "gtk_signal_connect",
{C_POINTER,C_POINTER,C_POINTER,C_POINTER} ),
gtk_main = define_c_proc( gtk, "gtk_main", {} )

constant
GTK_WINDOW_TOPLEVEL = 1 -- this might be 2

-- define a callback
function closeApp( atom widget, atom gdata )

    -- close the application
     c_proc( gtk_main_quit, {} )

     -- ok to close application
     return 0

end function

-- 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} )

-- run closeApp when button is clicked
c_proc( gtk_signal_connect, {
         button,
         allocate_string("clicked"),
         call_back( routine_id("closeApp") ),
         0 } )

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

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu