]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.h
Fix GRAPHICS_EDIT of InsetGraphics
[lyx.git] / src / insets / InsetTabular.h
index 6eaf4d601c8db8b15180e5e630981993413b8ea1..f71a9e59854b487cfba6cd8fb88a48242418a350 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
 
 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 +107,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,
@@ -182,6 +175,8 @@ public:
                ///
                SET_INTERLINE_SPACE,
                ///
+               SET_BORDER_LINES,
+               ///
                LAST_ACTION
        };
        ///
@@ -241,17 +236,16 @@ public:
        /// constructor
        Tabular();
        /// constructor
-       Tabular(BufferParams const &, col_type columns_arg,
-                  row_type rows_arg);
+       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;
@@ -286,14 +280,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 setBottomLine(idx_type cell, bool line, bool wholerow = false);
+       void setLeftLine(idx_type cell, bool line);
        ///
-       void setLeftLine(idx_type cell, bool line, bool wholecolumn = false);
+       void setRightLine(idx_type cell, bool line);
        ///
-       void setRightLine(idx_type cell, bool line, bool wholecolumn = false);
+       bool rowTopLine(row_type row) const;
        ///
+       bool rowBottomLine(row_type row) const;
+       ///
+       bool columnLeftLine(col_type column) const;
+       ///
+       bool columnRightLine(col_type column) const;
+
        void setAlignment(idx_type cell, LyXAlignment align,
                          bool onlycolumn = false);
        ///
@@ -325,17 +327,17 @@ public:
        ///
        int getBeginningOfTextInCell(idx_type cell) const;
        ///
-       void appendRow(BufferParams const &, idx_type cell);
+       void appendRow(idx_type cell);
        ///
        void deleteRow(row_type row);
        ///
-       void copyRow(BufferParams const &, row_type);
+       void copyRow(row_type);
        ///
-       void appendColumn(BufferParams const &, idx_type cell);
+       void appendColumn(idx_type cell);
        ///
        void deleteColumn(col_type column);
        ///
-       void copyColumn(BufferParams const &, col_type);
+       void copyColumn(col_type);
        ///
        bool isFirstCellInRow(idx_type cell) const;
        ///
@@ -349,23 +351,23 @@ public:
        ///
        idx_type numberOfCellsInRow(idx_type cell) const;
        ///
-       void write(Buffer const &, std::ostream &) const;
+       void write(std::ostream &) const;
        ///
-       void read(Buffer const &, Lexer &);
+       void read(Lexer &);
        ///
-       int latex(Buffer const &, odocstream &, OutputParams const &) const;
+       int latex(odocstream &, OutputParams const &) const;
        //
-       int docbook(Buffer const & buf, odocstream & os, OutputParams const &) const;
+       int docbook(odocstream & os, OutputParams const &) const;
        ///
-       void plaintext(Buffer const &, odocstream &,
+       void plaintext(odocstream &,
                       OutputParams const & runparams, int const depth,
-                      bool onlydata, unsigned char delim) const;
+                      bool onlydata, char_type delim) const;
        ///
        bool isMultiColumn(idx_type cell) const;
        ///
        bool isMultiColumnReal(idx_type cell) const;
        ///
-       void setMultiColumn(Buffer *, idx_type cell, idx_type number);
+       void setMultiColumn(idx_type cell, idx_type number);
        ///
        idx_type unsetMultiColumn(idx_type cell); // returns number of new cells
        ///
@@ -401,10 +403,6 @@ public:
        ///
        idx_type getCellBelow(idx_type cell) const;
        ///
-       idx_type getLastCellAbove(idx_type cell) const;
-       ///
-       idx_type getLastCellBelow(idx_type cell) const;
-       ///
        idx_type cellIndex(row_type row, col_type column) const;
        ///
        void setUsebox(idx_type cell, BoxType);
@@ -441,13 +439,13 @@ public:
        ///
        // end longtable support
        ///
-       boost::shared_ptr<InsetText> getCellInset(idx_type cell) const;
+       boost::shared_ptr<InsetTableCell> getCellInset(idx_type cell) const;
        ///
-       boost::shared_ptr<InsetText> getCellInset(row_type row,
+       boost::shared_ptr<InsetTableCell> getCellInset(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;
@@ -460,16 +458,16 @@ public:
        ///
 //private:
        ///
-       class cellstruct {
+       class CellData {
        public:
                ///
-               cellstruct(BufferParams const &);
+               CellData(Buffer const &, Tabular const &);
                ///
-               cellstruct(cellstruct const &);
+               CellData(CellData const &);
                ///
-               cellstruct & operator=(cellstruct);
+               CellData & operator=(CellData);
                ///
-               void swap(cellstruct & rhs);
+               void swap(CellData & rhs);
                ///
                idx_type cellno;
                ///
@@ -497,19 +495,19 @@ public:
                ///
                Length p_width; // this is only set for multicolumn!!!
                ///
-               boost::shared_ptr<InsetText> inset;
+               boost::shared_ptr<InsetTableCell> inset;
        };
-       cellstruct & cellinfo_of_cell(idx_type cell) const;
+       CellData & cellinfo_of_cell(idx_type cell) const;
        ///
-       typedef std::vector<cellstruct> cell_vector;
+       typedef std::vector<CellData> cell_vector;
        ///
        typedef std::vector<cell_vector> cell_vvector;
 
        ///
-       class rowstruct {
+       class RowData {
        public:
                ///
-               rowstruct();
+               RowData();
                ///
                int ascent;
                ///
@@ -539,17 +537,17 @@ public:
                bool endfoot;
                /// row of endlastfoot
                bool endlastfoot;
-               /// row for a pagebreak
+               /// row for a newpage
                bool newpage;
        };
        ///
-       typedef std::vector<rowstruct> row_vector;
+       typedef std::vector<RowData> row_vector;
 
        ///
-       class columnstruct {
+       class ColumnData {
                public:
                ///
-               columnstruct();
+               ColumnData();
                ///
                LyXAlignment alignment;
                ///
@@ -566,7 +564,7 @@ public:
                docstring align_special;
        };
        ///
-       typedef std::vector<columnstruct> column_vector;
+       typedef std::vector<ColumnData> column_vector;
 
        ///
        idx_type numberofcells;
@@ -598,7 +596,7 @@ public:
        ltType endlastfoot;
 
        ///
-       void init(BufferParams const &, row_type rows_arg,
+       void init(Buffer const &, row_type rows_arg,
                  col_type columns_arg);
        ///
        void updateIndexes();
@@ -611,7 +609,7 @@ public:
        ///
        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;
        ///
@@ -625,12 +623,11 @@ public:
        ///
        int TeXCellPostamble(odocstream &, idx_type cell) const;
        ///
-       int TeXLongtableHeaderFooter(odocstream &, Buffer const & buf,
-                                    OutputParams const &) const;
+       int TeXLongtableHeaderFooter(odocstream &, OutputParams const &) const;
        ///
        bool isValidRow(row_type const row) const;
        ///
-       int TeXRow(odocstream &, row_type const row, Buffer const & buf,
+       int TeXRow(odocstream &, row_type const row,
                   OutputParams const &) const;
        ///
        // helper functions for plain text
@@ -641,21 +638,63 @@ public:
        bool plaintextBottomHLine(odocstream &, row_type row,
                                  std::vector<unsigned int> const &) const;
        ///
-       void plaintextPrintCell(Buffer const &, odocstream &,
+       void plaintextPrintCell(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, odocstream & os, row_type,
-                      OutputParams const &) const;
+       int docbookRow(odocstream & os, row_type, OutputParams const &) const;
+
+       /// change associated Buffer
+       void setBuffer(Buffer const & buffer) { buffer_ = &buffer; }
+       /// retrieve associated Buffer
+       Buffer const & buffer() const { return *buffer_; }
 
 private:
+       Buffer const * buffer_;
+
        /// renumber cells after structural changes
        void fixCellNums();
-};
+}; // Tabular
 
 
+///
+class InsetTableCell : public InsetText {
+public:
+       ///
+       explicit InsetTableCell(Buffer const & buf,
+               Tabular::CellData const * cd, Tabular const * t);
+       ///
+       virtual 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:
+       /// 
+       Tabular::CellData const * cell_data_;
+       /// 
+       Tabular const * table_;
+       /// unimplemented
+       InsetTableCell();
+       /// unimplemented
+       void operator=(InsetTableCell const &);
+};
+
 
 class InsetTabular : public Inset {
 public:
@@ -665,9 +704,9 @@ public:
        ///
        ~InsetTabular();
        ///
-       void read(Buffer const &, Lexer &);
+       void read(Lexer &);
        ///
-       void write(Buffer const &, std::ostream &) const;
+       void write(std::ostream &) const;
        ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
@@ -675,11 +714,11 @@ public:
        ///
        void drawSelection(PainterInfo & pi, int x, int y) const;
        ///
-       virtual docstring const editMessage() const;
+       docstring editMessage() const;
        ///
        EDITABLE editable() const { return HIGHLY_EDITABLE; }
        ///
-       bool insetAllowed(Inset::Code) const { return true; }
+       bool insetAllowed(InsetCode code) const;
        ///
        bool allowSpellCheck() const { return true; }
        ///
@@ -691,18 +730,15 @@ public:
        ///
        DisplayType display() const { return tabular.isLongTabular() ? AlignCenter : Inline; }
        ///
-       int latex(Buffer const &, odocstream &,
-                 OutputParams const &) const;
+       int latex(odocstream &, OutputParams const &) const;
        ///
-       int plaintext(Buffer const &, odocstream &,
-                     OutputParams const &) const;
+       int plaintext(odocstream &, OutputParams const &) const;
        ///
-       int docbook(Buffer const &, odocstream &,
-                   OutputParams const &) const;
+       int docbook(odocstream &, OutputParams const &) const;
        ///
        void validate(LaTeXFeatures & features) const;
        ///
-       Code lyxCode() const { return Inset::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;
@@ -718,9 +754,9 @@ public:
        /// number of cells
        size_t nargs() const { return tabular.cellCount(); }
        ///
-       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;
 
@@ -734,42 +770,62 @@ 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;
        ///
-       void addPreview(graphics::PreviewLoader &) const;
-
+       virtual bool forceEmptyLayout(idx_type cell = 0) const;
+       ///
+       virtual bool useEmptyLayout() { return true; }
        ///
-       Buffer const & buffer() const;
+       void addPreview(graphics::PreviewLoader &) const;
 
-       /// set the owning buffer
-       void buffer(Buffer const * buf);
        /// lock cell with given index
-       void edit(Cursor & cur, bool left);
+       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?
        bool descendable() const { return true; }
        // Update the counters of this inset and of its contents
-       virtual void updateLabels(Buffer const &, ParIterator const &);
+       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;
 
        //
        // 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:
-       virtual Inset * clone() const;
+       ///
+       Inset * clone() const { return new InsetTabular(*this); }
 
        ///
        void drawCellLines(frontend::Painter &, int x, int y, row_type row,
@@ -813,8 +869,6 @@ private:
                                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_;