7 #include "math_matrixinset.h"
8 #include "math_rowst.h"
9 #include "math_xiter.h"
10 #include "support/LOstream.h"
14 extern int number_of_newlines;
16 MathMatrixInset::MathMatrixInset(int m, int n, short st)
17 : MathParInset(st, "array", LM_OT_MATRIX), nc_(m), nr_(0), ws_(m),
18 v_align_(0), h_align_(nc_, 'c')
22 row_.data_ = new MathedRowSt(nc_ + 1);
24 for (int j = 1; j < n; ++j)
27 if (nr_ == 1 && nc_ > 1) {
28 for (int j = 0; j < nc_ - 1; ++j)
29 it.insert('T', LM_TC_TAB);
32 row_.data_ = new MathedRowSt(nc_ + 1);
38 MathedInset * MathMatrixInset::Clone()
40 return new MathMatrixInset(*this);
44 void MathMatrixInset::SetAlign(char vv, string const & hh)
47 h_align_ = hh.substr(0, nc_); // usr just h_align = hh; perhaps
51 // Check the number of tabs and crs
52 void MathMatrixInset::setData(MathedArray const & a)
56 MathedIter it(&array);
72 it.insert(' ', LM_TC_TAB);
82 // Automatically inserts tabs around bops
83 // DISABLED because it's very easy to insert tabs
87 void MathMatrixInset::draw(Painter & pain, int x, int baseline)
89 MathParInset::draw(pain, x, baseline);
94 void MathMatrixInset::Metrics()
97 // lyxerr << " MIDA ";
99 row_.data_ = it.adjustVerticalSt();
103 for (MathedRowContainer::iterator it = row_.begin(); it; ++it)
104 for (int i = 0; i <= nc_; ++i)
108 MathParInset::Metrics();
110 MathedRowContainer::iterator cxrow = row_.begin();
111 if (nc_ <= 1 && cxrow.is_last()) {
112 cxrow->ascent(ascent);
113 cxrow->descent(descent);
116 // Vertical positions of each row
117 MathedRowContainer::iterator cprow = cxrow;
119 for ( ; cxrow; ++cxrow) {
120 for (int i = 0; i < nc_; ++i) {
121 if (cxrow == row_.begin() || ws_[i] < cxrow->getTab(i))
122 ws_[i] = cxrow->getTab(i);
123 if (cxrow.is_last() && ws_[i] == 0)
127 cxrow->setBaseline((cxrow == row_.begin()) ?
129 cxrow->ascent() + cprow->descent()
130 + MATH_ROWSEP + cprow->getBaseline());
131 h += cxrow->ascent() + cxrow->descent() + MATH_ROWSEP;
135 int const hl = Descent();
138 // Compute vertical align
141 ascent = row_.begin()->getBaseline();
147 ascent = (row_.begin().is_last()) ? h / 2 : h - hl;
150 descent = h - ascent + 2;
152 // Increase ws_[i] for 'R' columns (except the first one)
153 for (int i = 1; i < nc_; ++i)
154 if (h_align_[i] == 'R')
155 ws_[i] += 10 * df_width;
156 // Increase ws_[i] for 'C' column
157 if (h_align_[0] == 'C')
158 if (ws_[0] < 7 * workWidth / 8)
159 ws_[0] = 7 * workWidth / 8;
163 for (cxrow = row_.begin(); cxrow; ++cxrow) {
164 int rg = MATH_COLSEP;
166 for (int i = 0; i < nc_; ++i) {
168 if (cxrow->getTab(i) <= 0) {
169 cxrow->setTab(i, df_width);
172 switch (h_align_[i]) {
177 lf = (ws_[i] - cxrow->getTab(i))/2;
181 lf = ws_[i] - cxrow->getTab(i);
184 if (cxrow == row_.begin())
186 else if (cxrow.is_last())
187 lf = ws_[i] - cxrow->getTab(i);
189 lf = (ws_[i] - cxrow->getTab(i))/2;
192 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
193 cxrow->setTab(i, lf + rg);
194 rg = ws_[i] - ww + MATH_COLSEP;
195 if (cxrow == row_.begin())
196 width += ws_[i] + MATH_COLSEP;
198 cxrow->setBaseline(cxrow->getBaseline() - ascent);
203 void MathMatrixInset::Write(ostream & os, bool fragile)
205 if (GetType() == LM_OT_MATRIX) {
211 if (v_align_ == 't' || v_align_ == 'b') {
219 ++number_of_newlines;
221 MathParInset::Write(os, fragile);
222 if (GetType() == LM_OT_MATRIX){
229 ++number_of_newlines;