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

' I'm going to be lazy and use some global variables to
' store the position of the widget within the fixed
' container
DIM SHARED AS gint _
  x = 50 _
, y = 50

' This callback function moves the button to a new position
' in the Fixed container.
SUB move_button CDECL( BYVAL widget AS GtkWidget PTR, BYVAL fixed AS GtkWidget PTR )
    x = (x + 30) MOD 300
    y = (y + 50) MOD 300
    gtk_fixed_move (GTK_FIXED (fixed), widget, x, y)
END SUB


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

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

' Create a new window
VAR win = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_window_set_title (GTK_WINDOW (win), "Fixed Container")

' Here we connect the "destroy" event to a signal handler
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 Fixed Container
VAR fixed = gtk_fixed_new ()
gtk_container_add (GTK_CONTAINER (win), fixed)
gtk_widget_show (fixed)

FOR i AS gint = 1 TO 3
  ' Creates a new button with the label "Press me"
  VAR button = gtk_button_new_with_label ("Press me")

  ' When the button receives the "clicked" signal, it will call the
  ' function move_button() passing it the Fixed Container as its
  ' argument.
  g_signal_connect (G_OBJECT (button), "clicked", _
                    G_CALLBACK (@move_button), fixed)

  ' This packs the button into the fixed containers window.
  gtk_fixed_put (GTK_FIXED (fixed), button, i * 50, i * 50)

  ' The final step is to display this newly created widget.
  gtk_widget_show (button)
NEXT

' Display the window
gtk_widget_show (win)

' Enter the event loop
gtk_main ()
