]> git.lyx.org Git - lyx.git/blob - src/mathed/math_tabularinset.C
Andreas' patch to prevent crash on click on previewd inset
[lyx.git] / src / mathed / math_tabularinset.C
1 /**
2  * \file math_tabularinset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "math_tabularinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
17
18 #include "support/lstrings.h"
19 #include "support/std_ostream.h"
20
21 #include <iterator>
22
23
24 using std::string;
25 using std::auto_ptr;
26
27
28 MathTabularInset::MathTabularInset(string const & name, int m, int n)
29         : MathGridInset(m, n), name_(name)
30 {}
31
32
33 MathTabularInset::MathTabularInset(string const & name, int m, int n,
34                 char valign, string const & halign)
35         : MathGridInset(m, n, valign, halign), name_(name)
36 {}
37
38
39 MathTabularInset::MathTabularInset(string const & name, char valign,
40                 string const & halign)
41         : MathGridInset(valign, halign), name_(name)
42 {}
43
44
45 auto_ptr<InsetBase> MathTabularInset::doClone() const
46 {
47         return auto_ptr<InsetBase>(new MathTabularInset(*this));
48 }
49
50
51 void MathTabularInset::metrics(MetricsInfo & mi, Dimension & dim) const
52 {
53         FontSetChanger dummy(mi.base, "textnormal");
54         MathGridInset::metrics(mi, dim);
55         dim.wid += 6;
56         dim_ = dim;
57 }
58
59
60 void MathTabularInset::draw(PainterInfo & pi, int x, int y) const
61 {
62         FontSetChanger dummy(pi.base, "textnormal");
63         MathGridInset::drawWithMargin(pi, x, y, 4, 2);
64 }
65
66
67 void MathTabularInset::write(WriteStream & os) const
68 {
69         if (os.fragile())
70                 os << "\\protect";
71         os << "\\begin{" << name_ << '}';
72
73         if (v_align_ == 't' || v_align_ == 'b')
74                 os << '[' << char(v_align_) << ']';
75         os << '{' << halign() << "}\n";
76
77         MathGridInset::write(os);
78
79         if (os.fragile())
80                 os << "\\protect";
81         os << "\\end{" << name_ << '}';
82         // adding a \n here is bad if the tabular is the last item
83         // in an \eqnarray...
84 }
85
86
87 void MathTabularInset::infoize(std::ostream & os) const
88 {
89         string name = name_;
90         name[0] = lyx::support::uppercase(name[0]);
91         os << name << ' ';
92 }
93
94
95 void MathTabularInset::normalize(NormalStream & os) const
96 {
97         os << '[' << name_ << ' ';
98         MathGridInset::normalize(os);
99         os << ']';
100 }
101
102
103 void MathTabularInset::maple(MapleStream & os) const
104 {
105         os << "array(";
106         MathGridInset::maple(os);
107         os << ')';
108 }