/* This file is part of
- * ======================================================
- *
+ * ======================================================
+ *
* LyX, The Document Processor
- *
+ *
* Copyright 2000-2002 The LyX Team.
*
* @author: Jürgen Vigna
*
- * ======================================================
+ * ======================================================
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
// temporary until verified (08/08/2001 Jug)
#define SPECIAL_COLUM_HANDLING 1
#include "layout.h"
#include "buffer.h"
#include "BufferView.h"
-#include "Painter.h"
+#include "frontends/Painter.h"
#include "LaTeXFeatures.h"
#include "insets/insettabular.h"
#include "insets/insettext.h"
#include "frontends/Alert.h"
#include "gettext.h"
#include "tabular_funcs.h"
-#include "lyxtextclasslist.h"
+#include "lyxlex.h"
#include <algorithm>
#include <cstdlib>
+using std::abs;
using std::ostream;
using std::istream;
using std::getline;
}
-LyXTabular::rowstruct::rowstruct()
+LyXTabular::rowstruct::rowstruct()
{
top_line = true;
bottom_line = false;
}
-LyXTabular::columnstruct::columnstruct()
+LyXTabular::columnstruct::columnstruct()
{
left_line = true;
right_line = false;
}
-LyXTabular::lttype::lttype()
+LyXTabular::ltType::ltType()
{
topDL = false;
bottomDL = false;
LyXTabular::LyXTabular(BufferParams const & bp,
InsetTabular * inset, LyXTabular const & lt,
- bool same_id)
+ bool same_id)
{
owner_ = inset;
cur_cell = -1;
LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
{
#if 0
-#warning This while method should look like this: (Lgb)
+#warning This whole method should look like this: (Lgb)
LyXTabular tmp(lt);
tmp.swap(*this);
}
-/* activates all lines and sets all widths to 0 */
+/* activates all lines and sets all widths to 0 */
void LyXTabular::Init(BufferParams const & bp,
- int rows_arg, int columns_arg, LyXTabular const * lt)
+ int rows_arg, int columns_arg, LyXTabular const * lt)
{
rows_ = rows_arg;
columns_ = columns_arg;
calculate_width_of_column(i);
}
column_info.back().right_line = true;
-
+
calculate_width_of_tabular();
rowofcell = vector<int>();
void LyXTabular::AppendRow(BufferParams const & bp, int cell)
{
++rows_;
-
+
int row = row_of_cell(cell);
row_vector::iterator rit = row_info.begin() + row;
cell_info = c_info;
++row;
for (int j = 0; j < columns_; ++j) {
- cell_info[row][j].inset.clear();
+ cell_info[row][j].inset.clear(false);
+ if (bp.tracking_changes)
+ cell_info[row][j].inset.markNew(true);
}
#endif
Reinit();
void LyXTabular::DeleteRow(int row)
{
if (rows_ == 1) return; // Not allowed to delete last row
-
+
row_info.erase(row_info.begin() + row); //&row_info[row]);
cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
--rows_;
void LyXTabular::AppendColumn(BufferParams const & bp, int cell)
{
++columns_;
-
+
cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
cellstruct(bp)));
int const column = column_of_cell(cell);
cell_info = c_info;
//++column;
for (int i = 0; i < rows_; ++i) {
- //cell_info[i][column].inset.clear();
- cell_info[i][column + 1].inset.clear();
+ cell_info[i][column + 1].inset.clear(false);
+ if (bp.tracking_changes)
+ cell_info[i][column + 1].inset.markNew(true);
}
Reinit();
}
//if (!(columns_ - 1))
//return;
if (columns_ == 1) return; // Not allowed to delete last column
-
+
column_info.erase(column_info.begin() + column);
for (int i = 0; i < rows_; ++i) {
cell_info[i].erase(cell_info[i].begin() + column);
}
}
}
-
+
for (int i = 0; i < columns_; ++i) {
calculate_width_of_column(i);
}
}
-/* returns 1 if there is a topline, returns 0 if not */
+/* returns 1 if there is a topline, returns 0 if not */
bool LyXTabular::TopLine(int cell, bool onlycolumn) const
{
int const row = row_of_cell(cell);
-
+
if (!onlycolumn && IsMultiColumn(cell))
return cellinfo_of_cell(cell)->top_line;
return row_info[row].top_line;
#ifdef SPECIAL_COLUM_HANDLING
if (cellinfo_of_cell(cell)->align_special.empty())
return cellinfo_of_cell(cell)->left_line;
- return prefixIs(frontStrip(cellinfo_of_cell(cell)->align_special), "|");
+ return prefixIs(ltrim(cellinfo_of_cell(cell)->align_special), "|");
#else
return cellinfo_of_cell(cell)->left_line;
#endif
#ifdef SPECIAL_COLUM_HANDLING
if (column_info[column_of_cell(cell)].align_special.empty())
return column_info[column_of_cell(cell)].left_line;
- return prefixIs(frontStrip(column_info[column_of_cell(cell)].align_special), "|");
+ return prefixIs(ltrim(column_info[column_of_cell(cell)].align_special), "|");
#else
return column_info[column_of_cell(cell)].left_line;
#endif
#ifdef SPECIAL_COLUM_HANDLING
if (cellinfo_of_cell(cell)->align_special.empty())
return cellinfo_of_cell(cell)->right_line;
- return suffixIs(strip(cellinfo_of_cell(cell)->align_special), "|");
+ return suffixIs(rtrim(cellinfo_of_cell(cell)->align_special), "|");
#else
return cellinfo_of_cell(cell)->right_line;
#endif
#ifdef SPECIAL_COLUM_HANDLING
if (column_info[column_of_cell(cell)].align_special.empty())
return column_info[right_column_of_cell(cell)].right_line;
- return suffixIs(strip(column_info[column_of_cell(cell)].align_special), "|");
+ return suffixIs(rtrim(column_info[column_of_cell(cell)].align_special), "|");
#else
return column_info[right_column_of_cell(cell)].right_line;
#endif
}
-bool LyXTabular::TopAlreadyDrawed(int cell) const
+bool LyXTabular::topAlreadyDrawn(int cell) const
{
int row = row_of_cell(cell);
if ((row > 0) && !GetAdditionalHeight(row)) {
}
-bool LyXTabular::LeftAlreadyDrawed(int cell) const
+bool LyXTabular::leftAlreadyDrawn(int cell) const
{
int column = column_of_cell(cell);
if (column > 0) {
}
-// returns the maximum over all rows
+// returns the maximum over all rows
int LyXTabular::GetWidthOfColumn(int cell) const
{
int const column1 = column_of_cell(cell);
}
-/* returns 1 if a complete update is necessary, otherwise 0 */
+/* returns 1 if a complete update is necessary, otherwise 0 */
bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
{
if (!IsMultiColumn(cell))
return false;
-
+
int const row = row_of_cell(cell);
int const column1 = column_of_cell(cell);
int const column2 = right_column_of_cell(cell);
int const old_val = cell_info[row][column2].width_of_cell;
-
+
// first set columns to 0 so we can calculate the right width
for (int i = column1; i <= column2; ++i) {
cell_info[row][i].width_of_cell = 0;
{
int const cellno = cell_info[row][column].cellno;
SetWidthOfMulticolCell(cellno,
- GetWidthOfCell(cellno)-(2 * WIDTH_OF_LINE));
+ GetWidthOfCell(cellno)-(2 * WIDTH_OF_LINE));
}
}
}
-/* returns 1 if a complete update is necessary, otherwise 0 */
+/* returns 1 if a complete update is necessary, otherwise 0 */
bool LyXTabular::SetWidthOfCell(int cell, int new_width)
{
int const row = row_of_cell(cell);
int const j = column_of_cell(cell);
column_info[j].p_width = width;
- if (flag) // do this only if there is a width
- SetAlignment(cell, LYX_ALIGN_LEFT);
+ // This should not ne necessary anymore
+ // if (flag) // do this only if there is a width
+ // SetAlignment(cell, LYX_ALIGN_LEFT);
for (int i = 0; i < rows_; ++i) {
int c = GetCellNumber(i, j);
flag = !GetPWidth(c).zero(); // because of multicolumns!
bool LyXTabular::SetAlignSpecial(int cell, string const & special,
- LyXTabular::Feature what)
+ LyXTabular::Feature what)
{
if (what == SET_SPECIAL_MULTI)
cellinfo_of_cell(cell)->align_special = special;
int LyXTabular::GetBeginningOfTextInCell(int cell) const
{
int x = 0;
-
+
switch (GetAlignment(cell)) {
case LYX_ALIGN_CENTER:
x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
// + GetAdditionalWidth(cell);
break;
- default: /* LYX_ALIGN_LEFT: nothing :-) */
+ default: /* LYX_ALIGN_LEFT: nothing :-) */
break;
}
-
+
// the LaTeX Way :-(
x += WIDTH_OF_LINE;
return x;
{
int const old_column_width = column_info[column].width_of_column;
int maximum = 0;
-
+
for (int i = 0; i < rows_; ++i) {
maximum = max(cell_info[i][column].width_of_cell, maximum);
}
Init(buf->params, rows_arg, columns_arg);
l_getline(is, line);
if (!prefixIs(line, "<features")) {
- lyxerr << "Wrong tabular format (expected <features ...> got" <<
- line << ")" << endl;
+ lyxerr << "Wrong tabular format (expected <features ...> got"
+ << line << ')' << endl;
return;
}
getTokenValue(line, "rotate", rotate);
for (int j = 0; j < columns_; ++j) {
l_getline(is,line);
if (!prefixIs(line,"<column")) {
- lyxerr << "Wrong tabular format (expected <column ...> got" <<
- line << ")" << endl;
+ lyxerr << "Wrong tabular format (expected <column ...> got"
+ << line << ')' << endl;
return;
}
getTokenValue(line, "alignment", column_info[j].alignment);
for (int i = 0; i < rows_; ++i) {
l_getline(is, line);
if (!prefixIs(line, "<row")) {
- lyxerr << "Wrong tabular format (expected <row ...> got" <<
- line << ")" << endl;
+ lyxerr << "Wrong tabular format (expected <row ...> got"
+ << line << ')' << endl;
return;
}
getTokenValue(line, "topline", row_info[i].top_line);
for (int j = 0; j < columns_; ++j) {
l_getline(is, line);
if (!prefixIs(line, "<cell")) {
- lyxerr << "Wrong tabular format (expected <cell ...> got" <<
- line << ")" << endl;
+ lyxerr << "Wrong tabular format (expected <cell ...> got"
+ << line << ')' << endl;
return;
}
getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
l_getline(is, line);
}
if (!prefixIs(line, "</cell>")) {
- lyxerr << "Wrong tabular format (expected </cell> got" <<
- line << ")" << endl;
+ 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;
+ lyxerr << "Wrong tabular format (expected </row> got"
+ << line << ')' << endl;
return;
}
}
void LyXTabular::OldFormatRead(BufferParams const & bp,
- LyXLex & lex, string const & fl)
+ LyXLex & lex, string const & fl)
{
int version;
int i;
int e = 0;
int f = 0;
int g = 0;
-
+
istream & is = lex.getStream();
string s(fl);
if (s.length() > 8)
#else
// ignore is buggy but we will use it later (Lgb)
is.ignore(); // skip '"'
-#endif
+#endif
getline(is, s1, '"');
#if 1
is >> ch; // skip '"'
Paragraph * par = new Paragraph;
Paragraph * return_par = 0;
- par->layout(textclasslist[bp.textclass].defaultLayoutName());
+ par->layout(bp.getLyXTextClass().defaultLayout());
+
string tmptok;
int pos = 0;
Paragraph::depth_type depth = 0;
if (token.empty())
continue;
if (token == "\\layout"
- || token == "\\end_float"
- || token == "\\end_deeper") {
+ || token == "\\end_float" // this should not exist anymore
+ || token == "\\end_inset" // as it is substituted by this
+ || token == "\\end_deeper")
+ {
lex.pushToken(token);
-#ifndef NO_COMPABILITY
- // Here we need to insert the inset_ert_contents into the last
- // cell of the tabular.
- owner_->bufferOwner()->insertErtContents(par, pos);
-#endif
break;
}
if (owner_->bufferOwner()->parseSingleLyXformat2Token(lex, par,
}
-void LyXTabular::SetMultiColumn(int cell, int number)
+void LyXTabular::SetMultiColumn(Buffer const * buffer, int cell, int number)
{
cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
+ cellinfo_of_cell(cell)->right_line = column_info[column_of_cell(cell+number-1)].right_line;
+#if 1
+ for (int i = 1; i < number; ++i) {
+ cellinfo_of_cell(cell+i)->multicolumn = CELL_PART_OF_MULTICOLUMN;
+ cellinfo_of_cell(cell)->inset.appendParagraphs(buffer->params,
+ cellinfo_of_cell(cell+i)->inset.paragraph());
+ cellinfo_of_cell(cell+i)->inset.clear(false);
+ }
+#else
for (number--; number > 0; --number) {
cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
}
+#endif
set_row_column_number_info();
}
{
int const row = row_of_cell(cell);
int column = column_of_cell(cell);
-
+
int result = 0;
-
+
if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
cell_info[row][column].multicolumn = CELL_NORMAL;
++column;
os << cellinfo_of_cell(cell)->align_special << "}{";
} else {
if (LeftLine(cell) &&
- (IsFirstCellInRow(cell) ||
+ (IsFirstCellInRow(cell) ||
(!IsMultiColumn(cell-1) && !LeftLine(cell, true) &&
!RightLine(cell-1, true))))
{
if (!GetPWidth(cell).zero()) {
switch (GetVAlignment(cell)) {
case LYX_VALIGN_TOP:
- os << "p";
+ os << 'p';
break;
case LYX_VALIGN_CENTER:
- os << "m";
+ os << 'm';
break;
case LYX_VALIGN_BOTTOM:
- os << "b";
+ os << 'b';
break;
}
- os << "{" << GetPWidth(cell).asLatexString() << '}';
+ os << '{'
+ << GetPWidth(cell).asLatexString()
+ << '}';
} else {
switch (GetAlignment(cell)) {
case LYX_ALIGN_LEFT:
os << "\\parbox[";
switch (GetVAlignment(cell)) {
case LYX_VALIGN_TOP:
- os << "t";
+ os << 't';
break;
case LYX_VALIGN_CENTER:
- os << "c";
+ os << 'c';
break;
case LYX_VALIGN_BOTTOM:
- os << "b";
+ os << 'b';
break;
}
os << "]{" << GetPWidth(cell).asLatexString() << "}{";
os << "\\begin{minipage}[";
switch (GetVAlignment(cell)) {
case LYX_VALIGN_TOP:
- os << "t";
+ os << 't';
break;
case LYX_VALIGN_CENTER:
- os << "m";
+ os << 'm';
break;
case LYX_VALIGN_BOTTOM:
- os << "b";
+ os << 'b';
break;
}
os << "]{" << GetPWidth(cell).asLatexString() << "}\n";
// usual cells
if (GetUsebox(cell) == BOX_PARBOX)
- os << "}";
+ os << '}';
else if (GetUsebox(cell) == BOX_MINIPAGE) {
os << "%\n\\end{minipage}";
ret += 2;
int LyXTabular::TeXLongtableHeaderFooter(ostream & os, Buffer const * buf,
- bool fragile, bool fp) const
+ bool fragile, bool fp) const
{
if (!is_long_tabular)
return 0;
int LyXTabular::TeXRow(ostream & os, int const i, Buffer const * buf,
- bool fragile, bool fp) const
+ bool fragile, bool fp) const
{
int ret = 0;
int cell = GetCellNumber(i, 0);
InsetText * inset = GetCellInset(cell);
bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) &&
- inset->paragraph()->size() > 0 && GetPWidth(cell).zero();
+ !inset->paragraph()->empty() && GetPWidth(cell).zero();
if (rtl)
os << "\\R{";
ret += inset->latex(buf, os, fragile, fp);
if (rtl)
- os << "}";
+ os << '}';
ret += TeXCellPostamble(os, cell);
if (!IsLastCellInRow(cell)) { // not last cell in row
}
++cell;
}
- os << "\\\\\n";
+ os << "\\tabularnewline\n";
++ret;
ret += TeXBottomHLine(os, i);
return ret;
for (int i = 0; i < columns_; ++i) {
if (!column_info[i].align_special.empty()) {
os << column_info[i].align_special;
- } else {
+ } else {
if (column_info[i].left_line)
os << '|';
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;
+ }
+
switch (column_info[i].valignment) {
case LYX_VALIGN_TOP:
- os << "p";
+ os << 'p';
break;
case LYX_VALIGN_CENTER:
- os << "m";
+ os << 'm';
break;
case LYX_VALIGN_BOTTOM:
- os << "b";
+ os << 'b';
break;
}
- os << "{"
+ os << '{'
<< column_info[i].p_width.asLatexString()
<< '}';
} else {
os << 'l';
break;
case LYX_ALIGN_RIGHT:
- os << 'r';
- break;
+ os << 'r';
+ break;
default:
os << 'c';
break;
++ret;
ret += TeXLongtableHeaderFooter(os, buf, fragile, fp);
-
+
//+---------------------------------------------------------------------
//+ the single row and columns (cells) +
//+---------------------------------------------------------------------
{
int ret = 0;
int cell = GetFirstCellInRow(row);
-
+
os << "<row>\n";
for (int j = 0; j < columns_; ++j) {
if (IsPartOfMultiColumn(row, j))
case LYX_VALIGN_CENTER:
os << "middle";
}
- os << "\"";
+ os << '"';
if (IsMultiColumn(cell)) {
os << " namest=\"col" << j << "\" ";
- os << "nameend=\"col" << j + cells_in_multicolumn(cell) - 1<< "\"";
+ os << "nameend=\"col" << j + cells_in_multicolumn(cell) - 1<< '"';
}
- os << ">";
- ret += GetCellInset(cell)->docbook(buf, os);
+ os << '>';
+ ret += GetCellInset(cell)->docbook(buf, os, true);
os << "</entry>\n";
++cell;
}
os << "</row>\n";
return ret;
-}
+}
-int LyXTabular::docBook(Buffer const * buf, ostream & os) const
+int LyXTabular::docbook(Buffer const * buf, ostream & os,
+ bool /*mixcont*/) const
{
int ret = 0;
os << "<tgroup cols=\"" << columns_
<< "\" colsep=\"1\" rowsep=\"1\">\n";
-
+
for (int i = 0; i < columns_; ++i) {
os << "<colspec colname=\"col" << i << "\" align=\"";
switch (column_info[i].alignment) {
ret += docbookRow(buf, os, i);
}
}
- os << "<thead>\n";
+ os << "</thead>\n";
++ret;
}
// output footer info
// ASCII export function and helpers
//--
int LyXTabular::asciiTopHLine(ostream & os, int row,
- vector<unsigned int> const & clen) const
+ vector<unsigned int> const & clen) const
{
int const fcell = GetFirstCellInRow(row);
int const n = NumberOfCellsInRow(fcell) + fcell;
int LyXTabular::asciiBottomHLine(ostream & os, int row,
- vector<unsigned int> const & clen) const
+ vector<unsigned int> const & clen) const
{
int const fcell = GetFirstCellInRow(row);
int const n = NumberOfCellsInRow(fcell) + fcell;
int LyXTabular::asciiPrintCell(Buffer const * buf, ostream & os,
- int cell, int row, int column,
- vector<unsigned int> const & clen,
- bool onlydata) const
+ int cell, int row, int column,
+ vector<unsigned int> const & clen,
+ bool onlydata) const
{
ostringstream sstr;
int ret = GetCellInset(cell)->ascii(buf, sstr, 0);
os << sstr.str();
return ret;
}
-
+
if (LeftLine(cell))
os << "| ";
else
break;
}
- for (unsigned int i = 0; i < len1; ++i)
- os << " ";
- os << sstr.str();
- for (unsigned int i = 0; i < len2; ++i)
- os << " ";
+ os << string(len1, ' ')
+ << sstr.str()
+ << string(len2, ' ');
if (RightLine(cell))
os << " |";
else
<< "this is not a cell of the tabular!" << endl;
return -1;
}
-
+
const int save_cur_cell = cur_cell;
int cell = cur_cell;
if (GetCellInset(cell) != inset) {
cell = -1;
}
}
-
+
if (cell == -1) {
for (cell = GetNumberOfCells(); cell >= 0; --cell) {
if (GetCellInset(cell) == inset)
lyxerr[Debug::INSETTEXT]
<< "LyXTabular::GetCellFromInset: "
<< "cell=" << cell
- << ", cur_cell=" << save_cur_cell
+ << ", cur_cell=" << save_cur_cell
<< ", maybe_cell=" << maybe_cell
<< endl;
// We should have found a cell at this point
<< "Cell not found!" << endl;
}
}
-
+
return cell;
}
void LyXTabular::Validate(LaTeXFeatures & features) const
{
+ features.require("NeedTabularnewline");
if (IsLongTabular())
features.require("longtable");
if (NeedRotating())
features.require("rotating");
for (int cell = 0; cell < numberofcells; ++cell) {
- if (GetVAlignment(cell) != LYX_VALIGN_TOP)
+ if ( (GetVAlignment(cell) != LYX_VALIGN_TOP) ||
+ ( !(GetPWidth(cell).zero())&&!(IsMultiColumn(cell)) )
+ )
features.require("array");
GetCellInset(cell)->validate(features);
}
return label_list;
}
-
+
LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
{
- Paragraph * par = GetCellInset(cell)->paragraph();
+ ParagraphList const & parlist = GetCellInset(cell)->paragraphs;
+ ParagraphList::iterator cit = parlist.begin();
+ ParagraphList::iterator end = parlist.end();
- for (; par; par = par->next()) {
- for (int i = 0; i < par->size(); ++i) {
- if (par->getChar(i) == Paragraph::META_NEWLINE)
+ for (; cit != end; ++cit) {
+ for (int i = 0; i < cit->size(); ++i) {
+ if (cit->getChar(i) == Paragraph::META_NEWLINE)
return BOX_PARBOX;
}
}