REM
REM GTK example with BACON
REM March 2009 - PvE.
REM Adapted November 2009.
REM
TRAP LOCAL
CATCH GOTO print_error

CONST Gtk$ = "libgtk-x11-2.0.so.0"
CONST Gobject$ = "libgobject-2.0.so.0"

REM Get needed functions from GTK
IMPORT "gtk_init(int*,void*)" FROM Gtk$ TYPE void
IMPORT "gtk_window_new(int)" FROM Gtk$ TYPE long
IMPORT "gtk_window_set_title(long,char*)" FROM Gtk$ TYPE void
IMPORT "gtk_table_new(int,int,int)" FROM Gtk$ TYPE long
IMPORT "gtk_table_attach_defaults(long,long,int,int,int,int)" FROM Gtk$ TYPE void
IMPORT "gtk_container_add(long,long)" FROM Gtk$ TYPE void
IMPORT "gtk_button_new_from_stock(char*)" FROM Gtk$ TYPE long
IMPORT "gtk_label_new(char*)" FROM Gtk$ TYPE long
IMPORT "gtk_widget_show_all(long)" FROM Gtk$ TYPE void
IMPORT "gtk_main" FROM Gtk$ TYPE void
IMPORT "gtk_exit(int)" FROM Gtk$ TYPE void
IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM Gobject$ TYPE void

REM Callback for closing window
SUB exit_prog
    gtk_exit(0)
ENDSUB

REM Main program starts here
gtk_init(0, 0)
LET window = gtk_window_new(0)
gtk_window_set_title(window, "Hello world")
LET table = gtk_table_new(15, 15, 1)
gtk_container_add(window, table)
LET label = gtk_label_new("Bacon and GTK example!")
gtk_table_attach_defaults(table, label, 1, 8, 3, 7)
LET button = gtk_button_new_from_stock("gtk-quit")
gtk_table_attach_defaults(table, button, 10, 14, 12, 14)

REM Show whole GUI
gtk_widget_show_all(window)

REM Use as callback the defined SUB
g_signal_connect_data(window, "delete-event", ADDRESS(exit_prog), 0, 0, 0)
g_signal_connect_data(button, "clicked", ADDRESS(exit_prog), 0, 0, 0)

REM Endless event handling by GTK
gtk_main

REM Error handling
LABEL print_error
    PRINT "GTK library ", Gtk$, " is not available on this platform!"
    END