#************************************************************
# nlvmenu.tcl --
#
#    Main window's menu.
#
# 8/12/98 : - Added GraphSizeDlg procedure. Basically a copy
#           of DisplayDlg, which modifies a different
#           element of the param() array.
#           - Eliminated some minor bugs with the
#           bookmark list facility.
# 8/13/98 : - Put both GraphSizeDlg and DisplayDlg into
#           a cascaded menu entry instead!
#
# 12/15/98: - Changed menubar titles to more conventional
#             File,Screen,Modes,Options,Help
# later   : - Got rid of the Edit menu.
#
#************************************************************
proc CreateMenu { w } {
    global param
    # Make unset colors white.
    foreach col [list color-menufg color-menubg color-menuabg] {
	if { ![info exists param($col)] } {
	    puts "setting param($col) to white"
	    set param($col) \#ffffff
	}
    }
    # Menu/button attributes
    set mattr [list -activebackground $param(color-menuabg) \
		   -highlightbackground $param(color-ctlbg) \
		   -background $param(color-menubg) \
		   -foreground $param(color-menufg)]
    set battr [list -activebackground $param(color-menuabg) \
		   -background $param(color-menubg) \
		   -foreground $param(color-menufg) ]
    # Menu bar
    set menubar [list File Screen Options Modes Help]
    set mf0 [frame $w]
    set mf [frame $mf0.top -bg $param(color-menubg)]
    foreach i $menubar {
	set pathnm [string tolower $i]
	eval { menubutton $mf.$pathnm -menu $mf.$pathnm.m -text "$i" } $mattr
	menu $mf.$pathnm.m -tearoff no
    }
    # Fill in skeleton details for each item
    # ---- FILE MENU -----
    set b $mf.file
    eval {$b.m add command -label {Bookmark file..} -command {BkmkFileDlg}} $battr 
    eval {$b.m add command -label {Print...} -command {ShowPrintDlg}} $battr
    eval {$b.m add command -label {Quit} -command {ExitProgram}} $battr
    # ----- SCREEN MENU ----
    set b $mf.screen
    eval {$b.m add command -label {Graph symbols..} -command {ShowSymDlg}} $battr
    eval {$b.m add cascade -label {Controls size} -menu $b.m.sub_ctl} $battr
    set m2 [menu $b.m.sub_ctl -tearoff no]
    eval {$m2 add radio -label big -variable param(ctlsize) -command SetControlSize} $battr
    eval {$m2 add radio -label small -variable param(ctlsize) -command SetControlSize} $battr
    eval {$m2 add radio -label tiny -variable param(ctlsize) -command SetControlSize} $battr
    eval {$b.m add cascade -label {Graph size} -menu  $b.m.sub_graph} $battr
    set m2 [menu $b.m.sub_graph -tearoff no]
    eval {$m2 add radio -label big -variable param(graphsize) -command SetGraphSize} $battr
    eval {$m2 add radio -label small -variable param(graphsize) -command SetGraphSize} $battr
    eval {$m2 add radio -label tiny -variable param(graphsize) -command SetGraphSize} $battr
    #------ MODES MENU ----
    set b $mf.modes
    eval {$b.m add checkbutton -label "Stop on EOF" -variable param(eofpolicy)} $battr
    eval {$b.m add checkbutton -label "Skip to data" -variable param(skiptonextdata) } $battr
    eval {$b.m add checkbutton -label "Auto-resize to data" -command ToggleAutoResize } $battr
    # ---- OPTIONS MENU ----
    set b $mf.options
    eval {$b.m add command -label {Set graph title..} -command {GraphTitleDlg}} $battr
    eval {$b.m add command -label {Select events..} -command {ShowKeyDlg}} $battr
    eval {$b.m add command -label {Bookmarks..} -command {BkmkList}} $battr

    # ---- HELP MENU -----
    set b $mf.help
    eval { $b.m add command -label {About} -command {AboutMsg} } $battr
    eval { $b.m add command -label {Index} -command {}         } $battr
    
    # Pack menubar items 1 at a time
    # Put the "help" menu on the right
    foreach i $menubar {
	set nm [string tolower $i]
	if { $nm != "help" } {
	    pack $mf.$nm -side left -anchor w
	} else {
	    pack $mf.$nm -side right -anchor w
	}
    }
    # Pack menu bar into parent frame
    pack $mf -side top -anchor nw -expand 1 -fill x
#    pack $mf0 -side top -anchor w -expand 1 -fill both
    pack $mf0 -side top -anchor w -expand 1 -fill x
    # Return name of menu's frame
    return $mf
}

#################
# AboutMsg
#
#    Tell about NLV

proc AboutMsg { } {
    set msg {
            NLV - NetLogger Visualization
            
            Written and maintained by Dan Gunter\n
            
            (c)1999 Lawrence Berkeley National Labs
            For more information, please refer to:

                 www-didc.lbl.gov/NetLogger/nlv/nlvmain.html 
   }  
   set title "About NLV"
   MessageBox $msg $title
   return
}
