]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.h
Fix bug http://bugzilla.lyx.org/show_bug.cgi?id=4910 by creating InsetText::addToToc().
[lyx.git] / src / insets / InsetTabular.h
index 78727b0f5cb12d32793dd0ce6d870a72d8edbb3c..27b059dd0ecad5a816f07a876a3420b877b0c994 100644 (file)
@@ -4,7 +4,6 @@
  * 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
 
 // Lgb
 
-#ifndef INSETTABULAR_H
-#define INSETTABULAR_H
+#ifndef INSET_TABULAR_H
+#define INSET_TABULAR_H
 
 #include "Inset.h"
 #include "InsetText.h"
 #include "Layout.h"
 #include "Length.h"
-#include "MailInset.h"
 
 #include <boost/shared_ptr.hpp>
 
 
 namespace lyx {
 
-class FuncStatus;
-class Lexer;
-class BufferView;
 class Buffer;
 class BufferParams;
-class Paragraph;
+class BufferView;
+class CompletionList;
 class CursorSlice;
+class InsetTableCell;
+class FuncStatus;
+class Lexer;
+class Paragraph;
 
 namespace frontend { class Painter; }
 
@@ -106,14 +106,6 @@ public:
                ///
                VALIGN_MIDDLE,
                ///
-               M_TOGGLE_LINE_TOP,
-               ///
-               M_TOGGLE_LINE_BOTTOM,
-               ///
-               M_TOGGLE_LINE_LEFT,
-               ///
-               M_TOGGLE_LINE_RIGHT,
-               ///
                M_ALIGN_LEFT,
                ///
                M_ALIGN_RIGHT,
@@ -168,6 +160,8 @@ public:
                ///
                SET_LTNEWPAGE,
                ///
+               TOGGLE_LTCAPTION,
+               ///
                SET_SPECIAL_COLUMN,
                ///
                SET_SPECIAL_MULTI,
@@ -182,6 +176,8 @@ public:
                ///
                SET_INTERLINE_SPACE,
                ///
+               SET_BORDER_LINES,
+               ///
                LAST_ACTION
        };
        ///
@@ -238,19 +234,17 @@ public:
        /// index indicating an invalid position
        static const idx_type npos = static_cast<idx_type>(-1);
 
-       /// constructor
-       Tabular();
        /// constructor
        Tabular(Buffer 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;
+       bool topLine(idx_type cell) const;
        /// Returns true if there is a topline, returns false if not
-       bool bottomLine(idx_type cell, bool wholerow = false) const;
+       bool bottomLine(idx_type cell) const;
        /// Returns true if there is a topline, returns false if not
-       bool leftLine(idx_type cell, bool wholecolumn = false) const;
+       bool leftLine(idx_type cell) const;
        /// Returns true if there is a topline, returns false if not
-       bool rightLine(idx_type cell, bool wholecolumn = false) const;
+       bool rightLine(idx_type cell) const;
 
        ///
        bool topAlreadyDrawn(idx_type cell) const;
@@ -285,14 +279,22 @@ public:
        ///
        void setAllLines(idx_type cell, bool line);
        ///
-       void setTopLine(idx_type cell, bool line, bool wholerow = false);
+       void setTopLine(idx_type cell, bool line);
+       ///
+       void setBottomLine(idx_type cell, bool line);
+       ///
+       void setLeftLine(idx_type cell, bool line);
+       ///
+       void setRightLine(idx_type cell, bool line);
        ///
-       void setBottomLine(idx_type cell, bool line, bool wholerow = false);
+       bool rowTopLine(row_type row) const;
        ///
-       void setLeftLine(idx_type cell, bool line, bool wholecolumn = false);
+       bool rowBottomLine(row_type row) const;
        ///
-       void setRightLine(idx_type cell, bool line, bool wholecolumn = false);
+       bool columnLeftLine(col_type column) const;
        ///
+       bool columnRightLine(col_type column) const;
+
        void setAlignment(idx_type cell, LyXAlignment align,
                          bool onlycolumn = false);
        ///
@@ -314,12 +316,6 @@ public:
        ///
        Length const getPWidth(idx_type cell) const;
        ///
-       Length const getColumnPWidth(idx_type cell) const;
-       ///
-       Length const getMColumnPWidth(idx_type cell) const;
-       ///
-       docstring const getAlignSpecial(idx_type cell, int what) const;
-       ///
        int cellWidth(idx_type cell) const;
        ///
        int getBeginningOfTextInCell(idx_type cell) const;
@@ -344,8 +340,6 @@ public:
        ///
        idx_type getLastCellInRow(row_type row) const;
        ///
-       idx_type cellCount() const;
-       ///
        idx_type numberOfCellsInRow(idx_type cell) const;
        ///
        void write(std::ostream &) const;
@@ -376,18 +370,6 @@ public:
        ///
        col_type cellRightColumn(idx_type cell) const;
        ///
-       void setBookTabs(bool);
-       ///
-       bool useBookTabs() const;
-       ///
-       void setLongTabular(bool);
-       ///
-       bool isLongTabular() const;
-       ///
-       void setRotateTabular(bool);
-       ///
-       bool getRotateTabular() const;
-       ///
        void setRotateCell(idx_type cell, bool);
        ///
        bool getRotateCell(idx_type cell) const;
@@ -396,13 +378,9 @@ public:
        ///
        bool isLastCell(idx_type cell) const;
        ///
-       idx_type getCellAbove(idx_type cell) const;
-       ///
-       idx_type getCellBelow(idx_type cell) const;
-       ///
-       idx_type getLastCellAbove(idx_type cell) const;
+       idx_type cellAbove(idx_type cell) const;
        ///
-       idx_type getLastCellBelow(idx_type cell) const;
+       idx_type cellBelow(idx_type cell) const;
        ///
        idx_type cellIndex(row_type row, col_type column) const;
        ///
@@ -430,6 +408,10 @@ public:
        ///
        bool getLTNewPage(row_type row) const;
        ///
+       idx_type setLTCaption(row_type row, bool what);
+       ///
+       bool ltCaption(row_type row) const;
+       ///
        bool haveLTHead() const;
        ///
        bool haveLTFirstHead() const;
@@ -440,20 +422,16 @@ public:
        ///
        // end longtable support
        ///
-       boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
+       boost::shared_ptr<InsetTableCell> cellInset(idx_type cell) const;
        ///
-       boost::shared_ptr<InsetText> getCellInset(row_type row,
+       boost::shared_ptr<InsetTableCell> cellInset(row_type row,
                                                  col_type column) const;
        ///
        void setCellInset(row_type row, col_type column,
-                         boost::shared_ptr<InsetText>) const;
+                         boost::shared_ptr<InsetTableCell>) const;
        /// Search for \param inset in the tabular, with the
        ///
-       idx_type getCellFromInset(Inset const * inset) const;
-       ///
-       row_type rowCount() const { return row_info.size(); }
-       ///
-       col_type columnCount() const { return column_info.size();}
+       idx_type cellFromInset(Inset const * inset) const;
        ///
        void validate(LaTeXFeatures &) const;
        ///
@@ -462,7 +440,7 @@ public:
        class CellData {
        public:
                ///
-               CellData(Buffer const &);
+               CellData(Buffer const &, Tabular const &);
                ///
                CellData(CellData const &);
                ///
@@ -496,9 +474,9 @@ public:
                ///
                Length p_width; // this is only set for multicolumn!!!
                ///
-               boost::shared_ptr<InsetText> inset;
+               boost::shared_ptr<InsetTableCell> inset;
        };
-       CellData & cellinfo_of_cell(idx_type cell) const;
+       CellData & cellInfo(idx_type cell) const;
        ///
        typedef std::vector<CellData> cell_vector;
        ///
@@ -513,10 +491,6 @@ public:
                int ascent;
                ///
                int descent;
-               ///
-               bool top_line;
-               ///
-               bool bottom_line;
                /// Extra space between the top line and this row
                Length top_space;
                /// Ignore top_space if true and use the default top space
@@ -540,6 +514,8 @@ public:
                bool endlastfoot;
                /// row for a newpage
                bool newpage;
+               /// caption
+               bool caption;
        };
        ///
        typedef std::vector<RowData> row_vector;
@@ -554,10 +530,6 @@ public:
                ///
                VAlignment valignment;
                ///
-               bool left_line;
-               ///
-               bool right_line;
-               ///
                int width;
                ///
                Length p_width;
@@ -601,16 +573,10 @@ public:
                  col_type columns_arg);
        ///
        void updateIndexes();
-       /// Returns true if a complete update is necessary, otherwise false
-       bool setWidthOfMulticolCell(idx_type cell, int new_width);
+       /// return true of update is needed
+       bool updateColumnWidths();
        ///
-       void recalculateMulticolumnsOfColumn(col_type column);
-       /// Returns true if change
-       void calculate_width_of_column(col_type column);
-       ///
-       bool calculate_width_of_column_NMC(col_type column); // no multi cells
-       ///
-       idx_type cells_in_multicolumn(idx_type cell) const;
+       idx_type columnSpan(idx_type cell) const;
        ///
        BoxType useParbox(idx_type cell) const;
        ///
@@ -620,9 +586,9 @@ public:
        ///
        int TeXBottomHLine(odocstream &, row_type row) const;
        ///
-       int TeXCellPreamble(odocstream &, idx_type cell) const;
+       int TeXCellPreamble(odocstream &, idx_type cell, bool & ismulticol) const;
        ///
-       int TeXCellPostamble(odocstream &, idx_type cell) const;
+       int TeXCellPostamble(odocstream &, idx_type cell, bool ismulticol) const;
        ///
        int TeXLongtableHeaderFooter(odocstream &, OutputParams const &) const;
        ///
@@ -655,13 +621,50 @@ public:
 private:
        Buffer const * buffer_;
 
-       /// renumber cells after structural changes
-       void fixCellNums();
-};
+}; // Tabular
 
 
+///
+class InsetTableCell : public InsetText
+{
+public:
+       ///
+       InsetTableCell(Buffer const & buf,
+               Tabular::CellData const * cd, Tabular const * t);
+       ///
+       InsetCode lyxCode() const { return CELL_CODE; }
+       ///
+       Inset * clone() { return new InsetTableCell(*this); }
+       ///
+       virtual bool useEmptyLayout() const { return true; }
+       /// 
+       virtual bool forceEmptyLayout(idx_type = 0) const;
+       /// 
+       virtual bool allowParagraphCustomization(idx_type = 0) const;
+       ///
+       bool getStatus(Cursor & cur, FuncRequest const & cmd,
+               FuncStatus & status) const;
+       ///
+       virtual bool neverIndent() { return true; }
+       ///
+       void setCellData(Tabular::CellData const * cd) { cell_data_ = cd; }
+       ///
+       void setTabular(Tabular const * t) { table_ = t; }
+private:
+       /// unimplemented
+       InsetTableCell();
+       /// unimplemented
+       void operator=(InsetTableCell const &);
+
+       /// 
+       Tabular::CellData const * cell_data_;
+       /// 
+       Tabular const * table_;
+};
+
 
-class InsetTabular : public Inset {
+class InsetTabular : public Inset
+{
 public:
        ///
        InsetTabular(Buffer const &, row_type rows = 1,
@@ -669,6 +672,10 @@ public:
        ///
        ~InsetTabular();
        ///
+       static void string2params(std::string const &, InsetTabular &);
+       ///
+       static std::string params2string(InsetTabular const &);
+       ///
        void read(Lexer &);
        ///
        void write(std::ostream &) const;
@@ -693,7 +700,7 @@ public:
            insets that may contain several paragraphs */
        bool noFontChange() const { return true; }
        ///
-       DisplayType display() const { return tabular.isLongTabular() ? AlignCenter : Inline; }
+       DisplayType display() const { return tabular.is_long_tabular ? AlignCenter : Inline; }
        ///
        int latex(odocstream &, OutputParams const &) const;
        ///
@@ -704,6 +711,8 @@ public:
        void validate(LaTeXFeatures & features) const;
        ///
        InsetCode lyxCode() const { return TABULAR_CODE; }
+       ///
+       docstring contextMenu(BufferView const & bv, int x, int y) const;
        /// get offset of this cursor slice relative to our upper left corner
        void cursorPos(BufferView const & bv, CursorSlice const & sl,
                bool boundary, int & x, int & y) const;
@@ -717,11 +726,11 @@ public:
        ///
        bool showInsetDialog(BufferView *) const;
        /// number of cells
-       size_t nargs() const { return tabular.cellCount(); }
+       size_t nargs() const { return tabular.numberofcells; }
        ///
-       boost::shared_ptr<InsetText const> cell(idx_type) const;
+       boost::shared_ptr<InsetTableCell const> cell(idx_type) const;
        ///
-       boost::shared_ptr<InsetText> cell(idx_type);
+       boost::shared_ptr<InsetTableCell> cell(idx_type);
        ///
        Text * getText(int) const;
 
@@ -737,12 +746,18 @@ public:
        /// should all paragraphs be output with "Standard" layout?
        virtual bool allowParagraphCustomization(idx_type cell = 0) const;
        ///
-       virtual bool forceEmptyLayout() { return true; }
+       virtual bool forceEmptyLayout(idx_type cell = 0) const;
+       ///
+       virtual bool useEmptyLayout() { return true; }
        ///
        void addPreview(graphics::PreviewLoader &) const;
 
        /// lock cell with given index
        void edit(Cursor & cur, bool front, EntryDirection entry_from);
+       /// get table row from x coordinate
+       int rowFromY(Cursor & cur, int y) const;
+       /// get table column from y coordinate
+       int columnFromX(Cursor & cur, int x) const;
        ///
        Inset * editXY(Cursor & cur, int x, int y);
        /// can we go further down on mouse click?
@@ -750,23 +765,48 @@ public:
        // Update the counters of this inset and of its contents
        void updateLabels(ParIterator const &);
 
+       ///
+       bool completionSupported(Cursor const &) const;
+       ///
+       bool inlineCompletionSupported(Cursor const & cur) const;
+       ///
+       bool automaticInlineCompletion() const;
+       ///
+       bool automaticPopupCompletion() const;
+       ///
+       bool showCompletionCursor() const;
+       ///
+       CompletionList const * createCompletionList(Cursor const & cur) const;
+       ///
+       docstring completionPrefix(Cursor const & cur) const;
+       ///
+       bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
+       ///
+       void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
+
+       ///
+       virtual InsetTabular * asInsetTabular() { return this; }
+       ///
+       virtual InsetTabular const * asInsetTabular() const { return this; }
+       ///
+       bool isRightToLeft(Cursor & cur) const;
+
        //
        // Public structures and variables
        ///
        mutable Tabular tabular;
 
-protected:
+private:
        ///
        InsetTabular(InsetTabular const &);
        ///
-       virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
+       void doDispatch(Cursor & cur, FuncRequest & cmd);
        ///
        bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
        ///
        int scroll() const { return scx_; }
-
-private:
-       Inset * clone() const;
+       ///
+       Inset * clone() const { return new InsetTabular(*this); }
 
        ///
        void drawCellLines(frontend::Painter &, int x, int y, row_type row,
@@ -775,11 +815,13 @@ private:
        void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
 
        ///
-       void moveNextCell(Cursor & cur);
+       void moveNextCell(Cursor & cur, 
+                               EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
        ///
-       void movePrevCell(Cursor & cur);
+       void movePrevCell(Cursor & cur,
+                               EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
        ///
-       int getCellXPos(idx_type cell) const;
+       int cellXPos(idx_type cell) const;
        ///
        void resetPos(Cursor & cur) const;
        ///
@@ -791,8 +833,6 @@ private:
        ///
        void cutSelection(Cursor & cur);
        ///
-       bool isRightToLeft(Cursor & cur) const;
-       ///
        void getSelection(Cursor & cur, row_type & rs, row_type & re,
                          col_type & cs, col_type & ce) const;
        ///
@@ -813,32 +853,14 @@ private:
        mutable idx_type first_visible_cell;
        ///
        mutable int scx_;
-};
-
-
-class InsetTabularMailer : public MailInset {
-public:
-       ///
-       InsetTabularMailer(InsetTabular const & inset);
-       ///
-       virtual Inset & inset() const { return inset_; }
-       ///
-       virtual std::string const & name() const { return name_; }
-       ///
-       virtual std::string const inset2string(Buffer const &) const;
-       ///
-       static void string2params(std::string const &, InsetTabular &);
-       ///
-       static std::string const params2string(InsetTabular const &);
-private:
-       ///
-       static std::string const name_;
-       ///
-       InsetTabular & inset_;
+       /// true when selecting rows with the mouse
+       bool rowselect_;
+       /// true when selecting columns with the mouse
+       bool colselect_;
 };
 
 std::string const featureAsString(Tabular::Feature feature);
 
 } // namespace lyx
 
-#endif
+#endif // INSET_TABULAR_H