]> git.lyx.org Git - lyx.git/blob - src/mathed/math_boxinset.C
Add string << operators for the other streams as well, and removes
[lyx.git] / src / mathed / math_boxinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_boxinset.h"
8 #include "support/LOstream.h"
9 #include "LColor.h"
10 #include "debug.h"
11 #include "Painter.h"
12 #include "math_cursor.h"
13 #include "insets/insettext.h"
14 #include "math_mathmlstream.h"
15 #include "math_streamstr.h"
16
17 MathBoxInset::MathBoxInset(string const & name)
18         : MathDimInset(), name_(name), text_(new InsetText), buffer_(0)
19 {}
20
21
22 MathBoxInset::MathBoxInset(MathBoxInset const & m)
23         :       MathDimInset(*this), name_(m.name_), text_(0), buffer_(m.buffer_)
24 {
25         if (!m.buffer_)
26                 lyxerr << "no buffer\n";
27         else
28                 text_ = static_cast<InsetText *>(m.text_->clone(*m.buffer_, false));
29 }
30
31
32 MathBoxInset::~MathBoxInset()
33 {
34         delete text_;
35 }
36
37
38 MathInset * MathBoxInset::clone() const
39 {
40         return new MathBoxInset(*this);
41 }
42
43
44 UpdatableInset * MathBoxInset::asHyperActiveInset() const
45 {
46         return text_;
47 }
48
49
50 void MathBoxInset::write(WriteStream & os) const
51 {
52         os << "\\" << name_ << "{" << cell(0) << "}";
53 }
54
55
56 void MathBoxInset::normalize(NormalStream & os) const
57 {
58         os << "[mbox ";
59         //text_->write(buffer(), os);
60         os << "] ";
61 }
62
63
64 void MathBoxInset::metrics(MathMetricsInfo const & st) const
65 {
66         mi_ = st;
67         if (text_ && mi_.view) {
68                 ascent_  = text_->ascent(mi_.view, mi_.font)  + 2;
69                 descent_ = text_->descent(mi_.view, mi_.font) + 2;
70                 width_   = text_->width(mi_.view, mi_.font)   + 4;
71         } else {
72                 ascent_  = 10;
73                 descent_ = 0;
74                 width_   = 10;
75         }
76 }
77
78
79 void MathBoxInset::draw(Painter & pain, int x, int y) const
80 {
81         float fx = x + 2;
82         if (text_ && mi_.view)
83                 text_->draw(mi_.view, mi_.font, y, fx, false);
84         if (mathcursor && mathcursor->isInside(this))
85                 pain.rectangle(x, y - ascent(), xcell(0).width(), height(),
86                         LColor::mathframe);
87 }
88
89
90 void MathBoxInset::edit(BufferView * bv, int x, int y, unsigned int button)
91 {
92         if (text_)
93                 text_->edit(bv, x, y, button);
94 }