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 WriteStream wsdata(data);
59 wsdata << "\n\\end_inset\n\n";
61 cmd.view()->owner()->getDialogs().
62 show("ref", data.str(), this);
66 case LFUN_MOUSE_PRESS:
67 case LFUN_MOUSE_MOTION:
68 // eat other mouse commands
71 return CommandInset::dispatch(cmd, idx, pos);
78 string RefInset::screenLabel() const
81 for (int i = 0; !types[i].latex_name.empty(); ++i)
82 if (name_ == types[i].latex_name) {
83 str = _(types[i].short_gui_name);
86 str += asString(cell(0));
88 //if (/* !isLatex && */ !cell(0).empty()) {
90 // str += asString(cell(1));
96 void RefInset::validate(LaTeXFeatures & features) const
98 if (name_ == "vref" || name_ == "vpageref")
99 features.require("varioref");
100 else if (name_ == "prettyref")
101 features.require("prettyref");
105 int RefInset::ascii(std::ostream & os, int) const
107 os << '[' << asString(cell(0)) << ']';
112 int RefInset::linuxdoc(std::ostream & os) const
114 os << "<ref id=\"" << asString(cell(0))
115 << "\" name=\"" << asString(cell(1)) << "\" >";
120 int RefInset::docbook(std::ostream & os, bool) const
122 if (cell(1).empty()) {
123 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
125 os << "<link linkend=\"" << asString(cell(0))
126 << "\">" << asString(cell(1)) << "</link>";
133 dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
136 if (!string2RefInset(cmd.argument, ar))
139 *this = *ar[0].nucleus()->asRefInset();
144 bool string2RefInset(string const & str, MathArray & ar)
146 // str comes with a head "LatexCommand " and a
147 // tail "\nend_inset\n\n". Strip them off.
149 string body = split(str, trimmed, ' ');
150 split(body, trimmed, '\n');
152 mathed_parse_cell(ar, trimmed);
156 return ar[0].nucleus()->asRefInset();
160 RefInset::ref_type_info RefInset::types[] = {
161 { "ref", N_("Standard"), N_("Ref: ")},
162 { "pageref", N_("Page Number"), N_("Page: ")},
163 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
164 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
165 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},