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
|
|
|
|
*
|
2007-04-26 12:54:21 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Matthias Ettrich
|
|
|
|
|
* \author Jos<EFBFBD> Matos
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
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"
|
|
|
|
|
#include "paragraph_funcs.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"
|
|
|
|
|
#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" },
|
|
|
|
|
{ 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" },
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2008-03-21 17:45:14 +00:00
|
|
|
|
Tabular::CellData::CellData(Buffer const & buf, Tabular const & table)
|
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-03-21 17:45:14 +00:00
|
|
|
|
inset(new InsetTableCell(buf, this, &table))
|
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
|
|
|
|
{
|
2008-03-04 22:28:18 +00:00
|
|
|
|
inset->setBuffer(const_cast<Buffer &>(buf));
|
|
|
|
|
inset->paragraphs().back().setLayout(buf.params().documentClass().emptyLayout());
|
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()))
|
|
|
|
|
{
|
|
|
|
|
inset->setCellData(this);
|
|
|
|
|
}
|
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),
|
|
|
|
|
newpage(false)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-10-06 09:19:53 +00:00
|
|
|
|
Tabular::Tabular()
|
|
|
|
|
{
|
|
|
|
|
// unusable now!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
Tabular::Tabular(Buffer const & 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// activates all lines and sets all widths to 0
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void Tabular::init(Buffer const & buf, row_type rows_arg,
|
2007-04-26 12:54:21 +00:00
|
|
|
|
col_type columns_arg)
|
|
|
|
|
{
|
2008-02-27 20:43:16 +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-03-21 17:45:14 +00:00
|
|
|
|
cell_info = cell_vvector(rows_arg, cell_vector(columns_arg, CellData(buf, *this)));
|
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;
|
|
|
|
|
rotate = false;
|
|
|
|
|
use_booktabs = false;
|
2008-03-18 18:08:32 +00:00
|
|
|
|
// set silly default lines
|
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i)
|
|
|
|
|
for (col_type j = 0; j < columnCount(); ++j) {
|
|
|
|
|
cell_info[i][j].top_line = true;
|
|
|
|
|
cell_info[i][j].left_line = true;
|
|
|
|
|
cell_info[i][j].bottom_line = i == 0 || i == rowCount() - 1;
|
|
|
|
|
cell_info[i][j].right_line = j == columnCount() - 1;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2008-02-27 20:43:16 +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];
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
row_type const nrows = rowCount();
|
|
|
|
|
col_type const ncols = columnCount();
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
2008-03-21 17:45:14 +00:00
|
|
|
|
cell_info = cell_vvector(nrows, cell_vector(ncols, CellData(buffer(), *this)));
|
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);
|
|
|
|
|
setLeftLine(i, isPartOfMultiColumn(row, c) ? false : leftLine(j));
|
|
|
|
|
if (cell_info[row][c].multicolumn == CELL_NORMAL || c == ncols - 1
|
|
|
|
|
|| (c + 1 < ncols
|
|
|
|
|
&& cell_info[row][c].multicolumn != CELL_NORMAL
|
|
|
|
|
&& cell_info[row][c + 1].multicolumn == CELL_NORMAL))
|
|
|
|
|
setRightLine(i, rightLine(j));
|
|
|
|
|
else
|
|
|
|
|
setRightLine(i, false);
|
|
|
|
|
// 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
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (rowCount() == 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)
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
col_type const column = cellColumn(cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
column_vector::iterator cit = column_info.begin() + column + 1;
|
2008-02-27 20:59:44 +00:00
|
|
|
|
column_info.insert(cit, ColumnData());
|
2008-03-28 12:00:53 +00:00
|
|
|
|
row_type const nrows = rowCount();
|
2008-03-15 16:44:00 +00:00
|
|
|
|
col_type const ncols = columnCount();
|
2007-04-26 12:54:21 +00:00
|
|
|
|
// set the column values of the column before
|
|
|
|
|
column_info[column + 1] = column_info[column];
|
|
|
|
|
|
2008-03-28 12:00:53 +00:00
|
|
|
|
for (row_type r = 0; r < nrows; ++r) {
|
|
|
|
|
cell_info[r].insert(cell_info[r].begin() + column + 1,
|
|
|
|
|
CellData(buffer(), *this));
|
2008-03-15 16:44:00 +00:00
|
|
|
|
col_type c = column + 2;
|
|
|
|
|
while (c < ncols
|
2008-03-28 12:00:53 +00:00
|
|
|
|
&& cell_info[r][c].multicolumn == CELL_PART_OF_MULTICOLUMN) {
|
|
|
|
|
cell_info[r][c].multicolumn = CELL_NORMAL;
|
2008-03-15 16:44:00 +00:00
|
|
|
|
++c;
|
|
|
|
|
}
|
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
|
|
|
|
|
idx_type const i = cellIndex(r, column + 1);
|
|
|
|
|
idx_type const j = cellIndex(r, column);
|
|
|
|
|
setBottomLine(i, bottomLine(j));
|
|
|
|
|
setTopLine(i, topLine(j));
|
|
|
|
|
//
|
|
|
|
|
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
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (columnCount() == 1)
|
2007-04-26 12:54:21 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
column_info.erase(column_info.begin() + column);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
2007-08-12 13:25:36 +00:00
|
|
|
|
// Care about multicolumn cells
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (column + 1 < columnCount() &&
|
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
|
|
|
|
}
|
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]);
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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)
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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
|
|
|
|
{
|
2008-03-23 11:35:46 +00:00
|
|
|
|
col_type ncols = columnCount();
|
|
|
|
|
row_type nrows = rowCount();
|
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;
|
|
|
|
|
++i;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
Tabular::idx_type Tabular::cellCount() const
|
2007-04-26 12:54:21 +00:00
|
|
|
|
{
|
|
|
|
|
return numberofcells;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type i = 0; i < columnCount(); ++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));
|
|
|
|
|
return !rowBottomLine(row - 1) && 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
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
return cellRow(cell) == rowCount() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Tabular::getAdditionalHeight(row_type row) const
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (!row || row >= rowCount())
|
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)
|
|
|
|
|
&& nextcol < columnCount() && 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-03-24 14:03:00 +00:00
|
|
|
|
col_type const ncols = columnCount();
|
|
|
|
|
row_type const nrows = rowCount();
|
|
|
|
|
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-03-24 14:03:00 +00:00
|
|
|
|
col_type const ncols = columnCount();
|
|
|
|
|
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;
|
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);
|
|
|
|
|
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
|
2007-08-21 13:03:55 +00:00
|
|
|
|
inset->getText(0)->setLayout(cur.bv().buffer(), 0, cur.lastpit() + 1,
|
2008-02-28 01:42:02 +00:00
|
|
|
|
bp.documentClass().emptyLayoutName());
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
bool all_cols_set = true;
|
2008-03-25 20:48:48 +00:00
|
|
|
|
row_type const nrows = rowCount();
|
2008-03-18 18:08:32 +00:00
|
|
|
|
for (row_type r = 0; all_cols_set && r < nrows; ++r) {
|
|
|
|
|
idx_type i = cellIndex(r, c);
|
2008-03-25 20:48:48 +00:00
|
|
|
|
if (c == cellColumn(i))
|
2008-03-25 13:32:38 +00:00
|
|
|
|
all_cols_set = cellInfo(i).left_line;
|
2008-03-18 18:08:32 +00:00
|
|
|
|
}
|
|
|
|
|
return all_cols_set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::columnRightLine(col_type c) const
|
|
|
|
|
{
|
|
|
|
|
bool all_cols_set = true;
|
2008-03-25 20:48:48 +00:00
|
|
|
|
row_type const nrows = rowCount();
|
2008-03-18 18:08:32 +00:00
|
|
|
|
for (row_type r = 0; all_cols_set && r < nrows; ++r) {
|
|
|
|
|
idx_type i = cellIndex(r, c);
|
|
|
|
|
if (c == cellColumn(i) + columnSpan(i) - 1)
|
2008-03-25 13:32:38 +00:00
|
|
|
|
all_cols_set = cellInfo(i).right_line;
|
2008-03-18 18:08:32 +00:00
|
|
|
|
}
|
|
|
|
|
return all_cols_set;
|
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-04-28 12:58:49 +00:00
|
|
|
|
Length const Tabular::getColumnPWidth(idx_type cell) const
|
2007-04-26 12:54:21 +00:00
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
return column_info[cellColumn(cell)].p_width;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length const Tabular::getMColumnPWidth(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-04-28 12:58:49 +00:00
|
|
|
|
return Length();
|
2007-04-26 12:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const Tabular::getAlignSpecial(idx_type cell, int what) const
|
|
|
|
|
{
|
|
|
|
|
if (what == SET_SPECIAL_MULTI)
|
2008-03-25 13:32:38 +00:00
|
|
|
|
return cellInfo(cell).align_special;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
return column_info[cellColumn(cell)].align_special;
|
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
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (row > rowCount() - 1)
|
|
|
|
|
row = rowCount() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
return cell_info[row][0].cellno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isLastCellInRow(idx_type cell) const
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
return cellRightColumn(cell) == columnCount() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (row > rowCount() - 1)
|
|
|
|
|
row = rowCount() - 1;
|
|
|
|
|
return cell_info[row][columnCount() - 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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (cell >= cellCount())
|
|
|
|
|
return rowCount() - 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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (cell >= cellCount())
|
|
|
|
|
return columnCount() - 1;
|
2007-04-26 12:54:21 +00:00
|
|
|
|
if (cell == npos)
|
|
|
|
|
return 0;
|
|
|
|
|
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);
|
|
|
|
|
while (column < columnCount() - 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)
|
2007-09-04 10:52:08 +00:00
|
|
|
|
<< write_attribute("rows", rowCount())
|
|
|
|
|
<< write_attribute("columns", columnCount())
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< ">\n";
|
|
|
|
|
// global longtable options
|
|
|
|
|
os << "<features"
|
|
|
|
|
<< write_attribute("rotate", rotate)
|
|
|
|
|
<< write_attribute("booktabs", use_booktabs)
|
|
|
|
|
<< write_attribute("islongtable", is_long_tabular)
|
|
|
|
|
<< write_attribute("firstHeadTopDL", endfirsthead.topDL)
|
|
|
|
|
<< 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)
|
|
|
|
|
<< write_attribute("lastFootEmpty", endlastfoot.empty)
|
|
|
|
|
<< ">\n";
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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";
|
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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)
|
|
|
|
|
<< ">\n";
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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 ")) {
|
2007-04-26 12:54:21 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int version;
|
|
|
|
|
if (!getTokenValue(line, "version", version))
|
|
|
|
|
return;
|
|
|
|
|
BOOST_ASSERT(version >= 2);
|
|
|
|
|
|
|
|
|
|
int rows_arg;
|
|
|
|
|
if (!getTokenValue(line, "rows", rows_arg))
|
|
|
|
|
return;
|
|
|
|
|
int columns_arg;
|
|
|
|
|
if (!getTokenValue(line, "columns", columns_arg))
|
|
|
|
|
return;
|
2008-02-27 20:43:16 +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);
|
|
|
|
|
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);
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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);
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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);
|
|
|
|
|
getTokenValue(line, "special", cell_info[i][j].align_special);
|
|
|
|
|
l_getline(is, line);
|
|
|
|
|
if (prefixIs(line, "\\begin_inset")) {
|
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-03-24 14:03:00 +00:00
|
|
|
|
col_type const ncols = columnCount();
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
while (column < columnCount() &&
|
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::setBookTabs(bool what)
|
|
|
|
|
{
|
|
|
|
|
use_booktabs = what;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::useBookTabs() const
|
|
|
|
|
{
|
|
|
|
|
return use_booktabs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setLongTabular(bool what)
|
|
|
|
|
{
|
|
|
|
|
is_long_tabular = what;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::isLongTabular() const
|
|
|
|
|
{
|
|
|
|
|
return is_long_tabular;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::setRotateTabular(bool flag)
|
|
|
|
|
{
|
|
|
|
|
rotate = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::getRotateTabular() const
|
|
|
|
|
{
|
|
|
|
|
return rotate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i)
|
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (cell + 1 < cellCount())
|
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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (cellRow(cell) + 1 < rowCount())
|
|
|
|
|
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
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
BOOST_ASSERT(column != npos && column < columnCount() &&
|
|
|
|
|
row != npos && row < rowCount());
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::BoxType Tabular::getUsebox(idx_type cell) const
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (column_info[cellColumn(cell)].p_width.zero() &&
|
2008-03-25 13:32:38 +00:00
|
|
|
|
!(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
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
|
if (row_info[i].endfirsthead)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Tabular::haveLTFoot() const
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i)
|
2007-04-26 12:54:21 +00:00
|
|
|
|
if (row_info[i].endlastfoot)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (row >= rowCount() || 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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (row >= rowCount() || 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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (row >= rowCount())
|
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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
BOOST_ASSERT(row < rowCount());
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type row = 0; row < rowCount(); ++row)
|
|
|
|
|
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
|
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
BOOST_ASSERT(row < rowCount());
|
|
|
|
|
BOOST_ASSERT(column < columnCount());
|
2007-04-26 12:54:21 +00:00
|
|
|
|
return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Tabular::TeXTopHLine(odocstream & os, row_type row) const
|
|
|
|
|
{
|
|
|
|
|
// FIXME: assert or return 0 as in TeXBottomHLine()?
|
|
|
|
|
BOOST_ASSERT(row != npos);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
BOOST_ASSERT(row < rowCount());
|
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;
|
|
|
|
|
|
|
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
|
if (topLine(i))
|
|
|
|
|
++tmp;
|
|
|
|
|
}
|
2008-02-15 11:36:05 +00:00
|
|
|
|
if (use_booktabs && row == 0) {
|
|
|
|
|
if (topLine(fcell))
|
|
|
|
|
os << "\\toprule ";
|
2007-04-26 12:54:21 +00:00
|
|
|
|
} else if (tmp == n - fcell) {
|
|
|
|
|
os << (use_booktabs ? "\\midrule " : "\\hline ");
|
|
|
|
|
} else if (tmp) {
|
|
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
|
if (topLine(i)) {
|
|
|
|
|
os << (use_booktabs ? "\\cmidrule{" : "\\cline{")
|
2007-09-04 10:52:08 +00:00
|
|
|
|
<< cellColumn(i) + 1
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< '-'
|
2007-09-04 10:52:08 +00:00
|
|
|
|
<< cellRightColumn(i) + 1
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< "} ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
os << "\n";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Tabular::TeXBottomHLine(odocstream & os, row_type row) const
|
|
|
|
|
{
|
|
|
|
|
// FIXME: return 0 or assert as in TeXTopHLine()?
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (row == npos || row >= rowCount())
|
2007-04-26 12:54:21 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
idx_type const fcell = getFirstCellInRow(row);
|
|
|
|
|
idx_type const n = numberOfCellsInRow(fcell) + fcell;
|
|
|
|
|
idx_type tmp = 0;
|
|
|
|
|
|
|
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
|
if (bottomLine(i))
|
|
|
|
|
++tmp;
|
|
|
|
|
}
|
2008-02-15 01:28:46 +00:00
|
|
|
|
if (use_booktabs && row == rowCount() - 1) {
|
2008-02-15 11:36:05 +00:00
|
|
|
|
if (bottomLine(fcell))
|
|
|
|
|
os << "\\bottomrule";
|
2007-04-26 12:54:21 +00:00
|
|
|
|
} else if (tmp == n - fcell) {
|
|
|
|
|
os << (use_booktabs ? "\\midrule" : "\\hline");
|
|
|
|
|
} else if (tmp) {
|
|
|
|
|
for (idx_type i = fcell; i < n; ++i) {
|
|
|
|
|
if (bottomLine(i)) {
|
|
|
|
|
os << (use_booktabs ? "\\cmidrule{" : "\\cline{")
|
2007-09-04 10:52:08 +00:00
|
|
|
|
<< cellColumn(i) + 1
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< '-'
|
2007-09-04 10:52:08 +00:00
|
|
|
|
<< cellRightColumn(i) + 1
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< "} ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
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-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
|
2008-03-26 10:34:48 +00:00
|
|
|
|
row_type const r = cellRow(cell);
|
2008-03-25 20:48:48 +00:00
|
|
|
|
col_type const c = cellColumn(cell);
|
|
|
|
|
col_type const nextcol = c + columnSpan(cell);
|
2008-03-26 10:34:48 +00:00
|
|
|
|
bool prevcellright = c > 0 && rightLine(cellIndex(r, c - 1));
|
2008-03-28 12:00:53 +00:00
|
|
|
|
bool forceleft = ismulticol && !prevcellright && leftLine(cell);
|
2008-03-25 20:48:48 +00:00
|
|
|
|
bool nextcolleft = nextcol < columnCount() && columnLeftLine(nextcol);
|
|
|
|
|
bool coldouble = columnRightLine(c) && nextcolleft;
|
2008-03-28 12:00:53 +00:00
|
|
|
|
bool nextcellleft = nextcol < columnCount()
|
|
|
|
|
&& leftLine(cellIndex(r, nextcol));
|
2008-03-25 20:48:48 +00:00
|
|
|
|
bool celldouble = rightLine(cell) && nextcellleft;
|
|
|
|
|
bool doubleright = celldouble && (isMultiColumn(cell) || !coldouble);
|
|
|
|
|
ismulticol = isMultiColumn(cell)
|
|
|
|
|
|| (leftLine(cell) && !columnLeftLine(c))
|
2008-03-25 11:40:16 +00:00
|
|
|
|
|| (rightLine(cell) && !columnRightLine(c))
|
2008-03-28 12:00:53 +00:00
|
|
|
|
|| (!celldouble && coldouble) || doubleright || forceleft;
|
2008-03-25 20:48:48 +00:00
|
|
|
|
if (ismulticol) {
|
2008-03-18 18:08:32 +00:00
|
|
|
|
os << "\\multicolumn{" << columnSpan(cell) << "}{";
|
2008-03-25 20:48:48 +00:00
|
|
|
|
if (leftLine(cell) || forceleft)
|
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-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-03-25 20:48:48 +00:00
|
|
|
|
if (rightLine(cell))
|
|
|
|
|
os << '|';
|
|
|
|
|
if (doubleright)
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
// output header info
|
|
|
|
|
if (haveLTHead()) {
|
|
|
|
|
if (endhead.topDL) {
|
|
|
|
|
os << "\\hline\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
2007-04-26 12:54:21 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (endhead.bottomDL) {
|
|
|
|
|
os << "\\hline\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
os << "\\endhead\n";
|
|
|
|
|
++ret;
|
|
|
|
|
if (endfirsthead.empty) {
|
|
|
|
|
os << "\\endfirsthead\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// output firstheader info
|
|
|
|
|
if (haveLTFirstHead()) {
|
|
|
|
|
if (endfirsthead.topDL) {
|
|
|
|
|
os << "\\hline\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
2007-04-26 12:54:21 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (endfirsthead.bottomDL) {
|
|
|
|
|
os << "\\hline\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
os << "\\endfirsthead\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
// output footer info
|
|
|
|
|
if (haveLTFoot()) {
|
|
|
|
|
if (endfoot.topDL) {
|
|
|
|
|
os << "\\hline\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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;
|
|
|
|
|
if (endlastfoot.empty) {
|
|
|
|
|
os << "\\endlastfoot\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// output lastfooter info
|
|
|
|
|
if (haveLTLastFoot()) {
|
|
|
|
|
if (endlastfoot.topDL) {
|
|
|
|
|
os << "\\hline\n";
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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;
|
|
|
|
|
return !row_info[row].endhead && !row_info[row].endfirsthead &&
|
|
|
|
|
!row_info[row].endfoot && !row_info[row].endlastfoot;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
int ret = TeXTopHLine(os, i);
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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-02-27 20:43:16 +00:00
|
|
|
|
if (par.getParLanguage(buffer().params())->lang() ==
|
2007-05-31 18:53:01 +00:00
|
|
|
|
"farsi")
|
|
|
|
|
os << "\\textFR{";
|
2008-02-27 20:43:16 +00:00
|
|
|
|
else if (par.getParLanguage(buffer().params())->lang() == "arabic_arabi")
|
2007-06-26 00:11:03 +00:00
|
|
|
|
os << "\\textAR{";
|
|
|
|
|
// currently, remaning RTL languages are arabic_arabtex and hebrew
|
2007-05-31 18:53:01 +00:00
|
|
|
|
else
|
|
|
|
|
os << "\\R{";
|
|
|
|
|
}
|
2008-02-27 20:43:16 +00:00
|
|
|
|
ret += inset->latex(os, runparams);
|
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;
|
|
|
|
|
}
|
|
|
|
|
os << "\\tabularnewline";
|
|
|
|
|
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;
|
|
|
|
|
ret += TeXBottomHLine(os, i);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (is_long_tabular)
|
|
|
|
|
os << "\\begin{longtable}{";
|
|
|
|
|
else
|
|
|
|
|
os << "\\begin{tabular}{";
|
2008-03-18 18:08:32 +00:00
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type i = 0; i < columnCount(); ++i) {
|
2008-03-18 18:08:32 +00:00
|
|
|
|
if (!use_booktabs && 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-03-18 18:08:32 +00:00
|
|
|
|
if (!use_booktabs && 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
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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";
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
os << "<tgroup cols=\"" << columnCount()
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< "\" colsep=\"1\" rowsep=\"1\">\n";
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type i = 0; i < columnCount(); ++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 +
|
|
|
|
|
//+---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// output header info
|
|
|
|
|
if (haveLTHead() || haveLTFirstHead()) {
|
|
|
|
|
os << "<thead>\n";
|
|
|
|
|
++ret;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
2007-04-26 12:54:21 +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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++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];
|
2007-09-04 10:52:08 +00:00
|
|
|
|
while (column < columnCount() - 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];
|
2007-09-04 10:52:08 +00:00
|
|
|
|
while (column < columnCount() -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];
|
2007-09-04 10:52:08 +00:00
|
|
|
|
while (column < columnCount() -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
|
2007-09-04 10:52:08 +00:00
|
|
|
|
vector<unsigned int> clen(columnCount());
|
2007-04-26 12:54:21 +00:00
|
|
|
|
|
|
|
|
|
if (!onlydata) {
|
|
|
|
|
// first all non (real) multicolumn cells!
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++j) {
|
2007-04-26 12:54:21 +00:00
|
|
|
|
clen[j] = 0;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
|
|
|
|
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!
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++j) {
|
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < rowCount(); ++i) {
|
2007-04-26 12:54:21 +00:00
|
|
|
|
if (!onlydata && plaintextTopHLine(os, i, clen))
|
|
|
|
|
os << docstring(depth * 2, ' ');
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < columnCount(); ++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;
|
|
|
|
|
// reset the InsetTableCell's pointers
|
|
|
|
|
ins->setCellData(&cd);
|
|
|
|
|
ins->setTabular(this);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tabular::idx_type
|
2008-03-25 13:32:38 +00:00
|
|
|
|
Tabular::cellFromInset(Inset const * inset) const
|
2007-04-26 12:54:21 +00:00
|
|
|
|
{
|
|
|
|
|
// is this inset part of the tabular?
|
|
|
|
|
if (!inset) {
|
|
|
|
|
lyxerr << "Error: this is not a cell of the tabular!" << endl;
|
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (idx_type cell = 0, n = cellCount(); cell < n; ++cell)
|
2008-03-25 13:32:38 +00:00
|
|
|
|
if (cellInset(cell).get() == inset) {
|
|
|
|
|
LYXERR(Debug::INSETTEXT, "Tabular::cellFromInset: "
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< "cell=" << cell);
|
2007-04-26 12:54:21 +00:00
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We should have found a cell at this point
|
2008-03-25 13:32:38 +00:00
|
|
|
|
lyxerr << "Tabular::cellFromInset: Cell of inset "
|
2007-04-26 12:54:21 +00:00
|
|
|
|
<< inset << " not found!" << endl;
|
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
|
// shut up compiler
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tabular::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.require("NeedTabularnewline");
|
|
|
|
|
if (useBookTabs())
|
|
|
|
|
features.require("booktabs");
|
|
|
|
|
if (isLongTabular())
|
|
|
|
|
features.require("longtable");
|
|
|
|
|
if (needRotating())
|
|
|
|
|
features.require("rotating");
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (idx_type cell = 0; cell < cellCount(); ++cell) {
|
2007-04-26 12:54:21 +00:00
|
|
|
|
if (getVAlignment(cell) != LYX_VALIGN_TOP ||
|
|
|
|
|
(!getPWidth(cell).zero() && !isMultiColumn(cell)))
|
|
|
|
|
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
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
InsetTableCell::InsetTableCell(Buffer const & buf,
|
|
|
|
|
Tabular::CellData const * cell, Tabular const * table)
|
|
|
|
|
: InsetText(buf), cell_data_(cell), table_(table)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetTableCell::forceEmptyLayout(idx_type) const
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(table_);
|
|
|
|
|
BOOST_ASSERT(cell_data_);
|
|
|
|
|
return table_->getPWidth(cell_data_->cellno).zero();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InsetTableCell::allowParagraphCustomization(idx_type) const
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(table_);
|
|
|
|
|
BOOST_ASSERT(cell_data_);
|
|
|
|
|
return !table_->getPWidth(cell_data_->cellno).zero();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
|
FuncStatus & status) const
|
|
|
|
|
{
|
|
|
|
|
bool enabled;
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_LAYOUT:
|
|
|
|
|
enabled = !forceEmptyLayout();
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
|
|
|
|
enabled = allowParagraphCustomization();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return InsetText::getStatus(cur, cmd, status);
|
|
|
|
|
}
|
|
|
|
|
status.enabled(enabled);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// InsetTabular
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2004-12-03 13:57:50 +00:00
|
|
|
|
InsetTabular::InsetTabular(Buffer const & buf, row_type rows,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
col_type columns)
|
2008-03-25 21:26:03 +00:00
|
|
|
|
: tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))), scx_(0),
|
|
|
|
|
rowselect_(false), colselect_(false)
|
2008-02-23 22:32:33 +00:00
|
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
|
setBuffer(const_cast<Buffer &>(buf)); // FIXME: remove later
|
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)
|
|
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
|
setBuffer(const_cast<Buffer &>(tab.buffer())); // FIXME: remove later
|
2008-02-23 22:32:33 +00:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 20:42:46 +00:00
|
|
|
|
bool InsetTabular::insetAllowed(InsetCode code) const
|
|
|
|
|
{
|
|
|
|
|
if (code == MATHMACRO_CODE)
|
|
|
|
|
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
|
|
|
|
{
|
2001-08-06 19:13:25 +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
|
|
|
|
|
2001-04-04 09:42:56 +00:00
|
|
|
|
if (old_format)
|
|
|
|
|
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
|
|
|
|
}
|
2007-03-26 13:43:49 +00:00
|
|
|
|
if (!lex) {
|
2001-04-04 09:42:56 +00:00
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
2001-04-04 22:08:13 +00:00
|
|
|
|
"Read: `$$Token'");
|
2001-04-04 09:42:56 +00:00
|
|
|
|
}
|
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);
|
|
|
|
|
size_t nrows = tabular.rowCount();
|
|
|
|
|
row_type r = 0;
|
|
|
|
|
for (;r < nrows && y > h; ++r) {
|
|
|
|
|
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;
|
|
|
|
|
size_t ncols = tabular.columnCount();
|
|
|
|
|
col_type c = 0;
|
|
|
|
|
for (;c < ncols && x > w; ++c) {
|
|
|
|
|
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) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "InsetTabular::metrics: need bv" << endl;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (idx_type cell = 0; i < tabular.rowCount(); ++i) {
|
2004-02-16 11:58:51 +00:00
|
|
|
|
int maxAsc = 0;
|
|
|
|
|
int maxDesc = 0;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type j = 0; j < tabular.columnCount(); ++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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2007-08-31 14:02:12 +00:00
|
|
|
|
// FIXME: As the full backrgound is painted in drawSelection(),
|
|
|
|
|
// 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();
|
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (row_type i = 0; i < tabular.rowCount(); ++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);
|
|
|
|
|
for (col_type j = 0; j < tabular.columnCount(); ++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
|
|
|
|
|
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);
|
2006-10-30 10:09:59 +00:00
|
|
|
|
drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
|
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);
|
2005-09-07 10:37:05 +00:00
|
|
|
|
drawCellLines(pi.pain, nx, y, i, idx, pi.erased_);
|
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;
|
2000-11-19 16:07:18 +00:00
|
|
|
|
}
|
2003-05-26 11:33:37 +00:00
|
|
|
|
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (i + 1 < tabular.rowCount())
|
|
|
|
|
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();
|
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);
|
2006-06-20 10:44:49 +00:00
|
|
|
|
pi.pain.fillRectangle(x, yy, w, h, backgroundColor());
|
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
|
|
|
|
|
2005-01-06 15:40:49 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (tablemode(cur)) {
|
2004-12-03 13:57:50 +00:00
|
|
|
|
row_type rs, re;
|
|
|
|
|
col_type cs, ce;
|
2004-11-30 01:59:49 +00:00
|
|
|
|
getSelection(cur, rs, re, cs, ce);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
y -= tabular.rowAscent(0);
|
|
|
|
|
for (row_type j = 0; j < tabular.rowCount(); ++j) {
|
|
|
|
|
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);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
for (col_type i = 0; i < tabular.columnCount(); ++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);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
if (i >= cs && i <= ce && j >= rs && j <= re)
|
2005-03-21 10:17:21 +00:00
|
|
|
|
pi.pain.fillRectangle(xx, y, w, h,
|
2007-10-25 12:41:02 +00:00
|
|
|
|
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,
|
2005-09-07 10:37:05 +00:00
|
|
|
|
row_type row, idx_type cell, bool erased) 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;
|
2007-10-25 12:41:02 +00:00
|
|
|
|
ColorCode col = Color_tabularline;
|
|
|
|
|
ColorCode onoffcol = Color_tabularonoffline;
|
2005-09-07 10:37:05 +00:00
|
|
|
|
|
|
|
|
|
if (erased) {
|
2007-10-25 12:41:02 +00:00
|
|
|
|
col = Color_deletedtext;
|
|
|
|
|
onoffcol = Color_deletedtext;
|
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-27 20:43:16 +00:00
|
|
|
|
docstring InsetTabular::editMessage() const
|
2000-04-19 14:42:19 +00:00
|
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
|
return _("Opened table");
|
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();
|
2004-10-23 09:46:33 +00:00
|
|
|
|
cur.selection() = 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))
|
2007-09-04 10:52:08 +00:00
|
|
|
|
cur.idx() = tabular.getFirstCellInRow(tabular.rowCount() - 1);
|
2003-11-04 12:36:59 +00:00
|
|
|
|
else
|
2007-09-04 10:52:08 +00:00
|
|
|
|
cur.idx() = tabular.cellCount() - 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-02-28 01:42:02 +00:00
|
|
|
|
Counters & cnts = buffer().params().documentClass().counters();
|
2007-08-12 21:43:58 +00:00
|
|
|
|
string const saveflt = cnts.current_float();
|
|
|
|
|
if (tabular.isLongTabular())
|
|
|
|
|
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-02-27 20:43:16 +00:00
|
|
|
|
lyx::updateLabels(buffer(), it2);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
//reset afterwards
|
|
|
|
|
if (tabular.isLongTabular())
|
|
|
|
|
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();
|
|
|
|
|
cur.selection() = true;
|
|
|
|
|
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();
|
|
|
|
|
cur.idx() = tabular.cellIndex(tabular.rowCount() - 1, c);
|
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
cur.selection() = true;
|
|
|
|
|
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
|
|
|
|
|
&& tablemode(bvcur))
|
|
|
|
|
;
|
|
|
|
|
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);
|
2004-08-14 21:23:16 +00:00
|
|
|
|
bvcur.setCursor(cur);
|
2004-08-14 22:38:45 +00:00
|
|
|
|
bvcur.selection() = 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);
|
|
|
|
|
cur.idx() = tabular.cellIndex(tabular.rowCount() - 1, c);
|
|
|
|
|
bvcur.setCursor(cur);
|
|
|
|
|
bvcur.selection() = true;
|
|
|
|
|
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);
|
|
|
|
|
bvcur.selection() = true;
|
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);
|
|
|
|
|
cur.selection() = 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);
|
2004-02-13 16:22:53 +00:00
|
|
|
|
cur.selection() = false;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
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:
|
2004-11-23 23:04:52 +00:00
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2005-10-21 08:16:12 +00:00
|
|
|
|
if (!cur.result().dispatched()) {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
moveNextCell(cur);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
if (sl == cur.top())
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
2005-10-21 08:16:12 +00:00
|
|
|
|
else
|
|
|
|
|
cur.dispatched();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
}
|
2004-02-13 16:22:53 +00:00
|
|
|
|
break;
|
2002-08-19 10:11:13 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHAR_BACKWARD_SELECT:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_CHAR_BACKWARD:
|
2004-11-23 23:04:52 +00:00
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2005-10-21 08:16:12 +00:00
|
|
|
|
if (!cur.result().dispatched()) {
|
2007-10-22 22:18:52 +00:00
|
|
|
|
movePrevCell(cur);
|
2006-04-05 23:56:29 +00:00
|
|
|
|
if (sl == cur.top())
|
2007-10-22 22:18:52 +00:00
|
|
|
|
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
2005-10-21 08:16:12 +00:00
|
|
|
|
else
|
|
|
|
|
cur.dispatched();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
}
|
2004-02-13 16:22:53 +00:00
|
|
|
|
break;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2007-10-22 22:18:52 +00:00
|
|
|
|
case LFUN_CHAR_RIGHT_SELECT:
|
|
|
|
|
case LFUN_CHAR_RIGHT:
|
|
|
|
|
//FIXME: for visual cursor, really move right
|
|
|
|
|
if (isRightToLeft(cur))
|
|
|
|
|
lyx::dispatch(FuncRequest(
|
|
|
|
|
cmd.action == LFUN_CHAR_RIGHT_SELECT ?
|
|
|
|
|
LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
|
|
|
|
|
else
|
|
|
|
|
lyx::dispatch(FuncRequest(
|
|
|
|
|
cmd.action == LFUN_CHAR_RIGHT_SELECT ?
|
|
|
|
|
LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_CHAR_LEFT_SELECT:
|
|
|
|
|
case LFUN_CHAR_LEFT:
|
|
|
|
|
//FIXME: for visual cursor, really move left
|
|
|
|
|
if (isRightToLeft(cur))
|
|
|
|
|
lyx::dispatch(FuncRequest(
|
|
|
|
|
cmd.action == LFUN_CHAR_LEFT_SELECT ?
|
|
|
|
|
LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD));
|
|
|
|
|
else
|
|
|
|
|
lyx::dispatch(FuncRequest(
|
|
|
|
|
cmd.action == LFUN_CHAR_LEFT_SELECT ?
|
|
|
|
|
LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD));
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_DOWN_SELECT:
|
2004-02-13 16:22:53 +00:00
|
|
|
|
case LFUN_DOWN:
|
2004-11-23 23:04:52 +00:00
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-03-27 12:40:39 +00:00
|
|
|
|
cur.dispatched(); // override the cell's decision
|
2004-03-01 17:12:09 +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.
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (tabular.cellRow(cur.idx()) != tabular.rowCount() - 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
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
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:
|
2004-11-23 23:04:52 +00:00
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-03-27 12:40:39 +00:00
|
|
|
|
cur.dispatched(); // override the cell's decision
|
2004-03-01 17:12:09 +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.
|
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
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
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:
|
|
|
|
|
case LFUN_FILE_INSERT_PLAINTEXT: {
|
2006-12-04 14:45:17 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-12-02 11:55:25 +00:00
|
|
|
|
docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
|
2007-12-02 20:05:17 +00:00
|
|
|
|
FileName(to_utf8(cmd.argument())));
|
2007-12-02 15:19:39 +00:00
|
|
|
|
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
|
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
|
|
|
|
case LFUN_CUT:
|
2005-03-17 15:57:41 +00:00
|
|
|
|
if (tablemode(cur)) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
2004-01-08 18:30:14 +00:00
|
|
|
|
}
|
2005-03-17 15:57:41 +00:00
|
|
|
|
else
|
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
2004-02-13 16:22:53 +00:00
|
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2006-05-08 18:09:19 +00:00
|
|
|
|
case LFUN_CHAR_DELETE_BACKWARD:
|
|
|
|
|
case LFUN_CHAR_DELETE_FORWARD:
|
2005-09-15 10:40:12 +00:00
|
|
|
|
if (tablemode(cur)) {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndoInset(DELETE_UNDO);
|
2004-02-13 16:22:53 +00:00
|
|
|
|
cutSelection(cur);
|
2005-09-15 10:40:12 +00:00
|
|
|
|
}
|
2004-02-13 16:22:53 +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;
|
2005-03-17 15:57:41 +00:00
|
|
|
|
if (tablemode(cur)) {
|
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:
|
2007-12-28 15:56:05 +00:00
|
|
|
|
if (tabularStackDirty() && theClipboard().isInternal() ||
|
|
|
|
|
!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
|
|
|
|
break;
|
|
|
|
|
}
|
2004-11-23 23:04:52 +00:00
|
|
|
|
cell(cur.idx())->dispatch(cur, cmd);
|
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:
|
|
|
|
|
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:
|
|
|
|
|
case LFUN_FONT_FREE_APPLY:
|
|
|
|
|
case LFUN_FONT_FREE_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:
|
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:
|
2005-03-13 10:36:42 +00:00
|
|
|
|
if (tablemode(cur)) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
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_ALL_LINES:
|
|
|
|
|
case Tabular::UNSET_ALL_LINES:
|
|
|
|
|
case Tabular::SET_TOP_SPACE:
|
|
|
|
|
case Tabular::SET_BOTTOM_SPACE:
|
|
|
|
|
case Tabular::SET_INTERLINE_SPACE:
|
2008-03-20 08:45:40 +00:00
|
|
|
|
case Tabular::SET_BORDER_LINES:
|
2004-03-27 12:40:39 +00:00
|
|
|
|
status.clear();
|
|
|
|
|
return true;
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::MULTICOLUMN:
|
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
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::TOGGLE_LINE_TOP:
|
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-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-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-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:
|
2004-10-23 09:21:38 +00:00
|
|
|
|
status.enabled(!tabular.getPWidth(cur.idx()).zero());
|
|
|
|
|
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:
|
2004-03-27 12:40:39 +00:00
|
|
|
|
status.setOnOff(tabular.isLongTabular());
|
|
|
|
|
break;
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::UNSET_LONGTABULAR:
|
2004-03-27 12:40:39 +00:00
|
|
|
|
status.setOnOff(!tabular.isLongTabular());
|
|
|
|
|
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:
|
2004-03-27 12:40:39 +00:00
|
|
|
|
status.setOnOff(tabular.getRotateTabular());
|
|
|
|
|
break;
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::UNSET_ROTATE_TABULAR:
|
2004-03-27 12:40:39 +00:00
|
|
|
|
status.setOnOff(!tabular.getRotateTabular());
|
|
|
|
|
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;
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::SET_LTFIRSTHEAD:
|
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_LTFIRSTHEAD:
|
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_LTHEAD:
|
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:
|
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:
|
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_LTLASTFOOT:
|
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_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
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::SET_BOOKTABS:
|
2006-07-03 19:13:56 +00:00
|
|
|
|
status.setOnOff(tabular.useBookTabs());
|
|
|
|
|
break;
|
2006-09-09 15:27:44 +00:00
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::UNSET_BOOKTABS:
|
2006-07-03 19:13:56 +00:00
|
|
|
|
status.setOnOff(!tabular.useBookTabs());
|
|
|
|
|
break;
|
2004-03-27 12:40:39 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
status.clear();
|
|
|
|
|
status.enabled(false);
|
|
|
|
|
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:
|
|
|
|
|
status.enabled(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:
|
|
|
|
|
case LFUN_WRAP_INSERT:
|
|
|
|
|
case LFUN_ERT_INSERT: {
|
2005-03-13 10:36:42 +00:00
|
|
|
|
if (tablemode(cur)) {
|
|
|
|
|
status.enabled(false);
|
|
|
|
|
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:
|
2006-05-05 20:23:12 +00:00
|
|
|
|
case LFUN_BREAK_PARAGRAPH:
|
|
|
|
|
case LFUN_BREAK_PARAGRAPH_SKIP: {
|
2005-07-28 09:45:43 +00:00
|
|
|
|
if (tabular.getPWidth(cur.idx()).zero()) {
|
|
|
|
|
status.enabled(false);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2006-03-17 13:11:32 +00:00
|
|
|
|
case LFUN_PASTE:
|
2007-01-04 12:05:24 +00:00
|
|
|
|
if (tabularStackDirty() && theClipboard().isInternal()) {
|
2006-03-17 13:11:32 +00:00
|
|
|
|
status.enabled(true);
|
|
|
|
|
return true;
|
2007-01-04 11:05:22 +00:00
|
|
|
|
} else
|
|
|
|
|
return cell(cur.idx())->getStatus(cur, cmd, status);
|
2006-03-17 13:11:32 +00:00
|
|
|
|
|
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) {
|
2005-04-15 08:13:54 +00:00
|
|
|
|
status.enabled(true);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
cur.selection() = 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);
|
2007-09-02 09:44: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);
|
2007-09-02 09:44: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
|
|
|
|
|
|
|
|
|
if (&cur.inset() != this) {
|
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-03-25 13:32:38 +00:00
|
|
|
|
int const x1 = xo(cur.bv()) + cellXPos(cur.idx()) + offset;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
int const x2 = x1 + tabular.columnWidth(cur.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
|
|
|
|
|
2006-10-22 11:46:36 +00:00
|
|
|
|
cur.updateFlags(Update::Force | Update::FitCursor);
|
2003-12-15 15:33:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetTabular::moveNextCell(Cursor & cur)
|
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());
|
|
|
|
|
if (row == tabular.rowCount() - 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
|
|
|
|
}
|
2004-11-24 21:53:46 +00:00
|
|
|
|
cur.pit() = 0;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
cur.pos() = 0;
|
|
|
|
|
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
|
|
|
|
void InsetTabular::movePrevCell(Cursor & cur)
|
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
|
|
|
|
}
|
2005-03-17 13:23:14 +00:00
|
|
|
|
cur.pit() = cur.lastpit();
|
|
|
|
|
cur.pos() = cur.lastpos();
|
2006-10-20 16:11:30 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: this accesses the position cache before it is initialized
|
|
|
|
|
//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);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (sel_row_start >= tabular.rowCount())
|
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;
|
2004-02-13 16:22:53 +00:00
|
|
|
|
cur.selection() = 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);
|
2007-09-04 10:52:08 +00:00
|
|
|
|
if (sel_col_start >= tabular.columnCount())
|
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;
|
2004-02-13 16:22:53 +00:00
|
|
|
|
cur.selection() = 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: {
|
2001-04-04 09:42:56 +00:00
|
|
|
|
if (sel_row_start != sel_row_end) {
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: Need I say it ? This is horrible.
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::error(_("Error setting multicolumn"),
|
|
|
|
|
_("You cannot set multicolumn vertically."));
|
2001-04-04 09:42:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
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;
|
2004-02-13 16:22:53 +00:00
|
|
|
|
cur.selection() = 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:
|
2003-06-13 07:37:48 +00:00
|
|
|
|
tabular.setLongTabular(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:
|
2003-06-13 07:37:48 +00:00
|
|
|
|
tabular.setLongTabular(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:
|
2003-06-13 07:37:48 +00:00
|
|
|
|
tabular.setRotateTabular(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:
|
2003-06-13 07:37:48 +00:00
|
|
|
|
tabular.setRotateTabular(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:
|
|
|
|
|
tabular.setRotateTabular(!tabular.getRotateTabular());
|
|
|
|
|
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
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::SET_BOOKTABS:
|
2006-07-03 19:13:56 +00:00
|
|
|
|
tabular.setBookTabs(true);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-04-26 12:54:21 +00:00
|
|
|
|
case Tabular::UNSET_BOOKTABS:
|
2006-07-03 19:13:56 +00:00
|
|
|
|
tabular.setBookTabs(false);
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
while (paste_tabular->rowCount() > 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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
while (paste_tabular->columnCount() > columns)
|
2003-06-12 11:52:44 +00:00
|
|
|
|
paste_tabular->deleteColumn(columns);
|
2003-07-31 10:48:50 +00:00
|
|
|
|
|
2008-03-21 17:45:14 +00:00
|
|
|
|
// We clear all the InsetTableCell pointers, since they
|
|
|
|
|
// might now become invalid and there is no point in having
|
|
|
|
|
// them point to temporary things in paste_tabular.
|
|
|
|
|
for (row_type i = 0; i < paste_tabular->rowCount(); ++i)
|
|
|
|
|
for (col_type j = 0; j < paste_tabular->columnCount(); ++j) {
|
2008-03-25 13:32:38 +00:00
|
|
|
|
paste_tabular->cellInset(i,j)->setCellData(0);
|
|
|
|
|
paste_tabular->cellInset(i,j)->setTabular(0);
|
2008-03-21 17:45:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
col_type const actcol = tabular.cellColumn(cur.idx());
|
|
|
|
|
row_type const actrow = tabular.cellRow(cur.idx());
|
2004-12-03 13:57:50 +00:00
|
|
|
|
for (row_type r1 = 0, r2 = actrow;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
r1 < paste_tabular->rowCount() && r2 < tabular.rowCount();
|
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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
c1 < paste_tabular->columnCount() && c2 < tabular.columnCount();
|
2001-04-04 22:08:13 +00:00
|
|
|
|
++c1, ++c2) {
|
2003-07-21 11:01:29 +00:00
|
|
|
|
if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
|
|
|
|
|
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)));
|
2008-03-21 17:45:14 +00:00
|
|
|
|
// note that setCellInset will call InsetTableCell::setCellData()
|
|
|
|
|
// and InsetTableCell::setTabular()
|
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)
|
|
|
|
|
inset->setChange(Change(cur.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));
|
2006-10-06 18:53:35 +00:00
|
|
|
|
if (cur.buffer().params().trackChanges)
|
|
|
|
|
// 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
|
|
|
|
{
|
2005-02-08 13:18:05 +00:00
|
|
|
|
BOOST_ASSERT(cur.depth() > 1);
|
|
|
|
|
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();
|
2007-08-21 13:03:55 +00:00
|
|
|
|
return parentpar.getFontSettings(cur.bv().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
|
|
|
|
|
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
|
|
|
|
|
2007-01-23 21:53:16 +00:00
|
|
|
|
void InsetTabular::acceptChanges(BufferParams const & bparams)
|
2006-10-24 06:11:45 +00:00
|
|
|
|
{
|
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2007-01-23 21:53:16 +00:00
|
|
|
|
cell(idx)->acceptChanges(bparams);
|
2006-10-24 06:11:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-23 21:53:16 +00:00
|
|
|
|
void InsetTabular::rejectChanges(BufferParams const & bparams)
|
2006-10-24 21:38:47 +00:00
|
|
|
|
{
|
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
2007-01-23 21:53:16 +00:00
|
|
|
|
cell(idx)->rejectChanges(bparams);
|
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-03-19 16:21:33 +00:00
|
|
|
|
bool InsetTabular::forceEmptyLayout(idx_type cell) const
|
|
|
|
|
{
|
|
|
|
|
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) {
|
2008-02-27 20:43:16 +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;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
idx_type const cells = loctab->cellCount();
|
2002-03-04 15:42:54 +00:00
|
|
|
|
p = 0;
|
|
|
|
|
cols = ocol;
|
2007-09-04 10:52:08 +00:00
|
|
|
|
rows = loctab->rowCount();
|
|
|
|
|
col_type const columns = loctab->columnCount();
|
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);
|
2007-09-02 21:48:49 +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);
|
2007-09-02 21:48:49 +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-02-27 23:03:26 +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
|
|
|
|
{
|
2007-09-04 10:52:08 +00:00
|
|
|
|
row_type const rows = tabular.rowCount();
|
|
|
|
|
col_type const columns = tabular.columnCount();
|
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
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetTabular::tablemode(Cursor & cur) const
|
2004-01-08 18:30:14 +00:00
|
|
|
|
{
|
2004-04-07 08:07:26 +00:00
|
|
|
|
return cur.selection() && cur.selBegin().idx() != cur.selEnd().idx();
|
2004-01-08 18:30:14 +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
|