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/docstream.h"
25 #include "support/lstrings.h"
30 using support::escape;
36 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
37 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
41 InsetRef::InsetRef(InsetRef const & ir)
42 : InsetCommand(ir), isLatex(ir.isLatex)
46 bool InsetRef::isCompatibleCommand(std::string const & s) {
47 //FIXME This is likely not the best way to handle this.
48 //But this stuff is hardcoded elsewhere already.
58 CommandInfo const * InsetRef::findInfo(std::string const & /* cmdName */)
60 static const char * const paramnames[] = {"name", "reference", ""};
61 static const bool isoptional[] = {true, false};
62 static const CommandInfo info = {2, paramnames, isoptional};
67 void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
70 case LFUN_MOUSE_RELEASE:
71 // Eventually trigger dialog with button 3 not 1
72 if (cmd.button() == mouse_button::button3)
73 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
74 getParam("reference")));
76 InsetCommand::doDispatch(cur, cmd);
80 InsetCommand::doDispatch(cur, cmd);
85 docstring const InsetRef::getScreenLabel(Buffer const &) const
88 for (int i = 0; !types[i].latex_name.empty(); ++i) {
89 if (getCmdName() == types[i].latex_name) {
90 temp = _(types[i].short_gui_name);
94 temp += getParam("reference");
96 if (!isLatex && !getParam("name").empty()) {
98 temp += getParam("name");
104 int InsetRef::latex(Buffer const &, odocstream & os,
105 OutputParams const &) const
107 // We don't want to output p_["name"], since that is only used
108 // in docbook. So we construct new params, without it, and use that.
109 InsetCommandParams p(REF_CODE, getCmdName());
110 p["reference"] = getParam("reference");
111 os << escape(p.getCommand());
116 int InsetRef::plaintext(Buffer const &, odocstream & os,
117 OutputParams const &) const
119 docstring const str = getParam("reference");
120 os << '[' << str << ']';
121 return 2 + str.size();
125 int InsetRef::docbook(Buffer const & buf, odocstream & os,
126 OutputParams const & runparams) const
128 docstring const & name = getParam("name");
130 if (runparams.flavor == OutputParams::XML) {
131 os << "<xref linkend=\""
132 << sgml::cleanID(buf, runparams, getParam("reference"))
135 os << "<xref linkend=\""
136 << sgml::cleanID(buf, runparams, getParam("reference"))
140 os << "<link linkend=\""
141 << sgml::cleanID(buf, runparams, getParam("reference"))
151 int InsetRef::textString(Buffer const & buf, odocstream & os,
152 OutputParams const & op) const
154 return plaintext(buf, os, op);
158 void InsetRef::validate(LaTeXFeatures & features) const
160 if (getCmdName() == "vref" || getCmdName() == "vpageref")
161 features.require("varioref");
162 else if (getCmdName() == "prettyref")
163 features.require("prettyref");
164 else if (getCmdName() == "eqref")
165 features.require("amsmath");
169 InsetRef::type_info InsetRef::types[] = {
170 { "ref", N_("Standard"), N_("Ref: ")},
171 { "eqref", N_("Equation"), N_("EqRef: ")},
172 { "pageref", N_("Page Number"), N_("Page: ")},
173 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
174 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
175 { "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
180 int InsetRef::getType(string const & name)
182 for (int i = 0; !types[i].latex_name.empty(); ++i)
183 if (name == types[i].latex_name)
189 string const & InsetRef::getName(int type)
191 return types[type].latex_name;