]> git.lyx.org Git - lyx.git/blob - src/mathed/math_boxinset.C
use stream-like syntax for LaTeX output
[lyx.git] / src / mathed / math_boxinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_boxinset.h"
6 #include "support/LOstream.h"
7 #include "LColor.h"
8 #include "debug.h"
9 #include "Painter.h"
10 #include "math_cursor.h"
11 #include "insets/insettext.h"
12
13
14 MathBoxInset::MathBoxInset(string const & name)
15         : MathDimInset(), name_(name), text_(new InsetText), buffer_(0)
16 {
17         lyxerr << "creating new " << name << endl;
18 }
19
20
21 MathBoxInset::MathBoxInset(MathBoxInset const & m)
22         :       MathDimInset(*this), name_(m.name_), text_(0), buffer_(m.buffer_)
23 {
24         if (!m.buffer_)
25                 cerr << "no buffer\n";
26         else
27                 text_ = static_cast<InsetText *>(m.text_->clone(*m.buffer_, false));
28 }
29
30
31 MathBoxInset::~MathBoxInset()
32 {
33         delete text_;
34 }
35
36
37 MathInset * MathBoxInset::clone() const
38 {
39         return new MathBoxInset(*this);
40 }
41
42
43 void MathBoxInset::write(MathWriteInfo & os) const
44 {
45         os << "\\" << name_ << "{" << cell(0) << "}";
46 }
47
48
49 void MathBoxInset::writeNormal(std::ostream & os) const
50 {
51         os << "[mbox ";
52         //text_->write(buffer(), os);
53         os << "] ";
54 }
55
56
57 void MathBoxInset::metrics(MathMetricsInfo const & st) const
58 {
59         size_ = st;
60         if (text_ && st.view && st.font) {
61                 ascent_  = text_->ascent(st.view, *st.font)  + 2;
62                 descent_ = text_->descent(st.view, *st.font) + 2;
63                 width_   = text_->width(st.view, *st.font)   + 4;
64         } else {
65                 ascent_  = 10;
66                 descent_ = 0;
67                 width_   = 10;
68         }
69 }
70
71
72 void MathBoxInset::draw(Painter & pain, int x, int y) const
73 {
74         float fx = x + 2;
75
76         if (text_ && size_.view && size_.font)
77                 text_->draw(size_.view, *(size_.font), y, fx, false);
78         if (mathcursor && mathcursor->isInside(this))
79                 pain.rectangle(x, y - ascent(), xcell(0).width(), height(),
80                         LColor::mathframe);
81 }