inset(new InsetTableCell(buf))
{
inset->setBuffer(const_cast<Buffer &>(buf));
- inset->paragraphs().back().setLayout(buf.params().documentClass().plainLayout());
}
if (column_info.size() == 1)
return;
- column_info.erase(column_info.begin() + column);
- size_t row_count = row_info.size();
+ size_t const row_count = row_info.size();
for (row_type i = 0; i < row_count; ++i) {
// Care about multicolumn cells
if (column + 1 < column_info.size() &&
}
cell_info[i].erase(cell_info[i].begin() + column);
}
+ column_info.erase(column_info.begin() + column);
updateIndexes();
}
bool Tabular::setFixedWidth(row_type r, col_type c)
{
bool const multicol = cell_info[r][c].multicolumn != CELL_NORMAL;
- if ((!column_info[c].p_width.zero() && !multicol)
- || (multicol && !cell_info[r][c].p_width.zero())) {
- cell_info[r][c].inset->toggleFixedWidth(true);
- return true;
- }
- return false;
+ bool const fixed_width = (!column_info[c].p_width.zero() && !multicol)
+ || (multicol && !cell_info[r][c].p_width.zero());
+ cell_info[r][c].inset->toggleFixedWidth(fixed_width);
+ return fixed_width;
}
{
idx_type i = getFirstCellInRow(row);
if (what) {
- setMultiColumn(i, column_info.size());
+ setMultiColumn(i, numberOfCellsInRow(i));
setTopLine(i, false);
setBottomLine(i, false);
setLeftLine(i, false);
setRightLine(i, false);
- } else
+ } else {
unsetMultiColumn(i);
+ // FIXME: when unsetting a caption row, also all existing captions
+ // in this row must be dissolved, see (bug 5754)
+ // dispatch(FuncRequest(LFUN_INSET_DISSOLVE, "caption-insert"));
+ }
row_info[row].caption = what;
return i;
}
}
+bool Tabular::haveLTCaption() const
+{
+ for (row_type i = 0; i < row_info.size(); ++i)
+ if (row_info[i].caption)
+ return true;
+ return false;
+}
+
+
// end longtable support functions
void Tabular::setRowAscent(row_type row, int height)
return 0;
int ret = 0;
- // output header info
- if (haveLTHead()) {
- if (endhead.topDL) {
+ // caption handling
+ // the caption must be output befrore the headers
+ if (haveLTCaption()) {
+ for (row_type i = 0; i < row_info.size(); ++i) {
+ if (row_info[i].caption) {
+ ret += TeXRow(os, i, runparams);
+ }
+ }
+ }
+ // output first header info
+ // first header must be output before the header, otherwise the
+ // correct caption placement becomes really weird
+ if (haveLTFirstHead()) {
+ if (endfirsthead.topDL) {
os << "\\hline\n";
++ret;
}
for (row_type i = 0; i < row_info.size(); ++i) {
- if (row_info[i].endhead) {
+ if (row_info[i].endfirsthead) {
ret += TeXRow(os, i, runparams);
}
}
- if (endhead.bottomDL) {
+ if (endfirsthead.bottomDL) {
os << "\\hline\n";
++ret;
}
- os << "\\endhead\n";
+ os << "\\endfirsthead\n";
++ret;
- if (endfirsthead.empty) {
+ }
+ // output header info
+ if (haveLTHead()) {
+ if (endfirsthead.empty && !haveLTFirstHead()) {
os << "\\endfirsthead\n";
++ret;
}
- }
- // output firstheader info
- if (haveLTFirstHead()) {
- if (endfirsthead.topDL) {
+ if (endhead.topDL) {
os << "\\hline\n";
++ret;
}
for (row_type i = 0; i < row_info.size(); ++i) {
- if (row_info[i].endfirsthead) {
+ if (row_info[i].endhead) {
ret += TeXRow(os, i, runparams);
}
}
- if (endfirsthead.bottomDL) {
+ if (endhead.bottomDL) {
os << "\\hline\n";
++ret;
}
- os << "\\endfirsthead\n";
+ os << "\\endhead\n";
++ret;
}
// output footer info
}
os << "\\endfoot\n";
++ret;
- if (endlastfoot.empty) {
+ if (endlastfoot.empty && !haveLTLastFoot()) {
os << "\\endlastfoot\n";
++ret;
}
{
if (!is_long_tabular)
return true;
- return !row_info[row].endhead && !row_info[row].endfirsthead &&
- !row_info[row].endfoot && !row_info[row].endlastfoot;
+ return !row_info[row].endhead && !row_info[row].endfirsthead
+ && !row_info[row].endfoot && !row_info[row].endlastfoot
+ && !row_info[row].caption;
}
//+ Long Tabular case +
//+---------------------------------------------------------------------
+ // output caption info
+ if (haveLTCaption()) {
+ os << "<caption>\n";
+ ++ret;
+ for (row_type i = 0; i < row_info.size(); ++i) {
+ if (row_info[i].caption) {
+ ret += docbookRow(os, i, runparams);
+ }
+ }
+ os << "</caption>\n";
+ ++ret;
+ }
// output header info
if (haveLTHead() || haveLTFirstHead()) {
os << "<thead>\n";
/////////////////////////////////////////////////////////////////////
InsetTableCell::InsetTableCell(Buffer & buf)
- : InsetText(buf), isFixedWidth(false),
+ : InsetText(buf, InsetText::PlainLayout), isFixedWidth(false),
contentAlign(LYX_ALIGN_CENTER)
{}
bool InsetTabular::insetAllowed(InsetCode code) const
{
- if (code == MATHMACRO_CODE)
+ if (code == MATHMACRO_CODE
+ || (code == CAPTION_CODE && !tabular.is_long_tabular))
return false;
return true;
|| y - a > bv->workHeight()) {
pi.pain.setDrawingEnabled(false);
cell(idx)->draw(pi, cx, y);
- drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
+ drawCellLines(pi.pain, nx, y, i, idx, pi.change_);
pi.pain.setDrawingEnabled(original_drawing_state);
} else {
cell(idx)->draw(pi, cx, y);
- drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
+ drawCellLines(pi.pain, nx, y, i, idx, pi.change_);
}
nx += tabular.columnWidth(idx);
++idx;
void InsetTabular::drawCellLines(Painter & pain, int x, int y,
- row_type row, idx_type cell, bool erased) const
+ row_type row, idx_type cell, Change const & change) const
{
int x2 = x + tabular.columnWidth(cell);
bool on_off = false;
- ColorCode col = Color_tabularline;
- ColorCode onoffcol = Color_tabularonoffline;
+ Color col = Color_tabularline;
+ Color onoffcol = Color_tabularonoffline;
- if (erased) {
- col = Color_deletedtext;
- onoffcol = Color_deletedtext;
+ if (change.changed()) {
+ col = change.color();
+ onoffcol = change.color();
}
if (!tabular.topAlreadyDrawn(cell)) {
// insert file functions
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
- case LFUN_FILE_INSERT_PLAINTEXT: {
+ case LFUN_FILE_INSERT_PLAINTEXT:
// FIXME UNICODE
- docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
- FileName(to_utf8(cmd.argument())));
- if (tmpstr.empty())
- break;
- cur.recordUndoInset(INSERT_UNDO);
- if (insertPlaintextString(cur.bv(), tmpstr, false)) {
- // content has been replaced,
- // so cursor might be invalid
- cur.pos() = cur.lastpos();
- cur.pit() = cur.lastpit();
- bvcur.setCursor(cur);
- } else
- cur.undispatched();
+ if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
+ docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
+ FileName(to_utf8(cmd.argument())));
+ if (tmpstr.empty())
+ break;
+ cur.recordUndoInset(INSERT_UNDO);
+ if (insertPlaintextString(cur.bv(), tmpstr, false)) {
+ // content has been replaced,
+ // so cursor might be invalid
+ cur.pos() = cur.lastpos();
+ cur.pit() = cur.lastpit();
+ bvcur.setCursor(cur);
+ } else
+ cur.undispatched();
+ }
break;
- }
case LFUN_CUT:
if (cur.selIsMultiCell()) {
case LFUN_TEXTSTYLE_UPDATE:
case LFUN_FONT_SIZE:
case LFUN_FONT_UNDERLINE:
+ case LFUN_FONT_STRIKEOUT:
+ case LFUN_FONT_UULINE:
+ case LFUN_FONT_UWAVE:
case LFUN_LANGUAGE:
case LFUN_WORD_CAPITALIZE:
case LFUN_WORD_UPCASE:
cell(cur.idx())->dispatch(cur, cmd);
break;
}
+
+ case LFUN_INSET_SETTINGS:
+ // relay this lfun to Inset, not to the cell.
+ Inset::doDispatch(cur, cmd);
+ break;
+
default:
// we try to handle this event in the insets dispatch function.
cell(cur.idx())->dispatch(cur, cmd);
return true;
case Tabular::MULTICOLUMN:
- status.setEnabled(sel_row_start == sel_row_end);
+ // When a row is set as longtable caption, it must not be allowed
+ // to unset that this row is a multicolumn.
+ status.setEnabled(sel_row_start == sel_row_end
+ && !tabular.ltCaption(tabular.cellRow(cur.idx())));
status.setOnOff(tabular.isMultiColumn(cur.idx()));
break;
status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
break;
+ // every row can only be one thing:
+ // either a footer or header or caption
case Tabular::SET_LTFIRSTHEAD:
- status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
+ status.setEnabled(sel_row_start == sel_row_end
+ && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+ && !tabular.ltCaption(sel_row_start));
+ status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
break;
case Tabular::UNSET_LTFIRSTHEAD:
- status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
+ status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
break;
case Tabular::SET_LTHEAD:
+ status.setEnabled(sel_row_start == sel_row_end
+ && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+ && !tabular.ltCaption(sel_row_start));
status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
break;
break;
case Tabular::SET_LTFOOT:
+ status.setEnabled(sel_row_start == sel_row_end
+ && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+ && !tabular.ltCaption(sel_row_start));
status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
break;
break;
case Tabular::SET_LTLASTFOOT:
- status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
+ status.setEnabled(sel_row_start == sel_row_end
+ && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+ && !tabular.ltCaption(sel_row_start));
+ status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
break;
case Tabular::UNSET_LTLASTFOOT:
- status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
+ status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
break;
case Tabular::SET_LTNEWPAGE:
status.setOnOff(tabular.getLTNewPage(sel_row_start));
break;
+ // only one row can be the caption
case Tabular::TOGGLE_LTCAPTION:
- status.setEnabled(sel_row_start == sel_row_end);
+ status.setEnabled(sel_row_start == sel_row_end
+ && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
+ && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
+ && (!tabular.haveLTCaption()
+ || tabular.ltCaption(sel_row_start)));
status.setOnOff(tabular.ltCaption(sel_row_start));
break;
}
return cell(cur.idx())->getStatus(cur, cmd, status);
+ case LFUN_INSET_SETTINGS:
+ // relay this lfun to Inset, not to the cell.
+ return Inset::getStatus(cur, cmd, status);
+
case LFUN_INSET_MODIFY:
if (insetCode(cmd.getArg(0)) == TABULAR_CODE) {
status.setEnabled(true);
tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
break;
- case Tabular::TOGGLE_LTCAPTION:
- cur.idx() = tabular.setLTCaption(row, !tabular.ltCaption(row));
+ case Tabular::TOGGLE_LTCAPTION: {
+ bool set = !tabular.ltCaption(row);
+ cur.idx() = tabular.setLTCaption(row, set);
cur.pit() = 0;
cur.pos() = 0;
cur.setSelection(false);
+ // When a row is set as caption, then also insert a caption. Otherwise
+ // the LaTeX output is broken, when the user doesn't add a caption.
+ if (set)
+ lyx::dispatch(FuncRequest(LFUN_CAPTION_INSERT));
break;
+ }
case Tabular::SET_BOOKTABS:
tabular.use_booktabs = true;