' Buttons.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"

' Create a new hbox with an image and a label packed into it
' and return the box.

FUNCTION xpm_label_box CDECL(BYVAL xpm_filename AS gpointer PTR, BYVAL label_text AS gpointer PTR) AS GtkWidget PTR

	' Create box for image and label
	VAR box = gtk_hbox_new (FALSE, 0)
	gtk_container_set_border_width (GTK_CONTAINER (box), 2)

	' Now on to the image stuff
	VAR image = gtk_image_new_from_file (xpm_filename)

	' Create a label for the button
	VAR label = gtk_label_new (label_text)

	' Pack the image and label into the box
	gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 3)
	gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 3)

	gtk_widget_show (image)
	gtk_widget_show (label)

	RETURN box
END FUNCTION

' Our usual callback function
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 a decent default size for the window.
gtk_window_set_default_size( GTK_WINDOW( win ), 200, 20 )
gtk_window_set_title (GTK_WINDOW (win), "Pixmap'd Buttons!")

' It's a good idea to do this for all windows.
g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (@gtk_main_quit), NULL)
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), 10)

' Create a new button
VAR button = gtk_button_new ()

' Connect the "clicked" signal of the button to our callback
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (@callback), STRPTR("cool button"))

' This calls our box creating function
VAR box = xpm_label_box (STRPTR("info.xpm"), STRPTR("cool button"))

' Pack and show all our widgets
gtk_widget_show (box)

gtk_container_add (GTK_CONTAINER (button), box)

gtk_widget_show (button)

gtk_container_add (GTK_CONTAINER (win), button)

gtk_widget_show (win)

' Rest in gtk_main and wait for the fun to begin!
gtk_main ()
