5 #include "funcrequest.h"
6 #include "formulabase.h"
7 #include "BufferView.h"
8 #include "frontends/LyXView.h"
9 #include "frontends/Painter.h"
10 #include "frontends/Dialogs.h"
13 #include "LaTeXFeatures.h"
15 #include "math_mathmlstream.h"
17 #include "math_parser.h"
18 #include "support/lstrings.h"
26 RefInset::RefInset(string const & data)
31 MathInset * RefInset::clone() const
33 return new RefInset(*this);
37 void RefInset::infoize(std::ostream & os) const
39 os << "Ref: " << cell(0);
44 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
47 case LFUN_MOUSE_RELEASE:
48 if (cmd.button() == mouse_button::button3) {
49 lyxerr << "trying to goto ref" << cell(0) << "\n";
50 cmd.view()->dispatch(FuncRequest(LFUN_REF_GOTO, asString(cell(0))));
53 if (cmd.button() == mouse_button::button1) {
54 // Eventually trigger dialog with button 3
57 data << "ref LatexCommand ";
58 WriteStream wsdata(data);
60 wsdata << "\n\\end_inset\n\n";
62 cmd.view()->owner()->getDialogs().
63 show("ref", data.str(), this);
67 case LFUN_MOUSE_PRESS:
68 case LFUN_MOUSE_MOTION:
69 // eat other mouse commands
72 return CommandInset::dispatch(cmd, idx, pos);
79 string RefInset::screenLabel() const
82 for (int i = 0; !types[i].latex_name.empty(); ++i)
83 if (name_ == types[i].latex_name) {
84 str = _(types[i].short_gui_name);
87 str += asString(cell(0));
89 //if (/* !isLatex && */ !cell(0).empty()) {
91 // str += asString(cell(1));
97 void RefInset::validate(LaTeXFeatures & features) const
99 if (name_ == "vref" || name_ == "vpageref")
100 features.require("varioref");
101 else if (name_ == "prettyref")
102 features.require("prettyref");
106 int RefInset::ascii(std::ostream & os, int) const
108 os << '[' << asString(cell(0)) << ']';
113 int RefInset::linuxdoc(std::ostream & os) const
115 os << "<ref id=\"" << asString(cell(0))
116 << "\" name=\"" << asString(cell(1)) << "\" >";
121 int RefInset::docbook(std::ostream & os, bool) const
123 if (cell(1).empty()) {
124 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
126 os << "<link linkend=\"" << asString(cell(0))
127 << "\">" << asString(cell(1)) << "</link>";
134 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
136 if (cmd.action != LFUN_INSET_APPLY || cmd.getArg(0) != "ref")
140 if (!string2RefInset(cmd.argument, ar))
143 *this = *ar[0].nucleus()->asRefInset();
145 // // This does not compile because updateInset expects
146 // // an Inset* and 'this' isn't.
147 // cmd.view()->updateInset(this, true);
152 bool string2RefInset(string const & str, MathArray & ar)
155 string body = split(str, name, ' ');
160 // body comes with a head "LatexCommand " and a
161 // tail "\nend_inset\n\n". Strip them off.
163 body = split(body, trimmed, ' ');
164 split(body, trimmed, '\n');
166 mathed_parse_cell(ar, trimmed);
170 return ar[0].nucleus()->asRefInset();
174 RefInset::ref_type_info RefInset::types[] = {
175 { "ref", N_("Standard"), N_("Ref: ")},
176 { "pageref", N_("Page Number"), N_("Page: ")},
177 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
178 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
179 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},