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 "BufferView.h"
17 #include "dispatchresult.h"
18 #include "funcrequest.h"
20 #include "LaTeXFeatures.h"
22 #include "frontends/LyXView.h"
24 #include "support/lstrings.h"
27 using lyx::support::escape;
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 void InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
46 case LFUN_MOUSE_PRESS:
47 // Eventually trigger dialog with button 3 not 1
48 if (cmd.button() == mouse_button::button3)
49 cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
51 InsetCommandMailer("ref", *this).showDialog(&cur.bv());
54 case LFUN_MOUSE_RELEASE:
58 return InsetCommand::priv_dispatch(cur, cmd);
63 string 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 += getContents();
74 if (!isLatex && !getOptions().empty()) {
82 int InsetRef::latex(Buffer const &, ostream & os,
83 OutputParams const &) const
85 if (getOptions().empty())
86 os << escape(getCommand());
88 InsetCommandParams p(getCmdName(), getContents(), "");
89 os << escape(p.getCommand());
95 int InsetRef::plaintext(Buffer const &, ostream & os,
96 OutputParams const &) const
98 os << '[' << getContents() << ']';
103 int InsetRef::linuxdoc(Buffer const &, ostream & os,
104 OutputParams const &) const
106 os << "<ref id=\"" << getContents()
107 << "\" name=\"" << getOptions() << "\" >";
112 int InsetRef::docbook(Buffer const &, ostream & os,
113 OutputParams const &) const
115 if (getOptions().empty()) {
116 os << "<xref linkend=\"" << getContents() << "\">";
118 os << "<link linkend=\"" << getContents()
119 << "\">" << getOptions() << "</link>";
126 void InsetRef::validate(LaTeXFeatures & features) const
128 if (getCmdName() == "vref" || getCmdName() == "vpageref")
129 features.require("varioref");
130 else if (getCmdName() == "prettyref")
131 features.require("prettyref");
132 else if (getCmdName() == "eqref")
133 features.require("amsmath");
137 InsetRef::type_info InsetRef::types[] = {
138 { "ref", N_("Standard"), N_("Ref: ")},
139 { "eqref", N_("Equation"), N_("EqRef: ")},
140 { "pageref", N_("Page Number"), N_("Page: ")},
141 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
142 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
143 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
148 int InsetRef::getType(string const & name)
150 for (int i = 0; !types[i].latex_name.empty(); ++i)
151 if (name == types[i].latex_name)
157 string const & InsetRef::getName(int type)
159 return types[type].latex_name;