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 "dispatchresult.h"
17 #include "funcrequest.h"
19 #include "LaTeXFeatures.h"
21 #include "outputparams.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::doDispatch(LCursor & cur, FuncRequest & cmd)
46 case LFUN_MOUSE_PRESS:
47 // Eventually trigger dialog with button 3 not 1
48 if (cmd.button() == mouse_button::button3)
49 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO, getContents()));
51 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) {
71 temp = lyx::to_utf8(_(types[i].short_gui_name));
75 temp += getContents();
77 if (!isLatex && !getOptions().empty()) {
85 int InsetRef::latex(Buffer const &, ostream & os,
86 OutputParams const &) const
88 if (getOptions().empty())
89 os << escape(getCommand());
91 InsetCommandParams p(getCmdName(), getContents(), "");
92 os << escape(p.getCommand());
98 int InsetRef::plaintext(Buffer const &, ostream & os,
99 OutputParams const &) const
101 os << '[' << getContents() << ']';
106 int InsetRef::docbook(Buffer const & buf, ostream & os,
107 OutputParams const & runparams) const
109 if (getOptions().empty() && runparams.flavor == OutputParams::XML) {
110 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\" />";
111 } else if (getOptions().empty()) {
112 os << "<xref linkend=\"" << sgml::cleanID(buf, runparams, getContents()) << "\">";
114 os << "<link linkend=\"" << sgml::cleanID(buf, runparams, getContents())
115 << "\">" << getOptions() << "</link>";
122 int InsetRef::textString(Buffer const & buf, ostream & os,
123 OutputParams const & op) const
125 return plaintext(buf, os, op);
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;