7 #include "math_boxinset.h"
8 #include "math_support.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
12 #include "math_cursor.h"
13 #include "commandtags.h"
14 #include "formulabase.h"
15 #include "BufferView.h"
16 #include "frontends/LyXView.h"
17 #include "frontends/Painter.h"
18 #include "frontends/Dialogs.h"
21 #include "LaTeXFeatures.h"
24 ButtonInset::ButtonInset()
29 void ButtonInset::metrics(MathMetricsInfo & mi) const
31 MathFontSetChanger dummy(mi.base, "textnormal");
33 MathNestInset::metrics(mi);
34 width_ = xcell(0).width() + xcell(1).width() + 4;
35 ascent_ = max(xcell(0).ascent(), xcell(1).ascent());
36 descent_ = max(xcell(0).descent(), xcell(1).descent());
38 string s = screenLabel();
39 mathed_string_dim(mi.base.font,
40 s, ascent_, descent_, width_);
46 void ButtonInset::draw(MathPainterInfo & pi, int x, int y) const
48 MathFontSetChanger dummy(pi.base, "textnormal");
50 xcell(0).draw(pi, x, y);
51 xcell(1).draw(pi, x + xcell(0).width() + 2, y);
52 mathed_draw_framebox(pi, x, y, this);
54 pi.pain.buttonText(x + 2, y, screenLabel(),
60 ////////////////////////////////
62 CommandInset::CommandInset(string const & data)
66 string::size_type idx0 = data.find("|++|");
67 name_ = data.substr(0, idx0);
68 if (idx0 == string::npos)
71 string::size_type idx1 = data.find("|++|", idx0);
72 cell(0) = asArray(data.substr(idx0, idx1 - idx0));
73 if (idx1 == string::npos)
75 cell(1) = asArray(data.substr(idx1 + 4));
79 MathInset * CommandInset::clone() const
81 return new CommandInset(*this);
85 void CommandInset::write(WriteStream & os) const
89 os << "[" << cell(1) << "]";
90 os << "{" << cell(0) << "}";
94 string CommandInset::screenLabel() const
99 ////////////////////////////////
102 : CommandInset("ref")
106 RefInset::RefInset(string const & data)
111 MathInset * RefInset::clone() const
113 return new RefInset(*this);
117 void RefInset::infoize(std::ostream & os) const
119 os << "Ref: " << cell(0);
123 int RefInset::dispatch(string const & cmd, idx_type, pos_type)
125 if (cmd == "mouse 3") {
126 cerr << "trying to goto ref" << cell(0) << "\n";
127 mathcursor->formula()->view()->owner()->getLyXFunc()->
128 dispatch(LFUN_REF_GOTO, asString(cell(0)));
129 return 1; // dispatched
132 if (cmd == "mouse 1") {
133 cerr << "trying to open ref" << cell(0) << "\n";
134 // Eventually trigger dialog with button 3 not 1
135 // mathcursor->formula()->view()->owner()->getDialogs()
137 return 1; // dispatched
140 return 0; // undispatched
144 string RefInset::screenLabel() const
147 for (int i = 0; !types[i].latex_name.empty(); ++i)
148 if (name_ == types[i].latex_name) {
149 str = _(types[i].short_gui_name);
152 str += asString(cell(0));
154 //if (/* !isLatex && */ !cell(0).empty()) {
156 // str += asString(cell(1));
162 void RefInset::validate(LaTeXFeatures & features) const
164 if (name_ == "vref" || name_ == "vpageref")
165 features.require("varioref");
166 else if (name_ == "prettyref")
167 features.require("prettyref");
171 int RefInset::ascii(std::ostream & os, int) const
173 os << "[" << asString(cell(0)) << "]";
178 int RefInset::linuxdoc(std::ostream & os) const
180 os << "<ref id=\"" << asString(cell(0))
181 << "\" name=\"" << asString(cell(1)) << "\" >";
186 int RefInset::docbook(std::ostream & os, bool) const
188 if (cell(1).empty()) {
189 os << "<xref linkend=\"" << asString(cell(0)) << "\">";
191 os << "<link linkend=\"" << asString(cell(0))
192 << "\">" << asString(cell(1)) << "</link>";
198 RefInset::type_info RefInset::types[] = {
199 { "ref", N_("Standard"), N_("Ref: ")},
200 { "pageref", N_("Page Number"), N_("Page: ")},
201 { "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
202 { "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
203 { "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
207 ///////////////////////////////////
210 MathBoxInset::MathBoxInset(string const & name)
211 : MathGridInset(1, 1), name_(name)
215 MathInset * MathBoxInset::clone() const
217 return new MathBoxInset(*this);
221 void MathBoxInset::write(WriteStream & os) const
223 os << "\\" << name_ << "{" << cell(0) << "}";
227 void MathBoxInset::normalize(NormalStream & os) const
229 os << '[' << name_ << ' ';
230 //text_->write(buffer(), os);
235 void MathBoxInset::rebreak()
237 //lyxerr << "trying to rebreak...\n";
241 void MathBoxInset::metrics(MathMetricsInfo & mi) const
243 MathFontSetChanger dummy(mi.base, "textnormal");
244 MathGridInset::metrics(mi);
248 void MathBoxInset::draw(MathPainterInfo & pi, int x, int y) const
250 MathFontSetChanger dummy(pi.base, "textnormal");
251 MathGridInset::draw(pi, x, y);
252 mathed_draw_framebox(pi, x, y, this);