]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.h
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetTabular.h
index f042b0a6f32a98377f7c9608d34712680bfa4309..79bc8cea23f7fc994408a2315a94f13580c88f00 100644 (file)
 #define INSETTABULAR_H
 
 #include "Inset.h"
-#include "MailInset.h"
-#include "LyXLength.h"
 #include "InsetText.h"
-
+#include "Layout.h"
+#include "Length.h"
+#include "MailInset.h"
 
 #include <boost/shared_ptr.hpp>
 
@@ -61,13 +61,13 @@ namespace frontend { class Painter; }
 
 
 class InsetTabular;
-class LCursor;
+class Cursor;
 class OutputParams;
 
 //
 // A helper struct for tables
-// 
-class Tabular  {
+//
+class Tabular {
 public:
        ///
        enum Feature {
@@ -144,10 +144,14 @@ public:
                ///
                UNSET_ROTATE_TABULAR,
                ///
+               TOGGLE_ROTATE_TABULAR,
+               ///
                SET_ROTATE_CELL,
                ///
                UNSET_ROTATE_CELL,
                ///
+               TOGGLE_ROTATE_CELL,
+               ///
                SET_USEBOX,
                ///
                SET_LTHEAD,
@@ -234,6 +238,8 @@ public:
        /// index indicating an invalid position
        static const idx_type npos = static_cast<idx_type>(-1);
 
+       /// constructor
+       Tabular();
        /// constructor
        Tabular(BufferParams const &, col_type columns_arg,
                   row_type rows_arg);
@@ -262,21 +268,21 @@ public:
 
        /* returns the maximum over all rows */
        ///
-       int getWidthOfColumn(idx_type cell) const;
+       int columnWidth(idx_type cell) const;
        ///
-       int getWidthOfTabular() const;
+       int width() const;
        ///
-       int getAscentOfRow(row_type row) const;
+       int height() const;
        ///
-       int getDescentOfRow(row_type row) const;
+       int rowAscent(row_type row) const;
        ///
-       int getHeightOfTabular() const;
+       int rowDescent(row_type row) const;
        ///
-       void setAscentOfRow(row_type row, int height);
+       void setRowAscent(row_type row, int height);
        ///
-       void setDescentOfRow(row_type row, int height);
+       void setRowDescent(row_type row, int height);
        ///
-       void setWidthOfCell(idx_type cell, int new_width);
+       void setCellWidth(idx_type cell, int new_width);
        ///
        void setAllLines(idx_type cell, bool line);
        ///
@@ -294,9 +300,9 @@ public:
        void setVAlignment(idx_type cell, VAlignment align,
                           bool onlycolumn = false);
        ///
-       void setColumnPWidth(LCursor &, idx_type, LyXLength const &);
+       void setColumnPWidth(Cursor &, idx_type, Length const &);
        ///
-       bool setMColumnPWidth(LCursor &, idx_type, LyXLength const &);
+       bool setMColumnPWidth(Cursor &, idx_type, Length const &);
        ///
        void setAlignSpecial(idx_type cell, docstring const & special,
                             Feature what);
@@ -307,15 +313,15 @@ public:
        VAlignment getVAlignment(idx_type cell,
                                 bool onlycolumn = false) const;
        ///
-       LyXLength const getPWidth(idx_type cell) const;
+       Length const getPWidth(idx_type cell) const;
        ///
-       LyXLength const getColumnPWidth(idx_type cell) const;
+       Length const getColumnPWidth(idx_type cell) const;
        ///
-       LyXLength const getMColumnPWidth(idx_type cell) const;
+       Length const getMColumnPWidth(idx_type cell) const;
        ///
        docstring const getAlignSpecial(idx_type cell, int what) const;
        ///
-       int getWidthOfCell(idx_type cell) const;
+       int cellWidth(idx_type cell) const;
        ///
        int getBeginningOfTextInCell(idx_type cell) const;
        ///
@@ -339,7 +345,7 @@ public:
        ///
        idx_type getLastCellInRow(row_type row) const;
        ///
-       idx_type getNumberOfCells() const;
+       idx_type cellCount() const;
        ///
        idx_type numberOfCellsInRow(idx_type cell) const;
        ///
@@ -352,8 +358,8 @@ public:
        int docbook(Buffer const & buf, odocstream & os, OutputParams const &) const;
        ///
        void plaintext(Buffer const &, odocstream &,
-                      OutputParams const & runparams, int const depth,
-                      bool onlydata, unsigned char delim) const;
+                      OutputParams const & runparams, int const depth,
+                      bool onlydata, char_type delim) const;
        ///
        bool isMultiColumn(idx_type cell) const;
        ///
@@ -365,11 +371,11 @@ public:
        ///
        bool isPartOfMultiColumn(row_type row, col_type column) const;
        ///
-       row_type row_of_cell(idx_type cell) const;
+       row_type cellRow(idx_type cell) const;
        ///
-       col_type column_of_cell(idx_type cell) const;
+       col_type cellColumn(idx_type cell) const;
        ///
-       col_type right_column_of_cell(idx_type cell) const;
+       col_type cellRightColumn(idx_type cell) const;
        ///
        void setBookTabs(bool);
        ///
@@ -399,7 +405,7 @@ public:
        ///
        idx_type getLastCellBelow(idx_type cell) const;
        ///
-       idx_type getCellNumber(row_type row, col_type column) const;
+       idx_type cellIndex(row_type row, col_type column) const;
        ///
        void setUsebox(idx_type cell, BoxType);
        ///
@@ -444,11 +450,11 @@ public:
                          boost::shared_ptr<InsetText>) const;
        /// Search for \param inset in the tabular, with the
        ///
-       idx_type getCellFromInset(InsetBase const * inset) const;
+       idx_type getCellFromInset(Inset const * inset) const;
        ///
-       row_type rows() const { return rows_; }
+       row_type rowCount() const { return row_info.size(); }
        ///
-       col_type columns() const { return columns_;}
+       col_type columnCount() const { return column_info.size();}
        ///
        void validate(LaTeXFeatures &) const;
        ///
@@ -467,7 +473,7 @@ public:
                ///
                idx_type cellno;
                ///
-               int width_of_cell;
+               int width;
                ///
                int multicolumn;
                ///
@@ -489,7 +495,7 @@ public:
                ///
                docstring align_special;
                ///
-               LyXLength p_width; // this is only set for multicolumn!!!
+               Length p_width; // this is only set for multicolumn!!!
                ///
                boost::shared_ptr<InsetText> inset;
        };
@@ -505,23 +511,23 @@ public:
                ///
                rowstruct();
                ///
-               int ascent_of_row;
+               int ascent;
                ///
-               int descent_of_row;
+               int descent;
                ///
                bool top_line;
                ///
                bool bottom_line;
                /// Extra space between the top line and this row
-               LyXLength top_space;
+               Length 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;
+               Length 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;
+               Length interline_space;
                /// Ignore interline_space if true and use the default interline space
                bool interline_space_default;
                /// This are for longtabulars only
@@ -533,7 +539,7 @@ public:
                bool endfoot;
                /// row of endlastfoot
                bool endlastfoot;
-               /// row for a pagebreak
+               /// row for a newpage
                bool newpage;
        };
        ///
@@ -553,19 +559,15 @@ public:
                ///
                bool right_line;
                ///
-               int  width_of_column;
+               int width;
                ///
-               LyXLength p_width;
+               Length p_width;
                ///
                docstring align_special;
        };
        ///
        typedef std::vector<columnstruct> column_vector;
 
-       ///
-       row_type rows_;
-       ///
-       col_type columns_;
        ///
        idx_type numberofcells;
        ///
@@ -579,8 +581,6 @@ public:
        ///
        mutable cell_vvector cell_info;
        ///
-       int width_of_tabular;
-       ///
        bool use_booktabs;
        ///
        bool rotate;
@@ -601,7 +601,7 @@ public:
        void init(BufferParams const &, row_type rows_arg,
                  col_type columns_arg);
        ///
-       void set_row_column_number_info();
+       void updateIndexes();
        /// Returns true if a complete update is necessary, otherwise false
        bool setWidthOfMulticolCell(idx_type cell, int new_width);
        ///
@@ -611,10 +611,6 @@ public:
        ///
        bool calculate_width_of_column_NMC(col_type column); // no multi cells
        ///
-       void calculate_width_of_tabular();
-       ///
-       void delete_column(col_type column);
-       ///
        idx_type cells_in_multicolumn(idx_type cell) const;
        ///
        BoxType useParbox(idx_type cell) const;
@@ -640,16 +636,16 @@ public:
        // helper functions for plain text
        ///
        bool plaintextTopHLine(odocstream &, row_type row,
-                              std::vector<unsigned int> const &) const;
+                              std::vector<unsigned int> const &) const;
        ///
        bool plaintextBottomHLine(odocstream &, row_type row,
-                                 std::vector<unsigned int> const &) const;
+                                 std::vector<unsigned int> const &) const;
        ///
        void plaintextPrintCell(Buffer const &, odocstream &,
-                               OutputParams const &,
-                               idx_type cell, row_type row, col_type column,
-                               std::vector<unsigned int> const &,
-                               bool onlydata) const;
+                               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, odocstream & os, row_type,
                       OutputParams const &) const;
@@ -661,7 +657,7 @@ private:
 
 
 
-class InsetTabular : public InsetOld {
+class InsetTabular : public Inset {
 public:
        ///
        InsetTabular(Buffer const &, row_type rows = 1,
@@ -673,7 +669,7 @@ public:
        ///
        void write(Buffer const &, std::ostream &) const;
        ///
-       bool metrics(MetricsInfo &, Dimension &) const;
+       void metrics(MetricsInfo &, Dimension &) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
@@ -683,7 +679,7 @@ public:
        ///
        EDITABLE editable() const { return HIGHLY_EDITABLE; }
        ///
-       bool insetAllowed(InsetBase::Code) const { return true; }
+       bool insetAllowed(InsetCode code) const;
        ///
        bool allowSpellCheck() const { return true; }
        ///
@@ -693,40 +689,40 @@ public:
            insets that may contain several paragraphs */
        bool noFontChange() const { return true; }
        ///
-       bool display() const { return tabular.isLongTabular(); }
+       DisplayType display() const { return tabular.isLongTabular() ? AlignCenter : Inline; }
        ///
        int latex(Buffer const &, odocstream &,
-                 OutputParams const &) const;
+                 OutputParams const &) const;
        ///
        int plaintext(Buffer const &, odocstream &,
-                     OutputParams const &) const;
+                     OutputParams const &) const;
        ///
        int docbook(Buffer const &, odocstream &,
-                   OutputParams const &) const;
+                   OutputParams const &) const;
        ///
        void validate(LaTeXFeatures & features) const;
        ///
-       Code lyxCode() const { return InsetBase::TABULAR_CODE; }
+       InsetCode lyxCode() const { return TABULAR_CODE; }
        /// 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;
        ///
-       bool tabularFeatures(LCursor & cur, std::string const & what);
+       bool tabularFeatures(Cursor & cur, std::string const & what);
        ///
-       void tabularFeatures(LCursor & cur, Tabular::Feature feature,
+       void tabularFeatures(Cursor & cur, Tabular::Feature feature,
                             std::string const & val = std::string());
        ///
        void openLayoutDialog(BufferView *) const;
        ///
        bool showInsetDialog(BufferView *) const;
        /// number of cells
-       size_t nargs() const { return tabular.getNumberOfCells(); }
+       size_t nargs() const { return tabular.cellCount(); }
        ///
        boost::shared_ptr<InsetText const> cell(idx_type) const;
        ///
        boost::shared_ptr<InsetText> cell(idx_type);
        ///
-       LyXText * getText(int) const;
+       Text * getText(int) const;
 
        /// set the change for the entire inset
        void setChange(Change const & change);
@@ -738,8 +734,9 @@ public:
        // this should return true if we have a "normal" cell, otherwise false.
        // "normal" means without width set!
        /// should all paragraphs be output with "Standard" layout?
-       bool forceDefaultParagraphs(idx_type cell = 0) const;
-
+       virtual bool allowParagraphCustomization(idx_type cell = 0) const;
+       ///
+       virtual bool forceEmptyLayout() { return true; }
        ///
        void addPreview(graphics::PreviewLoader &) const;
 
@@ -749,11 +746,13 @@ public:
        /// set the owning buffer
        void buffer(Buffer const * buf);
        /// lock cell with given index
-       void edit(LCursor & cur, bool left);
+       void edit(Cursor & cur, bool front, EntryDirection entry_from);
        ///
-       InsetBase * editXY(LCursor & cur, int x, int y);
+       Inset * editXY(Cursor & cur, int x, int y);
        /// can we go further down on mouse click?
        bool descendable() const { return true; }
+       // Update the counters of this inset and of its contents
+       virtual void updateLabels(Buffer const &, ParIterator const &);
 
        //
        // Public structures and variables
@@ -764,61 +763,62 @@ protected:
        ///
        InsetTabular(InsetTabular const &);
        ///
-       virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
+       virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
        ///
-       bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
+       bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
        ///
        int scroll() const { return scx_; }
 
 private:
-       virtual std::auto_ptr<InsetBase> doClone() const;
+       virtual Inset * clone() const;
 
        ///
        void drawCellLines(frontend::Painter &, int x, int y, row_type row,
                           idx_type cell, bool erased) const;
        ///
-       void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
+       void setCursorFromCoordinates(Cursor & cur, int x, int y) const;
 
        ///
-       void moveNextCell(LCursor & cur);
+       void moveNextCell(Cursor & cur);
        ///
-       void movePrevCell(LCursor & cur);
+       void movePrevCell(Cursor & cur);
        ///
        int getCellXPos(idx_type cell) const;
        ///
-       void resetPos(LCursor & cur) const;
+       void resetPos(Cursor & cur) const;
        ///
        void removeTabularRow();
        ///
-       bool copySelection(LCursor & cur);
+       bool copySelection(Cursor & cur);
        ///
-       bool pasteClipboard(LCursor & cur);
+       bool pasteClipboard(Cursor & cur);
        ///
-       void cutSelection(LCursor & cur);
+       void cutSelection(Cursor & cur);
        ///
-       bool isRightToLeft(LCursor & cur) const;
+       bool isRightToLeft(Cursor & cur) const;
        ///
-       void getSelection(LCursor & cur, row_type & rs, row_type & re,
+       void getSelection(Cursor & cur, row_type & rs, row_type & re,
                          col_type & cs, col_type & ce) const;
        ///
        bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
        /// are we operating on several cells?
-       bool tablemode(LCursor & cur) const;
+       bool tablemode(Cursor & cur) const;
 
        /// return the "Manhattan distance" to nearest corner
        int dist(BufferView &, idx_type cell, int x, int y) const;
        /// return the cell nearest to x, y
        idx_type getNearestCell(BufferView &, int x, int y) const;
 
+       /// test the rotation state of the give cell range.
+       bool oneCellHasRotationState(bool rotated,
+                               row_type row_start, row_type row_end,
+                               col_type col_start, col_type col_end) const;
        ///
        Buffer const * buffer_;
        ///
        mutable idx_type first_visible_cell;
        ///
        mutable int scx_;
-       /// Ugly boolean used when this inset is dissolved and
-       /// InsetTabularMailer should not be used.
-       bool is_deleted_;
 };
 
 
@@ -827,7 +827,7 @@ public:
        ///
        InsetTabularMailer(InsetTabular const & inset);
        ///
-       virtual InsetBase & inset() const { return inset_; }
+       virtual Inset & inset() const { return inset_; }
        ///
        virtual std::string const & name() const { return name_; }
        ///