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"
31 using support::escape;
34 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
35 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
39 InsetRef::InsetRef(InsetRef const & ir)
40 : InsetCommand(ir), isLatex(ir.isLatex)
44 bool InsetRef::isCompatibleCommand(std::string const & s) {
45 //FIXME This is likely not the best way to handle this.
46 //But this stuff is hardcoded elsewhere already.
56 CommandInfo const * InsetRef::findInfo(std::string const & /* cmdName */)
58 static const char * const paramnames[] = {"name", "reference", ""};
59 static const bool isoptional[] = {true, false};
60 static const CommandInfo info = {2, paramnames, isoptional};
65 void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
68 case LFUN_MOUSE_RELEASE:
69 // Eventually trigger dialog with button 3 not 1
70 if (cmd.button() == mouse_button::button3)
71 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
72 getParam("reference")));
74 InsetCommand::doDispatch(cur, cmd);
78 InsetCommand::doDispatch(cur, cmd);
83 docstring const InsetRef::getScreenLabel(Buffer const &) const
86 for (int i = 0; !types[i].latex_name.empty(); ++i) {
87 if (getCmdName() == types[i].latex_name) {
88 temp = _(types[i].short_gui_name);
92 temp += getParam("reference");
94 if (!isLatex && !getParam("name").empty()) {
96 temp += getParam("name");
102 int InsetRef::latex(Buffer const &, odocstream & os,
103 OutputParams const &) const
105 // We don't want to output p_["name"], since that is only used
106 // in docbook. So we construct new params, without it, and use that.
107 InsetCommandParams p(REF_CODE, getCmdName());
108 p["reference"] = getParam("reference");
109 os << escape(p.getCommand());
114 int InsetRef::plaintext(Buffer const &, odocstream & os,
115 OutputParams const &) const
117 docstring const str = getParam("reference");
118 os << '[' << str << ']';
119 return 2 + str.size();
123 int InsetRef::docbook(Buffer const & buf, odocstream & os,
124 OutputParams const & runparams) const
126 docstring const & name = getParam("name");
128 if (runparams.flavor == OutputParams::XML) {
129 os << "<xref linkend=\""
130 << sgml::cleanID(buf, runparams, getParam("reference"))
133 os << "<xref linkend=\""
134 << sgml::cleanID(buf, runparams, getParam("reference"))
138 os << "<link linkend=\""
139 << sgml::cleanID(buf, runparams, getParam("reference"))
149 int InsetRef::textString(Buffer const & buf, odocstream & os,
150 OutputParams const & op) const
152 return plaintext(buf, os, op);
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;