#include <config.h>
+#include "BufferView.h"
#include "ControlTabular.h"
+#include "cursor.h"
#include "funcrequest.h"
#include "lyxrc.h"
#include "paragraph.h"
#include "insets/insettabular.h"
-#include "support/LAssert.h"
-using namespace lyx::support;
+using std::string;
+
+namespace lyx {
+namespace frontend {
ControlTabular::ControlTabular(Dialog & parent)
- : Dialog::Controller(parent), active_cell_(-1)
+ : Dialog::Controller(parent), active_cell_(LyXTabular::npos)
{}
bool ControlTabular::initialiseParams(string const & data)
{
- Buffer & buffer = kernel().buffer();
-
- InsetTabular tmp(buffer);
- int cell = InsetTabularMailer::string2params(data, tmp);
- if (cell != -1) {
- params_.reset(new LyXTabular(tmp.tabular));
- active_cell_ = cell;
+ // try to get the current cell
+ BufferView const * const bv = kernel().bufferview();
+ if (bv) {
+ LCursor const & cur = bv->cursor();
+ // get the innermost tabular inset;
+ // assume that it is "ours"
+ for (int i = cur.depth() - 1; i >= 0; --i)
+ if (cur[i].inset().lyxCode() == InsetBase::TABULAR_CODE) {
+ active_cell_ = cur[i].idx();
+ break;
+ }
}
+ InsetTabular tmp(kernel().buffer());
+ InsetTabularMailer::string2params(data, tmp);
+ params_.reset(new LyXTabular(tmp.tabular));
return true;
}
void ControlTabular::clearParams()
{
params_.reset();
- active_cell_ = -1;
+ active_cell_ = LyXTabular::npos;
}
-int ControlTabular::getActiveCell() const
+LyXTabular::idx_type ControlTabular::getActiveCell() const
{
return active_cell_;
}
LyXTabular const & ControlTabular::tabular() const
{
- Assert(params_.get());
+ BOOST_ASSERT(params_.get());
return *params_.get();
}
void ControlTabular::set(LyXTabular::Feature f, string const & arg)
{
string const data = featureAsString(f) + ' ' + arg;
- kernel().dispatch(FuncRequest(LFUN_TABULAR_FEATURE, data));
+ kernel().dispatch(FuncRequest(getLfun(), data));
}
bool ControlTabular::useMetricUnits() const
{
- return lyxrc.default_papersize > PAPER_EXECUTIVEPAPER;
+ return lyxrc.default_papersize > PAPER_USEXECUTIVE;
}
else
set(LyXTabular::UNSET_LONGTABULAR);
}
+
+} // namespace frontend
+} // namespace lyx