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.
15 #include "BufferView.h"
16 #include "funcrequest.h"
18 #include "LaTeXFeatures.h"
20 #include "frontends/LyXView.h"
22 #include "support/lstrings.h"
25 using lyx::support::escape;
31 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
32 : InsetCommand(p), isLatex(buf.isLatex())
36 InsetRef::InsetRef(InsetRef const & ir)
37 : InsetCommand(ir), isLatex(ir.isLatex)
44 InsetCommandMailer("ref", *this).hideDialog();
49 InsetRef::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
53 // Eventually trigger dialog with button 3 not 1
54 if (cmd.button() == mouse_button::button3)
56 dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
58 InsetCommandMailer("ref", *this).showDialog(cmd.view());
62 return InsetCommand::priv_dispatch(cmd, idx, pos);
67 string 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);
75 temp += getContents();
78 && !getOptions().empty()) {
86 int InsetRef::latex(Buffer const &, ostream & os,
87 LatexRunParams const &) const
89 if (getOptions().empty())
90 os << escape(getCommand());
92 InsetCommandParams p(getCmdName(), getContents(), "");
93 os << escape(p.getCommand());
99 int InsetRef::ascii(Buffer const &, ostream & os, int) const
101 os << '[' << getContents() << ']';
106 int InsetRef::linuxdoc(Buffer const &, ostream & os) const
108 os << "<ref id=\"" << getContents()
109 << "\" name=\"" << getOptions() << "\" >";
114 int InsetRef::docbook(Buffer const &, ostream & os, bool) const
116 if (getOptions().empty()) {
117 os << "<xref linkend=\"" << getContents() << "\">";
119 os << "<link linkend=\"" << getContents()
120 << "\">" << getOptions() << "</link>";
127 void InsetRef::validate(LaTeXFeatures & features) const
129 if (getCmdName() == "vref" || getCmdName() == "vpageref")
130 features.require("varioref");
131 else if (getCmdName() == "prettyref")
132 features.require("prettyref");
133 else if (getCmdName() == "eqref")
134 features.require("amsmath");
138 InsetRef::type_info InsetRef::types[] = {
139 { "ref", N_("Standard"), N_("Ref: ")},
140 { "eqref", N_("Equation"), N_("EqRef: ")},
141 { "pageref", N_("Page Number"), N_("Page: ")},
142 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
143 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
144 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
149 int InsetRef::getType(string const & name)
151 for (int i = 0; !types[i].latex_name.empty(); ++i)
152 if (name == types[i].latex_name)
158 string const & InsetRef::getName(int type)
160 return types[type].latex_name;