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(LCursor & cur, FuncRequest & cmd)
48 case LFUN_MOUSE_PRESS:
49 // Eventually trigger dialog with button 3 not 1
50 if (cmd.button() == mouse_button::button3)
51 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getParam("reference")));
53 InsetCommandMailer("ref", *this).showDialog(&cur.bv());
58 case LFUN_MOUSE_RELEASE:
62 return InsetCommand::doDispatch(cur, cmd);
67 docstring const InsetRef::getScreenLabel(Buffer const &) const
70 for (int i = 0; !types[i].latex_name.empty(); ++i) {
71 if (getCmdName() == types[i].latex_name) {
72 temp = _(types[i].short_gui_name);
76 temp += getParam("reference");
78 if (!isLatex && !getParam("name").empty()) {
80 temp += getParam("name");
86 int InsetRef::latex(Buffer const &, odocstream & os,
87 OutputParams const &) const
89 // Don't output p_["name"], this is only used in docbook
90 InsetCommandParams p(getCmdName());
91 p["reference"] = getParam("reference");
92 os << escape(p.getCommand());
97 int InsetRef::plaintext(Buffer const &, odocstream & os,
98 OutputParams const &) const
100 os << '[' << getParam("reference") << ']';
105 int InsetRef::docbook(Buffer const & buf, odocstream & os,
106 OutputParams const & runparams) const
108 docstring const & name = getParam("name");
110 if (runparams.flavor == OutputParams::XML) {
111 os << "<xref linkend=\""
112 << sgml::cleanID(buf, runparams, getParam("reference"))
115 os << "<xref linkend=\""
116 << sgml::cleanID(buf, runparams, getParam("reference"))
120 os << "<link linkend=\""
121 << sgml::cleanID(buf, runparams, getParam("reference"))
131 int InsetRef::textString(Buffer const & buf, odocstream & os,
132 OutputParams const & op) const
134 return plaintext(buf, os, op);
138 void InsetRef::validate(LaTeXFeatures & features) const
140 if (getCmdName() == "vref" || getCmdName() == "vpageref")
141 features.require("varioref");
142 else if (getCmdName() == "prettyref")
143 features.require("prettyref");
144 else if (getCmdName() == "eqref")
145 features.require("amsmath");
149 InsetRef::type_info InsetRef::types[] = {
150 { "ref", N_("Standard"), N_("Ref: ")},
151 { "eqref", N_("Equation"), N_("EqRef: ")},
152 { "pageref", N_("Page Number"), N_("Page: ")},
153 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
154 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
155 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
160 int InsetRef::getType(string const & name)
162 for (int i = 0; !types[i].latex_name.empty(); ++i)
163 if (name == types[i].latex_name)
169 string const & InsetRef::getName(int type)
171 return types[type].latex_name;