2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetTabular.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2007-04-26 12:54:21 +00:00
|
|
|
* \author Matthias Ettrich
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author José Matos
|
2007-04-26 12:54:21 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
|
|
|
* \author Jürgen Vigna
|
2009-07-13 23:25:47 +00:00
|
|
|
* \author Uwe Stöhr
|
2000-04-19 14:42:19 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-04-19 14:42:19 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetTabular.h"
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-10-03 20:18:58 +00:00
|
|
|
#include "Buffer.h"
|
2007-04-26 12:54:21 +00:00
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
2007-10-03 20:18:58 +00:00
|
|
|
#include "CoordCache.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 12:54:21 +00:00
|
|
|
#include "CutAndPaste.h"
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "Language.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "Lexer.h"
|
2007-10-22 22:18:52 +00:00
|
|
|
#include "LyXFunc.h"
|
2008-03-15 12:22:28 +00:00
|
|
|
#include "LyXRC.h"
|
2007-04-26 12:54:21 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2007-10-03 20:18:58 +00:00
|
|
|
#include "Paragraph.h"
|
2007-04-26 12:54:21 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "ParIterator.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2007-10-11 09:59:01 +00:00
|
|
|
#include "TextMetrics.h"
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "frontends/Application.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "frontends/alert.h"
|
2007-04-26 12:54:21 +00:00
|
|
|
#include "frontends/Clipboard.h"
|
|
|
|
#include "frontends/Painter.h"
|
|
|
|
#include "frontends/Selection.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/convert.h"
|
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/docstream.h"
|
|
|
|
#include "support/FileName.h"
|
|
|
|
#include "support/gettext.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/lassert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2007-10-25 12:41:02 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <limits>
|
2008-02-07 17:04:06 +00:00
|
|
|
#include <cstring>
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2007-07-17 17:33:36 +00:00
|
|
|
using boost::shared_ptr;
|
|
|
|
using boost::dynamic_pointer_cast;
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
2007-07-17 17:33:36 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
using cap::dirtyTabularStack;
|
|
|
|
using cap::tabularStackDirty;
|
|
|
|
|
|
|
|
using graphics::PreviewLoader;
|
|
|
|
|
|
|
|
using frontend::Painter;
|
|
|
|
using frontend::Clipboard;
|
|
|
|
|
|
|
|
namespace Alert = frontend::Alert;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
int const ADD_TO_HEIGHT = 2; // in cell
|
|
|
|
int const ADD_TO_TABULAR_WIDTH = 6; // horiz space before and after the table
|
|
|
|
int const default_line_space = 10; // ?
|
|
|
|
int const WIDTH_OF_LINE = 5; // space between double lines
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
boost::scoped_ptr<Tabular> paste_tabular;
|
|
|
|
|
|
|
|
|
|
|
|
struct TabularFeature {
|
|
|
|
Tabular::Feature action;
|
|
|
|
string feature;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TabularFeature tabularFeature[] =
|
|
|
|
{
|
|
|
|
{ Tabular::APPEND_ROW, "append-row" },
|
|
|
|
{ Tabular::APPEND_COLUMN, "append-column" },
|
|
|
|
{ Tabular::DELETE_ROW, "delete-row" },
|
|
|
|
{ Tabular::DELETE_COLUMN, "delete-column" },
|
|
|
|
{ Tabular::COPY_ROW, "copy-row" },
|
|
|
|
{ Tabular::COPY_COLUMN, "copy-column" },
|
|
|
|
{ Tabular::TOGGLE_LINE_TOP, "toggle-line-top" },
|
|
|
|
{ Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
|
|
|
|
{ Tabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
|
|
|
|
{ Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
|
|
|
|
{ Tabular::ALIGN_LEFT, "align-left" },
|
|
|
|
{ Tabular::ALIGN_RIGHT, "align-right" },
|
|
|
|
{ Tabular::ALIGN_CENTER, "align-center" },
|
|
|
|
{ Tabular::ALIGN_BLOCK, "align-block" },
|
|
|
|
{ Tabular::VALIGN_TOP, "valign-top" },
|
|
|
|
{ Tabular::VALIGN_BOTTOM, "valign-bottom" },
|
|
|
|
{ Tabular::VALIGN_MIDDLE, "valign-middle" },
|
|
|
|
{ Tabular::M_ALIGN_LEFT, "m-align-left" },
|
|
|
|
{ Tabular::M_ALIGN_RIGHT, "m-align-right" },
|
|
|
|
{ Tabular::M_ALIGN_CENTER, "m-align-center" },
|
|
|
|
{ Tabular::M_VALIGN_TOP, "m-valign-top" },
|
|
|
|
{ Tabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
|
|
|
|
{ Tabular::M_VALIGN_MIDDLE, "m-valign-middle" },
|
|
|
|
{ Tabular::MULTICOLUMN, "multicolumn" },
|
|
|
|
{ Tabular::SET_ALL_LINES, "set-all-lines" },
|
|
|
|
{ Tabular::UNSET_ALL_LINES, "unset-all-lines" },
|
|
|
|
{ Tabular::SET_LONGTABULAR, "set-longtabular" },
|
|
|
|
{ Tabular::UNSET_LONGTABULAR, "unset-longtabular" },
|
|
|
|
{ Tabular::SET_PWIDTH, "set-pwidth" },
|
|
|
|
{ Tabular::SET_MPWIDTH, "set-mpwidth" },
|
|
|
|
{ Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
|
|
|
|
{ Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
|
2007-05-12 20:59:21 +00:00
|
|
|
{ Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular" },
|
2007-04-26 12:54:21 +00:00
|
|
|
{ Tabular::SET_ROTATE_CELL, "set-rotate-cell" },
|
|
|
|
{ Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
|
2007-05-12 20:59:21 +00:00
|
|
|
{ Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell" },
|
2007-04-26 12:54:21 +00:00
|
|
|
{ Tabular::SET_USEBOX, "set-usebox" },
|
|
|
|
{ Tabular::SET_LTHEAD, "set-lthead" },
|
|
|
|
{ Tabular::UNSET_LTHEAD, "unset-lthead" },
|
|
|
|
{ Tabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
|
|
|
|
{ Tabular::UNSET_LTFIRSTHEAD, "unset-ltfirsthead" },
|
|
|
|
{ Tabular::SET_LTFOOT, "set-ltfoot" },
|
|
|
|
{ Tabular::UNSET_LTFOOT, "unset-ltfoot" },
|
|
|
|
{ Tabular::SET_LTLASTFOOT, "set-ltlastfoot" },
|
|
|
|
{ Tabular::UNSET_LTLASTFOOT, "unset-ltlastfoot" },
|
|
|
|
{ Tabular::SET_LTNEWPAGE, "set-ltnewpage" },
|
2008-05-04 07:51:50 +00:00
|
|
|
{ Tabular::TOGGLE_LTCAPTION, "toggle-ltcaption" },
|
2007-04-26 12:54:21 +00:00
|
|
|
{ Tabular::SET_SPECIAL_COLUMN, "set-special-column" },
|
|
|
|
{ Tabular::SET_SPECIAL_MULTI, "set-special-multi" },
|
|
|
|
{ Tabular::SET_BOOKTABS, "set-booktabs" },
|
|
|
|
{ Tabular::UNSET_BOOKTABS, "unset-booktabs" },
|
|
|
|
{ Tabular::SET_TOP_SPACE, "set-top-space" },
|
|
|
|
{ Tabular::SET_BOTTOM_SPACE, "set-bottom-space" },
|
|
|
|
{ Tabular::SET_INTERLINE_SPACE, "set-interline-space" },
|
2008-03-20 08:45:40 +00:00
|
|
|
{ Tabular::SET_BORDER_LINES, "set-border-lines" },
|
2009-01-03 18:33:09 +00:00
|
|
|
{ Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top"},
|
|
|
|
{ Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle"},
|
|
|
|
{ Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom"},
|
2009-07-11 13:09:45 +00:00
|
|
|
{ Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left" },
|
|
|
|
{ Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center" },
|
|
|
|
{ Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right" },
|
2007-04-26 12:54:21 +00:00
|
|
|
{ Tabular::LAST_ACTION, "" }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
class FeatureEqual : public unary_function<TabularFeature, bool> {
|
2007-04-26 12:54:21 +00:00
|
|
|
public:
|
|
|
|
FeatureEqual(Tabular::Feature feature)
|
|
|
|
: feature_(feature) {}
|
|
|
|
bool operator()(TabularFeature const & tf) const {
|
|
|
|
return tf.action == feature_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Tabular::Feature feature_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
string const write_attribute(string const & name, T const & t)
|
|
|
|
{
|
|
|
|
string const s = tostr(t);
|
|
|
|
return s.empty() ? s : " " + name + "=\"" + s + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
string const write_attribute(string const & name, string const & t)
|
|
|
|
{
|
|
|
|
return t.empty() ? t : " " + name + "=\"" + t + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
string const write_attribute(string const & name, docstring const & t)
|
|
|
|
{
|
|
|
|
return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
string const write_attribute(string const & name, bool const & b)
|
|
|
|
{
|
|
|
|
// we write only true attribute values so we remove a bit of the
|
|
|
|
// file format bloat for tabulars.
|
|
|
|
return b ? write_attribute(name, convert<string>(b)) : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
string const write_attribute(string const & name, int const & i)
|
|
|
|
{
|
|
|
|
// we write only true attribute values so we remove a bit of the
|
|
|
|
// file format bloat for tabulars.
|
|
|
|
return i ? write_attribute(name, convert<string>(i)) : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
string const write_attribute(string const & name, Tabular::idx_type const & i)
|
|
|
|
{
|
|
|
|
// we write only true attribute values so we remove a bit of the
|
|
|
|
// file format bloat for tabulars.
|
|
|
|
return i ? write_attribute(name, convert<string>(i)) : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
2007-04-28 12:58:49 +00:00
|
|
|
string const write_attribute(string const & name, Length const & value)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
// we write only the value if we really have one same reson as above.
|
|
|
|
return value.zero() ? string() : write_attribute(name, value.asString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const tostr(LyXAlignment const & num)
|
|
|
|
{
|
|
|
|
switch (num) {
|
|
|
|
case LYX_ALIGN_NONE:
|
|
|
|
return "none";
|
|
|
|
case LYX_ALIGN_BLOCK:
|
|
|
|
return "block";
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
return "left";
|
|
|
|
case LYX_ALIGN_CENTER:
|
|
|
|
return "center";
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
return "right";
|
|
|
|
case LYX_ALIGN_LAYOUT:
|
|
|
|
return "layout";
|
|
|
|
case LYX_ALIGN_SPECIAL:
|
|
|
|
return "special";
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
string const tostr(Tabular::HAlignment const & num)
|
|
|
|
{
|
|
|
|
switch (num) {
|
|
|
|
case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
|
|
|
|
return "left";
|
|
|
|
case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
|
|
|
|
return "center";
|
|
|
|
case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
|
|
|
|
return "right";
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
string const tostr(Tabular::VAlignment const & num)
|
|
|
|
{
|
|
|
|
switch (num) {
|
|
|
|
case Tabular::LYX_VALIGN_TOP:
|
|
|
|
return "top";
|
|
|
|
case Tabular::LYX_VALIGN_MIDDLE:
|
|
|
|
return "middle";
|
|
|
|
case Tabular::LYX_VALIGN_BOTTOM:
|
|
|
|
return "bottom";
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const tostr(Tabular::BoxType const & num)
|
|
|
|
{
|
|
|
|
switch (num) {
|
|
|
|
case Tabular::BOX_NONE:
|
|
|
|
return "none";
|
|
|
|
case Tabular::BOX_PARBOX:
|
|
|
|
return "parbox";
|
|
|
|
case Tabular::BOX_MINIPAGE:
|
|
|
|
return "minipage";
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// I would have liked a fromstr template a lot better. (Lgb)
|
|
|
|
bool string2type(string const str, LyXAlignment & num)
|
|
|
|
{
|
|
|
|
if (str == "none")
|
|
|
|
num = LYX_ALIGN_NONE;
|
|
|
|
else if (str == "block")
|
|
|
|
num = LYX_ALIGN_BLOCK;
|
|
|
|
else if (str == "left")
|
|
|
|
num = LYX_ALIGN_LEFT;
|
|
|
|
else if (str == "center")
|
|
|
|
num = LYX_ALIGN_CENTER;
|
|
|
|
else if (str == "right")
|
|
|
|
num = LYX_ALIGN_RIGHT;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
bool string2type(string const str, Tabular::HAlignment & num)
|
|
|
|
{
|
|
|
|
if (str == "left")
|
|
|
|
num = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
|
|
|
|
else if (str == "center" )
|
|
|
|
num = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
|
|
|
|
else if (str == "right")
|
|
|
|
num = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
bool string2type(string const str, Tabular::VAlignment & num)
|
|
|
|
{
|
|
|
|
if (str == "top")
|
|
|
|
num = Tabular::LYX_VALIGN_TOP;
|
|
|
|
else if (str == "middle" )
|
|
|
|
num = Tabular::LYX_VALIGN_MIDDLE;
|
|
|
|
else if (str == "bottom")
|
|
|
|
num = Tabular::LYX_VALIGN_BOTTOM;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool string2type(string const str, Tabular::BoxType & num)
|
|
|
|
{
|
|
|
|
if (str == "none")
|
|
|
|
num = Tabular::BOX_NONE;
|
|
|
|
else if (str == "parbox")
|
|
|
|
num = Tabular::BOX_PARBOX;
|
|
|
|
else if (str == "minipage")
|
|
|
|
num = Tabular::BOX_MINIPAGE;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool string2type(string const str, bool & num)
|
|
|
|
{
|
|
|
|
if (str == "true")
|
|
|
|
num = true;
|
|
|
|
else if (str == "false")
|
|
|
|
num = false;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getTokenValue(string const & str, char const * token, string & ret)
|
|
|
|
{
|
|
|
|
ret.erase();
|
|
|
|
size_t token_length = strlen(token);
|
2008-02-27 23:03:26 +00:00
|
|
|
size_t pos = str.find(token);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
if (pos == string::npos || pos + token_length + 1 >= str.length()
|
|
|
|
|| str[pos + token_length] != '=')
|
|
|
|
return false;
|
|
|
|
pos += token_length + 1;
|
|
|
|
char ch = str[pos];
|
|
|
|
if (ch != '"' && ch != '\'') { // only read till next space
|
|
|
|
ret += ch;
|
|
|
|
ch = ' ';
|
|
|
|
}
|
|
|
|
while (pos < str.length() - 1 && str[++pos] != ch)
|
|
|
|
ret += str[pos];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getTokenValue(string const & str, char const * token, docstring & ret)
|
|
|
|
{
|
|
|
|
string tmp;
|
|
|
|
bool const success = getTokenValue(str, token, tmp);
|
|
|
|
ret = from_utf8(tmp);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getTokenValue(string const & str, char const * token, int & num)
|
|
|
|
{
|
|
|
|
string tmp;
|
|
|
|
num = 0;
|
|
|
|
if (!getTokenValue(str, token, tmp))
|
|
|
|
return false;
|
|
|
|
num = convert<int>(tmp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
|
|
|
|
{
|
|
|
|
string tmp;
|
|
|
|
return getTokenValue(str, token, tmp) && string2type(tmp, num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
bool getTokenValue(string const & str, char const * token,
|
|
|
|
Tabular::HAlignment & num)
|
|
|
|
{
|
|
|
|
string tmp;
|
|
|
|
return getTokenValue(str, token, tmp) && string2type(tmp, num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
bool getTokenValue(string const & str, char const * token,
|
|
|
|
Tabular::VAlignment & num)
|
|
|
|
{
|
|
|
|
string tmp;
|
|
|
|
return getTokenValue(str, token, tmp) && string2type(tmp, num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getTokenValue(string const & str, char const * token,
|
|
|
|
Tabular::BoxType & num)
|
|
|
|
{
|
|
|
|
string tmp;
|
|
|
|
return getTokenValue(str, token, tmp) && string2type(tmp, num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getTokenValue(string const & str, char const * token, bool & flag)
|
|
|
|
{
|
|
|
|
// set the flag always to false as this should be the default for bools
|
|
|
|
// not in the file-format.
|
|
|
|
flag = false;
|
|
|
|
string tmp;
|
|
|
|
return getTokenValue(str, token, tmp) && string2type(tmp, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool getTokenValue(string const & str, char const * token, Length & len)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-27 20:19:06 +00:00
|
|
|
// set the length to be zero() as default as this it should be if not
|
2007-04-26 12:54:21 +00:00
|
|
|
// in the file format.
|
2007-04-28 12:58:49 +00:00
|
|
|
len = Length();
|
2007-04-26 12:54:21 +00:00
|
|
|
string tmp;
|
|
|
|
return getTokenValue(str, token, tmp) && isValidLength(tmp, &len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
bool getTokenValue(string const & str, char const * token, Length & len, bool & flag)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-04-28 12:58:49 +00:00
|
|
|
len = Length();
|
2007-04-26 12:54:21 +00:00
|
|
|
flag = false;
|
|
|
|
string tmp;
|
|
|
|
if (!getTokenValue(str, token, tmp))
|
|
|
|
return false;
|
|
|
|
if (tmp == "default") {
|
|
|
|
flag = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isValidLength(tmp, &len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void l_getline(istream & is, string & str)
|
|
|
|
{
|
|
|
|
str.erase();
|
|
|
|
while (str.empty()) {
|
|
|
|
getline(is, str);
|
|
|
|
if (!str.empty() && str[str.length() - 1] == '\r')
|
|
|
|
str.erase(str.length() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
string const featureAsString(Tabular::Feature feature)
|
|
|
|
{
|
|
|
|
TabularFeature * end = tabularFeature +
|
|
|
|
sizeof(tabularFeature) / sizeof(TabularFeature);
|
2007-12-12 19:28:07 +00:00
|
|
|
TabularFeature * it = find_if(tabularFeature, end,
|
2007-04-26 14:56:30 +00:00
|
|
|
FeatureEqual(feature));
|
|
|
|
return (it == end) ? string() : it->feature;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Tabular
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
Tabular::CellData::CellData(Buffer * buf)
|
2007-04-26 12:54:21 +00:00
|
|
|
: cellno(0),
|
2007-09-04 10:52:08 +00:00
|
|
|
width(0),
|
2007-04-26 12:54:21 +00:00
|
|
|
multicolumn(Tabular::CELL_NORMAL),
|
|
|
|
alignment(LYX_ALIGN_CENTER),
|
|
|
|
valignment(LYX_VALIGN_TOP),
|
2008-03-18 18:08:32 +00:00
|
|
|
top_line(false),
|
2007-04-26 12:54:21 +00:00
|
|
|
bottom_line(false),
|
2008-03-18 18:08:32 +00:00
|
|
|
left_line(false),
|
2007-04-26 12:54:21 +00:00
|
|
|
right_line(false),
|
|
|
|
usebox(BOX_NONE),
|
|
|
|
rotate(false),
|
2008-07-16 14:23:32 +00:00
|
|
|
inset(new InsetTableCell(buf))
|
Fix bug 4037 and related problems. The patch has been cleaned up a bit
from the one posted to the list.
The basic idea has two parts. First, we hard code an "empty layout"
(called PlainLayout, for want of a better name) in TextClass and read it
before doing anything else. It can therefore be customized by classes,
if they want---say, to make it left-aligned. Second, InsetText's are
divided into three types: (i) normal ones, that use the "default" layout
defined by the text class; (ii) highly restrictive ones, such as ERT and
(not quite an inset) table cells, which demand the empty layout; (iii)
middling ones, which default to an empty layout and use the empty layout
in place of the default. (This is so we don't get the same problem we
had with ERT in e.g. footnotes.) The type of inset is signaled by new
methods InsetText::forceEmptyLayout() and InsetText::useEmptyLayout().
(The latter might better be called: useEmptyLayoutInsteadOfDefault(),
but that's silly.) The old InsetText::forceDefaultParagraphs() has been
split into these, plus a new method InsetText::allowParagraphCustomization().
A lot of the changes just adapt to this change.
The other big change is in GuiToolbar: We want to show LyXDefault and
the "default" layout only when they're active.
There are a handful of places where I'm not entirely sure whether we
should be using forceEmptyLayout or !allowParagraphCustomization() or
both. The InsetCaption is one of these. These places, and some others,
are marked with FIXMEs, so I'd appreciate it if people would search
through the patch and let me know whether these need changing. If they
don't, the FIXMEs can be deleted.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22966 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-12 17:31:07 +00:00
|
|
|
{
|
2009-11-08 15:53:21 +00:00
|
|
|
inset->setBuffer(*buf);
|
Fix bug 4037 and related problems. The patch has been cleaned up a bit
from the one posted to the list.
The basic idea has two parts. First, we hard code an "empty layout"
(called PlainLayout, for want of a better name) in TextClass and read it
before doing anything else. It can therefore be customized by classes,
if they want---say, to make it left-aligned. Second, InsetText's are
divided into three types: (i) normal ones, that use the "default" layout
defined by the text class; (ii) highly restrictive ones, such as ERT and
(not quite an inset) table cells, which demand the empty layout; (iii)
middling ones, which default to an empty layout and use the empty layout
in place of the default. (This is so we don't get the same problem we
had with ERT in e.g. footnotes.) The type of inset is signaled by new
methods InsetText::forceEmptyLayout() and InsetText::useEmptyLayout().
(The latter might better be called: useEmptyLayoutInsteadOfDefault(),
but that's silly.) The old InsetText::forceDefaultParagraphs() has been
split into these, plus a new method InsetText::allowParagraphCustomization().
A lot of the changes just adapt to this change.
The other big change is in GuiToolbar: We want to show LyXDefault and
the "default" layout only when they're active.
There are a handful of places where I'm not entirely sure whether we
should be using forceEmptyLayout or !allowParagraphCustomization() or
both. The InsetCaption is one of these. These places, and some others,
are marked with FIXMEs, so I'd appreciate it if people would search
through the patch and let me know whether these need changing. If they
don't, the FIXMEs can be deleted.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22966 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-12 17:31:07 +00:00
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:59:44 +00:00
|
|
|
Tabular::CellData::CellData(CellData const & cs)
|
2007-04-26 12:54:21 +00:00
|
|
|
: cellno(cs.cellno),
|
2007-09-04 10:52:08 +00:00
|
|
|
width(cs.width),
|
2007-04-26 12:54:21 +00:00
|
|
|
multicolumn(cs.multicolumn),
|
|
|
|
alignment(cs.alignment),
|
|
|
|
valignment(cs.valignment),
|
|
|
|
top_line(cs.top_line),
|
|
|
|
bottom_line(cs.bottom_line),
|
|
|
|
left_line(cs.left_line),
|
|
|
|
right_line(cs.right_line),
|
|
|
|
usebox(cs.usebox),
|
|
|
|
rotate(cs.rotate),
|
|
|
|
align_special(cs.align_special),
|
|
|
|
p_width(cs.p_width),
|
2008-03-21 17:45:14 +00:00
|
|
|
inset(dynamic_cast<InsetTableCell *>(cs.inset->clone()))
|
2008-07-23 12:13:41 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-02-27 20:59:44 +00:00
|
|
|
Tabular::CellData & Tabular::CellData::operator=(CellData cs)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
swap(cs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-02-27 20:59:44 +00:00
|
|
|
void Tabular::CellData::swap(CellData & rhs)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
std::swap(cellno, rhs.cellno);
|
2007-09-04 10:52:08 +00:00
|
|
|
std::swap(width, rhs.width);
|
2007-04-26 12:54:21 +00:00
|
|
|
std::swap(multicolumn, rhs.multicolumn);
|
|
|
|
std::swap(alignment, rhs.alignment);
|
|
|
|
std::swap(valignment, rhs.valignment);
|
|
|
|
std::swap(top_line, rhs.top_line);
|
|
|
|
std::swap(bottom_line, rhs.bottom_line);
|
|
|
|
std::swap(left_line, rhs.left_line);
|
|
|
|
std::swap(right_line, rhs.right_line);
|
|
|
|
std::swap(usebox, rhs.usebox);
|
|
|
|
std::swap(rotate, rhs.rotate);
|
|
|
|
std::swap(align_special, rhs.align_special);
|
|
|
|
p_width.swap(rhs.p_width);
|
|
|
|
inset.swap(rhs.inset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:59:44 +00:00
|
|
|
Tabular::RowData::RowData()
|
2007-09-04 10:52:08 +00:00
|
|
|
: ascent(0),
|
|
|
|
descent(0),
|
2007-04-26 12:54:21 +00:00
|
|
|
top_space_default(false),
|
|
|
|
bottom_space_default(false),
|
|
|
|
interline_space_default(false),
|
|
|
|
endhead(false),
|
|
|
|
endfirsthead(false),
|
|
|
|
endfoot(false),
|
|
|
|
endlastfoot(false),
|
2008-05-04 07:51:50 +00:00
|
|
|
newpage(false),
|
|
|
|
caption(false)
|
2007-04-26 12:54:21 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-27 20:59:44 +00:00
|
|
|
Tabular::ColumnData::ColumnData()
|
2007-04-26 12:54:21 +00:00
|
|
|
: alignment(LYX_ALIGN_CENTER),
|
|
|
|
valignment(LYX_VALIGN_TOP),
|
2007-09-04 10:52:08 +00:00
|
|
|
width(0)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::ltType::ltType()
|
|
|
|
: topDL(false),
|
|
|
|
bottomDL(false),
|
|
|
|
empty(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
Tabular::Tabular(Buffer * buffer, row_type rows_arg, col_type columns_arg)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
init(buffer, rows_arg, columns_arg);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-23 12:13:41 +00:00
|
|
|
void Tabular::setBuffer(Buffer & buffer)
|
|
|
|
{
|
|
|
|
buffer_ = &buffer;
|
|
|
|
size_t row_count = row_info.size();
|
|
|
|
size_t column_count = column_info.size();
|
|
|
|
// set silly default lines
|
|
|
|
for (row_type i = 0; i < row_count; ++i)
|
|
|
|
for (col_type j = 0; j < column_count; ++j)
|
|
|
|
cell_info[i][j].inset->setBuffer(*buffer_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
// activates all lines and sets all widths to 0
|
2009-11-08 15:53:21 +00:00
|
|
|
void Tabular::init(Buffer * buf, row_type rows_arg,
|
2007-04-26 12:54:21 +00:00
|
|
|
col_type columns_arg)
|
|
|
|
{
|
2009-11-08 15:53:21 +00:00
|
|
|
buffer_ = buf;
|
2007-09-04 10:52:08 +00:00
|
|
|
row_info = row_vector(rows_arg);
|
|
|
|
column_info = column_vector(columns_arg);
|
2008-07-16 14:23:32 +00:00
|
|
|
cell_info = cell_vvector(rows_arg, cell_vector(columns_arg, CellData(buf)));
|
2007-04-26 12:54:21 +00:00
|
|
|
row_info.reserve(10);
|
|
|
|
column_info.reserve(10);
|
|
|
|
cell_info.reserve(100);
|
2008-03-23 11:35:46 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
is_long_tabular = false;
|
2009-01-03 18:33:09 +00:00
|
|
|
tabular_valignment = LYX_VALIGN_MIDDLE;
|
2009-07-11 13:09:45 +00:00
|
|
|
longtabular_alignment = LYX_LONGTABULAR_ALIGN_CENTER;
|
2007-04-26 12:54:21 +00:00
|
|
|
rotate = false;
|
|
|
|
use_booktabs = false;
|
2008-04-21 13:33:39 +00:00
|
|
|
size_t row_count = row_info.size();
|
|
|
|
size_t column_count = column_info.size();
|
2008-03-18 18:08:32 +00:00
|
|
|
// set silly default lines
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_count; ++i)
|
|
|
|
for (col_type j = 0; j < column_count; ++j) {
|
2008-07-23 12:13:41 +00:00
|
|
|
cell_info[i][j].inset->setBuffer(*buffer_);
|
2008-03-18 18:08:32 +00:00
|
|
|
cell_info[i][j].top_line = true;
|
|
|
|
cell_info[i][j].left_line = true;
|
2008-04-21 13:33:39 +00:00
|
|
|
cell_info[i][j].bottom_line = i == 0 || i == row_count - 1;
|
|
|
|
cell_info[i][j].right_line = j == column_count - 1;
|
2008-03-18 18:08:32 +00:00
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::appendRow(idx_type const cell)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2009-11-08 15:53:21 +00:00
|
|
|
BufferParams const & bp = buffer_->params();
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = cellRow(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
row_vector::iterator rit = row_info.begin() + row;
|
2008-02-27 20:59:44 +00:00
|
|
|
row_info.insert(rit, RowData());
|
2007-04-26 12:54:21 +00:00
|
|
|
// now set the values of the row before
|
|
|
|
row_info[row] = row_info[row + 1];
|
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
row_type const nrows = row_info.size();
|
|
|
|
col_type const ncols = column_info.size();
|
2007-09-04 10:52:08 +00:00
|
|
|
|
|
|
|
cell_vvector old(nrows - 1);
|
|
|
|
for (row_type i = 0; i < nrows - 1; ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
swap(cell_info[i], old[i]);
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
cell_info = cell_vvector(nrows, cell_vector(ncols, CellData(buffer_)));
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
for (row_type i = 0; i <= row; ++i)
|
|
|
|
swap(cell_info[i], old[i]);
|
2007-09-04 10:52:08 +00:00
|
|
|
for (row_type i = row + 2; i < nrows; ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
swap(cell_info[i], old[i - 1]);
|
|
|
|
|
2007-09-04 18:13:19 +00:00
|
|
|
updateIndexes();
|
2008-03-28 12:00:53 +00:00
|
|
|
for (col_type c = 0; c < ncols; ++c) {
|
|
|
|
// inherit line settings
|
|
|
|
idx_type const i = cellIndex(row + 1, c);
|
|
|
|
idx_type const j = cellIndex(row, c);
|
2008-04-19 08:53:24 +00:00
|
|
|
setLeftLine(i, leftLine(j));
|
|
|
|
setRightLine(i, rightLine(j));
|
|
|
|
setTopLine(i, topLine(j));
|
|
|
|
if (topLine(j) && bottomLine(j)) {
|
|
|
|
setBottomLine(i, true);
|
|
|
|
setBottomLine(j, false);
|
|
|
|
}
|
2008-03-28 12:00:53 +00:00
|
|
|
// mark track changes
|
|
|
|
if (bp.trackChanges)
|
|
|
|
cellInfo(i).inset->setChange(Change(Change::INSERTED));
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::deleteRow(row_type const row)
|
|
|
|
{
|
|
|
|
// Not allowed to delete last row
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row_info.size() == 1)
|
2007-04-26 12:54:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
row_info.erase(row_info.begin() + row);
|
|
|
|
cell_info.erase(cell_info.begin() + row);
|
2008-03-23 11:35:46 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::copyRow(row_type const row)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
row_info.insert(row_info.begin() + row, row_info[row]);
|
|
|
|
cell_info.insert(cell_info.begin() + row, cell_info[row]);
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
if (buffer().params().trackChanges)
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j)
|
2007-04-26 12:54:21 +00:00
|
|
|
cell_info[row + 1][j].inset->setChange(Change(Change::INSERTED));
|
|
|
|
|
2007-09-04 18:13:19 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::appendColumn(idx_type const cell)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-19 08:53:24 +00:00
|
|
|
col_type const c = cellColumn(cell);
|
|
|
|
column_vector::iterator cit = column_info.begin() + c + 1;
|
2008-02-27 20:59:44 +00:00
|
|
|
column_info.insert(cit, ColumnData());
|
2008-04-21 13:33:39 +00:00
|
|
|
row_type const nrows = row_info.size();
|
2007-04-26 12:54:21 +00:00
|
|
|
// set the column values of the column before
|
2008-04-19 08:53:24 +00:00
|
|
|
column_info[c + 1] = column_info[c];
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-03-28 12:00:53 +00:00
|
|
|
for (row_type r = 0; r < nrows; ++r) {
|
2008-04-19 08:53:24 +00:00
|
|
|
cell_info[r].insert(cell_info[r].begin() + c + 1,
|
2009-11-08 15:53:21 +00:00
|
|
|
CellData(buffer_));
|
2008-09-15 08:43:42 +00:00
|
|
|
#if 0
|
|
|
|
// FIXME: This code does not work. It deletes the cell's content and
|
|
|
|
// it triggers an assertion if the cursor is at pos > 0.
|
2008-04-19 08:53:24 +00:00
|
|
|
if (cell_info[r][c].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
|
|
|
|
cell_info[r][c + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
|
|
|
|
else
|
|
|
|
cell_info[r][c + 1].multicolumn = cell_info[r][c].multicolumn;
|
2008-09-15 08:43:42 +00:00
|
|
|
#endif
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
2008-03-28 12:00:53 +00:00
|
|
|
updateIndexes();
|
|
|
|
for (row_type r = 0; r < nrows; ++r) {
|
|
|
|
// inherit line settings
|
2008-04-19 08:53:24 +00:00
|
|
|
idx_type const i = cellIndex(r, c + 1);
|
|
|
|
idx_type const j = cellIndex(r, c);
|
2008-03-28 12:00:53 +00:00
|
|
|
setBottomLine(i, bottomLine(j));
|
|
|
|
setTopLine(i, topLine(j));
|
2008-04-19 08:53:24 +00:00
|
|
|
setLeftLine(i, leftLine(j));
|
|
|
|
if (rightLine(j) && rightLine(j)) {
|
|
|
|
setRightLine(i, true);
|
|
|
|
setRightLine(j, false);
|
|
|
|
}
|
2008-03-28 12:00:53 +00:00
|
|
|
//
|
|
|
|
cellInfo(i).inset->clear();
|
2008-03-15 16:44:00 +00:00
|
|
|
if (buffer().params().trackChanges)
|
2008-03-28 12:00:53 +00:00
|
|
|
cellInfo(i).inset->setChange(Change(Change::INSERTED));
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::deleteColumn(col_type const column)
|
|
|
|
{
|
|
|
|
// Not allowed to delete last column
|
2008-04-21 13:33:39 +00:00
|
|
|
if (column_info.size() == 1)
|
2007-04-26 12:54:21 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-09 19:39:28 +00:00
|
|
|
size_t const row_count = row_info.size();
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_count; ++i) {
|
2007-08-12 13:25:36 +00:00
|
|
|
// Care about multicolumn cells
|
2008-04-21 13:33:39 +00:00
|
|
|
if (column + 1 < column_info.size() &&
|
2007-08-12 13:25:36 +00:00
|
|
|
cell_info[i][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN &&
|
|
|
|
cell_info[i][column + 1].multicolumn == CELL_PART_OF_MULTICOLUMN) {
|
|
|
|
cell_info[i][column + 1].multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
cell_info[i].erase(cell_info[i].begin() + column);
|
2007-08-12 13:25:36 +00:00
|
|
|
}
|
2009-02-09 19:39:28 +00:00
|
|
|
column_info.erase(column_info.begin() + column);
|
2008-03-23 11:35:46 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::copyColumn(col_type const column)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
BufferParams const & bp = buffer().params();
|
2007-04-26 12:54:21 +00:00
|
|
|
column_info.insert(column_info.begin() + column, column_info[column]);
|
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
size_t row_count = row_info.size();
|
|
|
|
for (row_type i = 0; i < row_count; ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
cell_info[i].insert(cell_info[i].begin() + column, cell_info[i][column]);
|
|
|
|
|
|
|
|
if (bp.trackChanges)
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_count; ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED));
|
2008-03-23 11:35:46 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 18:13:19 +00:00
|
|
|
void Tabular::updateIndexes()
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2009-11-16 00:18:52 +00:00
|
|
|
setBuffer(buffer());
|
2008-04-21 13:33:39 +00:00
|
|
|
col_type ncols = column_info.size();
|
|
|
|
row_type nrows = row_info.size();
|
2007-04-26 12:54:21 +00:00
|
|
|
numberofcells = 0;
|
2008-03-23 11:35:46 +00:00
|
|
|
for (row_type row = 0; row < nrows; ++row)
|
|
|
|
for (col_type column = 0; column < ncols; ++column) {
|
|
|
|
if (!isPartOfMultiColumn(row, column))
|
2007-04-26 12:54:21 +00:00
|
|
|
++numberofcells;
|
2008-03-23 11:35:46 +00:00
|
|
|
cell_info[row][column].cellno = numberofcells - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rowofcell.resize(numberofcells);
|
|
|
|
columnofcell.resize(numberofcells);
|
2008-03-23 11:35:46 +00:00
|
|
|
idx_type i = 0;
|
|
|
|
for (row_type row = 0; row < nrows; ++row)
|
|
|
|
for (col_type column = 0; column < ncols; ++column) {
|
|
|
|
if (isPartOfMultiColumn(row, column))
|
2007-04-26 12:54:21 +00:00
|
|
|
continue;
|
2008-03-23 11:35:46 +00:00
|
|
|
rowofcell[i] = row;
|
|
|
|
columnofcell[i] = column;
|
2008-07-21 02:07:54 +00:00
|
|
|
setFixedWidth(row, column);
|
2008-09-15 08:09:52 +00:00
|
|
|
updateContentAlignment(row, column);
|
2008-03-23 11:35:46 +00:00
|
|
|
++i;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::idx_type Tabular::numberOfCellsInRow(idx_type const cell) const
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = cellRow(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
idx_type result = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type i = 0; i < column_info.size(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
if (cell_info[row][i].multicolumn != Tabular::CELL_PART_OF_MULTICOLUMN)
|
|
|
|
++result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
bool Tabular::topLine(idx_type const cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).top_line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
bool Tabular::bottomLine(idx_type const cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).bottom_line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
bool Tabular::leftLine(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
if (use_booktabs)
|
|
|
|
return false;
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).left_line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
bool Tabular::rightLine(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
if (use_booktabs)
|
|
|
|
return false;
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).right_line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::topAlreadyDrawn(idx_type cell) const
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type row = cellRow(cell);
|
2008-03-18 18:08:32 +00:00
|
|
|
if (row == 0)
|
|
|
|
return false;
|
|
|
|
idx_type i = cellIndex(row - 1, cellColumn(cell));
|
2008-04-17 15:07:04 +00:00
|
|
|
return !rowTopLine(row) && bottomLine(i);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::leftAlreadyDrawn(idx_type cell) const
|
|
|
|
{
|
2008-03-18 18:08:32 +00:00
|
|
|
col_type col = cellColumn(cell);
|
|
|
|
if (col == 0)
|
|
|
|
return false;
|
|
|
|
idx_type i = cellIndex(cellRow(cell), col - 1);
|
2008-03-25 20:48:48 +00:00
|
|
|
return rightLine(i) && !leftLine(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isLastRow(idx_type cell) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
return cellRow(cell) == row_info.size() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Tabular::getAdditionalHeight(row_type row) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (!row || row >= row_info.size())
|
2007-04-26 12:54:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
int const interline_space = row_info[row - 1].interline_space_default ?
|
|
|
|
default_line_space :
|
2007-09-04 10:52:08 +00:00
|
|
|
row_info[row - 1].interline_space.inPixels(width());
|
2008-03-18 18:08:32 +00:00
|
|
|
if (rowTopLine(row) && rowBottomLine(row - 1))
|
2007-04-26 12:54:21 +00:00
|
|
|
return interline_space + WIDTH_OF_LINE;
|
|
|
|
return interline_space;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Tabular::getAdditionalWidth(idx_type cell) const
|
|
|
|
{
|
2008-03-25 20:48:48 +00:00
|
|
|
col_type const nextcol = cellColumn(cell) + columnSpan(cell);
|
|
|
|
if (rightLine(cell)
|
2008-04-21 13:33:39 +00:00
|
|
|
&& nextcol < column_info.size() && leftLine(cellIndex(cellRow(cell), nextcol)))
|
2007-04-26 12:54:21 +00:00
|
|
|
return WIDTH_OF_LINE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
int Tabular::columnWidth(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-24 14:03:00 +00:00
|
|
|
int w = 0;
|
|
|
|
col_type const span = columnSpan(cell);
|
|
|
|
col_type const col = cellColumn(cell);
|
|
|
|
for(col_type c = col; c < col + span ; ++c)
|
|
|
|
w += column_info[c].width;
|
|
|
|
return w;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-24 14:03:00 +00:00
|
|
|
bool Tabular::updateColumnWidths()
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
col_type const ncols = column_info.size();
|
|
|
|
row_type const nrows = row_info.size();
|
2008-03-24 14:03:00 +00:00
|
|
|
bool update = false;
|
|
|
|
// for each col get max of single col cells
|
|
|
|
for(col_type c = 0; c < ncols; ++c) {
|
|
|
|
int new_width = 0;
|
|
|
|
for(row_type r = 0; r < nrows; ++r) {
|
|
|
|
idx_type const i = cellIndex(r, c);
|
|
|
|
if (columnSpan(i) == 1)
|
2008-03-25 13:32:38 +00:00
|
|
|
new_width = max(new_width, cellInfo(i).width);
|
2008-03-24 14:03:00 +00:00
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-03-24 14:03:00 +00:00
|
|
|
if (column_info[c].width != new_width) {
|
|
|
|
column_info[c].width = new_width;
|
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// update col widths to fit merged cells
|
|
|
|
for(col_type c = 0; c < ncols; ++c)
|
|
|
|
for(row_type r = 0; r < nrows; ++r) {
|
|
|
|
idx_type const i = cellIndex(r, c);
|
|
|
|
int const span = columnSpan(i);
|
|
|
|
if (span == 1 || c > cellColumn(i))
|
|
|
|
continue;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-03-24 14:03:00 +00:00
|
|
|
int old_width = 0;
|
|
|
|
for(col_type j = c; j < c + span ; ++j)
|
|
|
|
old_width += column_info[j].width;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
if (cellInfo(i).width > old_width) {
|
|
|
|
column_info[c + span - 1].width += cellInfo(i).width - old_width;
|
2008-03-24 14:03:00 +00:00
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return update;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-24 14:03:00 +00:00
|
|
|
int Tabular::width() const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
col_type const ncols = column_info.size();
|
2008-03-24 14:03:00 +00:00
|
|
|
int width = 0;
|
|
|
|
for (col_type i = 0; i < ncols; ++i)
|
|
|
|
width += column_info[i].width;
|
|
|
|
return width;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
void Tabular::setCellWidth(idx_type cell, int new_width)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 20:48:48 +00:00
|
|
|
cellInfo(cell).width = new_width + 2 * WIDTH_OF_LINE
|
|
|
|
+ getAdditionalWidth(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setAlignment(idx_type cell, LyXAlignment align,
|
|
|
|
bool onlycolumn)
|
|
|
|
{
|
|
|
|
if (!isMultiColumn(cell) || onlycolumn)
|
2007-09-04 10:52:08 +00:00
|
|
|
column_info[cellColumn(cell)].alignment = align;
|
2007-04-26 12:54:21 +00:00
|
|
|
if (!onlycolumn)
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).alignment = align;
|
2008-09-13 10:10:01 +00:00
|
|
|
cellInset(cell).get()->setContentAlignment(align);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setVAlignment(idx_type cell, VAlignment align,
|
|
|
|
bool onlycolumn)
|
|
|
|
{
|
|
|
|
if (!isMultiColumn(cell) || onlycolumn)
|
2007-09-04 10:52:08 +00:00
|
|
|
column_info[cellColumn(cell)].valignment = align;
|
2007-04-26 12:54:21 +00:00
|
|
|
if (!onlycolumn)
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).valignment = align;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow line and paragraph breaks for fixed width cells or disallow them,
|
|
|
|
* merge cell paragraphs and reset layout to standard for variable width
|
|
|
|
* cells.
|
|
|
|
*/
|
2008-03-21 06:16:05 +00:00
|
|
|
void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
inset->setAutoBreakRows(fixedWidth);
|
2008-07-16 14:23:32 +00:00
|
|
|
inset->toggleFixedWidth(fixedWidth);
|
2007-04-26 12:54:21 +00:00
|
|
|
if (fixedWidth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// merge all paragraphs to one
|
2007-08-21 13:03:55 +00:00
|
|
|
BufferParams const & bp = cur.bv().buffer().params();
|
2007-04-26 12:54:21 +00:00
|
|
|
while (inset->paragraphs().size() > 1)
|
|
|
|
mergeParagraph(bp, inset->paragraphs(), 0);
|
|
|
|
|
|
|
|
// reset layout
|
|
|
|
cur.push(*inset);
|
|
|
|
// undo information has already been recorded
|
2009-08-09 15:29:34 +00:00
|
|
|
inset->getText(0)->setLayout(0, cur.lastpit() + 1,
|
2008-08-01 20:57:27 +00:00
|
|
|
bp.documentClass().plainLayoutName());
|
2007-04-26 12:54:21 +00:00
|
|
|
cur.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void Tabular::setColumnPWidth(Cursor & cur, idx_type cell,
|
2007-04-28 12:58:49 +00:00
|
|
|
Length const & width)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
col_type const j = cellColumn(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
column_info[j].p_width = width;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-09-04 10:52:08 +00:00
|
|
|
idx_type const cell = cellIndex(i, j);
|
2007-04-26 12:54:21 +00:00
|
|
|
// because of multicolumns
|
2008-03-25 13:32:38 +00:00
|
|
|
toggleFixedWidth(cur, cellInset(cell).get(),
|
2007-04-26 12:54:21 +00:00
|
|
|
!getPWidth(cell).zero());
|
|
|
|
}
|
|
|
|
// cur paragraph can become invalid after paragraphs were merged
|
|
|
|
if (cur.pit() > cur.lastpit())
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
// cur position can become invalid after newlines were removed
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-21 02:07:54 +00:00
|
|
|
bool Tabular::setFixedWidth(row_type r, col_type c)
|
|
|
|
{
|
2008-09-12 17:25:11 +00:00
|
|
|
bool const multicol = cell_info[r][c].multicolumn != CELL_NORMAL;
|
2009-02-09 09:02:50 +00:00
|
|
|
bool const fixed_width = (!column_info[c].p_width.zero() && !multicol)
|
|
|
|
|| (multicol && !cell_info[r][c].p_width.zero());
|
|
|
|
cell_info[r][c].inset->toggleFixedWidth(fixed_width);
|
|
|
|
return fixed_width;
|
2008-07-21 02:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-15 08:09:52 +00:00
|
|
|
void Tabular::updateContentAlignment(row_type r, col_type c)
|
|
|
|
{
|
|
|
|
cell_info[r][c].inset->setContentAlignment(
|
|
|
|
getAlignment(cellIndex(r, c)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell,
|
2007-04-28 12:58:49 +00:00
|
|
|
Length const & width)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
if (!isMultiColumn(cell))
|
|
|
|
return false;
|
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).p_width = width;
|
|
|
|
toggleFixedWidth(cur, cellInset(cell).get(), !width.zero());
|
2007-04-26 12:54:21 +00:00
|
|
|
// cur paragraph can become invalid after paragraphs were merged
|
|
|
|
if (cur.pit() > cur.lastpit())
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
// cur position can become invalid after newlines were removed
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
|
|
|
|
Tabular::Feature what)
|
|
|
|
{
|
|
|
|
if (what == SET_SPECIAL_MULTI)
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).align_special = special;
|
2007-04-26 12:54:21 +00:00
|
|
|
else
|
2007-09-04 10:52:08 +00:00
|
|
|
column_info[cellColumn(cell)].align_special = special;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setAllLines(idx_type cell, bool line)
|
|
|
|
{
|
|
|
|
setTopLine(cell, line);
|
|
|
|
setBottomLine(cell, line);
|
|
|
|
setRightLine(cell, line);
|
|
|
|
setLeftLine(cell, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
void Tabular::setTopLine(idx_type i, bool line)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(i).top_line = line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
void Tabular::setBottomLine(idx_type i, bool line)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(i).bottom_line = line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
void Tabular::setLeftLine(idx_type cell, bool line)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).left_line = line;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
void Tabular::setRightLine(idx_type cell, bool line)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).right_line = line;
|
2008-03-18 18:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Tabular::rowTopLine(row_type r) const
|
|
|
|
{
|
|
|
|
idx_type i0 = getFirstCellInRow(r);
|
|
|
|
idx_type i1 = getLastCellInRow(r);
|
|
|
|
bool all_rows_set = true;
|
|
|
|
for (idx_type j = i0; all_rows_set && j <= i1; ++j)
|
2008-03-25 13:32:38 +00:00
|
|
|
all_rows_set = cellInfo(j).top_line;
|
2008-03-18 18:08:32 +00:00
|
|
|
return all_rows_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::rowBottomLine(row_type r) const
|
|
|
|
{
|
|
|
|
idx_type i0 = getFirstCellInRow(r);
|
|
|
|
idx_type i1 = getLastCellInRow(r);
|
|
|
|
bool all_rows_set = true;
|
|
|
|
for (idx_type j = i0; all_rows_set && j <= i1; ++j)
|
2008-03-25 13:32:38 +00:00
|
|
|
all_rows_set = cellInfo(j).bottom_line;
|
2008-03-18 18:08:32 +00:00
|
|
|
return all_rows_set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::columnLeftLine(col_type c) const
|
|
|
|
{
|
2008-05-07 09:37:22 +00:00
|
|
|
if (use_booktabs)
|
|
|
|
return false;
|
|
|
|
|
2008-04-24 17:26:17 +00:00
|
|
|
int nrows_left = 0;
|
|
|
|
int total = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
row_type const nrows = row_info.size();
|
2008-04-24 17:26:17 +00:00
|
|
|
for (row_type r = 0; r < nrows; ++r) {
|
2008-03-18 18:08:32 +00:00
|
|
|
idx_type i = cellIndex(r, c);
|
2008-04-24 17:26:17 +00:00
|
|
|
if (c == cellColumn(i)) {
|
|
|
|
++total;
|
2008-04-25 11:56:21 +00:00
|
|
|
bool right = c > 0 && cellInfo(cellIndex(r, c - 1)).right_line;
|
2008-04-24 17:26:17 +00:00
|
|
|
if (cellInfo(i).left_line || right)
|
|
|
|
++nrows_left;
|
|
|
|
}
|
2008-03-18 18:08:32 +00:00
|
|
|
}
|
2008-06-09 08:11:46 +00:00
|
|
|
return 2 * nrows_left >= total;
|
2008-03-18 18:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::columnRightLine(col_type c) const
|
|
|
|
{
|
2008-05-07 09:37:22 +00:00
|
|
|
if (use_booktabs)
|
|
|
|
return false;
|
|
|
|
|
2008-04-24 17:26:17 +00:00
|
|
|
int nrows_right = 0;
|
|
|
|
int total = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
row_type const nrows = row_info.size();
|
2008-04-24 17:26:17 +00:00
|
|
|
for (row_type r = 0; r < nrows; ++r) {
|
2008-03-18 18:08:32 +00:00
|
|
|
idx_type i = cellIndex(r, c);
|
2008-04-24 17:26:17 +00:00
|
|
|
if (c == cellColumn(i) + columnSpan(i) - 1) {
|
|
|
|
++total;
|
2008-12-22 18:18:47 +00:00
|
|
|
bool left = (c + 1 < column_info.size()
|
|
|
|
&& cellInfo(cellIndex(r, c + 1)).left_line)
|
2008-04-24 17:26:17 +00:00
|
|
|
|| c + 1 == column_info.size();
|
|
|
|
if (cellInfo(i).right_line && left)
|
|
|
|
++nrows_right;
|
|
|
|
}
|
2008-03-18 18:08:32 +00:00
|
|
|
}
|
2008-06-09 08:11:46 +00:00
|
|
|
return 2 * nrows_right >= total;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
|
|
|
|
{
|
|
|
|
if (!onlycolumn && isMultiColumn(cell))
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).alignment;
|
2007-09-04 10:52:08 +00:00
|
|
|
return column_info[cellColumn(cell)].alignment;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::VAlignment
|
|
|
|
Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
|
|
|
|
{
|
|
|
|
if (!onlycolumn && isMultiColumn(cell))
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).valignment;
|
2007-09-04 10:52:08 +00:00
|
|
|
return column_info[cellColumn(cell)].valignment;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
Length const Tabular::getPWidth(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
if (isMultiColumn(cell))
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).p_width;
|
2007-09-04 10:52:08 +00:00
|
|
|
return column_info[cellColumn(cell)].p_width;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
int Tabular::cellWidth(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).width;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Tabular::getBeginningOfTextInCell(idx_type cell) const
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
switch (getAlignment(cell)) {
|
|
|
|
case LYX_ALIGN_CENTER:
|
2007-09-04 10:52:08 +00:00
|
|
|
x += (columnWidth(cell) - cellWidth(cell)) / 2;
|
2007-04-26 12:54:21 +00:00
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
2007-09-04 10:52:08 +00:00
|
|
|
x += columnWidth(cell) - cellWidth(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
// + getAdditionalWidth(cell);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// LYX_ALIGN_LEFT: nothing :-)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the LaTeX Way :-(
|
|
|
|
x += WIDTH_OF_LINE;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isFirstCellInRow(idx_type cell) const
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
return cellColumn(cell) == 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::idx_type Tabular::getFirstCellInRow(row_type row) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row > row_info.size() - 1)
|
|
|
|
row = row_info.size() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
return cell_info[row][0].cellno;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isLastCellInRow(idx_type cell) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
return cellRightColumn(cell) == column_info.size() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row > row_info.size() - 1)
|
|
|
|
row = row_info.size() - 1;
|
|
|
|
return cell_info[row][column_info.size() - 1].cellno;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
Tabular::row_type Tabular::cellRow(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (cell >= numberofcells)
|
|
|
|
return row_info.size() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
if (cell == npos)
|
|
|
|
return 0;
|
|
|
|
return rowofcell[cell];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
Tabular::col_type Tabular::cellColumn(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (cell >= numberofcells)
|
|
|
|
return column_info.size() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
if (cell == npos)
|
2008-07-16 14:23:32 +00:00
|
|
|
return 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
return columnofcell[cell];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
Tabular::col_type Tabular::cellRightColumn(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = cellRow(cell);
|
|
|
|
col_type column = cellColumn(cell);
|
2008-04-21 13:33:39 +00:00
|
|
|
while (column < column_info.size() - 1 &&
|
2008-03-18 18:08:32 +00:00
|
|
|
cell_info[row][column + 1].multicolumn == CELL_PART_OF_MULTICOLUMN)
|
2007-04-26 12:54:21 +00:00
|
|
|
++column;
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::write(ostream & os) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
// header line
|
|
|
|
os << "<lyxtabular"
|
|
|
|
<< write_attribute("version", 3)
|
2008-04-21 13:33:39 +00:00
|
|
|
<< write_attribute("rows", row_info.size())
|
|
|
|
<< write_attribute("columns", column_info.size())
|
2007-04-26 12:54:21 +00:00
|
|
|
<< ">\n";
|
|
|
|
// global longtable options
|
|
|
|
os << "<features"
|
|
|
|
<< write_attribute("rotate", rotate)
|
|
|
|
<< write_attribute("booktabs", use_booktabs)
|
2009-07-11 14:33:05 +00:00
|
|
|
<< write_attribute("islongtable", is_long_tabular)
|
|
|
|
<< write_attribute("firstHeadTopDL", endfirsthead.topDL)
|
2007-04-26 12:54:21 +00:00
|
|
|
<< write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
|
|
|
|
<< write_attribute("firstHeadEmpty", endfirsthead.empty)
|
|
|
|
<< write_attribute("headTopDL", endhead.topDL)
|
|
|
|
<< write_attribute("headBottomDL", endhead.bottomDL)
|
|
|
|
<< write_attribute("footTopDL", endfoot.topDL)
|
|
|
|
<< write_attribute("footBottomDL", endfoot.bottomDL)
|
|
|
|
<< write_attribute("lastFootTopDL", endlastfoot.topDL)
|
|
|
|
<< write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
|
2009-07-11 14:33:05 +00:00
|
|
|
<< write_attribute("lastFootEmpty", endlastfoot.empty);
|
|
|
|
// longtables cannot be aligned vertically
|
|
|
|
if (!is_long_tabular)
|
|
|
|
os << write_attribute("tabularvalignment", tabular_valignment);
|
|
|
|
if (is_long_tabular)
|
|
|
|
os << write_attribute("longtabularalignment",
|
|
|
|
longtabular_alignment);
|
|
|
|
os << ">\n";
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "<column"
|
|
|
|
<< write_attribute("alignment", column_info[j].alignment)
|
|
|
|
<< write_attribute("valignment", column_info[j].valignment)
|
|
|
|
<< write_attribute("width", column_info[j].p_width.asString())
|
|
|
|
<< write_attribute("special", column_info[j].align_special)
|
|
|
|
<< ">\n";
|
|
|
|
}
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
static const string def("default");
|
2008-03-18 18:08:32 +00:00
|
|
|
os << "<row";
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].top_space_default)
|
|
|
|
os << write_attribute("topspace", def);
|
|
|
|
else
|
|
|
|
os << write_attribute("topspace", row_info[i].top_space);
|
|
|
|
if (row_info[i].bottom_space_default)
|
|
|
|
os << write_attribute("bottomspace", def);
|
|
|
|
else
|
|
|
|
os << write_attribute("bottomspace", row_info[i].bottom_space);
|
|
|
|
if (row_info[i].interline_space_default)
|
|
|
|
os << write_attribute("interlinespace", def);
|
|
|
|
else
|
|
|
|
os << write_attribute("interlinespace", row_info[i].interline_space);
|
|
|
|
os << write_attribute("endhead", row_info[i].endhead)
|
|
|
|
<< write_attribute("endfirsthead", row_info[i].endfirsthead)
|
|
|
|
<< write_attribute("endfoot", row_info[i].endfoot)
|
|
|
|
<< write_attribute("endlastfoot", row_info[i].endlastfoot)
|
|
|
|
<< write_attribute("newpage", row_info[i].newpage)
|
2008-05-04 07:51:50 +00:00
|
|
|
<< write_attribute("caption", row_info[i].caption)
|
2007-04-26 12:54:21 +00:00
|
|
|
<< ">\n";
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "<cell"
|
|
|
|
<< write_attribute("multicolumn", cell_info[i][j].multicolumn)
|
|
|
|
<< write_attribute("alignment", cell_info[i][j].alignment)
|
|
|
|
<< write_attribute("valignment", cell_info[i][j].valignment)
|
|
|
|
<< write_attribute("topline", cell_info[i][j].top_line)
|
|
|
|
<< write_attribute("bottomline", cell_info[i][j].bottom_line)
|
|
|
|
<< write_attribute("leftline", cell_info[i][j].left_line)
|
|
|
|
<< write_attribute("rightline", cell_info[i][j].right_line)
|
|
|
|
<< write_attribute("rotate", cell_info[i][j].rotate)
|
|
|
|
<< write_attribute("usebox", cell_info[i][j].usebox)
|
|
|
|
<< write_attribute("width", cell_info[i][j].p_width)
|
|
|
|
<< write_attribute("special", cell_info[i][j].align_special)
|
|
|
|
<< ">\n";
|
|
|
|
os << "\\begin_inset ";
|
2008-02-27 20:43:16 +00:00
|
|
|
cell_info[i][j].inset->write(os);
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "\n\\end_inset\n"
|
|
|
|
<< "</cell>\n";
|
|
|
|
}
|
|
|
|
os << "</row>\n";
|
|
|
|
}
|
|
|
|
os << "</lyxtabular>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::read(Lexer & lex)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
string line;
|
|
|
|
istream & is = lex.getStream();
|
|
|
|
|
|
|
|
l_getline(is, line);
|
2008-02-27 20:43:16 +00:00
|
|
|
if (!prefixIs(line, "<lyxtabular ") && !prefixIs(line, "<Tabular ")) {
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(false, /**/);
|
2007-04-26 12:54:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int version;
|
|
|
|
if (!getTokenValue(line, "version", version))
|
|
|
|
return;
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(version >= 2, /**/);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
int rows_arg;
|
|
|
|
if (!getTokenValue(line, "rows", rows_arg))
|
|
|
|
return;
|
|
|
|
int columns_arg;
|
|
|
|
if (!getTokenValue(line, "columns", columns_arg))
|
|
|
|
return;
|
2009-11-08 15:53:21 +00:00
|
|
|
init(buffer_, rows_arg, columns_arg);
|
2007-04-26 12:54:21 +00:00
|
|
|
l_getline(is, line);
|
|
|
|
if (!prefixIs(line, "<features")) {
|
|
|
|
lyxerr << "Wrong tabular format (expected <features ...> got"
|
|
|
|
<< line << ')' << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getTokenValue(line, "rotate", rotate);
|
|
|
|
getTokenValue(line, "booktabs", use_booktabs);
|
|
|
|
getTokenValue(line, "islongtable", is_long_tabular);
|
2009-01-03 18:33:09 +00:00
|
|
|
getTokenValue(line, "tabularvalignment", tabular_valignment);
|
2009-07-11 13:09:45 +00:00
|
|
|
getTokenValue(line, "longtabularalignment", longtabular_alignment);
|
2007-04-26 12:54:21 +00:00
|
|
|
getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
|
|
|
|
getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
|
|
|
|
getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
|
|
|
|
getTokenValue(line, "headTopDL", endhead.topDL);
|
|
|
|
getTokenValue(line, "headBottomDL", endhead.bottomDL);
|
|
|
|
getTokenValue(line, "footTopDL", endfoot.topDL);
|
|
|
|
getTokenValue(line, "footBottomDL", endfoot.bottomDL);
|
|
|
|
getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
|
|
|
|
getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
|
|
|
|
getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
|
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
l_getline(is,line);
|
|
|
|
if (!prefixIs(line,"<column")) {
|
|
|
|
lyxerr << "Wrong tabular format (expected <column ...> got"
|
|
|
|
<< line << ')' << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getTokenValue(line, "alignment", column_info[j].alignment);
|
|
|
|
getTokenValue(line, "valignment", column_info[j].valignment);
|
|
|
|
getTokenValue(line, "width", column_info[j].p_width);
|
|
|
|
getTokenValue(line, "special", column_info[j].align_special);
|
|
|
|
}
|
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
l_getline(is, line);
|
|
|
|
if (!prefixIs(line, "<row")) {
|
|
|
|
lyxerr << "Wrong tabular format (expected <row ...> got"
|
|
|
|
<< line << ')' << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getTokenValue(line, "topspace", row_info[i].top_space,
|
2007-05-28 22:27:45 +00:00
|
|
|
row_info[i].top_space_default);
|
2007-04-26 12:54:21 +00:00
|
|
|
getTokenValue(line, "bottomspace", row_info[i].bottom_space,
|
2007-05-28 22:27:45 +00:00
|
|
|
row_info[i].bottom_space_default);
|
2007-04-26 12:54:21 +00:00
|
|
|
getTokenValue(line, "interlinespace", row_info[i].interline_space,
|
2007-05-28 22:27:45 +00:00
|
|
|
row_info[i].interline_space_default);
|
2007-04-26 12:54:21 +00:00
|
|
|
getTokenValue(line, "endfirsthead", row_info[i].endfirsthead);
|
|
|
|
getTokenValue(line, "endhead", row_info[i].endhead);
|
|
|
|
getTokenValue(line, "endfoot", row_info[i].endfoot);
|
|
|
|
getTokenValue(line, "endlastfoot", row_info[i].endlastfoot);
|
|
|
|
getTokenValue(line, "newpage", row_info[i].newpage);
|
2008-05-04 07:51:50 +00:00
|
|
|
getTokenValue(line, "caption", row_info[i].caption);
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
l_getline(is, line);
|
|
|
|
if (!prefixIs(line, "<cell")) {
|
|
|
|
lyxerr << "Wrong tabular format (expected <cell ...> got"
|
|
|
|
<< line << ')' << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
|
|
|
|
getTokenValue(line, "alignment", cell_info[i][j].alignment);
|
|
|
|
getTokenValue(line, "valignment", cell_info[i][j].valignment);
|
|
|
|
getTokenValue(line, "topline", cell_info[i][j].top_line);
|
|
|
|
getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
|
|
|
|
getTokenValue(line, "leftline", cell_info[i][j].left_line);
|
|
|
|
getTokenValue(line, "rightline", cell_info[i][j].right_line);
|
|
|
|
getTokenValue(line, "rotate", cell_info[i][j].rotate);
|
|
|
|
getTokenValue(line, "usebox", cell_info[i][j].usebox);
|
|
|
|
getTokenValue(line, "width", cell_info[i][j].p_width);
|
2008-07-21 02:07:54 +00:00
|
|
|
setFixedWidth(i,j);
|
2007-04-26 12:54:21 +00:00
|
|
|
getTokenValue(line, "special", cell_info[i][j].align_special);
|
|
|
|
l_getline(is, line);
|
|
|
|
if (prefixIs(line, "\\begin_inset")) {
|
2008-07-23 12:13:41 +00:00
|
|
|
cell_info[i][j].inset->setBuffer(*buffer_);
|
2008-02-27 20:43:16 +00:00
|
|
|
cell_info[i][j].inset->read(lex);
|
2007-04-26 12:54:21 +00:00
|
|
|
l_getline(is, line);
|
|
|
|
}
|
|
|
|
if (!prefixIs(line, "</cell>")) {
|
|
|
|
lyxerr << "Wrong tabular format (expected </cell> got"
|
|
|
|
<< line << ')' << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l_getline(is, line);
|
|
|
|
if (!prefixIs(line, "</row>")) {
|
|
|
|
lyxerr << "Wrong tabular format (expected </row> got"
|
|
|
|
<< line << ')' << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!prefixIs(line, "</lyxtabular>")) {
|
|
|
|
l_getline(is, line);
|
|
|
|
}
|
2007-09-04 18:13:19 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isMultiColumn(idx_type cell) const
|
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).multicolumn != CELL_NORMAL;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isMultiColumnReal(idx_type cell) const
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
return cellColumn(cell) != cellRightColumn(cell) &&
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).multicolumn != CELL_NORMAL;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
Tabular::CellData & Tabular::cellInfo(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
return cell_info[cellRow(cell)][cellColumn(cell)];
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::setMultiColumn(idx_type cell, idx_type number)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
CellData & cs = cellInfo(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
|
2007-09-04 10:52:08 +00:00
|
|
|
cs.alignment = column_info[cellColumn(cell)].alignment;
|
2008-03-28 12:00:53 +00:00
|
|
|
setRightLine(cell, rightLine(cell + number - 1));
|
2007-04-26 12:54:21 +00:00
|
|
|
for (idx_type i = 1; i < number; ++i) {
|
2008-03-25 13:32:38 +00:00
|
|
|
CellData & cs1 = cellInfo(cell + i);
|
2007-04-26 12:54:21 +00:00
|
|
|
cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
|
2008-02-27 20:43:16 +00:00
|
|
|
cs.inset->appendParagraphs(cs1.inset->paragraphs());
|
2007-04-26 12:54:21 +00:00
|
|
|
cs1.inset->clear();
|
|
|
|
}
|
2007-09-04 18:13:19 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
Tabular::idx_type Tabular::columnSpan(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = cellRow(cell);
|
2008-04-21 13:33:39 +00:00
|
|
|
col_type const ncols = column_info.size();
|
2007-04-26 12:54:21 +00:00
|
|
|
idx_type result = 1;
|
2008-03-24 14:03:00 +00:00
|
|
|
col_type column = cellColumn(cell) + 1;
|
|
|
|
while (column < ncols && isPartOfMultiColumn(row, column)) {
|
2007-04-26 12:54:21 +00:00
|
|
|
++result;
|
|
|
|
++column;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::idx_type Tabular::unsetMultiColumn(idx_type cell)
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = cellRow(cell);
|
|
|
|
col_type column = cellColumn(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
idx_type result = 0;
|
|
|
|
|
|
|
|
if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
|
|
|
|
cell_info[row][column].multicolumn = CELL_NORMAL;
|
|
|
|
++column;
|
2008-04-21 13:33:39 +00:00
|
|
|
while (column < column_info.size() &&
|
2007-04-26 12:54:21 +00:00
|
|
|
cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
|
|
|
|
{
|
|
|
|
cell_info[row][column].multicolumn = CELL_NORMAL;
|
|
|
|
++column;
|
|
|
|
++result;
|
|
|
|
}
|
|
|
|
}
|
2007-09-04 18:13:19 +00:00
|
|
|
updateIndexes();
|
2007-04-26 12:54:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setRotateCell(idx_type cell, bool flag)
|
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).rotate = flag;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getRotateCell(idx_type cell) const
|
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return cellInfo(cell).rotate;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::needRotating() const
|
|
|
|
{
|
|
|
|
if (rotate)
|
|
|
|
return true;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i)
|
|
|
|
for (col_type j = 0; j < column_info.size(); ++j)
|
2007-04-26 12:54:21 +00:00
|
|
|
if (cell_info[i][j].rotate)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isLastCell(idx_type cell) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (cell + 1 < numberofcells)
|
2007-04-26 12:54:21 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
Tabular::idx_type Tabular::cellAbove(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
if (cellRow(cell) > 0)
|
|
|
|
return cell_info[cellRow(cell)-1][cellColumn(cell)].cellno;
|
2007-04-26 12:54:21 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
Tabular::idx_type Tabular::cellBelow(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (cellRow(cell) + 1 < row_info.size())
|
2007-09-04 10:52:08 +00:00
|
|
|
return cell_info[cellRow(cell)+1][cellColumn(cell)].cellno;
|
2007-04-26 12:54:21 +00:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
Tabular::idx_type Tabular::cellIndex(row_type row,
|
2007-04-26 12:54:21 +00:00
|
|
|
col_type column) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
BOOST_ASSERT(column != npos && column < column_info.size()
|
|
|
|
&& row != npos && row < row_info.size());
|
2007-04-26 12:54:21 +00:00
|
|
|
return cell_info[row][column].cellno;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setUsebox(idx_type cell, BoxType type)
|
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInfo(cell).usebox = type;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-25 21:14:36 +00:00
|
|
|
// FIXME: Remove this routine because we cannot insert \parboxes when the user
|
|
|
|
// adds line breaks, see bug 4886.
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular::BoxType Tabular::getUsebox(idx_type cell) const
|
|
|
|
{
|
2008-05-25 21:14:36 +00:00
|
|
|
if ((!column_info[cellColumn(cell)].p_width.zero() && !isMultiColumn(cell)) ||
|
|
|
|
(isMultiColumn(cell) && !cellInfo(cell).p_width.zero()))
|
2007-04-26 12:54:21 +00:00
|
|
|
return BOX_NONE;
|
2008-03-25 13:32:38 +00:00
|
|
|
if (cellInfo(cell).usebox > 1)
|
|
|
|
return cellInfo(cell).usebox;
|
2007-04-26 12:54:21 +00:00
|
|
|
return useParbox(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
// This are functions used for the longtable support
|
|
|
|
///
|
|
|
|
void Tabular::setLTHead(row_type row, bool flag, ltType const & hd,
|
|
|
|
bool first)
|
|
|
|
{
|
|
|
|
if (first) {
|
|
|
|
endfirsthead = hd;
|
|
|
|
if (hd.set)
|
|
|
|
row_info[row].endfirsthead = flag;
|
|
|
|
} else {
|
|
|
|
endhead = hd;
|
|
|
|
if (hd.set)
|
|
|
|
row_info[row].endhead = flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getRowOfLTHead(row_type row, ltType & hd) const
|
|
|
|
{
|
|
|
|
hd = endhead;
|
|
|
|
hd.set = haveLTHead();
|
|
|
|
return row_info[row].endhead;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getRowOfLTFirstHead(row_type row, ltType & hd) const
|
|
|
|
{
|
|
|
|
hd = endfirsthead;
|
|
|
|
hd.set = haveLTFirstHead();
|
|
|
|
return row_info[row].endfirsthead;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setLTFoot(row_type row, bool flag, ltType const & fd,
|
|
|
|
bool last)
|
|
|
|
{
|
|
|
|
if (last) {
|
|
|
|
endlastfoot = fd;
|
|
|
|
if (fd.set)
|
|
|
|
row_info[row].endlastfoot = flag;
|
|
|
|
} else {
|
|
|
|
endfoot = fd;
|
|
|
|
if (fd.set)
|
|
|
|
row_info[row].endfoot = flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getRowOfLTFoot(row_type row, ltType & fd) const
|
|
|
|
{
|
|
|
|
fd = endfoot;
|
|
|
|
fd.set = haveLTFoot();
|
|
|
|
return row_info[row].endfoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getRowOfLTLastFoot(row_type row, ltType & fd) const
|
|
|
|
{
|
|
|
|
fd = endlastfoot;
|
|
|
|
fd.set = haveLTLastFoot();
|
|
|
|
return row_info[row].endlastfoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setLTNewPage(row_type row, bool what)
|
|
|
|
{
|
|
|
|
row_info[row].newpage = what;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getLTNewPage(row_type row) const
|
|
|
|
{
|
|
|
|
return row_info[row].newpage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::haveLTHead() const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endhead)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::haveLTFirstHead() const
|
|
|
|
{
|
|
|
|
if (endfirsthead.empty)
|
|
|
|
return false;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endfirsthead)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::haveLTFoot() const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endfoot)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::haveLTLastFoot() const
|
|
|
|
{
|
|
|
|
if (endlastfoot.empty)
|
|
|
|
return false;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endlastfoot)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-04 07:51:50 +00:00
|
|
|
Tabular::idx_type Tabular::setLTCaption(row_type row, bool what)
|
|
|
|
{
|
|
|
|
idx_type i = getFirstCellInRow(row);
|
|
|
|
if (what) {
|
2009-02-10 00:02:39 +00:00
|
|
|
setMultiColumn(i, numberOfCellsInRow(i));
|
2008-05-04 07:51:50 +00:00
|
|
|
setTopLine(i, false);
|
|
|
|
setBottomLine(i, false);
|
|
|
|
setLeftLine(i, false);
|
|
|
|
setRightLine(i, false);
|
2009-02-10 18:08:09 +00:00
|
|
|
} else {
|
2008-05-04 07:51:50 +00:00
|
|
|
unsetMultiColumn(i);
|
2009-11-02 04:31:06 +00:00
|
|
|
// When unsetting a caption row, also all existing
|
|
|
|
// captions in this row must be dissolved.
|
2009-02-10 18:08:09 +00:00
|
|
|
}
|
2008-05-04 07:51:50 +00:00
|
|
|
row_info[row].caption = what;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::ltCaption(row_type row) const
|
|
|
|
{
|
|
|
|
return row_info[row].caption;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 18:08:09 +00:00
|
|
|
bool Tabular::haveLTCaption() const
|
|
|
|
{
|
|
|
|
for (row_type i = 0; i < row_info.size(); ++i)
|
|
|
|
if (row_info[i].caption)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
// end longtable support functions
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
void Tabular::setRowAscent(row_type row, int height)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row >= row_info.size() || row_info[row].ascent == height)
|
2007-04-26 12:54:21 +00:00
|
|
|
return;
|
2007-09-04 10:52:08 +00:00
|
|
|
row_info[row].ascent = height;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
void Tabular::setRowDescent(row_type row, int height)
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row >= row_info.size() || row_info[row].descent == height)
|
2007-04-26 12:54:21 +00:00
|
|
|
return;
|
2007-09-04 10:52:08 +00:00
|
|
|
row_info[row].descent = height;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
int Tabular::rowAscent(row_type row) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row >= row_info.size())
|
2007-04-26 12:54:21 +00:00
|
|
|
return 0;
|
2007-09-04 10:52:08 +00:00
|
|
|
return row_info[row].ascent;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
int Tabular::rowDescent(row_type row) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
LASSERT(row < row_info.size(), /**/);
|
2007-09-04 10:52:08 +00:00
|
|
|
return row_info[row].descent;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
int Tabular::height() const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
int height = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type row = 0; row < row_info.size(); ++row)
|
2007-09-04 10:52:08 +00:00
|
|
|
height += rowAscent(row) + rowDescent(row) +
|
2007-04-26 12:54:21 +00:00
|
|
|
getAdditionalHeight(row);
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isPartOfMultiColumn(row_type row, col_type column) const
|
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
LASSERT(row < row_info.size(), /**/);
|
|
|
|
LASSERT(column < column_info.size(), /**/);
|
2007-04-26 12:54:21 +00:00
|
|
|
return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-26 21:24:59 +00:00
|
|
|
int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-09-14 17:43:04 +00:00
|
|
|
// we only output complete row lines and the 1st row here, the rest
|
|
|
|
// is done in Tabular::TeXBottomHLine(...)
|
|
|
|
|
|
|
|
// get for each column the topline (if any)
|
2008-09-14 12:31:58 +00:00
|
|
|
col_type const ncols = column_info.size();
|
|
|
|
vector<bool> topline;
|
2008-09-18 16:29:27 +00:00
|
|
|
col_type nset = 0;
|
2008-09-14 12:31:58 +00:00
|
|
|
for (col_type c = 0; c < ncols; ++c) {
|
|
|
|
topline.push_back(topLine(cellIndex(row, c)));
|
|
|
|
if (topline[c])
|
|
|
|
++nset;
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-09-14 17:43:04 +00:00
|
|
|
// do nothing if empty first row, or incomplete row line after
|
2008-09-14 12:31:58 +00:00
|
|
|
if ((row == 0 && nset == 0) || (row > 0 && nset != ncols))
|
|
|
|
return 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-09-14 17:43:04 +00:00
|
|
|
// only output complete row lines and the 1st row's clines
|
2008-09-14 12:31:58 +00:00
|
|
|
if (nset == ncols) {
|
|
|
|
if (use_booktabs) {
|
|
|
|
os << (row == 0 ? "\\toprule " : "\\midrule ");
|
|
|
|
} else {
|
|
|
|
os << "\\hline ";
|
|
|
|
}
|
|
|
|
} else if (row == 0) {
|
|
|
|
for (col_type c = 0; c < ncols; ++c) {
|
|
|
|
if (topline[c]) {
|
2008-09-26 21:24:59 +00:00
|
|
|
//babel makes the "-" character an active one, so we have to suppress this here
|
|
|
|
//see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
|
|
|
|
if (lang == "slovak" || lang == "czech")
|
|
|
|
os << (use_booktabs ? "\\expandafter\\cmidrule\\expandafter{\\expandafter" :
|
|
|
|
"\\expandafter\\cline\\expandafter{\\expandafter")
|
|
|
|
<< c + 1 << "\\string-";
|
|
|
|
else
|
|
|
|
os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 << '-';
|
2008-09-14 17:43:04 +00:00
|
|
|
// get to last column of line span
|
2008-09-14 12:31:58 +00:00
|
|
|
while (c < ncols && topline[c])
|
|
|
|
++c;
|
|
|
|
os << c << "} ";
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-26 21:24:59 +00:00
|
|
|
int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-09-14 17:43:04 +00:00
|
|
|
// we output bottomlines of row r and the toplines of row r+1
|
|
|
|
// if the latter do not span the whole tabular
|
|
|
|
|
|
|
|
// get the bottomlines of row r, and toplines in next row
|
2008-09-14 12:31:58 +00:00
|
|
|
bool lastrow = row == row_info.size() - 1;
|
|
|
|
col_type const ncols = column_info.size();
|
|
|
|
vector<bool> bottomline, topline;
|
|
|
|
bool nextrowset = true;
|
|
|
|
for (col_type c = 0; c < ncols; ++c) {
|
|
|
|
bottomline.push_back(bottomLine(cellIndex(row, c)));
|
|
|
|
topline.push_back(!lastrow && topLine(cellIndex(row + 1, c)));
|
|
|
|
nextrowset &= topline[c];
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-09-14 17:43:04 +00:00
|
|
|
// combine this row's bottom lines and next row's toplines if necessary
|
2008-09-18 16:29:27 +00:00
|
|
|
col_type nset = 0;
|
2008-09-14 12:31:58 +00:00
|
|
|
for (col_type c = 0; c < ncols; ++c) {
|
|
|
|
if (!nextrowset)
|
|
|
|
bottomline[c] = bottomline[c] || topline[c];
|
|
|
|
if (bottomline[c])
|
|
|
|
++nset;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
2008-09-14 12:31:58 +00:00
|
|
|
|
2008-09-14 17:43:04 +00:00
|
|
|
// do nothing if empty, OR incomplete row line with a topline in next row
|
2008-09-14 12:31:58 +00:00
|
|
|
if (nset == 0 || (nextrowset && nset != ncols))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (nset == ncols) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << (lastrow ? "\\bottomrule" : "\\midrule");
|
|
|
|
else
|
|
|
|
os << "\\hline";
|
|
|
|
} else {
|
|
|
|
for (col_type c = 0; c < ncols; ++c) {
|
|
|
|
if (bottomline[c]) {
|
2008-09-26 21:24:59 +00:00
|
|
|
//babel makes the "-" character an active one, so we have to suppress this here
|
|
|
|
//see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
|
|
|
|
if (lang == "slovak" || lang == "czech")
|
|
|
|
os << (use_booktabs ? "\\expandafter\\cmidrule\\expandafter{\\expandafter" :
|
|
|
|
"\\expandafter\\cline\\expandafter{\\expandafter")
|
|
|
|
<< c + 1 << "\\string-";
|
|
|
|
else
|
|
|
|
os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 << '-';
|
2008-09-14 17:43:04 +00:00
|
|
|
// get to last column of line span
|
2008-09-14 12:31:58 +00:00
|
|
|
while (c < ncols && bottomline[c])
|
|
|
|
++c;
|
|
|
|
os << c << "} ";
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 20:48:48 +00:00
|
|
|
int Tabular::TeXCellPreamble(odocstream & os, idx_type cell, bool & ismulticol) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-05-04 07:51:50 +00:00
|
|
|
row_type const r = cellRow(cell);
|
|
|
|
if (is_long_tabular && row_info[r].caption)
|
|
|
|
return ret;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
Tabular::VAlignment valign = getVAlignment(cell, !isMultiColumn(cell));
|
|
|
|
LyXAlignment align = getAlignment(cell, !isMultiColumn(cell));
|
2008-03-25 20:48:48 +00:00
|
|
|
// figure out how to set the lines
|
|
|
|
// we always set double lines to the right of the cell
|
|
|
|
col_type const c = cellColumn(cell);
|
|
|
|
col_type const nextcol = c + columnSpan(cell);
|
2008-04-24 17:26:17 +00:00
|
|
|
bool colright = columnRightLine(c);
|
|
|
|
bool colleft = columnLeftLine(c);
|
2008-05-06 11:24:54 +00:00
|
|
|
bool nextcolleft = nextcol < column_info.size() && columnLeftLine(nextcol);
|
2008-04-27 09:12:53 +00:00
|
|
|
bool nextcellleft = nextcol < column_info.size()
|
2008-03-28 12:00:53 +00:00
|
|
|
&& leftLine(cellIndex(r, nextcol));
|
2008-04-27 09:12:53 +00:00
|
|
|
bool coldouble = colright && nextcolleft;
|
|
|
|
bool celldouble = rightLine(cell) && nextcellleft;
|
2008-03-25 20:48:48 +00:00
|
|
|
ismulticol = isMultiColumn(cell)
|
2008-04-27 09:12:53 +00:00
|
|
|
|| (c == 0 && colleft != leftLine(cell))
|
|
|
|
|| ((colright || nextcolleft) && !rightLine(cell) && !nextcellleft)
|
|
|
|
|| (!colright && !nextcolleft && (rightLine(cell) || nextcellleft))
|
|
|
|
|| (coldouble != celldouble);
|
2008-03-25 20:48:48 +00:00
|
|
|
if (ismulticol) {
|
2008-03-18 18:08:32 +00:00
|
|
|
os << "\\multicolumn{" << columnSpan(cell) << "}{";
|
2008-07-04 13:18:28 +00:00
|
|
|
if (c ==0 && leftLine(cell))
|
2007-04-26 21:40:51 +00:00
|
|
|
os << '|';
|
2008-03-25 13:32:38 +00:00
|
|
|
if (!cellInfo(cell).align_special.empty()) {
|
|
|
|
os << cellInfo(cell).align_special;
|
2007-04-26 12:54:21 +00:00
|
|
|
} else {
|
|
|
|
if (!getPWidth(cell).zero()) {
|
2008-09-10 12:49:08 +00:00
|
|
|
switch (align) {
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
os << ">{\\raggedright}";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
os << ">{\\raggedleft}";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_CENTER:
|
|
|
|
os << ">{\\centering}";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-03-18 18:08:32 +00:00
|
|
|
switch (valign) {
|
2007-04-26 12:54:21 +00:00
|
|
|
case LYX_VALIGN_TOP:
|
|
|
|
os << 'p';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_MIDDLE:
|
|
|
|
os << 'm';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_BOTTOM:
|
|
|
|
os << 'b';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << '{'
|
|
|
|
<< from_ascii(getPWidth(cell).asLatexString())
|
|
|
|
<< '}';
|
|
|
|
} else {
|
2008-03-18 18:08:32 +00:00
|
|
|
switch (align) {
|
2007-04-26 12:54:21 +00:00
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
os << 'l';
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
os << 'r';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << 'c';
|
|
|
|
break;
|
|
|
|
}
|
2007-04-26 21:40:51 +00:00
|
|
|
} // end if else !getPWidth
|
|
|
|
} // end if else !cellinfo_of_cell
|
2008-04-27 09:12:53 +00:00
|
|
|
if (rightLine(cell) || nextcellleft)
|
2008-03-25 20:48:48 +00:00
|
|
|
os << '|';
|
2008-04-24 17:26:17 +00:00
|
|
|
if (celldouble)
|
2008-03-25 20:48:48 +00:00
|
|
|
// add extra vertical line if we want a double one
|
2007-04-26 21:40:51 +00:00
|
|
|
os << '|';
|
|
|
|
os << "}{";
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
2008-03-31 12:09:24 +00:00
|
|
|
if (getRotateCell(cell)) {
|
|
|
|
os << "\\begin{sideways}\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
if (getUsebox(cell) == BOX_PARBOX) {
|
|
|
|
os << "\\parbox[";
|
2008-03-18 18:08:32 +00:00
|
|
|
switch (valign) {
|
2007-04-26 12:54:21 +00:00
|
|
|
case LYX_VALIGN_TOP:
|
|
|
|
os << 't';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_MIDDLE:
|
|
|
|
os << 'c';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_BOTTOM:
|
|
|
|
os << 'b';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << "]{" << from_ascii(getPWidth(cell).asLatexString())
|
|
|
|
<< "}{";
|
|
|
|
} else if (getUsebox(cell) == BOX_MINIPAGE) {
|
|
|
|
os << "\\begin{minipage}[";
|
2008-03-18 18:08:32 +00:00
|
|
|
switch (valign) {
|
2007-04-26 12:54:21 +00:00
|
|
|
case LYX_VALIGN_TOP:
|
|
|
|
os << 't';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_MIDDLE:
|
|
|
|
os << 'm';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_BOTTOM:
|
|
|
|
os << 'b';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << "]{" << from_ascii(getPWidth(cell).asLatexString())
|
|
|
|
<< "}\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 20:48:48 +00:00
|
|
|
int Tabular::TeXCellPostamble(odocstream & os, idx_type cell, bool ismulticol) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-05-04 07:51:50 +00:00
|
|
|
row_type const r = cellRow(cell);
|
|
|
|
if (is_long_tabular && row_info[r].caption)
|
|
|
|
return ret;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
// usual cells
|
|
|
|
if (getUsebox(cell) == BOX_PARBOX)
|
|
|
|
os << '}';
|
|
|
|
else if (getUsebox(cell) == BOX_MINIPAGE) {
|
|
|
|
os << "%\n\\end{minipage}";
|
|
|
|
ret += 2;
|
|
|
|
}
|
|
|
|
if (getRotateCell(cell)) {
|
|
|
|
os << "%\n\\end{sideways}";
|
|
|
|
++ret;
|
|
|
|
}
|
2008-03-31 12:09:24 +00:00
|
|
|
if (ismulticol) {
|
|
|
|
os << '}';
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int Tabular::TeXLongtableHeaderFooter(odocstream & os,
|
2007-04-26 12:54:21 +00:00
|
|
|
OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
if (!is_long_tabular)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int ret = 0;
|
2009-02-12 02:23:48 +00:00
|
|
|
// caption handling
|
2009-07-12 13:43:05 +00:00
|
|
|
// the caption must be output before the headers
|
2009-02-12 02:23:48 +00:00
|
|
|
if (haveLTCaption()) {
|
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
|
|
|
if (row_info[i].caption) {
|
|
|
|
ret += TeXRow(os, i, runparams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// output first header info
|
|
|
|
// first header must be output before the header, otherwise the
|
2009-05-17 11:27:44 +00:00
|
|
|
// correct caption placement becomes really weird
|
2009-02-12 02:23:48 +00:00
|
|
|
if (haveLTFirstHead()) {
|
|
|
|
if (endfirsthead.topDL) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2009-02-12 02:23:48 +00:00
|
|
|
if (row_info[i].endfirsthead) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += TeXRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-12 02:23:48 +00:00
|
|
|
if (endfirsthead.bottomDL) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2009-02-12 02:23:48 +00:00
|
|
|
os << "\\endfirsthead\n";
|
2007-04-26 12:54:21 +00:00
|
|
|
++ret;
|
2009-02-12 02:23:48 +00:00
|
|
|
}
|
|
|
|
// output header info
|
|
|
|
if (haveLTHead()) {
|
2009-02-13 23:48:19 +00:00
|
|
|
if (endfirsthead.empty && !haveLTFirstHead()) {
|
|
|
|
os << "\\endfirsthead\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2009-02-12 02:23:48 +00:00
|
|
|
if (endhead.topDL) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2009-02-12 02:23:48 +00:00
|
|
|
if (row_info[i].endhead) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += TeXRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-12 02:23:48 +00:00
|
|
|
if (endhead.bottomDL) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2009-02-12 02:23:48 +00:00
|
|
|
os << "\\endhead\n";
|
2007-04-26 12:54:21 +00:00
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
// output footer info
|
|
|
|
if (haveLTFoot()) {
|
|
|
|
if (endfoot.topDL) {
|
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endfoot) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += TeXRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (endfoot.bottomDL) {
|
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
os << "\\endfoot\n";
|
|
|
|
++ret;
|
2009-02-13 23:48:19 +00:00
|
|
|
if (endlastfoot.empty && !haveLTLastFoot()) {
|
|
|
|
os << "\\endlastfoot\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
// output lastfooter info
|
|
|
|
if (haveLTLastFoot()) {
|
|
|
|
if (endlastfoot.topDL) {
|
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endlastfoot) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += TeXRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (endlastfoot.bottomDL) {
|
|
|
|
os << "\\hline\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
os << "\\endlastfoot\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isValidRow(row_type row) const
|
|
|
|
{
|
|
|
|
if (!is_long_tabular)
|
|
|
|
return true;
|
2009-02-12 02:23:48 +00:00
|
|
|
return !row_info[row].endhead && !row_info[row].endfirsthead
|
|
|
|
&& !row_info[row].endfoot && !row_info[row].endlastfoot
|
|
|
|
&& !row_info[row].caption;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int Tabular::TeXRow(odocstream & os, row_type i,
|
2007-04-26 12:54:21 +00:00
|
|
|
OutputParams const & runparams) const
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
idx_type cell = cellIndex(i, 0);
|
2008-09-26 21:24:59 +00:00
|
|
|
shared_ptr<InsetTableCell> inset = cellInset(cell);
|
|
|
|
Paragraph const & par = inset->paragraphs().front();
|
2008-09-27 15:32:43 +00:00
|
|
|
string const lang = par.getParLanguage(buffer().params())->lang();
|
2008-09-26 21:24:59 +00:00
|
|
|
|
|
|
|
//output the top line
|
|
|
|
int ret = TeXTopHLine(os, i, lang);
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].top_space_default) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << "\\addlinespace\n";
|
|
|
|
else
|
|
|
|
os << "\\noalign{\\vskip\\doublerulesep}\n";
|
|
|
|
++ret;
|
|
|
|
} else if(!row_info[i].top_space.zero()) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << "\\addlinespace["
|
|
|
|
<< from_ascii(row_info[i].top_space.asLatexString())
|
|
|
|
<< "]\n";
|
|
|
|
else {
|
|
|
|
os << "\\noalign{\\vskip"
|
|
|
|
<< from_ascii(row_info[i].top_space.asLatexString())
|
|
|
|
<< "}\n";
|
|
|
|
}
|
|
|
|
++ret;
|
|
|
|
}
|
2008-03-25 20:48:48 +00:00
|
|
|
bool ismulticol = false;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isPartOfMultiColumn(i, j))
|
|
|
|
continue;
|
2008-03-25 20:48:48 +00:00
|
|
|
ret += TeXCellPreamble(os, cell, ismulticol);
|
2008-03-25 13:32:38 +00:00
|
|
|
shared_ptr<InsetTableCell> inset = cellInset(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
Paragraph const & par = inset->paragraphs().front();
|
2008-02-27 20:43:16 +00:00
|
|
|
bool rtl = par.isRTL(buffer().params())
|
2007-04-26 12:54:21 +00:00
|
|
|
&& !par.empty()
|
|
|
|
&& getPWidth(cell).zero();
|
|
|
|
|
2007-05-31 18:53:01 +00:00
|
|
|
if (rtl) {
|
2008-09-10 16:02:32 +00:00
|
|
|
string const lang =
|
|
|
|
par.getParLanguage(buffer().params())->lang();
|
|
|
|
if (lang == "farsi")
|
2007-05-31 18:53:01 +00:00
|
|
|
os << "\\textFR{";
|
2008-09-10 16:02:32 +00:00
|
|
|
else if (lang == "arabic_arabi")
|
2007-06-26 00:11:03 +00:00
|
|
|
os << "\\textAR{";
|
2008-09-10 16:02:32 +00:00
|
|
|
// currently, remaning RTL languages are
|
|
|
|
// arabic_arabtex and hebrew
|
2007-05-31 18:53:01 +00:00
|
|
|
else
|
|
|
|
os << "\\R{";
|
|
|
|
}
|
2008-09-10 16:02:32 +00:00
|
|
|
// pass to the OutputParams that we are in a cell and
|
|
|
|
// which alignment we have set.
|
|
|
|
// InsetNewline needs this context information.
|
2008-09-27 15:32:43 +00:00
|
|
|
OutputParams newrp(runparams);
|
2008-09-10 16:02:32 +00:00
|
|
|
newrp.inTableCell = (getAlignment(cell) == LYX_ALIGN_BLOCK)
|
|
|
|
? OutputParams::PLAIN
|
|
|
|
: OutputParams::ALIGNED;
|
|
|
|
ret += inset->latex(os, newrp);
|
2008-09-27 15:32:43 +00:00
|
|
|
runparams.encoding = newrp.encoding;
|
2007-04-26 12:54:21 +00:00
|
|
|
if (rtl)
|
|
|
|
os << '}';
|
|
|
|
|
2008-03-25 20:48:48 +00:00
|
|
|
ret += TeXCellPostamble(os, cell, ismulticol);
|
2007-04-26 12:54:21 +00:00
|
|
|
if (!isLastCellInRow(cell)) { // not last cell in row
|
|
|
|
os << " & ";
|
|
|
|
}
|
|
|
|
++cell;
|
|
|
|
}
|
2009-07-12 13:43:05 +00:00
|
|
|
if (row_info[i].caption && !endfirsthead.empty && !haveLTFirstHead())
|
|
|
|
// if no first header and no empty first header is used,
|
|
|
|
// the caption needs to be terminated by \endfirsthead
|
2009-07-12 13:47:06 +00:00
|
|
|
// (bug 6057)
|
2009-07-12 13:43:05 +00:00
|
|
|
os << "\\endfirsthead";
|
|
|
|
else
|
|
|
|
os << "\\tabularnewline";
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].bottom_space_default) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << "\\addlinespace";
|
|
|
|
else
|
|
|
|
os << "[\\doublerulesep]";
|
|
|
|
} else if (!row_info[i].bottom_space.zero()) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << "\\addlinespace";
|
|
|
|
os << '['
|
|
|
|
<< from_ascii(row_info[i].bottom_space.asLatexString())
|
|
|
|
<< ']';
|
|
|
|
}
|
|
|
|
os << '\n';
|
|
|
|
++ret;
|
2008-09-26 21:24:59 +00:00
|
|
|
|
|
|
|
//output the bottom line
|
|
|
|
ret += TeXBottomHLine(os, i, lang);
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].interline_space_default) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << "\\addlinespace\n";
|
|
|
|
else
|
|
|
|
os << "\\noalign{\\vskip\\doublerulesep}\n";
|
|
|
|
++ret;
|
|
|
|
} else if (!row_info[i].interline_space.zero()) {
|
|
|
|
if (use_booktabs)
|
|
|
|
os << "\\addlinespace["
|
|
|
|
<< from_ascii(row_info[i].interline_space.asLatexString())
|
|
|
|
<< "]\n";
|
|
|
|
else
|
|
|
|
os << "\\noalign{\\vskip"
|
|
|
|
<< from_ascii(row_info[i].interline_space.asLatexString())
|
|
|
|
<< "}\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2001-12-18 03:21:10 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int Tabular::latex(odocstream & os, OutputParams const & runparams) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2005-01-27 21:05:44 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ first the opening preamble +
|
|
|
|
//+---------------------------------------------------------------------
|
2001-12-18 03:21:10 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
if (rotate) {
|
|
|
|
os << "\\begin{sideways}\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2009-07-11 13:09:45 +00:00
|
|
|
if (is_long_tabular) {
|
2009-01-03 18:33:09 +00:00
|
|
|
os << "\\begin{longtable}";
|
2009-07-11 13:09:45 +00:00
|
|
|
switch (longtabular_alignment) {
|
|
|
|
case LYX_LONGTABULAR_ALIGN_LEFT:
|
|
|
|
os << "[l]";
|
|
|
|
break;
|
|
|
|
case LYX_LONGTABULAR_ALIGN_CENTER:
|
|
|
|
break;
|
|
|
|
case LYX_LONGTABULAR_ALIGN_RIGHT:
|
|
|
|
os << "[r]";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2009-01-03 18:33:09 +00:00
|
|
|
os << "\\begin{tabular}";
|
2009-07-11 13:09:45 +00:00
|
|
|
switch (tabular_valignment) {
|
2009-01-03 18:33:09 +00:00
|
|
|
case LYX_VALIGN_TOP:
|
|
|
|
os << "[t]";
|
|
|
|
break;
|
2009-07-11 13:09:45 +00:00
|
|
|
case LYX_VALIGN_MIDDLE:
|
|
|
|
break;
|
2009-01-03 18:33:09 +00:00
|
|
|
case LYX_VALIGN_BOTTOM:
|
|
|
|
os << "[b]";
|
|
|
|
break;
|
2009-07-11 13:09:45 +00:00
|
|
|
}
|
2009-01-03 18:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
os << "{";
|
2008-03-18 18:08:32 +00:00
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type i = 0; i < column_info.size(); ++i) {
|
2008-05-07 09:37:22 +00:00
|
|
|
if (columnLeftLine(i))
|
2007-04-26 21:40:51 +00:00
|
|
|
os << '|';
|
2007-04-26 12:54:21 +00:00
|
|
|
if (!column_info[i].align_special.empty()) {
|
|
|
|
os << column_info[i].align_special;
|
|
|
|
} else {
|
|
|
|
if (!column_info[i].p_width.zero()) {
|
|
|
|
switch (column_info[i].alignment) {
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
os << ">{\\raggedright}";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
os << ">{\\raggedleft}";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_CENTER:
|
|
|
|
os << ">{\\centering}";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_NONE:
|
|
|
|
case LYX_ALIGN_BLOCK:
|
|
|
|
case LYX_ALIGN_LAYOUT:
|
|
|
|
case LYX_ALIGN_SPECIAL:
|
|
|
|
break;
|
|
|
|
}
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
switch (column_info[i].valignment) {
|
|
|
|
case LYX_VALIGN_TOP:
|
|
|
|
os << 'p';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_MIDDLE:
|
|
|
|
os << 'm';
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_BOTTOM:
|
|
|
|
os << 'b';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << '{'
|
|
|
|
<< from_ascii(column_info[i].p_width.asLatexString())
|
|
|
|
<< '}';
|
|
|
|
} else {
|
|
|
|
switch (column_info[i].alignment) {
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
os << 'l';
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
os << 'r';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << 'c';
|
|
|
|
break;
|
|
|
|
}
|
2007-04-26 21:40:51 +00:00
|
|
|
} // end if else !column_info[i].p_width
|
|
|
|
} // end if else !column_info[i].align_special
|
2008-05-07 09:37:22 +00:00
|
|
|
if (columnRightLine(i))
|
2007-04-26 21:40:51 +00:00
|
|
|
os << '|';
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
os << "}\n";
|
|
|
|
++ret;
|
2006-09-03 07:02:38 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += TeXLongtableHeaderFooter(os, runparams);
|
2005-09-06 17:39:39 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ the single row and columns (cells) +
|
|
|
|
//+---------------------------------------------------------------------
|
2003-09-09 22:13:45 +00:00
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isValidRow(i)) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += TeXRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
if (is_long_tabular && row_info[i].newpage) {
|
|
|
|
os << "\\newpage\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ the closing of the tabular +
|
|
|
|
//+---------------------------------------------------------------------
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
if (is_long_tabular)
|
|
|
|
os << "\\end{longtable}";
|
|
|
|
else
|
|
|
|
os << "\\end{tabular}";
|
|
|
|
if (rotate) {
|
|
|
|
os << "\n\\end{sideways}";
|
|
|
|
++ret;
|
|
|
|
}
|
2006-06-20 08:39:16 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2004-11-23 23:04:52 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int Tabular::docbookRow(odocstream & os, row_type row,
|
2007-04-26 12:54:21 +00:00
|
|
|
OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
idx_type cell = getFirstCellInRow(row);
|
2006-10-07 16:47:54 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "<row>\n";
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isPartOfMultiColumn(row, j))
|
|
|
|
continue;
|
2003-07-04 08:23:23 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "<entry align=\"";
|
|
|
|
switch (getAlignment(cell)) {
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
os << "left";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
os << "right";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << "center";
|
|
|
|
break;
|
|
|
|
}
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "\" valign=\"";
|
|
|
|
switch (getVAlignment(cell)) {
|
|
|
|
case LYX_VALIGN_TOP:
|
|
|
|
os << "top";
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_BOTTOM:
|
|
|
|
os << "bottom";
|
|
|
|
break;
|
|
|
|
case LYX_VALIGN_MIDDLE:
|
|
|
|
os << "middle";
|
|
|
|
}
|
|
|
|
os << '"';
|
2001-12-18 03:21:10 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isMultiColumn(cell)) {
|
|
|
|
os << " namest=\"col" << j << "\" ";
|
2008-03-18 18:08:32 +00:00
|
|
|
os << "nameend=\"col" << j + columnSpan(cell) - 1<< '"';
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
os << '>';
|
2008-03-25 13:32:38 +00:00
|
|
|
ret += cellInset(cell)->docbook(os, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "</entry>\n";
|
|
|
|
++cell;
|
|
|
|
}
|
|
|
|
os << "</row>\n";
|
|
|
|
return ret;
|
|
|
|
}
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2000-07-28 14:28:54 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ first the opening preamble +
|
|
|
|
//+---------------------------------------------------------------------
|
2000-07-28 14:28:54 +00:00
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
os << "<tgroup cols=\"" << column_info.size()
|
2007-04-26 12:54:21 +00:00
|
|
|
<< "\" colsep=\"1\" rowsep=\"1\">\n";
|
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type i = 0; i < column_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "<colspec colname=\"col" << i << "\" align=\"";
|
|
|
|
switch (column_info[i].alignment) {
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
os << "left";
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
os << "right";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << "center";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << '"';
|
|
|
|
if (runparams.flavor == OutputParams::XML)
|
|
|
|
os << '/';
|
|
|
|
os << ">\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ Long Tabular case +
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
|
2009-02-12 02:37:14 +00:00
|
|
|
// output caption info
|
|
|
|
if (haveLTCaption()) {
|
|
|
|
os << "<caption>\n";
|
|
|
|
++ret;
|
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
|
|
|
if (row_info[i].caption) {
|
|
|
|
ret += docbookRow(os, i, runparams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</caption>\n";
|
|
|
|
++ret;
|
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
// output header info
|
2009-02-12 02:37:14 +00:00
|
|
|
if (haveLTHead() || haveLTFirstHead()) {
|
2007-04-26 12:54:21 +00:00
|
|
|
os << "<thead>\n";
|
|
|
|
++ret;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2009-02-12 02:37:14 +00:00
|
|
|
if (row_info[i].endhead || row_info[i].endfirsthead) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += docbookRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</thead>\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
// output footer info
|
|
|
|
if (haveLTFoot() || haveLTLastFoot()) {
|
|
|
|
os << "<tfoot>\n";
|
|
|
|
++ret;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (row_info[i].endfoot || row_info[i].endlastfoot) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += docbookRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</tfoot>\n";
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ the single row and columns (cells) +
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
|
|
|
|
os << "<tbody>\n";
|
|
|
|
++ret;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isValidRow(i)) {
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += docbookRow(os, i, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</tbody>\n";
|
|
|
|
++ret;
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
//+ the closing of the tabular +
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
|
|
|
|
os << "</tgroup>";
|
|
|
|
++ret;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
|
2007-05-28 22:27:45 +00:00
|
|
|
vector<unsigned int> const & clen) const
|
2000-07-28 14:28:54 +00:00
|
|
|
{
|
2007-04-26 12:54:21 +00:00
|
|
|
idx_type const fcell = getFirstCellInRow(row);
|
|
|
|
idx_type const n = numberOfCellsInRow(fcell) + fcell;
|
|
|
|
idx_type tmp = 0;
|
2000-07-28 14:28:54 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
if (topLine(i)) {
|
|
|
|
++tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!tmp)
|
|
|
|
return false;
|
2004-01-05 17:33:57 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
char_type ch;
|
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
if (topLine(i)) {
|
|
|
|
if (leftLine(i))
|
|
|
|
os << "+-";
|
|
|
|
else
|
|
|
|
os << "--";
|
|
|
|
ch = '-';
|
|
|
|
} else {
|
|
|
|
os << " ";
|
|
|
|
ch = ' ';
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
col_type column = cellColumn(i);
|
2007-04-26 12:54:21 +00:00
|
|
|
int len = clen[column];
|
2008-04-21 13:33:39 +00:00
|
|
|
while (column < column_info.size() - 1
|
2007-04-26 12:54:21 +00:00
|
|
|
&& isPartOfMultiColumn(row, ++column))
|
|
|
|
len += clen[column] + 4;
|
|
|
|
os << docstring(len, ch);
|
|
|
|
if (topLine(i)) {
|
|
|
|
if (rightLine(i))
|
|
|
|
os << "-+";
|
|
|
|
else
|
|
|
|
os << "--";
|
|
|
|
} else {
|
|
|
|
os << " ";
|
|
|
|
}
|
2003-03-09 18:11:57 +00:00
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
os << endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::plaintextBottomHLine(odocstream & os, row_type row,
|
2007-05-28 22:27:45 +00:00
|
|
|
vector<unsigned int> const & clen) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
idx_type const fcell = getFirstCellInRow(row);
|
|
|
|
idx_type const n = numberOfCellsInRow(fcell) + fcell;
|
|
|
|
idx_type tmp = 0;
|
2003-03-09 18:11:57 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
if (bottomLine(i)) {
|
|
|
|
++tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!tmp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char_type ch;
|
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
if (bottomLine(i)) {
|
|
|
|
if (leftLine(i))
|
|
|
|
os << "+-";
|
|
|
|
else
|
|
|
|
os << "--";
|
|
|
|
ch = '-';
|
|
|
|
} else {
|
|
|
|
os << " ";
|
|
|
|
ch = ' ';
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
col_type column = cellColumn(i);
|
2007-04-26 12:54:21 +00:00
|
|
|
int len = clen[column];
|
2008-04-21 13:33:39 +00:00
|
|
|
while (column < column_info.size() -1
|
2007-04-26 12:54:21 +00:00
|
|
|
&& isPartOfMultiColumn(row, ++column))
|
|
|
|
len += clen[column] + 4;
|
|
|
|
os << docstring(len, ch);
|
|
|
|
if (bottomLine(i)) {
|
|
|
|
if (rightLine(i))
|
|
|
|
os << "-+";
|
|
|
|
else
|
|
|
|
os << "--";
|
|
|
|
} else {
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << endl;
|
|
|
|
return true;
|
|
|
|
}
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::plaintextPrintCell(odocstream & os,
|
2007-04-26 12:54:21 +00:00
|
|
|
OutputParams const & runparams,
|
|
|
|
idx_type cell, row_type row, col_type column,
|
|
|
|
vector<unsigned int> const & clen,
|
|
|
|
bool onlydata) const
|
2003-03-09 18:11:57 +00:00
|
|
|
{
|
2007-04-26 12:54:21 +00:00
|
|
|
odocstringstream sstr;
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInset(cell)->plaintext(sstr, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
if (onlydata) {
|
|
|
|
os << sstr.str();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftLine(cell))
|
|
|
|
os << "| ";
|
|
|
|
else
|
|
|
|
os << " ";
|
|
|
|
|
|
|
|
unsigned int len1 = sstr.str().length();
|
|
|
|
unsigned int len2 = clen[column];
|
2008-04-21 13:33:39 +00:00
|
|
|
while (column < column_info.size() -1
|
2007-04-26 12:54:21 +00:00
|
|
|
&& isPartOfMultiColumn(row, ++column))
|
|
|
|
len2 += clen[column] + 4;
|
|
|
|
len2 -= len1;
|
|
|
|
|
|
|
|
switch (getAlignment(cell)) {
|
|
|
|
default:
|
|
|
|
case LYX_ALIGN_LEFT:
|
|
|
|
len1 = 0;
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_RIGHT:
|
|
|
|
len1 = len2;
|
|
|
|
len2 = 0;
|
|
|
|
break;
|
|
|
|
case LYX_ALIGN_CENTER:
|
|
|
|
len1 = len2 / 2;
|
|
|
|
len2 -= len1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
os << docstring(len1, ' ') << sstr.str()
|
|
|
|
<< docstring(len2, ' ');
|
|
|
|
|
|
|
|
if (rightLine(cell))
|
|
|
|
os << " |";
|
|
|
|
else
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void Tabular::plaintext(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams, int const depth,
|
2007-11-01 16:59:40 +00:00
|
|
|
bool onlydata, char_type delim) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
|
|
|
// first calculate the width of the single columns
|
2008-04-21 13:33:39 +00:00
|
|
|
vector<unsigned int> clen(column_info.size());
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
if (!onlydata) {
|
|
|
|
// first all non (real) multicolumn cells!
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
clen[j] = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-09-04 10:52:08 +00:00
|
|
|
idx_type cell = cellIndex(i, j);
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isMultiColumnReal(cell))
|
|
|
|
continue;
|
|
|
|
odocstringstream sstr;
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInset(cell)->plaintext(sstr, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
if (clen[j] < sstr.str().length())
|
|
|
|
clen[j] = sstr.str().length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// then all (real) multicolumn cells!
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-09-04 10:52:08 +00:00
|
|
|
idx_type cell = cellIndex(i, j);
|
2007-04-26 12:54:21 +00:00
|
|
|
if (!isMultiColumnReal(cell) || isPartOfMultiColumn(i, j))
|
|
|
|
continue;
|
|
|
|
odocstringstream sstr;
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInset(cell)->plaintext(sstr, runparams);
|
2007-04-26 12:54:21 +00:00
|
|
|
int len = int(sstr.str().length());
|
2008-03-18 18:08:32 +00:00
|
|
|
idx_type const n = columnSpan(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
for (col_type k = j; len > 0 && k < j + n - 1; ++k)
|
|
|
|
len -= clen[k];
|
|
|
|
if (len > int(clen[j + n - 1]))
|
|
|
|
clen[j + n - 1] = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idx_type cell = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < row_info.size(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (!onlydata && plaintextTopHLine(os, i, clen))
|
|
|
|
os << docstring(depth * 2, ' ');
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < column_info.size(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
if (isPartOfMultiColumn(i, j))
|
|
|
|
continue;
|
|
|
|
if (onlydata && j > 0)
|
2007-11-01 16:59:40 +00:00
|
|
|
// we don't use operator<< for single UCS4 character.
|
|
|
|
// see explanation in docstream.h
|
|
|
|
os.put(delim);
|
2008-02-27 20:43:16 +00:00
|
|
|
plaintextPrintCell(os, runparams, cell, i, j, clen, onlydata);
|
2007-04-26 12:54:21 +00:00
|
|
|
++cell;
|
|
|
|
}
|
|
|
|
os << endl;
|
|
|
|
if (!onlydata) {
|
|
|
|
os << docstring(depth * 2, ' ');
|
|
|
|
if (plaintextBottomHLine(os, i, clen))
|
|
|
|
os << docstring(depth * 2, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
shared_ptr<InsetTableCell> Tabular::cellInset(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
return cell_info[cellRow(cell)][cellColumn(cell)].inset;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
shared_ptr<InsetTableCell> Tabular::cellInset(row_type row,
|
2007-04-26 12:54:21 +00:00
|
|
|
col_type column) const
|
|
|
|
{
|
|
|
|
return cell_info[row][column].inset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setCellInset(row_type row, col_type column,
|
2008-03-21 06:16:05 +00:00
|
|
|
shared_ptr<InsetTableCell> ins) const
|
2007-04-26 12:54:21 +00:00
|
|
|
{
|
2008-03-21 17:45:14 +00:00
|
|
|
CellData & cd = cell_info[row][column];
|
|
|
|
cd.inset = ins;
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
features.require("NeedTabularnewline");
|
2008-04-21 13:33:39 +00:00
|
|
|
if (use_booktabs)
|
2007-04-26 12:54:21 +00:00
|
|
|
features.require("booktabs");
|
2008-04-21 13:33:39 +00:00
|
|
|
if (is_long_tabular)
|
2007-04-26 12:54:21 +00:00
|
|
|
features.require("longtable");
|
|
|
|
if (needRotating())
|
|
|
|
features.require("rotating");
|
2008-04-21 13:33:39 +00:00
|
|
|
for (idx_type cell = 0; cell < numberofcells; ++cell) {
|
2008-09-10 12:49:08 +00:00
|
|
|
if (getVAlignment(cell) != LYX_VALIGN_TOP
|
|
|
|
|| !getPWidth(cell).zero())
|
2007-04-26 12:54:21 +00:00
|
|
|
features.require("array");
|
2008-03-25 13:32:38 +00:00
|
|
|
cellInset(cell)->validate(features);
|
2007-04-26 12:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::BoxType Tabular::useParbox(idx_type cell) const
|
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
ParagraphList const & parlist = cellInset(cell)->paragraphs();
|
2007-04-26 12:54:21 +00:00
|
|
|
ParagraphList::const_iterator cit = parlist.begin();
|
|
|
|
ParagraphList::const_iterator end = parlist.end();
|
|
|
|
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
for (int i = 0; i < cit->size(); ++i)
|
|
|
|
if (cit->isNewline(i))
|
|
|
|
return BOX_PARBOX;
|
|
|
|
|
|
|
|
return BOX_NONE;
|
2003-03-09 18:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 17:45:14 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetTableCell
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetTableCell::InsetTableCell(Buffer * buf)
|
2009-04-04 19:34:14 +00:00
|
|
|
: InsetText(buf, InsetText::PlainLayout), isFixedWidth(false),
|
2008-09-13 10:10:01 +00:00
|
|
|
contentAlign(LYX_ALIGN_CENTER)
|
2008-03-21 17:45:14 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-07-10 17:41:52 +00:00
|
|
|
bool InsetTableCell::forcePlainLayout(idx_type) const
|
2008-03-21 17:45:14 +00:00
|
|
|
{
|
2008-07-16 14:23:32 +00:00
|
|
|
return !isFixedWidth;
|
2008-03-21 17:45:14 +00:00
|
|
|
}
|
|
|
|
|
2008-09-10 16:02:32 +00:00
|
|
|
|
2008-03-21 17:45:14 +00:00
|
|
|
bool InsetTableCell::allowParagraphCustomization(idx_type) const
|
|
|
|
{
|
2008-07-16 14:23:32 +00:00
|
|
|
return isFixedWidth;
|
2008-03-21 17:45:14 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 18:42:17 +00:00
|
|
|
|
2008-03-21 17:45:14 +00:00
|
|
|
bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
switch (cmd.action) {
|
|
|
|
case LFUN_LAYOUT:
|
2008-07-10 17:41:52 +00:00
|
|
|
enabled = !forcePlainLayout();
|
2008-03-21 17:45:14 +00:00
|
|
|
break;
|
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
|
|
|
enabled = allowParagraphCustomization();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return InsetText::getStatus(cur, cmd, status);
|
|
|
|
}
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(enabled);
|
2008-03-21 17:45:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-08 21:26:18 +00:00
|
|
|
docstring InsetTableCell::asString(bool intoInsets)
|
|
|
|
{
|
|
|
|
docstring retval;
|
|
|
|
if (paragraphs().empty())
|
|
|
|
return retval;
|
|
|
|
ParagraphList::const_iterator it = paragraphs().begin();
|
|
|
|
ParagraphList::const_iterator en = paragraphs().end();
|
|
|
|
bool first = true;
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
if (!first)
|
|
|
|
retval += "\n";
|
|
|
|
else
|
|
|
|
first = false;
|
|
|
|
retval += it->asString(intoInsets ? AS_STR_INSETS : AS_STR_NONE);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetTabular
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetTabular::InsetTabular(Buffer * buf, row_type rows,
|
2006-04-05 23:56:29 +00:00
|
|
|
col_type columns)
|
2009-11-08 15:53:21 +00:00
|
|
|
: Inset(buf), tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))), scx_(0),
|
2008-03-25 21:26:03 +00:00
|
|
|
rowselect_(false), colselect_(false)
|
2008-02-23 22:32:33 +00:00
|
|
|
{
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2003-06-03 15:10:14 +00:00
|
|
|
InsetTabular::InsetTabular(InsetTabular const & tab)
|
2008-02-23 22:32:33 +00:00
|
|
|
: Inset(tab), tabular(tab.tabular), scx_(0)
|
|
|
|
{
|
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
InsetTabular::~InsetTabular()
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
hideDialogs("tabular", this);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-23 13:25:03 +00:00
|
|
|
void InsetTabular::setBuffer(Buffer & buf)
|
|
|
|
{
|
|
|
|
tabular.setBuffer(buf);
|
|
|
|
Inset::setBuffer(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
bool InsetTabular::insetAllowed(InsetCode code) const
|
|
|
|
{
|
2009-02-14 21:39:15 +00:00
|
|
|
if (code == MATHMACRO_CODE
|
|
|
|
|| (code == CAPTION_CODE && !tabular.is_long_tabular))
|
2007-12-21 20:42:46 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetTabular::write(ostream & os) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2003-07-28 13:04:40 +00:00
|
|
|
os << "Tabular" << endl;
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.write(os);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-28 18:50:33 +00:00
|
|
|
docstring InsetTabular::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
// FIXME: depending on the selection state, we could offer a different menu.
|
|
|
|
return from_ascii("context-tabular");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetTabular::read(Lexer & lex)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
//bool const old_format = (lex.getString() == "\\LyXTable");
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.read(lex);
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2008-04-05 10:34:29 +00:00
|
|
|
//if (old_format)
|
2008-04-05 21:24:57 +00:00
|
|
|
// return;
|
2000-05-17 14:43:09 +00:00
|
|
|
|
2004-10-05 12:56:22 +00:00
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
string token = lex.getString();
|
2007-03-26 13:43:49 +00:00
|
|
|
while (lex && token != "\\end_inset") {
|
2004-10-05 12:56:22 +00:00
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
token = lex.getString();
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2008-04-05 21:24:57 +00:00
|
|
|
if (!lex)
|
|
|
|
lex.printError("Missing \\end_inset at this point. ");
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
int InsetTabular::rowFromY(Cursor & cur, int y) const
|
|
|
|
{
|
|
|
|
// top y coordinate of tabular
|
|
|
|
int h = yo(cur.bv()) - tabular.rowAscent(0);
|
2008-04-21 13:33:39 +00:00
|
|
|
size_t nrows = tabular.row_info.size();
|
2008-03-18 18:08:32 +00:00
|
|
|
row_type r = 0;
|
2008-04-05 21:24:57 +00:00
|
|
|
for (; r < nrows && y > h; ++r) {
|
2008-03-18 18:08:32 +00:00
|
|
|
h += tabular.rowAscent(r);
|
|
|
|
h += tabular.rowDescent(r);
|
|
|
|
h += tabular.getAdditionalHeight(r);
|
|
|
|
}
|
|
|
|
return r - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetTabular::columnFromX(Cursor & cur, int x) const
|
|
|
|
{
|
|
|
|
// left x coordinate of tabular
|
|
|
|
int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH;
|
2008-04-21 13:33:39 +00:00
|
|
|
size_t ncols = tabular.column_info.size();
|
2008-03-18 18:08:32 +00:00
|
|
|
col_type c = 0;
|
2008-04-05 21:24:57 +00:00
|
|
|
for (; c < ncols && x > w; ++c)
|
2008-03-18 18:08:32 +00:00
|
|
|
w += tabular.columnWidth(c);
|
|
|
|
return c - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2003-07-17 15:57:08 +00:00
|
|
|
//lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
|
|
|
|
// mi.base.textwidth << "\n";
|
|
|
|
if (!mi.base.bv) {
|
2008-04-05 21:24:57 +00:00
|
|
|
LYXERR0("need bv");
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(false, /**/);
|
2003-07-17 15:57:08 +00:00
|
|
|
}
|
2003-07-25 17:11:25 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
row_type i = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (idx_type cell = 0; i < tabular.row_info.size(); ++i) {
|
2004-02-16 11:58:51 +00:00
|
|
|
int maxAsc = 0;
|
|
|
|
int maxDesc = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < tabular.column_info.size(); ++j) {
|
2004-02-16 11:58:51 +00:00
|
|
|
if (tabular.isPartOfMultiColumn(i, j))
|
2005-09-16 10:19:02 +00:00
|
|
|
// Multicolumn cell, but not first one
|
2004-02-16 11:58:51 +00:00
|
|
|
continue;
|
|
|
|
Dimension dim;
|
|
|
|
MetricsInfo m = mi;
|
2007-04-28 12:58:49 +00:00
|
|
|
Length p_width;
|
2006-04-05 23:56:29 +00:00
|
|
|
if (tabular.cell_info[i][j].multicolumn ==
|
2008-03-18 18:08:32 +00:00
|
|
|
Tabular::CELL_BEGIN_OF_MULTICOLUMN)
|
2008-03-25 13:32:38 +00:00
|
|
|
p_width = tabular.cellInfo(cell).p_width;
|
2005-09-16 10:19:02 +00:00
|
|
|
else
|
|
|
|
p_width = tabular.column_info[j].p_width;
|
2005-06-16 15:20:09 +00:00
|
|
|
if (!p_width.zero())
|
2004-08-14 21:55:38 +00:00
|
|
|
m.base.textwidth = p_width.inPixels(mi.base.textwidth);
|
2008-03-25 13:32:38 +00:00
|
|
|
tabular.cellInset(cell)->metrics(m, dim);
|
2005-06-16 15:20:09 +00:00
|
|
|
if (!p_width.zero())
|
|
|
|
dim.wid = m.base.textwidth;
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.setCellWidth(cell, dim.wid);
|
2004-02-16 11:58:51 +00:00
|
|
|
maxAsc = max(maxAsc, dim.asc);
|
|
|
|
maxDesc = max(maxDesc, dim.des);
|
2004-12-03 13:57:50 +00:00
|
|
|
++cell;
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2006-07-03 19:13:56 +00:00
|
|
|
int const top_space = tabular.row_info[i].top_space_default ?
|
|
|
|
default_line_space :
|
|
|
|
tabular.row_info[i].top_space.inPixels(mi.base.textwidth);
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.setRowAscent(i, maxAsc + ADD_TO_HEIGHT + top_space);
|
2006-07-03 19:13:56 +00:00
|
|
|
int const bottom_space = tabular.row_info[i].bottom_space_default ?
|
|
|
|
default_line_space :
|
|
|
|
tabular.row_info[i].bottom_space.inPixels(mi.base.textwidth);
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.setRowDescent(i, maxDesc + ADD_TO_HEIGHT + bottom_space);
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2008-03-24 14:03:00 +00:00
|
|
|
tabular.updateColumnWidths();
|
2007-09-04 10:52:08 +00:00
|
|
|
dim.asc = tabular.rowAscent(0);
|
|
|
|
dim.des = tabular.height() - dim.asc;
|
|
|
|
dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
if (&cur.inset() == this && cur.selection()) {
|
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
row_type rs, re;
|
|
|
|
col_type cs, ce;
|
|
|
|
getSelection(cur, rs, re, cs, ce);
|
|
|
|
|
|
|
|
if (col >= cs && col <= ce && row >= rs && row <= re)
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
if (col == tabular.cellColumn(cur.idx())
|
|
|
|
&& row == tabular.cellRow(cur.idx())) {
|
|
|
|
CursorSlice const & beg = cur.selBegin();
|
|
|
|
CursorSlice const & end = cur.selEnd();
|
|
|
|
|
2008-11-18 21:37:02 +00:00
|
|
|
if ((end.lastpos() > 0 || end.lastpit() > 0)
|
|
|
|
&& end.pos() == end.lastpos() && beg.pos() == 0
|
|
|
|
&& end.pit() == end.lastpit() && beg.pit() == 0)
|
2008-10-25 10:47:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetTabular::draw(PainterInfo & pi, int x, int y) const
|
2001-04-04 09:42:56 +00:00
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
//lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
|
2003-05-30 06:48:24 +00:00
|
|
|
BufferView * bv = pi.base.bv;
|
2008-10-25 10:47:38 +00:00
|
|
|
Cursor & cur = pi.base.bv->cursor();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
// FIXME: As the full background is painted in drawSelection(),
|
2007-08-31 14:02:12 +00:00
|
|
|
// we have no choice but to do a full repaint for the Text cells.
|
|
|
|
pi.full_repaint = true;
|
|
|
|
|
2006-10-20 16:33:41 +00:00
|
|
|
resetPos(bv->cursor());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
2005-07-15 22:10:25 +00:00
|
|
|
x += scx_;
|
2001-04-04 09:42:56 +00:00
|
|
|
x += ADD_TO_TABULAR_WIDTH;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-11-06 14:07:49 +00:00
|
|
|
bool const original_drawing_state = pi.pain.isDrawingEnabled();
|
2008-10-25 10:47:38 +00:00
|
|
|
bool const original_selection_state = pi.selected;
|
2007-11-06 14:07:49 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
idx_type idx = 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
first_visible_cell = Tabular::npos;
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type i = 0; i < tabular.row_info.size(); ++i) {
|
2003-07-30 15:41:39 +00:00
|
|
|
int nx = x;
|
2007-09-04 10:52:08 +00:00
|
|
|
int const a = tabular.rowAscent(i);
|
|
|
|
int const d = tabular.rowDescent(i);
|
|
|
|
idx = tabular.cellIndex(i, 0);
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type j = 0; j < tabular.column_info.size(); ++j) {
|
2003-06-13 07:37:48 +00:00
|
|
|
if (tabular.isPartOfMultiColumn(i, j))
|
2003-03-17 01:34:36 +00:00
|
|
|
continue;
|
2007-04-26 12:54:21 +00:00
|
|
|
if (first_visible_cell == Tabular::npos)
|
2004-02-16 11:58:51 +00:00
|
|
|
first_visible_cell = idx;
|
2003-03-17 01:34:36 +00:00
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.selected |= isCellSelected(cur, i, j);
|
2004-02-16 11:58:51 +00:00
|
|
|
int const cx = nx + tabular.getBeginningOfTextInCell(idx);
|
2007-09-20 10:58:38 +00:00
|
|
|
// Cache the Inset position.
|
|
|
|
bv->coordCache().insets().add(cell(idx).get(), cx, y);
|
2007-09-04 10:52:08 +00:00
|
|
|
if (nx + tabular.columnWidth(idx) < 0
|
2004-11-30 01:59:49 +00:00
|
|
|
|| nx > bv->workWidth()
|
2004-12-06 02:35:12 +00:00
|
|
|
|| y + d < 0
|
2004-11-30 01:59:49 +00:00
|
|
|
|| y - a > bv->workHeight()) {
|
2006-10-30 10:09:59 +00:00
|
|
|
pi.pain.setDrawingEnabled(false);
|
2007-09-09 20:21:43 +00:00
|
|
|
cell(idx)->draw(pi, cx, y);
|
2009-02-09 21:14:23 +00:00
|
|
|
drawCellLines(pi.pain, nx, y, i, idx, pi.change_);
|
2007-11-06 14:07:49 +00:00
|
|
|
pi.pain.setDrawingEnabled(original_drawing_state);
|
2004-11-30 01:59:49 +00:00
|
|
|
} else {
|
2007-09-09 20:21:43 +00:00
|
|
|
cell(idx)->draw(pi, cx, y);
|
2009-02-09 21:14:23 +00:00
|
|
|
drawCellLines(pi.pain, nx, y, i, idx, pi.change_);
|
2004-11-30 01:59:49 +00:00
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
nx += tabular.columnWidth(idx);
|
2004-02-16 11:58:51 +00:00
|
|
|
++idx;
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.selected = original_selection_state;
|
2000-11-19 16:07:18 +00:00
|
|
|
}
|
2003-05-26 11:33:37 +00:00
|
|
|
|
2008-04-21 13:33:39 +00:00
|
|
|
if (i + 1 < tabular.row_info.size())
|
2007-09-04 10:52:08 +00:00
|
|
|
y += d + tabular.rowAscent(i + 1) +
|
2004-11-30 01:59:49 +00:00
|
|
|
tabular.getAdditionalHeight(i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor & cur = pi.base.bv->cursor();
|
2009-02-08 18:33:01 +00:00
|
|
|
resetPos(cur);
|
2006-06-18 09:27:57 +00:00
|
|
|
|
|
|
|
x += scx_ + ADD_TO_TABULAR_WIDTH;
|
|
|
|
|
2007-08-31 14:02:12 +00:00
|
|
|
// FIXME: it is wrong to completely paint the background
|
|
|
|
// if we want to do single row painting.
|
|
|
|
|
2006-06-20 10:44:49 +00:00
|
|
|
// Paint background of current tabular
|
2007-09-04 10:52:08 +00:00
|
|
|
int const w = tabular.width();
|
|
|
|
int const h = tabular.height();
|
|
|
|
int yy = y - tabular.rowAscent(0);
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.pain.fillRectangle(x, yy, w, h, pi.backgroundColor(this));
|
2006-06-18 09:27:57 +00:00
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
if (!cur.selection())
|
|
|
|
return;
|
2007-11-01 22:17:22 +00:00
|
|
|
if (&cur.inset() != this)
|
2004-11-30 01:59:49 +00:00
|
|
|
return;
|
2003-05-26 11:33:37 +00:00
|
|
|
|
2005-07-15 17:15:32 +00:00
|
|
|
//resetPos(cur);
|
2004-12-06 02:35:12 +00:00
|
|
|
|
2008-11-18 22:35:02 +00:00
|
|
|
bool const full_cell_selected = isCellSelected(cur,
|
|
|
|
tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
|
2005-01-06 15:40:49 +00:00
|
|
|
|
2008-11-18 22:35:02 +00:00
|
|
|
if (cur.selIsMultiCell() || full_cell_selected) {
|
2007-09-04 10:52:08 +00:00
|
|
|
y -= tabular.rowAscent(0);
|
2008-04-21 13:33:39 +00:00
|
|
|
for (row_type j = 0; j < tabular.row_info.size(); ++j) {
|
2007-09-04 10:52:08 +00:00
|
|
|
int const a = tabular.rowAscent(j);
|
|
|
|
int const h = a + tabular.rowDescent(j);
|
2004-11-30 01:59:49 +00:00
|
|
|
int xx = x;
|
|
|
|
y += tabular.getAdditionalHeight(j);
|
2008-04-21 13:33:39 +00:00
|
|
|
for (col_type i = 0; i < tabular.column_info.size(); ++i) {
|
2004-11-30 01:59:49 +00:00
|
|
|
if (tabular.isPartOfMultiColumn(j, i))
|
|
|
|
continue;
|
2004-12-03 13:57:50 +00:00
|
|
|
idx_type const cell =
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.cellIndex(j, i);
|
|
|
|
int const w = tabular.columnWidth(cell);
|
2008-10-25 10:47:38 +00:00
|
|
|
if (isCellSelected(cur, j, i))
|
2008-11-18 22:35:02 +00:00
|
|
|
pi.pain.fillRectangle(xx, y, w, h, Color_selection);
|
2004-11-30 01:59:49 +00:00
|
|
|
xx += w;
|
|
|
|
}
|
|
|
|
y += h;
|
|
|
|
}
|
2005-01-06 15:40:49 +00:00
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
} else {
|
2008-03-25 13:32:38 +00:00
|
|
|
x += cellXPos(cur.idx());
|
2007-06-25 08:19:15 +00:00
|
|
|
x += tabular.getBeginningOfTextInCell(cur.idx());
|
|
|
|
cell(cur.idx())->drawSelection(pi, x, 0 /* ignored */);
|
2000-09-28 14:05:24 +00:00
|
|
|
}
|
2000-06-16 15:13:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetTabular::drawCellLines(Painter & pain, int x, int y,
|
2009-02-09 21:14:23 +00:00
|
|
|
row_type row, idx_type cell, Change const & change) const
|
2001-04-04 09:42:56 +00:00
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
int x2 = x + tabular.columnWidth(cell);
|
2003-11-10 09:06:48 +00:00
|
|
|
bool on_off = false;
|
2009-02-09 21:14:23 +00:00
|
|
|
Color col = Color_tabularline;
|
|
|
|
Color onoffcol = Color_tabularonoffline;
|
2005-09-07 10:37:05 +00:00
|
|
|
|
2009-02-09 21:14:23 +00:00
|
|
|
if (change.changed()) {
|
|
|
|
col = change.color();
|
|
|
|
onoffcol = change.color();
|
2005-09-07 10:37:05 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-06-13 07:37:48 +00:00
|
|
|
if (!tabular.topAlreadyDrawn(cell)) {
|
|
|
|
on_off = !tabular.topLine(cell);
|
2007-09-04 10:52:08 +00:00
|
|
|
pain.line(x, y - tabular.rowAscent(row),
|
|
|
|
x2, y - tabular.rowAscent(row),
|
2005-09-07 10:37:05 +00:00
|
|
|
on_off ? onoffcol : col,
|
2001-04-04 22:08:13 +00:00
|
|
|
on_off ? Painter::line_onoffdash : Painter::line_solid);
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2003-06-13 07:37:48 +00:00
|
|
|
on_off = !tabular.bottomLine(cell);
|
2007-09-04 10:52:08 +00:00
|
|
|
pain.line(x, y + tabular.rowDescent(row),
|
|
|
|
x2, y + tabular.rowDescent(row),
|
2005-09-07 10:37:05 +00:00
|
|
|
on_off ? onoffcol : col,
|
2001-04-04 22:08:13 +00:00
|
|
|
on_off ? Painter::line_onoffdash : Painter::line_solid);
|
2003-06-13 07:37:48 +00:00
|
|
|
if (!tabular.leftAlreadyDrawn(cell)) {
|
|
|
|
on_off = !tabular.leftLine(cell);
|
2007-09-04 10:52:08 +00:00
|
|
|
pain.line(x, y - tabular.rowAscent(row),
|
|
|
|
x, y + tabular.rowDescent(row),
|
2005-09-07 10:37:05 +00:00
|
|
|
on_off ? onoffcol : col,
|
2001-04-04 22:08:13 +00:00
|
|
|
on_off ? Painter::line_onoffdash : Painter::line_solid);
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2003-06-13 07:37:48 +00:00
|
|
|
on_off = !tabular.rightLine(cell);
|
|
|
|
pain.line(x2 - tabular.getAdditionalWidth(cell),
|
2007-09-04 10:52:08 +00:00
|
|
|
y - tabular.rowAscent(row),
|
2003-06-13 07:37:48 +00:00
|
|
|
x2 - tabular.getAdditionalWidth(cell),
|
2007-09-04 10:52:08 +00:00
|
|
|
y + tabular.rowDescent(row),
|
2005-09-07 10:37:05 +00:00
|
|
|
on_off ? onoffcol : col,
|
2001-04-04 22:08:13 +00:00
|
|
|
on_off ? Painter::line_onoffdash : Painter::line_solid);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-12 20:58:12 +00:00
|
|
|
void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
|
2003-10-15 08:49:44 +00:00
|
|
|
{
|
2006-01-19 15:49:21 +00:00
|
|
|
//lyxerr << "InsetTabular::edit: " << this << endl;
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.finishUndo();
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2004-08-16 00:32:04 +00:00
|
|
|
cur.push(*this);
|
2008-02-12 20:58:12 +00:00
|
|
|
if (front) {
|
2004-01-20 14:25:24 +00:00
|
|
|
if (isRightToLeft(cur))
|
2004-10-23 09:46:33 +00:00
|
|
|
cur.idx() = tabular.getLastCellInRow(0);
|
2003-11-04 12:36:59 +00:00
|
|
|
else
|
2004-10-23 09:46:33 +00:00
|
|
|
cur.idx() = 0;
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2004-10-23 09:46:33 +00:00
|
|
|
cur.pos() = 0;
|
2003-11-04 12:36:59 +00:00
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
if (isRightToLeft(cur))
|
2008-04-21 13:33:39 +00:00
|
|
|
cur.idx() = tabular.getFirstCellInRow(tabular.row_info.size() - 1);
|
2003-11-04 12:36:59 +00:00
|
|
|
else
|
2008-04-21 13:33:39 +00:00
|
|
|
cur.idx() = tabular.numberofcells - 1;
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2004-10-23 09:46:33 +00:00
|
|
|
cur.pos() = cur.lastpos(); // FIXME crude guess
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
2006-10-20 16:11:30 +00:00
|
|
|
// FIXME: this accesses the position cache before it is initialized
|
2004-08-14 14:03:42 +00:00
|
|
|
//resetPos(cur);
|
|
|
|
//cur.bv().fitCursor();
|
2003-11-04 12:36:59 +00:00
|
|
|
}
|
2003-10-15 08:49:44 +00:00
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetTabular::updateLabels(ParIterator const & it)
|
2007-08-12 21:43:58 +00:00
|
|
|
{
|
|
|
|
// In a longtable, tell captions what the current float is
|
2008-11-15 19:30:58 +00:00
|
|
|
Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
|
2007-08-12 21:43:58 +00:00
|
|
|
string const saveflt = cnts.current_float();
|
2008-04-21 13:33:39 +00:00
|
|
|
if (tabular.is_long_tabular)
|
2007-08-12 21:43:58 +00:00
|
|
|
cnts.current_float("table");
|
|
|
|
|
|
|
|
ParIterator it2 = it;
|
|
|
|
it2.forwardPos();
|
2007-08-14 14:41:06 +00:00
|
|
|
size_t const end = it2.nargs();
|
2007-08-23 21:35:40 +00:00
|
|
|
for ( ; it2.idx() < end; it2.top().forwardIdx())
|
2008-11-16 17:49:00 +00:00
|
|
|
buffer().updateLabels(it2);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
|
|
|
//reset afterwards
|
2008-04-21 13:33:39 +00:00
|
|
|
if (tabular.is_long_tabular)
|
2007-08-12 21:43:58 +00:00
|
|
|
cnts.current_float(saveflt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2004-02-13 16:22:53 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::DEBUG, "# InsetTabular::doDispatch: cmd: " << cmd
|
|
|
|
<< "\n cur:" << cur);
|
2004-03-01 17:12:09 +00:00
|
|
|
CursorSlice sl = cur.top();
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor & bvcur = cur.bv().cursor();
|
2003-10-15 08:49:44 +00:00
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
switch (cmd.action) {
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2008-03-18 18:08:32 +00:00
|
|
|
case LFUN_MOUSE_PRESS: {
|
2005-07-15 11:43:07 +00:00
|
|
|
//lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
|
2008-03-18 18:08:32 +00:00
|
|
|
// 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);
|
|
|
|
cur.idx() = tabular.getFirstCellInRow(r);
|
|
|
|
cur.pos() = 0;
|
|
|
|
cur.resetAnchor();
|
|
|
|
cur.idx() = tabular.getLastCellInRow(r);
|
|
|
|
cur.pos() = cur.lastpos();
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(true);
|
2008-03-18 18:08:32 +00:00
|
|
|
bvcur = cur;
|
2008-03-25 21:26:03 +00:00
|
|
|
rowselect_ = true;
|
2008-03-18 18:08:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
cur.idx() = tabular.cellIndex(0, c);
|
|
|
|
cur.pos() = 0;
|
|
|
|
cur.resetAnchor();
|
2008-04-21 13:33:39 +00:00
|
|
|
cur.idx() = tabular.cellIndex(tabular.row_info.size() - 1, c);
|
2008-03-18 18:08:32 +00:00
|
|
|
cur.pos() = cur.lastpos();
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(true);
|
2008-03-18 18:08:32 +00:00
|
|
|
bvcur = cur;
|
2008-03-25 21:26:03 +00:00
|
|
|
colselect_ = true;
|
2008-03-18 18:08:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-13 15:38:32 +00:00
|
|
|
// do not reset cursor/selection if we have selected
|
|
|
|
// some cells (bug 2715).
|
|
|
|
if (cmd.button() == mouse_button::button3
|
|
|
|
&& &bvcur.selBegin().inset() == this
|
2008-08-09 16:29:25 +00:00
|
|
|
&& bvcur.selIsMultiCell())
|
2007-08-13 15:38:32 +00:00
|
|
|
;
|
|
|
|
else
|
2008-03-21 06:16:05 +00:00
|
|
|
// Let InsetTableCell do it
|
2007-08-13 15:38:32 +00:00
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2003-12-12 15:18:29 +00:00
|
|
|
break;
|
2008-03-18 18:08:32 +00:00
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
case LFUN_MOUSE_MOTION:
|
2005-07-15 11:43:07 +00:00
|
|
|
//lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
|
2004-08-14 22:38:45 +00:00
|
|
|
if (cmd.button() == mouse_button::button1) {
|
2004-08-14 21:23:16 +00:00
|
|
|
// only accept motions to places not deeper nested than the real anchor
|
2008-03-18 18:08:32 +00:00
|
|
|
if (!bvcur.anchor_.hasPart(cur)) {
|
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// select (additional) row
|
2008-03-25 21:26:03 +00:00
|
|
|
if (rowselect_) {
|
2008-03-18 18:08:32 +00:00
|
|
|
row_type r = rowFromY(cur, cmd.y);
|
|
|
|
cur.idx() = tabular.getLastCellInRow(r);
|
2008-08-08 19:21:06 +00:00
|
|
|
// we need to reset the cursor's pit and pos now, as the old ones
|
|
|
|
// may no longer be valid.
|
|
|
|
cur.pit() = 0;
|
|
|
|
cur.pos() = 0;
|
2004-08-14 21:23:16 +00:00
|
|
|
bvcur.setCursor(cur);
|
2008-09-24 21:27:41 +00:00
|
|
|
bvcur.setSelection(true);
|
2008-03-18 18:08:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// select (additional) column
|
2008-03-25 21:26:03 +00:00
|
|
|
if (colselect_) {
|
2008-03-18 18:08:32 +00:00
|
|
|
col_type c = columnFromX(cur, cmd.x);
|
2008-04-21 13:33:39 +00:00
|
|
|
cur.idx() = tabular.cellIndex(tabular.row_info.size() - 1, c);
|
2008-08-08 19:21:06 +00:00
|
|
|
// we need to reset the cursor's pit and pos now, as the old ones
|
|
|
|
// may no longer be valid.
|
|
|
|
cur.pit() = 0;
|
|
|
|
cur.pos() = 0;
|
2008-03-18 18:08:32 +00:00
|
|
|
bvcur.setCursor(cur);
|
2008-09-24 21:27:41 +00:00
|
|
|
bvcur.setSelection(true);
|
2008-03-18 18:08:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// only update if selection changes
|
|
|
|
if (bvcur.idx() == cur.idx() &&
|
|
|
|
!(bvcur.anchor_.idx() == cur.idx() && bvcur.pos() != cur.pos()))
|
|
|
|
cur.noUpdate();
|
|
|
|
setCursorFromCoordinates(cur, cmd.x, cmd.y);
|
|
|
|
bvcur.setCursor(cur);
|
2008-09-24 21:27:41 +00:00
|
|
|
bvcur.setSelection(true);
|
2008-08-08 19:34:47 +00:00
|
|
|
// if this is a multicell selection, we just set the cursor to
|
|
|
|
// the beginning of the cell's text.
|
2008-08-09 16:29:25 +00:00
|
|
|
if (bvcur.selIsMultiCell()) {
|
2008-10-01 08:18:57 +00:00
|
|
|
bvcur.pit() = bvcur.lastpit();
|
|
|
|
bvcur.pos() = bvcur.lastpos();
|
2008-08-08 19:34:47 +00:00
|
|
|
}
|
2004-08-14 21:23:16 +00:00
|
|
|
}
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-12-12 15:18:29 +00:00
|
|
|
|
2008-03-25 21:26:03 +00:00
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
rowselect_ = false;
|
|
|
|
colselect_ = false;
|
|
|
|
break;
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
case LFUN_CELL_BACKWARD:
|
|
|
|
movePrevCell(cur);
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-12-12 15:18:29 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_CELL_FORWARD:
|
2004-02-16 11:58:51 +00:00
|
|
|
moveNextCell(cur);
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2008-08-09 00:43:15 +00:00
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
case LFUN_CHAR_FORWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_CHAR_FORWARD:
|
2008-04-11 12:02:10 +00:00
|
|
|
case LFUN_CHAR_BACKWARD_SELECT:
|
|
|
|
case LFUN_CHAR_BACKWARD:
|
|
|
|
case LFUN_CHAR_RIGHT_SELECT:
|
|
|
|
case LFUN_CHAR_RIGHT:
|
|
|
|
case LFUN_CHAR_LEFT_SELECT:
|
|
|
|
case LFUN_CHAR_LEFT: {
|
|
|
|
// determine whether we move to next or previous cell, where to enter
|
|
|
|
// the new cell from, and which command to "finish" (i.e., exit the
|
|
|
|
// inset) with:
|
|
|
|
bool next_cell;
|
|
|
|
EntryDirection entry_from = ENTRY_DIRECTION_IGNORE;
|
|
|
|
FuncCode finish_lfun;
|
|
|
|
|
|
|
|
if (cmd.action == LFUN_CHAR_FORWARD
|
|
|
|
|| cmd.action == 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) {
|
|
|
|
next_cell = false;
|
|
|
|
finish_lfun = LFUN_FINISHED_BACKWARD;
|
|
|
|
}
|
|
|
|
// LEFT or RIGHT commands --- the interpretation will depend on the
|
|
|
|
// table's direction.
|
|
|
|
else {
|
2009-02-05 22:14:57 +00:00
|
|
|
bool const right = cmd.action == LFUN_CHAR_RIGHT
|
|
|
|
|| cmd.action == LFUN_CHAR_RIGHT_SELECT;
|
|
|
|
next_cell = isRightToLeft(cur) != right;
|
2008-04-11 12:02:10 +00:00
|
|
|
|
2009-02-05 22:14:57 +00:00
|
|
|
if (lyxrc.visual_cursor)
|
2008-04-11 12:02:10 +00:00
|
|
|
entry_from = right ? ENTRY_DIRECTION_LEFT:ENTRY_DIRECTION_RIGHT;
|
|
|
|
|
2009-02-05 22:14:57 +00:00
|
|
|
finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
|
2004-03-18 12:53:43 +00:00
|
|
|
}
|
2002-08-19 10:11:13 +00:00
|
|
|
|
2009-02-07 15:24:47 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
// If we have a multicell selection or we're
|
|
|
|
// not doing some LFUN_*_SELECT thing anyway...
|
|
|
|
if (!cur.selIsMultiCell() || !select) {
|
|
|
|
col_type const c = tabular.cellColumn(cur.idx());
|
|
|
|
row_type const r = tabular.cellRow(cur.idx());
|
|
|
|
// Are we trying to select the whole cell and is the whole cell
|
|
|
|
// not yet selected?
|
|
|
|
bool const select_whole = select && !isCellSelected(cur, r, c) &&
|
|
|
|
((next_cell && cur.pit() == cur.lastpit()
|
|
|
|
&& cur.pos() == cur.lastpos())
|
|
|
|
|| (!next_cell && cur.pit() == 0 && cur.pos() == 0));
|
|
|
|
|
2009-08-18 18:34:22 +00:00
|
|
|
bool const empty_cell = cur.lastpos() == 0 && cur.lastpit() == 0;
|
|
|
|
|
2008-08-09 00:43:15 +00:00
|
|
|
// ...try to dispatch to the cell's inset.
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2009-02-07 15:24:47 +00:00
|
|
|
|
|
|
|
// When we already have a selection we want to select the whole cell
|
|
|
|
// before going to the next cell.
|
|
|
|
if (select_whole && !empty_cell){
|
|
|
|
getText(cur.idx())->selectAll(cur);
|
|
|
|
cur.dispatched();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: When we support the selection of an empty cell, remove
|
|
|
|
// the !empty_cell from this condition. For now we jump to the next
|
|
|
|
// cell if the current cell is empty.
|
|
|
|
if (cur.result().dispatched() && !empty_cell)
|
2008-08-09 00:43:15 +00:00
|
|
|
break;
|
2004-03-18 12:53:43 +00:00
|
|
|
}
|
2009-02-07 15:24:47 +00:00
|
|
|
|
2008-08-09 00:43:15 +00:00
|
|
|
// move to next/prev cell, as appropriate
|
|
|
|
// note that we will always do this if we're selecting and we have
|
|
|
|
// a multicell selection
|
|
|
|
LYXERR(Debug::RTL, "entering " << (next_cell ? "next" : "previous")
|
|
|
|
<< " cell from: " << int(entry_from));
|
|
|
|
if (next_cell)
|
|
|
|
moveNextCell(cur, entry_from);
|
|
|
|
else
|
|
|
|
movePrevCell(cur, entry_from);
|
|
|
|
// if we're exiting the table, call the appropriate FINISHED lfun
|
|
|
|
if (sl == cur.top())
|
|
|
|
cmd = FuncRequest(finish_lfun);
|
|
|
|
else
|
|
|
|
cur.dispatched();
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2008-04-11 12:02:10 +00:00
|
|
|
}
|
2007-10-22 22:18:52 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_DOWN_SELECT:
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_DOWN:
|
2008-11-19 01:02:48 +00:00
|
|
|
if (!(cur.selection() && cur.selIsMultiCell()))
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
|
|
|
|
2004-03-27 12:40:39 +00:00
|
|
|
cur.dispatched(); // override the cell's decision
|
2008-11-19 01:02:48 +00:00
|
|
|
if (sl == cur.top()) {
|
2007-04-29 23:33:02 +00:00
|
|
|
// if our Text didn't do anything to the cursor
|
2005-07-18 10:24:35 +00:00
|
|
|
// then we try to put the cursor into the cell below
|
|
|
|
// setting also the right targetX.
|
2008-11-19 01:02:48 +00:00
|
|
|
cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
|
2008-04-21 13:33:39 +00:00
|
|
|
if (tabular.cellRow(cur.idx()) != tabular.row_info.size() - 1) {
|
2008-03-25 13:32:38 +00:00
|
|
|
cur.idx() = tabular.cellBelow(cur.idx());
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2007-01-01 11:36:30 +00:00
|
|
|
TextMetrics const & tm =
|
|
|
|
cur.bv().textMetrics(cell(cur.idx())->getText(0));
|
|
|
|
cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2008-11-19 01:02:48 +00:00
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
if (sl == cur.top()) {
|
2007-10-22 22:18:52 +00:00
|
|
|
// we trick it to go to forward after leaving the
|
2005-07-18 10:24:35 +00:00
|
|
|
// tabular.
|
2007-10-22 22:18:52 +00:00
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
2004-03-18 12:53:43 +00:00
|
|
|
cur.undispatched();
|
|
|
|
}
|
2008-10-01 08:18:57 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
return;
|
|
|
|
}
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_UP_SELECT:
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_UP:
|
2008-11-19 01:02:48 +00:00
|
|
|
if (!(cur.selection() && cur.selIsMultiCell()))
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-03-27 12:40:39 +00:00
|
|
|
cur.dispatched(); // override the cell's decision
|
2008-11-19 01:02:48 +00:00
|
|
|
if (sl == cur.top()) {
|
2007-04-29 23:33:02 +00:00
|
|
|
// if our Text didn't do anything to the cursor
|
2005-07-18 10:24:35 +00:00
|
|
|
// then we try to put the cursor into the cell above
|
|
|
|
// setting also the right targetX.
|
2008-11-19 01:02:48 +00:00
|
|
|
cur.selHandle(cmd.action == LFUN_UP_SELECT);
|
2007-09-04 10:52:08 +00:00
|
|
|
if (tabular.cellRow(cur.idx()) != 0) {
|
2008-03-25 13:32:38 +00:00
|
|
|
cur.idx() = tabular.cellAbove(cur.idx());
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = cur.lastpit();
|
2007-04-29 23:33:02 +00:00
|
|
|
Text const * text = cell(cur.idx())->getText(0);
|
2007-01-01 11:36:30 +00:00
|
|
|
TextMetrics const & tm = cur.bv().textMetrics(text);
|
2006-12-29 23:54:48 +00:00
|
|
|
ParagraphMetrics const & pm =
|
2007-01-01 11:36:30 +00:00
|
|
|
tm.parMetrics(cur.lastpit());
|
|
|
|
cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, cur.targetX());
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2008-11-19 01:02:48 +00:00
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
if (sl == cur.top()) {
|
2007-05-29 20:53:32 +00:00
|
|
|
cmd = FuncRequest(LFUN_UP);
|
2004-03-18 12:53:43 +00:00
|
|
|
cur.undispatched();
|
|
|
|
}
|
2008-10-01 08:18:57 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
2008-11-19 01:02:48 +00:00
|
|
|
cur.pit() = 0;
|
2008-10-01 08:18:57 +00:00
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
return;
|
|
|
|
}
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
// case LFUN_SCREEN_DOWN: {
|
2004-11-30 01:59:49 +00:00
|
|
|
// //if (hasSelection())
|
|
|
|
// // cur.selection() = false;
|
2007-09-04 10:52:08 +00:00
|
|
|
// col_type const col = tabular.cellColumn(cur.idx());
|
2006-07-13 16:37:55 +00:00
|
|
|
// int const t = cur.bv().top_y() + cur.bv().height();
|
2004-11-30 01:59:49 +00:00
|
|
|
// if (t < yo() + tabular.getHeightOfTabular()) {
|
|
|
|
// cur.bv().scrollDocView(t);
|
2008-03-25 13:32:38 +00:00
|
|
|
// cur.idx() = tabular.cellBelow(first_visible_cell) + col;
|
2004-11-30 01:59:49 +00:00
|
|
|
// } else {
|
|
|
|
// cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
|
|
|
|
// }
|
|
|
|
// cur.par() = 0;
|
|
|
|
// cur.pos() = 0;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//
|
2006-05-05 20:23:12 +00:00
|
|
|
// case LFUN_SCREEN_UP: {
|
2004-11-30 01:59:49 +00:00
|
|
|
// //if (hasSelection())
|
|
|
|
// // cur.selection() = false;
|
2007-09-04 10:52:08 +00:00
|
|
|
// col_type const col = tabular.cellColumn(cur.idx());
|
2006-07-13 16:37:55 +00:00
|
|
|
// int const t = cur.bv().top_y() + cur.bv().height();
|
2004-11-30 01:59:49 +00:00
|
|
|
// if (yo() < 0) {
|
|
|
|
// cur.bv().scrollDocView(t);
|
|
|
|
// if (yo() > 0)
|
|
|
|
// cur.idx() = col;
|
|
|
|
// else
|
2008-03-25 13:32:38 +00:00
|
|
|
// cur.idx() = tabular.cellBelow(first_visible_cell) + col;
|
2004-11-30 01:59:49 +00:00
|
|
|
// } else {
|
|
|
|
// cur.idx() = col;
|
|
|
|
// }
|
|
|
|
// cur.par() = cur.lastpar();
|
|
|
|
// cur.pos() = cur.lastpos();
|
|
|
|
// break;
|
|
|
|
// }
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_LAYOUT_TABULAR:
|
2008-03-27 22:26:24 +00:00
|
|
|
cur.bv().showDialog("tabular", params2string(*this), this);
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-03-27 22:26:24 +00:00
|
|
|
cur.bv().updateDialog("tabular", params2string(*this));
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_TABULAR_FEATURE:
|
2006-10-21 00:16:43 +00:00
|
|
|
if (!tabularFeatures(cur, to_utf8(cmd.argument())))
|
2004-03-01 17:12:09 +00:00
|
|
|
cur.undispatched();
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
// insert file functions
|
2007-01-15 22:49:14 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
|
2009-05-12 00:15:16 +00:00
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT:
|
2006-12-04 14:45:17 +00:00
|
|
|
// FIXME UNICODE
|
2009-05-12 00:15:16 +00:00
|
|
|
if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
|
|
|
|
docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
|
|
|
|
FileName(to_utf8(cmd.argument())));
|
|
|
|
if (tmpstr.empty())
|
|
|
|
break;
|
|
|
|
cur.recordUndoInset(INSERT_UNDO);
|
|
|
|
if (insertPlaintextString(cur.bv(), tmpstr, false)) {
|
|
|
|
// content has been replaced,
|
|
|
|
// so cursor might be invalid
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
bvcur.setCursor(cur);
|
|
|
|
} else
|
|
|
|
cur.undispatched();
|
|
|
|
}
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_CUT:
|
2008-08-09 16:29:25 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
2005-03-17 15:57:41 +00:00
|
|
|
if (copySelection(cur)) {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset(DELETE_UNDO);
|
2005-03-17 15:57:41 +00:00
|
|
|
cutSelection(cur);
|
|
|
|
}
|
2009-05-17 21:22:02 +00:00
|
|
|
} else
|
2005-03-17 15:57:41 +00:00
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2008-10-01 08:18:57 +00:00
|
|
|
case LFUN_SELF_INSERT:
|
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
cur.recordUndoInset(DELETE_UNDO);
|
|
|
|
cutSelection(cur);
|
|
|
|
}
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
case LFUN_CHAR_DELETE_BACKWARD:
|
|
|
|
case LFUN_CHAR_DELETE_FORWARD:
|
2008-08-09 16:29:25 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset(DELETE_UNDO);
|
2004-02-13 16:22:53 +00:00
|
|
|
cutSelection(cur);
|
2009-07-12 14:36:42 +00:00
|
|
|
} else
|
2004-11-23 23:04:52 +00:00
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2004-01-08 18:30:14 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_COPY:
|
|
|
|
if (!cur.selection())
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2008-08-09 16:29:25 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.finishUndo();
|
2005-03-17 15:57:41 +00:00
|
|
|
copySelection(cur);
|
|
|
|
} else
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
Split clipboard and X selection
* src/LyXAction.C
(LyXAction::init): handle new LFUN_CLIPBOARD_PASTE
* src/insets/insettabular.C
(InsetTabular::doDispatch): ditto
* src/insets/insetbox.C
(InsetBox::doDispatch): ditto
* src/insets/insetert.C
(InsetERT::doDispatch): ditto
(InsetERT::getStatus): ditto
* src/insets/insetcharstyle.C
(InsetCharStyle::doDispatch): ditto
* src/BufferView_pimpl.C
(BufferView::Pimpl::selectionRequest): stuff selection, not clipboard
* src/mathed/math_nestinset.C
(MathNestInset::lfunMousePress): get stuff selection, not clipboard
(MathNestInset::lfunMouseRelease): clipboard -> selection in
commented code
* src/CutAndPaste.C
(cutSelection): ditto
* src/frontends/{qt3,gtk}/GuiImplementation.C
(GuiImplementation::newWorkArea): create new selection, not clipboard,
since the clipboard is now an object
(GuiImplementation::destroyWorkArea): destroy selection, not clipboard
* src/frontends/{qt4,qt3,gtk}/GuiSelection.h: new, copied from
GuiClipboard.h
* src/frontends/{qt4,qt3,gtk}/GuiSelection.C: new, copied from
GuiClipboard.C
* src/frontends/{qt3,gtk}/GuiImplementation.h
(selection): new accessor for selection_
(selection_): new, the global selection object
* src/frontends/{qt4,qt3,gtk}/Makefile.am: add GuiSelection.C and
GuiSelection.h
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.C
(GuiClipboard::get): return clipboard, not selection
(GuiClipboard::put): stuff clipboard, not selection
* src/frontends/{qt4,qt3,gtk}/GuiClipboard.h
(haveSelection): remove (this is now in GuiSelection)
* src/frontends/{qt3,gtk}/GuiClipboard.h
(old_work_area_): remove, since it is not needed anymore
* src/frontends/gtk/ghelpers.C
(getGTKStockIcon): handle LFUN_CLIPBOARD_PASTE
* src/frontends/Clipboard.h
(haveSelection): remove (this is now in Selection)
* src/frontends/qt4/GuiImplementation.[Ch]
(GuiImplementation::selection): new accessor for selection_
* src/frontends/Gui.h
(selection): New accessor for the global selection object
* src/frontends/Selection.h; new, copied from Clipboard.h
* src/frontends/Makefile.am: add Selection.h
* src/text3.C
(various): s/clipboard().haveSelection/selection().haveSelection/
(LyXText::dispatch): handle LFUN_CLIPBOARD_PASTE
(LyXText::getStatus): ditto
* src/lfuns.h: new lfun LFUN_CLIPBOARD_PASTE
* lib/ui/stdmenus.ui: add new lfun LFUN_CLIPBOARD_PASTE
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14408 a592a061-630c-0410-9148-cb99ea01b6c8
2006-07-10 11:32:25 +00:00
|
|
|
case LFUN_CLIPBOARD_PASTE:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_PRIMARY_SELECTION_PASTE: {
|
2006-09-03 07:02:38 +00:00
|
|
|
docstring const clip = (cmd.action == LFUN_CLIPBOARD_PASTE) ?
|
2007-01-13 18:29:50 +00:00
|
|
|
theClipboard().getAsText() :
|
2006-10-11 17:24:46 +00:00
|
|
|
theSelection().get();
|
2004-02-13 16:22:53 +00:00
|
|
|
if (clip.empty())
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2007-01-15 22:49:14 +00:00
|
|
|
// pass to InsertPlaintextString, but
|
2006-05-22 10:19:27 +00:00
|
|
|
// only if we have multi-cell content
|
2006-10-21 00:16:43 +00:00
|
|
|
if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) {
|
2007-11-22 09:09:39 +00:00
|
|
|
cur.recordUndoInset(INSERT_UNDO);
|
2007-01-15 22:49:14 +00:00
|
|
|
if (insertPlaintextString(cur.bv(), clip, false)) {
|
2006-05-22 10:19:27 +00:00
|
|
|
// content has been replaced,
|
|
|
|
// so cursor might be invalid
|
|
|
|
cur.pos() = cur.lastpos();
|
2007-12-02 15:19:39 +00:00
|
|
|
cur.pit() = cur.lastpit();
|
2006-05-22 10:19:27 +00:00
|
|
|
bvcur.setCursor(cur);
|
|
|
|
break;
|
|
|
|
}
|
2001-01-03 16:04:05 +00:00
|
|
|
}
|
2007-01-04 09:48:54 +00:00
|
|
|
// Let the cell handle normal text
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2007-01-04 09:50:25 +00:00
|
|
|
break;
|
2004-02-13 16:22:53 +00:00
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
case LFUN_PASTE:
|
2008-05-22 10:44:28 +00:00
|
|
|
if (!tabularStackDirty()) {
|
2009-05-17 21:22:02 +00:00
|
|
|
if (!cur.selIsMultiCell())
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2008-05-22 10:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (theClipboard().isInternal() ||
|
2008-12-22 18:18:47 +00:00
|
|
|
(!theClipboard().hasInternal() && theClipboard().hasLyXContents())) {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset(INSERT_UNDO);
|
2007-02-02 03:10:15 +00:00
|
|
|
pasteClipboard(cur);
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_FONT_EMPH:
|
|
|
|
case LFUN_FONT_BOLD:
|
2008-09-15 16:49:11 +00:00
|
|
|
case LFUN_FONT_BOLDSYMBOL:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_FONT_ROMAN:
|
|
|
|
case LFUN_FONT_NOUN:
|
|
|
|
case LFUN_FONT_ITAL:
|
|
|
|
case LFUN_FONT_FRAK:
|
2007-09-20 18:02:39 +00:00
|
|
|
case LFUN_FONT_TYPEWRITER:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_FONT_SANS:
|
2008-06-11 08:35:15 +00:00
|
|
|
case LFUN_TEXTSTYLE_APPLY:
|
|
|
|
case LFUN_TEXTSTYLE_UPDATE:
|
2005-03-17 13:23:14 +00:00
|
|
|
case LFUN_FONT_SIZE:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_FONT_UNDERLINE:
|
2009-05-03 22:45:14 +00:00
|
|
|
case LFUN_FONT_STRIKEOUT:
|
2009-05-05 09:26:28 +00:00
|
|
|
case LFUN_FONT_UULINE:
|
|
|
|
case LFUN_FONT_UWAVE:
|
2005-03-17 13:23:14 +00:00
|
|
|
case LFUN_LANGUAGE:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_WORD_CAPITALIZE:
|
|
|
|
case LFUN_WORD_UPCASE:
|
|
|
|
case LFUN_WORD_LOWCASE:
|
|
|
|
case LFUN_CHARS_TRANSPOSE:
|
2008-08-09 16:29:25 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
2005-03-13 10:36:42 +00:00
|
|
|
row_type rs, re;
|
|
|
|
col_type cs, ce;
|
|
|
|
getSelection(cur, rs, re, cs, ce);
|
2007-04-26 14:56:30 +00:00
|
|
|
Cursor tmpcur = cur;
|
2005-07-16 18:25:58 +00:00
|
|
|
for (row_type i = rs; i <= re; ++i) {
|
2005-03-13 10:36:42 +00:00
|
|
|
for (col_type j = cs; j <= ce; ++j) {
|
|
|
|
// cursor follows cell:
|
2007-09-04 10:52:08 +00:00
|
|
|
tmpcur.idx() = tabular.cellIndex(i, j);
|
2005-03-13 10:36:42 +00:00
|
|
|
// select this cell only:
|
2006-09-21 10:43:49 +00:00
|
|
|
tmpcur.pit() = 0;
|
|
|
|
tmpcur.pos() = 0;
|
|
|
|
tmpcur.resetAnchor();
|
|
|
|
tmpcur.pit() = tmpcur.lastpit();
|
|
|
|
tmpcur.pos() = tmpcur.top().lastpos();
|
|
|
|
tmpcur.setCursor(tmpcur);
|
|
|
|
tmpcur.setSelection();
|
|
|
|
cell(tmpcur.idx())->dispatch(tmpcur, cmd);
|
2005-03-13 10:36:42 +00:00
|
|
|
}
|
2005-07-16 18:25:58 +00:00
|
|
|
}
|
2005-03-13 10:36:42 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
2009-04-10 00:17:34 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_SETTINGS:
|
|
|
|
// relay this lfun to Inset, not to the cell.
|
|
|
|
Inset::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
default:
|
2004-02-16 11:58:51 +00:00
|
|
|
// we try to handle this event in the insets dispatch function.
|
2004-11-23 23:04:52 +00:00
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-02-13 16:22:53 +00:00
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-27 12:40:39 +00:00
|
|
|
// function sets an object as defined in func_status.h:
|
|
|
|
// states OK, Unknown, Disabled, On, Off.
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2004-03-27 12:40:39 +00:00
|
|
|
FuncStatus & status) const
|
2004-03-18 13:57:20 +00:00
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
2004-03-27 12:40:39 +00:00
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2007-04-26 12:54:21 +00:00
|
|
|
int action = Tabular::LAST_ACTION;
|
2004-03-27 12:40:39 +00:00
|
|
|
int i = 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
|
2004-03-27 12:40:39 +00:00
|
|
|
string const tmp = tabularFeature[i].feature;
|
2006-10-21 00:16:43 +00:00
|
|
|
if (tmp == to_utf8(cmd.argument()).substr(0, tmp.length())) {
|
2004-03-27 12:40:39 +00:00
|
|
|
action = tabularFeature[i].action;
|
2004-03-18 13:57:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-27 12:40:39 +00:00
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
if (action == Tabular::LAST_ACTION) {
|
2004-03-27 12:40:39 +00:00
|
|
|
status.clear();
|
|
|
|
status.unknown(true);
|
|
|
|
return true;
|
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
|
2004-03-27 12:40:39 +00:00
|
|
|
string const argument
|
2006-10-21 00:16:43 +00:00
|
|
|
= ltrim(to_utf8(cmd.argument()).substr(tabularFeature[i].feature.length()));
|
2004-03-27 12:40:39 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
row_type sel_row_start = 0;
|
|
|
|
row_type sel_row_end = 0;
|
2007-05-12 20:59:21 +00:00
|
|
|
col_type sel_col_start = 0;
|
|
|
|
col_type sel_col_end = 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular::ltType dummyltt;
|
2004-03-27 12:40:39 +00:00
|
|
|
bool flag = true;
|
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
|
2004-03-27 12:40:39 +00:00
|
|
|
|
|
|
|
switch (action) {
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_PWIDTH:
|
|
|
|
case Tabular::SET_MPWIDTH:
|
|
|
|
case Tabular::SET_SPECIAL_COLUMN:
|
|
|
|
case Tabular::SET_SPECIAL_MULTI:
|
|
|
|
case Tabular::APPEND_ROW:
|
|
|
|
case Tabular::APPEND_COLUMN:
|
|
|
|
case Tabular::DELETE_ROW:
|
|
|
|
case Tabular::DELETE_COLUMN:
|
|
|
|
case Tabular::COPY_ROW:
|
|
|
|
case Tabular::COPY_COLUMN:
|
|
|
|
case Tabular::SET_TOP_SPACE:
|
|
|
|
case Tabular::SET_BOTTOM_SPACE:
|
|
|
|
case Tabular::SET_INTERLINE_SPACE:
|
2004-03-27 12:40:39 +00:00
|
|
|
status.clear();
|
|
|
|
return true;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::MULTICOLUMN:
|
2009-05-18 06:22:25 +00:00
|
|
|
// If a row is set as longtable caption, it must not be allowed
|
2009-02-12 03:02:34 +00:00
|
|
|
// to unset that this row is a multicolumn.
|
|
|
|
status.setEnabled(sel_row_start == sel_row_end
|
|
|
|
&& !tabular.ltCaption(tabular.cellRow(cur.idx())));
|
2004-10-23 09:21:38 +00:00
|
|
|
status.setOnOff(tabular.isMultiColumn(cur.idx()));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
2004-03-18 13:57:20 +00:00
|
|
|
|
2008-05-04 07:51:50 +00:00
|
|
|
case Tabular::SET_ALL_LINES:
|
|
|
|
case Tabular::UNSET_ALL_LINES:
|
|
|
|
case Tabular::SET_BORDER_LINES:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
|
2008-05-04 07:51:50 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_TOP:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
|
2008-03-18 18:08:32 +00:00
|
|
|
status.setOnOff(tabular.topLine(cur.idx()));
|
2004-03-18 13:57:20 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_BOTTOM:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
|
2008-03-18 18:08:32 +00:00
|
|
|
status.setOnOff(tabular.bottomLine(cur.idx()));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_LEFT:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
|
2008-03-18 18:08:32 +00:00
|
|
|
status.setOnOff(tabular.leftLine(cur.idx()));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_RIGHT:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
|
2008-03-18 18:08:32 +00:00
|
|
|
status.setOnOff(tabular.rightLine(cur.idx()));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_LEFT:
|
2004-03-27 12:40:39 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::ALIGN_LEFT:
|
2004-10-23 09:21:38 +00:00
|
|
|
status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_RIGHT:
|
2004-03-27 12:40:39 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::ALIGN_RIGHT:
|
2004-10-23 09:21:38 +00:00
|
|
|
status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_CENTER:
|
2004-03-27 12:40:39 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::ALIGN_CENTER:
|
2004-10-23 09:21:38 +00:00
|
|
|
status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::ALIGN_BLOCK:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(!tabular.getPWidth(cur.idx()).zero());
|
2004-10-23 09:21:38 +00:00
|
|
|
status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_TOP:
|
2004-03-27 12:40:39 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::VALIGN_TOP:
|
2004-03-27 12:40:39 +00:00
|
|
|
status.setOnOff(
|
2007-04-26 12:54:21 +00:00
|
|
|
tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_TOP);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_BOTTOM:
|
2004-03-27 12:40:39 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::VALIGN_BOTTOM:
|
2004-03-27 12:40:39 +00:00
|
|
|
status.setOnOff(
|
2007-04-26 12:54:21 +00:00
|
|
|
tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_BOTTOM);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_MIDDLE:
|
2004-03-27 12:40:39 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::VALIGN_MIDDLE:
|
2004-03-27 12:40:39 +00:00
|
|
|
status.setOnOff(
|
2007-04-26 12:54:21 +00:00
|
|
|
tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_MIDDLE);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LONGTABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
status.setOnOff(tabular.is_long_tabular);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LONGTABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
status.setOnOff(!tabular.is_long_tabular);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
case Tabular::TOGGLE_ROTATE_TABULAR:
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_ROTATE_TABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
status.setOnOff(tabular.rotate);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-03 18:33:09 +00:00
|
|
|
case Tabular::TABULAR_VALIGN_TOP:
|
|
|
|
status.setOnOff(tabular.tabular_valignment
|
|
|
|
== Tabular::LYX_VALIGN_TOP);
|
|
|
|
break;
|
|
|
|
case Tabular::TABULAR_VALIGN_MIDDLE:
|
|
|
|
status.setOnOff(tabular.tabular_valignment
|
|
|
|
== Tabular::LYX_VALIGN_MIDDLE);
|
|
|
|
break;
|
|
|
|
case Tabular::TABULAR_VALIGN_BOTTOM:
|
|
|
|
status.setOnOff(tabular.tabular_valignment
|
|
|
|
== Tabular::LYX_VALIGN_BOTTOM);
|
|
|
|
break;
|
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
case Tabular::LONGTABULAR_ALIGN_LEFT:
|
|
|
|
status.setOnOff(tabular.longtabular_alignment
|
|
|
|
== Tabular::LYX_LONGTABULAR_ALIGN_LEFT);
|
|
|
|
break;
|
|
|
|
case Tabular::LONGTABULAR_ALIGN_CENTER:
|
|
|
|
status.setOnOff(tabular.longtabular_alignment
|
|
|
|
== Tabular::LYX_LONGTABULAR_ALIGN_CENTER);
|
|
|
|
break;
|
|
|
|
case Tabular::LONGTABULAR_ALIGN_RIGHT:
|
|
|
|
status.setOnOff(tabular.longtabular_alignment
|
|
|
|
== Tabular::LYX_LONGTABULAR_ALIGN_RIGHT);
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_ROTATE_TABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
status.setOnOff(!tabular.rotate);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
case Tabular::TOGGLE_ROTATE_CELL:
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_ROTATE_CELL:
|
2007-05-28 22:27:45 +00:00
|
|
|
status.setOnOff(!oneCellHasRotationState(false,
|
2007-05-12 20:59:21 +00:00
|
|
|
sel_row_start, sel_row_end, sel_col_start, sel_col_end));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_ROTATE_CELL:
|
2007-05-28 22:27:45 +00:00
|
|
|
status.setOnOff(!oneCellHasRotationState(true,
|
2007-05-12 20:59:21 +00:00
|
|
|
sel_row_start, sel_row_end, sel_col_start, sel_col_end));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_USEBOX:
|
2005-01-27 21:05:44 +00:00
|
|
|
status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-02-11 03:18:16 +00:00
|
|
|
// every row can only be one thing:
|
|
|
|
// either a footer or header or caption
|
2009-05-17 11:27:44 +00:00
|
|
|
case Tabular::SET_LTFIRSTHEAD:
|
2009-02-10 18:08:09 +00:00
|
|
|
status.setEnabled(sel_row_start == sel_row_end
|
2009-02-11 03:18:16 +00:00
|
|
|
&& !tabular.ltCaption(sel_row_start));
|
|
|
|
status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTFIRSTHEAD:
|
2009-02-11 03:18:16 +00:00
|
|
|
status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
|
2005-04-23 17:39:12 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTHEAD:
|
2009-02-10 18:08:09 +00:00
|
|
|
status.setEnabled(sel_row_start == sel_row_end
|
2009-02-11 03:18:16 +00:00
|
|
|
&& !tabular.ltCaption(sel_row_start));
|
2004-03-27 12:40:39 +00:00
|
|
|
status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTHEAD:
|
2005-04-23 17:39:12 +00:00
|
|
|
status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTFOOT:
|
2009-02-10 18:08:09 +00:00
|
|
|
status.setEnabled(sel_row_start == sel_row_end
|
2009-02-11 03:18:16 +00:00
|
|
|
&& !tabular.ltCaption(sel_row_start));
|
2004-03-27 12:40:39 +00:00
|
|
|
status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTFOOT:
|
2005-04-23 17:39:12 +00:00
|
|
|
status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTLASTFOOT:
|
2009-02-10 18:08:09 +00:00
|
|
|
status.setEnabled(sel_row_start == sel_row_end
|
2009-02-11 03:18:16 +00:00
|
|
|
&& !tabular.ltCaption(sel_row_start));
|
|
|
|
status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTLASTFOOT:
|
2009-02-11 03:18:16 +00:00
|
|
|
status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
|
2005-04-23 17:39:12 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTNEWPAGE:
|
2004-03-27 12:40:39 +00:00
|
|
|
status.setOnOff(tabular.getLTNewPage(sel_row_start));
|
|
|
|
break;
|
2006-09-09 15:27:44 +00:00
|
|
|
|
2009-02-13 03:17:01 +00:00
|
|
|
// only one row can be the caption
|
2008-05-04 07:51:50 +00:00
|
|
|
case Tabular::TOGGLE_LTCAPTION:
|
2009-02-10 18:08:09 +00:00
|
|
|
status.setEnabled(sel_row_start == sel_row_end
|
|
|
|
&& !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
|
|
|
|
&& !tabular.getRowOfLTHead(sel_row_start, dummyltt)
|
|
|
|
&& !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
|
2009-02-13 03:17:01 +00:00
|
|
|
&& !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
|
|
|
|
&& (!tabular.haveLTCaption()
|
|
|
|
|| tabular.ltCaption(sel_row_start)));
|
2008-05-04 07:51:50 +00:00
|
|
|
status.setOnOff(tabular.ltCaption(sel_row_start));
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_BOOKTABS:
|
2008-04-21 13:33:39 +00:00
|
|
|
status.setOnOff(tabular.use_booktabs);
|
2006-07-03 19:13:56 +00:00
|
|
|
break;
|
2006-09-09 15:27:44 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_BOOKTABS:
|
2008-04-21 13:33:39 +00:00
|
|
|
status.setOnOff(!tabular.use_booktabs);
|
2006-07-03 19:13:56 +00:00
|
|
|
break;
|
2004-03-27 12:40:39 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
status.clear();
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2004-03-27 12:40:39 +00:00
|
|
|
break;
|
2004-03-18 13:57:20 +00:00
|
|
|
}
|
|
|
|
return true;
|
2004-03-27 12:40:39 +00:00
|
|
|
}
|
2004-03-18 13:57:20 +00:00
|
|
|
|
2005-03-21 11:14:54 +00:00
|
|
|
// These are only enabled inside tabular
|
|
|
|
case LFUN_CELL_BACKWARD:
|
|
|
|
case LFUN_CELL_FORWARD:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2005-07-18 11:00:15 +00:00
|
|
|
return true;
|
2005-04-26 11:12:20 +00:00
|
|
|
|
2005-03-13 10:36:42 +00:00
|
|
|
// disable these with multiple cells selected
|
2005-04-13 09:43:58 +00:00
|
|
|
case LFUN_INSET_INSERT:
|
2005-06-16 15:20:09 +00:00
|
|
|
case LFUN_TABULAR_INSERT:
|
2007-09-05 18:40:56 +00:00
|
|
|
case LFUN_FLEX_INSERT:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_FLOAT_INSERT:
|
|
|
|
case LFUN_FLOAT_WIDE_INSERT:
|
|
|
|
case LFUN_FOOTNOTE_INSERT:
|
|
|
|
case LFUN_MARGINALNOTE_INSERT:
|
|
|
|
case LFUN_MATH_INSERT:
|
2005-03-17 13:23:14 +00:00
|
|
|
case LFUN_MATH_MODE:
|
|
|
|
case LFUN_MATH_MUTATE:
|
|
|
|
case LFUN_MATH_DISPLAY:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_NOTE_INSERT:
|
|
|
|
case LFUN_OPTIONAL_INSERT:
|
|
|
|
case LFUN_BOX_INSERT:
|
|
|
|
case LFUN_BRANCH_INSERT:
|
2009-01-30 00:56:37 +00:00
|
|
|
case LFUN_PHANTOM_INSERT:
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_WRAP_INSERT:
|
|
|
|
case LFUN_ERT_INSERT: {
|
2008-08-09 16:29:25 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2005-03-13 10:36:42 +00:00
|
|
|
return true;
|
2005-08-07 18:36:21 +00:00
|
|
|
} else
|
|
|
|
return cell(cur.idx())->getStatus(cur, cmd, status);
|
2005-03-13 10:36:42 +00:00
|
|
|
}
|
|
|
|
|
2005-07-28 09:45:43 +00:00
|
|
|
// disable in non-fixed-width cells
|
2008-03-26 08:10:01 +00:00
|
|
|
case LFUN_NEWLINE_INSERT:
|
2008-06-04 18:09:06 +00:00
|
|
|
case LFUN_BREAK_PARAGRAPH: {
|
2005-07-28 09:45:43 +00:00
|
|
|
if (tabular.getPWidth(cur.idx()).zero()) {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2005-07-28 09:45:43 +00:00
|
|
|
return true;
|
2005-08-07 18:36:21 +00:00
|
|
|
} else
|
|
|
|
return cell(cur.idx())->getStatus(cur, cmd, status);
|
2005-07-28 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 02:02:16 +00:00
|
|
|
case LFUN_NEWPAGE_INSERT:
|
|
|
|
status.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
|
2006-03-17 13:11:32 +00:00
|
|
|
case LFUN_PASTE:
|
2007-01-04 12:05:24 +00:00
|
|
|
if (tabularStackDirty() && theClipboard().isInternal()) {
|
2009-05-17 21:22:02 +00:00
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
row_type rs, re;
|
|
|
|
col_type cs, ce;
|
|
|
|
getSelection(cur, rs, re, cs, ce);
|
|
|
|
if (paste_tabular && paste_tabular->column_info.size() == ce - cs + 1
|
|
|
|
&& paste_tabular->row_info.size() == re - rs + 1)
|
|
|
|
status.setEnabled(true);
|
|
|
|
else {
|
|
|
|
status.setEnabled(false);
|
|
|
|
status.message(_("Selection size should match clipboard content."));
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
status.setEnabled(true);
|
2006-03-17 13:11:32 +00:00
|
|
|
return true;
|
2009-05-17 21:22:02 +00:00
|
|
|
}
|
2008-08-08 17:28:25 +00:00
|
|
|
return cell(cur.idx())->getStatus(cur, cmd, status);
|
2006-03-17 13:11:32 +00:00
|
|
|
|
2009-04-10 00:17:34 +00:00
|
|
|
case LFUN_INSET_SETTINGS:
|
2009-04-22 20:55:13 +00:00
|
|
|
// relay this lfun to Inset, not to the cell.
|
|
|
|
return Inset::getStatus(cur, cmd, status);
|
|
|
|
|
2005-04-15 08:13:54 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2007-10-13 12:50:18 +00:00
|
|
|
if (insetCode(cmd.getArg(0)) == TABULAR_CODE) {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2005-04-15 08:13:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Fall through
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
default:
|
|
|
|
// we try to handle this event in the insets dispatch function.
|
2004-11-23 23:04:52 +00:00
|
|
|
return cell(cur.idx())->getStatus(cur, cmd, status);
|
2004-03-18 13:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
Inset::DisplayType InsetTabular::display() const
|
|
|
|
{
|
|
|
|
if (tabular.is_long_tabular) {
|
|
|
|
switch (tabular.longtabular_alignment) {
|
|
|
|
case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
|
|
|
|
return AlignLeft;
|
|
|
|
case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
|
|
|
|
return AlignCenter;
|
|
|
|
case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
|
|
|
|
return AlignRight;
|
2009-07-11 13:41:34 +00:00
|
|
|
default:
|
|
|
|
return AlignCenter;
|
2009-07-11 13:09:45 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
return Inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetTabular::latex(odocstream & os, OutputParams const & runparams) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
return tabular.latex(os, runparams);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetTabular::plaintext(odocstream & os, OutputParams const & runparams) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2007-02-18 10:47:08 +00:00
|
|
|
os << '\n'; // output table on a new line
|
|
|
|
int const dp = runparams.linelen > 0 ? runparams.depth : 0;
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.plaintext(os, runparams, dp, false, 0);
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetTabular::docbook(odocstream & os, OutputParams const & runparams) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2001-10-24 07:43:34 +00:00
|
|
|
int ret = 0;
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * master = 0;
|
2001-10-24 07:43:34 +00:00
|
|
|
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: Why not pass a proper DocIterator here?
|
2004-03-25 09:16:36 +00:00
|
|
|
#if 0
|
2001-10-24 07:43:34 +00:00
|
|
|
// if the table is inside a float it doesn't need the informaltable
|
|
|
|
// wrapper. Search for it.
|
2004-01-08 18:30:14 +00:00
|
|
|
for (master = owner(); master; master = master->owner())
|
2007-10-13 09:04:52 +00:00
|
|
|
if (master->lyxCode() == FLOAT_CODE)
|
2004-01-08 18:30:14 +00:00
|
|
|
break;
|
2004-03-25 09:16:36 +00:00
|
|
|
#endif
|
2001-10-24 07:43:34 +00:00
|
|
|
|
|
|
|
if (!master) {
|
2002-06-18 15:44:30 +00:00
|
|
|
os << "<informaltable>";
|
2003-07-31 10:48:50 +00:00
|
|
|
++ret;
|
2001-10-24 07:43:34 +00:00
|
|
|
}
|
2008-02-27 20:43:16 +00:00
|
|
|
ret += tabular.docbook(os, runparams);
|
2001-10-24 07:43:34 +00:00
|
|
|
if (!master) {
|
2002-06-18 15:44:30 +00:00
|
|
|
os << "</informaltable>";
|
2003-07-31 10:48:50 +00:00
|
|
|
++ret;
|
2001-10-24 07:43:34 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetTabular::validate(LaTeXFeatures & features) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.validate(features);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 06:16:05 +00:00
|
|
|
shared_ptr<InsetTableCell const> InsetTabular::cell(idx_type idx) const
|
2001-04-04 09:42:56 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return tabular.cellInset(idx);
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 06:16:05 +00:00
|
|
|
shared_ptr<InsetTableCell> InsetTabular::cell(idx_type idx)
|
2004-02-16 11:58:51 +00:00
|
|
|
{
|
2008-03-25 13:32:38 +00:00
|
|
|
return tabular.cellInset(idx);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
void InsetTabular::cursorPos(BufferView const & bv,
|
|
|
|
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2004-11-30 01:59:49 +00:00
|
|
|
{
|
2006-10-17 16:23:27 +00:00
|
|
|
cell(sl.idx())->cursorPos(bv, sl, boundary, x, y);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
// y offset correction
|
2007-09-04 10:52:08 +00:00
|
|
|
int const row = tabular.cellRow(sl.idx());
|
2004-11-30 01:59:49 +00:00
|
|
|
for (int i = 0; i <= row; ++i) {
|
|
|
|
if (i != 0) {
|
2007-09-04 10:52:08 +00:00
|
|
|
y += tabular.rowAscent(i);
|
2004-11-30 01:59:49 +00:00
|
|
|
y += tabular.getAdditionalHeight(i);
|
|
|
|
}
|
|
|
|
if (i != row)
|
2007-09-04 10:52:08 +00:00
|
|
|
y += tabular.rowDescent(i);
|
2004-11-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-06 02:35:12 +00:00
|
|
|
// x offset correction
|
2007-09-04 10:52:08 +00:00
|
|
|
int const col = tabular.cellColumn(sl.idx());
|
|
|
|
int idx = tabular.cellIndex(row, 0);
|
2004-11-30 01:59:49 +00:00
|
|
|
for (int j = 0; j < col; ++j) {
|
|
|
|
if (tabular.isPartOfMultiColumn(row, j))
|
|
|
|
continue;
|
2007-09-04 10:52:08 +00:00
|
|
|
x += tabular.columnWidth(idx);
|
2004-11-30 01:59:49 +00:00
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
x += tabular.getBeginningOfTextInCell(idx);
|
|
|
|
x += ADD_TO_TABULAR_WIDTH;
|
2005-07-15 22:10:25 +00:00
|
|
|
x += scx_;
|
2004-11-30 01:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-13 16:44:44 +00:00
|
|
|
int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
int xx = 0;
|
|
|
|
int yy = 0;
|
2008-03-25 13:32:38 +00:00
|
|
|
Inset const & inset = *tabular.cellInset(cell);
|
2006-10-13 16:44:44 +00:00
|
|
|
Point o = bv.coordCache().getInsets().xy(&inset);
|
2005-06-27 12:53:35 +00:00
|
|
|
int const xbeg = o.x_ - tabular.getBeginningOfTextInCell(cell);
|
2007-09-04 10:52:08 +00:00
|
|
|
int const xend = xbeg + tabular.columnWidth(cell);
|
|
|
|
row_type const row = tabular.cellRow(cell);
|
|
|
|
int const ybeg = o.y_ - tabular.rowAscent(row) -
|
2006-09-09 15:27:44 +00:00
|
|
|
tabular.getAdditionalHeight(row);
|
2007-09-04 10:52:08 +00:00
|
|
|
int const yend = o.y_ + tabular.rowDescent(row);
|
2005-06-27 12:53:35 +00:00
|
|
|
|
2005-07-15 11:43:07 +00:00
|
|
|
if (x < xbeg)
|
2005-06-27 12:53:35 +00:00
|
|
|
xx = xbeg - x;
|
2005-07-15 11:43:07 +00:00
|
|
|
else if (x > xend)
|
2005-06-27 12:53:35 +00:00
|
|
|
xx = x - xend;
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
if (y < ybeg)
|
2005-06-27 12:53:35 +00:00
|
|
|
yy = ybeg - y;
|
2006-04-05 23:56:29 +00:00
|
|
|
else if (y > yend)
|
2005-06-27 12:53:35 +00:00
|
|
|
yy = y - yend;
|
|
|
|
|
2005-07-15 11:43:07 +00:00
|
|
|
//lyxerr << " xbeg=" << xbeg << " xend=" << xend
|
|
|
|
// << " ybeg=" << ybeg << " yend=" << yend
|
|
|
|
// << " xx=" << xx << " yy=" << yy
|
|
|
|
// << " dist=" << xx + yy << endl;
|
2004-11-30 01:59:49 +00:00
|
|
|
return xx + yy;
|
2001-08-01 15:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2005-03-21 18:21:13 +00:00
|
|
|
//lyxerr << "InsetTabular::editXY: " << this << endl;
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2005-07-15 00:39:44 +00:00
|
|
|
cur.push(*this);
|
2006-10-13 16:44:44 +00:00
|
|
|
cur.idx() = getNearestCell(cur.bv(), x, y);
|
2005-03-21 18:21:13 +00:00
|
|
|
resetPos(cur);
|
2008-07-29 12:07:08 +00:00
|
|
|
return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
|
2005-03-21 18:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const
|
2005-03-21 18:21:13 +00:00
|
|
|
{
|
2006-10-13 16:44:44 +00:00
|
|
|
cur.idx() = getNearestCell(cur.bv(), x, y);
|
2008-07-29 12:07:08 +00:00
|
|
|
cur.bv().textMetrics(&cell(cur.idx())->text()).setCursorFromCoordinates(cur, x, y);
|
2005-03-21 18:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-13 16:44:44 +00:00
|
|
|
InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const
|
2005-03-21 18:21:13 +00:00
|
|
|
{
|
2004-12-03 13:57:50 +00:00
|
|
|
idx_type idx_min = 0;
|
2007-12-12 19:28:07 +00:00
|
|
|
int dist_min = numeric_limits<int>::max();
|
2005-07-18 12:57:08 +00:00
|
|
|
for (idx_type i = 0, n = nargs(); i != n; ++i) {
|
2008-03-25 13:32:38 +00:00
|
|
|
if (bv.coordCache().getInsets().has(tabular.cellInset(i).get())) {
|
2006-10-13 16:44:44 +00:00
|
|
|
int const d = dist(bv, i, x, y);
|
2004-11-30 01:59:49 +00:00
|
|
|
if (d < dist_min) {
|
|
|
|
dist_min = d;
|
|
|
|
idx_min = i;
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-21 18:21:13 +00:00
|
|
|
return idx_min;
|
2000-04-21 15:16:22 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2008-03-25 13:32:38 +00:00
|
|
|
int InsetTabular::cellXPos(idx_type const cell) const
|
2000-05-15 14:49:36 +00:00
|
|
|
{
|
2004-12-03 13:57:50 +00:00
|
|
|
idx_type c = cell;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-06-13 07:37:48 +00:00
|
|
|
for (; !tabular.isFirstCellInRow(c); --c)
|
2001-04-04 09:42:56 +00:00
|
|
|
;
|
2007-06-25 08:19:15 +00:00
|
|
|
int lx = 0;
|
2003-07-30 16:14:02 +00:00
|
|
|
for (; c < cell; ++c)
|
2007-09-04 10:52:08 +00:00
|
|
|
lx += tabular.columnWidth(c);
|
2003-07-30 16:14:02 +00:00
|
|
|
|
2007-06-25 08:19:15 +00:00
|
|
|
return lx;
|
2000-05-15 14:49:36 +00:00
|
|
|
}
|
2000-04-21 15:16:22 +00:00
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetTabular::resetPos(Cursor & cur) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
BufferView & bv = cur.bv();
|
2005-07-15 11:43:07 +00:00
|
|
|
int const maxwidth = bv.workWidth();
|
2004-11-30 01:59:49 +00:00
|
|
|
|
2008-09-09 14:12:08 +00:00
|
|
|
int const scx_old = scx_;
|
|
|
|
int const i = cur.find(this);
|
|
|
|
if (i == -1) {
|
2005-07-15 22:10:25 +00:00
|
|
|
scx_ = 0;
|
2004-11-30 01:59:49 +00:00
|
|
|
} else {
|
|
|
|
int const X1 = 0;
|
2005-07-15 11:43:07 +00:00
|
|
|
int const X2 = maxwidth;
|
2004-11-30 01:59:49 +00:00
|
|
|
int const offset = ADD_TO_TABULAR_WIDTH + 2;
|
2008-09-09 14:12:08 +00:00
|
|
|
int const x1 = xo(cur.bv()) + cellXPos(cur[i].idx()) + offset;
|
|
|
|
int const x2 = x1 + tabular.columnWidth(cur[i].idx());
|
2004-11-30 01:59:49 +00:00
|
|
|
|
2004-12-06 02:35:12 +00:00
|
|
|
if (x1 < X1)
|
2005-07-15 22:10:25 +00:00
|
|
|
scx_ = X1 + 20 - x1;
|
2004-12-06 02:35:12 +00:00
|
|
|
else if (x2 > X2)
|
2005-07-15 22:10:25 +00:00
|
|
|
scx_ = X2 - 20 - x2;
|
2005-07-15 16:44:41 +00:00
|
|
|
else
|
2005-07-15 22:10:25 +00:00
|
|
|
scx_ = 0;
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2003-12-15 15:33:15 +00:00
|
|
|
|
2008-09-09 14:12:08 +00:00
|
|
|
// only update if offset changed
|
|
|
|
if (scx_ != scx_old)
|
|
|
|
cur.updateFlags(Update::Force | Update::FitCursor);
|
2003-12-15 15:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-11 12:02:10 +00:00
|
|
|
void InsetTabular::moveNextCell(Cursor & cur, EntryDirection entry_from)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
if (isRightToLeft(cur)) {
|
|
|
|
if (tabular.isFirstCellInRow(cur.idx())) {
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = tabular.cellRow(cur.idx());
|
2008-04-21 13:33:39 +00:00
|
|
|
if (row == tabular.row_info.size() - 1)
|
2004-02-16 11:58:51 +00:00
|
|
|
return;
|
2008-03-25 13:32:38 +00:00
|
|
|
cur.idx() = tabular.cellBelow(tabular.getLastCellInRow(row));
|
2001-04-04 09:42:56 +00:00
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
if (cur.idx() == 0)
|
2004-02-16 11:58:51 +00:00
|
|
|
return;
|
2004-01-20 14:25:24 +00:00
|
|
|
--cur.idx();
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2001-01-08 16:14:09 +00:00
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
if (tabular.isLastCell(cur.idx()))
|
2004-02-16 11:58:51 +00:00
|
|
|
return;
|
2004-01-20 14:25:24 +00:00
|
|
|
++cur.idx();
|
2001-01-08 16:14:09 +00:00
|
|
|
}
|
2008-10-01 08:18:57 +00:00
|
|
|
|
|
|
|
cur.boundary(false);
|
|
|
|
|
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
resetPos(cur);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2004-01-20 14:25:24 +00:00
|
|
|
cur.pos() = 0;
|
2008-04-11 12:02:10 +00:00
|
|
|
|
|
|
|
// in visual mode, place cursor at extreme left or right
|
|
|
|
|
|
|
|
switch(entry_from) {
|
|
|
|
|
|
|
|
case ENTRY_DIRECTION_RIGHT:
|
|
|
|
cur.posVisToRowExtremity(false /* !left */);
|
|
|
|
break;
|
|
|
|
case ENTRY_DIRECTION_LEFT:
|
|
|
|
cur.posVisToRowExtremity(true /* left */);
|
|
|
|
break;
|
|
|
|
case ENTRY_DIRECTION_IGNORE:
|
|
|
|
// nothing to do in this case
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
resetPos(cur);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2008-04-11 12:02:10 +00:00
|
|
|
void InsetTabular::movePrevCell(Cursor & cur, EntryDirection entry_from)
|
2000-04-19 14:42:19 +00:00
|
|
|
{
|
2004-01-20 14:25:24 +00:00
|
|
|
if (isRightToLeft(cur)) {
|
|
|
|
if (tabular.isLastCellInRow(cur.idx())) {
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = tabular.cellRow(cur.idx());
|
2001-04-04 09:42:56 +00:00
|
|
|
if (row == 0)
|
2004-02-16 11:58:51 +00:00
|
|
|
return;
|
2004-01-20 14:25:24 +00:00
|
|
|
cur.idx() = tabular.getFirstCellInRow(row);
|
2008-03-25 13:32:38 +00:00
|
|
|
cur.idx() = tabular.cellAbove(cur.idx());
|
2001-04-04 09:42:56 +00:00
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
if (tabular.isLastCell(cur.idx()))
|
2004-02-16 11:58:51 +00:00
|
|
|
return;
|
2004-01-20 14:25:24 +00:00
|
|
|
++cur.idx();
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2001-01-08 16:14:09 +00:00
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
if (cur.idx() == 0) // first cell
|
2004-02-16 11:58:51 +00:00
|
|
|
return;
|
2004-01-20 14:25:24 +00:00
|
|
|
--cur.idx();
|
2001-01-08 16:14:09 +00:00
|
|
|
}
|
2008-10-01 08:18:57 +00:00
|
|
|
|
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
resetPos(cur);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-17 13:23:14 +00:00
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
cur.pos() = cur.lastpos();
|
2006-10-20 16:11:30 +00:00
|
|
|
|
2008-04-11 12:02:10 +00:00
|
|
|
// in visual mode, place cursor at extreme left or right
|
|
|
|
|
|
|
|
switch(entry_from) {
|
|
|
|
|
|
|
|
case ENTRY_DIRECTION_RIGHT:
|
|
|
|
cur.posVisToRowExtremity(false /* !left */);
|
|
|
|
break;
|
|
|
|
case ENTRY_DIRECTION_LEFT:
|
|
|
|
cur.posVisToRowExtremity(true /* left */);
|
|
|
|
break;
|
|
|
|
case ENTRY_DIRECTION_IGNORE:
|
|
|
|
// nothing to do in this case
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-09 14:12:08 +00:00
|
|
|
resetPos(cur);
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetTabular::tabularFeatures(Cursor & cur, string const & what)
|
2000-07-28 14:28:54 +00:00
|
|
|
{
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular::Feature action = Tabular::LAST_ACTION;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
int i = 0;
|
2007-04-26 12:54:21 +00:00
|
|
|
for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
|
2001-06-28 10:25:20 +00:00
|
|
|
string const tmp = tabularFeature[i].feature;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
if (tmp == what.substr(0, tmp.length())) {
|
|
|
|
//if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
|
2007-05-28 22:27:45 +00:00
|
|
|
//tabularFeatures[i].feature.length()))
|
2001-06-28 10:25:20 +00:00
|
|
|
action = tabularFeature[i].action;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-07-28 14:28:54 +00:00
|
|
|
}
|
2007-04-26 12:54:21 +00:00
|
|
|
if (action == Tabular::LAST_ACTION)
|
2001-04-04 09:42:56 +00:00
|
|
|
return false;
|
2000-07-28 14:28:54 +00:00
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
string const val =
|
2002-07-28 22:50:13 +00:00
|
|
|
ltrim(what.substr(tabularFeature[i].feature.length()));
|
2004-01-20 14:25:24 +00:00
|
|
|
tabularFeatures(cur, action, val);
|
2001-04-04 09:42:56 +00:00
|
|
|
return true;
|
2000-07-28 14:28:54 +00:00
|
|
|
}
|
|
|
|
|
2003-12-15 15:33:15 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
static void checkLongtableSpecial(Tabular::ltType & ltt,
|
2003-02-14 15:01:06 +00:00
|
|
|
string const & special, bool & flag)
|
2001-12-19 16:13:21 +00:00
|
|
|
{
|
|
|
|
if (special == "dl_above") {
|
|
|
|
ltt.topDL = flag;
|
2001-12-20 14:52:15 +00:00
|
|
|
ltt.set = false;
|
2001-12-19 16:13:21 +00:00
|
|
|
} else if (special == "dl_below") {
|
|
|
|
ltt.bottomDL = flag;
|
2001-12-20 14:52:15 +00:00
|
|
|
ltt.set = false;
|
2001-12-19 16:13:21 +00:00
|
|
|
} else if (special == "empty") {
|
|
|
|
ltt.empty = flag;
|
2001-12-20 14:52:15 +00:00
|
|
|
ltt.set = false;
|
2001-12-19 21:25:34 +00:00
|
|
|
} else if (flag) {
|
|
|
|
ltt.empty = false;
|
2001-12-20 14:52:15 +00:00
|
|
|
ltt.set = true;
|
2001-12-19 16:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
bool InsetTabular::oneCellHasRotationState(bool rotated,
|
2007-05-28 22:27:45 +00:00
|
|
|
row_type row_start, row_type row_end,
|
2007-05-12 20:59:21 +00:00
|
|
|
col_type col_start, col_type col_end) const {
|
|
|
|
|
|
|
|
for (row_type i = row_start; i <= row_end; ++i) {
|
|
|
|
for (col_type j = col_start; j <= col_end; ++j) {
|
2007-09-04 10:52:08 +00:00
|
|
|
if (tabular.getRotateCell(tabular.cellIndex(i, j))
|
2007-05-12 20:59:21 +00:00
|
|
|
== rotated) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2000-07-28 14:28:54 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetTabular::tabularFeatures(Cursor & cur,
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular::Feature feature, string const & value)
|
2001-04-04 09:42:56 +00:00
|
|
|
{
|
2004-12-03 13:57:50 +00:00
|
|
|
col_type sel_col_start;
|
|
|
|
col_type sel_col_end;
|
|
|
|
row_type sel_row_start;
|
|
|
|
row_type sel_row_end;
|
2001-04-04 22:08:13 +00:00
|
|
|
bool setLines = false;
|
2001-04-04 09:42:56 +00:00
|
|
|
LyXAlignment setAlign = LYX_ALIGN_LEFT;
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular::VAlignment setVAlign = Tabular::LYX_VALIGN_TOP;
|
2001-04-04 09:42:56 +00:00
|
|
|
|
|
|
|
switch (feature) {
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_LEFT:
|
|
|
|
case Tabular::ALIGN_LEFT:
|
2001-12-11 17:26:52 +00:00
|
|
|
setAlign = LYX_ALIGN_LEFT;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_RIGHT:
|
|
|
|
case Tabular::ALIGN_RIGHT:
|
2001-12-11 17:26:52 +00:00
|
|
|
setAlign = LYX_ALIGN_RIGHT;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_CENTER:
|
|
|
|
case Tabular::ALIGN_CENTER:
|
2001-12-11 17:26:52 +00:00
|
|
|
setAlign = LYX_ALIGN_CENTER;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::ALIGN_BLOCK:
|
2002-11-21 12:24:50 +00:00
|
|
|
setAlign = LYX_ALIGN_BLOCK;
|
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_TOP:
|
|
|
|
case Tabular::VALIGN_TOP:
|
|
|
|
setVAlign = Tabular::LYX_VALIGN_TOP;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_BOTTOM:
|
|
|
|
case Tabular::VALIGN_BOTTOM:
|
|
|
|
setVAlign = Tabular::LYX_VALIGN_BOTTOM;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_MIDDLE:
|
|
|
|
case Tabular::VALIGN_MIDDLE:
|
|
|
|
setVAlign = Tabular::LYX_VALIGN_MIDDLE;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
default:
|
|
|
|
break;
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset(ATOMIC_UNDO);
|
2000-04-19 14:42:19 +00:00
|
|
|
|
2004-02-13 16:22:53 +00:00
|
|
|
getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
|
2007-09-04 10:52:08 +00:00
|
|
|
row_type const row = tabular.cellRow(cur.idx());
|
|
|
|
col_type const column = tabular.cellColumn(cur.idx());
|
2001-04-04 09:42:56 +00:00
|
|
|
bool flag = true;
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular::ltType ltt;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
switch (feature) {
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_PWIDTH: {
|
2007-04-28 12:58:49 +00:00
|
|
|
Length const len(value);
|
2005-11-28 11:52:03 +00:00
|
|
|
tabular.setColumnPWidth(cur, cur.idx(), len);
|
2003-10-10 09:01:23 +00:00
|
|
|
if (len.zero()
|
2004-10-23 09:21:38 +00:00
|
|
|
&& tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
|
2007-04-26 12:54:21 +00:00
|
|
|
tabularFeatures(cur, Tabular::ALIGN_CENTER, string());
|
2003-07-31 10:48:50 +00:00
|
|
|
break;
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_MPWIDTH:
|
2007-04-28 12:58:49 +00:00
|
|
|
tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
|
2003-11-10 09:06:48 +00:00
|
|
|
break;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_SPECIAL_COLUMN:
|
|
|
|
case Tabular::SET_SPECIAL_MULTI:
|
2007-01-05 17:11:32 +00:00
|
|
|
tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::APPEND_ROW:
|
2001-04-04 09:42:56 +00:00
|
|
|
// append the row into the tabular
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.appendRow(cur.idx());
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::APPEND_COLUMN:
|
2001-04-04 09:42:56 +00:00
|
|
|
// append the column into the tabular
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.appendColumn(cur.idx());
|
2007-09-04 10:52:08 +00:00
|
|
|
cur.idx() = tabular.cellIndex(row, column);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::DELETE_ROW:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.deleteRow(sel_row_start);
|
2008-04-21 13:33:39 +00:00
|
|
|
if (sel_row_start >= tabular.row_info.size())
|
2001-08-08 13:29:13 +00:00
|
|
|
--sel_row_start;
|
2007-09-04 10:52:08 +00:00
|
|
|
cur.idx() = tabular.cellIndex(sel_row_start, column);
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2004-10-23 09:21:38 +00:00
|
|
|
cur.pos() = 0;
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::DELETE_COLUMN:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (col_type i = sel_col_start; i <= sel_col_end; ++i)
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.deleteColumn(sel_col_start);
|
2008-04-21 13:33:39 +00:00
|
|
|
if (sel_col_start >= tabular.column_info.size())
|
2001-08-08 13:29:13 +00:00
|
|
|
--sel_col_start;
|
2007-09-04 10:52:08 +00:00
|
|
|
cur.idx() = tabular.cellIndex(row, sel_col_start);
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2004-10-23 09:21:38 +00:00
|
|
|
cur.pos() = 0;
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-10-14 13:01:49 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::COPY_ROW:
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.copyRow(row);
|
2006-09-27 16:28:09 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::COPY_COLUMN:
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.copyColumn(column);
|
2007-09-04 10:52:08 +00:00
|
|
|
cur.idx() = tabular.cellIndex(row, column);
|
2006-09-27 16:28:09 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_TOP: {
|
2008-03-18 18:08:32 +00:00
|
|
|
bool lineSet = !tabular.topLine(cur.idx());
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-03-18 18:08:32 +00:00
|
|
|
tabular.setTopLine(tabular.cellIndex(i, j), lineSet);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2001-04-04 22:08:13 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_BOTTOM: {
|
2008-03-18 18:08:32 +00:00
|
|
|
bool lineSet = !tabular.bottomLine(cur.idx());
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-03-18 18:08:32 +00:00
|
|
|
tabular.setBottomLine(tabular.cellIndex(i, j), lineSet);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2001-04-04 22:08:13 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_LEFT: {
|
2008-03-18 18:08:32 +00:00
|
|
|
bool lineSet = !tabular.leftLine(cur.idx());
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-03-18 18:08:32 +00:00
|
|
|
tabular.setLeftLine(tabular.cellIndex(i, j), lineSet);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2001-04-04 22:08:13 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::TOGGLE_LINE_RIGHT: {
|
2008-03-18 18:08:32 +00:00
|
|
|
bool lineSet = !tabular.rightLine(cur.idx());
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-03-18 18:08:32 +00:00
|
|
|
tabular.setRightLine(tabular.cellIndex(i, j), lineSet);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2001-04-04 22:08:13 +00:00
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_ALIGN_LEFT:
|
|
|
|
case Tabular::M_ALIGN_RIGHT:
|
|
|
|
case Tabular::M_ALIGN_CENTER:
|
2001-04-04 09:42:56 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::ALIGN_LEFT:
|
|
|
|
case Tabular::ALIGN_RIGHT:
|
|
|
|
case Tabular::ALIGN_CENTER:
|
|
|
|
case Tabular::ALIGN_BLOCK:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.setAlignment(tabular.cellIndex(i, j), setAlign, flag);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::M_VALIGN_TOP:
|
|
|
|
case Tabular::M_VALIGN_BOTTOM:
|
|
|
|
case Tabular::M_VALIGN_MIDDLE:
|
2001-04-04 09:42:56 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::VALIGN_TOP:
|
|
|
|
case Tabular::VALIGN_BOTTOM:
|
|
|
|
case Tabular::VALIGN_MIDDLE:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.setVAlignment(tabular.cellIndex(i, j), setVAlign, flag);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::MULTICOLUMN: {
|
2004-11-24 16:48:21 +00:00
|
|
|
if (!cur.selection()) {
|
|
|
|
// just multicol for one single cell
|
|
|
|
// check whether we are completely in a multicol
|
2004-10-23 09:21:38 +00:00
|
|
|
if (tabular.isMultiColumn(cur.idx()))
|
|
|
|
tabular.unsetMultiColumn(cur.idx());
|
2003-08-05 12:35:25 +00:00
|
|
|
else
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.setMultiColumn(cur.idx(), 1);
|
2003-04-10 20:56:16 +00:00
|
|
|
break;
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
|
|
|
// we have a selection so this means we just add all this
|
|
|
|
// cells to form a multicolumn cell
|
2004-12-03 13:57:50 +00:00
|
|
|
idx_type const s_start = cur.selBegin().idx();
|
|
|
|
idx_type const s_end = cur.selEnd().idx();
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.setMultiColumn(s_start, s_end - s_start + 1);
|
2004-10-23 09:21:38 +00:00
|
|
|
cur.idx() = s_start;
|
2004-11-24 21:53:46 +00:00
|
|
|
cur.pit() = 0;
|
2004-10-23 09:46:33 +00:00
|
|
|
cur.pos() = 0;
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2000-05-26 13:09:14 +00:00
|
|
|
}
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_ALL_LINES:
|
2001-04-04 22:08:13 +00:00
|
|
|
setLines = true;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_ALL_LINES:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.setAllLines(
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.cellIndex(i,j), setLines);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2008-03-20 08:45:40 +00:00
|
|
|
case Tabular::SET_BORDER_LINES:
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.setLeftLine(tabular.cellIndex(i, sel_col_start), true);
|
|
|
|
tabular.setRightLine(tabular.cellIndex(i, sel_col_end), true);
|
|
|
|
}
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j) {
|
|
|
|
tabular.setTopLine(tabular.cellIndex(sel_row_start, j), true);
|
|
|
|
tabular.setBottomLine(tabular.cellIndex(sel_row_end, j), true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LONGTABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.is_long_tabular = true;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LONGTABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.is_long_tabular = false;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_ROTATE_TABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.rotate = true;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_ROTATE_TABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.rotate = false;
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
case Tabular::TOGGLE_ROTATE_TABULAR:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.rotate = !tabular.rotate;
|
2007-05-12 20:59:21 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-03 18:33:09 +00:00
|
|
|
case Tabular::TABULAR_VALIGN_TOP:
|
|
|
|
tabular.tabular_valignment = Tabular::LYX_VALIGN_TOP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tabular::TABULAR_VALIGN_MIDDLE:
|
|
|
|
tabular.tabular_valignment = Tabular::LYX_VALIGN_MIDDLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tabular::TABULAR_VALIGN_BOTTOM:
|
|
|
|
tabular.tabular_valignment = Tabular::LYX_VALIGN_BOTTOM;
|
|
|
|
break;
|
|
|
|
|
2009-07-11 13:09:45 +00:00
|
|
|
case Tabular::LONGTABULAR_ALIGN_LEFT:
|
|
|
|
tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tabular::LONGTABULAR_ALIGN_CENTER:
|
|
|
|
tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tabular::LONGTABULAR_ALIGN_RIGHT:
|
|
|
|
tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_ROTATE_CELL:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.setRotateCell(
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.cellIndex(i, j), true);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_ROTATE_CELL:
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2008-02-27 20:43:16 +00:00
|
|
|
tabular.setRotateCell(tabular.cellIndex(i, j), false);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
case Tabular::TOGGLE_ROTATE_CELL:
|
|
|
|
{
|
|
|
|
bool oneNotRotated = oneCellHasRotationState(false,
|
|
|
|
sel_row_start, sel_row_end, sel_col_start, sel_col_end);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-05-12 20:59:21 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.setRotateCell(tabular.cellIndex(i, j),
|
2007-05-12 20:59:21 +00:00
|
|
|
oneNotRotated);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_USEBOX: {
|
|
|
|
Tabular::BoxType val = Tabular::BoxType(convert<int>(value));
|
2004-10-23 09:21:38 +00:00
|
|
|
if (val == tabular.getUsebox(cur.idx()))
|
2007-04-26 12:54:21 +00:00
|
|
|
val = Tabular::BOX_NONE;
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
|
2007-09-04 10:52:08 +00:00
|
|
|
tabular.setUsebox(tabular.cellIndex(i, j), val);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTFIRSTHEAD:
|
2001-12-19 16:13:21 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTFIRSTHEAD:
|
2003-07-18 16:23:17 +00:00
|
|
|
tabular.getRowOfLTFirstHead(row, ltt);
|
2001-12-19 21:25:34 +00:00
|
|
|
checkLongtableSpecial(ltt, value, flag);
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.setLTHead(row, flag, ltt, true);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTHEAD:
|
2001-12-19 16:13:21 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTHEAD:
|
2003-07-18 16:23:17 +00:00
|
|
|
tabular.getRowOfLTHead(row, ltt);
|
2001-12-19 21:25:34 +00:00
|
|
|
checkLongtableSpecial(ltt, value, flag);
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.setLTHead(row, flag, ltt, false);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTFOOT:
|
2001-12-19 16:13:21 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTFOOT:
|
2003-07-18 16:23:17 +00:00
|
|
|
tabular.getRowOfLTFoot(row, ltt);
|
2001-12-19 21:25:34 +00:00
|
|
|
checkLongtableSpecial(ltt, value, flag);
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.setLTFoot(row, flag, ltt, false);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_LTLASTFOOT:
|
2001-12-19 16:13:21 +00:00
|
|
|
flag = false;
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTLASTFOOT:
|
2003-07-18 16:23:17 +00:00
|
|
|
tabular.getRowOfLTLastFoot(row, ltt);
|
2001-12-19 21:25:34 +00:00
|
|
|
checkLongtableSpecial(ltt, value, flag);
|
2003-06-13 07:37:48 +00:00
|
|
|
tabular.setLTFoot(row, flag, ltt, true);
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_LTNEWPAGE:
|
2003-10-14 13:01:49 +00:00
|
|
|
tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2009-03-01 15:50:46 +00:00
|
|
|
case Tabular::TOGGLE_LTCAPTION: {
|
2009-11-22 17:10:56 +00:00
|
|
|
bool const set = !tabular.ltCaption(row);
|
2009-03-01 15:50:46 +00:00
|
|
|
cur.idx() = tabular.setLTCaption(row, set);
|
2008-05-04 07:51:50 +00:00
|
|
|
cur.pit() = 0;
|
|
|
|
cur.pos() = 0;
|
2008-09-24 21:27:41 +00:00
|
|
|
cur.setSelection(false);
|
2009-11-22 17:10:56 +00:00
|
|
|
|
2009-03-01 15:50:46 +00:00
|
|
|
if (set)
|
2009-11-22 17:10:56 +00:00
|
|
|
// When a row is set as caption, then also insert
|
|
|
|
// a caption. Otherwise the LaTeX output is broken.
|
2009-03-01 15:50:46 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_CAPTION_INSERT));
|
2009-11-22 17:10:56 +00:00
|
|
|
else {
|
|
|
|
FuncRequest fr(LFUN_INSET_DISSOLVE, "caption");
|
|
|
|
if (lyx::getStatus(fr).enabled())
|
|
|
|
lyx::dispatch(fr);
|
|
|
|
}
|
2008-05-04 07:51:50 +00:00
|
|
|
break;
|
2009-03-01 15:50:46 +00:00
|
|
|
}
|
2008-05-04 07:51:50 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_BOOKTABS:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.use_booktabs = true;
|
2006-07-03 19:13:56 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::UNSET_BOOKTABS:
|
2008-04-21 13:33:39 +00:00
|
|
|
tabular.use_booktabs = false;
|
2006-07-03 19:13:56 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_TOP_SPACE: {
|
2007-04-28 12:58:49 +00:00
|
|
|
Length len;
|
2006-07-03 19:13:56 +00:00
|
|
|
if (value == "default")
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
tabular.row_info[i].top_space_default = true;
|
|
|
|
else if (isValidLength(value, &len))
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.row_info[i].top_space_default = false;
|
|
|
|
tabular.row_info[i].top_space = len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.row_info[i].top_space_default = false;
|
|
|
|
tabular.row_info[i].top_space = len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_BOTTOM_SPACE: {
|
2007-04-28 12:58:49 +00:00
|
|
|
Length len;
|
2006-07-03 19:13:56 +00:00
|
|
|
if (value == "default")
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
tabular.row_info[i].bottom_space_default = true;
|
|
|
|
else if (isValidLength(value, &len))
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.row_info[i].bottom_space_default = false;
|
|
|
|
tabular.row_info[i].bottom_space = len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.row_info[i].bottom_space_default = false;
|
|
|
|
tabular.row_info[i].bottom_space = len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::SET_INTERLINE_SPACE: {
|
2007-04-28 12:58:49 +00:00
|
|
|
Length len;
|
2006-07-03 19:13:56 +00:00
|
|
|
if (value == "default")
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
|
|
|
|
tabular.row_info[i].interline_space_default = true;
|
|
|
|
else if (isValidLength(value, &len))
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.row_info[i].interline_space_default = false;
|
|
|
|
tabular.row_info[i].interline_space = len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
|
|
|
|
tabular.row_info[i].interline_space_default = false;
|
|
|
|
tabular.row_info[i].interline_space = len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-04-04 22:08:13 +00:00
|
|
|
// dummy stuff just to avoid warnings
|
2007-04-26 12:54:21 +00:00
|
|
|
case Tabular::LAST_ACTION:
|
2001-04-04 09:42:56 +00:00
|
|
|
break;
|
2000-05-26 13:09:14 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
}
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
bool InsetTabular::showInsetDialog(BufferView * bv) const
|
2001-03-26 14:47:34 +00:00
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
bv->showDialog("tabular", params2string(*this),
|
|
|
|
const_cast<InsetTabular *>(this));
|
2001-04-04 09:42:56 +00:00
|
|
|
return true;
|
2001-03-26 14:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetTabular::openLayoutDialog(BufferView * bv) const
|
2000-08-01 09:35:42 +00:00
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
bv->showDialog("tabular", params2string(*this),
|
|
|
|
const_cast<InsetTabular *>(this));
|
2000-08-01 09:35:42 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetTabular::copySelection(Cursor & cur)
|
2000-08-23 15:18:19 +00:00
|
|
|
{
|
2004-02-13 16:22:53 +00:00
|
|
|
if (!cur.selection())
|
2001-04-04 09:42:56 +00:00
|
|
|
return false;
|
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
row_type rs, re;
|
|
|
|
col_type cs, ce;
|
2004-02-13 16:22:53 +00:00
|
|
|
getSelection(cur, rs, re, cs, ce);
|
2001-04-04 09:42:56 +00:00
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
paste_tabular.reset(new Tabular(tabular));
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = 0; i < rs; ++i)
|
2003-06-12 11:52:44 +00:00
|
|
|
paste_tabular->deleteRow(0);
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
row_type const rows = re - rs + 1;
|
2008-04-21 13:33:39 +00:00
|
|
|
while (paste_tabular->row_info.size() > rows)
|
2003-06-12 11:52:44 +00:00
|
|
|
paste_tabular->deleteRow(rows);
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
for (col_type i = 0; i < cs; ++i)
|
2003-06-12 11:52:44 +00:00
|
|
|
paste_tabular->deleteColumn(0);
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
col_type const columns = ce - cs + 1;
|
2008-04-21 13:33:39 +00:00
|
|
|
while (paste_tabular->column_info.size() > columns)
|
2003-06-12 11:52:44 +00:00
|
|
|
paste_tabular->deleteColumn(columns);
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2008-07-23 12:13:41 +00:00
|
|
|
paste_tabular->setBuffer(tabular.buffer());
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
odocstringstream os;
|
2007-03-18 10:59:16 +00:00
|
|
|
OutputParams const runparams(0);
|
2008-02-27 20:43:16 +00:00
|
|
|
paste_tabular->plaintext(os, runparams, 0, true, '\t');
|
2007-01-13 18:29:50 +00:00
|
|
|
// Needed for the "Edit->Paste recent" menu and the system clipboard.
|
|
|
|
cap::copySelection(cur, os.str());
|
|
|
|
|
2005-09-06 17:39:39 +00:00
|
|
|
// mark tabular stack dirty
|
2006-04-05 23:56:29 +00:00
|
|
|
// FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
|
2005-09-06 17:39:39 +00:00
|
|
|
// when we (hopefully) have a one-for-all paste mechanism.
|
2007-01-13 18:29:50 +00:00
|
|
|
// This must be called after cap::copySelection.
|
2007-01-04 11:00:09 +00:00
|
|
|
dirtyTabularStack(true);
|
2005-09-06 17:39:39 +00:00
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
return true;
|
2000-08-23 15:18:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetTabular::pasteClipboard(Cursor & cur)
|
2000-08-23 15:18:19 +00:00
|
|
|
{
|
2001-04-04 09:42:56 +00:00
|
|
|
if (!paste_tabular)
|
|
|
|
return false;
|
2009-05-17 21:22:02 +00:00
|
|
|
col_type actcol = tabular.cellColumn(cur.idx());
|
|
|
|
row_type actrow = tabular.cellRow(cur.idx());
|
|
|
|
|
|
|
|
if (cur.selIsMultiCell()) {
|
|
|
|
row_type re;
|
|
|
|
col_type ce;
|
|
|
|
getSelection(cur, actrow, re, actcol, ce);
|
|
|
|
}
|
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type r1 = 0, r2 = actrow;
|
2008-04-21 13:33:39 +00:00
|
|
|
r1 < paste_tabular->row_info.size() && r2 < tabular.row_info.size();
|
2001-04-04 22:08:13 +00:00
|
|
|
++r1, ++r2) {
|
2004-12-03 13:57:50 +00:00
|
|
|
for (col_type c1 = 0, c2 = actcol;
|
2008-04-21 13:33:39 +00:00
|
|
|
c1 < paste_tabular->column_info.size() && c2 < tabular.column_info.size();
|
2001-04-04 22:08:13 +00:00
|
|
|
++c1, ++c2) {
|
2003-07-21 11:01:29 +00:00
|
|
|
if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
|
2009-05-17 21:22:02 +00:00
|
|
|
tabular.isPartOfMultiColumn(r2, c2))
|
2001-04-04 09:42:56 +00:00
|
|
|
continue;
|
2003-07-21 11:01:29 +00:00
|
|
|
if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
|
2001-04-04 09:42:56 +00:00
|
|
|
--c2;
|
|
|
|
continue;
|
|
|
|
}
|
2003-07-21 11:01:29 +00:00
|
|
|
if (tabular.isPartOfMultiColumn(r2, c2)) {
|
2001-04-04 09:42:56 +00:00
|
|
|
--c1;
|
|
|
|
continue;
|
|
|
|
}
|
2008-03-21 06:16:05 +00:00
|
|
|
shared_ptr<InsetTableCell> inset(
|
2008-03-25 13:32:38 +00:00
|
|
|
new InsetTableCell(*paste_tabular->cellInset(r1, c1)));
|
2005-05-12 12:22:39 +00:00
|
|
|
tabular.setCellInset(r2, c2, inset);
|
2006-10-20 09:29:19 +00:00
|
|
|
// FIXME: change tracking (MG)
|
2008-11-17 11:46:07 +00:00
|
|
|
inset->setChange(Change(buffer().params().trackChanges ?
|
2007-05-28 22:27:45 +00:00
|
|
|
Change::INSERTED : Change::UNCHANGED));
|
2005-05-12 12:22:39 +00:00
|
|
|
cur.pos() = 0;
|
2001-04-04 09:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2000-08-23 15:18:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetTabular::cutSelection(Cursor & cur)
|
2000-08-23 15:18:19 +00:00
|
|
|
{
|
2004-02-13 16:22:53 +00:00
|
|
|
if (!cur.selection())
|
|
|
|
return;
|
2003-07-31 10:48:50 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
row_type rs, re;
|
|
|
|
col_type cs, ce;
|
2004-04-03 08:37:12 +00:00
|
|
|
getSelection(cur, rs, re, cs, ce);
|
2005-09-07 10:37:05 +00:00
|
|
|
for (row_type i = rs; i <= re; ++i) {
|
|
|
|
for (col_type j = cs; j <= ce; ++j) {
|
2008-03-21 06:16:05 +00:00
|
|
|
shared_ptr<InsetTableCell> t
|
2007-09-04 10:52:08 +00:00
|
|
|
= cell(tabular.cellIndex(i, j));
|
2008-11-17 11:46:07 +00:00
|
|
|
if (buffer().params().trackChanges)
|
2006-10-06 18:53:35 +00:00
|
|
|
// FIXME: Change tracking (MG)
|
2006-10-20 09:29:19 +00:00
|
|
|
t->setChange(Change(Change::DELETED));
|
2005-09-07 10:37:05 +00:00
|
|
|
else
|
|
|
|
t->clear();
|
|
|
|
}
|
|
|
|
}
|
2004-10-23 08:50:30 +00:00
|
|
|
|
|
|
|
// cursor position might be invalid now
|
2006-09-20 12:16:26 +00:00
|
|
|
if (cur.pit() > cur.lastpit())
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
cur.pos() = cur.lastpos();
|
2004-10-23 08:50:30 +00:00
|
|
|
cur.clearSelection();
|
2000-08-23 15:18:19 +00:00
|
|
|
}
|
|
|
|
|
2001-04-04 22:08:13 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetTabular::isRightToLeft(Cursor & cur) const
|
2001-01-08 16:14:09 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(cur.depth() > 1, /**/);
|
2005-02-08 13:18:05 +00:00
|
|
|
Paragraph const & parentpar = cur[cur.depth() - 2].paragraph();
|
2006-10-21 00:16:43 +00:00
|
|
|
pos_type const parentpos = cur[cur.depth() - 2].pos();
|
2008-11-17 11:46:07 +00:00
|
|
|
return parentpar.getFontSettings(buffer().params(),
|
2006-04-09 00:26:19 +00:00
|
|
|
parentpos).language()->rightToLeft();
|
2001-01-08 16:14:09 +00:00
|
|
|
}
|
2001-04-27 14:03:25 +00:00
|
|
|
|
2008-08-08 21:26:18 +00:00
|
|
|
docstring InsetTabular::asString(idx_type stidx, idx_type enidx,
|
|
|
|
bool intoInsets)
|
|
|
|
{
|
|
|
|
LASSERT(stidx <= enidx, return docstring());
|
|
|
|
docstring retval;
|
|
|
|
col_type const col1 = tabular.cellColumn(stidx);
|
|
|
|
col_type const col2 = tabular.cellColumn(enidx);
|
|
|
|
row_type const row1 = tabular.cellRow(stidx);
|
|
|
|
row_type const row2 = tabular.cellRow(enidx);
|
|
|
|
bool first = true;
|
|
|
|
for (col_type col = col1; col <= col2; col++)
|
|
|
|
for (row_type row = row1; row <= row2; row++) {
|
|
|
|
if (!first)
|
|
|
|
retval += "\n";
|
|
|
|
else
|
|
|
|
first = false;
|
|
|
|
retval += tabular.cellInset(row, col)->asString(intoInsets);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetTabular::getSelection(Cursor & cur,
|
2004-12-03 13:57:50 +00:00
|
|
|
row_type & rs, row_type & re, col_type & cs, col_type & ce) const
|
2001-05-28 15:11:24 +00:00
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
CursorSlice const & beg = cur.selBegin();
|
|
|
|
CursorSlice const & end = cur.selEnd();
|
2007-09-04 10:52:08 +00:00
|
|
|
cs = tabular.cellColumn(beg.idx());
|
|
|
|
ce = tabular.cellColumn(end.idx());
|
2004-02-13 16:22:53 +00:00
|
|
|
if (cs > ce) {
|
|
|
|
ce = cs;
|
2007-09-04 10:52:08 +00:00
|
|
|
cs = tabular.cellColumn(end.idx());
|
2004-02-13 16:22:53 +00:00
|
|
|
} else {
|
2007-09-04 10:52:08 +00:00
|
|
|
ce = tabular.cellRightColumn(end.idx());
|
2004-02-13 16:22:53 +00:00
|
|
|
}
|
2001-05-28 15:11:24 +00:00
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
rs = tabular.cellRow(beg.idx());
|
|
|
|
re = tabular.cellRow(end.idx());
|
2004-02-13 16:22:53 +00:00
|
|
|
if (rs > re)
|
|
|
|
swap(rs, re);
|
2001-05-28 15:11:24 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 22:08:49 +00:00
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
Text * InsetTabular::getText(int idx) const
|
2003-10-14 13:01:49 +00:00
|
|
|
{
|
2004-11-23 23:04:52 +00:00
|
|
|
return size_t(idx) < nargs() ? cell(idx)->getText(0) : 0;
|
2003-10-14 13:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-20 09:29:19 +00:00
|
|
|
void InsetTabular::setChange(Change const & change)
|
2003-02-08 19:18:01 +00:00
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2006-10-20 09:29:19 +00:00
|
|
|
cell(idx)->setChange(change);
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
2003-03-03 23:19:01 +00:00
|
|
|
|
2009-07-16 08:37:32 +00:00
|
|
|
void InsetTabular::acceptChanges()
|
2006-10-24 06:11:45 +00:00
|
|
|
{
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2009-07-16 08:37:32 +00:00
|
|
|
cell(idx)->acceptChanges();
|
2006-10-24 06:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-16 08:37:32 +00:00
|
|
|
void InsetTabular::rejectChanges()
|
2006-10-24 21:38:47 +00:00
|
|
|
{
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2009-07-16 08:37:32 +00:00
|
|
|
cell(idx)->rejectChanges();
|
2006-10-24 21:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Fix bug 4037 and related problems. The patch has been cleaned up a bit
from the one posted to the list.
The basic idea has two parts. First, we hard code an "empty layout"
(called PlainLayout, for want of a better name) in TextClass and read it
before doing anything else. It can therefore be customized by classes,
if they want---say, to make it left-aligned. Second, InsetText's are
divided into three types: (i) normal ones, that use the "default" layout
defined by the text class; (ii) highly restrictive ones, such as ERT and
(not quite an inset) table cells, which demand the empty layout; (iii)
middling ones, which default to an empty layout and use the empty layout
in place of the default. (This is so we don't get the same problem we
had with ERT in e.g. footnotes.) The type of inset is signaled by new
methods InsetText::forceEmptyLayout() and InsetText::useEmptyLayout().
(The latter might better be called: useEmptyLayoutInsteadOfDefault(),
but that's silly.) The old InsetText::forceDefaultParagraphs() has been
split into these, plus a new method InsetText::allowParagraphCustomization().
A lot of the changes just adapt to this change.
The other big change is in GuiToolbar: We want to show LyXDefault and
the "default" layout only when they're active.
There are a handful of places where I'm not entirely sure whether we
should be using forceEmptyLayout or !allowParagraphCustomization() or
both. The InsetCaption is one of these. These places, and some others,
are marked with FIXMEs, so I'd appreciate it if people would search
through the patch and let me know whether these need changing. If they
don't, the FIXMEs can be deleted.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22966 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-12 17:31:07 +00:00
|
|
|
bool InsetTabular::allowParagraphCustomization(idx_type cell) const
|
2002-01-08 14:24:49 +00:00
|
|
|
{
|
2004-12-03 13:57:50 +00:00
|
|
|
return tabular.getPWidth(cell).zero();
|
2002-01-08 14:24:49 +00:00
|
|
|
}
|
2002-03-04 15:42:54 +00:00
|
|
|
|
2003-07-18 16:13:33 +00:00
|
|
|
|
2008-07-10 17:41:52 +00:00
|
|
|
bool InsetTabular::forcePlainLayout(idx_type cell) const
|
2008-03-19 16:21:33 +00:00
|
|
|
{
|
|
|
|
return !tabular.getPWidth(cell).zero();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-15 22:49:14 +00:00
|
|
|
bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
|
2002-03-21 17:09:55 +00:00
|
|
|
bool usePaste)
|
2002-03-04 15:42:54 +00:00
|
|
|
{
|
2002-03-26 11:05:30 +00:00
|
|
|
if (buf.length() <= 0)
|
|
|
|
return true;
|
2002-04-22 16:31:14 +00:00
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
col_type cols = 1;
|
|
|
|
row_type rows = 1;
|
|
|
|
col_type maxCols = 1;
|
2008-02-27 23:03:26 +00:00
|
|
|
size_t const len = buf.length();
|
|
|
|
size_t p = 0;
|
2002-03-04 15:42:54 +00:00
|
|
|
|
2006-09-03 07:02:38 +00:00
|
|
|
while (p < len &&
|
2006-10-21 00:16:43 +00:00
|
|
|
(p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos) {
|
2002-03-04 15:42:54 +00:00
|
|
|
switch (buf[p]) {
|
|
|
|
case '\t':
|
|
|
|
++cols;
|
|
|
|
break;
|
|
|
|
case '\n':
|
2003-10-14 13:01:49 +00:00
|
|
|
if (p + 1 < len)
|
2002-03-04 15:42:54 +00:00
|
|
|
++rows;
|
|
|
|
maxCols = max(cols, maxCols);
|
|
|
|
cols = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
maxCols = max(cols, maxCols);
|
2007-04-26 12:54:21 +00:00
|
|
|
Tabular * loctab;
|
2004-12-03 13:57:50 +00:00
|
|
|
idx_type cell = 0;
|
|
|
|
col_type ocol = 0;
|
|
|
|
row_type row = 0;
|
2002-03-04 15:42:54 +00:00
|
|
|
if (usePaste) {
|
2009-11-08 15:53:21 +00:00
|
|
|
paste_tabular.reset(new Tabular(buffer_, rows, maxCols));
|
2003-11-03 17:47:28 +00:00
|
|
|
loctab = paste_tabular.get();
|
2002-03-04 15:42:54 +00:00
|
|
|
cols = 0;
|
2006-03-28 14:04:14 +00:00
|
|
|
dirtyTabularStack(true);
|
2002-03-04 15:42:54 +00:00
|
|
|
} else {
|
2003-06-13 07:37:48 +00:00
|
|
|
loctab = &tabular;
|
2004-10-23 09:21:38 +00:00
|
|
|
cell = bv.cursor().idx();
|
2007-09-04 10:52:08 +00:00
|
|
|
ocol = tabular.cellColumn(cell);
|
|
|
|
row = tabular.cellRow(cell);
|
2002-03-04 15:42:54 +00:00
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2008-02-27 23:03:26 +00:00
|
|
|
size_t op = 0;
|
2008-04-21 13:33:39 +00:00
|
|
|
idx_type const cells = loctab->numberofcells;
|
2002-03-04 15:42:54 +00:00
|
|
|
p = 0;
|
|
|
|
cols = ocol;
|
2008-04-21 13:33:39 +00:00
|
|
|
rows = loctab->row_info.size();
|
|
|
|
col_type const columns = loctab->column_info.size();
|
2003-03-03 23:19:01 +00:00
|
|
|
|
2003-07-18 16:13:33 +00:00
|
|
|
while (cell < cells && p < len && row < rows &&
|
2006-10-21 00:16:43 +00:00
|
|
|
(p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos)
|
2002-03-04 15:42:54 +00:00
|
|
|
{
|
|
|
|
if (p >= len)
|
|
|
|
break;
|
|
|
|
switch (buf[p]) {
|
|
|
|
case '\t':
|
|
|
|
// we can only set this if we are not too far right
|
|
|
|
if (cols < columns) {
|
2008-03-25 13:32:38 +00:00
|
|
|
shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
|
2008-07-29 12:07:08 +00:00
|
|
|
Font const font = bv.textMetrics(&inset->text()).
|
2008-02-27 23:03:26 +00:00
|
|
|
displayFont(0, 0);
|
2006-10-20 11:44:58 +00:00
|
|
|
inset->setText(buf.substr(op, p - op), font,
|
2008-02-27 20:43:16 +00:00
|
|
|
buffer().params().trackChanges);
|
2002-03-04 15:42:54 +00:00
|
|
|
++cols;
|
|
|
|
++cell;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
// we can only set this if we are not too far right
|
2002-03-26 11:05:30 +00:00
|
|
|
if (cols < columns) {
|
2008-03-25 13:32:38 +00:00
|
|
|
shared_ptr<InsetTableCell> inset = tabular.cellInset(cell);
|
2008-07-29 12:07:08 +00:00
|
|
|
Font const font = bv.textMetrics(&inset->text()).
|
2008-02-27 23:03:26 +00:00
|
|
|
displayFont(0, 0);
|
2006-10-20 11:44:58 +00:00
|
|
|
inset->setText(buf.substr(op, p - op), font,
|
2008-02-27 20:43:16 +00:00
|
|
|
buffer().params().trackChanges);
|
2002-03-26 11:05:30 +00:00
|
|
|
}
|
2002-03-04 15:42:54 +00:00
|
|
|
cols = ocol;
|
|
|
|
++row;
|
|
|
|
if (row < rows)
|
2007-09-04 10:52:08 +00:00
|
|
|
cell = loctab->cellIndex(row, cols);
|
2002-03-04 15:42:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++p;
|
|
|
|
op = p;
|
|
|
|
}
|
|
|
|
// check for the last cell if there is no trailing '\n'
|
2003-07-18 16:13:33 +00:00
|
|
|
if (cell < cells && op < len) {
|
2008-03-25 13:32:38 +00:00
|
|
|
shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
|
2008-07-29 12:07:08 +00:00
|
|
|
Font const font = bv.textMetrics(&inset->text()).displayFont(0, 0);
|
2006-10-20 11:44:58 +00:00
|
|
|
inset->setText(buf.substr(op, len - op), font,
|
2008-02-27 20:43:16 +00:00
|
|
|
buffer().params().trackChanges);
|
2002-03-26 11:05:30 +00:00
|
|
|
}
|
2002-03-04 15:42:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-08-02 16:39:43 +00:00
|
|
|
|
|
|
|
|
2003-07-18 16:13:33 +00:00
|
|
|
void InsetTabular::addPreview(PreviewLoader & loader) const
|
2002-08-02 16:39:43 +00:00
|
|
|
{
|
2008-04-21 13:33:39 +00:00
|
|
|
row_type const rows = tabular.row_info.size();
|
|
|
|
col_type const columns = tabular.column_info.size();
|
2004-12-03 13:57:50 +00:00
|
|
|
for (row_type i = 0; i < rows; ++i) {
|
|
|
|
for (col_type j = 0; j < columns; ++j)
|
2008-03-25 13:32:38 +00:00
|
|
|
tabular.cellInset(i, j)->addPreview(loader);
|
2003-11-10 09:06:48 +00:00
|
|
|
}
|
2002-08-02 16:39:43 +00:00
|
|
|
}
|
2003-03-09 18:11:57 +00:00
|
|
|
|
|
|
|
|
2008-03-15 12:22:28 +00:00
|
|
|
bool InsetTabular::completionSupported(Cursor const & cur) const
|
|
|
|
{
|
|
|
|
Cursor const & bvCur = cur.bv().cursor();
|
|
|
|
if (&bvCur.inset() != this)
|
|
|
|
return false;
|
|
|
|
return cur.text()->completionSupported(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetTabular::inlineCompletionSupported(Cursor const & cur) const
|
|
|
|
{
|
|
|
|
return completionSupported(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetTabular::automaticInlineCompletion() const
|
|
|
|
{
|
|
|
|
return lyxrc.completion_inline_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetTabular::automaticPopupCompletion() const
|
|
|
|
{
|
|
|
|
return lyxrc.completion_popup_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-16 17:07:10 +00:00
|
|
|
bool InsetTabular::showCompletionCursor() const
|
|
|
|
{
|
|
|
|
return lyxrc.completion_cursor_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-15 12:22:28 +00:00
|
|
|
CompletionList const * InsetTabular::createCompletionList(Cursor const & cur) const
|
|
|
|
{
|
|
|
|
return completionSupported(cur) ? cur.text()->createCompletionList(cur) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetTabular::completionPrefix(Cursor const & cur) const
|
|
|
|
{
|
|
|
|
if (!completionSupported(cur))
|
|
|
|
return docstring();
|
|
|
|
return cur.text()->completionPrefix(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetTabular::insertCompletion(Cursor & cur, docstring const & s, bool finished)
|
|
|
|
{
|
|
|
|
if (!completionSupported(cur))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return cur.text()->insertCompletion(cur, s, finished);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetTabular::completionPosAndDim(Cursor const & cur, int & x, int & y,
|
|
|
|
Dimension & dim) const
|
|
|
|
{
|
|
|
|
TextMetrics const & tm = cur.bv().textMetrics(cur.text());
|
|
|
|
tm.completionPosAndDim(cur, x, y, dim);
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetTabular::string2params(string const & in, InsetTabular & inset)
|
2003-03-09 18:11:57 +00:00
|
|
|
{
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-03-09 18:11:57 +00:00
|
|
|
lex.setStream(data);
|
|
|
|
|
2003-04-24 20:02:49 +00:00
|
|
|
if (in.empty())
|
2004-11-18 12:58:19 +00:00
|
|
|
return;
|
2003-04-29 23:59:39 +00:00
|
|
|
|
2004-11-18 12:58:19 +00:00
|
|
|
string token;
|
|
|
|
lex >> token;
|
2008-03-27 22:26:24 +00:00
|
|
|
if (!lex || token != "tabular") {
|
|
|
|
LYXERR0("Expected arg 1 to be \"tabular\" in " << in);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-09 18:11:57 +00:00
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
// by Buffer::readInset
|
2004-11-18 12:58:19 +00:00
|
|
|
lex >> token;
|
2008-03-27 22:26:24 +00:00
|
|
|
if (!lex || token != "Tabular") {
|
|
|
|
LYXERR0("Expected arg 2 to be \"Tabular\" in " << in);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-10 03:11:54 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
inset.read(lex);
|
2003-03-09 18:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetTabular::params2string(InsetTabular const & inset)
|
2003-03-09 18:11:57 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
data << "tabular" << ' ';
|
2008-02-27 20:43:16 +00:00
|
|
|
inset.write(data);
|
2003-03-09 18:11:57 +00:00
|
|
|
data << "\\end_inset\n";
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-03-09 18:11:57 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|