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 "dispatchresult.h"
17 #include "funcrequest.h"
19 #include "LaTeXFeatures.h"
21 #include "frontends/LyXView.h"
23 #include "support/lstrings.h"
26 using lyx::support::escape;
32 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
33 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
37 InsetRef::InsetRef(InsetRef const & ir)
38 : InsetCommand(ir), isLatex(ir.isLatex)
43 InsetRef::priv_dispatch(BufferView & bv, 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 bv.owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
51 InsetCommandMailer("ref", *this).showDialog(&bv);
52 return DispatchResult(true, true);
55 return InsetCommand::priv_dispatch(bv, cmd);
60 string const InsetRef::getScreenLabel(Buffer const &) const
63 for (int i = 0; !types[i].latex_name.empty(); ++ i)
64 if (getCmdName() == types[i].latex_name) {
65 temp = _(types[i].short_gui_name);
68 temp += getContents();
71 && !getOptions().empty()) {
79 int InsetRef::latex(Buffer const &, ostream & os,
80 OutputParams const &) const
82 if (getOptions().empty())
83 os << escape(getCommand());
85 InsetCommandParams p(getCmdName(), getContents(), "");
86 os << escape(p.getCommand());
92 int InsetRef::plaintext(Buffer const &, ostream & os,
93 OutputParams const &) const
95 os << '[' << getContents() << ']';
100 int InsetRef::linuxdoc(Buffer const &, ostream & os,
101 OutputParams const &) const
103 os << "<ref id=\"" << getContents()
104 << "\" name=\"" << getOptions() << "\" >";
109 int InsetRef::docbook(Buffer const &, ostream & os,
110 OutputParams const &) const
112 if (getOptions().empty()) {
113 os << "<xref linkend=\"" << getContents() << "\">";
115 os << "<link linkend=\"" << getContents()
116 << "\">" << getOptions() << "</link>";
123 void InsetRef::validate(LaTeXFeatures & features) const
125 if (getCmdName() == "vref" || getCmdName() == "vpageref")
126 features.require("varioref");
127 else if (getCmdName() == "prettyref")
128 features.require("prettyref");
129 else if (getCmdName() == "eqref")
130 features.require("amsmath");
134 InsetRef::type_info InsetRef::types[] = {
135 { "ref", N_("Standard"), N_("Ref: ")},
136 { "eqref", N_("Equation"), N_("EqRef: ")},
137 { "pageref", N_("Page Number"), N_("Page: ")},
138 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
139 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
140 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
145 int InsetRef::getType(string const & name)
147 for (int i = 0; !types[i].latex_name.empty(); ++i)
148 if (name == types[i].latex_name)
154 string const & InsetRef::getName(int type)
156 return types[type].latex_name;