using namespace std;
using namespace lyx::support;
-using boost::shared_ptr;
namespace lyx {
Tabular::CellData::CellData(Buffer * buf)
: cellno(0),
width(0),
- height(0),
- ascent(0),
- descent(0),
multicolumn(Tabular::CELL_NORMAL),
multirow(Tabular::CELL_NORMAL),
alignment(LYX_ALIGN_CENTER),
valignment(LYX_VALIGN_TOP),
+ voffset(0),
top_line(false),
bottom_line(false),
left_line(false),
multirow(cs.multirow),
alignment(cs.alignment),
valignment(cs.valignment),
+ voffset(cs.voffset),
top_line(cs.top_line),
bottom_line(cs.bottom_line),
left_line(cs.left_line),
std::swap(multirow, rhs.multirow);
std::swap(alignment, rhs.alignment);
std::swap(valignment, rhs.valignment);
+ std::swap(voffset, rhs.voffset);
std::swap(top_line, rhs.top_line);
std::swap(bottom_line, rhs.bottom_line);
std::swap(left_line, rhs.left_line);
endfoot(false),
endlastfoot(false),
newpage(false),
- caption(false),
- valignment(LYX_VALIGN_TOP),
- maxheight(0)
+ caption(false)
{}
int Tabular::textVOffset(idx_type cell) const
{
- row_type const r = cellRow(cell);
- int y = cellHeight(cell) - rowDescent(r) - rowAscent(r);
- switch (getVAlignment(cell)) {
- case LYX_VALIGN_TOP:
- y = 0;
- break;
- case LYX_VALIGN_MIDDLE:
- y = y/2;
- break;
- case LYX_VALIGN_BOTTOM:
- break;
+ int voffset = cellInfo(cell).voffset;
+ if (isMultiRow(cell)) {
+ row_type const row = cellRow(cell);
+ voffset += (cellHeight(cell) - rowAscent(row) - rowDescent(row))/2;
}
-
- return y;
+ return voffset;
}
CellData & cs = cellInfo(cell);
cs.multirow = CELL_BEGIN_OF_MULTIROW;
cs.valignment = LYX_VALIGN_MIDDLE;
+ // FIXME: the horizontal alignment of multirow cells can only
+ // be changed for the whole table,
+ // support for this needs to be implemented but us a fileformat
+ // change (assigning this to uwestoehr)
+ // until LyX supports this, use the deault alignment of multirow
+ // cells: left
+ cs.alignment = LYX_ALIGN_LEFT;
// set the bottom row of the last selected cell
setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
return;
cellInfo(cell).valignment = LYX_VALIGN_TOP;
+ cellInfo(cell).alignment = LYX_ALIGN_CENTER;
row_type const row = cellRow(cell);
col_type const col = cellColumn(cell);
row_type const span = rowSpan(cell);
FuncStatus & status) const
{
bool enabled;
- switch (cmd.action) {
+ switch (cmd.action()) {
case LFUN_LAYOUT:
enabled = !forcePlainLayout();
break;
}
for (row_type r = 0; r < tabular.nrows(); ++r) {
- int maxAsc = 0;
- int maxDesc = 0;
+ int maxasc = 0;
+ int maxdes = 0;
for (col_type c = 0; c < tabular.ncols(); ++c) {
if (tabular.isPartOfMultiColumn(r, c)
|| tabular.isPartOfMultiRow(r, c))
idx_type const cell = tabular.cellIndex(r, c);
Dimension dim;
MetricsInfo m = mi;
- Length p_width;
- if (tabular.cell_info[r][c].multicolumn ==
- Tabular::CELL_BEGIN_OF_MULTICOLUMN)
- p_width = tabular.cellInfo(cell).p_width;
- else
- p_width = tabular.column_info[c].p_width;
+ Length const p_width = tabular.getPWidth(cell);
if (!p_width.zero())
m.base.textwidth = p_width.inPixels(mi.base.textwidth);
tabular.cellInset(cell)->metrics(m, dim);
if (!p_width.zero())
dim.wid = m.base.textwidth;
tabular.setCellWidth(cell, dim.wid);
- maxAsc = max(maxAsc, dim.asc);
- maxDesc = max(maxDesc, dim.des);
- // store the height for every cell
- // this is later needed in InsetTabular::draw to determine the valignment
- int const top_space_cell = tabular.row_info[r].top_space_default ?
- default_line_space :
- tabular.row_info[r].top_space.inPixels(mi.base.textwidth);
- int const bottom_space_cell = tabular.row_info[r].bottom_space_default ?
- default_line_space :
- tabular.cell_info[r][c].height = dim.asc + dim.des;
- tabular.cell_info[r][c].ascent = dim.asc;
- tabular.cell_info[r][c].descent = dim.des;
+ // FIXME(?): do we need a second metrics call?
+ TextMetrics const & tm =
+ mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
+ // with LYX_VALIGN_BOTTOM the descent is relative to the last par
+ // = descent of text in last par + TEXT_TO_INSET_OFFSET:
+ int const lastpardes = tm.last().second->descent()
+ + TEXT_TO_INSET_OFFSET;
+ int offset = 0;
+ switch (tabular.getVAlignment(cell)) {
+ case Tabular::LYX_VALIGN_TOP:
+ break;
+ case Tabular::LYX_VALIGN_MIDDLE:
+ offset = -(dim.des - lastpardes)/2;
+ break;
+ case Tabular::LYX_VALIGN_BOTTOM:
+ offset = -(dim.des - lastpardes);
+ break;
+ }
+ tabular.cell_info[r][c].voffset = offset;
+ maxasc = max(maxasc, dim.asc - offset);
+ maxdes = max(maxdes, dim.des + offset);
}
int const top_space = tabular.row_info[r].top_space_default ?
default_line_space :
tabular.row_info[r].top_space.inPixels(mi.base.textwidth);
- tabular.setRowAscent(r, maxAsc + ADD_TO_HEIGHT + top_space);
+ tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
int const bottom_space = tabular.row_info[r].bottom_space_default ?
default_line_space :
tabular.row_info[r].bottom_space.inPixels(mi.base.textwidth);
- tabular.setRowDescent(r, maxDesc + ADD_TO_HEIGHT + bottom_space);
+ tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
}
tabular.updateColumnWidths();
dim.asc = tabular.rowAscent(0);
bool const original_selection_state = pi.selected;
idx_type idx = 0;
- int cy = 0;
first_visible_cell = Tabular::npos;
-
- // determine the highest cell because its valignment sets the row valignment
- // also store its height
- for (row_type r = 0; r < tabular.nrows(); ++r) {
- int nx = x;
- for (col_type c = 0; c < tabular.ncols(); ++c) {
- if (tabular.cell_info[r][c].height >= tabular.row_info[r].maxheight) {
- tabular.row_info[r].maxheight = tabular.cell_info[r][c].height;
- switch (tabular.getVAlignment(tabular.cellIndex(r, c))) {
- case Tabular::LYX_VALIGN_TOP:
- tabular.row_info[r].valignment = Tabular::LYX_VALIGN_TOP;
- break;
- case Tabular::LYX_VALIGN_MIDDLE:
- tabular.row_info[r].valignment = Tabular::LYX_VALIGN_MIDDLE;
- break;
- case Tabular::LYX_VALIGN_BOTTOM:
- tabular.row_info[r].valignment = Tabular::LYX_VALIGN_BOTTOM;
- break;
- }
- }
- }
- }
-
- // step over all cells
for (row_type r = 0; r < tabular.nrows(); ++r) {
int nx = x;
for (col_type c = 0; c < tabular.ncols(); ++c) {
first_visible_cell = idx;
pi.selected |= isCellSelected(cur, r, c);
-
- // set the position for the vertical alignment
- // if the cell is not the highest, align it according to the row valignment
- // and according to its own valignment
- // Note: The fractions of the scent values were found by testing
- // there is no bettwer way for the calculation because of LyX's definition
- // of ascent and descent. The correct way would be to calculate based
- // on the text height, the line space and paragraph separation.
- cy = y;
- if (tabular.cell_info[r][c].height < tabular.row_info[r].maxheight) {
- switch (tabular.row_info[r].valignment) {
- case Tabular::LYX_VALIGN_TOP:
- switch (tabular.getVAlignment(idx)) {
- case Tabular::LYX_VALIGN_TOP:
- break;
- case Tabular::LYX_VALIGN_MIDDLE:
- cy += - tabular.cell_info[r][c].descent / 2
- + 0.3 * tabular.cell_info[r][c].ascent;
- // FIXME the row also needs to be increased at the upper border
- break;
- case Tabular::LYX_VALIGN_BOTTOM:
- cy += - tabular.cell_info[r][c].descent
- + 0.6 * tabular.cell_info[r][c].ascent;
- // FIXME the row also needs to be increased at the upper border
- break;
- }
- break;
- case Tabular::LYX_VALIGN_MIDDLE:
- switch (tabular.getVAlignment(idx)) {
- case Tabular::LYX_VALIGN_TOP:
- cy += tabular.row_info[r].maxheight / 2
- - 0.75 * tabular.cell_info[r][c].ascent;
- break;
- case Tabular::LYX_VALIGN_MIDDLE:
- cy += tabular.row_info[r].maxheight / 2
- - tabular.cell_info[r][c].descent / 2
- - 0.5 * tabular.cell_info[r][c].ascent;
- break;
- case Tabular::LYX_VALIGN_BOTTOM:
- cy += tabular.row_info[r].maxheight / 2
- - tabular.cell_info[r][c].descent
- - 0.2 * tabular.cell_info[r][c].ascent;
- break;
- }
- break;
- case Tabular::LYX_VALIGN_BOTTOM:
- switch (tabular.getVAlignment(idx)) {
- case Tabular::LYX_VALIGN_TOP:
- cy += tabular.row_info[r].maxheight
- - 1.5 * tabular.cell_info[r][c].ascent;
- break;
- case Tabular::LYX_VALIGN_MIDDLE:
- cy += tabular.row_info[r].maxheight
- - tabular.cell_info[r][c].descent / 2
- - 1.2 * tabular.cell_info[r][c].ascent;
- // FIXME the row also needs to be increased at the lower border
- break;
- case Tabular::LYX_VALIGN_BOTTOM:
- cy += tabular.row_info[r].maxheight
- - tabular.cell_info[r][c].descent
- - 0.9 * tabular.cell_info[r][c].ascent;
- // FIXME the row also needs to be increased at the lower border
- break;
- }
- break;
- }
- }
-
int const cx = nx + tabular.textHOffset(idx);
+ int const cy = y + tabular.textVOffset(idx);
// Cache the Inset position.
bv->coordCache().insets().add(cell(idx).get(), cx, cy);
cell(idx)->draw(pi, cx, cy);
Color gridcolor = change.changed() ? change.color() : Color_tabularonoffline;
// Top
- bool drawline = tabular.topLine(cell) || row > 0
- && tabular.bottomLine(tabular.cellAbove(cell));
+ bool drawline = tabular.topLine(cell)
+ || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
pain.line(x, y, x + w, y,
drawline ? linecolor : gridcolor,
drawline ? Painter::line_solid : Painter::line_onoffdash);
// Left
col_type const col = tabular.cellColumn(cell);
- drawline = tabular.leftLine(cell) || col > 0
- && tabular.rightLine(tabular.cellIndex(row, col - 1));
+ drawline = tabular.leftLine(cell)
+ || (col > 0 && tabular.rightLine(tabular.cellIndex(row, col - 1)));
pain.line(x, y, x, y + h,
drawline ? linecolor : gridcolor,
drawline ? Painter::line_solid : Painter::line_onoffdash);
// Right
x -= tabular.interColumnSpace(cell);
- drawline = tabular.rightLine(cell) || col + 1 < tabular.ncols()
- && tabular.leftLine(tabular.cellIndex(row, col + 1));
+ drawline = tabular.rightLine(cell)
+ || (col + 1 < tabular.ncols()
+ && tabular.leftLine(tabular.cellIndex(row, col + 1)));
pain.line(x + w, y, x + w, y + h,
drawline ? linecolor : gridcolor,
drawline ? Painter::line_solid : Painter::line_onoffdash);
CursorSlice sl = cur.top();
Cursor & bvcur = cur.bv().cursor();
- switch (cmd.action) {
+ FuncCode const act = cmd.action();
+
+ switch (act) {
case LFUN_MOUSE_PRESS: {
//lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
// select row
- if (cmd.x < xo(cur.bv()) + ADD_TO_TABULAR_WIDTH
- || cmd.x > xo(cur.bv()) + tabular.width()) {
- row_type r = rowFromY(cur, cmd.y);
+ if (cmd.x() < xo(cur.bv()) + ADD_TO_TABULAR_WIDTH
+ || cmd.x() > xo(cur.bv()) + tabular.width()) {
+ row_type r = rowFromY(cur, cmd.y());
cur.idx() = tabular.getFirstCellInRow(r);
cur.pos() = 0;
cur.resetAnchor();
}
// select column
int const y0 = yo(cur.bv()) - tabular.rowAscent(0);
- if (cmd.y < y0 + ADD_TO_TABULAR_WIDTH
- || cmd.y > y0 + tabular.height()) {
- col_type c = columnFromX(cur, cmd.x);
+ if (cmd.y() < y0 + ADD_TO_TABULAR_WIDTH
+ || cmd.y() > y0 + tabular.height()) {
+ col_type c = columnFromX(cur, cmd.x());
cur.idx() = tabular.cellIndex(0, c);
cur.pos() = 0;
cur.resetAnchor();
//lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
if (cmd.button() == mouse_button::button1) {
// only accept motions to places not deeper nested than the real anchor
- if (!bvcur.anchor_.hasPart(cur)) {
+ if (!bvcur.realAnchor().hasPart(cur)) {
cur.undispatched();
break;
}
// select (additional) row
if (rowselect_) {
- row_type r = rowFromY(cur, cmd.y);
+ row_type r = rowFromY(cur, cmd.y());
cur.idx() = tabular.getLastCellInRow(r);
// we need to reset the cursor's pit and pos now, as the old ones
// may no longer be valid.
}
// select (additional) column
if (colselect_) {
- col_type c = columnFromX(cur, cmd.x);
+ col_type c = columnFromX(cur, cmd.x());
cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
// we need to reset the cursor's pit and pos now, as the old ones
// may no longer be valid.
}
// only update if selection changes
if (bvcur.idx() == cur.idx() &&
- !(bvcur.anchor_.idx() == cur.idx() && bvcur.pos() != cur.pos()))
+ !(bvcur.realAnchor().idx() == cur.idx() && bvcur.pos() != cur.pos()))
cur.noUpdate();
- setCursorFromCoordinates(cur, cmd.x, cmd.y);
+ setCursorFromCoordinates(cur, cmd.x(), cmd.y());
bvcur.setCursor(cur);
bvcur.setSelection(true);
// if this is a multicell selection, we just set the cursor to
EntryDirection entry_from = ENTRY_DIRECTION_IGNORE;
FuncCode finish_lfun;
- if (cmd.action == LFUN_CHAR_FORWARD
- || cmd.action == LFUN_CHAR_FORWARD_SELECT) {
+ if (act == LFUN_CHAR_FORWARD
+ || act == LFUN_CHAR_FORWARD_SELECT) {
next_cell = true;
finish_lfun = LFUN_FINISHED_FORWARD;
}
- else if (cmd.action == LFUN_CHAR_BACKWARD
- || cmd.action == LFUN_CHAR_BACKWARD_SELECT) {
+ else if (act == LFUN_CHAR_BACKWARD
+ || act == LFUN_CHAR_BACKWARD_SELECT) {
next_cell = false;
finish_lfun = LFUN_FINISHED_BACKWARD;
}
// LEFT or RIGHT commands --- the interpretation will depend on the
// table's direction.
else {
- bool const right = cmd.action == LFUN_CHAR_RIGHT
- || cmd.action == LFUN_CHAR_RIGHT_SELECT;
+ bool const right = act == LFUN_CHAR_RIGHT
+ || act == LFUN_CHAR_RIGHT_SELECT;
next_cell = isRightToLeft(cur) != right;
if (lyxrc.visual_cursor)
finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
}
- bool const select = cmd.action == LFUN_CHAR_FORWARD_SELECT ||
- cmd.action == LFUN_CHAR_BACKWARD_SELECT ||
- cmd.action == LFUN_CHAR_RIGHT_SELECT ||
- cmd.action == LFUN_CHAR_LEFT_SELECT;
+ bool const select = act == LFUN_CHAR_FORWARD_SELECT ||
+ act == LFUN_CHAR_BACKWARD_SELECT ||
+ act == LFUN_CHAR_RIGHT_SELECT ||
+ act == LFUN_CHAR_LEFT_SELECT;
// If we have a multicell selection or we're
// not doing some LFUN_*_SELECT thing anyway...
// if our Text didn't do anything to the cursor
// then we try to put the cursor into the cell below
// setting also the right targetX.
- cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
+ cur.selHandle(act == LFUN_DOWN_SELECT);
if (tabular.cellRow(cur.idx()) != tabular.nrows() - 1) {
cur.idx() = tabular.cellBelow(cur.idx());
cur.pit() = 0;
// if our Text didn't do anything to the cursor
// then we try to put the cursor into the cell above
// setting also the right targetX.
- cur.selHandle(cmd.action == LFUN_UP_SELECT);
+ cur.selHandle(act == LFUN_UP_SELECT);
if (tabular.cellRow(cur.idx()) != 0) {
cur.idx() = tabular.cellAbove(cur.idx());
cur.pit() = cur.lastpit();
case LFUN_CLIPBOARD_PASTE:
case LFUN_PRIMARY_SELECTION_PASTE: {
- docstring const clip = (cmd.action == LFUN_CLIPBOARD_PASTE) ?
+ docstring const clip = (act == LFUN_CLIPBOARD_PASTE) ?
theClipboard().getAsText() :
theSelection().get();
if (clip.empty())
bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
- switch (cmd.action) {
+ switch (cmd.action()) {
case LFUN_INSET_MODIFY: {
if (&cur.inset() != this || cmd.getArg(0) != "tabular")
break;
}
if (action == Tabular::LAST_ACTION) {
status.clear();
- status.unknown(true);
+ status.setUnknown(true);
return true;
}
case LFUN_BRANCH_INSERT:
case LFUN_PHANTOM_INSERT:
case LFUN_WRAP_INSERT:
+ case LFUN_PREVIEW_INSERT:
case LFUN_ERT_INSERT: {
if (cur.selIsMultiCell()) {
status.setEnabled(false);
break;
case Tabular::SET_SPECIAL_MULTIROW:
- //FIXME: noting to do here?
+ // nothing to do
break;
case Tabular::APPEND_ROW: