#include "cursor.h"
#include "debug.h"
#include "funcrequest.h"
+#include "gettext.h"
#include "undo.h"
#include "frontends/Painter.h"
-#include "support/std_sstream.h"
-
#include "insets/mailinset.h"
+#include "support/lstrings.h"
+
+#include <sstream>
+
+using lyx::support::bformat;
+
using std::endl;
using std::max;
using std::min;
MathGridInset::ColInfo::ColInfo()
- : align_('c'), leftline_(false), rightline_(false), lines_(0)
+ : align_('c'), lines_(0)
{}
}
-auto_ptr<InsetBase> MathGridInset::clone() const
+auto_ptr<InsetBase> MathGridInset::doClone() const
{
return auto_ptr<InsetBase>(new MathGridInset(*this));
}
{
col_type col = 0;
for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
- if (col >= ncols())
- break;
char c = *it;
if (c == '|') {
colinfo_[col].lines_++;
+ } else if (col >= ncols()) {
+ // Only '|' is allowed in the last dummy column
+ break;
} else if (c == 'c' || c == 'l' || c == 'r') {
colinfo_[col].align_ = c;
++col;
void MathGridInset::draw(PainterInfo & pi, int x, int y) const
+{
+ drawWithMargin(pi, x, y, 0, 0);
+}
+
+void MathGridInset::drawWithMargin(PainterInfo & pi, int x, int y,
+ int lmargin, int rmargin) const
{
for (idx_type idx = 0; idx < nargs(); ++idx)
- cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
+ cell(idx).draw(pi, x + lmargin + cellXOffset(idx),
+ y + cellYOffset(idx));
for (row_type row = 0; row <= nrows(); ++row)
- for (int i = 0; i < rowinfo_[row].lines_; ++i) {
+ for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
- i * hlinesep() - hlinesep()/2 - rowsep()/2;
- pi.pain.line(x + 1, yy,
- x + dim_.width() - 1, yy,
+ pi.pain.line(x + lmargin + 1, yy,
+ x + dim_.width() - rmargin - 1, yy,
LColor::foreground);
}
for (col_type col = 0; col <= ncols(); ++col)
- for (int i = 0; i < colinfo_[col].lines_; ++i) {
- int xx = x + colinfo_[col].offset_
+ for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
+ int xx = x + lmargin + colinfo_[col].offset_
- i * vlinesep() - vlinesep()/2 - colsep()/2;
pi.pain.line(xx, y - dim_.ascent() + 1,
xx, y + dim_.descent() - 1,
}
-void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
+void MathGridInset::doDispatch(LCursor & cur, FuncRequest & cmd)
{
//lyxerr << "*** MathGridInset: request: " << cmd << endl;
switch (cmd.action) {
// GridInsetMailer(*this).showDialog();
// return DispatchResult(true, true);
//}
- MathNestInset::priv_dispatch(cur, cmd);
+ MathNestInset::doDispatch(cur, cmd);
break;
case LFUN_INSET_DIALOG_UPDATE:
else if (s == "valign-bottom")
valign('b');
else if (s == "align-left")
- halign('l', col(cur.idx()));
+ halign('l', cur.col());
else if (s == "align-right")
- halign('r', col(cur.idx()));
+ halign('r', cur.col());
else if (s == "align-center")
- halign('c', col(cur.idx()));
+ halign('c', cur.col());
else if (s == "append-row")
for (int i = 0, n = extractInt(is); i < n; ++i)
addRow(cur.row());
copyRow(cur.row());
else if (s == "swap-row")
swapRow(cur.row());
+ else if (s == "add-hline-above")
+ rowinfo_[cur.row()].lines_++;
+ else if (s == "add-hline-below")
+ rowinfo_[cur.row()+1].lines_++;
+ else if (s == "delete-hline-above")
+ rowinfo_[cur.row()].lines_--;
+ else if (s == "delete-hline-below")
+ rowinfo_[cur.row()+1].lines_--;
else if (s == "append-column")
for (int i = 0, n = extractInt(is); i < n; ++i) {
- row_type r = cur.row();
- col_type c = col(cur.idx());
+ row_type const r = cur.row();
+ col_type const c = cur.col();
addCol(c);
cur.idx() = index(r, c);
}
else if (s == "delete-column")
for (int i = 0, n = extractInt(is); i < n; ++i) {
- row_type r = cur.row();
- col_type c = col(cur.idx());
+ row_type const r = cur.row();
+ col_type const c = cur.col();
delCol(col(cur.idx()));
cur.idx() = index(r, c);
if (cur.idx() > nargs())
cur.idx() -= ncols();
}
else if (s == "copy-column")
- copyCol(col(cur.idx()));
+ copyCol(cur.col());
else if (s == "swap-column")
- swapCol(col(cur.idx()));
+ swapCol(cur.col());
+ else if (s == "add-vline-left")
+ colinfo_[cur.col()].lines_++;
+ else if (s == "add-vline-right")
+ colinfo_[cur.col()+1].lines_++;
+ else if (s == "delete-vline-left")
+ colinfo_[cur.col()].lines_--;
+ else if (s == "delete-vline-right")
+ colinfo_[cur.col()+1].lines_--;
else {
cur.undispatched();
break;
break;
default:
- MathNestInset::priv_dispatch(cur, cmd);
+ MathNestInset::doDispatch(cur, cmd);
}
}
bool MathGridInset::getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
- bool ret = true;
switch (cmd.action) {
- case LFUN_TABULAR_FEATURE:
+ case LFUN_TABULAR_FEATURE: {
+ string const s = cmd.argument;
+ if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
+ flag.enabled(false);
+ flag.message(N_("Only one row"));
+ return true;
+ }
+ if (ncols() <= 1 &&
+ (s == "delete-column" || s == "swap-column")) {
+ flag.enabled(false);
+ flag.message(N_("Only one column"));
+ return true;
+ }
+ if ((rowinfo_[cur.row()].lines_ == 0 &&
+ s == "delete-hline-above") ||
+ (rowinfo_[cur.row() + 1].lines_ == 0 &&
+ s == "delete-hline-below")) {
+ flag.enabled(false);
+ flag.message(N_("No hline to delete"));
+ return true;
+ }
+
+ if ((colinfo_[cur.col()].lines_ == 0 &&
+ s == "delete-vline-left") ||
+ (colinfo_[cur.col() + 1].lines_ == 0 &&
+ s == "delete-vline-right")) {
+ flag.enabled(false);
+ flag.message(N_("No vline to delete"));
+ return true;
+ }
+ if (s == "valign-top" || s == "valign-middle" ||
+ s == "valign-bottom" || s == "align-left" ||
+ s == "align-right" || s == "align-center" ||
+ s == "append-row" || s == "delete-row" ||
+ s == "copy-row" || s == "swap-row" ||
+ s == "add-hline-above" || s == "add-hline-below" ||
+ s == "delete-hline-above" || s == "delete-hline-below" ||
+ s == "append-column" || s == "delete-column" ||
+ s == "copy-column" || s == "swap-column" ||
+ s == "add-vline-left" || s == "add-vline-right" ||
+ s == "delete-vline-left" || s == "delete-vline-right")
+ flag.enabled(true);
+ else {
+ flag.enabled(false);
+ flag.message(bformat(
+ N_("Unknown tabular feature '%1$s'"), s));
+ }
#if 0
+ // FIXME: What did this code do?
+ // Please check wether it is still needed!
// should be more precise
if (v_align_ == '\0') {
flag.enable(true);
flag.enable(false);
break;
}
- if (!contains("tcb", cmd.argument[0])) {
+ if (!lyx::support::contains("tcb", cmd.argument[0])) {
flag.enable(false);
break;
}
flag.setOnOff(cmd.argument[0] == v_align_);
+ flag.enabled(true);
#endif
+ return true;
+ }
+ case LFUN_CELL_SPLIT:
flag.enabled(true);
- break;
+ return true;
default:
- ret = MathNestInset::getStatus(cur, cmd, flag);
- break;
+ return MathNestInset::getStatus(cur, cmd, flag);
}
- return ret;
}