#!/usr/bin/perl -w

use strict;

$| = 1;

MenuTest->run;

exit;


package MenuTest;

use base qw(Class::Accessor::Fast);

use Glib qw(TRUE FALSE);
use Gtk2 -init;
use Gtk2::GladeXML;

BEGIN {
  __PACKAGE__->mk_accessors(qw(
    gui
  ));
}

sub run { my $self = shift->new; Gtk2->main; }

sub new { return bless({}, shift)->_init; }

sub _init {
  my $self = shift;

  local($/);
  my $gui = $self->gui(Gtk2::GladeXML->new_from_buffer(<DATA>));

  $gui->signal_autoconnect_from_package($self);

  return $self;
}

sub on_execute_clicked {
  my $self = shift;

  print "\n===== Effects Menu =====\n";
  my $menu = $self->gui->get_widget('effects') or die "can't find Effects menu";
  $menu = $menu->get_submenu;
  foreach my $item ($menu->get_children) {
    next if $item->isa('Gtk2::SeparatorMenuItem');
    my $selected = $item->get_active ? 'selected' : 'not selected';
    $item = $item->child if $item->can('child');
    printf("%-12s %s\n", $item->get_label, $selected);
  }
}

sub on_menutest_delete_event { Gtk2->main_quit; }


__DATA__
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="menutest">
  <property name="visible">True</property>
  <property name="title" translatable="yes">window1</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <signal name="delete_event" handler="on_menutest_delete_event" last_modification_time="Sun, 17 Apr 2005 21:18:22 GMT"/>

  <child>
    <widget class="GtkToolbar" id="toolbar1">
      <property name="visible">True</property>
      <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
      <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
      <property name="tooltips">True</property>
      <property name="show_arrow">True</property>

      <child>
	<widget class="GtkToolButton" id="execute">
	  <property name="visible">True</property>
	  <property name="stock_id">gtk-execute</property>
	  <property name="visible_horizontal">True</property>
	  <property name="visible_vertical">True</property>
	  <property name="is_important">False</property>
	  <signal name="clicked" handler="on_execute_clicked" last_modification_time="Sun, 17 Apr 2005 22:23:58 GMT"/>
	</widget>
	<packing>
	  <property name="expand">False</property>
	  <property name="homogeneous">True</property>
	</packing>
      </child>

      <child>
	<widget class="GtkToolItem" id="toolitem1">
	  <property name="visible">True</property>
	  <property name="visible_horizontal">True</property>
	  <property name="visible_vertical">True</property>
	  <property name="is_important">False</property>

	  <child>
	    <widget class="GtkMenuBar" id="menubar">
	      <property name="visible">True</property>

	      <child>
		<widget class="GtkMenuItem" id="effects">
		  <property name="visible">True</property>
		  <property name="label" translatable="yes">Effects</property>
		  <property name="use_underline">True</property>

		  <child>
		    <widget class="GtkMenu" id="effects_menu">

		      <child>
			<widget class="GtkCheckMenuItem" id="none">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">None</property>
			  <property name="use_underline">True</property>
			  <property name="active">True</property>
			</widget>
		      </child>

		      <child>
			<widget class="GtkCheckMenuItem" id="fade">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">Fade</property>
			  <property name="use_underline">True</property>
			  <property name="active">False</property>
			</widget>
		      </child>

		      <child>
			<widget class="GtkSeparatorMenuItem" id="separator1">
			  <property name="visible">True</property>
			</widget>
		      </child>

		      <child>
			<widget class="GtkRadioMenuItem" id="1x_speed">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">1x Speed</property>
			  <property name="use_underline">True</property>
			  <property name="active">True</property>
			</widget>
		      </child>

		      <child>
			<widget class="GtkRadioMenuItem" id="2x_speed">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">2x Speed</property>
			  <property name="use_underline">True</property>
			  <property name="active">False</property>
			  <property name="group">1x_speed</property>
			</widget>
		      </child>

		      <child>
			<widget class="GtkRadioMenuItem" id="3x_speed">
			  <property name="visible">True</property>
			  <property name="label" translatable="yes">3x Speed</property>
			  <property name="use_underline">True</property>
			  <property name="active">False</property>
			  <property name="group">1x_speed</property>
			</widget>
		      </child>
		    </widget>
		  </child>
		</widget>
	      </child>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="expand">False</property>
	  <property name="homogeneous">False</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>
