-// -*- C++ -*-
/**
* \file ControlTabular.C
* This file is part of LyX, the document processor.
*
* \author John Levon
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#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 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();
- if (!buffer)
- return false;
-
- 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
{
- lyx::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 > BufferParams::PAPER_EXECUTIVEPAPER;
+ return lyxrc.default_papersize > PAPER_USEXECUTIVE;
}
void ControlTabular::valign(ControlTabular::VALIGN v)
{
- LyXTabular::Feature num = LyXTabular::VALIGN_CENTER;
- LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_CENTER;
+ LyXTabular::Feature num = LyXTabular::VALIGN_MIDDLE;
+ LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_MIDDLE;
switch (v) {
case TOP:
num = LyXTabular::VALIGN_TOP;
multi_num = LyXTabular::M_VALIGN_TOP;
break;
- case VCENTER:
- num = LyXTabular::VALIGN_CENTER;
- multi_num = LyXTabular::M_VALIGN_CENTER;
+ case MIDDLE:
+ num = LyXTabular::VALIGN_MIDDLE;
+ multi_num = LyXTabular::M_VALIGN_MIDDLE;
break;
case BOTTOM:
num = LyXTabular::VALIGN_BOTTOM;
else
set(LyXTabular::UNSET_LONGTABULAR);
}
+
+} // namespace frontend
+} // namespace lyx