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

TYPE StatusUdt
  AS GtkWidget PTR status_bar
  AS guint context_id
END TYPE


SUB push_item CDECL( BYVAL widget AS GtkWidget PTR, BYVAL user_data AS gpointer )

  STATIC AS gint count
  DIM AS STRING buff = "Item " + STR(count)

  count += 1
  WITH *CAST(StatusUdt PTR, user_data)
    gtk_statusbar_push (GTK_STATUSBAR (.status_bar), .context_id, SADD(buff))
  END WITH

END SUB

SUB pop_item CDECL( BYVAL widget AS GtkWidget PTR, BYVAL user_data AS gpointer )

  WITH *CAST(StatusUdt PTR, user_data)
    gtk_statusbar_pop (GTK_STATUSBAR (.status_bar), .context_id)
  END WITH

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_widget_set_size_request (GTK_WIDGET (win), 250, 100)
gtk_window_set_title (GTK_WINDOW (win), "GTK Statusbar Example")
g_signal_connect (G_OBJECT (win), "delete_event", _
                  G_CALLBACK (@gtk_main_quit), NULL)

VAR vbox = gtk_vbox_new (FALSE, 1)
gtk_container_add (GTK_CONTAINER (win), vbox)
gtk_widget_show (vbox)

DIM AS StatusUdt UserDat
WITH UserDat
  .status_bar = gtk_statusbar_new ()
  gtk_box_pack_start (GTK_BOX (vbox), .status_bar, TRUE, TRUE, 0)
  gtk_widget_show (.status_bar)

  .context_id = gtk_statusbar_get_context_id( GTK_STATUSBAR (.status_bar), _
                                             "Statusbar example")
END WITH

VAR button = gtk_button_new_with_label ("push item")
g_signal_connect (G_OBJECT (button), "clicked", _
                  G_CALLBACK (@push_item), @UserDat)
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 2)
gtk_widget_show (button)

button = gtk_button_new_with_label ("pop last item")
g_signal_connect (G_OBJECT (button), "clicked", _
                  G_CALLBACK (@pop_item), @UserDat)
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 2)
gtk_widget_show (button)

' always display the window as the last step so it all splashes on
' the screen at once.
gtk_widget_show (win)

gtk_main ()
