2 * \file InsetMathRef.cpp
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.
13 #include "InsetMathRef.h"
15 #include "BufferView.h"
16 #include "LaTeXFeatures.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
23 #include "MathArray.h"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "OutputParams.h"
29 #include "insets/InsetCommand.h"
40 : CommandInset(from_ascii("ref"))
44 RefInset::RefInset(docstring const & data)
49 auto_ptr<InsetBase> RefInset::doClone() const
51 return auto_ptr<InsetBase>(new RefInset(*this));
55 void RefInset::infoize(odocstream & os) const
57 os << "Ref: " << cell(0);
61 void RefInset::doDispatch(Cursor & cur, FuncRequest & cmd)
64 case LFUN_INSET_MODIFY:
65 if (cmd.getArg(0) == "ref") {
67 if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
68 *this = *ar[0].nucleus()->asRefInset();
75 case LFUN_INSET_DIALOG_UPDATE: {
76 string const data = createDialogStr("ref");
77 cur.bv().updateDialog("ref", data);
81 case LFUN_MOUSE_RELEASE:
82 if (cmd.button() == mouse_button::button3) {
83 lyxerr << "trying to goto ref '" << to_utf8(asString(cell(0))) << "'" << endl;
84 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
87 if (cmd.button() == mouse_button::button1) {
88 // Eventually trigger dialog with button 3, not 1
89 string const data = createDialogStr("ref");
90 cur.bv().showInsetDialog("ref", data, this);
96 case LFUN_MOUSE_PRESS:
97 case LFUN_MOUSE_MOTION:
98 // eat other mouse commands
102 CommandInset::doDispatch(cur, cmd);
108 bool RefInset::getStatus(Cursor & cur, FuncRequest const & cmd,
109 FuncStatus & status) const
111 switch (cmd.action) {
113 case LFUN_INSET_MODIFY:
114 case LFUN_INSET_DIALOG_UPDATE:
115 case LFUN_MOUSE_RELEASE:
116 case LFUN_MOUSE_PRESS:
117 case LFUN_MOUSE_MOTION:
118 status.enabled(true);
121 return CommandInset::getStatus(cur, cmd, status);
126 docstring const RefInset::screenLabel() const
129 for (int i = 0; !types[i].latex_name.empty(); ++i) {
130 if (commandname() == types[i].latex_name) {
131 str = _(to_utf8(types[i].short_gui_name));
135 str += asString(cell(0));
137 //if (/* !isLatex && */ !cell(0).empty()) {
139 // str += asString(cell(1));
145 void RefInset::validate(LaTeXFeatures & features) const
147 if (commandname() == "vref" || commandname() == "vpageref")
148 features.require("varioref");
149 else if (commandname() == "prettyref")
150 features.require("prettyref");
154 int RefInset::docbook(Buffer const & buf, odocstream & os,
155 OutputParams const & runparams) const
157 if (cell(1).empty()) {
158 os << "<xref linkend=\""
159 << sgml::cleanID(buf, runparams, asString(cell(0)));
160 if (runparams.flavor == OutputParams::XML)
165 os << "<link linkend=\""
166 << sgml::cleanID(buf, runparams, asString(cell(0)))
176 string const RefInset::createDialogStr(string const & name) const
178 InsetCommandParams icp(to_ascii(commandname()));
179 icp["reference"] = asString(cell(0));
180 if (!cell(1).empty())
181 icp["name"] = asString(cell(1));
182 return InsetCommandMailer::params2string(name, icp);
186 RefInset::ref_type_info RefInset::types[] = {
187 { from_ascii("ref"), from_ascii(N_("Standard")), from_ascii(N_("Ref: "))},
188 { from_ascii("eqref"), from_ascii(N_("Equation")), from_ascii(N_("EqRef: "))},
189 { from_ascii("pageref"), from_ascii(N_("Page Number")), from_ascii(N_("Page: "))},
190 { from_ascii("vpageref"), from_ascii(N_("Textual Page Number")), from_ascii(N_("TextPage: "))},
191 { from_ascii("vref"), from_ascii(N_("Standard+Textual Page")), from_ascii(N_("Ref+Text: "))},
192 { from_ascii("prettyref"), from_ascii(N_("PrettyRef")), from_ascii(N_("FormatRef: "))},
193 { from_ascii(""), from_ascii(""), from_ascii("") }