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 CommandInfo const * InsetRef::findInfo(string const & /* cmdName */)
57 static const char * const paramnames[] = {"name", "reference", ""};
58 static const bool isoptional[] = {true, false};
59 static const CommandInfo info = {2, paramnames, isoptional};
64 void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
67 case LFUN_MOUSE_RELEASE:
68 // Eventually trigger dialog with button 3 not 1
69 if (cmd.button() == mouse_button::button3)
70 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
71 getParam("reference")));
73 InsetCommand::doDispatch(cur, cmd);
77 InsetCommand::doDispatch(cur, cmd);
82 docstring const InsetRef::getScreenLabel(Buffer const &) const
85 for (int i = 0; !types[i].latex_name.empty(); ++i) {
86 if (getCmdName() == types[i].latex_name) {
87 temp = _(types[i].short_gui_name);
91 temp += getParam("reference");
93 if (!isLatex && !getParam("name").empty()) {
95 temp += getParam("name");
101 int InsetRef::latex(Buffer const &, odocstream & os,
102 OutputParams const &) const
104 // We don't want to output p_["name"], since that is only used
105 // in docbook. So we construct new params, without it, and use that.
106 InsetCommandParams p(REF_CODE, getCmdName());
107 p["reference"] = getParam("reference");
108 os << escape(p.getCommand());
113 int InsetRef::plaintext(Buffer const &, odocstream & os,
114 OutputParams const &) const
116 docstring const str = getParam("reference");
117 os << '[' << str << ']';
118 return 2 + str.size();
122 int InsetRef::docbook(Buffer const & buf, odocstream & os,
123 OutputParams const & runparams) const
125 docstring const & name = getParam("name");
127 if (runparams.flavor == OutputParams::XML) {
128 os << "<xref linkend=\""
129 << sgml::cleanID(buf, runparams, getParam("reference"))
132 os << "<xref linkend=\""
133 << sgml::cleanID(buf, runparams, getParam("reference"))
137 os << "<link linkend=\""
138 << sgml::cleanID(buf, runparams, getParam("reference"))
148 void InsetRef::textString(Buffer const & buf, odocstream & os) const
150 plaintext(buf, os, OutputParams(0));
154 void InsetRef::validate(LaTeXFeatures & features) const
156 if (getCmdName() == "vref" || getCmdName() == "vpageref")
157 features.require("varioref");
158 else if (getCmdName() == "prettyref")
159 features.require("prettyref");
160 else if (getCmdName() == "eqref")
161 features.require("amsmath");
165 InsetRef::type_info InsetRef::types[] = {
166 { "ref", N_("Standard"), N_("Ref: ")},
167 { "eqref", N_("Equation"), N_("EqRef: ")},
168 { "pageref", N_("Page Number"), N_("Page: ")},
169 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
170 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
171 { "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
176 int InsetRef::getType(string const & name)
178 for (int i = 0; !types[i].latex_name.empty(); ++i)
179 if (name == types[i].latex_name)
185 string const & InsetRef::getName(int type)
187 return types[type].latex_name;