int Tabular::rowHeight(idx_type cell) const
{
- row_type const span = rowSpan(cell);
- row_type const row = cellRow(cell);
- int h = rowAscent(row) + rowDescent(row);
+ row_type const span = rowSpan(cell);
+ row_type const row = cellRow(cell);
+ int h = 0;
+ for(row_type r = row; r < row + span ; ++r) {
+ h += rowAscent(r) + rowDescent(r);
+ if (r != row + span - 1)
+ h += interRowSpace(r + 1);
+ }
- for(row_type r = row; r < row + span ; ++r) {
- if (r > row) {
- h += rowAscent(r);
- h += interRowSpace(r);
- }
- if (r < row + span - 1)
- h += rowDescent(r);
- }
- return h;
+ return h;
}
Tabular::VAlignment
Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
{
- if (!onlycolumn && isMultiColumn(cell))
+ if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
return cellInfo(cell).valignment;
return column_info[cellColumn(cell)].valignment;
}
int Tabular::textVOffset(idx_type cell) const
{
int h = rowHeight(cell);
-
+
+ row_type const r = cellRow(cell);
+ if (rowSpan(cell) > 1)
+ h -= rowDescent(r) + rowAscent(r);
+
int y = 0;
switch (getVAlignment(cell)) {
case LYX_VALIGN_TOP:
}
-void Tabular::setMultiColumn(idx_type cell, idx_type number)
+Tabular::idx_type Tabular::setMultiColumn(idx_type cell, idx_type number)
{
idx_type const col = cellColumn(cell);
idx_type const row = cellRow(cell);
for (idx_type i = 0; i < number; ++i)
unsetMultiRow(cellIndex(row, col + i));
+ // unsetting of multirow may have invalidated cell index
+ cell = cellIndex(row, col);
CellData & cs = cellInfo(cell);
cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
- cs.alignment = column_info[cellColumn(cell)].alignment;
- setRightLine(cell, rightLine(cell + number - 1));
+ cs.alignment = column_info[col].alignment;
+ if (col > 0)
+ setRightLine(cell, rightLine(cellIndex(row, col - 1)));
for (idx_type i = 1; i < number; ++i) {
CellData & cs1 = cellInfo(cell + i);
cs1.inset->clear();
}
updateIndexes();
+ return cell;
}
}
-void Tabular::setMultiRow(idx_type cell, idx_type number)
+Tabular::idx_type Tabular::setMultiRow(idx_type cell, idx_type number)
{
idx_type const col = cellColumn(cell);
idx_type const row = cellRow(cell);
for (idx_type i = 0; i < number; ++i)
unsetMultiColumn(cellIndex(row + i, col));
+ // unsetting of multicol may have invalidated cell index
+ cell = cellIndex(row, col);
CellData & cs = cellInfo(cell);
cs.multirow = CELL_BEGIN_OF_MULTIROW;
- // reset the vertical alignment to top because multirows cells
- // cannot be vertically aligned (they can also only have one paragraph)
- column_info[col].valignment = LYX_VALIGN_TOP;
-
- // FIXME: the horizontal alignment can only be changed for
- // the whole table, support for this needs to be implemented
- // (assigning this to uwestoehr)
- // until LyX supports this, the alignment is always left
- column_info[col].alignment = LYX_ALIGN_LEFT;
+ cs.valignment = LYX_VALIGN_MIDDLE;
// set the bottom row of the last selected cell
setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
cs1.inset->clear();
}
updateIndexes();
+ return cell;
}
if (!isMultiRow(cell))
return;
+ cellInfo(cell).valignment = LYX_VALIGN_TOP;
row_type const row = cellRow(cell);
col_type const col = cellColumn(cell);
row_type const span = rowSpan(cell);
else
// we need to set a default value
// needs to be discussed
- os << "2.0cm";
+ os << "*";
os << "}{";
} // end if ismultirow
// top y coordinate of tabular
int h = yo(cur.bv()) - tabular.rowAscent(0);
row_type r = 0;
- for (; r < nrows() && y > h; ++r)
+ for (; r < tabular.nrows() && y > h; ++r)
h += tabular.rowAscent(r) + tabular.rowDescent(r)
+ tabular.interRowSpace(r);
col_type cs, ce;
getSelection(cur, rs, re, cs, ce);
- if (col >= cs && col <= ce && row >= rs && row <= re)
+ idx_type const cell = tabular.cellIndex(row, col);
+ col_type const cspan = tabular.columnSpan(cell);
+ row_type const rspan = tabular.rowSpan(cell);
+ if (col + cspan - 1 >= cs && col <= ce
+ && row + rspan - 1 >= rs && row <= re)
return true;
} else
if (col == tabular.cellColumn(cur.idx())
}
if (r + 1 < tabular.nrows())
- y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
- + tabular.interRowSpace(r + 1);
+ y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
+ + tabular.interRowSpace(r + 1);
}
}
tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
if (cur.selIsMultiCell() || full_cell_selected) {
- y -= tabular.rowAscent(0);
for (row_type r = 0; r < tabular.nrows(); ++r) {
int xx = x;
for (col_type c = 0; c < tabular.ncols(); ++c) {
}
int const w = tabular.columnWidth(cell);
int const h = tabular.rowHeight(cell);
+ int const yy = y - tabular.rowAscent(r);
if (isCellSelected(cur, r, c))
- pi.pain.fillRectangle(xx, y, w, h, Color_selection);
+ pi.pain.fillRectangle(xx, yy, w, h, Color_selection);
xx += w;
}
if (r + 1 < tabular.nrows())
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
- istringstream is(to_utf8(cmd.argument()));
- string s;
- is >> s;
- if (insetCode(s) != TABULAR_CODE) {
- status.clear();
- status.setEnabled(false);
+ if (&cur.inset() != this || cmd.getArg(0) != "tabular")
break;
- }
- is >> s;
+
+ string const s = cmd.getArg(1);
// FIXME: We only check for the very first argument...
int action = Tabular::LAST_ACTION;
int i = 0;
for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
- string const tmp = tabularFeature[i].feature;
- if (tmp == s.substr(0, tmp.length())) {
+ if (tabularFeature[i].feature == s) {
action = tabularFeature[i].action;
break;
}
return true;
}
- string const argument
- = ltrim(s.substr(tabularFeature[i].feature.length()));
+ string const argument = cmd.getLongArg(2);
row_type sel_row_start = 0;
row_type sel_row_end = 0;
int const col = tabular.cellColumn(sl.idx());
// y offset correction
- for (int r = 0; r <= row; ++r) {
- if (r != 0) {
- y += tabular.rowAscent(r);
- y += tabular.interRowSpace(r);
- }
- if (r != row)
- y += tabular.rowDescent(r);
- }
+ for (int r = 0; r < row; ++r)
+ y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
+ + tabular.interRowSpace(r + 1);
+
y += tabular.textVOffset(sl.idx());
// x offset correction
idx_type const s_start = cur.selBegin().idx();
row_type const col_start = tabular.cellColumn(s_start);
row_type const col_end = tabular.cellColumn(cur.selEnd().idx());
- tabular.setMultiColumn(s_start, col_end - col_start + 1);
- cur.idx() = s_start;
+ cur.idx() = tabular.setMultiColumn(s_start, col_end - col_start + 1);
cur.pit() = 0;
cur.pos() = 0;
cur.setSelection(false);
idx_type const s_start = cur.selBegin().idx();
row_type const row_start = tabular.cellRow(s_start);
row_type const row_end = tabular.cellRow(cur.selEnd().idx());
- tabular.setMultiRow(s_start, row_end - row_start + 1);
- cur.idx() = s_start;
+ cur.idx() = tabular.setMultiRow(s_start, row_end - row_start + 1);
cur.pit() = 0;
cur.pos() = 0;
cur.setSelection(false);