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"
21 #include "outputparams.h"
23 #include "frontends/LyXView.h"
25 #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::priv_dispatch(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 cur.bv().owner()->dispatch(FuncRequest(LFUN_REF_GOTO, getContents()));
52 InsetCommandMailer("ref", *this).showDialog(&cur.bv());
55 case LFUN_MOUSE_RELEASE:
59 return InsetCommand::priv_dispatch(cur, cmd);
64 string const InsetRef::getScreenLabel(Buffer const &) const
67 for (int i = 0; !types[i].latex_name.empty(); ++i) {
68 if (getCmdName() == types[i].latex_name) {
69 temp = _(types[i].short_gui_name);
73 temp += getContents();
75 if (!isLatex && !getOptions().empty()) {
83 int InsetRef::latex(Buffer const &, ostream & os,
84 OutputParams const &) const
86 if (getOptions().empty())
87 os << escape(getCommand());
89 InsetCommandParams p(getCmdName(), getContents(), "");
90 os << escape(p.getCommand());
96 int InsetRef::plaintext(Buffer const &, ostream & os,
97 OutputParams const &) const
99 os << '[' << getContents() << ']';
104 int InsetRef::linuxdoc(Buffer const &, ostream & os,
105 OutputParams const &) const
107 os << "<ref id=\"" << getContents()
108 << "\" name=\"" << getOptions() << "\" >";
113 int InsetRef::docbook(Buffer const &, ostream & os,
114 OutputParams const & runparams) const
116 if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
117 os << "<xref linkend=\"" << getContents() << "\" />";
118 } else if (getOptions().empty()) {
119 os << "<xref linkend=\"" << getContents() << "\">";
121 os << "<link linkend=\"" << getContents()
122 << "\">" << getOptions() << "</link>";
129 void InsetRef::validate(LaTeXFeatures & features) const
131 if (getCmdName() == "vref" || getCmdName() == "vpageref")
132 features.require("varioref");
133 else if (getCmdName() == "prettyref")
134 features.require("prettyref");
135 else if (getCmdName() == "eqref")
136 features.require("amsmath");
140 InsetRef::type_info InsetRef::types[] = {
141 { "ref", N_("Standard"), N_("Ref: ")},
142 { "eqref", N_("Equation"), N_("EqRef: ")},
143 { "pageref", N_("Page Number"), N_("Page: ")},
144 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
145 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
146 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
151 int InsetRef::getType(string const & name)
153 for (int i = 0; !types[i].latex_name.empty(); ++i)
154 if (name == types[i].latex_name)
160 string const & InsetRef::getName(int type)
162 return types[type].latex_name;