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"
19 #include "LaTeXFeatures.h"
21 #include "OutputParams.h"
24 #include "support/lstrings.h"
29 using support::escape;
35 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
36 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
40 InsetRef::InsetRef(InsetRef const & ir)
41 : InsetCommand(ir), isLatex(ir.isLatex)
45 bool InsetRef::isCompatibleCommand(std::string const & s) {
46 //FIXME This is likely not the best way to handle this.
47 //But this stuff is hardcoded elsewhere already.
57 CommandInfo const * InsetRef::findInfo(std::string const & /* cmdName */)
59 static const char * const paramnames[] = {"name", "reference", ""};
60 static const bool isoptional[] = {true, false};
61 static const CommandInfo info = {2, paramnames, isoptional};
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 int InsetRef::textString(Buffer const & buf, odocstream & os,
151 OutputParams const & op) const
153 return plaintext(buf, os, op);
157 void InsetRef::validate(LaTeXFeatures & features) const
159 if (getCmdName() == "vref" || getCmdName() == "vpageref")
160 features.require("varioref");
161 else if (getCmdName() == "prettyref")
162 features.require("prettyref");
163 else if (getCmdName() == "eqref")
164 features.require("amsmath");
168 InsetRef::type_info InsetRef::types[] = {
169 { "ref", N_("Standard"), N_("Ref: ")},
170 { "eqref", N_("Equation"), N_("EqRef: ")},
171 { "pageref", N_("Page Number"), N_("Page: ")},
172 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
173 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
174 { "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
179 int InsetRef::getType(string const & name)
181 for (int i = 0; !types[i].latex_name.empty(); ++i)
182 if (name == types[i].latex_name)
188 string const & InsetRef::getName(int type)
190 return types[type].latex_name;