From 5e0121cf5854a2a0039e6cb4970aeddb18bd4b23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 15 Mar 2008 08:43:16 +0000 Subject: [PATCH] cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23759 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/InsetMathArray.cpp | 13 +++----- src/mathed/InsetMathArray.h | 2 -- src/mathed/InsetMathGrid.cpp | 57 +++++++++++++-------------------- src/mathed/InsetMathGrid.h | 34 ++++++++++---------- src/mathed/InsetMathSplit.cpp | 4 +-- src/mathed/InsetMathTabular.cpp | 12 +++---- src/mathed/InsetMathTabular.h | 4 +-- src/mathed/MathParser.cpp | 6 ++-- 8 files changed, 55 insertions(+), 77 deletions(-) diff --git a/src/mathed/InsetMathArray.cpp b/src/mathed/InsetMathArray.cpp index 319e7ef55c..78e190e053 100644 --- a/src/mathed/InsetMathArray.cpp +++ b/src/mathed/InsetMathArray.cpp @@ -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); diff --git a/src/mathed/InsetMathArray.h b/src/mathed/InsetMathArray.h index f59d9e7304..f6901bed16 100644 --- a/src/mathed/InsetMathArray.h +++ b/src/mathed/InsetMathArray.h @@ -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); /// diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index ae009cff22..308e059fd7 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -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? diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index da309998d1..15aa437d8a 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -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 halign(char c, col_type col); - /// - char halign(col_type col) const; + void setHorizontalAlignment(char c, col_type col); /// - docstring halign() const; + char horizontalAlignment(col_type col) const; /// - void valign(char c); + docstring horizontalAlignments() const; + /// 't', 'b', or 'm' + void setVerticalAlignment(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_; /// cell info std::vector cellinfo_; +private: /// char v_align_; // add approp. type -private: - virtual Inset * clone() const; + /// + Inset * clone() const; }; - } // namespace lyx + #endif diff --git a/src/mathed/InsetMathSplit.cpp b/src/mathed/InsetMathSplit.cpp index 647f5cf737..01b5bcfe68 100644 --- a/src/mathed/InsetMathSplit.cpp +++ b/src/mathed/InsetMathSplit.cpp @@ -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((ncols() + 1)/2) << '}'; InsetMathGrid::write(ws); diff --git a/src/mathed/InsetMathTabular.cpp b/src/mathed/InsetMathTabular.cpp index bb4e5c4838..636c2c29f1 100644 --- a/src/mathed/InsetMathTabular.cpp +++ b/src/mathed/InsetMathTabular.cpp @@ -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); diff --git a/src/mathed/InsetMathTabular.h b/src/mathed/InsetMathTabular.h index d6c5bbac15..15a8809f92 100644 --- a/src/mathed/InsetMathTabular.h +++ b/src/mathed/InsetMathTabular.h @@ -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_; }; diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index d267021642..266272e84e 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -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); } -- 2.39.5