]> git.lyx.org Git - lyx.git/blob - src/mathed/math_boxinset.C
don't #include too much stuff in .h
[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 #include "math_mathmlstream.h"
13
14
15 MathBoxInset::MathBoxInset(string const & name)
16         : MathDimInset(), name_(name), text_(new InsetText), buffer_(0)
17 {}
18
19
20 MathBoxInset::MathBoxInset(MathBoxInset const & m)
21         :       MathDimInset(*this), name_(m.name_), text_(0), buffer_(m.buffer_)
22 {
23         if (!m.buffer_)
24                 lyxerr << "no buffer\n";
25         else
26                 text_ = static_cast<InsetText *>(m.text_->clone(*m.buffer_, false));
27 }
28
29
30 MathBoxInset::~MathBoxInset()
31 {
32         delete text_;
33 }
34
35
36 MathInset * MathBoxInset::clone() const
37 {
38         return new MathBoxInset(*this);
39 }
40
41
42 UpdatableInset * MathBoxInset::asHyperActiveInset() const
43 {
44         return text_;
45 }
46
47
48 void MathBoxInset::write(MathWriteInfo & os) const
49 {
50         os << "\\" << name_.c_str() << "{" << cell(0) << "}";
51 }
52
53
54 void MathBoxInset::writeNormal(NormalStream & os) const
55 {
56         os << "[mbox ";
57         //text_->write(buffer(), os);
58         os << "] ";
59 }
60
61
62 void MathBoxInset::metrics(MathMetricsInfo const & st) const
63 {
64         mi_ = st;
65         if (text_ && mi_.view) {
66                 ascent_  = text_->ascent(mi_.view, mi_.font)  + 2;
67                 descent_ = text_->descent(mi_.view, mi_.font) + 2;
68                 width_   = text_->width(mi_.view, mi_.font)   + 4;
69         } else {
70                 ascent_  = 10;
71                 descent_ = 0;
72                 width_   = 10;
73         }
74 }
75
76
77 void MathBoxInset::draw(Painter & pain, int x, int y) const
78 {
79         float fx = x + 2;
80         if (text_ && mi_.view)
81                 text_->draw(mi_.view, mi_.font, y, fx, false);
82         if (mathcursor && mathcursor->isInside(this))
83                 pain.rectangle(x, y - ascent(), xcell(0).width(), height(),
84                         LColor::mathframe);
85 }
86
87
88 void MathBoxInset::edit(BufferView * bv, int x, int y, unsigned int button)
89 {
90         if (text_)
91                 text_->edit(bv, x, y, button);
92 }