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