1 /**
2  * \file InsetMathTabular.cpp
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 "InsetMathTabular.h"
14 
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "MathStream.h"
18 
19 #include "MetricsInfo.h"
20 
21 #include "support/lstrings.h"
22 
23 #include <ostream>
24 
25 namespace lyx {
26 
InsetMathTabular(Buffer * buf,docstring const & name,int m,int n)27 InsetMathTabular::InsetMathTabular(Buffer * buf, docstring const & name, int m,
28 		int n)
29 	: InsetMathGrid(buf, m, n), name_(name)
30 {}
31 
32 
InsetMathTabular(Buffer * buf,docstring const & name,int m,int n,char valign,docstring const & halign)33 InsetMathTabular::InsetMathTabular(Buffer * buf, docstring const & name, int m,
34 		int n, char valign, docstring const & halign)
35 	: InsetMathGrid(buf, m, n, valign, halign), name_(name)
36 {}
37 
38 
39 
clone() const40 Inset * InsetMathTabular::clone() const
41 {
42 	return new InsetMathTabular(*this);
43 }
44 
45 
metrics(MetricsInfo & mi,Dimension & dim) const46 void InsetMathTabular::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48 	Changer dummy = mi.base.changeFontSet("textnormal");
49 	InsetMathGrid::metrics(mi, dim);
50 }
51 
52 
draw(PainterInfo & pi,int x,int y) const53 void InsetMathTabular::draw(PainterInfo & pi, int x, int y) const
54 {
55 	Changer dummy = pi.base.changeFontSet("textnormal");
56 	InsetMathGrid::draw(pi, x, y);
57 }
58 
59 
write(WriteStream & os) const60 void InsetMathTabular::write(WriteStream & os) const
61 {
62 	ModeSpecifier specifier(os, TEXT_MODE);
63 
64 	if (os.fragile())
65 		os << "\\protect";
66 	os << "\\begin{" << name_ << '}';
67 	bool open = os.startOuterRow();
68 
69 	char const v = verticalAlignment();
70 	if (v == 't' || v == 'b')
71 		os << '[' << v << ']';
72 	os << '{' << horizontalAlignments() << "}\n";
73 
74 	InsetMathGrid::write(os);
75 
76 	if (os.fragile())
77 		os << "\\protect";
78 	os << "\\end{" << name_ << '}';
79 	if (open)
80 		os.startOuterRow();
81 	// adding a \n here is bad if the tabular is the last item
82 	// in an \eqnarray...
83 }
84 
85 
infoize(odocstream & os) const86 void InsetMathTabular::infoize(odocstream & os) const
87 {
88 	docstring name = name_;
89 	name[0] = support::uppercase(name[0]);
90 	os << name << ' ';
91 }
92 
93 
normalize(NormalStream & os) const94 void InsetMathTabular::normalize(NormalStream & os) const
95 {
96 	os << '[' << name_ << ' ';
97 	InsetMathGrid::normalize(os);
98 	os << ']';
99 }
100 
101 
maple(MapleStream & os) const102 void InsetMathTabular::maple(MapleStream & os) const
103 {
104 	os << "array(";
105 	InsetMathGrid::maple(os);
106 	os << ')';
107 }
108 
109 
110 } // namespace lyx
111