]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.h
Allows editing when the Prefs dialog is opened; fix bug 3140:
[lyx.git] / src / tabular.h
index 36b034dd76b1b42acca14159e02532ca36748db7..163f33a2b746aa364181e4bd20f9b6f967078b52 100644 (file)
@@ -1,36 +1,36 @@
 // -*- 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 "lyxlex.h"
-#include "layout.h"
-#include "LString.h"
 #include "lyxlength.h"
-
 #include "insets/insettext.h"
 
+#include <boost/shared_ptr.hpp>
+
 #include <iosfwd>
 #include <vector>
 
+
+namespace lyx {
+
 class InsetTabular;
-class LaTeXFeatures;
-class Buffer;
+class LCursor;
+class OutputParams;
 
-/* The features the text class offers for tables */ 
+/* The features the text class offers for tables */
 
 ///
 class LyXTabular  {
@@ -46,6 +46,10 @@ public:
                ///
                DELETE_COLUMN,
                ///
+               COPY_ROW,
+               ///
+               COPY_COLUMN,
+               ///
                TOGGLE_LINE_TOP,
                ///
                TOGGLE_LINE_BOTTOM,
@@ -60,11 +64,13 @@ public:
                ///
                ALIGN_CENTER,
                ///
+               ALIGN_BLOCK,
+               ///
                VALIGN_TOP,
                ///
                VALIGN_BOTTOM,
                ///
-               VALIGN_CENTER,
+               VALIGN_MIDDLE,
                ///
                M_TOGGLE_LINE_TOP,
                ///
@@ -84,7 +90,7 @@ public:
                ///
                M_VALIGN_BOTTOM,
                ///
-               M_VALIGN_CENTER,
+               M_VALIGN_MIDDLE,
                ///
                MULTICOLUMN,
                ///
@@ -128,6 +134,16 @@ public:
                ///
                SET_SPECIAL_MULTI,
                ///
+               SET_BOOKTABS,
+               ///
+               UNSET_BOOKTABS,
+               ///
+               SET_TOP_SPACE,
+               ///
+               SET_BOTTOM_SPACE,
+               ///
+               SET_INTERLINE_SPACE,
+               ///
                LAST_ACTION
        };
        ///
@@ -147,7 +163,7 @@ public:
                ///
                LYX_VALIGN_BOTTOM = 1,
                ///
-               LYX_VALIGN_CENTER = 2
+               LYX_VALIGN_MIDDLE = 2
        };
 
        enum BoxType {
@@ -159,10 +175,11 @@ public:
                BOX_MINIPAGE = 2
        };
 
-       struct lttype {
+       class ltType {
+       public:
                // constructor
-               lttype();
-               // we have this header type (is set in the GetLT... functions)
+               ltType();
+               // we have this header type (is set in the getLT... functions)
                bool set;
                // double borders on top
                bool topDL;
@@ -173,195 +190,207 @@ public:
                // ignored in the output and it is set to be empty!
                bool empty;
        };
+
+       /// 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(idx_type cell, bool wholerow = false) const;
+       /// Returns true if there is a topline, returns false if not
+       bool bottomLine(idx_type cell, bool wholerow = false) const;
+       /// Returns true if there is a topline, returns false if not
+       bool leftLine(idx_type cell, bool wholecolumn = false) const;
+       /// Returns true if there is a topline, returns false if not
+       bool rightLine(idx_type cell, bool wholecolumn = false) const;
+
        ///
-       typedef struct lttype ltType;
-       
-       /* konstruktor */
+       bool topAlreadyDrawn(idx_type cell) const;
        ///
-       LyXTabular(InsetTabular *, int columns_arg, int rows_arg);
+       bool leftAlreadyDrawn(idx_type cell) const;
        ///
-       LyXTabular(InsetTabular *, LyXTabular const &, bool same_id = false);
+       bool isLastRow(idx_type cell) const;
+
+       /// return space occupied by the second horizontal line and
+       /// interline space above row \p row in pixels
+       int getAdditionalHeight(row_type row) const;
        ///
-       explicit
-       LyXTabular(Buffer const *, InsetTabular *, LyXLex & lex);
+       int getAdditionalWidth(idx_type cell) const;
+
+       /* returns the maximum over all rows */
        ///
-       LyXTabular & operator=(LyXTabular const &);
+       int getWidthOfColumn(idx_type cell) const;
        ///
-       LyXTabular * clone(InsetTabular *, bool same_id = false);
-       
-       /// Returns true if there is a topline, returns false if not
-       bool TopLine(int cell, bool onlycolumn = false) const;
-       /// Returns true if there is a topline, returns false if not
-       bool BottomLine(int cell, bool onlycolumn = false) const;
-       /// Returns true if there is a topline, returns false if not
-       bool LeftLine(int cell, bool onlycolumn = false) const;
-       /// Returns true if there is a topline, returns false if not
-       bool RightLine(int cell, bool onlycolumn = false) const;
-       
+       int getWidthOfTabular() const;
        ///
-       bool TopAlreadyDrawed(int cell) const;
+       int getAscentOfRow(row_type row) const;
        ///
-       bool LeftAlreadyDrawed(int cell) const;
+       int getDescentOfRow(row_type row) const;
        ///
-       bool IsLastRow(int cell) const;
-
+       int getHeightOfTabular() const;
        ///
-       int GetAdditionalHeight(int row) const;
+       void setAscentOfRow(row_type row, int height);
        ///
-       int GetAdditionalWidth(int cell) const;
-       
-       /* returns the maximum over all rows */
+       void setDescentOfRow(row_type row, int height);
        ///
-       int GetWidthOfColumn(int cell) const;
+       void setWidthOfCell(idx_type cell, int new_width);
        ///
-       int GetWidthOfTabular() const;
+       void setAllLines(idx_type cell, bool line);
        ///
-       int GetAscentOfRow(int row) const;
+       void setTopLine(idx_type cell, bool line, bool wholerow = false);
        ///
-       int GetDescentOfRow(int row) const;
+       void setBottomLine(idx_type cell, bool line, bool wholerow = false);
        ///
-       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,
+       void setLeftLine(idx_type cell, bool line, bool wholecolumn = false);
+       ///
+       void setRightLine(idx_type cell, bool line, bool wholecolumn = false);
+       ///
+       void setAlignment(idx_type cell, LyXAlignment align,
                          bool onlycolumn = false);
-       /// Returns true if a complete update is necessary, otherwise false
-       bool SetVAlignment(int cell, VAlignment align,
+       ///
+       void setVAlignment(idx_type cell, VAlignment align,
                           bool onlycolumn = false);
        ///
-       bool SetColumnPWidth(int cell, LyXLength const & width);
+       void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
+       ///
+       bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
        ///
-       bool SetMColumnPWidth(int cell, LyXLength const & width);
+       void setAlignSpecial(idx_type cell, docstring const & special,
+                            Feature what);
        ///
-       bool SetAlignSpecial(int cell, string const & special, Feature what);
+       LyXAlignment getAlignment(idx_type cell,
+                                 bool onlycolumn = false) const;
        ///
-       LyXAlignment GetAlignment(int cell, bool onlycolumn = false) const;
+       VAlignment getVAlignment(idx_type cell,
+                                bool onlycolumn = false) const;
        ///
-       VAlignment GetVAlignment(int cell, bool onlycolumn = false) const;
+       LyXLength const getPWidth(idx_type cell) const;
        ///
-       LyXLength const GetPWidth(int cell) const;
+       LyXLength const getColumnPWidth(idx_type cell) const;
        ///
-       LyXLength const GetColumnPWidth(int cell) const;
+       LyXLength const getMColumnPWidth(idx_type cell) const;
        ///
-       LyXLength const GetMColumnPWidth(int cell) const;
+       docstring const getAlignSpecial(idx_type cell, int what) const;
        ///
-       string const GetAlignSpecial(int cell, int what) const;
+       int getWidthOfCell(idx_type cell) const;
        ///
-       int GetWidthOfCell(int cell) const;
+       int getBeginningOfTextInCell(idx_type cell) const;
        ///
-       int GetBeginningOfTextInCell(int cell) const;
+       void appendRow(BufferParams const &, idx_type cell);
        ///
-       void AppendRow(int cell);
+       void deleteRow(row_type row);
        ///
-       void DeleteRow(int row);
+       void copyRow(BufferParams const &, row_type);
        ///
-       void AppendColumn(int cell);
+       void appendColumn(BufferParams const &, idx_type cell);
        ///
-       void DeleteColumn(int column);
+       void deleteColumn(col_type column);
        ///
-       bool IsFirstCellInRow(int cell) const;
+       void copyColumn(BufferParams const &, col_type);
        ///
-       int GetFirstCellInRow(int row) const;
+       bool isFirstCellInRow(idx_type cell) const;
        ///
-       bool IsLastCellInRow(int cell) const;
+       idx_type getFirstCellInRow(row_type row) const;
        ///
-       int GetLastCellInRow(int row) const;
+       bool isLastCellInRow(idx_type cell) const;
        ///
-       int GetNumberOfCells() const;
+       idx_type getLastCellInRow(row_type row) const;
        ///
-       int NumberOfCellsInRow(int cell) const;
+       idx_type getNumberOfCells() const;
        ///
-       void Write(Buffer const *, std::ostream &) const;
+       idx_type numberOfCellsInRow(idx_type cell) const;
        ///
-       void Read(Buffer const *, LyXLex &);
+       void write(Buffer const &, std::ostream &) const;
        ///
-       void OldFormatRead(LyXLex &, string const &);
+       void read(Buffer const &, LyXLex &);
        ///
-       int latex(Buffer const *, std::ostream &, bool, bool) const;
+       int latex(Buffer const &, odocstream &, OutputParams const &) const;
+       //
+       int docbook(Buffer const & buf, odocstream & os, OutputParams const &) const;
+       ///
+       int plaintext(Buffer const &, odocstream &,
+                 OutputParams const & runparams,
+                 int const depth,
+                 bool onlydata, unsigned char delim) const;
        ///
-       int docBook(Buffer const * buf, std::ostream & os) const;
+       bool isMultiColumn(idx_type cell) const;
        ///
-       int ascii(Buffer const *, std::ostream &, int const depth,
-                 bool onlydata, unsigned char delim) const;
+       bool isMultiColumnReal(idx_type cell) const;
        ///
-       bool IsMultiColumn(int cell, bool real = false) const;
+       void setMultiColumn(Buffer *, idx_type cell, idx_type number);
        ///
-       void SetMultiColumn(int cell, int number);
+       idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
        ///
-       int UnsetMultiColumn(int cell); // returns number of new cells
+       bool isPartOfMultiColumn(row_type row, col_type column) const;
        ///
-       bool IsPartOfMultiColumn(int row, int column) const;
+       row_type row_of_cell(idx_type cell) const;
        ///
-       int row_of_cell(int cell) const;
+       col_type column_of_cell(idx_type cell) const;
        ///
-       int column_of_cell(int cell) const;
+       col_type right_column_of_cell(idx_type cell) const;
        ///
-       int right_column_of_cell(int cell) const;
+       void setBookTabs(bool);
        ///
-       void SetLongTabular(bool);
+       bool useBookTabs() 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 support functions
        ///
-       bool checkLTType(int row, ltType const &) const;
+       bool checkLTType(row_type row, ltType const &) const;
        ///
-       void SetLTHead(int row, bool flag, 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(int row, bool flag, 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 row, bool what);
+       void setLTNewPage(row_type row, bool what);
        ///
-       bool GetLTNewPage(int row) const;
+       bool getLTNewPage(row_type row) const;
        ///
        bool haveLTHead() const;
        ///
@@ -373,31 +402,37 @@ public:
        ///
        // end longtable support
        ///
-       InsetText * GetCellInset(int cell) const;
+       boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
        ///
-       InsetText * GetCellInset(int row, int column) const;
+       boost::shared_ptr<InsetText> getCellInset(row_type row,
+                                                 col_type column) const;
        ///
-       int rows() const { return rows_; }
+       void setCellInset(row_type row, col_type column,
+                         boost::shared_ptr<InsetText>) const;
+       /// Search for \param inset in the tabular, with the
        ///
-       int columns() const { return columns_;}
+       idx_type getCellFromInset(InsetBase const * inset) const;
        ///
-       InsetTabular * owner() const { return owner_; }
+       row_type rows() const { return rows_; }
        ///
-       void Validate(LaTeXFeatures &) const;
+       col_type columns() const { return columns_;}
        ///
-       std::vector<string> const getLabelList() const;
+       void validate(LaTeXFeatures &) const;
        ///
-       /// recalculate the widths/heights only!
-       void reinit();
+//private:
        ///
-       mutable int cur_cell;
-private:
-       ///
-       struct cellstruct {
+       class cellstruct {
+       public:
+               ///
+               cellstruct(BufferParams const &);
+               ///
+               cellstruct(cellstruct const &);
+               ///
+               cellstruct & operator=(cellstruct);
                ///
-               cellstruct();
+               void swap(cellstruct & rhs);
                ///
-               int cellno;
+               idx_type cellno;
                ///
                int width_of_cell;
                ///
@@ -419,19 +454,21 @@ private:
                ///
                bool rotate;
                ///
-               string align_special;
+               docstring align_special;
                ///
                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;
        ///
        typedef std::vector<cell_vector> cell_vvector;
 
        ///
-       struct rowstruct {
+       class rowstruct {
+       public:
                ///
                rowstruct();
                ///
@@ -442,6 +479,18 @@ private:
                bool top_line;
                ///
                bool bottom_line;
+               /// Extra space between the top line and this row
+               LyXLength top_space;
+               /// Ignore top_space if true and use the default top space
+               bool top_space_default;
+               /// Extra space between this row and the bottom line
+               LyXLength bottom_space;
+               /// Ignore bottom_space if true and use the default bottom space
+               bool bottom_space_default;
+               /// Extra space between the bottom line and the next top line
+               LyXLength interline_space;
+               /// Ignore interline_space if true and use the default interline space
+               bool interline_space_default;
                /// This are for longtabulars only
                /// a row of endhead
                bool endhead;
@@ -458,7 +507,8 @@ private:
        typedef std::vector<rowstruct> row_vector;
 
        ///
-       struct columnstruct {
+       class columnstruct {
+               public:
                ///
                columnstruct();
                ///
@@ -474,27 +524,21 @@ private:
                ///
                LyXLength p_width;
                ///
-               string align_special;
+               docstring align_special;
        };
        ///
        typedef std::vector<columnstruct> column_vector;
 
        ///
-       void ReadNew(Buffer const * buf, std::istream & is,
-                                LyXLex & lex, string const & l, int const version);
+       row_type rows_;
        ///
-       void ReadOld(Buffer const * buf, std::istream & is,
-                                LyXLex & lex, string const & l);
+       col_type columns_;
        ///
-       int rows_;
+       idx_type numberofcells;
        ///
-       int columns_;
+       std::vector<row_type> rowofcell;
        ///
-       int numberofcells;
-       ///
-       std::vector<int> rowofcell;
-       ///
-       std::vector<int> columnofcell;
+       std::vector<col_type> columnofcell;
        ///
        row_vector row_info;
        ///
@@ -504,6 +548,8 @@ private:
        ///
        int width_of_tabular;
        ///
+       bool use_booktabs;
+       ///
        bool rotate;
        //
        // for long tabulars
@@ -517,69 +563,70 @@ private:
        ltType endfoot;
        /// endlastfoot data
        ltType endlastfoot;
-       //
-       ///
-       InsetTabular * owner_;
 
        ///
-       void Init(int columns_arg, int rows_arg, LyXTabular const * lt = 0);
-       ///
-       void Reinit(bool reset_widths = true);
+       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(int column);
-       ///
-       int cells_in_multicolumn(int cell) const;
+       void delete_column(col_type column);
        ///
-       BoxType UseParbox(int cell) const;
+       idx_type cells_in_multicolumn(idx_type cell) const;
        ///
-       void setHeaderFooterRows(int header, int fheader, int footer, int lfooter);
+       BoxType useParbox(idx_type cell) const;
        ///
        // helper function for Latex returns number of newlines
        ///
-       int TeXTopHLine(std::ostream &, int row) const;
+       int TeXTopHLine(odocstream &, row_type row) const;
        ///
-       int TeXBottomHLine(std::ostream &, int row) const;
+       int TeXBottomHLine(odocstream &, row_type row) const;
        ///
-       int TeXCellPreamble(std::ostream &, int cell) const;
+       int TeXCellPreamble(odocstream &, idx_type cell) const;
        ///
-       int TeXCellPostamble(std::ostream &, int cell) const;
+       int TeXCellPostamble(odocstream &, idx_type cell) const;
        ///
-       int TeXLongtableHeaderFooter(std::ostream &, Buffer const * buf,
-                                    bool fragile, bool fp) const;
+       int TeXLongtableHeaderFooter(odocstream &, Buffer const & buf,
+                                    OutputParams const &) const;
        ///
-       bool isValidRow(int const row) const;
+       bool isValidRow(row_type const row) const;
        ///
-       int TeXRow(std::ostream &, int const row, Buffer const * buf,
-                  bool fragile, bool fp) const;
+       int TeXRow(odocstream &, row_type const row, Buffer const & buf,
+                  OutputParams const &) const;
        ///
-       // helper function for ASCII returns number of newlines
+       // helper functions for plain text return number of newlines
        ///
-       int asciiTopHLine(std::ostream &, int row,
-                         std::vector<unsigned int> const &) const;
+       int plaintextTopHLine(odocstream &, row_type row,
+                       std::vector<unsigned int> const &) const;
        ///
-       int asciiBottomHLine(std::ostream &, int row,
-                            std::vector<unsigned int> const &) const;
+       int plaintextBottomHLine(odocstream &, row_type row,
+                       std::vector<unsigned int> const &) const;
        ///
-       int asciiPrintCell(Buffer const *, std::ostream &,
-                          int cell, int row, int column,
-                          std::vector<unsigned int> const &,
+       int plaintextPrintCell(Buffer const &, odocstream &,
+                       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, int row) const;
+       int docbookRow(Buffer const & buf, odocstream & os, row_type,
+                      OutputParams const &) const;
+
+private:
+       /// renumber cells after structural changes
+       void fixCellNums();
 };
 
+
+} // namespace lyx
+
 #endif