' Table.bas
' Translated from C to FB by TinyCla, 2006
'
' Reviewed by TJF (2011-2014)
' Details: http://developer.gnome.org/gtk/

#INCLUDE ONCE "Gir/Gtk-3.0.bi"
'#INCLUDE ONCE "Gir/Gtk-2.0.bi"
#INCLUDE ONCE "Gir/_GObjectMacros-2.0.bi"

' Our callback.
' The data passed to this function is printed to stdout
SUB callback CDECL(BYVAL widget AS GtkWidget PTR, BYVAL user_data AS gpointer PTR)

    g_print (!"Hello again - %s was pressed\n", user_data)

END SUB

' ==============================================
' Main
' ==============================================

' Initialize the toolkit
gtk_init(@__FB_ARGC__, @__FB_ARGV__)

' Create a new window
VAR win = gtk_window_new (GTK_WINDOW_TOPLEVEL)

' Set the window title
gtk_window_set_title (GTK_WINDOW (win), "Table")

' Set a handler for delete_event that immediately
' exits GTK.
g_signal_connect (G_OBJECT (win), "delete_event", _
                  G_CALLBACK (@gtk_main_quit), NULL)

' Sets the border width of the window.
gtk_container_set_border_width (GTK_CONTAINER (win), 20)

' Create a 2x2 table
VAR table = gtk_table_new (2, 2, TRUE)

' Put the table in the main window
gtk_container_add (GTK_CONTAINER (win), table)

' Create first button
VAR button = gtk_button_new_with_label ("button 1")

' When the button is clicked, we call the "callback" function
' with a pointer to "button 1" as its argument
g_signal_connect (G_OBJECT (button), "clicked", _
                  G_CALLBACK (@callback), STRPTR("button 1"))

' Insert button 1 into the upper left quadrant of the table
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 0, 1)

gtk_widget_show (button)

' Create second button
button = gtk_button_new_with_label ("button 2")

' When the button is clicked, we call the "callback" function
' with a pointer to "button 2" as its argument
g_signal_connect (G_OBJECT (button), "clicked", _
                  G_CALLBACK (@callback), STRPTR("button 2"))

' Insert button 2 into the upper right quadrant of the table
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 0, 1)

gtk_widget_show (button)

' Create "Quit" button
button = gtk_button_new_with_label ("Quit")

' When the button is clicked, we call the "delete_event" function
' and the program exits
g_signal_connect (G_OBJECT (button), "clicked", _
                  G_CALLBACK (@gtk_main_quit), NULL)

' Insert the quit button into the both
' lower quadrants of the table
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 1, 2)

gtk_widget_show (button)
gtk_widget_show (table)
gtk_widget_show (win)

gtk_main ()
