]> git.lyx.org Git - lyx.git/blob - src/mathed/math_boxinset.C
small step forward on the lenghty path to \mbox support
[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 void MathBoxInset::write(MathWriteInfo & os) const
42 {
43         os << "\\" << name_ << "{" << cell(0) << "}";
44 }
45
46
47 void MathBoxInset::writeNormal(std::ostream & os) const
48 {
49         os << "[mbox ";
50         //text_->write(buffer(), os);
51         os << "] ";
52 }
53
54
55 void MathBoxInset::metrics(MathMetricsInfo const & st) const
56 {
57         mi_ = st;
58         if (text_ && mi_.view) {
59                 ascent_  = text_->ascent(mi_.view, mi_.font)  + 2;
60                 descent_ = text_->descent(mi_.view, mi_.font) + 2;
61                 width_   = text_->width(mi_.view, mi_.font)   + 4;
62         } else {
63                 ascent_  = 10;
64                 descent_ = 0;
65                 width_   = 10;
66         }
67 }
68
69
70 void MathBoxInset::draw(Painter & pain, int x, int y) const
71 {
72         float fx = x + 2;
73         if (text_ && mi_.view)
74                 text_->draw(mi_.view, mi_.font, y, fx, false);
75         if (mathcursor && mathcursor->isInside(this))
76                 pain.rectangle(x, y - ascent(), xcell(0).width(), height(),
77                         LColor::mathframe);
78 }