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)
44 InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
47 case LFUN_MOUSE_PRESS:
48 // Eventually trigger dialog with button 3 not 1
49 if (cmd.button() == mouse_button::button3)
50 cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
52 InsetCommandMailer("ref", *this).showDialog(&cur.bv());
53 return DispatchResult(true, true);
56 return InsetCommand::priv_dispatch(cur, cmd);
61 string const InsetRef::getScreenLabel(Buffer const &) const
64 for (int i = 0; !types[i].latex_name.empty(); ++ i)
65 if (getCmdName() == types[i].latex_name) {
66 temp = _(types[i].short_gui_name);
69 temp += getContents();
72 && !getOptions().empty()) {
80 int InsetRef::latex(Buffer const &, ostream & os,
81 OutputParams const &) const
83 if (getOptions().empty())
84 os << escape(getCommand());
86 InsetCommandParams p(getCmdName(), getContents(), "");
87 os << escape(p.getCommand());
93 int InsetRef::plaintext(Buffer const &, ostream & os,
94 OutputParams const &) const
96 os << '[' << getContents() << ']';
101 int InsetRef::linuxdoc(Buffer const &, ostream & os,
102 OutputParams const &) const
104 os << "<ref id=\"" << getContents()
105 << "\" name=\"" << getOptions() << "\" >";
110 int InsetRef::docbook(Buffer const &, ostream & os,
111 OutputParams const &) const
113 if (getOptions().empty()) {
114 os << "<xref linkend=\"" << getContents() << "\">";
116 os << "<link linkend=\"" << getContents()
117 << "\">" << getOptions() << "</link>";
124 void InsetRef::validate(LaTeXFeatures & features) const
126 if (getCmdName() == "vref" || getCmdName() == "vpageref")
127 features.require("varioref");
128 else if (getCmdName() == "prettyref")
129 features.require("prettyref");
130 else if (getCmdName() == "eqref")
131 features.require("amsmath");
135 InsetRef::type_info InsetRef::types[] = {
136 { "ref", N_("Standard"), N_("Ref: ")},
137 { "eqref", N_("Equation"), N_("EqRef: ")},
138 { "pageref", N_("Page Number"), N_("Page: ")},
139 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
140 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
141 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
146 int InsetRef::getType(string const & name)
148 for (int i = 0; !types[i].latex_name.empty(); ++i)
149 if (name == types[i].latex_name)
155 string const & InsetRef::getName(int type)
157 return types[type].latex_name;