' Created by vladimir777, 2011
'
' 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"

SUB undo_redo CDECL(BYVAL widget AS GtkWidget PTR, BYVAL item AS gpointer)

  STATIC count AS gint = 0
  VAR NAME1 = *gtk_widget_get_name(widget)

  PRINT NAME1

  gtk_widget_set_sensitive(item, TRUE)
  IF (NAME1 = "undo1") THEN
    count += 1
    IF count < 2 THEN EXIT SUB
  ELSE
    count -= 1
    IF count > -2 THEN EXIT SUB
  END IF
  gtk_widget_set_sensitive(widget, FALSE)

END SUB


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

VAR win = gtk_window_new(GTK_WINDOW_TOPLEVEL)
gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER)
gtk_window_set_default_size(GTK_WINDOW(win), 250, 200)
gtk_window_set_title(GTK_WINDOW(win), "undoredo")

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

VAR toolbar = gtk_toolbar_new()
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS)

gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2)

VAR undo1 = gtk_tool_button_new_from_stock(GTK_STOCK_UNDO)
gtk_widget_set_name(GTK_WIDGET(undo1), "undo1")
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), undo1, -1)

VAR redo1 = gtk_tool_button_new_from_stock(GTK_STOCK_REDO)
gtk_widget_set_name(GTK_WIDGET(redo1), "redo1")
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), redo1, -1)

VAR sep = gtk_separator_tool_item_new()
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), sep, -1)

VAR EXIT1 = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT)
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), EXIT1, -1)

gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 5)
g_signal_connect (G_OBJECT(undo1), "clicked", _
                  G_CALLBACK(@undo_redo), redo1)
g_signal_connect (G_OBJECT(redo1), "clicked", _
                  G_CALLBACK(@undo_redo), undo1)
g_signal_connect (G_OBJECT(EXIT1), "clicked", _
                  G_CALLBACK(@gtk_main_quit), NULL)
g_signal_connect (G_OBJECT(win), "delete-event", _
                  G_CALLBACK(@gtk_main_quit), NULL)
gtk_widget_show_all(win)

gtk_main()

