// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 2000-2001 The LyX Team.
+/**
+ * \file tabular.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * @author: Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ * \author Matthias Ettrich
+ * \author André Pönitz
+ * \author Jürgen Vigna
*
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
+
#ifndef TABULAR_H
#define TABULAR_H
-#ifdef __GNUG__
-#pragma interface
-#endif
+#include "lyxlength.h"
+#include "insets/insettext.h"
+
+#include <boost/shared_ptr.hpp>
#include <iosfwd>
#include <vector>
-#include "lyxlex.h"
-#include "layout.h"
-#include "LString.h"
-#include "insets/insettext.h"
-
class InsetTabular;
-class LaTeXFeatures;
-class Buffer;
+class OutputParams;
-/* The features the text class offers for tables */
+/* The features the text class offers for tables */
///
class LyXTabular {
///
ALIGN_CENTER,
///
+ ALIGN_BLOCK,
+ ///
VALIGN_TOP,
///
VALIGN_BOTTOM,
///
- VALIGN_CENTER,
+ VALIGN_MIDDLE,
///
M_TOGGLE_LINE_TOP,
///
///
M_VALIGN_BOTTOM,
///
- M_VALIGN_CENTER,
+ M_VALIGN_MIDDLE,
///
MULTICOLUMN,
///
///
LYX_VALIGN_BOTTOM = 1,
///
- LYX_VALIGN_CENTER = 2
+ LYX_VALIGN_MIDDLE = 2
};
enum BoxType {
BOX_MINIPAGE = 2
};
- struct lttype {
+ struct ltType {
// constructor
- lttype();
- // row of the header/footer type end definition
- int row;
+ ltType();
+ // we have this header type (is set in the getLT... functions)
+ bool set;
// double borders on top
bool topDL;
// double borders on bottom
bool bottomDL;
+ // used for FirstHeader & LastFooter and if this is true
+ // all the rows marked as FirstHeader or LastFooter are
+ // ignored in the output and it is set to be empty!
+ bool empty;
};
- ///
- typedef struct lttype ltType;
-
- /* konstruktor */
- ///
- LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
- ///
- LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
- ///
- explicit
- LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
- ///
- LyXTabular & operator=(LyXTabular const &);
- ///
- LyXTabular * clone(InsetTabular *, bool same_id = false);
-
+
+ /// type for row numbers
+ typedef size_t row_type;
+ /// type for column numbers
+ typedef size_t col_type;
+ /// type for cell indices
+ typedef size_t idx_type;
+ /// index indicating an invalid position
+ static const idx_type npos = static_cast<idx_type>(-1);
+
+ /// constructor
+ LyXTabular(BufferParams const &, col_type columns_arg,
+ row_type rows_arg);
+
/// Returns true if there is a topline, returns false if not
- bool TopLine(int cell, bool onlycolumn = false) const;
+ bool topLine(idx_type cell, bool onlycolumn = false) const;
/// Returns true if there is a topline, returns false if not
- bool BottomLine(int cell, bool onlycolumn = false) const;
+ bool bottomLine(idx_type cell, bool onlycolumn = false) const;
/// Returns true if there is a topline, returns false if not
- bool LeftLine(int cell, bool onlycolumn = false) const;
+ bool leftLine(idx_type cell, bool onlycolumn = false) const;
/// Returns true if there is a topline, returns false if not
- bool RightLine(int cell, bool onlycolumn = false) const;
-
+ bool rightLine(idx_type cell, bool onlycolumn = false) const;
+
///
- bool TopAlreadyDrawed(int cell) const;
+ bool topAlreadyDrawn(idx_type cell) const;
///
- bool LeftAlreadyDrawed(int cell) const;
+ bool leftAlreadyDrawn(idx_type cell) const;
///
- bool IsLastRow(int cell) const;
+ bool isLastRow(idx_type cell) const;
///
- int GetAdditionalHeight(int row) const;
+ int getAdditionalHeight(row_type row) const;
///
- int GetAdditionalWidth(int cell) const;
-
+ int getAdditionalWidth(idx_type cell) const;
+
/* returns the maximum over all rows */
///
- int GetWidthOfColumn(int cell) const;
+ int getWidthOfColumn(idx_type cell) const;
///
- int GetWidthOfTabular() const;
+ int getWidthOfTabular() const;
///
- int GetAscentOfRow(int row) const;
+ int getAscentOfRow(row_type row) const;
///
- int GetDescentOfRow(int row) const;
+ int getDescentOfRow(row_type row) const;
///
- int GetHeightOfTabular() const;
- /// Returns true if a complete update is necessary, otherwise false
- bool SetAscentOfRow(int row, int height);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetDescentOfRow(int row, int height);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetWidthOfCell(int cell, int new_width);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetAllLines(int cell, bool line);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetTopLine(int cell, bool line, bool onlycolumn = false);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetBottomLine(int cell, bool line, bool onlycolumn = false);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetLeftLine(int cell, bool line, bool onlycolumn = false);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetRightLine(int cell, bool line, bool onlycolumn = false);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetAlignment(int cell, LyXAlignment align,
- bool onlycolumn = false);
- /// Returns true if a complete update is necessary, otherwise false
- bool SetVAlignment(int cell, VAlignment align,
- bool onlycolumn = false);
+ int getHeightOfTabular() const;
///
- bool SetColumnPWidth(int cell, string const & width);
+ void setAscentOfRow(row_type row, int height);
///
- bool SetMColumnPWidth(int cell, string const & width);
+ void setDescentOfRow(row_type row, int height);
///
- bool SetAlignSpecial(int cell, string const & special, Feature what);
+ void setWidthOfCell(idx_type cell, int new_width);
///
- LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
+ void setAllLines(idx_type cell, bool line);
///
- VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
+ void setTopLine(idx_type cell, bool line, bool onlycolumn = false);
///
- string const GetPWidth(int cell) const;
+ void setBottomLine(idx_type cell, bool line, bool onlycolumn = false);
///
- string const GetColumnPWidth(int cell) const;
+ void setLeftLine(idx_type cell, bool line, bool onlycolumn = false);
///
- string const GetMColumnPWidth(int cell) const;
+ void setRightLine(idx_type cell, bool line, bool onlycolumn = false);
///
- string const GetAlignSpecial(int cell, int what) const;
+ void setAlignment(idx_type cell, LyXAlignment align,
+ bool onlycolumn = false);
///
- int GetWidthOfCell(int cell) const;
+ void setVAlignment(idx_type cell, VAlignment align,
+ bool onlycolumn = false);
///
- int GetBeginningOfTextInCell(int cell) const;
+ void setColumnPWidth(idx_type cell, LyXLength const & width);
///
- void AppendRow(int cell);
+ bool setMColumnPWidth(idx_type cell, LyXLength const & width);
///
- void DeleteRow(int row);
+ void setAlignSpecial(idx_type cell, std::string const & special,
+ Feature what);
///
- void AppendColumn(int cell);
+ LyXAlignment getAlignment(idx_type cell,
+ bool onlycolumn = false) const;
///
- void DeleteColumn(int column);
+ VAlignment getVAlignment(idx_type cell,
+ bool onlycolumn = false) const;
///
- bool IsFirstCellInRow(int cell) const;
+ LyXLength const getPWidth(idx_type cell) const;
///
- int GetFirstCellInRow(int row) const;
+ LyXLength const getColumnPWidth(idx_type cell) const;
///
- bool IsLastCellInRow(int cell) const;
+ LyXLength const getMColumnPWidth(idx_type cell) const;
///
- int GetLastCellInRow(int row) const;
+ std::string const getAlignSpecial(idx_type cell, int what) const;
///
- int GetNumberOfCells() const;
+ int getWidthOfCell(idx_type cell) const;
///
- int NumberOfCellsInRow(int cell) const;
+ int getBeginningOfTextInCell(idx_type cell) const;
///
- void Write(Buffer const *, std::ostream &) const;
+ void appendRow(BufferParams const &, idx_type cell);
///
- void Read(Buffer const *, LyXLex &);
+ void deleteRow(row_type row);
///
- void OldFormatRead(LyXLex &, string const &);
- //
- // helper function for Latex returns number of newlines
+ void appendColumn(BufferParams const &, idx_type cell);
///
- int TeXTopHLine(std::ostream &, int row) const;
+ void deleteColumn(col_type column);
///
- int TeXBottomHLine(std::ostream &, int row) const;
+ bool isFirstCellInRow(idx_type cell) const;
///
- int TeXCellPreamble(std::ostream &, int cell) const;
+ idx_type getFirstCellInRow(row_type row) const;
///
- int TeXCellPostamble(std::ostream &, int cell) const;
+ bool isLastCellInRow(idx_type cell) const;
///
- int Latex(Buffer const *, std::ostream &, bool, bool) const;
- /// auxiliary function for docbook rows
- int docbookRow(Buffer const * buf, std::ostream & os, int row) const;
+ idx_type getLastCellInRow(row_type row) const;
///
- int DocBook(Buffer const * buf, std::ostream & os) const;
+ idx_type getNumberOfCells() const;
///
- // helper function for Latex returns number of newlines
+ idx_type numberOfCellsInRow(idx_type cell) const;
///
- int AsciiTopHLine(std::ostream &, int row,
- std::vector<unsigned int> const &) const;
+ void write(Buffer const &, std::ostream &) const;
///
- int AsciiBottomHLine(std::ostream &, int row,
- std::vector<unsigned int> const &) const;
+ void read(Buffer const &, LyXLex &);
+ ///
+ int latex(Buffer const &, std::ostream &,
+ OutputParams const &) const;
+ //
+ int linuxdoc(Buffer const & buf, std::ostream & os,
+ OutputParams const &) const;
///
- int AsciiPrintCell(Buffer const *, std::ostream &,
- int cell, int row, int column,
- std::vector<unsigned int> const &) const;
+ int docbook(Buffer const & buf, std::ostream & os,
+ OutputParams const &) const;
///
- int Ascii(Buffer const *, std::ostream &) const;
+ int plaintext(Buffer const &, std::ostream &,
+ OutputParams const & runparams,
+ int const depth,
+ bool onlydata, unsigned char delim) const;
///
- bool IsMultiColumn(int cell, bool real = false) const;
+ bool isMultiColumn(idx_type cell) const;
///
- void SetMultiColumn(int cell, int number);
+ bool isMultiColumnReal(idx_type cell) const;
///
- int UnsetMultiColumn(int cell); // returns number of new cells
+ void setMultiColumn(Buffer *, idx_type cell, idx_type number);
///
- bool IsPartOfMultiColumn(int row, int column) const;
+ idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
///
- int row_of_cell(int cell) const;
+ bool isPartOfMultiColumn(row_type row, col_type column) const;
///
- int column_of_cell(int cell) const;
+ row_type row_of_cell(idx_type cell) const;
///
- int right_column_of_cell(int cell) const;
+ col_type column_of_cell(idx_type cell) const;
///
- void SetLongTabular(bool);
+ col_type right_column_of_cell(idx_type cell) const;
///
- bool IsLongTabular() const;
+ void setLongTabular(bool);
///
- void SetRotateTabular(bool);
+ bool isLongTabular() const;
///
- bool GetRotateTabular() const;
+ void setRotateTabular(bool);
///
- void SetRotateCell(int cell, bool);
+ bool getRotateTabular() const;
///
- bool GetRotateCell(int cell) const;
+ void setRotateCell(idx_type cell, bool);
///
- bool NeedRotating() const;
+ bool getRotateCell(idx_type cell) const;
///
- bool IsLastCell(int cell) const;
+ bool needRotating() const;
///
- int GetCellAbove(int cell) const;
+ bool isLastCell(idx_type cell) const;
///
- int GetCellBelow(int cell) const;
+ idx_type getCellAbove(idx_type cell) const;
///
- int GetLastCellAbove(int cell) const;
+ idx_type getCellBelow(idx_type cell) const;
///
- int GetLastCellBelow(int cell) const;
+ idx_type getLastCellAbove(idx_type cell) const;
///
- int GetCellNumber(int row, int column) const;
+ idx_type getLastCellBelow(idx_type cell) const;
///
- void SetUsebox(int cell, BoxType);
+ idx_type getCellNumber(row_type row, col_type column) const;
///
- BoxType GetUsebox(int cell) const;
+ void setUsebox(idx_type cell, BoxType);
+ ///
+ BoxType getUsebox(idx_type cell) const;
//
- // Long Tabular Options
+ // Long Tabular Options support functions
///
- bool checkLTType(int row, ltType const &) const;
+ bool checkLTType(row_type row, ltType const &) const;
///
- void SetLTHead(ltType const &, bool first);
+ void setLTHead(row_type row, bool flag, ltType const &, bool first);
///
- bool GetRowOfLTHead(int row, ltType &) const;
+ bool getRowOfLTHead(row_type row, ltType &) const;
///
- bool GetRowOfLTFirstHead(int row, ltType &) const;
+ bool getRowOfLTFirstHead(row_type row, ltType &) const;
///
- void SetLTFoot(ltType const &, bool last);
+ void setLTFoot(row_type row, bool flag, ltType const &, bool last);
///
- bool GetRowOfLTFoot(int row, ltType &) const;
+ bool getRowOfLTFoot(row_type row, ltType &) const;
///
- bool GetRowOfLTLastFoot(int row, ltType &) const;
+ bool getRowOfLTLastFoot(row_type row, ltType &) const;
///
- void SetLTNewPage(int cell, bool what);
+ void setLTNewPage(row_type row, bool what);
///
- bool GetLTNewPage(int cell) const;
+ bool getLTNewPage(row_type row) const;
///
- InsetText * GetCellInset(int cell) const;
+ bool haveLTHead() const;
///
- InsetText * GetCellInset(int row, int column) const;
+ bool haveLTFirstHead() const;
///
- int rows() const { return rows_; }
+ bool haveLTFoot() const;
///
- int columns() const { return columns_;}
+ bool haveLTLastFoot() const;
///
- InsetTabular * owner() const { return owner_; }
+ // end longtable support
///
- void Validate(LaTeXFeatures &) const;
+ boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
///
- std::vector<string> const getLabelList() const;
+ boost::shared_ptr<InsetText> getCellInset(row_type row,
+ col_type column) const;
+ /// Search for \param inset in the tabular, with the
///
- mutable int cur_cell;
-private:
+ idx_type getCellFromInset(InsetBase const * inset) const;
+ ///
+ row_type rows() const { return rows_; }
+ ///
+ col_type columns() const { return columns_;}
+ ///
+ void validate(LaTeXFeatures &) const;
+ /// Appends \c list with all labels found within this inset.
+ void getLabelList(Buffer const &, std::vector<std::string> & list) const;
+ ///
+//private:
///
struct cellstruct {
///
- cellstruct();
+ cellstruct(BufferParams const &);
+ ///
+ cellstruct(cellstruct const &);
+ ///
+ cellstruct & operator=(cellstruct);
///
- int cellno;
+ void swap(cellstruct & rhs);
+ ///
+ idx_type cellno;
///
int width_of_cell;
///
///
bool rotate;
///
- string align_special;
+ std::string align_special;
///
- string p_width; // this is only set for multicolumn!!!
+ LyXLength p_width; // this is only set for multicolumn!!!
///
- InsetText inset;
+ boost::shared_ptr<InsetText> inset;
};
+ cellstruct & cellinfo_of_cell(idx_type cell) const;
///
typedef std::vector<cellstruct> cell_vector;
///
///
rowstruct();
///
- bool top_line;
- ///
- bool bottom_line;
- ///
int ascent_of_row;
///
int descent_of_row;
+ ///
+ bool top_line;
+ ///
+ bool bottom_line;
/// This are for longtabulars only
+ /// a row of endhead
+ bool endhead;
+ /// a row of endfirsthead
+ bool endfirsthead;
+ /// a row of endfoot
+ bool endfoot;
+ /// row of endlastfoot
+ bool endlastfoot;
+ /// row for a pagebreak
bool newpage;
};
///
///
int width_of_column;
///
- string p_width;
+ LyXLength p_width;
///
- string align_special;
+ std::string align_special;
};
///
typedef std::vector<columnstruct> column_vector;
///
- void ReadNew(Buffer const * buf, std::istream & is,
- LyXLex & lex, string const & l);
- ///
- void ReadOld(Buffer const * buf, std::istream & is,
- LyXLex & lex, string const & l);
+ row_type rows_;
///
- int rows_;
+ col_type columns_;
///
- int columns_;
+ idx_type numberofcells;
///
- int numberofcells;
+ std::vector<row_type> rowofcell;
///
- std::vector<int> rowofcell;
- ///
- std::vector<int> columnofcell;
+ std::vector<col_type> columnofcell;
///
row_vector row_info;
///
bool rotate;
//
// for long tabulars
- ///
+ //
bool is_long_tabular;
- /// row of endhead
+ /// endhead data
ltType endhead;
- /// row of endfirsthead
+ /// endfirsthead data
ltType endfirsthead;
- /// row of endfoot
+ /// endfoot data
ltType endfoot;
- /// row of endlastfoot
+ /// endlastfoot data
ltType endlastfoot;
- ///
- InsetTabular * owner_;
///
- void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
- ///
- void Reinit();
+ void init(BufferParams const &, row_type rows_arg,
+ col_type columns_arg);
///
- void set_row_column_number_info(bool oldformat = false);
+ void set_row_column_number_info();
/// Returns true if a complete update is necessary, otherwise false
- bool SetWidthOfMulticolCell(int cell, int new_width);
+ bool setWidthOfMulticolCell(idx_type cell, int new_width);
///
- void recalculateMulticolCells(int cell, int new_width);
+ void recalculateMulticolumnsOfColumn(col_type column);
/// Returns true if change
- bool calculate_width_of_column(int column);
+ void calculate_width_of_column(col_type column);
///
- bool calculate_width_of_column_NMC(int column); // no multi cells
+ bool calculate_width_of_column_NMC(col_type column); // no multi cells
///
void calculate_width_of_tabular();
///
- cellstruct * cellinfo_of_cell(int cell) const;
+ void delete_column(col_type column);
+ ///
+ idx_type cells_in_multicolumn(idx_type cell) const;
+ ///
+ BoxType useParbox(idx_type cell) const;
+ ///
+ // helper function for Latex returns number of newlines
+ ///
+ int TeXTopHLine(std::ostream &, row_type row) const;
+ ///
+ int TeXBottomHLine(std::ostream &, row_type row) const;
+ ///
+ int TeXCellPreamble(std::ostream &, idx_type cell) const;
///
- void delete_column(int column);
+ int TeXCellPostamble(std::ostream &, idx_type cell) const;
///
- int cells_in_multicolumn(int cell) const;
+ int TeXLongtableHeaderFooter(std::ostream &, Buffer const & buf,
+ OutputParams const &) const;
///
- BoxType UseParbox(int cell) const;
+ bool isValidRow(row_type const row) const;
+ ///
+ int TeXRow(std::ostream &, row_type const row, Buffer const & buf,
+ OutputParams const &) const;
+ ///
+ // helper function for ASCII returns number of newlines
+ ///
+ int asciiTopHLine(std::ostream &, row_type row,
+ std::vector<unsigned int> const &) const;
+ ///
+ int asciiBottomHLine(std::ostream &, row_type row,
+ std::vector<unsigned int> const &) const;
+ ///
+ int asciiPrintCell(Buffer const &, std::ostream &,
+ OutputParams const &,
+ idx_type cell, row_type row, col_type column,
+ std::vector<unsigned int> const &,
+ bool onlydata) const;
+ /// auxiliary function for docbook
+ int docbookRow(Buffer const & buf, std::ostream & os, row_type,
+ OutputParams const &) const;
+
+private:
+ /// renumber cells after structural changes
+ void fixCellNums();
};
#endif