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
This commit is contained in:
Georg Baum 2007-08-31 10:31:19 +00:00
parent d6b762caec
commit c51c8a7257
6 changed files with 110 additions and 14 deletions

View File

@ -205,7 +205,7 @@ public:
Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_) Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
filename(file), file_fully_loaded(false), inset(params), 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); inset.setAutoBreakRows(true);
lyxvc.buffer(&parent); lyxvc.buffer(&parent);

View File

@ -63,7 +63,7 @@ ToolbarItem::ToolbarItem(Type type, FuncRequest const & func, docstring const &
ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label) ToolbarItem::ToolbarItem(Type type, string const & name, docstring const & label)
: type_(type), name_(name), label_(label) : type_(type), label_(label), name_(name)
{ {
} }

View File

@ -63,7 +63,6 @@ class InsetMathGrid;
class InsetMathHull; class InsetMathHull;
class InsetMathMatrix; class InsetMathMatrix;
class InsetMathNest; class InsetMathNest;
class InsetMathParbox;
class InsetMathScript; class InsetMathScript;
class InsetMathString; class InsetMathString;
class InsetMathSpace; class InsetMathSpace;
@ -132,7 +131,6 @@ public:
virtual InsetMathMatrix const * asMatrixInset() const { return 0; } virtual InsetMathMatrix const * asMatrixInset() const { return 0; }
virtual InsetMathNest * asNestInset() { return 0; } virtual InsetMathNest * asNestInset() { return 0; }
virtual InsetMathNest const * asNestInset() const { return 0; } virtual InsetMathNest const * asNestInset() const { return 0; }
virtual InsetMathParbox * asParboxInset() { return 0; }
virtual InsetMathScript * asScriptInset() { return 0; } virtual InsetMathScript * asScriptInset() { return 0; }
virtual InsetMathScript const * asScriptInset() const { return 0; } virtual InsetMathScript const * asScriptInset() const { return 0; }
virtual InsetMathSpace * asSpaceInset() { return 0; } virtual InsetMathSpace * asSpaceInset() { return 0; }

View File

@ -178,6 +178,7 @@ void InsetMathGrid::setDefaults()
for (col_type col = 0; col < ncols(); ++col) { for (col_type col = 0; col < ncols(); ++col) {
colinfo_[col].align_ = defaultColAlign(col); colinfo_[col].align_ = defaultColAlign(col);
colinfo_[col].skip_ = defaultColSpace(col); colinfo_[col].skip_ = defaultColSpace(col);
colinfo_[col].special_.clear();
} }
} }
@ -189,13 +190,70 @@ void InsetMathGrid::halign(docstring const & hh)
char_type c = *it; char_type c = *it;
if (c == '|') { if (c == '|') {
colinfo_[col].lines_++; colinfo_[col].lines_++;
} else if (col >= ncols()) { } else if ((c == 'p' || c == 'm' || c == 'b'||
// Only '|' is allowed in the last dummy column 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; break;
} else if (c == 'c' || c == 'l' || c == 'r') { colinfo_[col].align_ = 'l';
colinfo_[col].align_ = (char)c; } 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; ++col;
colinfo_[col].lines_ = 0; colinfo_[col].lines_ = 0;
colinfo_[col].special_.clear();
}
} else if (col >= ncols()) {
// Only intercolumn stuff is allowed in the last
// dummy column
break;
} else if (c == 'c' || c == 'l' || c == 'r') {
colinfo_[col].align_ = static_cast<char>(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 { } else {
lyxerr << "unknown column separator: '" << c << "'" << endl; lyxerr << "unknown column separator: '" << c << "'" << endl;
} }
@ -215,7 +273,8 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
{ {
col_type col = 0; col_type col = 0;
for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) 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; ++col;
// let's have at least one column, even if we did not recognize its // let's have at least one column, even if we did not recognize its
// alignment // alignment
@ -228,6 +287,12 @@ InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh) const
void InsetMathGrid::halign(char h, col_type col) void InsetMathGrid::halign(char h, col_type col)
{ {
colinfo_[col].align_ = h; 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; docstring res;
for (col_type col = 0; col < ncols(); ++col) { for (col_type col = 0; col < ncols(); ++col) {
if (colinfo_[col].special_.empty()) {
res += docstring(colinfo_[col].lines_, '|'); res += docstring(colinfo_[col].lines_, '|');
res += colinfo_[col].align_; res += colinfo_[col].align_;
} else
res += colinfo_[col].special_;
} }
if (colinfo_[ncols()].special_.empty())
return res + docstring(colinfo_[ncols()].lines_, '|'); 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()); swapCol(cur.col());
cur.pos() = 0; // trick, see above cur.pos() = 0; // trick, see above
} }
else if (s == "add-vline-left") else if (s == "add-vline-left") {
colinfo_[cur.col()].lines_++; 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_++; 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_--; 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_--; 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 { else {
cur.undispatched(); cur.undispatched();
break; break;

View File

@ -83,6 +83,11 @@ public:
unsigned int lines_; unsigned int lines_;
/// additional amount to be skipped when drawing /// additional amount to be skipped when drawing
int skip_; 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: public:

View File

@ -68,6 +68,9 @@ What's new
- Conversion from older documents failed if koi8 was used as the - Conversion from older documents failed if koi8 was used as the
document encoding (Bug 4158). document encoding (Bug 4158).
- Handle array column specifiers @{decl.}, p{width} and the extenions by
array.sty in mathed (Bug 4132).
* USER INTERFACE: * USER INTERFACE:
- Fix crash when clicking in a tabular cell and the "delete empty paragraph" - Fix crash when clicking in a tabular cell and the "delete empty paragraph"