2002-11-15 02:41:54 +00:00
|
|
|
/**
|
|
|
|
* \file ControlTabular.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-11-15 02:41:54 +00:00
|
|
|
*/
|
|
|
|
|
2003-03-09 18:11:57 +00:00
|
|
|
#include <config.h>
|
2002-11-15 02:41:54 +00:00
|
|
|
|
2004-11-18 12:58:19 +00:00
|
|
|
#include "BufferView.h"
|
2003-03-09 18:11:57 +00:00
|
|
|
#include "ControlTabular.h"
|
2004-11-18 12:58:19 +00:00
|
|
|
#include "cursor.h"
|
2003-03-09 18:11:57 +00:00
|
|
|
#include "funcrequest.h"
|
2002-11-15 02:41:54 +00:00
|
|
|
#include "lyxrc.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
#include "paragraph.h"
|
2002-12-01 22:59:25 +00:00
|
|
|
#include "insets/insettabular.h"
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2002-11-15 02:41:54 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2003-03-09 18:11:57 +00:00
|
|
|
ControlTabular::ControlTabular(Dialog & parent)
|
|
|
|
: Dialog::Controller(parent), active_cell_(-1)
|
2002-11-15 02:41:54 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
bool ControlTabular::initialiseParams(string const & data)
|
2002-11-15 02:41:54 +00:00
|
|
|
{
|
2004-11-18 12:58:19 +00:00
|
|
|
// 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.size() - 1; i >= 0; --i)
|
|
|
|
if (cur[i].inset().lyxCode() == InsetBase::TABULAR_CODE) {
|
|
|
|
active_cell_ = cur[i].idx();
|
|
|
|
break;
|
|
|
|
}
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
2004-11-18 12:58:19 +00:00
|
|
|
InsetTabular tmp(kernel().buffer());
|
|
|
|
InsetTabularMailer::string2params(data, tmp);
|
|
|
|
params_.reset(new LyXTabular(tmp.tabular));
|
2003-03-14 00:20:42 +00:00
|
|
|
return true;
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-09 18:11:57 +00:00
|
|
|
void ControlTabular::clearParams()
|
2002-11-15 02:41:54 +00:00
|
|
|
{
|
2003-03-09 18:11:57 +00:00
|
|
|
params_.reset();
|
|
|
|
active_cell_ = -1;
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-09 18:11:57 +00:00
|
|
|
int ControlTabular::getActiveCell() const
|
2002-11-15 02:41:54 +00:00
|
|
|
{
|
2003-03-09 18:11:57 +00:00
|
|
|
return active_cell_;
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
|
|
|
2003-03-09 10:08:22 +00:00
|
|
|
LyXTabular const & ControlTabular::tabular() const
|
2002-11-15 02:41:54 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(params_.get());
|
2003-03-09 18:11:57 +00:00
|
|
|
return *params_.get();
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-11-15 02:41:54 +00:00
|
|
|
void ControlTabular::set(LyXTabular::Feature f, string const & arg)
|
|
|
|
{
|
2003-03-09 18:11:57 +00:00
|
|
|
string const data = featureAsString(f) + ' ' + arg;
|
|
|
|
kernel().dispatch(FuncRequest(LFUN_TABULAR_FEATURE, data));
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2003-03-09 10:08:22 +00:00
|
|
|
bool ControlTabular::useMetricUnits() const
|
2002-11-15 02:41:54 +00:00
|
|
|
{
|
2003-07-26 23:04:39 +00:00
|
|
|
return lyxrc.default_papersize > PAPER_EXECUTIVEPAPER;
|
2002-11-15 02:41:54 +00:00
|
|
|
}
|
2003-04-10 20:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::toggleTopLine()
|
|
|
|
{
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(LyXTabular::M_TOGGLE_LINE_TOP);
|
|
|
|
else
|
|
|
|
set(LyXTabular::TOGGLE_LINE_TOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::toggleBottomLine()
|
|
|
|
{
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(LyXTabular::M_TOGGLE_LINE_BOTTOM);
|
|
|
|
else
|
|
|
|
set(LyXTabular::TOGGLE_LINE_BOTTOM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::toggleLeftLine()
|
|
|
|
{
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(LyXTabular::M_TOGGLE_LINE_LEFT);
|
|
|
|
else
|
|
|
|
set(LyXTabular::TOGGLE_LINE_LEFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::toggleRightLine()
|
|
|
|
{
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(LyXTabular::M_TOGGLE_LINE_RIGHT);
|
|
|
|
else
|
|
|
|
set(LyXTabular::TOGGLE_LINE_RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::setSpecial(string const & special)
|
|
|
|
{
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(LyXTabular::SET_SPECIAL_MULTI, special);
|
|
|
|
else
|
|
|
|
set(LyXTabular::SET_SPECIAL_COLUMN, special);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::setWidth(string const & width)
|
|
|
|
{
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(LyXTabular::SET_MPWIDTH, width);
|
|
|
|
else
|
|
|
|
set(LyXTabular::SET_PWIDTH, width);
|
|
|
|
|
|
|
|
dialog().view().update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::toggleMultiColumn()
|
|
|
|
{
|
|
|
|
set(LyXTabular::MULTICOLUMN);
|
|
|
|
dialog().view().update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::rotateTabular(bool yes)
|
|
|
|
{
|
|
|
|
if (yes)
|
|
|
|
set(LyXTabular::SET_ROTATE_TABULAR);
|
|
|
|
else
|
|
|
|
set(LyXTabular::UNSET_ROTATE_TABULAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::rotateCell(bool yes)
|
|
|
|
{
|
|
|
|
if (yes)
|
|
|
|
set(LyXTabular::SET_ROTATE_CELL);
|
|
|
|
else
|
|
|
|
set(LyXTabular::UNSET_ROTATE_CELL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::halign(ControlTabular::HALIGN h)
|
|
|
|
{
|
|
|
|
LyXTabular::Feature num = LyXTabular::ALIGN_LEFT;
|
|
|
|
LyXTabular::Feature multi_num = LyXTabular::M_ALIGN_LEFT;
|
|
|
|
|
|
|
|
switch (h) {
|
|
|
|
case LEFT:
|
|
|
|
num = LyXTabular::ALIGN_LEFT;
|
|
|
|
multi_num = LyXTabular::M_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case CENTER:
|
|
|
|
num = LyXTabular::ALIGN_CENTER;
|
|
|
|
multi_num = LyXTabular::M_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
num = LyXTabular::ALIGN_RIGHT;
|
|
|
|
multi_num = LyXTabular::M_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case BLOCK:
|
|
|
|
num = LyXTabular::ALIGN_BLOCK;
|
|
|
|
//multi_num: no equivalent
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(multi_num);
|
|
|
|
else
|
|
|
|
set(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::valign(ControlTabular::VALIGN v)
|
|
|
|
{
|
2003-08-14 15:45:09 +00:00
|
|
|
LyXTabular::Feature num = LyXTabular::VALIGN_MIDDLE;
|
|
|
|
LyXTabular::Feature multi_num = LyXTabular::M_VALIGN_MIDDLE;
|
2003-04-10 20:20:36 +00:00
|
|
|
|
|
|
|
switch (v) {
|
|
|
|
case TOP:
|
|
|
|
num = LyXTabular::VALIGN_TOP;
|
|
|
|
multi_num = LyXTabular::M_VALIGN_TOP;
|
|
|
|
break;
|
2003-08-14 15:45:09 +00:00
|
|
|
case MIDDLE:
|
|
|
|
num = LyXTabular::VALIGN_MIDDLE;
|
|
|
|
multi_num = LyXTabular::M_VALIGN_MIDDLE;
|
2003-04-10 20:20:36 +00:00
|
|
|
break;
|
|
|
|
case BOTTOM:
|
|
|
|
num = LyXTabular::VALIGN_BOTTOM;
|
|
|
|
multi_num = LyXTabular::M_VALIGN_BOTTOM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-06-12 11:52:44 +00:00
|
|
|
if (tabular().isMultiColumn(getActiveCell()))
|
2003-04-10 20:20:36 +00:00
|
|
|
set(multi_num);
|
|
|
|
else
|
|
|
|
set(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlTabular::longTabular(bool yes)
|
|
|
|
{
|
|
|
|
if (yes)
|
|
|
|
set(LyXTabular::SET_LONGTABULAR);
|
|
|
|
else
|
|
|
|
set(LyXTabular::UNSET_LONGTABULAR);
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|