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 void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
48 case LFUN_MOUSE_RELEASE:
49 // Eventually trigger dialog with button 3 not 1
50 if (cmd.button() == mouse_button::button3)
51 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
52 getParam("reference")));
54 InsetCommand::doDispatch(cur, cmd);
58 InsetCommand::doDispatch(cur, cmd);
63 docstring const InsetRef::getScreenLabel(Buffer const &) const
66 for (int i = 0; !types[i].latex_name.empty(); ++i) {
67 if (getCmdName() == types[i].latex_name) {
68 temp = _(types[i].short_gui_name);
72 temp += getParam("reference");
74 if (!isLatex && !getParam("name").empty()) {
76 temp += getParam("name");
82 int InsetRef::latex(Buffer const &, odocstream & os,
83 OutputParams const &) const
85 // We don't want to output p_["name"], since that is only used
86 // in docbook. So we construct new params, without it, and use that.
87 InsetCommandParams p(REF_CODE, getCmdName());
88 p["reference"] = getParam("reference");
89 os << escape(p.getCommand());
94 int InsetRef::plaintext(Buffer const &, odocstream & os,
95 OutputParams const &) const
97 docstring const str = getParam("reference");
98 os << '[' << str << ']';
99 return 2 + str.size();
103 int InsetRef::docbook(Buffer const & buf, odocstream & os,
104 OutputParams const & runparams) const
106 docstring const & name = getParam("name");
108 if (runparams.flavor == OutputParams::XML) {
109 os << "<xref linkend=\""
110 << sgml::cleanID(buf, runparams, getParam("reference"))
113 os << "<xref linkend=\""
114 << sgml::cleanID(buf, runparams, getParam("reference"))
118 os << "<link linkend=\""
119 << sgml::cleanID(buf, runparams, getParam("reference"))
129 int InsetRef::textString(Buffer const & buf, odocstream & os,
130 OutputParams const & op) const
132 return plaintext(buf, os, op);
136 void InsetRef::validate(LaTeXFeatures & features) const
138 if (getCmdName() == "vref" || getCmdName() == "vpageref")
139 features.require("varioref");
140 else if (getCmdName() == "prettyref")
141 features.require("prettyref");
142 else if (getCmdName() == "eqref")
143 features.require("amsmath");
147 InsetRef::type_info InsetRef::types[] = {
148 { "ref", N_("Standard"), N_("Ref: ")},
149 { "eqref", N_("Equation"), N_("EqRef: ")},
150 { "pageref", N_("Page Number"), N_("Page: ")},
151 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
152 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
153 { "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
158 int InsetRef::getType(string const & name)
160 for (int i = 0; !types[i].latex_name.empty(); ++i)
161 if (name == types[i].latex_name)
167 string const & InsetRef::getName(int type)
169 return types[type].latex_name;