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"
29 using 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(Cursor & cur, FuncRequest & cmd)
48 case LFUN_MOUSE_RELEASE:
49 // Eventually trigger dialog with button 3 not 1
50 if (cmd.button() == mouse_button::button3)
51 lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
52 getParam("reference")));
54 InsetCommand::doDispatch(cur, cmd);
58 InsetCommand::doDispatch(cur, cmd);
63 docstring const InsetRef::getScreenLabel(Buffer const &) const
66 for (int i = 0; !types[i].latex_name.empty(); ++i) {
67 if (getCmdName() == types[i].latex_name) {
68 temp = _(types[i].short_gui_name);
72 temp += getParam("reference");
74 if (!isLatex && !getParam("name").empty()) {
76 temp += getParam("name");
82 int InsetRef::latex(Buffer const &, odocstream & os,
83 OutputParams const &) const
85 // Don't output p_["name"], this is only used in docbook
86 InsetCommandParams p(getCmdName());
87 p["reference"] = getParam("reference");
88 os << escape(p.getCommand());
93 int InsetRef::plaintext(Buffer const &, odocstream & os,
94 OutputParams const &) const
96 docstring const str = getParam("reference");
97 os << '[' << str << ']';
98 return 2 + str.size();
102 int InsetRef::docbook(Buffer const & buf, odocstream & os,
103 OutputParams const & runparams) const
105 docstring const & name = getParam("name");
107 if (runparams.flavor == OutputParams::XML) {
108 os << "<xref linkend=\""
109 << sgml::cleanID(buf, runparams, getParam("reference"))
112 os << "<xref linkend=\""
113 << sgml::cleanID(buf, runparams, getParam("reference"))
117 os << "<link linkend=\""
118 << sgml::cleanID(buf, runparams, getParam("reference"))
128 int InsetRef::textString(Buffer const & buf, odocstream & os,
129 OutputParams const & op) const
131 return plaintext(buf, os, op);
135 void InsetRef::validate(LaTeXFeatures & features) const
137 if (getCmdName() == "vref" || getCmdName() == "vpageref")
138 features.require("varioref");
139 else if (getCmdName() == "prettyref")
140 features.require("prettyref");
141 else if (getCmdName() == "eqref")
142 features.require("amsmath");
146 InsetRef::type_info InsetRef::types[] = {
147 { "ref", N_("Standard"), N_("Ref: ")},
148 { "eqref", N_("Equation"), N_("EqRef: ")},
149 { "pageref", N_("Page Number"), N_("Page: ")},
150 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
151 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
152 { "prettyref", N_("PrettyRef"), N_("FormatRef: ")},
157 int InsetRef::getType(string const & name)
159 for (int i = 0; !types[i].latex_name.empty(); ++i)
160 if (name == types[i].latex_name)
166 string const & InsetRef::getName(int type)
168 return types[type].latex_name;