' Buttonbox.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 Button Box with the specified parameters
FUNCTION create_bbox( BYVAL horizontal AS gint, BYVAL title AS ZSTRING PTR, BYVAL spacing AS gint, _
        BYVAL child_w AS gint, BYVAL child_h AS gint, BYVAL layout AS gint) AS GtkWidget PTR

  VAR frame = gtk_frame_new (title)

  DIM AS GtkWidget PTR bbox
  IF horizontal THEN
      bbox = gtk_hbutton_box_new ()
  ELSE
      bbox = gtk_vbutton_box_new ()
  END IF

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5)
  gtk_container_add (GTK_CONTAINER (frame), bbox)

  ' Set the appearance of the Button Box
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout)
  gtk_box_set_spacing (GTK_BOX (bbox), spacing)

  g_object_set_data(G_Object (bbox), "child-min-width", @child_w)
  g_object_set_data(G_Object (bbox), "child-min-height", @child_h)

  VAR button = gtk_button_new_from_stock (GTK_STOCK_OK)
  gtk_container_add (GTK_CONTAINER (bbox), button)

  button = gtk_button_new_from_stock (GTK_STOCK_CANCEL)
  gtk_container_add (GTK_CONTAINER (bbox), button)

  button = gtk_button_new_from_stock (GTK_STOCK_HELP)
  gtk_container_add (GTK_CONTAINER (bbox), button)

  RETURN frame
END FUNCTION

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

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

VAR win = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_window_set_title (GTK_WINDOW (win), "Button Boxes")

g_signal_connect (G_OBJECT (win), "destroy", _
                  G_CALLBACK (@gtk_main_quit), NULL)

gtk_container_set_border_width (GTK_CONTAINER (win), 10)

VAR main_vbox = gtk_vbox_new (FALSE, 0)
gtk_container_add (GTK_CONTAINER (win), main_vbox)

VAR frame_horz = gtk_frame_new ("Horizontal Button Boxes")
gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10)

VAR vbox = gtk_vbox_new (FALSE, 0)
gtk_container_set_border_width (GTK_CONTAINER (vbox), 10)
gtk_container_add (GTK_CONTAINER (frame_horz), vbox)

gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "Spread (spacing 40)", 40, 85, 20, GTK_BUTTONBOX_SPREAD), TRUE, TRUE, 0)

gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "Edge (spacing 30)", 30, 85, 20, GTK_BUTTONBOX_EDGE), TRUE, TRUE, 5)

gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "Start (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_START), TRUE, TRUE, 5)

gtk_box_pack_start (GTK_BOX (vbox), create_bbox (TRUE, "End (spacing 10)", 10, 85, 20, GTK_BUTTONBOX_END), TRUE, TRUE, 5)

VAR frame_vert = gtk_frame_new ("Vertical Button Boxes")
gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10)

VAR hbox = gtk_hbox_new (FALSE, 0)
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10)
gtk_container_add (GTK_CONTAINER (frame_vert), hbox)

gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "Spread (spacing 5)", 5, 85, 20, GTK_BUTTONBOX_SPREAD), TRUE, TRUE, 0)

gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "Edge (spacing 30)", 30, 85, 20, GTK_BUTTONBOX_EDGE), TRUE, TRUE, 5)

gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "Start (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_START), TRUE, TRUE, 5)

gtk_box_pack_start (GTK_BOX (hbox), create_bbox (FALSE, "End (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_END), TRUE, TRUE, 5)

gtk_widget_show_all (win)

' Enter the event loop *
gtk_main ()
