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"
24 #include "frontends/LyXView.h"
26 #include "support/lstrings.h"
29 using lyx::support::escape;
35 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
36 : InsetCommand(p, "ref"), isLatex(buf.isLatex())
40 InsetRef::InsetRef(InsetRef const & ir)
41 : InsetCommand(ir), isLatex(ir.isLatex)
45 void InsetRef::doDispatch(LCursor & cur, FuncRequest & cmd)
48 case LFUN_MOUSE_PRESS:
49 // Eventually trigger dialog with button 3 not 1
50 if (cmd.button() == mouse_button::button3)
51 cur.bv().owner()->dispatch(FuncRequest(LFUN_LABEL_GOTO, getContents()));
53 InsetCommandMailer("ref", *this).showDialog(&cur.bv());
56 case LFUN_MOUSE_RELEASE:
60 return InsetCommand::doDispatch(cur, cmd);
65 string const InsetRef::getScreenLabel(Buffer const &) const
68 for (int i = 0; !types[i].latex_name.empty(); ++i) {
69 if (getCmdName() == types[i].latex_name) {
70 temp = _(types[i].short_gui_name);
74 temp += getContents();
76 if (!isLatex && !getOptions().empty()) {
84 int InsetRef::latex(Buffer const &, ostream & os,
85 OutputParams const &) const
87 if (getOptions().empty())
88 os << escape(getCommand());
90 InsetCommandParams p(getCmdName(), getContents(), "");
91 os << escape(p.getCommand());
97 int InsetRef::plaintext(Buffer const &, ostream & os,
98 OutputParams const &) const
100 os << '[' << getContents() << ']';
105 int InsetRef::linuxdoc(Buffer const & buf, ostream & os,
106 OutputParams const & runparams) const
108 os << "<ref id=\"" << sgml::cleanID(buf, runparams, getContents())
109 << "\" name=\"" << getOptions() << "\" >";
114 int InsetRef::docbook(Buffer const & buf, ostream & os,
115 OutputParams const & runparams) const
117 if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
118 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" />";
119 } else if (getOptions().empty()) {
120 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\">";
122 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, getContents())
123 << "\">" << getOptions() << "</link>";
130 void InsetRef::validate(LaTeXFeatures & features) const
132 if (getCmdName() == "vref" || getCmdName() == "vpageref")
133 features.require("varioref");
134 else if (getCmdName() == "prettyref")
135 features.require("prettyref");
136 else if (getCmdName() == "eqref")
137 features.require("amsmath");
141 InsetRef::type_info InsetRef::types[] = {
142 { "ref", N_("Standard"), N_("Ref: ")},
143 { "eqref", N_("Equation"), N_("EqRef: ")},
144 { "pageref", N_("Page Number"), N_("Page: ")},
145 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
146 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
147 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
152 int InsetRef::getType(string const & name)
154 for (int i = 0; !types[i].latex_name.empty(); ++i)
155 if (name == types[i].latex_name)
161 string const & InsetRef::getName(int type)
163 return types[type].latex_name;