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"
28 using lyx::support::escape;
34 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
35 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
39 InsetRef::InsetRef(InsetRef const & ir)
40 : InsetCommand(ir), isLatex(ir.isLatex)
44 void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd)
47 case LFUN_MOUSE_PRESS:
48 // Eventually trigger dialog with button 3 not 1
49 if (cmd.button() == mouse_button::button3)
50 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getContents()));
52 InsetCommandMailer("ref", *this).showDialog(&cur.bv());
57 case LFUN_MOUSE_RELEASE:
61 return InsetCommand::doDispatch(cur, cmd);
66 docstring const InsetRef::getScreenLabel(Buffer const &) const
69 for (int i = 0; !types[i].latex_name.empty(); ++i) {
70 if (getCmdName() == types[i].latex_name) {
71 temp = _(types[i].short_gui_name);
76 temp += lyx::from_utf8(getContents());
78 if (!isLatex && !getOptions().empty()) {
81 temp += lyx::from_utf8(getOptions());
87 int InsetRef::latex(Buffer const &, ostream & os,
88 OutputParams const &) const
90 if (getOptions().empty())
91 os << escape(getCommand());
93 InsetCommandParams p(getCmdName(), getContents(), "");
94 os << escape(p.getCommand());
100 int InsetRef::plaintext(Buffer const &, lyx::odocstream & os,
101 OutputParams const &) const
104 os << '[' << lyx::from_utf8(getContents()) << ']';
109 int InsetRef::docbook(Buffer const & buf, ostream & os,
110 OutputParams const & runparams) const
112 if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
113 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" />";
114 } else if (getOptions().empty()) {
115 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\">";
117 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, getContents())
118 << "\">" << getOptions() << "</link>";
125 int InsetRef::textString(Buffer const & buf, lyx::odocstream & os,
126 OutputParams const & op) const
128 return plaintext(buf, os, op);
132 void InsetRef::validate(LaTeXFeatures & features) const
134 if (getCmdName() == "vref" || getCmdName() == "vpageref")
135 features.require("varioref");
136 else if (getCmdName() == "prettyref")
137 features.require("prettyref");
138 else if (getCmdName() == "eqref")
139 features.require("amsmath");
143 InsetRef::type_info InsetRef::types[] = {
144 { "ref", N_("Standard"), N_("Ref: ")},
145 { "eqref", N_("Equation"), N_("EqRef: ")},
146 { "pageref", N_("Page Number"), N_("Page: ")},
147 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
148 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
149 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
154 int InsetRef::getType(string const & name)
156 for (int i = 0; !types[i].latex_name.empty(); ++i)
157 if (name == types[i].latex_name)
163 string const & InsetRef::getName(int type)
165 return types[type].latex_name;