From c51c8a7257fe34cd30b0531f76e093b11c8193fe Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 31 Aug 2007 10:31:19 +0000 Subject: [PATCH] fix bug 4132: parse some more column specifiers git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@19941 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 2 +- src/ToolbarBackend.cpp | 2 +- src/mathed/InsetMath.h | 2 - src/mathed/InsetMathGrid.cpp | 110 +++++++++++++++++++++++++++++++---- src/mathed/InsetMathGrid.h | 5 ++ status.15x | 3 + 6 files changed, 110 insertions(+), 14 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e5de38c482..973d86e9ce 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -205,7 +205,7 @@ public: Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_) : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), filename(file), file_fully_loaded(false), inset(params), - timestamp_(0), checksum_(0), toc_backend(&parent) + toc_backend(&parent), timestamp_(0), checksum_(0) { inset.setAutoBreakRows(true); lyxvc.buffer(&parent); diff --git a/src/ToolbarBackend.cpp b/src/ToolbarBackend.cpp index c6f78f61ed..8baddc4f54 100644 --- a/src/ToolbarBackend.cpp +++ b/src/ToolbarBackend.cpp @@ -63,7 +63,7 @@ ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const & ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label) - : type_(type), name_(name), label_(label) + : type_(type), label_(label), name_(name) { } diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index eaf6a40af9..3226d13111 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -63,7 +63,6 @@ class InsetMathGrid; class InsetMathHull; class InsetMathMatrix; class InsetMathNest; -class InsetMathParbox; class InsetMathScript; class InsetMathString; class InsetMathSpace; @@ -132,7 +131,6 @@ public: virtual InsetMathMatrix const * asMatrixInset() const { return 0; } virtual InsetMathNest * asNestInset() { return 0; } virtual InsetMathNest const * asNestInset() const { return 0; } - virtual InsetMathParbox * asParboxInset() { return 0; } virtual InsetMathScript * asScriptInset() { return 0; } virtual InsetMathScript const * asScriptInset() const { return 0; } virtual InsetMathSpace * asSpaceInset() { return 0; } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index a3b680dd34..0a62b19cab 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -178,6 +178,7 @@ void InsetMathGrid::setDefaults() for (col_type col = 0; col < ncols(); ++col) { colinfo_[col].align_ = defaultColAlign(col); colinfo_[col].skip_ = defaultColSpace(col); + colinfo_[col].special_.clear(); } } @@ -189,13 +190,70 @@ void InsetMathGrid::halign(docstring const & hh) char_type c = *it; if (c == '|') { colinfo_[col].lines_++; + } else if ((c == 'p' || c == 'm' || c == 'b'|| + c == '!' || c == '@' || c == '>' || c == '<') && + it + 1 != hh.end() && *(it + 1) == '{') { + // @{decl.} and p{width} are standard LaTeX, the + // others are extensions by array.sty + bool const newcolumn = c == 'p' || c == 'm' || c == 'b'; + if (newcolumn) { + // this declares a new column + if (col >= ncols()) + // Only intercolumn stuff is allowed + // in the last dummy column + break; + colinfo_[col].align_ = 'l'; + } else { + // this is intercolumn stuff + if (colinfo_[col].special_.empty()) + // Overtake possible lines + colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|'); + } + int brace_open = 0; + int brace_close = 0; + while (it != hh.end()) { + c = *it; + colinfo_[col].special_ += c; + if (c == '{') + ++brace_open; + else if (c == '}') + ++brace_close; + ++it; + if (brace_open > 0 && brace_open == brace_close) + break; + } + --it; + if (newcolumn) { + colinfo_[col].lines_ = std::count( + colinfo_[col].special_.begin(), + colinfo_[col].special_.end(), '|'); + LYXERR(Debug::MATHED) + << "special column separator: `" + << to_utf8(colinfo_[col].special_) + << '\'' << endl; + ++col; + colinfo_[col].lines_ = 0; + colinfo_[col].special_.clear(); + } } else if (col >= ncols()) { - // Only '|' is allowed in the last dummy column + // Only intercolumn stuff is allowed in the last + // dummy column break; } else if (c == 'c' || c == 'l' || c == 'r') { - colinfo_[col].align_ = (char)c; + colinfo_[col].align_ = static_cast(c); + if (!colinfo_[col].special_.empty()) { + colinfo_[col].special_ += c; + colinfo_[col].lines_ = std::count( + colinfo_[col].special_.begin(), + colinfo_[col].special_.end(), '|'); + LYXERR(Debug::MATHED) + << "special column separator: `" + << to_utf8(colinfo_[col].special_) + << '\'' << endl; + } ++col; colinfo_[col].lines_ = 0; + colinfo_[col].special_.clear(); } else { lyxerr << "unknown column separator: '" << c << "'" << endl; } @@ -215,7 +273,8 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const { col_type col = 0; for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) - if (*it == 'c' || *it == 'l' || *it == 'r') + if (*it == 'c' || *it == 'l' || *it == 'r'|| + *it == 'p' || *it == 'm' || *it == 'b') ++col; // let's have at least one column, even if we did not recognize its // alignment @@ -228,6 +287,12 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const void InsetMathGrid::halign(char h, col_type col) { colinfo_[col].align_ = h; + if (!colinfo_[col].special_.empty()) { + char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1]; + if (c == 'l' || c == 'c' || c == 'r') + c = h; + } + // FIXME: Change alignment of p, m and b columns, too } @@ -241,10 +306,15 @@ docstring InsetMathGrid::halign() const { docstring res; for (col_type col = 0; col < ncols(); ++col) { - res += docstring(colinfo_[col].lines_, '|'); - res += colinfo_[col].align_; + if (colinfo_[col].special_.empty()) { + res += docstring(colinfo_[col].lines_, '|'); + res += colinfo_[col].align_; + } else + res += colinfo_[col].special_; } - return res + docstring(colinfo_[ncols()].lines_, '|'); + if (colinfo_[ncols()].special_.empty()) + return res + docstring(colinfo_[ncols()].lines_, '|'); + return res + colinfo_[ncols()].special_; } @@ -1147,14 +1217,34 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) swapCol(cur.col()); cur.pos() = 0; // trick, see above } - else if (s == "add-vline-left") + else if (s == "add-vline-left") { colinfo_[cur.col()].lines_++; - else if (s == "add-vline-right") + if (!colinfo_[cur.col()].special_.empty()) + colinfo_[cur.col()].special_ += '|'; + } + else if (s == "add-vline-right") { colinfo_[cur.col()+1].lines_++; - else if (s == "delete-vline-left") + if (!colinfo_[cur.col()+1].special_.empty()) + colinfo_[cur.col()+1].special_.insert(0, 1, '|'); + } + else if (s == "delete-vline-left") { colinfo_[cur.col()].lines_--; - else if (s == "delete-vline-right") + docstring & special = colinfo_[cur.col()].special_; + if (!special.empty()) { + docstring::size_type i = special.rfind('|'); + BOOST_ASSERT(i != docstring::npos); + special.erase(i, 1); + } + } + else if (s == "delete-vline-right") { colinfo_[cur.col()+1].lines_--; + docstring & special = colinfo_[cur.col()+1].special_; + if (!special.empty()) { + docstring::size_type i = special.find('|'); + BOOST_ASSERT(i != docstring::npos); + special.erase(i, 1); + } + } else { cur.undispatched(); break; diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 3faa33f4ea..6d80ad6a4e 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -83,6 +83,11 @@ public: unsigned int lines_; /// additional amount to be skipped when drawing int skip_; + /// Special alignment. + /// This does also contain align_ and lines_ if it is nonempty. + /// It needs to be in sync with align_ and lines_ because some + /// code only uses align_ and lines_. + docstring special_; }; public: diff --git a/status.15x b/status.15x index 50aec41a59..6d56195ba2 100644 --- a/status.15x +++ b/status.15x @@ -68,6 +68,9 @@ What's new - Conversion from older documents failed if koi8 was used as the document encoding (Bug 4158). +- Handle array column specifiers @{decl.}, p{width} and the extenions by + array.sty in mathed (Bug 4132). + * USER INTERFACE: - Fix crash when clicking in a tabular cell and the "delete empty paragraph"