#!/usr/bin/perl

# Sample from perl cookbook pg 537,
# Menus are made of 4 separate components:
#       1) Frames               - horizontoal bar
#       2) Menubuttons          - Buttons like "File", "Edit", "Print"
#       3) Menus                - menus corresponding to the buttons "File", "Edit", "Print"
#       4) Menu Entries         - verticly arranged
#          lables|separators            - options on the menu

use Tk;

$main=MainWindow->new();

#  Create a horizontal space at the top of window
#  for the menu to live.
#
$menubar=$main->Frame(-relief                   => "raised",
                      -borderwidth              => 2)

              ->pack (-anchor                   => "nw",
                      -fill                     => "x");

# Create a button labeled "File" that brings up a menu
$file_menu=$menubar->Menubutton(-text           => "File",
                                -underline      => 1)
                        ->pack (-side           => "left" );

# Create entries in the "File" menu
$file_menu->command(-label      =>      "Print",
                    -command    =>      \&Print);

$file_menu->separator();

$file_menu->command(-label      =>      "Quit Immediately",
                    -command    =>      sub { exit });


# This uses the menuitems short cut to do the same thing:
$file_menu = $menubar->Menubutton(-text => "File",
                                -underline      => 1,
                                -menuitems      => [
                [ Button => "Print",-command => \&Print ],
                [ Button => "Save",-command => \&Save   ] ])
                   ->pack (-side                        => "left");

# Checkbutton (radio binary button)
$options_menu->checkbutton(     -label  =>      "Create Debugging File",
                                -variable       =>      \$debug,
                                -onvalue        =>      1,
                                -offvalue       =>      0);

# Radio Buttons
$debut_menu->radiobutton(       -label          =>      "Level 1",
                                -variable       =>      \$log_level,
                                -value          =>      1);

$debut_menu->radiobutton(       -label          =>      "Level 2",
                                -variable       =>      \$log_level,
                                -value          =>      2);

$debut_menu->radiobutton(       -label          =>      "Level 3",
                                -variable       =>      \$log_level,
                                -value          =>      3);

# Nested menus with the "cascade" method
# step 1: create cascading menu entry
$format_menu->cascade(          -label          =>      "Font");
# step 2: get the new Menu we just made
$font_menu = $format_menu->cget("-menu");
# step 3: populate that Menu
$font_menu->radiobutton(        -label          =>      "Courier",
                                -variable       =>      \$font_name,
                                -value          =>      "courier");
$font_menu->radiobutton(        -label          =>      "Times Roman",
                                -variable       =>      \$font_name,
                                -value          =>      "times");

# Tear-off Menu
$format_menu=$menubar->Menubutton(-text         =>      "Format",
                                  -underline    =>      1
                                  -tearoff      =>      0)
                     ->pack;
$font_menu=$format_menu ->cascade(-label        =>      "Font"
                                  -tearoff      =>      0);
