1#!/usr/bin/perl -w 2 3# Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the full 4# list) 5# 6# This library is free software; you can redistribute it and/or modify it under 7# the terms of the GNU Library General Public License as published by the Free 8# Software Foundation; either version 2.1 of the License, or (at your option) 9# any later version. 10# 11# This library is distributed in the hope that it will be useful, but WITHOUT 12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for 14# more details. 15# 16# You should have received a copy of the GNU Library General Public License 17# along with this library; if not, write to the Free Software Foundation, Inc., 18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19# 20# $Id$ 21# 22# r.m. 23# 24 25use strict; 26use Gtk2 '-init'; 27use Gtk2::SimpleMenu; 28use Data::Dumper; 29 30sub callback 31{ 32 print "Callback:\n"; 33 print Dumper(@_); 34} 35 36sub default_callback 37{ 38 print "Default Callback:\n"; 39 print Dumper(@_); 40} 41 42my $action = 0; 43my $menu_tree = [ 44 _File => { 45 item_type => '<Branch>', 46 children => [ 47 _New => { 48 callback => \&callback, 49 callback_action => $action++, 50 accelerator => '<ctrl>N', 51 }, 52 _Save => { 53 callback_action => $action++, 54 callback_data => 'cbdata 1', 55 accelerator => '<ctrl>S', 56 }, 57 'Save _As' => { 58 callback => \&callback, 59 callback_action => $action++, 60 callback_data => 'cbdata 2', 61 accelerator => '<ctrl>A', 62 }, 63 _Exit => { 64 callback => sub { Gtk2->main_quit; }, 65 callback_action => $action++, 66 accelerator => '<ctrl>E', 67 }, 68 ], 69 }, 70 _Edit => { 71 item_type => '<Branch>', 72 children => [ 73 _Copy => { 74 callback => \&callback, 75 callback_action => $action++, 76 }, 77 _Paste => { 78 callback_action => $action++, 79 }, 80 ], 81 }, 82 _Tools => { 83 item_type => '<Branch>', 84 children => [ 85 _Tearoff => { 86 item_type => '<Tearoff>', 87 }, 88 _CheckItem => { 89 callback => \&callback, 90 callback_action => $action++, 91 item_type => '<CheckItem>', 92 }, 93 _ToggleItem => { 94 callback_action => $action++, 95 item_type => '<ToggleItem>', 96 }, 97 _StockItem => { 98 callback => \&callback, 99 callback_action => $action++, 100 item_type => '<StockItem>', 101 extra_data => 'gtk-execute', 102 }, 103 _Radios => { 104 item_type => '<Branch>', 105 children => [ 106 'Radio _1' => { 107 callback => \&callback, 108 callback_action => $action++, 109 item_type => '<RadioItem>', 110 groupid => 1, 111 }, 112 'Radio _2' => { 113 callback => \&callback, 114 callback_action => $action++, 115 item_type => '<RadioItem>', 116 groupid => 1, 117 }, 118 'Radio _3' => { 119 callback => \&callback, 120 callback_action => $action++, 121 item_type => '<RadioItem>', 122 groupid => 1, 123 }, 124 ], 125 }, 126 Separator => { 127 item_type => '<Separator>', 128 }, 129# image menu item types are not supported at this point 130# _Image => { 131# callback => \&callback, 132# callback_action => $action++, 133# item_type => '<ImageItem>', 134# }, 135 ], 136 }, 137 _Help => { 138 item_type => '<Branch>', 139 children => [ 140 _Introduction => { 141 callback => \&callback, 142 callback_action => $action++, 143 }, 144 _About => { 145 callback_action => $action++, 146 } 147 ], 148 }, 149]; 150 151my $menu = Gtk2::SimpleMenu->new( 152 menu_tree => $menu_tree, 153 default_callback => \&default_callback, 154 user_data => 'user data', 155 ); 156 157$menu->get_widget('/Tools/Radios/Radio 2')->set_active(1); 158 159my $win = Gtk2::Window->new; 160$win->signal_connect(delete_event => sub { exit }); 161$win->add($menu->{widget}); 162$win->add_accel_group($menu->{accel_group}); 163$win->show_all; 164Gtk2->main; 165 166