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"
24 #include "MathFactory.h"
25 #include "MathSupport.h"
26 #include "outputparams.h"
30 using lyx::odocstream;
42 RefInset::RefInset(string const & data)
47 auto_ptr<InsetBase> RefInset::doClone() const
49 return auto_ptr<InsetBase>(new RefInset(*this));
53 void RefInset::infoize(std::ostream & os) const
55 os << "Ref: " << cell(0);
59 void RefInset::doDispatch(LCursor & cur, FuncRequest & cmd)
62 case LFUN_INSET_MODIFY:
63 if (cmd.getArg(0) == "ref") {
65 if (createInsetMath_fromDialogStr(lyx::to_utf8(cmd.argument()), ar)) {
66 *this = *ar[0].nucleus()->asRefInset();
73 case LFUN_INSET_DIALOG_UPDATE: {
74 string const data = createDialogStr("ref");
75 cur.bv().updateDialog("ref", data);
79 case LFUN_MOUSE_RELEASE:
80 if (cmd.button() == mouse_button::button3) {
81 lyxerr << "trying to goto ref '" << asString(cell(0)) << "'" << endl;
82 cur.bv().dispatch(FuncRequest(LFUN_LABEL_GOTO, asString(cell(0))));
85 if (cmd.button() == mouse_button::button1) {
86 // Eventually trigger dialog with button 3, not 1
87 string const data = createDialogStr("ref");
88 cur.bv().showInsetDialog("ref", data, this);
94 case LFUN_MOUSE_PRESS:
95 case LFUN_MOUSE_MOTION:
96 // eat other mouse commands
100 CommandInset::doDispatch(cur, cmd);
106 bool RefInset::getStatus(LCursor & cur, FuncRequest const & cmd,
107 FuncStatus & status) const
109 switch (cmd.action) {
111 case LFUN_INSET_MODIFY:
112 case LFUN_INSET_DIALOG_UPDATE:
113 case LFUN_MOUSE_RELEASE:
114 case LFUN_MOUSE_PRESS:
115 case LFUN_MOUSE_MOTION:
116 status.enabled(true);
119 return CommandInset::getStatus(cur, cmd, status);
124 docstring const RefInset::screenLabel() const
127 for (int i = 0; !types[i].latex_name.empty(); ++i)
128 if (commandname() == types[i].latex_name) {
129 str = _(types[i].short_gui_name);
133 str += lyx::from_utf8(asString(cell(0)));
135 //if (/* !isLatex && */ !cell(0).empty()) {
137 // str += asString(cell(1));
143 void RefInset::validate(LaTeXFeatures & features) const
145 if (commandname() == "vref" || commandname() == "vpageref")
146 features.require("varioref");
147 else if (commandname() == "prettyref")
148 features.require("prettyref");
152 int RefInset::plaintext(lyx::odocstream & os, OutputParams const &) const
155 os << '[' << lyx::from_utf8(asString(cell(0))) << ']';
160 int RefInset::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const
162 if (cell(1).empty()) {
164 os << "<xref linkend=\""
165 << lyx::from_ascii(sgml::cleanID(buf, runparams, asString(cell(0))));
166 if (runparams.flavor == OutputParams::XML)
172 os << "<link linkend=\""
173 << lyx::from_ascii(sgml::cleanID(buf, runparams, asString(cell(0))))
175 << lyx::from_ascii(asString(cell(1)))
183 RefInset::ref_type_info RefInset::types[] = {
184 { "ref", N_("Standard"), N_("Ref: ")},
185 { "eqref", N_("Equation"), N_("EqRef: ")},
186 { "pageref", N_("Page Number"), N_("Page: ")},
187 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
188 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
189 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},