3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
16 #include "DispatchResult.h"
17 #include "FuncRequest.h"
18 #include "support/gettext.h"
19 #include "LaTeXFeatures.h"
21 #include "OutputParams.h"
24 #include "support/docstream.h"
25 #include "support/lstrings.h"
28 using namespace lyx::support;
33 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
34 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
38 InsetRef::InsetRef(InsetRef const & ir)
39 : InsetCommand(ir), isLatex(ir.isLatex)
43 bool InsetRef::isCompatibleCommand(string const & s) {
44 //FIXME This is likely not the best way to handle this.
45 //But this stuff is hardcoded elsewhere already.
55 ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
57 static ParamInfo param_info_;
58 if (param_info_.empty()) {
59 param_info_.add("name", ParamInfo::LATEX_OPTIONAL);
60 param_info_.add("reference", ParamInfo::LATEX_REQUIRED);
66 void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
69 case LFUN_MOUSE_RELEASE:
70 // Eventually trigger dialog with button 3 not 1
71 if (cmd.button() == mouse_button::button3)
72 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
73 getParam("reference")));
75 InsetCommand::doDispatch(cur, cmd);
79 InsetCommand::doDispatch(cur, cmd);
84 docstring const InsetRef::getScreenLabel(Buffer const &) const
87 for (int i = 0; !types[i].latex_name.empty(); ++i) {
88 if (getCmdName() == types[i].latex_name) {
89 temp = _(types[i].short_gui_name);
93 temp += getParam("reference");
95 if (!isLatex && !getParam("name").empty()) {
97 temp += getParam("name");
103 int InsetRef::latex(Buffer const &, odocstream & os,
104 OutputParams const &) const
106 // We don't want to output p_["name"], since that is only used
107 // in docbook. So we construct new params, without it, and use that.
108 InsetCommandParams p(REF_CODE, getCmdName());
109 p["reference"] = getParam("reference");
110 os << escape(p.getCommand());
115 int InsetRef::plaintext(Buffer const &, odocstream & os,
116 OutputParams const &) const
118 docstring const str = getParam("reference");
119 os << '[' << str << ']';
120 return 2 + str.size();
124 int InsetRef::docbook(Buffer const & buf, odocstream & os,
125 OutputParams const & runparams) const
127 docstring const & name = getParam("name");
129 if (runparams.flavor == OutputParams::XML) {
130 os << "<xref linkend=\""
131 << sgml::cleanID(buf, runparams, getParam("reference"))
134 os << "<xref linkend=\""
135 << sgml::cleanID(buf, runparams, getParam("reference"))
139 os << "<link linkend=\""
140 << sgml::cleanID(buf, runparams, getParam("reference"))
150 void InsetRef::textString(Buffer const & buf, odocstream & os) const
152 plaintext(buf, os, OutputParams(0));
156 void InsetRef::validate(LaTeXFeatures & features) const
158 if (getCmdName() == "vref" || getCmdName() == "vpageref")
159 features.require("varioref");
160 else if (getCmdName() == "prettyref")
161 features.require("prettyref");
162 else if (getCmdName() == "eqref")
163 features.require("amsmath");
167 InsetRef::type_info InsetRef::types[] = {
168 { "ref", N_("Standard"), N_("Ref: ")},
169 { "eqref", N_("Equation"), N_("EqRef: ")},
170 { "pageref", N_("Page Number"), N_("Page: ")},
171 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
172 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
173 { "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
178 int InsetRef::getType(string const & name)
180 for (int i = 0; !types[i].latex_name.empty(); ++i)
181 if (name == types[i].latex_name)
187 string const & InsetRef::getName(int type)
189 return types[type].latex_name;