cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23759 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-03-15 08:43:16 +00:00
parent 5ffc0d19c1
commit 5e0121cf58
8 changed files with 55 additions and 77 deletions

View File

@ -39,12 +39,6 @@ InsetMathArray::InsetMathArray(docstring const & name, int m, int n,
{}
InsetMathArray::InsetMathArray(docstring const & name, char valign,
docstring const & halign)
: InsetMathGrid(valign, halign), name_(name)
{}
InsetMathArray::InsetMathArray(docstring const & name, docstring const & str)
: InsetMathGrid(1, 1), name_(name)
{
@ -105,9 +99,10 @@ void InsetMathArray::write(WriteStream & os) const
os << "\\protect";
os << "\\begin{" << name_ << '}';
if (v_align_ == 't' || v_align_ == 'b')
os << '[' << char(v_align_) << ']';
os << '{' << halign() << "}\n";
char const v = verticalAlignment();
if (v == 't' || v == 'b')
os << '[' << v << ']';
os << '{' << horizontalAlignments() << "}\n";
InsetMathGrid::write(os);

View File

@ -26,8 +26,6 @@ public:
///
InsetMathArray(docstring const &, int m, int n,
char valign, docstring const & halign);
///
InsetMathArray(docstring const &, char valign, docstring const & halign);
/// convenience constructor from whitespace/newline separated data
InsetMathArray(docstring const &, docstring const & str);
///

View File

@ -97,19 +97,6 @@ InsetMathGrid::ColInfo::ColInfo()
//////////////////////////////////////////////////////////////
InsetMathGrid::InsetMathGrid(char v, docstring const & h)
: InsetMathNest(guessColumns(h)),
rowinfo_(2),
colinfo_(guessColumns(h) + 1),
cellinfo_(1 * guessColumns(h))
{
setDefaults();
valign(v);
halign(h);
//lyxerr << "created grid with " << ncols() << " columns" << endl;
}
InsetMathGrid::InsetMathGrid()
: InsetMathNest(1),
rowinfo_(1 + 1),
@ -140,8 +127,8 @@ InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h
v_align_(v)
{
setDefaults();
valign(v);
halign(h);
setVerticalAlignment(v);
setHorizontalAlignments(h);
}
@ -171,7 +158,7 @@ void InsetMathGrid::setDefaults()
}
void InsetMathGrid::halign(docstring const & hh)
void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
{
col_type col = 0;
for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
@ -253,7 +240,7 @@ void InsetMathGrid::halign(docstring const & hh)
}
InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
{
col_type col = 0;
for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
@ -268,7 +255,7 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
}
void InsetMathGrid::halign(char h, col_type col)
void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
{
colinfo_[col].align_ = h;
if (!colinfo_[col].special_.empty()) {
@ -280,13 +267,13 @@ void InsetMathGrid::halign(char h, col_type col)
}
char InsetMathGrid::halign(col_type col) const
char InsetMathGrid::horizontalAlignment(col_type col) const
{
return colinfo_[col].align_;
}
docstring InsetMathGrid::halign() const
docstring InsetMathGrid::horizontalAlignments() const
{
docstring res;
for (col_type col = 0; col < ncols(); ++col) {
@ -302,13 +289,13 @@ docstring InsetMathGrid::halign() const
}
void InsetMathGrid::valign(char c)
void InsetMathGrid::setVerticalAlignment(char c)
{
v_align_ = c;
}
char InsetMathGrid::valign() const
char InsetMathGrid::verticalAlignment() const
{
return v_align_;
}
@ -1133,17 +1120,17 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
string s;
is >> s;
if (s == "valign-top")
valign('t');
setVerticalAlignment('t');
else if (s == "valign-middle")
valign('c');
setVerticalAlignment('c');
else if (s == "valign-bottom")
valign('b');
setVerticalAlignment('b');
else if (s == "align-left")
halign('l', cur.col());
setHorizontalAlignment('l', cur.col());
else if (s == "align-right")
halign('r', cur.col());
setHorizontalAlignment('r', cur.col());
else if (s == "align-center")
halign('c', cur.col());
setHorizontalAlignment('c', cur.col());
else if (s == "append-row")
for (int i = 0, n = extractInt(is); i < n; ++i)
addRow(cur.row());
@ -1398,12 +1385,14 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
}
status.setOnOff((s == "align-left" && halign(cur.col()) == 'l')
|| (s == "align-right" && halign(cur.col()) == 'r')
|| (s == "align-center" && halign(cur.col()) == 'c')
|| (s == "valign-top" && valign() == 't')
|| (s == "valign-bottom" && valign() == 'b')
|| (s == "valign-middle" && valign() == 'm'));
char const ha = horizontalAlignment(cur.col());
char const va = verticalAlignment();
status.setOnOff((s == "align-left" && ha == 'l')
|| (s == "align-right" && ha == 'r')
|| (s == "align-center" && ha == 'c')
|| (s == "valign-top" && va == 't')
|| (s == "valign-bottom" && va == 'b')
|| (s == "valign-middle" && va == 'm'));
#if 0
// FIXME: What did this code do?

View File

@ -91,10 +91,8 @@ public:
};
public:
/// sets nrows and ncols to 1
/// sets nrows and ncols to 1, vertical alingment to 'c'
InsetMathGrid();
/// constructor from columns description, creates one row
InsetMathGrid(char valign, docstring const & halign);
/// Note: columns first!
InsetMathGrid(col_type m, row_type n);
///
@ -113,18 +111,20 @@ public:
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
///
void drawT(TextPainter & pi, int x, int y) const;
/// extract number of columns from alignment string
static col_type guessColumns(docstring const & halign);
/// accepts some LaTeX column codes: p,m,!,@,M,<,>
void setHorizontalAlignments(docstring const & align);
///
void halign(docstring const & align);
void setHorizontalAlignment(char c, col_type col);
///
void halign(char c, col_type col);
char horizontalAlignment(col_type col) const;
///
char halign(col_type col) const;
docstring horizontalAlignments() const;
/// 't', 'b', or 'm'
void setVerticalAlignment(char c);
///
docstring halign() const;
///
void valign(char c);
///
char valign() const;
char verticalAlignment() const;
///
void vcrskip(Length const &, row_type row);
///
@ -219,7 +219,8 @@ public:
//void octave(OctaveStream &) const;
protected:
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
bool getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const;
@ -232,8 +233,6 @@ protected:
bool fragile) const;
/// returns proper 'end of column' code for LaTeX
virtual docstring eocString(col_type col, col_type lastcol) const;
/// extract number of columns from alignment string
col_type guessColumns(docstring const & halign) const;
/// splits cells and shifts right part to the next cell
void splitCell(Cursor & cur);
@ -245,13 +244,14 @@ protected:
std::vector<ColInfo> colinfo_;
/// cell info
std::vector<CellInfo> cellinfo_;
private:
///
char v_align_; // add approp. type
private:
virtual Inset * clone() const;
///
Inset * clone() const;
};
} // namespace lyx
#endif

View File

@ -90,8 +90,8 @@ void InsetMathSplit::write(WriteStream & ws) const
if (ws.fragile())
ws << "\\protect";
ws << "\\begin{" << name_ << '}';
if (name_ != "split" && valign() != 'c')
ws << '[' << valign() << ']';
if (name_ != "split" && verticalAlignment() != 'c')
ws << '[' << verticalAlignment() << ']';
if (name_ == "alignedat")
ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
InsetMathGrid::write(ws);

View File

@ -34,11 +34,6 @@ InsetMathTabular::InsetMathTabular(docstring const & name, int m, int n,
{}
InsetMathTabular::InsetMathTabular(docstring const & name, char valign,
docstring const & halign)
: InsetMathGrid(valign, halign), name_(name)
{}
Inset * InsetMathTabular::clone() const
{
@ -75,9 +70,10 @@ void InsetMathTabular::write(WriteStream & os) const
os << "\\protect";
os << "\\begin{" << name_ << '}';
if (v_align_ == 't' || v_align_ == 'b')
os << '[' << char(v_align_) << ']';
os << '{' << halign() << "}\n";
char const v = verticalAlignment();
if (v == 't' || v == 'b')
os << '[' << v << ']';
os << '{' << horizontalAlignments() << "}\n";
InsetMathGrid::write(os);

View File

@ -27,8 +27,6 @@ public:
InsetMathTabular(docstring const &, int m, int n,
char valign, docstring const & halign);
///
InsetMathTabular(docstring const &, char valign, docstring const & halign);
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
Dimension const dimension(BufferView const &) const;
@ -49,7 +47,7 @@ public:
void maple(MapleStream &) const;
private:
virtual Inset * clone() const;
Inset * clone() const;
///
docstring name_;
};

View File

@ -1299,14 +1299,16 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
if (name == "array" || name == "subarray") {
docstring const valign = parse_verbatim_option() + 'c';
docstring const halign = parse_verbatim_item();
cell->push_back(MathAtom(new InsetMathArray(name, (char)valign[0], halign)));
cell->push_back(MathAtom(new InsetMathArray(name,
InsetMathGrid::guessColumns(halign), 1, (char)valign[0], halign)));
parse2(cell->back(), FLAG_END, mode, false);
}
else if (name == "tabular") {
docstring const valign = parse_verbatim_option() + 'c';
docstring const halign = parse_verbatim_item();
cell->push_back(MathAtom(new InsetMathTabular(name, (char)valign[0], halign)));
cell->push_back(MathAtom(new InsetMathTabular(name,
InsetMathGrid::guessColumns(halign), 1, (char)valign[0], halign)));
parse2(cell->back(), FLAG_END, InsetMath::TEXT_MODE, false);
}